@domphy/core 0.1.7 → 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 +2 -2
- package/dist/core.global.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -14
- package/dist/index.d.ts +15 -14
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core.global.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var Domphy=(()=>{var N=Object.defineProperty;var
|
|
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)_=i,this._flush(t,s);_=[]}_flush(e,t){if(!this._listeners)return;let s=this._listeners[e];if(s){_.push([this,e]);for(let i of[...s])if(s.has(i))try{i(...t)}catch(o){console.error(o)}_.pop()}}};var S=class{constructor(e,t=typeof e){this.name=t;this._notifier=new y;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 v(n={},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=g(e));for(let o in e){let r=e[o];if(!(r==null||r===""))if(typeof r=="object"&&!Array.isArray(r))typeof n[o]=="object"?n[o]=v(n[o],r):n[o]=r;else if(t.includes(o))if(typeof n[o]=="function"||typeof r=="function"){let l=n[o];n[o]=h=>{let d=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[d,a].filter(f=>f).join(", ")}}else n[o]=[n[o],r].filter(l=>l).join(", ");else if(i.includes(o))if(typeof n[o]=="function"||typeof r=="function"){let l=n[o];n[o]=h=>{let d=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[d,a].filter(f=>f).join("")}}else n[o]=[n[o],r].filter(l=>l).join("");else if(s.includes(o))if(typeof n[o]=="function"||typeof r=="function"){let l=n[o];n[o]=h=>{let d=typeof l=="function"?l(h):l,a=typeof r=="function"?r(h):r;return[d,a].filter(f=>f).join(" ")}}else n[o]=[n[o],r].filter(l=>l).join(" ");else if(o.startsWith("on")){let l=o.replace("on","").toLowerCase();Z(n,l,r)}else if(o.startsWith("_on")){let l=o.replace("_on","");Y(n,l,r)}else n[o]=r}return n}function O(n=""){let e=2166136261;for(let t=0;t<n.length;t++)e^=n.charCodeAt(t),e=e*16777619>>>0;return String.fromCharCode(97+e%26)+e.toString(16)}function ae(n,e){return n instanceof S?n:new S(n,e)}function he(n){return n}function Y(n,e,t){let s=`_on${e}`,i=n[s];typeof i=="function"?n[s]=(...o)=>{i(...o),t(...o)}:n[s]=t}function Z(n,e,t){let s=X[e];if(!s)throw Error(`invalid event name "${e}"`);let i=n[s];typeof i=="function"?n[s]=(o,r)=>{i(o,r),t(o,r)}:n[s]=t}function g(n,e=new WeakMap){if(n===null||typeof n!="object"||typeof n=="function")return n;if(e.has(n))return e.get(n);let t=Object.getPrototypeOf(n);if(t!==Object.prototype&&!Array.isArray(n))return n;let s;if(Array.isArray(n)){s=[],e.set(n,s);for(let i of n)s.push(g(i,e));return s}if(n instanceof Date)return new Date(n);if(n instanceof RegExp)return new RegExp(n);if(n instanceof Map){s=new Map,e.set(n,s);for(let[i,o]of n)s.set(g(i,e),g(o,e));return s}if(n instanceof Set){s=new Set,e.set(n,s);for(let i of n)s.add(g(i,e));return s}if(ArrayBuffer.isView(n))return new n.constructor(n);if(n instanceof ArrayBuffer)return n.slice(0);s=Object.create(t),e.set(n,s);for(let i of Reflect.ownKeys(n))s[i]=g(n[i],e);return s}function D(n,e=!1){if(Object.prototype.toString.call(n)!=="[object Object]")throw Error(`typeof ${n} is invalid DomphyElement`);let t=Object.keys(n);for(let s=0;s<t.length;s++){let i=t[s],o=n[i];if(s==0&&!C.includes(i)&&!i.includes("-")&&!e)throw Error(`key ${i} is not valid HTML tag name`);if(i=="style"&&o&&Object.prototype.toString.call(o)!=="[object Object]")throw Error('"style" must be a object');if(i=="$")n.$.forEach(r=>D(r,!0));else{if(i.startsWith("_on")&&typeof o!="function")throw Error(`hook ${i} value "${o}" must be a function `);if(i.startsWith("on")&&typeof o!="function")throw Error(`event ${i} value "${o}" must be a function `);if(i=="_portal"&&typeof o!="function")throw Error('"_portal" must be a function return HTMLElement');if(i=="_context"&&Object.prototype.toString.call(o)!=="[object Object]")throw Error('"_context" must be a object');if(i=="_metadata"&&Object.prototype.toString.call(o)!=="[object Object]")throw Error('"_metadata" must be a object');if(i=="_key"&&typeof o!="string"&&typeof o!="number")throw Error('"_key" must be a string or number')}}return!0}function Q(n){return/<([a-z][\w-]*)(\s[^>]*)?>.*<\/\1>|<([a-z][\w-]*)(\s[^>]*)?\/>/i.test(n.trim())}function K(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ee(n){return Object.keys(n).find(e=>C.includes(e))}function M(n){return n.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function te(n){if(n.indexOf("@")===0)return[n];for(var e=[],t=0,s=0,i="",o=0,r=n.length;o<r;o++){var l=n[o];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 L(n){var t;let e=n.querySelector("#domphy-style");return e||(e=document.createElement("style"),e.id="domphy-style",n.appendChild(e)),e.dataset.domphyBase!=="true"&&((t=e.sheet)==null||t.insertRule("[hidden] { display: none !important; }",0),e.dataset.domphyBase="true"),e}var U=n=>{if(Array.isArray(n.$)){let e={};return n.$.forEach(t=>v(e,U(t))),delete n.$,v(e,n),e}else return n};var fe=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var 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"];var x=["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 F=["viewBox","preserveAspectRatio","gradientTransform","gradientUnits","spreadMethod","markerStart","markerMid","markerEnd","markerHeight","markerWidth","markerUnits","refX","refY","patternContentUnits","patternTransform","patternUnits","filterUnits","primitiveUnits","kernelUnitLength","clipPathUnits","maskContentUnits","maskUnits"];var j=class{constructor(e,t,s){this.parent=s,this.isBoolean=x.includes(e),F.includes(e)?this.name=e:this.name=M(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=K(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=o=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{o(),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}="${K(String(s))}"`}}};var T=class{constructor(e){this._notifier=new y;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 j(e,t,this.parent))}addListener(e,t){var s;if(this.has(e)&&((s=this.parent)!=null&&s.domElement)){let i=t;i.onSubscribe=o=>{var r;return(r=this.parent)==null?void 0:r.addHook("BeforeRemove",o)},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(!x.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,o)=>{let r=(i||"").split(" ").filter(l=>l);return!r.includes(o)&&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(o=>o).filter(o=>o!==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 H=class{constructor(e,t){this.type="TextNode";this.parent=t,this.text=e===""?"\u200B":String(e)}_createDOMNode(){let e;if(Q(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 R=class{constructor(e){this.items=[];this._nextKey=0;this.owner=e}_createNode(e){return typeof e=="object"&&e!==null?new u(e,this.owner,this._nextKey++):new H(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,i=e instanceof u?e.domElement:e.domText;if(i){let o=s.childNodes[t]||null;i!==o&&s.insertBefore(i,o)}}_swapDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let s=this.owner.domElement,i=e instanceof u?e.domElement:e.domText,o=t instanceof u?t.domElement:t.domText;if(!i||!o)return;let r=i.nextSibling,l=o.nextSibling;s.insertBefore(i,l),s.insertBefore(o,r)}update(e,t=!0,s=!1){var r,l,h,d;let i=this.items.slice(),o=new Map;for(let a of i)a instanceof u&&a.key!==null&&a.key!==void 0&&o.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 m=o.get(c);if(m){o.delete(c);let k=this.items.indexOf(m);if(k!==a&&k>=0){let $=m instanceof u&&!!m._portal;this.move(k,a,$?!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);o.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 o=this.items.length,r=typeof t!="number"||isNaN(t)||t<0||t>o?o:t,l=this._createNode(e);if(this.items.splice(r,0,l),l instanceof u){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 m=a.getRootNode(),k=m instanceof ShadowRoot?m:document.head,$=L(k);l.styles.render($),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(E=>{if(E instanceof u&&E._portal){let W=E._portal(E.getRoot());W&&E.render(W)}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 u){let o=()=>{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,o())};e._hooks.BeforeRemove(e,l),r||l()}else o()}else{let o=e.domText;this.items.splice(i,1),t&&o&&o.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 o=this.items[e],r=this.items[t];this.items[e]=r,this.items[t]=o,s&&this._swapDomElement(o,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 o=this.items[e];this.items.splice(e,1),this.items.splice(t,0,o),s&&this._moveDomElement(o,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 B=class{constructor(e,t,s){this.value="";this.name=e,this.cssName=M(e),this.parentRule=s,this.set(t)}_domUpdate(){if(!this.parentRule)return;let e=this.parentRule.domRule;if(e&&e.style){let t=e.style;t.setProperty(this.cssName,String(this.value)),b[this.name]&&b[this.name].forEach(s=>{t.setProperty(`-${s}-${this.cssName}`,String(this.value))})}}_dispose(){this.value="",this.parentRule=null}set(e){var t,s,i,o;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}_${(o=(i=this.parentRule)==null?void 0:i.root)==null?void 0:o.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),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 n{constructor(e,t){this.domRule=null;this.styleBlock={};this.selectorText=e,this.styleList=new w(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 n;)e=e.parent;return e}get parentNode(){let e=this.parent;for(;e&&e instanceof n;)e=e.parent;return e}insertStyle(e,t){this.styleBlock&&(this.styleBlock[e]?this.styleBlock[e].set(t):this.styleBlock[e]=new B(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),o=e.cssRules[i];this.mount(o)}}else{let s=`${this.selectorText} { ${t} }`,i=e.insertRule(s,e.cssRules.length),o=e.cssRules[i];o&&"selectorText"in o&&this.mount(o)}}catch(s){console.warn("Failed to insert rule:",this.selectorText,s)}}};var w=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(o,r){return o.startsWith("&")?`${r}${o.slice(1)}`:`${r} ${o}`}for(let o in e){let r=e[o],l=te(o);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 m=i(f,d);f.startsWith("&")?this.addCSS(c,m):a.styleList.insertRule(m).styleList.addCSS(c,m)}else a.insertStyle(f,c)}else s[h]=r}}if(Object.keys(s).length){let o=new p(t,this.parent);for(let r in s)o.insertStyle(r,s[r]);this.items.push(o)}}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,o)=>{let r=o-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 u=class n{constructor(e,t=null,s=0){this._disposed=!1;this.type="ElementNode";this.parent=null;this.children=new R(this);this.styles=new w(this);this.attributes=new T(this);this.domElement=null;this._hooks={};this._events=null;this._context={};this._metadata={};this.key=null;var l,h;e=g(e),D(e),e.style=e.style||{},this.parent=t,this.tagName=ee(e),e=U(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}`,o=JSON.stringify(e.style||{},(d,a)=>typeof a=="function"?i:a);this.nodeId=O(i+o),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=I.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,o=this._events[i],r=l=>o(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){v(this._context,e._context),v(this._metadata,e._metadata);let t=Object.keys(e);for(let s=0;s<t.length;s++){let i=t[s],o=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),o):i.startsWith("on")?this.addEvent(i.substring(2).toLowerCase(),o):i=="_portal"?this._portal=o:i=="class"&&typeof o=="string"?this.attributes.addClass(o):this.attributes.set(i,o))}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,o)=>{s(i,o),t(i,o)}: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 n&&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 n?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,o=this._events[i],r=l=>o(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 o=e.childNodes[i];o instanceof Node&&s instanceof n&&s.mount(o,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(),o=i instanceof ShadowRoot?i:document.head;return s||(s=L(o)),this.styles.render(s),this.children.items.forEach(r=>{if(r instanceof n&&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 V=class{constructor(e){this._notifier=new y;this.initialRecord=A({},e),this._record=A({},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()}};return re(de);})();
|
|
1
|
+
"use strict";var Domphy=(()=>{var N=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var G=(o,e,t)=>e in o?N(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,A=(o,e)=>{for(var t in e||(e={}))q.call(e,t)&&G(o,t,e[t]);if(z)for(var t of z(e))ne.call(e,t)&&G(o,t,e[t]);return o};var J=(o,e)=>{for(var t in e)N(o,t,{get:e[t],enumerable:!0})},oe=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of se(e))!q.call(o,s)&&s!==t&&N(o,s,{get:()=>e[s],enumerable:!(i=ie(e,s))||i.enumerable});return o};var re=o=>oe(N({},"__esModule",{value:!0}),o);var de={};J(de,{core:()=>P});var P={};J(P,{AttributeList:()=>T,BooleanAttributes:()=>x,CamelAttributes:()=>F,ElementList:()=>R,ElementNode:()=>c,HtmlTags:()=>C,Notifier:()=>y,PrefixCSS:()=>b,RecordState:()=>V,State:()=>S,SvgTags:()=>I,VoidTags:()=>fe,hashString:()=>O,merge:()=>v,r:()=>he,toState:()=>ae});var le=["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"],X=le.reduce((o,e)=>{let t=e.slice(2).toLowerCase();return o[t]=e,o},{});var C=["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 _=[],y=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:[..._]}),this._scheduled||(this._scheduled=!0,queueMicrotask(()=>this._flushAll()))))}_isCircular(e){let t=_.findIndex(([s,n])=>s===this&&n===e);if(t===-1)return!1;let i=[..._.slice(t).map(([,s])=>s),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:s}]of e)_=s,this._flush(t,i);_=[]}_flush(e,t){if(!this._listeners)return;let i=this._listeners[e];if(i){_.push([this,e]);for(let s of[...i])if(i.has(s))try{s(...t)}catch(n){console.error(n)}_.pop()}}};var S=class{constructor(e,t=typeof e){this.name=t;this._notifier=new y;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 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=g(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 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(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(n.startsWith("on")){let l=n.replace("on","").toLowerCase();Z(o,l,r)}else if(n.startsWith("_on")){let l=n.replace("_on","");Y(o,l,r)}else o[n]=r}return o}function O(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 ae(o,e){return o instanceof S?o:new S(o,e)}function he(o){return o}function Y(o,e,t){let i=`_on${e}`,s=o[i];typeof s=="function"?o[i]=(...n)=>{s(...n),t(...n)}:o[i]=t}function Z(o,e,t){let i=X[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 g(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(g(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(g(s,e),g(n,e));return i}if(o instanceof Set){i=new Set,e.set(o,i);for(let s of o)i.add(g(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]=g(o[s],e);return i}function D(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&&!C.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=>D(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 Q(o){return/<([a-z][\w-]*)(\s[^>]*)?>.*<\/\1>|<([a-z][\w-]*)(\s[^>]*)?\/>/i.test(o.trim())}function K(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ee(o){return Object.keys(o).find(e=>C.includes(e))}function M(o){return o.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function te(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 L(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 U=o=>{if(Array.isArray(o.$)){let e={};return o.$.forEach(t=>v(e,U(t))),delete o.$,v(e,o),e}else return o};var fe=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"];var 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"];var x=["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 F=["viewBox","preserveAspectRatio","gradientTransform","gradientUnits","spreadMethod","markerStart","markerMid","markerEnd","markerHeight","markerWidth","markerUnits","refX","refY","patternContentUnits","patternTransform","patternUnits","filterUnits","primitiveUnits","kernelUnitLength","clipPathUnits","maskContentUnits","maskUnits"];var j=class{constructor(e,t,i){this._notifier=new y;this.parent=i,this.isBoolean=x.includes(e),F.includes(e)?this.name=e:this.name=M(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,s;let t=this.value;if(e==null)this.value=null;else if(typeof e=="string"&&/<\/?[a-z][\s\S]*>/i.test(e))this.value=K(e);else if(typeof e=="function"){let n=()=>{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)};n.elementNode=this.parent,n.debug=`class:${(i=this.parent)==null?void 0:i.tagName}_${(s=this.parent)==null?void 0:s.nodeId} attribute:${this.name}`,n.onSubscribe=r=>{this.parent&&this.parent.addHook("BeforeRemove",()=>{r(),n=null})},this.value=this.isBoolean?!!e(n):e(n)}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 s;return(s=this.parent)==null?void 0:s.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}="${K(String(i))}"`}}};var T=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 j(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(!x.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 H=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(Q(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 R=class{constructor(e){this.items=[];this._nextKey=0;this.owner=e}_createNode(e){return typeof e=="object"&&e!==null?new c(e,this.owner,this._nextKey++):new H(e==null?"":String(e),this.owner)}_moveDomElement(e,t){if(!this.owner||!this.owner.domElement)return;let i=this.owner.domElement,s=e instanceof c?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 c?e.domElement:e.domText,n=t instanceof c?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,d;let s=this.items.slice(),n=new Map;for(let a of s)a instanceof c&&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 k=this.items.indexOf(m);if(k!==a&&k>=0){let $=m instanceof c&&!!m._portal;this.move(k,a,$?!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||(d=(h=this.owner._hooks)==null?void 0:h.Update)==null||d.call(h,this.owner)}insert(e,t,i=!0,s=!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 c){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(),k=m instanceof ShadowRoot?m:document.head,$=L(k);l.styles.render($),l._hooks.Mount&&l._hooks.Mount(l),l.children.items.forEach(E=>{if(E instanceof c&&E._portal){let W=E._portal(E.getRoot());W&&E.render(W)}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!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 c){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()};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(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.forEach(e=>e._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 B=class{constructor(e,t,i){this.value="";this.name=e,this.cssName=M(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){var t,i,s,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:${(i=(t=this.parentRule)==null?void 0:t.root)==null?void 0:i.tagName}_${(n=(s=this.parentRule)==null?void 0:s.root)==null?void 0:n.nodeId} style:${this.name}`,this.value=e(r)}else this.value=e;this._domUpdate()}remove(){if(this.parentRule){if(this.parentRule.domRule instanceof CSSStyleRule){let e=this.parentRule.domRule.style;e.removeProperty(this.cssName),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 w(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 B(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 w=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=te(n);for(let h of l){let d=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(d,this.parent);this.items.push(a);for(let[f,u]of Object.entries(r))if(typeof u=="object"&&u!=null){let m=s(f,d);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 c=class o{constructor(e,t=null,i=0){this._disposed=!1;this.type="ElementNode";this.parent=null;this.children=new R(this);this.styles=new w(this);this.attributes=new T(this);this.domElement=null;this._hooks={};this._events=null;this._context={};this._metadata={};this.key=null;var l,h;e=g(e),D(e),e.style=e.style||{},this.parent=t,this.tagName=ee(e),e=U(e),this.key=(l=e._key)!=null?l:null,this._context=e._context||{},this._metadata=e._metadata||{};let s=`${(h=this.parent)==null?void 0:h.nodeId}.${i}`,n=JSON.stringify(e.style||{},(d,a)=>typeof a=="function"?s:a);this.nodeId=O(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 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=I.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 s=i,n=this._events[s],r=l=>n(l,this);t.addEventListener(s,r),this.addHook("BeforeRemove",l=>{l.domElement.removeEventListener(s,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){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}`}`)}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=L(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())}};var V=class{constructor(e){this._notifier=new y;this.initialRecord=A({},e),this._record=A({},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()}};return re(de);})();
|
|
3
3
|
//# sourceMappingURL=core.global.js.map
|