ensojs 1.0.0-rc.5 → 1.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ It aims to be modern, minimal, and forward-focused — no compile step, no virtu
18
18
 
19
19
  Enso is guided by a few simple principles:
20
20
 
21
- - **Native-first** — build on the platform: Custom Elements, Shadow DOM, template literals.
21
+ - **Native-first** — built on the modern web: Custom Elements, Shadow DOM, and template literals.
22
22
  - **Minimal surface area** — small API, small mental overhead.
23
23
  - **Declarative over imperative** — components describe what they are, not how to wire them.
24
24
  - **No build step** — just write HTML, CSS, and JS.
@@ -50,7 +50,7 @@ class MyComponent extends WebComponent {
50
50
  }
51
51
  ```
52
52
 
53
- As real-world components grew, new sources of repetitive boilerplate appeared. For instance, querying the DOM for child elements. To solve this, a quick and simple processing step was added to the template parsing, to extract `#ref="myRef"` attributes, and insert them as fields on the component, for a simple access `this.myRef`. But it soon became apparent that there was still a great deal of boilerplate, attaching events and the `@<event>=""` attribute evolved to replace calls to `this.myRef.addEventListener(...)`. As more features were added, Enso started to form.
53
+ As real-world components grew, new sources of repetitive boilerplate appeared. For instance, querying the DOM for child elements. To solve this, a quick and simple processing step was added to the template parsing, to extract `#ref="myRef"` attributes, and insert them as fields on the component, for simple access via the class: `this.myRef`. But it soon became apparent that there was still a great deal of boilerplate, attaching events and the `@<event>=""` attribute evolved to replace calls to `this.myRef.addEventListener(...)`. As more features were added, Enso started to form.
54
54
 
55
55
  From:
56
56
 
