mancha 0.15.0 → 0.16.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/README.md +9 -2
- package/dist/browser.js +1 -1
- package/dist/cli.js +102 -13
- package/dist/cli.js.map +1 -1
- package/dist/mancha.js +1 -1
- package/dist/plugins.js +10 -0
- package/dist/plugins.js.map +1 -1
- package/dist/renderer.js +2 -0
- package/dist/renderer.js.map +1 -1
- package/dist/safe_browser.js +1 -1
- package/dist/test_types/api.d.ts +11 -0
- package/dist/test_types/api.js +3 -0
- package/dist/test_types/api.js.map +1 -0
- package/dist/test_types/product.d.ts +11 -0
- package/dist/test_types/product.js +3 -0
- package/dist/test_types/product.js.map +1 -0
- package/dist/test_types/user.d.ts +10 -0
- package/dist/test_types/user.js +3 -0
- package/dist/test_types/user.js.map +1 -0
- package/dist/type_checker.d.ts +5 -0
- package/dist/type_checker.js +281 -0
- package/dist/type_checker.js.map +1 -0
- package/docs/quickstart.md +281 -2
- package/package.json +10 -8
package/dist/safe_browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={};function e(t){0}class s{constructor(t,e){this.privateDoNotAccessOrElseWrappedAttributePrefix=e}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const i=s;function r(t){if(function(t){return t instanceof s}(t))return t.privateDoNotAccessOrElseWrappedAttributePrefix;throw new Error("")}function n(t){return Object.isFrozen(t)&&Object.isFrozen(t.raw)}function a(t){return-1===t.toString().indexOf("`")}a(t=>t``)||a(t=>t`\0`)||a(t=>t`\n`)||a(t=>t`\u0000`),n``&&n`\0`&&n`\n`&&n`\u0000`;function o(e){const s=e[0].toLowerCase();return new i(t,s)}let l,c="google#safe";function h(){var t;return""!==c&&null!==(t=function(){if("undefined"!=typeof window)return window.trustedTypes}())&&void 0!==t?t:null}class u{constructor(t,s){e(),this.privateDoNotAccessOrElseWrappedHtml=t}toString(){return this.privateDoNotAccessOrElseWrappedHtml.toString()}}function d(e,s){return null!=s?s:new u(e,t)}"undefined"!=typeof window&&window.TrustedHTML;function p(t){var e;const s=t;return d(s,null===(e=function(){var t,e;if(void 0===l)try{l=null!==(e=null===(t=h())||void 0===t?void 0:t.createPolicy(c,{createHTML:t=>t,createScript:t=>t,createScriptURL:t=>t}))&&void 0!==e?e:null}catch(t){l=null}return l}())||void 0===e?void 0:e.createHTML(s))}function f(t){var e;if(null===(e=h())||void 0===e?void 0:e.isHTML(t))return t;if(t instanceof u)return t.privateDoNotAccessOrElseWrappedHtml;throw new Error("")}"undefined"!=typeof window&&window.TrustedScriptURL;"undefined"!=typeof window&&window.TrustedScript;function _(t,e){e.appendChild(t);let s=(new XMLSerializer).serializeToString(e);return s=s.slice(s.indexOf(">")+1,s.lastIndexOf("</")),p(s)}const m=["data:","http:","https:","mailto:","ftp:"],E=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function w(t){if(!function(t){const e=!E.test(t);return e}(t))return t}function v(t){return w(t)}function b(t){const e=function(t){let e;try{e=new URL(t)}catch(t){return"https:"}return e.protocol}(t);return void 0!==e&&-1!==m.indexOf(e.toLowerCase())?t:"about:invalid#zClosurez"}function g(t,e){const s=e.createRange();s.selectNode(e.body);return function(t,e){return t.createContextualFragment(f(e))}(s,p(t))}function 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};
|
|
1
|
+
const t={};function e(t){0}class s{constructor(t,e){this.privateDoNotAccessOrElseWrappedAttributePrefix=e}toString(){return this.privateDoNotAccessOrElseWrappedAttributePrefix}}const i=s;function r(t){if(function(t){return t instanceof s}(t))return t.privateDoNotAccessOrElseWrappedAttributePrefix;throw new Error("")}function n(t){return Object.isFrozen(t)&&Object.isFrozen(t.raw)}function a(t){return-1===t.toString().indexOf("`")}a(t=>t``)||a(t=>t`\0`)||a(t=>t`\n`)||a(t=>t`\u0000`),n``&&n`\0`&&n`\n`&&n`\u0000`;function o(e){const s=e[0].toLowerCase();return new i(t,s)}let l,c="google#safe";function h(){var t;return""!==c&&null!==(t=function(){if("undefined"!=typeof window)return window.trustedTypes}())&&void 0!==t?t:null}class u{constructor(t,s){e(),this.privateDoNotAccessOrElseWrappedHtml=t}toString(){return this.privateDoNotAccessOrElseWrappedHtml.toString()}}function d(e,s){return null!=s?s:new u(e,t)}"undefined"!=typeof window&&window.TrustedHTML;function p(t){var e;const s=t;return d(s,null===(e=function(){var t,e;if(void 0===l)try{l=null!==(e=null===(t=h())||void 0===t?void 0:t.createPolicy(c,{createHTML:t=>t,createScript:t=>t,createScriptURL:t=>t}))&&void 0!==e?e:null}catch(t){l=null}return l}())||void 0===e?void 0:e.createHTML(s))}function f(t){var e;if(null===(e=h())||void 0===e?void 0:e.isHTML(t))return t;if(t instanceof u)return t.privateDoNotAccessOrElseWrappedHtml;throw new Error("")}"undefined"!=typeof window&&window.TrustedScriptURL;"undefined"!=typeof window&&window.TrustedScript;function _(t,e){e.appendChild(t);let s=(new XMLSerializer).serializeToString(e);return s=s.slice(s.indexOf(">")+1,s.lastIndexOf("</")),p(s)}const m=["data:","http:","https:","mailto:","ftp:"],E=/^\s*(?!javascript:)(?:[\w+.-]+:|[^:/?#]*(?:[/?#]|$))/i;function w(t){if(!function(t){const e=!E.test(t);return e}(t))return t}function v(t){return w(t)}function b(t){const e=function(t){let e;try{e=new URL(t)}catch(t){return"https:"}return e.protocol}(t);return void 0!==e&&-1!==m.indexOf(e.toLowerCase())?t:"about:invalid#zClosurez"}function g(t,e){const s=e.createRange();s.selectNode(e.body);return function(t,e){return t.createContextualFragment(f(e))}(s,p(t))}function y(t){const e=t.nodeName;return"string"==typeof e?e:"FORM"}function A(t){return 3===t.nodeType}function T(t){const e=t.nodeType;return 1===e||"number"!=typeof e}var R,O;function N(t){try{return new URL(t,window.document.baseURI)}catch(t){return new URL("about:invalid")}}function I(t){return{valueOf:t}.valueOf()}!function(t){t[t.STYLE_TAG=0]="STYLE_TAG",t[t.STYLE_ATTRIBUTE=1]="STYLE_ATTRIBUTE",t[t.HTML_ATTRIBUTE=2]="HTML_ATTRIBUTE"}(R||(R={}));class P{constructor(t,e,s,i,r){this.allowedElements=t,this.elementPolicies=e,this.allowedGlobalAttributes=s,this.globalAttributePolicies=i,this.globallyAllowedAttributePrefixes=r}isAllowedElement(t){return"FORM"!==t&&(this.allowedElements.has(t)||this.elementPolicies.has(t))}getAttributePolicy(t,e){const s=this.elementPolicies.get(e);if(null==s?void 0:s.has(t))return s.get(t);if(this.allowedGlobalAttributes.has(t))return{policyAction:O.KEEP};const i=this.globalAttributePolicies.get(t);return i||(this.globallyAllowedAttributePrefixes&&[...this.globallyAllowedAttributePrefixes].some(e=>0===t.indexOf(e))?{policyAction:O.KEEP}:{policyAction:O.DROP})}}!function(t){t[t.DROP=0]="DROP",t[t.KEEP=1]="KEEP",t[t.KEEP_AND_SANITIZE_URL=2]="KEEP_AND_SANITIZE_URL",t[t.KEEP_AND_NORMALIZE=3]="KEEP_AND_NORMALIZE",t[t.KEEP_AND_SANITIZE_STYLE=4]="KEEP_AND_SANITIZE_STYLE",t[t.KEEP_AND_USE_RESOURCE_URL_POLICY=5]="KEEP_AND_USE_RESOURCE_URL_POLICY",t[t.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET=6]="KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET"}(O||(O={}));const S=new Set(["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"]);const x=["ARTICLE","SECTION","NAV","ASIDE","H1","H2","H3","H4","H5","H6","HEADER","FOOTER","ADDRESS","P","HR","PRE","BLOCKQUOTE","OL","UL","LH","LI","DL","DT","DD","FIGURE","FIGCAPTION","MAIN","DIV","EM","STRONG","SMALL","S","CITE","Q","DFN","ABBR","RUBY","RB","RT","RTC","RP","DATA","TIME","CODE","VAR","SAMP","KBD","SUB","SUP","I","B","U","MARK","BDI","BDO","SPAN","BR","WBR","INS","DEL","PICTURE","PARAM","TRACK","MAP","TABLE","CAPTION","COLGROUP","COL","TBODY","THEAD","TFOOT","TR","TD","TH","SELECT","DATALIST","OPTGROUP","OPTION","OUTPUT","PROGRESS","METER","FIELDSET","LEGEND","DETAILS","SUMMARY","MENU","DIALOG","SLOT","CANVAS","FONT","CENTER","ACRONYM","BASEFONT","BIG","DIR","HGROUP","STRIKE","TT"],C=[["A",new Map([["href",{policyAction:O.KEEP_AND_SANITIZE_URL}]])],["AREA",new Map([["href",{policyAction:O.KEEP_AND_SANITIZE_URL}]])],["LINK",new Map([["href",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY,conditions:new Map([["rel",new Set(["alternate","author","bookmark","canonical","cite","help","icon","license","next","prefetch","dns-prefetch","prerender","preconnect","preload","prev","search","subresource"])]])}]])],["SOURCE",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["IMG",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}],["srcset",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET}]])],["VIDEO",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}]])],["AUDIO",new Map([["src",{policyAction:O.KEEP_AND_USE_RESOURCE_URL_POLICY}]])]],L=["title","aria-atomic","aria-autocomplete","aria-busy","aria-checked","aria-current","aria-disabled","aria-dropeffect","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-live","aria-multiline","aria-multiselectable","aria-orientation","aria-posinset","aria-pressed","aria-readonly","aria-relevant","aria-required","aria-selected","aria-setsize","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","alt","align","autocapitalize","autocomplete","autocorrect","autofocus","autoplay","bgcolor","border","cellpadding","cellspacing","checked","color","cols","colspan","controls","datetime","disabled","download","draggable","enctype","face","formenctype","frameborder","height","hreflang","hidden","ismap","label","lang","loop","max","maxlength","media","minlength","min","multiple","muted","nonce","open","placeholder","preload","rel","required","reversed","role","rows","rowspan","selected","shape","size","sizes","slot","span","spellcheck","start","step","summary","translate","type","valign","value","width","wrap","itemscope","itemtype","itemid","itemprop","itemref"],k=[["dir",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["dir",new Set(["auto","ltr","rtl"])]]))}],["async",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["async",new Set(["async"])]]))}],["cite",{policyAction:O.KEEP_AND_SANITIZE_URL}],["loading",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["loading",new Set(["eager","lazy"])]]))}],["poster",{policyAction:O.KEEP_AND_SANITIZE_URL}],["target",{policyAction:O.KEEP_AND_NORMALIZE,conditions:I(()=>new Map([["target",new Set(["_self","_blank"])]]))}]],D=new P(new Set(x),new Map(C),new Set(L),new Map(k));new P(new Set(I(()=>x.concat(["STYLE"]))),new Map(C),new Set(I(()=>L.concat(["id","name","class"]))),new Map(I(()=>k.concat([["style",{policyAction:O.KEEP_AND_SANITIZE_STYLE}]]))));class U{constructor(t,s,i,r,n){this.sanitizerTable=t,this.styleElementSanitizer=i,this.styleAttributeSanitizer=r,this.resourceUrlPolicy=n,this.changes=[],e()}sanitizeAssertUnchanged(t){return this.sanitize(t)}sanitize(t){const e=document.implementation.createHTMLDocument("");return _(this.sanitizeToFragmentInternal(t,e),e.body)}sanitizeToFragment(t){const e=document.implementation.createHTMLDocument("");return this.sanitizeToFragmentInternal(t,e)}sanitizeToFragmentInternal(t,e){const s=g(t,e),i=document.createTreeWalker(s,5,t=>this.nodeFilter(t));let r=i.nextNode();const n=e.createDocumentFragment();let a=n;for(;null!==r;){let t;if(A(r))if(this.styleElementSanitizer&&"STYLE"===a.nodeName){const e=this.styleElementSanitizer(r.data);t=this.createTextNode(e)}else t=this.sanitizeTextNode(r);else{if(!T(r)){throw new Error("")}t=this.sanitizeElementNode(r,e)}if(a.appendChild(t),r=i.firstChild(),r)a=t;else for(;!(r=i.nextSibling())&&(r=i.parentNode());)a=a.parentNode}return n}createTextNode(t){return document.createTextNode(t)}sanitizeTextNode(t){return this.createTextNode(t.data)}sanitizeElementNode(t,e){const s=y(t),i=e.createElement(s),r=t.attributes;for(const{name:t,value:e}of r){const n=this.sanitizerTable.getAttributePolicy(t,s);if(this.satisfiesAllConditions(n.conditions,r))switch(n.policyAction){case O.KEEP:z(i,t,e);break;case O.KEEP_AND_SANITIZE_URL:const r=b(e);r!==e&&this.recordChange(`Url in attribute ${t} was modified during sanitization. Original url:"${e}" was sanitized to: "${r}"`),z(i,t,r);break;case O.KEEP_AND_NORMALIZE:z(i,t,e.toLowerCase());break;case O.KEEP_AND_SANITIZE_STYLE:if(this.styleAttributeSanitizer){z(i,t,this.styleAttributeSanitizer(e))}else z(i,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:s},n=N(e),a=this.resourceUrlPolicy(n,r);a&&z(i,t,a.toString())}else z(i,t,e);break;case O.KEEP_AND_USE_RESOURCE_URL_POLICY_FOR_SRCSET:if(this.resourceUrlPolicy){const r={type:R.HTML_ATTRIBUTE,attributeName:t,tagName:s},n=$(e),a={parts:[]};for(const t of n.parts){const e=N(t.url),s=this.resourceUrlPolicy(e,r);s&&a.parts.push({url:s.toString(),descriptor:t.descriptor})}z(i,t,M(a))}else z(i,t,e);break;case O.DROP:this.recordChange(`Attribute: ${t} was dropped`)}else this.recordChange(`Not all conditions satisfied for attribute: ${t}.`)}return i}nodeFilter(t){if(A(t))return 1;if(!T(t))return 2;const e=y(t);return null===e?(this.recordChange(`Node name was null for node: ${t}`),2):this.sanitizerTable.isAllowedElement(e)?1:(this.recordChange(`Element: ${e} was dropped`),2)}recordChange(t){0}satisfiesAllConditions(t,e){var s;if(!t)return!0;for(const[i,r]of t){const t=null===(s=e.getNamedItem(i))||void 0===s?void 0:s.value;if(t&&!r.has(t))return!1}return!0}}function z(t,e,s){t.setAttribute(e,s)}function $(t){const e=[];for(const s of t.split(",")){const[t,i]=s.trim().split(/\s+/,2);e.push({url:t,descriptor:i})}return{parts:e}}function M(t){return t.parts.map(t=>{const{url:e,descriptor:s}=t;return`${e}${s?` ${s}`:""}`}).join(" , ")}class F{constructor(){this.calledBuild=!1,this.sanitizerTable=D}onlyAllowElements(t){const e=new Set,s=new Map;for(let i of t){if(i=i.toUpperCase(),!this.sanitizerTable.isAllowedElement(i))throw new Error(`Element: ${i}, is not allowed by html5_contract.textpb`);const t=this.sanitizerTable.elementPolicies.get(i);void 0!==t?s.set(i,t):e.add(i)}return this.sanitizerTable=new P(e,s,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}allowCustomElement(t,e){const s=new Set(this.sanitizerTable.allowedElements),i=new Map(this.sanitizerTable.elementPolicies);if(t=t.toUpperCase(),r=t,S.has(r.toUpperCase())||!/^[a-z][-_.a-z0-9]*-[-_.a-z0-9]*$/i.test(r))throw new Error(`Element: ${t} is not a custom element`);var r;if(e){const s=new Map;for(const t of e)s.set(t,{policyAction:O.KEEP});i.set(t,s)}else s.add(t);return this.sanitizerTable=new P(s,i,this.sanitizerTable.allowedGlobalAttributes,this.sanitizerTable.globalAttributePolicies),this}onlyAllowAttributes(t){const e=new Set,s=new Map,i=new Map;for(const i of t)this.sanitizerTable.allowedGlobalAttributes.has(i)&&e.add(i),this.sanitizerTable.globalAttributePolicies.has(i)&&s.set(i,this.sanitizerTable.globalAttributePolicies.get(i));for(const[e,s]of this.sanitizerTable.elementPolicies.entries()){const r=new Map;for(const[e,i]of s.entries())t.has(e)&&r.set(e,i);i.set(e,r)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,i,e,s),this}allowDataAttributes(t){const e=new Set(this.sanitizerTable.allowedGlobalAttributes);for(const s of t){if(0!==s.indexOf("data-"))throw new Error(`data attribute: ${s} does not begin with the prefix "data-"`);e.add(s)}return this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,e,this.sanitizerTable.globalAttributePolicies),this}allowStyleAttributes(){const t=new Map(this.sanitizerTable.globalAttributePolicies);return t.set("style",{policyAction:O.KEEP_AND_SANITIZE_STYLE}),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,this.sanitizerTable.allowedGlobalAttributes,t),this}allowClassAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("class"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}allowIdAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("id"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}allowIdReferenceAttributes(){const t=new Set(this.sanitizerTable.allowedGlobalAttributes);return t.add("aria-activedescendant").add("aria-controls").add("aria-labelledby").add("aria-owns").add("for").add("list"),this.sanitizerTable=new P(this.sanitizerTable.allowedElements,this.sanitizerTable.elementPolicies,t,this.sanitizerTable.globalAttributePolicies),this}withResourceUrlPolicy(t){return this.resourceUrlPolicy=t,this}build(){if(this.calledBuild)throw new Error("this sanitizer has already called build");return this.calledBuild=!0,new U(this.sanitizerTable,t,void 0,void 0,this.resourceUrlPolicy)}}function G(t,e,s,i){if(0===t.length){throw new Error("")}const n=t.map(t=>r(t)),a=s.toLowerCase();if(n.every(t=>0!==a.indexOf(t)))throw new Error(`Attribute "${s}" does not match any of the allowed prefixes.`);e.setAttribute(s,i)}function K(t,e,s){return t.parseFromString(f(e),s)}Error;const H=[o`:`,o`style`,o`class`];function*W(t,e=new Set){const s=new Set,i=Array.from(t.childNodes).filter(t=>!e.has(t));for(yield t;i.length;){const t=i.shift();s.has(t)||(s.add(t),yield t),t.childNodes&&Array.from(t.childNodes).filter(t=>!e.has(t)).forEach(t=>i.push(t))}}function Y(t,e){return void 0!==t?.[e]}function B(t,e){return"function"==typeof t?.[e]}function V(t){return t.replace(/-./g,t=>t[1].toUpperCase())}function Z(t,e){return Y(t,"attribs")?t.attribs?.[e]??null:t.getAttribute?.(e)??null}function j(t,e,s=""){return Z(t,s+e)||(t.dataset?.[V(e)]??null)}function q(t,e,s){Y(t,"attribs")?t.attribs[e]=s:t.setAttribute?.(e,s)}function X(t,e,s){Y(t,"attribs")?t.attribs[e]=s:G(H,t,e,s)}function Q(t,e,s){switch(e){case"disabled":return void(t.disabled=s);case"selected":return void(t.selected=s);case"checked":return void(t.checked=s);default:t[e]=s}}function J(t,e){Y(t,"attribs")?delete t.attribs[e]:t.removeAttribute?.(e)}function tt(t,e,s=""){J(t,`${s}${e}`),J(t,`data-${e}`)}function et(t,e,s){if(Y(t,"attribs")&&Y(e,"attribs"))e.attribs[s]=t.attribs[s];else if(s.startsWith("data-")){const i=V(s.slice(5));e.dataset[i]=t.dataset?.[i]}else{const i=t?.getAttribute?.(s);X(e,s,i||"")}}function st(t){if(Y(t,"firstElementChild"))return t.firstElementChild;return Array.from(t.children).find(t=>1===t.nodeType)}function it(t,...e){if(B(t,"replaceWith"))return t.replaceWith(...e);{const s=t,i=s.parentNode,r=Array.from(i.childNodes).indexOf(s);e.forEach(t=>t.parentNode=i),i.childNodes=[].concat(Array.from(i.childNodes).slice(0,r)).concat(e).concat(Array.from(i.childNodes).slice(r+1))}}function rt(t,...e){B(t,"replaceChildren")?t.replaceChildren(...e):(t.childNodes=e,e.forEach(e=>e.parentNode=t))}function nt(t,e){return B(e,"appendChild")?t.appendChild(e):(t.childNodes.push(e),e.parentNode=t,e)}function at(t,e){return B(e,"removeChild")?t.removeChild(e):(rt(t,...Array.from(t.childNodes).filter(t=>t!==e)),e)}function ot(t,e,s){return s?B(t,"insertBefore")?t.insertBefore(e,s):(it(s,e,s),e):nt(t,e)}function lt(t,e=0){return t?t.length<=e?t:t.slice(0,e-1)+"…":""}function ct(t,e=0){return globalThis.DocumentFragment&&t instanceof DocumentFragment?Array.from(t.childNodes).map(t=>ct(t,e)).join(""):lt(t.outerHTML||t.nodeValue||String(t),e)}function ht(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):""}class ut{iterable;constructor(t){this.iterable=t}filter(t){return new ut(ut.filterGenerator(t,this.iterable))}map(t){return new ut(ut.mapGenerator(t,this.iterable))}find(t){for(const e of this.iterable)if(t(e))return e}array(){return Array.from(this.iterable)}*generator(){for(const t of this.iterable)yield t}static*filterGenerator(t,e){for(const s of e)t(s)&&(yield s)}static*mapGenerator(t,e){for(const s of e)yield t(s)}static equals(t,e){const s=t[Symbol.iterator](),i=e[Symbol.iterator]();let r=s.next(),n=i.next();for(;!r.done&&!n.done;){if(r.value!==n.value)return!1;r=s.next(),n=i.next()}return r.done===n.done}}var dt;!function(t){t.resolveIncludes=async function(t,e){const s=t,i=s.tagName?.toLowerCase();if(!["include","link"].includes(i))return;if("link"===i&&"subresource"!==Z(s,"rel"))return;this.log("include directive found in:\n",ct(t,128)),this.log("include params:",e);const r="link"===s.tagName.toLocaleLowerCase()?"href":"src",n=Z(s,r);if(!n)throw new Error(`"${r}" attribute missing from ${ct(t,128)}.`);const a=[];"include"===i&&a.push("src"),"link"===i&&a.push("rel","href");const o=e=>{const i=st(e);for(const t of Array.from(s.attributes))i&&!a.includes(t.name)&&et(s,i,t.name);it(t,...e.childNodes)},l={...e,rootDocument:!1,maxdepth:e?.maxdepth-1};if(0===l.maxdepth)throw new Error("Maximum recursion depth reached.");if(n.includes("://")||n.startsWith("//"))this.log("Including remote file from absolute path:",n),await this.preprocessRemote(n,l).then(o);else if(e?.dirpath?.includes("://")||e?.dirpath?.startsWith("//")){const t=n.startsWith("/")?n:`${e.dirpath}/${n}`;this.log("Including remote file from relative path:",t),await this.preprocessRemote(t,l).then(o)}else if("/"===n.charAt(0))this.log("Including local file from absolute path:",n),await this.preprocessLocal(n,l).then(o);else{const t=e?.dirpath&&"."!==e?.dirpath?`${e?.dirpath}/${n}`:n;this.log("Including local file from relative path:",t),await this.preprocessLocal(t,l).then(o)}},t.rebaseRelativePaths=async function(t,e){const s=t,i=s.tagName?.toLowerCase();if(!e?.dirpath)return;const r=Z(s,"src"),n=Z(s,"href"),a=r||n;if(!a||((o=a).includes("://")||o.startsWith("/")||o.startsWith("#")||o.startsWith("data:")))return;var o;const l=`${e.dirpath}/${a}`;this.log("Rebasing relative path as:",l),Y(s,"attribs")?X(s,r?"src":"href",l):"img"===i?s.src=l:"a"===i?function(t,e){const s=v(e);void 0!==s&&(t.href=s)}(s,l):"source"===i||"audio"===i||"video"===i||"track"===i||"input"===i?s.src=l:"area"===i?function(t,e){const s=v(e);void 0!==s&&(t.href=s)}(s,l):this.log("Unable to rebase relative path for element:",i)},t.registerCustomElements=async function(t,e){const s=t,i=s.tagName?.toLowerCase(),r=(Z(s,"is")||Z(s,"alt"))?.toLowerCase();if(["template","div"].includes(i)&&r){if("div"===i&&"template"!==Z(s,"role"))return;this._customElements.has(r)||(this.log(`Registering custom element: ${r}\n`,ct(s,128)),this._customElements.set(r,s),at(s.parentNode,s))}},t.resolveCustomElements=async function(t,e){const s=t,i=s.tagName?.toLowerCase();let r=i;if("div"===r&&(r=Z(s,"role")?.toLowerCase()||r),r&&this._customElements.has(r)){this.log(`Processing custom element: ${r}\n`,ct(s,128));const e=this._customElements.get(r),n=(e.content||e).cloneNode(!0),a=st(n);if(a)for(const t of Array.from(s.attributes))"div"===i&&"role"===t.name||et(s,a,t.name);const o=new ut(W(n)).find(t=>"slot"===t.tagName?.toLowerCase());o&&it(o,...s.childNodes),it(t,...n.childNodes)}},t.resolveTextNodeExpressions=async function(t,e){const s=t.nodeValue||"";if(3!==t.nodeType||!s?.trim())return;this.log("Processing node content value:\n",lt(s,128));const i=new RegExp(/{{ ([^}]+) }}/gm),r=Array.from(s.matchAll(i)).map(t=>t[1]);return this.effect(function(){let e=s;for(const s of r){const i=this.eval(s,{$elem:t});e=e.replace(`{{ ${s} }}`,String(i))}t.nodeValue=e})},t.resolveDataAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"data",":");if(i){this.log(":data attribute found in:\n",ct(t,128)),tt(s,"data",":");const r=e?.rootNode===t?this:this.subrenderer();t.renderer=r;const n=r.eval(i,{$elem:t});if(await Promise.all(Object.entries(n).map(([t,e])=>r._store.set(t,e))),r!==this)for(const e of W(t,this._skipNodes))this._skipNodes.add(e);await r.mount(t,e)}},t.resolveClassAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"class",":");if(i){this.log(":class attribute found in:\n",ct(t,128)),tt(s,"class",":");const e=Z(s,"class")||"";return this.effect(function(){const r=this.eval(i,{$elem:t});X(s,"class",(r?`${e} ${r}`:e).trim())})}},t.resolveTextAttributes=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"text",":");if(i){this.log(":text attribute found in:\n",ct(t,128)),tt(s,"text",":");const e=e=>this.textContent(t,e);return this.effect(function(){e(this.eval(i,{$elem:t}))})}},t.resolveHtmlAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"html",":");return i?(this.log(":html attribute found in:\n",ct(t,128)),tt(s,"html",":"),this.effect(function(){const r=this.eval(i,{$elem:t});return new Promise(async t=>{const i=await this.preprocessString(r,e);await this.renderNode(i),rt(s,i),t()})})):void 0},t.resolveEventAttributes=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[]))if(e.name.startsWith(":on:")||e.name.startsWith("data-on-")){let i="",r=[];if(e.name.startsWith(":on:")?[i,...r]=e.name.substring(4).split("."):e.name.startsWith("data-on-")&&([i,...r]=e.name.substring(8).split(".")),!i)throw new Error(`Invalid event attribute: ${e.name}`);this.log(e.name,"attribute found in:\n",ct(t,128)),tt(s,e.name);const n="submit"===i&&"FORM"===s.tagName.toUpperCase();t.addEventListener?.(i,s=>((r.includes("prevent")||n)&&s.preventDefault(),this.eval(e.value,{$elem:t,$event:s})))}},t.resolveForAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"for",":")?.trim();if(i){this.log(":for attribute found in:\n",ct(t,128)),tt(s,"for",":");for(const e of W(t,this._skipNodes))this._skipNodes.add(e);const r=Z(s,"style")||"";q(s,"style","display: none;");const n=t.parentNode,a=this.createElement("template",t.ownerDocument);ot(n,a,t),at(n,t),nt(a,t),this.log(":for template:\n",ct(a,128));const o=i.split(" in ",2);if(2!==o.length)throw new Error(`Invalid :for format: \`${i}\`. Expected "{key} in {expression}".`);const l=[],[c,h]=o;await this.effect(function(){const s=this.eval(h,{$elem:t});if(this.log(":for list items:",s),l.splice(0,l.length).forEach(t=>{at(n,t),this._skipNodes.delete(t)}),!Array.isArray(s))return console.error(`Expression did not yield a list: \`${h}\` => \`${s}\``),Promise.resolve();const i=[];for(const n of s){const s=this.subrenderer();s._store.set(c,n);const a=t.cloneNode(!0);q(a,"style",r),l.push(a),this._skipNodes.add(a),i.push(s.mount(a,e)),this.log("Rendered list child:\n",ct(a,128))}const o=a.nextSibling;for(const t of l)ot(n,t,o);return Promise.all(i)})}},t.resolveBindAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"bind",":");if(i){this.log(":bind attribute found in:\n",ct(t,128));const e=["change","input"],r=Z(s,":bind:on")?.split(",")||s.dataset?.bindOn?.split(",")||e;tt(s,"bind",":"),J(s,":bind:on"),J(s,"data-bind-on");const n="checkbox"===Z(s,"type")?"checked":"value";i.includes(".")||this.has(i)||this.set(i,""),this.effect(function(){const e=this.eval(i,{$elem:t});"checked"===n?s.checked=!!e:s.value=e});const a=`${i} = $elem.${n}`;for(const e of r)t.addEventListener(e,()=>this.eval(a,{$elem:t}))}},t.resolveShowAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t,i=j(s,"show",":");if(i){this.log(":show attribute found in:\n",ct(t,128)),tt(s,"show",":");const e="none"===s.style?.display?"":s.style?.display??Z(s,"style")?.split(";")?.find(t=>"display"===t.split(":")[0])?.split(":")?.at(1)?.trim();this.effect(function(){const r=this.eval(i,{$elem:t});s.style?s.style.display=r?e:"none":X(s,"style",`display: ${r?e:"none"};`)})}},t.resolveCustomAttribute=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[])){const i=":attr:",r="data-attr-";if(e.name.startsWith(i)||e.name.startsWith(r)){this.log(e.name,"attribute found in:\n",ct(t,128)),J(s,e.name);const n=e.name.split(i,2).at(-1)?.split(r,2).at(-1);this.effect(function(){const i=this.eval(e.value,{$elem:t});q(s,n,i)})}}},t.resolveCustomProperty=async function(t,e){if(this._skipNodes.has(t))return;const s=t;for(const e of Array.from(s.attributes||[])){const i=":prop:",r="data-prop-";if(e.name.startsWith(i)||e.name.startsWith(r)){this.log(e.name,"property found in:\n",ct(t,128)),J(s,e.name);const n=e.name.split(i,2).at(-1)?.split(r,2).at(-1),a=V(n);this.effect(function(){const i=this.eval(e.value,{$elem:t});Q(s,a,i)})}}},t.stripTypes=async function(t,e){const s=t;Z(s,":types")&&J(s,":types"),Z(s,"data-types")&&J(s,"data-types")}}(dt||(dt={}));const pt=["this"],ft=["+","-","!"],_t=["=","+","-","*","/","%","^","==","!=",">","<",">=","<=","||","&&","??","&","===","!==","|","|>"],mt={"!":0,":":0,",":0,")":0,"]":0,"}":0,"|>":1,"?":2,"??":3,"||":4,"&&":5,"|":6,"^":7,"&":8,"!=":9,"==":9,"!==":9,"===":9,">=":10,">":10,"<=":10,"<":10,"+":11,"-":11,"%":12,"/":12,"*":12,"(":13,"[":13,".":13,"{":13},Et=["==","!=","<=",">=","||","&&","??","|>"],wt=["===","!=="];var vt;!function(t){t[t.STRING=1]="STRING",t[t.IDENTIFIER=2]="IDENTIFIER",t[t.DOT=3]="DOT",t[t.COMMA=4]="COMMA",t[t.COLON=5]="COLON",t[t.INTEGER=6]="INTEGER",t[t.DECIMAL=7]="DECIMAL",t[t.OPERATOR=8]="OPERATOR",t[t.GROUPER=9]="GROUPER",t[t.KEYWORD=10]="KEYWORD",t[t.ARROW=11]="ARROW"}(vt||(vt={}));const bt=(t,e,s=0)=>({kind:t,value:e,precedence:s}),gt=t=>9===t||10===t||13===t||32===t,yt=t=>95===t||36===t||65<=(t&=-33)&&t<=90,At=t=>yt(t)||Tt(t),Tt=t=>48<=t&&t<=57;class Rt{_input;_index=-1;_tokenStart=0;_next;constructor(t){this._input=t,this._advance()}nextToken(){for(;gt(this._next);)this._advance(!0);if(34===(t=this._next)||39===t)return this._tokenizeString();var t;if(yt(this._next))return this._tokenizeIdentOrKeyword();if(Tt(this._next))return this._tokenizeNumber();if(46===this._next)return this._tokenizeDot();if(44===this._next)return this._tokenizeComma();if(58===this._next)return this._tokenizeColon();if((t=>43===t||45===t||42===t||47===t||33===t||38===t||37===t||60===t||61===t||62===t||63===t||94===t||124===t)(this._next))return this._tokenizeOperator();if((t=>40===t||41===t||91===t||93===t||123===t||125===t)(this._next))return this._tokenizeGrouper();if(this._advance(),void 0!==this._next)throw new Error(`Expected end of input, got ${this._next}`)}_advance(t){this._index++,this._index<this._input.length?(this._next=this._input.charCodeAt(this._index),!0===t&&(this._tokenStart=this._index)):this._next=void 0}_getValue(t=0){const e=this._input.substring(this._tokenStart,this._index+t);return 0===t&&this._clearValue(),e}_clearValue(){this._tokenStart=this._index}_tokenizeString(){const t="unterminated string",e=this._next;for(this._advance(!0);this._next!==e;){if(void 0===this._next)throw new Error(t);if(92===this._next&&(this._advance(),void 0===this._next))throw new Error(t);this._advance()}const s=bt(vt.STRING,this._getValue().replace(/\\(.)/g,(t,e)=>{switch(e){case"n":return"\n";case"r":return"\r";case"t":return"\t";case"b":return"\b";case"f":return"\f";default:return e}}));return this._advance(),s}_tokenizeIdentOrKeyword(){do{this._advance()}while(At(this._next));const t=this._getValue(),e=(s=t,-1!==pt.indexOf(s)?vt.KEYWORD:vt.IDENTIFIER);var s;return bt(e,t)}_tokenizeNumber(){do{this._advance()}while(Tt(this._next));return 46===this._next?this._tokenizeDot():bt(vt.INTEGER,this._getValue())}_tokenizeDot(){return this._advance(),Tt(this._next)?this._tokenizeFraction():(this._clearValue(),bt(vt.DOT,".",13))}_tokenizeComma(){return this._advance(!0),bt(vt.COMMA,",")}_tokenizeColon(){return this._advance(!0),bt(vt.COLON,":")}_tokenizeFraction(){do{this._advance()}while(Tt(this._next));return bt(vt.DECIMAL,this._getValue())}_tokenizeOperator(){this._advance();let t=this._getValue(2);if(-1!==wt.indexOf(t))this._advance(),this._advance();else{if(t=this._getValue(1),"=>"===t)return this._advance(),bt(vt.ARROW,t);-1!==Et.indexOf(t)&&this._advance()}return t=this._getValue(),bt(vt.OPERATOR,t,mt[t])}_tokenizeGrouper(){const t=String.fromCharCode(this._next),e=bt(vt.GROUPER,t,mt[t]);return this._advance(!0),e}}class Ot{_kind;_tokenizer;_ast;_token;_value;constructor(t,e){this._tokenizer=new Rt(t),this._ast=e}parse(){return this._advance(),this._parseExpression()}_advance(t,e){if(!this._matches(t,e))throw new Error(`Expected kind ${t} (${e}), was ${this._token?.kind} (${this._token?.value})`);const s=this._tokenizer.nextToken();this._token=s,this._kind=s?.kind,this._value=s?.value}_matches(t,e){return!(t&&this._kind!==t||e&&this._value!==e)}_parseExpression(){if(!this._token)return this._ast.empty();const t=this._parseUnary();return void 0===t?void 0:this._parsePrecedence(t,0)}_parsePrecedence(t,e){if(void 0===t)throw new Error("Expected left to be defined.");for(;this._token;)if(this._matches(vt.GROUPER,"(")){const e=this._parseArguments();t=this._ast.invoke(t,void 0,e)}else if(this._matches(vt.GROUPER,"[")){const e=this._parseIndex();t=this._ast.index(t,e)}else if(this._matches(vt.DOT)){this._advance();const e=this._parseUnary();t=this._makeInvokeOrGetter(t,e)}else{if(this._matches(vt.KEYWORD))break;if(!(this._matches(vt.OPERATOR)&&this._token.precedence>=e))break;t="?"===this._value?this._parseTernary(t):this._parseBinary(t,this._token)}return t}_makeInvokeOrGetter(t,e){if(void 0===e)throw new Error("expected identifier");if("ID"===e.type)return this._ast.getter(t,e.value);if("Invoke"===e.type&&"ID"===e.receiver.type){const s=e.receiver;return this._ast.invoke(t,s.value,e.arguments)}throw new Error(`expected identifier: ${e}`)}_parseBinary(t,e){if(-1===_t.indexOf(e.value))throw new Error(`unknown operator: ${e.value}`);this._advance();let s=this._parseUnary();for(;(this._kind===vt.OPERATOR||this._kind===vt.DOT||this._kind===vt.GROUPER)&&this._token.precedence>e.precedence;)s=this._parsePrecedence(s,this._token.precedence);return this._ast.binary(t,e.value,s)}_parseUnary(){if(this._matches(vt.OPERATOR)){const t=this._value;if(this._advance(),"+"===t||"-"===t){if(this._matches(vt.INTEGER))return this._parseInteger(t);if(this._matches(vt.DECIMAL))return this._parseDecimal(t)}if(-1===ft.indexOf(t))throw new Error(`unexpected token: ${t}`);const e=this._parsePrecedence(this._parsePrimary(),13);return this._ast.unary(t,e)}return this._parsePrimary()}_parseTernary(t){this._advance(vt.OPERATOR,"?");const e=this._parseExpression();this._advance(vt.COLON);const s=this._parseExpression();return this._ast.ternary(t,e,s)}_parsePrimary(){switch(this._kind){case vt.KEYWORD:const t=this._value;if("this"===t)return this._advance(),this._ast.id(t);if(-1!==pt.indexOf(t))throw new Error(`unexpected keyword: ${t}`);throw new Error(`unrecognized keyword: ${t}`);case vt.IDENTIFIER:return this._parseInvokeOrIdentifier();case vt.STRING:return this._parseString();case vt.INTEGER:return this._parseInteger();case vt.DECIMAL:return this._parseDecimal();case vt.GROUPER:return"("===this._value?this._parseParenOrFunction():"{"===this._value?this._parseMap():"["===this._value?this._parseList():void 0;case vt.COLON:throw new Error('unexpected token ":"');default:return}}_parseList(){const t=[];do{if(this._advance(),this._matches(vt.GROUPER,"]"))break;t.push(this._parseExpression())}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,"]"),this._ast.list(t)}_parseMap(){const t={};do{if(this._advance(),this._matches(vt.GROUPER,"}"))break;const e=this._value;(this._matches(vt.STRING)||this._matches(vt.IDENTIFIER))&&this._advance(),this._advance(vt.COLON),t[e]=this._parseExpression()}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,"}"),this._ast.map(t)}_parseInvokeOrIdentifier(){const t=this._value;if("true"===t)return this._advance(),this._ast.literal(!0);if("false"===t)return this._advance(),this._ast.literal(!1);if("null"===t)return this._advance(),this._ast.literal(null);if("undefined"===t)return this._advance(),this._ast.literal(void 0);const e=this._parseIdentifier(),s=this._parseArguments();return s?this._ast.invoke(e,void 0,s):e}_parseIdentifier(){if(!this._matches(vt.IDENTIFIER))throw new Error(`expected identifier: ${this._value}`);const t=this._value;return this._advance(),this._ast.id(t)}_parseArguments(){if(!this._matches(vt.GROUPER,"("))return;const t=[];do{if(this._advance(),this._matches(vt.GROUPER,")"))break;const e=this._parseExpression();t.push(e)}while(this._matches(vt.COMMA));return this._advance(vt.GROUPER,")"),t}_parseIndex(){this._advance();const t=this._parseExpression();return this._advance(vt.GROUPER,"]"),t}_parseParenOrFunction(){const t=this._parseArguments();if(this._matches(vt.ARROW)){this._advance();const e=this._parseExpression(),s=t?.map(t=>t.value)??[];return this._ast.arrowFunction(s,e)}return this._ast.paren(t[0])}_parseString(){const t=this._ast.literal(this._value);return this._advance(),t}_parseInteger(t=""){const e=this._ast.literal(parseInt(`${t}${this._value}`,10));return this._advance(),e}_parseDecimal(t=""){const e=this._ast.literal(parseFloat(`${t}${this._value}`));return this._advance(),e}}const Nt={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e,">":(t,e)=>t>e,">=":(t,e)=>t>=e,"<":(t,e)=>t<e,"<=":(t,e)=>t<=e,"||":(t,e)=>t||e,"&&":(t,e)=>t&&e,"??":(t,e)=>t??e,"|":(t,e)=>e(t),"|>":(t,e)=>e(t)},It={"+":t=>t,"-":t=>-t,"!":t=>!t};class Pt{timeouts=new Map;debounce(t,e){return new Promise((s,i)=>{const r=this.timeouts.get(e);r&&clearTimeout(r),this.timeouts.set(e,setTimeout(()=>{try{s(e()),this.timeouts.delete(e)}catch(t){i(t)}},t))})}}const St=new class{empty(){return{type:"Empty",evaluate:t=>t,getIds:t=>t}}literal(t){return{type:"Literal",value:t,evaluate(t){return this.value},getIds:t=>t}}id(t){return{type:"ID",value:t,evaluate(t){return"this"===this.value?t:t?.[this.value]},getIds(t){return t.push(this.value),t}}}unary(t,e){const s=It[t];return{type:"Unary",operator:t,child:e,evaluate(t){return s(this.child.evaluate(t))},getIds(t){return this.child.getIds(t)}}}binary(t,e,s){const i=Nt[e];return{type:"Binary",operator:e,left:t,right:s,evaluate(t){if("="===this.operator){if("ID"!==this.left.type&&"Getter"!==this.left.type&&"Index"!==this.left.type)throw new Error(`Invalid assignment target: ${this.left}`);const e=this.right.evaluate(t);let s,i;return"Getter"===this.left.type?(s=this.left.receiver.evaluate(t),i=this.left.name):"Index"===this.left.type?(s=this.left.receiver.evaluate(t),i=this.left.argument.evaluate(t)):"ID"===this.left.type&&(s=t,i=this.left.value),void 0===s?void 0:s[i]=e}return i(this.left.evaluate(t),this.right.evaluate(t))},getIds(t){return this.left.getIds(t),this.right.getIds(t),t}}}getter(t,e){return{type:"Getter",receiver:t,name:e,evaluate(t){return this.receiver.evaluate(t)?.[this.name]},getIds(t){return this.receiver.getIds(t),t}}}invoke(t,e,s){if(null!=e&&"string"!=typeof e)throw new Error("method not a string");return{type:"Invoke",receiver:t,method:e,arguments:s,evaluate(t){const s=this.receiver.evaluate(t),i=this.method?s:t?.this??t,r=this.method?s?.[e]:s,n=(this.arguments??[]).map(e=>e?.evaluate(t));return r?.apply?.(i,n)},getIds(t){return this.receiver.getIds(t),this.arguments?.forEach(e=>e?.getIds(t)),t}}}paren(t){return t}index(t,e){return{type:"Index",receiver:t,argument:e,evaluate(t){return this.receiver.evaluate(t)?.[this.argument.evaluate(t)]},getIds(t){return this.receiver.getIds(t),t}}}ternary(t,e,s){return{type:"Ternary",condition:t,trueExpr:e,falseExpr:s,evaluate(t){return this.condition.evaluate(t)?this.trueExpr.evaluate(t):this.falseExpr.evaluate(t)},getIds(t){return this.condition.getIds(t),this.trueExpr.getIds(t),this.falseExpr.getIds(t),t}}}map(t){return{type:"Map",entries:t,evaluate(e){const s={};if(t&&this.entries)for(const i in t){const t=this.entries[i];t&&(s[i]=t.evaluate(e))}return s},getIds(e){if(t&&this.entries)for(const s in t){const t=this.entries[s];t&&t.getIds(e)}return e}}}list(t){return{type:"List",items:t,evaluate(t){return this.items?.map(e=>e?.evaluate(t))},getIds(t){return this.items?.forEach(e=>e?.getIds(t)),t}}}arrowFunction(t,e){return{type:"ArrowFunction",params:t,body:e,evaluate(t){const e=this.params,s=this.body;return function(...i){const r=Object.fromEntries(e.map((t,e)=>[t,i[e]])),n=new Proxy(t??{},{set:(t,e,s)=>(r.hasOwnProperty(e)&&(r[e]=s),t[e]=s),get:(t,e)=>r.hasOwnProperty(e)?r[e]:t[e]});return s.evaluate(n)}},getIds(t){return this.body.getIds(t).filter(t=>!this.params.includes(t))}}}};function xt(t,e){const s=t?._store;return s?.has(e)?s.get(e):s?.has("$parent")?xt(s.get("$parent"),e):null}function Ct(t,e){const s=t?._store;return s?.has(e)?t:s?.has("$parent")?Ct(s.get("$parent"),e):null}class Lt extends Pt{evalkeys=["$elem","$event"];expressionCache=new Map;observers=new Map;keyHandlers=new Map;_observer=null;_store=new Map;_lock=Promise.resolve();constructor(t){super();for(let[e,s]of Object.entries(t||{}))this.set(e,s)}wrapFunction(t){return(...e)=>t.call(this.$,...e)}wrapObject(t,e){return null==t||((s=t)instanceof Lt||s.__is_proxy__)||t.constructor!==Object&&!Array.isArray(t)?t:new Proxy(t,{deleteProperty:(t,s)=>s in t&&(delete t[s],e(),!0),set:(s,i,r,n)=>{"object"==typeof r&&null!=t&&(r=this.wrapObject(r,e));const a=Reflect.set(s,i,r,n);return e(),a},get:(t,e,s)=>"__is_proxy__"===e||Reflect.get(t,e,s)});var s}watch(t,e){const s=Ct(this,t);if(!s)throw new Error(`Cannot watch key "${t}" as it does not exist in the store.`);s.observers.has(t)||s.observers.set(t,new Set),s.observers.get(t)?.has(e)||s.observers.get(t)?.add(e)}addKeyHandler(t,e){this.keyHandlers.has(t)||this.keyHandlers.set(t,new Set),this.keyHandlers.get(t).add(e)}async notify(t,e=10){const s=Ct(this,t),i=Array.from(s?.observers.get(t)||[]);await this.debounce(e,()=>Promise.all(i.map(t=>t.call(this.proxify(t)))))}get(t,e){return e&&this.watch(t,e),xt(this,t)}async set(t,e){if(e===this._store.get(t))return;const s=()=>this.notify(t);e&&"function"==typeof e&&(e=this.wrapFunction(e)),e&&"object"==typeof e&&(e=this.wrapObject(e,s)),function(t,e,s){const i=Ct(t,e);i?i._store.set(e,s):t._store.set(e,s)}(this,t,e);for(const[s,i]of this.keyHandlers.entries())if(s.test(t))for(const s of i)await Promise.resolve(s.call(this.$,t,e));await s()}async del(t){await this.set(t,null),this._store.delete(t),this.observers.delete(t)}keys(){return Array.from(this._store.keys())}has(t){return this._store.has(t)}effect(t){return t.call(this.proxify(t))}proxify(t){const e=Array.from(this._store.entries()).map(([t])=>t),s=Object.fromEntries(e.map(t=>[t,null]));return new Proxy(s,{get:(e,s,i)=>"string"==typeof s&&Ct(this,s)?this.get(s,t):"$"===s?this.proxify(t):Reflect.get(this,s,i),set:(t,e,s,i)=>("string"!=typeof e||e in this?Reflect.set(this,e,s,i):this.set(e,s),!0)})}get $(){return this.proxify()}makeEvalFunction(t){if(t.includes(";"))throw new Error("Complex expressions are not supported.");let e=null;if(t.includes(" = ")){const[s,i]=t.split(" = ");e=s.trim(),t=i.trim()}return(s,i)=>{const r=((t,e)=>new Ot(t,e).parse())(t,St),n=r?.getIds([])?.map(t=>[t,i[t]??s[t]??globalThis[t]]),a=r?.evaluate(Object.fromEntries(n||[]));if(!e)return a;!function(t,e,s){const i=e.split(".");for(let e=0;e<i.length-1;e++)i[e]in t||(t[i[e]]={}),t=t[i[e]];t[i[i.length-1]]=s}(s,e,a)}}cachedExpressionFunction(t){return t=t.trim(),this.expressionCache.has(t)||this.expressionCache.set(t,this.makeEvalFunction(t)),this.expressionCache.get(t)}eval(t,e={}){const s=this._observer?this:this.$;if(this._store.has(t))return s[t];{const i=this.cachedExpressionFunction(t);try{return i(s,e)}catch(e){return console.error(`Failed to evaluate expression: ${t}`),console.error(e),null}}}}const kt="$$";function Dt(){return new URL(globalThis.window?.location?.href||"http://localhost/")}function Ut(t){return`${kt}${t}`}function zt(t){return t.keys().filter(t=>t.startsWith(kt))}function $t(t,e,s){const i=function(t){return t.substring(2)}(e);let r=!1;if(s){const e=String(s);t.searchParams.get(i)!==e&&(t.searchParams.set(i,e),r=!0)}else t.searchParams.has(i)&&(t.searchParams.delete(i),r=!0);return r}async function Mt(t){const e=Dt();await async function(t,e){for(const[s,i]of e.searchParams.entries()){const e=Ut(s);t.get(e)!==i&&await t.set(e,i)}}(t,e),function(t,e){let s=!1;for(const i of zt(e))$t(t,i,e.get(i))&&(s=!0);s&&globalThis.window?.history?.replaceState({},"",t.toString())}(e,t),t.addKeyHandler(new RegExp("^\\$\\$"),(t,e)=>{const s=Dt();$t(s,t,e)&&globalThis.window?.history?.replaceState({},"",s.toString())}),globalThis.window?.addEventListener("popstate",function(t){return async()=>{const e=Dt(),s=new Set;for(const[i,r]of e.searchParams.entries()){const e=Ut(i);s.add(e),t.get(e)!==r&&t.set(e,r)}const i=zt(t);for(const e of i)s.has(e)||t.del(e)}}(t))}class Ft extends Lt{debugging=!1;dirpath="";_skipNodes=new Set;_customElements=new Map;debug(t){return this.debugging=t,this}async fetchRemote(t,e){return fetch(t,{cache:e?.cache??"default"}).then(t=>t.text())}async fetchLocal(t,e){return this.fetchRemote(t,e)}async preprocessString(t,e){this.log("Preprocessing string content with params:\n",e);const s=this.parseHTML(t,e);return await this.preprocessNode(s,e),s}async preprocessRemote(t,e){const s={};e?.cache&&(s.cache=e.cache);const i=await fetch(t,s).then(t=>t.text());return this.preprocessString(i,{...e,dirpath:ht(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}async preprocessLocal(t,e){const s=await this.fetchLocal(t,e);return this.preprocessString(s,{...e,dirpath:ht(t),rootDocument:e?.rootDocument??!t.endsWith(".tpl.html")})}subrenderer(){const t=(new this.constructor).debug(this.debugging);return t._store.set("$parent",this),t._store.set("$rootRenderer",this.get("$rootRenderer")??this),t._customElements=this._customElements,t}log(...t){this.debugging&&console.debug(...t)}async preprocessNode(t,e){e={dirpath:this.dirpath,maxdepth:10,...e};const s=new ut(W(t,this._skipNodes)).map(async t=>{this.log("Preprocessing node:\n",ct(t,128)),await dt.resolveIncludes.call(this,t,e),await dt.rebaseRelativePaths.call(this,t,e),await dt.registerCustomElements.call(this,t,e),await dt.resolveCustomElements.call(this,t,e)});return await Promise.all(s.generator()),t}async renderNode(t,e){for(const s of W(t,this._skipNodes))this.log("Rendering node:\n",ct(s,128)),await dt.resolveForAttribute.call(this,s,e),await dt.resolveDataAttribute.call(this,s,e),await dt.resolveTextAttributes.call(this,s,e),await dt.resolveHtmlAttribute.call(this,s,e),await dt.resolveShowAttribute.call(this,s,e),await dt.resolveClassAttribute.call(this,s,e),await dt.resolveBindAttribute.call(this,s,e),await dt.resolveEventAttributes.call(this,s,e),await dt.resolveTextNodeExpressions.call(this,s,e),await dt.resolveCustomAttribute.call(this,s,e),await dt.resolveCustomProperty.call(this,s,e),await dt.stripTypes.call(this,s,e);return t}async mount(t,e){e={...e,rootNode:t},Q(t,"renderer",this),this._store.set("$rootNode",t),this.has("$rootRenderer")||this._store.set("$rootRenderer",this),this.get("$rootRenderer")===this&&await Mt(this),await this.preprocessNode(t,e),await this.renderNode(t,e)}}const Gt=[":data",":for",":text",":html",":show",":class",":bind",":on:click",":on:click.prevent",":on:input",":on:input.prevent",":on:change",":on:change.prevent",":on:submit",":on:submit.prevent",":attr:src",":attr:href",":attr:title",":prop:checked",":prop:selected",":prop:disabled"];class Kt extends Ft{impl="safe_browser";dirpath=ht(globalThis.location?.href??"http://localhost/");parseHTML(t,e={rootDocument:!1}){for(const e of Gt)t=t.replace(new RegExp(`\\s:${e.slice(1)}=`,"g"),` data-${e.slice(1).replace(":","-")}=`);t=(t=(t=t.replace(/<include(.*) src="([^"]+)"(.*)><\/include>/g,'<link $1 rel="subresource" href="$2" $3>')).replace(/<template is="([^"]+)">([\s\S]*)<\/template>/g,'<div role="template" alt="$1">$2</div>')).replace(/<(\w+)-(\w+)(.*)>([\s\S]*)<\/(\w+)-(\w+)>/g,'<div role="$1-$2" $3>$4</div>');const s=Gt.map(t=>`data-${t.slice(1).replace(":","-")}`);s.push("data-testid");const i=(new F).allowDataAttributes(s).allowClassAttributes().allowStyleAttributes().build();if(this.log("parseHTML",t),this.log("sanitized",String(i.sanitize(t))),e.rootDocument){return K(new DOMParser,i.sanitize(t),"text/html")}return i.sanitizeToFragment(t)}serializeHTML(t){return(new XMLSerializer).serializeToString(t).replace(/\s?xmlns="[^"]+"/gm,"")}preprocessLocal(t,e){return this.preprocessRemote(t,e)}createElement(t,e){return(e||document).createElement(t)}textContent(t,e){t.textContent=e}}const Ht=new Kt;export{Ht as Mancha,Kt as Renderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/test_types/api.ts"],"names":[],"mappings":"AAAA,sDAAsD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/test_types/product.ts"],"names":[],"mappings":"AAAA,sDAAsD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/test_types/user.ts"],"names":[],"mappings":"AAAA,sDAAsD"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import * as fs from "fs/promises";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { JSDOM } from "jsdom";
|
|
5
|
+
import { getAttributeOrDataset } from "./dome.js";
|
|
6
|
+
async function getDiagnostics(content, options) {
|
|
7
|
+
// Create temp file in src directory so relative imports resolve correctly
|
|
8
|
+
const srcDir = path.dirname(new URL(import.meta.url).pathname);
|
|
9
|
+
const tempFilePath = path.join(srcDir, `temp_type_check_${Math.random().toString(36).substring(2, 15)}.ts`);
|
|
10
|
+
await fs.writeFile(tempFilePath, content);
|
|
11
|
+
const program = ts.createProgram([tempFilePath], {
|
|
12
|
+
noEmit: true,
|
|
13
|
+
strict: options.strict,
|
|
14
|
+
strictNullChecks: options.strict,
|
|
15
|
+
lib: ["es2022", "dom"],
|
|
16
|
+
target: ts.ScriptTarget.ES2022,
|
|
17
|
+
module: ts.ModuleKind.None,
|
|
18
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
19
|
+
});
|
|
20
|
+
const allDiagnostics = ts.getPreEmitDiagnostics(program);
|
|
21
|
+
await fs.unlink(tempFilePath);
|
|
22
|
+
// Filter out irrelevant diagnostics (keep semantic errors 2000-2999 and strict mode errors 18000-18999)
|
|
23
|
+
return allDiagnostics.filter((d) => (d.code >= 2000 && d.code < 3000) || (d.code >= 18000 && d.code < 19000));
|
|
24
|
+
}
|
|
25
|
+
// Replace @import:MODULE_PATH:TYPE_NAME with import("MODULE_PATH").TYPE_NAME
|
|
26
|
+
function replaceImportSyntax(typeString) {
|
|
27
|
+
return typeString.replace(/@import:([^:]+):([A-Za-z_][A-Za-z0-9_]*)/g, 'import("$1").$2');
|
|
28
|
+
}
|
|
29
|
+
function buildTypeScriptSource(types, scope) {
|
|
30
|
+
const namespace = `M${Math.random().toString(36).substring(2, 15)}`;
|
|
31
|
+
// Apply import syntax transformation to all type values
|
|
32
|
+
const declarations = Array.from(types.entries())
|
|
33
|
+
.map(([key, value]) => {
|
|
34
|
+
const resolvedType = replaceImportSyntax(value);
|
|
35
|
+
return `declare let ${key}: ${resolvedType};`;
|
|
36
|
+
})
|
|
37
|
+
.join("\n");
|
|
38
|
+
// Recursively build checks from scope
|
|
39
|
+
const buildChecks = (currentScope, indent = "") => {
|
|
40
|
+
let result = "";
|
|
41
|
+
// Add expressions in current scope
|
|
42
|
+
for (const expr of currentScope.expressions) {
|
|
43
|
+
result += `${indent}(${expr});\n`;
|
|
44
|
+
}
|
|
45
|
+
// Add for loops with their nested scopes
|
|
46
|
+
for (const forLoop of currentScope.forLoops) {
|
|
47
|
+
result += `${indent}for (const ${forLoop.itemName} of ${forLoop.itemsExpression}) {\n`;
|
|
48
|
+
result += buildChecks(forLoop.scope, indent + " ");
|
|
49
|
+
result += `${indent}}\n`;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
const checks = buildChecks(scope);
|
|
54
|
+
return `namespace ${namespace} {\n${declarations}\n${checks}}`;
|
|
55
|
+
}
|
|
56
|
+
// Helper to check if an element is nested within another :types element
|
|
57
|
+
function hasTypesAncestor(element) {
|
|
58
|
+
let parent = element.parentElement;
|
|
59
|
+
while (parent) {
|
|
60
|
+
if (getAttributeOrDataset(parent, "types", ":")) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
parent = parent.parentElement;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// Compute type of for-loop variable based on the items expression
|
|
68
|
+
function computeForLoopVariableType(itemsType) {
|
|
69
|
+
// Handle array types: string[] -> string, Array<T> -> T
|
|
70
|
+
if (itemsType.endsWith("[]")) {
|
|
71
|
+
return itemsType.slice(0, -2);
|
|
72
|
+
}
|
|
73
|
+
if (itemsType.match(/^Array<(.+)>$/)) {
|
|
74
|
+
return itemsType.match(/^Array<(.+)>$/)[1];
|
|
75
|
+
}
|
|
76
|
+
// For complex types, try to infer element type
|
|
77
|
+
// This is a simple heuristic - for more complex cases, TypeScript would need to resolve the type
|
|
78
|
+
return "any";
|
|
79
|
+
}
|
|
80
|
+
// Find for-loop ancestors of an element and compute their variable types
|
|
81
|
+
function getForLoopContext(element, typesMap) {
|
|
82
|
+
const forLoopTypes = new Map();
|
|
83
|
+
let current = element.parentElement;
|
|
84
|
+
while (current) {
|
|
85
|
+
const forAttr = getAttributeOrDataset(current, "for", ":");
|
|
86
|
+
if (forAttr) {
|
|
87
|
+
const parts = forAttr.split(" in ");
|
|
88
|
+
const itemName = parts[0].trim();
|
|
89
|
+
const itemsExpression = parts[1].trim();
|
|
90
|
+
// Try to determine the type of the items expression
|
|
91
|
+
// First check if it's a simple variable name in our types map
|
|
92
|
+
if (typesMap.has(itemsExpression)) {
|
|
93
|
+
const itemsType = typesMap.get(itemsExpression);
|
|
94
|
+
const itemType = computeForLoopVariableType(itemsType);
|
|
95
|
+
forLoopTypes.set(itemName, itemType);
|
|
96
|
+
}
|
|
97
|
+
else if (forLoopTypes.has(itemsExpression)) {
|
|
98
|
+
// Check if it's a for-loop variable from an outer loop (for shadowing)
|
|
99
|
+
const itemsType = forLoopTypes.get(itemsExpression);
|
|
100
|
+
const itemType = computeForLoopVariableType(itemsType);
|
|
101
|
+
forLoopTypes.set(itemName, itemType);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Try to infer from more complex expressions like user.scores
|
|
105
|
+
// For now, use a simple heuristic
|
|
106
|
+
const match = itemsExpression.match(/^(\w+)\.(\w+)$/);
|
|
107
|
+
if (match && forLoopTypes.has(match[1])) {
|
|
108
|
+
// e.g., user.scores where user is already in forLoopTypes
|
|
109
|
+
const parentType = forLoopTypes.get(match[1]);
|
|
110
|
+
const propertyName = match[2];
|
|
111
|
+
// Extract property type from parent type (simple heuristic)
|
|
112
|
+
const propMatch = parentType.match(new RegExp(`${propertyName}:\\s*([^,}]+)`));
|
|
113
|
+
if (propMatch) {
|
|
114
|
+
const propType = propMatch[1].trim();
|
|
115
|
+
const itemType = computeForLoopVariableType(propType);
|
|
116
|
+
forLoopTypes.set(itemName, itemType);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Stop if we hit a :types boundary (don't cross into parent :types scopes)
|
|
122
|
+
if (current !== element && getAttributeOrDataset(current, "types", ":")) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
current = current.parentElement;
|
|
126
|
+
}
|
|
127
|
+
return forLoopTypes;
|
|
128
|
+
}
|
|
129
|
+
// Recursively process a :types element and its nested :types descendants
|
|
130
|
+
async function processTypesElement(element, parentTypes, options, processedElements) {
|
|
131
|
+
// Skip if already processed
|
|
132
|
+
if (processedElements.has(element)) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
processedElements.add(element);
|
|
136
|
+
const allDiagnostics = [];
|
|
137
|
+
const typesAttr = getAttributeOrDataset(element, "types", ":");
|
|
138
|
+
if (!typesAttr)
|
|
139
|
+
return allDiagnostics;
|
|
140
|
+
try {
|
|
141
|
+
// Parse types for this element
|
|
142
|
+
const elementTypes = new Map(Object.entries(JSON.parse(typesAttr)));
|
|
143
|
+
// Merge with parent types (element types override parent types)
|
|
144
|
+
const mergedTypes = new Map([...parentTypes, ...elementTypes]);
|
|
145
|
+
// Get expressions for this element (excluding nested :types descendants)
|
|
146
|
+
const expressions = getExpressionsExcludingNestedTypes(element);
|
|
147
|
+
// Type check expressions in this scope
|
|
148
|
+
const source = buildTypeScriptSource(mergedTypes, expressions);
|
|
149
|
+
const diagnostics = await getDiagnostics(source, options);
|
|
150
|
+
allDiagnostics.push(...diagnostics);
|
|
151
|
+
// Find and process nested :types elements
|
|
152
|
+
const nestedTypesElements = findDirectNestedTypesElements(element);
|
|
153
|
+
for (const nestedElement of nestedTypesElements) {
|
|
154
|
+
// Compute for-loop context for the nested element
|
|
155
|
+
const forLoopContext = getForLoopContext(nestedElement, mergedTypes);
|
|
156
|
+
// Merge for-loop variables with parent types (for-loop variables take precedence)
|
|
157
|
+
const nestedParentTypes = new Map([...mergedTypes, ...forLoopContext]);
|
|
158
|
+
const nestedDiagnostics = await processTypesElement(nestedElement, nestedParentTypes, options, processedElements);
|
|
159
|
+
allDiagnostics.push(...nestedDiagnostics);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
console.error("Error parsing :types attribute:", e);
|
|
164
|
+
}
|
|
165
|
+
return allDiagnostics;
|
|
166
|
+
}
|
|
167
|
+
// Find nested :types elements that are direct descendants (not grandchildren through other :types)
|
|
168
|
+
function findDirectNestedTypesElements(element) {
|
|
169
|
+
const result = [];
|
|
170
|
+
const walker = element.ownerDocument.createTreeWalker(element, 1); // 1 = SHOW_ELEMENT
|
|
171
|
+
while (walker.nextNode()) {
|
|
172
|
+
const node = walker.currentNode;
|
|
173
|
+
if (node === element)
|
|
174
|
+
continue;
|
|
175
|
+
const typesAttr = getAttributeOrDataset(node, "types", ":");
|
|
176
|
+
if (typesAttr) {
|
|
177
|
+
// Check if this is a direct nested :types (not nested within another :types first)
|
|
178
|
+
let parent = node.parentElement;
|
|
179
|
+
let foundIntermediateTypes = false;
|
|
180
|
+
while (parent && parent !== element) {
|
|
181
|
+
if (getAttributeOrDataset(parent, "types", ":")) {
|
|
182
|
+
foundIntermediateTypes = true;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
parent = parent.parentElement;
|
|
186
|
+
}
|
|
187
|
+
if (!foundIntermediateTypes) {
|
|
188
|
+
result.push(node);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
// Get expressions excluding those in nested :types elements
|
|
195
|
+
function getExpressionsExcludingNestedTypes(root) {
|
|
196
|
+
const scope = { expressions: [], forLoops: [] };
|
|
197
|
+
const processedForElements = new Set();
|
|
198
|
+
const processElement = (element, currentScope) => {
|
|
199
|
+
// Stop if we encounter a nested :types element
|
|
200
|
+
if (element !== root && getAttributeOrDataset(element, "types", ":")) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// Check if this element has a :for attribute
|
|
204
|
+
const forAttr = getAttributeOrDataset(element, "for", ":");
|
|
205
|
+
if (forAttr) {
|
|
206
|
+
if (processedForElements.has(element))
|
|
207
|
+
return;
|
|
208
|
+
processedForElements.add(element);
|
|
209
|
+
const parts = forAttr.split(" in ");
|
|
210
|
+
const itemName = parts[0].trim();
|
|
211
|
+
const itemsExpression = parts[1].trim();
|
|
212
|
+
currentScope.expressions.push(itemsExpression);
|
|
213
|
+
const forScope = { expressions: [], forLoops: [] };
|
|
214
|
+
processDescendants(element, forScope);
|
|
215
|
+
currentScope.forLoops.push({ itemName, itemsExpression, scope: forScope });
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// Process attributes
|
|
219
|
+
for (const attr of Array.from(element.attributes)) {
|
|
220
|
+
if ((attr.name.startsWith(":") || attr.name.startsWith("data-")) &&
|
|
221
|
+
attr.name !== ":types" &&
|
|
222
|
+
attr.name !== "data-types") {
|
|
223
|
+
currentScope.expressions.push(attr.value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Process children
|
|
227
|
+
for (const child of Array.from(element.childNodes)) {
|
|
228
|
+
if (child.nodeType === 1) {
|
|
229
|
+
processElement(child, currentScope);
|
|
230
|
+
}
|
|
231
|
+
else if (child.nodeType === 3) {
|
|
232
|
+
processTextNode(child, currentScope);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const processDescendants = (element, currentScope) => {
|
|
238
|
+
for (const child of Array.from(element.childNodes)) {
|
|
239
|
+
if (child.nodeType === 1) {
|
|
240
|
+
processElement(child, currentScope);
|
|
241
|
+
}
|
|
242
|
+
else if (child.nodeType === 3) {
|
|
243
|
+
processTextNode(child, currentScope);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const processTextNode = (textNode, currentScope) => {
|
|
248
|
+
const text = textNode.nodeValue;
|
|
249
|
+
if (text) {
|
|
250
|
+
const matches = text.matchAll(/{{(.*?)}}/g);
|
|
251
|
+
for (const match of matches) {
|
|
252
|
+
currentScope.expressions.push(match[1].trim());
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
// Start processing from root's children
|
|
257
|
+
for (const child of Array.from(root.childNodes)) {
|
|
258
|
+
if (child.nodeType === 1) {
|
|
259
|
+
processElement(child, scope);
|
|
260
|
+
}
|
|
261
|
+
else if (child.nodeType === 3) {
|
|
262
|
+
processTextNode(child, scope);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return scope;
|
|
266
|
+
}
|
|
267
|
+
export async function typeCheck(html, options) {
|
|
268
|
+
const dom = new JSDOM(html);
|
|
269
|
+
const allTypeNodes = dom.window.document.querySelectorAll("[\\:types], [data-types]");
|
|
270
|
+
const allDiagnostics = [];
|
|
271
|
+
const processedElements = new Set();
|
|
272
|
+
// Find top-level :types elements (not nested within other :types)
|
|
273
|
+
const topLevelTypeNodes = Array.from(allTypeNodes).filter((node) => !hasTypesAncestor(node));
|
|
274
|
+
// Process each top-level :types element and its nested descendants
|
|
275
|
+
for (const node of topLevelTypeNodes) {
|
|
276
|
+
const diagnostics = await processTypesElement(node, new Map(), options, processedElements);
|
|
277
|
+
allDiagnostics.push(...diagnostics);
|
|
278
|
+
}
|
|
279
|
+
return allDiagnostics;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=type_checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type_checker.js","sourceRoot":"","sources":["../src/type_checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAMlD,KAAK,UAAU,cAAc,CAC3B,OAAe,EACf,OAAyB;IAEzB,0EAA0E;IAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAC5B,MAAM,EACN,mBAAmB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CACpE,CAAC;IACF,MAAM,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAE1C,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC,YAAY,CAAC,EAAE;QAC/C,MAAM,EAAE,IAAI;QACZ,MAA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