{"version":3,"file":"index.js","sources":["masonry-helpers.js","masonry-layout.js"],"sourcesContent":["export const DEFAULT_MAX_COL_WIDTH = 500;\nexport const DEFAULT_COLS = \"auto\";\nexport const DEFAULT_DEBOUNCE_MS = 300;\nexport const DEFAULT_GAP_PX = 24;\nexport const COL_COUNT_CSS_VAR_NAME = `--_masonry-layout-col-count`;\nexport const GAP_CSS_VAR_NAME = `--_masonry-layout-gap`;\n// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\nexport const ELEMENT_NODE_TYPE = 1;\nconst DEBOUNCE_MAP = new Map();\n/**\n * Returns a number attribute from an element.\n * @param $elem\n * @param name\n * @param defaultValue\n */\nexport function getNumberAttribute($elem, name, defaultValue) {\n const value = parseFloat($elem.getAttribute(name) || \"\");\n return isNaN(value) ? defaultValue : value;\n}\n/**\n * Returns the amount of cols that the masonry grid should have.\n * @param totalWidth\n * @param cols\n * @param maxColWidth\n */\nexport function getColCount(totalWidth, cols, maxColWidth) {\n return isNaN(cols)\n ? Math.max(1, Math.ceil(totalWidth / maxColWidth))\n : cols;\n}\n/**\n * Debounces a function.\n * @param cb\n * @param ms\n * @param id\n */\nexport function debounce(cb, ms, id) {\n const existingTimeout = DEBOUNCE_MAP.get(id);\n if (existingTimeout != null)\n window.clearTimeout(existingTimeout);\n DEBOUNCE_MAP.set(id, window.setTimeout(cb, ms));\n}\n/**\n * Returns the index of the column with the smallest height.\n * @param colHeights\n */\nexport function findSmallestColIndex(colHeights) {\n let smallestIndex = 0;\n let smallestHeight = Infinity;\n colHeights.forEach((height, i) => {\n if (height < smallestHeight) {\n smallestHeight = height;\n smallestIndex = i;\n }\n });\n return smallestIndex;\n}\n//# sourceMappingURL=masonry-helpers.js.map","import { COL_COUNT_CSS_VAR_NAME, debounce, DEFAULT_COLS, DEFAULT_DEBOUNCE_MS, DEFAULT_GAP_PX, DEFAULT_MAX_COL_WIDTH, ELEMENT_NODE_TYPE, findSmallestColIndex, GAP_CSS_VAR_NAME, getColCount, getNumberAttribute } from \"./masonry-helpers\";\n/**\n * Template for the masonry layout.\n * Max width of each column is computed as the width in percentage of\n * the column minus the total with of the gaps divided between each column.\n */\nconst $template = document.createElement(\"template\");\n$template.innerHTML = `\n \n