@domphy/core 0.1.8 → 0.1.9
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 +1 -1
- package/dist/core.global.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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 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){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(([n,s])=>n===this&&s===e);if(t===-1)return!1;let i=[...v.slice(t).map(([,n])=>n),e];return console.error(`[Domphy] Circular dependency detected:
|
|
2
|
-
${i.join(" \u2192 ")}`),!0}_flushAll(){this._scheduled=!1;let e=this._pending;this._pending=new Map;for(let[t,{args:i,chain:n}]of e)v=n,this._flush(t,i);v=[]}_flush(e,t){if(!this._listeners)return;let i=this._listeners[e];if(i){v.push([this,e]);for(let n of[...i])if(i.has(n))try{n(...t)}catch(s){console.error(s)}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"],i=["class","rel","transform","acceptCharset","sandbox"],n=["content"];Object.prototype.toString.call(e)==="[object Object]"&&Object.getPrototypeOf(e)===Object.prototype&&(e=y(e));for(let s in e){let r=e[s];if(!(r==null||r===""))if(typeof r=="object"&&!Array.isArray(r))typeof o[s]=="object"?o[s]=b(o[s],r):o[s]=r;else if(t.includes(s))if(typeof o[s]=="function"||typeof r=="function"){let l=o[s];o[s]=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[s]=[o[s],r].filter(l=>l).join(", ");else if(n.includes(s))if(typeof o[s]=="function"||typeof r=="function"){let l=o[s];o[s]=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[s]=[o[s],r].filter(l=>l).join("");else if(i.includes(s))if(typeof o[s]=="function"||typeof r=="function"){let l=o[s];o[s]=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[s]=[o[s],r].filter(l=>l).join(" ");else if(s.startsWith("on")){let l=s.replace("on","").toLowerCase();W(o,l,r)}else if(s.startsWith("_on")){let l=s.replace("_on","");V(o,l,r)}else o[s]=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 de(o){return o}function V(o,e,t){let i=`_on${e}`,n=o[i];typeof n=="function"?o[i]=(...s)=>{n(...s),t(...s)}:o[i]=t}function W(o,e,t){let i=I[e];if(!i)throw Error(`invalid event name "${e}"`);let n=o[i];typeof n=="function"?o[i]=(s,r)=>{n(s,r),t(s,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 n of o)i.push(y(n,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[n,s]of o)i.set(y(n,e),y(s,e));return i}if(o instanceof Set){i=new Set,e.set(o,i);for(let n of o)i.add(y(n,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 n of Reflect.ownKeys(o))i[n]=y(o[n],e);return i}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 i=0;i<t.length;i++){let n=t[i],s=o[n];if(i==0&&!P.includes(n)&&!n.includes("-")&&!e)throw Error(`key ${n} is not valid HTML tag name`);if(n=="style"&&s&&Object.prototype.toString.call(s)!=="[object Object]")throw Error('"style" must be a object');if(n=="$")o.$.forEach(r=>$(r,!0));else{if(n.startsWith("_on")&&typeof s!="function")throw Error(`hook ${n} value "${s}" must be a function `);if(n.startsWith("on")&&typeof s!="function")throw Error(`event ${n} value "${s}" must be a function `);if(n=="_portal"&&typeof s!="function")throw Error('"_portal" must be a function return HTMLElement');if(n=="_context"&&Object.prototype.toString.call(s)!=="[object Object]")throw Error('"_context" must be a object');if(n=="_metadata"&&Object.prototype.toString.call(s)!=="[object Object]")throw Error('"_metadata" must be a object');if(n=="_key"&&typeof s!="string"&&typeof s!="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,i=0,n="",s=0,r=o.length;s<r;s++){var l=o[s];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(n.trim()),n="";continue}n+=l}return e.push(n.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 ge=["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,i){this._notifier=new g;this.parent=i,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 i,n;let t=this.value;if(e==null)this.value=null;else if(typeof e=="string"&&/<\/?[a-z][\s\S]*>/i.test(e))this.value=A(e);else if(typeof e=="function"){let s=()=>{if(!this.parent||this.parent._disposed)return;let r=this.value;this.value=this.isBoolean?!!e():e(),this.render(),r!==this.value&&this._notifier.notify(this.name,this.value)};s.elementNode=this.parent,s.debug=`class:${(i=this.parent)==null?void 0:i.tagName}_${(n=this.parent)==null?void 0:n.nodeId} attribute:${this.name}`,s.onSubscribe=r=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{r(),s=null})},this.value=this.isBoolean?!!e(s):e(s)}else this.value=this.isBoolean?!!e:e;this.render(),t!==this.value&&this._notifier.notify(this.name,this.value)}addListener(e){let t=e;t.onSubscribe=i=>{var n;return(n=this.parent)==null?void 0:n.addHook("BeforeRemove",i)},this._notifier.addListener(this.name,t)}remove(){this.parent&&this.parent.attributes&&this.parent.attributes.remove(this.name),this._dispose()}_dispose(){this._notifier._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.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.items[e]=new N(e,t,this.parent))}addListener(e,t){this.has(e)&&this.items[e].addListener(t)}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.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=(n,s)=>{let r=(n||"").split(" ").filter(l=>l);return!r.includes(s)&&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(n=>n).includes(e)}toggleClass(e){!e||typeof e!="string"||(this.hasClass(e)?this.removeClass(e):this.addClass(e))}removeClass(e){if(!e||typeof e!="string")return;let n=(this.get("class")||"").split(" ").filter(s=>s).filter(s=>s!==e);n.length>0?this.set("class",n.join(" ")):this.remove("class")}replaceClass(e,t){!e||!t||typeof e!="string"||typeof t!="string"||this.hasClass(e)&&(this.removeClass(e),this.addClass(t))}};var 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 i=this.owner.domElement,n=e instanceof m?e.domElement:e.domText;if(n){let s=i.childNodes[t]||null;n!==s&&i.insertBefore(n,s)}}_swapDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let i=this.owner.domElement,n=e instanceof m?e.domElement:e.domText,s=t instanceof m?t.domElement:t.domText;if(!n||!s)return;let r=n.nextSibling,l=s.nextSibling;i.insertBefore(n,l),i.insertBefore(s,r)}update(e,t=!0,i=!1){var r,l,h,d;let n=this.items.slice(),s=new Map;for(let a of n)a instanceof m&&a.key!==null&&a.key!==void 0&&s.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 c=s.get(u);if(c){s.delete(u);let k=this.items.indexOf(c);if(k!==a&&k>=0){let H=c instanceof m&&!!c._portal;this.move(k,a,H?!1:t,!0)}c.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);s.forEach(a=>this.remove(a,t,!0)),i||(d=(h=this.owner._hooks)==null?void 0:h.Update)==null||d.call(h,this.owner)}insert(e,t,i=!0,n=!1){var h,d;let s=this.items.length,r=typeof t!="number"||isNaN(t)||t<0||t>s?s: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(),u=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,u);let c=a.getRootNode(),k=c instanceof ShadowRoot?c: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(i&&a){let f=l._createDOMNode(),u=(d=a.childNodes[r])!=null?d:null;a.insertBefore(f,u)}}return!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner),l}remove(e,t=!0,i=!1){let n=this.items.indexOf(e);if(!(n<0)){if(e instanceof m){let s=()=>{var l,h;let r=e.domElement;this.items.splice(n,1),t&&r&&r.remove(),(h=(l=e._hooks)==null?void 0:l.Remove)==null||h.call(l,e),e._dispose()};if(e._hooks.BeforeRemove&&e.domElement){let r=!1,l=()=>{r||(r=!0,s())};e._hooks.BeforeRemove(e,l),r||l()}else s()}else{let s=e.domText;this.items.splice(n,1),t&&s&&s.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 n of i)this.remove(n,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,i=!0,n=!1){if(e<0||t<0||e>=this.items.length||t>=this.items.length||e===t)return;let s=this.items[e],r=this.items[t];this.items[e]=r,this.items[t]=s,i&&this._swapDomElement(s,r),!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}move(e,t,i=!0,n=!1){if(e<0||e>=this.items.length||t<0||t>=this.items.length||e===t)return;let s=this.items[e];this.items.splice(e,1),this.items.splice(t,0,s),i&&this._moveDomElement(s,t),!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}generateHTML(){let e="";for(let t of this.items)e+=t.generateHTML();return e}};var j=class{constructor(e,t,i){this.value="";this.name=e,this.cssName=x(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)),_[this.name]&&_[this.name].forEach(i=>{t.setProperty(`-${i}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){var t,i,n,s;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:${(i=(t=this.parentRule)==null?void 0:t.root)==null?void 0:i.tagName}_${(s=(n=this.parentRule)==null?void 0:n.root)==null?void 0:s.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(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),n=e.cssRules[i];"cssRules"in n&&(this.mount(n),this.styleList.render(n))}else if(this.selectorText.startsWith("@keyframes")||this.selectorText.startsWith("@font-face")){let i=this.cssText(),n=e.insertRule(i,e.cssRules.length),s=e.cssRules[n];this.mount(s)}}else{let i=`${this.selectorText} { ${t} }`,n=e.insertRule(i,e.cssRules.length),s=e.cssRules[n];s&&"selectorText"in s&&this.mount(s)}}catch(i){console.warn("Failed to insert rule:",this.selectorText,i)}}};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 i={};function n(s,r){return s.startsWith("&")?`${r}${s.slice(1)}`:`${r} ${s}`}for(let s in e){let r=e[s],l=q(s);for(let h of l){let d=n(h,t);if(/^@(container|layer|supports|media)\b/.test(h)){if(typeof r=="object"&&r!=null){let a=new p(h,this.parent);a.styleList.addCSS(r,t),this.items.push(a)}}else if(h.startsWith("@keyframes")){let a=new p(h,this.parent);a.styleList.addCSS(r,""),this.items.push(a)}else if(h.startsWith("@font-face")){let a=new p(h,this.parent);for(let f in r)a.insertStyle(f,r[f]);this.items.push(a)}else if(typeof r=="object"&&r!=null){let a=new p(d,this.parent);this.items.push(a);for(let[f,u]of Object.entries(r))if(typeof u=="object"&&u!=null){let c=n(f,d);f.startsWith("&")?this.addCSS(u,c):a.styleList.insertRule(c).styleList.addCSS(u,c)}else a.insertStyle(f,u)}else i[h]=r}}if(Object.keys(i).length){let s=new p(t,this.parent);for(let r in i)s.insertStyle(r,i[r]);this.items.push(s)}}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=n=>n.replace("(odd)","(2n+1)").replace("(even)","(2n)");this.items.forEach((n,s)=>{let r=s-t,l=e[r];l&&(n.selectorText.startsWith("@")&&l instanceof CSSKeyframesRule||"keyText"in l?n.mount(l):"selectorText"in l?l.selectorText!==i(n.selectorText)?t+=1:n.mount(l):"cssRules"in l&&n.mount(l))})}render(e){e instanceof HTMLStyleElement?(this.domStyle=e,this.items.forEach(t=>t.render(e.sheet))):e instanceof CSSGroupingRule&&this.items.forEach(t=>t.render(e))}_dispose(){if(this.items)for(let e=0;e<this.items.length;e++)this.items[e]._dispose();this.items=[],this.parent=null,this.domStyle=null}};var m=class o{constructor(e,t=null,i=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 n=`${(h=this.parent)==null?void 0:h.nodeId}.${i}`,s=JSON.stringify(e.style||{},(d,a)=>typeof a=="function"?n:a);this.nodeId=F(n+s),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 i in this._events){let n=i,s=this._events[n],r=l=>s(l,this);t.addEventListener(n,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(n,r),r=null})}return this.attributes&&Object.values(this.attributes.items).forEach(i=>i.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 i=0;i<t.length;i++){let n=t[i],s=e[n];["$","_onSchedule","_key","_context","_metadata","style",this.tagName].includes(n)||(["_onInit","_onInsert","_onMount","_onBeforeUpdate","_onUpdate","_onBeforeRemove","_onRemove"].includes(n)?this.addHook(n.substring(3),s):n.startsWith("on")?this.addEvent(n.substring(2).toLowerCase(),s):n=="_portal"?this._portal=s:n=="class"&&typeof s=="string"?this.attributes.addClass(s):this.attributes.set(n,s))}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]=(n,s)=>{i(n,s),t(n,s)}:this._events[e]=t}addHook(e,t){let i=this._hooks[e];typeof i=="function"?this._hooks[e]=((...n)=>{i(...n),t(...n)}):this._hooks[e]=t}getRoot(){let e=this;for(;e&&e instanceof o&&e.parent;)e=e.parent;return e}getContext(e){let t=this;for(;t&&(!t._context||!Object.prototype.hasOwnProperty.call(t._context,e));)t=t.parent;return t&&t._context?t._context[e]:void 0}setContext(e,t){this._context=this._context||{},this._context[e]=t}getMetadata(e){return this._metadata?this._metadata[e]:void 0}setMetadata(e,t){this._metadata=this._metadata||{},this._metadata[e]=t}generateCSS(){if(!this.styles||!this.children)return"";let e=this.styles.cssText();return e+=this.children.items.map(t=>t instanceof o?t.generateCSS():"").join(""),e}generateHTML(){if(!this.children||!this.attributes)return"";let e=this.children.generateHTML(),t=this.attributes.generateHTML();return`<${this.tagName}${t}>${e}</${this.tagName}>`}mount(e,t){if(!e)throw new Error("Missing dom node on bind");if(this.domElement=e,this._events)for(let i in this._events){let n=i,s=this._events[n],r=l=>s(l,this);e.addEventListener(n,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(n,r),r=null})}this.children&&this.children.items.forEach((i,n)=>{let s=e.childNodes[n];s instanceof Node&&i instanceof o&&i.mount(s,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,n=e.getRootNode(),s=n instanceof ShadowRoot?n:document.head;return i||(i=T(s)),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())}};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,ge as VoidTags,F as hashString,b as merge,de as r,fe as toState};
|
|
2
|
+
${i.join(" \u2192 ")}`),!0}_flushAll(){this._scheduled=!1;let e=this._pending;this._pending=new Map;for(let[t,{args:i,chain:n}]of e)v=n,this._flush(t,i);v=[]}_flush(e,t){if(!this._listeners)return;let i=this._listeners[e];if(i){v.push([this,e]);for(let n of[...i])if(i.has(n))try{n(...t)}catch(s){console.error(s)}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"],i=["class","rel","transform","acceptCharset","sandbox"],n=["content"];Object.prototype.toString.call(e)==="[object Object]"&&Object.getPrototypeOf(e)===Object.prototype&&(e=y(e));for(let s in e){let r=e[s];if(!(r==null||r===""))if(typeof r=="object"&&!Array.isArray(r))typeof o[s]=="object"?o[s]=b(o[s],r):o[s]=r;else if(t.includes(s))if(typeof o[s]=="function"||typeof r=="function"){let l=o[s];o[s]=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[s]=[o[s],r].filter(l=>l).join(", ");else if(n.includes(s))if(typeof o[s]=="function"||typeof r=="function"){let l=o[s];o[s]=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[s]=[o[s],r].filter(l=>l).join("");else if(i.includes(s))if(typeof o[s]=="function"||typeof r=="function"){let l=o[s];o[s]=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[s]=[o[s],r].filter(l=>l).join(" ");else if(s.startsWith("on")){let l=s.replace("on","").toLowerCase();W(o,l,r)}else if(s.startsWith("_on")){let l=s.replace("_on","");V(o,l,r)}else o[s]=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 de(o){return o}function V(o,e,t){let i=`_on${e}`,n=o[i];typeof n=="function"?o[i]=(...s)=>{n(...s),t(...s)}:o[i]=t}function W(o,e,t){let i=I[e];if(!i)throw Error(`invalid event name "${e}"`);let n=o[i];typeof n=="function"?o[i]=(s,r)=>{n(s,r),t(s,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 n of o)i.push(y(n,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[n,s]of o)i.set(y(n,e),y(s,e));return i}if(o instanceof Set){i=new Set,e.set(o,i);for(let n of o)i.add(y(n,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 n of Reflect.ownKeys(o))i[n]=y(o[n],e);return i}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 i=0;i<t.length;i++){let n=t[i],s=o[n];if(i==0&&!P.includes(n)&&!n.includes("-")&&!e)throw Error(`key ${n} is not valid HTML tag name`);if(n=="style"&&s&&Object.prototype.toString.call(s)!=="[object Object]")throw Error('"style" must be a object');if(n=="$")o.$.forEach(r=>$(r,!0));else{if(n.startsWith("_on")&&typeof s!="function")throw Error(`hook ${n} value "${s}" must be a function `);if(n.startsWith("on")&&typeof s!="function")throw Error(`event ${n} value "${s}" must be a function `);if(n=="_portal"&&typeof s!="function")throw Error('"_portal" must be a function return HTMLElement');if(n=="_context"&&Object.prototype.toString.call(s)!=="[object Object]")throw Error('"_context" must be a object');if(n=="_metadata"&&Object.prototype.toString.call(s)!=="[object Object]")throw Error('"_metadata" must be a object');if(n=="_key"&&typeof s!="string"&&typeof s!="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,i=0,n="",s=0,r=o.length;s<r;s++){var l=o[s];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(n.trim()),n="";continue}n+=l}return e.push(n.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 ge=["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,i){this._notifier=new g;this.parent=i,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 i,n;let t=this.value;if(e==null)this.value=null;else if(typeof e=="string"&&/<\/?[a-z][\s\S]*>/i.test(e))this.value=A(e);else if(typeof e=="function"){let s=()=>{if(!this.parent||this.parent._disposed)return;let r=this.value;this.value=this.isBoolean?!!e():e(),this.render(),r!==this.value&&this._notifier.notify(this.name,this.value)};s.elementNode=this.parent,s.debug=`class:${(i=this.parent)==null?void 0:i.tagName}_${(n=this.parent)==null?void 0:n.nodeId} attribute:${this.name}`,s.onSubscribe=r=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{r(),s=null})},this.value=this.isBoolean?!!e(s):e(s)}else this.value=this.isBoolean?!!e:e;this.render(),t!==this.value&&this._notifier.notify(this.name,this.value)}addListener(e){let t=e;t.onSubscribe=i=>{var n;return(n=this.parent)==null?void 0:n.addHook("BeforeRemove",i)},this._notifier.addListener(this.name,t)}remove(){this.parent&&this.parent.attributes&&this.parent.attributes.remove(this.name),this._dispose()}_dispose(){this._notifier._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.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.items[e]=new N(e,t,this.parent))}addListener(e,t){this.has(e)&&this.items[e].addListener(t)}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.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=(n,s)=>{let r=(n||"").split(" ").filter(l=>l);return!r.includes(s)&&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(n=>n).includes(e)}toggleClass(e){!e||typeof e!="string"||(this.hasClass(e)?this.removeClass(e):this.addClass(e))}removeClass(e){if(!e||typeof e!="string")return;let n=(this.get("class")||"").split(" ").filter(s=>s).filter(s=>s!==e);n.length>0?this.set("class",n.join(" ")):this.remove("class")}replaceClass(e,t){!e||!t||typeof e!="string"||typeof t!="string"||this.hasClass(e)&&(this.removeClass(e),this.addClass(t))}};var M=class{constructor(e,t){this.type="TextNode";this.parent=t;let i=t.tagName;this.text=e===""&&i!=="textarea"?"\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 i=this.owner.domElement,n=e instanceof m?e.domElement:e.domText;if(n){let s=i.childNodes[t]||null;n!==s&&i.insertBefore(n,s)}}_swapDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let i=this.owner.domElement,n=e instanceof m?e.domElement:e.domText,s=t instanceof m?t.domElement:t.domText;if(!n||!s)return;let r=n.nextSibling,l=s.nextSibling;i.insertBefore(n,l),i.insertBefore(s,r)}update(e,t=!0,i=!1){var r,l,h,d;let n=this.items.slice(),s=new Map;for(let a of n)a instanceof m&&a.key!==null&&a.key!==void 0&&s.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 c=s.get(u);if(c){s.delete(u);let k=this.items.indexOf(c);if(k!==a&&k>=0){let H=c instanceof m&&!!c._portal;this.move(k,a,H?!1:t,!0)}c.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);s.forEach(a=>this.remove(a,t,!0)),i||(d=(h=this.owner._hooks)==null?void 0:h.Update)==null||d.call(h,this.owner)}insert(e,t,i=!0,n=!1){var h,d;let s=this.items.length,r=typeof t!="number"||isNaN(t)||t<0||t>s?s: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(),u=(h=a.childNodes[r])!=null?h:null;a.insertBefore(f,u);let c=a.getRootNode(),k=c instanceof ShadowRoot?c: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(i&&a){let f=l._createDOMNode(),u=(d=a.childNodes[r])!=null?d:null;a.insertBefore(f,u)}}return!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner),l}remove(e,t=!0,i=!1){let n=this.items.indexOf(e);if(!(n<0)){if(e instanceof m){let s=()=>{var l,h;let r=e.domElement;this.items.splice(n,1),t&&r&&r.remove(),(h=(l=e._hooks)==null?void 0:l.Remove)==null||h.call(l,e),e._dispose()};if(e._hooks.BeforeRemove&&e.domElement){let r=!1,l=()=>{r||(r=!0,s())};e._hooks.BeforeRemove(e,l),r||l()}else s()}else{let s=e.domText;this.items.splice(n,1),t&&s&&s.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 n of i)this.remove(n,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,i=!0,n=!1){if(e<0||t<0||e>=this.items.length||t>=this.items.length||e===t)return;let s=this.items[e],r=this.items[t];this.items[e]=r,this.items[t]=s,i&&this._swapDomElement(s,r),!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}move(e,t,i=!0,n=!1){if(e<0||e>=this.items.length||t<0||t>=this.items.length||e===t)return;let s=this.items[e];this.items.splice(e,1),this.items.splice(t,0,s),i&&this._moveDomElement(s,t),!n&&this.owner.domElement&&this.owner._hooks.Update&&this.owner._hooks.Update(this.owner)}generateHTML(){let e="";for(let t of this.items)e+=t.generateHTML();return e}};var j=class{constructor(e,t,i){this.value="";this.name=e,this.cssName=x(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)),_[this.name]&&_[this.name].forEach(i=>{t.setProperty(`-${i}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){var t,i,n,s;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:${(i=(t=this.parentRule)==null?void 0:t.root)==null?void 0:i.tagName}_${(s=(n=this.parentRule)==null?void 0:n.root)==null?void 0:s.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(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),n=e.cssRules[i];"cssRules"in n&&(this.mount(n),this.styleList.render(n))}else if(this.selectorText.startsWith("@keyframes")||this.selectorText.startsWith("@font-face")){let i=this.cssText(),n=e.insertRule(i,e.cssRules.length),s=e.cssRules[n];this.mount(s)}}else{let i=`${this.selectorText} { ${t} }`,n=e.insertRule(i,e.cssRules.length),s=e.cssRules[n];s&&"selectorText"in s&&this.mount(s)}}catch(i){console.warn("Failed to insert rule:",this.selectorText,i)}}};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 i={};function n(s,r){return s.startsWith("&")?`${r}${s.slice(1)}`:`${r} ${s}`}for(let s in e){let r=e[s],l=q(s);for(let h of l){let d=n(h,t);if(/^@(container|layer|supports|media)\b/.test(h)){if(typeof r=="object"&&r!=null){let a=new p(h,this.parent);a.styleList.addCSS(r,t),this.items.push(a)}}else if(h.startsWith("@keyframes")){let a=new p(h,this.parent);a.styleList.addCSS(r,""),this.items.push(a)}else if(h.startsWith("@font-face")){let a=new p(h,this.parent);for(let f in r)a.insertStyle(f,r[f]);this.items.push(a)}else if(typeof r=="object"&&r!=null){let a=new p(d,this.parent);this.items.push(a);for(let[f,u]of Object.entries(r))if(typeof u=="object"&&u!=null){let c=n(f,d);f.startsWith("&")?this.addCSS(u,c):a.styleList.insertRule(c).styleList.addCSS(u,c)}else a.insertStyle(f,u)}else i[h]=r}}if(Object.keys(i).length){let s=new p(t,this.parent);for(let r in i)s.insertStyle(r,i[r]);this.items.push(s)}}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=n=>n.replace("(odd)","(2n+1)").replace("(even)","(2n)");this.items.forEach((n,s)=>{let r=s-t,l=e[r];l&&(n.selectorText.startsWith("@")&&l instanceof CSSKeyframesRule||"keyText"in l?n.mount(l):"selectorText"in l?l.selectorText!==i(n.selectorText)?t+=1:n.mount(l):"cssRules"in l&&n.mount(l))})}render(e){e instanceof HTMLStyleElement?(this.domStyle=e,this.items.forEach(t=>t.render(e.sheet))):e instanceof CSSGroupingRule&&this.items.forEach(t=>t.render(e))}_dispose(){if(this.items)for(let e=0;e<this.items.length;e++)this.items[e]._dispose();this.items=[],this.parent=null,this.domStyle=null}};var m=class o{constructor(e,t=null,i=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 n=`${(h=this.parent)==null?void 0:h.nodeId}.${i}`,s=JSON.stringify(e.style||{},(d,a)=>typeof a=="function"?n:a);this.nodeId=F(n+s),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 i in this._events){let n=i,s=this._events[n],r=l=>s(l,this);t.addEventListener(n,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(n,r),r=null})}return this.attributes&&Object.values(this.attributes.items).forEach(i=>i.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 i=0;i<t.length;i++){let n=t[i],s=e[n];["$","_onSchedule","_key","_context","_metadata","style",this.tagName].includes(n)||(["_onInit","_onInsert","_onMount","_onBeforeUpdate","_onUpdate","_onBeforeRemove","_onRemove"].includes(n)?this.addHook(n.substring(3),s):n.startsWith("on")?this.addEvent(n.substring(2).toLowerCase(),s):n=="_portal"?this._portal=s:n=="class"&&typeof s=="string"?this.attributes.addClass(s):this.attributes.set(n,s))}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]=(n,s)=>{i(n,s),t(n,s)}:this._events[e]=t}addHook(e,t){let i=this._hooks[e];typeof i=="function"?this._hooks[e]=((...n)=>{i(...n),t(...n)}):this._hooks[e]=t}getRoot(){let e=this;for(;e&&e instanceof o&&e.parent;)e=e.parent;return e}getContext(e){let t=this;for(;t&&(!t._context||!Object.prototype.hasOwnProperty.call(t._context,e));)t=t.parent;return t&&t._context?t._context[e]:void 0}setContext(e,t){this._context=this._context||{},this._context[e]=t}getMetadata(e){return this._metadata?this._metadata[e]:void 0}setMetadata(e,t){this._metadata=this._metadata||{},this._metadata[e]=t}generateCSS(){if(!this.styles||!this.children)return"";let e=this.styles.cssText();return e+=this.children.items.map(t=>t instanceof o?t.generateCSS():"").join(""),e}generateHTML(){if(!this.children||!this.attributes)return"";let e=this.children.generateHTML(),t=this.attributes.generateHTML();return`<${this.tagName}${t}>${e}</${this.tagName}>`}mount(e,t){if(!e)throw new Error("Missing dom node on bind");if(this.domElement=e,this._events)for(let i in this._events){let n=i,s=this._events[n],r=l=>s(l,this);e.addEventListener(n,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(n,r),r=null})}this.children&&this.children.items.forEach((i,n)=>{let s=e.childNodes[n];s instanceof Node&&i instanceof o&&i.mount(s,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,n=e.getRootNode(),s=n instanceof ShadowRoot?n:document.head;return i||(i=T(s)),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())}};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,ge as VoidTags,F as hashString,b as merge,de as r,fe as toState};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|