ensojs 1.0.0-rc.10 → 1.0.0-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ensojs.es.js +1 -1
- package/dist/errors.es.js +1 -0
- package/package.json +6 -2
package/dist/ensojs.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=Symbol("enso.internal"),e=Symbol("enso.scheduleUpdate"),n=Symbol("enso.scheduleEffect"),r=Symbol("enso.attachTemplates"),s=Symbol("enso.markChanged"),o=Symbol("enso.addChild"),i=Symbol("enso.update"),c=Symbol("enso.getBinding"),a=Symbol("enso.setBinding"),h=Symbol("enso.taskList"),u=Symbol("enso.bindings"),d=Symbol("enso.children"),l=Symbol("enso.anchor"),p=Symbol("enso.nodes"),f=Symbol("enso.root"),m=Symbol("enso.env"),b="ENSO-FRAGMENT",g="data-enso-node",w="data-enso-root",y="data-enso-fragment",E=Object.freeze({Window:{},Document:{},eval:null,Function:null,setTimeout:null}),v=Object.freeze({parse:(t,...e)=>{let n=!1;const r=t.reduce((t,r,s)=>{const o=e[s];return!0===o&&(n=!0),t+r+(!0!==(i=o)&&!1!==i&&null!=i?o:"");var i},"");return!(!n||r)||r},...E}),A=(t={},e=v)=>Object.freeze(Object.assign(Object.create(e),t)),N=t=>`(()=>parse\`${t.replaceAll("{{","${").replaceAll("}}","}").trim()}\`)`;class S{#t;#e;constructor(t,e,n){this.#t=e;try{this.#e=n.createFunc(t)}catch(r){console.error("[Enso] Error instantiating effect:\n",r,n),this.#e=()=>{}}}get element(){return this.#t}get action(){return this.#e}run(){try{return this.#e?.()}catch(t){return void console.error("[Enso] Error running effect:\n",t,this.#e.toString())}}}class O{#n;#r;#s;#o;constructor(t,e={},n=S){this.#r=t,this.#n=n,this.#s=e,this.#o=(t=>{const e=(t=>`with (env) {\n return (() => {\n "use strict";\n try { return ${t}; } catch(e) {\n console.error('[Enso] Runtime error in effect:', e);\n return undefined;\n }\n })();\n }`)(t);try{return new Function("env",e)}catch(n){return console.error("[Enso] Error in effect: ",n,"\n",e),()=>()=>{}}})(t)}get data(){return this.#s}get code(){return this.#r}createEffect(t,e){return new this.#n(t,e,this)}createFunc(t){const{component:e,[m]:n}=t,r=this.#o.call(e,n);if("function"!=typeof r)throw new TypeError("[Enso] Expected function but got "+typeof r);return r}}const _=(e,n)=>{const r=class extends e{constructor(){super(t)}};if(!n)return r;const s=typeof n;if("object"!==s)throw new Error(`Component expected object litteral but got ${s}`);const o=Object.getOwnPropertyDescriptors(n);for(const t in o)Object.defineProperty(r.prototype,t,o[t]);return r},T=(t=Object)=>class extends t{#i;#c=/* @__PURE__ */new Set;#a=[];constructor(){super(),this[i]=this[i].bind(this),this[s]=this[s].bind(this)}get[u](){return this.#i}set[u](t){this.#i=t}get[h](){return this.#c}get[d](){return this.#a}[o](t){this.#a.push(t)}[c](t){return this.#i.get(t)}[a](t,e){const n=this[c](t);n&&(n.effects.push(e),n.changed=!0)}[n](t){this.#c.add(t)}[s](t){const r=this.#i.get(t);if(r&&!r.changed){r.changed=!0;for(const t of r.effects)this[n](t);this[e]()}for(const e of this.#a)e[s](t)}[i](){for(const e of this.#c)e.run();this.#c.clear();for(const e of this.#i.values())e.changed=!1;const t=[...this.#a];for(const e of t)e[i]()}},j=Object.freeze({mount:"lifecycle:mount",update:"lifecycle:update",unmount:"lifecycle:unmount"}),P=Object.values(j);class C extends(T(HTMLElement)){#h=!1;#u=null;#d=!1;#l;#p=/* @__PURE__ */Object.create(null);#f=A(this.expose);#m(){return this.shadowRoot??this.attachShadow({mode:this.settings.shadowMode})}constructor(e){if(super(),e!==t)throw new Error("Direct subclassing of Enso is not supported.\nUse Enso.component() instead.");this.#l=new this.constructor.WatchedClass(this),this[u]=this.#l[u],this.#u=this.settings.useShadow?this.#m():this}get refs(){return this.#p}get component(){return this}get isAttached(){return this.#h}get watched(){return this.#l}get[f](){return this.#u}get[m](){return this.#f}connectedCallback(){if(this.#h)return;this.#h=!0;const t=this.observedAttributes;for(const e of t)this.watched._defs[e].attribute.force&&this.reflectAttribute(e);this[r](this.template.process(this,this.template)),this.styles&&((t,e)=>{const n=t instanceof ShadowRoot?t:t.getRootNode();(n instanceof Document||n instanceof ShadowRoot)&&(n.adoptedStyleSheets=[...n.adoptedStyleSheets,...e])})(this[f],this.styles),this[i]()}disconnectedCallback(){this.#l._notify(j.unmount)}attributeChangedCallback(t,e,n){if(e===n)return;const r=this.watched._defs[t].attribute.toProp(n);this.watched[t]!==r&&(this.watched[t]=r)}[r](t){const e=Array.from(t.firstElementChild.childNodes);this[f].append(...e),this.#l._notify(j.mount)}reflectAttribute(t){const e=this.#l._defs[t],n=e.attribute.toAttr(this.watched[t]);n!==this.getAttribute(e.name)&&(null===n?this.removeAttribute(e.name):this.setAttribute(e.name,n))}[e](){this.#d||(this.#d=!0,requestAnimationFrame(this[i]))}[i](){this.#d=!1,super[i](),this.#l._notify(j.update)}}const $=t=>{const e=document.createElement("template");return e.content.appendChild("string"==typeof t?(t=>document.createRange().createContextualFragment(t))(t):t),e},k=t=>{const e=t instanceof HTMLTemplateElement?t:$(t);return e.content.querySelectorAll("script").forEach(t=>t.remove()),e},M="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",R=(t=6)=>{let e="",n=Math.max(0,Math.trunc(t));for(;n--;)e+=M[Math.trunc(64*Math.random())];return e},L=t=>t.nodeType===Node.TEXT_NODE?t.parentElement:t;class x{#b;#g;#w;#y;#E=[];#v=[];#A=[];#N;#S=/* @__PURE__ */new Set;constructor(t,e,n){this.#b=t,this.#g=n,this.#w=e}get id(){return this.#b}get node(){return this.#w}get map(){return this.#g}get ref(){return this.#y}set ref(t){this.#y=t,this.markWatched()}addEvent(t,e){this.#v.push({name:t,action:e}),this.markWatched()}get events(){return this.#v}addAttribute(t,e,n){this.#E.push({name:t,action:e,binds:n}),this.markWatched()}get attributes(){return this.#E}addContent(t,e,n,r){this.#A.push({parent:t,index:e,action:n,binds:r}),this.markWatched()}get content(){return this.#A}setDirective({type:t=this.#N?.type,template:e=this.#N?.template,action:n=this.#N?.effect,binds:r=this.#N?.binds}={}){this.#N={type:t,template:e,action:n,binds:r}}get directive(){return this.#N}attachParser(t){this.#S.add(t)}get parsers(){return this.#S}markRoot(t=!1){this.#w?.setAttribute(w,t?this.#b:"")}unRoot(){this.#w?.removeAttribute(w)}isRoot(){return this.#w?.hasAttribute(w)}markWatched(t=!0){const e=L(this.#w);e.hasAttribute(g)||e.setAttribute(g,this.#b),t&&this.#g.add(this)}unWatch(){const t=L(this.#w);t?.removeAttribute(g)}isWatched(){return this.#w?.hasAttribute(g)}replaceNode(t){const e=this.#w;return this.#w.replaceWith(t),this.#w=t,this.markWatched(!1),e}}class W{#g=/* @__PURE__ */new Map;get size(){return this.#g.size}add(t){this.#g.has(t.id)||this.#g.set(t.id,t)}get(t){return this.#g.has(t)?this.#g.get(t):null}getByNode(t){if(!t?.hasAttribute(g))return null;const e=t.getAttribute(g);return this.#g.get(e)}getByRoot(t){if(!t?.hasAttribute(w))return null;const e=t.getAttribute(w);return this.#g.get(e)}create(t){const e=L(t).getAttribute(g);return this.#g.has(e)?this.#g.get(e):new x(R(),t,this)}createRoot(t){const e=new x(R(),t,this);return e.markRoot(!0),this.add(e),e}[Symbol.iterator](){return this.#g.values()}}const D=(()=>{const t=[],e=[];return Object.freeze({registerNode(e){t.push(e)},registerAttr(t){e.push(t)},getNodeParser(e){for(const n of t)if(n.match(e))return n;return null},getAttrParser(t,n){for(const r of e)if(r.match(t,n))return r;return null},markRoot(t){t.setAttribute(w,"")},getRoot:t=>t.querySelector(`[${w}]:not([${w}="COMPONENT"])`),isParsed:t=>t.hasAttribute(y),getWatched:t=>t.querySelector(`[${g}]`),preprocess(t,e){let n=!1;const r=this.getNodeParser(e);if(r&&(n=r.preprocess(t,e)),e.attributes?.length){const r=[...e.attributes];for(const s of r){const r=this.getAttrParser(e,s);r&&(n=r.preprocess(t,e,s)||n)}}return n},process(t,e,n){for(const r of t.parsers)r.process(t,e,n);n.removeAttribute(g)}})})(),F=(t,e=1)=>{const n=t.name;if(n.startsWith("enso-")){const t=n.indexOf(":");if(t>-1)return n.slice(t+1).toLowerCase()}return n.slice(e).toLowerCase()},z=(t,e,n=null)=>{if(!t?.name)return!1;const r=t.name;return!!r.startsWith(e)||!!n&&r.startsWith(`enso-${n}:`)},B=/(?:this\.watched\.|watched:|@:)([A-Za-z_$][\w$]*)/g,q=/(?:this\.refs\.|ref:|#:)([A-Za-z_$][\w$]*)/g,H=(t,e=null)=>{const n=t.replace(B,(t,n)=>(e&&e.add(n),`this.watched.${n}`)).replace(q,(t,e)=>`this.refs.${e}`);return e&&e.add(j.mount),n},I=(t,e,r)=>{t[a](e,r),t[n](r)},X=()=>document.createElement("template"),U=(t,e,n)=>{if(!t)return null;const r=t.getAttributeNode(e)??t.getAttributeNode(n);return r&&t.removeAttribute(r.name),r?.value??null},V=/({{(.|\n)*}})/;class J extends S{run(){const t=super.run();this.element&&t&&(this.element.textContent=t)}}D.registerNode({type:"text",match:t=>t.nodeType===Node.TEXT_NODE&&V.test(t.nodeValue),preprocess(t,e){const n=/* @__PURE__ */new Set,r=N(H(e.nodeValue,n));return t.addContent(e.parentNode,((t,e)=>Array.prototype.indexOf.call(t.childNodes,e))(e.parentNode,e),new O(r,{},J),n),t.attachParser(this),!0},process(t,e,n){if(t.content)for(const r of t.content){const t=n.childNodes[r.index],s=r.action.createEffect(e,t);for(const n of r.binds)I(e,n,s)}}});class Z extends S{#O;constructor(t,e,n){super(t,e,n),this.#O=n.data.name}run(){const t=super.run(),e=this.element;t?e.setAttribute(this.#O,!0===t?"":t):e.removeAttribute(this.#O)}}function G(t,e,n){const{name:r,action:s}=n;try{const n=s.createFunc(t);e.addEventListener(r.toLowerCase(),n.bind(t.component))}catch(o){console.error("[Enso] - ",o),e.addEventListener(r.toLowerCase(),()=>console.warn(`[Enso] Invalid handler for event '${r}'`))}}if(D.registerAttr({type:"attr",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&z(e,":","attr"),preprocess(t,e,n){const r=F(n),s=/* @__PURE__ */new Set,o=N(H(n.value,s));return t.addAttribute(r,new O(o,{name:r},Z),s),e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){if(t.attributes)for(const r of t.attributes){const t=r.action.createEffect(e,n);for(const n of r.binds)I(e,n,t)}}}),D.registerAttr({type:"event",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&z(e,"@","evt"),preprocess(t,e,n){const r=H(n.value);return t.addEvent(F(n),new O(r)),e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){if(t.events?.length)for(const r of t.events)G(e,n,r)}}),D.registerAttr({type:"ref",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&("#ref"===e.name||"enso-ref"===e.name),preprocess(t,e,n){return t.ref=n.value,e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){t.ref&&Object.defineProperty(e.component.refs,t.ref,{value:n,writable:!1,configurable:!1})}}),!customElements.get(b.toLowerCase())){class t extends HTMLElement{}customElements.define(b.toLowerCase(),t)}class K extends(T()){#_;#T;#j;#P=null;#u=null;#f;#C=!1;constructor(t,e,n){super(),this.#_=t.component,this.#T=t,this.#f=t[m],n&&(this.#j=document.createComment(this.tag),n.replaceWith(this.#j)),t[o](this);const r=/* @__PURE__ */new Map;for(const[s,o]of this.#_[u])r.set(s,{changed:!1,watchers:o.watchers,effects:[]});this[u]=r,this._processTemplate(e)}_processTemplate(t){t&&(this.#u=t.process(this))}_getChildren(){this.#P=Array.from(this.#u.childNodes)}get tag(){return"enso:fragment"}get component(){return this.#_}get isAttached(){return this.#C}set isAttached(t){this.#C=t}get[l](){return this.#j}get[p](){return this.#P}get[m](){return this.#f}set[m](t){this.#f=A(t,this.#T[m])}get#$(){return this.#T.isAttached}[e](){this.#_[e]()}mount(){!this.#C&&this.#$&&(this._getChildren(),this.#j.after(...this.#P),this.#C=!0,this[i]())}[i](){this.#C&&super[i]()}unmount(){this.#C&&(this.#u.append(...this.#P),this.#P=null,this.#C=!1)}}class Q extends K{#k;constructor(t,e,n,r){super(t,e,n),this.#k=r.createEffect(t,null)}get tag(){return"enso:if"}run(){this.#k.run()?this.mount():this.unmount()}}D.registerNode({type:"if",match:t=>t.nodeType===Node.ELEMENT_NODE&&(t.hasAttribute("*if")||t.hasAttribute("enso-if")),preprocess(t,e){if(t.directive)return!1;let n=U(e,"*if","enso-if");const r=/* @__PURE__ */new Set;n=H(n,r);const s=new O(N(n)),o=t.map.createRoot(e);return o.setDirective({type:"if",action:s,binds:r}),o.attachParser(this),!0},process(t,e,n){if("if"===t?.directive?.type){const r=new Q(e,t.directive.template,n,t.directive.action);for(const n of t.directive.binds)I(e,n,r)}}});const Y=t=>t.includes(":")?Y(t.split(":")[1]):t.includes("=")?Y(t.split("=")[0]):t.trim(),tt=t=>{const[e]=t.split(/\b(?:of|in)\b(?!.*\b(of|in)\b)/).filter(Boolean),n=(t=>{const e={"{":"}","[":"]","}":"{","]":"["},n=[{token:"",capturing:!0}];let r=!0;const s=t=>{const s=n.at(-1).capturing&&r;n.push({token:e[t],capturing:s}),r=!0},o=t=>{if(t!==n.pop().token)throw new Error("mismatched brackets");r=!1},i={",":()=>{r=!0},"{":s,"[":s,"}":o,"]":o},c=t.split(/([{}[\],])/).map(t=>{if(t?.trim())return i[t]?i[t](t):n.at(-1).capturing?(r=!1,":"===t.trim().at(-1)&&(r=!0),Y(t)):void 0}).filter(Boolean);if(n.length>1)throw new Error("mismatched brackets");return c})(e);return n};class et extends K{constructor(t,e,n){super(t),this[m]=n,this._processTemplate(e)}mount(){return this.isAttached=!0,this[i](),this._getChildren(),this[p]}}class nt extends K{#k;#M;constructor(t,e,n,r){super(t,null,n),this.#k=r.createEffect(t,null),this.#M=e}get tag(){return"enso:for"}run(){this.mount()}mount(){this.unmount();const t=[],e=this.#k.run();for(const n of e){const e=new et(this,this.#M,n);t.push(...e.mount())}this[l].after(...t),this.isAttached=!0,this[i]()}unmount(){for(const t of this[d])t.unmount();this[d].length=0,this.isAttached=!1}}D.registerNode({type:"for",match:t=>t.nodeType===Node.ELEMENT_NODE&&(t.hasAttribute("*for")||t.hasAttribute("enso-for")),preprocess(t,e){if(t.directive)return!1;const n=/* @__PURE__ */new Set,r=H(U(e,"*for","enso-for"),n),s=tt(r),o=new O(`(function* () {\n try {\n for (const ${r}) {\n yield { ${s.join(", ")} };\n }\n } catch(e) {\n console.error('Runtime error in for loop:', e);\n }\n }).bind(this);/*js*/`);const i=t.map.createRoot(e);return i.setDirective({type:"for",action:o,binds:n}),i.attachParser(this),!0},process(t,e,n){if("for"===t?.directive?.type){const r=new nt(e,t.directive.template,n,t.directive.action);for(const n of t.directive.binds)I(e,n,r)}}});const rt=/{{[^]*}}/,st=t=>(t=>t.nodeType===Node.ELEMENT_NODE&&t.hasAttribute("enso:ignore"))(t)||(t=>t.parentNode?.hasAttribute("enso:ignore-children"))(t)?NodeFilter.FILTER_REJECT:t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&rt.test(t.nodeValue)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT,ot=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT;class it{#M=null;#l;constructor(t,e=new W){const n=k(t);this.#l=e,this.#M=this.#R(n),this.#L()}#R(t){if(D.isParsed(t))return t;const e=(t=>{const e=document.createElement(b);return e.append(t),e})(t.content);e.setAttribute(w,"COMPONENT"),t.content.append(e);const n=(t=>document.createTreeWalker(t,ot,{acceptNode:st}))(e);let r;for(;r=n.nextNode();){const t=this.#l.create(r);D.preprocess(t,r)}return t.setAttribute(y,""),this.#l,t}#L(){const t=this.#M.content;let e;for((t=>{const e=t.querySelectorAll(`${b}:not([${w}])`);for(const n of e){const t=[...n.childNodes];0!==t.length?n.replaceWith(...t):n.remove()}})(t);e=D.getRoot(t);){const t=this.#l.getByRoot(e);t.unRoot(),t.replaceNode(X());const n=k(e);n.setAttribute(y,""),t.directive.template=new it(n,this.#l,!0)}}process(t){const e=this.#M.content.cloneNode(!0);let n;for(;n=D.getWatched(e);){const e=this.#l.getByNode(n);D.process(e,t,n)}return e}clone(){const t=this.#M.cloneNode(!0);return new it(t,this.#l)}get watchedNodes(){return this.#l}get template(){return this.#M}}const ct=(t,...e)=>"string"==typeof t?t:t.reduce((t,n,r)=>t+n+(e[r]||""),""),at=(t,...e)=>(t=>{const e=new CSSStyleSheet;return e.replaceSync(t),e})(ct(t,...e)),ht=(t,...e)=>new it(ct(t,...e)),ut=(t,e,n=null)=>{const r=(e="")=>{const r=(t=>{if(!t)return"";let e="";for(const[n,r]of Object.entries(t))if(!0===r)e+=` ${n}`;else{if(!1===r||null==r)continue;e+=` ${n}="${String(r)}"`}return e})(n);return e?`<${t}${r}>${e}</${t}>`:`<${t}${r}></${t}>`};function s(s,...o){if(!Array.isArray(s)||!s.raw){const r={...n||{},...s};return ut(t,e,r)}const i=String.raw(s,...o);return r(i)}return Object.defineProperties(s,{toString:{value:()=>r(),enumerable:!1},[Symbol.toPrimitive]:{value:()=>r(),enumerable:!1},Class:{get:()=>e,enumerable:!1},tag:{value:t,enumerable:!0},attrs:{value:n,enumerable:!1}}),Object.freeze(s)},dt=/* @__PURE__ */new WeakMap,lt=/* @__PURE__ */new WeakMap,pt=(t,e)=>({get(n,r,s){const o=Reflect.get(n,r,s);return"object"==typeof o&&null!==o&&o?gt(o,e,t):o},set(n,r,s,o){const i=n[r],c=Reflect.set(n,r,s,o);return i!==s&&t(e),c},deleteProperty(n,r){const s=Object.prototype.hasOwnProperty.call(n,r),o=Reflect.deleteProperty(n,r);return s&&o&&t(e),o}}),ft=["values","entries","keys",Symbol.iterator],mt=(t,e,n)=>{const r=pt(t,e);return{...r,get(s,o,i){const c=Reflect.get(s,o,i);return"function"==typeof c&&n.has(o)?(...n)=>{const r=c.apply(s,n);return t(e),r}:((t,e)=>"function"==typeof t[e]&&ft.includes(e))(s,o)?s[o].bind(s):r.get(s,o,i)}}},bt={Array:/* @__PURE__ */new Set(["push","pop","shift","unshift","splice","sort","reverse"]),Set:/* @__PURE__ */new Set(["add","delete","clear"]),Map:/* @__PURE__ */new Set(["set","delete","clear"])},gt=(t,e,n)=>{if("object"!=typeof t||null===t)return t;if(dt.has(t))return dt.get(t);const r=((t,e,n)=>Array.isArray(t)?mt(n,e,bt.Array):t instanceof Set?mt(n,e,bt.Set):t instanceof Map?mt(n,e,bt.Map):pt(n,e))(t,e,n),s=new Proxy(t,r);return dt.set(t,s),lt.set(s,!0),s},wt=Object.freeze([Boolean,Number,String]),yt=/* @__PURE__ */new Map([[Boolean,{toProp:t=>"false"!==t&&null!==t,toAttr:t=>t?"":null}],[Number,{toProp:t=>Number(t),toAttr:t=>null!==t?String(t):null}],[String,{toProp:t=>t,toAttr:t=>t}]]);function Et(t){return"function"==typeof t?t:null===t||"object"!=typeof t?()=>t:()=>structuredClone(t)}const vt=t=>Object.defineProperty(t,"_prop",{value:!0,writable:!1,configurable:!1,enumerable:!1}),At=(t=null,e=!1)=>(e=e&&null!==t&&"object"==typeof t,vt({value:Et(t),deep:e,attribute:!1})),Nt=(t=null,e=String)=>{const n=null!=t;if(n&&(e=t.constructor),!wt.includes(e)||null!==t&&"object"==typeof t)throw new Error(`Unsupported attribute type '${e}'. Allowed: ${wt.map(t=>t.name).join(", ")}`);const{toProp:r,toAttr:s}=yt.get(e);return vt({value:Et(t),deep:!1,attribute:{type:e,force:n,toProp:r,toAttr:s}})};function St(t){return t.watched[Tt]}function Ot(t,e){t.watched._update(e)}function _t(t,e=[],n=!1){if(!(t=>"function"==typeof t&&void 0!==t.prototype)(t))throw new Error("[Enso] - Watches can only be applied to functions.");return t.__watches={props:e,keep:n},t}const Tt=Symbol("enso.watched.values");function jt(t){const e=/* @__PURE__ */Object.create(null);if(!t)return e;for(const[r,s]of(n=t,Object.entries(Object.getOwnPropertyDescriptors(n)))){const n=s.value;if(n?.__watches){for(const t of n.__watches.props)(e[t]||=[]).push(n);n.__watches.keep||delete t[r]}}var n;return e}const Pt=t=>{if(t.startsWith("_"))throw new Error("[Enso] - Watched property names must not start with '_'.")},Ct=(t,e,n=[])=>{const r=e?._prop?e:At(e);return Object.assign({},r,{name:t,watchers:n})};class $t{static define(t,e={}){const n=class extends $t{};n.attr=[],n.defs=/* @__PURE__ */Object.create(null);for(const[r,s]of Object.entries(t)){Pt(r);const t=Ct(r,s,e[r]);Object.defineProperty(n.prototype,t.name,{configurable:!0,enumerable:!0,get(){return this._getProp(t)},set(e){this._setProp(t,e)}}),n.defs[t.name]=t,t.attribute&&n.attr.push(t.name)}for(const r of P)n.defs[r]={name:r,value:()=>!1,attribute:!1,watchers:e[r]??[]};return Object.freeze(n.defs),Object.freeze(n.attr),n}#_;#x=/* @__PURE__ */new Map;#i=/* @__PURE__ */new Map;constructor(t){this.#_=t;for(const e in this._defs){const n=this._defs[e];let r=n.value();n.deep&&"object"==typeof r&&null!==r&&(r=gt(r,n.name,t[s])),this.#x.set(e,r),this.#i.set(e,{changed:!1,watchers:n.watchers,effects:[]})}}get[u](){return this.#i}get[Tt](){return Object.fromEntries(this.#x)}get _defs(){return this.constructor.defs}_notify(t){if(this.#i.has(t)){const{watchers:e}=this.#i.get(t),n=this.#x.get(t);for(const r of e)r.call(this.#_,t,n)}}_getProp(t){return this.#x.get(t.name)}_setProp(t,e){t.deep&&"object"==typeof e&&null!==e&&(e=gt(e,t.name,this.#_[s])),this.#x.set(t.name,e),this.#_[s](t.name),t.attribute&&this.#_.reflectAttribute(t.name),this._notify(t.name)}_update(t){for(const e in t)t[e]!==this.#x.get(e)&&this._setProp(this._defs[e],t[e])}}const kt=Object.seal({version:"1.0.0-rc.10",component(t,{template:e,styles:n=null,expose:r={},watched:s={},script:o=null,settings:i={}}){if(i=((t={})=>({useShadow:!0,shadowMode:"open",...t}))(i),customElements.get(t))throw new Error(`[Enso] Component "${t}" is already defined. Did you load the component twice?`);const c=jt(o),a=_(C,o),h=$t.define(s,c);return n&&!Array.isArray(n)&&(n=[n]),Object.defineProperties(a,{observedAttributes:{get:()=>h.attr},WatchedClass:{get:()=>h}}),Object.defineProperties(a.prototype,{observedAttributes:{get:()=>h.attr},settings:{get:()=>i},template:{get:()=>e},styles:{get:()=>n},expose:{get:()=>r}}),customElements.define(t,a),ut(t,a)}});export{Nt as attr,at as css,kt as default,St as getWatched,ht as html,j as lifecycle,At as prop,Ot as setWatched,_t as watches};
|
|
1
|
+
let t=(t,e)=>`${t}: ${e}`;const e=(e,n)=>{throw new Error(`[Enso] - ${t(e,n)}`)},n=(e,n,r)=>{const s=console[e];s&&s(`[Enso] - ${t(n,r)}`)},r=e=>{"function"==typeof e&&(t=e)},s=Symbol(),o=Symbol(),i=Symbol(),c=Symbol(),a=Symbol(),u=Symbol(),h=Symbol(),d=Symbol(),l=Symbol(),p=Symbol(),f=Symbol(),m=Symbol(),g=Symbol(),b=Symbol(),y=Symbol(),w=Symbol(),E="ENSO-FRAGMENT",A="enso-node",_="enso-root",N="enso-frag",S=Object.freeze({Window:{},Document:{},eval:null,Function:null,setTimeout:null}),v=Object.freeze({parse:(t,...e)=>{let n=!1;const r=t.reduce((t,r,s)=>{const o=e[s];return!0===o&&(n=!0),t+r+(!0!==(i=o)&&!1!==i&&null!=i?o:"");var i},"");return!(!n||r)||r},...S}),O=(t={},e=v)=>Object.freeze(Object.assign(Object.create(e),t));class T{#t;#e;constructor(t,e,r){this.#t=e;try{this.#e=r.createFunc(t)}catch(s){n("error",302,`\n${s}\n${r}`),this.#e=()=>{}}}get element(){return this.#t}get action(){return this.#e}run(){try{return this.#e?.()}catch(t){return void n("error",311,`\n${t}\n${this.#e.toString()}`)}}}const $=(t,n)=>{const r=class extends t{constructor(){super(s)}};if(!n)return r;const o=typeof n;"object"!==o&&e(103,o);const i=Object.getOwnPropertyDescriptors(n);for(const e in i)Object.defineProperty(r.prototype,e,i[e]);return r},j=(t=Object)=>class extends t{#n;#r=/* @__PURE__ */new Set;#s=[];constructor(){super(),this[h]=this[h].bind(this),this[a]=this[a].bind(this)}get isComponent(){return!1}get[f](){return this.#n}set[f](t){this.#n=t}get[p](){return this.#r}get[m](){return this.#s}[u](t){this.#s.push(t)}[d](t){return this.#n[t]}[l](t,e){const n=this[d](t);n&&(n.effects.push(e),n.changed=!0)}[i](t){this.#r.add(t)}[a](t){const e=this.#n[t];if(e&&!e.changed){e.changed=!0;for(const t of e.effects)this[i](t);this[o]()}for(const n of this.#s)n[a](t)}[h](){for(const e of this.#r)e.run();this.#r.clear();for(const e of Object.values(this.#n))e.changed=!1;const t=[...this.#s];for(const e of t)e[h]()}},C=Object.freeze({mount:"lifecycle:mount",update:"lifecycle:update",unmount:"lifecycle:unmount"}),M=Object.values(C);class P extends(j(HTMLElement)){#o=!1;#i=null;#c=!1;#a;#u=/* @__PURE__ */Object.create(null);#h=O(this.expose);#d(){return this.shadowRoot??this.attachShadow({mode:this.settings.shadowMode})}constructor(t){super(),t!==s&&e(102),this.#a=new this.constructor.WatchedClass(this),this[f]=this.#a[f],this.#i=this.settings.useShadow?this.#d():this}_report(t,e,r){n(t,e,r)}get refs(){return this.#u}get component(){return this}get isAttached(){return this.#o}get watched(){return this.#a}get isComponent(){return!0}get[y](){return this.#i}get[w](){return this.#h}connectedCallback(){if(this.#o)return;this.#o=!0;const t=this.constructor.observedAttributes;for(const e of t)this.watched._defs[e].attribute.force&&this.reflectAttribute(e);this[c](this.template.process(this,this.template)),this.styles&&((t,e)=>{const n=t instanceof ShadowRoot?t:t.getRootNode();(n instanceof Document||n instanceof ShadowRoot)&&(n.adoptedStyleSheets=[...n.adoptedStyleSheets,...e])})(this[y],this.styles),this[h]()}disconnectedCallback(){this.#a._notify(C.unmount)}attributeChangedCallback(t,e,n){if(e===n)return;const r=this.watched._defs[t].attribute.toProp(n);this.watched[t]!==r&&(this.watched[t]=r)}[a](t){super[a](t),this.watched._notify(t)}[c](t){const e=Array.from(t.firstElementChild.childNodes);this[y].append(...e),this.#a._notify(C.mount)}reflectAttribute(t){const e=this.#a._defs[t],n=e.attribute.toAttr(this.watched[t]);n!==this.getAttribute(e.name)&&(null===n?this.removeAttribute(e.name):this.setAttribute(e.name,n))}[o](){this.#c||(this.#c=!0,requestAnimationFrame(this[h]))}[h](){this.#c=!1,super[h](),this.#a._notify(C.update)}}const R=t=>{const e=document.createElement("template");return e.content.appendChild("string"==typeof t?(t=>document.createRange().createContextualFragment(t))(t):t),e},x=t=>{const e=t instanceof HTMLTemplateElement?t:R(t);return e.content.querySelectorAll("script").forEach(t=>t.remove()),e},W=(t,e)=>Array.prototype.indexOf.call(t.childNodes,e),L="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",k=(t=6)=>{let e="",n=Math.max(0,Math.trunc(t));for(;n--;)e+=L[Math.trunc(64*Math.random())];return e},F=t=>t.nodeType===Node.TEXT_NODE?t.parentElement:t;class D{#l;#p;#f;#m=/* @__PURE__ */new Map;#g=null;constructor(t,e,n){this.#l=t,this.#p=n,this.#f=e}get id(){return this.#l}get node(){return this.#f}get map(){return this.#p}setGenerator(t,e){this.#g={parser:t,data:e}}getGenerator(){return this.#g}addMutator(t,e){this.#m.has(t)||this.#m.set(t,[]),this.#m.get(t).push(e),this.markWatched()}getMutators(t){return this.#m.get(t)||[]}mutators(){return this.#m.entries()}markRoot(t=!1){this.#f?.setAttribute(_,t?this.#l:"")}unRoot(){this.#f?.removeAttribute(_)}isRoot(){return this.#f?.hasAttribute(_)}markWatched(t=!0){const e=F(this.#f);e.hasAttribute(A)||e.setAttribute(A,this.#l),t&&this.#p.add(this)}unWatch(){const t=F(this.#f);t?.removeAttribute(A)}isWatched(){return this.#f?.hasAttribute(A)}replaceNode(t){const e=this.#f;return this.#f.replaceWith(t),this.#f=t,this.markWatched(!1),e}}class z{#p=/* @__PURE__ */new Map;get size(){return this.#p.size}add(t){this.#p.has(t.id)||this.#p.set(t.id,t)}get(t){return this.#p.has(t)?this.#p.get(t):null}getByNode(t){if(!t?.hasAttribute(A))return null;const e=t.getAttribute(A);return this.#p.get(e)}getByRoot(t){if(!t?.hasAttribute(_))return null;const e=t.getAttribute(_);return this.#p.get(e)}create(t){const e=F(t).getAttribute(A);return this.#p.has(e)?this.#p.get(e):new D(k(),t,this)}createRoot(t){const e=new D(k(),t,this);return e.markRoot(!0),this.add(e),e}[Symbol.iterator](){return this.#p.values()}}const B=(t,e=1)=>{const n=t.name;if(n.startsWith("enso-")){const t=n.indexOf(":");if(t>-1)return n.slice(t+1).toLowerCase()}return n.slice(e).toLowerCase()},G=(t,e,n=null)=>{if(!t?.name)return!1;const r=t.name;return!!r.startsWith(e)||!!n&&r.startsWith(`enso-${n}:`)},V=/(?:this\.watched\.|watched:|@:)([A-Za-z_$][\w$]*)/g,q=/(?:this\.refs\.|ref:|#:)([A-Za-z_$][\w$]*)/g,H=()=>document.createElement("template"),I=(t,e,n)=>{if(!t)return null;const r=t.getAttributeNode(e)??t.getAttributeNode(n);return r&&t.removeAttribute(r.name),r?.value??null};const U=t=>t.includes(":")?U(t.split(":")[1]):t.includes("=")?U(t.split("=")[0]):t.trim(),X=t=>{const[n]=t.split(/\b(?:of|in)\b(?!.*\b(of|in)\b)/).filter(Boolean),r=(t=>{const n={"{":"}","[":"]","}":"{","]":"["},r=[{token:"",capturing:!0}];let s=!0;const o=t=>{const e=r.at(-1).capturing&&s;r.push({token:n[t],capturing:e}),s=!0},i=t=>{t!==r.pop().token&&e(411),s=!1},c={",":()=>{s=!0},"{":o,"[":o,"}":i,"]":i},a=t.split(/([{}[\],])/).map(t=>{if(t?.trim())return c[t]?c[t](t):r.at(-1).capturing?(s=!1,":"===t.trim().at(-1)&&(s=!0),U(t)):void 0}).filter(Boolean);return r.length>1&&e(411),a})(n);return r};if(!customElements.get(E.toLowerCase())){class t extends HTMLElement{}customElements.define(E.toLowerCase(),t)}class J extends(j()){#b;#y;#w;#E=null;#i=null;#h;#A=!1;constructor(t,e,n){super(),this.#b=t.component,this.#y=t,this.#h=t[w],n&&(this.#w=document.createComment(this.tag),n.replaceWith(this.#w)),t[u](this);const r=/* @__PURE__ */new Map;for(const[s,o]of Object.entries(this.#b[f]))r[s]={changed:!1,watchers:o.watchers,effects:[]};this[f]=r,this._processTemplate(e)}_processTemplate(t){t&&(this.#i=t.process(this))}_getChildren(){this.#E=Array.from(this.#i.childNodes)}get tag(){return"enso:fragment"}get component(){return this.#b}get isAttached(){return this.#A}set isAttached(t){this.#A=t}get[g](){return this.#w}get[b](){return this.#E}get[w](){return this.#h}set[w](t){this.#h=O(t,this.#y[w])}get#_(){return this.#y.isAttached}[o](){this.#b[o]()}mount(){!this.#A&&this.#_&&(this._getChildren(),this.#w.after(...this.#E),this.#A=!0,this[h]())}[h](){this.#A&&super[h]()}unmount(){this.#A&&(this.#i.append(...this.#E),this.#E=null,this.#A=!1)}_requestUpdate(){this[h]()}_getNodes(){return this[b]}_setENV(t){this[w]=t}_insertAfterAnchor(...t){this[g].after(...t)}_getChildFragments(){return this[m]}}const Z=()=>{const t=/* @__PURE__ */new Map;return{get(e,n=null){for(const r of t.values())if(r.match(e,n))return r;return null},set(e){t.set(e.type,e)},[Symbol.iterator]:()=>t.values()}},K=(()=>{const t={generator:Z(),attribute:Z(),content:Z()};return Object.freeze({register(n,r="attribute"){const s=t[r];s||e(401,r),s.set(n)},get(n,r,s=null){const o=t[n];return o||e(401,n),o.get(r,s)},markRoot(t){t.setAttribute(_,"")},getRoot:t=>t.querySelector(`[${_}]:not([${_}="COMPONENT"])`),isParsed:t=>t.hasAttribute(N),getWatched:t=>t.querySelector(`[${A}]`),preprocess(e,n){let r=!1;const s=t.generator.get(n);s&&(r=s.preprocess(e,n));for(const o of t.content)o.match(n)&&(r=o.preprocess(e,n)||r);if(n.attributes?.length){const s=[...n.attributes];for(const o of s){const s=t.attribute.get(n,o);s&&(r=s.preprocess(e,n,o)||r)}}return r},process(t,e,n){const r=t.getGenerator();r&&r.parser.process(r.data,e,n);for(const[s,o]of t.mutators())s.process(o,e,n);n.removeAttribute(A)}})})(),Q=Object.freeze({Effect:T,Action:class{#N;#S;#v;#O;constructor(t,e={},r=T){this.#S=t,this.#N=r,this.#v=e,this.#O=(t=>{const e=(t=>`with (env) {\n return (() => {\n "use strict";\n try { return ${t}; } catch(e) {\n this._report('error', 312, e); // E_EFFECT_RUNTIME\n return undefined;\n }\n })();\n }`)(t);try{return new Function("env",e)}catch(r){return n("error",301,`\n${r}\n${e}`),()=>()=>{}}})(t)}get data(){return this.#v}get code(){return this.#S}createEffect(t,e){return new this.#N(t,e,this)}createFunc(t){const{component:n,[w]:r}=t,s=this.#O.call(n,r),o=typeof s;return"function"!==o&&e(303,o),s}},compileValue:t=>`(()=>parse\`${t.replaceAll("{{","${").replaceAll("}}","}").trim()}\`)`,addBinding:(t,e,n)=>{t[l](e,n),t[i](n)},addWatcher:(t,e,n)=>{t.watched._addWatcher(e,n);const r=t.watched._getProp(e);n.call(t,e,r)},parseSource:(t,e=null)=>{const n=t.replace(V,(t,n)=>(e&&e.add(n),`this.watched.${n}`)).replace(q,(t,e)=>`this.refs.${e}`);return e&&e.add(C.mount),n},collectBindings:(t,e)=>{let n;for(;null!==(n=V.exec(t));)e.add(n[1]);e.add(C.mount)},EnsoFragment:J}),Y={generator(t){K.register(t,"generator")},attribute(t){K.register(t,"attribute")},content(t){K.register(t,"content")}};var tt,et;(function(t,e){const{Action:n,parseSource:r}=e;function s(t,e,n){const{name:r,action:s}=n;try{const n=s.createFunc(t);e.addEventListener(r.toLowerCase(),n.bind(t.component))}catch(o){console.error("[Enso] - ",o)}}t.attribute({type:"enso:event",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&G(e,"@","evt"),preprocess(t,e,s){const o=r(s.value);return t.addMutator(this,{name:B(s),action:new n(o)}),e.removeAttribute(s.name),!0},process(t,e,n){for(const r of t)s(e,n,r)}})})(tt=Y,et=Q),function(t,e){const{addBinding:n,parseSource:r,Effect:s,Action:o,compileValue:i}=e,c=/({{(.|\n)*}})/;class a extends s{run(){const t=super.run();this.element&&t&&(this.element.textContent=t)}}t.content({type:"enso:text",match:t=>t.nodeType===Node.TEXT_NODE&&c.test(t.nodeValue),preprocess(t,e){const n=/* @__PURE__ */new Set,s=i(r(e.nodeValue,n));return t.addMutator(this,{parent:e.parentNode,index:W(e.parentNode,e),action:new o(s,{},a),binds:n}),!0},process(t,e,r){for(const s of t){const t=r.childNodes[s.index],o=s.action.createEffect(e,t);for(const r of s.binds)n(e,r,o)}}})}(tt,et),function(t,e){const{addBinding:n,parseSource:r,Effect:s,Action:o,compileValue:i}=e;class c extends s{#T;constructor(t,e,n){super(t,e,n),this.#T=n.data.name}run(){const t=super.run(),e=this.element;t?e.setAttribute(this.#T,!0===t?"":t):e.removeAttribute(this.#T)}}t.attribute({type:"enso:attr",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&G(e,":","attr"),preprocess(t,e,n){const s=B(n),a=/* @__PURE__ */new Set,u=i(r(n.value,a));return t.addMutator(this,{name:s,action:new o(u,{name:s},c),binds:a}),e.removeAttribute(n.name),!0},process(t,e,r){for(const s of t){const t=s.action.createEffect(e,r);for(const r of s.binds)n(e,r,t)}}})}(tt,et),function(t,e){const{parseSource:n,addWatcher:r,Effect:s,Action:o}=e;class i extends s{#$;constructor(t,e,n){super(t,e,n),this.#$=n.data.name}run(){const t=super.run();void 0!==t&&(this.element[this.#$]=t)}}t.attribute({type:"enso:prop",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&G(e,".","prop"),preprocess(t,e,r){const s=B(r),c=/* @__PURE__ */new Set,a=`(()=>${n(r.value,c).replaceAll("{{","").replaceAll("}}","").trim()})`;return t.addMutator(this,{name:s,action:new o(a,{name:s},i),binds:c}),e.removeAttribute(r.name),!0},process(t,e,n){for(const s of t){const t=s.action.createEffect(e,n);for(const n of s.binds)r(e,n,()=>t.run())}}})}(tt,et),function(t){t.generator({type:"enso:ref",match:t=>t.nodeType===Node.ELEMENT_NODE&&(t.hasAttribute("#ref")||t.hasAttribute("enso-ref")),preprocess(t,e){if(t.getGenerator())return!1;const n=I(e,"#ref","enso-ref");return t.setGenerator(this,{type:"ref",name:n}),t.markWatched(),!0},process(t,e,n){t&&"ref"===t.type&&(e.isComponent?Object.defineProperty(e.component.refs,t.name,{value:n,writable:!1,configurable:!1}):console.warn(`[Enso] #ref="${t.name}" ignored: refs are only supported on static elements (not inside *for or *if).`))}})}(tt),function(t,e){const{addBinding:n,parseSource:r,EnsoFragment:s,Action:o}=e;class i extends s{constructor(t,e,n){super(t),this._setENV(n),this._processTemplate(e)}mount(){return this.isAttached=!0,this._requestUpdate(),this._getChildren(),this._getNodes()}}class c extends s{#j;#C;constructor(t,e,n,r){super(t,null,n),this.#j=r.createEffect(t,null),this.#C=e}get tag(){return"enso:for"}run(){this.mount()}mount(){this.unmount();const t=[],e=this.#j.run();for(const n of e){const e=new i(this,this.#C,n);t.push(...e.mount())}this._insertAfterAnchor(...t),this.isAttached=!0,this._requestUpdate()}unmount(){for(const t of this._getChildFragments())t.unmount();this._getChildFragments().length=0,this.isAttached=!1}}t.generator({type:"enso:for",match:t=>t.nodeType===Node.ELEMENT_NODE&&(t.hasAttribute("*for")||t.hasAttribute("enso-for")),preprocess(t,e){if(t.getGenerator())return!1;const n=/* @__PURE__ */new Set,s=r(I(e,"*for","enso-for"),n),i=X(s),c=new o(`(function* () {\n try {\n for (const ${s}) {\n yield { ${i.join(", ")} };\n }\n } catch(e) {\n this._report(412, e);\n }\n }).bind(this);/*js*/`);return t.map.createRoot(e).setGenerator(this,{type:"for",action:c,binds:n,template:null}),!0},fragment(t,e){t.getGenerator().data.template=e},process(t,e,r){if("for"===t?.type){const s=new c(e,t.template,r,t.action);for(const r of t.binds)n(e,r,s)}}})}(tt,et),function(t,e){const{addBinding:n,parseSource:r,compileValue:s,Action:o,EnsoFragment:i}=e;class c extends i{#j;constructor(t,e,n,r){super(t,e,n),this.#j=r.createEffect(t,null)}get tag(){return"enso:if"}run(){this.#j.run()?this.mount():this.unmount()}}t.generator({type:"enso:if",match:t=>t.nodeType===Node.ELEMENT_NODE&&(t.hasAttribute("*if")||t.hasAttribute("enso-if")),preprocess(t,e){if(t.getGenerator())return!1;let n=I(e,"*if","enso-if");const i=/* @__PURE__ */new Set;n=r(n,i);const c=new o(s(n));return t.map.createRoot(e).setGenerator(this,{type:"if",action:c,binds:i,template:null}),!0},fragment(t,e){t.getGenerator().data.template=e},process(t,e,r){if("if"===t?.type){const s=new c(e,t.template,r,t.action);for(const r of t.binds)n(e,r,s)}}})}(tt,et);const nt=/{{[^]*}}/,rt=t=>(t=>t.nodeType===Node.ELEMENT_NODE&&t.hasAttribute("enso:ignore"))(t)||(t=>t.parentNode?.hasAttribute("enso:ignore-children"))(t)?NodeFilter.FILTER_REJECT:t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&nt.test(t.nodeValue)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT,st=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT;class ot{#C=null;#a;constructor(t,e=new z){const n=x(t);this.#a=e,this.#C=this.#M(n),this.#P()}#M(t){if(K.isParsed(t))return t;const e=(t=>{const e=document.createElement(E);return e.append(t),e})(t.content);e.setAttribute(_,"COMPONENT"),t.content.append(e);const n=(t=>document.createTreeWalker(t,st,{acceptNode:rt}))(e);let r;for(;r=n.nextNode();){const t=this.#a.create(r);K.preprocess(t,r)}return t.setAttribute(N,""),t}#P(){const t=this.#C.content;let e;for((t=>{const e=t.querySelectorAll(`${E}:not([${_}])`);for(const n of e)n.replaceWith(...n.childNodes)})(t);e=K.getRoot(t);){const t=this.#a.getByRoot(e),n=H();t.unRoot(),t.replaceNode(n);const r=x(e);r.setAttribute(N,""),t.getGenerator()?.parser?.fragment(t,new ot(r,this.#a,!0),n)}}process(t){const e=this.#C.content.cloneNode(!0);let n;for(;n=K.getWatched(e);){const e=this.#a.getByNode(n);K.process(e,t,n)}return e}clone(){const t=this.#C.cloneNode(!0);return new ot(t,this.#a)}get watchedNodes(){return this.#a}get template(){return this.#C}}const it=(t,...e)=>"string"==typeof t?t:t.reduce((t,n,r)=>t+n+(e[r]||""),""),ct=(t,...e)=>(t=>{const e=new CSSStyleSheet;return e.replaceSync(t),e})(it(t,...e)),at=(t,...e)=>new ot(it(t,...e));const ut=/* @__PURE__ */new WeakMap,ht=/* @__PURE__ */new WeakMap,dt=(t,e)=>({get(n,r,s){const o=Reflect.get(n,r,s);return"object"==typeof o&&null!==o&&o?bt(o,e,t):o},set(n,r,s,o){const i=n[r],c=Reflect.set(n,r,s,o);return i!==s&&t(e),c},deleteProperty(n,r){const s=Object.prototype.hasOwnProperty.call(n,r),o=Reflect.deleteProperty(n,r);return s&&o&&t(e),o}}),lt=["values","entries","keys",Symbol.iterator],pt=(t,e,n)=>{const r=dt(t,e);return{...r,get(s,o,i){const c=Reflect.get(s,o,i);return"function"==typeof c&&n.has(o)?(...n)=>{const r=c.apply(s,n);return t(e),r}:((t,e)=>"function"==typeof t[e]&<.includes(e))(s,o)?s[o].bind(s):r.get(s,o,i)}}},ft=/* @__PURE__ */new Set(["push","pop","shift","unshift","splice","sort","reverse"]),mt=/* @__PURE__ */new Set(["add","delete","clear"]),gt=/* @__PURE__ */new Set(["set","delete","clear"]),bt=(t,e,n)=>{if("object"!=typeof t||null===t)return t;if(ut.has(t))return ut.get(t);const r=((t,e,n)=>Array.isArray(t)?pt(n,e,ft):t instanceof Set?pt(n,e,mt):t instanceof Map?pt(n,e,gt):dt(n,e))(t,e,n),s=new Proxy(t,r);return ut.set(t,s),ht.set(s,!0),s},yt=Object.freeze([Boolean,Number,String]),wt=/* @__PURE__ */new Map([[Boolean,{toProp:t=>"false"!==t&&null!==t,toAttr:t=>t?"":null}],[Number,{toProp:t=>Number(t),toAttr:t=>null!==t?String(t):null}],[String,{toProp:t=>t,toAttr:t=>t}]]);function Et(t){return"function"==typeof t?t:null===t||"object"!=typeof t?()=>t:()=>structuredClone(t)}const At=t=>Object.defineProperty(t,"_prop",{value:!0,writable:!1,configurable:!1,enumerable:!1});function _t(t=null,e=!1){return e=e&&null!==t&&"object"==typeof t,At({value:Et(t),deep:e,attribute:!1})}function Nt(t=null,n=String){const r=null!=t;r&&(n=t.constructor),(!yt.includes(n)||null!==t&&"object"==typeof t)&&e(201,n);const{toProp:s,toAttr:o}=wt.get(n);return At({value:Et(t),deep:!1,attribute:{type:n,force:r,toProp:s,toAttr:o}})}function St(t,n){return"function"!=typeof t&&e(211),Array.isArray(n)&&n.every(t=>"string"==typeof t)||e(212),n.includes(C.mount)||n.push(C.mount),At({value:void 0,deps:n,comp:t,deep:!1,attribute:!1})}function vt(t){return t.watched[$t]}function Ot(t,e){t.watched._update(e)}function Tt(t,n=[],r=!1){return"function"==typeof t&&void 0!==t.prototype?t.__watches={props:n,keep:r}:e(221),t}const $t=Symbol("enso.watched.values");function jt(t){t.startsWith("_")&&e(231)}function Ct(t,e,n){const r=e&&e._prop?e:_t(e);return r.name=t,r.watchers=n||[],r}class Mt{static define(t,n={}){const r=[],s=class extends Mt{};s.attr=[],s.defs=/* @__PURE__ */Object.create(null);for(const[o,i]of Object.entries(t)){jt(o);const t=Ct(o,i,n[o]);Object.defineProperty(s.prototype,t.name,{configurable:!0,enumerable:!0,get(){return this._getProp(t)},set(n){t.comp&&e(213,t.name),this._setProp(t,n)}}),t.comp&&r.push(t),s.defs[t.name]=t,t.attribute&&s.attr.push(t.name)}for(const e of M)s.defs[e]={name:e,value:()=>!1,attribute:!1,watchers:n[e]??[],lifecycle:!0};for(const e of r){const t=function(){this.watched._setProp(e,e.comp.call(this))};for(const n of e.deps){const e=s.defs[n];e&&e.watchers.push(t)}}return Object.freeze(s.defs),Object.freeze(s.attr),s}#b;#R=/* @__PURE__ */Object.create(null);#n=/* @__PURE__ */Object.create(null);constructor(t){this.#b=t;for(const n in this._defs){const r=this._defs[n];let s=r?.value?.();r.lifecycle||(t.hasOwnProperty(r.name)&&(s=t[r.name]),Object.defineProperty(t,r.name,{configurable:!0,enumerable:!0,get:()=>this._getProp(r),set:r.comp?()=>{e(213,r.name)}:t=>this._setProp(r,t)})),r.deep&&"object"==typeof s&&null!==s&&(s=bt(s,r.name,t[a])),this.#R[n]=s,this.#n[n]={changed:!1,watchers:r.watchers,effects:[]}}}get[f](){return this.#n}get[$t](){return structuredClone(this.#R)}get _defs(){return this.constructor.defs}_addWatcher(t,e){this.#n[t]&&this.#n[t].watchers.push(e)}_notify(t){if(this.#n[t]){const{watchers:e}=this.#n[t],n=this.#R[t];for(const r of e)r.call(this.#b,t,n)}}_getProp(t){return this.#R[t.name]}_setProp(t,e){t.deep&&"object"==typeof e&&null!==e&&(e=bt(e,t.name,this.#b[a])),this.#R[t.name]=e,this.#b[a](t.name),t.attribute&&this.#b.reflectAttribute(t.name)}_update(t){for(const e in t)t[e]!==this.#R[e]&&this._setProp(this._defs[e],t[e])}}let Pt=!1,Rt=null;const xt=(t,e)=>`${t}: ${e}`,Wt={version:"1.0.0-rc.11",component(t,{template:n,styles:r=null,expose:s={},watched:o={},script:i=null,settings:c={}}){c=((t={})=>({useShadow:!0,shadowMode:"open",...t}))(c),customElements.get(t)&&e(101,t);const a=function(t){const e=/* @__PURE__ */Object.create(null);if(!t)return e;for(const n in t){const r=t[n];if(r?.__watches){for(const t of r.__watches.props)(e[t]||=[]).push(r);r.__watches.keep||delete t[n]}}return e}(i),u=$(P,i),h=Mt.define(o,a);return r&&!Array.isArray(r)&&(r=[r]),Object.defineProperties(u,{observedAttributes:{get:()=>h.attr},WatchedClass:{get:()=>h}}),Object.defineProperties(u.prototype,{settings:{get:()=>c},template:{get:()=>n},styles:{get:()=>r},expose:{get:()=>s}}),customElements.define(t,u),function(t,e){function n(e,n){const r=e?Object.entries(e).reduce((t,[e,n])=>!0===n?`${t} ${e}`:null!=n&&!1!==n?`${t} ${e}="${n}"`:t,""):"";return null!=n?`<${t}${r}>${n}</${t}>`:`<${t}${r}></${t}>`}return n.toString=()=>`<${t}></${t}>`,n.tag=t,n.Class=e,n}(t,u)},use(t){t(Y,Q)},async enableDiagnostics(){Pt=!0,Rt||=import("./errors.es.js");const{default:t}=await Rt;Pt&&r(t)},disableDiagnostics(){Pt=!1,r(xt)}},Lt=Object.freeze(Wt);export{Lt as Enso,Nt as attr,St as computed,ct as css,Lt as default,vt as getWatched,at as html,C as lifecycle,_t as prop,Ot as setWatched,Tt as watches};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={101:e=>`Component "${e}" is already defined. Did you load the component twice?`,102:()=>"Direct subclassing of Enso is not supported. Use Enso.component() instead.",103:e=>`Component expected object litteral but got "${e}"`,201:e=>`Unsupported attribute type: "${e}"`,211:()=>"computed() expects a function",212:()=>"computed() expects an array of dependency names",213:e=>`Tried to set value of computed property: "${e}"`,221:()=>"Watches can only be applied to functions.",231:()=>"Watched property names must not start with '_'.",301:e=>`Error in effect: ${e}`,302:e=>`Error instantiating effect: ${e}`,303:e=>`Expected function but got "${e}"`,311:e=>`Error running effect: ${e}`,312:e=>`Runtime error in effect: ${e}`,401:e=>`Unknown parser type "${e}"`,411:()=>"Mismatched brackets",412:e=>`Runtime error in for loop: ${e}`},t=(t,n)=>{const o=e[t];return o?o(n):`${t}: ${n}`};export{t as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ensojs",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A lightweight Web Component framework focused on clarity, reactivity, and minimal boilerplate.",
|
|
6
6
|
"author": "Sean Young <seanyoung247@gmail.com>",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"source": "./src/helpers/index.js",
|
|
17
17
|
"default": "./dist/helpers.es.js"
|
|
18
18
|
},
|
|
19
|
+
"./errors": {
|
|
20
|
+
"source": "./src/errors/index.js",
|
|
21
|
+
"default": "./dist/errors.es.js"
|
|
22
|
+
},
|
|
19
23
|
"./package.json": "./package.json"
|
|
20
24
|
},
|
|
21
25
|
"files": [
|
|
@@ -29,7 +33,7 @@
|
|
|
29
33
|
"dev": "vite",
|
|
30
34
|
"build": "vite build",
|
|
31
35
|
"preview": "vite preview",
|
|
32
|
-
"test": "vitest run",
|
|
36
|
+
"test": "vitest run --no-cache",
|
|
33
37
|
"test:build": "BUILD=1 vitest run",
|
|
34
38
|
"coverage": "vitest run --coverage",
|
|
35
39
|
"test:browser": "vitest --config=vitest.browser.config.js"
|