@domphy/core 0.1.4 → 0.1.6

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
@@ -192,12 +192,12 @@ type VoidTagName = (typeof VoidTags)[number];
192
192
  type Handler = ((...args: any[]) => any) & {
193
193
  onSubscribe?: (release: () => void) => void;
194
194
  };
195
- type Listener = Handler & {
195
+ type Listener$1 = Handler & {
196
196
  elementNode: ElementNode;
197
197
  debug?: string;
198
198
  };
199
199
 
200
- type ReactiveProperty<T> = T | ((listener: Listener) => T);
200
+ type ReactiveProperty<T> = T | ((listener: Listener$1) => T);
201
201
  type AttributeValue = ReactiveProperty<string | boolean | number | null | undefined>;
202
202
  type StyleValue = ReactiveProperty<string | number>;
203
203
  type Selector = TagName | `.${string}` | `#${string}` | `[${string}` | `@${string}` | `*${string}`;
@@ -206,7 +206,7 @@ type StyleSheet = {
206
206
  };
207
207
  type CSSProperties = Properties;
208
208
  type StyleBlock = {
209
- [K in keyof Properties]?: ReactiveProperty<Properties[K]>;
209
+ [K in keyof Properties]?: StyleValue;
210
210
  };
211
211
  type StyleObject = StyleBlock & {
212
212
  [selector in `&${string}` | `${number}%${string}` | "from" | "to" | `@${string}`]?: StyleObject;
@@ -287,13 +287,14 @@ declare class ElementAttribute {
287
287
 
288
288
  declare class Notifier {
289
289
  private _listeners;
290
- private _notifying;
291
290
  private _pending;
292
291
  private _scheduled;
293
292
  _dispose(): void;
294
293
  addListener(event: string, listener: Handler): () => void;
295
294
  removeListener(event: string, listener: Handler): void;
296
295
  notify(event: string, ...args: unknown[]): void;
296
+ private _isCircular;
297
+ private _flushAll;
297
298
  private _flush;
298
299
  }
299
300
 
@@ -305,7 +306,7 @@ declare class AttributeList {
305
306
  generateHTML(): string;
306
307
  get(name: string): any;
307
308
  set(name: string, value: AttributeValue): void;
308
- onChange(name: string, callback: (value: string | number) => void): void;
309
+ addListener(name: string, callback: (value: string | number) => void): void;
309
310
  has(name: string): boolean;
310
311
  remove(name: string): void;
311
312
  _dispose(): void;
@@ -395,6 +396,7 @@ declare class StyleList {
395
396
  }
396
397
 
397
398
  declare class ElementNode {
399
+ _disposed: boolean;
398
400
  type: string;
399
401
  parent: ElementNode | null;
400
402
  _portal?: (root: ElementNode) => HTMLElement;
@@ -432,43 +434,37 @@ declare class ElementNode {
432
434
  type ValueListener<T> = ((_value: T) => void) & Handler;
433
435
  type ValueOrState<T> = T | State<T>;
434
436
  declare class State<T> {
437
+ readonly name: string;
435
438
  private _value;
436
439
  readonly initialValue: T;
437
440
  private _notifier;
438
- constructor(initialValue: T);
441
+ constructor(initialValue: T, name?: string);
439
442
  get(listener?: ValueListener<T>): T;
440
443
  set(newValue: T): void;
441
444
  reset(): void;
442
- onChange(listener: ValueListener<T>): () => void;
445
+ addListener(listener: ValueListener<T>): () => void;
446
+ removeListener(listener: ValueListener<T>): void;
443
447
  _dispose(): void;
444
448
  }
445
449
 
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;
450
+ type Listener = (...args: any[]) => void;
451
+ declare class RecordState<T extends Record<string, any> = Record<string, any>> {
452
+ private _notifier;
453
+ private _record;
454
+ readonly initialRecord: T;
455
+ constructor(record: T);
456
+ get<K extends keyof T>(key: K, l?: Listener): T[K];
457
+ set<K extends keyof T>(key: K, value: T[K]): void;
458
+ addListener<K extends keyof T>(key: K, fn: Listener): () => void;
459
+ removeListener<K extends keyof T>(key: K, fn: Listener): void;
460
+ reset<K extends keyof T>(key: K): void;
467
461
  _dispose(): void;
468
462
  }
469
463
 
470
464
  declare const HtmlTags: string[];
471
465
 
466
+ declare const SvgTags: string[];
467
+
472
468
  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"];
473
469
 
474
470
  declare const PrefixCSS: Record<string, string[]>;
@@ -477,7 +473,6 @@ declare const CamelAttributes: string[];
477
473
 
478
474
  declare function merge(source?: Record<string, any>, target?: Record<string, any>): Record<string, any>;
479
475
  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>;
476
+ declare function toState<T>(val: T | State<T>, name?: string): State<T>;
482
477
 
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 };
478
+ 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$1 as Listener, Notifier, type PartialElement, PrefixCSS, type PropertyHookMap, type ReactiveProperty, RecordState, type Selector, State, type StyleBlock, type StyleObject, type StyleSheet, type StyleValue, SvgTags, type TagName, type ValueListener, type ValueOrState, type VoidTagName, VoidTags, hashString, merge, toState };
package/dist/index.d.ts CHANGED
@@ -192,12 +192,12 @@ type VoidTagName = (typeof VoidTags)[number];
192
192
  type Handler = ((...args: any[]) => any) & {
193
193
  onSubscribe?: (release: () => void) => void;
194
194
  };
195
- type Listener = Handler & {
195
+ type Listener$1 = Handler & {
196
196
  elementNode: ElementNode;
197
197
  debug?: string;
198
198
  };
199
199
 
200
- type ReactiveProperty<T> = T | ((listener: Listener) => T);
200
+ type ReactiveProperty<T> = T | ((listener: Listener$1) => T);
201
201
  type AttributeValue = ReactiveProperty<string | boolean | number | null | undefined>;
202
202
  type StyleValue = ReactiveProperty<string | number>;
203
203
  type Selector = TagName | `.${string}` | `#${string}` | `[${string}` | `@${string}` | `*${string}`;
@@ -206,7 +206,7 @@ type StyleSheet = {
206
206
  };
207
207
  type CSSProperties = Properties;
208
208
  type StyleBlock = {
209
- [K in keyof Properties]?: ReactiveProperty<Properties[K]>;
209
+ [K in keyof Properties]?: StyleValue;
210
210
  };
211
211
  type StyleObject = StyleBlock & {
212
212
  [selector in `&${string}` | `${number}%${string}` | "from" | "to" | `@${string}`]?: StyleObject;
@@ -287,13 +287,14 @@ declare class ElementAttribute {
287
287
 
288
288
  declare class Notifier {
289
289
  private _listeners;
290
- private _notifying;
291
290
  private _pending;
292
291
  private _scheduled;
293
292
  _dispose(): void;
294
293
  addListener(event: string, listener: Handler): () => void;
295
294
  removeListener(event: string, listener: Handler): void;
296
295
  notify(event: string, ...args: unknown[]): void;
296
+ private _isCircular;
297
+ private _flushAll;
297
298
  private _flush;
298
299
  }
299
300
 
@@ -305,7 +306,7 @@ declare class AttributeList {
305
306
  generateHTML(): string;
306
307
  get(name: string): any;
307
308
  set(name: string, value: AttributeValue): void;
308
- onChange(name: string, callback: (value: string | number) => void): void;
309
+ addListener(name: string, callback: (value: string | number) => void): void;
309
310
  has(name: string): boolean;
310
311
  remove(name: string): void;
311
312
  _dispose(): void;
@@ -395,6 +396,7 @@ declare class StyleList {
395
396
  }
396
397
 
397
398
  declare class ElementNode {
399
+ _disposed: boolean;
398
400
  type: string;
399
401
  parent: ElementNode | null;
400
402
  _portal?: (root: ElementNode) => HTMLElement;
@@ -432,43 +434,37 @@ declare class ElementNode {
432
434
  type ValueListener<T> = ((_value: T) => void) & Handler;
433
435
  type ValueOrState<T> = T | State<T>;
434
436
  declare class State<T> {
437
+ readonly name: string;
435
438
  private _value;
436
439
  readonly initialValue: T;
437
440
  private _notifier;
438
- constructor(initialValue: T);
441
+ constructor(initialValue: T, name?: string);
439
442
  get(listener?: ValueListener<T>): T;
440
443
  set(newValue: T): void;
441
444
  reset(): void;
442
- onChange(listener: ValueListener<T>): () => void;
445
+ addListener(listener: ValueListener<T>): () => void;
446
+ removeListener(listener: ValueListener<T>): void;
443
447
  _dispose(): void;
444
448
  }
445
449
 
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;
450
+ type Listener = (...args: any[]) => void;
451
+ declare class RecordState<T extends Record<string, any> = Record<string, any>> {
452
+ private _notifier;
453
+ private _record;
454
+ readonly initialRecord: T;
455
+ constructor(record: T);
456
+ get<K extends keyof T>(key: K, l?: Listener): T[K];
457
+ set<K extends keyof T>(key: K, value: T[K]): void;
458
+ addListener<K extends keyof T>(key: K, fn: Listener): () => void;
459
+ removeListener<K extends keyof T>(key: K, fn: Listener): void;
460
+ reset<K extends keyof T>(key: K): void;
467
461
  _dispose(): void;
468
462
  }
469
463
 
470
464
  declare const HtmlTags: string[];
471
465
 
466
+ declare const SvgTags: string[];
467
+
472
468
  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"];
473
469
 
474
470
  declare const PrefixCSS: Record<string, string[]>;
@@ -477,7 +473,6 @@ declare const CamelAttributes: string[];
477
473
 
478
474
  declare function merge(source?: Record<string, any>, target?: Record<string, any>): Record<string, any>;
479
475
  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>;
476
+ declare function toState<T>(val: T | State<T>, name?: string): State<T>;
482
477
 
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 };
478
+ 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$1 as Listener, Notifier, type PartialElement, PrefixCSS, type PropertyHookMap, type ReactiveProperty, RecordState, type Selector, State, type StyleBlock, type StyleObject, type StyleSheet, type StyleValue, SvgTags, type TagName, type ValueListener, type ValueOrState, type VoidTagName, VoidTags, hashString, merge, toState };
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
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};
1
+ var Z=Object.defineProperty;var K=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var U=(o,e,t)=>e in o?Z(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,B=(o,e)=>{for(var t in e||(e={}))Q.call(e,t)&&U(o,t,e[t]);if(K)for(var t of K(e))ee.call(e,t)&&U(o,t,e[t]);return o};var te=["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"],I=te.reduce((o,e)=>{let t=e.slice(2).toLowerCase();return o[t]=e,o},{});var P=["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=[],g=class{constructor(){this._listeners={};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){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){this._listeners&&this._listeners[e]&&(this._isCircular(e)||(this._pending.set(e,{args:t,chain:[...v]}),this._scheduled||(this._scheduled=!0,queueMicrotask(()=>this._flushAll()))))}_isCircular(e){let t=v.findIndex(([i,n])=>i===this&&n===e);if(t===-1)return!1;let s=[...v.slice(t).map(([,i])=>i),e];return console.error(`[Domphy] Circular dependency detected:
2
+ ${s.join(" \u2192 ")}`),!0}_flushAll(){this._scheduled=!1;let e=this._pending;this._pending=new Map;for(let[t,{args:s,chain:i}]of e)v=i,this._flush(t,s);v=[]}_flush(e,t){if(!this._listeners)return;let s=this._listeners[e];if(s){v.push([this,e]);for(let i of[...s])if(s.has(i))try{i(...t)}catch(n){console.error(n)}v.pop()}}};var w=class{constructor(e,t=typeof e){this.name=t;this._notifier=new g;this.initialValue=e,this._value=e}get(e){return e&&this.addListener(e),this._value}set(e){this._notifier&&(this._value=e,this._notifier.notify(this.name,e))}reset(){this.set(this.initialValue)}addListener(e){return this._notifier?this._notifier.addListener(this.name,e):()=>{}}removeListener(e){this._notifier&&this._notifier.removeListener(this.name,e)}_dispose(){this._notifier&&(this._notifier._dispose(),this._notifier=null)}};function b(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]=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 d=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[d,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 d=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[d,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 d=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[d,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();W(o,l,r)}else if(n.startsWith("_on")){let l=n.replace("_on","");V(o,l,r)}else o[n]=r}return o}function F(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 fe(o,e){return o instanceof w?o:new w(o,e)}function V(o,e,t){let s=`_on${e}`,i=o[s];typeof i=="function"?o[s]=(...n)=>{i(...n),t(...n)}:o[s]=t}function W(o,e,t){let s=I[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 $(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&&!P.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=>$(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 z(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 G(o){return Object.keys(o).find(e=>P.includes(e))}function x(o){return o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function q(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}function T(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=>b(e,O(t))),delete o.$,b(e,o),e}else return o};var ye=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var J=["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"];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 _={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 X=["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,s){this.parent=s,this.isBoolean=R.includes(e),X.includes(e)?this.name=e:this.name=x(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,s;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 i=()=>{!this.parent||this.parent._disposed||(this.value=this.isBoolean?!!e():e(),this.render())};i.elementNode=this.parent,i.debug=`class:${(t=this.parent)==null?void 0:t.tagName}_${(s=this.parent)==null?void 0:s.nodeId} attribute:${this.name}`,i.onSubscribe=n=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{n(),i=null})},this.value=this.isBoolean?!!e(i):e(i)}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 C=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))}addListener(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(!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=(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 M=class{constructor(e,t){this.type="TextNode";this.parent=t,this.text=e===""?"\u200B":String(e)}_createDOMNode(){let e;if(z(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 M(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,d;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],c=typeof f=="object"&&f!==null?f._key:void 0;if(c!==void 0){let u=n.get(c);if(u){n.delete(c);let k=this.items.indexOf(u);if(k!==a&&k>=0){let H=u instanceof m&&!!u._portal;this.move(k,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)),s||(d=(h=this.owner._hooks)==null?void 0:h.Update)==null||d.call(h,this.owner)}insert(e,t,s=!0,i=!1){var h,d;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(s&&a)if(l._portal){let f=l._portal(this.owner.getRoot());f&&l.render(f)}else{let f=l._createDOMNode(),c=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,c);let u=a.getRootNode(),k=u instanceof ShadowRoot?u:document.head,H=T(k);l.styles.render(H),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(E=>{if(E instanceof m&&E._portal){let D=E._portal(E.getRoot());D&&E.render(D)}else E.render(f)})}}else{let a=this.owner.domElement;if(s&&a){let f=l._createDOMNode(),c=(d=a.childNodes[r])!=null?d:null;a.insertBefore(f,c)}}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()};if(e._hooks.BeforeRemove&&e.domElement){let r=!1,l=()=>{r||(r=!0,n())};e._hooks.BeforeRemove(e,l),r||l()}else 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.forEach(e=>e._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=x(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)),_[this.name]&&_[this.name].forEach(s=>{t.setProperty(`-${s}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){var t,s,i,n;if(typeof e=="function"){let r=(()=>{var l;!this.parentRule||(l=this.parentRule.parentNode)!=null&&l._disposed||(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:${(s=(t=this.parentRule)==null?void 0:t.root)==null?void 0:s.tagName}_${(n=(i=this.parentRule)==null?void 0:i.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),_[this.name]&&_[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 _[this.name]&&_[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=q(n);for(let h of l){let d=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(d,this.parent);this.items.push(a);for(let[f,c]of Object.entries(r))if(typeof c=="object"&&c!=null){let u=i(f,d);f.startsWith("&")?this.addCSS(c,u):a.styleList.insertRule(u).styleList.addCSS(c,u)}else a.insertStyle(f,c)}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._disposed=!1;this.type="ElementNode";this.parent=null;this.children=new L(this);this.styles=new S(this);this.attributes=new C(this);this.domElement=null;this._hooks={};this._events=null;this._context={};this._metadata={};this.key=null;var l,h;e=y(e),$(e),e.style=e.style||{},this.parent=t,this.tagName=G(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.nodeId}.${s}`,n=JSON.stringify(e.style||{},(d,a)=>typeof a=="function"?i:a);this.nodeId=F(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 d=()=>{if(this._disposed)return;let a=r(d);this.children.update(Array.isArray(a)?a:[a])};d.elementNode=this,d.debug=`class:${this.tagName}_${this.nodeId} children`,d.onSubscribe=a=>this.addHook("BeforeRemove",()=>{a(),d=null}),d&&d()}else this.children.update(Array.isArray(r)?r:[r]);this._hooks.Init&&this._hooks.Init(this)}_createDOMNode(){let t=J.includes(this.tagName)?document.createElementNS("http://www.w3.org/2000/svg",this.tagName):document.createElement(this.tagName);if(this.domElement=t,this._events)for(let s in this._events){let i=s,n=this._events[i],r=l=>n(l,this);t.addEventListener(i,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(i,r),r=null})}return this.attributes&&Object.values(this.attributes.items).forEach(s=>s.render()),t}_dispose(){this._disposed=!0,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 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}`}`)}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){let t=this._createDOMNode();e.appendChild(t),this._hooks.Mount&&this._hooks.Mount(this);let s=this.getRoot().styles.domStyle,i=e.getRootNode(),n=i instanceof ShadowRoot?i:document.head;return s||(s=T(n)),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())}};var Y=class{constructor(e){this._notifier=new g;this.initialRecord=B({},e),this._record=B({},e)}get(e,t){return t&&this._notifier.addListener(e,t),this._record[e]}set(e,t){this._record[e]=t,this._notifier.notify(e)}addListener(e,t){return this._notifier.addListener(e,t)}removeListener(e,t){this._notifier.removeListener(e,t)}reset(e){this.set(e,this.initialRecord[e])}_dispose(){this._notifier._dispose()}};export{C as AttributeList,R as BooleanAttributes,X as CamelAttributes,L as ElementList,m as ElementNode,P as HtmlTags,g as Notifier,_ as PrefixCSS,Y as RecordState,w as State,J as SvgTags,ye as VoidTags,F as hashString,b as merge,fe as toState};
2
3
  //# sourceMappingURL=index.js.map