mancha 0.14.4 → 0.15.0
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/.github/workflows/ci.yml +74 -13
- package/dist/browser.js +1 -1
- package/dist/css_gen_utils.js +20 -1
- package/dist/css_gen_utils.js.map +1 -1
- package/dist/mancha.js +1 -1
- package/dist/plugins.js +11 -7
- package/dist/plugins.js.map +1 -1
- package/dist/safe_browser.js +1 -1
- package/dist/safe_browser.js.map +1 -1
- package/docs/quickstart.md +119 -0
- package/package.json +2 -2
package/dist/safe_browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={};function e(t){0}class i{constructor(t,e){this.privateDoNotAccessOrElseWrappedAttributePrefix=e}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const s=i;function r(t){if(function(t){return t instanceof i}(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 i=e[0].toLowerCase();return new s(t,i)}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,i){e(),this.privateDoNotAccessOrElseWrappedHtml=t}toString(){return this.privateDoNotAccessOrElseWrappedHtml.toString()}}function d(e,i){return null!=i?i:new u(e,t)}"undefined"!=typeof window&&window.TrustedHTML;function p(t){var e;const i=t;return d(i,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(i))}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 i=(new XMLSerializer).serializeToString(e);return i=i.slice(i.indexOf(">")+1,i.lastIndexOf("</")),p(i)}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 i=e.createRange();i.selectNode(e.body);return function(t,e){return t.createContextualFragment(f(e))}(i,p(t))}function A(t){const e=t.nodeName;return"string"==typeof e?e:"FORM"}function y(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,i,s,r){this.allowedElements=t,this.elementPolicies=e,this.allowedGlobalAttributes=i,this.globalAttributePolicies=s,this.globallyAllowedAttributePrefixes=r}isAllowedElement(t){return"FORM"!==t&&(this.allowedElements.has(t)||this.elementPolicies.has(t))}getAttributePolicy(t,e){const i=this.elementPolicies.get(e);if(null==i?void 0:i.has(t))return i.get(t);if(this.allowedGlobalAttributes.has(t))return{policyAction:O.KEEP};const s=this.globalAttributePolicies.get(t);return s||(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,i,s,r,n){this.sanitizerTable=t,this.styleElementSanitizer=s,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 i=g(t,e),s=document.createTreeWalker(i,5,(t=>this.nodeFilter(t)));let r=s.nextNode();const n=e.createDocumentFragment();let a=n;for(;null!==r;){let t;if(y(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=s.firstChild(),r)a=t;else for(;!(r=s.nextSibling())&&(r=s.parentNode());)a=a.parentNode}return n}createTextNode(t){return document.createTextNode(t)}sanitizeTextNode(t){return this.createTextNode(t.data)}sanitizeElementNode(t,e){const i=A(t),s=e.createElement(i),r=t.attributes;for(const{name:t,value:e}of r){const n=this.sanitizerTable.getAttributePolicy(t,i);if(this.satisfiesAllConditions(n.conditions,r))switch(n.policyAction){case O.KEEP:z(s,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(s,t,r);break;case O.KEEP_AND_NORMALIZE:z(s,t,e.toLowerCase());break;case O.KEEP_AND_SANITIZE_STYLE:if(this.styleAttributeSanitizer){z(s,t,this.styleAttributeSanitizer(e))}else z(s,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:i},n=N(e),a=this.resourceUrlPolicy(n,r);a&&z(s,t,a.toString())}else z(s,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:i},n=$(e),a={parts:[]};for(const t of n.parts){const e=N(t.url),i=this.resourceUrlPolicy(e,r);i&&a.parts.push({url:i.toString(),descriptor:t.descriptor})}z(s,t,M(a))}else z(s,t,e);break;case O.DROP:this.recordChange(`Attribute: ${t} was dropped`)}else this.recordChange(`Not all conditions satisfied for attribute: ${t}.`)}return s}nodeFilter(t){if(y(t))return 1;if(!T(t))return 2;const e=A(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 i;if(!t)return!0;for(const[s,r]of t){const t=null===(i=e.getNamedItem(s))||void 0===i?void 0:i.value;if(t&&!r.has(t))return!1}return!0}}function z(t,e,i){t.setAttribute(e,i)}function $(t){const e=[];for(const i of t.split(",")){const[t,s]=i.trim().split(/\s+/,2);e.push({url:t,descriptor:s})}return{parts:e}}function M(t){return t.parts.map((t=>{const{url:e,descriptor:i}=t;return`${e}${i?` ${i}`:""}`})).join(" , ")}class F{constructor(){this.calledBuild=!1,this.sanitizerTable=D}onlyAllowElements(t){const e=new Set,i=new Map;for(let s of t){if(s=s.toUpperCase(),!this.sanitizerTable.isAllowedElement(s))throw new Error(`Element: ${s}, is not allowed by html5_contract.textpb`);const t=this.sanitizerTable.elementPolicies.get(s);void 0!==t?i.set(s,t):e.add(s)}return this.sanitizerTable=new P(e,i,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}allowCustomElement(t,e){const i=new Set(this.sanitizerTable.allowedElements),s=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 i=new Map;for(const t of e)i.set(t,{policyAction:O.KEEP});s.set(t,i)}else i.add(t);return this.sanitizerTable=new P(i,s,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}onlyAllowAttributes(t){const e=new Set,i=new Map,s=new Map;for(const s of t)this.sanitizerTable.allowedGlobalAttributes.has(s)&&e.add(s),this.sanitizerTable.globalAttributePolicies.has(s)&&i.set(s,this.sanitizerTable.globalAttributePolicies.get(s));for(const[e,i]of this.sanitizerTable.elementPolicies.entries()){const r=new Map;for(const[e,s]of i.entries())t.has(e)&&r.set(e,s);s.set(e,r)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,s,e,i),this}allowDataAttributes(t){const e=new Set(this.sanitizerTable.allowedGlobalAttributes);for(const i of t){if(0!==i.indexOf("data-"))throw new Error(`data attribute: ${i} does not begin with the prefix "data-"`);e.add(i)}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,i,s){if(0===t.length){throw new Error("")}const n=t.map((t=>r(t))),a=i.toLowerCase();if(n.every((t=>0!==a.indexOf(t))))throw new Error(`Attribute "${i}" does not match any of the allowed prefixes.`);e.setAttribute(i,s)}function K(t,e,i){return t.parseFromString(f(e),i)}Error;const H=[o`:`,o`style`,o`class`];function*W(t,e=new Set){const i=new Set,s=Array.from(t.childNodes).filter((t=>!e.has(t)));for(yield t;s.length;){const t=s.shift();i.has(t)||(i.add(t),yield t),t.childNodes&&Array.from(t.childNodes).filter((t=>!e.has(t))).forEach((t=>s.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,i=""){return Z(t,i+e)||(t.dataset?.[V(e)]??null)}function q(t,e,i=""){return function(t,e){return Y(t,"attribs")?e in(t.attribs||{}):t.hasAttribute?.(e)??!1}(t,i+e)||Y(t.dataset,V(e))}function X(t,e,i){Y(t,"attribs")?t.attribs[e]=i:t.setAttribute?.(e,i)}function Q(t,e,i){Y(t,"attribs")?t.attribs[e]=i:G(H,t,e,i)}function J(t,e,i){switch(e){case"disabled":return void(t.disabled=i);case"selected":return void(t.selected=i);case"checked":return void(t.checked=i);default:t[e]=i}}function tt(t,e){Y(t,"attribs")?delete t.attribs[e]:t.removeAttribute?.(e)}function et(t,e,i=""){tt(t,`${i}${e}`),tt(t,`data-${e}`)}function it(t,e,i){if(Y(t,"attribs")&&Y(e,"attribs"))e.attribs[i]=t.attribs[i];else if(i.startsWith("data-")){const s=V(i.slice(5));e.dataset[s]=t.dataset?.[s]}else{const s=t?.getAttribute?.(i);Q(e,i,s||"")}}function st(t){if(Y(t,"firstElementChild"))return t.firstElementChild;return Array.from(t.children).find((t=>1===t.nodeType))}function rt(t,...e){if(B(t,"replaceWith"))return t.replaceWith(...e);{const i=t,s=i.parentNode,r=Array.from(s.childNodes).indexOf(i);e.forEach((t=>t.parentNode=s)),s.childNodes=[].concat(Array.from(s.childNodes).slice(0,r)).concat(e).concat(Array.from(s.childNodes).slice(r+1))}}function nt(t,...e){B(t,"replaceChildren")?t.replaceChildren(...e):(t.childNodes=e,e.forEach((e=>e.parentNode=t)))}function at(t,e){return B(e,"appendChild")?t.appendChild(e):(t.childNodes.push(e),e.parentNode=t,e)}function ot(t,e){return B(e,"removeChild")?t.removeChild(e):(nt(t,...Array.from(t.childNodes).filter((t=>t!==e))),e)}function lt(t,e,i){return i?B(t,"insertBefore")?t.insertBefore(e,i):(rt(i,e,i),e):at(t,e)}function ct(t,e=0){return t?t.length<=e?t:t.slice(0,e-1)+"…":""}function ht(t,e=0){return globalThis.DocumentFragment&&t instanceof DocumentFragment?Array.from(t.childNodes).map((t=>ht(t,e))).join(""):ct(t.outerHTML||t.nodeValue||String(t),e)}function ut(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):""}class dt{iterable;constructor(t){this.iterable=t}filter(t){return new dt(dt.filterGenerator(t,this.iterable))}map(t){return new dt(dt.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 i of e)t(i)&&(yield i)}static*mapGenerator(t,e){for(const i of e)yield t(i)}static equals(t,e){const i=t[Symbol.iterator](),s=e[Symbol.iterator]();let r=i.next(),n=s.next();for(;!r.done&&!n.done;){if(r.value!==n.value)return!1;r=i.next(),n=s.next()}return r.done===n.done}}var pt;!function(t){t.resolveIncludes=async function(t,e){const i=t,s=i.tagName?.toLowerCase();if(!["include","link"].includes(s))return;if("link"===s&&"subresource"!==Z(i,"rel"))return;this.log("include directive found in:\n",ht(t,128)),this.log("include params:",e);const r="link"===i.tagName.toLocaleLowerCase()?"href":"src",n=Z(i,r);if(!n)throw new Error(`"${r}" attribute missing from ${ht(t,128)}.`);const a=[];"include"===s&&a.push("src"),"link"===s&&a.push("rel","href");const o=e=>{const s=st(e);for(const t of Array.from(i.attributes))s&&!a.includes(t.name)&&it(i,s,t.name);rt(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 i=t,s=i.tagName?.toLowerCase();if(!e?.dirpath)return;const r=Z(i,"src"),n=Z(i,"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(i,"attribs")?Q(i,r?"src":"href",l):"img"===s?i.src=l:"a"===s?function(t,e){const i=v(e);void 0!==i&&(t.href=i)}(i,l):"source"===s||"audio"===s||"video"===s||"track"===s||"input"===s?i.src=l:"area"===s?function(t,e){const i=v(e);void 0!==i&&(t.href=i)}(i,l):this.log("Unable to rebase relative path for element:",s)},t.registerCustomElements=async function(t,e){const i=t,s=i.tagName?.toLowerCase(),r=(Z(i,"is")||Z(i,"alt"))?.toLowerCase();if(["template","div"].includes(s)&&r){if("div"===s&&"template"!==Z(i,"role"))return;this._customElements.has(r)||(this.log(`Registering custom element: ${r}\n`,ht(i,128)),this._customElements.set(r,i),ot(i.parentNode,i))}},t.resolveCustomElements=async function(t,e){const i=t,s=i.tagName?.toLowerCase();let r=s;if("div"===r&&(r=Z(i,"role")?.toLowerCase()||r),r&&this._customElements.has(r)){this.log(`Processing custom element: ${r}\n`,ht(i,128));const e=this._customElements.get(r),n=(e.content||e).cloneNode(!0),a=st(n);if(a)for(const t of Array.from(i.attributes))"div"===s&&"role"===t.name||it(i,a,t.name);const o=new dt(W(n)).find((t=>"slot"===t.tagName?.toLowerCase()));o&&rt(o,...i.childNodes),rt(t,...n.childNodes)}},t.resolveTextNodeExpressions=async function(t,e){const i=t.nodeValue||"";if(3!==t.nodeType||!i?.trim())return;this.log("Processing node content value:\n",ct(i,128));const s=new RegExp(/{{ ([^}]+) }}/gm),r=Array.from(i.matchAll(s)).map((t=>t[1]));return this.effect((function(){let e=i;for(const i of r){const s=this.eval(i,{$elem:t});e=e.replace(`{{ ${i} }}`,String(s))}t.nodeValue=e}))},t.resolveDataAttribute=async function(t,e){if(this._skipNodes.has(t))return;const i=t,s=j(i,"data",":");if(s){this.log(":data attribute found in:\n",ht(t,128)),et(i,"data",":");const r=e?.rootNode===t?this:this.subrenderer();t.renderer=r;const n=r.eval(s,{$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 i=t,s=j(i,"class",":");if(s){this.log(":class attribute found in:\n",ht(t,128)),et(i,"class",":");const e=Z(i,"class")||"";return this.effect((function(){const r=this.eval(s,{$elem:t});Q(i,"class",(r?`${e} ${r}`:e).trim())}))}},t.resolveTextAttributes=async function(t,e){if(this._skipNodes.has(t))return;const i=t,s=j(i,"text",":");if(s){this.log(":text attribute found in:\n",ht(t,128)),et(i,"text",":");const e=e=>this.textContent(t,e);return this.effect((function(){e(this.eval(s,{$elem:t}))}))}},t.resolveHtmlAttribute=async function(t,e){if(this._skipNodes.has(t))return;const i=t,s=j(i,"html",":");return s?(this.log(":html attribute found in:\n",ht(t,128)),et(i,"html",":"),this.effect((function(){const r=this.eval(s,{$elem:t});return new Promise((async t=>{const s=await this.preprocessString(r,e);await this.renderNode(s),nt(i,s),t()}))}))):void 0},t.resolveEventAttributes=async function(t,e){if(this._skipNodes.has(t))return;const i=t;for(const e of Array.from(i.attributes||[]))if(e.name.startsWith(":on:")||e.name.startsWith("data-on-")){const s=e.name.split(":on:",2).at(-1)?.split("data-on-",2).at(-1)||"";if(!s)throw new Error(`Invalid event attribute: ${e.name}`);this.log(e.name,"attribute found in:\n",ht(t,128));const r=q(i,"prevent",":");et(i,e.name),et(i,"prevent",":");const n="submit"===s&&"FORM"===i.tagName.toUpperCase();t.addEventListener?.(s,(i=>((r||n)&&i.preventDefault(),this.eval(e.value,{$elem:t,$event:i}))))}},t.resolveForAttribute=async function(t,e){if(this._skipNodes.has(t))return;const i=t,s=j(i,"for",":")?.trim();if(s){this.log(":for attribute found in:\n",ht(t,128)),et(i,"for",":");for(const e of W(t,this._skipNodes))this._skipNodes.add(e);const r=Z(i,"style")||"";X(i,"style","display: none;");const n=t.parentNode,a=this.createElement("template",t.ownerDocument);lt(n,a,t),ot(n,t),at(a,t),this.log(":for template:\n",ht(a,128));const o=s.split(" in ",2);if(2!==o.length)throw new Error(`Invalid :for format: \`${s}\`. Expected "{key} in {expression}".`);const l=[],[c,h]=o;await this.effect((function(){const i=this.eval(h,{$elem:t});if(this.log(":for list items:",i),l.splice(0,l.length).forEach((t=>{ot(n,t),this._skipNodes.delete(t)})),!Array.isArray(i))return console.error(`Expression did not yield a list: \`${h}\` => \`${i}\``),Promise.resolve();const s=[];for(const n of i){const i=this.subrenderer();i._store.set(c,n);const a=t.cloneNode(!0);X(a,"style",r),l.push(a),this._skipNodes.add(a),s.push(i.mount(a,e)),this.log("Rendered list child:\n",ht(a,128))}const o=a.nextSibling;for(const t of l)lt(n,t,o);return Promise.all(s)}))}},t.resolveBindAttribute=async function(t,e){if(this._skipNodes.has(t))return;const i=t,s=j(i,"bind",":");if(s){this.log(":bind attribute found in:\n",ht(t,128));const e=["change","input"],r=Z(i,":bind:on")?.split(",")||i.dataset?.bindOn?.split(",")||e;et(i,"bind",":"),tt(i,":bind:on"),tt(i,"data-bind-on");const n="checkbox"===Z(i,"type")?"checked":"value";s.includes(".")||this.has(s)||this.set(s,""),this.effect((function(){const e=this.eval(s,{$elem:t});"checked"===n?i.checked=!!e:i.value=e}));const a=`${s} = $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 i=t,s=j(i,"show",":");if(s){this.log(":show attribute found in:\n",ht(t,128)),et(i,"show",":");const e="none"===i.style?.display?"":i.style?.display??Z(i,"style")?.split(";")?.find((t=>"display"===t.split(":")[0]))?.split(":")?.at(1)?.trim();this.effect((function(){const r=this.eval(s,{$elem:t});i.style?i.style.display=r?e:"none":Q(i,"style",`display: ${r?e:"none"};`)}))}},t.resolveCustomAttribute=async function(t,e){if(this._skipNodes.has(t))return;const i=t;for(const e of Array.from(i.attributes||[])){const s=":attr:",r="data-attr-";if(e.name.startsWith(s)||e.name.startsWith(r)){this.log(e.name,"attribute found in:\n",ht(t,128)),tt(i,e.name);const n=e.name.split(s,2).at(-1)?.split(r,2).at(-1);this.effect((function(){const s=this.eval(e.value,{$elem:t});X(i,n,s)}))}}},t.resolveCustomProperty=async function(t,e){if(this._skipNodes.has(t))return;const i=t;for(const e of Array.from(i.attributes||[])){const s=":prop:",r="data-prop-";if(e.name.startsWith(s)||e.name.startsWith(r)){this.log(e.name,"property found in:\n",ht(t,128)),tt(i,e.name);const n=e.name.split(s,2).at(-1)?.split(r,2).at(-1),a=V(n);this.effect((function(){const s=this.eval(e.value,{$elem:t});J(i,a,s)}))}}}}(pt||(pt={}));const ft=["this"],_t=["+","-","!"],mt=["=","+","-","*","/","%","^","==","!=",">","<",">=","<=","||","&&","??","&","===","!==","|","|>"],Et={"!":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},wt=["==","!=","<=",">=","||","&&","??","|>"],vt=["===","!=="];var bt;!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"}(bt||(bt={}));const gt=(t,e,i=0)=>({kind:t,value:e,precedence:i}),At=t=>95===t||36===t||65<=(t&=-33)&&t<=90,yt=t=>48<=t&&t<=57;class Tt{_input;_index=-1;_tokenStart=0;_next;constructor(t){this._input=t,this._advance()}nextToken(){for(;9===(t=this._next)||10===t||13===t||32===t;)this._advance(!0);var t;if((t=>34===t||39===t)(this._next))return this._tokenizeString();if(At(this._next))return this._tokenizeIdentOrKeyword();if(yt(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 i=gt(bt.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(),i}_tokenizeIdentOrKeyword(){do{this._advance()}while(t=this._next,At(t)||yt(t));var t;const e=this._getValue(),i=(s=e,-1!==ft.indexOf(s)?bt.KEYWORD:bt.IDENTIFIER);var s;return gt(i,e)}_tokenizeNumber(){do{this._advance()}while(yt(this._next));return 46===this._next?this._tokenizeDot():gt(bt.INTEGER,this._getValue())}_tokenizeDot(){return this._advance(),yt(this._next)?this._tokenizeFraction():(this._clearValue(),gt(bt.DOT,".",13))}_tokenizeComma(){return this._advance(!0),gt(bt.COMMA,",")}_tokenizeColon(){return this._advance(!0),gt(bt.COLON,":")}_tokenizeFraction(){do{this._advance()}while(yt(this._next));return gt(bt.DECIMAL,this._getValue())}_tokenizeOperator(){this._advance();let t=this._getValue(2);if(-1!==vt.indexOf(t))this._advance(),this._advance();else{if(t=this._getValue(1),"=>"===t)return this._advance(),gt(bt.ARROW,t);-1!==wt.indexOf(t)&&this._advance()}return t=this._getValue(),gt(bt.OPERATOR,t,Et[t])}_tokenizeGrouper(){const t=String.fromCharCode(this._next),e=gt(bt.GROUPER,t,Et[t]);return this._advance(!0),e}}class Rt{_kind;_tokenizer;_ast;_token;_value;constructor(t,e){this._tokenizer=new Tt(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 i=this._tokenizer.nextToken();this._token=i,this._kind=i?.kind,this._value=i?.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(bt.GROUPER,"(")){const e=this._parseArguments();t=this._ast.invoke(t,void 0,e)}else if(this._matches(bt.GROUPER,"[")){const e=this._parseIndex();t=this._ast.index(t,e)}else if(this._matches(bt.DOT)){this._advance();const e=this._parseUnary();t=this._makeInvokeOrGetter(t,e)}else{if(this._matches(bt.KEYWORD))break;if(!(this._matches(bt.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 i=e.receiver;return this._ast.invoke(t,i.value,e.arguments)}throw new Error(`expected identifier: ${e}`)}_parseBinary(t,e){if(-1===mt.indexOf(e.value))throw new Error(`unknown operator: ${e.value}`);this._advance();let i=this._parseUnary();for(;(this._kind===bt.OPERATOR||this._kind===bt.DOT||this._kind===bt.GROUPER)&&this._token.precedence>e.precedence;)i=this._parsePrecedence(i,this._token.precedence);return this._ast.binary(t,e.value,i)}_parseUnary(){if(this._matches(bt.OPERATOR)){const t=this._value;if(this._advance(),"+"===t||"-"===t){if(this._matches(bt.INTEGER))return this._parseInteger(t);if(this._matches(bt.DECIMAL))return this._parseDecimal(t)}if(-1===_t.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(bt.OPERATOR,"?");const e=this._parseExpression();this._advance(bt.COLON);const i=this._parseExpression();return this._ast.ternary(t,e,i)}_parsePrimary(){switch(this._kind){case bt.KEYWORD:const t=this._value;if("this"===t)return this._advance(),this._ast.id(t);if(-1!==ft.indexOf(t))throw new Error(`unexpected keyword: ${t}`);throw new Error(`unrecognized keyword: ${t}`);case bt.IDENTIFIER:return this._parseInvokeOrIdentifier();case bt.STRING:return this._parseString();case bt.INTEGER:return this._parseInteger();case bt.DECIMAL:return this._parseDecimal();case bt.GROUPER:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case bt.COLON:throw new Error('unexpected token ":"');default:return}}_parseList(){const t=[];do{if(this._advance(),this._matches(bt.GROUPER,"]"))break;t.push(this._parseExpression())}while(this._matches(bt.COMMA));return this._advance(bt.GROUPER,"]"),this._ast.list(t)}_parseMap(){const t={};do{if(this._advance(),this._matches(bt.GROUPER,"}"))break;const e=this._value;(this._matches(bt.STRING)||this._matches(bt.IDENTIFIER))&&this._advance(),this._advance(bt.COLON),t[e]=this._parseExpression()}while(this._matches(bt.COMMA));return this._advance(bt.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(),i=this._parseArguments();return i?this._ast.invoke(e,void 0,i):e}_parseIdentifier(){if(!this._matches(bt.IDENTIFIER))throw new Error(`expected identifier: ${this._value}`);const t=this._value;return this._advance(),this._ast.id(t)}_parseArguments(){if(!this._matches(bt.GROUPER,"("))return;const t=[];do{if(this._advance(),this._matches(bt.GROUPER,")"))break;const e=this._parseExpression();t.push(e)}while(this._matches(bt.COMMA));return this._advance(bt.GROUPER,")"),t}_parseIndex(){this._advance();const t=this._parseExpression();return this._advance(bt.GROUPER,"]"),t}_parseParenOrFunction(){const t=this._parseArguments();if(this._matches(bt.ARROW)){this._advance();const e=this._parseExpression(),i=t?.map((t=>t.value))??[];return this._ast.arrowFunction(i,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 Ot={"+":(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)},Nt={"+":t=>t,"-":t=>-t,"!":t=>!t};class It{timeouts=new Map;debounce(t,e){return new Promise(((i,s)=>{const r=this.timeouts.get(e);r&&clearTimeout(r),this.timeouts.set(e,setTimeout((()=>{try{i(e()),this.timeouts.delete(e)}catch(t){s(t)}}),t))}))}}const Pt=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 i=Nt[t];return{type:"Unary",operator:t,child:e,evaluate(t){return i(this.child.evaluate(t))},getIds(t){return this.child.getIds(t)}}}binary(t,e,i){const s=Ot[e];return{type:"Binary",operator:e,left:t,right:i,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 i,s;return"Getter"===this.left.type?(i=this.left.receiver.evaluate(t),s=this.left.name):"Index"===this.left.type?(i=this.left.receiver.evaluate(t),s=this.left.argument.evaluate(t)):"ID"===this.left.type&&(i=t,s=this.left.value),void 0===i?void 0:i[s]=e}return s(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,i){if(null!=e&&"string"!=typeof e)throw new Error("method not a string");return{type:"Invoke",receiver:t,method:e,arguments:i,evaluate(t){const i=this.receiver.evaluate(t),s=this.method?i:t?.this??t,r=this.method?i?.[e]:i,n=(this.arguments??[]).map((e=>e?.evaluate(t)));return r?.apply?.(s,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,i){return{type:"Ternary",condition:t,trueExpr:e,falseExpr:i,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 i={};if(t&&this.entries)for(const s in t){const t=this.entries[s];t&&(i[s]=t.evaluate(e))}return i},getIds(e){if(t&&this.entries)for(const i in t){const t=this.entries[i];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,i=this.body;return function(...s){const r=Object.fromEntries(e.map(((t,e)=>[t,s[e]]))),n=new Proxy(t??{},{set:(t,e,i)=>(r.hasOwnProperty(e)&&(r[e]=i),t[e]=i),get:(t,e)=>r.hasOwnProperty(e)?r[e]:t[e]});return i.evaluate(n)}},getIds(t){return this.body.getIds(t).filter((t=>!this.params.includes(t)))}}}};function St(t,e){const i=t?._store;return i?.has(e)?i.get(e):i?.has("$parent")?St(i.get("$parent"),e):null}function xt(t,e){const i=t?._store;return i?.has(e)?t:i?.has("$parent")?xt(i.get("$parent"),e):null}class Ct extends It{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,i]of Object.entries(t||{}))this.set(e,i)}wrapFunction(t){return(...e)=>t.call(this.$,...e)}wrapObject(t,e){return null==t||((i=t)instanceof Ct||i.__is_proxy__)||t.constructor!==Object&&!Array.isArray(t)?t:new Proxy(t,{deleteProperty:(t,i)=>i in t&&(delete t[i],e(),!0),set:(i,s,r,n)=>{"object"==typeof r&&null!=t&&(r=this.wrapObject(r,e));const a=Reflect.set(i,s,r,n);return e(),a},get:(t,e,i)=>"__is_proxy__"===e||Reflect.get(t,e,i)});var i}watch(t,e){const i=xt(this,t);if(!i)throw new Error(`Cannot watch key "${t}" as it does not exist in the store.`);i.observers.has(t)||i.observers.set(t,new Set),i.observers.get(t)?.has(e)||i.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 i=xt(this,t),s=Array.from(i?.observers.get(t)||[]);await this.debounce(e,(()=>Promise.all(s.map((t=>t.call(this.proxify(t)))))))}get(t,e){return e&&this.watch(t,e),St(this,t)}async set(t,e){if(e===this._store.get(t))return;const i=()=>this.notify(t);e&&"function"==typeof e&&(e=this.wrapFunction(e)),e&&"object"==typeof e&&(e=this.wrapObject(e,i)),function(t,e,i){const s=xt(t,e);s?s._store.set(e,i):t._store.set(e,i)}(this,t,e);for(const[i,s]of this.keyHandlers.entries())if(i.test(t))for(const i of s)await Promise.resolve(i.call(this.$,t,e));await i()}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)),i=Object.fromEntries(e.map((t=>[t,null])));return new Proxy(i,{get:(e,i,s)=>"string"==typeof i&&xt(this,i)?this.get(i,t):"$"===i?this.proxify(t):Reflect.get(this,i,s),set:(t,e,i,s)=>("string"!=typeof e||e in this?Reflect.set(this,e,i,s):this.set(e,i),!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[i,s]=t.split(" = ");e=i.trim(),t=s.trim()}return(i,s)=>{const r=((t,e)=>new Rt(t,e).parse())(t,Pt),n=r?.getIds([])?.map((t=>[t,s[t]??i[t]??globalThis[t]])),a=r?.evaluate(Object.fromEntries(n||[]));if(!e)return a;!function(t,e,i){const s=e.split(".");for(let e=0;e<s.length-1;e++)s[e]in t||(t[s[e]]={}),t=t[s[e]];t[s[s.length-1]]=i}(i,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 i=this._observer?this:this.$;if(this._store.has(t))return i[t];{const s=this.cachedExpressionFunction(t);try{return s(i,e)}catch(e){return console.error(`Failed to evaluate expression: ${t}`),console.error(e),null}}}}const Lt="$$",kt="http://localhost/";function Dt(){return new URL(globalThis.window?.location?.href||kt)}function Ut(t){return`${Lt}${t}`}function zt(t){return t.keys().filter((t=>t.startsWith(Lt)))}function $t(t,e,i){const s=function(t){return t.substring(Lt.length)}(e);let r=!1;if(i){const e=String(i);t.searchParams.get(s)!==e&&(t.searchParams.set(s,e),r=!0)}else t.searchParams.has(s)&&(t.searchParams.delete(s),r=!0);return r}async function Mt(t){const e=Dt();await async function(t,e){for(const[i,s]of e.searchParams.entries()){const e=Ut(i);t.get(e)!==s&&await t.set(e,s)}}(t,e),function(t,e){let i=!1;for(const s of zt(e))$t(t,s,e.get(s))&&(i=!0);i&&globalThis.window?.history?.replaceState({},"",t.toString())}(e,t),t.addKeyHandler(new RegExp("^\\$\\$"),((t,e)=>{const i=Dt();$t(i,t,e)&&globalThis.window?.history?.replaceState({},"",i.toString())})),globalThis.window?.addEventListener("popstate",function(t){return async()=>{const e=Dt(),i=new Set;for(const[s,r]of e.searchParams.entries()){const e=Ut(s);i.add(e),t.get(e)!==r&&t.set(e,r)}const s=zt(t);for(const e of s)i.has(e)||t.del(e)}}(t))}class Ft extends Ct{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 i=this.parseHTML(t,e);return await this.preprocessNode(i,e),i}async preprocessRemote(t,e){const i={};e?.cache&&(i.cache=e.cache);const s=await fetch(t,i).then((t=>t.text()));return this.preprocessString(s,{...e,dirpath:ut(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}async preprocessLocal(t,e){const i=await this.fetchLocal(t,e);return this.preprocessString(i,{...e,dirpath:ut(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 i=new dt(W(t,this._skipNodes)).map((async t=>{this.log("Preprocessing node:\n",ht(t,128)),await pt.resolveIncludes.call(this,t,e),await pt.rebaseRelativePaths.call(this,t,e),await pt.registerCustomElements.call(this,t,e),await pt.resolveCustomElements.call(this,t,e)}));return await Promise.all(i.generator()),t}async renderNode(t,e){for(const i of W(t,this._skipNodes))this.log("Rendering node:\n",ht(i,128)),await pt.resolveForAttribute.call(this,i,e),await pt.resolveDataAttribute.call(this,i,e),await pt.resolveTextAttributes.call(this,i,e),await pt.resolveHtmlAttribute.call(this,i,e),await pt.resolveShowAttribute.call(this,i,e),await pt.resolveClassAttribute.call(this,i,e),await pt.resolveBindAttribute.call(this,i,e),await pt.resolveEventAttributes.call(this,i,e),await pt.resolveTextNodeExpressions.call(this,i,e),await pt.resolveCustomAttribute.call(this,i,e),await pt.resolveCustomProperty.call(this,i,e);return t}async mount(t,e){e={...e,rootNode:t},J(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:input",":on:change",":on:submit",":attr:src",":attr:href",":attr:title",":prop:checked",":prop:selected",":prop:disabled"];class Kt extends Ft{impl="safe_browser";dirpath=ut(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 i=Gt.map((t=>`data-${t.slice(1).replace(":","-")}`));i.push("data-testid");const s=(new F).allowDataAttributes(i).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 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 A(t){const e=t.nodeName;return"string"==typeof e?e:"FORM"}function y(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(y(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=A(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(y(t))return 1;if(!T(t))return 2;const e=A(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)})}}}}(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,At=t=>95===t||36===t||65<=(t&=-33)&&t<=90,yt=t=>At(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(At(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(yt(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);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};
|
package/dist/safe_browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe_browser.js","sourceRoot":"","sources":["../src/safe_browser.ts"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"safe_browser.js","sourceRoot":"","sources":["../src/safe_browser.ts"],"names":[],"mappings":"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"}
|
package/docs/quickstart.md
CHANGED
|
@@ -132,6 +132,56 @@ the `<script>` tag that imports `Mancha`, and explicitly call the `mount()` func
|
|
|
132
132
|
</script>
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
## Reusable Components
|
|
136
|
+
|
|
137
|
+
`mancha` supports custom components, which can be defined using the template tag:
|
|
138
|
+
|
|
139
|
+
```html
|
|
140
|
+
<!-- Use <template is="my-component-name"> to register a component. -->
|
|
141
|
+
<template is="my-red-button">
|
|
142
|
+
<button style="background-color: red;">
|
|
143
|
+
<slot></slot>
|
|
144
|
+
</button>
|
|
145
|
+
</template>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The components can live in their own, separate files. A common pattern is to separate each component into their own file, and import them all in a single "roll-up" file. For example, your files might look like this:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
src/
|
|
152
|
+
├─ components/
|
|
153
|
+
| ├─ footer.tpl.html
|
|
154
|
+
| ├─ my-red-button.tpl.html
|
|
155
|
+
| ├─ my-custom-component.tpl.html
|
|
156
|
+
├─ index.html
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Instead of importing the components individually, you could create a single file `registry.tpl.html` which imports all the custom components:
|
|
160
|
+
|
|
161
|
+
```html
|
|
162
|
+
<!-- src/components/registry.tpl.html -->
|
|
163
|
+
<include src="./my-red-button.tpl.html" />
|
|
164
|
+
<include src="./my-custom-component.tpl.html" />
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Then in `index.html`:
|
|
168
|
+
|
|
169
|
+
```html
|
|
170
|
+
<!-- src/index.html -->
|
|
171
|
+
<head>
|
|
172
|
+
<!-- ... -->
|
|
173
|
+
</head>
|
|
174
|
+
<body>
|
|
175
|
+
<!-- Include the custom component definition before using any of the components -->
|
|
176
|
+
<include src="components/registry.tpl.html" />
|
|
177
|
+
|
|
178
|
+
<!-- Now you can use any of the custom components -->
|
|
179
|
+
<my-red-button>Click Me!</my-red-button>
|
|
180
|
+
|
|
181
|
+
<!-- Any other components can also use the custom components, and don't need to re-import them -->
|
|
182
|
+
<include src="components/footer.tpl.html"/>
|
|
183
|
+
```
|
|
184
|
+
|
|
135
185
|
## URL Query Parameter Binding
|
|
136
186
|
|
|
137
187
|
`mancha` makes it easy to synchronize your application's state with the URL query parameters. This is particularly useful for maintaining state across page reloads or for creating shareable links.
|
|
@@ -160,3 +210,72 @@ Here's how you can use it:
|
|
|
160
210
|
```
|
|
161
211
|
|
|
162
212
|
In this example, the input field is bound to `$$search`. As you type, the URL will be updated with a `search` query parameter (e.g., `?search=your-text`). If you reload the page with the query parameter in the URL, the input field will be automatically populated with the value from the URL.
|
|
213
|
+
|
|
214
|
+
## Testing
|
|
215
|
+
|
|
216
|
+
`mancha`'s architecture makes it easy to test your application's UI without having to run a full browser environment. You can use a library like `JSDOM` to simulate a browser environment in Node.js and then use mancha to render your components and make assertions about the output.
|
|
217
|
+
|
|
218
|
+
Here's an example of how you can test a simple component:
|
|
219
|
+
|
|
220
|
+
```html
|
|
221
|
+
<!-- my-component.html -->
|
|
222
|
+
<body>
|
|
223
|
+
<button data-testid="login-button" :show="!user">Login</button>
|
|
224
|
+
<button data-testid="logout-button" :show="user">Logout</button>
|
|
225
|
+
</body>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
// test.js
|
|
230
|
+
import { test, describe, before } from "node:test";
|
|
231
|
+
import assert from "node:assert";
|
|
232
|
+
import * as fs from "node:fs/promises";
|
|
233
|
+
import * as path from "node:path";
|
|
234
|
+
import { Renderer } from "mancha";
|
|
235
|
+
|
|
236
|
+
const componentPath = path.join(import.meta.dirname, "my-component.html");
|
|
237
|
+
const findByTestId = (node, testId) => node.querySelector(`[data-testid="${testId}"]`);
|
|
238
|
+
|
|
239
|
+
describe("My Component", () => {
|
|
240
|
+
|
|
241
|
+
test("renders correctly when logged out", async () => {
|
|
242
|
+
// 1. Initialize the renderer with the desired state for this test case.
|
|
243
|
+
const renderer = new Renderer({ user: null });
|
|
244
|
+
|
|
245
|
+
// 2. Create a clean DOM fragment from the page content.
|
|
246
|
+
const fragment = await renderer.preprocessLocal(componentPath);
|
|
247
|
+
|
|
248
|
+
// 3. Mount the renderer to the fragment to apply data bindings.
|
|
249
|
+
await renderer.mount(fragment);
|
|
250
|
+
|
|
251
|
+
// 4. Find elements and assert their state.
|
|
252
|
+
const loginButton = findByTestId(fragment, "login-button");
|
|
253
|
+
const logoutButton = findByTestId(fragment, "logout-button");
|
|
254
|
+
|
|
255
|
+
assert.ok(loginButton, "Login button should exist");
|
|
256
|
+
assert.ok(logoutButton, "Logout button should exist");
|
|
257
|
+
|
|
258
|
+
assert.strictEqual(loginButton.style.display, "", "Login button should be visible");
|
|
259
|
+
assert.strictEqual(logoutButton.style.display, "none", "Logout button should be hidden");
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test("renders correctly when logged in", async () => {
|
|
263
|
+
// 1. Initialize the renderer with the desired state for this test case.
|
|
264
|
+
const renderer = new Renderer({ user: { name: "John Doe" } });
|
|
265
|
+
|
|
266
|
+
// 2. Create a clean DOM fragment from the page content.
|
|
267
|
+
const fragment = await renderer.preprocessLocal(componentPath);
|
|
268
|
+
|
|
269
|
+
// 3. Mount the renderer to the fragment to apply data bindings.
|
|
270
|
+
await renderer.mount(fragment);
|
|
271
|
+
|
|
272
|
+
// 4. Find elements and assert their state.
|
|
273
|
+
const loginButton = findByTestId(fragment, "login-button");
|
|
274
|
+
const logoutButton = findByTestId(fragment, "logout-button");
|
|
275
|
+
|
|
276
|
+
assert.strictEqual(loginButton.style.display, "none", "Login button should be hidden");
|
|
277
|
+
assert.strictEqual(logoutButton.style.display, "", "Logout button should be visible");
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
package/package.json
CHANGED