mancha 0.16.5 → 0.16.7
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/browser.js +1 -1
- package/dist/cli.js +7 -1
- package/dist/cli.js.map +1 -1
- package/dist/css_gen_utils.js +8 -0
- package/dist/css_gen_utils.js.map +1 -1
- package/dist/mancha.js +1 -1
- package/dist/safe_browser.js +1 -1
- package/dist/safe_browser.js.map +1 -1
- package/dist/trusted_attributes.d.ts +4 -0
- package/dist/trusted_attributes.js +28 -0
- package/dist/trusted_attributes.js.map +1 -0
- package/dist/type_checker.js +24 -3
- package/dist/type_checker.js.map +1 -1
- package/package.json +1 -1
package/dist/mancha.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function t(t){if(!function(t){const r=!e.test(t);return r}(t))return t}function r(e){return t(e)}const i={};function n(e){0}"undefined"!=typeof window&&window.TrustedScriptURL;class s{constructor(e,t){this.privateDoNotAccessOrElseWrappedAttributePrefix=t}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const o=s;function a(e){if(function(e){return e instanceof s}(e))return e.privateDoNotAccessOrElseWrappedAttributePrefix;throw new Error("")}"undefined"!=typeof window&&window.TrustedHTML;function l(e,t,r,i){if(0===e.length){throw new Error("")}const n=e.map(e=>a(e)),s=r.toLowerCase();if(n.every(e=>0!==s.indexOf(e)))throw new Error(`Attribute "${r}" does not match any of the allowed prefixes.`);t.setAttribute(r,i)}"undefined"!=typeof window&&window.TrustedScript;class c{}class h extends c{constructor(e,t){super(),n(),this.privateDoNotAccessOrElseWrappedStyleSheet=e}toString(){return this.privateDoNotAccessOrElseWrappedStyleSheet}}function d(e){return new h(e,i)}function u(e){if(e instanceof h)return e.privateDoNotAccessOrElseWrappedStyleSheet;throw new Error("")}function p(e,t){e.textContent=u(t)}Error;class f{iterable;constructor(e){this.iterable=e}filter(e){return new f(f.filterGenerator(e,this.iterable))}map(e){return new f(f.mapGenerator(e,this.iterable))}find(e){for(const t of this.iterable)if(e(t))return t}array(){return Array.from(this.iterable)}*generator(){for(const e of this.iterable)yield e}static*filterGenerator(e,t){for(const r of t)e(r)&&(yield r)}static*mapGenerator(e,t){for(const r of t)yield e(r)}static equals(e,t){const r=e[Symbol.iterator](),i=t[Symbol.iterator]();let n=r.next(),s=i.next();for(;!n.done&&!s.done;){if(n.value!==s.value)return!1;n=r.next(),s=i.next()}return n.done===s.done}}function m(e){return Object.isFrozen(e)&&Object.isFrozen(e.raw)}function g(e){return-1===e.toString().indexOf("`")}g(e=>e``)||g(e=>e`\0`)||g(e=>e`\n`)||g(e=>e`\u0000`),m``&&m`\0`&&m`\n`&&m`\u0000`;function _(e){const t=e[0].toLowerCase();return new o(i,t)}var w,v;function $(e){return{valueOf:e}.valueOf()}!function(e){e[e.STYLE_TAG=0]="STYLE_TAG",e[e.STYLE_ATTRIBUTE=1]="STYLE_ATTRIBUTE",e[e.HTML_ATTRIBUTE=2]="HTML_ATTRIBUTE"}(w||(w={}));class x{constructor(e,t,r,i,n){this.allowedElements=e,this.elementPolicies=t,this.allowedGlobalAttributes=r,this.globalAttributePolicies=i,this.globallyAllowedAttributePrefixes=n}isAllowedElement(e){return"FORM"!==e&&(this.allowedElements.has(e)||this.elementPolicies.has(e))}getAttributePolicy(e,t){const r=this.elementPolicies.get(t);if(null==r?void 0:r.has(e))return r.get(e);if(this.allowedGlobalAttributes.has(e))return{policyAction:v.KEEP};const i=this.globalAttributePolicies.get(e);return i||(this.globallyAllowedAttributePrefixes&&[...this.globallyAllowedAttributePrefixes].some(t=>0===e.indexOf(t))?{policyAction:v.KEEP}:{policyAction:v.DROP})}}!function(e){e[e.DROP=0]="DROP",e[e.KEEP=1]="KEEP",e[e.KEEP_AND_SANITIZE_URL=2]="KEEP_AND_SANITIZE_URL",e[e.KEEP_AND_NORMALIZE=3]="KEEP_AND_NORMALIZE",e[e.KEEP_AND_SANITIZE_STYLE=4]="KEEP_AND_SANITIZE_STYLE",e[e.KEEP_AND_USE_RESOURCE_URL_POLICY=5]="KEEP_AND_USE_RESOURCE_URL_POLICY",e[e.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET=6]="KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET"}(v||(v={}));new Set(["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"]);const b=["ARTICLE","SECTION","NAV","ASIDE","H1","H2","H3","H4","H5","H6","HEADER","FOOTER","ADDRESS","P","HR","PRE","BLOCKQUOTE","OL","UL","LH","LI","DL","DT","DD","FIGURE","FIGCAPTION","MAIN","DIV","EM","STRONG","SMALL","S","CITE","Q","DFN","ABBR","RUBY","RB","RT","RTC","RP","DATA","TIME","CODE","VAR","SAMP","KBD","SUB","SUP","I","B","U","MARK","BDI","BDO","SPAN","BR","WBR","INS","DEL","PICTURE","PARAM","TRACK","MAP","TABLE","CAPTION","COLGROUP","COL","TBODY","THEAD","TFOOT","TR","TD","TH","SELECT","DATALIST","OPTGROUP","OPTION","OUTPUT","PROGRESS","METER","FIELDSET","LEGEND","DETAILS","SUMMARY","MENU","DIALOG","SLOT","CANVAS","FONT","CENTER","ACRONYM","BASEFONT","BIG","DIR","HGROUP","STRIKE","TT"],y=[["A",new Map([["href",{policyAction:v.KEEP_AND_SANITIZE_URL}]])],["AREA",new Map([["href",{policyAction:v.KEEP_AND_SANITIZE_URL}]])],["LINK",new Map([["href",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY,conditions:new Map([["rel",new Set(["alternate","author","bookmark","canonical","cite","help","icon","license","next","prefetch","dns-prefetch","prerender","preconnect","preload","prev","search","subresource"])]])}]])],["SOURCE",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["IMG",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["VIDEO",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}]])],["AUDIO",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}]])]],E=["title","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-current","aria-disabled","aria-dropeffect","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-live","aria-multiline","aria-multiselectable","aria-orientation","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","alt","align","autocapitalize","autocomplete","autocorrect","autofocus","autoplay","bgcolor","border","cellpadding","cellspacing","checked","color","cols","colspan","controls","datetime","disabled","download","draggable","enctype","face","formenctype","frameborder","height","hreflang","hidden","ismap","label","lang","loop","max","maxlength","media","minlength","min","multiple","muted","nonce","open","placeholder","preload","rel","required","reversed","role","rows","rowspan","selected","shape","size","sizes","slot","span","spellcheck","start","step","summary","translate","type","valign","value","width","wrap","itemscope","itemtype","itemid","itemprop","itemref"],A=[["dir",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["dir",new Set(["auto","ltr","rtl"])]]))}],["async",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["async",new Set(["async"])]]))}],["cite",{policyAction:v.KEEP_AND_SANITIZE_URL}],["loading",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["loading",new Set(["eager","lazy"])]]))}],["poster",{policyAction:v.KEEP_AND_SANITIZE_URL}],["target",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["target",new Set(["_self","_blank"])]]))}]];new x(new Set(b),new Map(y),new Set(E),new Map(A)),new x(new Set($(()=>b.concat(["STYLE"]))),new Map(y),new Set($(()=>E.concat(["id","name","class"]))),new Map($(()=>A.concat([["style",{policyAction:v.KEEP_AND_SANITIZE_STYLE}]]))));function R(e){return d(e[0])}const O=[_`:`,_`style`,_`class`];function*I(e,t=new Set){const r=new Set,i=Array.from(e.childNodes).filter(e=>!t.has(e));for(yield e;i.length;){const e=i.shift();r.has(e)||(r.add(e),yield e),e.childNodes&&Array.from(e.childNodes).filter(e=>!t.has(e)).forEach(e=>i.push(e))}}function N(e,t){return void 0!==e?.[t]}function k(e,t){return"function"==typeof e?.[t]}function T(e){return e.replace(/-./g,e=>e[1].toUpperCase())}function S(e,t){return N(e,"attribs")?e.attribs?.[t]??null:e.getAttribute?.(t)??null}function P(e,t,r=""){return S(e,r+t)||(e.dataset?.[T(t)]??null)}function C(e,t,r){N(e,"attribs")?e.attribs[t]=r:e.setAttribute?.(t,r)}function L(e,t,r){N(e,"attribs")?e.attribs[t]=r:l(O,e,t,r)}function D(e,t,r){switch(t){case"disabled":return void(e.disabled=r);case"selected":return void(e.selected=r);case"checked":return void(e.checked=r);default:e[t]=r}}function M(e,t){N(e,"attribs")?delete e.attribs[t]:e.removeAttribute?.(t)}function U(e,t,r=""){M(e,`${r}${t}`),M(e,`data-${t}`)}function z(e,t,r){if(N(e,"attribs")&&N(t,"attribs"))t.attribs[r]=e.attribs[r];else if(r.startsWith("data-")){const i=T(r.slice(5));t.dataset[i]=e.dataset?.[i]}else{const i=e?.getAttribute?.(r);L(t,r,i||"")}}function j(e){if(N(e,"firstElementChild"))return e.firstElementChild;return Array.from(e.children).find(e=>1===e.nodeType)}function F(e,...t){if(k(e,"replaceWith"))return e.replaceWith(...t);{const r=e,i=r.parentNode,n=Array.from(i.childNodes).indexOf(r);t.forEach(e=>e.parentNode=i),i.childNodes=[].concat(Array.from(i.childNodes).slice(0,n)).concat(t).concat(Array.from(i.childNodes).slice(n+1))}}function G(e,...t){k(e,"replaceChildren")?e.replaceChildren(...t):(e.childNodes=t,t.forEach(t=>t.parentNode=e))}function K(e,t){return k(t,"appendChild")?e.appendChild(t):(e.childNodes.push(t),t.parentNode=e,t)}function W(e,t){return k(t,"removeChild")?e.removeChild(t):(G(e,...Array.from(e.childNodes).filter(e=>e!==t)),t)}function H(e,t,r){return r?k(e,"insertBefore")?e.insertBefore(t,r):(F(r,t,r),t):K(e,t)}function Y(e,t=0){return e?e.length<=t?e:e.slice(0,t-1)+"…":""}function B(e,t=0){return globalThis.DocumentFragment&&e instanceof DocumentFragment?Array.from(e.childNodes).map(e=>B(e,t)).join(""):Y(e.outerHTML||e.nodeValue||String(e),t)}function V(e){return e.includes("/")?e.split("/").slice(0,-1).join("/"):""}var Z;!function(e){e.resolveIncludes=async function(e,t){const r=e,i=r.tagName?.toLowerCase();if(!["include","link"].includes(i))return;if("link"===i&&"subresource"!==S(r,"rel"))return;this.log("include directive found in:\n",B(e,128)),this.log("include params:",t);const n="link"===r.tagName.toLocaleLowerCase()?"href":"src",s=S(r,n);if(!s)throw new Error(`"${n}" attribute missing from ${B(e,128)}.`);const o=[];"include"===i&&o.push("src"),"link"===i&&o.push("rel","href");const a=t=>{const i=j(t);for(const e of Array.from(r.attributes))i&&!o.includes(e.name)&&z(r,i,e.name);F(e,...t.childNodes)},l={...t,rootDocument:!1,maxdepth:t?.maxdepth-1};if(0===l.maxdepth)throw new Error("Maximum recursion depth reached.");if(s.includes("://")||s.startsWith("//"))this.log("Including remote file from absolute path:",s),await this.preprocessRemote(s,l).then(a);else if(t?.dirpath?.includes("://")||t?.dirpath?.startsWith("//")){const e=s.startsWith("/")?s:`${t.dirpath}/${s}`;this.log("Including remote file from relative path:",e),await this.preprocessRemote(e,l).then(a)}else if("/"===s.charAt(0))this.log("Including local file from absolute path:",s),await this.preprocessLocal(s,l).then(a);else{const e=t?.dirpath&&"."!==t?.dirpath?`${t?.dirpath}/${s}`:s;this.log("Including local file from relative path:",e),await this.preprocessLocal(e,l).then(a)}},e.rebaseRelativePaths=async function(e,t){const i=e,n=i.tagName?.toLowerCase();if(!t?.dirpath)return;const s=S(i,"src"),o=S(i,"href"),a=s||o;if(!a||((l=a).includes("://")||l.startsWith("/")||l.startsWith("#")||l.startsWith("data:")))return;var l;const c=`${t.dirpath}/${a}`;this.log("Rebasing relative path as:",c),N(i,"attribs")?L(i,s?"src":"href",c):"img"===n?i.src=c:"a"===n?function(e,t){const i=r(t);void 0!==i&&(e.href=i)}(i,c):"source"===n||"audio"===n||"video"===n||"track"===n||"input"===n?i.src=c:"area"===n?function(e,t){const i=r(t);void 0!==i&&(e.href=i)}(i,c):this.log("Unable to rebase relative path for element:",n)},e.registerCustomElements=async function(e,t){const r=e,i=r.tagName?.toLowerCase(),n=(S(r,"is")||S(r,"alt"))?.toLowerCase();if(["template","div"].includes(i)&&n){if("div"===i&&"template"!==S(r,"role"))return;this._customElements.has(n)||(this.log(`Registering custom element: ${n}\n`,B(r,128)),this._customElements.set(n,r),W(r.parentNode,r))}},e.resolveCustomElements=async function(e,t){const r=e,i=r.tagName?.toLowerCase();let n=i;if("div"===n&&(n=S(r,"role")?.toLowerCase()||n),n&&this._customElements.has(n)){this.log(`Processing custom element: ${n}\n`,B(r,128));const t=this._customElements.get(n),s=(t.content||t).cloneNode(!0),o=j(s);if(o)for(const e of Array.from(r.attributes))"div"===i&&"role"===e.name||z(r,o,e.name);const a=new f(I(s)).find(e=>"slot"===e.tagName?.toLowerCase());a&&F(a,...r.childNodes),F(e,...s.childNodes)}},e.resolveTextNodeExpressions=async function(e,t){const r=e.nodeValue||"";if(3!==e.nodeType||!r?.trim())return;this.log("Processing node content value:\n",Y(r,128));const i=new RegExp(/{{ ([^}]+) }}/gm),n=Array.from(r.matchAll(i)).map(e=>e[1]);return this.effect(function(){let t=r;for(const r of n){const i=this.eval(r,{$elem:e});t=t.replace(`{{ ${r} }}`,String(i))}e.nodeValue=t})},e.resolveDataAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"data",":");if(i){this.log(":data attribute found in:\n",B(e,128)),U(r,"data",":");const n=t?.rootNode===e?this:this.subrenderer();e.renderer=n;const s=n.eval(i,{$elem:e});if(await Promise.all(Object.entries(s).map(([e,t])=>n._store.set(e,t))),n!==this)for(const t of I(e,this._skipNodes))this._skipNodes.add(t);await n.mount(e,t)}},e.resolveClassAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"class",":");if(i){this.log(":class attribute found in:\n",B(e,128)),U(r,"class",":");const t=S(r,"class")||"";return this.effect(function(){const n=this.eval(i,{$elem:e});L(r,"class",(n?`${t} ${n}`:t).trim())})}},e.resolveTextAttributes=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"text",":");if(i){this.log(":text attribute found in:\n",B(e,128)),U(r,"text",":");const t=t=>this.textContent(e,t);return this.effect(function(){t(this.eval(i,{$elem:e}))})}},e.resolveHtmlAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"html",":");return i?(this.log(":html attribute found in:\n",B(e,128)),U(r,"html",":"),this.effect(function(){const n=this.eval(i,{$elem:e});return new Promise(async e=>{const i=await this.preprocessString(n,t);await this.renderNode(i),G(r,i),e()})})):void 0},e.resolveEventAttributes=async function(e,t){if(this._skipNodes.has(e))return;const r=e;for(const t of Array.from(r.attributes||[]))if(t.name.startsWith(":on:")||t.name.startsWith("data-on-")){let i="",n=[];if(t.name.startsWith(":on:")?[i,...n]=t.name.substring(4).split("."):t.name.startsWith("data-on-")&&([i,...n]=t.name.substring(8).split(".")),!i)throw new Error(`Invalid event attribute: ${t.name}`);this.log(t.name,"attribute found in:\n",B(e,128)),U(r,t.name);const s="submit"===i&&"FORM"===r.tagName.toUpperCase();e.addEventListener?.(i,r=>((n.includes("prevent")||s)&&r.preventDefault(),this.eval(t.value,{$elem:e,$event:r})))}},e.resolveForAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"for",":")?.trim();if(i){this.log(":for attribute found in:\n",B(e,128)),U(r,"for",":");for(const t of I(e,this._skipNodes))this._skipNodes.add(t);const n=S(r,"style")||"";C(r,"style","display: none;");const s=e.parentNode,o=this.createElement("template",e.ownerDocument);H(s,o,e),W(s,e),K(o,e),this.log(":for template:\n",B(o,128));const a=i.split(" in ",2);if(2!==a.length)throw new Error(`Invalid :for format: \`${i}\`. Expected "{key} in {expression}".`);const l=[],[c,h]=a;await this.effect(function(){const r=this.eval(h,{$elem:e});if(this.log(":for list items:",r),l.splice(0,l.length).forEach(e=>{W(s,e),this._skipNodes.delete(e)}),!Array.isArray(r))return console.error(`Expression did not yield a list: \`${h}\` => \`${r}\``),Promise.resolve();const i=[];for(const s of r){const r=this.subrenderer();r._store.set(c,s);const o=e.cloneNode(!0);C(o,"style",n),l.push(o),this._skipNodes.add(o),i.push(r.mount(o,t)),this.log("Rendered list child:\n",B(o,128))}const a=o.nextSibling;for(const e of l)H(s,e,a);return Promise.all(i)})}},e.resolveBindAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"bind",":");if(i){this.log(":bind attribute found in:\n",B(e,128));const t=["change","input"],n=S(r,":bind:on")?.split(",")||r.dataset?.bindOn?.split(",")||t;U(r,"bind",":"),M(r,":bind:on"),M(r,"data-bind-on");const s="checkbox"===S(r,"type")?"checked":"value";i.includes(".")||this.has(i)||this.set(i,""),this.effect(function(){const t=this.eval(i,{$elem:e});"checked"===s?r.checked=!!t:r.value=t});const o=`${i} = $elem.${s}`;for(const t of n)e.addEventListener(t,()=>this.eval(o,{$elem:e}))}},e.resolveShowAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"show",":");if(i){this.log(":show attribute found in:\n",B(e,128)),U(r,"show",":");const t="none"===r.style?.display?"":r.style?.display??S(r,"style")?.split(";")?.find(e=>"display"===e.split(":")[0])?.split(":")?.at(1)?.trim();this.effect(function(){const n=this.eval(i,{$elem:e});r.style?r.style.display=n?t:"none":L(r,"style",`display: ${n?t:"none"};`)})}},e.resolveCustomAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e;for(const t of Array.from(r.attributes||[])){const i=":attr:",n="data-attr-";if(t.name.startsWith(i)||t.name.startsWith(n)){this.log(t.name,"attribute found in:\n",B(e,128)),M(r,t.name);const s=t.name.split(i,2).at(-1)?.split(n,2).at(-1);this.effect(function(){const i=this.eval(t.value,{$elem:e});C(r,s,i)})}}},e.resolveCustomProperty=async function(e,t){if(this._skipNodes.has(e))return;const r=e;for(const t of Array.from(r.attributes||[])){const i=":prop:",n="data-prop-";if(t.name.startsWith(i)||t.name.startsWith(n)){this.log(t.name,"property found in:\n",B(e,128)),M(r,t.name);const s=t.name.split(i,2).at(-1)?.split(n,2).at(-1),o=T(s);this.effect(function(){const i=this.eval(t.value,{$elem:e});D(r,o,i)})}}},e.stripTypes=async function(e,t){const r=e;S(r,":types")&&M(r,":types"),S(r,"data-types")&&M(r,"data-types")}}(Z||(Z={}));const q=["this"],Q=["+","-","!"],X=["=","+","-","*","/","%","^","==","!=",">","<",">=","<=","||","&&","??","&","===","!==","|","|>"],J={"!":0,":":0,",":0,")":0,"]":0,"}":0,"|>":1,"?":2,"??":3,"||":4,"&&":5,"|":6,"^":7,"&":8,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},ee=["==","!=","<=",">=","||","&&","??","|>"],te=["===","!=="];var re;!function(e){e[e.STRING=1]="STRING",e[e.IDENTIFIER=2]="IDENTIFIER",e[e.DOT=3]="DOT",e[e.COMMA=4]="COMMA",e[e.COLON=5]="COLON",e[e.INTEGER=6]="INTEGER",e[e.DECIMAL=7]="DECIMAL",e[e.OPERATOR=8]="OPERATOR",e[e.GROUPER=9]="GROUPER",e[e.KEYWORD=10]="KEYWORD",e[e.ARROW=11]="ARROW"}(re||(re={}));const ie=(e,t,r=0)=>({kind:e,value:t,precedence:r}),ne=e=>9===e||10===e||13===e||32===e,se=e=>95===e||36===e||65<=(e&=-33)&&e<=90,oe=e=>se(e)||ae(e),ae=e=>48<=e&&e<=57;class le{_input;_index=-1;_tokenStart=0;_next;constructor(e){this._input=e,this._advance()}nextToken(){for(;ne(this._next);)this._advance(!0);if(34===(e=this._next)||39===e)return this._tokenizeString();var e;if(se(this._next))return this._tokenizeIdentOrKeyword();if(ae(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((e=>43===e||45===e||42===e||47===e||33===e||38===e||37===e||60===e||61===e||62===e||63===e||94===e||124===e)(this._next))return this._tokenizeOperator();if((e=>40===e||41===e||91===e||93===e||123===e||125===e)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(e){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),!0===e&&(this._tokenStart=this._index)):this._next=void 0}_getValue(e=0){const t=this._input.substring(this._tokenStart,this._index+e);return 0===e&&this._clearValue(),t}_clearValue(){this._tokenStart=this._index}_tokenizeString(){const e="unterminated string",t=this._next;for(this._advance(!0);this._next!==t;){if(void 0===this._next)throw new Error(e);if(92===this._next&&(this._advance(),void 0===this._next))throw new Error(e);this._advance()}const r=ie(re.STRING,this._getValue().replace(/\\(.)/g,(e,t)=>{switch(t){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return t}}));return this._advance(),r}_tokenizeIdentOrKeyword(){do{this._advance()}while(oe(this._next));const e=this._getValue(),t=(r=e,-1!==q.indexOf(r)?re.KEYWORD:re.IDENTIFIER);var r;return ie(t,e)}_tokenizeNumber(){do{this._advance()}while(ae(this._next));return 46===this._next?this._tokenizeDot():ie(re.INTEGER,this._getValue())}_tokenizeDot(){return this._advance(),ae(this._next)?this._tokenizeFraction():(this._clearValue(),ie(re.DOT,".",13))}_tokenizeComma(){return this._advance(!0),ie(re.COMMA,",")}_tokenizeColon(){return this._advance(!0),ie(re.COLON,":")}_tokenizeFraction(){do{this._advance()}while(ae(this._next));return ie(re.DECIMAL,this._getValue())}_tokenizeOperator(){this._advance();let e=this._getValue(2);if(-1!==te.indexOf(e))this._advance(),this._advance();else{if(e=this._getValue(1),"=>"===e)return this._advance(),ie(re.ARROW,e);-1!==ee.indexOf(e)&&this._advance()}return e=this._getValue(),ie(re.OPERATOR,e,J[e])}_tokenizeGrouper(){const e=String.fromCharCode(this._next),t=ie(re.GROUPER,e,J[e]);return this._advance(!0),t}}class ce{_kind;_tokenizer;_ast;_token;_value;constructor(e,t){this._tokenizer=new le(e),this._ast=t}parse(){return this._advance(),this._parseExpression()}_advance(e,t){if(!this._matches(e,t))throw new Error(`Expected kind ${e} (${t}), was ${this._token?.kind} (${this._token?.value})`);const r=this._tokenizer.nextToken();this._token=r,this._kind=r?.kind,this._value=r?.value}_matches(e,t){return!(e&&this._kind!==e||t&&this._value!==t)}_parseExpression(){if(!this._token)return this._ast.empty();const e=this._parseUnary();return void 0===e?void 0:this._parsePrecedence(e,0)}_parsePrecedence(e,t){if(void 0===e)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(re.GROUPER,"(")){const t=this._parseArguments();e=this._ast.invoke(e,void 0,t)}else if(this._matches(re.GROUPER,"[")){const t=this._parseIndex();e=this._ast.index(e,t)}else if(this._matches(re.DOT)){this._advance();const t=this._parseUnary();e=this._makeInvokeOrGetter(e,t)}else{if(this._matches(re.KEYWORD))break;if(!(this._matches(re.OPERATOR)&&this._token.precedence>=t))break;e="?"===this._value?this._parseTernary(e):this._parseBinary(e,this._token)}return e}_makeInvokeOrGetter(e,t){if(void 0===t)throw new Error("expected identifier");if("ID"===t.type)return this._ast.getter(e,t.value);if("Invoke"===t.type&&"ID"===t.receiver.type){const r=t.receiver;return this._ast.invoke(e,r.value,t.arguments)}throw new Error(`expected identifier: ${t}`)}_parseBinary(e,t){if(-1===X.indexOf(t.value))throw new Error(`unknown operator: ${t.value}`);this._advance();let r=this._parseUnary();for(;(this._kind===re.OPERATOR||this._kind===re.DOT||this._kind===re.GROUPER)&&this._token.precedence>t.precedence;)r=this._parsePrecedence(r,this._token.precedence);return this._ast.binary(e,t.value,r)}_parseUnary(){if(this._matches(re.OPERATOR)){const e=this._value;if(this._advance(),"+"===e||"-"===e){if(this._matches(re.INTEGER))return this._parseInteger(e);if(this._matches(re.DECIMAL))return this._parseDecimal(e)}if(-1===Q.indexOf(e))throw new Error(`unexpected token: ${e}`);const t=this._parsePrecedence(this._parsePrimary(),13);return this._ast.unary(e,t)}return this._parsePrimary()}_parseTernary(e){this._advance(re.OPERATOR,"?");const t=this._parseExpression();this._advance(re.COLON);const r=this._parseExpression();return this._ast.ternary(e,t,r)}_parsePrimary(){switch(this._kind){case re.KEYWORD:const e=this._value;if("this"===e)return this._advance(),this._ast.id(e);if(-1!==q.indexOf(e))throw new Error(`unexpected keyword: ${e}`);throw new Error(`unrecognized keyword: ${e}`);case re.IDENTIFIER:return this._parseInvokeOrIdentifier();case re.STRING:return this._parseString();case re.INTEGER:return this._parseInteger();case re.DECIMAL:return this._parseDecimal();case re.GROUPER:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case re.COLON:throw new Error('unexpected token ":"');default:return}}_parseList(){const e=[];do{if(this._advance(),this._matches(re.GROUPER,"]"))break;e.push(this._parseExpression())}while(this._matches(re.COMMA));return this._advance(re.GROUPER,"]"),this._ast.list(e)}_parseMap(){const e={};do{if(this._advance(),this._matches(re.GROUPER,"}"))break;const t=this._value;(this._matches(re.STRING)||this._matches(re.IDENTIFIER))&&this._advance(),this._advance(re.COLON),e[t]=this._parseExpression()}while(this._matches(re.COMMA));return this._advance(re.GROUPER,"}"),this._ast.map(e)}_parseInvokeOrIdentifier(){const e=this._value;if("true"===e)return this._advance(),this._ast.literal(!0);if("false"===e)return this._advance(),this._ast.literal(!1);if("null"===e)return this._advance(),this._ast.literal(null);if("undefined"===e)return this._advance(),this._ast.literal(void 0);const t=this._parseIdentifier(),r=this._parseArguments();return r?this._ast.invoke(t,void 0,r):t}_parseIdentifier(){if(!this._matches(re.IDENTIFIER))throw new Error(`expected identifier: ${this._value}`);const e=this._value;return this._advance(),this._ast.id(e)}_parseArguments(){if(!this._matches(re.GROUPER,"("))return;const e=[];do{if(this._advance(),this._matches(re.GROUPER,")"))break;const t=this._parseExpression();e.push(t)}while(this._matches(re.COMMA));return this._advance(re.GROUPER,")"),e}_parseIndex(){this._advance();const e=this._parseExpression();return this._advance(re.GROUPER,"]"),e}_parseParenOrFunction(){const e=this._parseArguments();if(this._matches(re.ARROW)){this._advance();const t=this._parseExpression(),r=e?.map(e=>e.value)??[];return this._ast.arrowFunction(r,t)}return this._ast.paren(e[0])}_parseString(){const e=this._ast.literal(this._value);return this._advance(),e}_parseInteger(e=""){const t=this._ast.literal(parseInt(`${e}${this._value}`,10));return this._advance(),t}_parseDecimal(e=""){const t=this._ast.literal(parseFloat(`${e}${this._value}`));return this._advance(),t}}const he={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,"==":(e,t)=>e==t,"!=":(e,t)=>e!=t,"===":(e,t)=>e===t,"!==":(e,t)=>e!==t,">":(e,t)=>e>t,">=":(e,t)=>e>=t,"<":(e,t)=>e<t,"<=":(e,t)=>e<=t,"||":(e,t)=>e||t,"&&":(e,t)=>e&&t,"??":(e,t)=>e??t,"|":(e,t)=>t(e),"|>":(e,t)=>t(e)},de={"+":e=>e,"-":e=>-e,"!":e=>!e};class ue{timeouts=new Map;debounce(e,t){return new Promise((r,i)=>{const n=this.timeouts.get(t);n&&clearTimeout(n),this.timeouts.set(t,setTimeout(()=>{try{r(t()),this.timeouts.delete(t)}catch(e){i(e)}},e))})}}const pe=new class{empty(){return{type:"Empty",evaluate:e=>e,getIds:e=>e}}literal(e){return{type:"Literal",value:e,evaluate(e){return this.value},getIds:e=>e}}id(e){return{type:"ID",value:e,evaluate(e){return"this"===this.value?e:e?.[this.value]},getIds(e){return e.push(this.value),e}}}unary(e,t){const r=de[e];return{type:"Unary",operator:e,child:t,evaluate(e){return r(this.child.evaluate(e))},getIds(e){return this.child.getIds(e)}}}binary(e,t,r){const i=he[t];return{type:"Binary",operator:t,left:e,right:r,evaluate(e){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const t=this.right.evaluate(e);let r,i;return"Getter"===this.left.type?(r=this.left.receiver.evaluate(e),i=this.left.name):"Index"===this.left.type?(r=this.left.receiver.evaluate(e),i=this.left.argument.evaluate(e)):"ID"===this.left.type&&(r=e,i=this.left.value),void 0===r?void 0:r[i]=t}return i(this.left.evaluate(e),this.right.evaluate(e))},getIds(e){return this.left.getIds(e),this.right.getIds(e),e}}}getter(e,t){return{type:"Getter",receiver:e,name:t,evaluate(e){return this.receiver.evaluate(e)?.[this.name]},getIds(e){return this.receiver.getIds(e),e}}}invoke(e,t,r){if(null!=t&&"string"!=typeof t)throw new Error("method not a string");return{type:"Invoke",receiver:e,method:t,arguments:r,evaluate(e){const r=this.receiver.evaluate(e),i=this.method?r:e?.this??e,n=this.method?r?.[t]:r,s=(this.arguments??[]).map(t=>t?.evaluate(e));return n?.apply?.(i,s)},getIds(e){return this.receiver.getIds(e),this.arguments?.forEach(t=>t?.getIds(e)),e}}}paren(e){return e}index(e,t){return{type:"Index",receiver:e,argument:t,evaluate(e){return this.receiver.evaluate(e)?.[this.argument.evaluate(e)]},getIds(e){return this.receiver.getIds(e),e}}}ternary(e,t,r){return{type:"Ternary",condition:e,trueExpr:t,falseExpr:r,evaluate(e){return this.condition.evaluate(e)?this.trueExpr.evaluate(e):this.falseExpr.evaluate(e)},getIds(e){return this.condition.getIds(e),this.trueExpr.getIds(e),this.falseExpr.getIds(e),e}}}map(e){return{type:"Map",entries:e,evaluate(t){const r={};if(e&&this.entries)for(const i in e){const e=this.entries[i];e&&(r[i]=e.evaluate(t))}return r},getIds(t){if(e&&this.entries)for(const r in e){const e=this.entries[r];e&&e.getIds(t)}return t}}}list(e){return{type:"List",items:e,evaluate(e){return this.items?.map(t=>t?.evaluate(e))},getIds(e){return this.items?.forEach(t=>t?.getIds(e)),e}}}arrowFunction(e,t){return{type:"ArrowFunction",params:e,body:t,evaluate(e){const t=this.params,r=this.body;return function(...i){const n=Object.fromEntries(t.map((e,t)=>[e,i[t]])),s=new Proxy(e??{},{set:(e,t,r)=>(n.hasOwnProperty(t)&&(n[t]=r),e[t]=r),get:(e,t)=>n.hasOwnProperty(t)?n[t]:e[t]});return r.evaluate(s)}},getIds(e){return this.body.getIds(e).filter(e=>!this.params.includes(e))}}}};function fe(e,t){const r=e?._store;return r?.has(t)?r.get(t):r?.has("$parent")?fe(r.get("$parent"),t):null}function me(e,t){const r=e?._store;return r?.has(t)?e:r?.has("$parent")?me(r.get("$parent"),t):null}class ge extends ue{evalkeys=["$elem","$event"];expressionCache=new Map;observers=new Map;keyHandlers=new Map;_observer=null;_store=new Map;_lock=Promise.resolve();constructor(e){super();for(let[t,r]of Object.entries(e||{}))this.set(t,r)}wrapFunction(e){return(...t)=>e.call(this.$,...t)}wrapObject(e,t){return null==e||((r=e)instanceof ge||r.__is_proxy__)||e.constructor!==Object&&!Array.isArray(e)?e:new Proxy(e,{deleteProperty:(e,r)=>r in e&&(delete e[r],t(),!0),set:(r,i,n,s)=>{"object"==typeof n&&null!=e&&(n=this.wrapObject(n,t));const o=Reflect.set(r,i,n,s);return t(),o},get:(e,t,r)=>"__is_proxy__"===t||Reflect.get(e,t,r)});var r}watch(e,t){const r=me(this,e);if(!r)throw new Error(`Cannot watch key "${e}" as it does not exist in the store.`);r.observers.has(e)||r.observers.set(e,new Set),r.observers.get(e)?.has(t)||r.observers.get(e)?.add(t)}addKeyHandler(e,t){this.keyHandlers.has(e)||this.keyHandlers.set(e,new Set),this.keyHandlers.get(e).add(t)}async notify(e,t=10){const r=me(this,e),i=Array.from(r?.observers.get(e)||[]);await this.debounce(t,()=>Promise.all(i.map(e=>e.call(this.proxify(e)))))}get(e,t){return t&&this.watch(e,t),fe(this,e)}async set(e,t){if(t===this._store.get(e))return;const r=()=>this.notify(e);t&&"function"==typeof t&&(t=this.wrapFunction(t)),t&&"object"==typeof t&&(t=this.wrapObject(t,r)),function(e,t,r){const i=me(e,t);i?i._store.set(t,r):e._store.set(t,r)}(this,e,t);for(const[r,i]of this.keyHandlers.entries())if(r.test(e))for(const r of i)await Promise.resolve(r.call(this.$,e,t));await r()}async del(e){await this.set(e,null),this._store.delete(e),this.observers.delete(e)}keys(){return Array.from(this._store.keys())}has(e){return this._store.has(e)}effect(e){return e.call(this.proxify(e))}proxify(e){const t=Array.from(this._store.entries()).map(([e])=>e),r=Object.fromEntries(t.map(e=>[e,null]));return new Proxy(r,{get:(t,r,i)=>"string"==typeof r&&me(this,r)?this.get(r,e):"$"===r?this.proxify(e):Reflect.get(this,r,i),set:(e,t,r,i)=>("string"!=typeof t||t in this?Reflect.set(this,t,r,i):this.set(t,r),!0)})}get $(){return this.proxify()}makeEvalFunction(e){if(e.includes(";"))throw new Error("Complex expressions are not supported.");let t=null;if(e.includes(" = ")){const[r,i]=e.split(" = ");t=r.trim(),e=i.trim()}return(r,i)=>{const n=((e,t)=>new ce(e,t).parse())(e,pe),s=n?.getIds([])?.map(e=>[e,i[e]??r[e]??globalThis[e]]),o=n?.evaluate(Object.fromEntries(s||[]));if(!t)return o;!function(e,t,r){const i=t.split(".");for(let t=0;t<i.length-1;t++)i[t]in e||(e[i[t]]={}),e=e[i[t]];e[i[i.length-1]]=r}(r,t,o)}}cachedExpressionFunction(e){return e=e.trim(),this.expressionCache.has(e)||this.expressionCache.set(e,this.makeEvalFunction(e)),this.expressionCache.get(e)}eval(e,t={}){const r=this._observer?this:this.$;if(this._store.has(e))return r[e];{const i=this.cachedExpressionFunction(e);try{return i(r,t)}catch(t){return console.error(`Failed to evaluate expression: ${e}`),console.error(t),null}}}}const _e="$$";function we(){return new URL(globalThis.window?.location?.href||"http://localhost/")}function ve(e){return`${_e}${e}`}function $e(e){return e.keys().filter(e=>e.startsWith(_e))}function xe(e,t,r){const i=function(e){return e.substring(2)}(t);let n=!1;if(r){const t=String(r);e.searchParams.get(i)!==t&&(e.searchParams.set(i,t),n=!0)}else e.searchParams.has(i)&&(e.searchParams.delete(i),n=!0);return n}async function be(e){const t=we();await async function(e,t){for(const[r,i]of t.searchParams.entries()){const t=ve(r);e.get(t)!==i&&await e.set(t,i)}}(e,t),function(e,t){let r=!1;for(const i of $e(t))xe(e,i,t.get(i))&&(r=!0);r&&globalThis.window?.history?.replaceState({},"",e.toString())}(t,e),e.addKeyHandler(new RegExp("^\\$\\$"),(e,t)=>{const r=we();xe(r,e,t)&&globalThis.window?.history?.replaceState({},"",r.toString())}),globalThis.window?.addEventListener("popstate",function(e){return async()=>{const t=we(),r=new Set;for(const[i,n]of t.searchParams.entries()){const t=ve(i);r.add(t),e.get(t)!==n&&e.set(t,n)}const i=$e(e);for(const t of i)r.has(t)||e.del(t)}}(e))}class ye extends ge{debugging=!1;dirpath="";_skipNodes=new Set;_customElements=new Map;debug(e){return this.debugging=e,this}async fetchRemote(e,t){return fetch(e,{cache:t?.cache??"default"}).then(e=>e.text())}async fetchLocal(e,t){return this.fetchRemote(e,t)}async preprocessString(e,t){this.log("Preprocessing string content with params:\n",t);const r=this.parseHTML(e,t);return await this.preprocessNode(r,t),r}async preprocessRemote(e,t){const r={};t?.cache&&(r.cache=t.cache);const i=await fetch(e,r).then(e=>e.text());return this.preprocessString(i,{...t,dirpath:V(e),rootDocument:t?.rootDocument??!e.endsWith(".tpl.html")})}async preprocessLocal(e,t){const r=await this.fetchLocal(e,t);return this.preprocessString(r,{...t,dirpath:V(e),rootDocument:t?.rootDocument??!e.endsWith(".tpl.html")})}subrenderer(){const e=(new this.constructor).debug(this.debugging);return e._store.set("$parent",this),e._store.set("$rootRenderer",this.get("$rootRenderer")??this),e._customElements=this._customElements,e}log(...e){this.debugging&&console.debug(...e)}async preprocessNode(e,t){t={dirpath:this.dirpath,maxdepth:10,...t};const r=new f(I(e,this._skipNodes)).map(async e=>{this.log("Preprocessing node:\n",B(e,128)),await Z.resolveIncludes.call(this,e,t),await Z.rebaseRelativePaths.call(this,e,t),await Z.registerCustomElements.call(this,e,t),await Z.resolveCustomElements.call(this,e,t)});return await Promise.all(r.generator()),e}async renderNode(e,t){for(const r of I(e,this._skipNodes))this.log("Rendering node:\n",B(r,128)),await Z.resolveForAttribute.call(this,r,t),await Z.resolveDataAttribute.call(this,r,t),await Z.resolveTextAttributes.call(this,r,t),await Z.resolveHtmlAttribute.call(this,r,t),await Z.resolveShowAttribute.call(this,r,t),await Z.resolveClassAttribute.call(this,r,t),await Z.resolveBindAttribute.call(this,r,t),await Z.resolveEventAttributes.call(this,r,t),await Z.resolveTextNodeExpressions.call(this,r,t),await Z.resolveCustomAttribute.call(this,r,t),await Z.resolveCustomProperty.call(this,r,t),await Z.stripTypes.call(this,r,t);return e}async mount(e,t){t={...t,rootNode:e},D(e,"renderer",this),this._store.set("$rootNode",e),this.has("$rootRenderer")||this._store.set("$rootRenderer",this),this.get("$rootRenderer")===this&&await be(this),await this.preprocessNode(e,t),await this.renderNode(e,t)}}function Ee(){return d([R`html{`,R`max-width: 70ch;`,R`padding: 2em 1em;`,R`margin: auto;`,R`line-height: 1.75;`,R`font-size: 1.25em;`,R`font-family: sans-serif;`,R`}`,R`h1,h2,h3,h4,h5,h6{`,R`margin: 1em 0 0.5em;`,R`}`,R`p,ul,ol{`,R`margin-bottom: 1em;`,R`color: #1d1d1d;`,R`}`].map(u).join(""))}const Ae={sm:640,md:768,lg:1024,xl:1280},Re=.25,Oe=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],Ie=[...Oe,16,20,24,25,28,30,32,36,40,44,48,50,52,56,60,64,72,80,96,100,112,128,144,160,192,200,224,256,288,300,320,384,400,448,500,512,...Object.values(Ae)],Ne=[1,2,5,10,20,25,30,40,50,60,70,75,80,90,95,98,99,100],ke=[75,100,150,200,300,500,700,1e3],Te=["hover","focus","disabled","active"],Se={margin:"m",padding:"p"},Pe={width:"w",height:"h"},Ce={top:"top",right:"right",bottom:"bottom",left:"left"},Le={"min-width":"min-w","min-height":"min-h","max-width":"max-w","max-height":"max-h"},De={"font-mono":{"font-family":"monospace"},"font-sans":{"font-family":"sans-serif"},"font-serif":{"font-family":"serif"},"font-cursive":{"font-family":"cursive"},"text-xs":{"font-size":".75rem","line-height":"calc(1 / 0.75)"},"text-sm":{"font-size":".875rem","line-height":"calc(1.25 / 0.875)"},"text-base":{"font-size":"1rem","line-height":"calc(1.5 / 1)"},"text-lg":{"font-size":"1.125rem","line-height":"calc(1.75 / 1.125)"},"text-xl":{"font-size":"1.25rem","line-height":"calc(1.75 / 1.25)"},"text-2xl":{"font-size":"1.5rem","line-height":"calc(2 / 1.5)"},"text-3xl":{"font-size":"1.875rem","line-height":"calc(2.25 / 1.875)"},"text-4xl":{"font-size":"2.25rem","line-height":"calc(2.5 / 2.25)"},"text-5xl":{"font-size":"3rem","line-height":"1"},"text-6xl":{"font-size":"3.75rem","line-height":"1"},"text-7xl":{"font-size":"4.5rem","line-height":"1"},"font-thin":{"font-weight":100},"font-extralight":{"font-weight":200},"font-light":{"font-weight":300},"font-normal":{"font-weight":400},"font-medium":{"font-weight":500},"font-semibold":{"font-weight":600},"font-bold":{"font-weight":700},"font-extrabold":{"font-weight":800},"font-black":{"font-weight":900},italic:{"font-style":"italic"},"not-italic":{"font-style":"normal"},"w-max":{width:"max-content"},"w-min":{width:"min-content"},"w-fit":{width:"fit-content"},"h-max":{height:"max-content"},"h-min":{height:"min-content"},"h-fit":{height:"fit-content"},"size-auto":{width:"auto",height:"auto"},"size-px":{width:"1px",height:"1px"},"size-full":{width:"100%",height:"100%"},"size-dvw":{width:"100dvw",height:"100dvw"},"size-dvh":{width:"100dvh",height:"100dvh"},"size-lvw":{width:"100lvw",height:"100lvw"},"size-lvh":{width:"100lvh",height:"100lvh"},"size-svw":{width:"100svw",height:"100svw"},"size-svh":{width:"100svh",height:"100svh"},"size-min":{width:"min-content",height:"min-content"},"size-max":{width:"max-content",height:"max-content"},"size-fit":{width:"fit-content",height:"fit-content"},"tracking-tighter":{"letter-spacing":"-0.05em"},"tracking-tight":{"letter-spacing":"-0.025em"},"tracking-normal":{"letter-spacing":"0"},"tracking-wide":{"letter-spacing":"0.025em"},"tracking-wider":{"letter-spacing":"0.05em"},"tracking-widest":{"letter-spacing":"0.1em"},"leading-none":{"line-height":"1"},"leading-tight":{"line-height":"1.25"},"leading-snug":{"line-height":"1.375"},"leading-normal":{"line-height":"1.5"},"leading-relaxed":{"line-height":"1.625"},"leading-loose":{"line-height":"2"},"text-left":{"text-align":"left"},"text-right":{"text-align":"right"},"text-center":{"text-align":"center"},"text-justify":{"text-align":"justify"},underline:{"text-decoration":"underline"},"no-underline":{"text-decoration":"none"},"decoration-none":{"text-decoration":"none"},"line-through":{"text-decoration":"line-through"},uppercase:{"text-transform":"uppercase"},lowercase:{"text-transform":"lowercase"},capitalize:{"text-transform":"capitalize"},truncate:{"white-space":"nowrap",overflow:"hidden","text-overflow":"ellipsis"},"text-elipsis":{"text-overflow":"ellipsis"},"text-clip":{"text-overflow":"clip"},"text-wrap":{"text-wrap":"wrap"},"text-nowrap":{"text-wrap":"nowrap"},"text-balance":{"text-wrap":"balance"},"text-pretty":{"text-wrap":"pretty"},"whitespace-normal":{"white-space":"normal"},"whitespace-nowrap":{"white-space":"nowrap"},"whitespace-pre":{"white-space":"pre"},"whitespace-pre-line":{"white-space":"pre-line"},"whitespace-pre-wrap":{"white-space":"pre-wrap"},"whitespace-break-spaces":{"white-space":"break-spaces"},relative:{position:"relative"},fixed:{position:"fixed"},absolute:{position:"absolute"},sticky:{position:"sticky"},"object-contain":{"object-fit":"contain"},"object-cover":{"object-fit":"cover"},"object-fill":{"object-fit":"fill"},"object-none":{"object-fit":"none"},block:{display:"block"},contents:{display:"contents"},hidden:{display:"none"},inline:{display:"inline"},"inline-block":{display:"inline-block"},visible:{visibility:"visible"},invisible:{visibility:"hidden"},collapse:{visibility:"collapse"},"list-none":{"list-style-type":"none"},"list-disc":{"list-style-type":"disc"},"list-decimal":{"list-style-type":"decimal"},flex:{display:"flex"},"flex-1":{flex:"1 1 0%"},"flex-inline":{display:"inline-flex"},"flex-row":{"flex-direction":"row"},"flex-col":{"flex-direction":"column"},"flex-row-reverse":{"flex-direction":"row-reverse"},"flex-col-reverse":{"flex-direction":"column-reverse"},"flex-wrap":{"flex-wrap":"wrap"},"flex-wrap-reverse":{"flex-wrap":"wrap-reverse"},"flex-nowrap":{"flex-wrap":"nowrap"},"justify-start":{"justify-content":"flex-start"},"justify-end":{"justify-content":"flex-end"},"justify-center":{"justify-content":"center"},"justify-between":{"justify-content":"space-between"},"justify-around":{"justify-content":"space-around"},"justify-evenly":{"justify-content":"space-evenly"},"justify-stretch":{"justify-content":"stretch"},"items-start":{"align-items":"flex-start"},"items-end":{"align-items":"flex-end"},"items-center":{"align-items":"center"},"items-stretch":{"align-items":"stretch"},"flex-grow":{"flex-grow":1},"flex-shrink":{"flex-shrink":1},"align-baseline":{"vertical-align":"baseline"},"align-top":{"vertical-align":"top"},"align-middle":{"vertical-align":"middle"},"align-bottom":{"vertical-align":"bottom"},"align-text-top":{"vertical-align":"text-top"},"align-text-bottom":{"vertical-align":"text-bottom"},"overflow-auto":{overflow:"auto"},"overflow-x-auto":{"overflow-x":"auto"},"overflow-y-auto":{"overflow-y":"auto"},"overflow-hidden":{overflow:"hidden"},"overflow-x-hidden":{"overflow-x":"hidden"},"overflow-y-hidden":{"overflow-y":"hidden"},"overflow-visible":{overflow:"visible"},"overscroll-auto":{"overscroll-behavior":"auto"},"overscroll-contain":{"overscroll-behavior":"contain"},"overscroll-none":{"overscroll-behavior":"none"},"overscroll-x-auto":{"overscroll-behavior-x":"auto"},"overscroll-x-contain":{"overscroll-behavior-x":"contain"},"overscroll-x-none":{"overscroll-behavior-x":"none"},"overscroll-y-auto":{"overscroll-behavior-y":"auto"},"overscroll-y-contain":{"overscroll-behavior-y":"contain"},"overscroll-y-none":{"overscroll-behavior-y":"none"},"z-auto":{"z-index":"auto"},"cursor-pointer":{cursor:"pointer"},"cursor-wait":{cursor:"wait"},"cursor-not-allowed":{cursor:"not-allowed"},"select-none":{"user-select":"none"},"select-all":{"user-select":"all"},"pointer-events-auto":{"pointer-events":"auto"},"pointer-events-none":{"pointer-events":"none"},"box-border":{"box-sizing":"border-box"},"box-content":{"box-sizing":"content-box"},resize:{resize:"both"},"resize-x":{resize:"horizontal"},"resize-y":{resize:"vertical"},"resize-none":{resize:"none"},border:{border:"1px solid"},"border-none":{border:"none"},"border-solid":{"border-style":"solid"},"border-dashed":{"border-style":"dashed"},"border-dotted":{"border-style":"dotted"},"border-collapse":{"border-collapse":"collapse"},"rounded-none":{"border-radius":"0"},rounded:{"border-radius":".25rem"},"rounded-sm":{"border-radius":".125rem"},"rounded-md":{"border-radius":".375rem"},"rounded-lg":{"border-radius":".5rem"},"rounded-xl":{"border-radius":".75rem"},"rounded-full":{"border-radius":"9999px"},shadow:{"box-shadow":"0 0 1px 0 rgba(0, 0, 0, 0.05)"},"shadow-sm":{"box-shadow":"0 1px 2px 0 rgba(0, 0, 0, 0.05)"},"shadow-md":{"box-shadow":"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)"},"shadow-lg":{"box-shadow":"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)"},"shadow-xl":{"box-shadow":"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)"},"shadow-2xl":{"box-shadow":"0 25px 50px -12px rgba(0, 0, 0, 0.25)"},"shadow-inner":{"box-shadow":"inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)"},"shadow-outline":{"box-shadow":"0 0 0 3px rgba(66, 153, 225, 0.5)"},"shadow-none":{"box-shadow":"none"},"transition-none":{transition:"none"},transition:{transition:"all 150ms ease-in-out"},"animate-none":{animation:"none"},"animate-spin":{animation:"spin 1s linear infinite"},"animate-ping":{animation:"ping 1s cubic-bezier(0, 0, 0.2, 1) infinite"},"animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}},Me=["@keyframes spin {\n from { transform: rotate(0deg) }\n to { transform: rotate(360deg) }\n }","@keyframes ping {\n 75%, 100% {\n transform: scale(2);\n opacity: 0;\n }\n }","@keyframes pulse {\n 0%, 100% { opacity: 1 }\n 50% { opacity: .5 }\n }"],Ue={red:{50:16772078,100:16764370,200:15702682,300:15037299,400:15684432,500:16007990,600:15022389,700:13840175,800:12986408,900:12000284},pink:{50:16573676,100:16301008,200:16027569,300:15753874,400:15483002,500:15277667,600:14162784,700:12720219,800:11342935,900:8916559},purple:{50:15984117,100:14794471,200:13538264,300:12216520,400:11225020,500:10233776,600:9315498,700:8069026,800:6953882,900:4854924},"deep-purple":{50:15591414,100:13747433,200:11771355,300:9795021,400:8280002,500:6765239,600:6174129,700:5320104,800:4532128,900:3218322},indigo:{50:15264502,100:12962537,200:10463450,300:7964363,400:6056896,500:4149685,600:3754411,700:3162015,800:2635155,900:1713022},blue:{50:14938877,100:12312315,200:9489145,300:6600182,400:4367861,500:2201331,600:2001125,700:1668818,800:1402304,900:870305},"light-blue":{50:14808574,100:11789820,200:8508666,300:5227511,400:2733814,500:240116,600:236517,700:166097,800:161725,900:87963},cyan:{50:14743546,100:11725810,200:8445674,300:5099745,400:2541274,500:48340,600:44225,700:38823,800:33679,900:24676},teal:{50:14742257,100:11722715,200:8440772,300:5093036,400:2533018,500:38536,600:35195,700:31083,800:26972,900:19776},green:{50:15267305,100:13166281,200:10868391,300:8505220,400:6732650,500:5025616,600:4431943,700:3706428,800:3046706,900:1793568},"light-green":{50:15857897,100:14478792,200:12968357,300:11457921,400:10275941,500:9159498,600:8172354,700:6856504,800:5606191,900:3369246},lime:{50:16382951,100:15791299,200:15134364,300:14477173,400:13951319,500:13491257,600:12634675,700:11514923,800:10394916,900:8550167},yellow:{50:16776679,100:16775620,200:16774557,300:16773494,400:16772696,500:16771899,600:16635957,700:16498733,800:16361509,900:16088855},amber:{50:16775393,100:16772275,200:16769154,300:16766287,400:16763432,500:16761095,600:16757504,700:16752640,800:16748288,900:16740096},orange:{50:16774112,100:16769202,200:16764032,300:16758605,400:16754470,500:16750592,600:16485376,700:16088064,800:15690752,900:15094016},"deep-orange":{50:16509415,100:16764092,200:16755601,300:16747109,400:16740419,500:16733986,600:16011550,700:15092249,800:14172949,900:12531212},brown:{50:15723497,100:14142664,200:12364452,300:10586239,400:9268835,500:7951688,600:7162945,700:6111287,800:5125166,900:4073251},gray:{50:16448250,100:16119285,200:15658734,300:14737632,400:12434877,500:10395294,600:7697781,700:6381921,800:4342338,900:2171169},"blue-gray":{50:15527921,100:13621468,200:11583173,300:9479342,400:7901340,500:6323595,600:5533306,700:4545124,800:3622735,900:2503224}};function ze(e){return`#${e.toString(16).padStart(6,"0")}`}function je(e){return Te.map(t=>`.${t}\\:${e}:${t}`)}function Fe(e,t){return Object.entries(Ae).map(([r,i])=>`@media (min-width: ${i}px) { .${r}\\:${e} { ${t} } }`)}function Ge(e,t){return e.includes("@media")&&!t.includes("@media")?1:!e.includes("@media")&&t.includes("@media")?-1:e.localeCompare(t)}function Ke(e){return Object.entries(e).flatMap(([e,t])=>[[`${t}-0`,`${e}: 0`],[`${t}-screen`,`${e}: 100v${e.includes("height")?"h":"w"}`],[`${t}-full`,`${e}: 100%`],...Ie.map(r=>[`${t}-${r}`,`${e}: ${r*Re}rem`]),...Ie.map(r=>[`-${t}-${r}`,`${e}: -${r*Re}rem`]),...Ie.map(r=>[`${t}-${r}px`,`${e}: ${r}px`]),...Ie.map(r=>[`-${t}-${r}px`,`${e}: -${r}px`]),...Ne.map(r=>[`${t}-${r}\\%`,`${e}: ${r}%`]),...Ne.map(r=>[`-${t}-${r}\\%`,`${e}: -${r}%`])]).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])}function We(e){return Object.entries(e).flatMap(([e,t])=>[[`${t}-auto`,`${e}: auto`],[`${t}x-auto`,`${e}-left: auto; ${e}-right: auto;`],[`${t}y-auto`,`${e}-top: auto; ${e}-bottom: auto;`],[`${t}x-0`,`${e}-left: 0; ${e}-right: 0;`],[`${t}y-0`,`${e}-top: 0; ${e}-bottom: 0;`],...Ie.map(e=>[e,e*Re]).map(([r,i])=>[`${t}x-${r}`,`${e}-left: ${i}rem; ${e}-right: ${i}rem;`]),...Ie.map(e=>[e,e*Re]).map(([r,i])=>[`${t}y-${r}`,`${e}-top: ${i}rem; ${e}-bottom: ${i}rem;`]),...Ie.map(r=>[`${t}x-${r}px`,`${e}-left: ${r}px; ${e}-right: ${r}px;`]),...Ie.map(r=>[`${t}y-${r}px`,`${e}-top: ${r}px; ${e}-bottom: ${r}px;`]),...Ne.map(r=>[`${t}x-${r}\\%`,`${e}-left: ${r}%; ${e}-right: ${r}%;`]),...Ne.map(r=>[`${t}y-${r}\\%`,`${e}-top: ${r}%; ${e}-bottom: ${r}%;`])]).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])}function He(){const e=[["white","#fff"],["black","#000"],["transparent","transparent"]].flatMap(([e,t])=>[[`text-${e}`,`color: ${t}`],[`fill-${e}`,`fill: ${t}`],[`bg-${e}`,`background-color: ${t}`],[`border-${e}`,`border-color: ${t}`]]),t=Object.entries(Ue).flatMap(([e,t])=>[[`text-${e}`,`color: ${ze(t[500])}`],[`fill-${e}`,`fill: ${ze(t[500])}`],[`bg-${e}`,`background-color: ${ze(t[500])}`],[`border-${e}`,`border-color: ${ze(t[500])}`]]),r=Object.entries(Ue).flatMap(([e,t])=>Object.entries(t).flatMap(([t,r])=>[[`text-${e}-${t}`,`color: ${ze(r)}`],[`fill-${e}-${t}`,`fill: ${ze(r)}`],[`bg-${e}-${t}`,`background-color: ${ze(r)}`],[`border-${e}-${t}`,`border-color: ${ze(r)}`]]));return[].concat(e).concat(t).concat(r).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])}function Ye(){return[...Me,...Object.entries(De).flatMap(([e,t])=>Object.entries(t).flatMap(([t,r])=>[`.${e} { ${t}: ${r} }`,`${je(e).join(",")} { ${t}: ${r} }`,...Fe(e,`${t}: ${r}`)])),...He(),...[["opacity-0","opacity: 0"],...Ne.map(e=>[`opacity-${e}`,"opacity: "+e/100])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...[...Ne.map(e=>[`z-${e}`,`z-index: ${e}`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...[...ke.map(e=>[`duration-${e}`,`transition-duration: ${e}ms`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...Ke(Ce),...Ke(Pe),...We(Pe),...(e=Se,Object.entries(e).flatMap(([e,t])=>[[`${t}t-0`,`${e}-top: 0`],[`${t}b-0`,`${e}-bottom: 0`],[`${t}l-0`,`${e}-left: 0`],[`${t}r-0`,`${e}-right: 0`],[`${t}t-auto`,`${e}-top: auto`],[`${t}b-auto`,`${e}-bottom: auto`],[`${t}l-auto`,`${e}-left: auto`],[`${t}r-auto`,`${e}-right: auto`],...["","-"].flatMap(r=>[...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}t-${i}`,`${e}-top: ${r}${n}rem`]),...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}b-${i}`,`${e}-bottom: ${r}${n}rem`]),...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}l-${i}`,`${e}-left: ${r}${n}rem`]),...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}r-${i}`,`${e}-right: ${r}${n}rem`]),...Ie.map(i=>[`${r}${t}t-${i}px`,`${e}-top: ${r}${i}px`]),...Ie.map(i=>[`${r}${t}b-${i}px`,`${e}-bottom: ${r}${i}px`]),...Ie.map(i=>[`${r}${t}l-${i}px`,`${e}-left: ${r}${i}px`]),...Ie.map(i=>[`${r}${t}r-${i}px`,`${e}-right: ${r}${i}px`]),...Ne.map(i=>[`${r}${t}t-${i}\\%`,`${e}-top: ${r}${i}%`]),...Ne.map(i=>[`${r}${t}b-${i}\\%`,`${e}-bottom: ${r}${i}%;`]),...Ne.map(i=>[`${r}${t}l-${i}\\%`,`${e}-left: ${r}${i}%`]),...Ne.map(i=>[`${r}${t}r-${i}\\%`,`${e}-right: ${r}${i}%`])])]).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])),...Ke(Se),...We(Se),...[["space-x-0 > *","margin-left: 0"],["space-y-0 > *","margin-top: 0"],...Ie.map(e=>[`space-x-${e} > :not(:first-child)`,`margin-left: ${e*Re}rem`]),...Ie.map(e=>[`space-y-${e} > :not(:first-child)`,`margin-top: ${e*Re}rem`]),...Ie.map(e=>[`space-x-${e}px > :not(:first-child)`,`margin-left: ${e}px`]),...Ie.map(e=>[`space-y-${e}px > :not(:first-child)`,`margin-top: ${e}px`]),["gap-0","gap: 0"],...Ie.map(e=>[`gap-${e}`,`gap: ${e*Re}rem`]),...Ie.map(e=>[`gap-${e}px`,`gap: ${e}px`]),...Ie.map(e=>[`gap-x-${e}`,`column-gap: ${e*Re}rem`]),...Ie.map(e=>[`gap-y-${e}`,`row-gap: ${e*Re}rem`]),...Ie.map(e=>[`gap-x-${e}px`,`column-gap: ${e}px`]),...Ie.map(e=>[`gap-y-${e}px`,`row-gap: ${e}px`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...Ke(Le),...[["border","border: 1px"],["border-x","border-inline-width: 1px"],["border-y","border-block-width: 1px"],...[0,...Oe].map(e=>[`border-${e}`,`border-width: ${e}px`]),...[0,...Oe].map(e=>[`border-x-${e}`,`border-inline-width: ${e}px;`]),...[0,...Oe].map(e=>[`border-y-${e}`,`border-block-width: ${e}px;`]),...["top","bottom","left","right"].flatMap(e=>[[`border-${e.slice(0,1)}`,`border-${e}: 1px`],...[0,...Oe].map(t=>[`border-${e.slice(0,1)}-${t}`,`border-${e}-width: ${t}px`])])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...[...Array.from({length:100},(e,t)=>t).map(e=>[`text-${e}px`,`font-size: ${e}px`]),...Array.from({length:100},(e,t)=>t*Re).map(e=>[`text-${e}rem`,`font-size: ${e}rem`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])].sort(Ge).join("\n");var e}class Be extends ye{impl="browser";dirpath=V(globalThis.location?.href??"http://localhost/");parseHTML(e,t={rootDocument:!1}){if(t.rootDocument)return(new DOMParser).parseFromString(e,"text/html");{const t=document.createRange();return t.selectNodeContents(document.body),t.createContextualFragment(e)}}serializeHTML(e){return(new XMLSerializer).serializeToString(e).replace(/\s?xmlns="[^"]+"/gm,"")}preprocessLocal(e,t){return this.preprocessRemote(e,t)}createElement(e,t){return(t||document).createElement(e)}textContent(e,t){e.textContent=t}}new Be;const Ve=new Be;globalThis.Mancha=Ve;const Ze=globalThis.document?.currentScript;if(globalThis.document?.currentScript?.hasAttribute("init")){const e=Ze?.hasAttribute("debug"),t=Ze?.getAttribute("cache"),r=Ze?.getAttribute("target")?.split("+")||["body"];window.addEventListener("load",()=>{r.map(async r=>{const i=globalThis.document.querySelector(r);await Ve.debug(e).mount(i,{cache:t})})})}if(globalThis.document?.currentScript?.hasAttribute("css")){const e=Ze?.getAttribute("css")?.split("+");for(const t of e){const e=document.createElement("style");switch(t){case"basic":p(e,Ee());break;case"utils":e.textContent=Ye();break;default:console.error(`Unknown style name: "${t}"`)}globalThis.document.head.appendChild(e)}}})();
|
|
1
|
+
(()=>{"use strict";const e=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function t(t){if(!function(t){const r=!e.test(t);return r}(t))return t}function r(e){return t(e)}const i={};function n(e){0}"undefined"!=typeof window&&window.TrustedScriptURL;class s{constructor(e,t){this.privateDoNotAccessOrElseWrappedAttributePrefix=t}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const o=s;function a(e){if(function(e){return e instanceof s}(e))return e.privateDoNotAccessOrElseWrappedAttributePrefix;throw new Error("")}"undefined"!=typeof window&&window.TrustedHTML;function l(e,t,r,i){if(0===e.length){throw new Error("")}const n=e.map(e=>a(e)),s=r.toLowerCase();if(n.every(e=>0!==s.indexOf(e)))throw new Error(`Attribute "${r}" does not match any of the allowed prefixes.`);t.setAttribute(r,i)}"undefined"!=typeof window&&window.TrustedScript;class c{}class h extends c{constructor(e,t){super(),n(),this.privateDoNotAccessOrElseWrappedStyleSheet=e}toString(){return this.privateDoNotAccessOrElseWrappedStyleSheet}}function d(e){return new h(e,i)}function u(e){if(e instanceof h)return e.privateDoNotAccessOrElseWrappedStyleSheet;throw new Error("")}function p(e,t){e.textContent=u(t)}Error;class f{iterable;constructor(e){this.iterable=e}filter(e){return new f(f.filterGenerator(e,this.iterable))}map(e){return new f(f.mapGenerator(e,this.iterable))}find(e){for(const t of this.iterable)if(e(t))return t}array(){return Array.from(this.iterable)}*generator(){for(const e of this.iterable)yield e}static*filterGenerator(e,t){for(const r of t)e(r)&&(yield r)}static*mapGenerator(e,t){for(const r of t)yield e(r)}static equals(e,t){const r=e[Symbol.iterator](),i=t[Symbol.iterator]();let n=r.next(),s=i.next();for(;!n.done&&!s.done;){if(n.value!==s.value)return!1;n=r.next(),s=i.next()}return n.done===s.done}}function m(e){return Object.isFrozen(e)&&Object.isFrozen(e.raw)}function g(e){return-1===e.toString().indexOf("`")}g(e=>e``)||g(e=>e`\0`)||g(e=>e`\n`)||g(e=>e`\u0000`),m``&&m`\0`&&m`\n`&&m`\u0000`;function _(e){const t=e[0].toLowerCase();return new o(i,t)}var w,v;function $(e){return{valueOf:e}.valueOf()}!function(e){e[e.STYLE_TAG=0]="STYLE_TAG",e[e.STYLE_ATTRIBUTE=1]="STYLE_ATTRIBUTE",e[e.HTML_ATTRIBUTE=2]="HTML_ATTRIBUTE"}(w||(w={}));class b{constructor(e,t,r,i,n){this.allowedElements=e,this.elementPolicies=t,this.allowedGlobalAttributes=r,this.globalAttributePolicies=i,this.globallyAllowedAttributePrefixes=n}isAllowedElement(e){return"FORM"!==e&&(this.allowedElements.has(e)||this.elementPolicies.has(e))}getAttributePolicy(e,t){const r=this.elementPolicies.get(t);if(null==r?void 0:r.has(e))return r.get(e);if(this.allowedGlobalAttributes.has(e))return{policyAction:v.KEEP};const i=this.globalAttributePolicies.get(e);return i||(this.globallyAllowedAttributePrefixes&&[...this.globallyAllowedAttributePrefixes].some(t=>0===e.indexOf(t))?{policyAction:v.KEEP}:{policyAction:v.DROP})}}!function(e){e[e.DROP=0]="DROP",e[e.KEEP=1]="KEEP",e[e.KEEP_AND_SANITIZE_URL=2]="KEEP_AND_SANITIZE_URL",e[e.KEEP_AND_NORMALIZE=3]="KEEP_AND_NORMALIZE",e[e.KEEP_AND_SANITIZE_STYLE=4]="KEEP_AND_SANITIZE_STYLE",e[e.KEEP_AND_USE_RESOURCE_URL_POLICY=5]="KEEP_AND_USE_RESOURCE_URL_POLICY",e[e.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET=6]="KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET"}(v||(v={}));new Set(["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"]);const x=["ARTICLE","SECTION","NAV","ASIDE","H1","H2","H3","H4","H5","H6","HEADER","FOOTER","ADDRESS","P","HR","PRE","BLOCKQUOTE","OL","UL","LH","LI","DL","DT","DD","FIGURE","FIGCAPTION","MAIN","DIV","EM","STRONG","SMALL","S","CITE","Q","DFN","ABBR","RUBY","RB","RT","RTC","RP","DATA","TIME","CODE","VAR","SAMP","KBD","SUB","SUP","I","B","U","MARK","BDI","BDO","SPAN","BR","WBR","INS","DEL","PICTURE","PARAM","TRACK","MAP","TABLE","CAPTION","COLGROUP","COL","TBODY","THEAD","TFOOT","TR","TD","TH","SELECT","DATALIST","OPTGROUP","OPTION","OUTPUT","PROGRESS","METER","FIELDSET","LEGEND","DETAILS","SUMMARY","MENU","DIALOG","SLOT","CANVAS","FONT","CENTER","ACRONYM","BASEFONT","BIG","DIR","HGROUP","STRIKE","TT"],y=[["A",new Map([["href",{policyAction:v.KEEP_AND_SANITIZE_URL}]])],["AREA",new Map([["href",{policyAction:v.KEEP_AND_SANITIZE_URL}]])],["LINK",new Map([["href",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY,conditions:new Map([["rel",new Set(["alternate","author","bookmark","canonical","cite","help","icon","license","next","prefetch","dns-prefetch","prerender","preconnect","preload","prev","search","subresource"])]])}]])],["SOURCE",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["IMG",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["VIDEO",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}]])],["AUDIO",new Map([["src",{policyAction:v.KEEP_AND_USE_RESOURCE_URL_POLICY}]])]],E=["title","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-current","aria-disabled","aria-dropeffect","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-live","aria-multiline","aria-multiselectable","aria-orientation","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","alt","align","autocapitalize","autocomplete","autocorrect","autofocus","autoplay","bgcolor","border","cellpadding","cellspacing","checked","color","cols","colspan","controls","datetime","disabled","download","draggable","enctype","face","formenctype","frameborder","height","hreflang","hidden","ismap","label","lang","loop","max","maxlength","media","minlength","min","multiple","muted","nonce","open","placeholder","preload","rel","required","reversed","role","rows","rowspan","selected","shape","size","sizes","slot","span","spellcheck","start","step","summary","translate","type","valign","value","width","wrap","itemscope","itemtype","itemid","itemprop","itemref"],A=[["dir",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["dir",new Set(["auto","ltr","rtl"])]]))}],["async",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["async",new Set(["async"])]]))}],["cite",{policyAction:v.KEEP_AND_SANITIZE_URL}],["loading",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["loading",new Set(["eager","lazy"])]]))}],["poster",{policyAction:v.KEEP_AND_SANITIZE_URL}],["target",{policyAction:v.KEEP_AND_NORMALIZE,conditions:$(()=>new Map([["target",new Set(["_self","_blank"])]]))}]];new b(new Set(x),new Map(y),new Set(E),new Map(A)),new b(new Set($(()=>x.concat(["STYLE"]))),new Map(y),new Set($(()=>E.concat(["id","name","class"]))),new Map($(()=>A.concat([["style",{policyAction:v.KEEP_AND_SANITIZE_STYLE}]]))));function R(e){return d(e[0])}const O=[_`:`,_`style`,_`class`];function*I(e,t=new Set){const r=new Set,i=Array.from(e.childNodes).filter(e=>!t.has(e));for(yield e;i.length;){const e=i.shift();r.has(e)||(r.add(e),yield e),e.childNodes&&Array.from(e.childNodes).filter(e=>!t.has(e)).forEach(e=>i.push(e))}}function N(e,t){return void 0!==e?.[t]}function k(e,t){return"function"==typeof e?.[t]}function T(e){return e.replace(/-./g,e=>e[1].toUpperCase())}function S(e,t){return N(e,"attribs")?e.attribs?.[t]??null:e.getAttribute?.(t)??null}function P(e,t,r=""){return S(e,r+t)||(e.dataset?.[T(t)]??null)}function C(e,t,r){N(e,"attribs")?e.attribs[t]=r:e.setAttribute?.(t,r)}function L(e,t,r){N(e,"attribs")?e.attribs[t]=r:l(O,e,t,r)}function D(e,t,r){switch(t){case"disabled":return void(e.disabled=r);case"selected":return void(e.selected=r);case"checked":return void(e.checked=r);default:e[t]=r}}function M(e,t){N(e,"attribs")?delete e.attribs[t]:e.removeAttribute?.(t)}function U(e,t,r=""){M(e,`${r}${t}`),M(e,`data-${t}`)}function z(e,t,r){if(N(e,"attribs")&&N(t,"attribs"))t.attribs[r]=e.attribs[r];else if(r.startsWith("data-")){const i=T(r.slice(5));t.dataset[i]=e.dataset?.[i]}else{const i=e?.getAttribute?.(r);L(t,r,i||"")}}function j(e){if(N(e,"firstElementChild"))return e.firstElementChild;return Array.from(e.children).find(e=>1===e.nodeType)}function F(e,...t){if(k(e,"replaceWith"))return e.replaceWith(...t);{const r=e,i=r.parentNode,n=Array.from(i.childNodes).indexOf(r);t.forEach(e=>e.parentNode=i),i.childNodes=[].concat(Array.from(i.childNodes).slice(0,n)).concat(t).concat(Array.from(i.childNodes).slice(n+1))}}function G(e,...t){k(e,"replaceChildren")?e.replaceChildren(...t):(e.childNodes=t,t.forEach(t=>t.parentNode=e))}function K(e,t){return k(t,"appendChild")?e.appendChild(t):(e.childNodes.push(t),t.parentNode=e,t)}function W(e,t){return k(t,"removeChild")?e.removeChild(t):(G(e,...Array.from(e.childNodes).filter(e=>e!==t)),t)}function H(e,t,r){return r?k(e,"insertBefore")?e.insertBefore(t,r):(F(r,t,r),t):K(e,t)}function Y(e,t=0){return e?e.length<=t?e:e.slice(0,t-1)+"…":""}function B(e,t=0){return globalThis.DocumentFragment&&e instanceof DocumentFragment?Array.from(e.childNodes).map(e=>B(e,t)).join(""):Y(e.outerHTML||e.nodeValue||String(e),t)}function V(e){return e.includes("/")?e.split("/").slice(0,-1).join("/"):""}var Z;!function(e){e.resolveIncludes=async function(e,t){const r=e,i=r.tagName?.toLowerCase();if(!["include","link"].includes(i))return;if("link"===i&&"subresource"!==S(r,"rel"))return;this.log("include directive found in:\n",B(e,128)),this.log("include params:",t);const n="link"===r.tagName.toLocaleLowerCase()?"href":"src",s=S(r,n);if(!s)throw new Error(`"${n}" attribute missing from ${B(e,128)}.`);const o=[];"include"===i&&o.push("src"),"link"===i&&o.push("rel","href");const a=t=>{const i=j(t);for(const e of Array.from(r.attributes))i&&!o.includes(e.name)&&z(r,i,e.name);F(e,...t.childNodes)},l={...t,rootDocument:!1,maxdepth:t?.maxdepth-1};if(0===l.maxdepth)throw new Error("Maximum recursion depth reached.");if(s.includes("://")||s.startsWith("//"))this.log("Including remote file from absolute path:",s),await this.preprocessRemote(s,l).then(a);else if(t?.dirpath?.includes("://")||t?.dirpath?.startsWith("//")){const e=s.startsWith("/")?s:`${t.dirpath}/${s}`;this.log("Including remote file from relative path:",e),await this.preprocessRemote(e,l).then(a)}else if("/"===s.charAt(0))this.log("Including local file from absolute path:",s),await this.preprocessLocal(s,l).then(a);else{const e=t?.dirpath&&"."!==t?.dirpath?`${t?.dirpath}/${s}`:s;this.log("Including local file from relative path:",e),await this.preprocessLocal(e,l).then(a)}},e.rebaseRelativePaths=async function(e,t){const i=e,n=i.tagName?.toLowerCase();if(!t?.dirpath)return;const s=S(i,"src"),o=S(i,"href"),a=s||o;if(!a||((l=a).includes("://")||l.startsWith("/")||l.startsWith("#")||l.startsWith("data:")))return;var l;const c=`${t.dirpath}/${a}`;this.log("Rebasing relative path as:",c),N(i,"attribs")?L(i,s?"src":"href",c):"img"===n?i.src=c:"a"===n?function(e,t){const i=r(t);void 0!==i&&(e.href=i)}(i,c):"source"===n||"audio"===n||"video"===n||"track"===n||"input"===n?i.src=c:"area"===n?function(e,t){const i=r(t);void 0!==i&&(e.href=i)}(i,c):this.log("Unable to rebase relative path for element:",n)},e.registerCustomElements=async function(e,t){const r=e,i=r.tagName?.toLowerCase(),n=(S(r,"is")||S(r,"alt"))?.toLowerCase();if(["template","div"].includes(i)&&n){if("div"===i&&"template"!==S(r,"role"))return;this._customElements.has(n)||(this.log(`Registering custom element: ${n}\n`,B(r,128)),this._customElements.set(n,r),W(r.parentNode,r))}},e.resolveCustomElements=async function(e,t){const r=e,i=r.tagName?.toLowerCase();let n=i;if("div"===n&&(n=S(r,"role")?.toLowerCase()||n),n&&this._customElements.has(n)){this.log(`Processing custom element: ${n}\n`,B(r,128));const t=this._customElements.get(n),s=(t.content||t).cloneNode(!0),o=j(s);if(o)for(const e of Array.from(r.attributes))"div"===i&&"role"===e.name||z(r,o,e.name);const a=new f(I(s)).find(e=>"slot"===e.tagName?.toLowerCase());a&&F(a,...r.childNodes),F(e,...s.childNodes)}},e.resolveTextNodeExpressions=async function(e,t){const r=e.nodeValue||"";if(3!==e.nodeType||!r?.trim())return;this.log("Processing node content value:\n",Y(r,128));const i=new RegExp(/{{ ([^}]+) }}/gm),n=Array.from(r.matchAll(i)).map(e=>e[1]);return this.effect(function(){let t=r;for(const r of n){const i=this.eval(r,{$elem:e});t=t.replace(`{{ ${r} }}`,String(i))}e.nodeValue=t})},e.resolveDataAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"data",":");if(i){this.log(":data attribute found in:\n",B(e,128)),U(r,"data",":");const n=t?.rootNode===e?this:this.subrenderer();e.renderer=n;const s=n.eval(i,{$elem:e});if(await Promise.all(Object.entries(s).map(([e,t])=>n._store.set(e,t))),n!==this)for(const t of I(e,this._skipNodes))this._skipNodes.add(t);await n.mount(e,t)}},e.resolveClassAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"class",":");if(i){this.log(":class attribute found in:\n",B(e,128)),U(r,"class",":");const t=S(r,"class")||"";return this.effect(function(){const n=this.eval(i,{$elem:e});L(r,"class",(n?`${t} ${n}`:t).trim())})}},e.resolveTextAttributes=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"text",":");if(i){this.log(":text attribute found in:\n",B(e,128)),U(r,"text",":");const t=t=>this.textContent(e,t);return this.effect(function(){t(this.eval(i,{$elem:e}))})}},e.resolveHtmlAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"html",":");return i?(this.log(":html attribute found in:\n",B(e,128)),U(r,"html",":"),this.effect(function(){const n=this.eval(i,{$elem:e});return new Promise(async e=>{const i=await this.preprocessString(n,t);await this.renderNode(i),G(r,i),e()})})):void 0},e.resolveEventAttributes=async function(e,t){if(this._skipNodes.has(e))return;const r=e;for(const t of Array.from(r.attributes||[]))if(t.name.startsWith(":on:")||t.name.startsWith("data-on-")){let i="",n=[];if(t.name.startsWith(":on:")?[i,...n]=t.name.substring(4).split("."):t.name.startsWith("data-on-")&&([i,...n]=t.name.substring(8).split(".")),!i)throw new Error(`Invalid event attribute: ${t.name}`);this.log(t.name,"attribute found in:\n",B(e,128)),U(r,t.name);const s="submit"===i&&"FORM"===r.tagName.toUpperCase();e.addEventListener?.(i,r=>((n.includes("prevent")||s)&&r.preventDefault(),this.eval(t.value,{$elem:e,$event:r})))}},e.resolveForAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"for",":")?.trim();if(i){this.log(":for attribute found in:\n",B(e,128)),U(r,"for",":");for(const t of I(e,this._skipNodes))this._skipNodes.add(t);const n=S(r,"style")||"";C(r,"style","display: none;");const s=e.parentNode,o=this.createElement("template",e.ownerDocument);H(s,o,e),W(s,e),K(o,e),this.log(":for template:\n",B(o,128));const a=i.split(" in ",2);if(2!==a.length)throw new Error(`Invalid :for format: \`${i}\`. Expected "{key} in {expression}".`);const l=[],[c,h]=a;await this.effect(function(){const r=this.eval(h,{$elem:e});if(this.log(":for list items:",r),l.splice(0,l.length).forEach(e=>{W(s,e),this._skipNodes.delete(e)}),!Array.isArray(r))return console.error(`Expression did not yield a list: \`${h}\` => \`${r}\``),Promise.resolve();const i=[];for(const s of r){const r=this.subrenderer();r._store.set(c,s);const o=e.cloneNode(!0);C(o,"style",n),l.push(o),this._skipNodes.add(o),i.push(r.mount(o,t)),this.log("Rendered list child:\n",B(o,128))}const a=o.nextSibling;for(const e of l)H(s,e,a);return Promise.all(i)})}},e.resolveBindAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"bind",":");if(i){this.log(":bind attribute found in:\n",B(e,128));const t=["change","input"],n=S(r,":bind:on")?.split(",")||r.dataset?.bindOn?.split(",")||t;U(r,"bind",":"),M(r,":bind:on"),M(r,"data-bind-on");const s="checkbox"===S(r,"type")?"checked":"value";i.includes(".")||this.has(i)||this.set(i,""),this.effect(function(){const t=this.eval(i,{$elem:e});"checked"===s?r.checked=!!t:r.value=t});const o=`${i} = $elem.${s}`;for(const t of n)e.addEventListener(t,()=>this.eval(o,{$elem:e}))}},e.resolveShowAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e,i=P(r,"show",":");if(i){this.log(":show attribute found in:\n",B(e,128)),U(r,"show",":");const t="none"===r.style?.display?"":r.style?.display??S(r,"style")?.split(";")?.find(e=>"display"===e.split(":")[0])?.split(":")?.at(1)?.trim();this.effect(function(){const n=this.eval(i,{$elem:e});r.style?r.style.display=n?t:"none":L(r,"style",`display: ${n?t:"none"};`)})}},e.resolveCustomAttribute=async function(e,t){if(this._skipNodes.has(e))return;const r=e;for(const t of Array.from(r.attributes||[])){const i=":attr:",n="data-attr-";if(t.name.startsWith(i)||t.name.startsWith(n)){this.log(t.name,"attribute found in:\n",B(e,128)),M(r,t.name);const s=t.name.split(i,2).at(-1)?.split(n,2).at(-1);this.effect(function(){const i=this.eval(t.value,{$elem:e});C(r,s,i)})}}},e.resolveCustomProperty=async function(e,t){if(this._skipNodes.has(e))return;const r=e;for(const t of Array.from(r.attributes||[])){const i=":prop:",n="data-prop-";if(t.name.startsWith(i)||t.name.startsWith(n)){this.log(t.name,"property found in:\n",B(e,128)),M(r,t.name);const s=t.name.split(i,2).at(-1)?.split(n,2).at(-1),o=T(s);this.effect(function(){const i=this.eval(t.value,{$elem:e});D(r,o,i)})}}},e.stripTypes=async function(e,t){const r=e;S(r,":types")&&M(r,":types"),S(r,"data-types")&&M(r,"data-types")}}(Z||(Z={}));const q=["this"],Q=["+","-","!"],X=["=","+","-","*","/","%","^","==","!=",">","<",">=","<=","||","&&","??","&","===","!==","|","|>"],J={"!":0,":":0,",":0,")":0,"]":0,"}":0,"|>":1,"?":2,"??":3,"||":4,"&&":5,"|":6,"^":7,"&":8,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},ee=["==","!=","<=",">=","||","&&","??","|>"],te=["===","!=="];var re;!function(e){e[e.STRING=1]="STRING",e[e.IDENTIFIER=2]="IDENTIFIER",e[e.DOT=3]="DOT",e[e.COMMA=4]="COMMA",e[e.COLON=5]="COLON",e[e.INTEGER=6]="INTEGER",e[e.DECIMAL=7]="DECIMAL",e[e.OPERATOR=8]="OPERATOR",e[e.GROUPER=9]="GROUPER",e[e.KEYWORD=10]="KEYWORD",e[e.ARROW=11]="ARROW"}(re||(re={}));const ie=(e,t,r=0)=>({kind:e,value:t,precedence:r}),ne=e=>9===e||10===e||13===e||32===e,se=e=>95===e||36===e||65<=(e&=-33)&&e<=90,oe=e=>se(e)||ae(e),ae=e=>48<=e&&e<=57;class le{_input;_index=-1;_tokenStart=0;_next;constructor(e){this._input=e,this._advance()}nextToken(){for(;ne(this._next);)this._advance(!0);if(34===(e=this._next)||39===e)return this._tokenizeString();var e;if(se(this._next))return this._tokenizeIdentOrKeyword();if(ae(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((e=>43===e||45===e||42===e||47===e||33===e||38===e||37===e||60===e||61===e||62===e||63===e||94===e||124===e)(this._next))return this._tokenizeOperator();if((e=>40===e||41===e||91===e||93===e||123===e||125===e)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(e){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),!0===e&&(this._tokenStart=this._index)):this._next=void 0}_getValue(e=0){const t=this._input.substring(this._tokenStart,this._index+e);return 0===e&&this._clearValue(),t}_clearValue(){this._tokenStart=this._index}_tokenizeString(){const e="unterminated string",t=this._next;for(this._advance(!0);this._next!==t;){if(void 0===this._next)throw new Error(e);if(92===this._next&&(this._advance(),void 0===this._next))throw new Error(e);this._advance()}const r=ie(re.STRING,this._getValue().replace(/\\(.)/g,(e,t)=>{switch(t){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return t}}));return this._advance(),r}_tokenizeIdentOrKeyword(){do{this._advance()}while(oe(this._next));const e=this._getValue(),t=(r=e,-1!==q.indexOf(r)?re.KEYWORD:re.IDENTIFIER);var r;return ie(t,e)}_tokenizeNumber(){do{this._advance()}while(ae(this._next));return 46===this._next?this._tokenizeDot():ie(re.INTEGER,this._getValue())}_tokenizeDot(){return this._advance(),ae(this._next)?this._tokenizeFraction():(this._clearValue(),ie(re.DOT,".",13))}_tokenizeComma(){return this._advance(!0),ie(re.COMMA,",")}_tokenizeColon(){return this._advance(!0),ie(re.COLON,":")}_tokenizeFraction(){do{this._advance()}while(ae(this._next));return ie(re.DECIMAL,this._getValue())}_tokenizeOperator(){this._advance();let e=this._getValue(2);if(-1!==te.indexOf(e))this._advance(),this._advance();else{if(e=this._getValue(1),"=>"===e)return this._advance(),ie(re.ARROW,e);-1!==ee.indexOf(e)&&this._advance()}return e=this._getValue(),ie(re.OPERATOR,e,J[e])}_tokenizeGrouper(){const e=String.fromCharCode(this._next),t=ie(re.GROUPER,e,J[e]);return this._advance(!0),t}}class ce{_kind;_tokenizer;_ast;_token;_value;constructor(e,t){this._tokenizer=new le(e),this._ast=t}parse(){return this._advance(),this._parseExpression()}_advance(e,t){if(!this._matches(e,t))throw new Error(`Expected kind ${e} (${t}), was ${this._token?.kind} (${this._token?.value})`);const r=this._tokenizer.nextToken();this._token=r,this._kind=r?.kind,this._value=r?.value}_matches(e,t){return!(e&&this._kind!==e||t&&this._value!==t)}_parseExpression(){if(!this._token)return this._ast.empty();const e=this._parseUnary();return void 0===e?void 0:this._parsePrecedence(e,0)}_parsePrecedence(e,t){if(void 0===e)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(re.GROUPER,"(")){const t=this._parseArguments();e=this._ast.invoke(e,void 0,t)}else if(this._matches(re.GROUPER,"[")){const t=this._parseIndex();e=this._ast.index(e,t)}else if(this._matches(re.DOT)){this._advance();const t=this._parseUnary();e=this._makeInvokeOrGetter(e,t)}else{if(this._matches(re.KEYWORD))break;if(!(this._matches(re.OPERATOR)&&this._token.precedence>=t))break;e="?"===this._value?this._parseTernary(e):this._parseBinary(e,this._token)}return e}_makeInvokeOrGetter(e,t){if(void 0===t)throw new Error("expected identifier");if("ID"===t.type)return this._ast.getter(e,t.value);if("Invoke"===t.type&&"ID"===t.receiver.type){const r=t.receiver;return this._ast.invoke(e,r.value,t.arguments)}throw new Error(`expected identifier: ${t}`)}_parseBinary(e,t){if(-1===X.indexOf(t.value))throw new Error(`unknown operator: ${t.value}`);this._advance();let r=this._parseUnary();for(;(this._kind===re.OPERATOR||this._kind===re.DOT||this._kind===re.GROUPER)&&this._token.precedence>t.precedence;)r=this._parsePrecedence(r,this._token.precedence);return this._ast.binary(e,t.value,r)}_parseUnary(){if(this._matches(re.OPERATOR)){const e=this._value;if(this._advance(),"+"===e||"-"===e){if(this._matches(re.INTEGER))return this._parseInteger(e);if(this._matches(re.DECIMAL))return this._parseDecimal(e)}if(-1===Q.indexOf(e))throw new Error(`unexpected token: ${e}`);const t=this._parsePrecedence(this._parsePrimary(),13);return this._ast.unary(e,t)}return this._parsePrimary()}_parseTernary(e){this._advance(re.OPERATOR,"?");const t=this._parseExpression();this._advance(re.COLON);const r=this._parseExpression();return this._ast.ternary(e,t,r)}_parsePrimary(){switch(this._kind){case re.KEYWORD:const e=this._value;if("this"===e)return this._advance(),this._ast.id(e);if(-1!==q.indexOf(e))throw new Error(`unexpected keyword: ${e}`);throw new Error(`unrecognized keyword: ${e}`);case re.IDENTIFIER:return this._parseInvokeOrIdentifier();case re.STRING:return this._parseString();case re.INTEGER:return this._parseInteger();case re.DECIMAL:return this._parseDecimal();case re.GROUPER:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case re.COLON:throw new Error('unexpected token ":"');default:return}}_parseList(){const e=[];do{if(this._advance(),this._matches(re.GROUPER,"]"))break;e.push(this._parseExpression())}while(this._matches(re.COMMA));return this._advance(re.GROUPER,"]"),this._ast.list(e)}_parseMap(){const e={};do{if(this._advance(),this._matches(re.GROUPER,"}"))break;const t=this._value;(this._matches(re.STRING)||this._matches(re.IDENTIFIER))&&this._advance(),this._advance(re.COLON),e[t]=this._parseExpression()}while(this._matches(re.COMMA));return this._advance(re.GROUPER,"}"),this._ast.map(e)}_parseInvokeOrIdentifier(){const e=this._value;if("true"===e)return this._advance(),this._ast.literal(!0);if("false"===e)return this._advance(),this._ast.literal(!1);if("null"===e)return this._advance(),this._ast.literal(null);if("undefined"===e)return this._advance(),this._ast.literal(void 0);const t=this._parseIdentifier(),r=this._parseArguments();return r?this._ast.invoke(t,void 0,r):t}_parseIdentifier(){if(!this._matches(re.IDENTIFIER))throw new Error(`expected identifier: ${this._value}`);const e=this._value;return this._advance(),this._ast.id(e)}_parseArguments(){if(!this._matches(re.GROUPER,"("))return;const e=[];do{if(this._advance(),this._matches(re.GROUPER,")"))break;const t=this._parseExpression();e.push(t)}while(this._matches(re.COMMA));return this._advance(re.GROUPER,")"),e}_parseIndex(){this._advance();const e=this._parseExpression();return this._advance(re.GROUPER,"]"),e}_parseParenOrFunction(){const e=this._parseArguments();if(this._matches(re.ARROW)){this._advance();const t=this._parseExpression(),r=e?.map(e=>e.value)??[];return this._ast.arrowFunction(r,t)}return this._ast.paren(e[0])}_parseString(){const e=this._ast.literal(this._value);return this._advance(),e}_parseInteger(e=""){const t=this._ast.literal(parseInt(`${e}${this._value}`,10));return this._advance(),t}_parseDecimal(e=""){const t=this._ast.literal(parseFloat(`${e}${this._value}`));return this._advance(),t}}const he={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,"==":(e,t)=>e==t,"!=":(e,t)=>e!=t,"===":(e,t)=>e===t,"!==":(e,t)=>e!==t,">":(e,t)=>e>t,">=":(e,t)=>e>=t,"<":(e,t)=>e<t,"<=":(e,t)=>e<=t,"||":(e,t)=>e||t,"&&":(e,t)=>e&&t,"??":(e,t)=>e??t,"|":(e,t)=>t(e),"|>":(e,t)=>t(e)},de={"+":e=>e,"-":e=>-e,"!":e=>!e};class ue{timeouts=new Map;debounce(e,t){return new Promise((r,i)=>{const n=this.timeouts.get(t);n&&clearTimeout(n),this.timeouts.set(t,setTimeout(()=>{try{r(t()),this.timeouts.delete(t)}catch(e){i(e)}},e))})}}const pe=new class{empty(){return{type:"Empty",evaluate:e=>e,getIds:e=>e}}literal(e){return{type:"Literal",value:e,evaluate(e){return this.value},getIds:e=>e}}id(e){return{type:"ID",value:e,evaluate(e){return"this"===this.value?e:e?.[this.value]},getIds(e){return e.push(this.value),e}}}unary(e,t){const r=de[e];return{type:"Unary",operator:e,child:t,evaluate(e){return r(this.child.evaluate(e))},getIds(e){return this.child.getIds(e)}}}binary(e,t,r){const i=he[t];return{type:"Binary",operator:t,left:e,right:r,evaluate(e){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const t=this.right.evaluate(e);let r,i;return"Getter"===this.left.type?(r=this.left.receiver.evaluate(e),i=this.left.name):"Index"===this.left.type?(r=this.left.receiver.evaluate(e),i=this.left.argument.evaluate(e)):"ID"===this.left.type&&(r=e,i=this.left.value),void 0===r?void 0:r[i]=t}return i(this.left.evaluate(e),this.right.evaluate(e))},getIds(e){return this.left.getIds(e),this.right.getIds(e),e}}}getter(e,t){return{type:"Getter",receiver:e,name:t,evaluate(e){return this.receiver.evaluate(e)?.[this.name]},getIds(e){return this.receiver.getIds(e),e}}}invoke(e,t,r){if(null!=t&&"string"!=typeof t)throw new Error("method not a string");return{type:"Invoke",receiver:e,method:t,arguments:r,evaluate(e){const r=this.receiver.evaluate(e),i=this.method?r:e?.this??e,n=this.method?r?.[t]:r,s=(this.arguments??[]).map(t=>t?.evaluate(e));return n?.apply?.(i,s)},getIds(e){return this.receiver.getIds(e),this.arguments?.forEach(t=>t?.getIds(e)),e}}}paren(e){return e}index(e,t){return{type:"Index",receiver:e,argument:t,evaluate(e){return this.receiver.evaluate(e)?.[this.argument.evaluate(e)]},getIds(e){return this.receiver.getIds(e),e}}}ternary(e,t,r){return{type:"Ternary",condition:e,trueExpr:t,falseExpr:r,evaluate(e){return this.condition.evaluate(e)?this.trueExpr.evaluate(e):this.falseExpr.evaluate(e)},getIds(e){return this.condition.getIds(e),this.trueExpr.getIds(e),this.falseExpr.getIds(e),e}}}map(e){return{type:"Map",entries:e,evaluate(t){const r={};if(e&&this.entries)for(const i in e){const e=this.entries[i];e&&(r[i]=e.evaluate(t))}return r},getIds(t){if(e&&this.entries)for(const r in e){const e=this.entries[r];e&&e.getIds(t)}return t}}}list(e){return{type:"List",items:e,evaluate(e){return this.items?.map(t=>t?.evaluate(e))},getIds(e){return this.items?.forEach(t=>t?.getIds(e)),e}}}arrowFunction(e,t){return{type:"ArrowFunction",params:e,body:t,evaluate(e){const t=this.params,r=this.body;return function(...i){const n=Object.fromEntries(t.map((e,t)=>[e,i[t]])),s=new Proxy(e??{},{set:(e,t,r)=>(n.hasOwnProperty(t)&&(n[t]=r),e[t]=r),get:(e,t)=>n.hasOwnProperty(t)?n[t]:e[t]});return r.evaluate(s)}},getIds(e){return this.body.getIds(e).filter(e=>!this.params.includes(e))}}}};function fe(e,t){const r=e?._store;return r?.has(t)?r.get(t):r?.has("$parent")?fe(r.get("$parent"),t):null}function me(e,t){const r=e?._store;return r?.has(t)?e:r?.has("$parent")?me(r.get("$parent"),t):null}class ge extends ue{evalkeys=["$elem","$event"];expressionCache=new Map;observers=new Map;keyHandlers=new Map;_observer=null;_store=new Map;_lock=Promise.resolve();constructor(e){super();for(let[t,r]of Object.entries(e||{}))this.set(t,r)}wrapFunction(e){return(...t)=>e.call(this.$,...t)}wrapObject(e,t){return null==e||((r=e)instanceof ge||r.__is_proxy__)||e.constructor!==Object&&!Array.isArray(e)?e:new Proxy(e,{deleteProperty:(e,r)=>r in e&&(delete e[r],t(),!0),set:(r,i,n,s)=>{"object"==typeof n&&null!=e&&(n=this.wrapObject(n,t));const o=Reflect.set(r,i,n,s);return t(),o},get:(e,t,r)=>"__is_proxy__"===t||Reflect.get(e,t,r)});var r}watch(e,t){const r=me(this,e);if(!r)throw new Error(`Cannot watch key "${e}" as it does not exist in the store.`);r.observers.has(e)||r.observers.set(e,new Set),r.observers.get(e)?.has(t)||r.observers.get(e)?.add(t)}addKeyHandler(e,t){this.keyHandlers.has(e)||this.keyHandlers.set(e,new Set),this.keyHandlers.get(e).add(t)}async notify(e,t=10){const r=me(this,e),i=Array.from(r?.observers.get(e)||[]);await this.debounce(t,()=>Promise.all(i.map(e=>e.call(this.proxify(e)))))}get(e,t){return t&&this.watch(e,t),fe(this,e)}async set(e,t){if(t===this._store.get(e))return;const r=()=>this.notify(e);t&&"function"==typeof t&&(t=this.wrapFunction(t)),t&&"object"==typeof t&&(t=this.wrapObject(t,r)),function(e,t,r){const i=me(e,t);i?i._store.set(t,r):e._store.set(t,r)}(this,e,t);for(const[r,i]of this.keyHandlers.entries())if(r.test(e))for(const r of i)await Promise.resolve(r.call(this.$,e,t));await r()}async del(e){await this.set(e,null),this._store.delete(e),this.observers.delete(e)}keys(){return Array.from(this._store.keys())}has(e){return this._store.has(e)}effect(e){return e.call(this.proxify(e))}proxify(e){const t=Array.from(this._store.entries()).map(([e])=>e),r=Object.fromEntries(t.map(e=>[e,null]));return new Proxy(r,{get:(t,r,i)=>"string"==typeof r&&me(this,r)?this.get(r,e):"$"===r?this.proxify(e):Reflect.get(this,r,i),set:(e,t,r,i)=>("string"!=typeof t||t in this?Reflect.set(this,t,r,i):this.set(t,r),!0)})}get $(){return this.proxify()}makeEvalFunction(e){if(e.includes(";"))throw new Error("Complex expressions are not supported.");let t=null;if(e.includes(" = ")){const[r,i]=e.split(" = ");t=r.trim(),e=i.trim()}return(r,i)=>{const n=((e,t)=>new ce(e,t).parse())(e,pe),s=n?.getIds([])?.map(e=>[e,i[e]??r[e]??globalThis[e]]),o=n?.evaluate(Object.fromEntries(s||[]));if(!t)return o;!function(e,t,r){const i=t.split(".");for(let t=0;t<i.length-1;t++)i[t]in e||(e[i[t]]={}),e=e[i[t]];e[i[i.length-1]]=r}(r,t,o)}}cachedExpressionFunction(e){return e=e.trim(),this.expressionCache.has(e)||this.expressionCache.set(e,this.makeEvalFunction(e)),this.expressionCache.get(e)}eval(e,t={}){const r=this._observer?this:this.$;if(this._store.has(e))return r[e];{const i=this.cachedExpressionFunction(e);try{return i(r,t)}catch(t){return console.error(`Failed to evaluate expression: ${e}`),console.error(t),null}}}}const _e="$$";function we(){return new URL(globalThis.window?.location?.href||"http://localhost/")}function ve(e){return`${_e}${e}`}function $e(e){return e.keys().filter(e=>e.startsWith(_e))}function be(e,t,r){const i=function(e){return e.substring(2)}(t);let n=!1;if(r){const t=String(r);e.searchParams.get(i)!==t&&(e.searchParams.set(i,t),n=!0)}else e.searchParams.has(i)&&(e.searchParams.delete(i),n=!0);return n}async function xe(e){const t=we();await async function(e,t){for(const[r,i]of t.searchParams.entries()){const t=ve(r);e.get(t)!==i&&await e.set(t,i)}}(e,t),function(e,t){let r=!1;for(const i of $e(t))be(e,i,t.get(i))&&(r=!0);r&&globalThis.window?.history?.replaceState({},"",e.toString())}(t,e),e.addKeyHandler(new RegExp("^\\$\\$"),(e,t)=>{const r=we();be(r,e,t)&&globalThis.window?.history?.replaceState({},"",r.toString())}),globalThis.window?.addEventListener("popstate",function(e){return async()=>{const t=we(),r=new Set;for(const[i,n]of t.searchParams.entries()){const t=ve(i);r.add(t),e.get(t)!==n&&e.set(t,n)}const i=$e(e);for(const t of i)r.has(t)||e.del(t)}}(e))}class ye extends ge{debugging=!1;dirpath="";_skipNodes=new Set;_customElements=new Map;debug(e){return this.debugging=e,this}async fetchRemote(e,t){return fetch(e,{cache:t?.cache??"default"}).then(e=>e.text())}async fetchLocal(e,t){return this.fetchRemote(e,t)}async preprocessString(e,t){this.log("Preprocessing string content with params:\n",t);const r=this.parseHTML(e,t);return await this.preprocessNode(r,t),r}async preprocessRemote(e,t){const r={};t?.cache&&(r.cache=t.cache);const i=await fetch(e,r).then(e=>e.text());return this.preprocessString(i,{...t,dirpath:V(e),rootDocument:t?.rootDocument??!e.endsWith(".tpl.html")})}async preprocessLocal(e,t){const r=await this.fetchLocal(e,t);return this.preprocessString(r,{...t,dirpath:V(e),rootDocument:t?.rootDocument??!e.endsWith(".tpl.html")})}subrenderer(){const e=(new this.constructor).debug(this.debugging);return e._store.set("$parent",this),e._store.set("$rootRenderer",this.get("$rootRenderer")??this),e._customElements=this._customElements,e}log(...e){this.debugging&&console.debug(...e)}async preprocessNode(e,t){t={dirpath:this.dirpath,maxdepth:10,...t};const r=new f(I(e,this._skipNodes)).map(async e=>{this.log("Preprocessing node:\n",B(e,128)),await Z.resolveIncludes.call(this,e,t),await Z.rebaseRelativePaths.call(this,e,t),await Z.registerCustomElements.call(this,e,t),await Z.resolveCustomElements.call(this,e,t)});return await Promise.all(r.generator()),e}async renderNode(e,t){for(const r of I(e,this._skipNodes))this.log("Rendering node:\n",B(r,128)),await Z.resolveForAttribute.call(this,r,t),await Z.resolveDataAttribute.call(this,r,t),await Z.resolveTextAttributes.call(this,r,t),await Z.resolveHtmlAttribute.call(this,r,t),await Z.resolveShowAttribute.call(this,r,t),await Z.resolveClassAttribute.call(this,r,t),await Z.resolveBindAttribute.call(this,r,t),await Z.resolveEventAttributes.call(this,r,t),await Z.resolveTextNodeExpressions.call(this,r,t),await Z.resolveCustomAttribute.call(this,r,t),await Z.resolveCustomProperty.call(this,r,t),await Z.stripTypes.call(this,r,t);return e}async mount(e,t){t={...t,rootNode:e},D(e,"renderer",this),this._store.set("$rootNode",e),this.has("$rootRenderer")||this._store.set("$rootRenderer",this),this.get("$rootRenderer")===this&&await xe(this),await this.preprocessNode(e,t),await this.renderNode(e,t)}}function Ee(){return d([R`html{`,R`max-width: 70ch;`,R`padding: 2em 1em;`,R`margin: auto;`,R`line-height: 1.75;`,R`font-size: 1.25em;`,R`font-family: sans-serif;`,R`}`,R`h1,h2,h3,h4,h5,h6{`,R`margin: 1em 0 0.5em;`,R`}`,R`p,ul,ol{`,R`margin-bottom: 1em;`,R`color: #1d1d1d;`,R`}`].map(u).join(""))}const Ae={sm:640,md:768,lg:1024,xl:1280},Re=.25,Oe=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],Ie=[...Oe,16,20,24,25,28,30,32,36,40,44,48,50,52,56,60,64,72,80,96,100,112,128,144,160,192,200,224,256,288,300,320,384,400,448,500,512,...Object.values(Ae)],Ne=[1,2,5,10,20,25,30,40,50,60,70,75,80,90,95,98,99,100],ke=[75,100,150,200,300,500,700,1e3],Te=["hover","focus","disabled","active"],Se={margin:"m",padding:"p"},Pe={width:"w",height:"h"},Ce={top:"top",right:"right",bottom:"bottom",left:"left"},Le={"min-width":"min-w","min-height":"min-h","max-width":"max-w","max-height":"max-h"},De={"font-mono":{"font-family":"monospace"},"font-sans":{"font-family":"sans-serif"},"font-serif":{"font-family":"serif"},"font-cursive":{"font-family":"cursive"},"text-xs":{"font-size":".75rem","line-height":"calc(1 / 0.75)"},"text-sm":{"font-size":".875rem","line-height":"calc(1.25 / 0.875)"},"text-base":{"font-size":"1rem","line-height":"calc(1.5 / 1)"},"text-lg":{"font-size":"1.125rem","line-height":"calc(1.75 / 1.125)"},"text-xl":{"font-size":"1.25rem","line-height":"calc(1.75 / 1.25)"},"text-2xl":{"font-size":"1.5rem","line-height":"calc(2 / 1.5)"},"text-3xl":{"font-size":"1.875rem","line-height":"calc(2.25 / 1.875)"},"text-4xl":{"font-size":"2.25rem","line-height":"calc(2.5 / 2.25)"},"text-5xl":{"font-size":"3rem","line-height":"1"},"text-6xl":{"font-size":"3.75rem","line-height":"1"},"text-7xl":{"font-size":"4.5rem","line-height":"1"},"font-thin":{"font-weight":100},"font-extralight":{"font-weight":200},"font-light":{"font-weight":300},"font-normal":{"font-weight":400},"font-medium":{"font-weight":500},"font-semibold":{"font-weight":600},"font-bold":{"font-weight":700},"font-extrabold":{"font-weight":800},"font-black":{"font-weight":900},italic:{"font-style":"italic"},"not-italic":{"font-style":"normal"},"w-max":{width:"max-content"},"w-min":{width:"min-content"},"w-fit":{width:"fit-content"},"h-max":{height:"max-content"},"h-min":{height:"min-content"},"h-fit":{height:"fit-content"},"size-auto":{width:"auto",height:"auto"},"size-px":{width:"1px",height:"1px"},"size-full":{width:"100%",height:"100%"},"size-dvw":{width:"100dvw",height:"100dvw"},"size-dvh":{width:"100dvh",height:"100dvh"},"size-lvw":{width:"100lvw",height:"100lvw"},"size-lvh":{width:"100lvh",height:"100lvh"},"size-svw":{width:"100svw",height:"100svw"},"size-svh":{width:"100svh",height:"100svh"},"size-min":{width:"min-content",height:"min-content"},"size-max":{width:"max-content",height:"max-content"},"size-fit":{width:"fit-content",height:"fit-content"},"tracking-tighter":{"letter-spacing":"-0.05em"},"tracking-tight":{"letter-spacing":"-0.025em"},"tracking-normal":{"letter-spacing":"0"},"tracking-wide":{"letter-spacing":"0.025em"},"tracking-wider":{"letter-spacing":"0.05em"},"tracking-widest":{"letter-spacing":"0.1em"},"leading-none":{"line-height":"1"},"leading-tight":{"line-height":"1.25"},"leading-snug":{"line-height":"1.375"},"leading-normal":{"line-height":"1.5"},"leading-relaxed":{"line-height":"1.625"},"leading-loose":{"line-height":"2"},"text-left":{"text-align":"left"},"text-right":{"text-align":"right"},"text-center":{"text-align":"center"},"text-justify":{"text-align":"justify"},underline:{"text-decoration":"underline"},"no-underline":{"text-decoration":"none"},"decoration-none":{"text-decoration":"none"},"line-through":{"text-decoration":"line-through"},uppercase:{"text-transform":"uppercase"},lowercase:{"text-transform":"lowercase"},capitalize:{"text-transform":"capitalize"},truncate:{"white-space":"nowrap",overflow:"hidden","text-overflow":"ellipsis"},"text-elipsis":{"text-overflow":"ellipsis"},"text-clip":{"text-overflow":"clip"},"text-wrap":{"text-wrap":"wrap"},"text-nowrap":{"text-wrap":"nowrap"},"text-balance":{"text-wrap":"balance"},"text-pretty":{"text-wrap":"pretty"},"whitespace-normal":{"white-space":"normal"},"whitespace-nowrap":{"white-space":"nowrap"},"whitespace-pre":{"white-space":"pre"},"whitespace-pre-line":{"white-space":"pre-line"},"whitespace-pre-wrap":{"white-space":"pre-wrap"},"whitespace-break-spaces":{"white-space":"break-spaces"},relative:{position:"relative"},fixed:{position:"fixed"},absolute:{position:"absolute"},sticky:{position:"sticky"},"object-contain":{"object-fit":"contain"},"object-cover":{"object-fit":"cover"},"object-fill":{"object-fit":"fill"},"object-none":{"object-fit":"none"},block:{display:"block"},contents:{display:"contents"},hidden:{display:"none"},inline:{display:"inline"},"inline-block":{display:"inline-block"},visible:{visibility:"visible"},invisible:{visibility:"hidden"},collapse:{visibility:"collapse"},"list-none":{"list-style-type":"none"},"list-disc":{"list-style-type":"disc"},"list-decimal":{"list-style-type":"decimal"},flex:{display:"flex"},"flex-1":{flex:"1 1 0%"},"flex-inline":{display:"inline-flex"},"flex-row":{"flex-direction":"row"},"flex-col":{"flex-direction":"column"},"flex-row-reverse":{"flex-direction":"row-reverse"},"flex-col-reverse":{"flex-direction":"column-reverse"},"flex-wrap":{"flex-wrap":"wrap"},"flex-wrap-reverse":{"flex-wrap":"wrap-reverse"},"flex-nowrap":{"flex-wrap":"nowrap"},"justify-start":{"justify-content":"flex-start"},"justify-end":{"justify-content":"flex-end"},"justify-center":{"justify-content":"center"},"justify-between":{"justify-content":"space-between"},"justify-around":{"justify-content":"space-around"},"justify-evenly":{"justify-content":"space-evenly"},"justify-stretch":{"justify-content":"stretch"},"items-start":{"align-items":"flex-start"},"items-end":{"align-items":"flex-end"},"items-center":{"align-items":"center"},"items-stretch":{"align-items":"stretch"},"flex-grow":{"flex-grow":1},"flex-shrink":{"flex-shrink":1},"align-baseline":{"vertical-align":"baseline"},"align-top":{"vertical-align":"top"},"align-middle":{"vertical-align":"middle"},"align-bottom":{"vertical-align":"bottom"},"align-text-top":{"vertical-align":"text-top"},"align-text-bottom":{"vertical-align":"text-bottom"},"overflow-auto":{overflow:"auto"},"overflow-x-auto":{"overflow-x":"auto"},"overflow-y-auto":{"overflow-y":"auto"},"overflow-hidden":{overflow:"hidden"},"overflow-x-hidden":{"overflow-x":"hidden"},"overflow-y-hidden":{"overflow-y":"hidden"},"overflow-visible":{overflow:"visible"},"overscroll-auto":{"overscroll-behavior":"auto"},"overscroll-contain":{"overscroll-behavior":"contain"},"overscroll-none":{"overscroll-behavior":"none"},"overscroll-x-auto":{"overscroll-behavior-x":"auto"},"overscroll-x-contain":{"overscroll-behavior-x":"contain"},"overscroll-x-none":{"overscroll-behavior-x":"none"},"overscroll-y-auto":{"overscroll-behavior-y":"auto"},"overscroll-y-contain":{"overscroll-behavior-y":"contain"},"overscroll-y-none":{"overscroll-behavior-y":"none"},"z-auto":{"z-index":"auto"},"cursor-pointer":{cursor:"pointer"},"cursor-wait":{cursor:"wait"},"cursor-not-allowed":{cursor:"not-allowed"},"select-none":{"user-select":"none"},"select-all":{"user-select":"all"},"pointer-events-auto":{"pointer-events":"auto"},"pointer-events-none":{"pointer-events":"none"},"box-border":{"box-sizing":"border-box"},"box-content":{"box-sizing":"content-box"},resize:{resize:"both"},"resize-x":{resize:"horizontal"},"resize-y":{resize:"vertical"},"resize-none":{resize:"none"},border:{border:"1px solid"},"border-none":{border:"none"},"border-solid":{"border-style":"solid"},"border-dashed":{"border-style":"dashed"},"border-dotted":{"border-style":"dotted"},"border-collapse":{"border-collapse":"collapse"},"rounded-none":{"border-radius":"0"},rounded:{"border-radius":".25rem"},"rounded-sm":{"border-radius":".125rem"},"rounded-md":{"border-radius":".375rem"},"rounded-lg":{"border-radius":".5rem"},"rounded-xl":{"border-radius":".75rem"},"rounded-full":{"border-radius":"9999px"},shadow:{"box-shadow":"0 0 1px 0 rgba(0, 0, 0, 0.05)"},"shadow-sm":{"box-shadow":"0 1px 2px 0 rgba(0, 0, 0, 0.05)"},"shadow-md":{"box-shadow":"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)"},"shadow-lg":{"box-shadow":"0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)"},"shadow-xl":{"box-shadow":"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)"},"shadow-2xl":{"box-shadow":"0 25px 50px -12px rgba(0, 0, 0, 0.25)"},"shadow-inner":{"box-shadow":"inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)"},"shadow-outline":{"box-shadow":"0 0 0 3px rgba(66, 153, 225, 0.5)"},"shadow-none":{"box-shadow":"none"},"transition-none":{transition:"none"},transition:{transition:"all 150ms ease-in-out"},"animate-none":{animation:"none"},"animate-spin":{animation:"spin 1s linear infinite"},"animate-ping":{animation:"ping 1s cubic-bezier(0, 0, 0.2, 1) infinite"},"animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},"bg-auto":{"background-size":"auto"},"bg-cover":{"background-size":"cover"},"bg-contain":{"background-size":"contain"},"bg-no-repeat":{"background-repeat":"no-repeat"},"bg-fixed":{"background-attachment":"fixed"},"bg-local":{"background-attachment":"local"},"bg-scroll":{"background-attachment":"scroll"}},Me=["@keyframes spin {\n from { transform: rotate(0deg) }\n to { transform: rotate(360deg) }\n }","@keyframes ping {\n 75%, 100% {\n transform: scale(2);\n opacity: 0;\n }\n }","@keyframes pulse {\n 0%, 100% { opacity: 1 }\n 50% { opacity: .5 }\n }"],Ue={red:{50:16772078,100:16764370,200:15702682,300:15037299,400:15684432,500:16007990,600:15022389,700:13840175,800:12986408,900:12000284},pink:{50:16573676,100:16301008,200:16027569,300:15753874,400:15483002,500:15277667,600:14162784,700:12720219,800:11342935,900:8916559},purple:{50:15984117,100:14794471,200:13538264,300:12216520,400:11225020,500:10233776,600:9315498,700:8069026,800:6953882,900:4854924},"deep-purple":{50:15591414,100:13747433,200:11771355,300:9795021,400:8280002,500:6765239,600:6174129,700:5320104,800:4532128,900:3218322},indigo:{50:15264502,100:12962537,200:10463450,300:7964363,400:6056896,500:4149685,600:3754411,700:3162015,800:2635155,900:1713022},blue:{50:14938877,100:12312315,200:9489145,300:6600182,400:4367861,500:2201331,600:2001125,700:1668818,800:1402304,900:870305},"light-blue":{50:14808574,100:11789820,200:8508666,300:5227511,400:2733814,500:240116,600:236517,700:166097,800:161725,900:87963},cyan:{50:14743546,100:11725810,200:8445674,300:5099745,400:2541274,500:48340,600:44225,700:38823,800:33679,900:24676},teal:{50:14742257,100:11722715,200:8440772,300:5093036,400:2533018,500:38536,600:35195,700:31083,800:26972,900:19776},green:{50:15267305,100:13166281,200:10868391,300:8505220,400:6732650,500:5025616,600:4431943,700:3706428,800:3046706,900:1793568},"light-green":{50:15857897,100:14478792,200:12968357,300:11457921,400:10275941,500:9159498,600:8172354,700:6856504,800:5606191,900:3369246},lime:{50:16382951,100:15791299,200:15134364,300:14477173,400:13951319,500:13491257,600:12634675,700:11514923,800:10394916,900:8550167},yellow:{50:16776679,100:16775620,200:16774557,300:16773494,400:16772696,500:16771899,600:16635957,700:16498733,800:16361509,900:16088855},amber:{50:16775393,100:16772275,200:16769154,300:16766287,400:16763432,500:16761095,600:16757504,700:16752640,800:16748288,900:16740096},orange:{50:16774112,100:16769202,200:16764032,300:16758605,400:16754470,500:16750592,600:16485376,700:16088064,800:15690752,900:15094016},"deep-orange":{50:16509415,100:16764092,200:16755601,300:16747109,400:16740419,500:16733986,600:16011550,700:15092249,800:14172949,900:12531212},brown:{50:15723497,100:14142664,200:12364452,300:10586239,400:9268835,500:7951688,600:7162945,700:6111287,800:5125166,900:4073251},gray:{50:16448250,100:16119285,200:15658734,300:14737632,400:12434877,500:10395294,600:7697781,700:6381921,800:4342338,900:2171169},"blue-gray":{50:15527921,100:13621468,200:11583173,300:9479342,400:7901340,500:6323595,600:5533306,700:4545124,800:3622735,900:2503224}};function ze(e){return`#${e.toString(16).padStart(6,"0")}`}function je(e){return Te.map(t=>`.${t}\\:${e}:${t}`)}function Fe(e,t){return Object.entries(Ae).map(([r,i])=>`@media (min-width: ${i}px) { .${r}\\:${e} { ${t} } }`)}function Ge(e,t){return e.includes("@media")&&!t.includes("@media")?1:!e.includes("@media")&&t.includes("@media")?-1:e.localeCompare(t)}function Ke(e){return Object.entries(e).flatMap(([e,t])=>[[`${t}-0`,`${e}: 0`],[`${t}-screen`,`${e}: 100v${e.includes("height")?"h":"w"}`],[`${t}-full`,`${e}: 100%`],...Ie.map(r=>[`${t}-${r}`,`${e}: ${r*Re}rem`]),...Ie.map(r=>[`-${t}-${r}`,`${e}: -${r*Re}rem`]),...Ie.map(r=>[`${t}-${r}px`,`${e}: ${r}px`]),...Ie.map(r=>[`-${t}-${r}px`,`${e}: -${r}px`]),...Ne.map(r=>[`${t}-${r}\\%`,`${e}: ${r}%`]),...Ne.map(r=>[`-${t}-${r}\\%`,`${e}: -${r}%`])]).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])}function We(e){return Object.entries(e).flatMap(([e,t])=>[[`${t}-auto`,`${e}: auto`],[`${t}x-auto`,`${e}-left: auto; ${e}-right: auto;`],[`${t}y-auto`,`${e}-top: auto; ${e}-bottom: auto;`],[`${t}x-0`,`${e}-left: 0; ${e}-right: 0;`],[`${t}y-0`,`${e}-top: 0; ${e}-bottom: 0;`],...Ie.map(e=>[e,e*Re]).map(([r,i])=>[`${t}x-${r}`,`${e}-left: ${i}rem; ${e}-right: ${i}rem;`]),...Ie.map(e=>[e,e*Re]).map(([r,i])=>[`${t}y-${r}`,`${e}-top: ${i}rem; ${e}-bottom: ${i}rem;`]),...Ie.map(r=>[`${t}x-${r}px`,`${e}-left: ${r}px; ${e}-right: ${r}px;`]),...Ie.map(r=>[`${t}y-${r}px`,`${e}-top: ${r}px; ${e}-bottom: ${r}px;`]),...Ne.map(r=>[`${t}x-${r}\\%`,`${e}-left: ${r}%; ${e}-right: ${r}%;`]),...Ne.map(r=>[`${t}y-${r}\\%`,`${e}-top: ${r}%; ${e}-bottom: ${r}%;`])]).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])}function He(){const e=[["white","#fff"],["black","#000"],["transparent","transparent"]].flatMap(([e,t])=>[[`text-${e}`,`color: ${t}`],[`fill-${e}`,`fill: ${t}`],[`bg-${e}`,`background-color: ${t}`],[`border-${e}`,`border-color: ${t}`]]),t=Object.entries(Ue).flatMap(([e,t])=>[[`text-${e}`,`color: ${ze(t[500])}`],[`fill-${e}`,`fill: ${ze(t[500])}`],[`bg-${e}`,`background-color: ${ze(t[500])}`],[`border-${e}`,`border-color: ${ze(t[500])}`]]),r=Object.entries(Ue).flatMap(([e,t])=>Object.entries(t).flatMap(([t,r])=>[[`text-${e}-${t}`,`color: ${ze(r)}`],[`fill-${e}-${t}`,`fill: ${ze(r)}`],[`bg-${e}-${t}`,`background-color: ${ze(r)}`],[`border-${e}-${t}`,`border-color: ${ze(r)}`]]));return[].concat(e).concat(t).concat(r).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])}function Ye(){return[...Me,...Object.entries(De).flatMap(([e,t])=>Object.entries(t).flatMap(([t,r])=>[`.${e} { ${t}: ${r} }`,`${je(e).join(",")} { ${t}: ${r} }`,...Fe(e,`${t}: ${r}`)])),...He(),...[["opacity-0","opacity: 0"],...Ne.map(e=>[`opacity-${e}`,"opacity: "+e/100])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...[...Ne.map(e=>[`z-${e}`,`z-index: ${e}`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...[...ke.map(e=>[`duration-${e}`,`transition-duration: ${e}ms`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...Ke(Ce),...Ke(Pe),...We(Pe),...(e=Se,Object.entries(e).flatMap(([e,t])=>[[`${t}t-0`,`${e}-top: 0`],[`${t}b-0`,`${e}-bottom: 0`],[`${t}l-0`,`${e}-left: 0`],[`${t}r-0`,`${e}-right: 0`],[`${t}t-auto`,`${e}-top: auto`],[`${t}b-auto`,`${e}-bottom: auto`],[`${t}l-auto`,`${e}-left: auto`],[`${t}r-auto`,`${e}-right: auto`],...["","-"].flatMap(r=>[...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}t-${i}`,`${e}-top: ${r}${n}rem`]),...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}b-${i}`,`${e}-bottom: ${r}${n}rem`]),...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}l-${i}`,`${e}-left: ${r}${n}rem`]),...Ie.map(e=>[e,e*Re]).map(([i,n])=>[`${r}${t}r-${i}`,`${e}-right: ${r}${n}rem`]),...Ie.map(i=>[`${r}${t}t-${i}px`,`${e}-top: ${r}${i}px`]),...Ie.map(i=>[`${r}${t}b-${i}px`,`${e}-bottom: ${r}${i}px`]),...Ie.map(i=>[`${r}${t}l-${i}px`,`${e}-left: ${r}${i}px`]),...Ie.map(i=>[`${r}${t}r-${i}px`,`${e}-right: ${r}${i}px`]),...Ne.map(i=>[`${r}${t}t-${i}\\%`,`${e}-top: ${r}${i}%`]),...Ne.map(i=>[`${r}${t}b-${i}\\%`,`${e}-bottom: ${r}${i}%;`]),...Ne.map(i=>[`${r}${t}l-${i}\\%`,`${e}-left: ${r}${i}%`]),...Ne.map(i=>[`${r}${t}r-${i}\\%`,`${e}-right: ${r}${i}%`])])]).flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])),...Ke(Se),...We(Se),...[["space-x-0 > *","margin-left: 0"],["space-y-0 > *","margin-top: 0"],...Ie.map(e=>[`space-x-${e} > :not(:first-child)`,`margin-left: ${e*Re}rem`]),...Ie.map(e=>[`space-y-${e} > :not(:first-child)`,`margin-top: ${e*Re}rem`]),...Ie.map(e=>[`space-x-${e}px > :not(:first-child)`,`margin-left: ${e}px`]),...Ie.map(e=>[`space-y-${e}px > :not(:first-child)`,`margin-top: ${e}px`]),["gap-0","gap: 0"],...Ie.map(e=>[`gap-${e}`,`gap: ${e*Re}rem`]),...Ie.map(e=>[`gap-${e}px`,`gap: ${e}px`]),...Ie.map(e=>[`gap-x-${e}`,`column-gap: ${e*Re}rem`]),...Ie.map(e=>[`gap-y-${e}`,`row-gap: ${e*Re}rem`]),...Ie.map(e=>[`gap-x-${e}px`,`column-gap: ${e}px`]),...Ie.map(e=>[`gap-y-${e}px`,`row-gap: ${e}px`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...Ke(Le),...[["border","border: 1px"],["border-x","border-inline-width: 1px"],["border-y","border-block-width: 1px"],...[0,...Oe].map(e=>[`border-${e}`,`border-width: ${e}px`]),...[0,...Oe].map(e=>[`border-x-${e}`,`border-inline-width: ${e}px;`]),...[0,...Oe].map(e=>[`border-y-${e}`,`border-block-width: ${e}px;`]),...["top","bottom","left","right"].flatMap(e=>[[`border-${e.slice(0,1)}`,`border-${e}: 1px`],...[0,...Oe].map(t=>[`border-${e.slice(0,1)}-${t}`,`border-${e}-width: ${t}px`])])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)]),...[...Array.from({length:100},(e,t)=>t).map(e=>[`text-${e}px`,`font-size: ${e}px`]),...Array.from({length:100},(e,t)=>t*Re).map(e=>[`text-${e}rem`,`font-size: ${e}rem`])].flatMap(([e,t])=>[`.${e} { ${t} }`,`${je(e).join(",")} { ${t} }`,...Fe(e,t)])].sort(Ge).join("\n");var e}class Be extends ye{impl="browser";dirpath=V(globalThis.location?.href??"http://localhost/");parseHTML(e,t={rootDocument:!1}){if(t.rootDocument)return(new DOMParser).parseFromString(e,"text/html");{const t=document.createRange();return t.selectNodeContents(document.body),t.createContextualFragment(e)}}serializeHTML(e){return(new XMLSerializer).serializeToString(e).replace(/\s?xmlns="[^"]+"/gm,"")}preprocessLocal(e,t){return this.preprocessRemote(e,t)}createElement(e,t){return(t||document).createElement(e)}textContent(e,t){e.textContent=t}}new Be;const Ve=new Be;globalThis.Mancha=Ve;const Ze=globalThis.document?.currentScript;if(globalThis.document?.currentScript?.hasAttribute("init")){const e=Ze?.hasAttribute("debug"),t=Ze?.getAttribute("cache"),r=Ze?.getAttribute("target")?.split("+")||["body"];window.addEventListener("load",()=>{r.map(async r=>{const i=globalThis.document.querySelector(r);await Ve.debug(e).mount(i,{cache:t})})})}if(globalThis.document?.currentScript?.hasAttribute("css")){const e=Ze?.getAttribute("css")?.split("+");for(const t of e){const e=document.createElement("style");switch(t){case"basic":p(e,Ee());break;case"utils":e.textContent=Ye();break;default:console.error(`Unknown style name: "${t}"`)}globalThis.document.head.appendChild(e)}}})();
|
package/dist/safe_browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={};function e(t){0}class s{constructor(t,e){this.privateDoNotAccessOrElseWrappedAttributePrefix=e}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const i=s;function r(t){if(function(t){return t instanceof s}(t))return t.privateDoNotAccessOrElseWrappedAttributePrefix;throw new Error("")}function n(t){return Object.isFrozen(t)&&Object.isFrozen(t.raw)}function a(t){return-1===t.toString().indexOf("`")}a(t=>t``)||a(t=>t`\0`)||a(t=>t`\n`)||a(t=>t`\u0000`),n``&&n`\0`&&n`\n`&&n`\u0000`;function o(e){const s=e[0].toLowerCase();return new i(t,s)}let l,c="google#safe";function h(){var t;return""!==c&&null!==(t=function(){if("undefined"!=typeof window)return window.trustedTypes}())&&void 0!==t?t:null}class u{constructor(t,s){e(),this.privateDoNotAccessOrElseWrappedHtml=t}toString(){return this.privateDoNotAccessOrElseWrappedHtml.toString()}}function d(e,s){return null!=s?s:new u(e,t)}"undefined"!=typeof window&&window.TrustedHTML;function p(t){var e;const s=t;return d(s,null===(e=function(){var t,e;if(void 0===l)try{l=null!==(e=null===(t=h())||void 0===t?void 0:t.createPolicy(c,{createHTML:t=>t,createScript:t=>t,createScriptURL:t=>t}))&&void 0!==e?e:null}catch(t){l=null}return l}())||void 0===e?void 0:e.createHTML(s))}function f(t){var e;if(null===(e=h())||void 0===e?void 0:e.isHTML(t))return t;if(t instanceof u)return t.privateDoNotAccessOrElseWrappedHtml;throw new Error("")}"undefined"!=typeof window&&window.TrustedScriptURL;"undefined"!=typeof window&&window.TrustedScript;function _(t,e){e.appendChild(t);let s=(new XMLSerializer).serializeToString(e);return s=s.slice(s.indexOf(">")+1,s.lastIndexOf("</")),p(s)}const m=["data:","http:","https:","mailto:","ftp:"],E=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function w(t){if(!function(t){const e=!E.test(t);return e}(t))return t}function v(t){return w(t)}function b(t){const e=function(t){let e;try{e=new URL(t)}catch(t){return"https:"}return e.protocol}(t);return void 0!==e&&-1!==m.indexOf(e.toLowerCase())?t:"about:invalid#zClosurez"}function g(t,e){const s=e.createRange();s.selectNode(e.body);return function(t,e){return t.createContextualFragment(f(e))}(s,p(t))}function y(t){const e=t.nodeName;return"string"==typeof e?e:"FORM"}function A(t){return 3===t.nodeType}function T(t){const e=t.nodeType;return 1===e||"number"!=typeof e}var R,O;function N(t){try{return new URL(t,window.document.baseURI)}catch(t){return new URL("about:invalid")}}function I(t){return{valueOf:t}.valueOf()}!function(t){t[t.STYLE_TAG=0]="STYLE_TAG",t[t.STYLE_ATTRIBUTE=1]="STYLE_ATTRIBUTE",t[t.HTML_ATTRIBUTE=2]="HTML_ATTRIBUTE"}(R||(R={}));class P{constructor(t,e,s,i,r){this.allowedElements=t,this.elementPolicies=e,this.allowedGlobalAttributes=s,this.globalAttributePolicies=i,this.globallyAllowedAttributePrefixes=r}isAllowedElement(t){return"FORM"!==t&&(this.allowedElements.has(t)||this.elementPolicies.has(t))}getAttributePolicy(t,e){const s=this.elementPolicies.get(e);if(null==s?void 0:s.has(t))return s.get(t);if(this.allowedGlobalAttributes.has(t))return{policyAction:O.KEEP};const i=this.globalAttributePolicies.get(t);return i||(this.globallyAllowedAttributePrefixes&&[...this.globallyAllowedAttributePrefixes].some(e=>0===t.indexOf(e))?{policyAction:O.KEEP}:{policyAction:O.DROP})}}!function(t){t[t.DROP=0]="DROP",t[t.KEEP=1]="KEEP",t[t.KEEP_AND_SANITIZE_URL=2]="KEEP_AND_SANITIZE_URL",t[t.KEEP_AND_NORMALIZE=3]="KEEP_AND_NORMALIZE",t[t.KEEP_AND_SANITIZE_STYLE=4]="KEEP_AND_SANITIZE_STYLE",t[t.KEEP_AND_USE_RESOURCE_URL_POLICY=5]="KEEP_AND_USE_RESOURCE_URL_POLICY",t[t.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET=6]="KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET"}(O||(O={}));const S=new Set(["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"]);const x=["ARTICLE","SECTION","NAV","ASIDE","H1","H2","H3","H4","H5","H6","HEADER","FOOTER","ADDRESS","P","HR","PRE","BLOCKQUOTE","OL","UL","LH","LI","DL","DT","DD","FIGURE","FIGCAPTION","MAIN","DIV","EM","STRONG","SMALL","S","CITE","Q","DFN","ABBR","RUBY","RB","RT","RTC","RP","DATA","TIME","CODE","VAR","SAMP","KBD","SUB","SUP","I","B","U","MARK","BDI","BDO","SPAN","BR","WBR","INS","DEL","PICTURE","PARAM","TRACK","MAP","TABLE","CAPTION","COLGROUP","COL","TBODY","THEAD","TFOOT","TR","TD","TH","SELECT","DATALIST","OPTGROUP","OPTION","OUTPUT","PROGRESS","METER","FIELDSET","LEGEND","DETAILS","SUMMARY","MENU","DIALOG","SLOT","CANVAS","FONT","CENTER","ACRONYM","BASEFONT","BIG","DIR","HGROUP","STRIKE","TT"],C=[["A",new Map([["href",{policyAction:O.KEEP_AND_SANITIZE_URL}]])],["AREA",new Map([["href",{policyAction:O.KEEP_AND_SANITIZE_URL}]])],["LINK",new Map([["href",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY,conditions:new Map([["rel",new Set(["alternate","author","bookmark","canonical","cite","help","icon","license","next","prefetch","dns-prefetch","prerender","preconnect","preload","prev","search","subresource"])]])}]])],["SOURCE",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["IMG",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["VIDEO",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}]])],["AUDIO",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}]])]],L=["title","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-current","aria-disabled","aria-dropeffect","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-live","aria-multiline","aria-multiselectable","aria-orientation","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","alt","align","autocapitalize","autocomplete","autocorrect","autofocus","autoplay","bgcolor","border","cellpadding","cellspacing","checked","color","cols","colspan","controls","datetime","disabled","download","draggable","enctype","face","formenctype","frameborder","height","hreflang","hidden","ismap","label","lang","loop","max","maxlength","media","minlength","min","multiple","muted","nonce","open","placeholder","preload","rel","required","reversed","role","rows","rowspan","selected","shape","size","sizes","slot","span","spellcheck","start","step","summary","translate","type","valign","value","width","wrap","itemscope","itemtype","itemid","itemprop","itemref"],k=[["dir",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["dir",new Set(["auto","ltr","rtl"])]]))}],["async",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["async",new Set(["async"])]]))}],["cite",{policyAction:O.KEEP_AND_SANITIZE_URL}],["loading",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["loading",new Set(["eager","lazy"])]]))}],["poster",{policyAction:O.KEEP_AND_SANITIZE_URL}],["target",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["target",new Set(["_self","_blank"])]]))}]],D=new P(new Set(x),new Map(C),new Set(L),new Map(k));new P(new Set(I(()=>x.concat(["STYLE"]))),new Map(C),new Set(I(()=>L.concat(["id","name","class"]))),new Map(I(()=>k.concat([["style",{policyAction:O.KEEP_AND_SANITIZE_STYLE}]]))));class U{constructor(t,s,i,r,n){this.sanitizerTable=t,this.styleElementSanitizer=i,this.styleAttributeSanitizer=r,this.resourceUrlPolicy=n,this.changes=[],e()}sanitizeAssertUnchanged(t){return this.sanitize(t)}sanitize(t){const e=document.implementation.createHTMLDocument("");return _(this.sanitizeToFragmentInternal(t,e),e.body)}sanitizeToFragment(t){const e=document.implementation.createHTMLDocument("");return this.sanitizeToFragmentInternal(t,e)}sanitizeToFragmentInternal(t,e){const s=g(t,e),i=document.createTreeWalker(s,5,t=>this.nodeFilter(t));let r=i.nextNode();const n=e.createDocumentFragment();let a=n;for(;null!==r;){let t;if(A(r))if(this.styleElementSanitizer&&"STYLE"===a.nodeName){const e=this.styleElementSanitizer(r.data);t=this.createTextNode(e)}else t=this.sanitizeTextNode(r);else{if(!T(r)){throw new Error("")}t=this.sanitizeElementNode(r,e)}if(a.appendChild(t),r=i.firstChild(),r)a=t;else for(;!(r=i.nextSibling())&&(r=i.parentNode());)a=a.parentNode}return n}createTextNode(t){return document.createTextNode(t)}sanitizeTextNode(t){return this.createTextNode(t.data)}sanitizeElementNode(t,e){const s=y(t),i=e.createElement(s),r=t.attributes;for(const{name:t,value:e}of r){const n=this.sanitizerTable.getAttributePolicy(t,s);if(this.satisfiesAllConditions(n.conditions,r))switch(n.policyAction){case O.KEEP:z(i,t,e);break;case O.KEEP_AND_SANITIZE_URL:const r=b(e);r!==e&&this.recordChange(`Url in attribute ${t} was modified during sanitization. Original url:"${e}" was sanitized to: "${r}"`),z(i,t,r);break;case O.KEEP_AND_NORMALIZE:z(i,t,e.toLowerCase());break;case O.KEEP_AND_SANITIZE_STYLE:if(this.styleAttributeSanitizer){z(i,t,this.styleAttributeSanitizer(e))}else z(i,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:s},n=N(e),a=this.resourceUrlPolicy(n,r);a&&z(i,t,a.toString())}else z(i,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:s},n=$(e),a={parts:[]};for(const t of n.parts){const e=N(t.url),s=this.resourceUrlPolicy(e,r);s&&a.parts.push({url:s.toString(),descriptor:t.descriptor})}z(i,t,M(a))}else z(i,t,e);break;case O.DROP:this.recordChange(`Attribute: ${t} was dropped`)}else this.recordChange(`Not all conditions satisfied for attribute: ${t}.`)}return i}nodeFilter(t){if(A(t))return 1;if(!T(t))return 2;const e=y(t);return null===e?(this.recordChange(`Node name was null for node: ${t}`),2):this.sanitizerTable.isAllowedElement(e)?1:(this.recordChange(`Element: ${e} was dropped`),2)}recordChange(t){0}satisfiesAllConditions(t,e){var s;if(!t)return!0;for(const[i,r]of t){const t=null===(s=e.getNamedItem(i))||void 0===s?void 0:s.value;if(t&&!r.has(t))return!1}return!0}}function z(t,e,s){t.setAttribute(e,s)}function $(t){const e=[];for(const s of t.split(",")){const[t,i]=s.trim().split(/\s+/,2);e.push({url:t,descriptor:i})}return{parts:e}}function M(t){return t.parts.map(t=>{const{url:e,descriptor:s}=t;return`${e}${s?` ${s}`:""}`}).join(" , ")}class F{constructor(){this.calledBuild=!1,this.sanitizerTable=D}onlyAllowElements(t){const e=new Set,s=new Map;for(let i of t){if(i=i.toUpperCase(),!this.sanitizerTable.isAllowedElement(i))throw new Error(`Element: ${i}, is not allowed by html5_contract.textpb`);const t=this.sanitizerTable.elementPolicies.get(i);void 0!==t?s.set(i,t):e.add(i)}return this.sanitizerTable=new P(e,s,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}allowCustomElement(t,e){const s=new Set(this.sanitizerTable.allowedElements),i=new Map(this.sanitizerTable.elementPolicies);if(t=t.toUpperCase(),r=t,S.has(r.toUpperCase())||!/^[a-z][-_.a-z0-9]*-[-_.a-z0-9]*$/i.test(r))throw new Error(`Element: ${t} is not a custom element`);var r;if(e){const s=new Map;for(const t of e)s.set(t,{policyAction:O.KEEP});i.set(t,s)}else s.add(t);return this.sanitizerTable=new P(s,i,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}onlyAllowAttributes(t){const e=new Set,s=new Map,i=new Map;for(const i of t)this.sanitizerTable.allowedGlobalAttributes.has(i)&&e.add(i),this.sanitizerTable.globalAttributePolicies.has(i)&&s.set(i,this.sanitizerTable.globalAttributePolicies.get(i));for(const[e,s]of this.sanitizerTable.elementPolicies.entries()){const r=new Map;for(const[e,i]of s.entries())t.has(e)&&r.set(e,i);i.set(e,r)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,i,e,s),this}allowDataAttributes(t){const e=new Set(this.sanitizerTable.allowedGlobalAttributes);for(const s of t){if(0!==s.indexOf("data-"))throw new Error(`data attribute: ${s} does not begin with the prefix "data-"`);e.add(s)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,e,this.sanitizerTable.globalAttributePolicies),this}allowStyleAttributes(){const t=new Map(this.sanitizerTable.globalAttributePolicies);return t.set("style",{policyAction:O.KEEP_AND_SANITIZE_STYLE}),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,this.sanitizerTable.allowedGlobalAttributes,t),this}allowClassAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("class"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}allowIdAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("id"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}allowIdReferenceAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("aria-activedescendant").add("aria-controls").add("aria-labelledby").add("aria-owns").add("for").add("list"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}withResourceUrlPolicy(t){return this.resourceUrlPolicy=t,this}build(){if(this.calledBuild)throw new Error("this sanitizer has already called build");return this.calledBuild=!0,new U(this.sanitizerTable,t,void 0,void 0,this.resourceUrlPolicy)}}function G(t,e,s,i){if(0===t.length){throw new Error("")}const n=t.map(t=>r(t)),a=s.toLowerCase();if(n.every(t=>0!==a.indexOf(t)))throw new Error(`Attribute "${s}" does not match any of the allowed prefixes.`);e.setAttribute(s,i)}function K(t,e,s){return t.parseFromString(f(e),s)}Error;const H=[o`:`,o`style`,o`class`];function*W(t,e=new Set){const s=new Set,i=Array.from(t.childNodes).filter(t=>!e.has(t));for(yield t;i.length;){const t=i.shift();s.has(t)||(s.add(t),yield t),t.childNodes&&Array.from(t.childNodes).filter(t=>!e.has(t)).forEach(t=>i.push(t))}}function Y(t,e){return void 0!==t?.[e]}function B(t,e){return"function"==typeof t?.[e]}function V(t){return t.replace(/-./g,t=>t[1].toUpperCase())}function Z(t,e){return Y(t,"attribs")?t.attribs?.[e]??null:t.getAttribute?.(e)??null}function j(t,e,s=""){return Z(t,s+e)||(t.dataset?.[V(e)]??null)}function q(t,e,s){Y(t,"attribs")?t.attribs[e]=s:t.setAttribute?.(e,s)}function X(t,e,s){Y(t,"attribs")?t.attribs[e]=s:G(H,t,e,s)}function Q(t,e,s){switch(e){case"disabled":return void(t.disabled=s);case"selected":return void(t.selected=s);case"checked":return void(t.checked=s);default:t[e]=s}}function J(t,e){Y(t,"attribs")?delete t.attribs[e]:t.removeAttribute?.(e)}function tt(t,e,s=""){J(t,`${s}${e}`),J(t,`data-${e}`)}function et(t,e,s){if(Y(t,"attribs")&&Y(e,"attribs"))e.attribs[s]=t.attribs[s];else if(s.startsWith("data-")){const i=V(s.slice(5));e.dataset[i]=t.dataset?.[i]}else{const i=t?.getAttribute?.(s);X(e,s,i||"")}}function st(t){if(Y(t,"firstElementChild"))return t.firstElementChild;return Array.from(t.children).find(t=>1===t.nodeType)}function it(t,...e){if(B(t,"replaceWith"))return t.replaceWith(...e);{const s=t,i=s.parentNode,r=Array.from(i.childNodes).indexOf(s);e.forEach(t=>t.parentNode=i),i.childNodes=[].concat(Array.from(i.childNodes).slice(0,r)).concat(e).concat(Array.from(i.childNodes).slice(r+1))}}function rt(t,...e){B(t,"replaceChildren")?t.replaceChildren(...e):(t.childNodes=e,e.forEach(e=>e.parentNode=t))}function nt(t,e){return B(e,"appendChild")?t.appendChild(e):(t.childNodes.push(e),e.parentNode=t,e)}function at(t,e){return B(e,"removeChild")?t.removeChild(e):(rt(t,...Array.from(t.childNodes).filter(t=>t!==e)),e)}function ot(t,e,s){return s?B(t,"insertBefore")?t.insertBefore(e,s):(it(s,e,s),e):nt(t,e)}function lt(t,e=0){return t?t.length<=e?t:t.slice(0,e-1)+"…":""}function ct(t,e=0){return globalThis.DocumentFragment&&t instanceof DocumentFragment?Array.from(t.childNodes).map(t=>ct(t,e)).join(""):lt(t.outerHTML||t.nodeValue||String(t),e)}function ht(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):""}class ut{iterable;constructor(t){this.iterable=t}filter(t){return new ut(ut.filterGenerator(t,this.iterable))}map(t){return new ut(ut.mapGenerator(t,this.iterable))}find(t){for(const e of this.iterable)if(t(e))return e}array(){return Array.from(this.iterable)}*generator(){for(const t of this.iterable)yield t}static*filterGenerator(t,e){for(const s of e)t(s)&&(yield s)}static*mapGenerator(t,e){for(const s of e)yield t(s)}static equals(t,e){const s=t[Symbol.iterator](),i=e[Symbol.iterator]();let r=s.next(),n=i.next();for(;!r.done&&!n.done;){if(r.value!==n.value)return!1;r=s.next(),n=i.next()}return r.done===n.done}}var dt;!function(t){t.resolveIncludes=async function(t,e){const s=t,i=s.tagName?.toLowerCase();if(!["include","link"].includes(i))return;if("link"===i&&"subresource"!==Z(s,"rel"))return;this.log("include directive found in:\n",ct(t,128)),this.log("include params:",e);const r="link"===s.tagName.toLocaleLowerCase()?"href":"src",n=Z(s,r);if(!n)throw new Error(`"${r}" attribute missing from ${ct(t,128)}.`);const a=[];"include"===i&&a.push("src"),"link"===i&&a.push("rel","href");const o=e=>{const i=st(e);for(const t of Array.from(s.attributes))i&&!a.includes(t.name)&&et(s,i,t.name);it(t,...e.childNodes)},l={...e,rootDocument:!1,maxdepth:e?.maxdepth-1};if(0===l.maxdepth)throw new Error("Maximum recursion depth reached.");if(n.includes("://")||n.startsWith("//"))this.log("Including remote file from absolute path:",n),await this.preprocessRemote(n,l).then(o);else if(e?.dirpath?.includes("://")||e?.dirpath?.startsWith("//")){const t=n.startsWith("/")?n:`${e.dirpath}/${n}`;this.log("Including remote file from relative path:",t),await this.preprocessRemote(t,l).then(o)}else if("/"===n.charAt(0))this.log("Including local file from absolute path:",n),await this.preprocessLocal(n,l).then(o);else{const t=e?.dirpath&&"."!==e?.dirpath?`${e?.dirpath}/${n}`:n;this.log("Including local file from relative path:",t),await this.preprocessLocal(t,l).then(o)}},t.rebaseRelativePaths=async function(t,e){const s=t,i=s.tagName?.toLowerCase();if(!e?.dirpath)return;const r=Z(s,"src"),n=Z(s,"href"),a=r||n;if(!a||((o=a).includes("://")||o.startsWith("/")||o.startsWith("#")||o.startsWith("data:")))return;var o;const l=`${e.dirpath}/${a}`;this.log("Rebasing relative path as:",l),Y(s,"attribs")?X(s,r?"src":"href",l):"img"===i?s.src=l:"a"===i?function(t,e){const s=v(e);void 0!==s&&(t.href=s)}(s,l):"source"===i||"audio"===i||"video"===i||"track"===i||"input"===i?s.src=l:"area"===i?function(t,e){const s=v(e);void 0!==s&&(t.href=s)}(s,l):this.log("Unable to rebase relative path for element:",i)},t.registerCustomElements=async function(t,e){const s=t,i=s.tagName?.toLowerCase(),r=(Z(s,"is")||Z(s,"alt"))?.toLowerCase();if(["template","div"].includes(i)&&r){if("div"===i&&"template"!==Z(s,"role"))return;this._customElements.has(r)||(this.log(`Registering custom element: ${r}\n`,ct(s,128)),this._customElements.set(r,s),at(s.parentNode,s))}},t.resolveCustomElements=async function(t,e){const s=t,i=s.tagName?.toLowerCase();let r=i;if("div"===r&&(r=Z(s,"role")?.toLowerCase()||r),r&&this._customElements.has(r)){this.log(`Processing custom element: ${r}\n`,ct(s,128));const e=this._customElements.get(r),n=(e.content||e).cloneNode(!0),a=st(n);if(a)for(const t of Array.from(s.attributes))"div"===i&&"role"===t.name||et(s,a,t.name);const o=new ut(W(n)).find(t=>"slot"===t.tagName?.toLowerCase());o&&it(o,...s.childNodes),it(t,...n.childNodes)}},t.resolveTextNodeExpressions=async function(t,e){const s=t.nodeValue||"";if(3!==t.nodeType||!s?.trim())return;this.log("Processing node content value:\n",lt(s,128));const i=new RegExp(/{{ ([^}]+) }}/gm),r=Array.from(s.matchAll(i)).map(t=>t[1]);return this.effect(function(){let e=s;for(const s of r){const i=this.eval(s,{$elem:t});e=e.replace(`{{ ${s} }}`,String(i))}t.nodeValue=e})},t.resolveDataAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"data",":");if(i){this.log(":data attribute found in:\n",ct(t,128)),tt(s,"data",":");const r=e?.rootNode===t?this:this.subrenderer();t.renderer=r;const n=r.eval(i,{$elem:t});if(await Promise.all(Object.entries(n).map(([t,e])=>r._store.set(t,e))),r!==this)for(const e of W(t,this._skipNodes))this._skipNodes.add(e);await r.mount(t,e)}},t.resolveClassAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"class",":");if(i){this.log(":class attribute found in:\n",ct(t,128)),tt(s,"class",":");const e=Z(s,"class")||"";return this.effect(function(){const r=this.eval(i,{$elem:t});X(s,"class",(r?`${e} ${r}`:e).trim())})}},t.resolveTextAttributes=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"text",":");if(i){this.log(":text attribute found in:\n",ct(t,128)),tt(s,"text",":");const e=e=>this.textContent(t,e);return this.effect(function(){e(this.eval(i,{$elem:t}))})}},t.resolveHtmlAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"html",":");return i?(this.log(":html attribute found in:\n",ct(t,128)),tt(s,"html",":"),this.effect(function(){const r=this.eval(i,{$elem:t});return new Promise(async t=>{const i=await this.preprocessString(r,e);await this.renderNode(i),rt(s,i),t()})})):void 0},t.resolveEventAttributes=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[]))if(e.name.startsWith(":on:")||e.name.startsWith("data-on-")){let i="",r=[];if(e.name.startsWith(":on:")?[i,...r]=e.name.substring(4).split("."):e.name.startsWith("data-on-")&&([i,...r]=e.name.substring(8).split(".")),!i)throw new Error(`Invalid event attribute: ${e.name}`);this.log(e.name,"attribute found in:\n",ct(t,128)),tt(s,e.name);const n="submit"===i&&"FORM"===s.tagName.toUpperCase();t.addEventListener?.(i,s=>((r.includes("prevent")||n)&&s.preventDefault(),this.eval(e.value,{$elem:t,$event:s})))}},t.resolveForAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"for",":")?.trim();if(i){this.log(":for attribute found in:\n",ct(t,128)),tt(s,"for",":");for(const e of W(t,this._skipNodes))this._skipNodes.add(e);const r=Z(s,"style")||"";q(s,"style","display: none;");const n=t.parentNode,a=this.createElement("template",t.ownerDocument);ot(n,a,t),at(n,t),nt(a,t),this.log(":for template:\n",ct(a,128));const o=i.split(" in ",2);if(2!==o.length)throw new Error(`Invalid :for format: \`${i}\`. Expected "{key} in {expression}".`);const l=[],[c,h]=o;await this.effect(function(){const s=this.eval(h,{$elem:t});if(this.log(":for list items:",s),l.splice(0,l.length).forEach(t=>{at(n,t),this._skipNodes.delete(t)}),!Array.isArray(s))return console.error(`Expression did not yield a list: \`${h}\` => \`${s}\``),Promise.resolve();const i=[];for(const n of s){const s=this.subrenderer();s._store.set(c,n);const a=t.cloneNode(!0);q(a,"style",r),l.push(a),this._skipNodes.add(a),i.push(s.mount(a,e)),this.log("Rendered list child:\n",ct(a,128))}const o=a.nextSibling;for(const t of l)ot(n,t,o);return Promise.all(i)})}},t.resolveBindAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"bind",":");if(i){this.log(":bind attribute found in:\n",ct(t,128));const e=["change","input"],r=Z(s,":bind:on")?.split(",")||s.dataset?.bindOn?.split(",")||e;tt(s,"bind",":"),J(s,":bind:on"),J(s,"data-bind-on");const n="checkbox"===Z(s,"type")?"checked":"value";i.includes(".")||this.has(i)||this.set(i,""),this.effect(function(){const e=this.eval(i,{$elem:t});"checked"===n?s.checked=!!e:s.value=e});const a=`${i} = $elem.${n}`;for(const e of r)t.addEventListener(e,()=>this.eval(a,{$elem:t}))}},t.resolveShowAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"show",":");if(i){this.log(":show attribute found in:\n",ct(t,128)),tt(s,"show",":");const e="none"===s.style?.display?"":s.style?.display??Z(s,"style")?.split(";")?.find(t=>"display"===t.split(":")[0])?.split(":")?.at(1)?.trim();this.effect(function(){const r=this.eval(i,{$elem:t});s.style?s.style.display=r?e:"none":X(s,"style",`display: ${r?e:"none"};`)})}},t.resolveCustomAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[])){const i=":attr:",r="data-attr-";if(e.name.startsWith(i)||e.name.startsWith(r)){this.log(e.name,"attribute found in:\n",ct(t,128)),J(s,e.name);const n=e.name.split(i,2).at(-1)?.split(r,2).at(-1);this.effect(function(){const i=this.eval(e.value,{$elem:t});q(s,n,i)})}}},t.resolveCustomProperty=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[])){const i=":prop:",r="data-prop-";if(e.name.startsWith(i)||e.name.startsWith(r)){this.log(e.name,"property found in:\n",ct(t,128)),J(s,e.name);const n=e.name.split(i,2).at(-1)?.split(r,2).at(-1),a=V(n);this.effect(function(){const i=this.eval(e.value,{$elem:t});Q(s,a,i)})}}},t.stripTypes=async function(t,e){const s=t;Z(s,":types")&&J(s,":types"),Z(s,"data-types")&&J(s,"data-types")}}(dt||(dt={}));const pt=["this"],ft=["+","-","!"],_t=["=","+","-","*","/","%","^","==","!=",">","<",">=","<=","||","&&","??","&","===","!==","|","|>"],mt={"!":0,":":0,",":0,")":0,"]":0,"}":0,"|>":1,"?":2,"??":3,"||":4,"&&":5,"|":6,"^":7,"&":8,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},Et=["==","!=","<=",">=","||","&&","??","|>"],wt=["===","!=="];var vt;!function(t){t[t.STRING=1]="STRING",t[t.IDENTIFIER=2]="IDENTIFIER",t[t.DOT=3]="DOT",t[t.COMMA=4]="COMMA",t[t.COLON=5]="COLON",t[t.INTEGER=6]="INTEGER",t[t.DECIMAL=7]="DECIMAL",t[t.OPERATOR=8]="OPERATOR",t[t.GROUPER=9]="GROUPER",t[t.KEYWORD=10]="KEYWORD",t[t.ARROW=11]="ARROW"}(vt||(vt={}));const bt=(t,e,s=0)=>({kind:t,value:e,precedence:s}),gt=t=>9===t||10===t||13===t||32===t,yt=t=>95===t||36===t||65<=(t&=-33)&&t<=90,At=t=>yt(t)||Tt(t),Tt=t=>48<=t&&t<=57;class Rt{_input;_index=-1;_tokenStart=0;_next;constructor(t){this._input=t,this._advance()}nextToken(){for(;gt(this._next);)this._advance(!0);if(34===(t=this._next)||39===t)return this._tokenizeString();var t;if(yt(this._next))return this._tokenizeIdentOrKeyword();if(Tt(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((t=>43===t||45===t||42===t||47===t||33===t||38===t||37===t||60===t||61===t||62===t||63===t||94===t||124===t)(this._next))return this._tokenizeOperator();if((t=>40===t||41===t||91===t||93===t||123===t||125===t)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(t){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),!0===t&&(this._tokenStart=this._index)):this._next=void 0}_getValue(t=0){const e=this._input.substring(this._tokenStart,this._index+t);return 0===t&&this._clearValue(),e}_clearValue(){this._tokenStart=this._index}_tokenizeString(){const t="unterminated string",e=this._next;for(this._advance(!0);this._next!==e;){if(void 0===this._next)throw new Error(t);if(92===this._next&&(this._advance(),void 0===this._next))throw new Error(t);this._advance()}const s=bt(vt.STRING,this._getValue().replace(/\\(.)/g,(t,e)=>{switch(e){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return e}}));return this._advance(),s}_tokenizeIdentOrKeyword(){do{this._advance()}while(At(this._next));const t=this._getValue(),e=(s=t,-1!==pt.indexOf(s)?vt.KEYWORD:vt.IDENTIFIER);var s;return bt(e,t)}_tokenizeNumber(){do{this._advance()}while(Tt(this._next));return 46===this._next?this._tokenizeDot():bt(vt.INTEGER,this._getValue())}_tokenizeDot(){return this._advance(),Tt(this._next)?this._tokenizeFraction():(this._clearValue(),bt(vt.DOT,".",13))}_tokenizeComma(){return this._advance(!0),bt(vt.COMMA,",")}_tokenizeColon(){return this._advance(!0),bt(vt.COLON,":")}_tokenizeFraction(){do{this._advance()}while(Tt(this._next));return bt(vt.DECIMAL,this._getValue())}_tokenizeOperator(){this._advance();let t=this._getValue(2);if(-1!==wt.indexOf(t))this._advance(),this._advance();else{if(t=this._getValue(1),"=>"===t)return this._advance(),bt(vt.ARROW,t);-1!==Et.indexOf(t)&&this._advance()}return t=this._getValue(),bt(vt.OPERATOR,t,mt[t])}_tokenizeGrouper(){const t=String.fromCharCode(this._next),e=bt(vt.GROUPER,t,mt[t]);return this._advance(!0),e}}class Ot{_kind;_tokenizer;_ast;_token;_value;constructor(t,e){this._tokenizer=new Rt(t),this._ast=e}parse(){return this._advance(),this._parseExpression()}_advance(t,e){if(!this._matches(t,e))throw new Error(`Expected kind ${t} (${e}), was ${this._token?.kind} (${this._token?.value})`);const s=this._tokenizer.nextToken();this._token=s,this._kind=s?.kind,this._value=s?.value}_matches(t,e){return!(t&&this._kind!==t||e&&this._value!==e)}_parseExpression(){if(!this._token)return this._ast.empty();const t=this._parseUnary();return void 0===t?void 0:this._parsePrecedence(t,0)}_parsePrecedence(t,e){if(void 0===t)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(vt.GROUPER,"(")){const e=this._parseArguments();t=this._ast.invoke(t,void 0,e)}else if(this._matches(vt.GROUPER,"[")){const e=this._parseIndex();t=this._ast.index(t,e)}else if(this._matches(vt.DOT)){this._advance();const e=this._parseUnary();t=this._makeInvokeOrGetter(t,e)}else{if(this._matches(vt.KEYWORD))break;if(!(this._matches(vt.OPERATOR)&&this._token.precedence>=e))break;t="?"===this._value?this._parseTernary(t):this._parseBinary(t,this._token)}return t}_makeInvokeOrGetter(t,e){if(void 0===e)throw new Error("expected identifier");if("ID"===e.type)return this._ast.getter(t,e.value);if("Invoke"===e.type&&"ID"===e.receiver.type){const s=e.receiver;return this._ast.invoke(t,s.value,e.arguments)}throw new Error(`expected identifier: ${e}`)}_parseBinary(t,e){if(-1===_t.indexOf(e.value))throw new Error(`unknown operator: ${e.value}`);this._advance();let s=this._parseUnary();for(;(this._kind===vt.OPERATOR||this._kind===vt.DOT||this._kind===vt.GROUPER)&&this._token.precedence>e.precedence;)s=this._parsePrecedence(s,this._token.precedence);return this._ast.binary(t,e.value,s)}_parseUnary(){if(this._matches(vt.OPERATOR)){const t=this._value;if(this._advance(),"+"===t||"-"===t){if(this._matches(vt.INTEGER))return this._parseInteger(t);if(this._matches(vt.DECIMAL))return this._parseDecimal(t)}if(-1===ft.indexOf(t))throw new Error(`unexpected token: ${t}`);const e=this._parsePrecedence(this._parsePrimary(),13);return this._ast.unary(t,e)}return this._parsePrimary()}_parseTernary(t){this._advance(vt.OPERATOR,"?");const e=this._parseExpression();this._advance(vt.COLON);const s=this._parseExpression();return this._ast.ternary(t,e,s)}_parsePrimary(){switch(this._kind){case vt.KEYWORD:const t=this._value;if("this"===t)return this._advance(),this._ast.id(t);if(-1!==pt.indexOf(t))throw new Error(`unexpected keyword: ${t}`);throw new Error(`unrecognized keyword: ${t}`);case vt.IDENTIFIER:return this._parseInvokeOrIdentifier();case vt.STRING:return this._parseString();case vt.INTEGER:return this._parseInteger();case vt.DECIMAL:return this._parseDecimal();case vt.GROUPER:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case vt.COLON:throw new Error('unexpected token ":"');default:return}}_parseList(){const t=[];do{if(this._advance(),this._matches(vt.GROUPER,"]"))break;t.push(this._parseExpression())}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,"]"),this._ast.list(t)}_parseMap(){const t={};do{if(this._advance(),this._matches(vt.GROUPER,"}"))break;const e=this._value;(this._matches(vt.STRING)||this._matches(vt.IDENTIFIER))&&this._advance(),this._advance(vt.COLON),t[e]=this._parseExpression()}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,"}"),this._ast.map(t)}_parseInvokeOrIdentifier(){const t=this._value;if("true"===t)return this._advance(),this._ast.literal(!0);if("false"===t)return this._advance(),this._ast.literal(!1);if("null"===t)return this._advance(),this._ast.literal(null);if("undefined"===t)return this._advance(),this._ast.literal(void 0);const e=this._parseIdentifier(),s=this._parseArguments();return s?this._ast.invoke(e,void 0,s):e}_parseIdentifier(){if(!this._matches(vt.IDENTIFIER))throw new Error(`expected identifier: ${this._value}`);const t=this._value;return this._advance(),this._ast.id(t)}_parseArguments(){if(!this._matches(vt.GROUPER,"("))return;const t=[];do{if(this._advance(),this._matches(vt.GROUPER,")"))break;const e=this._parseExpression();t.push(e)}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,")"),t}_parseIndex(){this._advance();const t=this._parseExpression();return this._advance(vt.GROUPER,"]"),t}_parseParenOrFunction(){const t=this._parseArguments();if(this._matches(vt.ARROW)){this._advance();const e=this._parseExpression(),s=t?.map(t=>t.value)??[];return this._ast.arrowFunction(s,e)}return this._ast.paren(t[0])}_parseString(){const t=this._ast.literal(this._value);return this._advance(),t}_parseInteger(t=""){const e=this._ast.literal(parseInt(`${t}${this._value}`,10));return this._advance(),e}_parseDecimal(t=""){const e=this._ast.literal(parseFloat(`${t}${this._value}`));return this._advance(),e}}const Nt={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e,">":(t,e)=>t>e,">=":(t,e)=>t>=e,"<":(t,e)=>t<e,"<=":(t,e)=>t<=e,"||":(t,e)=>t||e,"&&":(t,e)=>t&&e,"??":(t,e)=>t??e,"|":(t,e)=>e(t),"|>":(t,e)=>e(t)},It={"+":t=>t,"-":t=>-t,"!":t=>!t};class Pt{timeouts=new Map;debounce(t,e){return new Promise((s,i)=>{const r=this.timeouts.get(e);r&&clearTimeout(r),this.timeouts.set(e,setTimeout(()=>{try{s(e()),this.timeouts.delete(e)}catch(t){i(t)}},t))})}}const St=new class{empty(){return{type:"Empty",evaluate:t=>t,getIds:t=>t}}literal(t){return{type:"Literal",value:t,evaluate(t){return this.value},getIds:t=>t}}id(t){return{type:"ID",value:t,evaluate(t){return"this"===this.value?t:t?.[this.value]},getIds(t){return t.push(this.value),t}}}unary(t,e){const s=It[t];return{type:"Unary",operator:t,child:e,evaluate(t){return s(this.child.evaluate(t))},getIds(t){return this.child.getIds(t)}}}binary(t,e,s){const i=Nt[e];return{type:"Binary",operator:e,left:t,right:s,evaluate(t){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const e=this.right.evaluate(t);let s,i;return"Getter"===this.left.type?(s=this.left.receiver.evaluate(t),i=this.left.name):"Index"===this.left.type?(s=this.left.receiver.evaluate(t),i=this.left.argument.evaluate(t)):"ID"===this.left.type&&(s=t,i=this.left.value),void 0===s?void 0:s[i]=e}return i(this.left.evaluate(t),this.right.evaluate(t))},getIds(t){return this.left.getIds(t),this.right.getIds(t),t}}}getter(t,e){return{type:"Getter",receiver:t,name:e,evaluate(t){return this.receiver.evaluate(t)?.[this.name]},getIds(t){return this.receiver.getIds(t),t}}}invoke(t,e,s){if(null!=e&&"string"!=typeof e)throw new Error("method not a string");return{type:"Invoke",receiver:t,method:e,arguments:s,evaluate(t){const s=this.receiver.evaluate(t),i=this.method?s:t?.this??t,r=this.method?s?.[e]:s,n=(this.arguments??[]).map(e=>e?.evaluate(t));return r?.apply?.(i,n)},getIds(t){return this.receiver.getIds(t),this.arguments?.forEach(e=>e?.getIds(t)),t}}}paren(t){return t}index(t,e){return{type:"Index",receiver:t,argument:e,evaluate(t){return this.receiver.evaluate(t)?.[this.argument.evaluate(t)]},getIds(t){return this.receiver.getIds(t),t}}}ternary(t,e,s){return{type:"Ternary",condition:t,trueExpr:e,falseExpr:s,evaluate(t){return this.condition.evaluate(t)?this.trueExpr.evaluate(t):this.falseExpr.evaluate(t)},getIds(t){return this.condition.getIds(t),this.trueExpr.getIds(t),this.falseExpr.getIds(t),t}}}map(t){return{type:"Map",entries:t,evaluate(e){const s={};if(t&&this.entries)for(const i in t){const t=this.entries[i];t&&(s[i]=t.evaluate(e))}return s},getIds(e){if(t&&this.entries)for(const s in t){const t=this.entries[s];t&&t.getIds(e)}return e}}}list(t){return{type:"List",items:t,evaluate(t){return this.items?.map(e=>e?.evaluate(t))},getIds(t){return this.items?.forEach(e=>e?.getIds(t)),t}}}arrowFunction(t,e){return{type:"ArrowFunction",params:t,body:e,evaluate(t){const e=this.params,s=this.body;return function(...i){const r=Object.fromEntries(e.map((t,e)=>[t,i[e]])),n=new Proxy(t??{},{set:(t,e,s)=>(r.hasOwnProperty(e)&&(r[e]=s),t[e]=s),get:(t,e)=>r.hasOwnProperty(e)?r[e]:t[e]});return s.evaluate(n)}},getIds(t){return this.body.getIds(t).filter(t=>!this.params.includes(t))}}}};function xt(t,e){const s=t?._store;return s?.has(e)?s.get(e):s?.has("$parent")?xt(s.get("$parent"),e):null}function Ct(t,e){const s=t?._store;return s?.has(e)?t:s?.has("$parent")?Ct(s.get("$parent"),e):null}class Lt extends Pt{evalkeys=["$elem","$event"];expressionCache=new Map;observers=new Map;keyHandlers=new Map;_observer=null;_store=new Map;_lock=Promise.resolve();constructor(t){super();for(let[e,s]of Object.entries(t||{}))this.set(e,s)}wrapFunction(t){return(...e)=>t.call(this.$,...e)}wrapObject(t,e){return null==t||((s=t)instanceof Lt||s.__is_proxy__)||t.constructor!==Object&&!Array.isArray(t)?t:new Proxy(t,{deleteProperty:(t,s)=>s in t&&(delete t[s],e(),!0),set:(s,i,r,n)=>{"object"==typeof r&&null!=t&&(r=this.wrapObject(r,e));const a=Reflect.set(s,i,r,n);return e(),a},get:(t,e,s)=>"__is_proxy__"===e||Reflect.get(t,e,s)});var s}watch(t,e){const s=Ct(this,t);if(!s)throw new Error(`Cannot watch key "${t}" as it does not exist in the store.`);s.observers.has(t)||s.observers.set(t,new Set),s.observers.get(t)?.has(e)||s.observers.get(t)?.add(e)}addKeyHandler(t,e){this.keyHandlers.has(t)||this.keyHandlers.set(t,new Set),this.keyHandlers.get(t).add(e)}async notify(t,e=10){const s=Ct(this,t),i=Array.from(s?.observers.get(t)||[]);await this.debounce(e,()=>Promise.all(i.map(t=>t.call(this.proxify(t)))))}get(t,e){return e&&this.watch(t,e),xt(this,t)}async set(t,e){if(e===this._store.get(t))return;const s=()=>this.notify(t);e&&"function"==typeof e&&(e=this.wrapFunction(e)),e&&"object"==typeof e&&(e=this.wrapObject(e,s)),function(t,e,s){const i=Ct(t,e);i?i._store.set(e,s):t._store.set(e,s)}(this,t,e);for(const[s,i]of this.keyHandlers.entries())if(s.test(t))for(const s of i)await Promise.resolve(s.call(this.$,t,e));await s()}async del(t){await this.set(t,null),this._store.delete(t),this.observers.delete(t)}keys(){return Array.from(this._store.keys())}has(t){return this._store.has(t)}effect(t){return t.call(this.proxify(t))}proxify(t){const e=Array.from(this._store.entries()).map(([t])=>t),s=Object.fromEntries(e.map(t=>[t,null]));return new Proxy(s,{get:(e,s,i)=>"string"==typeof s&&Ct(this,s)?this.get(s,t):"$"===s?this.proxify(t):Reflect.get(this,s,i),set:(t,e,s,i)=>("string"!=typeof e||e in this?Reflect.set(this,e,s,i):this.set(e,s),!0)})}get $(){return this.proxify()}makeEvalFunction(t){if(t.includes(";"))throw new Error("Complex expressions are not supported.");let e=null;if(t.includes(" = ")){const[s,i]=t.split(" = ");e=s.trim(),t=i.trim()}return(s,i)=>{const r=((t,e)=>new Ot(t,e).parse())(t,St),n=r?.getIds([])?.map(t=>[t,i[t]??s[t]??globalThis[t]]),a=r?.evaluate(Object.fromEntries(n||[]));if(!e)return a;!function(t,e,s){const i=e.split(".");for(let e=0;e<i.length-1;e++)i[e]in t||(t[i[e]]={}),t=t[i[e]];t[i[i.length-1]]=s}(s,e,a)}}cachedExpressionFunction(t){return t=t.trim(),this.expressionCache.has(t)||this.expressionCache.set(t,this.makeEvalFunction(t)),this.expressionCache.get(t)}eval(t,e={}){const s=this._observer?this:this.$;if(this._store.has(t))return s[t];{const i=this.cachedExpressionFunction(t);try{return i(s,e)}catch(e){return console.error(`Failed to evaluate expression: ${t}`),console.error(e),null}}}}const kt="$$";function Dt(){return new URL(globalThis.window?.location?.href||"http://localhost/")}function Ut(t){return`${kt}${t}`}function zt(t){return t.keys().filter(t=>t.startsWith(kt))}function $t(t,e,s){const i=function(t){return t.substring(2)}(e);let r=!1;if(s){const e=String(s);t.searchParams.get(i)!==e&&(t.searchParams.set(i,e),r=!0)}else t.searchParams.has(i)&&(t.searchParams.delete(i),r=!0);return r}async function Mt(t){const e=Dt();await async function(t,e){for(const[s,i]of e.searchParams.entries()){const e=Ut(s);t.get(e)!==i&&await t.set(e,i)}}(t,e),function(t,e){let s=!1;for(const i of zt(e))$t(t,i,e.get(i))&&(s=!0);s&&globalThis.window?.history?.replaceState({},"",t.toString())}(e,t),t.addKeyHandler(new RegExp("^\\$\\$"),(t,e)=>{const s=Dt();$t(s,t,e)&&globalThis.window?.history?.replaceState({},"",s.toString())}),globalThis.window?.addEventListener("popstate",function(t){return async()=>{const e=Dt(),s=new Set;for(const[i,r]of e.searchParams.entries()){const e=Ut(i);s.add(e),t.get(e)!==r&&t.set(e,r)}const i=zt(t);for(const e of i)s.has(e)||t.del(e)}}(t))}class Ft extends Lt{debugging=!1;dirpath="";_skipNodes=new Set;_customElements=new Map;debug(t){return this.debugging=t,this}async fetchRemote(t,e){return fetch(t,{cache:e?.cache??"default"}).then(t=>t.text())}async fetchLocal(t,e){return this.fetchRemote(t,e)}async preprocessString(t,e){this.log("Preprocessing string content with params:\n",e);const s=this.parseHTML(t,e);return await this.preprocessNode(s,e),s}async preprocessRemote(t,e){const s={};e?.cache&&(s.cache=e.cache);const i=await fetch(t,s).then(t=>t.text());return this.preprocessString(i,{...e,dirpath:ht(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}async preprocessLocal(t,e){const s=await this.fetchLocal(t,e);return this.preprocessString(s,{...e,dirpath:ht(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}subrenderer(){const t=(new this.constructor).debug(this.debugging);return t._store.set("$parent",this),t._store.set("$rootRenderer",this.get("$rootRenderer")??this),t._customElements=this._customElements,t}log(...t){this.debugging&&console.debug(...t)}async preprocessNode(t,e){e={dirpath:this.dirpath,maxdepth:10,...e};const s=new ut(W(t,this._skipNodes)).map(async t=>{this.log("Preprocessing node:\n",ct(t,128)),await dt.resolveIncludes.call(this,t,e),await dt.rebaseRelativePaths.call(this,t,e),await dt.registerCustomElements.call(this,t,e),await dt.resolveCustomElements.call(this,t,e)});return await Promise.all(s.generator()),t}async renderNode(t,e){for(const s of W(t,this._skipNodes))this.log("Rendering node:\n",ct(s,128)),await dt.resolveForAttribute.call(this,s,e),await dt.resolveDataAttribute.call(this,s,e),await dt.resolveTextAttributes.call(this,s,e),await dt.resolveHtmlAttribute.call(this,s,e),await dt.resolveShowAttribute.call(this,s,e),await dt.resolveClassAttribute.call(this,s,e),await dt.resolveBindAttribute.call(this,s,e),await dt.resolveEventAttributes.call(this,s,e),await dt.resolveTextNodeExpressions.call(this,s,e),await dt.resolveCustomAttribute.call(this,s,e),await dt.resolveCustomProperty.call(this,s,e),await dt.stripTypes.call(this,s,e);return t}async mount(t,e){e={...e,rootNode:t},Q(t,"renderer",this),this._store.set("$rootNode",t),this.has("$rootRenderer")||this._store.set("$rootRenderer",this),this.get("$rootRenderer")===this&&await Mt(this),await this.preprocessNode(t,e),await this.renderNode(t,e)}}const Gt=[":data",":for",":text",":html",":show",":class",":bind",":on:click",":on:click.prevent",":on:input",":on:input.prevent",":on:change",":on:change.prevent",":on:submit",":on:submit.prevent",":attr:src",":attr:href",":attr:title",":prop:checked",":prop:selected",":prop:disabled"];class Kt extends Ft{impl="safe_browser";dirpath=ht(globalThis.location?.href??"http://localhost/");parseHTML(t,e={rootDocument:!1}){for(const e of Gt)t=t.replace(new RegExp(`\\s:${e.slice(1)}=`,"g"),` data-${e.slice(1).replace(":","-")}=`);t=(t=(t=t.replace(/<include(.*) src="([^"]+)"(.*)><\/include>/g,'<link $1 rel="subresource" href="$2" $3>')).replace(/<template is="([^"]+)">([\s\S]*)<\/template>/g,'<div role="template" alt="$1">$2</div>')).replace(/<(\w+)-(\w+)(.*)>([\s\S]*)<\/(\w+)-(\w+)>/g,'<div role="$1-$2" $3>$4</div>');const s=Gt.map(t=>`data-${t.slice(1).replace(":","-")}`);s.push("data-testid");const i=(new F).allowDataAttributes(s).allowClassAttributes().allowStyleAttributes().build();if(this.log("parseHTML",t),this.log("sanitized",String(i.sanitize(t))),e.rootDocument){return K(new DOMParser,i.sanitize(t),"text/html")}return i.sanitizeToFragment(t)}serializeHTML(t){return(new XMLSerializer).serializeToString(t).replace(/\s?xmlns="[^"]+"/gm,"")}preprocessLocal(t,e){return this.preprocessRemote(t,e)}createElement(t,e){return(e||document).createElement(t)}textContent(t,e){t.textContent=e}}const Ht=new Kt;export{Ht as Mancha,Kt as Renderer};
|
|
1
|
+
const t={};function e(t){0}class s{constructor(t,e){this.privateDoNotAccessOrElseWrappedAttributePrefix=e}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const i=s;function r(t){if(function(t){return t instanceof s}(t))return t.privateDoNotAccessOrElseWrappedAttributePrefix;throw new Error("")}function n(t){return Object.isFrozen(t)&&Object.isFrozen(t.raw)}function a(t){return-1===t.toString().indexOf("`")}a(t=>t``)||a(t=>t`\0`)||a(t=>t`\n`)||a(t=>t`\u0000`),n``&&n`\0`&&n`\n`&&n`\u0000`;function o(e){const s=e[0].toLowerCase();return new i(t,s)}let l,c="google#safe";function h(){var t;return""!==c&&null!==(t=function(){if("undefined"!=typeof window)return window.trustedTypes}())&&void 0!==t?t:null}class u{constructor(t,s){e(),this.privateDoNotAccessOrElseWrappedHtml=t}toString(){return this.privateDoNotAccessOrElseWrappedHtml.toString()}}function d(e,s){return null!=s?s:new u(e,t)}"undefined"!=typeof window&&window.TrustedHTML;function p(t){var e;const s=t;return d(s,null===(e=function(){var t,e;if(void 0===l)try{l=null!==(e=null===(t=h())||void 0===t?void 0:t.createPolicy(c,{createHTML:t=>t,createScript:t=>t,createScriptURL:t=>t}))&&void 0!==e?e:null}catch(t){l=null}return l}())||void 0===e?void 0:e.createHTML(s))}function f(t){var e;if(null===(e=h())||void 0===e?void 0:e.isHTML(t))return t;if(t instanceof u)return t.privateDoNotAccessOrElseWrappedHtml;throw new Error("")}"undefined"!=typeof window&&window.TrustedScriptURL;"undefined"!=typeof window&&window.TrustedScript;function _(t,e){e.appendChild(t);let s=(new XMLSerializer).serializeToString(e);return s=s.slice(s.indexOf(">")+1,s.lastIndexOf("</")),p(s)}const m=["data:","http:","https:","mailto:","ftp:"],E=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function w(t){if(!function(t){const e=!E.test(t);return e}(t))return t}function v(t){return w(t)}function b(t){const e=function(t){let e;try{e=new URL(t)}catch(t){return"https:"}return e.protocol}(t);return void 0!==e&&-1!==m.indexOf(e.toLowerCase())?t:"about:invalid#zClosurez"}function g(t,e){const s=e.createRange();s.selectNode(e.body);return function(t,e){return t.createContextualFragment(f(e))}(s,p(t))}function y(t){const e=t.nodeName;return"string"==typeof e?e:"FORM"}function A(t){return 3===t.nodeType}function T(t){const e=t.nodeType;return 1===e||"number"!=typeof e}var R,O;function N(t){try{return new URL(t,window.document.baseURI)}catch(t){return new URL("about:invalid")}}function I(t){return{valueOf:t}.valueOf()}!function(t){t[t.STYLE_TAG=0]="STYLE_TAG",t[t.STYLE_ATTRIBUTE=1]="STYLE_ATTRIBUTE",t[t.HTML_ATTRIBUTE=2]="HTML_ATTRIBUTE"}(R||(R={}));class P{constructor(t,e,s,i,r){this.allowedElements=t,this.elementPolicies=e,this.allowedGlobalAttributes=s,this.globalAttributePolicies=i,this.globallyAllowedAttributePrefixes=r}isAllowedElement(t){return"FORM"!==t&&(this.allowedElements.has(t)||this.elementPolicies.has(t))}getAttributePolicy(t,e){const s=this.elementPolicies.get(e);if(null==s?void 0:s.has(t))return s.get(t);if(this.allowedGlobalAttributes.has(t))return{policyAction:O.KEEP};const i=this.globalAttributePolicies.get(t);return i||(this.globallyAllowedAttributePrefixes&&[...this.globallyAllowedAttributePrefixes].some(e=>0===t.indexOf(e))?{policyAction:O.KEEP}:{policyAction:O.DROP})}}!function(t){t[t.DROP=0]="DROP",t[t.KEEP=1]="KEEP",t[t.KEEP_AND_SANITIZE_URL=2]="KEEP_AND_SANITIZE_URL",t[t.KEEP_AND_NORMALIZE=3]="KEEP_AND_NORMALIZE",t[t.KEEP_AND_SANITIZE_STYLE=4]="KEEP_AND_SANITIZE_STYLE",t[t.KEEP_AND_USE_RESOURCE_URL_POLICY=5]="KEEP_AND_USE_RESOURCE_URL_POLICY",t[t.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET=6]="KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET"}(O||(O={}));const S=new Set(["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"]);const x=["ARTICLE","SECTION","NAV","ASIDE","H1","H2","H3","H4","H5","H6","HEADER","FOOTER","ADDRESS","P","HR","PRE","BLOCKQUOTE","OL","UL","LH","LI","DL","DT","DD","FIGURE","FIGCAPTION","MAIN","DIV","EM","STRONG","SMALL","S","CITE","Q","DFN","ABBR","RUBY","RB","RT","RTC","RP","DATA","TIME","CODE","VAR","SAMP","KBD","SUB","SUP","I","B","U","MARK","BDI","BDO","SPAN","BR","WBR","INS","DEL","PICTURE","PARAM","TRACK","MAP","TABLE","CAPTION","COLGROUP","COL","TBODY","THEAD","TFOOT","TR","TD","TH","SELECT","DATALIST","OPTGROUP","OPTION","OUTPUT","PROGRESS","METER","FIELDSET","LEGEND","DETAILS","SUMMARY","MENU","DIALOG","SLOT","CANVAS","FONT","CENTER","ACRONYM","BASEFONT","BIG","DIR","HGROUP","STRIKE","TT"],C=[["A",new Map([["href",{policyAction:O.KEEP_AND_SANITIZE_URL}]])],["AREA",new Map([["href",{policyAction:O.KEEP_AND_SANITIZE_URL}]])],["LINK",new Map([["href",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY,conditions:new Map([["rel",new Set(["alternate","author","bookmark","canonical","cite","help","icon","license","next","prefetch","dns-prefetch","prerender","preconnect","preload","prev","search","subresource"])]])}]])],["SOURCE",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["IMG",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["VIDEO",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}]])],["AUDIO",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}]])]],L=["title","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-current","aria-disabled","aria-dropeffect","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-live","aria-multiline","aria-multiselectable","aria-orientation","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","alt","align","autocapitalize","autocomplete","autocorrect","autofocus","autoplay","bgcolor","border","cellpadding","cellspacing","checked","color","cols","colspan","controls","datetime","disabled","download","draggable","enctype","face","formenctype","frameborder","height","hreflang","hidden","ismap","label","lang","loop","max","maxlength","media","minlength","min","multiple","muted","nonce","open","placeholder","preload","rel","required","reversed","role","rows","rowspan","selected","shape","size","sizes","slot","span","spellcheck","start","step","summary","translate","type","valign","value","width","wrap","itemscope","itemtype","itemid","itemprop","itemref"],k=[["dir",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["dir",new Set(["auto","ltr","rtl"])]]))}],["async",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["async",new Set(["async"])]]))}],["cite",{policyAction:O.KEEP_AND_SANITIZE_URL}],["loading",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["loading",new Set(["eager","lazy"])]]))}],["poster",{policyAction:O.KEEP_AND_SANITIZE_URL}],["target",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["target",new Set(["_self","_blank"])]]))}]],D=new P(new Set(x),new Map(C),new Set(L),new Map(k));new P(new Set(I(()=>x.concat(["STYLE"]))),new Map(C),new Set(I(()=>L.concat(["id","name","class"]))),new Map(I(()=>k.concat([["style",{policyAction:O.KEEP_AND_SANITIZE_STYLE}]]))));class U{constructor(t,s,i,r,n){this.sanitizerTable=t,this.styleElementSanitizer=i,this.styleAttributeSanitizer=r,this.resourceUrlPolicy=n,this.changes=[],e()}sanitizeAssertUnchanged(t){return this.sanitize(t)}sanitize(t){const e=document.implementation.createHTMLDocument("");return _(this.sanitizeToFragmentInternal(t,e),e.body)}sanitizeToFragment(t){const e=document.implementation.createHTMLDocument("");return this.sanitizeToFragmentInternal(t,e)}sanitizeToFragmentInternal(t,e){const s=g(t,e),i=document.createTreeWalker(s,5,t=>this.nodeFilter(t));let r=i.nextNode();const n=e.createDocumentFragment();let a=n;for(;null!==r;){let t;if(A(r))if(this.styleElementSanitizer&&"STYLE"===a.nodeName){const e=this.styleElementSanitizer(r.data);t=this.createTextNode(e)}else t=this.sanitizeTextNode(r);else{if(!T(r)){throw new Error("")}t=this.sanitizeElementNode(r,e)}if(a.appendChild(t),r=i.firstChild(),r)a=t;else for(;!(r=i.nextSibling())&&(r=i.parentNode());)a=a.parentNode}return n}createTextNode(t){return document.createTextNode(t)}sanitizeTextNode(t){return this.createTextNode(t.data)}sanitizeElementNode(t,e){const s=y(t),i=e.createElement(s),r=t.attributes;for(const{name:t,value:e}of r){const n=this.sanitizerTable.getAttributePolicy(t,s);if(this.satisfiesAllConditions(n.conditions,r))switch(n.policyAction){case O.KEEP:z(i,t,e);break;case O.KEEP_AND_SANITIZE_URL:const r=b(e);r!==e&&this.recordChange(`Url in attribute ${t} was modified during sanitization. Original url:"${e}" was sanitized to: "${r}"`),z(i,t,r);break;case O.KEEP_AND_NORMALIZE:z(i,t,e.toLowerCase());break;case O.KEEP_AND_SANITIZE_STYLE:if(this.styleAttributeSanitizer){z(i,t,this.styleAttributeSanitizer(e))}else z(i,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:s},n=N(e),a=this.resourceUrlPolicy(n,r);a&&z(i,t,a.toString())}else z(i,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:s},n=$(e),a={parts:[]};for(const t of n.parts){const e=N(t.url),s=this.resourceUrlPolicy(e,r);s&&a.parts.push({url:s.toString(),descriptor:t.descriptor})}z(i,t,M(a))}else z(i,t,e);break;case O.DROP:this.recordChange(`Attribute: ${t} was dropped`)}else this.recordChange(`Not all conditions satisfied for attribute: ${t}.`)}return i}nodeFilter(t){if(A(t))return 1;if(!T(t))return 2;const e=y(t);return null===e?(this.recordChange(`Node name was null for node: ${t}`),2):this.sanitizerTable.isAllowedElement(e)?1:(this.recordChange(`Element: ${e} was dropped`),2)}recordChange(t){0}satisfiesAllConditions(t,e){var s;if(!t)return!0;for(const[i,r]of t){const t=null===(s=e.getNamedItem(i))||void 0===s?void 0:s.value;if(t&&!r.has(t))return!1}return!0}}function z(t,e,s){t.setAttribute(e,s)}function $(t){const e=[];for(const s of t.split(",")){const[t,i]=s.trim().split(/\s+/,2);e.push({url:t,descriptor:i})}return{parts:e}}function M(t){return t.parts.map(t=>{const{url:e,descriptor:s}=t;return`${e}${s?` ${s}`:""}`}).join(" , ")}class F{constructor(){this.calledBuild=!1,this.sanitizerTable=D}onlyAllowElements(t){const e=new Set,s=new Map;for(let i of t){if(i=i.toUpperCase(),!this.sanitizerTable.isAllowedElement(i))throw new Error(`Element: ${i}, is not allowed by html5_contract.textpb`);const t=this.sanitizerTable.elementPolicies.get(i);void 0!==t?s.set(i,t):e.add(i)}return this.sanitizerTable=new P(e,s,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}allowCustomElement(t,e){const s=new Set(this.sanitizerTable.allowedElements),i=new Map(this.sanitizerTable.elementPolicies);if(t=t.toUpperCase(),r=t,S.has(r.toUpperCase())||!/^[a-z][-_.a-z0-9]*-[-_.a-z0-9]*$/i.test(r))throw new Error(`Element: ${t} is not a custom element`);var r;if(e){const s=new Map;for(const t of e)s.set(t,{policyAction:O.KEEP});i.set(t,s)}else s.add(t);return this.sanitizerTable=new P(s,i,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}onlyAllowAttributes(t){const e=new Set,s=new Map,i=new Map;for(const i of t)this.sanitizerTable.allowedGlobalAttributes.has(i)&&e.add(i),this.sanitizerTable.globalAttributePolicies.has(i)&&s.set(i,this.sanitizerTable.globalAttributePolicies.get(i));for(const[e,s]of this.sanitizerTable.elementPolicies.entries()){const r=new Map;for(const[e,i]of s.entries())t.has(e)&&r.set(e,i);i.set(e,r)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,i,e,s),this}allowDataAttributes(t){const e=new Set(this.sanitizerTable.allowedGlobalAttributes);for(const s of t){if(0!==s.indexOf("data-"))throw new Error(`data attribute: ${s} does not begin with the prefix "data-"`);e.add(s)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,e,this.sanitizerTable.globalAttributePolicies),this}allowStyleAttributes(){const t=new Map(this.sanitizerTable.globalAttributePolicies);return t.set("style",{policyAction:O.KEEP_AND_SANITIZE_STYLE}),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,this.sanitizerTable.allowedGlobalAttributes,t),this}allowClassAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("class"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}allowIdAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("id"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}allowIdReferenceAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("aria-activedescendant").add("aria-controls").add("aria-labelledby").add("aria-owns").add("for").add("list"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}withResourceUrlPolicy(t){return this.resourceUrlPolicy=t,this}build(){if(this.calledBuild)throw new Error("this sanitizer has already called build");return this.calledBuild=!0,new U(this.sanitizerTable,t,void 0,void 0,this.resourceUrlPolicy)}}function G(t,e,s,i){if(0===t.length){throw new Error("")}const n=t.map(t=>r(t)),a=s.toLowerCase();if(n.every(t=>0!==a.indexOf(t)))throw new Error(`Attribute "${s}" does not match any of the allowed prefixes.`);e.setAttribute(s,i)}function K(t,e,s){return t.parseFromString(f(e),s)}Error;const H=[o`:`,o`style`,o`class`];function*W(t,e=new Set){const s=new Set,i=Array.from(t.childNodes).filter(t=>!e.has(t));for(yield t;i.length;){const t=i.shift();s.has(t)||(s.add(t),yield t),t.childNodes&&Array.from(t.childNodes).filter(t=>!e.has(t)).forEach(t=>i.push(t))}}function Y(t,e){return void 0!==t?.[e]}function B(t,e){return"function"==typeof t?.[e]}function V(t){return t.replace(/-./g,t=>t[1].toUpperCase())}function Z(t,e){return Y(t,"attribs")?t.attribs?.[e]??null:t.getAttribute?.(e)??null}function j(t,e,s=""){return Z(t,s+e)||(t.dataset?.[V(e)]??null)}function q(t,e,s){Y(t,"attribs")?t.attribs[e]=s:t.setAttribute?.(e,s)}function X(t,e,s){Y(t,"attribs")?t.attribs[e]=s:G(H,t,e,s)}function Q(t,e,s){switch(e){case"disabled":return void(t.disabled=s);case"selected":return void(t.selected=s);case"checked":return void(t.checked=s);default:t[e]=s}}function J(t,e){Y(t,"attribs")?delete t.attribs[e]:t.removeAttribute?.(e)}function tt(t,e,s=""){J(t,`${s}${e}`),J(t,`data-${e}`)}function et(t,e,s){if(Y(t,"attribs")&&Y(e,"attribs"))e.attribs[s]=t.attribs[s];else if(s.startsWith("data-")){const i=V(s.slice(5));e.dataset[i]=t.dataset?.[i]}else{const i=t?.getAttribute?.(s);X(e,s,i||"")}}function st(t){if(Y(t,"firstElementChild"))return t.firstElementChild;return Array.from(t.children).find(t=>1===t.nodeType)}function it(t,...e){if(B(t,"replaceWith"))return t.replaceWith(...e);{const s=t,i=s.parentNode,r=Array.from(i.childNodes).indexOf(s);e.forEach(t=>t.parentNode=i),i.childNodes=[].concat(Array.from(i.childNodes).slice(0,r)).concat(e).concat(Array.from(i.childNodes).slice(r+1))}}function rt(t,...e){B(t,"replaceChildren")?t.replaceChildren(...e):(t.childNodes=e,e.forEach(e=>e.parentNode=t))}function nt(t,e){return B(e,"appendChild")?t.appendChild(e):(t.childNodes.push(e),e.parentNode=t,e)}function at(t,e){return B(e,"removeChild")?t.removeChild(e):(rt(t,...Array.from(t.childNodes).filter(t=>t!==e)),e)}function ot(t,e,s){return s?B(t,"insertBefore")?t.insertBefore(e,s):(it(s,e,s),e):nt(t,e)}function lt(t,e=0){return t?t.length<=e?t:t.slice(0,e-1)+"…":""}function ct(t,e=0){return globalThis.DocumentFragment&&t instanceof DocumentFragment?Array.from(t.childNodes).map(t=>ct(t,e)).join(""):lt(t.outerHTML||t.nodeValue||String(t),e)}function ht(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):""}class ut{iterable;constructor(t){this.iterable=t}filter(t){return new ut(ut.filterGenerator(t,this.iterable))}map(t){return new ut(ut.mapGenerator(t,this.iterable))}find(t){for(const e of this.iterable)if(t(e))return e}array(){return Array.from(this.iterable)}*generator(){for(const t of this.iterable)yield t}static*filterGenerator(t,e){for(const s of e)t(s)&&(yield s)}static*mapGenerator(t,e){for(const s of e)yield t(s)}static equals(t,e){const s=t[Symbol.iterator](),i=e[Symbol.iterator]();let r=s.next(),n=i.next();for(;!r.done&&!n.done;){if(r.value!==n.value)return!1;r=s.next(),n=i.next()}return r.done===n.done}}var dt;!function(t){t.resolveIncludes=async function(t,e){const s=t,i=s.tagName?.toLowerCase();if(!["include","link"].includes(i))return;if("link"===i&&"subresource"!==Z(s,"rel"))return;this.log("include directive found in:\n",ct(t,128)),this.log("include params:",e);const r="link"===s.tagName.toLocaleLowerCase()?"href":"src",n=Z(s,r);if(!n)throw new Error(`"${r}" attribute missing from ${ct(t,128)}.`);const a=[];"include"===i&&a.push("src"),"link"===i&&a.push("rel","href");const o=e=>{const i=st(e);for(const t of Array.from(s.attributes))i&&!a.includes(t.name)&&et(s,i,t.name);it(t,...e.childNodes)},l={...e,rootDocument:!1,maxdepth:e?.maxdepth-1};if(0===l.maxdepth)throw new Error("Maximum recursion depth reached.");if(n.includes("://")||n.startsWith("//"))this.log("Including remote file from absolute path:",n),await this.preprocessRemote(n,l).then(o);else if(e?.dirpath?.includes("://")||e?.dirpath?.startsWith("//")){const t=n.startsWith("/")?n:`${e.dirpath}/${n}`;this.log("Including remote file from relative path:",t),await this.preprocessRemote(t,l).then(o)}else if("/"===n.charAt(0))this.log("Including local file from absolute path:",n),await this.preprocessLocal(n,l).then(o);else{const t=e?.dirpath&&"."!==e?.dirpath?`${e?.dirpath}/${n}`:n;this.log("Including local file from relative path:",t),await this.preprocessLocal(t,l).then(o)}},t.rebaseRelativePaths=async function(t,e){const s=t,i=s.tagName?.toLowerCase();if(!e?.dirpath)return;const r=Z(s,"src"),n=Z(s,"href"),a=r||n;if(!a||((o=a).includes("://")||o.startsWith("/")||o.startsWith("#")||o.startsWith("data:")))return;var o;const l=`${e.dirpath}/${a}`;this.log("Rebasing relative path as:",l),Y(s,"attribs")?X(s,r?"src":"href",l):"img"===i?s.src=l:"a"===i?function(t,e){const s=v(e);void 0!==s&&(t.href=s)}(s,l):"source"===i||"audio"===i||"video"===i||"track"===i||"input"===i?s.src=l:"area"===i?function(t,e){const s=v(e);void 0!==s&&(t.href=s)}(s,l):this.log("Unable to rebase relative path for element:",i)},t.registerCustomElements=async function(t,e){const s=t,i=s.tagName?.toLowerCase(),r=(Z(s,"is")||Z(s,"alt"))?.toLowerCase();if(["template","div"].includes(i)&&r){if("div"===i&&"template"!==Z(s,"role"))return;this._customElements.has(r)||(this.log(`Registering custom element: ${r}\n`,ct(s,128)),this._customElements.set(r,s),at(s.parentNode,s))}},t.resolveCustomElements=async function(t,e){const s=t,i=s.tagName?.toLowerCase();let r=i;if("div"===r&&(r=Z(s,"role")?.toLowerCase()||r),r&&this._customElements.has(r)){this.log(`Processing custom element: ${r}\n`,ct(s,128));const e=this._customElements.get(r),n=(e.content||e).cloneNode(!0),a=st(n);if(a)for(const t of Array.from(s.attributes))"div"===i&&"role"===t.name||et(s,a,t.name);const o=new ut(W(n)).find(t=>"slot"===t.tagName?.toLowerCase());o&&it(o,...s.childNodes),it(t,...n.childNodes)}},t.resolveTextNodeExpressions=async function(t,e){const s=t.nodeValue||"";if(3!==t.nodeType||!s?.trim())return;this.log("Processing node content value:\n",lt(s,128));const i=new RegExp(/{{ ([^}]+) }}/gm),r=Array.from(s.matchAll(i)).map(t=>t[1]);return this.effect(function(){let e=s;for(const s of r){const i=this.eval(s,{$elem:t});e=e.replace(`{{ ${s} }}`,String(i))}t.nodeValue=e})},t.resolveDataAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"data",":");if(i){this.log(":data attribute found in:\n",ct(t,128)),tt(s,"data",":");const r=e?.rootNode===t?this:this.subrenderer();t.renderer=r;const n=r.eval(i,{$elem:t});if(await Promise.all(Object.entries(n).map(([t,e])=>r._store.set(t,e))),r!==this)for(const e of W(t,this._skipNodes))this._skipNodes.add(e);await r.mount(t,e)}},t.resolveClassAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"class",":");if(i){this.log(":class attribute found in:\n",ct(t,128)),tt(s,"class",":");const e=Z(s,"class")||"";return this.effect(function(){const r=this.eval(i,{$elem:t});X(s,"class",(r?`${e} ${r}`:e).trim())})}},t.resolveTextAttributes=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"text",":");if(i){this.log(":text attribute found in:\n",ct(t,128)),tt(s,"text",":");const e=e=>this.textContent(t,e);return this.effect(function(){e(this.eval(i,{$elem:t}))})}},t.resolveHtmlAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"html",":");return i?(this.log(":html attribute found in:\n",ct(t,128)),tt(s,"html",":"),this.effect(function(){const r=this.eval(i,{$elem:t});return new Promise(async t=>{const i=await this.preprocessString(r,e);await this.renderNode(i),rt(s,i),t()})})):void 0},t.resolveEventAttributes=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[]))if(e.name.startsWith(":on:")||e.name.startsWith("data-on-")){let i="",r=[];if(e.name.startsWith(":on:")?[i,...r]=e.name.substring(4).split("."):e.name.startsWith("data-on-")&&([i,...r]=e.name.substring(8).split(".")),!i)throw new Error(`Invalid event attribute: ${e.name}`);this.log(e.name,"attribute found in:\n",ct(t,128)),tt(s,e.name);const n="submit"===i&&"FORM"===s.tagName.toUpperCase();t.addEventListener?.(i,s=>((r.includes("prevent")||n)&&s.preventDefault(),this.eval(e.value,{$elem:t,$event:s})))}},t.resolveForAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"for",":")?.trim();if(i){this.log(":for attribute found in:\n",ct(t,128)),tt(s,"for",":");for(const e of W(t,this._skipNodes))this._skipNodes.add(e);const r=Z(s,"style")||"";q(s,"style","display: none;");const n=t.parentNode,a=this.createElement("template",t.ownerDocument);ot(n,a,t),at(n,t),nt(a,t),this.log(":for template:\n",ct(a,128));const o=i.split(" in ",2);if(2!==o.length)throw new Error(`Invalid :for format: \`${i}\`. Expected "{key} in {expression}".`);const l=[],[c,h]=o;await this.effect(function(){const s=this.eval(h,{$elem:t});if(this.log(":for list items:",s),l.splice(0,l.length).forEach(t=>{at(n,t),this._skipNodes.delete(t)}),!Array.isArray(s))return console.error(`Expression did not yield a list: \`${h}\` => \`${s}\``),Promise.resolve();const i=[];for(const n of s){const s=this.subrenderer();s._store.set(c,n);const a=t.cloneNode(!0);q(a,"style",r),l.push(a),this._skipNodes.add(a),i.push(s.mount(a,e)),this.log("Rendered list child:\n",ct(a,128))}const o=a.nextSibling;for(const t of l)ot(n,t,o);return Promise.all(i)})}},t.resolveBindAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"bind",":");if(i){this.log(":bind attribute found in:\n",ct(t,128));const e=["change","input"],r=Z(s,":bind:on")?.split(",")||s.dataset?.bindOn?.split(",")||e;tt(s,"bind",":"),J(s,":bind:on"),J(s,"data-bind-on");const n="checkbox"===Z(s,"type")?"checked":"value";i.includes(".")||this.has(i)||this.set(i,""),this.effect(function(){const e=this.eval(i,{$elem:t});"checked"===n?s.checked=!!e:s.value=e});const a=`${i} = $elem.${n}`;for(const e of r)t.addEventListener(e,()=>this.eval(a,{$elem:t}))}},t.resolveShowAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"show",":");if(i){this.log(":show attribute found in:\n",ct(t,128)),tt(s,"show",":");const e="none"===s.style?.display?"":s.style?.display??Z(s,"style")?.split(";")?.find(t=>"display"===t.split(":")[0])?.split(":")?.at(1)?.trim();this.effect(function(){const r=this.eval(i,{$elem:t});s.style?s.style.display=r?e:"none":X(s,"style",`display: ${r?e:"none"};`)})}},t.resolveCustomAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[])){const i=":attr:",r="data-attr-";if(e.name.startsWith(i)||e.name.startsWith(r)){this.log(e.name,"attribute found in:\n",ct(t,128)),J(s,e.name);const n=e.name.split(i,2).at(-1)?.split(r,2).at(-1);this.effect(function(){const i=this.eval(e.value,{$elem:t});q(s,n,i)})}}},t.resolveCustomProperty=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[])){const i=":prop:",r="data-prop-";if(e.name.startsWith(i)||e.name.startsWith(r)){this.log(e.name,"property found in:\n",ct(t,128)),J(s,e.name);const n=e.name.split(i,2).at(-1)?.split(r,2).at(-1),a=V(n);this.effect(function(){const i=this.eval(e.value,{$elem:t});Q(s,a,i)})}}},t.stripTypes=async function(t,e){const s=t;Z(s,":types")&&J(s,":types"),Z(s,"data-types")&&J(s,"data-types")}}(dt||(dt={}));const pt=["this"],ft=["+","-","!"],_t=["=","+","-","*","/","%","^","==","!=",">","<",">=","<=","||","&&","??","&","===","!==","|","|>"],mt={"!":0,":":0,",":0,")":0,"]":0,"}":0,"|>":1,"?":2,"??":3,"||":4,"&&":5,"|":6,"^":7,"&":8,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},Et=["==","!=","<=",">=","||","&&","??","|>"],wt=["===","!=="];var vt;!function(t){t[t.STRING=1]="STRING",t[t.IDENTIFIER=2]="IDENTIFIER",t[t.DOT=3]="DOT",t[t.COMMA=4]="COMMA",t[t.COLON=5]="COLON",t[t.INTEGER=6]="INTEGER",t[t.DECIMAL=7]="DECIMAL",t[t.OPERATOR=8]="OPERATOR",t[t.GROUPER=9]="GROUPER",t[t.KEYWORD=10]="KEYWORD",t[t.ARROW=11]="ARROW"}(vt||(vt={}));const bt=(t,e,s=0)=>({kind:t,value:e,precedence:s}),gt=t=>9===t||10===t||13===t||32===t,yt=t=>95===t||36===t||65<=(t&=-33)&&t<=90,At=t=>yt(t)||Tt(t),Tt=t=>48<=t&&t<=57;class Rt{_input;_index=-1;_tokenStart=0;_next;constructor(t){this._input=t,this._advance()}nextToken(){for(;gt(this._next);)this._advance(!0);if(34===(t=this._next)||39===t)return this._tokenizeString();var t;if(yt(this._next))return this._tokenizeIdentOrKeyword();if(Tt(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((t=>43===t||45===t||42===t||47===t||33===t||38===t||37===t||60===t||61===t||62===t||63===t||94===t||124===t)(this._next))return this._tokenizeOperator();if((t=>40===t||41===t||91===t||93===t||123===t||125===t)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(t){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),!0===t&&(this._tokenStart=this._index)):this._next=void 0}_getValue(t=0){const e=this._input.substring(this._tokenStart,this._index+t);return 0===t&&this._clearValue(),e}_clearValue(){this._tokenStart=this._index}_tokenizeString(){const t="unterminated string",e=this._next;for(this._advance(!0);this._next!==e;){if(void 0===this._next)throw new Error(t);if(92===this._next&&(this._advance(),void 0===this._next))throw new Error(t);this._advance()}const s=bt(vt.STRING,this._getValue().replace(/\\(.)/g,(t,e)=>{switch(e){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return e}}));return this._advance(),s}_tokenizeIdentOrKeyword(){do{this._advance()}while(At(this._next));const t=this._getValue(),e=(s=t,-1!==pt.indexOf(s)?vt.KEYWORD:vt.IDENTIFIER);var s;return bt(e,t)}_tokenizeNumber(){do{this._advance()}while(Tt(this._next));return 46===this._next?this._tokenizeDot():bt(vt.INTEGER,this._getValue())}_tokenizeDot(){return this._advance(),Tt(this._next)?this._tokenizeFraction():(this._clearValue(),bt(vt.DOT,".",13))}_tokenizeComma(){return this._advance(!0),bt(vt.COMMA,",")}_tokenizeColon(){return this._advance(!0),bt(vt.COLON,":")}_tokenizeFraction(){do{this._advance()}while(Tt(this._next));return bt(vt.DECIMAL,this._getValue())}_tokenizeOperator(){this._advance();let t=this._getValue(2);if(-1!==wt.indexOf(t))this._advance(),this._advance();else{if(t=this._getValue(1),"=>"===t)return this._advance(),bt(vt.ARROW,t);-1!==Et.indexOf(t)&&this._advance()}return t=this._getValue(),bt(vt.OPERATOR,t,mt[t])}_tokenizeGrouper(){const t=String.fromCharCode(this._next),e=bt(vt.GROUPER,t,mt[t]);return this._advance(!0),e}}class Ot{_kind;_tokenizer;_ast;_token;_value;constructor(t,e){this._tokenizer=new Rt(t),this._ast=e}parse(){return this._advance(),this._parseExpression()}_advance(t,e){if(!this._matches(t,e))throw new Error(`Expected kind ${t} (${e}), was ${this._token?.kind} (${this._token?.value})`);const s=this._tokenizer.nextToken();this._token=s,this._kind=s?.kind,this._value=s?.value}_matches(t,e){return!(t&&this._kind!==t||e&&this._value!==e)}_parseExpression(){if(!this._token)return this._ast.empty();const t=this._parseUnary();return void 0===t?void 0:this._parsePrecedence(t,0)}_parsePrecedence(t,e){if(void 0===t)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(vt.GROUPER,"(")){const e=this._parseArguments();t=this._ast.invoke(t,void 0,e)}else if(this._matches(vt.GROUPER,"[")){const e=this._parseIndex();t=this._ast.index(t,e)}else if(this._matches(vt.DOT)){this._advance();const e=this._parseUnary();t=this._makeInvokeOrGetter(t,e)}else{if(this._matches(vt.KEYWORD))break;if(!(this._matches(vt.OPERATOR)&&this._token.precedence>=e))break;t="?"===this._value?this._parseTernary(t):this._parseBinary(t,this._token)}return t}_makeInvokeOrGetter(t,e){if(void 0===e)throw new Error("expected identifier");if("ID"===e.type)return this._ast.getter(t,e.value);if("Invoke"===e.type&&"ID"===e.receiver.type){const s=e.receiver;return this._ast.invoke(t,s.value,e.arguments)}throw new Error(`expected identifier: ${e}`)}_parseBinary(t,e){if(-1===_t.indexOf(e.value))throw new Error(`unknown operator: ${e.value}`);this._advance();let s=this._parseUnary();for(;(this._kind===vt.OPERATOR||this._kind===vt.DOT||this._kind===vt.GROUPER)&&this._token.precedence>e.precedence;)s=this._parsePrecedence(s,this._token.precedence);return this._ast.binary(t,e.value,s)}_parseUnary(){if(this._matches(vt.OPERATOR)){const t=this._value;if(this._advance(),"+"===t||"-"===t){if(this._matches(vt.INTEGER))return this._parseInteger(t);if(this._matches(vt.DECIMAL))return this._parseDecimal(t)}if(-1===ft.indexOf(t))throw new Error(`unexpected token: ${t}`);const e=this._parsePrecedence(this._parsePrimary(),13);return this._ast.unary(t,e)}return this._parsePrimary()}_parseTernary(t){this._advance(vt.OPERATOR,"?");const e=this._parseExpression();this._advance(vt.COLON);const s=this._parseExpression();return this._ast.ternary(t,e,s)}_parsePrimary(){switch(this._kind){case vt.KEYWORD:const t=this._value;if("this"===t)return this._advance(),this._ast.id(t);if(-1!==pt.indexOf(t))throw new Error(`unexpected keyword: ${t}`);throw new Error(`unrecognized keyword: ${t}`);case vt.IDENTIFIER:return this._parseInvokeOrIdentifier();case vt.STRING:return this._parseString();case vt.INTEGER:return this._parseInteger();case vt.DECIMAL:return this._parseDecimal();case vt.GROUPER:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case vt.COLON:throw new Error('unexpected token ":"');default:return}}_parseList(){const t=[];do{if(this._advance(),this._matches(vt.GROUPER,"]"))break;t.push(this._parseExpression())}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,"]"),this._ast.list(t)}_parseMap(){const t={};do{if(this._advance(),this._matches(vt.GROUPER,"}"))break;const e=this._value;(this._matches(vt.STRING)||this._matches(vt.IDENTIFIER))&&this._advance(),this._advance(vt.COLON),t[e]=this._parseExpression()}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,"}"),this._ast.map(t)}_parseInvokeOrIdentifier(){const t=this._value;if("true"===t)return this._advance(),this._ast.literal(!0);if("false"===t)return this._advance(),this._ast.literal(!1);if("null"===t)return this._advance(),this._ast.literal(null);if("undefined"===t)return this._advance(),this._ast.literal(void 0);const e=this._parseIdentifier(),s=this._parseArguments();return s?this._ast.invoke(e,void 0,s):e}_parseIdentifier(){if(!this._matches(vt.IDENTIFIER))throw new Error(`expected identifier: ${this._value}`);const t=this._value;return this._advance(),this._ast.id(t)}_parseArguments(){if(!this._matches(vt.GROUPER,"("))return;const t=[];do{if(this._advance(),this._matches(vt.GROUPER,")"))break;const e=this._parseExpression();t.push(e)}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,")"),t}_parseIndex(){this._advance();const t=this._parseExpression();return this._advance(vt.GROUPER,"]"),t}_parseParenOrFunction(){const t=this._parseArguments();if(this._matches(vt.ARROW)){this._advance();const e=this._parseExpression(),s=t?.map(t=>t.value)??[];return this._ast.arrowFunction(s,e)}return this._ast.paren(t[0])}_parseString(){const t=this._ast.literal(this._value);return this._advance(),t}_parseInteger(t=""){const e=this._ast.literal(parseInt(`${t}${this._value}`,10));return this._advance(),e}_parseDecimal(t=""){const e=this._ast.literal(parseFloat(`${t}${this._value}`));return this._advance(),e}}const Nt={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e,">":(t,e)=>t>e,">=":(t,e)=>t>=e,"<":(t,e)=>t<e,"<=":(t,e)=>t<=e,"||":(t,e)=>t||e,"&&":(t,e)=>t&&e,"??":(t,e)=>t??e,"|":(t,e)=>e(t),"|>":(t,e)=>e(t)},It={"+":t=>t,"-":t=>-t,"!":t=>!t};class Pt{timeouts=new Map;debounce(t,e){return new Promise((s,i)=>{const r=this.timeouts.get(e);r&&clearTimeout(r),this.timeouts.set(e,setTimeout(()=>{try{s(e()),this.timeouts.delete(e)}catch(t){i(t)}},t))})}}const St=new class{empty(){return{type:"Empty",evaluate:t=>t,getIds:t=>t}}literal(t){return{type:"Literal",value:t,evaluate(t){return this.value},getIds:t=>t}}id(t){return{type:"ID",value:t,evaluate(t){return"this"===this.value?t:t?.[this.value]},getIds(t){return t.push(this.value),t}}}unary(t,e){const s=It[t];return{type:"Unary",operator:t,child:e,evaluate(t){return s(this.child.evaluate(t))},getIds(t){return this.child.getIds(t)}}}binary(t,e,s){const i=Nt[e];return{type:"Binary",operator:e,left:t,right:s,evaluate(t){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const e=this.right.evaluate(t);let s,i;return"Getter"===this.left.type?(s=this.left.receiver.evaluate(t),i=this.left.name):"Index"===this.left.type?(s=this.left.receiver.evaluate(t),i=this.left.argument.evaluate(t)):"ID"===this.left.type&&(s=t,i=this.left.value),void 0===s?void 0:s[i]=e}return i(this.left.evaluate(t),this.right.evaluate(t))},getIds(t){return this.left.getIds(t),this.right.getIds(t),t}}}getter(t,e){return{type:"Getter",receiver:t,name:e,evaluate(t){return this.receiver.evaluate(t)?.[this.name]},getIds(t){return this.receiver.getIds(t),t}}}invoke(t,e,s){if(null!=e&&"string"!=typeof e)throw new Error("method not a string");return{type:"Invoke",receiver:t,method:e,arguments:s,evaluate(t){const s=this.receiver.evaluate(t),i=this.method?s:t?.this??t,r=this.method?s?.[e]:s,n=(this.arguments??[]).map(e=>e?.evaluate(t));return r?.apply?.(i,n)},getIds(t){return this.receiver.getIds(t),this.arguments?.forEach(e=>e?.getIds(t)),t}}}paren(t){return t}index(t,e){return{type:"Index",receiver:t,argument:e,evaluate(t){return this.receiver.evaluate(t)?.[this.argument.evaluate(t)]},getIds(t){return this.receiver.getIds(t),t}}}ternary(t,e,s){return{type:"Ternary",condition:t,trueExpr:e,falseExpr:s,evaluate(t){return this.condition.evaluate(t)?this.trueExpr.evaluate(t):this.falseExpr.evaluate(t)},getIds(t){return this.condition.getIds(t),this.trueExpr.getIds(t),this.falseExpr.getIds(t),t}}}map(t){return{type:"Map",entries:t,evaluate(e){const s={};if(t&&this.entries)for(const i in t){const t=this.entries[i];t&&(s[i]=t.evaluate(e))}return s},getIds(e){if(t&&this.entries)for(const s in t){const t=this.entries[s];t&&t.getIds(e)}return e}}}list(t){return{type:"List",items:t,evaluate(t){return this.items?.map(e=>e?.evaluate(t))},getIds(t){return this.items?.forEach(e=>e?.getIds(t)),t}}}arrowFunction(t,e){return{type:"ArrowFunction",params:t,body:e,evaluate(t){const e=this.params,s=this.body;return function(...i){const r=Object.fromEntries(e.map((t,e)=>[t,i[e]])),n=new Proxy(t??{},{set:(t,e,s)=>(r.hasOwnProperty(e)&&(r[e]=s),t[e]=s),get:(t,e)=>r.hasOwnProperty(e)?r[e]:t[e]});return s.evaluate(n)}},getIds(t){return this.body.getIds(t).filter(t=>!this.params.includes(t))}}}};function xt(t,e){const s=t?._store;return s?.has(e)?s.get(e):s?.has("$parent")?xt(s.get("$parent"),e):null}function Ct(t,e){const s=t?._store;return s?.has(e)?t:s?.has("$parent")?Ct(s.get("$parent"),e):null}class Lt extends Pt{evalkeys=["$elem","$event"];expressionCache=new Map;observers=new Map;keyHandlers=new Map;_observer=null;_store=new Map;_lock=Promise.resolve();constructor(t){super();for(let[e,s]of Object.entries(t||{}))this.set(e,s)}wrapFunction(t){return(...e)=>t.call(this.$,...e)}wrapObject(t,e){return null==t||((s=t)instanceof Lt||s.__is_proxy__)||t.constructor!==Object&&!Array.isArray(t)?t:new Proxy(t,{deleteProperty:(t,s)=>s in t&&(delete t[s],e(),!0),set:(s,i,r,n)=>{"object"==typeof r&&null!=t&&(r=this.wrapObject(r,e));const a=Reflect.set(s,i,r,n);return e(),a},get:(t,e,s)=>"__is_proxy__"===e||Reflect.get(t,e,s)});var s}watch(t,e){const s=Ct(this,t);if(!s)throw new Error(`Cannot watch key "${t}" as it does not exist in the store.`);s.observers.has(t)||s.observers.set(t,new Set),s.observers.get(t)?.has(e)||s.observers.get(t)?.add(e)}addKeyHandler(t,e){this.keyHandlers.has(t)||this.keyHandlers.set(t,new Set),this.keyHandlers.get(t).add(e)}async notify(t,e=10){const s=Ct(this,t),i=Array.from(s?.observers.get(t)||[]);await this.debounce(e,()=>Promise.all(i.map(t=>t.call(this.proxify(t)))))}get(t,e){return e&&this.watch(t,e),xt(this,t)}async set(t,e){if(e===this._store.get(t))return;const s=()=>this.notify(t);e&&"function"==typeof e&&(e=this.wrapFunction(e)),e&&"object"==typeof e&&(e=this.wrapObject(e,s)),function(t,e,s){const i=Ct(t,e);i?i._store.set(e,s):t._store.set(e,s)}(this,t,e);for(const[s,i]of this.keyHandlers.entries())if(s.test(t))for(const s of i)await Promise.resolve(s.call(this.$,t,e));await s()}async del(t){await this.set(t,null),this._store.delete(t),this.observers.delete(t)}keys(){return Array.from(this._store.keys())}has(t){return this._store.has(t)}effect(t){return t.call(this.proxify(t))}proxify(t){const e=Array.from(this._store.entries()).map(([t])=>t),s=Object.fromEntries(e.map(t=>[t,null]));return new Proxy(s,{get:(e,s,i)=>"string"==typeof s&&Ct(this,s)?this.get(s,t):"$"===s?this.proxify(t):Reflect.get(this,s,i),set:(t,e,s,i)=>("string"!=typeof e||e in this?Reflect.set(this,e,s,i):this.set(e,s),!0)})}get $(){return this.proxify()}makeEvalFunction(t){if(t.includes(";"))throw new Error("Complex expressions are not supported.");let e=null;if(t.includes(" = ")){const[s,i]=t.split(" = ");e=s.trim(),t=i.trim()}return(s,i)=>{const r=((t,e)=>new Ot(t,e).parse())(t,St),n=r?.getIds([])?.map(t=>[t,i[t]??s[t]??globalThis[t]]),a=r?.evaluate(Object.fromEntries(n||[]));if(!e)return a;!function(t,e,s){const i=e.split(".");for(let e=0;e<i.length-1;e++)i[e]in t||(t[i[e]]={}),t=t[i[e]];t[i[i.length-1]]=s}(s,e,a)}}cachedExpressionFunction(t){return t=t.trim(),this.expressionCache.has(t)||this.expressionCache.set(t,this.makeEvalFunction(t)),this.expressionCache.get(t)}eval(t,e={}){const s=this._observer?this:this.$;if(this._store.has(t))return s[t];{const i=this.cachedExpressionFunction(t);try{return i(s,e)}catch(e){return console.error(`Failed to evaluate expression: ${t}`),console.error(e),null}}}}const kt="$$";function Dt(){return new URL(globalThis.window?.location?.href||"http://localhost/")}function Ut(t){return`${kt}${t}`}function zt(t){return t.keys().filter(t=>t.startsWith(kt))}function $t(t,e,s){const i=function(t){return t.substring(2)}(e);let r=!1;if(s){const e=String(s);t.searchParams.get(i)!==e&&(t.searchParams.set(i,e),r=!0)}else t.searchParams.has(i)&&(t.searchParams.delete(i),r=!0);return r}async function Mt(t){const e=Dt();await async function(t,e){for(const[s,i]of e.searchParams.entries()){const e=Ut(s);t.get(e)!==i&&await t.set(e,i)}}(t,e),function(t,e){let s=!1;for(const i of zt(e))$t(t,i,e.get(i))&&(s=!0);s&&globalThis.window?.history?.replaceState({},"",t.toString())}(e,t),t.addKeyHandler(new RegExp("^\\$\\$"),(t,e)=>{const s=Dt();$t(s,t,e)&&globalThis.window?.history?.replaceState({},"",s.toString())}),globalThis.window?.addEventListener("popstate",function(t){return async()=>{const e=Dt(),s=new Set;for(const[i,r]of e.searchParams.entries()){const e=Ut(i);s.add(e),t.get(e)!==r&&t.set(e,r)}const i=zt(t);for(const e of i)s.has(e)||t.del(e)}}(t))}class Ft extends Lt{debugging=!1;dirpath="";_skipNodes=new Set;_customElements=new Map;debug(t){return this.debugging=t,this}async fetchRemote(t,e){return fetch(t,{cache:e?.cache??"default"}).then(t=>t.text())}async fetchLocal(t,e){return this.fetchRemote(t,e)}async preprocessString(t,e){this.log("Preprocessing string content with params:\n",e);const s=this.parseHTML(t,e);return await this.preprocessNode(s,e),s}async preprocessRemote(t,e){const s={};e?.cache&&(s.cache=e.cache);const i=await fetch(t,s).then(t=>t.text());return this.preprocessString(i,{...e,dirpath:ht(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}async preprocessLocal(t,e){const s=await this.fetchLocal(t,e);return this.preprocessString(s,{...e,dirpath:ht(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}subrenderer(){const t=(new this.constructor).debug(this.debugging);return t._store.set("$parent",this),t._store.set("$rootRenderer",this.get("$rootRenderer")??this),t._customElements=this._customElements,t}log(...t){this.debugging&&console.debug(...t)}async preprocessNode(t,e){e={dirpath:this.dirpath,maxdepth:10,...e};const s=new ut(W(t,this._skipNodes)).map(async t=>{this.log("Preprocessing node:\n",ct(t,128)),await dt.resolveIncludes.call(this,t,e),await dt.rebaseRelativePaths.call(this,t,e),await dt.registerCustomElements.call(this,t,e),await dt.resolveCustomElements.call(this,t,e)});return await Promise.all(s.generator()),t}async renderNode(t,e){for(const s of W(t,this._skipNodes))this.log("Rendering node:\n",ct(s,128)),await dt.resolveForAttribute.call(this,s,e),await dt.resolveDataAttribute.call(this,s,e),await dt.resolveTextAttributes.call(this,s,e),await dt.resolveHtmlAttribute.call(this,s,e),await dt.resolveShowAttribute.call(this,s,e),await dt.resolveClassAttribute.call(this,s,e),await dt.resolveBindAttribute.call(this,s,e),await dt.resolveEventAttributes.call(this,s,e),await dt.resolveTextNodeExpressions.call(this,s,e),await dt.resolveCustomAttribute.call(this,s,e),await dt.resolveCustomProperty.call(this,s,e),await dt.stripTypes.call(this,s,e);return t}async mount(t,e){e={...e,rootNode:t},Q(t,"renderer",this),this._store.set("$rootNode",t),this.has("$rootRenderer")||this._store.set("$rootRenderer",this),this.get("$rootRenderer")===this&&await Mt(this),await this.preprocessNode(t,e),await this.renderNode(t,e)}}const Gt=[":data",":for",":text",":html",":show",":class",":bind",":on:click",":on:click.prevent",":on:input",":on:input.prevent",":on:change",":on:change.prevent",":on:submit",":on:submit.prevent",":attr:src",":attr:href",":attr:title",":prop:checked",":prop:selected",":prop:disabled"],Kt=[...Gt.map(t=>(t=>`data-${t.slice(1).replace(":","-")}`)(t)),"data-testid"];class Ht extends Ft{impl="safe_browser";dirpath=ht(globalThis.location?.href??"http://localhost/");parseHTML(t,e={rootDocument:!1}){for(const e of Gt)t=t.replace(new RegExp(`\\s:${e.slice(1)}=`,"g"),` data-${e.slice(1).replace(":","-")}=`);t=(t=(t=t.replace(/<include(.*) src="([^"]+)"(.*)><\/include>/g,'<link $1 rel="subresource" href="$2" $3>')).replace(/<template is="([^"]+)">([\s\S]*)<\/template>/g,'<div role="template" alt="$1">$2</div>')).replace(/<(\w+)-(\w+)(.*)>([\s\S]*)<\/(\w+)-(\w+)>/g,'<div role="$1-$2" $3>$4</div>');const s=(new F).allowDataAttributes(Kt).allowClassAttributes().allowStyleAttributes().build();if(this.log("parseHTML",t),this.log("sanitized",String(s.sanitize(t))),e.rootDocument){return K(new DOMParser,s.sanitize(t),"text/html")}return s.sanitizeToFragment(t)}serializeHTML(t){return(new XMLSerializer).serializeToString(t).replace(/\s?xmlns="[^"]+"/gm,"")}preprocessLocal(t,e){return this.preprocessRemote(t,e)}createElement(t,e){return(e||document).createElement(t)}textContent(t,e){t.textContent=e}}const Wt=new Ht;export{Wt as Mancha,Ht as Renderer};
|
package/dist/safe_browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe_browser.js","sourceRoot":"","sources":["../src/safe_browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"safe_browser.js","sourceRoot":"","sources":["../src/safe_browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE7E,MAAM,OAAO,QAAS,SAAQ,SAAS;IAC5B,IAAI,GAAG,cAAc,CAAC;IACZ,OAAO,GAAW,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,IAAI,mBAAmB,CAAC,CAAC;IAC/F,SAAS,CACP,OAAe,EACf,SAAuB,EAAE,YAAY,EAAE,KAAK,EAAE;QAE9C,kFAAkF;QAClF,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;YACnC,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EACxC,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAC5C,CAAC;QACJ,CAAC;QAED,kFAAkF;QAClF,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,6CAA6C,EAC7C,0CAA0C,CAC3C,CAAC;QAEF,yEAAyE;QACzE,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,+CAA+C,EAC/C,wCAAwC,CACzC,CAAC;QAEF,kEAAkE;QAClE,OAAO,GAAG,OAAO,CAAC,OAAO,CACvB,4CAA4C,EAC5C,+BAA+B,CAChC,CAAC;QAEF,+DAA+D;QAC/D,wBAAwB;QACxB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE;aACzC,mBAAmB,CAAC,iBAAiB,CAAC;aACtC,oBAAoB,EAAE;aACtB,oBAAoB,EAAE;aACtB,KAAK,EAAE,CAAC;QAEX,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC3D,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxB,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC/B,OAAO,aAAa,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC;QACzF,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IACD,aAAa,CAAC,IAA6B;QACzC,OAAO,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,eAAe,CACb,KAAa,EACb,MAAoC;QAEpC,6EAA6E;QAC7E,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IACD,aAAa,CAAC,GAAW,EAAE,KAAuB;QAChD,OAAO,CAAC,KAAK,IAAI,QAAQ,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;IACD,WAAW,CAAC,IAAU,EAAE,OAAe;QACrC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC"}
|