@domphy/core 0.1.3 → 0.1.5
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/core.global.js +2 -1
- package/dist/core.global.js.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -32
- package/dist/index.d.ts +31 -32
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -192,11 +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
|
+
debug?: string;
|
|
197
198
|
};
|
|
198
199
|
|
|
199
|
-
type ReactiveProperty<T> = T | ((listener: Listener) => T);
|
|
200
|
+
type ReactiveProperty<T> = T | ((listener: Listener$1) => T);
|
|
200
201
|
type AttributeValue = ReactiveProperty<string | boolean | number | null | undefined>;
|
|
201
202
|
type StyleValue = ReactiveProperty<string | number>;
|
|
202
203
|
type Selector = TagName | `.${string}` | `#${string}` | `[${string}` | `@${string}` | `*${string}`;
|
|
@@ -286,10 +287,15 @@ declare class ElementAttribute {
|
|
|
286
287
|
|
|
287
288
|
declare class Notifier {
|
|
288
289
|
private _listeners;
|
|
290
|
+
private _pending;
|
|
291
|
+
private _scheduled;
|
|
289
292
|
_dispose(): void;
|
|
290
293
|
addListener(event: string, listener: Handler): () => void;
|
|
291
294
|
removeListener(event: string, listener: Handler): void;
|
|
292
295
|
notify(event: string, ...args: unknown[]): void;
|
|
296
|
+
private _isCircular;
|
|
297
|
+
private _flushAll;
|
|
298
|
+
private _flush;
|
|
293
299
|
}
|
|
294
300
|
|
|
295
301
|
declare class AttributeList {
|
|
@@ -300,7 +306,7 @@ declare class AttributeList {
|
|
|
300
306
|
generateHTML(): string;
|
|
301
307
|
get(name: string): any;
|
|
302
308
|
set(name: string, value: AttributeValue): void;
|
|
303
|
-
|
|
309
|
+
addListener(name: string, callback: (value: string | number) => void): void;
|
|
304
310
|
has(name: string): boolean;
|
|
305
311
|
remove(name: string): void;
|
|
306
312
|
_dispose(): void;
|
|
@@ -329,8 +335,9 @@ type NodeItem = ElementNode | TextNode;
|
|
|
329
335
|
declare class ElementList {
|
|
330
336
|
items: NodeItem[];
|
|
331
337
|
owner: ElementNode;
|
|
338
|
+
_nextKey: number;
|
|
332
339
|
constructor(parent: ElementNode);
|
|
333
|
-
_createNode(element: ElementInput | DomphyElement
|
|
340
|
+
_createNode(element: ElementInput | DomphyElement): NodeItem;
|
|
334
341
|
_moveDomElement(node: NodeItem, index: number): void;
|
|
335
342
|
_swapDomElement(aNode: NodeItem, bNode: NodeItem): void;
|
|
336
343
|
update(inputs: ElementInput[], updateDom?: boolean, silent?: boolean): void;
|
|
@@ -389,6 +396,7 @@ declare class StyleList {
|
|
|
389
396
|
}
|
|
390
397
|
|
|
391
398
|
declare class ElementNode {
|
|
399
|
+
_disposed: boolean;
|
|
392
400
|
type: string;
|
|
393
401
|
parent: ElementNode | null;
|
|
394
402
|
_portal?: (root: ElementNode) => HTMLElement;
|
|
@@ -408,9 +416,7 @@ declare class ElementNode {
|
|
|
408
416
|
constructor(domphyElement: DomphyElement, _parent?: ElementNode | null, index?: number);
|
|
409
417
|
_createDOMNode(): HTMLElement | SVGElement;
|
|
410
418
|
_dispose(): void;
|
|
411
|
-
get pathId(): string;
|
|
412
419
|
merge(part: PartialElement): void;
|
|
413
|
-
getPath(): string;
|
|
414
420
|
addEvent(name: EventName, callback: (event: Event, node: ElementNode) => void): void;
|
|
415
421
|
addHook<K extends keyof HookMap>(name: K, callback: HookMap[K]): void;
|
|
416
422
|
getRoot(): ElementNode;
|
|
@@ -428,43 +434,37 @@ declare class ElementNode {
|
|
|
428
434
|
type ValueListener<T> = ((_value: T) => void) & Handler;
|
|
429
435
|
type ValueOrState<T> = T | State<T>;
|
|
430
436
|
declare class State<T> {
|
|
437
|
+
readonly name: string;
|
|
431
438
|
private _value;
|
|
432
439
|
readonly initialValue: T;
|
|
433
440
|
private _notifier;
|
|
434
|
-
constructor(initialValue: T);
|
|
441
|
+
constructor(initialValue: T, name?: string);
|
|
435
442
|
get(listener?: ValueListener<T>): T;
|
|
436
443
|
set(newValue: T): void;
|
|
437
444
|
reset(): void;
|
|
438
|
-
|
|
445
|
+
addListener(listener: ValueListener<T>): () => void;
|
|
446
|
+
removeListener(listener: ValueListener<T>): void;
|
|
439
447
|
_dispose(): void;
|
|
440
448
|
}
|
|
441
449
|
|
|
442
|
-
type
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
keys(Handler?: Handler): number[];
|
|
454
|
-
_createEntry(item: T | State<T>): ListEntry<T>;
|
|
455
|
-
_findEntry(state: State<T>): ListEntry<T> | undefined;
|
|
456
|
-
insert(item: T, silent?: boolean): ListEntry<T>;
|
|
457
|
-
remove(state: State<T>, silent?: boolean): void;
|
|
458
|
-
move(from: number, to: number, silent?: boolean): void;
|
|
459
|
-
swap(aIndex: number, bIndex: number, silent?: boolean): void;
|
|
460
|
-
clear(silent?: boolean): void;
|
|
461
|
-
reset(silent?: boolean): void;
|
|
462
|
-
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;
|
|
463
461
|
_dispose(): void;
|
|
464
462
|
}
|
|
465
463
|
|
|
466
464
|
declare const HtmlTags: string[];
|
|
467
465
|
|
|
466
|
+
declare const SvgTags: string[];
|
|
467
|
+
|
|
468
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"];
|
|
469
469
|
|
|
470
470
|
declare const PrefixCSS: Record<string, string[]>;
|
|
@@ -473,7 +473,6 @@ declare const CamelAttributes: string[];
|
|
|
473
473
|
|
|
474
474
|
declare function merge(source?: Record<string, any>, target?: Record<string, any>): Record<string, any>;
|
|
475
475
|
declare function hashString(str?: string): string;
|
|
476
|
-
declare function toState<T>(val: T | State<T
|
|
477
|
-
declare function toListState<T>(val: T[] | ListState<T>): ListState<T>;
|
|
476
|
+
declare function toState<T>(val: T | State<T>, name?: string): State<T>;
|
|
478
477
|
|
|
479
|
-
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
|
|
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,11 +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
|
+
debug?: string;
|
|
197
198
|
};
|
|
198
199
|
|
|
199
|
-
type ReactiveProperty<T> = T | ((listener: Listener) => T);
|
|
200
|
+
type ReactiveProperty<T> = T | ((listener: Listener$1) => T);
|
|
200
201
|
type AttributeValue = ReactiveProperty<string | boolean | number | null | undefined>;
|
|
201
202
|
type StyleValue = ReactiveProperty<string | number>;
|
|
202
203
|
type Selector = TagName | `.${string}` | `#${string}` | `[${string}` | `@${string}` | `*${string}`;
|
|
@@ -286,10 +287,15 @@ declare class ElementAttribute {
|
|
|
286
287
|
|
|
287
288
|
declare class Notifier {
|
|
288
289
|
private _listeners;
|
|
290
|
+
private _pending;
|
|
291
|
+
private _scheduled;
|
|
289
292
|
_dispose(): void;
|
|
290
293
|
addListener(event: string, listener: Handler): () => void;
|
|
291
294
|
removeListener(event: string, listener: Handler): void;
|
|
292
295
|
notify(event: string, ...args: unknown[]): void;
|
|
296
|
+
private _isCircular;
|
|
297
|
+
private _flushAll;
|
|
298
|
+
private _flush;
|
|
293
299
|
}
|
|
294
300
|
|
|
295
301
|
declare class AttributeList {
|
|
@@ -300,7 +306,7 @@ declare class AttributeList {
|
|
|
300
306
|
generateHTML(): string;
|
|
301
307
|
get(name: string): any;
|
|
302
308
|
set(name: string, value: AttributeValue): void;
|
|
303
|
-
|
|
309
|
+
addListener(name: string, callback: (value: string | number) => void): void;
|
|
304
310
|
has(name: string): boolean;
|
|
305
311
|
remove(name: string): void;
|
|
306
312
|
_dispose(): void;
|
|
@@ -329,8 +335,9 @@ type NodeItem = ElementNode | TextNode;
|
|
|
329
335
|
declare class ElementList {
|
|
330
336
|
items: NodeItem[];
|
|
331
337
|
owner: ElementNode;
|
|
338
|
+
_nextKey: number;
|
|
332
339
|
constructor(parent: ElementNode);
|
|
333
|
-
_createNode(element: ElementInput | DomphyElement
|
|
340
|
+
_createNode(element: ElementInput | DomphyElement): NodeItem;
|
|
334
341
|
_moveDomElement(node: NodeItem, index: number): void;
|
|
335
342
|
_swapDomElement(aNode: NodeItem, bNode: NodeItem): void;
|
|
336
343
|
update(inputs: ElementInput[], updateDom?: boolean, silent?: boolean): void;
|
|
@@ -389,6 +396,7 @@ declare class StyleList {
|
|
|
389
396
|
}
|
|
390
397
|
|
|
391
398
|
declare class ElementNode {
|
|
399
|
+
_disposed: boolean;
|
|
392
400
|
type: string;
|
|
393
401
|
parent: ElementNode | null;
|
|
394
402
|
_portal?: (root: ElementNode) => HTMLElement;
|
|
@@ -408,9 +416,7 @@ declare class ElementNode {
|
|
|
408
416
|
constructor(domphyElement: DomphyElement, _parent?: ElementNode | null, index?: number);
|
|
409
417
|
_createDOMNode(): HTMLElement | SVGElement;
|
|
410
418
|
_dispose(): void;
|
|
411
|
-
get pathId(): string;
|
|
412
419
|
merge(part: PartialElement): void;
|
|
413
|
-
getPath(): string;
|
|
414
420
|
addEvent(name: EventName, callback: (event: Event, node: ElementNode) => void): void;
|
|
415
421
|
addHook<K extends keyof HookMap>(name: K, callback: HookMap[K]): void;
|
|
416
422
|
getRoot(): ElementNode;
|
|
@@ -428,43 +434,37 @@ declare class ElementNode {
|
|
|
428
434
|
type ValueListener<T> = ((_value: T) => void) & Handler;
|
|
429
435
|
type ValueOrState<T> = T | State<T>;
|
|
430
436
|
declare class State<T> {
|
|
437
|
+
readonly name: string;
|
|
431
438
|
private _value;
|
|
432
439
|
readonly initialValue: T;
|
|
433
440
|
private _notifier;
|
|
434
|
-
constructor(initialValue: T);
|
|
441
|
+
constructor(initialValue: T, name?: string);
|
|
435
442
|
get(listener?: ValueListener<T>): T;
|
|
436
443
|
set(newValue: T): void;
|
|
437
444
|
reset(): void;
|
|
438
|
-
|
|
445
|
+
addListener(listener: ValueListener<T>): () => void;
|
|
446
|
+
removeListener(listener: ValueListener<T>): void;
|
|
439
447
|
_dispose(): void;
|
|
440
448
|
}
|
|
441
449
|
|
|
442
|
-
type
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
keys(Handler?: Handler): number[];
|
|
454
|
-
_createEntry(item: T | State<T>): ListEntry<T>;
|
|
455
|
-
_findEntry(state: State<T>): ListEntry<T> | undefined;
|
|
456
|
-
insert(item: T, silent?: boolean): ListEntry<T>;
|
|
457
|
-
remove(state: State<T>, silent?: boolean): void;
|
|
458
|
-
move(from: number, to: number, silent?: boolean): void;
|
|
459
|
-
swap(aIndex: number, bIndex: number, silent?: boolean): void;
|
|
460
|
-
clear(silent?: boolean): void;
|
|
461
|
-
reset(silent?: boolean): void;
|
|
462
|
-
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;
|
|
463
461
|
_dispose(): void;
|
|
464
462
|
}
|
|
465
463
|
|
|
466
464
|
declare const HtmlTags: string[];
|
|
467
465
|
|
|
466
|
+
declare const SvgTags: string[];
|
|
467
|
+
|
|
468
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"];
|
|
469
469
|
|
|
470
470
|
declare const PrefixCSS: Record<string, string[]>;
|
|
@@ -473,7 +473,6 @@ declare const CamelAttributes: string[];
|
|
|
473
473
|
|
|
474
474
|
declare function merge(source?: Record<string, any>, target?: Record<string, any>): Record<string, any>;
|
|
475
475
|
declare function hashString(str?: string): string;
|
|
476
|
-
declare function toState<T>(val: T | State<T
|
|
477
|
-
declare function toListState<T>(val: T[] | ListState<T>): ListState<T>;
|
|
476
|
+
declare function toState<T>(val: T | State<T>, name?: string): State<T>;
|
|
478
477
|
|
|
479
|
-
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
|
|
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"],U=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={}}_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 i=()=>this.removeListener(e,t);return this._listeners[e].has(t)||(this._listeners[e].add(t),typeof t.onSubscribe=="function"&&t.onSubscribe(i)),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){if(!this._listeners)return;let i=this._listeners[e];if(i)for(let s of[...i])try{s(...t)}catch(n){console.error(n)}}};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:K(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),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=[],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 v(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]=v(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 P(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 K(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=U[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 O(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=>O(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 A(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function z(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 G(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 $=o=>{if(Array.isArray(o.$)){let e={};return o.$.forEach(t=>v(e,$(t))),delete o.$,v(e,o),e}else return o};var me=["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 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 I=["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),I.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){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=i=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{i(),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 i=Array.isArray(t)?JSON.stringify(t):t;return`${e}="${A(String(i))}"`}}};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))}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 M=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"?"​":this.text}render(e){let t=this._createDOMNode();e.appendChild(t)}};var L=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 M(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let i=this.owner.domElement,s=e instanceof d?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 d?e.domElement:e.domText,n=t instanceof d?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 d&&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],u=typeof f=="object"&&f!==null?f._key:void 0;if(u!==void 0){let m=n.get(u);if(m){n.delete(u);let E=this.items.indexOf(m);if(E!==a&&E>=0){let H=m instanceof d&&!!m._portal;this.move(E,a,H?!1:t,!0)}m.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,r);if(this.items.splice(r,0,l),l instanceof d){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(),u=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,u);let m=a.getRootNode(),E=m instanceof ShadowRoot?m:document.head,H=x(E);l.styles.render(H),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(S=>{if(S instanceof d&&S._portal){let D=S._portal(S.getRoot());D&&S.render(D)}else S.render(f)})}}else{let a=this.owner.domElement;if(i&&a){let f=l._createDOMNode(),u=(c=a.childNodes[r])!=null?c:null;a.insertBefore(f,u)}}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 d){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)),b[this.name]&&b[this.name].forEach(i=>{t.setProperty(`-${i}-${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=i=>{var s;(s=this.parentRule.parentNode)==null||s.addHook("BeforeRemove",()=>{i(),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 k(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 k=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=G(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,u]of Object.entries(r))if(typeof u=="object"&&u!=null){let m=s(f,c);f.startsWith("&")?this.addCSS(u,m):a.styleList.insertRule(m).styleList.addCSS(u,m)}else a.insertStyle(f,u)}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 d=class o{constructor(e,t=null,i=0){this.type="ElementNode";this.parent=null;this.children=new L(this);this.styles=new k(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),O(e),e.style=e.style||{},this.parent=t,this.tagName=z(e),e=$(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.getPath()}.${i}`,n=JSON.stringify(e.style||{},(c,a)=>typeof a=="function"?s:a);this.nodeId=P(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.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}get pathId(){return P(this.getPath())}merge(e){v(this._context,e._context),v(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}`}`)}getPath(){let e=[],t=this;for(;t&&t.parent;){let i=t.parent,s=i.children.items.indexOf(t);e.push(s),t=i}return e.reverse().join(".")}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{C as AttributeList,R as BooleanAttributes,I as CamelAttributes,L as ElementList,d as ElementNode,B as HtmlTags,w as ListState,g as Notifier,b as PrefixCSS,_ as State,me as VoidTags,P as hashString,v as merge,le as toListState,K 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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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"?"​":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
|