@domphy/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 domphy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @domphy/core
2
+
3
+ DOM rendering with fine-grained reactivity, CSS-in-JS, and SSR — using plain JavaScript objects. No JSX, no compiler, no virtual DOM.
4
+
5
+ ```bash
6
+ npm install @domphy/core
7
+ ```
8
+
9
+ ## How it works
10
+
11
+ A Domphy element is a plain object. The HTML tag is the key; its value is the content.
12
+
13
+ ```ts
14
+ import { ElementNode, toState } from "@domphy/core"
15
+
16
+ const count = toState(0)
17
+
18
+ const App = {
19
+ div: [
20
+ {
21
+ p: (listener) => `Count: ${count.get(listener)}`
22
+ // count.get(listener) — returns value AND subscribes.
23
+ // When count changes, only this text node re-renders.
24
+ },
25
+ {
26
+ button: "Increment",
27
+ onClick: () => count.set(count.get() + 1),
28
+ style: {
29
+ padding: "4px 16px",
30
+ borderRadius: "6px",
31
+ "&:hover": { opacity: 0.8 }
32
+ }
33
+ }
34
+ ]
35
+ }
36
+
37
+ new ElementNode(App).render(document.body)
38
+ ```
39
+
40
+ ## SSR
41
+
42
+ Same element definition on server and client — no duplication.
43
+
44
+ ```ts
45
+ // server.js
46
+ const node = new ElementNode(App)
47
+ const page = `<html>
48
+ <head><style>${node.generateCSS()}</style></head>
49
+ <body><div id="app">${node.generateHTML()}</div></body>
50
+ </html>`
51
+
52
+ // client.js
53
+ new ElementNode(App).mount(document.getElementById("app"))
54
+ ```
55
+
56
+ ## Patches
57
+
58
+ A Patch is a function returning a partial element descriptor, applied via `$`. Element properties always override patch defaults — the element owns the final result.
59
+
60
+ ```ts
61
+ import { merge } from "@domphy/core"
62
+
63
+ function rounded() {
64
+ return (base) => merge(base, {
65
+ style: { borderRadius: "8px", padding: "8px 16px" }
66
+ })
67
+ }
68
+
69
+ const btn = { button: "Click", $: [rounded()] }
70
+ ```
71
+
72
+ ---
73
+
74
+ **[Full documentation →](https://domphy.dev/core/)**
@@ -0,0 +1,2 @@
1
+ "use strict";var Domphy=(()=>{var z=Object.defineProperty;var G=(o,e)=>{for(var t in e)z(o,t,{get:e[t],enumerable:!0})};var $={};G($,{AttributeList:()=>x,BooleanAttributes:()=>w,CamelAttributes:()=>O,ElementList:()=>T,ElementNode:()=>m,HtmlTags:()=>R,Notifier:()=>v,PrefixCSS:()=>b,State:()=>E,VoidTags:()=>X,hashString:()=>N,merge:()=>g,toState:()=>J});var q=["onAbort","onAuxClick","onBeforeMatch","onBeforeToggle","onBlur","onCancel","onCanPlay","onCanPlayThrough","onChange","onClick","onClose","onContextLost","onContextMenu","onContextRestored","onCopy","onCueChange","onCut","onDblClick","onDrag","onDragEnd","onDragEnter","onDragLeave","onDragOver","onDragStart","onDrop","onDurationChange","onEmptied","onEnded","onError","onFocus","onFormData","onInput","onInvalid","onKeyDown","onKeyPress","onKeyUp","onLoad","onLoadedData","onLoadedMetadata","onLoadStart","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onPaste","onPause","onPlay","onPlaying","onProgress","onRateChange","onReset","onResize","onScroll","onScrollEnd","onSecurityPolicyViolation","onSeeked","onSeeking","onSelect","onSlotChange","onStalled","onSubmit","onSuspend","onTimeUpdate","onToggle","onVolumeChange","onWaiting","onWheel","onTouchStart","onTouchMove","onTouchEnd","onTouchCancel","onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut","onGotPointerCapture","onLostPointerCapture","onCompositionStart","onCompositionUpdate","onCompositionEnd","onTransitionEnd","onTransitionStart","onAnimationStart","onAnimationEnd","onAnimationIteration","onFullscreenChange","onFullscreenError","onFocusIn","onFocusOut"],U=q.reduce((o,e)=>{let t=e.slice(2).toLowerCase();return o[t]=e,o},{});var R=["a","abbr","address","article","aside","audio","b","base","blockquote","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","i","iframe","img","input","ins","kbd","label","legend","li","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","slot","small","source","span","strong","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","bdi","bdo","math","menu","search","area","embed","hr","animate","animateMotion","animateTransform","circle","clipPath","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","prefetch","radialGradient","rect","set","solidColor","stop","svg","switch","symbol","tbreak","text","textPath","tspan","use","view"];var v=class{constructor(){this._listeners={}}_dispose(){if(this._listeners)for(let e in this._listeners)this._listeners[e].clear();this._listeners=null}addListener(e,t){if(!this._listeners)return()=>{};if(typeof e!="string"||typeof t!="function")throw new Error("Event name must be a string, listener must be a function");this._listeners[e]||(this._listeners[e]=new Set);let s=()=>this.removeListener(e,t);return this._listeners[e].has(t)||(this._listeners[e].add(t),typeof t.onSubscribe=="function"&&t.onSubscribe(s)),s}removeListener(e,t){if(!this._listeners)return;let s=this._listeners[e];s&&s.has(t)&&(s.delete(t),s.size===0&&delete this._listeners[e])}notify(e,...t){if(!this._listeners)return;let s=this._listeners[e];if(s)for(let n of[...s])try{n(...t)}catch(i){console.error(i)}}};var E=class{constructor(e){this._notifier=new v;this.initialValue=e,this._value=e}get(e){return e&&this.onChange(e),this._value}set(e){this._notifier&&(this._value=e,this._notifier.notify("change",e))}reset(){this.set(this.initialValue)}onChange(e){return this._notifier?this._notifier.addListener("change",e):()=>{}}_dispose(){this._notifier&&(this._notifier._dispose(),this._notifier=null)}};function g(o={},e={}){let t=["animation","transition","boxShadow","textShadow","background","fontFamily"],s=["class","rel","transform","acceptCharset","sandbox"],n=["content"];Object.prototype.toString.call(e)==="[object Object]"&&Object.getPrototypeOf(e)===Object.prototype&&(e=y(e));for(let i in e){let r=e[i];if(!(r==null||r===""))if(typeof r=="object"&&!Array.isArray(r))typeof o[i]=="object"?o[i]=g(o[i],r):o[i]=r;else if(t.includes(i))if(typeof o[i]=="function"||typeof r=="function"){let l=o[i];o[i]=h=>{let c=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[c,a].filter(f=>f).join(", ")}}else o[i]=[o[i],r].filter(l=>l).join(", ");else if(n.includes(i))if(typeof o[i]=="function"||typeof r=="function"){let l=o[i];o[i]=h=>{let c=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[c,a].filter(f=>f).join("")}}else o[i]=[o[i],r].filter(l=>l).join("");else if(s.includes(i))if(typeof o[i]=="function"||typeof r=="function"){let l=o[i];o[i]=h=>{let c=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[c,a].filter(f=>f).join(" ")}}else o[i]=[o[i],r].filter(l=>l).join(" ");else if(i.startsWith("on")){let l=i.replace("on","").toLowerCase();I(o,l,r)}else if(i.startsWith("_on")){let l=i.replace("_on","");F(o,l,r)}else o[i]=r}return o}function J(o){return o instanceof E?o:new E(o)}function N(o=""){let e=2166136261;for(let t=0;t<o.length;t++)e^=o.charCodeAt(t),e=e*16777619>>>0;return String.fromCharCode(97+e%26)+e.toString(16)}function F(o,e,t){let s=`_on${e}`,n=o[s];typeof n=="function"?o[s]=(...i)=>{n(...i),t(...i)}:o[s]=t}function I(o,e,t){let s=U[e];if(!s)throw Error(`invalid event name "${e}"`);let n=o[s];typeof n=="function"?o[s]=(i,r)=>{n(i,r),t(i,r)}:o[s]=t}function y(o,e=new WeakMap){if(o===null||typeof o!="object"||typeof o=="function")return o;if(e.has(o))return e.get(o);let t=Object.getPrototypeOf(o);if(t!==Object.prototype&&!Array.isArray(o))return o;let s;if(Array.isArray(o)){s=[],e.set(o,s);for(let n of o)s.push(y(n,e));return s}if(o instanceof Date)return new Date(o);if(o instanceof RegExp)return new RegExp(o);if(o instanceof Map){s=new Map,e.set(o,s);for(let[n,i]of o)s.set(y(n,e),y(i,e));return s}if(o instanceof Set){s=new Set,e.set(o,s);for(let n of o)s.add(y(n,e));return s}if(ArrayBuffer.isView(o))return new o.constructor(o);if(o instanceof ArrayBuffer)return o.slice(0);s=Object.create(t),e.set(o,s);for(let n of Reflect.ownKeys(o))s[n]=y(o[n],e);return s}function P(o,e=!1){if(Object.prototype.toString.call(o)!=="[object Object]")throw Error(`typeof ${o} is invalid DomphyElement`);let t=Object.keys(o);for(let s=0;s<t.length;s++){let n=t[s],i=o[n];if(s==0&&!R.includes(n)&&!n.includes("-")&&!e)throw Error(`key ${n} is not valid HTML tag name`);if(n=="style"&&i&&Object.prototype.toString.call(i)!=="[object Object]")throw Error('"style" must be a object');if(n=="$")o.$.forEach(r=>P(r,!0));else{if(n.startsWith("_on")&&typeof i!="function")throw Error(`hook ${n} value "${i}" must be a function `);if(n.startsWith("on")&&typeof i!="function")throw Error(`event ${n} value "${i}" must be a function `);if(n=="_portal"&&typeof i!="function")throw Error('"_portal" must be a function return HTMLElement');if(n=="_context"&&Object.prototype.toString.call(i)!=="[object Object]")throw Error('"_context" must be a object');if(n=="_metadata"&&Object.prototype.toString.call(i)!=="[object Object]")throw Error('"_metadata" must be a object');if(n=="_key"&&typeof i!="string"&&typeof i!="number")throw Error('"_key" must be a string or number')}}return!0}function K(o){return/<([a-z][\w-]*)(\s[^>]*)?>.*<\/\1>|<([a-z][\w-]*)(\s[^>]*)?\/>/i.test(o.trim())}function B(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function V(o){return Object.keys(o).find(e=>R.includes(e))}function C(o){return o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function W(o){if(o.indexOf("@")===0)return[o];for(var e=[],t=0,s=0,n="",i=0,r=o.length;i<r;i++){var l=o[i];if(l==="(")t+=1;else if(l===")")t-=1;else if(l==="[")s+=1;else if(l==="]")s-=1;else if(l===","&&!t&&!s){e.push(n.trim()),n="";continue}n+=l}return e.push(n.trim()),e}var A=o=>{if(Array.isArray(o.$)){let e={};return o.$.forEach(t=>g(e,A(t))),delete o.$,g(e,o),e}else return o};var X=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var w=["allowFullScreen","async","autoFocus","autoPlay","checked","compact","contentEditable","controls","declare","default","defer","disabled","formNoValidate","hidden","isMap","itemScope","loop","multiple","muted","noHref","noShade","noValidate","open","playsInline","readonly","required","reversed","scoped","selected","sortable","trueSpeed","typeMustMatch","wmode","autoCapitalize","translate","spellCheck","inert","download","noModule","paused","autoPictureInPicture"];var b={transform:["webkit","ms"],transition:["webkit","ms"],animation:["webkit"],userSelect:["webkit","ms"],flexDirection:["webkit","ms"],flexWrap:["webkit","ms"],justifyContent:["webkit","ms"],alignItems:["webkit","ms"],alignSelf:["webkit","ms"],order:["webkit","ms"],flexGrow:["webkit","ms"],flexShrink:["webkit","ms"],flexBasis:["webkit","ms"],columns:["webkit"],columnCount:["webkit"],columnGap:["webkit"],columnRule:["webkit"],columnWidth:["webkit"],boxSizing:["webkit"],appearance:["webkit","moz"],filter:["webkit"],backdropFilter:["webkit"],clipPath:["webkit"],mask:["webkit"],maskImage:["webkit"],textSizeAdjust:["webkit","ms"],hyphens:["webkit","ms"],writingMode:["webkit","ms"],gridTemplateColumns:["ms"],gridTemplateRows:["ms"],gridAutoColumns:["ms"],gridAutoRows:["ms"],gridColumn:["ms"],gridRow:["ms"],marginInlineStart:["webkit"],marginInlineEnd:["webkit"],paddingInlineStart:["webkit"],paddingInlineEnd:["webkit"],minInlineSize:["webkit"],maxInlineSize:["webkit"],minBlockSize:["webkit"],maxBlockSize:["webkit"],inlineSize:["webkit"],blockSize:["webkit"],tabSize:["moz"],overscrollBehavior:["webkit","ms"],touchAction:["ms"],resize:["webkit"],printColorAdjust:["webkit"],backgroundClip:["webkit"],boxDecorationBreak:["webkit"],overflowScrolling:["webkit"]};var O=["viewBox","preserveAspectRatio","gradientTransform","gradientUnits","spreadMethod","markerStart","markerMid","markerEnd","markerHeight","markerWidth","markerUnits","refX","refY","patternContentUnits","patternTransform","patternUnits","filterUnits","primitiveUnits","kernelUnitLength","clipPathUnits","maskContentUnits","maskUnits"];var M=class{constructor(e,t,s){this.parent=s,this.isBoolean=w.includes(e),O.includes(e)?this.name=e:this.name=C(e),this.value=void 0,this.set(t)}render(){if(!this.parent||!this.parent.domElement)return;let e=this.parent.domElement,t=["value"];this.isBoolean?this.value===!1||this.value==null?e.removeAttribute(this.name):e.setAttribute(this.name,this.value===!0?"":this.value):this.value==null?e.removeAttribute(this.name):t.includes(this.name)?e[this.name]=this.value:e.setAttribute(this.name,this.value)}set(e){if(e==null){this.value=null,this.render();return}if(typeof e=="string"&&/<\/?[a-z][\s\S]*>/i.test(e))this.value=B(e);else if(typeof e=="function"){let t=()=>{t&&(this.value=this.isBoolean?!!e():e(),this.render())};t.elementNode=this.parent,t.onSubscribe=s=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{s(),t=null})},this.value=this.isBoolean?!!e(t):e(t)}else this.value=this.isBoolean?!!e:e;this.render()}remove(){this.parent&&this.parent.attributes&&this.parent.attributes.remove(this.name),this._dispose()}_dispose(){this.value=null,this.parent=null}generateHTML(){let{name:e,value:t}=this;if(this.isBoolean)return t?`${e}`:"";{let s=Array.isArray(t)?JSON.stringify(t):t;return`${e}="${B(String(s))}"`}}};var x=class{constructor(e){this._notifier=new v;this.items={};this.parent=e}generateHTML(){if(!this.items)return"";let e=Object.values(this.items).map(t=>t.generateHTML()).join(" ");return e?` ${e}`:""}get(e){var t;if(this.items)return(t=this.items[e])==null?void 0:t.value}set(e,t){!this.items||!this.parent||(this.items[e]?(this.items[e].set(t),this.parent.domElement&&this._notifier.notify(e,this.items[e].value)):this.items[e]=new M(e,t,this.parent))}onChange(e,t){var s;if(this.has(e)&&((s=this.parent)!=null&&s.domElement)){let n=t;n.onSubscribe=i=>{var r;return(r=this.parent)==null?void 0:r.addHook("BeforeRemove",i)},this._notifier.addListener(e,n)}}has(e){return this.items?Object.prototype.hasOwnProperty.call(this.items,e):!1}remove(e){this.items&&(this.items[e]&&(this.items[e]._dispose(),delete this.items[e]),this.parent&&this.parent.domElement&&this.parent.domElement instanceof Element&&this.parent.domElement.removeAttribute(e))}_dispose(){if(this.items)for(let e in this.items)this.items[e]._dispose();this._notifier._dispose(),this.items=null,this.parent=null}toggle(e,t){if(!w.includes(e))throw Error(`${e} is not a boolean attribute`);t===!0?this.set(e,!0):t===!1?this.remove(e):this.has(e)?this.remove(e):this.set(e,!0)}addClass(e){if(!e||typeof e!="string")return;let t=(n,i)=>{let r=(n||"").split(" ").filter(l=>l);return!r.includes(i)&&r.push(e),r.join(" ")},s=this.get("class");typeof s=="function"?this.set("class",()=>t(s(),e)):this.set("class",t(s,e))}hasClass(e){return!e||typeof e!="string"?!1:(this.get("class")||"").split(" ").filter(n=>n).includes(e)}toggleClass(e){!e||typeof e!="string"||(this.hasClass(e)?this.removeClass(e):this.addClass(e))}removeClass(e){if(!e||typeof e!="string")return;let n=(this.get("class")||"").split(" ").filter(i=>i).filter(i=>i!==e);n.length>0?this.set("class",n.join(" ")):this.remove("class")}replaceClass(e,t){!e||!t||typeof e!="string"||typeof t!="string"||this.hasClass(e)&&(this.removeClass(e),this.addClass(t))}};var L=class{constructor(e,t){this.type="TextNode";this.parent=t,this.text=e===""?"\u200B":String(e)}_createDOMNode(){let e;if(K(this.text)){let t=document.createElement("template");t.innerHTML=this.text.trim(),e=t.content.firstChild||document.createTextNode("")}else e=document.createTextNode(this.text);return this.domText=e,e}_dispose(){this.domText=void 0,this.text=""}generateHTML(){return this.text==="\u200B"?"&#8203;":this.text}render(e){let t=this._createDOMNode();e.appendChild(t)}};var T=class{constructor(e){this.items=[];this.owner=e}_createNode(e,t=0){return typeof e=="object"&&e!==null?new m(e,this.owner,t):new L(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,n=e instanceof m?e.domElement:e.domText;if(n){let i=s.childNodes[t]||null;n!==i&&s.insertBefore(n,i)}}_swapDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,n=e instanceof m?e.domElement:e.domText,i=t instanceof m?t.domElement:t.domText;if(!n||!i)return;let r=n.nextSibling,l=i.nextSibling;s.insertBefore(n,l),s.insertBefore(i,r)}update(e,t=!0,s=!1){var r,l,h,c;let n=this.items.slice(),i=new Map;for(let a of n)a instanceof m&&a.key!==null&&a.key!==void 0&&i.set(a.key,a);!s&&this.owner.domElement&&((l=(r=this.owner._hooks)==null?void 0:r.BeforeUpdate)==null||l.call(r,this.owner,e));for(let a=0;a<e.length;a++){let f=e[a],u=typeof f=="object"&&f!==null?f._key:void 0;if(u!==void 0){let d=i.get(u);if(d){i.delete(u);let _=this.items.indexOf(d);if(_!==a&&_>=0){let H=d instanceof m&&!!d._portal;this.move(_,a,H?!1:t,!0)}d.parent=this.owner;continue}}this.insert(f,a,t,!0)}for(;this.items.length>e.length;)this.remove(this.items[this.items.length-1],t,!0);i.forEach(a=>this.remove(a,t,!0)),s||(c=(h=this.owner._hooks)==null?void 0:h.Update)==null||c.call(h,this.owner)}insert(e,t,s=!0,n=!1){var h,c;let i=this.items.length,r=typeof t!="number"||isNaN(t)||t<0||t>i?i:t,l=this._createNode(e,r);if(this.items.splice(r,0,l),l instanceof m){l._hooks.Insert&&l._hooks.Insert(l);let a=this.owner.domElement;if(s&&a)if(l._portal){let f=l._portal(this.owner.getRoot());f&&l.render(f)}else{let f=l._createDOMNode(),u=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,u);let d=a.getRootNode(),H=(d instanceof ShadowRoot?d:document.head).querySelector("#domphy-style");l.styles.render(H),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(k=>{if(k instanceof m&&k._portal){let D=k._portal(k.getRoot());D&&k.render(D)}else k.render(f)})}}else{let a=this.owner.domElement;if(s&&a){let f=l._createDOMNode(),u=(c=a.childNodes[r])!=null?c:null;a.insertBefore(f,u)}}return!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner),l}remove(e,t=!0,s=!1){let n=this.items.indexOf(e);if(!(n<0)){if(e instanceof m){let i=()=>{var l,h;let r=e.domElement;this.items.splice(n,1),t&&r&&r.remove(),(h=(l=e._hooks)==null?void 0:l.Remove)==null||h.call(l,e),e._dispose()};e._hooks&&e._hooks.BeforeRemove&&e.domElement?e._hooks.BeforeRemove(e,i):i()}else{let i=e.domText;this.items.splice(n,1),t&&i&&i.remove(),e._dispose()}!s&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}}clear(e=!0,t=!1){if(this.items.length===0)return;let s=this.items.slice();for(let n of s)this.remove(n,e,!0);!t&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}_dispose(){this.items=[]}swap(e,t,s=!0,n=!1){if(e<0||t<0||e>=this.items.length||t>=this.items.length||e===t)return;let i=this.items[e],r=this.items[t];this.items[e]=r,this.items[t]=i,s&&this._swapDomElement(i,r),!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}move(e,t,s=!0,n=!1){if(e<0||e>=this.items.length||t<0||t>=this.items.length||e===t)return;let i=this.items[e];this.items.splice(e,1),this.items.splice(t,0,i),s&&this._moveDomElement(i,t),!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}generateHTML(){let e="";for(let t of this.items)e+=t.generateHTML();return e}};var j=class{constructor(e,t,s){this.value="";this.name=e,this.cssName=C(e),this.parentRule=s,this.set(t)}_domUpdate(){if(!this.parentRule)return;let e=this.parentRule.domRule;if(e&&e.style){let t=e.style;t.setProperty(this.cssName,String(this.value)),b[this.name]&&b[this.name].forEach(s=>{t.setProperty(`-${s}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){if(typeof e=="function"){let t=()=>{t&&(this.value=e(t),this._domUpdate())};t.onSubscribe=s=>{var n;(n=this.parentRule.parentNode)==null||n.addHook("BeforeRemove",()=>{s(),t=null})},t.elementNode=this.parentRule.root,this.value=e(t)}else this.value=e;this._domUpdate()}remove(){if(this.parentRule){if(this.parentRule.domRule instanceof CSSStyleRule){let e=this.parentRule.domRule.style;e.removeProperty(this.cssName),b[this.name]&&b[this.name].forEach(t=>{e.removeProperty(`-${t}-${this.cssName}`)})}delete this.parentRule.styleBlock[this.name],this._dispose()}}cssText(){let e=`${this.cssName}: ${this.value}`;return b[this.name]&&b[this.name].forEach(t=>{e+=`; -${t}-${this.cssName}: ${this.value}`}),e}};var p=class o{constructor(e,t){this.domRule=null;this.styleBlock={};this.selectorText=e,this.styleList=new S(this),this.parent=t}_dispose(){if(this.styleBlock)for(let e of Object.values(this.styleBlock))e._dispose();this.styleList&&this.styleList._dispose(),this.styleBlock=null,this.styleList=null,this.domRule=null,this.parent=null}get root(){let e=this.parent;for(;e instanceof o;)e=e.parent;return e}get parentNode(){let e=this.parent;for(;e&&e instanceof o;)e=e.parent;return e}insertStyle(e,t){this.styleBlock&&(this.styleBlock[e]?this.styleBlock[e].set(t):this.styleBlock[e]=new j(e,t,this))}removeStyle(e){this.styleBlock&&this.styleBlock[e]&&this.styleBlock[e].remove()}cssText(){if(!this.styleBlock||!this.styleList)return"";let e=Object.values(this.styleBlock).map(s=>s.cssText()).join(";"),t=this.styleList.cssText();return`${this.selectorText} { ${e} ${t} } `}mount(e){!e||!this.styleList||(this.domRule=e,"cssRules"in e&&this.styleList.mount(e.cssRules))}remove(){if(this.domRule&&this.domRule.parentStyleSheet){let e=this.domRule.parentStyleSheet,t=e.cssRules;for(let s=0;s<t.length;s++)if(t[s]===this.domRule){e.deleteRule(s);break}}this._dispose()}render(e){if(!this.styleBlock||!this.styleList)return;let t=Object.values(this.styleBlock).map(s=>s.cssText()).join(";");try{if(this.selectorText.startsWith("@")){if(/^@(media|supports|container|layer)\b/.test(this.selectorText)){let s=e.insertRule(`${this.selectorText} {}`,e.cssRules.length),n=e.cssRules[s];"cssRules"in n&&(this.mount(n),this.styleList.render(n))}else if(this.selectorText.startsWith("@keyframes")||this.selectorText.startsWith("@font-face")){let s=this.cssText(),n=e.insertRule(s,e.cssRules.length),i=e.cssRules[n];this.mount(i)}}else{let s=`${this.selectorText} { ${t} }`,n=e.insertRule(s,e.cssRules.length),i=e.cssRules[n];i&&"selectorText"in i&&this.mount(i)}}catch(s){console.warn("Failed to insert rule:",this.selectorText,s)}}};var S=class{constructor(e){this.items=[];this.domStyle=null;this.parent=e}get parentNode(){let e=this.parent;for(;e&&e instanceof p;)e=e.parent;return e}addCSS(e,t=""){if(!this.items||!this.parent)return;let s={};function n(i,r){return i.startsWith("&")?`${r}${i.slice(1)}`:`${r} ${i}`}for(let i in e){let r=e[i],l=W(i);for(let h of l){let c=n(h,t);if(/^@(container|layer|supports|media)\b/.test(h)){if(typeof r=="object"&&r!=null){let a=new p(h,this.parent);a.styleList.addCSS(r,t),this.items.push(a)}}else if(h.startsWith("@keyframes")){let a=new p(h,this.parent);a.styleList.addCSS(r,""),this.items.push(a)}else if(h.startsWith("@font-face")){let a=new p(h,this.parent);for(let f in r)a.insertStyle(f,r[f]);this.items.push(a)}else if(typeof r=="object"&&r!=null){let a=new p(c,this.parent);this.items.push(a);for(let[f,u]of Object.entries(r))if(typeof u=="object"&&u!=null){let d=n(f,c);f.startsWith("&")?this.addCSS(u,d):a.styleList.insertRule(d).styleList.addCSS(u,d)}else a.insertStyle(f,u)}else s[h]=r}}if(Object.keys(s).length){let i=new p(t,this.parent);for(let r in s)i.insertStyle(r,s[r]);this.items.push(i)}}cssText(){return this.items?this.items.map(e=>e.cssText()).join(""):""}insertRule(e){if(!this.items||!this.parent)return null;let t=this.items.find(s=>s.selectorText===e);return t||(t=new p(e,this.parent),this.items.push(t)),t}mount(e){if(!this.items)return;if(!e)throw Error("Require domRuleList argument");let t=0,s=n=>n.replace("(odd)","(2n+1)").replace("(even)","(2n)");this.items.forEach((n,i)=>{let r=i-t,l=e[r];l&&(n.selectorText.startsWith("@")&&l instanceof CSSKeyframesRule||"keyText"in l?n.mount(l):"selectorText"in l?l.selectorText!==s(n.selectorText)?t+=1:n.mount(l):"cssRules"in l&&n.mount(l))})}render(e){e instanceof HTMLStyleElement?(this.domStyle=e,this.items.forEach(t=>t.render(e.sheet))):e instanceof CSSGroupingRule&&this.items.forEach(t=>t.render(e))}_dispose(){if(this.items)for(let e=0;e<this.items.length;e++)this.items[e]._dispose();this.items=[],this.parent=null,this.domStyle=null}};var m=class o{constructor(e,t=null,s=0){this.type="ElementNode";this.parent=null;this.children=new T(this);this.styles=new S(this);this.attributes=new x(this);this.domElement=null;this._hooks={};this._events=null;this._context={};this._metadata={};this.key=null;var l,h;e=y(e),P(e),e.style=e.style||{},this.parent=t,this.tagName=V(e),e=A(e),this.key=(l=e._key)!=null?l:null,this._context=e._context||{},this._metadata=e._metadata||{};let n=`${(h=this.parent)==null?void 0:h.getPath()}.${s}`,i=JSON.stringify(e.style||{},(c,a)=>typeof a=="function"?n:a);this.nodeId=N(n+i),this.attributes.addClass(`${this.tagName}_${this.nodeId}`),e._onSchedule&&e._onSchedule(this,e),this.merge(e);let r=e[this.tagName];if(r!=null&&r!=null)if(typeof r=="function"){let c=()=>{let a=r(c);this.children.update(Array.isArray(a)?a:[a])};c.elementNode=this,c.onSubscribe=a=>this.addHook("BeforeRemove",()=>{a(),c=null}),c&&c()}else this.children.update(Array.isArray(r)?r:[r]);this._hooks.Init&&this._hooks.Init(this)}_createDOMNode(){let s=["svg","circle","path","rect","ellipse","line","polyline","polygon","g","defs","use","symbol","linearGradient","radialGradient","stop","clipPath","mask","filter","text","tspan","textPath","image","pattern","marker","animate","animateTransform","animateMotion","feGaussianBlur","feComposite","feColorMatrix","feMerge","feMergeNode","feOffset","feFlood","feBlend","foreignObject"].includes(this.tagName)?document.createElementNS("http://www.w3.org/2000/svg",this.tagName):document.createElement(this.tagName);if(this.domElement=s,this._events)for(let n in this._events){let i=n,r=this._events[i],l=h=>r(h,this);s.addEventListener(i,l),this.addHook("BeforeRemove",h=>{h.domElement.removeEventListener(i,l),l=null})}return this.attributes&&Object.values(this.attributes.items).forEach(n=>n.render()),s}_dispose(){this.children&&this.children._dispose(),this.styles&&(this.styles.items.forEach(e=>e.remove()),this.styles._dispose()),this.attributes&&this.attributes._dispose(),this.domElement=null,this._hooks={},this._events=null,this._context={},this._metadata={},this.parent=null}get pathId(){return N(this.getPath())}merge(e){g(this._context,e._context),g(this._metadata,e._metadata);let t=Object.keys(e);for(let s=0;s<t.length;s++){let n=t[s],i=e[n];["$","_onSchedule","_key","_context","_metadata","style",this.tagName].includes(n)||(["_onInit","_onInsert","_onMount","_onBeforeUpdate","_onUpdate","_onBeforeRemove","_onRemove"].includes(n)?this.addHook(n.substring(3),i):n.startsWith("on")?this.addEvent(n.substring(2).toLowerCase(),i):n=="_portal"?this._portal=i:n=="class"&&typeof i=="string"?this.attributes.addClass(i):this.attributes.set(n,i))}e.style&&this.styles.addCSS(e.style||{},`.${`${this.tagName}_${this.nodeId}`}`)}getPath(){let e=[],t=this;for(;t&&t.parent;){let s=t.parent,n=s.children.items.indexOf(t);e.push(n),t=s}return e.reverse().join(".")}addEvent(e,t){this._events=this._events||{};let s=this._events[e];typeof s=="function"?this._events[e]=(n,i)=>{s(n,i),t(n,i)}:this._events[e]=t}addHook(e,t){let s=this._hooks[e];typeof s=="function"?this._hooks[e]=((...n)=>{s(...n),t(...n)}):this._hooks[e]=t}getRoot(){let e=this;for(;e&&e instanceof o&&e.parent;)e=e.parent;return e}getContext(e){let t=this;for(;t&&(!t._context||!Object.prototype.hasOwnProperty.call(t._context,e));)t=t.parent;return t&&t._context?t._context[e]:void 0}setContext(e,t){this._context=this._context||{},this._context[e]=t}getMetadata(e){return this._metadata?this._metadata[e]:void 0}setMetadata(e,t){this._metadata=this._metadata||{},this._metadata[e]=t}generateCSS(){if(!this.styles||!this.children)return"";let e=this.styles.cssText();return e+=this.children.items.map(t=>t instanceof o?t.generateCSS():"").join(""),e}generateHTML(){if(!this.children||!this.attributes)return"";let e=this.children.generateHTML(),t=this.attributes.generateHTML();return`<${this.tagName}${t}>${e}</${this.tagName}>`}mount(e,t){if(!e)throw new Error("Missing dom node on bind");if(this.domElement=e,this._events)for(let s in this._events){let n=s,i=this._events[n],r=l=>i(l,this);e.addEventListener(n,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(n,r),r=null})}this.children&&this.children.items.forEach((s,n)=>{let i=e.childNodes[n];i instanceof Node&&s instanceof o&&s.mount(i,t)}),this._hooks.Mount&&this._hooks.Mount(this)}render(e,t=null){let s=this._createDOMNode();e.appendChild(s),this._hooks.Mount&&this._hooks.Mount(this),t||(t=this.getRoot().styles.domStyle);let n=e.getRootNode(),i=n instanceof ShadowRoot?n:document.head;return t||(t=i.querySelector("#domphy-style")),t||(t=document.createElement("style"),t.id="domphy-style",i.appendChild(t)),this.styles.render(t),this.children.items.forEach(r=>{if(r instanceof o&&r._portal){let l=r._portal(this.getRoot());l&&r.render(l)}else r.render(s)}),s}remove(){var e;this.parent?this.parent.children.remove(this):((e=this.domElement)==null||e.remove(),this._dispose())}};globalThis.Domphy={core:$};})();
2
+ //# sourceMappingURL=core.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/types/EventProperties.ts","../src/constants/HtmlTags.ts","../src/classes/Notifier.ts","../src/classes/State.ts","../src/utils.ts","../src/helpers.ts","../src/constants/VoidTags.ts","../src/constants/BooleanAttributes.ts","../src/constants/PrefixCSS.ts","../src/constants/CamelAttributes.ts","../src/classes/ElementAttribute.ts","../src/classes/AttributeList.ts","../src/classes/TextNode.ts","../src/classes/ElementList.ts","../src/classes/StyleProperty.ts","../src/classes/StyleRule.ts","../src/classes/StyleList.ts","../src/classes/ElementNode.ts","../src/global.ts"],"sourcesContent":["export * from \"./classes/ElementNode.js\";\nexport * from \"./classes/ElementList.js\";\nexport * from \"./classes/AttributeList.js\";\nexport * from \"./classes/Notifier.js\";\nexport * from \"./classes/State.js\";\nexport * from \"./types.js\";\nexport * from \"./constants.js\";\nexport * from \"./utils.js\";\n","export const EventProperties = [\n \"onAbort\",\n \"onAuxClick\",\n \"onBeforeMatch\",\n \"onBeforeToggle\",\n \"onBlur\",\n \"onCancel\",\n \"onCanPlay\",\n \"onCanPlayThrough\",\n \"onChange\",\n \"onClick\",\n \"onClose\",\n \"onContextLost\",\n \"onContextMenu\",\n \"onContextRestored\",\n \"onCopy\",\n \"onCueChange\",\n \"onCut\",\n \"onDblClick\",\n \"onDrag\",\n \"onDragEnd\",\n \"onDragEnter\",\n \"onDragLeave\",\n \"onDragOver\",\n \"onDragStart\",\n \"onDrop\",\n \"onDurationChange\",\n \"onEmptied\",\n \"onEnded\",\n \"onError\",\n \"onFocus\",\n \"onFormData\",\n \"onInput\",\n \"onInvalid\",\n \"onKeyDown\",\n \"onKeyPress\",\n \"onKeyUp\",\n \"onLoad\",\n \"onLoadedData\",\n \"onLoadedMetadata\",\n \"onLoadStart\",\n \"onMouseDown\",\n \"onMouseEnter\",\n \"onMouseLeave\",\n \"onMouseMove\",\n \"onMouseOut\",\n \"onMouseOver\",\n \"onMouseUp\",\n \"onPaste\",\n \"onPause\",\n \"onPlay\",\n \"onPlaying\",\n \"onProgress\",\n \"onRateChange\",\n \"onReset\",\n \"onResize\",\n \"onScroll\",\n \"onScrollEnd\",\n \"onSecurityPolicyViolation\",\n \"onSeeked\",\n \"onSeeking\",\n \"onSelect\",\n \"onSlotChange\",\n \"onStalled\",\n \"onSubmit\",\n \"onSuspend\",\n \"onTimeUpdate\",\n \"onToggle\",\n \"onVolumeChange\",\n \"onWaiting\",\n \"onWheel\",\n \"onTouchStart\",\n \"onTouchMove\",\n \"onTouchEnd\",\n \"onTouchCancel\",\n \"onPointerDown\",\n \"onPointerMove\",\n \"onPointerUp\",\n \"onPointerCancel\",\n \"onPointerEnter\",\n \"onPointerLeave\",\n \"onPointerOver\",\n \"onPointerOut\",\n \"onGotPointerCapture\",\n \"onLostPointerCapture\",\n \"onCompositionStart\",\n \"onCompositionUpdate\",\n \"onCompositionEnd\",\n \"onTransitionEnd\",\n \"onTransitionStart\",\n \"onAnimationStart\",\n \"onAnimationEnd\",\n \"onAnimationIteration\",\n \"onFullscreenChange\",\n \"onFullscreenError\",\n \"onFocusIn\",\n \"onFocusOut\",\n] as const\n\nexport const eventNameMap = EventProperties.reduce((acc, ev) => {\n const key = ev.slice(2).toLowerCase() as keyof HTMLElementEventMap\n acc[key] = ev;\n return acc;\n}, {} as Partial<Record<keyof HTMLElementEventMap, (typeof EventProperties)[number]>>);\n","export const HtmlTags = [\n \"a\",\n \"abbr\",\n \"address\",\n \"article\",\n \"aside\",\n \"audio\",\n \"b\",\n \"base\",\n \"blockquote\",\n \"br\",\n \"button\",\n \"canvas\",\n \"caption\",\n \"cite\",\n \"code\",\n \"col\",\n \"colgroup\",\n \"data\",\n \"datalist\",\n \"dd\",\n \"del\",\n \"details\",\n \"dfn\",\n \"dialog\",\n \"div\",\n \"dl\",\n \"dt\",\n \"em\",\n \"fieldset\",\n \"figcaption\",\n \"figure\",\n \"footer\",\n \"form\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"header\",\n \"hgroup\",\n \"i\",\n \"iframe\",\n \"img\",\n \"input\",\n \"ins\",\n \"kbd\",\n \"label\",\n \"legend\",\n \"li\",\n \"main\",\n \"map\",\n \"mark\",\n \"meta\",\n \"meter\",\n \"nav\",\n \"noscript\",\n \"object\",\n \"ol\",\n \"optgroup\",\n \"option\",\n \"output\",\n \"p\",\n \"param\",\n \"picture\",\n \"pre\",\n \"progress\",\n \"q\",\n \"rp\",\n \"rt\",\n \"ruby\",\n \"s\",\n \"samp\",\n \"section\",\n \"select\",\n \"slot\",\n \"small\",\n \"source\",\n \"span\",\n \"strong\",\n \"sub\",\n \"summary\",\n \"sup\",\n \"table\",\n \"tbody\",\n \"td\",\n \"template\",\n \"textarea\",\n \"tfoot\",\n \"th\",\n \"thead\",\n \"time\",\n \"title\",\n \"tr\",\n \"track\",\n \"u\",\n \"ul\",\n \"var\",\n \"video\",\n \"wbr\",\n \"bdi\",\n \"bdo\",\n \"math\",\n \"menu\",\n \"search\",\n \"area\",\n \"embed\",\n \"hr\",\n \"animate\",\n \"animateMotion\",\n \"animateTransform\",\n \"circle\",\n \"clipPath\",\n \"cursor\",\n \"defs\",\n \"desc\",\n \"ellipse\",\n \"feBlend\",\n \"feColorMatrix\",\n \"feComponentTransfer\",\n \"feComposite\",\n \"feConvolveMatrix\",\n \"feDiffuseLighting\",\n \"feDisplacementMap\",\n \"feDistantLight\",\n \"feDropShadow\",\n \"feFlood\",\n \"feFuncA\",\n \"feFuncB\",\n \"feFuncG\",\n \"feFuncR\",\n \"feGaussianBlur\",\n \"feImage\",\n \"feMerge\",\n \"feMergeNode\",\n \"feMorphology\",\n \"feOffset\",\n \"fePointLight\",\n \"feSpecularLighting\",\n \"feSpotLight\",\n \"feTile\",\n \"feTurbulence\",\n \"filter\",\n \"foreignObject\",\n \"g\",\n \"image\",\n \"line\",\n \"linearGradient\",\n \"marker\",\n \"mask\",\n \"metadata\",\n \"mpath\",\n \"path\",\n \"pattern\",\n \"polygon\",\n \"polyline\",\n \"prefetch\",\n \"radialGradient\",\n \"rect\",\n \"set\",\n \"solidColor\",\n \"stop\",\n \"svg\",\n \"switch\",\n \"symbol\",\n \"tbreak\",\n \"text\",\n \"textPath\",\n \"tspan\",\n \"use\",\n \"view\",\n];","import { Handler } from \"../types.js\"\r\n\r\nexport class Notifier {\r\n private _listeners: Record<string, Set<Handler>> | null = {};\r\n\r\n _dispose(): void {\r\n if (this._listeners) {\r\n for (const event in this._listeners) {\r\n this._listeners[event].clear();\r\n }\r\n }\r\n\r\n this._listeners = null;\r\n }\r\n addListener(event: string, listener: Handler): () => void {\r\n if (!this._listeners) return () => { };\r\n\r\n if (typeof event !== \"string\" || typeof listener !== \"function\") {\r\n throw new Error(\"Event name must be a string, listener must be a function\");\r\n }\r\n\r\n if (!this._listeners[event]) {\r\n this._listeners[event] = new Set();\r\n }\r\n\r\n const release = () => this.removeListener(event, listener);\r\n\r\n if (!this._listeners[event].has(listener)) {\r\n this._listeners[event].add(listener);\r\n if (typeof listener.onSubscribe === \"function\") {\r\n listener.onSubscribe(release);\r\n }\r\n }\r\n\r\n return release;\r\n }\r\n\r\n removeListener(event: string, listener: Handler): void {\r\n if (!this._listeners) return;\r\n\r\n const listeners = this._listeners[event];\r\n if (listeners && listeners.has(listener)) {\r\n listeners.delete(listener);\r\n if (listeners.size === 0) {\r\n delete this._listeners[event];\r\n }\r\n }\r\n }\r\n\r\n notify(event: string, ...args: unknown[]): void {\r\n if (!this._listeners) return;\r\n const listeners = this._listeners[event];\r\n if (listeners) {\r\n for (const listener of [...listeners]) {\r\n try {\r\n listener(...args);\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n }\r\n }\r\n }\r\n}","import { Notifier } from \"./Notifier.js\";\nimport { Handler } from \"../types.js\"\n\nexport type ValueListener<T> = ((_value: T) => void) & Handler\nexport type ValueOrState<T> = T | State<T>\nexport class State<T> {\n private _value: T;\n readonly initialValue: T;\n private _notifier: Notifier | null = new Notifier();\n\n constructor(initialValue: T) {\n this.initialValue = initialValue;\n this._value = initialValue;\n }\n\n get(listener?: ValueListener<T>): T {\n if (listener) this.onChange(listener);\n return this._value;\n }\n\n set(newValue: T): void {\n if (!this._notifier) return;\n this._value = newValue;\n this._notifier.notify(\"change\", newValue);\n }\n\n reset(): void {\n this.set(this.initialValue);\n }\n\n onChange(listener: ValueListener<T>): () => void {\n if (!this._notifier) return () => { };\n return this._notifier.addListener(\"change\", listener);\n }\n\n _dispose(): void {\n if (this._notifier) {\n this._notifier._dispose();\n this._notifier = null;\n }\n }\n}","import { DomphyElement, HookMap, EventName, Handler } from \"./types.js\";\r\nimport { State } from \"./classes/State.js\"\r\nimport { deepClone, addEvent, addHook } from \"./helpers.js\"\r\n\r\nexport function merge(source: Record<string, any> = {}, target: Record<string, any> = {}): Record<string, any> {\r\n const comma = [\"animation\", \"transition\", \"boxShadow\", \"textShadow\", \"background\", \"fontFamily\"]\r\n const space = [\"class\", \"rel\", \"transform\", \"acceptCharset\", \"sandbox\"]\r\n const adjacent = [\"content\"]\r\n if (Object.prototype.toString.call(target) === \"[object Object]\" && Object.getPrototypeOf(target) === Object.prototype) { // plainjs not class instance\r\n target = deepClone(target)\r\n }\r\n\r\n for (const key in target) {\r\n\r\n const value = target[key];\r\n if (value === undefined || value === null || value === \"\") continue;\r\n\r\n if (typeof value === \"object\" && !Array.isArray(value)) {\r\n if (typeof source[key] === \"object\") {\r\n source[key] = merge(source[key], value);\r\n } else {\r\n source[key] = value;\r\n }\r\n\r\n } else {\r\n if (comma.includes(key)) {\r\n if (typeof source[key] === \"function\" || typeof value === \"function\") {\r\n let old = source[key]\r\n source[key] = (listener: Handler) => {\r\n let val1 = typeof old === \"function\" ? old(listener) : old\r\n let val2 = typeof value === \"function\" ? value(listener) : value\r\n return [val1, val2].filter(e => e).join(\", \")\r\n }\r\n } else {\r\n source[key] = [source[key], value].filter(e => e).join(\", \")\r\n }\r\n\r\n } else if (adjacent.includes(key)) {\r\n if (typeof source[key] === \"function\" || typeof value === \"function\") {\r\n let old = source[key]\r\n source[key] = (listener: Handler) => {\r\n let val1 = typeof old === \"function\" ? old(listener) : old\r\n let val2 = typeof value === \"function\" ? value(listener) : value\r\n return [val1, val2].filter(e => e).join(\"\")\r\n }\r\n } else {\r\n source[key] = [source[key], value].filter(e => e).join(\"\")\r\n }\r\n } else if (space.includes(key)) {\r\n if (typeof source[key] === \"function\" || typeof value === \"function\") {\r\n let old = source[key]\r\n source[key] = (listener: Handler) => {\r\n let val1 = typeof old === \"function\" ? old(listener) : old\r\n let val2 = typeof value === \"function\" ? value(listener) : value\r\n return [val1, val2].filter(e => e).join(\" \")\r\n }\r\n } else {\r\n source[key] = [source[key], value].filter(e => e).join(\" \")\r\n }\r\n } else if (key.startsWith(\"on\")) {\r\n let name = key.replace(\"on\", \"\").toLowerCase() as EventName\r\n addEvent(source as DomphyElement, name, value)\r\n } else if (key.startsWith(\"_on\")) {\r\n let name = key.replace(\"_on\", \"\") as keyof HookMap\r\n addHook(source as DomphyElement, name, value)\r\n } else {\r\n source[key] = value;\r\n }\r\n }\r\n }\r\n return source;\r\n}\r\n\r\nexport function toState<T>(val: T | State<T>): State<T> {\r\n return val instanceof State ? val : new State<T>(val);\r\n}\r\n\r\nexport function hashString(str: string = \"\"): string {\r\n let hash = 0x811c9dc5; // FNV-1a 32-bit offset basis\r\n for (let i = 0; i < str.length; i++) {\r\n hash ^= str.charCodeAt(i);\r\n hash = (hash * 0x01000193) >>> 0; // FNV prime, keep 32-bit unsigned\r\n }\r\n return String.fromCharCode(97 + (hash % 26)) + hash.toString(16);\r\n}","import { DomphyElement, PartialElement, HookMap, EventName, Handler, TagName } from \"./types.js\";\r\nimport { ElementNode } from \"./classes/ElementNode.js\"\r\nimport { State } from \"./classes/State.js\"\r\nimport { eventNameMap } from \"./types/EventProperties.js\"\r\nimport { HtmlTags } from \"./constants/HtmlTags.js\"\r\nimport {merge} from \"./utils.js\"\r\n\r\nexport function addHook<K extends keyof HookMap>(partial: PartialElement, hookName: K, handler: HookMap[K]): void {\r\n const hookProperty = `_on${hookName}` as keyof PartialElement;\r\n let current = partial[hookProperty];\r\n\r\n if (typeof current === \"function\") {\r\n (partial as any)[hookProperty] = (...args: any[]) => {\r\n (current as Function)(...args);\r\n (handler as Function)(...args);\r\n };\r\n } else {\r\n (partial as any)[hookProperty] = handler;\r\n }\r\n}\r\n\r\nexport function addEvent<K extends keyof HTMLElementEventMap>(\r\n attributes: PartialElement,\r\n eventName: K,\r\n handler: (event: HTMLElementEventMap[K], node: ElementNode) => void\r\n): void {\r\n const eventProperty = eventNameMap[eventName];\r\n if (!eventProperty) {\r\n throw Error(`invalid event name \"${eventName}\"`);\r\n }\r\n const current = (attributes as any)[eventProperty]\r\n\r\n if (typeof current == \"function\") {\r\n (attributes as any)[eventProperty] = (event: HTMLElementEventMap[K], node: ElementNode) => {\r\n current(event, node)\r\n handler(event, node);\r\n };\r\n } else {\r\n (attributes as any)[eventProperty] = handler\r\n }\r\n}\r\n\r\nexport function deepClone(value: any, seen = new WeakMap()): any {\r\n if (value === null || typeof value !== \"object\") return value;\r\n if (typeof value === \"function\") return value;\r\n if (seen.has(value)) return seen.get(value);\r\n\r\n const proto = Object.getPrototypeOf(value);\r\n if (proto !== Object.prototype && !Array.isArray(value)) return value; // ignore class instance\r\n\r\n let clone: any;\r\n\r\n if (Array.isArray(value)) {\r\n clone = [];\r\n seen.set(value, clone);\r\n for (const v of value) clone.push(deepClone(v, seen));\r\n return clone;\r\n }\r\n\r\n if (value instanceof Date) return new Date(value);\r\n if (value instanceof RegExp) return new RegExp(value);\r\n if (value instanceof Map) {\r\n clone = new Map();\r\n seen.set(value, clone);\r\n for (const [k, v] of value) clone.set(deepClone(k, seen), deepClone(v, seen));\r\n return clone;\r\n }\r\n if (value instanceof Set) {\r\n clone = new Set();\r\n seen.set(value, clone);\r\n for (const v of value) clone.add(deepClone(v, seen));\r\n return clone;\r\n }\r\n if (ArrayBuffer.isView(value)) {\r\n return new (value as any).constructor(value);\r\n }\r\n if (value instanceof ArrayBuffer) {\r\n return value.slice(0);\r\n }\r\n\r\n clone = Object.create(proto);\r\n seen.set(value, clone);\r\n\r\n for (const key of Reflect.ownKeys(value)) {\r\n clone[key] = deepClone(value[key], seen);\r\n }\r\n\r\n return clone;\r\n}\r\n\r\nexport function validate(element: DomphyElement | PartialElement, asPartial = false): boolean {\r\n if (Object.prototype.toString.call(element) !== \"[object Object]\") {\r\n throw Error(`typeof ${element} is invalid DomphyElement`);\r\n }\r\n let keys = Object.keys(element);\r\n for (let i = 0; i < keys.length; i++) {\r\n let key = keys[i];\r\n let val = element[key as keyof typeof element]\r\n if (i == 0 && !HtmlTags.includes(key) && !key.includes(\"-\") && !asPartial) { // web-component\r\n throw Error(`key ${key} is not valid HTML tag name`);\r\n } else if (key == \"style\" && val && Object.prototype.toString.call(val) !== \"[object Object]\") {\r\n throw Error(`\"style\" must be a object`);\r\n } else if (key == \"$\") {\r\n element.$!.forEach(v => validate(v as PartialElement, true))\r\n } else if (key.startsWith(\"_on\") && typeof val != \"function\") {\r\n throw Error(`hook ${key} value \"${val}\" must be a function `)\r\n } else if (key.startsWith(\"on\") && typeof val != \"function\") {\r\n throw Error(`event ${key} value \"${val}\" must be a function `);\r\n } else if (key == \"_portal\" && typeof val !== \"function\") {\r\n throw Error(`\"_portal\" must be a function return HTMLElement`);\r\n } else if (key == \"_context\" && Object.prototype.toString.call(val) !== \"[object Object]\") {\r\n throw Error(`\"_context\" must be a object`);\r\n } else if (key == \"_metadata\" && Object.prototype.toString.call(val) !== \"[object Object]\") {\r\n throw Error(`\"_metadata\" must be a object`);\r\n } else if (key == \"_key\" && (typeof val !== \"string\" && typeof val !== \"number\")) {\r\n throw Error(`\"_key\" must be a string or number`);\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nexport function isValid(element: DomphyElement): boolean {\r\n\r\n if (Array.isArray(element)) return false;\r\n if (!element || typeof element !== \"object\") return false;\r\n\r\n let keys = Object.keys(element);\r\n for (let i = 0; i < keys.length; i++) {\r\n let key = keys[i];\r\n let val = element[key as keyof typeof element];\r\n if (i == 0 && !HtmlTags.includes(key)) return false\r\n if (key === \"style\" && (val == null || typeof val !== \"object\" || Array.isArray(val))) return false;\r\n if (key.startsWith(\"_on\") && typeof val !== \"function\") return false;\r\n if (key.startsWith(\"on\") && typeof val !== \"function\") return false;\r\n if (key === \"_portalChildren\" && !Array.isArray(val)) return false;\r\n if ((key === \"_context\" || key === \"_metadata\") && (val == null || typeof val !== \"object\" || Array.isArray(val))) return false;\r\n }\r\n return true;\r\n}\r\n\r\nexport function isHTML(str: string): boolean {\r\n return /<([a-z][\\w-]*)(\\s[^>]*)?>.*<\\/\\1>|<([a-z][\\w-]*)(\\s[^>]*)?\\/>/i.test(str.trim());\r\n}\r\n\r\nexport function escapeHTML(str: string): string {\r\n return str\r\n .replace(/&/g, \"&amp;\")\r\n .replace(/</g, \"&lt;\")\r\n .replace(/>/g, \"&gt;\")\r\n .replace(/\"/g, \"&quot;\")\r\n .replace(/'/g, \"&#39;\");\r\n}\r\n\r\nexport function addClass(element: PartialElement, className: string): void {\r\n\r\n if (typeof element.class == \"function\") {\r\n let reactive = element.class\r\n element.class = (listener) => String(reactive(listener)) + \" \" + className\r\n } else {\r\n let current = element.class || \"\"\r\n let split = String(current).split(\" \")\r\n split.push(className)\r\n element.class = split.filter(e => e).join(\" \")\r\n }\r\n\r\n}\r\n\r\nexport function removeClass(element: PartialElement, className: string): void {\r\n\r\n if (typeof element.class == \"function\") {\r\n let reactive = element.class\r\n element.class = (listener) => {\r\n let split = String(reactive(listener)).split(\" \")\r\n return split.filter(e => e != className).join(\" \")\r\n }\r\n } else {\r\n let split = String(element.class).split(\" \")\r\n element.class ||= \"\"\r\n element.class = split.filter(e => e != className).join(\" \")\r\n }\r\n\r\n}\r\n\r\nexport function toggleClass(element: PartialElement, className: string): void {\r\n\r\n if (typeof element.class == \"function\") {\r\n let reactive = element.class\r\n element.class = (listener) => {\r\n let split = String(reactive(listener)).split(\" \")\r\n return split.includes(className) ? split.filter(e => e != className).join(\" \") : split.concat([className]).join(\" \")\r\n }\r\n } else {\r\n let split = String(element.class).split(\" \")\r\n element.class ||= \"\"\r\n element.class = split.includes(className) ? split.filter(e => e != className).join(\" \") : split.concat([className]).join(\" \")\r\n }\r\n\r\n}\r\n\r\nexport function getTagName(element: DomphyElement): TagName | undefined {\r\n return Object.keys(element).find(e => HtmlTags.includes(e)) as TagName | undefined\r\n}\r\n\r\n\r\nexport function camelToKebab(str: string): string {\r\n return str.replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\r\n}\r\n\r\nexport function selectorSplitter(selectors: string) {\r\n if (selectors.indexOf('@') === 0) {\r\n return [selectors];\r\n }\r\n var splitted = [];\r\n var parens = 0;\r\n var angulars = 0;\r\n var soFar = '';\r\n for (var i = 0, len = selectors.length; i < len; i++) {\r\n var char = selectors[i];\r\n if (char === '(') {\r\n parens += 1;\r\n } else if (char === ')') {\r\n parens -= 1;\r\n } else if (char === '[') {\r\n angulars += 1;\r\n } else if (char === ']') {\r\n angulars -= 1;\r\n } else if (char === ',') {\r\n if (!parens && !angulars) {\r\n splitted.push(soFar.trim());\r\n soFar = '';\r\n continue;\r\n }\r\n }\r\n soFar += char;\r\n }\r\n splitted.push(soFar.trim());\r\n return splitted;\r\n};\r\n\r\nexport const mergePartial = (partial: PartialElement | DomphyElement): typeof partial => {\r\n\r\n if (Array.isArray(partial.$)) {\r\n let part: typeof partial = {}\r\n partial.$.forEach(p => merge(part, mergePartial(p)))\r\n delete partial.$\r\n merge(part, partial) // native win\r\n\r\n return part\r\n } else {\r\n return partial\r\n }\r\n}","export const VoidTags = [\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"source\",\n \"track\",\n \"wbr\",\n] as const;\n\nexport type VoidTagName = (typeof VoidTags)[number];\n\n","export const BooleanAttributes = [\n \"allowFullScreen\",\n \"async\",\n \"autoFocus\",\n \"autoPlay\",\n \"checked\",\n \"compact\",\n \"contentEditable\",\n \"controls\",\n \"declare\",\n \"default\",\n \"defer\",\n \"disabled\",\n \"formNoValidate\",\n \"hidden\",\n \"isMap\",\n \"itemScope\",\n \"loop\",\n \"multiple\",\n \"muted\",\n \"noHref\",\n \"noShade\",\n \"noValidate\",\n \"open\",\n \"playsInline\",\n \"readonly\",\n \"required\",\n \"reversed\",\n \"scoped\",\n \"selected\",\n \"sortable\",\n \"trueSpeed\",\n \"typeMustMatch\",\n \"wmode\",\n \"autoCapitalize\",\n \"translate\",\n \"spellCheck\",\n \"inert\",\n \"download\",\n \"noModule\",\n \"paused\",\n \"autoPictureInPicture\",\n] as const;","//browserslist query \"> 0.1%, not dead\"\nexport const PrefixCSS: Record<string, string[]> = {\n transform: [\"webkit\", \"ms\"],\n transition: [\"webkit\", \"ms\"],\n animation: [\"webkit\"],\n userSelect: [\"webkit\", \"ms\"],\n flexDirection: [\"webkit\", \"ms\"],\n flexWrap: [\"webkit\", \"ms\"],\n justifyContent: [\"webkit\", \"ms\"],\n alignItems: [\"webkit\", \"ms\"],\n alignSelf: [\"webkit\", \"ms\"],\n order: [\"webkit\", \"ms\"],\n flexGrow: [\"webkit\", \"ms\"],\n flexShrink: [\"webkit\", \"ms\"],\n flexBasis: [\"webkit\", \"ms\"],\n columns: [\"webkit\"],\n columnCount: [\"webkit\"],\n columnGap: [\"webkit\"],\n columnRule: [\"webkit\"],\n columnWidth: [\"webkit\"],\n boxSizing: [\"webkit\"],\n appearance: [\"webkit\", \"moz\"],\n filter: [\"webkit\"],\n backdropFilter: [\"webkit\"],\n clipPath: [\"webkit\"],\n mask: [\"webkit\"],\n maskImage: [\"webkit\"],\n textSizeAdjust: [\"webkit\", \"ms\"],\n hyphens: [\"webkit\", \"ms\"],\n writingMode: [\"webkit\", \"ms\"],\n gridTemplateColumns: [\"ms\"],\n gridTemplateRows: [\"ms\"],\n gridAutoColumns: [\"ms\"],\n gridAutoRows: [\"ms\"],\n gridColumn: [\"ms\"],\n gridRow: [\"ms\"],\n marginInlineStart: [\"webkit\"],\n marginInlineEnd: [\"webkit\"],\n paddingInlineStart: [\"webkit\"],\n paddingInlineEnd: [\"webkit\"],\n minInlineSize: [\"webkit\"],\n maxInlineSize: [\"webkit\"],\n minBlockSize: [\"webkit\"],\n maxBlockSize: [\"webkit\"],\n inlineSize: [\"webkit\"],\n blockSize: [\"webkit\"],\n tabSize: [\"moz\"],\n overscrollBehavior: [\"webkit\", \"ms\"],\n touchAction: [\"ms\"],\n resize: [\"webkit\"],\n printColorAdjust: [\"webkit\"],\n backgroundClip: [\"webkit\"],\n boxDecorationBreak: [\"webkit\"],\n overflowScrolling: [\"webkit\"],\n};\n","export const CamelAttributes: string[] = [\r\n \"viewBox\",\r\n \"preserveAspectRatio\",\r\n \"gradientTransform\",\r\n \"gradientUnits\",\r\n \"spreadMethod\",\r\n \"markerStart\",\r\n \"markerMid\",\r\n \"markerEnd\",\r\n \"markerHeight\",\r\n \"markerWidth\",\r\n \"markerUnits\",\r\n \"refX\",\r\n \"refY\",\r\n \"patternContentUnits\",\r\n \"patternTransform\",\r\n \"patternUnits\",\r\n \"filterUnits\",\r\n \"primitiveUnits\",\r\n \"kernelUnitLength\",\r\n \"clipPathUnits\",\r\n \"maskContentUnits\",\r\n \"maskUnits\"\r\n] as const\r\n","import { escapeHTML, camelToKebab } from \"../helpers.js\";\nimport { BooleanAttributes, CamelAttributes } from \"../constants.js\";\nimport type { ElementNode } from \"./ElementNode.js\"\nimport { type AttributeValue } from \"../types.js\"\n\nexport class ElementAttribute {\n readonly name: string;\n readonly isBoolean: boolean;\n value: any;\n parent: ElementNode;\n constructor(name: string, value: any, parent: any) {\n this.parent = parent;\n this.isBoolean = (BooleanAttributes as readonly string[]).includes(name);\n if (CamelAttributes.includes(name)) {\n this.name = name\n } else {\n this.name = camelToKebab(name)\n }\n this.value = undefined;\n this.set(value);\n }\n\n render(): void {\n if (!this.parent || !this.parent.domElement) return;\n const domElement = this.parent.domElement;\n\n const mutateAttrs = [\"value\"];\n if (this.isBoolean) {\n if (this.value === false || this.value == null) {\n domElement.removeAttribute(this.name)\n } else {\n domElement.setAttribute(this.name, this.value === true ? \"\" : this.value)\n }\n } else if (this.value == null) {\n domElement.removeAttribute(this.name);\n } else if (mutateAttrs.includes(this.name)) {\n (domElement as any)[this.name] = this.value;\n } else {\n domElement.setAttribute(this.name, this.value);\n }\n }\n\n set(value: AttributeValue): void {\n if (value == null) {\n this.value = null;\n this.render();\n return;\n }\n if (typeof value === \"string\" && /<\\/?[a-z][\\s\\S]*>/i.test(value)) {\n this.value = escapeHTML(value);\n } else if (typeof value == \"function\") {\n let listener: any = () => {\n if (!listener) return;\n this.value = this.isBoolean ? Boolean((value as Function)()) : (value as Function)();\n this.render();\n };\n\n listener.elementNode = this.parent!;\n\n listener.onSubscribe = (release: () => void) => {\n if (this.parent) {\n this.parent.addHook(\"BeforeRemove\", () => {\n release();\n listener = null;\n });\n }\n };\n\n this.value = this.isBoolean ? Boolean(value(listener)) : value(listener);\n } else {\n this.value = this.isBoolean ? Boolean(value) : value;\n }\n\n this.render();\n }\n\n remove(): void {\n if (this.parent && this.parent.attributes) {\n this.parent.attributes.remove(this.name);\n }\n this._dispose();\n }\n\n _dispose(): void {\n this.value = null;\n this.parent = null as any\n }\n\n generateHTML(): string {\n const { name, value } = this;\n if (this.isBoolean) {\n return value ? `${name}` : \"\";\n } else {\n const val = Array.isArray(value) ? JSON.stringify(value) : value;\n return `${name}=\"${escapeHTML(String(val))}\"`;\n }\n }\n}","import type { ElementNode } from \"./ElementNode.js\";\nimport { ElementAttribute } from \"./ElementAttribute.js\";\nimport { BooleanAttributes } from \"../constants.js\";\nimport { Notifier } from \"./Notifier.js\"\nimport { AttributeValue } from \"../types.js\"\n\nexport class AttributeList {\n _notifier = new Notifier()\n\n items: Record<string, ElementAttribute> | null = {};\n parent: ElementNode | null;\n\n constructor(parent: ElementNode) {\n this.parent = parent;\n }\n\n generateHTML(): string {\n if (!this.items) return \"\";\n const str = Object.values(this.items)\n .map((attr) => attr.generateHTML())\n .join(\" \");\n return str ? ` ${str}` : \"\";\n }\n\n get(name: string): any {\n if (!this.items) return undefined;\n return this.items[name]?.value;\n }\n\n set(name: string, value: AttributeValue): void {\n if (!this.items || !this.parent) return;\n\n if (this.items[name]) {\n this.items[name].set(value);\n this.parent.domElement && this._notifier.notify(name, this.items[name].value)\n } else {\n this.items[name] = new ElementAttribute(name, value, this.parent);\n }\n }\n\n onChange(name: string, callback: (value: string | number) => void): void {\n if (this.has(name) && this.parent?.domElement) {\n const handler = callback as any\n handler.onSubscribe = (release: () => void) => this.parent?.addHook(\"BeforeRemove\", release);\n this._notifier.addListener(name, handler)\n }\n }\n\n has(name: string): boolean {\n if (!this.items) return false;\n return Object.prototype.hasOwnProperty.call(this.items, name);\n }\n\n remove(name: string): void {\n if (!this.items) return;\n\n if (this.items[name]) {\n this.items[name]._dispose();\n delete this.items[name];\n }\n\n if (this.parent && this.parent.domElement && this.parent.domElement instanceof Element) {\n this.parent.domElement.removeAttribute(name);\n }\n }\n\n _dispose(): void {\n\n if (this.items) {\n for (const key in this.items) {\n this.items[key]._dispose();\n }\n }\n this._notifier._dispose()\n this.items = null;\n this.parent = null;\n }\n\n toggle(name: string, force?: boolean): void {\n if (\n !BooleanAttributes.includes(name as (typeof BooleanAttributes)[number])\n ) {\n throw Error(`${name} is not a boolean attribute`);\n }\n if (force === true) {\n this.set(name, true);\n } else if (force === false) {\n this.remove(name);\n } else {\n this.has(name) ? this.remove(name) : this.set(name, true);\n }\n }\n\n addClass(className: string): void {\n if (!className || typeof className !== \"string\") return;\n\n const add = (classes: string, newClass: string) => {\n const list = (classes || \"\").split(\" \").filter((e: string) => e);\n !list.includes(newClass) && list.push(className)\n return list.join(\" \")\n }\n\n let current = this.get(\"class\");\n\n if (typeof current === \"function\") {\n this.set(\"class\", () => add(current(), className));\n } else {\n this.set(\"class\", add(current, className))\n }\n }\n\n hasClass(className: string): boolean {\n if (!className || typeof className !== \"string\") return false;\n const current = this.get(\"class\") || \"\";\n const list = current.split(\" \").filter((e: string) => e);\n return list.includes(className);\n }\n\n toggleClass(className: string): void {\n if (!className || typeof className !== \"string\") return;\n this.hasClass(className)\n ? this.removeClass(className)\n : this.addClass(className);\n }\n\n removeClass(className: string): void {\n if (!className || typeof className !== \"string\") return;\n const current = this.get(\"class\") || \"\";\n const list: string[] = current.split(\" \").filter((e: string) => e);\n const updated = list.filter((cls) => cls !== className);\n updated.length > 0\n ? this.set(\"class\", updated.join(\" \"))\n : this.remove(\"class\");\n }\n\n replaceClass(oldClass: string, newClass: string): void {\n if (\n !oldClass ||\n !newClass ||\n typeof oldClass !== \"string\" ||\n typeof newClass !== \"string\"\n )\n return;\n if (this.hasClass(oldClass)) {\n this.removeClass(oldClass);\n this.addClass(newClass);\n }\n }\n}","import { ElementNode } from \"./ElementNode.js\";\nimport { isHTML } from \"../helpers.js\";\n\nexport class TextNode {\n type = \"TextNode\"\n parent: ElementNode;\n text: string;\n domText?: ChildNode;\n\n constructor(textContent: string | number, parent: ElementNode) {\n this.parent = parent;\n this.text = textContent === \"\" ? \"\\u200B\" : String(textContent);\n }\n _createDOMNode() {\n let newNode: ChildNode;\n if (isHTML(this.text)) {\n const tpl = document.createElement(\"template\");\n tpl.innerHTML = this.text.trim();\n newNode = tpl.content.firstChild || document.createTextNode(\"\");\n } else {\n newNode = document.createTextNode(this.text);\n }\n this.domText = newNode;\n return newNode;\n }\n\n _dispose(): void {\n this.domText = undefined;\n this.text = \"\";\n }\n\n generateHTML(): string {\n return this.text === \"\\u200B\" ? \"&#8203;\" : this.text;\n }\n\n render(domText: ChildNode | DocumentFragment | HTMLElement): void {\n const newNode = this._createDOMNode();\n domText.appendChild(newNode);\n }\n}","import { TextNode } from \"./TextNode.js\";\nimport { ElementNode } from \"./ElementNode.js\";\nimport type { DomphyElement } from \"../types.js\";\n\ntype ElementInput = DomphyElement | null | undefined | number | string\ntype NodeItem = ElementNode | TextNode;\n\nexport class ElementList {\n items: NodeItem[] = [];\n owner: ElementNode;\n\n constructor(parent: ElementNode) {\n this.owner = parent;\n }\n\n _createNode(element: ElementInput | DomphyElement, index = 0): NodeItem {\n return (typeof element === \"object\" && element !== null)\n ? new ElementNode(element, this.owner, index)\n : new TextNode(element == null ? \"\" : String(element), this.owner);\n }\n\n _moveDomElement(node: NodeItem, index: number) {\n if (!this.owner || !this.owner.domElement) return;\n const dom = this.owner.domElement;\n\n const el = node instanceof ElementNode ? node.domElement : node.domText;\n if (el) {\n const currentRef = dom.childNodes[index] || null;\n if (el !== currentRef) {\n dom.insertBefore(el, currentRef);\n }\n }\n }\n\n _swapDomElement(aNode: NodeItem, bNode: NodeItem) {\n if (!this.owner || !this.owner.domElement) return;\n const parent = this.owner.domElement;\n\n const a = aNode instanceof ElementNode ? aNode.domElement : aNode.domText;\n const b = bNode instanceof ElementNode ? bNode.domElement : bNode.domText;\n if (!a || !b) return;\n\n const aNext = a.nextSibling;\n const bNext = b.nextSibling;\n\n parent.insertBefore(a, bNext);\n parent.insertBefore(b, aNext);\n }\n\n update(inputs: ElementInput[], updateDom = true, silent = false): void {\n\n const oldItems = this.items.slice(); // snapshot for cleanup\n\n // keyed lookup from old list\n const keyed = new Map<string | number, NodeItem>();\n for (const item of oldItems) {\n if (item instanceof ElementNode && item.key !== null && item.key !== undefined) {\n keyed.set(item.key, item);\n }\n }\n\n if (!silent && this.owner.domElement) this.owner._hooks?.BeforeUpdate?.(this.owner, inputs);\n // build target order using existing ops (mutating this.items)\n for (let i = 0; i < inputs.length; i++) {\n const input = inputs[i];\n const key =\n (typeof input === \"object\" && input !== null) ? (input as any)._key : undefined;\n\n if (key !== undefined) {\n const reused = keyed.get(key);\n if (reused) {\n keyed.delete(key);\n\n const cur = this.items.indexOf(reused);\n if (cur !== i && cur >= 0) {\n const isPortal = reused instanceof ElementNode && !!reused._portal;\n this.move(cur, i, isPortal ? false : updateDom, true);\n }\n reused.parent = this.owner as any;\n continue;\n }\n }\n\n this.insert(input, i, updateDom, true);\n }\n\n while (this.items.length > inputs.length) {\n this.remove(this.items[this.items.length - 1], updateDom, true);\n }\n keyed.forEach((node) => this.remove(node, updateDom, true));\n if (!silent) this.owner._hooks?.Update?.(this.owner);\n }\n\n insert(input: ElementInput, index?: number, updateDom = true, silent = false): NodeItem {\n\n let length = this.items.length;\n const finalIndex = (typeof index !== \"number\" || isNaN(index) || index < 0 || index > length)\n ? length\n : index;\n const item = this._createNode(input, finalIndex);\n this.items.splice(finalIndex, 0, item);\n\n if (item instanceof ElementNode) {\n //Parent always insert/mount before children\n item._hooks.Insert && item._hooks.Insert(item)\n\n let domElement = this.owner.domElement;\n if (updateDom && domElement) {\n\n\n if (item._portal) {\n let domElement = item._portal!(this.owner.getRoot())\n domElement && item.render(domElement)\n } else {\n let domNode = item._createDOMNode();\n const ref = domElement.childNodes[finalIndex] ?? null;\n domElement.insertBefore(domNode, ref);\n let root = domElement.getRootNode()\n const styleParent = root instanceof ShadowRoot ? root : document.head\n let domStyle = styleParent.querySelector(\"#domphy-style\") as HTMLStyleElement;\n item.styles.render(domStyle as HTMLStyleElement)\n item._hooks.Mount && item._hooks.Mount(item)\n item.children.items.forEach(child => {\n if (child instanceof ElementNode && child._portal) {\n let dom = child._portal!(child.getRoot())\n dom && child.render(dom)\n } else {\n child.render(domNode)\n }\n })\n }\n }\n\n\n\n } else {\n let domElement = this.owner.domElement;\n if (updateDom && domElement) {\n let domNode = item._createDOMNode();\n const ref = domElement.childNodes[finalIndex] ?? null;\n domElement.insertBefore(domNode, ref);\n }\n }\n !silent && this.owner.domElement && this.owner._hooks.Update && this.owner._hooks.Update(this.owner)\n return item;\n }\n\n remove(item: NodeItem, updateDom = true, silent = false): void {\n\n const index = this.items.indexOf(item);\n if (index < 0) return;\n\n if (item instanceof ElementNode) {\n const done = () => {\n const el = item.domElement\n this.items.splice(index, 1);\n updateDom && el && el.remove()\n item._hooks?.Remove?.(item)\n item._dispose();\n }\n if (item._hooks && item._hooks.BeforeRemove && item.domElement) {\n item._hooks.BeforeRemove(item, done)\n } else {\n done()\n }\n\n } else {\n const el = item.domText\n this.items.splice(index, 1);\n updateDom && el && el.remove()\n item._dispose();\n }\n\n !silent && this.owner.domElement && this.owner._hooks.Update && this.owner._hooks.Update(this.owner)\n }\n\n clear(updateDom = true, silent = false): void {\n if (this.items.length === 0) return;\n const snapshot = this.items.slice();\n\n for (const item of snapshot) {\n this.remove(item, updateDom, true);\n }\n !silent && this.owner.domElement && this.owner._hooks.Update && this.owner._hooks.Update(this.owner)\n }\n\n _dispose(): void {\n this.items = [];\n }\n\n swap(aIndex: number, bIndex: number, updateDom = true, silent = false) {\n if (aIndex < 0 || bIndex < 0 ||\n aIndex >= this.items.length || bIndex >= this.items.length ||\n aIndex === bIndex) return;\n\n const itemA = this.items[aIndex];\n const itemB = this.items[bIndex];\n\n this.items[aIndex] = itemB;\n this.items[bIndex] = itemA;\n\n if (updateDom) this._swapDomElement(itemA, itemB);\n\n !silent && this.owner.domElement && this.owner._hooks.Update && this.owner._hooks.Update(this.owner)\n }\n\n move(fromIndex: number, toIndex: number, updateDom = true, silent = false): void {\n if (fromIndex < 0 || fromIndex >= this.items.length ||\n toIndex < 0 || toIndex >= this.items.length || fromIndex === toIndex) return;\n\n const item = this.items[fromIndex];\n\n this.items.splice(fromIndex, 1);\n this.items.splice(toIndex, 0, item);\n\n if (updateDom) this._moveDomElement(item, toIndex);\n\n !silent && this.owner.domElement && this.owner._hooks.Update && this.owner._hooks.Update(this.owner)\n }\n\n generateHTML(): string {\n let html = \"\";\n for (const item of this.items) html += item.generateHTML();\n return html;\n }\n}","import type { StyleRule } from \"./StyleRule.js\";\nimport type { StyleValue } from \"../types.js\";\nimport { camelToKebab } from \"../helpers.js\";\nimport { PrefixCSS } from \"../constants.js\";\n\nexport class StyleProperty {\n name: string;\n cssName: string;\n value: StyleValue = \"\";\n parentRule: StyleRule;\n\n constructor(name: string, value: StyleValue, parentRule: StyleRule) {\n this.name = name;\n this.cssName = camelToKebab(name);\n this.parentRule = parentRule;\n this.set(value);\n }\n\n _domUpdate(): void {\n if (!this.parentRule) return;\n const domRule = this.parentRule.domRule;\n\n if (domRule && (domRule as CSSStyleRule).style) {\n let style: CSSStyleDeclaration = (domRule as CSSStyleRule).style;\n style.setProperty(this.cssName, String(this.value));\n\n if (PrefixCSS[this.name]) {\n PrefixCSS[this.name].forEach((prefix) => {\n style.setProperty(`-${prefix}-${this.cssName}`, String(this.value));\n });\n }\n }\n }\n _dispose(): void {\n this.value = \"\";\n this.parentRule = null as any;\n }\n\n set(value: StyleValue): void {\n\n if (typeof value === \"function\") {\n let Listener: any = () => {\n if (!Listener) return;\n this.value = value(Listener);\n this._domUpdate();\n }\n\n Listener.onSubscribe = (release: () => void) => {\n this.parentRule.parentNode?.addHook(\"BeforeRemove\", () => {\n release();\n Listener = null;\n });\n };\n\n Listener.elementNode = this.parentRule!.root;\n this.value = value(Listener);\n } else {\n this.value = value;\n }\n\n this._domUpdate();\n }\n\n remove(): void {\n if (!this.parentRule) return;\n\n if (this.parentRule.domRule instanceof CSSStyleRule) {\n const domStyle = this.parentRule.domRule.style;\n domStyle.removeProperty(this.cssName);\n\n if (PrefixCSS[this.name]) {\n PrefixCSS[this.name].forEach((prefix) => {\n domStyle.removeProperty(`-${prefix}-${this.cssName}`);\n });\n }\n }\n delete this.parentRule.styleBlock![this.name];\n this._dispose();\n }\n\n cssText(): string {\n let str = `${this.cssName}: ${this.value}`;\n if (PrefixCSS[this.name]) {\n PrefixCSS[this.name].forEach((prefix) => {\n str += `; -${prefix}-${this.cssName}: ${this.value}`;\n });\n }\n return str;\n }\n}","import { ElementNode } from \"./ElementNode.js\";\nimport { StyleProperty } from \"./StyleProperty.js\";\nimport { StyleList } from \"./StyleList.js\";\n\nexport class StyleRule {\n selectorText: string;\n domRule: CSSRule | CSSMediaRule | CSSKeyframesRule | null = null;\n styleList: StyleList | null;\n styleBlock: Record<string, StyleProperty> | null = {};\n parent: StyleRule | ElementNode | null;\n\n constructor(selectorText: string, parent: StyleRule | ElementNode) {\n this.selectorText = selectorText;\n this.styleList = new StyleList(this);\n this.parent = parent;\n }\n\n _dispose(): void {\n\n if (this.styleBlock) {\n for (const prop of Object.values(this.styleBlock)) {\n prop._dispose();\n }\n }\n\n if (this.styleList) {\n this.styleList._dispose();\n }\n\n this.styleBlock = null;\n this.styleList = null;\n this.domRule = null;\n this.parent = null;\n }\n\n get root() {\n let node = this.parent;\n while (node instanceof StyleRule) {\n node = node.parent;\n }\n return node;\n }\n\n get parentNode(): ElementNode | null {\n let root: any = this.parent;\n while (root && root instanceof StyleRule) {\n root = root.parent;\n }\n return root as ElementNode;\n }\n \n insertStyle(name: string, val: any): void {\n if (!this.styleBlock) return;\n if (this.styleBlock[name]) {\n this.styleBlock[name].set(val);\n } else {\n this.styleBlock[name] = new StyleProperty(name, val, this);\n }\n }\n\n removeStyle(name: string): void {\n if (!this.styleBlock) return;\n if (this.styleBlock[name]) {\n this.styleBlock[name].remove();\n }\n }\n\n cssText(): string {\n if (!this.styleBlock || !this.styleList) return \"\";\n const styleStr = Object.values(this.styleBlock).map(decl => decl.cssText()).join(\";\");\n const nested = this.styleList.cssText();\n return `${this.selectorText} { ${styleStr} ${nested} } `;\n }\n\n mount(domRule: CSSRule | CSSKeyframesRule): void {\n if (!domRule || !this.styleList) return;\n this.domRule = domRule;\n if (\"cssRules\" in domRule) {\n this.styleList.mount(domRule.cssRules as CSSRuleList);\n }\n }\n\n remove(): void {\n\n if (this.domRule && this.domRule.parentStyleSheet) {\n const sheet = this.domRule.parentStyleSheet;\n const rules = sheet.cssRules;\n for (let i = 0; i < rules.length; i++) {\n if (rules[i] === this.domRule) {\n sheet.deleteRule(i);\n break;\n }\n }\n }\n this._dispose();\n }\n\n render(domSheet: CSSStyleSheet | CSSGroupingRule) {\n if (!this.styleBlock || !this.styleList) return;\n const styleStr = Object.values(this.styleBlock).map(decl => decl.cssText()).join(\";\");\n try {\n if (!this.selectorText.startsWith(\"@\")) {\n const css = `${this.selectorText} { ${styleStr} }`;\n const index = domSheet.insertRule(css, domSheet.cssRules.length);\n const domRule = domSheet.cssRules[index];\n if (domRule && \"selectorText\" in domRule) {\n this.mount(domRule);\n }\n } else if (/^@(media|supports|container|layer)\\b/.test(this.selectorText)) {\n const index = domSheet.insertRule(`${this.selectorText} {}`, domSheet.cssRules.length);\n const domRule = domSheet.cssRules[index];\n if (\"cssRules\" in domRule) {\n this.mount(domRule as CSSGroupingRule);\n this.styleList.render(domRule as CSSGroupingRule);\n }\n } else if (this.selectorText.startsWith(\"@keyframes\") || this.selectorText.startsWith(\"@font-face\")) {\n const css = this.cssText();\n const index = domSheet.insertRule(css, domSheet.cssRules.length);\n const domRule = domSheet.cssRules[index];\n this.mount(domRule);\n }\n } catch (err) {\n console.warn(\"Failed to insert rule:\", this.selectorText, err);\n }\n }\n}","import { ElementNode } from \"./ElementNode.js\";\nimport { selectorSplitter } from \"../helpers.js\";\nimport { StyleRule } from \"./StyleRule.js\";\n\nexport class StyleList {\n parent: StyleRule | ElementNode | null;\n items: StyleRule[] = [];\n domStyle: HTMLStyleElement | null = null;\n\n constructor(parent: StyleRule | ElementNode) {\n this.parent = parent;\n }\n\n get parentNode(): ElementNode | null {\n let root: any = this.parent;\n while (root && root instanceof StyleRule) {\n root = root.parent;\n }\n return root as ElementNode;\n }\n\n addCSS(obj: Record<string, any>, parentSelector: string = \"\"): void {\n if (!this.items || !this.parent) return;\n const basic: Record<string, any> = {};\n\n function getSelector(selector: string, prev: string): string {\n return selector.startsWith(\"&\")\n ? `${prev}${selector.slice(1)}`\n : `${prev} ${selector}`;\n }\n\n for (const selector in obj) {\n const value = obj[selector];\n let splitKeys = selectorSplitter(selector);\n for (let key of splitKeys) {\n const currentSelector = getSelector(key, parentSelector);\n if (/^@(container|layer|supports|media)\\b/.test(key)) {\n if (typeof value === \"object\" && value != null) {\n const rule = new StyleRule(key, this.parent);\n rule.styleList!.addCSS(value, parentSelector);\n this.items.push(rule);\n }\n } else if (key.startsWith(\"@keyframes\")) {\n const rule = new StyleRule(key, this.parent);\n rule.styleList!.addCSS(value, \"\");\n this.items.push(rule);\n } else if (key.startsWith(\"@font-face\")) {\n const rule = new StyleRule(key, this.parent);\n for (const k in value) rule.insertStyle(k, value[k]);\n this.items.push(rule);\n } else if (typeof value === \"object\" && value != null) {\n const rule = new StyleRule(currentSelector, this.parent);\n this.items.push(rule);\n for (const [k, v] of Object.entries(value)) {\n if (typeof v === \"object\" && v != null) {\n let newSelector = getSelector(k, currentSelector);\n if (k.startsWith(\"&\")) {\n this.addCSS(v, newSelector);\n } else {\n const r = rule.styleList!.insertRule(newSelector);\n r.styleList!.addCSS(v, newSelector);\n }\n } else {\n rule.insertStyle(k, v);\n }\n }\n } else {\n basic[key] = value;\n }\n }\n }\n\n if (Object.keys(basic).length) {\n const rule = new StyleRule(parentSelector, this.parent);\n for (const key in basic) rule.insertStyle(key, basic[key]);\n this.items.push(rule);\n }\n }\n\n cssText(): string {\n if (!this.items) return \"\";\n return this.items.map((rule) => rule.cssText()).join(\"\");\n }\n\n insertRule(selector: string): StyleRule {\n if (!this.items || !this.parent) return null as any;\n let rule = this.items.find((rule) => rule.selectorText === selector);\n if (!rule) {\n rule = new StyleRule(selector, this.parent);\n this.items.push(rule);\n }\n return rule;\n }\n\n mount(domRuleList: CSSRuleList): void {\n if (!this.items) return;\n if (!domRuleList) throw Error(\"Require domRuleList argument\");\n let wrongCount = 0;\n const fixOddEven = (css: string) => css.replace(\"(odd)\", \"(2n+1)\").replace(\"(even)\", \"(2n)\");\n\n this.items.forEach((rule, i) => {\n const index = i - wrongCount;\n const domRule = domRuleList[index];\n if (!domRule) return;\n if (rule.selectorText.startsWith(\"@\") && domRule instanceof CSSKeyframesRule) {\n rule.mount(domRule);\n } else if (\"keyText\" in domRule) {\n rule.mount(domRule);\n } else if (\"selectorText\" in domRule) {\n if (domRule.selectorText !== fixOddEven(rule.selectorText)) {\n wrongCount += 1;\n } else {\n rule.mount(domRule);\n }\n } else if (\"cssRules\" in domRule) {\n rule.mount(domRule as CSSMediaRule);\n }\n });\n }\n\n render(dom: HTMLStyleElement | CSSGroupingRule) {\n if (dom instanceof HTMLStyleElement) {\n this.domStyle = dom\n this.items.forEach((rule) => rule.render(dom.sheet!));\n } else if (dom instanceof CSSGroupingRule) {\n this.items.forEach((rule) => rule.render(dom));\n }\n }\n\n _dispose(): void {\n\n if (this.items) {\n for (let i = 0; i < this.items.length; i++) {\n this.items[i]._dispose();\n }\n }\n\n this.items = [];\n this.parent = null;\n this.domStyle = null;\n }\n}\n","import type { DomphyElement, EventName, HookMap, TagName, PartialElement } from \"../types.js\";\nimport { AttributeList } from \"./AttributeList.js\";\nimport { ElementList } from \"./ElementList.js\";\nimport { StyleList } from \"./StyleList.js\";\nimport { validate, mergePartial, getTagName, deepClone } from \"../helpers.js\";\nimport { merge, hashString } from \"../utils.js\";\n\nexport class ElementNode {\n type = \"ElementNode\"\n parent: ElementNode | null = null;\n _portal?: (root: ElementNode) => HTMLElement;\n tagName: TagName;\n children = new ElementList(this);\n styles = new StyleList(this);\n attributes = new AttributeList(this);\n domElement?: HTMLElement | null = null;\n _hooks: HookMap = {};\n _events?: { [K in EventName]?: (event: Event, node: ElementNode) => void } | null = null;\n _context?: Record<string, any> = {};\n _metadata?: Record<string, any> = {};\n key?: string | number | null = null;\n nodeId: string\n\n constructor(domphyElement: DomphyElement, _parent: ElementNode | null = null, index = 0) {\n domphyElement = deepClone(domphyElement)\n validate(domphyElement)\n domphyElement.style = domphyElement.style || {}\n this.parent = _parent;\n this.tagName = getTagName(domphyElement) as TagName;\n domphyElement = mergePartial(domphyElement) as DomphyElement\n\n this.key = (domphyElement as any)._key ?? null;\n this._context = domphyElement._context || {}\n this._metadata = domphyElement._metadata || {}\n\n let tempPath = `${this.parent?.getPath()}.${index}`\n const str = JSON.stringify(domphyElement.style || {}, (k, v) => typeof v === \"function\" ? tempPath : v,);\n this.nodeId = hashString(tempPath + str)\n\n this.attributes!.addClass(`${this.tagName}_${this.nodeId}`);\n\n if (domphyElement._onSchedule) domphyElement._onSchedule(this, domphyElement)\n\n this.merge(domphyElement)\n\n const children = (domphyElement as any)[this.tagName];\n\n if (children != null && children != undefined) {\n if (typeof children === \"function\") {\n let listener: any = () => {\n let input = children(listener)\n this.children!.update(Array.isArray(input) ? input : [input])\n }\n listener!.elementNode = this;\n listener!.onSubscribe = (release: () => void) => this.addHook(\"BeforeRemove\", () => {\n release()\n listener = null\n });\n listener && listener();\n } else {\n this.children!.update(Array.isArray(children) ? children : [children])\n }\n }\n this._hooks.Init && this._hooks.Init(this)\n }\n\n _createDOMNode() {\n const svgNamespace = \"http://www.w3.org/2000/svg\"\n const svgTags = [\"svg\", \"circle\", \"path\", \"rect\", \"ellipse\",\n \"line\", \"polyline\", \"polygon\", \"g\", \"defs\",\n \"use\", \"symbol\", \"linearGradient\", \"radialGradient\",\n \"stop\", \"clipPath\", \"mask\", \"filter\", \"text\",\n \"tspan\", \"textPath\", \"image\", \"pattern\", \"marker\",\n \"animate\", \"animateTransform\", \"animateMotion\",\n \"feGaussianBlur\", \"feComposite\", \"feColorMatrix\",\n \"feMerge\", \"feMergeNode\", \"feOffset\", \"feFlood\",\n \"feBlend\", \"foreignObject\"]\n\n let node = svgTags.includes(this.tagName)\n ? document.createElementNS(svgNamespace, this.tagName)\n : document.createElement(this.tagName)\n\n this.domElement = node as HTMLElement\n\n if (this._events) {\n for (const key in this._events) {\n const eventName = key as EventName;\n const handler = this._events[eventName] as (event: Event, node: ElementNode) => void;\n let fn: any = (event: Event) => handler(event, this)\n node.addEventListener(eventName, fn)\n this.addHook(\"BeforeRemove\", (n) => {\n n.domElement!.removeEventListener(eventName, fn)\n fn = null\n })\n }\n }\n\n if (this.attributes) {\n Object.values(this.attributes.items!).forEach(attr => attr.render())\n }\n return node\n }\n\n _dispose(): void {\n\n if (this.children) {\n this.children._dispose();\n }\n\n if (this.styles) {\n this.styles.items!.forEach((rule) => rule.remove());\n this.styles._dispose();\n }\n\n if (this.attributes) {\n this.attributes._dispose();\n }\n\n this.domElement = null;\n this._hooks = {};\n this._events = null;\n this._context = {};\n this._metadata = {};\n this.parent = null;\n }\n get pathId(): string {\n return hashString(this.getPath())\n }\n merge(part: PartialElement) {\n merge(this._context, part._context)\n merge(this._metadata, part._metadata)\n\n const keys = Object.keys(part)\n for (let i = 0; i < keys.length; i++) {\n const originalKey = keys[i];\n const value = (part as any)[originalKey];\n if ([\"$\", \"_onSchedule\", \"_key\", \"_context\", \"_metadata\", \"style\", this.tagName].includes(originalKey)) {\n continue\n } else if ([\"_onInit\", \"_onInsert\", \"_onMount\", \"_onBeforeUpdate\", \"_onUpdate\", \"_onBeforeRemove\", \"_onRemove\"].includes(originalKey)) {\n this.addHook(originalKey.substring(3) as keyof HookMap, value);\n } else if (originalKey.startsWith(\"on\")) {\n this.addEvent(originalKey.substring(2).toLowerCase() as EventName, value);\n } else if (originalKey == \"_portal\") {\n this._portal = value\n } else if (originalKey == \"class\" && typeof value === \"string\") {\n this.attributes!.addClass(value);\n } else {\n this.attributes!.set(originalKey, value);\n }\n }\n if (part.style) {\n this.styles.addCSS(part.style || {}, `.${`${this.tagName}_${this.nodeId}`}`);\n }\n\n }\n getPath(): string {\n let path: number[] = []\n let node: ElementNode = this\n while (node && node.parent) {\n const parent = node.parent\n const index = parent.children!.items.indexOf(node)\n path.push(index)\n node = parent\n }\n return path.reverse().join(\".\")\n }\n\n addEvent(name: EventName, callback: (event: Event, node: ElementNode) => void): void {\n\n this._events = this._events || {}\n\n let current = this._events[name]\n if (typeof current == \"function\") {\n this._events[name] = (event: Event, node: ElementNode) => {\n current!(event, node)\n callback(event, node)\n }\n } else {\n this._events[name] = callback\n }\n }\n\n addHook<K extends keyof HookMap>(name: K, callback: HookMap[K]): void {\n const current = this._hooks[name];\n\n if (typeof current === \"function\") {\n this._hooks[name] = ((...args: any[]) => {\n (current as Function)(...args);\n (callback as Function)(...args);\n }) as HookMap[K];\n } else {\n this._hooks[name] = callback;\n }\n }\n getRoot(): ElementNode {\n let root: ElementNode = this;\n while (root && root instanceof ElementNode && root.parent) {\n root = root.parent;\n }\n return root\n }\n\n getContext(name: string): any {\n let node: ElementNode | null = this;\n while (node && (!node._context || !Object.prototype.hasOwnProperty.call(node._context, name))) {\n node = node.parent;\n }\n return node && node._context ? node._context[name] : undefined;\n }\n\n setContext(name: string, value: any) {\n this._context = this._context || {}\n this._context[name] = value;\n }\n\n getMetadata(name: string): any {\n return this._metadata ? this._metadata[name] : undefined;\n }\n\n setMetadata(key: string, value: any) {\n this._metadata = this._metadata || {}\n this._metadata[key] = value;\n\n }\n\n generateCSS(): string {\n if (!this.styles || !this.children) return \"\";\n let css = this.styles.cssText()\n css += this.children.items.map(child => child instanceof ElementNode ? child.generateCSS() : \"\").join(\"\")\n return css\n }\n\n generateHTML(): string {\n if (!this.children || !this.attributes) return \"\";\n let content = this.children.generateHTML();\n const attributes = this.attributes.generateHTML();\n return `<${this.tagName}${attributes}>${content}</${this.tagName}>`;\n }\n\n mount(domElement: HTMLElement, domStyle?: HTMLStyleElement): void {\n if (!domElement) throw new Error(\"Missing dom node on bind\");\n this.domElement = domElement;\n\n if (this._events) {\n for (const key in this._events) {\n const eventName = key as EventName;\n const handler = this._events[eventName] as (event: Event, node: ElementNode) => void;\n let fn: any = (event: Event) => handler(event, this)\n domElement.addEventListener(eventName, fn)\n this.addHook(\"BeforeRemove\", (n) => {\n n.domElement!.removeEventListener(eventName, fn)\n fn = null\n })\n }\n }\n\n if (this.children) {\n this.children.items.forEach((child, i) => {\n const childNode = domElement.childNodes[i];\n if (childNode instanceof Node && child instanceof ElementNode) {\n child.mount(childNode as HTMLElement, domStyle);\n }\n });\n }\n\n this._hooks.Mount && this._hooks.Mount(this)\n }\n\n render(domElement: HTMLElement | SVGElement | DocumentFragment, domStyle: HTMLStyleElement | null = null): HTMLElement | SVGElement {\n const newNode = this._createDOMNode();\n domElement.appendChild(newNode)\n this._hooks.Mount && this._hooks.Mount(this)\n domStyle ||= this.getRoot().styles.domStyle\n let root = domElement.getRootNode()\n const styleParent = root instanceof ShadowRoot ? root : document.head\n domStyle ||= styleParent.querySelector(\"#domphy-style\") as HTMLStyleElement;\n if (!domStyle) {\n domStyle = document.createElement(\"style\");\n domStyle.id = \"domphy-style\";\n styleParent.appendChild(domStyle);\n }\n this.styles.render(domStyle as HTMLStyleElement)\n this.children.items.forEach(child => {\n if (child instanceof ElementNode && child._portal) {\n let dom = child._portal!(this.getRoot())\n dom && child.render(dom)\n } else {\n child.render(newNode)\n }\n })\n return newNode;\n }\n\n remove() {\n if (this.parent) {\n this.parent.children.remove(this)\n\n } else {\n this.domElement?.remove()\n this._dispose();\n }\n }\n}\n","import * as core from \"./index.js\";\r\n\r\n(globalThis as any).Domphy = {\r\n core\r\n};"],"mappings":"wHAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,gBAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,UAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,UAAAC,EAAA,YAAAC,ICAO,IAAMC,EAAkB,CAC7B,UACA,aACA,gBACA,iBACA,SACA,WACA,YACA,mBACA,WACA,UACA,UACA,gBACA,gBACA,oBACA,SACA,cACA,QACA,aACA,SACA,YACA,cACA,cACA,aACA,cACA,SACA,mBACA,YACA,UACA,UACA,UACA,aACA,UACA,YACA,YACA,aACA,UACA,SACA,eACA,mBACA,cACA,cACA,eACA,eACA,cACA,aACA,cACA,YACA,UACA,UACA,SACA,YACA,aACA,eACA,UACA,WACA,WACA,cACA,4BACA,WACA,YACA,WACA,eACA,YACA,WACA,YACA,eACA,WACA,iBACA,YACA,UACA,eACA,cACA,aACA,gBACA,gBACA,gBACA,cACA,kBACA,iBACA,iBACA,gBACA,eACA,sBACA,uBACA,qBACA,sBACA,mBACA,kBACA,oBACA,mBACA,iBACA,uBACA,qBACA,oBACA,YACA,YACF,EAEaC,EAAeD,EAAgB,OAAO,CAACE,EAAKC,IAAO,CAC9D,IAAMC,EAAMD,EAAG,MAAM,CAAC,EAAE,YAAY,EACpC,OAAAD,EAAIE,CAAG,EAAID,EACJD,CACT,EAAG,CAAC,CAAiF,ECvG9E,IAAMG,EAAW,CACtB,IACA,OACA,UACA,UACA,QACA,QACA,IACA,OACA,aACA,KACA,SACA,SACA,UACA,OACA,OACA,MACA,WACA,OACA,WACA,KACA,MACA,UACA,MACA,SACA,MACA,KACA,KACA,KACA,WACA,aACA,SACA,SACA,OACA,KACA,KACA,KACA,KACA,KACA,KACA,SACA,SACA,IACA,SACA,MACA,QACA,MACA,MACA,QACA,SACA,KACA,OACA,MACA,OACA,OACA,QACA,MACA,WACA,SACA,KACA,WACA,SACA,SACA,IACA,QACA,UACA,MACA,WACA,IACA,KACA,KACA,OACA,IACA,OACA,UACA,SACA,OACA,QACA,SACA,OACA,SACA,MACA,UACA,MACA,QACA,QACA,KACA,WACA,WACA,QACA,KACA,QACA,OACA,QACA,KACA,QACA,IACA,KACA,MACA,QACA,MACA,MACA,MACA,OACA,OACA,SACA,OACA,QACA,KACA,UACA,gBACA,mBACA,SACA,WACA,SACA,OACA,OACA,UACA,UACA,gBACA,sBACA,cACA,mBACA,oBACA,oBACA,iBACA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AK,SAAS,EAElB,CACF,EC5SC,WAAmB,OAAS,CAC3B,KAAA+C,CACF","names":["src_exports","__export","AttributeList","BooleanAttributes","CamelAttributes","ElementList","ElementNode","HtmlTags","Notifier","PrefixCSS","State","VoidTags","hashString","merge","toState","EventProperties","eventNameMap","acc","ev","key","HtmlTags","Notifier","event","listener","release","listeners","args","e","State","initialValue","Notifier","listener","newValue","merge","source","target","comma","space","adjacent","deepClone","key","value","old","listener","val1","val2","e","name","addEvent","addHook","toState","val","State","hashString","str","hash","i","addHook","partial","hookName","handler","hookProperty","current","args","addEvent","attributes","eventName","eventProperty","eventNameMap","event","node","deepClone","value","seen","proto","clone","v","k","key","validate","element","asPartial","keys","i","val","HtmlTags","isHTML","str","escapeHTML","getTagName","element","HtmlTags","camelToKebab","str","selectorSplitter","selectors","splitted","parens","angulars","soFar","len","char","mergePartial","partial","part","p","merge","VoidTags","BooleanAttributes","PrefixCSS","CamelAttributes","ElementAttribute","name","value","parent","BooleanAttributes","CamelAttributes","camelToKebab","domElement","mutateAttrs","escapeHTML","listener","release","val","AttributeList","parent","Notifier","str","attr","name","_a","value","ElementAttribute","callback","handler","release","key","force","BooleanAttributes","className","add","classes","newClass","list","e","current","updated","cls","oldClass","TextNode","textContent","parent","newNode","isHTML","tpl","domText","ElementList","parent","element","index","ElementNode","TextNode","node","dom","el","currentRef","aNode","bNode","a","b","aNext","bNext","inputs","updateDom","silent","_a","_b","_c","_d","oldItems","keyed","item","i","input","key","reused","cur","isPortal","length","finalIndex","domElement","domNode","ref","root","domStyle","child","done","snapshot","aIndex","bIndex","itemA","itemB","fromIndex","toIndex","html","StyleProperty","name","value","parentRule","camelToKebab","domRule","style","PrefixCSS","prefix","Listener","release","_a","domStyle","str","StyleRule","_StyleRule","selectorText","parent","StyleList","prop","node","root","name","val","StyleProperty","styleStr","decl","nested","domRule","sheet","rules","i","domSheet","index","css","err","StyleList","parent","root","StyleRule","obj","parentSelector","basic","getSelector","selector","prev","value","splitKeys","selectorSplitter","key","currentSelector","rule","k","v","newSelector","domRuleList","wrongCount","fixOddEven","css","index","domRule","dom","i","ElementNode","_ElementNode","domphyElement","_parent","index","ElementList","StyleList","AttributeList","_a","_b","deepClone","validate","getTagName","mergePartial","tempPath","str","k","v","hashString","children","listener","input","release","node","key","eventName","handler","fn","event","n","attr","rule","part","merge","keys","i","originalKey","value","path","parent","name","callback","current","args","root","css","child","content","attributes","domElement","domStyle","childNode","newNode","styleParent","dom","src_exports"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var P=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var J=(o,e)=>{for(var t in e)P(o,t,{get:e[t],enumerable:!0})},X=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of G(e))!q.call(o,i)&&i!==t&&P(o,i,{get:()=>e[i],enumerable:!(s=z(e,i))||s.enumerable});return o};var Y=o=>X(P({},"__esModule",{value:!0}),o);var te={};J(te,{AttributeList:()=>x,BooleanAttributes:()=>w,CamelAttributes:()=>$,ElementList:()=>T,ElementNode:()=>m,HtmlTags:()=>R,Notifier:()=>v,PrefixCSS:()=>b,State:()=>E,VoidTags:()=>ee,hashString:()=>N,merge:()=>g,toState:()=>Q});module.exports=Y(te);var Z=["onAbort","onAuxClick","onBeforeMatch","onBeforeToggle","onBlur","onCancel","onCanPlay","onCanPlayThrough","onChange","onClick","onClose","onContextLost","onContextMenu","onContextRestored","onCopy","onCueChange","onCut","onDblClick","onDrag","onDragEnd","onDragEnter","onDragLeave","onDragOver","onDragStart","onDrop","onDurationChange","onEmptied","onEnded","onError","onFocus","onFormData","onInput","onInvalid","onKeyDown","onKeyPress","onKeyUp","onLoad","onLoadedData","onLoadedMetadata","onLoadStart","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onPaste","onPause","onPlay","onPlaying","onProgress","onRateChange","onReset","onResize","onScroll","onScrollEnd","onSecurityPolicyViolation","onSeeked","onSeeking","onSelect","onSlotChange","onStalled","onSubmit","onSuspend","onTimeUpdate","onToggle","onVolumeChange","onWaiting","onWheel","onTouchStart","onTouchMove","onTouchEnd","onTouchCancel","onPointerDown","onPointerMove","onPointerUp","onPointerCancel","onPointerEnter","onPointerLeave","onPointerOver","onPointerOut","onGotPointerCapture","onLostPointerCapture","onCompositionStart","onCompositionUpdate","onCompositionEnd","onTransitionEnd","onTransitionStart","onAnimationStart","onAnimationEnd","onAnimationIteration","onFullscreenChange","onFullscreenError","onFocusIn","onFocusOut"],U=Z.reduce((o,e)=>{let t=e.slice(2).toLowerCase();return o[t]=e,o},{});var R=["a","abbr","address","article","aside","audio","b","base","blockquote","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","i","iframe","img","input","ins","kbd","label","legend","li","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","slot","small","source","span","strong","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","bdi","bdo","math","menu","search","area","embed","hr","animate","animateMotion","animateTransform","circle","clipPath","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","prefetch","radialGradient","rect","set","solidColor","stop","svg","switch","symbol","tbreak","text","textPath","tspan","use","view"];var v=class{constructor(){this._listeners={}}_dispose(){if(this._listeners)for(let e in this._listeners)this._listeners[e].clear();this._listeners=null}addListener(e,t){if(!this._listeners)return()=>{};if(typeof e!="string"||typeof t!="function")throw new Error("Event name must be a string, listener must be a function");this._listeners[e]||(this._listeners[e]=new Set);let s=()=>this.removeListener(e,t);return this._listeners[e].has(t)||(this._listeners[e].add(t),typeof t.onSubscribe=="function"&&t.onSubscribe(s)),s}removeListener(e,t){if(!this._listeners)return;let s=this._listeners[e];s&&s.has(t)&&(s.delete(t),s.size===0&&delete this._listeners[e])}notify(e,...t){if(!this._listeners)return;let s=this._listeners[e];if(s)for(let i of[...s])try{i(...t)}catch(n){console.error(n)}}};var E=class{constructor(e){this._notifier=new v;this.initialValue=e,this._value=e}get(e){return e&&this.onChange(e),this._value}set(e){this._notifier&&(this._value=e,this._notifier.notify("change",e))}reset(){this.set(this.initialValue)}onChange(e){return this._notifier?this._notifier.addListener("change",e):()=>{}}_dispose(){this._notifier&&(this._notifier._dispose(),this._notifier=null)}};function g(o={},e={}){let t=["animation","transition","boxShadow","textShadow","background","fontFamily"],s=["class","rel","transform","acceptCharset","sandbox"],i=["content"];Object.prototype.toString.call(e)==="[object Object]"&&Object.getPrototypeOf(e)===Object.prototype&&(e=y(e));for(let n in e){let r=e[n];if(!(r==null||r===""))if(typeof r=="object"&&!Array.isArray(r))typeof o[n]=="object"?o[n]=g(o[n],r):o[n]=r;else if(t.includes(n))if(typeof o[n]=="function"||typeof r=="function"){let l=o[n];o[n]=h=>{let c=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[c,a].filter(f=>f).join(", ")}}else o[n]=[o[n],r].filter(l=>l).join(", ");else if(i.includes(n))if(typeof o[n]=="function"||typeof r=="function"){let l=o[n];o[n]=h=>{let c=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[c,a].filter(f=>f).join("")}}else o[n]=[o[n],r].filter(l=>l).join("");else if(s.includes(n))if(typeof o[n]=="function"||typeof r=="function"){let l=o[n];o[n]=h=>{let c=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[c,a].filter(f=>f).join(" ")}}else o[n]=[o[n],r].filter(l=>l).join(" ");else if(n.startsWith("on")){let l=n.replace("on","").toLowerCase();I(o,l,r)}else if(n.startsWith("_on")){let l=n.replace("_on","");F(o,l,r)}else o[n]=r}return o}function Q(o){return o instanceof E?o:new E(o)}function N(o=""){let e=2166136261;for(let t=0;t<o.length;t++)e^=o.charCodeAt(t),e=e*16777619>>>0;return String.fromCharCode(97+e%26)+e.toString(16)}function F(o,e,t){let s=`_on${e}`,i=o[s];typeof i=="function"?o[s]=(...n)=>{i(...n),t(...n)}:o[s]=t}function I(o,e,t){let s=U[e];if(!s)throw Error(`invalid event name "${e}"`);let i=o[s];typeof i=="function"?o[s]=(n,r)=>{i(n,r),t(n,r)}:o[s]=t}function y(o,e=new WeakMap){if(o===null||typeof o!="object"||typeof o=="function")return o;if(e.has(o))return e.get(o);let t=Object.getPrototypeOf(o);if(t!==Object.prototype&&!Array.isArray(o))return o;let s;if(Array.isArray(o)){s=[],e.set(o,s);for(let i of o)s.push(y(i,e));return s}if(o instanceof Date)return new Date(o);if(o instanceof RegExp)return new RegExp(o);if(o instanceof Map){s=new Map,e.set(o,s);for(let[i,n]of o)s.set(y(i,e),y(n,e));return s}if(o instanceof Set){s=new Set,e.set(o,s);for(let i of o)s.add(y(i,e));return s}if(ArrayBuffer.isView(o))return new o.constructor(o);if(o instanceof ArrayBuffer)return o.slice(0);s=Object.create(t),e.set(o,s);for(let i of Reflect.ownKeys(o))s[i]=y(o[i],e);return s}function B(o,e=!1){if(Object.prototype.toString.call(o)!=="[object Object]")throw Error(`typeof ${o} is invalid DomphyElement`);let t=Object.keys(o);for(let s=0;s<t.length;s++){let i=t[s],n=o[i];if(s==0&&!R.includes(i)&&!i.includes("-")&&!e)throw Error(`key ${i} is not valid HTML tag name`);if(i=="style"&&n&&Object.prototype.toString.call(n)!=="[object Object]")throw Error('"style" must be a object');if(i=="$")o.$.forEach(r=>B(r,!0));else{if(i.startsWith("_on")&&typeof n!="function")throw Error(`hook ${i} value "${n}" must be a function `);if(i.startsWith("on")&&typeof n!="function")throw Error(`event ${i} value "${n}" must be a function `);if(i=="_portal"&&typeof n!="function")throw Error('"_portal" must be a function return HTMLElement');if(i=="_context"&&Object.prototype.toString.call(n)!=="[object Object]")throw Error('"_context" must be a object');if(i=="_metadata"&&Object.prototype.toString.call(n)!=="[object Object]")throw Error('"_metadata" must be a object');if(i=="_key"&&typeof n!="string"&&typeof n!="number")throw Error('"_key" must be a string or number')}}return!0}function K(o){return/<([a-z][\w-]*)(\s[^>]*)?>.*<\/\1>|<([a-z][\w-]*)(\s[^>]*)?\/>/i.test(o.trim())}function A(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function V(o){return Object.keys(o).find(e=>R.includes(e))}function C(o){return o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function W(o){if(o.indexOf("@")===0)return[o];for(var e=[],t=0,s=0,i="",n=0,r=o.length;n<r;n++){var l=o[n];if(l==="(")t+=1;else if(l===")")t-=1;else if(l==="[")s+=1;else if(l==="]")s-=1;else if(l===","&&!t&&!s){e.push(i.trim()),i="";continue}i+=l}return e.push(i.trim()),e}var O=o=>{if(Array.isArray(o.$)){let e={};return o.$.forEach(t=>g(e,O(t))),delete o.$,g(e,o),e}else return o};var ee=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var w=["allowFullScreen","async","autoFocus","autoPlay","checked","compact","contentEditable","controls","declare","default","defer","disabled","formNoValidate","hidden","isMap","itemScope","loop","multiple","muted","noHref","noShade","noValidate","open","playsInline","readonly","required","reversed","scoped","selected","sortable","trueSpeed","typeMustMatch","wmode","autoCapitalize","translate","spellCheck","inert","download","noModule","paused","autoPictureInPicture"];var b={transform:["webkit","ms"],transition:["webkit","ms"],animation:["webkit"],userSelect:["webkit","ms"],flexDirection:["webkit","ms"],flexWrap:["webkit","ms"],justifyContent:["webkit","ms"],alignItems:["webkit","ms"],alignSelf:["webkit","ms"],order:["webkit","ms"],flexGrow:["webkit","ms"],flexShrink:["webkit","ms"],flexBasis:["webkit","ms"],columns:["webkit"],columnCount:["webkit"],columnGap:["webkit"],columnRule:["webkit"],columnWidth:["webkit"],boxSizing:["webkit"],appearance:["webkit","moz"],filter:["webkit"],backdropFilter:["webkit"],clipPath:["webkit"],mask:["webkit"],maskImage:["webkit"],textSizeAdjust:["webkit","ms"],hyphens:["webkit","ms"],writingMode:["webkit","ms"],gridTemplateColumns:["ms"],gridTemplateRows:["ms"],gridAutoColumns:["ms"],gridAutoRows:["ms"],gridColumn:["ms"],gridRow:["ms"],marginInlineStart:["webkit"],marginInlineEnd:["webkit"],paddingInlineStart:["webkit"],paddingInlineEnd:["webkit"],minInlineSize:["webkit"],maxInlineSize:["webkit"],minBlockSize:["webkit"],maxBlockSize:["webkit"],inlineSize:["webkit"],blockSize:["webkit"],tabSize:["moz"],overscrollBehavior:["webkit","ms"],touchAction:["ms"],resize:["webkit"],printColorAdjust:["webkit"],backgroundClip:["webkit"],boxDecorationBreak:["webkit"],overflowScrolling:["webkit"]};var $=["viewBox","preserveAspectRatio","gradientTransform","gradientUnits","spreadMethod","markerStart","markerMid","markerEnd","markerHeight","markerWidth","markerUnits","refX","refY","patternContentUnits","patternTransform","patternUnits","filterUnits","primitiveUnits","kernelUnitLength","clipPathUnits","maskContentUnits","maskUnits"];var M=class{constructor(e,t,s){this.parent=s,this.isBoolean=w.includes(e),$.includes(e)?this.name=e:this.name=C(e),this.value=void 0,this.set(t)}render(){if(!this.parent||!this.parent.domElement)return;let e=this.parent.domElement,t=["value"];this.isBoolean?this.value===!1||this.value==null?e.removeAttribute(this.name):e.setAttribute(this.name,this.value===!0?"":this.value):this.value==null?e.removeAttribute(this.name):t.includes(this.name)?e[this.name]=this.value:e.setAttribute(this.name,this.value)}set(e){if(e==null){this.value=null,this.render();return}if(typeof e=="string"&&/<\/?[a-z][\s\S]*>/i.test(e))this.value=A(e);else if(typeof e=="function"){let t=()=>{t&&(this.value=this.isBoolean?!!e():e(),this.render())};t.elementNode=this.parent,t.onSubscribe=s=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{s(),t=null})},this.value=this.isBoolean?!!e(t):e(t)}else this.value=this.isBoolean?!!e:e;this.render()}remove(){this.parent&&this.parent.attributes&&this.parent.attributes.remove(this.name),this._dispose()}_dispose(){this.value=null,this.parent=null}generateHTML(){let{name:e,value:t}=this;if(this.isBoolean)return t?`${e}`:"";{let s=Array.isArray(t)?JSON.stringify(t):t;return`${e}="${A(String(s))}"`}}};var x=class{constructor(e){this._notifier=new v;this.items={};this.parent=e}generateHTML(){if(!this.items)return"";let e=Object.values(this.items).map(t=>t.generateHTML()).join(" ");return e?` ${e}`:""}get(e){var t;if(this.items)return(t=this.items[e])==null?void 0:t.value}set(e,t){!this.items||!this.parent||(this.items[e]?(this.items[e].set(t),this.parent.domElement&&this._notifier.notify(e,this.items[e].value)):this.items[e]=new M(e,t,this.parent))}onChange(e,t){var s;if(this.has(e)&&((s=this.parent)!=null&&s.domElement)){let i=t;i.onSubscribe=n=>{var r;return(r=this.parent)==null?void 0:r.addHook("BeforeRemove",n)},this._notifier.addListener(e,i)}}has(e){return this.items?Object.prototype.hasOwnProperty.call(this.items,e):!1}remove(e){this.items&&(this.items[e]&&(this.items[e]._dispose(),delete this.items[e]),this.parent&&this.parent.domElement&&this.parent.domElement instanceof Element&&this.parent.domElement.removeAttribute(e))}_dispose(){if(this.items)for(let e in this.items)this.items[e]._dispose();this._notifier._dispose(),this.items=null,this.parent=null}toggle(e,t){if(!w.includes(e))throw Error(`${e} is not a boolean attribute`);t===!0?this.set(e,!0):t===!1?this.remove(e):this.has(e)?this.remove(e):this.set(e,!0)}addClass(e){if(!e||typeof e!="string")return;let t=(i,n)=>{let r=(i||"").split(" ").filter(l=>l);return!r.includes(n)&&r.push(e),r.join(" ")},s=this.get("class");typeof s=="function"?this.set("class",()=>t(s(),e)):this.set("class",t(s,e))}hasClass(e){return!e||typeof e!="string"?!1:(this.get("class")||"").split(" ").filter(i=>i).includes(e)}toggleClass(e){!e||typeof e!="string"||(this.hasClass(e)?this.removeClass(e):this.addClass(e))}removeClass(e){if(!e||typeof e!="string")return;let i=(this.get("class")||"").split(" ").filter(n=>n).filter(n=>n!==e);i.length>0?this.set("class",i.join(" ")):this.remove("class")}replaceClass(e,t){!e||!t||typeof e!="string"||typeof t!="string"||this.hasClass(e)&&(this.removeClass(e),this.addClass(t))}};var L=class{constructor(e,t){this.type="TextNode";this.parent=t,this.text=e===""?"\u200B":String(e)}_createDOMNode(){let e;if(K(this.text)){let t=document.createElement("template");t.innerHTML=this.text.trim(),e=t.content.firstChild||document.createTextNode("")}else e=document.createTextNode(this.text);return this.domText=e,e}_dispose(){this.domText=void 0,this.text=""}generateHTML(){return this.text==="\u200B"?"&#8203;":this.text}render(e){let t=this._createDOMNode();e.appendChild(t)}};var T=class{constructor(e){this.items=[];this.owner=e}_createNode(e,t=0){return typeof e=="object"&&e!==null?new m(e,this.owner,t):new L(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,i=e instanceof m?e.domElement:e.domText;if(i){let n=s.childNodes[t]||null;i!==n&&s.insertBefore(i,n)}}_swapDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,i=e instanceof m?e.domElement:e.domText,n=t instanceof m?t.domElement:t.domText;if(!i||!n)return;let r=i.nextSibling,l=n.nextSibling;s.insertBefore(i,l),s.insertBefore(n,r)}update(e,t=!0,s=!1){var r,l,h,c;let i=this.items.slice(),n=new Map;for(let a of i)a instanceof m&&a.key!==null&&a.key!==void 0&&n.set(a.key,a);!s&&this.owner.domElement&&((l=(r=this.owner._hooks)==null?void 0:r.BeforeUpdate)==null||l.call(r,this.owner,e));for(let a=0;a<e.length;a++){let f=e[a],u=typeof f=="object"&&f!==null?f._key:void 0;if(u!==void 0){let d=n.get(u);if(d){n.delete(u);let _=this.items.indexOf(d);if(_!==a&&_>=0){let H=d instanceof m&&!!d._portal;this.move(_,a,H?!1:t,!0)}d.parent=this.owner;continue}}this.insert(f,a,t,!0)}for(;this.items.length>e.length;)this.remove(this.items[this.items.length-1],t,!0);n.forEach(a=>this.remove(a,t,!0)),s||(c=(h=this.owner._hooks)==null?void 0:h.Update)==null||c.call(h,this.owner)}insert(e,t,s=!0,i=!1){var h,c;let n=this.items.length,r=typeof t!="number"||isNaN(t)||t<0||t>n?n:t,l=this._createNode(e,r);if(this.items.splice(r,0,l),l instanceof m){l._hooks.Insert&&l._hooks.Insert(l);let a=this.owner.domElement;if(s&&a)if(l._portal){let f=l._portal(this.owner.getRoot());f&&l.render(f)}else{let f=l._createDOMNode(),u=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,u);let d=a.getRootNode(),H=(d instanceof ShadowRoot?d:document.head).querySelector("#domphy-style");l.styles.render(H),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(k=>{if(k instanceof m&&k._portal){let D=k._portal(k.getRoot());D&&k.render(D)}else k.render(f)})}}else{let a=this.owner.domElement;if(s&&a){let f=l._createDOMNode(),u=(c=a.childNodes[r])!=null?c:null;a.insertBefore(f,u)}}return!i&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner),l}remove(e,t=!0,s=!1){let i=this.items.indexOf(e);if(!(i<0)){if(e instanceof m){let n=()=>{var l,h;let r=e.domElement;this.items.splice(i,1),t&&r&&r.remove(),(h=(l=e._hooks)==null?void 0:l.Remove)==null||h.call(l,e),e._dispose()};e._hooks&&e._hooks.BeforeRemove&&e.domElement?e._hooks.BeforeRemove(e,n):n()}else{let n=e.domText;this.items.splice(i,1),t&&n&&n.remove(),e._dispose()}!s&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}}clear(e=!0,t=!1){if(this.items.length===0)return;let s=this.items.slice();for(let i of s)this.remove(i,e,!0);!t&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}_dispose(){this.items=[]}swap(e,t,s=!0,i=!1){if(e<0||t<0||e>=this.items.length||t>=this.items.length||e===t)return;let n=this.items[e],r=this.items[t];this.items[e]=r,this.items[t]=n,s&&this._swapDomElement(n,r),!i&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}move(e,t,s=!0,i=!1){if(e<0||e>=this.items.length||t<0||t>=this.items.length||e===t)return;let n=this.items[e];this.items.splice(e,1),this.items.splice(t,0,n),s&&this._moveDomElement(n,t),!i&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}generateHTML(){let e="";for(let t of this.items)e+=t.generateHTML();return e}};var j=class{constructor(e,t,s){this.value="";this.name=e,this.cssName=C(e),this.parentRule=s,this.set(t)}_domUpdate(){if(!this.parentRule)return;let e=this.parentRule.domRule;if(e&&e.style){let t=e.style;t.setProperty(this.cssName,String(this.value)),b[this.name]&&b[this.name].forEach(s=>{t.setProperty(`-${s}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){if(typeof e=="function"){let t=()=>{t&&(this.value=e(t),this._domUpdate())};t.onSubscribe=s=>{var i;(i=this.parentRule.parentNode)==null||i.addHook("BeforeRemove",()=>{s(),t=null})},t.elementNode=this.parentRule.root,this.value=e(t)}else this.value=e;this._domUpdate()}remove(){if(this.parentRule){if(this.parentRule.domRule instanceof CSSStyleRule){let e=this.parentRule.domRule.style;e.removeProperty(this.cssName),b[this.name]&&b[this.name].forEach(t=>{e.removeProperty(`-${t}-${this.cssName}`)})}delete this.parentRule.styleBlock[this.name],this._dispose()}}cssText(){let e=`${this.cssName}: ${this.value}`;return b[this.name]&&b[this.name].forEach(t=>{e+=`; -${t}-${this.cssName}: ${this.value}`}),e}};var p=class o{constructor(e,t){this.domRule=null;this.styleBlock={};this.selectorText=e,this.styleList=new S(this),this.parent=t}_dispose(){if(this.styleBlock)for(let e of Object.values(this.styleBlock))e._dispose();this.styleList&&this.styleList._dispose(),this.styleBlock=null,this.styleList=null,this.domRule=null,this.parent=null}get root(){let e=this.parent;for(;e instanceof o;)e=e.parent;return e}get parentNode(){let e=this.parent;for(;e&&e instanceof o;)e=e.parent;return e}insertStyle(e,t){this.styleBlock&&(this.styleBlock[e]?this.styleBlock[e].set(t):this.styleBlock[e]=new j(e,t,this))}removeStyle(e){this.styleBlock&&this.styleBlock[e]&&this.styleBlock[e].remove()}cssText(){if(!this.styleBlock||!this.styleList)return"";let e=Object.values(this.styleBlock).map(s=>s.cssText()).join(";"),t=this.styleList.cssText();return`${this.selectorText} { ${e} ${t} } `}mount(e){!e||!this.styleList||(this.domRule=e,"cssRules"in e&&this.styleList.mount(e.cssRules))}remove(){if(this.domRule&&this.domRule.parentStyleSheet){let e=this.domRule.parentStyleSheet,t=e.cssRules;for(let s=0;s<t.length;s++)if(t[s]===this.domRule){e.deleteRule(s);break}}this._dispose()}render(e){if(!this.styleBlock||!this.styleList)return;let t=Object.values(this.styleBlock).map(s=>s.cssText()).join(";");try{if(this.selectorText.startsWith("@")){if(/^@(media|supports|container|layer)\b/.test(this.selectorText)){let s=e.insertRule(`${this.selectorText} {}`,e.cssRules.length),i=e.cssRules[s];"cssRules"in i&&(this.mount(i),this.styleList.render(i))}else if(this.selectorText.startsWith("@keyframes")||this.selectorText.startsWith("@font-face")){let s=this.cssText(),i=e.insertRule(s,e.cssRules.length),n=e.cssRules[i];this.mount(n)}}else{let s=`${this.selectorText} { ${t} }`,i=e.insertRule(s,e.cssRules.length),n=e.cssRules[i];n&&"selectorText"in n&&this.mount(n)}}catch(s){console.warn("Failed to insert rule:",this.selectorText,s)}}};var S=class{constructor(e){this.items=[];this.domStyle=null;this.parent=e}get parentNode(){let e=this.parent;for(;e&&e instanceof p;)e=e.parent;return e}addCSS(e,t=""){if(!this.items||!this.parent)return;let s={};function i(n,r){return n.startsWith("&")?`${r}${n.slice(1)}`:`${r} ${n}`}for(let n in e){let r=e[n],l=W(n);for(let h of l){let c=i(h,t);if(/^@(container|layer|supports|media)\b/.test(h)){if(typeof r=="object"&&r!=null){let a=new p(h,this.parent);a.styleList.addCSS(r,t),this.items.push(a)}}else if(h.startsWith("@keyframes")){let a=new p(h,this.parent);a.styleList.addCSS(r,""),this.items.push(a)}else if(h.startsWith("@font-face")){let a=new p(h,this.parent);for(let f in r)a.insertStyle(f,r[f]);this.items.push(a)}else if(typeof r=="object"&&r!=null){let a=new p(c,this.parent);this.items.push(a);for(let[f,u]of Object.entries(r))if(typeof u=="object"&&u!=null){let d=i(f,c);f.startsWith("&")?this.addCSS(u,d):a.styleList.insertRule(d).styleList.addCSS(u,d)}else a.insertStyle(f,u)}else s[h]=r}}if(Object.keys(s).length){let n=new p(t,this.parent);for(let r in s)n.insertStyle(r,s[r]);this.items.push(n)}}cssText(){return this.items?this.items.map(e=>e.cssText()).join(""):""}insertRule(e){if(!this.items||!this.parent)return null;let t=this.items.find(s=>s.selectorText===e);return t||(t=new p(e,this.parent),this.items.push(t)),t}mount(e){if(!this.items)return;if(!e)throw Error("Require domRuleList argument");let t=0,s=i=>i.replace("(odd)","(2n+1)").replace("(even)","(2n)");this.items.forEach((i,n)=>{let r=n-t,l=e[r];l&&(i.selectorText.startsWith("@")&&l instanceof CSSKeyframesRule||"keyText"in l?i.mount(l):"selectorText"in l?l.selectorText!==s(i.selectorText)?t+=1:i.mount(l):"cssRules"in l&&i.mount(l))})}render(e){e instanceof HTMLStyleElement?(this.domStyle=e,this.items.forEach(t=>t.render(e.sheet))):e instanceof CSSGroupingRule&&this.items.forEach(t=>t.render(e))}_dispose(){if(this.items)for(let e=0;e<this.items.length;e++)this.items[e]._dispose();this.items=[],this.parent=null,this.domStyle=null}};var m=class o{constructor(e,t=null,s=0){this.type="ElementNode";this.parent=null;this.children=new T(this);this.styles=new S(this);this.attributes=new x(this);this.domElement=null;this._hooks={};this._events=null;this._context={};this._metadata={};this.key=null;var l,h;e=y(e),B(e),e.style=e.style||{},this.parent=t,this.tagName=V(e),e=O(e),this.key=(l=e._key)!=null?l:null,this._context=e._context||{},this._metadata=e._metadata||{};let i=`${(h=this.parent)==null?void 0:h.getPath()}.${s}`,n=JSON.stringify(e.style||{},(c,a)=>typeof a=="function"?i:a);this.nodeId=N(i+n),this.attributes.addClass(`${this.tagName}_${this.nodeId}`),e._onSchedule&&e._onSchedule(this,e),this.merge(e);let r=e[this.tagName];if(r!=null&&r!=null)if(typeof r=="function"){let c=()=>{let a=r(c);this.children.update(Array.isArray(a)?a:[a])};c.elementNode=this,c.onSubscribe=a=>this.addHook("BeforeRemove",()=>{a(),c=null}),c&&c()}else this.children.update(Array.isArray(r)?r:[r]);this._hooks.Init&&this._hooks.Init(this)}_createDOMNode(){let s=["svg","circle","path","rect","ellipse","line","polyline","polygon","g","defs","use","symbol","linearGradient","radialGradient","stop","clipPath","mask","filter","text","tspan","textPath","image","pattern","marker","animate","animateTransform","animateMotion","feGaussianBlur","feComposite","feColorMatrix","feMerge","feMergeNode","feOffset","feFlood","feBlend","foreignObject"].includes(this.tagName)?document.createElementNS("http://www.w3.org/2000/svg",this.tagName):document.createElement(this.tagName);if(this.domElement=s,this._events)for(let i in this._events){let n=i,r=this._events[n],l=h=>r(h,this);s.addEventListener(n,l),this.addHook("BeforeRemove",h=>{h.domElement.removeEventListener(n,l),l=null})}return this.attributes&&Object.values(this.attributes.items).forEach(i=>i.render()),s}_dispose(){this.children&&this.children._dispose(),this.styles&&(this.styles.items.forEach(e=>e.remove()),this.styles._dispose()),this.attributes&&this.attributes._dispose(),this.domElement=null,this._hooks={},this._events=null,this._context={},this._metadata={},this.parent=null}get pathId(){return N(this.getPath())}merge(e){g(this._context,e._context),g(this._metadata,e._metadata);let t=Object.keys(e);for(let s=0;s<t.length;s++){let i=t[s],n=e[i];["$","_onSchedule","_key","_context","_metadata","style",this.tagName].includes(i)||(["_onInit","_onInsert","_onMount","_onBeforeUpdate","_onUpdate","_onBeforeRemove","_onRemove"].includes(i)?this.addHook(i.substring(3),n):i.startsWith("on")?this.addEvent(i.substring(2).toLowerCase(),n):i=="_portal"?this._portal=n:i=="class"&&typeof n=="string"?this.attributes.addClass(n):this.attributes.set(i,n))}e.style&&this.styles.addCSS(e.style||{},`.${`${this.tagName}_${this.nodeId}`}`)}getPath(){let e=[],t=this;for(;t&&t.parent;){let s=t.parent,i=s.children.items.indexOf(t);e.push(i),t=s}return e.reverse().join(".")}addEvent(e,t){this._events=this._events||{};let s=this._events[e];typeof s=="function"?this._events[e]=(i,n)=>{s(i,n),t(i,n)}:this._events[e]=t}addHook(e,t){let s=this._hooks[e];typeof s=="function"?this._hooks[e]=((...i)=>{s(...i),t(...i)}):this._hooks[e]=t}getRoot(){let e=this;for(;e&&e instanceof o&&e.parent;)e=e.parent;return e}getContext(e){let t=this;for(;t&&(!t._context||!Object.prototype.hasOwnProperty.call(t._context,e));)t=t.parent;return t&&t._context?t._context[e]:void 0}setContext(e,t){this._context=this._context||{},this._context[e]=t}getMetadata(e){return this._metadata?this._metadata[e]:void 0}setMetadata(e,t){this._metadata=this._metadata||{},this._metadata[e]=t}generateCSS(){if(!this.styles||!this.children)return"";let e=this.styles.cssText();return e+=this.children.items.map(t=>t instanceof o?t.generateCSS():"").join(""),e}generateHTML(){if(!this.children||!this.attributes)return"";let e=this.children.generateHTML(),t=this.attributes.generateHTML();return`<${this.tagName}${t}>${e}</${this.tagName}>`}mount(e,t){if(!e)throw new Error("Missing dom node on bind");if(this.domElement=e,this._events)for(let s in this._events){let i=s,n=this._events[i],r=l=>n(l,this);e.addEventListener(i,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(i,r),r=null})}this.children&&this.children.items.forEach((s,i)=>{let n=e.childNodes[i];n instanceof Node&&s instanceof o&&s.mount(n,t)}),this._hooks.Mount&&this._hooks.Mount(this)}render(e,t=null){let s=this._createDOMNode();e.appendChild(s),this._hooks.Mount&&this._hooks.Mount(this),t||(t=this.getRoot().styles.domStyle);let i=e.getRootNode(),n=i instanceof ShadowRoot?i:document.head;return t||(t=n.querySelector("#domphy-style")),t||(t=document.createElement("style"),t.id="domphy-style",n.appendChild(t)),this.styles.render(t),this.children.items.forEach(r=>{if(r instanceof o&&r._portal){let l=r._portal(this.getRoot());l&&r.render(l)}else r.render(s)}),s}remove(){var e;this.parent?this.parent.children.remove(this):((e=this.domElement)==null||e.remove(),this._dispose())}};0&&(module.exports={AttributeList,BooleanAttributes,CamelAttributes,ElementList,ElementNode,HtmlTags,Notifier,PrefixCSS,State,VoidTags,hashString,merge,toState});
2
+ //# sourceMappingURL=index.cjs.map