{"version":3,"file":"index.mjs","sources":["../code/imm_utils.mjs","../code/imm_pxy.mjs","../code/imm_raf.mjs","../code/imm_evt_core.mjs","../code/imm_async.mjs","../code/imm_query.mjs","../code/imm_dom_core.mjs","../code/imm_dom_async.mjs","../code/imm_dom.mjs","../code/imm_dom_ns.mjs","../code/imm_svg.mjs","../code/imm_css.mjs","../code/imm_htag.mjs","../code/imm_h1.mjs","../code/imm_h.mjs","../code/imm_tmpl_core.mjs","../code/imm_tmpl.mjs","../code/imm_elem_core.mjs","../code/imm_elem_model.mjs","../code/imm_elem.mjs","../code/imm_elem_raf.mjs","../code/imm_clone.mjs","../code/imm_qx.mjs","../code/imm_legacy.mjs","../code/imm_dialog.mjs"],"sourcesContent":["export const\n _I_ = x=>x,\n _dash_name = s => s?.replace(/_/g, '-'),\n _prop_name = s => s?.replace(/-/g, '_'),\n _pairs = o => Object.entries(o),\n _is_obj = a => 'object' === typeof a && null !== a,\n _is_iter = a => _is_obj(a) && Symbol.iterator in a,\n _is_attr_dict = a => _is_obj(a)\n && !a.nodeType && !a.toDOM\n && !_is_iter(a)\n\nexport const\n _imm_cp = (tgt, src, key) =>\n Object.assign(tgt, key ? {[key]:src} : src),\n _ce = /* #__PURE__ */ _I_(customElements),\n\n _el_on = (el, ...z) => ( el.addEventListener(...z), el ),\n _el_get = (el,k) => (k=el.getAttribute(k), ''==k || k),\n _el_has = (el,k) => el.hasAttribute(k),\n _el_set = (el,k,v) => (\n (null == v || false === v\n ? el.removeAttribute(k) // false or nullish is semantically removeAttribute()\n : _is_obj(v) == {style: 1}[k] ? _imm_cp(el[k], v) // use object assign for known keys: style; note true==1 but false!=undefined\n : el.setAttribute(k, true === v ? '' : v)\n ), 1)\n\n","import {_I_, _dash_name, _prop_name, _el_get, _el_has, _el_set} from './imm_utils.mjs'\n\n\nconst _imm_pxy_gset = /* #__PURE__ */ _I_({\n get: (fn,k) => fn(k),\n set: (fn,k,v) => (fn(k,v), 1),\n})\nexport const imm_pxy_gset = fn =>\n new Proxy(fn, _imm_pxy_gset)\n\n\nconst _imm_pxy = /* #__PURE__ */ _I_({\n get(tag_fn, key, ns) {\n let r = tag_fn[key]\n if (undefined === r && /[a-z]/.test(key))\n ns[key] = r = tag_fn\n .bind(null, _dash_name(key))\n return r }})\n\nexport const imm_pxy_tag = (tag_fn, kw=tag_fn) =>\n ({ __proto__: new Proxy(tag_fn, _imm_pxy), ... kw })\n\nconst\n _imm_pxy_attr = /* #__PURE__ */ _I_({\n // use k.trim to avoid Symbols\n get: ({$},k) => k.trim && (_el_get($, _dash_name(k)) || _el_get($, k)),\n has: ({$},k) => k.trim && (_el_has($, _dash_name(k)) || _el_has($, k)),\n set: ({$},k,v) => _el_set($, _dash_name(k), v),\n deleteProperty: ({$},k) => _el_set($, _dash_name(k)) || _el_set($, k),\n\n // update the proxy for each attribute to leverage default implementation of getOwnPropertyDescriptor()\n ownKeys: pxy => pxy.$.getAttributeNames().map(k => (k=_prop_name(k), pxy[k] = k)),\n })\n\nexport const imm_pxy_attr = el =>\n new Proxy({$:el}, _imm_pxy_attr)\n\nexport const with_ns_attr = ImmKlass =>\n class extends ImmKlass {\n get _ns_() { return imm_pxy_attr(this) }\n }\n\n\nexport function imm_pxy_css(css_style) {\n let _css_prop = css_style.getPropertyValue.bind(css_style)\n return imm_pxy_gset(k => _css_prop(_dash_name(k))) }\n\n","export const imm_raf_sym =\n imm_raf.sym = Symbol.for('imm_raf')\n\nlet _raf_p=0, _raf_map = new Map()\n\nexport function imm_raf(obj, x) {\n if (null != obj && !_raf_map.has(obj))\n _raf_map.set(obj, x)\n\n if (0 === _raf_p)\n _raf_p = new Promise(requestAnimationFrame)\n .then(_raf_tick)\n return _raf_p\n}\n\nfunction _raf_tick() {\n let coll = [... _raf_map.entries()]\n _raf_map = new Map()\n _raf_p = 0\n\n coll.map(_raf_notify)\n}\n\nasync function _raf_notify([obj, x]) {\n obj[await imm_raf_sym](imm_raf, x) }\n\nexport default imm_raf\n","import { _el_on, _pairs } from './imm_utils.mjs'\n \n\nexport function imm_emit0(tgt, evt, opt) {\n return tgt.dispatchEvent(new CustomEvent(evt, opt)) }\n\nexport function imm_emit_at(tgt, evt, detail, opt) {\n return imm_emit0(tgt, evt, {...opt, detail}) }\n\nexport function imm_emit(tgt, evt, detail, opt) {\n return imm_emit0(tgt, evt, {bubbles: true, cancelable: true, ...opt, detail}) }\n\nexport function imm_wcemit(tgt, evt, detail, opt) {\n return imm_emit(tgt, evt, detail, {composed: true, ...opt}) }\n\n\nexport function imm_on(el, ns, xfn=f=>f) {\n ns = ns[0] ? ns : _pairs(ns)\n for (let [n,f,o] of ns)\n _el_on(el, n, xfn(f), o)\n return el\n}\n\nexport const with_emit0 = ImmKlass =>\n class extends ImmKlass {\n emit0(evt, detail) {\n return imm_emit0(this, evt, {detail})\n }\n on(... ns) {\n ns = ns[1] ? [ns] : ns[0]\n return imm_on(this, ns, f => e => f(e.detail))\n }\n }\n\n","\nexport function imm_defer_ctx(as_res=((...args) => args)) {\n let y,n,_pset = (a,b) => { y=a, n=b }\n return p => (p = new Promise(_pset), as_res(p, y, n))\n}\n\nexport const imm_defer_v = /* #__PURE__ */\n imm_defer_ctx()\n\nexport const imm_defer = /* #__PURE__ */\n imm_defer_ctx((p,y,n) =>\n ({promise: p, resolve: y, reject: n}))\n\n","export const\n imm_wchost = el => el.getRootNode().host || null,\n imm_id = (el, id=`z${2e9*Math.random()|0}`) => el.id ||= id,\n\n imm_wcsel = (el, query) =>\n null === el ? null : query.nodeType ? query\n : el.closest?.(query) || imm_wcsel(imm_wchost(el), query),\n\n imm_set_qx = (key, el, query='*') => (\n imm_wcsel(el.parentNode, query)\n .dataset[key] = `${el.tagName}#${imm_id(el)}` ),\n\n imm_wcqx = (key, el_ctx, q) =>\n (el_ctx = imm_wcsel(el_ctx, `[data-${key}]`))\n ?.querySelector(q || el_ctx.dataset[key])\n\nexport {imm_wcqx as imm_qx}\n","import {\n _dash_name, _pairs,\n _is_attr_dict, _is_iter,\n _el_set, _el_on, _imm_cp\n} from './imm_utils.mjs'\nexport {\n _imm_cp\n} from './imm_utils.mjs'\n\n\n// complex expressions to avoid 'if', 'else', and 'return' keywords\nconst\n // .reduce(_imm_aop, el) interpretation of imm attribute dictionary semantics\n _imm_aop = (el,[k,v],k0,attrs) => (\n k0 = k[0]\n , (\n '$' === k0 // children to prepend\n ? (attrs.z ||= []).push(v)\n\n : '=' === k0 // direct property assignment\n ? _imm_cp(el, v, k.split('=')[1])\n\n : '@' === k0 // hook callback\n ? v(el, k)\n\n : v?.call // event handlers\n ? _el_on(el, k, v, v.opt)\n\n : _el_set(el, _dash_name(k), v) // attribute values\n ), el),\n\n // .flatMap(_imm_cf) interpretation of imm child elements and iterables\n _imm_cf = c => (\n // allow opt-in coersion\n c &&= c.toDOM?.(c) || c.valueOf(c),\n\n null == c ? [] // filter nullish\n\n : c.nodeType ? [c] // pass-through nodes\n\n : _is_iter(c) ? _imm_b(c) // recursively reduce arrays and iterables\n\n : ''+c ) // otherwise force toString()\n\n\n\nexport function imm(el, ...args) {\n let len=args.length, attrs=args[0]\n\n if (0 < len && el?.nodeType) {\n if (_is_attr_dict(attrs)) {\n // replace attrs with null in args\n 1 === len ? args = null : args[0] = null\n\n attrs = _pairs(attrs)\n attrs.reduce(_imm_aop, el)\n\n // prepend children found in attrs.z\n attrs.z && el.prepend(... _imm_b(attrs.z))\n }\n\n // append arguments as children\n args && el.append(... _imm_b(args))\n }\n return el\n}\n\n\nexport const\n // clear all inner content (text and html)\n _imm0 = el => (el.textContent = '', el),\n imm_set = (el, ...args) => imm(_imm0(el), ...args),\n\n _imm_b = iterable => [... iterable].flatMap(_imm_cf)\n\n","import {imm} from './imm_dom_core.mjs'\nexport {imm, imm_set} from './imm_dom_core.mjs'\n\nexport const imma = (el_placeholder, el_promise, attrs) =>\n (_imma(el_placeholder, el_promise, attrs)\n , el_placeholder)\n\nasync function _imma(el_placeholder, el_promise, attrs) {\n el_promise = imm(await el_promise, await attrs)\n el_placeholder?.replaceWith(el_promise)\n}\n","import {imm, imm_set} from './imm_dom_core.mjs'\nexport {imm, imm_set} from './imm_dom_core.mjs'\n\n\nexport function imm_dom(host, tagns) {\n tagns = {\n $: 'html', html: 'http://www.w3.org/1999/xhtml',\n svg: 'http://www.w3.org/2000/svg',\n ... tagns }\n let\n _tag0 = (tag, ns) => (\n // split xml-tag like namespace prefix\n ((ns = tag.split(':'))[1] // if tuple is present\n ? [ns, tag]=ns // use namespace by prefix\n : ns=0 ) // otherwise use default namespace (falsy)\n , host.createElementNS( tagns[ns || tagns.$], tag )),\n\n tag_fn = (tag, ...args) =>\n imm(tag.nodeType ? tag : _tag0(tag), ...args)\n\n tag_fn.fragment = (...args) =>\n imm(host.createDocumentFragment(), null, ...args)\n\n tag_fn.text = text =>\n host.createTextNode(text)\n\n return tag_fn.tag = tag_fn\n}\n\nexport const\n imm_otag = (el, tag, ...args) =>\n imm(el.ownerDocument.createElement(tag), ...args),\n\n imm_tag = /* #__PURE__ */\n imm_dom(document)\n\nexport {\n imm_tag as default,\n imm_tag as tag,\n}\n\n","import { imm_tag } from './imm_dom.mjs'\nimport { imm_pxy_tag } from './imm_pxy.mjs'\n\nexport { imm, imm_set } from './imm_dom_core.mjs'\n\nexport const imm_html = /* #__PURE__ */ imm_pxy_tag(imm_tag)\n\nexport { imm_html as html, imm_html as default }\n","import { imm_dom } from './imm_dom.mjs'\nimport { imm_pxy_tag } from './imm_pxy.mjs'\n\nexport { imm, imm_set } from './imm_dom_core.mjs'\n\n\nexport const imm_svg_tag = /* #__PURE__ */\n imm_dom(document, {$: 'svg'})\n\nexport const imm_svg = /* #__PURE__ */\n imm_pxy_tag(imm_svg_tag)\n\n\nexport {\n imm_svg_tag as tsvg,\n imm_svg as svg,\n imm_svg as default,\n}\n\n","import {tag} from './imm_dom.mjs'\nexport {imm, imm_set, imm_tag, tag} from './imm_dom.mjs'\n\nexport function _imm_css_link() {\n let el_doc = new DOMParser().parseFromString('', 'text/html')\n let el_style = el_doc.querySelector('style')\n let el = el_doc.body\n let z = el.style\n\n let wm_cache = new WeakMap()\n return (parts, ...args) => {\n if ('string' === typeof parts)\n parts = [parts]\n\n let valid = wm_cache.get(parts)\n if (undefined === valid)\n wm_cache.set(parts,\n valid = _css_valid(\n parts.join('var(--z);')))\n\n if (!valid)\n throw SyntaxError('imm_css invalid template')\n\n let i, s=''+parts[0], len=Math.min(args.length, parts.length-1)\n for (i=0; i\n tag('style', imm_css(...args))\n\nexport {\n imm_css as default,\n imm_css as css,\n imm_style as style\n}\n","import { _is_iter, _is_attr_dict } from './imm_utils.mjs'\n\nconst \n _imm_h = (h_tag, h_lst) =>\n [... h_lst].reduceRight(_h_rr, h_tag),\n\n _h_rr = (h_tag, v, idx, h_lst) =>\n ! idx ? h_tag(... h_lst)\n : (_is_iter(v)\n ? h_lst[idx] = _imm_h(h_tag, v)\n : v\n , h_tag),\n\n _hafn = (attrs, match, op, value) => (\n '.' === op\n ? attrs.class = `${attrs.class||''} ${value}`\n : attrs.id = value // # === op\n , ''),\n\n _htag = h_tag => (... h_lst) => (\n // ensure [1] is an attribute dict\n _is_attr_dict(h_lst[1]) || h_lst.splice(1,0,{}),\n\n // replace tag name, #id, and .class\n h_lst[0] = h_lst[0].replaceAll(\n /\\s*([.#])([^.#\\s]*)\\s*/g,\n _hafn.bind(0, h_lst[1])),\n\n // return our fixedup h_lst\n h_tag(... h_lst))\n\nexport { _htag, _imm_h }\n","import { imm_tag } from './imm_dom.mjs'\nimport { _imm_h } from './imm_htag.mjs'\nexport { imm_tag } from './imm_dom.mjs'\n\nconst imm_h1 = h_lst => _imm_h(imm_tag, h_lst)\n\nexport { imm_h1, imm_h1 as default }\n","import { imm_tag } from './imm_dom.mjs'\nimport { _imm_h, _htag } from './imm_htag.mjs'\nexport { imm_tag } from './imm_dom.mjs'\nexport { _htag } from './imm_htag.mjs'\n\nconst imm_h = h_lst => _imm_h(_htag(imm_tag), h_lst)\n\nexport { imm_h, imm_h as default }\n\n","// _tkey prefix from valid custom element name of [4.13.3: Core concepts][WHATWG ]\n//\n// [WHATWG]: https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-core-concepts\nconst _tkey = 'I\\u2133-'+Date.now(), _tqsel = '['+_tkey+']', _ttype = 'text/x-'+_tkey\n\nexport function imm_tmpl_link(invoke_arg) {\n let wm_cache = new WeakMap()\n return (parts, ...args) => {\n // Return cloned template content with args expanded into keyed nodes\n\n let el = wm_cache.get(parts)\n if (!el)\n wm_cache.set(parts,\n el = _imm_tmpl_c(parts))\n\n el = el.content.cloneNode(true)\n for (let tgt_elem of el.querySelectorAll(_tqsel)) {\n // remove the tag key -- intentionally ugly!\n let idx = + tgt_elem.getAttribute(_tkey)\n tgt_elem.removeAttribute(_tkey)\n\n let a = args[+idx]\n\n // update/replace target node with arg\n invoke_arg(\n tgt_elem, _ttype === tgt_elem.type,\n null == a ? a : a.valueOf(), idx)\n }\n return el\n }\n}\n\nexport function _imm_tmpl_c(parts) {\n // Compile into template element with keyed attributes and nodes\n\n // render all as attributes\n let kinds = Array(parts.length - 1).fill(2)\n let el0 = _imm_tmpl_r(parts, kinds)\n\n // reset mark node as default rendering\n kinds.fill(1)\n\n // mark found attributes\n for (let each of el0.content.querySelectorAll(_tqsel))\n kinds[+each.getAttribute(_tkey)] = 2\n\n // render correctly as node or attribute\n return _imm_tmpl_r(parts, kinds)\n}\n\nexport function _imm_tmpl_r(parts, kinds) {\n // Render into template element with keyed attributes.\n\n // Concatenates `parts` with attribute or node\n // driven by corresponding `kind`\n\n let s='', i=-1\n for (let p of parts) {\n s += p\n\n let pk = kinds[++i] | 0\n if (pk) {\n // as attribute\n let pi = ` ${_tkey}=${i}`\n\n if (1 & pk) // as node\n pi = `