package/dist/ensojs.es.js CHANGED
@@ -1 +1 @@
1
- const t=Symbol("enso.internal"),e=Symbol("enso.scheduleUpdate"),n=Symbol("enso.scheduleEffect"),s=Symbol("enso.attachTemplates"),r=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",v=Object.freeze({Window:{},Document:{},eval:null,Function:null,setTimeout:null}),E=Object.freeze({parse:(t,...e)=>{let n=!1;const s=t.reduce((t,s,r)=>{const o=e[r];return!0===o&&(n=!0),t+s+(!0!==(i=o)&&!1!==i&&null!=i?o:"");var i},"");return!(!n||s)||s},...v}),A=(t={},e=E)=>Object.freeze(Object.assign(Object.create(e),t)),S=t=>`(()=>parse\`${t.replaceAll("{{","${").replaceAll("}}","}").trim()}\`)`;class N{#t;#e;constructor(t,e,n){this.#t=e;try{this.#e=n.createFunc(t)}catch(s){console.error("[Enso] Error instantiating effect:\n",s,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 _{#n;#s;#r;#o;constructor(t,e={},n=N){this.#s=t,this.#n=n,this.#r=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.#r}get code(){return this.#s}createEffect(t,e){return new this.#n(t,e,this)}createFunc(t){const{component:e,[m]:n}=t,s=this.#o.call(e,n);if("function"!=typeof s)throw new TypeError("[Enso] Expected function but got "+typeof s);return s}}const O=(e,n)=>{const s=class extends e{constructor(){super(t)}};if(!n)return s;const r=typeof n;if("object"!==r)throw new Error(`Component expected object litteral but got ${r}`);const o=Object.getOwnPropertyDescriptors(n);for(const t in o)Object.defineProperty(s.prototype,t,o[t]);return s},j=(t=Object)=>class extends t{#i;#c=/* @__PURE__ */new Set;#a=[];constructor(){super(),this[i]=this[i].bind(this),this[r]=this[r].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)}[r](t){const s=this.#i.get(t);if(s&&!s.changed){s.changed=!0;for(const t of s.effects)this[n](t);this[e]()}for(const e of this.#a)e[r](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]()}},T=Object.freeze({mount:"lifecycle:mount",update:"lifecycle:update",unmount:"lifecycle:unmount"}),P=Object.values(T);class C extends(j(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[s](this.template.process(this,this.template)),this.styles&&((t,e)=>{const n=t instanceof ShadowRoot?t:document;n.adoptedStyleSheets=[...n.adoptedStyleSheets,...e]})(this[f],this.styles),this[i]()}disconnectedCallback(){this.#l._notify(T.unmount)}attributeChangedCallback(t,e,n){if(e===n)return;const s=this.watched._defs[t].attribute.toProp(n);this.watched[t]!==s&&(this.watched[t]=s)}[s](t){const e=Array.from(t.firstElementChild.childNodes);this[f].append(...e),this.#l._notify(T.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(T.update)}}const k=/* @__PURE__ */new WeakMap,M=/* @__PURE__ */new WeakMap,x=(t,e)=>({get(n,s,r){const o=Reflect.get(n,s,r);return"object"==typeof o&&null!==o&&o?D(o,e,t):o},set(n,s,r,o){const i=n[s],c=Reflect.set(n,s,r,o);return i!==r&&t(e),c},deleteProperty(n,s){const r=Object.prototype.hasOwnProperty.call(n,s),o=Reflect.deleteProperty(n,s);return r&&o&&t(e),o}}),R=["values","entries","keys",Symbol.iterator],W=(t,e,n)=>{const s=x(t,e);return{...s,get(r,o,i){const c=Reflect.get(r,o,i);return"function"==typeof c&&n.has(o)?(...n)=>{const s=c.apply(r,n);return t(e),s}:((t,e)=>"function"==typeof t[e]&&R.includes(e))(r,o)?r[o].bind(r):s.get(r,o,i)}}},L={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"])},D=(t,e,n)=>{if("object"!=typeof t||null===t)return t;if(k.has(t))return k.get(t);const s=((t,e,n)=>Array.isArray(t)?W(n,e,L.Array):t instanceof Set?W(n,e,L.Set):t instanceof Map?W(n,e,L.Map):x(n,e))(t,e,n),r=new Proxy(t,s);return k.set(t,r),M.set(r,!0),r},$=Object.freeze([Boolean,Number,String]),F=/* @__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 z(t){return"function"==typeof t?t:null===t||"object"!=typeof t?()=>t:()=>structuredClone(t)}const B=t=>Object.defineProperty(t,"_prop",{value:!0,writable:!1,configurable:!1,enumerable:!1}),H=(t=null,e=!1)=>(e=e&&null!==t&&"object"==typeof t,B({value:z(t),deep:e,attribute:!1})),q=(t=null,e=String)=>{const n=null!=t;if(n&&(e=t.constructor),!$.includes(e)||null!==t&&"object"==typeof t)throw new Error(`Unsupported attribute type '${e}'. Allowed: ${$.map(t=>t.name).join(", ")}`);const{toProp:s,toAttr:r}=F.get(e);return B({value:z(t),deep:!1,attribute:{type:e,force:n,toProp:s,toAttr:r}})};function X(t){return t.watched[V]}function I(t,e){t.watched._update(e)}function U(t,e,n=!1){return"function"==typeof t&&(t.__watches={props:e,keep:n}),t}const V=Symbol("enso.watched.values");function G(t){const e=/* @__PURE__ */Object.create(null);if(!t)return e;for(const[s,r]of(n=t,Object.entries(Object.getOwnPropertyDescriptors(n)))){const n=r.value;if(n?.__watches){for(const t of n.__watches.props)(e[t]||=[]).push(n);n.__watches.keep||delete t[s]}}var n;return e}const J=t=>{if(t.startsWith("_"))throw new Error("[Enso] - Watched property names must not start with '_'.")},Z=(t,e,n=[])=>{const s=e?._prop?e:H(e);return Object.assign({},s,{name:t,watchers:n})};class K{static define(t,e={}){const n=class extends K{};n.attr=[],n.defs=/* @__PURE__ */Object.create(null);for(const[s,r]of Object.entries(t)){J(s);const t=Z(s,r,e[s]);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 s of P)n.defs[s]={name:s,value:()=>!1,attribute:!1,watchers:e[s]??[]};return Object.freeze(n.defs),Object.freeze(n.attr),n}#b;#g=/* @__PURE__ */new Map;#i=/* @__PURE__ */new Map;constructor(t){this.#b=t;for(const e in this._defs){const n=this._defs[e];let s=n.value();n.deep&&"object"==typeof s&&null!==s&&(s=D(s,n.name,t[r])),this.#g.set(e,s),this.#i.set(e,{changed:!1,watchers:n.watchers,effects:[]})}}get[u](){return this.#i}get[V](){return Object.fromEntries(this.#g)}get _defs(){return this.constructor.defs}_notify(t){if(this.#i.has(t)){const{watchers:e}=this.#i.get(t),n=this.#g.get(t);for(const s of e)s.call(this.#b,t,n)}}_getProp(t){return this.#g.get(t.name)}_setProp(t,e){t.deep&&"object"==typeof e&&null!==e&&(e=D(e,t.name,this.#b[r])),this.#g.set(t.name,e),this.#b[r](t.name),t.attribute&&this.#b.reflectAttribute(t.name),this._notify(t.name)}_update(t){for(const e in t)t[e]!==this.#g.get(e)&&this._setProp(this._defs[e],t[e])}}const Q=t=>{if(t instanceof HTMLTemplateElement)return t;"string"==typeof t&&(t=t.replace(/<script\b[^>]*>.*?<\/script>/gis,""));const e=document.createElement("template");return e.content.appendChild("string"==typeof t?(t=>document.createRange().createContextualFragment(t))(t):t),e},Y="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",tt=(t=6)=>{let e="",n=Math.max(0,Math.trunc(t));for(;n--;)e+=Y[Math.trunc(64*Math.random())];return e},et=t=>t.nodeType===Node.TEXT_NODE?t.parentElement:t;class nt{#w;#y;#v;#E;#A=[];#S=[];#N=[];#_;#O=/* @__PURE__ */new Set;constructor(t,e,n){this.#w=t,this.#y=n,this.#v=e}get id(){return this.#w}get node(){return this.#v}get map(){return this.#y}get ref(){return this.#E}set ref(t){this.#E=t,this.markWatched()}addEvent(t,e){this.#S.push({name:t,action:e}),this.markWatched()}get events(){return this.#S}addAttribute(t,e,n){this.#A.push({name:t,action:e,binds:n}),this.markWatched()}get attributes(){return this.#A}addContent(t,e,n,s){this.#N.push({parent:t,index:e,action:n,binds:s}),this.markWatched()}get content(){return this.#N}setDirective({type:t=this.#_?.type,template:e=this.#_?.template,action:n=this.#_?.effect,binds:s=this.#_?.binds}={}){this.#_={type:t,template:e,action:n,binds:s}}get directive(){return this.#_}attachParser(t){this.#O.add(t)}get parsers(){return this.#O}markRoot(t=!1){this.#v?.setAttribute(w,t?this.#w:"")}unRoot(){this.#v?.removeAttribute(w)}isRoot(){return this.#v?.hasAttribute(w)}markWatched(t=!0){const e=et(this.#v);e.hasAttribute(g)||e.setAttribute(g,this.#w),t&&this.#y.add(this)}unWatch(){const t=et(this.#v);t?.removeAttribute(g)}isWatched(){return this.#v?.hasAttribute(g)}replaceNode(t){const e=this.#v;return this.#v.replaceWith(t),this.#v=t,this.markWatched(!1),e}}class st{#y=/* @__PURE__ */new Map;get size(){return this.#y.size}add(t){this.#y.has(t.id)||this.#y.set(t.id,t)}get(t){return this.#y.has(t)?this.#y.get(t):null}getByNode(t){if(!t?.hasAttribute(g))return null;const e=t.getAttribute(g);return this.#y.get(e)}getByRoot(t){if(!t?.hasAttribute(w))return null;const e=t.getAttribute(w);return this.#y.get(e)}create(t){const e=et(t).getAttribute(g);return this.#y.has(e)?this.#y.get(e):new nt(tt(),t,this)}createRoot(t){const e=new nt(tt(),t,this);return e.markRoot(!0),this.add(e),e}[Symbol.iterator](){return this.#y.values()}}const rt=(()=>{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 s of e)if(s.match(t,n))return s;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 s=this.getNodeParser(e);if(s&&(n=s.preprocess(t,e)),e.attributes?.length){const s=[...e.attributes];for(const r of s){const s=this.getAttrParser(e,r);s&&(n=s.preprocess(t,e,r)||n)}}return n},process(t,e,n){for(const s of t.parsers)s.process(t,e,n);n.removeAttribute(g)}})})(),ot=(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()},it=(t,e,n=null)=>{if(!t?.name)return!1;const s=t.name;return!!s.startsWith(e)||!!n&&s.startsWith(`enso-${n}:`)},ct=/(?:this\.watched\.|watched:|@:)([A-Za-z_$][\w$]*)/g,at=(t,e=null)=>{const n=t.replace(ct,(t,n)=>(e&&e.add(n),`this.watched.${n}`));return e&&0===e.size&&e.add("lifecycle:mount"),n},ht=(t,e,s)=>{t[a](e,s),t[n](s)},ut=()=>document.createElement("template"),dt=(t,e,n)=>{if(!t)return null;const s=t.getAttributeNode(e)??t.getAttributeNode(n);return s&&t.removeAttribute(s.name),s?.value??null},lt=/({{(.|\n)*}})/;class pt extends N{run(){const t=super.run();this.element&&t&&(this.element.textContent=t)}}rt.registerNode({type:"text",match:t=>t.nodeType===Node.TEXT_NODE&&lt.test(t.nodeValue),preprocess(t,e){const n=/* @__PURE__ */new Set,s=S(at(e.nodeValue,n));return t.addContent(e.parentNode,((t,e)=>Array.prototype.indexOf.call(t.childNodes,e))(e.parentNode,e),new _(s,{},pt),n),t.attachParser(this),!0},process(t,e,n){if(t.content)for(const s of t.content){const t=n.childNodes[s.index],r=s.action.createEffect(e,t);for(const n of s.binds)ht(e,n,r)}}});class ft extends N{#j;constructor(t,e,n){super(t,e,n),this.#j=n.data.name}run(){const t=super.run(),e=this.element;t?e.setAttribute(this.#j,!0===t?"":t):e.removeAttribute(this.#j)}}function mt(t,e,n){const{name:s,action:r}=n;try{const n=r.createFunc(t);e.addEventListener(s.toLowerCase(),n.bind(t.component))}catch(o){console.error("[Enso] - ",o),e.addEventListener(s.toLowerCase(),()=>console.warn(`[Enso] Invalid handler for event '${s}'`))}}if(rt.registerAttr({type:"attr",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&it(e,":","attr"),preprocess(t,e,n){const s=ot(n),r=/* @__PURE__ */new Set,o=S(at(n.value,r));return t.addAttribute(s,new _(o,{name:s},ft),r),e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){if(t.attributes)for(const s of t.attributes){const t=s.action.createEffect(e,n);for(const n of s.binds)ht(e,n,t)}}}),rt.registerAttr({type:"event",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&it(e,"@","evt"),preprocess(t,e,n){const s=at(n.value);return t.addEvent(ot(n),new _(s)),e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){if(t.events?.length)for(const s of t.events)mt(e,n,s)}}),rt.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 bt extends(j()){#b;#T;#P;#C=null;#u=null;#f;#k=!1;constructor(t,e,n){super(),this.#b=t.component,this.#T=t,this.#f=t[m],n&&(this.#P=document.createComment(this.tag),n.replaceWith(this.#P)),t[o](this);const s=/* @__PURE__ */new Map;for(const[r,o]of this.#b[u])s.set(r,{changed:!1,watchers:o.watchers,effects:[]});this[u]=s,this._processTemplate(e)}_processTemplate(t){t&&(this.#u=t.process(this))}_getChildren(){this.#C=Array.from(this.#u.childNodes)}get tag(){return"enso:fragment"}get component(){return this.#b}get isAttached(){return this.#k}set isAttached(t){this.#k=t}get[l](){return this.#P}get[p](){return this.#C}get[m](){return this.#f}set[m](t){this.#f=A(t,this.#T[m])}get#M(){return this.#T.isAttached}[e](){this.#b[e]()}mount(){!this.#k&&this.#M&&(this._getChildren(),this.#P.after(...this.#C),this.#k=!0,this[i]())}[i](){this.#k&&super[i]()}unmount(){this.#k&&(this.#u.append(...this.#C),this.#C=null,this.#k=!1)}}class gt extends bt{#x;constructor(t,e,n,s){super(t,e,n),this.#x=s.createEffect(t,null)}get tag(){return"enso:if"}run(){this.#x.run()?this.mount():this.unmount()}}rt.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=dt(e,"*if","enso-if");const s=/* @__PURE__ */new Set;n=at(n,s);const r=new _(S(n)),o=t.map.createRoot(e);return o.setDirective({type:"if",action:r,binds:s}),o.attachParser(this),!0},process(t,e,n){if("if"===t?.directive?.type){const s=new gt(e,t.directive.template,n,t.directive.action);for(const n of t.directive.binds)ht(e,n,s)}}});const wt=t=>t.includes(":")?wt(t.split(":")[1]):t.includes("=")?wt(t.split("=")[0]):t.trim(),yt=t=>{const[e]=t.split(/\b(?:of|in)\b(?!.*\b(of|in)\b)/).filter(Boolean),n=(t=>{const e={"{":"}","[":"]","}":"{","]":"["},n=[{token:"",capturing:!0}];let s=!0;const r=t=>{const r=n.at(-1).capturing&&s;n.push({token:e[t],capturing:r}),s=!0},o=t=>{if(t!==n.pop().token)throw new Error("mismatched brackets");s=!1},i={",":()=>{s=!0},"{":r,"[":r,"}":o,"]":o},c=t.split(/([{}[\],])/).map(t=>{if(t?.trim())return i[t]?i[t](t):n.at(-1).capturing?(s=!1,":"===t.trim().at(-1)&&(s=!0),wt(t)):void 0}).filter(Boolean);if(n.length>1)throw new Error("mismatched brackets");return c})(e);return n};class vt extends bt{constructor(t,e,n){super(t),this[m]=n,this._processTemplate(e)}mount(){return this.isAttached=!0,this[i](),this._getChildren(),this[p]}}class Et extends bt{#x;#R;constructor(t,e,n,s){super(t,null,n),this.#x=s.createEffect(t,null),this.#R=e}get tag(){return"enso:for"}run(){this.mount()}mount(){this.unmount();const t=[],e=this.#x.run();for(const n of e){const e=new vt(this,this.#R,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}}rt.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,s=at(dt(e,"*for","enso-for"),n),r=yt(s),o=new _(`(function* () {\n try {\n for (const ${s}) {\n yield { ${r.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 s=new Et(e,t.directive.template,n,t.directive.action);for(const n of t.directive.binds)ht(e,n,s)}}});const At=/({{(.|\n)*}})/,St=t=>t.nodeType!==Node.TEXT_NODE||At.test(t.nodeValue)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT,Nt=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT;class _t{#R=null;#l;constructor(t,e=new st){const n=Q(t);this.#l=e,this.#R=this.#W(n),this.#L()}#W(t){if(rt.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,Nt,{acceptNode:St}))(e);let s;for(;s=n.nextNode();){const t=this.#l.create(s);rt.preprocess(t,s)}return t.setAttribute(y,""),this.#l,t}#L(){const t=this.#R.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=rt.getRoot(t);){const t=this.#l.getByRoot(e);t.unRoot(),t.replaceNode(ut());const n=Q(e);n.setAttribute(y,""),t.directive.template=new _t(n,this.#l,!0)}}process(t){const e=this.#R.content.cloneNode(!0);let n;for(;n=rt.getWatched(e);){const e=this.#l.getByNode(n);rt.process(e,t,n)}return e}clone(){const t=this.#R.cloneNode(!0);return new _t(t,this.#l)}get watchedNodes(){return this.#l}get template(){return this.#R}}const Ot=(t,...e)=>"string"==typeof t?t:t.reduce((t,n,s)=>t+n+(e[s]||""),""),jt=(t,...e)=>(t=>{const e=new CSSStyleSheet;return e.replaceSync(t),e})(Ot(t,...e)),Tt=(t,...e)=>new _t(Ot(t,...e)),Pt=Object.seal({version:"1.0.0-rc.5",component(t,{template:e,styles:n=null,expose:s={},watched:r={},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. \n Did you load the component twice?`);const c=G(o),a=O(C,o),h=K.define(r,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:()=>s}}),customElements.define(t,a),a}});export{q as attr,jt as css,Pt as default,X as getWatched,Tt as html,T as lifecycle,H as prop,I as setWatched,U as watches};
1
+ const t=Symbol("enso.internal"),e=Symbol("enso.scheduleUpdate"),n=Symbol("enso.scheduleEffect"),s=Symbol("enso.attachTemplates"),r=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",v=Object.freeze({Window:{},Document:{},eval:null,Function:null,setTimeout:null}),E=Object.freeze({parse:(t,...e)=>{let n=!1;const s=t.reduce((t,s,r)=>{const o=e[r];return!0===o&&(n=!0),t+s+(!0!==(i=o)&&!1!==i&&null!=i?o:"");var i},"");return!(!n||s)||s},...v}),A=(t={},e=E)=>Object.freeze(Object.assign(Object.create(e),t)),S=t=>`(()=>parse\`${t.replaceAll("{{","${").replaceAll("}}","}").trim()}\`)`;class N{#t;#e;constructor(t,e,n){this.#t=e;try{this.#e=n.createFunc(t)}catch(s){console.error("[Enso] Error instantiating effect:\n",s,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 _{#n;#s;#r;#o;constructor(t,e={},n=N){this.#s=t,this.#n=n,this.#r=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.#r}get code(){return this.#s}createEffect(t,e){return new this.#n(t,e,this)}createFunc(t){const{component:e,[m]:n}=t,s=this.#o.call(e,n);if("function"!=typeof s)throw new TypeError("[Enso] Expected function but got "+typeof s);return s}}const O=(e,n)=>{const s=class extends e{constructor(){super(t)}};if(!n)return s;const r=typeof n;if("object"!==r)throw new Error(`Component expected object litteral but got ${r}`);const o=Object.getOwnPropertyDescriptors(n);for(const t in o)Object.defineProperty(s.prototype,t,o[t]);return s},j=(t=Object)=>class extends t{#i;#c=/* @__PURE__ */new Set;#a=[];constructor(){super(),this[i]=this[i].bind(this),this[r]=this[r].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)}[r](t){const s=this.#i.get(t);if(s&&!s.changed){s.changed=!0;for(const t of s.effects)this[n](t);this[e]()}for(const e of this.#a)e[r](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]()}},T=Object.freeze({mount:"lifecycle:mount",update:"lifecycle:update",unmount:"lifecycle:unmount"}),P=Object.values(T);class C extends(j(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[s](this.template.process(this,this.template)),this.styles&&((t,e)=>{const n=t instanceof ShadowRoot?t:document;n.adoptedStyleSheets=[...n.adoptedStyleSheets,...e]})(this[f],this.styles),this[i]()}disconnectedCallback(){this.#l._notify(T.unmount)}attributeChangedCallback(t,e,n){if(e===n)return;const s=this.watched._defs[t].attribute.toProp(n);this.watched[t]!==s&&(this.watched[t]=s)}[s](t){const e=Array.from(t.firstElementChild.childNodes);this[f].append(...e),this.#l._notify(T.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(T.update)}}const k=/* @__PURE__ */new WeakMap,M=/* @__PURE__ */new WeakMap,x=(t,e)=>({get(n,s,r){const o=Reflect.get(n,s,r);return"object"==typeof o&&null!==o&&o?D(o,e,t):o},set(n,s,r,o){const i=n[s],c=Reflect.set(n,s,r,o);return i!==r&&t(e),c},deleteProperty(n,s){const r=Object.prototype.hasOwnProperty.call(n,s),o=Reflect.deleteProperty(n,s);return r&&o&&t(e),o}}),R=["values","entries","keys",Symbol.iterator],W=(t,e,n)=>{const s=x(t,e);return{...s,get(r,o,i){const c=Reflect.get(r,o,i);return"function"==typeof c&&n.has(o)?(...n)=>{const s=c.apply(r,n);return t(e),s}:((t,e)=>"function"==typeof t[e]&&R.includes(e))(r,o)?r[o].bind(r):s.get(r,o,i)}}},L={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"])},D=(t,e,n)=>{if("object"!=typeof t||null===t)return t;if(k.has(t))return k.get(t);const s=((t,e,n)=>Array.isArray(t)?W(n,e,L.Array):t instanceof Set?W(n,e,L.Set):t instanceof Map?W(n,e,L.Map):x(n,e))(t,e,n),r=new Proxy(t,s);return k.set(t,r),M.set(r,!0),r},$=Object.freeze([Boolean,Number,String]),F=/* @__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 z(t){return"function"==typeof t?t:null===t||"object"!=typeof t?()=>t:()=>structuredClone(t)}const B=t=>Object.defineProperty(t,"_prop",{value:!0,writable:!1,configurable:!1,enumerable:!1}),H=(t=null,e=!1)=>(e=e&&null!==t&&"object"==typeof t,B({value:z(t),deep:e,attribute:!1})),q=(t=null,e=String)=>{const n=null!=t;if(n&&(e=t.constructor),!$.includes(e)||null!==t&&"object"==typeof t)throw new Error(`Unsupported attribute type '${e}'. Allowed: ${$.map(t=>t.name).join(", ")}`);const{toProp:s,toAttr:r}=F.get(e);return B({value:z(t),deep:!1,attribute:{type:e,force:n,toProp:s,toAttr:r}})};function X(t){return t.watched[V]}function I(t,e){t.watched._update(e)}function U(t,e,n=!1){return"function"==typeof t&&(t.__watches={props:e,keep:n}),t}const V=Symbol("enso.watched.values");function G(t){const e=/* @__PURE__ */Object.create(null);if(!t)return e;for(const[s,r]of(n=t,Object.entries(Object.getOwnPropertyDescriptors(n)))){const n=r.value;if(n?.__watches){for(const t of n.__watches.props)(e[t]||=[]).push(n);n.__watches.keep||delete t[s]}}var n;return e}const J=t=>{if(t.startsWith("_"))throw new Error("[Enso] - Watched property names must not start with '_'.")},Z=(t,e,n=[])=>{const s=e?._prop?e:H(e);return Object.assign({},s,{name:t,watchers:n})};class K{static define(t,e={}){const n=class extends K{};n.attr=[],n.defs=/* @__PURE__ */Object.create(null);for(const[s,r]of Object.entries(t)){J(s);const t=Z(s,r,e[s]);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 s of P)n.defs[s]={name:s,value:()=>!1,attribute:!1,watchers:e[s]??[]};return Object.freeze(n.defs),Object.freeze(n.attr),n}#b;#g=/* @__PURE__ */new Map;#i=/* @__PURE__ */new Map;constructor(t){this.#b=t;for(const e in this._defs){const n=this._defs[e];let s=n.value();n.deep&&"object"==typeof s&&null!==s&&(s=D(s,n.name,t[r])),this.#g.set(e,s),this.#i.set(e,{changed:!1,watchers:n.watchers,effects:[]})}}get[u](){return this.#i}get[V](){return Object.fromEntries(this.#g)}get _defs(){return this.constructor.defs}_notify(t){if(this.#i.has(t)){const{watchers:e}=this.#i.get(t),n=this.#g.get(t);for(const s of e)s.call(this.#b,t,n)}}_getProp(t){return this.#g.get(t.name)}_setProp(t,e){t.deep&&"object"==typeof e&&null!==e&&(e=D(e,t.name,this.#b[r])),this.#g.set(t.name,e),this.#b[r](t.name),t.attribute&&this.#b.reflectAttribute(t.name),this._notify(t.name)}_update(t){for(const e in t)t[e]!==this.#g.get(e)&&this._setProp(this._defs[e],t[e])}}const Q=t=>{if(t instanceof HTMLTemplateElement)return t;"string"==typeof t&&(t=t.replace(/<script\b[^>]*>.*?<\/script>/gis,""));const e=document.createElement("template");return e.content.appendChild("string"==typeof t?(t=>document.createRange().createContextualFragment(t))(t):t),e},Y="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",tt=(t=6)=>{let e="",n=Math.max(0,Math.trunc(t));for(;n--;)e+=Y[Math.trunc(64*Math.random())];return e},et=t=>t.nodeType===Node.TEXT_NODE?t.parentElement:t;class nt{#w;#y;#v;#E;#A=[];#S=[];#N=[];#_;#O=/* @__PURE__ */new Set;constructor(t,e,n){this.#w=t,this.#y=n,this.#v=e}get id(){return this.#w}get node(){return this.#v}get map(){return this.#y}get ref(){return this.#E}set ref(t){this.#E=t,this.markWatched()}addEvent(t,e){this.#S.push({name:t,action:e}),this.markWatched()}get events(){return this.#S}addAttribute(t,e,n){this.#A.push({name:t,action:e,binds:n}),this.markWatched()}get attributes(){return this.#A}addContent(t,e,n,s){this.#N.push({parent:t,index:e,action:n,binds:s}),this.markWatched()}get content(){return this.#N}setDirective({type:t=this.#_?.type,template:e=this.#_?.template,action:n=this.#_?.effect,binds:s=this.#_?.binds}={}){this.#_={type:t,template:e,action:n,binds:s}}get directive(){return this.#_}attachParser(t){this.#O.add(t)}get parsers(){return this.#O}markRoot(t=!1){this.#v?.setAttribute(w,t?this.#w:"")}unRoot(){this.#v?.removeAttribute(w)}isRoot(){return this.#v?.hasAttribute(w)}markWatched(t=!0){const e=et(this.#v);e.hasAttribute(g)||e.setAttribute(g,this.#w),t&&this.#y.add(this)}unWatch(){const t=et(this.#v);t?.removeAttribute(g)}isWatched(){return this.#v?.hasAttribute(g)}replaceNode(t){const e=this.#v;return this.#v.replaceWith(t),this.#v=t,this.markWatched(!1),e}}class st{#y=/* @__PURE__ */new Map;get size(){return this.#y.size}add(t){this.#y.has(t.id)||this.#y.set(t.id,t)}get(t){return this.#y.has(t)?this.#y.get(t):null}getByNode(t){if(!t?.hasAttribute(g))return null;const e=t.getAttribute(g);return this.#y.get(e)}getByRoot(t){if(!t?.hasAttribute(w))return null;const e=t.getAttribute(w);return this.#y.get(e)}create(t){const e=et(t).getAttribute(g);return this.#y.has(e)?this.#y.get(e):new nt(tt(),t,this)}createRoot(t){const e=new nt(tt(),t,this);return e.markRoot(!0),this.add(e),e}[Symbol.iterator](){return this.#y.values()}}const rt=(()=>{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 s of e)if(s.match(t,n))return s;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 s=this.getNodeParser(e);if(s&&(n=s.preprocess(t,e)),e.attributes?.length){const s=[...e.attributes];for(const r of s){const s=this.getAttrParser(e,r);s&&(n=s.preprocess(t,e,r)||n)}}return n},process(t,e,n){for(const s of t.parsers)s.process(t,e,n);n.removeAttribute(g)}})})(),ot=(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()},it=(t,e,n=null)=>{if(!t?.name)return!1;const s=t.name;return!!s.startsWith(e)||!!n&&s.startsWith(`enso-${n}:`)},ct=/(?:this\.watched\.|watched:|@:)([A-Za-z_$][\w$]*)/g,at=(t,e=null)=>{const n=t.replace(ct,(t,n)=>(e&&e.add(n),`this.watched.${n}`));return e&&0===e.size&&e.add("lifecycle:mount"),n},ht=(t,e,s)=>{t[a](e,s),t[n](s)},ut=()=>document.createElement("template"),dt=(t,e,n)=>{if(!t)return null;const s=t.getAttributeNode(e)??t.getAttributeNode(n);return s&&t.removeAttribute(s.name),s?.value??null},lt=/({{(.|\n)*}})/;class pt extends N{run(){const t=super.run();this.element&&t&&(this.element.textContent=t)}}rt.registerNode({type:"text",match:t=>t.nodeType===Node.TEXT_NODE&&lt.test(t.nodeValue),preprocess(t,e){const n=/* @__PURE__ */new Set,s=S(at(e.nodeValue,n));return t.addContent(e.parentNode,((t,e)=>Array.prototype.indexOf.call(t.childNodes,e))(e.parentNode,e),new _(s,{},pt),n),t.attachParser(this),!0},process(t,e,n){if(t.content)for(const s of t.content){const t=n.childNodes[s.index],r=s.action.createEffect(e,t);for(const n of s.binds)ht(e,n,r)}}});class ft extends N{#j;constructor(t,e,n){super(t,e,n),this.#j=n.data.name}run(){const t=super.run(),e=this.element;t?e.setAttribute(this.#j,!0===t?"":t):e.removeAttribute(this.#j)}}function mt(t,e,n){const{name:s,action:r}=n;try{const n=r.createFunc(t);e.addEventListener(s.toLowerCase(),n.bind(t.component))}catch(o){console.error("[Enso] - ",o),e.addEventListener(s.toLowerCase(),()=>console.warn(`[Enso] Invalid handler for event '${s}'`))}}if(rt.registerAttr({type:"attr",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&it(e,":","attr"),preprocess(t,e,n){const s=ot(n),r=/* @__PURE__ */new Set,o=S(at(n.value,r));return t.addAttribute(s,new _(o,{name:s},ft),r),e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){if(t.attributes)for(const s of t.attributes){const t=s.action.createEffect(e,n);for(const n of s.binds)ht(e,n,t)}}}),rt.registerAttr({type:"event",match:(t,e)=>t.nodeType===Node.ELEMENT_NODE&&it(e,"@","evt"),preprocess(t,e,n){const s=at(n.value);return t.addEvent(ot(n),new _(s)),e.removeAttribute(n.name),t.attachParser(this),!0},process(t,e,n){if(t.events?.length)for(const s of t.events)mt(e,n,s)}}),rt.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 bt extends(j()){#b;#T;#P;#C=null;#u=null;#f;#k=!1;constructor(t,e,n){super(),this.#b=t.component,this.#T=t,this.#f=t[m],n&&(this.#P=document.createComment(this.tag),n.replaceWith(this.#P)),t[o](this);const s=/* @__PURE__ */new Map;for(const[r,o]of this.#b[u])s.set(r,{changed:!1,watchers:o.watchers,effects:[]});this[u]=s,this._processTemplate(e)}_processTemplate(t){t&&(this.#u=t.process(this))}_getChildren(){this.#C=Array.from(this.#u.childNodes)}get tag(){return"enso:fragment"}get component(){return this.#b}get isAttached(){return this.#k}set isAttached(t){this.#k=t}get[l](){return this.#P}get[p](){return this.#C}get[m](){return this.#f}set[m](t){this.#f=A(t,this.#T[m])}get#M(){return this.#T.isAttached}[e](){this.#b[e]()}mount(){!this.#k&&this.#M&&(this._getChildren(),this.#P.after(...this.#C),this.#k=!0,this[i]())}[i](){this.#k&&super[i]()}unmount(){this.#k&&(this.#u.append(...this.#C),this.#C=null,this.#k=!1)}}class gt extends bt{#x;constructor(t,e,n,s){super(t,e,n),this.#x=s.createEffect(t,null)}get tag(){return"enso:if"}run(){this.#x.run()?this.mount():this.unmount()}}rt.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=dt(e,"*if","enso-if");const s=/* @__PURE__ */new Set;n=at(n,s);const r=new _(S(n)),o=t.map.createRoot(e);return o.setDirective({type:"if",action:r,binds:s}),o.attachParser(this),!0},process(t,e,n){if("if"===t?.directive?.type){const s=new gt(e,t.directive.template,n,t.directive.action);for(const n of t.directive.binds)ht(e,n,s)}}});const wt=t=>t.includes(":")?wt(t.split(":")[1]):t.includes("=")?wt(t.split("=")[0]):t.trim(),yt=t=>{const[e]=t.split(/\b(?:of|in)\b(?!.*\b(of|in)\b)/).filter(Boolean),n=(t=>{const e={"{":"}","[":"]","}":"{","]":"["},n=[{token:"",capturing:!0}];let s=!0;const r=t=>{const r=n.at(-1).capturing&&s;n.push({token:e[t],capturing:r}),s=!0},o=t=>{if(t!==n.pop().token)throw new Error("mismatched brackets");s=!1},i={",":()=>{s=!0},"{":r,"[":r,"}":o,"]":o},c=t.split(/([{}[\],])/).map(t=>{if(t?.trim())return i[t]?i[t](t):n.at(-1).capturing?(s=!1,":"===t.trim().at(-1)&&(s=!0),wt(t)):void 0}).filter(Boolean);if(n.length>1)throw new Error("mismatched brackets");return c})(e);return n};class vt extends bt{constructor(t,e,n){super(t),this[m]=n,this._processTemplate(e)}mount(){return this.isAttached=!0,this[i](),this._getChildren(),this[p]}}class Et extends bt{#x;#R;constructor(t,e,n,s){super(t,null,n),this.#x=s.createEffect(t,null),this.#R=e}get tag(){return"enso:for"}run(){this.mount()}mount(){this.unmount();const t=[],e=this.#x.run();for(const n of e){const e=new vt(this,this.#R,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}}rt.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,s=at(dt(e,"*for","enso-for"),n),r=yt(s),o=new _(`(function* () {\n try {\n for (const ${s}) {\n yield { ${r.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 s=new Et(e,t.directive.template,n,t.directive.action);for(const n of t.directive.binds)ht(e,n,s)}}});const At=/({{(.|\n)*}})/,St=t=>t.nodeType!==Node.TEXT_NODE||At.test(t.nodeValue)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT,Nt=NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT;class _t{#R=null;#l;constructor(t,e=new st){const n=Q(t);this.#l=e,this.#R=this.#W(n),this.#L()}#W(t){if(rt.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,Nt,{acceptNode:St}))(e);let s;for(;s=n.nextNode();){const t=this.#l.create(s);rt.preprocess(t,s)}return t.setAttribute(y,""),this.#l,t}#L(){const t=this.#R.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=rt.getRoot(t);){const t=this.#l.getByRoot(e);t.unRoot(),t.replaceNode(ut());const n=Q(e);n.setAttribute(y,""),t.directive.template=new _t(n,this.#l,!0)}}process(t){const e=this.#R.content.cloneNode(!0);let n;for(;n=rt.getWatched(e);){const e=this.#l.getByNode(n);rt.process(e,t,n)}return e}clone(){const t=this.#R.cloneNode(!0);return new _t(t,this.#l)}get watchedNodes(){return this.#l}get template(){return this.#R}}const Ot=(t,...e)=>"string"==typeof t?t:t.reduce((t,n,s)=>t+n+(e[s]||""),""),jt=(t,...e)=>(t=>{const e=new CSSStyleSheet;return e.replaceSync(t),e})(Ot(t,...e)),Tt=(t,...e)=>new _t(Ot(t,...e)),Pt=Object.seal({version:"1.0.0-rc.6",component(t,{template:e,styles:n=null,expose:s={},watched:r={},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. \n Did you load the component twice?`);const c=G(o),a=O(C,o),h=K.define(r,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:()=>s}}),customElements.define(t,a),a}});export{q as attr,jt as css,Pt as default,X as getWatched,Tt as html,T as lifecycle,H as prop,I as setWatched,U as watches};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ensojs",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.7",
4
4
  "type": "module",
5
5
 
6
6
  "description": "A lightweight Web Component framework focused on clarity, reactivity, and minimal boilerplate.",