{"version":3,"sources":["light-root.ts"],"sourcesContent":["import { domContext } from \"../app/dom-context.ts\";\n\n/**\n * Alternative to ShadowRoot, also works with slot elements.\n * Does not have a separate document and encapsulated styles\n */\nexport class LightRoot extends domContext.HTMLElement {\n\t\n\tconnectedCallback() {\n\t\tconst parent = this.parentElement!;\n\t\t// move all parent children to slots\n\t\tfor (const node of [...parent.childNodes as unknown as Iterable<Node>]) {\n\t\t\tif (node === this) continue;\n\t\t\tthis.appendChildToSlot(node);\n\t\t}\n\n\t\t// proxyify parent node dom modification methods\n\t\tparent.append = (...nodes) => {nodes.forEach(node => this.appendChildToSlot(node))}\n\t\tparent.appendChild = (node) => {\n\t\t\tthis.appendChildToSlot(node, true)\n\t\t\treturn node;\n\t\t}\n\t\tparent.removeChild = (node) => {this.removeChild(node); return node;}\n\n\t\t// TODO: support more methods, children, create virtual dom to keep track of parent children?\n\n\t}\n\n\t#defaultSlot?: HTMLSlotElement|null = null\n\n\tappendChildToSlot(child: Node|string, removeContent = false) {\n\t\tconst slot = this.getChildSlot(child);\n\t\tif (slot) {\n\t\t\tif (removeContent) slot.innerHTML = \"\";\n\t\t\tslot.appendChild(child);\n\t\t}\n\t}\n\n\tgetChildSlot(child: Node|string) {\n\t\tif (child instanceof domContext.Element && child.hasAttribute(\"slot\")) {\n\t\t\treturn this.querySelector(`slot[name=\"${child.getAttribute(\"slot\")}\"]`)\n\t\t}\n\t\telse {\n\t\t\treturn this.#defaultSlot ?? (this.#defaultSlot = this.querySelector('slot:not([name]), slot[name=\"\"]'))\n\t\t}\n\t}\n\t\n\t// disconnectedCallback() {\n\t// \tthrow new Error(\"Cannot remove light root from parent element\")\n\t// }\n\n}\n\ndomContext.customElements.define(\"light-root\", LightRoot)"],"names":["domContext","LightRoot","HTMLElement","connectedCallback","parent","parentElement","node","childNodes","appendChildToSlot","append","nodes","forEach","appendChild","removeChild","child","removeContent","slot","getChildSlot","innerHTML","Element","hasAttribute","querySelector","getAttribute","customElements","define"],"mappings":"AAAA,SAASA,UAAU,QAAQ,wBAAwB;AAMnD,OAAO,MAAMC,kBAAkBD,WAAWE,WAAW;IAEpDC,oBAAoB;QACnB,IAAMC,SAAS,IAAI,CAACC,aAAa;QAEjC,KAAK,IAAMC,QAAQ;eAAIF,OAAOG,UAAU;SAA8B,CACjED,SAAS,IAAI,IACjB,IAAI,CAACE,iBAAiB,CAACF;QAIxBF,OAAOK,MAAM,GAAG,CAAC,GAAGC;YAAWA,MAAMC,OAAO,CAACL,CAAAA,OAAQ,IAAI,CAACE,iBAAiB,CAACF;QAAM,GAClFF,OAAOQ,WAAW,GAAG,CAACN,QACrB,IAAI,CAACE,iBAAiB,CAACF,MAAM,CAAA,IACtBA,OAERF,OAAOS,WAAW,GAAG,CAACP,QAAU,IAAI,CAACO,WAAW,CAACP,OAAcA;IAIhE;IAEA,CAAA,WAAY,GAA0B,KAAI;IAE1CE,kBAAkBM,KAAkB,EAAEC,gBAAgB,CAAA,CAAK,EAAE;QAC5D,IAAMC,OAAO,IAAI,CAACC,YAAY,CAACH;QAC3BE,SACCD,iBAAeC,CAAAA,KAAKE,SAAS,GAAG,EAAC,GACrCF,KAAKJ,WAAW,CAACE;IAEnB;IAEAG,aAAaH,KAAkB,EAAE;eAChC,AAAIA,iBAAiBd,WAAWmB,OAAO,IAAIL,MAAMM,YAAY,CAAC,UACtD,IAAI,CAACC,aAAa,CAAC,CAAC,WAAW,EAAEP,MAAMQ,YAAY,CAAC,QAAQ,EAAE,CAAC,IAG/D,IAAI,CAAC,CAAA,WAAY,IAAK,CAAA,IAAI,CAAC,CAAA,WAAY,GAAG,IAAI,CAACD,aAAa,CAAC,kCAAiC;IAEvG;AAMD;AAEArB,WAAWuB,cAAc,CAACC,MAAM,CAAC,cAAcvB","sourceRoot":"/lib/uix-0.4.39/src/html/","file":"light-root.ts"}