mancha 0.5.0 → 0.5.1

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.
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import { IRenderer } from "./core";
3
+ export interface ParserParams {
4
+ /** Whether the file parsed is a root document, or a document fragment. */
5
+ root?: boolean;
6
+ /** Encoding to use when processing local files. */
7
+ encoding?: BufferEncoding;
8
+ }
9
+ /** The RendererParams interface defines the parameters that can be passed to the renderer. */
10
+ export interface RenderParams {
11
+ /** The current directory of the file being rendered. */
12
+ dirpath?: string;
13
+ /** Maximum level of recursion allowed when resolving includes. */
14
+ maxdepth?: number;
15
+ /** Cache policy used when resolving remote paths. */
16
+ cache?: RequestCache | null;
17
+ /** Whether to print debug information. */
18
+ debug?: boolean;
19
+ }
20
+ export type RendererPlugin = (this: IRenderer, node: ChildNode, params: RenderParams) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ export declare class Iterator<T> {
2
+ private readonly iterable;
3
+ constructor(iter: Iterable<T>);
4
+ filter(fn: (val: T) => boolean): Iterator<T>;
5
+ map<S>(fn: (val: T) => S): Iterator<S>;
6
+ array(): T[];
7
+ generator(): Iterable<T>;
8
+ static filterGenerator<T>(fn: (val: T) => boolean, iter: Iterable<T>): Iterable<T>;
9
+ static mapGenerator<T, S>(fn: (val: T) => S, iter: Iterable<T>): Iterable<S>;
10
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Iterator = void 0;
4
+ class Iterator {
5
+ constructor(iter) {
6
+ this.iterable = iter;
7
+ }
8
+ filter(fn) {
9
+ return new Iterator(Iterator.filterGenerator(fn, this.iterable));
10
+ }
11
+ map(fn) {
12
+ return new Iterator(Iterator.mapGenerator(fn, this.iterable));
13
+ }
14
+ array() {
15
+ return Array.from(this.iterable);
16
+ }
17
+ *generator() {
18
+ for (const val of this.iterable) {
19
+ yield val;
20
+ }
21
+ }
22
+ static *filterGenerator(fn, iter) {
23
+ for (const val of iter) {
24
+ if (fn(val))
25
+ yield val;
26
+ }
27
+ }
28
+ static *mapGenerator(fn, iter) {
29
+ for (const val of iter) {
30
+ yield fn(val);
31
+ }
32
+ }
33
+ }
34
+ exports.Iterator = Iterator;
package/dist/mancha.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var t={885:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.attributeNameToCamelCase=e.decodeHtmlAttrib=e.encodeHtmlAttrib=void 0,e.encodeHtmlAttrib=function(t){var e,i,r,n,o,s,l;return null!==(l=null===(s=null===(o=null===(n=null===(r=null===(i=null===(e=null==t?void 0:t.replace(/&/g,"&amp;"))||void 0===e?void 0:e.replace(/'/g,"&apos;"))||void 0===i?void 0:i.replace(/"/g,"&quot;"))||void 0===r?void 0:r.replace(/</g,"&lt;"))||void 0===n?void 0:n.replace(/>/g,"&gt;"))||void 0===o?void 0:o.replace(/\r\n/g,"&#13;"))||void 0===s?void 0:s.replace(/[\r\n]/g,"&#13;"))&&void 0!==l?l:""},e.decodeHtmlAttrib=function(t){var e,i,r,n,o,s;return null!==(s=null===(o=null===(n=null===(r=null===(i=null===(e=null==t?void 0:t.replace(/&amp;/g,"&"))||void 0===e?void 0:e.replace(/&apos;/g,"'"))||void 0===i?void 0:i.replace(/&quot;/g,'"'))||void 0===r?void 0:r.replace(/&lt;/g,"<"))||void 0===n?void 0:n.replace(/&gt;/g,">"))||void 0===o?void 0:o.replace(/&#13;/g,"\n"))&&void 0!==s?s:""},e.attributeNameToCamelCase=function(t){return t.replace(/-./g,(t=>t[1].toUpperCase()))}},246:function(t,e,i){var r,n,o,s,l=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(n,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function l(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,l)}a((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const a=i(283);class c extends a.IRenderer{constructor(){super(...arguments),this.fsroot=(0,a.folderPath)(self.location.href)}parseHTML(t,e={isRoot:!1}){if(e.isRoot)return(new DOMParser).parseFromString(t,"text/html");{const e=document.createRange();return e.selectNodeContents(document.body),e.createContextualFragment(t)}}serializeHTML(t){return(new XMLSerializer).serializeToString(t).replace(/\s?xmlns="[^"]+"/gm,"")}renderLocalPath(t,e){throw new Error("Not implemented.")}}const h=new c;self.Mancha=h;const d=null===(r=self.document)||void 0===r?void 0:r.currentScript;if(null===(o=null===(n=self.document)||void 0===n?void 0:n.currentScript)||void 0===o?void 0:o.hasAttribute("init")){h.update(Object.assign({},null==d?void 0:d.dataset));const t=null==d?void 0:d.hasAttribute("debug"),e=null==d?void 0:d.getAttribute("cache"),i=((null===(s=null==d?void 0:d.getAttribute("target"))||void 0===s?void 0:s.split(","))||["body"]).map((i=>l(void 0,void 0,void 0,(function*(){const r=self.document.querySelector(i);yield h.mount(r,{cache:e,debug:t})}))));Promise.all(i).then((()=>{dispatchEvent(new Event("mancha-render",{bubbles:!0}))}))}e.default=h},283:function(t,e,i){var r=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(n,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function l(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,l)}a((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.IRenderer=e.safeEval=e.extractTextNodeKeys=e.resolvePath=e.folderPath=e.traverse=void 0;const n=i(975),o=i(63),s=i(885),l=new Set([":bind",":bind-events",":data",":for",":show","@watch"]),a={$text:"$text-content",$html:"$inner-HTML"};function*c(t,e=new Set){const i=new Set,r=Array.from(t.childNodes).filter((t=>!e.has(t)));for(yield t;r.length;){const t=r.pop();i.has(t)||(i.add(t),yield t),t.childNodes&&Array.from(t.childNodes).filter((t=>!e.has(t))).forEach((t=>r.push(t)))}}function h(t){return t.endsWith("/")?t.slice(0,-1):n.dirname(t)}function d(t){const e=new RegExp(/{{ ([\w\.]+) }}/gm);return Array.from(t.matchAll(e)).map((t=>{const e=t[0];let i=t[1];const r=[];if(i.includes(".")){const t=i.split(".");i=t[0],r.push(...t.slice(1))}return[e,i,r]}))}function u(t,e,i={}){const r=`with (this) { return (async () => (${t}))(); }`;return new Function(...Object.keys(i),r).call(e,...Object.values(i))}e.traverse=c,e.folderPath=h,e.resolvePath=function t(e){if(e.includes("://")){const[i,r]=e.split("://",2);return`${i}://${t("/"+r).substring(1)}`}return n.resolve(e)},e.extractTextNodeKeys=d,e.safeEval=u;const f={maxdepth:10};class v extends o.ReactiveProxyStore{constructor(){super(...arguments),this.fsroot=".",this.skipNodes=new Set}clone(){return new this.constructor(Object.fromEntries(this.store.entries()))}log(t,...e){(null==t?void 0:t.debug)&&console.debug(...e)}eval(t){return r(this,arguments,void 0,(function*(t,e={},i){const r=(0,o.proxify)(this),n=yield u(t,r,Object.assign({},e));return this.log(i,`eval \`${t}\` => `,n),n}))}resolveIncludes(t,e){return r(this,void 0,void 0,(function*(){e=Object.assign({fsroot:this.fsroot},f,e);const i=Array.from(c(t,this.skipNodes)).map((t=>t)).filter((t=>{var e;return"include"===(null===(e=t.tagName)||void 0===e?void 0:e.toLocaleLowerCase())})).map((t=>r(this,void 0,void 0,(function*(){var i,r;const o=null===(i=t.getAttribute)||void 0===i?void 0:i.call(t,"src"),l=Object.assign({},t.dataset);if(Object.entries(l).forEach((([t,e])=>this.set(t,(0,s.decodeHtmlAttrib)(e)))),!o)throw new Error(`"src" attribute missing from ${t}.`);const a=e=>{t.replaceWith(...Array.from(e.childNodes))};if(e.maxdepth--,-1!==o.indexOf("://"))yield this.renderRemotePath(o,Object.assign(Object.assign({},e),{isRoot:!1})).then(a);else if(-1!==(null===(r=e.fsroot)||void 0===r?void 0:r.indexOf("://"))){const t=`${e.fsroot}/${o}`;yield this.renderRemotePath(t,Object.assign(Object.assign({},e),{isRoot:!1})).then(a)}else if("/"===o.charAt(0))yield this.renderLocalPath(o,Object.assign(Object.assign({},e),{isRoot:!1})).then(a);else{const t=n.join(e.fsroot,o);yield this.renderLocalPath(t,Object.assign(Object.assign({},e),{isRoot:!1})).then(a)}}))));if(yield Promise.all(i),0===i.length)return this;if(0===e.maxdepth)throw new Error("Maximum recursion depth reached.");return this.resolveIncludes(t,{fsroot:e.fsroot,maxdepth:e.maxdepth-1})}))}resolveTextNode(t,e){if(3!==t.nodeType)return[];const i=t.nodeValue||"",r=d(i).filter((([,t])=>this.store.has(t)));if(0===r.length)return[];this.log(e,r,"keys found in node:",t);const n=()=>{let e=i;r.forEach((([t,i,r])=>{var n;e=e.replace(t,String(null!==(n=this.get(i,...r))&&void 0!==n?n:""))})),t.nodeValue=e};return n(),this.watch(r.map((([,t])=>t)),n),r.map((([,t])=>this.store.get(t)))}resolveDataAttribute(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const r=t,n=null===(i=r.getAttribute)||void 0===i?void 0:i.call(r,":data");if(n){this.log(e,":data attribute found in:\n",t),r.removeAttribute(":data");const i=yield this.eval(n,{$elem:t},e);this.log(e,":data",n,"=>",i),yield this.update(i)}}))}resolveWatchAttribute(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const r=t,n=null===(i=r.getAttribute)||void 0===i?void 0:i.call(r,"@watch");if(n){this.log(e,"@watch attribute found in:\n",t),r.removeAttribute("@watch");const i=()=>this.eval(n,{$elem:t},e),[o,s]=yield this.trace(i);this.log(e,"@watch",n,"=>",o),this.watch(s,i)}}))}resolvePropAttributes(t,e){return r(this,void 0,void 0,(function*(){if(this.skipNodes.has(t))return;const i=t;for(const n of Array.from(i.attributes||[]))if(n.name.startsWith("$")&&!l.has(n.name)){this.log(e,n.name,"attribute found in:\n",t),i.removeAttribute(n.name);const o=(a[n.name]||n.name).slice(1),l=()=>this.eval(n.value,{$elem:t},e),[c,h]=yield this.trace(l);this.log(e,n.name,n.value,"=>",c,`[${h}]`);const d=(0,s.attributeNameToCamelCase)(o);this.watch(h,(()=>r(this,void 0,void 0,(function*(){return t[d]=yield l()})))),t[d]=c}}))}resolveAttrAttributes(t,e){return r(this,void 0,void 0,(function*(){if(this.skipNodes.has(t))return;const i=t;for(const n of Array.from(i.attributes||[]))if(n.name.startsWith(":")&&!l.has(n.name)){this.log(e,n.name,"attribute found in:\n",t),i.removeAttribute(n.name);const o=(a[n.name]||n.name).slice(1),s=()=>this.eval(n.value,{$elem:t},e),[l,c]=yield this.trace(s);this.log(e,n.name,n.value,"=>",l,`[${c}]`),this.watch(c,(()=>r(this,void 0,void 0,(function*(){return i.setAttribute(o,yield s())})))),i.setAttribute(o,l)}}))}resolveEventAttributes(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const r=t;for(const n of Array.from(r.attributes||[]))n.name.startsWith("@")&&!l.has(n.name)&&(this.log(e,n.name,"attribute found in:\n",t),r.removeAttribute(n.name),null===(i=t.addEventListener)||void 0===i||i.call(t,n.name.substring(1),(i=>this.eval(n.value,{$elem:t,$event:i},e))))}))}resolveForAttribute(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const n=t,o=null===(i=n.getAttribute)||void 0===i?void 0:i.call(n,":for");if(o){this.log(e,":for attribute found in:\n",t),n.removeAttribute(":for");for(const e of c(t,this.skipNodes))this.skipNodes.add(e);const i=t.parentNode,s=t.ownerDocument.createElement("template");i.insertBefore(s,t),s.append(t),this.log(e,":for template:\n",s);const l=o.split(" in ",2);if(2!==l.length)throw new Error(`Invalid :for format: \`${o}\`. Expected "{key} in {expression}".`);let a=[],h=[];const[d,u]=l;try{[a,h]=yield this.trace((()=>this.eval(u,{$elem:t},e))),this.log(e,u,"=>",a,`[${h}]`)}catch(t){return void console.error(t)}const f=[],v=n=>r(this,void 0,void 0,(function*(){if(this.log(e,":for list items:",n),Array.isArray(n))return this.lock=this.lock.then((()=>new Promise((o=>r(this,void 0,void 0,(function*(){f.splice(0,f.length).forEach((t=>{i.removeChild(t)}));for(const r of n.slice(0).reverse()){const n=this.clone();yield n.set(d,r);const o=t.cloneNode(!0);i.insertBefore(o,s.nextSibling),f.push(o),this.skipNodes.add(o),yield n.mount(o,e),this.log(e,"Rendered list child:\n",o)}o()})))))),this.lock;console.error(`Expression did not yield a list: \`${u}\` => \`${n}\``)}));return this.watch(h,(()=>r(this,void 0,void 0,(function*(){return v(yield this.eval(u,{$elem:t},e))})))),v(a)}}))}resolveBindAttribute(t,e){return r(this,void 0,void 0,(function*(){var i,r,n;if(this.skipNodes.has(t))return;const o=t,s=null===(i=o.getAttribute)||void 0===i?void 0:i.call(o,":bind");if(s){this.log(e,":bind attribute found in:\n",t);const i=["change","input"],l=(null===(n=null===(r=o.getAttribute)||void 0===r?void 0:r.call(o,":bind-events"))||void 0===n?void 0:n.split(","))||i,a="checkbox"===o.getAttribute("type")?"checked":"value";this.store.has(s)||(yield this.set(s,o[a])),o[a]=this.get(s);for(const e of l)t.addEventListener(e,(()=>this.set(s,o[a])));this.watch([s],(()=>o[a]=this.get(s))),o.removeAttribute(":bind"),o.removeAttribute(":bind-events")}}))}resolveShowAttribute(t,e){return r(this,void 0,void 0,(function*(){var i,n;if(this.skipNodes.has(t))return;const o=t,s=null===(n=(i=t).getAttribute)||void 0===n?void 0:n.call(i,":show");if(s){const i=()=>this.eval(s,{$elem:t},e),[n,l]=yield this.trace(i);this.log(e,":show",s,"=>",n,`[${l}]`);const a=t.parentNode;n||a.removeChild(t),this.watch(l,(()=>r(this,void 0,void 0,(function*(){(yield i())&&t.parentNode!==a?a.append(t):Array.from(a.childNodes).includes(t)&&t.remove()})))),o.removeAttribute(":show")}}))}mount(t,e){return r(this,void 0,void 0,(function*(){yield this.resolveIncludes(t,e);for(const i of c(t,this.skipNodes))this.log(e,"Processing node:\n",i),yield this.resolveShowAttribute(i,e),yield this.resolveDataAttribute(i,e),yield this.resolveWatchAttribute(i,e),yield this.resolveForAttribute(i,e),yield this.resolveBindAttribute(i,e),yield this.resolvePropAttributes(i,e),yield this.resolveAttrAttributes(i,e),yield this.resolveEventAttributes(i,e),this.resolveTextNode(i,e);return this}))}renderString(t,e){return r(this,void 0,void 0,(function*(){const i=this.parseHTML(t,e);return yield this.mount(i,e),i}))}renderRemotePath(t,e){return r(this,void 0,void 0,(function*(){const i=(null==e?void 0:e.cache)||"default",r=yield fetch(t,{cache:i}).then((t=>t.text()));return this.renderString(r,Object.assign(Object.assign({},e),{fsroot:h(t),isRoot:(null==e?void 0:e.isRoot)||!t.endsWith(".tpl.html")}))}))}}e.IRenderer=v},63:function(t,e){var i=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(n,o){function s(t){try{a(r.next(t))}catch(t){o(t)}}function l(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,l)}a((r=r.apply(t,e||[])).next())}))};function r(t,e,i=!0){if(null==t||function(t){return t instanceof n||t.__is_proxy__}(t))return t;if(i)for(const i in t)t.hasOwnProperty(i)&&"object"==typeof t[i]&&null!=t[i]&&(t[i]=r(t[i],e));return new Proxy(t,{deleteProperty:(t,i)=>i in t&&(delete t[i],e(),!0),set:(t,n,o,s)=>{i&&"object"==typeof o&&(o=r(o,e));const l=Reflect.set(t,n,o,s);return e(),l},get:(t,e,i)=>"__is_proxy__"===e||Reflect.get(t,e,i)})}Object.defineProperty(e,"__esModule",{value:!0}),e.proxify=e.ReactiveProxyStore=e.InertProxy=e.ReactiveProxy=e.proxifyObject=void 0,e.proxifyObject=r;class n{constructor(t=null,...e){this.value=null,this.listeners=[],this.set(t),e.forEach((t=>this.watch(t)))}static from(t,...e){return t instanceof n?(e.forEach(t.watch),t):new n(t,...e)}get(...t){return t.length?function(t,...e){let i=t;for(const t of e)i=i[t];return i}(this.value,...t):this.value}set(t){return i(this,void 0,void 0,(function*(){if(this.value!==t){const e=this.value;null!=t&&"object"==typeof t&&(t=r(t,(()=>this.trigger()))),this.value=t,yield this.trigger(e)}}))}watch(t){this.listeners.push(t)}unwatch(t){this.listeners=this.listeners.filter((e=>e!==t))}trigger(){return i(this,arguments,void 0,(function*(t=null){for(const e of this.listeners)yield e(this.value,t)}))}}e.ReactiveProxy=n;class o extends n{static from(t,...e){return t instanceof n?t:new o(t,...e)}watch(t){}trigger(t){return Promise.resolve()}}e.InertProxy=o,e.ReactiveProxyStore=class{constructor(t){this.store=new Map,this.tracing=!1,this.traced=new Set,this.lock=Promise.resolve();for(const[e,i]of Object.entries(t||{}))this.store.set(e,n.from(i))}entries(){return this.store.entries()}get(t,...e){var i;return this.tracing&&this.traced.add(t),null===(i=this.store.get(t))||void 0===i?void 0:i.get(...e)}set(t,e){return i(this,void 0,void 0,(function*(){this.store.has(t)?yield this.store.get(t).set(e):this.store.set(t,n.from(e))}))}del(t){return this.store.delete(t)}update(t){return i(this,void 0,void 0,(function*(){for(const[e,i]of Object.entries(t))yield this.set(e,i)}))}watch(t,e){(t=Array.isArray(t)?t:[t]).forEach((i=>this.store.get(i).watch((()=>e(...t.map((t=>this.store.get(t).get())))))))}trigger(t){return i(this,void 0,void 0,(function*(){for(const e of Array.isArray(t)?t:[t])yield this.store.get(e).trigger()}))}trace(t){return i(this,void 0,void 0,(function*(){yield this.lock;const e=new Promise(((e,r)=>i(this,void 0,void 0,(function*(){this.traced.clear(),this.tracing=!0;try{const i=yield t(),r=Array.from(this.traced);e([i,r])}catch(t){r(t)}finally{this.tracing=!1,this.traced.clear()}}))));return this.lock=e.then((()=>{})),e}))}computed(t,e){return i(this,void 0,void 0,(function*(){const[r,n]=yield this.trace((()=>e()));this.watch(n,(()=>i(this,void 0,void 0,(function*(){return this.set(t,yield e())})))),this.set(t,r)}))}},e.proxify=function(t){const e=Array.from(t.entries()).map((([t])=>t)),i=new Set(e);return new Proxy(Object.fromEntries(e.map((t=>[t,void 0]))),{get:(e,r,n)=>i.has(r)?t.get(r):Reflect.get(e,r,n),set:(e,r,n,o)=>(i.has(r)?t.set(r,n):Reflect.set(e,r,n,o),!0)})}},975:t=>{function e(t){if("string"!=typeof t)throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}function i(t,e){for(var i,r="",n=0,o=-1,s=0,l=0;l<=t.length;++l){if(l<t.length)i=t.charCodeAt(l);else{if(47===i)break;i=47}if(47===i){if(o===l-1||1===s);else if(o!==l-1&&2===s){if(r.length<2||2!==n||46!==r.charCodeAt(r.length-1)||46!==r.charCodeAt(r.length-2))if(r.length>2){var a=r.lastIndexOf("/");if(a!==r.length-1){-1===a?(r="",n=0):n=(r=r.slice(0,a)).length-1-r.lastIndexOf("/"),o=l,s=0;continue}}else if(2===r.length||1===r.length){r="",n=0,o=l,s=0;continue}e&&(r.length>0?r+="/..":r="..",n=2)}else r.length>0?r+="/"+t.slice(o+1,l):r=t.slice(o+1,l),n=l-o-1;o=l,s=0}else 46===i&&-1!==s?++s:s=-1}return r}var r={resolve:function(){for(var t,r="",n=!1,o=arguments.length-1;o>=-1&&!n;o--){var s;o>=0?s=arguments[o]:(void 0===t&&(t=process.cwd()),s=t),e(s),0!==s.length&&(r=s+"/"+r,n=47===s.charCodeAt(0))}return r=i(r,!n),n?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize:function(t){if(e(t),0===t.length)return".";var r=47===t.charCodeAt(0),n=47===t.charCodeAt(t.length-1);return 0!==(t=i(t,!r)).length||r||(t="."),t.length>0&&n&&(t+="/"),r?"/"+t:t},isAbsolute:function(t){return e(t),t.length>0&&47===t.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var t,i=0;i<arguments.length;++i){var n=arguments[i];e(n),n.length>0&&(void 0===t?t=n:t+="/"+n)}return void 0===t?".":r.normalize(t)},relative:function(t,i){if(e(t),e(i),t===i)return"";if((t=r.resolve(t))===(i=r.resolve(i)))return"";for(var n=1;n<t.length&&47===t.charCodeAt(n);++n);for(var o=t.length,s=o-n,l=1;l<i.length&&47===i.charCodeAt(l);++l);for(var a=i.length-l,c=s<a?s:a,h=-1,d=0;d<=c;++d){if(d===c){if(a>c){if(47===i.charCodeAt(l+d))return i.slice(l+d+1);if(0===d)return i.slice(l+d)}else s>c&&(47===t.charCodeAt(n+d)?h=d:0===d&&(h=0));break}var u=t.charCodeAt(n+d);if(u!==i.charCodeAt(l+d))break;47===u&&(h=d)}var f="";for(d=n+h+1;d<=o;++d)d!==o&&47!==t.charCodeAt(d)||(0===f.length?f+="..":f+="/..");return f.length>0?f+i.slice(l+h):(l+=h,47===i.charCodeAt(l)&&++l,i.slice(l))},_makeLong:function(t){return t},dirname:function(t){if(e(t),0===t.length)return".";for(var i=t.charCodeAt(0),r=47===i,n=-1,o=!0,s=t.length-1;s>=1;--s)if(47===(i=t.charCodeAt(s))){if(!o){n=s;break}}else o=!1;return-1===n?r?"/":".":r&&1===n?"//":t.slice(0,n)},basename:function(t,i){if(void 0!==i&&"string"!=typeof i)throw new TypeError('"ext" argument must be a string');e(t);var r,n=0,o=-1,s=!0;if(void 0!==i&&i.length>0&&i.length<=t.length){if(i.length===t.length&&i===t)return"";var l=i.length-1,a=-1;for(r=t.length-1;r>=0;--r){var c=t.charCodeAt(r);if(47===c){if(!s){n=r+1;break}}else-1===a&&(s=!1,a=r+1),l>=0&&(c===i.charCodeAt(l)?-1==--l&&(o=r):(l=-1,o=a))}return n===o?o=a:-1===o&&(o=t.length),t.slice(n,o)}for(r=t.length-1;r>=0;--r)if(47===t.charCodeAt(r)){if(!s){n=r+1;break}}else-1===o&&(s=!1,o=r+1);return-1===o?"":t.slice(n,o)},extname:function(t){e(t);for(var i=-1,r=0,n=-1,o=!0,s=0,l=t.length-1;l>=0;--l){var a=t.charCodeAt(l);if(47!==a)-1===n&&(o=!1,n=l+1),46===a?-1===i?i=l:1!==s&&(s=1):-1!==i&&(s=-1);else if(!o){r=l+1;break}}return-1===i||-1===n||0===s||1===s&&i===n-1&&i===r+1?"":t.slice(i,n)},format:function(t){if(null===t||"object"!=typeof t)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof t);return function(t,e){var i=e.dir||e.root,r=e.base||(e.name||"")+(e.ext||"");return i?i===e.root?i+r:i+"/"+r:r}(0,t)},parse:function(t){e(t);var i={root:"",dir:"",base:"",ext:"",name:""};if(0===t.length)return i;var r,n=t.charCodeAt(0),o=47===n;o?(i.root="/",r=1):r=0;for(var s=-1,l=0,a=-1,c=!0,h=t.length-1,d=0;h>=r;--h)if(47!==(n=t.charCodeAt(h)))-1===a&&(c=!1,a=h+1),46===n?-1===s?s=h:1!==d&&(d=1):-1!==s&&(d=-1);else if(!c){l=h+1;break}return-1===s||-1===a||0===d||1===d&&s===a-1&&s===l+1?-1!==a&&(i.base=i.name=0===l&&o?t.slice(1,a):t.slice(l,a)):(0===l&&o?(i.name=t.slice(1,s),i.base=t.slice(1,a)):(i.name=t.slice(l,s),i.base=t.slice(l,a)),i.ext=t.slice(s,a)),l>0?i.dir=t.slice(0,l-1):o&&(i.dir="/"),i},sep:"/",delimiter:":",win32:null,posix:null};r.posix=r,t.exports=r}},e={};!function i(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,i),o.exports}(246)})();
1
+ (()=>{"use strict";var t={885:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.attributeNameToCamelCase=void 0,e.attributeNameToCamelCase=function(t){return t.replace(/-./g,(t=>t[1].toUpperCase()))}},246:function(t,e,i){var r,o,s,n,a=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(o,s){function n(t){try{l(r.next(t))}catch(t){s(t)}}function a(t){try{l(r.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const l=i(283);class c extends l.IRenderer{constructor(){super(...arguments),this.dirpath=(0,l.dirname)(self.location.href)}parseHTML(t,e={root:!1}){if(e.root)return(new DOMParser).parseFromString(t,"text/html");{const e=document.createRange();return e.selectNodeContents(document.body),e.createContextualFragment(t)}}serializeHTML(t){return(new XMLSerializer).serializeToString(t).replace(/\s?xmlns="[^"]+"/gm,"")}preprocessLocal(t,e){return this.preprocessRemote(t,e)}}const h=new c;self.Mancha=h;const d=null===(r=self.document)||void 0===r?void 0:r.currentScript;if(null===(s=null===(o=self.document)||void 0===o?void 0:o.currentScript)||void 0===s?void 0:s.hasAttribute("init")){h.update(Object.assign({},null==d?void 0:d.dataset));const t=null==d?void 0:d.hasAttribute("debug"),e=null==d?void 0:d.getAttribute("cache");((null===(n=null==d?void 0:d.getAttribute("target"))||void 0===n?void 0:n.split(","))||["body"]).map((i=>a(void 0,void 0,void 0,(function*(){const r=self.document.querySelector(i);yield h.mount(r,{cache:e,debug:t})}))))}e.default=h},283:function(t,e,i){var r=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(o,s){function n(t){try{l(r.next(t))}catch(t){s(t)}}function a(t){try{l(r.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.IRenderer=e.safeEval=e.isRelativePath=e.dirname=e.traverse=void 0;const o=i(63),s=i(150),n=i(230);function*a(t,e=new Set){const i=new Set,r=Array.from(t.childNodes).filter((t=>!e.has(t)));for(yield t;r.length;){const t=r.pop();i.has(t)||(i.add(t),yield t),t.childNodes&&Array.from(t.childNodes).filter((t=>!e.has(t))).forEach((t=>r.push(t)))}}function l(t){return t.includes("/")?t.split("/").slice(0,-1).join("/"):""}function c(t,e,i={}){const r=`with (this) { return (async () => (${t}))(); }`;return new Function(...Object.keys(i),r).call(e,...Object.values(i))}e.traverse=a,e.dirname=l,e.isRelativePath=function(t){return!(t.includes("://")||t.startsWith("/")||t.startsWith("#")||t.startsWith("data:"))},e.safeEval=c;class h extends o.ReactiveProxyStore{constructor(){super(...arguments),this.dirpath="",this.skipNodes=new Set}fetchRemote(t,e){return r(this,void 0,void 0,(function*(){var i;return fetch(t,{cache:null!==(i=null==e?void 0:e.cache)&&void 0!==i?i:"default"}).then((t=>t.text()))}))}fetchLocal(t,e){return r(this,void 0,void 0,(function*(){return this.fetchRemote(t,e)}))}preprocessString(t,e){return r(this,void 0,void 0,(function*(){this.log(e,"Preprocessing string content with params:\n",e);const i=this.parseHTML(t,e);return yield this.preprocessNode(i,e),i}))}preprocessLocal(t,e){return r(this,void 0,void 0,(function*(){var i;const r=yield this.fetchLocal(t,e);return this.preprocessString(r,Object.assign(Object.assign({},e),{dirpath:l(t),root:null!==(i=null==e?void 0:e.root)&&void 0!==i?i:!t.endsWith(".tpl.html")}))}))}preprocessRemote(t,e){return r(this,void 0,void 0,(function*(){var i;const r=(null==e?void 0:e.cache)||"default",o=yield fetch(t,{cache:r}).then((t=>t.text()));return this.preprocessString(o,Object.assign(Object.assign({},e),{dirpath:l(t),root:null!==(i=null==e?void 0:e.root)&&void 0!==i?i:!t.endsWith(".tpl.html")}))}))}clone(){return new this.constructor(Object.fromEntries(this.store.entries()))}log(t,...e){(null==t?void 0:t.debug)&&console.debug(...e)}eval(t){return r(this,arguments,void 0,(function*(t,e={},i){const r=(0,o.proxify)(this),s=yield c(t,r,Object.assign({},e));return this.log(i,`eval \`${t}\` => `,s),s}))}preprocessNode(t,e){return r(this,void 0,void 0,(function*(){e=Object.assign({dirpath:this.dirpath,maxdepth:10},e);const i=new s.Iterator(a(t,this.skipNodes)).map((t=>r(this,void 0,void 0,(function*(){this.log(e,"Preprocessing node:\n",t),yield n.resolveIncludes.call(this,t,e),yield n.rebaseRelativePaths.call(this,t,e)}))));yield Promise.all(i.generator())}))}renderNode(t,e){return r(this,void 0,void 0,(function*(){for(const i of a(t,this.skipNodes))this.log(e,"Rendering node:\n",i),yield n.resolveDataAttribute.call(this,i,e),yield n.resolveForAttribute.call(this,i,e),yield n.resolveHtmlAttribute.call(this,i,e),yield n.resolveShowAttribute.call(this,i,e),yield n.resolveWatchAttribute.call(this,i,e),yield n.resolveBindAttribute.call(this,i,e),yield n.resolvePropAttributes.call(this,i,e),yield n.resolveAttrAttributes.call(this,i,e),yield n.resolveEventAttributes.call(this,i,e),yield n.resolveTextNodeExpressions.call(this,i,e)}))}mount(t,e){return r(this,void 0,void 0,(function*(){yield this.preprocessNode(t,e),yield this.renderNode(t,e)}))}}e.IRenderer=h},150:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Iterator=void 0;class i{constructor(t){this.iterable=t}filter(t){return new i(i.filterGenerator(t,this.iterable))}map(t){return new i(i.mapGenerator(t,this.iterable))}array(){return Array.from(this.iterable)}*generator(){for(const t of this.iterable)yield t}static*filterGenerator(t,e){for(const i of e)t(i)&&(yield i)}static*mapGenerator(t,e){for(const i of e)yield t(i)}}e.Iterator=i},230:function(t,e,i){var r=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(o,s){function n(t){try{l(r.next(t))}catch(t){s(t)}}function a(t){try{l(r.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}l((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.resolveShowAttribute=e.resolveBindAttribute=e.resolveForAttribute=e.resolveEventAttributes=e.resolveAttrAttributes=e.resolvePropAttributes=e.resolveHtmlAttribute=e.resolveWatchAttribute=e.resolveDataAttribute=e.resolveTextNodeExpressions=e.rebaseRelativePaths=e.resolveIncludes=void 0;const o=i(885),s=i(283),n=new Set([":bind",":bind-events",":data",":for",":show","@watch","$html"]),a={$text:"$text-content"};e.resolveIncludes=function(t,e){return r(this,void 0,void 0,(function*(){var i,r,o,s;const n=t;if("include"!==(null===(i=n.tagName)||void 0===i?void 0:i.toLocaleLowerCase()))return;this.log(e,"<include> tag found in:\n",t),this.log(e,"<include> params:",e);const a=null===(r=n.getAttribute)||void 0===r?void 0:r.call(n,"src");if(!a)throw new Error(`"src" attribute missing from ${t}.`);const l=e=>{t.replaceWith(...Array.from(e.childNodes))},c=Object.assign(Object.assign({},e),{root:!1,maxdepth:e.maxdepth-1});if(0===c.maxdepth)throw new Error("Maximum recursion depth reached.");if(a.includes("://")||a.startsWith("//"))this.log(e,"Including remote file from absolute path:",a),yield this.preprocessRemote(a,c).then(l);else if((null===(o=e.dirpath)||void 0===o?void 0:o.includes("://"))||(null===(s=e.dirpath)||void 0===s?void 0:s.startsWith("//"))){const t=e.dirpath&&"."!==e.dirpath?`${e.dirpath}/${a}`:a;this.log(e,"Including remote file from relative path:",t),yield this.preprocessRemote(t,c).then(l)}else if("/"===a.charAt(0))this.log(e,"Including local file from absolute path:",a),yield this.preprocessLocal(a,c).then(l);else{const t=e.dirpath&&"."!==e.dirpath?`${e.dirpath}/${a}`:a;this.log(e,"Including local file from relative path:",t),yield this.preprocessLocal(t,c).then(l)}}))},e.rebaseRelativePaths=function(t,e){return r(this,void 0,void 0,(function*(){var i,r,o,n,a,l,c;const h=t,d=null===(i=h.tagName)||void 0===i?void 0:i.toLowerCase();if(!e.dirpath)return;const u=null===(o=(r=t).getAttribute)||void 0===o?void 0:o.call(r,"src"),v=null===(a=(n=t).getAttribute)||void 0===a?void 0:a.call(n,"href"),f=null===(c=(l=t).getAttribute)||void 0===c?void 0:c.call(l,"data"),p=u||v||f;p&&(p&&(0,s.isRelativePath)(p)&&this.log(e,"Rebasing relative path as:",e.dirpath,"/",p),"img"===d&&u&&(0,s.isRelativePath)(u)?h.src=`${e.dirpath}/${u}`:"a"===d&&v&&(0,s.isRelativePath)(v)||"link"===d&&v&&(0,s.isRelativePath)(v)?h.href=`${e.dirpath}/${v}`:"script"===d&&u&&(0,s.isRelativePath)(u)||"source"===d&&u&&(0,s.isRelativePath)(u)||"audio"===d&&u&&(0,s.isRelativePath)(u)||"video"===d&&u&&(0,s.isRelativePath)(u)||"track"===d&&u&&(0,s.isRelativePath)(u)||"iframe"===d&&u&&(0,s.isRelativePath)(u)?h.src=`${e.dirpath}/${u}`:"object"===d&&f&&(0,s.isRelativePath)(f)?h.data=`${e.dirpath}/${f}`:"input"===d&&u&&(0,s.isRelativePath)(u)?h.src=`${e.dirpath}/${u}`:("area"===d&&v&&(0,s.isRelativePath)(v)||"base"===d&&v&&(0,s.isRelativePath)(v))&&(h.href=`${e.dirpath}/${v}`))}))},e.resolveTextNodeExpressions=function(t,e){return r(this,void 0,void 0,(function*(){if(3!==t.nodeType)return;const i=t.nodeValue||"",o=new RegExp(/{{ ([^}]+) }}/gm),s=Array.from(i.matchAll(o)).map((t=>t[1])),n=()=>r(this,void 0,void 0,(function*(){let r=i;for(const i of s){const o=yield this.eval(i,{$elem:t},e);r=r.replace(`{{ ${i} }}`,String(o))}t.nodeValue=r})),[a,l]=yield this.trace(n);this.log(e,i,"=>",a),this.watch(l,n)}))},e.resolveDataAttribute=function(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const r=t,o=null===(i=r.getAttribute)||void 0===i?void 0:i.call(r,":data");if(o){this.log(e,":data attribute found in:\n",t),r.removeAttribute(":data");const i=yield this.eval(o,{$elem:t},e);this.log(e,":data",o,"=>",i),yield this.update(i)}}))},e.resolveWatchAttribute=function(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const r=t,o=null===(i=r.getAttribute)||void 0===i?void 0:i.call(r,"@watch");if(o){this.log(e,"@watch attribute found in:\n",t),r.removeAttribute("@watch");const i=()=>this.eval(o,{$elem:t},e),[s,n]=yield this.trace(i);this.log(e,"@watch",o,"=>",s),this.watch(n,i)}}))},e.resolveHtmlAttribute=function(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const o=t,s=null===(i=o.getAttribute)||void 0===i?void 0:i.call(o,"$html");if(s){this.log(e,"$html attribute found in:\n",t),o.removeAttribute("$html");const i=this.clone(),n=()=>r(this,void 0,void 0,(function*(){const r=yield this.eval(s,{$elem:t},e),n=yield i.preprocessString(r,e);yield i.renderNode(n,e),o.replaceChildren(n)})),[a,l]=yield this.trace(n);this.log(e,"$html",s,"=>",a),this.watch(l,n)}}))},e.resolvePropAttributes=function(t,e){return r(this,void 0,void 0,(function*(){if(this.skipNodes.has(t))return;const i=t;for(const s of Array.from(i.attributes||[]))if(s.name.startsWith("$")&&!n.has(s.name)){this.log(e,s.name,"attribute found in:\n",t),i.removeAttribute(s.name);const n=(a[s.name]||s.name).slice(1),l=()=>this.eval(s.value,{$elem:t},e),[c,h]=yield this.trace(l);this.log(e,s.name,s.value,"=>",c,`[${h}]`);const d=(0,o.attributeNameToCamelCase)(n);this.watch(h,(()=>r(this,void 0,void 0,(function*(){return t[d]=yield l()})))),t[d]=c}}))},e.resolveAttrAttributes=function(t,e){return r(this,void 0,void 0,(function*(){if(this.skipNodes.has(t))return;const i=t;for(const o of Array.from(i.attributes||[]))if(o.name.startsWith(":")&&!n.has(o.name)){this.log(e,o.name,"attribute found in:\n",t),i.removeAttribute(o.name);const s=(a[o.name]||o.name).slice(1),n=()=>this.eval(o.value,{$elem:t},e),[l,c]=yield this.trace(n);this.log(e,o.name,o.value,"=>",l,`[${c}]`),this.watch(c,(()=>r(this,void 0,void 0,(function*(){return i.setAttribute(s,yield n())})))),i.setAttribute(s,l)}}))},e.resolveEventAttributes=function(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const r=t;for(const o of Array.from(r.attributes||[]))o.name.startsWith("@")&&!n.has(o.name)&&(this.log(e,o.name,"attribute found in:\n",t),r.removeAttribute(o.name),null===(i=t.addEventListener)||void 0===i||i.call(t,o.name.substring(1),(i=>this.eval(o.value,{$elem:t,$event:i},e))))}))},e.resolveForAttribute=function(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const o=t,n=null===(i=o.getAttribute)||void 0===i?void 0:i.call(o,":for");if(n){this.log(e,":for attribute found in:\n",t),o.removeAttribute(":for");for(const e of(0,s.traverse)(t,this.skipNodes))this.skipNodes.add(e);const i=t.parentNode,a=t.ownerDocument.createElement("template");i.insertBefore(a,t),a.append(t),this.log(e,":for template:\n",a);const l=n.split(" in ",2);if(2!==l.length)throw new Error(`Invalid :for format: \`${n}\`. Expected "{key} in {expression}".`);let c=[],h=[];const[d,u]=l;try{[c,h]=yield this.trace((()=>this.eval(u,{$elem:t},e))),this.log(e,u,"=>",c,`[${h}]`)}catch(t){return void console.error(t)}const v=[],f=o=>r(this,void 0,void 0,(function*(){if(this.log(e,":for list items:",o),Array.isArray(o))return this.lock=this.lock.then((()=>new Promise((s=>r(this,void 0,void 0,(function*(){v.splice(0,v.length).forEach((t=>{i.removeChild(t),this.skipNodes.delete(t)}));for(const r of o.slice(0).reverse()){const o=this.clone();yield o.set(d,r);const s=t.cloneNode(!0);i.insertBefore(s,a.nextSibling),v.push(s),this.skipNodes.add(s),yield o.mount(s,e),this.log(e,"Rendered list child:\n",s)}s()})))))),this.lock;console.error(`Expression did not yield a list: \`${u}\` => \`${o}\``)}));return this.watch(h,(()=>r(this,void 0,void 0,(function*(){return f(yield this.eval(u,{$elem:t},e))})))),f(c)}}))},e.resolveBindAttribute=function(t,e){return r(this,void 0,void 0,(function*(){var i,r,o;if(this.skipNodes.has(t))return;const s=t,n=null===(i=s.getAttribute)||void 0===i?void 0:i.call(s,":bind");if(n){this.log(e,":bind attribute found in:\n",t);const i=["change","input"],a=(null===(o=null===(r=s.getAttribute)||void 0===r?void 0:r.call(s,":bind-events"))||void 0===o?void 0:o.split(","))||i;s.removeAttribute(":bind"),s.removeAttribute(":bind-events");const l="checkbox"===s.getAttribute("type")?"checked":"value";this.has(n)||(yield this.set(n,s[l])),s[l]=this.get(n);for(const e of a)t.addEventListener(e,(()=>this.set(n,s[l])));this.watch([n],(()=>s[l]=this.get(n)))}}))},e.resolveShowAttribute=function(t,e){return r(this,void 0,void 0,(function*(){var i;if(this.skipNodes.has(t))return;const o=t,s=null===(i=o.getAttribute)||void 0===i?void 0:i.call(o,":show");if(s){this.log(e,":show attribute found in:\n",t),o.removeAttribute(":show");const i=()=>this.eval(s,{$elem:t},e),[n,a]=yield this.trace(i);this.log(e,":show",s,"=>",n,`[${a}]`);const l="none"===o.style.display?"":o.style.display;n||(o.style.display="none"),this.watch(a,(()=>r(this,void 0,void 0,(function*(){o.style.display=(yield i())?l:"none"}))))}}))}},63:function(t,e){var i=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(o,s){function n(t){try{l(r.next(t))}catch(t){s(t)}}function a(t){try{l(r.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}l((r=r.apply(t,e||[])).next())}))};function r(t,e,i=!0){if(null==t||function(t){return t instanceof o||t.__is_proxy__}(t))return t;if(i)for(const i in t)t.hasOwnProperty(i)&&"object"==typeof t[i]&&null!=t[i]&&(t[i]=r(t[i],e));return new Proxy(t,{deleteProperty:(t,i)=>i in t&&(delete t[i],e(),!0),set:(t,o,s,n)=>{i&&"object"==typeof s&&(s=r(s,e));const a=Reflect.set(t,o,s,n);return e(),a},get:(t,e,i)=>"__is_proxy__"===e||Reflect.get(t,e,i)})}Object.defineProperty(e,"__esModule",{value:!0}),e.proxify=e.ReactiveProxyStore=e.InertProxy=e.ReactiveProxy=e.proxifyObject=void 0,e.proxifyObject=r;class o{constructor(t=null,...e){this.value=null,this.listeners=[],this.set(t),e.forEach((t=>this.watch(t)))}static from(t,...e){return t instanceof o?(e.forEach(t.watch),t):new o(t,...e)}get(){return this.value}set(t){return i(this,void 0,void 0,(function*(){if(this.value!==t){const e=this.value;null!=t&&"object"==typeof t&&(t=r(t,(()=>this.trigger()))),this.value=t,yield this.trigger(e)}}))}watch(t){this.listeners.push(t)}unwatch(t){this.listeners=this.listeners.filter((e=>e!==t))}trigger(){return i(this,arguments,void 0,(function*(t=null){for(const e of this.listeners)yield e(this.value,t)}))}}e.ReactiveProxy=o;class s extends o{static from(t,...e){return t instanceof o?t:new s(t,...e)}watch(t){}trigger(t){return Promise.resolve()}}function n(t){const e=Array.from(t.entries()).map((([t])=>t)),i=Object.fromEntries(e.map((t=>[t,void 0])));return new Proxy(Object.assign({},t,i),{get:(e,i,r)=>"string"==typeof i&&t.has(i)?t.get(i):Reflect.get(t,i,r),set:(e,i,r,o)=>("string"!=typeof i||i in t?Reflect.set(t,i,r,o):t.set(i,r),!0)})}e.InertProxy=s,e.ReactiveProxyStore=class{wrapFnValue(t){return t&&"function"==typeof t?(...e)=>t.call(n(this),...e):t}constructor(t){this.store=new Map,this.tracing=!1,this.traced=new Set,this.lock=Promise.resolve();for(const[e,i]of Object.entries(t||{}))this.store.set(e,o.from(this.wrapFnValue(i)))}get $(){return n(this)}entries(){return this.store.entries()}get(t){var e;return this.tracing&&this.traced.add(t),null===(e=this.store.get(t))||void 0===e?void 0:e.get()}set(t,e){return i(this,void 0,void 0,(function*(){this.store.has(t)?yield this.store.get(t).set(this.wrapFnValue(e)):this.store.set(t,o.from(this.wrapFnValue(e)))}))}del(t){return this.store.delete(t)}has(t){return this.store.has(t)}update(t){return i(this,void 0,void 0,(function*(){for(const[e,i]of Object.entries(t))yield this.set(e,i)}))}watch(t,e){(t=Array.isArray(t)?t:[t]).forEach((i=>this.store.get(i).watch((()=>e(...t.map((t=>this.store.get(t).get())))))))}trigger(t){return i(this,void 0,void 0,(function*(){for(const e of Array.isArray(t)?t:[t])yield this.store.get(e).trigger()}))}trace(t){return i(this,void 0,void 0,(function*(){yield this.lock;const e=new Promise(((e,r)=>i(this,void 0,void 0,(function*(){this.traced.clear(),this.tracing=!0;try{const i=yield t(),r=Array.from(this.traced);e([i,r])}catch(t){r(t)}finally{this.tracing=!1,this.traced.clear()}}))));return this.lock=e.then((()=>{})),e}))}computed(t,e){return i(this,void 0,void 0,(function*(){const[r,o]=yield this.trace((()=>e.call(n(this))));this.watch(o,(()=>i(this,void 0,void 0,(function*(){return this.set(t,yield e.call(n(this)))})))),this.set(t,r)}))}},e.proxify=n}},e={};!function i(r){var o=e[r];if(void 0!==o)return o.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,i),s.exports}(246)})();
@@ -0,0 +1,13 @@
1
+ import { RendererPlugin } from "./interfaces";
2
+ export declare const resolveIncludes: RendererPlugin;
3
+ export declare const rebaseRelativePaths: RendererPlugin;
4
+ export declare const resolveTextNodeExpressions: RendererPlugin;
5
+ export declare const resolveDataAttribute: RendererPlugin;
6
+ export declare const resolveWatchAttribute: RendererPlugin;
7
+ export declare const resolveHtmlAttribute: RendererPlugin;
8
+ export declare const resolvePropAttributes: RendererPlugin;
9
+ export declare const resolveAttrAttributes: RendererPlugin;
10
+ export declare const resolveEventAttributes: RendererPlugin;
11
+ export declare const resolveForAttribute: RendererPlugin;
12
+ export declare const resolveBindAttribute: RendererPlugin;
13
+ export declare const resolveShowAttribute: RendererPlugin;
@@ -0,0 +1,434 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.resolveShowAttribute = exports.resolveBindAttribute = exports.resolveForAttribute = exports.resolveEventAttributes = exports.resolveAttrAttributes = exports.resolvePropAttributes = exports.resolveHtmlAttribute = exports.resolveWatchAttribute = exports.resolveDataAttribute = exports.resolveTextNodeExpressions = exports.rebaseRelativePaths = exports.resolveIncludes = void 0;
13
+ const attributes_1 = require("./attributes");
14
+ const core_1 = require("./core");
15
+ const KW_ATTRIBUTES = new Set([
16
+ ":bind",
17
+ ":bind-events",
18
+ ":data",
19
+ ":for",
20
+ ":show",
21
+ "@watch",
22
+ "$html",
23
+ ]);
24
+ const ATTR_SHORTHANDS = {
25
+ $text: "$text-content",
26
+ // $html: "$inner-HTML",
27
+ };
28
+ const resolveIncludes = function (node, params) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ var _a, _b, _c, _d;
31
+ const elem = node;
32
+ // Early exit: node must be an <include> element.
33
+ if (((_a = elem.tagName) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) !== "include")
34
+ return;
35
+ this.log(params, "<include> tag found in:\n", node);
36
+ this.log(params, "<include> params:", params);
37
+ // Early exit: <include> tags must have a src attribute.
38
+ const src = (_b = elem.getAttribute) === null || _b === void 0 ? void 0 : _b.call(elem, "src");
39
+ if (!src) {
40
+ throw new Error(`"src" attribute missing from ${node}.`);
41
+ }
42
+ // The included file will replace this tag, and all elements will be fully preprocessed.
43
+ const handler = (fragment) => {
44
+ node.replaceWith(...Array.from(fragment.childNodes));
45
+ };
46
+ // Compute the subparameters being passed down to the included file.
47
+ const subparameters = Object.assign(Object.assign({}, params), { root: false, maxdepth: params.maxdepth - 1 });
48
+ if (subparameters.maxdepth === 0)
49
+ throw new Error("Maximum recursion depth reached.");
50
+ // Case 1: Absolute remote path.
51
+ if (src.includes("://") || src.startsWith("//")) {
52
+ this.log(params, "Including remote file from absolute path:", src);
53
+ yield this.preprocessRemote(src, subparameters).then(handler);
54
+ // Case 2: Relative remote path.
55
+ }
56
+ else if (((_c = params.dirpath) === null || _c === void 0 ? void 0 : _c.includes("://")) || ((_d = params.dirpath) === null || _d === void 0 ? void 0 : _d.startsWith("//"))) {
57
+ const relpath = params.dirpath && params.dirpath !== "." ? `${params.dirpath}/${src}` : src;
58
+ this.log(params, "Including remote file from relative path:", relpath);
59
+ yield this.preprocessRemote(relpath, subparameters).then(handler);
60
+ // Case 3: Local absolute path.
61
+ }
62
+ else if (src.charAt(0) === "/") {
63
+ this.log(params, "Including local file from absolute path:", src);
64
+ yield this.preprocessLocal(src, subparameters).then(handler);
65
+ // Case 4: Local relative path.
66
+ }
67
+ else {
68
+ const relpath = params.dirpath && params.dirpath !== "." ? `${params.dirpath}/${src}` : src;
69
+ this.log(params, "Including local file from relative path:", relpath);
70
+ yield this.preprocessLocal(relpath, subparameters).then(handler);
71
+ }
72
+ });
73
+ };
74
+ exports.resolveIncludes = resolveIncludes;
75
+ const rebaseRelativePaths = function (node, params) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a, _b, _c, _d, _e, _f, _g;
78
+ const elem = node;
79
+ const tagName = (_a = elem.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
80
+ // Early exit: if there is no dirpath, we cannot rebase relative paths.
81
+ if (!params.dirpath)
82
+ return;
83
+ // We have to retrieve the attribute, because the node property is always an absolute path.
84
+ const src = (_c = (_b = node).getAttribute) === null || _c === void 0 ? void 0 : _c.call(_b, "src");
85
+ const href = (_e = (_d = node).getAttribute) === null || _e === void 0 ? void 0 : _e.call(_d, "href");
86
+ const data = (_g = (_f = node).getAttribute) === null || _g === void 0 ? void 0 : _g.call(_f, "data");
87
+ // Early exit: if there is no element attribute to rebase, we can skip this step.
88
+ const anyattr = src || href || data;
89
+ if (!anyattr)
90
+ return;
91
+ if (anyattr && (0, core_1.isRelativePath)(anyattr)) {
92
+ this.log(params, "Rebasing relative path as:", params.dirpath, "/", anyattr);
93
+ }
94
+ if (tagName === "img" && src && (0, core_1.isRelativePath)(src)) {
95
+ elem.src = `${params.dirpath}/${src}`;
96
+ }
97
+ else if (tagName === "a" && href && (0, core_1.isRelativePath)(href)) {
98
+ elem.href = `${params.dirpath}/${href}`;
99
+ }
100
+ else if (tagName === "link" && href && (0, core_1.isRelativePath)(href)) {
101
+ elem.href = `${params.dirpath}/${href}`;
102
+ }
103
+ else if (tagName === "script" && src && (0, core_1.isRelativePath)(src)) {
104
+ elem.src = `${params.dirpath}/${src}`;
105
+ }
106
+ else if (tagName === "source" && src && (0, core_1.isRelativePath)(src)) {
107
+ elem.src = `${params.dirpath}/${src}`;
108
+ }
109
+ else if (tagName === "audio" && src && (0, core_1.isRelativePath)(src)) {
110
+ elem.src = `${params.dirpath}/${src}`;
111
+ }
112
+ else if (tagName === "video" && src && (0, core_1.isRelativePath)(src)) {
113
+ elem.src = `${params.dirpath}/${src}`;
114
+ }
115
+ else if (tagName === "track" && src && (0, core_1.isRelativePath)(src)) {
116
+ elem.src = `${params.dirpath}/${src}`;
117
+ }
118
+ else if (tagName === "iframe" && src && (0, core_1.isRelativePath)(src)) {
119
+ elem.src = `${params.dirpath}/${src}`;
120
+ }
121
+ else if (tagName === "object" && data && (0, core_1.isRelativePath)(data)) {
122
+ elem.data = `${params.dirpath}/${data}`;
123
+ }
124
+ else if (tagName === "input" && src && (0, core_1.isRelativePath)(src)) {
125
+ elem.src = `${params.dirpath}/${src}`;
126
+ }
127
+ else if (tagName === "area" && href && (0, core_1.isRelativePath)(href)) {
128
+ elem.href = `${params.dirpath}/${href}`;
129
+ }
130
+ else if (tagName === "base" && href && (0, core_1.isRelativePath)(href)) {
131
+ elem.href = `${params.dirpath}/${href}`;
132
+ }
133
+ });
134
+ };
135
+ exports.rebaseRelativePaths = rebaseRelativePaths;
136
+ const resolveTextNodeExpressions = function (node, params) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ if (node.nodeType !== 3)
139
+ return;
140
+ const content = node.nodeValue || "";
141
+ // Identify all the expressions found in the content.
142
+ const matcher = new RegExp(/{{ ([^}]+) }}/gm);
143
+ const expressions = Array.from(content.matchAll(matcher)).map((match) => match[1]);
144
+ const fn = () => __awaiter(this, void 0, void 0, function* () {
145
+ let updatedContent = content;
146
+ for (const expr of expressions) {
147
+ const result = yield this.eval(expr, { $elem: node }, params);
148
+ updatedContent = updatedContent.replace(`{{ ${expr} }}`, String(result));
149
+ }
150
+ node.nodeValue = updatedContent;
151
+ });
152
+ // Update the content now, and set up the listeners for future updates.
153
+ const [result, dependencies] = yield this.trace(fn);
154
+ this.log(params, content, "=>", result);
155
+ // Watch for updates, and re-execute function if needed.
156
+ this.watch(dependencies, fn);
157
+ });
158
+ };
159
+ exports.resolveTextNodeExpressions = resolveTextNodeExpressions;
160
+ const resolveDataAttribute = function (node, params) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ var _a;
163
+ if (this.skipNodes.has(node))
164
+ return;
165
+ const elem = node;
166
+ const dataAttr = (_a = elem.getAttribute) === null || _a === void 0 ? void 0 : _a.call(elem, ":data");
167
+ if (dataAttr) {
168
+ this.log(params, ":data attribute found in:\n", node);
169
+ elem.removeAttribute(":data");
170
+ const result = yield this.eval(dataAttr, { $elem: node }, params);
171
+ this.log(params, ":data", dataAttr, "=>", result);
172
+ yield this.update(result);
173
+ }
174
+ });
175
+ };
176
+ exports.resolveDataAttribute = resolveDataAttribute;
177
+ const resolveWatchAttribute = function (node, params) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ var _a;
180
+ if (this.skipNodes.has(node))
181
+ return;
182
+ const elem = node;
183
+ const watchAttr = (_a = elem.getAttribute) === null || _a === void 0 ? void 0 : _a.call(elem, "@watch");
184
+ if (watchAttr) {
185
+ this.log(params, "@watch attribute found in:\n", node);
186
+ // Remove the attribute from the node.
187
+ elem.removeAttribute("@watch");
188
+ // Compute the function's result and trace dependencies.
189
+ const fn = () => this.eval(watchAttr, { $elem: node }, params);
190
+ const [result, dependencies] = yield this.trace(fn);
191
+ this.log(params, "@watch", watchAttr, "=>", result);
192
+ // Watch for updates, and re-execute function if needed.
193
+ this.watch(dependencies, fn);
194
+ }
195
+ });
196
+ };
197
+ exports.resolveWatchAttribute = resolveWatchAttribute;
198
+ const resolveHtmlAttribute = function (node, params) {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ var _a;
201
+ if (this.skipNodes.has(node))
202
+ return;
203
+ const elem = node;
204
+ const htmlAttr = (_a = elem.getAttribute) === null || _a === void 0 ? void 0 : _a.call(elem, "$html");
205
+ if (htmlAttr) {
206
+ this.log(params, "$html attribute found in:\n", node);
207
+ // Remove the attribute from the node.
208
+ elem.removeAttribute("$html");
209
+ // Obtain a subrenderer for the node contents.
210
+ const subrenderer = this.clone();
211
+ // Compute the function's result and trace dependencies.
212
+ const fn = () => __awaiter(this, void 0, void 0, function* () {
213
+ const html = yield this.eval(htmlAttr, { $elem: node }, params);
214
+ const fragment = yield subrenderer.preprocessString(html, params);
215
+ yield subrenderer.renderNode(fragment, params);
216
+ elem.replaceChildren(fragment);
217
+ });
218
+ const [result, dependencies] = yield this.trace(fn);
219
+ this.log(params, "$html", htmlAttr, "=>", result);
220
+ // Watch for updates, and re-execute function if needed.
221
+ this.watch(dependencies, fn);
222
+ }
223
+ });
224
+ };
225
+ exports.resolveHtmlAttribute = resolveHtmlAttribute;
226
+ const resolvePropAttributes = function (node, params) {
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ if (this.skipNodes.has(node))
229
+ return;
230
+ const elem = node;
231
+ for (const attr of Array.from(elem.attributes || [])) {
232
+ if (attr.name.startsWith("$") && !KW_ATTRIBUTES.has(attr.name)) {
233
+ this.log(params, attr.name, "attribute found in:\n", node);
234
+ // Remove the attribute from the node.
235
+ elem.removeAttribute(attr.name);
236
+ // Apply any shorthand conversions if necessary.
237
+ const propName = (ATTR_SHORTHANDS[attr.name] || attr.name).slice(1);
238
+ // Compute the function's result and trace dependencies.
239
+ const fn = () => this.eval(attr.value, { $elem: node }, params);
240
+ const [result, dependencies] = yield this.trace(fn);
241
+ this.log(params, attr.name, attr.value, "=>", result, `[${dependencies}]`);
242
+ // Set the requested property value on the original node, and watch for updates.
243
+ const prop = (0, attributes_1.attributeNameToCamelCase)(propName);
244
+ this.watch(dependencies, () => __awaiter(this, void 0, void 0, function* () { return (node[prop] = yield fn()); }));
245
+ node[prop] = result;
246
+ }
247
+ }
248
+ });
249
+ };
250
+ exports.resolvePropAttributes = resolvePropAttributes;
251
+ const resolveAttrAttributes = function (node, params) {
252
+ return __awaiter(this, void 0, void 0, function* () {
253
+ if (this.skipNodes.has(node))
254
+ return;
255
+ const elem = node;
256
+ for (const attr of Array.from(elem.attributes || [])) {
257
+ if (attr.name.startsWith(":") && !KW_ATTRIBUTES.has(attr.name)) {
258
+ this.log(params, attr.name, "attribute found in:\n", node);
259
+ // Remove the processed attributes from node.
260
+ elem.removeAttribute(attr.name);
261
+ // Apply any shorthand conversions if necessary.
262
+ const attrName = (ATTR_SHORTHANDS[attr.name] || attr.name).slice(1);
263
+ // Compute the function's result and trace dependencies.
264
+ const fn = () => this.eval(attr.value, { $elem: node }, params);
265
+ const [result, dependencies] = yield this.trace(fn);
266
+ this.log(params, attr.name, attr.value, "=>", result, `[${dependencies}]`);
267
+ // Set the requested property value on the original node, and watch for updates.
268
+ this.watch(dependencies, () => __awaiter(this, void 0, void 0, function* () { return elem.setAttribute(attrName, yield fn()); }));
269
+ elem.setAttribute(attrName, result);
270
+ }
271
+ }
272
+ });
273
+ };
274
+ exports.resolveAttrAttributes = resolveAttrAttributes;
275
+ const resolveEventAttributes = function (node, params) {
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ var _a;
278
+ if (this.skipNodes.has(node))
279
+ return;
280
+ const elem = node;
281
+ for (const attr of Array.from(elem.attributes || [])) {
282
+ if (attr.name.startsWith("@") && !KW_ATTRIBUTES.has(attr.name)) {
283
+ this.log(params, attr.name, "attribute found in:\n", node);
284
+ // Remove the processed attributes from node.
285
+ elem.removeAttribute(attr.name);
286
+ (_a = node.addEventListener) === null || _a === void 0 ? void 0 : _a.call(node, attr.name.substring(1), (event) => this.eval(attr.value, { $elem: node, $event: event }, params));
287
+ }
288
+ }
289
+ });
290
+ };
291
+ exports.resolveEventAttributes = resolveEventAttributes;
292
+ const resolveForAttribute = function (node, params) {
293
+ return __awaiter(this, void 0, void 0, function* () {
294
+ var _a;
295
+ if (this.skipNodes.has(node))
296
+ return;
297
+ const elem = node;
298
+ const forAttr = (_a = elem.getAttribute) === null || _a === void 0 ? void 0 : _a.call(elem, ":for");
299
+ if (forAttr) {
300
+ this.log(params, ":for attribute found in:\n", node);
301
+ // Remove the processed attributes from node.
302
+ elem.removeAttribute(":for");
303
+ // Ensure the node and its children are not processed by subsequent steps.
304
+ for (const child of (0, core_1.traverse)(node, this.skipNodes)) {
305
+ this.skipNodes.add(child);
306
+ }
307
+ // Place the template node into a template element.
308
+ const parent = node.parentNode;
309
+ const template = node.ownerDocument.createElement("template");
310
+ parent.insertBefore(template, node);
311
+ template.append(node);
312
+ this.log(params, ":for template:\n", template);
313
+ // Tokenize the input by splitting it based on the format "{key} in {expression}".
314
+ const tokens = forAttr.split(" in ", 2);
315
+ if (tokens.length !== 2) {
316
+ throw new Error(`Invalid :for format: \`${forAttr}\`. Expected "{key} in {expression}".`);
317
+ }
318
+ // Compute the container expression and trace dependencies.
319
+ let items = [];
320
+ let deps = [];
321
+ const [loopKey, itemsExpr] = tokens;
322
+ try {
323
+ [items, deps] = yield this.trace(() => this.eval(itemsExpr, { $elem: node }, params));
324
+ this.log(params, itemsExpr, "=>", items, `[${deps}]`);
325
+ }
326
+ catch (exc) {
327
+ console.error(exc);
328
+ return;
329
+ }
330
+ // Keep track of all the child nodes added.
331
+ const children = [];
332
+ // Define the function that will update the DOM.
333
+ const fn = (items) => __awaiter(this, void 0, void 0, function* () {
334
+ this.log(params, ":for list items:", items);
335
+ // Validate that the expression returns a list of items.
336
+ if (!Array.isArray(items)) {
337
+ console.error(`Expression did not yield a list: \`${itemsExpr}\` => \`${items}\``);
338
+ return;
339
+ }
340
+ // Acquire the lock atomically.
341
+ this.lock = this.lock.then(() => new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
342
+ // Remove all the previously added children, if any.
343
+ children.splice(0, children.length).forEach((child) => {
344
+ parent.removeChild(child);
345
+ this.skipNodes.delete(child);
346
+ });
347
+ // Loop through the container items in reverse, because we insert from back to front.
348
+ for (const item of items.slice(0).reverse()) {
349
+ // Create a subrenderer that will hold the loop item and all node descendants.
350
+ const subrenderer = this.clone();
351
+ yield subrenderer.set(loopKey, item);
352
+ // Create a new HTML element for each item and add them to parent node.
353
+ const copy = node.cloneNode(true);
354
+ parent.insertBefore(copy, template.nextSibling);
355
+ // Also add the new element to the store.
356
+ children.push(copy);
357
+ // Since the element will be handled by a subrenderer, skip it in parent renderer.
358
+ this.skipNodes.add(copy);
359
+ // Render the element using the subrenderer.
360
+ yield subrenderer.mount(copy, params);
361
+ this.log(params, "Rendered list child:\n", copy);
362
+ }
363
+ // Release the lock.
364
+ resolve();
365
+ })));
366
+ // Return the lock so the whole operation can be awaited.
367
+ return this.lock;
368
+ });
369
+ // Apply changes, and watch for updates in the dependencies.
370
+ this.watch(deps, () => __awaiter(this, void 0, void 0, function* () { return fn(yield this.eval(itemsExpr, { $elem: node }, params)); }));
371
+ return fn(items);
372
+ }
373
+ });
374
+ };
375
+ exports.resolveForAttribute = resolveForAttribute;
376
+ const resolveBindAttribute = function (node, params) {
377
+ return __awaiter(this, void 0, void 0, function* () {
378
+ var _a, _b, _c;
379
+ if (this.skipNodes.has(node))
380
+ return;
381
+ const elem = node;
382
+ const bindKey = (_a = elem.getAttribute) === null || _a === void 0 ? void 0 : _a.call(elem, ":bind");
383
+ if (bindKey) {
384
+ this.log(params, ":bind attribute found in:\n", node);
385
+ // The change events we listen for can be overriden by user.
386
+ const defaultEvents = ["change", "input"];
387
+ const updateEvents = ((_c = (_b = elem.getAttribute) === null || _b === void 0 ? void 0 : _b.call(elem, ":bind-events")) === null || _c === void 0 ? void 0 : _c.split(",")) || defaultEvents;
388
+ // Remove the processed attributes from node.
389
+ elem.removeAttribute(":bind");
390
+ elem.removeAttribute(":bind-events");
391
+ // If the element is of type checkbox, we bind to the "checked" property.
392
+ const prop = elem.getAttribute("type") === "checkbox" ? "checked" : "value";
393
+ // If the key is not found in our store, create it and initialize it with the node's value.
394
+ if (!this.has(bindKey))
395
+ yield this.set(bindKey, elem[prop]);
396
+ // Set the node's value to our current value.
397
+ elem[prop] = this.get(bindKey);
398
+ // Watch for updates in the node's value.
399
+ for (const event of updateEvents) {
400
+ node.addEventListener(event, () => this.set(bindKey, elem[prop]));
401
+ }
402
+ // Watch for updates in the store.
403
+ this.watch([bindKey], () => (elem[prop] = this.get(bindKey)));
404
+ }
405
+ });
406
+ };
407
+ exports.resolveBindAttribute = resolveBindAttribute;
408
+ const resolveShowAttribute = function (node, params) {
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ var _a;
411
+ if (this.skipNodes.has(node))
412
+ return;
413
+ const elem = node;
414
+ const showExpr = (_a = elem.getAttribute) === null || _a === void 0 ? void 0 : _a.call(elem, ":show");
415
+ if (showExpr) {
416
+ this.log(params, ":show attribute found in:\n", node);
417
+ // Remove the processed attributes from node.
418
+ elem.removeAttribute(":show");
419
+ // Compute the function's result and trace dependencies.
420
+ const fn = () => this.eval(showExpr, { $elem: node }, params);
421
+ const [result, dependencies] = yield this.trace(fn);
422
+ this.log(params, ":show", showExpr, "=>", result, `[${dependencies}]`);
423
+ // If the result is false, set the node's display to none.
424
+ const display = elem.style.display === "none" ? "" : elem.style.display;
425
+ if (!result)
426
+ elem.style.display = "none";
427
+ // Watch the dependencies, and re-evaluate the expression.
428
+ this.watch(dependencies, () => __awaiter(this, void 0, void 0, function* () {
429
+ elem.style.display = (yield fn()) ? display : "none";
430
+ }));
431
+ }
432
+ });
433
+ };
434
+ exports.resolveShowAttribute = resolveShowAttribute;