@domphy/core 0.1.2 → 0.1.4

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/dist/index.d.cts CHANGED
@@ -194,6 +194,7 @@ type Handler = ((...args: any[]) => any) & {
194
194
  };
195
195
  type Listener = Handler & {
196
196
  elementNode: ElementNode;
197
+ debug?: string;
197
198
  };
198
199
 
199
200
  type ReactiveProperty<T> = T | ((listener: Listener) => T);
@@ -286,10 +287,14 @@ declare class ElementAttribute {
286
287
 
287
288
  declare class Notifier {
288
289
  private _listeners;
290
+ private _notifying;
291
+ private _pending;
292
+ private _scheduled;
289
293
  _dispose(): void;
290
294
  addListener(event: string, listener: Handler): () => void;
291
295
  removeListener(event: string, listener: Handler): void;
292
296
  notify(event: string, ...args: unknown[]): void;
297
+ private _flush;
293
298
  }
294
299
 
295
300
  declare class AttributeList {
@@ -329,8 +334,9 @@ type NodeItem = ElementNode | TextNode;
329
334
  declare class ElementList {
330
335
  items: NodeItem[];
331
336
  owner: ElementNode;
337
+ _nextKey: number;
332
338
  constructor(parent: ElementNode);
333
- _createNode(element: ElementInput | DomphyElement, index?: number): NodeItem;
339
+ _createNode(element: ElementInput | DomphyElement): NodeItem;
334
340
  _moveDomElement(node: NodeItem, index: number): void;
335
341
  _swapDomElement(aNode: NodeItem, bNode: NodeItem): void;
336
342
  update(inputs: ElementInput[], updateDom?: boolean, silent?: boolean): void;
@@ -408,9 +414,7 @@ declare class ElementNode {
408
414
  constructor(domphyElement: DomphyElement, _parent?: ElementNode | null, index?: number);
409
415
  _createDOMNode(): HTMLElement | SVGElement;
410
416
  _dispose(): void;
411
- get pathId(): string;
412
417
  merge(part: PartialElement): void;
413
- getPath(): string;
414
418
  addEvent(name: EventName, callback: (event: Event, node: ElementNode) => void): void;
415
419
  addHook<K extends keyof HookMap>(name: K, callback: HookMap[K]): void;
416
420
  getRoot(): ElementNode;
@@ -439,6 +443,30 @@ declare class State<T> {
439
443
  _dispose(): void;
440
444
  }
441
445
 
446
+ type ListEntry<T> = {
447
+ key: number;
448
+ state: State<T>;
449
+ };
450
+ declare class ListState<T = unknown> {
451
+ _entries: ListEntry<T>[];
452
+ _notifier: Notifier;
453
+ _nextKey: number;
454
+ constructor(items?: (T | State<T>)[]);
455
+ entries(Handler?: Handler): ListEntry<T>[];
456
+ states(Handler?: Handler): State<T>[];
457
+ keys(Handler?: Handler): number[];
458
+ _createEntry(item: T | State<T>): ListEntry<T>;
459
+ _findEntry(state: State<T>): ListEntry<T> | undefined;
460
+ insert(item: T, silent?: boolean): ListEntry<T>;
461
+ remove(state: State<T>, silent?: boolean): void;
462
+ move(from: number, to: number, silent?: boolean): void;
463
+ swap(aIndex: number, bIndex: number, silent?: boolean): void;
464
+ clear(silent?: boolean): void;
465
+ reset(silent?: boolean): void;
466
+ onChange(fn: () => void): () => void;
467
+ _dispose(): void;
468
+ }
469
+
442
470
  declare const HtmlTags: string[];
443
471
 
444
472
  declare const BooleanAttributes: readonly ["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"];
@@ -448,7 +476,8 @@ declare const PrefixCSS: Record<string, string[]>;
448
476
  declare const CamelAttributes: string[];
449
477
 
450
478
  declare function merge(source?: Record<string, any>, target?: Record<string, any>): Record<string, any>;
451
- declare function toState<T>(val: T | State<T>): State<T>;
452
479
  declare function hashString(str?: string): string;
480
+ declare function toState<T>(val: T | State<T>): State<T>;
481
+ declare function toListState<T>(val: T[] | ListState<T>): ListState<T>;
453
482
 
454
- export { AttributeList, type AttributeValue, BooleanAttributes, type CSSProperties, CamelAttributes, type DomphyElement, type ElementInput$1 as ElementInput, ElementList, ElementNode, type EventHandler, type EventHandlerMap, type EventName, type Handler, type HookMap, HtmlTags, type Listener, Notifier, type PartialElement, PrefixCSS, type PropertyHookMap, type ReactiveProperty, type Selector, State, type StyleBlock, type StyleObject, type StyleSheet, type StyleValue, type TagName, type ValueListener, type ValueOrState, type VoidTagName, VoidTags, hashString, merge, toState };
483
+ export { AttributeList, type AttributeValue, BooleanAttributes, type CSSProperties, CamelAttributes, type DomphyElement, type ElementInput$1 as ElementInput, ElementList, ElementNode, type EventHandler, type EventHandlerMap, type EventName, type Handler, type HookMap, HtmlTags, type ListEntry, ListState, type Listener, Notifier, type PartialElement, PrefixCSS, type PropertyHookMap, type ReactiveProperty, type Selector, State, type StyleBlock, type StyleObject, type StyleSheet, type StyleValue, type TagName, type ValueListener, type ValueOrState, type VoidTagName, VoidTags, hashString, merge, toListState, toState };
package/dist/index.d.ts CHANGED
@@ -194,6 +194,7 @@ type Handler = ((...args: any[]) => any) & {
194
194
  };
195
195
  type Listener = Handler & {
196
196
  elementNode: ElementNode;
197
+ debug?: string;
197
198
  };
198
199
 
199
200
  type ReactiveProperty<T> = T | ((listener: Listener) => T);
@@ -286,10 +287,14 @@ declare class ElementAttribute {
286
287
 
287
288
  declare class Notifier {
288
289
  private _listeners;
290
+ private _notifying;
291
+ private _pending;
292
+ private _scheduled;
289
293
  _dispose(): void;
290
294
  addListener(event: string, listener: Handler): () => void;
291
295
  removeListener(event: string, listener: Handler): void;
292
296
  notify(event: string, ...args: unknown[]): void;
297
+ private _flush;
293
298
  }
294
299
 
295
300
  declare class AttributeList {
@@ -329,8 +334,9 @@ type NodeItem = ElementNode | TextNode;
329
334
  declare class ElementList {
330
335
  items: NodeItem[];
331
336
  owner: ElementNode;
337
+ _nextKey: number;
332
338
  constructor(parent: ElementNode);
333
- _createNode(element: ElementInput | DomphyElement, index?: number): NodeItem;
339
+ _createNode(element: ElementInput | DomphyElement): NodeItem;
334
340
  _moveDomElement(node: NodeItem, index: number): void;
335
341
  _swapDomElement(aNode: NodeItem, bNode: NodeItem): void;
336
342
  update(inputs: ElementInput[], updateDom?: boolean, silent?: boolean): void;
@@ -408,9 +414,7 @@ declare class ElementNode {
408
414
  constructor(domphyElement: DomphyElement, _parent?: ElementNode | null, index?: number);
409
415
  _createDOMNode(): HTMLElement | SVGElement;
410
416
  _dispose(): void;
411
- get pathId(): string;
412
417
  merge(part: PartialElement): void;
413
- getPath(): string;
414
418
  addEvent(name: EventName, callback: (event: Event, node: ElementNode) => void): void;
415
419
  addHook<K extends keyof HookMap>(name: K, callback: HookMap[K]): void;
416
420
  getRoot(): ElementNode;
@@ -439,6 +443,30 @@ declare class State<T> {
439
443
  _dispose(): void;
440
444
  }
441
445
 
446
+ type ListEntry<T> = {
447
+ key: number;
448
+ state: State<T>;
449
+ };
450
+ declare class ListState<T = unknown> {
451
+ _entries: ListEntry<T>[];
452
+ _notifier: Notifier;
453
+ _nextKey: number;
454
+ constructor(items?: (T | State<T>)[]);
455
+ entries(Handler?: Handler): ListEntry<T>[];
456
+ states(Handler?: Handler): State<T>[];
457
+ keys(Handler?: Handler): number[];
458
+ _createEntry(item: T | State<T>): ListEntry<T>;
459
+ _findEntry(state: State<T>): ListEntry<T> | undefined;
460
+ insert(item: T, silent?: boolean): ListEntry<T>;
461
+ remove(state: State<T>, silent?: boolean): void;
462
+ move(from: number, to: number, silent?: boolean): void;
463
+ swap(aIndex: number, bIndex: number, silent?: boolean): void;
464
+ clear(silent?: boolean): void;
465
+ reset(silent?: boolean): void;
466
+ onChange(fn: () => void): () => void;
467
+ _dispose(): void;
468
+ }
469
+
442
470
  declare const HtmlTags: string[];
443
471
 
444
472
  declare const BooleanAttributes: readonly ["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"];
@@ -448,7 +476,8 @@ declare const PrefixCSS: Record<string, string[]>;
448
476
  declare const CamelAttributes: string[];
449
477
 
450
478
  declare function merge(source?: Record<string, any>, target?: Record<string, any>): Record<string, any>;
451
- declare function toState<T>(val: T | State<T>): State<T>;
452
479
  declare function hashString(str?: string): string;
480
+ declare function toState<T>(val: T | State<T>): State<T>;
481
+ declare function toListState<T>(val: T[] | ListState<T>): ListState<T>;
453
482
 
454
- export { AttributeList, type AttributeValue, BooleanAttributes, type CSSProperties, CamelAttributes, type DomphyElement, type ElementInput$1 as ElementInput, ElementList, ElementNode, type EventHandler, type EventHandlerMap, type EventName, type Handler, type HookMap, HtmlTags, type Listener, Notifier, type PartialElement, PrefixCSS, type PropertyHookMap, type ReactiveProperty, type Selector, State, type StyleBlock, type StyleObject, type StyleSheet, type StyleValue, type TagName, type ValueListener, type ValueOrState, type VoidTagName, VoidTags, hashString, merge, toState };
483
+ export { AttributeList, type AttributeValue, BooleanAttributes, type CSSProperties, CamelAttributes, type DomphyElement, type ElementInput$1 as ElementInput, ElementList, ElementNode, type EventHandler, type EventHandlerMap, type EventName, type Handler, type HookMap, HtmlTags, type ListEntry, ListState, type Listener, Notifier, type PartialElement, PrefixCSS, type PropertyHookMap, type ReactiveProperty, type Selector, State, type StyleBlock, type StyleObject, type StyleSheet, type StyleValue, type TagName, type ValueListener, type ValueOrState, type VoidTagName, VoidTags, hashString, merge, toListState, toState };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 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"],D=z.reduce((o,e)=>{let t=e.slice(2).toLowerCase();return o[t]=e,o},{});var H=["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 E=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 _=class{constructor(e){this._notifier=new E;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();F(o,l,r)}else if(i.startsWith("_on")){let l=i.replace("_on","");U(o,l,r)}else o[i]=r}return o}function ee(o){return o instanceof _?o:new _(o)}function B(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 U(o,e,t){let s=`_on${e}`,n=o[s];typeof n=="function"?o[s]=(...i)=>{n(...i),t(...i)}:o[s]=t}function F(o,e,t){let s=D[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&&!H.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 I(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 K(o){return Object.keys(o).find(e=>H.includes(e))}function w(o){return o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function V(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}function x(o){var t;let e=o.querySelector("#domphy-style");return e||(e=document.createElement("style"),e.id="domphy-style",o.appendChild(e)),e.dataset.domphyBase!=="true"&&((t=e.sheet)==null||t.insertRule("[hidden] { display: none !important; }",0),e.dataset.domphyBase="true"),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 re=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var T=["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 W=["viewBox","preserveAspectRatio","gradientTransform","gradientUnits","spreadMethod","markerStart","markerMid","markerEnd","markerHeight","markerWidth","markerUnits","refX","refY","patternContentUnits","patternTransform","patternUnits","filterUnits","primitiveUnits","kernelUnitLength","clipPathUnits","maskContentUnits","maskUnits"];var R=class{constructor(e,t,s){this.parent=s,this.isBoolean=T.includes(e),W.includes(e)?this.name=e:this.name=w(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 N=class{constructor(e){this._notifier=new E;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 R(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(!T.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 C=class{constructor(e,t){this.type="TextNode";this.parent=t,this.text=e===""?"\u200B":String(e)}_createDOMNode(){let e;if(I(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 M=class{constructor(e){this.items=[];this.owner=e}_createNode(e,t=0){return typeof e=="object"&&e!==null?new d(e,this.owner,t):new C(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,n=e instanceof d?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 d?e.domElement:e.domText,i=t instanceof d?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 d&&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],m=typeof f=="object"&&f!==null?f._key:void 0;if(m!==void 0){let u=i.get(m);if(u){i.delete(m);let v=this.items.indexOf(u);if(v!==a&&v>=0){let j=u instanceof d&&!!u._portal;this.move(v,a,j?!1:t,!0)}u.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 d){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(),m=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,m);let u=a.getRootNode(),v=u instanceof ShadowRoot?u:document.head,j=x(v);l.styles.render(j),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(k=>{if(k instanceof d&&k._portal){let $=k._portal(k.getRoot());$&&k.render($)}else k.render(f)})}}else{let a=this.owner.domElement;if(s&&a){let f=l._createDOMNode(),m=(c=a.childNodes[r])!=null?c:null;a.insertBefore(f,m)}}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 d){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 L=class{constructor(e,t,s){this.value="";this.name=e,this.cssName=w(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 L(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=V(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,m]of Object.entries(r))if(typeof m=="object"&&m!=null){let u=n(f,c);f.startsWith("&")?this.addCSS(m,u):a.styleList.insertRule(u).styleList.addCSS(m,u)}else a.insertStyle(f,m)}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 d=class o{constructor(e,t=null,s=0){this.type="ElementNode";this.parent=null;this.children=new M(this);this.styles=new S(this);this.attributes=new N(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=K(e),e=O(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=B(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 B(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){let t=this._createDOMNode();e.appendChild(t),this._hooks.Mount&&this._hooks.Mount(this);let s=this.getRoot().styles.domStyle,n=e.getRootNode(),i=n instanceof ShadowRoot?n:document.head;return s||(s=x(i)),this.styles.render(s),this.children.items.forEach(r=>{if(r instanceof o&&r._portal){let l=r._portal(this.getRoot());l&&r.render(l)}else r.render(t)}),t}remove(){var e;this.parent?this.parent.children.remove(this):((e=this.domElement)==null||e.remove(),this._dispose())}};export{N as AttributeList,T as BooleanAttributes,W as CamelAttributes,M as ElementList,d as ElementNode,H as HtmlTags,E as Notifier,b as PrefixCSS,_ as State,re as VoidTags,B as hashString,g as merge,ee as toState};
1
+ 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"],D=q.reduce((o,e)=>{let t=e.slice(2).toLowerCase();return o[t]=e,o},{});var B=["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 g=class{constructor(){this._listeners={};this._notifying=new Set;this._pending=new Map;this._scheduled=!1}_dispose(){if(this._listeners)for(let e in this._listeners)this._listeners[e].clear();this._listeners=null}addListener(e,t){var s;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 i=()=>this.removeListener(e,t);if(!this._listeners[e].has(t)){if(this._notifying.has(e)){let n=(s=t.debug)!=null?s:"unknown";return console.warn(`[Domphy] "${n}" re-subscribed during notification. Parent and child are tracking the same state.`),this._listeners[e].add(t),typeof t.onSubscribe=="function"&&t.onSubscribe(i),this.removeListener(e,t),i}this._listeners[e].add(t),typeof t.onSubscribe=="function"&&t.onSubscribe(i)}return i}removeListener(e,t){if(!this._listeners)return;let i=this._listeners[e];i&&i.has(t)&&(i.delete(t),i.size===0&&delete this._listeners[e])}notify(e,...t){this._listeners&&this._listeners[e]&&(this._pending.set(e,t),this._scheduled||(this._scheduled=!0,queueMicrotask(()=>{this._scheduled=!1;let i=this._pending;this._pending=new Map;for(let[s,n]of i)this._flush(s,n)})))}_flush(e,t){if(!this._listeners)return;let i=this._listeners[e];if(i){this._notifying.add(e);for(let s of[...i])if(i.has(s))try{s(...t)}catch(n){console.error(n)}this._notifying.delete(e)}}};var _=class{constructor(e){this._notifier=new g;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)}};var w=class{constructor(e=[]){this._notifier=new g,this._nextKey=0,this._entries=e.map(t=>this._createEntry(t))}entries(e){return e&&this._notifier.addListener("change",e),this._entries}states(e){return e&&this._notifier.addListener("change",e),this._entries.map(t=>t.state)}keys(e){return e&&this._notifier.addListener("change",e),this._entries.map(t=>t.key)}_createEntry(e){let t=e instanceof _?e:U(e);return{key:this._nextKey++,state:t}}_findEntry(e){return this._entries.find(t=>t.state===e)}insert(e,t=!1){let i=this._createEntry(e);return this._entries.push(i),t||this._notifier.notify("change"),i}remove(e,t=!1){let i=this._findEntry(e);if(!i)return;let s=this._entries.indexOf(i);this._entries.splice(s,1),e._dispose(),t||this._notifier.notify("change")}move(e,t,i=!1){if(e<0||t<0||e>=this._entries.length||t>=this._entries.length||e===t)return;let[s]=this._entries.splice(e,1);this._entries.splice(t,0,s),i||this._notifier.notify("change")}swap(e,t,i=!1){if(e<0||t<0||e>=this._entries.length||t>=this._entries.length||e===t)return;let s=this._entries[e];this._entries[e]=this._entries[t],this._entries[t]=s,i||this._notifier.notify("change")}clear(e=!1){this._entries.length!==0&&(this._entries.forEach(t=>t.state._dispose()),this._entries=[],e||this._notifier.notify("change"))}reset(e=!1){this._entries.sort((t,i)=>t.key-i.key),e||this._notifier.notify("change")}onChange(e){return this._notifier.addListener("change",e)}_dispose(){this._entries.forEach(e=>e.state._dispose()),this._entries=[],this._notifier._dispose()}};function b(o={},e={}){let t=["animation","transition","boxShadow","textShadow","background","fontFamily"],i=["class","rel","transform","acceptCharset","sandbox"],s=["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]=b(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(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(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(n.startsWith("on")){let l=n.replace("on","").toLowerCase();V(o,l,r)}else if(n.startsWith("_on")){let l=n.replace("_on","");F(o,l,r)}else o[n]=r}return o}function K(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 U(o){return o instanceof _?o:new _(o)}function le(o){return o instanceof w?o:new w(o)}function F(o,e,t){let i=`_on${e}`,s=o[i];typeof s=="function"?o[i]=(...n)=>{s(...n),t(...n)}:o[i]=t}function V(o,e,t){let i=D[e];if(!i)throw Error(`invalid event name "${e}"`);let s=o[i];typeof s=="function"?o[i]=(n,r)=>{s(n,r),t(n,r)}:o[i]=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 i;if(Array.isArray(o)){i=[],e.set(o,i);for(let s of o)i.push(y(s,e));return i}if(o instanceof Date)return new Date(o);if(o instanceof RegExp)return new RegExp(o);if(o instanceof Map){i=new Map,e.set(o,i);for(let[s,n]of o)i.set(y(s,e),y(n,e));return i}if(o instanceof Set){i=new Set,e.set(o,i);for(let s of o)i.add(y(s,e));return i}if(ArrayBuffer.isView(o))return new o.constructor(o);if(o instanceof ArrayBuffer)return o.slice(0);i=Object.create(t),e.set(o,i);for(let s of Reflect.ownKeys(o))i[s]=y(o[s],e);return i}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 i=0;i<t.length;i++){let s=t[i],n=o[s];if(i==0&&!B.includes(s)&&!s.includes("-")&&!e)throw Error(`key ${s} is not valid HTML tag name`);if(s=="style"&&n&&Object.prototype.toString.call(n)!=="[object Object]")throw Error('"style" must be a object');if(s=="$")o.$.forEach(r=>P(r,!0));else{if(s.startsWith("_on")&&typeof n!="function")throw Error(`hook ${s} value "${n}" must be a function `);if(s.startsWith("on")&&typeof n!="function")throw Error(`event ${s} value "${n}" must be a function `);if(s=="_portal"&&typeof n!="function")throw Error('"_portal" must be a function return HTMLElement');if(s=="_context"&&Object.prototype.toString.call(n)!=="[object Object]")throw Error('"_context" must be a object');if(s=="_metadata"&&Object.prototype.toString.call(n)!=="[object Object]")throw Error('"_metadata" must be a object');if(s=="_key"&&typeof n!="string"&&typeof n!="number")throw Error('"_key" must be a string or number')}}return!0}function W(o){return/<([a-z][\w-]*)(\s[^>]*)?>.*<\/\1>|<([a-z][\w-]*)(\s[^>]*)?\/>/i.test(o.trim())}function $(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function I(o){return Object.keys(o).find(e=>B.includes(e))}function T(o){return o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function z(o){if(o.indexOf("@")===0)return[o];for(var e=[],t=0,i=0,s="",n=0,r=o.length;n<r;n++){var l=o[n];if(l==="(")t+=1;else if(l===")")t-=1;else if(l==="[")i+=1;else if(l==="]")i-=1;else if(l===","&&!t&&!i){e.push(s.trim()),s="";continue}s+=l}return e.push(s.trim()),e}function x(o){var t;let e=o.querySelector("#domphy-style");return e||(e=document.createElement("style"),e.id="domphy-style",o.appendChild(e)),e.dataset.domphyBase!=="true"&&((t=e.sheet)==null||t.insertRule("[hidden] { display: none !important; }",0),e.dataset.domphyBase="true"),e}var A=o=>{if(Array.isArray(o.$)){let e={};return o.$.forEach(t=>b(e,A(t))),delete o.$,b(e,o),e}else return o};var ue=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var R=["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 v={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 G=["viewBox","preserveAspectRatio","gradientTransform","gradientUnits","spreadMethod","markerStart","markerMid","markerEnd","markerHeight","markerWidth","markerUnits","refX","refY","patternContentUnits","patternTransform","patternUnits","filterUnits","primitiveUnits","kernelUnitLength","clipPathUnits","maskContentUnits","maskUnits"];var N=class{constructor(e,t,i){this.parent=i,this.isBoolean=R.includes(e),G.includes(e)?this.name=e:this.name=T(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){var t,i;if(e==null){this.value=null,this.render();return}if(typeof e=="string"&&/<\/?[a-z][\s\S]*>/i.test(e))this.value=$(e);else if(typeof e=="function"){let s=()=>{s&&(this.value=this.isBoolean?!!e():e(),this.render())};s.elementNode=this.parent,s.debug=`class:${(t=this.parent)==null?void 0:t.tagName}_${(i=this.parent)==null?void 0:i.nodeId} attribute:${this.name}`,s.onSubscribe=n=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{n(),s=null})},this.value=this.isBoolean?!!e(s):e(s)}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 i=Array.isArray(t)?JSON.stringify(t):t;return`${e}="${$(String(i))}"`}}};var M=class{constructor(e){this._notifier=new g;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 N(e,t,this.parent))}onChange(e,t){var i;if(this.has(e)&&((i=this.parent)!=null&&i.domElement)){let s=t;s.onSubscribe=n=>{var r;return(r=this.parent)==null?void 0:r.addHook("BeforeRemove",n)},this._notifier.addListener(e,s)}}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(!R.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=(s,n)=>{let r=(s||"").split(" ").filter(l=>l);return!r.includes(n)&&r.push(e),r.join(" ")},i=this.get("class");typeof i=="function"?this.set("class",()=>t(i(),e)):this.set("class",t(i,e))}hasClass(e){return!e||typeof e!="string"?!1:(this.get("class")||"").split(" ").filter(s=>s).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 s=(this.get("class")||"").split(" ").filter(n=>n).filter(n=>n!==e);s.length>0?this.set("class",s.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 C=class{constructor(e,t){this.type="TextNode";this.parent=t,this.text=e===""?"\u200B":String(e)}_createDOMNode(){let e;if(W(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 L=class{constructor(e){this.items=[];this._nextKey=0;this.owner=e}_createNode(e){return typeof e=="object"&&e!==null?new m(e,this.owner,this._nextKey++):new C(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let i=this.owner.domElement,s=e instanceof m?e.domElement:e.domText;if(s){let n=i.childNodes[t]||null;s!==n&&i.insertBefore(s,n)}}_swapDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let i=this.owner.domElement,s=e instanceof m?e.domElement:e.domText,n=t instanceof m?t.domElement:t.domText;if(!s||!n)return;let r=s.nextSibling,l=n.nextSibling;i.insertBefore(s,l),i.insertBefore(n,r)}update(e,t=!0,i=!1){var r,l,h,c;let s=this.items.slice(),n=new Map;for(let a of s)a instanceof m&&a.key!==null&&a.key!==void 0&&n.set(a.key,a);!i&&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],d=typeof f=="object"&&f!==null?f._key:void 0;if(d!==void 0){let u=n.get(d);if(u){n.delete(d);let S=this.items.indexOf(u);if(S!==a&&S>=0){let H=u instanceof m&&!!u._portal;this.move(S,a,H?!1:t,!0)}u.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)),i||(c=(h=this.owner._hooks)==null?void 0:h.Update)==null||c.call(h,this.owner)}insert(e,t,i=!0,s=!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);if(this.items.splice(r,0,l),l instanceof m){l._hooks.Insert&&l._hooks.Insert(l);let a=this.owner.domElement;if(i&&a)if(l._portal){let f=l._portal(this.owner.getRoot());f&&l.render(f)}else{let f=l._createDOMNode(),d=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,d);let u=a.getRootNode(),S=u instanceof ShadowRoot?u:document.head,H=x(S);l.styles.render(H),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(k=>{if(k instanceof m&&k._portal){let O=k._portal(k.getRoot());O&&k.render(O)}else k.render(f)})}}else{let a=this.owner.domElement;if(i&&a){let f=l._createDOMNode(),d=(c=a.childNodes[r])!=null?c:null;a.insertBefore(f,d)}}return!s&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner),l}remove(e,t=!0,i=!1){let s=this.items.indexOf(e);if(!(s<0)){if(e instanceof m){let n=()=>{var l,h;let r=e.domElement;this.items.splice(s,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(s,1),t&&n&&n.remove(),e._dispose()}!i&&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 i=this.items.slice();for(let s of i)this.remove(s,e,!0);!t&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}_dispose(){this.items=[]}swap(e,t,i=!0,s=!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,i&&this._swapDomElement(n,r),!s&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}move(e,t,i=!0,s=!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),i&&this._moveDomElement(n,t),!s&&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,i){this.value="";this.name=e,this.cssName=T(e),this.parentRule=i,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)),v[this.name]&&v[this.name].forEach(i=>{t.setProperty(`-${i}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){var t,i,s,n;if(typeof e=="function"){let r=()=>{r&&(this.value=e(r),this._domUpdate())};r.onSubscribe=l=>{var h;(h=this.parentRule.parentNode)==null||h.addHook("BeforeRemove",()=>{l(),r=null})},r.elementNode=this.parentRule.root,r.debug=`class:${(i=(t=this.parentRule)==null?void 0:t.root)==null?void 0:i.tagName}_${(n=(s=this.parentRule)==null?void 0:s.root)==null?void 0:n.nodeId} style:${this.name}`,this.value=e(r)}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),v[this.name]&&v[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 v[this.name]&&v[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 E(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(i=>i.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 i=0;i<t.length;i++)if(t[i]===this.domRule){e.deleteRule(i);break}}this._dispose()}render(e){if(!this.styleBlock||!this.styleList)return;let t=Object.values(this.styleBlock).map(i=>i.cssText()).join(";");try{if(this.selectorText.startsWith("@")){if(/^@(media|supports|container|layer)\b/.test(this.selectorText)){let i=e.insertRule(`${this.selectorText} {}`,e.cssRules.length),s=e.cssRules[i];"cssRules"in s&&(this.mount(s),this.styleList.render(s))}else if(this.selectorText.startsWith("@keyframes")||this.selectorText.startsWith("@font-face")){let i=this.cssText(),s=e.insertRule(i,e.cssRules.length),n=e.cssRules[s];this.mount(n)}}else{let i=`${this.selectorText} { ${t} }`,s=e.insertRule(i,e.cssRules.length),n=e.cssRules[s];n&&"selectorText"in n&&this.mount(n)}}catch(i){console.warn("Failed to insert rule:",this.selectorText,i)}}};var E=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 i={};function s(n,r){return n.startsWith("&")?`${r}${n.slice(1)}`:`${r} ${n}`}for(let n in e){let r=e[n],l=z(n);for(let h of l){let c=s(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,d]of Object.entries(r))if(typeof d=="object"&&d!=null){let u=s(f,c);f.startsWith("&")?this.addCSS(d,u):a.styleList.insertRule(u).styleList.addCSS(d,u)}else a.insertStyle(f,d)}else i[h]=r}}if(Object.keys(i).length){let n=new p(t,this.parent);for(let r in i)n.insertStyle(r,i[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(i=>i.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,i=s=>s.replace("(odd)","(2n+1)").replace("(even)","(2n)");this.items.forEach((s,n)=>{let r=n-t,l=e[r];l&&(s.selectorText.startsWith("@")&&l instanceof CSSKeyframesRule||"keyText"in l?s.mount(l):"selectorText"in l?l.selectorText!==i(s.selectorText)?t+=1:s.mount(l):"cssRules"in l&&s.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,i=0){this.type="ElementNode";this.parent=null;this.children=new L(this);this.styles=new E(this);this.attributes=new M(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=I(e),e=A(e),this.key=(l=e._key)!=null?l:null,this._context=e._context||{},this._metadata=e._metadata||{};let s=`${(h=this.parent)==null?void 0:h.nodeId}.${i}`,n=JSON.stringify(e.style||{},(c,a)=>typeof a=="function"?s:a);this.nodeId=K(s+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.debug=`class:${this.tagName}_${this.nodeId} children`,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 i=["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=i,this._events)for(let s in this._events){let n=s,r=this._events[n],l=h=>r(h,this);i.addEventListener(n,l),this.addHook("BeforeRemove",h=>{h.domElement.removeEventListener(n,l),l=null})}return this.attributes&&Object.values(this.attributes.items).forEach(s=>s.render()),i}_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}merge(e){b(this._context,e._context),b(this._metadata,e._metadata);let t=Object.keys(e);for(let i=0;i<t.length;i++){let s=t[i],n=e[s];["$","_onSchedule","_key","_context","_metadata","style",this.tagName].includes(s)||(["_onInit","_onInsert","_onMount","_onBeforeUpdate","_onUpdate","_onBeforeRemove","_onRemove"].includes(s)?this.addHook(s.substring(3),n):s.startsWith("on")?this.addEvent(s.substring(2).toLowerCase(),n):s=="_portal"?this._portal=n:s=="class"&&typeof n=="string"?this.attributes.addClass(n):this.attributes.set(s,n))}e.style&&this.styles.addCSS(e.style||{},`.${`${this.tagName}_${this.nodeId}`}`)}addEvent(e,t){this._events=this._events||{};let i=this._events[e];typeof i=="function"?this._events[e]=(s,n)=>{i(s,n),t(s,n)}:this._events[e]=t}addHook(e,t){let i=this._hooks[e];typeof i=="function"?this._hooks[e]=((...s)=>{i(...s),t(...s)}):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 i in this._events){let s=i,n=this._events[s],r=l=>n(l,this);e.addEventListener(s,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(s,r),r=null})}this.children&&this.children.items.forEach((i,s)=>{let n=e.childNodes[s];n instanceof Node&&i instanceof o&&i.mount(n,t)}),this._hooks.Mount&&this._hooks.Mount(this)}render(e){let t=this._createDOMNode();e.appendChild(t),this._hooks.Mount&&this._hooks.Mount(this);let i=this.getRoot().styles.domStyle,s=e.getRootNode(),n=s instanceof ShadowRoot?s:document.head;return i||(i=x(n)),this.styles.render(i),this.children.items.forEach(r=>{if(r instanceof o&&r._portal){let l=r._portal(this.getRoot());l&&r.render(l)}else r.render(t)}),t}remove(){var e;this.parent?this.parent.children.remove(this):((e=this.domElement)==null||e.remove(),this._dispose())}};export{M as AttributeList,R as BooleanAttributes,G as CamelAttributes,L as ElementList,m as ElementNode,B as HtmlTags,w as ListState,g as Notifier,v as PrefixCSS,_ as State,ue as VoidTags,K as hashString,b as merge,le as toListState,U as toState};
2
2
  //# sourceMappingURL=index.js.map