{
  "version": 3,
  "sources": ["components.js"],
  "sourcesContent": ["import $ from \"./jquery.js\";\n\nconst registry = new Map();\nconst MOUNTED_FLAG = \"componentMounted\";\n\n/**\n * Bind behaviour to a `data-component` name. The component's markup lives in a\n * template under `src/www/templates/components/`, declares its options as `data-*`\n * attributes and contains no script of its own.\n *\n * `init` is called with the component's root element and its `data-*` options.\n */\nexport function register(name, init) {\n    if (registry.has(name)) {\n        throw new Error(`Component \"${name}\" is already registered`);\n    }\n    registry.set(name, init);\n}\n\n/**\n * Mount every not-yet-mounted component in `root` and its descendants. Call it\n * after inserting markup that carries a `data-component`; `root` itself may be\n * that element.\n */\nexport function mountAll(root = document) {\n    $(root)\n        .find(\"[data-component]\")\n        .addBack(\"[data-component]\")\n        .each(function () {\n            const element = $(this);\n            if (element.data(MOUNTED_FLAG)) {\n                return;\n            }\n            const init = registry.get(element.attr(\"data-component\"));\n            if (!init) {\n                return;\n            }\n            // `.data()` hands back its live store, so copy before flagging -\n            // otherwise the mount flag shows up among the component's options.\n            const options = { ...element.data() };\n            element.data(MOUNTED_FLAG, true);\n            init(element, options);\n        });\n}\n\n$(() => mountAll());\n"],
  "mappings": "AAAA,OAAOA,MAAO,cAEd,MAAMC,EAAW,IAAI,IACfC,EAAe,mBASd,gBAAS,SAASC,EAAMC,EAAM,CACjC,GAAIH,EAAS,IAAIE,CAAI,EACjB,MAAM,IAAI,MAAM,cAAcA,CAAI,yBAAyB,EAE/DF,EAAS,IAAIE,EAAMC,CAAI,CAC3B,CAOO,gBAAS,SAASC,EAAO,SAAU,CACtCL,EAAEK,CAAI,EACD,KAAK,kBAAkB,EACvB,QAAQ,kBAAkB,EAC1B,KAAK,UAAY,CACd,MAAMC,EAAUN,EAAE,IAAI,EACtB,GAAIM,EAAQ,KAAKJ,CAAY,EACzB,OAEJ,MAAME,EAAOH,EAAS,IAAIK,EAAQ,KAAK,gBAAgB,CAAC,EACxD,GAAI,CAACF,EACD,OAIJ,MAAMG,EAAU,CAAE,GAAGD,EAAQ,KAAK,CAAE,EACpCA,EAAQ,KAAKJ,EAAc,EAAI,EAC/BE,EAAKE,EAASC,CAAO,CACzB,CAAC,CACT,CAEAP,EAAE,IAAM,SAAS,CAAC",
  "names": ["$", "registry", "MOUNTED_FLAG", "name", "init", "root", "element", "options"]
}
