/**
 * Bundled by jsDelivr using Rollup v4.62.2 and esbuild v0.28.1.
 * Original file: /npm/tutuca@0.15.0/dist/tutuca.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var I=t=>{if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||e===null},ke=t=>t==null?0:typeof t.length=="number"?t.length:typeof t.size=="number"?t.size:I(t)?Object.keys(t).length:0,w=(t,e,n=null)=>t==null?n:t instanceof Map?t.has(e)?t.get(e):n:t instanceof Set?t.has(e)?e:n:Object.hasOwn(t,e)?t[e]:typeof t.get=="function"?t.get(e,n):n,Ee=t=>Array.isArray(t),pr=t=>t instanceof Map||I(t),mr=t=>t instanceof Set;function*vr(t){if(t instanceof Map)yield*t.entries();else if(t instanceof Set)for(const e of t)yield[e,e];else if(I(t))yield*Object.entries(t);else if(Array.isArray(t))for(let e=0;e<t.length;e++)yield[e,t[e]]}var Te=Symbol.for("immer-nothing"),Ft=Symbol.for("immer-draftable"),_=Symbol.for("immer-state"),gr=[function(t){return`The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`},function(t){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${t}'`},"This object has been frozen and should not be mutated",function(t){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+t},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(t){return`'current' expects a draft, got: ${t}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(t){return`'original' expects a draft, got: ${t}`}];function y(t,...e){{const n=gr[t],r=typeof n=="function"?n.apply(null,e):n;throw new Error(`[Immer] ${r}`)}}var Y=Object.getPrototypeOf;function $(t){return!!t&&!!t[_]}function C(t){return t?Ce(t)||Array.isArray(t)||!!t[Ft]||!!t.constructor?.[Ft]||J(t)||mt(t):!1}var wr=Object.prototype.constructor.toString(),Oe=new WeakMap;function Ce(t){if(!t||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);if(e===null||e===Object.prototype)return!0;const n=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let r=Oe.get(n);return r===void 0&&(r=Function.toString.call(n),Oe.set(n,r)),r===wr}function dt(t,e,n=!0){pt(t)===0?(n?Reflect.ownKeys(t):Object.keys(t)).forEach(s=>{e(s,t[s],t)}):t.forEach((r,s)=>e(s,r,t))}function pt(t){const e=t[_];return e?e.type_:Array.isArray(t)?1:J(t)?2:mt(t)?3:0}function Mt(t,e){return pt(t)===2?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function xe(t,e,n){const r=pt(t);r===2?t.set(e,n):r===3?t.add(n):t[e]=n}function yr(t,e){return t===e?t!==0||1/t===1/e:t!==t&&e!==e}function J(t){return t instanceof Map}function mt(t){return t instanceof Set}function x(t){return t.copy_||t.base_}function Rt(t,e){if(J(t))return new Map(t);if(mt(t))return new Set(t);if(Array.isArray(t))return Array.prototype.slice.call(t);const n=Ce(t);if(e===!0||e==="class_only"&&!n){const r=Object.getOwnPropertyDescriptors(t);delete r[_];let s=Reflect.ownKeys(r);for(let i=0;i<s.length;i++){const a=s[i],o=r[a];o.writable===!1&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[a]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[a]})}return Object.create(Y(t),r)}else{const r=Y(t);if(r!==null&&n)return{...t};const s=Object.create(r);return Object.assign(s,t)}}function vt(t,e=!1){return wt(t)||$(t)||!C(t)||(pt(t)>1&&Object.defineProperties(t,{set:gt,add:gt,clear:gt,delete:gt}),Object.freeze(t),e&&Object.values(t).forEach(n=>vt(n,!0))),t}function _r(){y(2)}var gt={value:_r};function wt(t){return t===null||typeof t!="object"?!0:Object.isFrozen(t)}var Sr={};function D(t){const e=Sr[t];return e||y(0,t),e}var q;function De(){return q}function br(t,e){return{drafts_:[],parent_:t,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ve(t,e){e&&(D("Patches"),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function Lt(t){Bt(t),t.drafts_.forEach(Pr),t.drafts_=null}function Bt(t){t===q&&(q=t.parent_)}function Fe(t){return q=br(q,t)}function Pr(t){const e=t[_];e.type_===0||e.type_===1?e.revoke_():e.revoked_=!0}function Me(t,e){e.unfinalizedDrafts_=e.drafts_.length;const n=e.drafts_[0];return t!==void 0&&t!==n?(n[_].modified_&&(Lt(e),y(4)),C(t)&&(t=yt(e,t),e.parent_||_t(e,t)),e.patches_&&D("Patches").generateReplacementPatches_(n[_].base_,t,e.patches_,e.inversePatches_)):t=yt(e,n,[]),Lt(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==Te?t:void 0}function yt(t,e,n){if(wt(e))return e;const r=t.immer_.shouldUseStrictIteration(),s=e[_];if(!s)return dt(e,(i,a)=>Re(t,s,e,i,a,n),r),e;if(s.scope_!==t)return e;if(!s.modified_)return _t(t,s.base_,!0),s.base_;if(!s.finalized_){s.finalized_=!0,s.scope_.unfinalizedDrafts_--;const i=s.copy_;let a=i,o=!1;s.type_===3&&(a=new Set(i),i.clear(),o=!0),dt(a,(l,c)=>Re(t,s,i,l,c,n,o),r),_t(t,i,!1),n&&t.patches_&&D("Patches").generatePatches_(s,n,t.patches_,t.inversePatches_)}return s.copy_}function Re(t,e,n,r,s,i,a){if(s==null||typeof s!="object"&&!a)return;const o=wt(s);if(!(o&&!a)){if(s===n&&y(5),$(s)){const l=i&&e&&e.type_!==3&&!Mt(e.assigned_,r)?i.concat(r):void 0,c=yt(t,s,l);if(xe(n,r,c),$(c))t.canAutoFreeze_=!1;else return}else a&&n.add(s);if(C(s)&&!o){if(!t.immer_.autoFreeze_&&t.unfinalizedDrafts_<1||e&&e.base_&&e.base_[r]===s&&o)return;yt(t,s),(!e||!e.scope_.parent_)&&typeof r!="symbol"&&(J(n)?n.has(r):Object.prototype.propertyIsEnumerable.call(n,r))&&_t(t,s)}}}function _t(t,e,n=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&vt(e,n)}function Ar(t,e){const n=Array.isArray(t),r={type_:n?1:0,scope_:e?e.scope_:De(),modified_:!1,finalized_:!1,assigned_:{},parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1};let s=r,i=$t;n&&(s=[r],i=Z);const{revoke:a,proxy:o}=Proxy.revocable(s,i);return r.draft_=o,r.revoke_=a,o}var $t={get(t,e){if(e===_)return t;const n=x(t);if(!Mt(n,e))return Ir(t,n,e);const r=n[e];return t.finalized_||!C(r)?r:r===Kt(t.base_,e)?(Wt(t),t.copy_[e]=zt(r,t)):r},has(t,e){return e in x(t)},ownKeys(t){return Reflect.ownKeys(x(t))},set(t,e,n){const r=Le(x(t),e);if(r?.set)return r.set.call(t.draft_,n),!0;if(!t.modified_){const s=Kt(x(t),e),i=s?.[_];if(i&&i.base_===n)return t.copy_[e]=n,t.assigned_[e]=!1,!0;if(yr(n,s)&&(n!==void 0||Mt(t.base_,e)))return!0;Wt(t),Ht(t)}return t.copy_[e]===n&&(n!==void 0||e in t.copy_)||Number.isNaN(n)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=n,t.assigned_[e]=!0),!0},deleteProperty(t,e){return Kt(t.base_,e)!==void 0||e in t.base_?(t.assigned_[e]=!1,Wt(t),Ht(t)):delete t.assigned_[e],t.copy_&&delete t.copy_[e],!0},getOwnPropertyDescriptor(t,e){const n=x(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r&&{writable:!0,configurable:t.type_!==1||e!=="length",enumerable:r.enumerable,value:n[e]}},defineProperty(){y(11)},getPrototypeOf(t){return Y(t.base_)},setPrototypeOf(){y(12)}},Z={};dt($t,(t,e)=>{Z[t]=function(){return arguments[0]=arguments[0][0],e.apply(this,arguments)}}),Z.deleteProperty=function(t,e){return isNaN(parseInt(e))&&y(13),Z.set.call(this,t,e,void 0)},Z.set=function(t,e,n){return e!=="length"&&isNaN(parseInt(e))&&y(14),$t.set.call(this,t[0],e,n,t[0])};function Kt(t,e){const n=t[_];return(n?x(n):t)[e]}function Ir(t,e,n){const r=Le(e,n);return r?"value"in r?r.value:r.get?.call(t.draft_):void 0}function Le(t,e){if(!(e in t))return;let n=Y(t);for(;n;){const r=Object.getOwnPropertyDescriptor(n,e);if(r)return r;n=Y(n)}}function Ht(t){t.modified_||(t.modified_=!0,t.parent_&&Ht(t.parent_))}function Wt(t){t.copy_||(t.copy_=Rt(t.base_,t.scope_.immer_.useStrictShallowCopy_))}var Nr=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(e,n,r)=>{if(typeof e=="function"&&typeof n!="function"){const i=n;n=e;const a=this;return function(l=i,...c){return a.produce(l,u=>n.call(this,u,...c))}}typeof n!="function"&&y(6),r!==void 0&&typeof r!="function"&&y(7);let s;if(C(e)){const i=Fe(this),a=zt(e,void 0);let o=!0;try{s=n(a),o=!1}finally{o?Lt(i):Bt(i)}return Ve(i,r),Me(s,i)}else if(!e||typeof e!="object"){if(s=n(e),s===void 0&&(s=e),s===Te&&(s=void 0),this.autoFreeze_&&vt(s,!0),r){const i=[],a=[];D("Patches").generateReplacementPatches_(e,s,i,a),r(i,a)}return s}else y(1,e)},this.produceWithPatches=(e,n)=>{if(typeof e=="function")return(a,...o)=>this.produceWithPatches(a,l=>e(l,...o));let r,s;return[this.produce(e,n,(a,o)=>{r=a,s=o}),r,s]},typeof t?.autoFreeze=="boolean"&&this.setAutoFreeze(t.autoFreeze),typeof t?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),typeof t?.useStrictIteration=="boolean"&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){C(t)||y(8),$(t)&&(t=kr(t));const e=Fe(this),n=zt(t,void 0);return n[_].isManual_=!0,Bt(e),n}finishDraft(t,e){const n=t&&t[_];(!n||!n.isManual_)&&y(9);const{scope_:r}=n;return Ve(r,e),Me(void 0,r)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,e){let n;for(n=e.length-1;n>=0;n--){const s=e[n];if(s.path.length===0&&s.op==="replace"){t=s.value;break}}n>-1&&(e=e.slice(n+1));const r=D("Patches").applyPatches_;return $(t)?r(t,e):this.produce(t,s=>r(s,e))}};function zt(t,e){const n=J(t)?D("MapSet").proxyMap_(t,e):mt(t)?D("MapSet").proxySet_(t,e):Ar(t,e);return(e?e.scope_:De()).drafts_.push(n),n}function kr(t){return $(t)||y(10,t),Be(t)}function Be(t){if(!C(t)||wt(t))return t;const e=t[_];let n,r=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,n=Rt(t,e.scope_.immer_.useStrictShallowCopy_),r=e.scope_.immer_.shouldUseStrictIteration()}else n=Rt(t,!0);return dt(n,(s,i)=>{xe(n,s,Be(i))},r),e&&(e.finalized_=!1),n}var Er=new Nr,$e=Er.produce,m=Symbol("NONE"),Ke=(t,e,n)=>{t instanceof Map?t.set(e,n):t instanceof Set?(t.delete(e),t.add(n)):t[e]=n},He=(t,e,n)=>!(t instanceof Map||t instanceof Set||Array.isArray(t))&&!Object.hasOwn(t,e)&&typeof t?.set=="function"?t.set(e,n):Ke(t,e,n),Q=class{setDraftValue(t,e){}enterFrame(t,e,n){return t.enter(e,{},!0,n)}toAbstractPathStep(){return this}pinKey(t){return this}toKey(){return null}},Tr=class extends Q{constructor(t){super(),this.binds=t}lookup(t){return t}enterFrame(t,e,n){return t.enter(e,{...this.binds},!1,n)}toAbstractPathStep(){return null}},Or=class extends Tr{constructor(t,e={}){super(e),this.val=t}enterFrame(t,e,n){const r=this.val.evalAsHandler(t)?.call(t.it)??{};return t.enter(e,{...this.binds,...r},!1,n)}},tt=class extends Q{constructor(t){super(),this.field=t}lookup(t){return w(t,this.field,m)}setDraftValue(t,e){Ke(t,this.field,e)}toKey(){return{field:this.field}}},A=class extends Q{constructor(t,e){super(),this.field=t,this.key=e}lookup(t){return w(w(t,this.field,null),this.key,m)}setDraftValue(t,e){const n=w(t,this.field,null);n!=null&&He(n,this.key,e)}enterFrame(t,e,n){return t.enter(e,{key:this.key},!0,n)}toKey(){return{field:this.field,key:this.key}}},jt=class extends Q{constructor(t,e){super(),this.seqField=t,this.keyField=e}lookup(t){const e=w(t,this.seqField,m),n=w(t,this.keyField,m);return n!==m&&e!==m?w(e,n,m):m}setDraftValue(t,e){const n=w(t,this.seqField,m),r=w(t,this.keyField,m);n!==m&&r!==m&&He(n,r,e)}pinKey(t){const e=w(t,this.keyField,m);return e===m?this:new A(this.seqField,e)}toKey(){return{field:this.seqField}}},Cr=class extends Q{constructor(t,e){super(),this.eachNode=t,this.key=e}lookup(t){return t}enterFrame(t,e,n){return t.enter(e,this.eachNode.enrichBinds(t,this.key),!1,n)}toAbstractPathStep(){return null}},xr=class extends A{enterFrame(t,e,n){return t.enter(e,{key:this.key,value:e},!1,n).enter(e,{},!0,n)}toAbstractPathStep(){return new A(this.field,this.key)}};function Dr(t){return t instanceof A?{f:t.field,k:t.key}:t instanceof tt?{f:t.field}:t instanceof jt?{f:t.seqField,a:t.keyField}:null}function Vr(t){return t==null||typeof t.f!="string"?null:t.k!==void 0?new A(t.f,t.k):t.a!==void 0?new jt(t.f,t.a):new tt(t.f)}function We(t){const e=[];for(const n of t.steps){const r=Dr(n);if(r===null)return null;e.push(r)}return e}function ze(t){if(!Array.isArray(t))return null;const e=[];for(const n of t){const r=Vr(n);if(r===null)return null;e.push(r)}return new et(e)}var et=class xt{constructor(e=[]){this.steps=e}concat(e){return new xt(this.steps.concat(e))}compact(){const e=[];for(const n of this.steps){const r=n.toAbstractPathStep();r!==null&&e.push(r)}return new xt(e)}pinKeys(e){let n=e,r=null;for(let s=0;s<this.steps.length;s++){const i=this.steps[s],a=i.pinKey(n);if(a!==i&&((r??=this.steps.slice())[s]=a),n=i.lookup(n),n===m)break}return r?new xt(r):this}lookup(e,n=null){let r=e;for(const s of this.steps)if(r=s.lookup(r),r===m)return n;return r}resolveChain(e){const n=[e];let r=e;for(const s of this.steps){if(r=s.lookup(r),r===m)break;n.push(r)}return n}toKeys(){const e=[];for(const n of this.steps){const r=n.toKey();r!==null&&e.push(r)}return e}setValue(e,n){return this.steps.length===0?n:$e(e,r=>{let s=r;for(let i=0;i<this.steps.length-1;i++)if(s=this.steps[i].lookup(s),s===m)return;this.steps.at(-1).setDraftValue(s,n)})}};function Fr(t,e,n,r){let s=t.it;for(const i of e){const a=i.lookup(s);if(a===m)return console.warn("bad PathItem",{root:t.it,step:i,path:r}),null;n=n.pushItem(i),t=i.enterFrame(t,a,n),s=a}return[t,n]}var je=new et([]),St=class T{constructor(e=[{base:je,items:[]}]){this.frames=e}static ofSteps(e){return new T([{base:je,items:e.slice()}])}get top(){return this.frames[this.frames.length-1]}_withTopItems(e){const n=this.frames.slice();return n[n.length-1]={base:this.top.base,items:e},new T(n)}concat(e){return this._withTopItems(this.top.items.concat(e))}pushItem(e){return this.concat([e])}pushFrame(e){return new T(this.frames.concat({base:e,items:[]}))}canPop(){return this.frames.length>1||this.frames[0].items.length>0}popStep(){const{top:e}=this;return e.items.length>0?this._withTopItems(e.items.slice(0,-1)):this.frames.length>1?new T(this.frames.slice(0,-1)):this}compact(){return new T(this.frames.map(({base:e,items:n})=>({base:e,items:new et(n).compact().steps})))}get addressKey(){return this._addressKey??=Rr(this.toTransactionPath().compact()),this._addressKey}toTransactionPath(){const{base:e,items:n}=this.top;return e.concat(n)}buildStack(e){let n=new T;for(let r=0;r<this.frames.length;r++){const{base:s,items:i}=this.frames[r];if(r>0||s.steps.length>0){const o=s.lookup(e.root,m);if(o===m)return console.warn("bad frame base",{base:s,path:this}),null;n=n.pushFrame(s),e=e.enter(o,{},!0,n)}const a=Fr(e,i,n,this);if(a===null)return null;[e,n]=a}return e}static fromNodeAndEventName(e,n,r,s,i=!0){const a=[],o=Wr.has(n);let l=[],c=null,u=[],h=!0;const f=(p,S)=>{const B=s.getComponentForId(p);let P=!0;if(c===null&&(h||o))if(c=$r(B,l,S,n),c===null){if(h&&i&&!o)return!1}else h||(a.length=0,P=!1);if(h=!1,P){const O=Hr(B,u,S);O&&a.push(O)}return l=[],u=[],!0};for(;e&&e!==r;){if(e?.dataset){const{eid:p,cid:S,vid:B,rp:P}=e.dataset;p!==void 0&&l.push(p);const O=Br(e.previousSibling);let X=!1;for(const g of O)if(g.$==="Comp"){if(X=!0,!f(g.cid,g.vid))return Ue;u.push({nid:g.nid,base:ze(g.base)})}else u.push({nid:g.nid,si:g.si,sk:g.sk});if(!X&&S!==void 0){if(!f(+S,B))return Ue;if(P!==void 0){const g=Lr(P);g!==null&&u.push({base:g})}}}e=e.parentNode}a.reverse();let d=new T;for(const p of a)d=p.base!==void 0?d.pushFrame(p.base):d.pushItem(p.step);return[d,c]}};function Mr(t,e){const n=t.steps,r=n[n.length-1];return r instanceof A||r instanceof tt?new et(n.slice(0,-1).concat(new A(r.field,e))):null}function Rr(t){return JSON.stringify(We(t))}function Lr(t){try{return ze(JSON.parse(t))}catch(e){return console.warn("bad render path",e,t),null}}function Br(t){const e=[];for(;t?.nodeType===8&&t.textContent[0]==="\xA7";){try{e.push(JSON.parse(t.textContent.slice(1,-1)))}catch(n){console.warn(n,t)}t=t.previousSibling}return e}function $r(t,e,n,r){for(const s of e){const i=t.getEventForId(+s,n).getHandlersFor(r);if(i!==null)return i}return null}var Kr=class ir{constructor(e,n,r,s){this.comp=e,this.nodeIds=n,this.idx=r,this.vid=s}get meta(){return this.nodeIds[this.idx]}get key(){const e=this.meta;return e.si!==void 0?+e.si:e.sk}get hasKey(){const e=this.meta;return e.si!==void 0||e.sk!==void 0}next(){const{idx:e,nodeIds:n}=this;return e+1<n.length?new ir(this.comp,n,e+1,this.vid):null}resolveNode(){return this.comp.getNodeForId(+this.meta.nid,this.vid)}};function Hr(t,e,n){for(let r=0;r<e.length;r++){const s=e[r];if(s.base!=null)return{base:s.base};if(s.nid===void 0||s.nid===null)continue;const i=new Kr(t,e,r,n),a=i.resolveNode()?.toPathStep(i)??null;if(a!==null)return{step:a}}return null}var Ue=[null,null],Wr=new Set(["drop"]),zr=()=>new Ge,Ge=class{constructor(){this.pathChanges=[]}toPath(){return new et(this.pathChanges)}add(t){return this.pathChanges.push(t),this}field(t){return this.add(new tt(t))}index(t,e){return this.add(new A(t,e))}key(t,e){return this.add(new A(t,e))}},jr=(globalThis.navigator?.userAgent??"").toLowerCase().includes("mac"),Ur=/^[a-zA-Z][a-zA-Z0-9_]*\??$/,Ut=t=>Ur.test(t),Gr=/^-?[0-9]+(\.[0-9]+)?$/,Xr=/(\{[^}]+\})/g,nt=(t,e)=>Ut(t)?new e(t):null,Yr=/\$'(?:[^'\\]|\\.)*'|'(?:[^'\\]|\\.)*'|\S+/g,bt=t=>t.match(Yr)??[],Xe=t=>t.replace(/\\(['\\])/g,"$1"),rt=1,Gt=2,V=4,Xt=8,st=16,Pt=32,it=256,K=1024,Ye=2048,Yt=V|K|Xt|st|rt,Jr=Yt|Gt,qr=V|it|st,Zr=V|st,Qr=V|it,ts=V|K|rt|it,Je=V|K|Xt|st|Pt|rt,es=Je&~Pt|Ye,ns=Je|Gt|it;function qe(t){if(t==null)return null;const e=t.size;if(typeof e=="number")return e;const n=t.length;return typeof n=="number"?n:I(t)?Object.keys(t).length:null}var Ze=t=>Number.isNaN(t)?null:t;function Jt(t){return t.target.type==="checkbox"?t.target.checked:(t instanceof CustomEvent?t.detail:t.target.value)??null}var Qe=t=>{const e=qe(t);return e===null?!!t:e>0},rs={"empty?":{name:"empty?",arity:1,fn:t=>t==null||qe(t)===0},"truthy?":{name:"truthy?",arity:1,fn:Qe},"falsy?":{name:"falsy?",arity:1,fn:t=>!Qe(t)},"null?":{name:"null?",arity:1,fn:t=>t==null},"equals?":{name:"equals?",arity:2,fn:(t,e)=>Object.is(t,e)}};function N(t,e){const n=t.charCodeAt(0);if(n===39)return t.length>=2&&t.charCodeAt(t.length-1)===39?new v(Xe(t.slice(1,-1))):null;if(n===36&&t.charCodeAt(1)===39)return t.length>=3&&t.charCodeAt(t.length-1)===39?ds.parse(t.slice(2,-1),e):null;if(t.indexOf("[")!==-1||t.indexOf("]")!==-1)return ss(t,e);if(t.indexOf("{")!==-1||t.indexOf("}")!==-1)return null;switch(n){case 94:{const s=t.slice(1),i=e.frame.macroVars?.[s];if(i!==void 0){const a=bt(i.trim());if(a.length!==1)return null;const o=N(a[0],e);return o instanceof v&&(o.fromMacroVar=!0),o}return e.onParseIssue("bad-value",{role:"macro-var",name:s,value:t}),null}case 36:return nt(t.slice(1),ys);case 64:{const s=t.indexOf(".",1);if(s===-1)return nt(t.slice(1),rn);const i=t.slice(1,s),a=t.slice(s+1);return Ut(i)&&Ut(a)?new ws(i,a):null}case 42:return nt(t.slice(1),ot);case 46:return nt(t.slice(1),It)}const r=Gr.test(t)?parseFloat(t):null;return Number.isFinite(r)?new v(r):t==="true"||t==="false"?new v(t==="true"):n===101&&/^e(\.[a-zA-Z][a-zA-Z0-9_]*)+$/.exec(t)!==null?new gs(t.split(".").slice(1)):n>=97&&n<=122?nt(t,nn):null}function ss(t,e){const n=t.indexOf("["),r=t.indexOf("]");if(n<1||r!==t.length-1||r<n||t.indexOf("[",n+1)!==-1)return null;const s=N(t.slice(0,n),e),i=N(t.slice(n+1,r),e);return s instanceof It&&i instanceof It?new _s(s,i):null}function H(t,e,n){const r=bt(t.trim());if(r.length!==1)return null;const s=N(r[0],e);return s!==null&&at(s)&n?s:null}function W(t,e){const n=t.trim(),r=bt(n);if(r.length!==1)return r.length===0?null:hs(n,r,e);const s=N(r[0],e);return s!==null&&at(s)&Yt?s:null}var k=(t,e)=>H(t,e,Jr),is=(t,e)=>H(t,e,qr),tn=(t,e)=>H(t,e,Zr),as=(t,e)=>H(t,e,ts),os=(t,e)=>H(t,e,Qr),ls=(t,e)=>H(t,e,ns),cs=(t,e)=>en(t,e,"receive",!0,!0,!1),us=(t,e)=>en(t,e,"alter",!1,!1,!0)?.handlerVal??null;function en(t,e,n,r,s,i){const a=bt(t.trim()),o=a[0]??"",l=o===""?null:N(o,e),c=at(l);let u;if(c&K&&i)u=l;else{if(c&K)return s&&e.onParseIssue("event-method-handler",{name:l.name,role:"handler-name",value:o}),null;if(c&Pt)u=new ps(l.name,n);else return s&&e.onParseIssue("bad-value",{role:"handler-name",value:o}),null}if(!r)return a.length===1?{handlerVal:u,args:[]}:null;const h=new Array(a.length-1);for(let f=1;f<a.length;f++){const d=N(a[f],e);d!==null&&at(d)&es?h[f-1]=d:(s&&e.onParseIssue("bad-value",{role:"handler-arg",value:a[f]}),h[f-1]=qt)}return{handlerVal:u,args:h}}function hs(t,e,n){const r=e[0],s=rs[r];if(s===void 0)return n.onParseIssue("bad-value",{role:"predicate",value:r}),null;const i=e.length-1;if(i!==s.arity)return n.onParseIssue("bad-value",{role:"predicate-arity",value:t,predicate:r}),null;const a=new Array(i);for(let o=0;o<i;o++){const l=e[o+1],c=N(l,n);if(c===null||!(at(c)&Yt))return n.onParseIssue("bad-value",{role:"predicate-arg",value:l}),null;a[o]=c}return new fs(s,a)}var at=t=>t?.kind??0,F=class{kind=0;eval(t){}toPathItem(){return null}evalAsHandler(t){return this.eval(t)}},v=class extends F{constructor(t,e=rt){super(),this.val=t,this.kind=e}eval(t){return this.val}toString(){const t=this.val;return typeof t=="string"?`'${t.replace(/(['\\])/g,"\\$1")}'`:`${t}`}},qt=new v(null),fs=class extends F{constructor(t,e){super(),this.pred=t,this.args=e}eval(t){const e=this.args.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=this.args[r].eval(t);return this.pred.fn(...n)}toString(){return`${this.pred.name} ${this.args.map(String).join(" ")}`}},ds=class ar extends F{constructor(e){super(),this.vals=e,this.kind=this.isLiteral()?rt:Gt}isLiteral(){for(const e of this.vals)if(!(e instanceof v)||e.fromMacroVar)return!1;return!0}eval(e){const n=new Array(this.vals.length);for(let r=0;r<this.vals.length;r++)n[r]=this.vals[r]?.eval(e,"");return n.join("")}toLiteralSource(){if(!this.isLiteral())return null;let e="";for(const n of this.vals)e+=n.val;return new v(e).toString()}static parse(e,n){const r=Xe(e).split(Xr),s=new Array(r.length);for(let l=0;l<r.length;l++){const c=r[l],u=c[0]==="{"&&c.at(-1)==="}";s[l]=u?k(c.slice(1,-1),n):new v(c)}let i=0,a=s.length;const o=l=>l instanceof v&&l.val===""&&!l.fromMacroVar;for(;i<a&&o(s[i]);)i++;for(;a>i&&o(s[a-1]);)a--;return new ar(i===0&&a===s.length?s:s.slice(i,a))}},nn=class extends F{kind=Pt;constructor(t){super(),this.name=t}toString(){return this.name}},ps=class extends nn{constructor(t,e){super(t),this.namespace=e}eval(t){return t.getHandlerFor(this.name,this.namespace)??ms(t,this.namespace,this.name)}},ms=(t,e,n)=>function(...r){const s=t?.ctx?.transactor;return s?s.refuse("NO_HANDLER",{namespace:e,name:n,argCount:r.length}):console.warn("handler not found",{type:e,name:n}),this},z=t=>e=>e.key===t,Zt=t=>jr&&t.metaKey||t.ctrlKey,Qt=t=>(e,n)=>{const r=n.lookupDragInfo();return r==null?null:t(r)},vs={value:t=>Jt(t),valueAsInt:t=>Ze(parseInt(Jt(t),10)),valueAsFloat:t=>Ze(parseFloat(Jt(t))),isAlt:t=>t.altKey,isShift:t=>t.shiftKey,isCtrl:Zt,isCmd:Zt,isUpKey:z("ArrowUp"),isDownKey:z("ArrowDown"),isSend:z("Enter"),isCancel:z("Escape"),isTabKey:z("Tab"),dragInfo:(t,e)=>e.lookupDragInfo(),dragType:Qt(t=>t.type),dragValue:Qt(t=>t.val),dragKey:Qt(t=>t.lookupBind("key"))},gs=class extends F{kind=Ye;constructor(t){super(),this.members=t}eval(t){const e=t.lookupEvent();if(e==null)return null;if(this.members.length===1){const r=vs[this.members[0]];if(r!==void 0)return r(e,t)}let n=e;for(const r of this.members){if(n==null)return null;n=n[r]}return n??null}toString(){return`e.${this.members.join(".")}`}},At=class extends F{constructor(t){super(),this.name=t}toString(){return this.sigil+this.name}},rn=class extends At{kind=Xt;sigil="@";eval(t){return t.lookupBind(this.name)}},ws=class extends rn{constructor(t,e){super(t),this.member=e}eval(t){const e=t.lookupBind(this.name);return w(e,this.member,null)}toString(){return`@${this.name}.${this.member}`}},ot=class extends At{kind=st;sigil="*";eval(t){return t.lookupDynamic(this.name)}},It=class extends At{kind=V;sigil=".";eval(t){return t.lookupFieldRaw(this.name)}toPathItem(){return new tt(this.name)}},ys=class extends At{kind=K;sigil="$";eval(t){return t.lookupMethod(this.name)}evalAsHandler(t){return t.lookupFieldRaw(this.name)}},_s=class extends F{kind=it;constructor(t,e){super(),this.seqVal=t,this.keyVal=e}toPathItem(){return new jt(this.seqVal.name,this.keyVal.name)}eval(t){const e=this.keyVal.eval(t);return w(this.seqVal.eval(t),e,null)}toString(){return`${this.seqVal}[${this.keyVal}]`}},sn=class{constructor(t){this.items=t}isConstant(){return!1}},Ss="itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected",bs=new Set(Ss.split(","));function M(t,e,n,r){const s=r(n,t);return s===null&&t.onParseIssue("bad-value",{role:"directive",directive:e,value:n}),s}var Ps={when:"whenVal","loop-with":"loopWithVal","enrich-with":"enrichWithVal"},an=(t,e,n)=>M(t,e,n,us);function As(t,e){const n=r=>{const s=t.getNamedItem(`@${r}`);return s?an(e,r,s.value):null};return{whenVal:n("when"),loopWithVal:n("loop-with")}}var on=class{constructor(t){this.px=t,this.attrs=null,this.hasDynamic=!1,this.wrapperAttrs=null,this.textChild=null,this.eachAttr=null,this.ifAttr=null,this.events=null}parseAttr(t,e,n=!1){const r=n?ls(e,this.px):k(e,this.px);r!==null?(this.attrs??=[],this.attrs.push(new te(t,r)),this.hasDynamic||=!(r instanceof v)):this.px.onParseIssue("bad-value",{role:"attr",attr:t,value:e})}pushWrapper(t,e,n){const r={name:t,val:n,raw:e};return this.wrapperAttrs??=[],this.wrapperAttrs.push(r),r}parseIf(t,e){const n=W(e,this.px);if(n)this.ifAttr=new Es(t.slice(3),n),this.attrs??=[],this.attrs.push(this.ifAttr),this.hasDynamic=!0;else{const r={role:"if",attr:t.slice(3),value:e};this.px.onParseIssue("bad-value",r)}}parseBranch(t,e,n){if(this.ifAttr===null)return this._orphan(e,n,"if");this.ifAttr[t]=k(n,this.px)??Nt}parseIter(t,e){const n=an(this.px,t,e);this.eachAttr!==null?this.eachAttr[Ps[t]]=n:t==="enrich-with"?this.pushWrapper("scope",e,n):this._orphan(t,e,"each")}_orphan(t,e,n){this.px.onParseIssue("orphan-directive",{name:t,value:e,needs:n})}parseEvent(t,e){const[n,...r]=t.slice(3).split("+"),s=Ts.parse(e,this.px);s&&(this.events===null&&(this.events=this.px.registerEvents(),this.attrs??=[],this.attrs.push(new ee("data-eid",new v(this.events.id)))),this.events.add(n,s,r))}parseDirective(t,e){switch(e){case"dangerouslysetinnerhtml":this.attrs??=[],this.attrs.push(new ks(M(this.px,e,t,k))),this.hasDynamic=!0;return;case"push-view":this.pushWrapper("push-view",t,M(this.px,e,t,k));return;case"text":this.textChild=M(this.px,e,t,k);return;case"show":this.pushWrapper("show",t,M(this.px,e,t,W));return;case"hide":this.pushWrapper("hide",t,M(this.px,e,t,W));return;case"each":{const n=M(this.px,e,t,tn);this.eachAttr=this.pushWrapper("each",t,n);return}case"when":case"loop-with":case"enrich-with":this.parseIter(e,t);return;case"then":this.parseBranch("thenVal",e,t);return;case"else":this.parseBranch("elseVal",e,t);return}if(e.startsWith("on."))this.parseEvent(e,t);else if(e.startsWith("if."))this.parseIf(e,t);else if(e.startsWith("then."))this.parseBranch("thenVal",e,t);else if(e.startsWith("else."))this.parseBranch("elseVal",e,t);else{const n={name:e,value:t};this.px.onParseIssue("unknown-directive",n)}}parse(t,e=!1){for(const{name:i,value:a}of t){const o=i.charCodeAt(0);if(o===58)this.parseAttr(i===":viewbox"?"viewBox":i.slice(1),a,e);else if(o===64)this.parseDirective(a,i.slice(1));else{this.attrs??=[];const l=a===""&&bs.has(i)?!0:a;this.attrs.push(new ee(i,new v(l)))}}const{attrs:n,hasDynamic:r}=this;return[r?new Ns(n):Is.fromAttrs(n??[]),this.wrapperAttrs,this.textChild]}},Is=class or extends sn{eval(e){return this.items}static fromAttrs(e){const n={};for(const r of e)n[r.name]=r.val.eval(null);return new or(n)}setDataAttr(e,n){this.items[e]=n}toMacroVars(){const e={};for(const n in this.items)e[n]=new v(`${this.items[n]}`).toString();return e}isConstant(){return!0}},Ns=class extends sn{eval(t){const e={};for(let n=0;n<this.items.length;n++){const r=this.items[n];e[r.name]=r.eval(t)}return e}setDataAttr(t,e){this.items.push(new ee(t,new v(e)))}toMacroVars(){const t={};for(const e of this.items)t[e.name]=e.val.toString();return t}},ln=class{constructor(t){this.name=t}},te=class extends ln{constructor(t,e){super(t),this.val=e}eval(t){return this.val.eval(t)}},ee=class extends te{},ks=class extends te{constructor(t){super("dangerouslySetInnerHTML",t??qt)}eval(t){return{__html:`${this.val.eval(t)}`}}},Nt=qt,Es=class extends ln{constructor(t,e){super(t),this.condVal=e,this.thenVal=this.elseVal=Nt}get anyBranchIsSet(){return this.thenVal!==Nt||this.elseVal!==Nt}eval(t){return this.condVal.eval(t)?this.thenVal.eval(t):this.elseVal.eval(t)}},Ts=class lr{constructor(e,n=[]){this.handlerVal=e,this.args=n}getHandlerAndArgs(e,n){const r=new Array(this.args.length);for(let s=0;s<r.length;s++)r[s]=this.args[s].eval(e);return[this.handlerVal.evalAsHandler(e),r]}static parse(e,n){const r=cs(e,n);return r===null?null:new lr(r.handlerVal,r.args)}},cn=Symbol.for("tutuca.seqInfo"),un=(t,e,n)=>{let r=t==null?0:t<0?n+t:t,s=e==null?n:e<0?n+e:e;return r=r<0?0:r>n?n:r,s=s<0?0:s>n?n:s,[r,s<r?r:s]},Os=(t,e,n,r)=>{const[s,i]=un(n,r,ke(t));for(let a=s;a<i;a++)e(a,t[a],"si")},Cs=(t,e,n,r)=>{const[s,i]=un(n,r,ke(t));let a=0;for(const[o,l]of vr(t)){if(a>=i)break;a>=s&&e(o,l,"sk"),a++}},xs=()=>{},Ds=t=>Ee(t)?Os:pr(t)||mr(t)?Cs:t?.[cn]??xs,Vs=(t,e,n)=>!0,Fs=t=>({iterData:{seq:t}}),hn=(t,e)=>{const n=t??{};return{iterData:n.iterData??{seq:e},start:n.start,end:n.end,keys:n.keys}},fn=(t,e)=>({lookup:n=>t.lookupBind(n),filter:(n,r,s)=>e.call(t.it,n,r,s)}),dn=(t,e,n,r,s,i)=>{t.call(e,n,r,s,i),console.assert(n.key===r&&n.value===s,"@enrich-with handlers must not overwrite binds.key or binds.value"),n.key=r,n.value=s};function Ms({seq:t,it:e,loopWith:n,enricher:r,ctx:s},i){const a=w(t,i,null),o={key:i,value:a};if(r){const{iterData:l}=hn(n.call(e,t,s),t);dn(r,e,o,i,a,l)}return o}var Rs=(t,e,n)=>{const r=Ee(t)?"si":"sk";for(const s of e)n(s,w(t,s),r)};function Ls({seq:t,it:e,filter:n,loopWith:r,enricher:s,ctx:i},a){const{iterData:o,start:l,end:c,keys:u}=hn(r.call(e,t,i),t),h=(f,d,p)=>{const S={key:f,value:d};s&&dn(s,e,S,f,d,o),a(f,d,p,S)};u?Rs(t,u,h):Ds(t)(t,(f,d,p)=>{n.call(e,f,d,o)&&h(f,d,p)},l,c)}var pn="http://www.w3.org/1999/xhtml",mn="http://www.w3.org/2000/svg",Bs="http://www.w3.org/1998/Math/MathML",ne=t=>{const e=t.namespaceURI;return e!==null&&e!==pn},$s=t=>t.length===13&&t.toLowerCase()==="foreignobject",vn=(t,e)=>t.namespace??e.namespace??null;function gn(t,e,n){const r=e===mn&&$s(t.tag)?null:e;return r===(n.namespace??null)?n:{...n,namespace:r}}var Ks=new Set("width height href list form tabIndex download rowSpan colSpan role popover".split(" ")),Hs={className:"class",htmlFor:"for"};function wn(t,e){const n=ne(t);for(const r in e)re(t,r,e[r],n)}function re(t,e,n,r){if(e==="dangerouslySetInnerHTML"){if(n===void 0)t.replaceChildren();else{const i=n.__html??"";i!==t.innerHTML&&(t.innerHTML=i)}return}if(typeof n=="function")return;const s=!r&&!Ks.has(e)&&e in t;if(s&&n!=null)try{t[e]=n;return}catch{}if(n==null||n===!1&&e[4]!=="-")if(s){try{t[e]=""}catch{}t.removeAttribute(Hs[e]??e)}else t.removeAttribute(e);else t.setAttribute(e,n)}function yn(t,e){t.tagName==="PROGRESS"&&(e==null||e===0)?t.removeAttribute("value"):re(t,"value",e,ne(t))}var lt=class{},ct=t=>t instanceof kt?t.key:void 0,Ws=t=>t!=null&&typeof t!="string"&&typeof t[Symbol.iterator]=="function";function _n(t,e){if(t===e)return!0;for(let n=0;n<t.length;n++)if(!t[n].isEqualTo(e[n]))return!1;return!0}function se(t,e,n){for(const r of e)t.appendChild(r.toDom(n))}function ie(t,e){if(e!=null)if(Ws(e))for(const n of e)ie(t,n);else e instanceof lt?e instanceof E?t.push(...e.childs):t.push(e):t.push(new zs(e))}var zs=class cr extends lt{constructor(e){super(),this.text=String(e)}get nodeType(){return 3}isEqualTo(e){return e instanceof cr&&this.text===e.text}toDom(e){return e.document.createTextNode(this.text)}},ae=class ur extends lt{constructor(e){super(),this.text=e}get nodeType(){return 8}isEqualTo(e){return e instanceof ur&&this.text===e.text}toDom(e){return e.document.createComment(this.text)}},E=class hr extends lt{constructor(e){super(),this.childs=[],ie(this.childs,e)}get nodeType(){return 11}isEqualTo(e){return!(e instanceof hr)||this.childs.length!==e.childs.length?!1:_n(this.childs,e.childs)}toDom(e){const n=e.document.createDocumentFragment();return se(n,this.childs,e),n}},kt=class fr extends lt{constructor(e,n,r,s,i){super(),this.tag=e,this.attrs=n??{},this.childs=r??[],this.key=s!=null?String(s):void 0,this.namespace=typeof i=="string"?i:null}get nodeType(){return 1}isSameKind(e){return this.tag===e.tag&&this.namespace===e.namespace&&this.key===e.key}isEqualTo(e){if(this===e)return!0;if(!(e instanceof fr)||!this.isSameKind(e)||this.childs.length!==e.childs.length)return!1;if(this.attrs!==e.attrs){for(const n in this.attrs)if(this.attrs[n]!==e.attrs[n])return!1;for(const n in e.attrs)if(!Object.hasOwn(this.attrs,n))return!1}return _n(this.childs,e.childs)}toDom(e){const n=e.document,r=vn(this,e),s=r!==null&&this.tag===this.tag.toUpperCase()?this.tag.toLowerCase():this.tag,i=this.attrs,a=i.is!=null?{is:i.is}:void 0,o=r===null?n.createElement(s,a):n.createElementNS(r,s,a),l=gn(this,r,e);return Sn(o,i,()=>se(o,this.childs,l)),o}};function Sn(t,e,n){const r="value"in e,s="checked"in e;if(r||s){const{value:i,checked:a,...o}=e;wn(t,o)}else wn(t,e);n(),r&&yn(t,e.value),s&&re(t,"checked",e.checked,ne(t))}function js(t,e){if(t===e)return null;let n=null;for(const r in t)Object.hasOwn(e,r)?t[r]!==e[r]&&(n??={},n[r]=e[r]):(n??={},n[r]=void 0);for(const r in e)Object.hasOwn(t,r)||(n??={},n[r]=e[r]);return n}function oe(t,e,n,r){if(e===n||e.isEqualTo(n))return t;const s=e.nodeType;if(s===n.nodeType){if(s===3||s===8)return t.data=n.text,t;if(s===1&&e.isSameKind(n)){const a=js(e.attrs,n.attrs),o=()=>{if(n.attrs.dangerouslySetInnerHTML)return;const l=vn(n,r);bn(t,e.childs,n.childs,gn(n,l,r))};return a?Sn(t,a,o):o(),!(a&&"value"in a)&&e.tag==="SELECT"&&n.attrs.value!==void 0&&yn(t,n.attrs.value),t}if(s===11)return bn(t,e.childs,n.childs,r),t}const i=n.toDom(r);return t.parentNode?.replaceChild(i,t),i}function bn(t,e,n,r){if(e.length===0){se(t,n,r);return}if(n.length===0){t.replaceChildren();return}if(e.length===n.length){let l=!1;for(let c=0;c<e.length;c++)if(ct(e[c])!=null||ct(n[c])!=null){l=!0;break}if(!l){let c=t.firstChild;for(let u=0;u<e.length;u++){const h=c.nextSibling;oe(c,e[u],n[u],r),c=h}return}}const s=Array.from(t.childNodes),i=Object.create(null);for(let l=0;l<e.length;l++){const c=ct(e[l]);c!=null&&(i[c]=l)}const a=new Uint8Array(e.length);let o=0;for(let l=0;l<n.length;l++){const c=n[l],u=ct(c);let h=-1;if(u!=null)u in i&&!a[i[u]]&&(h=i[u]);else for(;o<e.length;){if(!a[o]&&ct(e[o])==null){h=o++;break}o++}if(h>=0){a[h]=1;const f=oe(s[h],e[h],c,r),d=t.childNodes[l]??null;f!==d&&t.insertBefore(f,d)}else{const f=t.childNodes[l]??null;t.insertBefore(c.toDom(r),f)}}for(let l=e.length-1;l>=0;l--)!a[l]&&s[l].parentNode===t&&t.removeChild(s[l])}function Us(t,e,n,r){if(t==null)return e.replaceChildren(),{vnode:null,dom:null};const s=t instanceof E;if(r&&r.vnode instanceof E===s){const a=s?e:r.dom,o=oe(a,r.vnode,t,n);return{vnode:t,dom:s?e:o}}const i=t.toDom(n);return e.replaceChildren(i),{vnode:t,dom:s?e:i}}function Gs(t,e,n,r){const s={};let i;if(e)for(const c in e){const u=e[c];c==="key"?i=u:c==="namespace"?r=r??u:s[c]=u}if(r==null){const c=t.toLowerCase();c==="svg"?(r=mn,t="svg"):c==="math"&&(r=Bs,t="math")}const a=t.charCodeAt(0),o=r==null&&a>=97&&a<=122&&t===t.toLowerCase()?t.toUpperCase():t,l=[];return ie(l,n),new kt(o,s,l,i,r)}function Xs(t,e){if(t instanceof ot){const s=e.lookupDynamicLocated(t.name);return s?.path==null?[s?.value??null,e.renderPath,null]:[s.value,e.renderPath.pushFrame(s.path),s.path]}const n=t.toPathItem?.()??null;if(n===null)return[t.eval(e),e.renderPath,null];const r=e.renderPath.pushItem(n);return[t.eval(e),r,e.pendingFrame?r.toTransactionPath():null]}var ut=class{render(t,e){return null}setDataAttr(t,e){}isConstant(){return!1}isWhiteSpace(){return!1}optimize(){}},le=class extends ut{constructor(t){super(),this.val=t}render(t,e){return this.val}isWhiteSpace(){for(let t=0;t<this.val.length;t++){const e=this.val.charCodeAt(t);if(!(e===32||e===10||e===9||e===13))return!1}return!0}hasNewLine(){for(let t=0;t<this.val.length;t++){const e=this.val.charCodeAt(t);if(e===10||e===13)return!0}return!1}condenseWhiteSpace(t=""){this.val=t}isConstant(){return!0}},R=class extends le{render(t,e){return e.renderComment(this.val)}};function Et(t){return t.isConstant()?new si(t):(t.optimize(),t)}var Pn=class extends ut{constructor(t){super(),this.childs=t}isConstant(){return this.childs.every(t=>t.isConstant())}optimize(){const{childs:t}=this;for(let e=0;e<t.length;e++)t[e]=Et(t[e])}},An=class extends Pn{constructor(t,e,n,r=null){super(n),this.tagName=t,this.attrs=e,this.namespace=r}render(t,e){const n=new Array(this.childs.length);for(let r=0;r<n.length;r++)n[r]=this.childs[r].render(t,e);return e.renderTag(this.tagName,this.attrs.eval(t),n,this.namespace)}setDataAttr(t,e){this.attrs.setDataAttr(t,e)}isConstant(){return this.attrs.isConstant()&&super.isConstant()}},ce=class extends Pn{render(t,e){return e.renderFragment(this.childs.map(n=>n.render(t,e)))}setDataAttr(t,e){for(const n of this.childs)n.setDataAttr(t,e)}},j=t=>t.length===1?t[0]:new ce(t),Ys=/^[a-zA-Z][a-zA-Z0-9-]*$/,ht=class Dt extends ut{constructor(e,n){super(),this.nodeId=e,this.val=n}toPathStep(e){return this.val?.toPathItem?.()??null}static parse(e,n){const r=n.parseHTML(e);if(r.length===0)return new R("Empty View in ANode.parse");if(r.length===1)return Dt.fromDOM(r[0],n);const s=[];for(let a=0;a<r.length;a++){const o=Dt.fromDOM(r[a],n);o!==null&&s.push(o)}const i=xn(s);return i.length===0?new R("Empty View in ANode.parse"):j(i)}static fromDOM(e,n){if(e.nodeType===3)return new le(e.textContent);if(e.nodeType===8)return new R(e.textContent);const{childNodes:r,attributes:s,tagName:i}=e,a=[];for(let l=0;l<r.length;l++){const c=Dt.fromDOM(r[l],n);c!==null&&a.push(c)}const o=n.currentTag;n.currentTag=i;try{const l=s[0]?.name==="@x";if(i==="X"||l)return Js(s,a,l?1:0,n);if(i.charCodeAt(1)===58&&(i.charCodeAt(0)===88||i.charCodeAt(0)===120)){const c=i.slice(2).toLowerCase();if(c==="slot"){const f=s.getNamedItem("name")?.value??"_";return n.frame.macroSlots[f]??j(a)}const[u,h]=new on(n).parse(s,!0);return n.onAttributes(u,h,null,!0,i),In(n.newMacroNode(c,u.toMacroVars(),a),n,h)}else if(Ys.test(i)){const[c,u,h]=new on(n).parse(s);n.onAttributes(c,u,h,!1,i),h&&a.unshift(new En(null,h));const f=i!=="PRE"?xn(a):a,d=e.namespaceURI,p=d&&d!==pn?d:null;return In(new An(i,c,f,p),n,u)}return new R(`Error: InvalidTagName ${i}`)}finally{n.currentTag=o}}};function Js(t,e,n,r){if(t.length<=n)return j(e);const{name:s,value:i}=t[n];de[s]?.ignoresChildren&&pi(e)&&r.onParseIssue("x-op-ignores-children",{op:s});const a=t.getNamedItem("as")?.value??null,o=a===null?null:qs(a,r);let l;switch(s){case"slot":l=new ai(null,new v(i),j(e));break;case"text":l=r.addNodeIf(En,ft(s,i,r,k));break;case"render":l=r.addNodeIf(ni,ft(s,i,r,is),o);break;case"render-it":l=r.addNode(kn,o);break;case"render-each":l=ri(r,i,o,t);break;case"show":{const c=ft(s,i,r,W);l=r.addNodeIf(ue,c,j(e));break}case"hide":{const c=ft(s,i,r,W);l=r.addNodeIf(he,c,j(e));break}default:return r.onParseIssue("unknown-x-op",{name:s,value:i}),new R(`Error: InvalidSpecialTagOp ${s}=${i}`)}return Zs(l,t,s,n+1,r)}function ft(t,e,n,r){const s=r(e,n);return s===null&&n.onParseIssue("bad-value",{role:"x-op",op:t,value:e}),s}function qs(t,e){return k(t,e)??new v(t)}function Zs(t,e,n,r,s){const{consumed:i,wrappable:a}=de[n],o=[];for(let l=r;l<e.length;l++){const c=e[l],u=c.name;if(i.has(u))continue;if(a&&u.charCodeAt(0)===64){const f=de[u.slice(1)]?.wrapper;if(f){o.push([f,W(c.value,s)]);continue}}const h={op:n,name:u,value:c.value};s.onParseIssue("unknown-x-attr",h)}for(let l=o.length-1;l>=0;l--){const[c,u]=o[l],h=s.addNodeIf(c,u,t);h!==null&&(t=h)}return t}function In(t,e,n){if(n)for(let r=n.length-1;r>=0;r--){const s=Qs(n[r],e);s&&(s.wrapNode(t),t=s)}return t}function Qs(t,e){const n=ci[t.name],r=n.register?e.addNodeIf(n,t.val):t.val&&new n(null,t.val);return r!==null&&t.name==="each"&&(r.iterInfo.enrichWithVal=t.enrichWithVal??null,r.iterInfo.whenVal=t.whenVal??null,r.iterInfo.loopWithVal=t.loopWithVal??null),r}var ti=class extends ut{constructor(t,e,n,r){super(),this.name=t,this.attrs=e,this.slots=n,this.px=r,this.node=null,this.dataAttrs={}}compile(t){const{name:e,attrs:n,slots:r}=this;if(this.px.isInsideMacro(e))throw new Error(`Recursive macro expansion: ${e}`);const s=t.lookupMacro(e);if(s===null)this.node=new R(`bad macro: ${e}`);else{const i={...s.defaults,...n};this.node=s.expand(this.px.enterMacro(e,i,r));for(const a in this.dataAttrs)this.node.setDataAttr(a,this.dataAttrs[a])}}render(t,e){return this.node.render(t,e)}setDataAttr(t,e){this.dataAttrs[t]=e}isConstant(){return this.node.isConstant()}optimize(){this.node=Et(this.node)}},ei=class{constructor(t,e){this.defaults=t,this.rawView=e}expand(t){return ht.parse(this.rawView,t)}},Nn=class extends ht{constructor(t,e,n){super(t,e),this.viewVal=n}evalViewName(t){return this.viewVal?this.viewVal.eval(t):null}},ni=class extends Nn{render(t,e){const[n,r,s]=Xs(this.val,t),i=t.enter(n,{},!0,r,!1);return e.renderIt(i,this,this.evalViewName(t),s)}toPathStep(t){return this.val instanceof ot?null:super.toPathStep(t)}},kn=class extends Nn{render(t,e){const n=t.pendingFrame?t.renderPath.toTransactionPath():null,r=t.enter(t.it,{},!0,t.renderPath,!1);return e.renderIt(r,this,this.evalViewName(t),n)}toPathStep(t){const e=t.next();if(e===null)return null;const n=e.resolveNode();return n instanceof fe&&e.hasKey?n.val instanceof ot?null:new xr(n.val.name,e.key):null}};function ri(t,e,n,r){const s=ft("render-each",e,t,tn);if(s===null)return null;const i=t.addNode(kn,n),{whenVal:a,loopWithVal:o}=As(r,t),l=t.addNodeIf(fe,s);return l.iterInfo.whenVal=a,l.iterInfo.loopWithVal=o,l.fromRenderEach=!0,l.wrapNode(i),l}var En=class extends ht{render(t,e){return this.val.eval(t)}},si=class extends ut{constructor(t){super(),this.node=t,this._render=(e,n)=>{const r=t.render(e,n);return this._render=(s,i)=>r,r}}render(t,e){return this._render(t,e)}},U=class extends ht{constructor(t,e,n=null){super(t,e),this.node=n}wrapNode(t){this.node=t}setDataAttr(t,e){this.node.setDataAttr(t,e)}optimize(){this.node=Et(this.node)}static register=!1},ue=class extends U{render(t,e){return this.val.eval(t)?this.node.render(t,e):null}},he=class extends U{render(t,e){return this.val.eval(t)?null:this.node.render(t,e)}},ii=class extends U{render(t,e){return this.node.render(t.pushViewName(this.val.eval(t)),e)}},ai=class extends U{isSlotNode=!0;optimize(){this.node.optimize()}},oi=class extends U{render(t,e){const n=this.val.evalAsHandler(t)?.call(t.it)??{},r=this.node.render(t.enter(t.it,n,!1),e);return e.renderScopeMeta(this.nodeId,r)}toPathStep(t){return new Or(this.val)}wrapNode(t){this.node=t,this.node.setDataAttr("data-nid",this.nodeId)}static register=!0},fe=class extends U{constructor(t,e){super(t,e),this.iterInfo=new li}render(t,e){return e.renderEachWhen(t,this)}evalIter(t){const{whenVal:e,loopWithVal:n,enrichWithVal:r}=this.iterInfo;return{seq:this.val.eval(t)??[],filter:e?.evalAsHandler(t)??Vs,loopWith:n?.evalAsHandler(t)??Fs,enricher:r?.evalAsHandler(t)??null}}enrichBinds(t,e){const{seq:n,filter:r,loopWith:s,enricher:i}=this.evalIter(t),a=fn(t,r);return Ms({seq:n,it:t.it,loopWith:s,enricher:i,ctx:a},e)}toPathStep(t){return t.hasKey?new Cr(this,t.key):null}itemStep(t){return this.val instanceof It?new A(this.val.name,t):null}static register=!0},li=class{constructor(){this.whenVal=null,this.loopWithVal=null,this.enrichWithVal=null}};function L(t=[],{wrappable:e=!1,wrapper:n=null,ignoresChildren:r=!1}={}){return{consumed:new Set(t),wrappable:e,wrapper:n,ignoresChildren:r}}var de={slot:L(),text:L([],{wrappable:!0,ignoresChildren:!0}),render:L(["as"],{wrappable:!0,ignoresChildren:!0}),"render-it":L(["as"],{wrappable:!0,ignoresChildren:!0}),"render-each":L(["as","@when","@loop-with"],{wrappable:!0,ignoresChildren:!0}),show:L([],{wrapper:ue}),hide:L([],{wrapper:he})},ci={show:ue,hide:he,each:fe,scope:oi,"push-view":ii},Tn=class{constructor(t=globalThis.document){this.document=t,this.nodes=[],this.events=[],this.macroNodes=[],this.parent=null,this.frame={},this.currentTag=null}isInsideMacro(t){return this.frame.macroName===t||this.parent?.isInsideMacro(t)}enterMacro(t,e,n){const r=Object.create(Object.getPrototypeOf(this));return Object.assign(r,this,{frame:{macroName:t,macroVars:e,macroSlots:n},parent:this,currentTag:null})}parseHTML(t){const e=this.document.createElement("template");return e.innerHTML=t,e.content.childNodes}addNodeIf(t,e,n){if(e!==null){const r=this.nodes.length,s=new t(r,e,n);return this.nodes.push(s),s}return null}addNode(t,e){const n=this.nodes.length,r=new t(n,null,e);return this.nodes.push(r),r}registerEvents(){const t=this.events.length,e=new mi(t);return this.events.push(e),e}newMacroNode(t,e,n){const r=[],s={_:new ce(r)};for(const a of n)a.isSlotNode?s[a.val.val]=a.node:a.isWhiteSpace()||r.push(a);const i=new ti(t,e,s,this);return this.macroNodes.push(i),i}compile(t){for(let e=0;e<this.macroNodes.length;e++)this.macroNodes[e].compile(t)}*genEventNames(){for(const t of this.events)yield*t.genEventNames()}getEventForId(t){return this.events[t]??null}getNodeForId(t){return this.nodes[t]??null}onAttributes(t,e,n,r,s){}onParseIssue(t,e){console.warn(`tutuca parse issue [${t}]`,e)}},ui="ADDRESS,ARTICLE,ASIDE,BLOCKQUOTE,CAPTION,COL,COLGROUP,DETAILS,DIALOG,DIV,DD,DL,DT,FIELDSET,FIGCAPTION,FIGURE,FOOTER,FORM,H1,H2,H3,H4,H5,H6,HEADER,HGROUP,HR,LEGEND,LI,MAIN,MENU,NAV,OL,P,PRE,SECTION,SUMMARY,TABLE,TBODY,TD,TFOOT,TH,THEAD,TR,UL",hi=new Set(ui.split(",")),On=t=>{const e=t instanceof ce?t.childs[0]:t;return e instanceof An&&hi.has(e.tagName)},fi=t=>t instanceof le&&t.val==="",di=t=>t instanceof R||t.isWhiteSpace(),pi=t=>t.some(e=>!di(e));function Cn(t){return t.isWhiteSpace()?(t.condenseWhiteSpace(),!0):!1}function xn(t){if(t.length===0)return t;const e=t.length-1;let n=Cn(t[0]);e>0&&Cn(t[e])&&(n=!0);for(let r=1;r<e;r++){const s=t[r];if(!(s.isWhiteSpace()&&s.hasNewLine()))continue;const i=On(t[r-1])&&On(t[r+1]);s.condenseWhiteSpace(i?"":" "),i&&(n=!0)}return n?t.filter(r=>!fi(r)):t}var Dn=class{constructor(t,e="No View Defined",n=""){this.name=t,this.rawView=e,this.style=n,this.anode=null,this.ctx=null}compile(t,e,n){this.ctx=t,this.anode=ht.parse(this.rawView,t),this.anode.setDataAttr("data-cid",n),this.anode.setDataAttr("data-vid",this.name),this.ctx.compile(e),this.anode=Et(this.anode)}render(t,e){if(this.anode===null)throw new Error(`tutuca: view "${this.name}" was rendered before it was compiled \u2014 its component is not registered in this app/scope. Source: ${String(this.rawView).slice(0,80).replace(/\s+/g," ")}\u2026`);return this.anode.render(t,e)}},mi=class{constructor(t){this.id=t,this.handlers=[]}add(t,e,n){this.handlers.push(new vi(t,e,n))}*genEventNames(){for(const t of this.handlers)yield t.name}getHandlersFor(t){let e=null;for(const n of this.handlers)n.name===t&&(e??=[],e.push(n));return e}},vi=class{constructor(t,e,n){this.name=t,this.handlerCall=e,this.modifierWrapper=Ii(t,n),this.modifiers=n}getHandlerAndArgs(t,e){const n=this.handlerCall.getHandlerAndArgs(t,e);return n[0]=this.modifierWrapper(n[0],e),n}},gi=t=>e=>(n,r,s,i)=>t(i)?e(n,r,s,i):n,Tt=t=>gi(({e})=>t(e)),Vn=t=>Tt(z(t)),Fn=Tt(Zt),wi=Tt(t=>t.metaKey),yi=Tt(t=>t.altKey),_i={ctrl:Fn,cmd:Fn,meta:wi,alt:yi},Si={keydown:{send:Vn("Enter"),cancel:Vn("Escape")}},bi={prevent:t=>t.preventDefault?.(),stop:t=>t.stopPropagation?.()},Pi={},Ai=(t,e)=>t;function Ii(t,e){if(e.length===0)return Ai;const n=Si[t]??Pi,r=[];for(const i of e){const a=bi[i];a!==void 0&&r.push(a)}let s=r.length===0?(i,a,o,l)=>a.apply(i,o):(i,a,o,l)=>{for(const c of r)c(l.e);return a.apply(i,o)};for(const i of e){const a=n[i]??_i[i];a!==void 0&&(s=a(s))}return(i,a)=>function(...o){return s(this,i,o,a)}}var Mn=Symbol("STOP"),pe=Symbol("NEXT"),me=["dyn","lex"],G=t=>{const e=t.charCodeAt(0);return e>=65&&e<=90};function ve(t,e,n=null){let r=t;for(;r!==null;){const s=r[0].lookup(e);if(s===Mn)return n;if(s!==pe)return s;r=r[1]}return n}var Rn=class{constructor(t,e,n){this.it=t,this.binds=e,this.isFrame=n}lookup(t){const e=this.binds[t];return e===void 0?this.isFrame?Mn:pe:e}},Ln=class{constructor(t,e){this.binds=t,this.types=e}lookup(t){const e=(G(t)?this.types:this.binds)[t];return e===void 0?pe:e}};function Ni(t){let e="",n=t;for(;n!==null;)e+=n[0],n=n[1];return e==="main"?"":e}var ge=class Ae{constructor(e){Object.assign(this,e)}_with(e){return new Ae({...this,...e})}_pushProvides(){const e=this.comps.getCompFor(this.it);if(e==null)return this;const{provide:n,provideType:r}=e,s={},i={};let a=!1;const o=this._publishBase();for(const l in n){const c=n[l].toPathItem?.()??null;if(c===null)continue;const u=n[l].eval(this);s[l]={value:u,path:o===null?null:o.concat([c])},a=!0}for(const l in r)i[l]=r[l],a=!0;return a?this._with({dynBinds:[new Ln(s,i),this.dynBinds]}):this}_publishBase(){const e=this.renderPath.toTransactionPath().compact();return e.lookup(this.root,we)===this.it?e:null}static root(e,n,r=null){return new Ae({comps:e,root:n,it:n,binds:[new Rn(n,{},!0),null],dynBinds:[new Ln({},{}),null],views:["main",null],viewsId:"",renderPath:new St,pendingFrame:!1,ctx:r})._pushProvides()}enter(e,n={},r=!0,s=this.renderPath,i=null){const a=this._with({it:e,binds:[new Rn(e,n,r),this.binds],renderPath:s,pendingFrame:i??(r?!1:this.pendingFrame)});return r?a._pushProvides():a}pushViewName(e){const n=[e,this.views];return this._with({views:n,viewsId:Ni(n)})}_pushDynBindValuesToArray(e,n){for(const r in n.provide)e.push(this.lookupDynamic(r));for(const r in n.lookup)e.push(this.lookupDynamic(r))}lookupDynamicLocated(e){if(G(e))return null;const n=ve(this.dynBinds,e);if(n!=null)return n;const r=this.comps.getCompFor(this.it);if(r==null)return null;const s=r.scope?.lookupPath?.(e)??null;if(s!==null){const l=s.lookup(this.root,we);if(l!==we)return{value:l,path:s}}const i=r.lookup[e]??null;if(i===null)return null;const a=i.toPathItem?.()??null,o=i.eval(this);return a===null?{value:o,path:null}:{value:o,path:this.renderPath.toTransactionPath().concat([a])}}lookupDynamic(e){return G(e)?ve(this.dynBinds,e):this.lookupDynamicLocated(e)?.value??null}lookupBind(e){return ve(this.binds,e)}lookupFieldRaw(e){return this.it[e]??null}lookupMethod(e){const n=this.it[e];return n instanceof Function?n.call(this.it):null}lookupEvent(){return this.ctx?.e??null}lookupDragInfo(){return this.ctx?.dragInfo??null}getHandlerFor(e,n){return this.comps.getHandlerFor(this.it,e,n)}lookupBestView(e,n){let r=this.views;for(;r!==null;){const s=e[r[0]];if(s!==void 0)return s;r=r[1]}return e[n]}},we=Symbol("NOT_FOUND"),Ot=Symbol.for("tutuca.component"),Bn=class{constructor(){this.byId=new Map}registerComponent(t){this.byId.set(t.id,t)}getComponentForId(t){return this.byId.get(t)??null}getCompFor(t){const e=t?.constructor;return e?.[Ot]?e:null}getHandlerFor(t,e,n){return this.getCompFor(t)?.[n][e]??null}getIntentChainFor(t,e){return this.getCompFor(t)?.scope.lookupIntentChain(e)??[]}compileStyles(){const t=[];for(const e of this.byId.values())t.push(e.compileStyle());return t.join(`
`)}},ki=class dr{constructor(e=new Bn,n=null){this.comps=e,this.parent=n,this.byName={},this.intentsByName={},this.macros={},this.paths={}}enter(){return new dr(this.comps,this)}registerComponents(e,n){const{aliases:r={},paths:s}=n??{};s&&this.registerPaths(s);for(let i=0;i<e.length;i++){const a=e[i];a.scope=this.enter(),this.comps.registerComponent(a),this.byName[a.name]=a}for(const i in r){const a=this.byName[r[i]];console.assert(this.byName[i]===void 0,"alias overrides component",i),a!==void 0?this.byName[i]=a:console.warn("alias",i,"to inexistent component",r[i])}}registerPaths(e){for(const n in e){if(G(n)){console.warn("registerPaths: a type name has no path",n);continue}this.paths[n]=e[n].toPath()}}lookupPath(e){return this.paths[e]??this.parent?.lookupPath(e)??null}registerMacros(e){for(const n in e){const r=n.toLowerCase();console.assert(this.macros[r]===void 0,"macro key collision",r),this.macros[r]=e[n]}}getCompFor(e){return this.comps.getCompFor(e)}registerIntentHandlers(e){for(const n in e){const r=e[n];this.intentsByName[n]=Array.isArray(r)?r:[r]}}lookupIntentChain(e){const n=this.intentsByName[e]??[],r=this.parent?.lookupIntentChain(e)??[];return r.length===0?n:n.concat(r)}lookupComponent(e){return this.byName[e]??this.parent?.lookupComponent(e)??null}hasProvider(e){for(const n in this.byName)if(this.byName[n].provide?.[e]!==void 0)return!0;return this.parent?.hasProvider(e)??!1}lookupMacro(e){return this.macros[e]??this.parent?.lookupMacro(e)??null}},Ct=t=>typeof t=="string",Ei="name view style commonStyle globalStyle receive intent alter views provide lookup fields methods statics",Ti=new Set(Ei.split(" ")),Oi=0;function Ci(t,e){t[Ot]=t,t.id=Oi++,t.views={main:new Dn("main",e.view,e.style)},t.commonStyle=e.commonStyle??"",t.globalStyle=e.globalStyle??"",t.receive=e.receive??{},t.intent=e.intent??{},t.alter=e.alter??{};for(const n in e.views??{}){const r=e.views[n],{view:s,style:i}=Ct(r)?{view:r}:r;t.views[n]=new Dn(n,s,i)}t._rawProvide=e.provide??{},t._rawLookup=e.lookup??[],t.provide={},t.provideType={},t.lookup={},t.scope=null,t.spec=e,t.extra={};for(const n of Object.keys(e))Ti.has(n)||(t.extra[n]=e[n]);return Object.assign(t,$n)}var $n={compile(t){for(const n in this.views)this.views[n].compile(new t,this.scope,this.id);const e=this.views.main.ctx;for(const n in this._rawProvide){if(G(n)){this._rawProvide[n]==="self"&&(this.provideType[n]=this);continue}const r=os(this._rawProvide[n],e);r&&(this.provide[n]=r)}for(const n of this._rawLookup){const r=Ct(n)?n:Ct(n?.name)?n.name:null;if(r===null)continue;const s=Ct(n?.default)?n.default:null;this.lookup[r]=s===null?null:as(s,e)}for(const n in this.lookup)this.provide[n]!==void 0&&console.warn("name declared in both provide and lookup",this.name,n)},getView(t){return this.views[t]??this.views.main},getEventForId(t,e){return this.getView(e).ctx.getEventForId(t)},getNodeForId(t,e){return this.getView(e).ctx.getNodeForId(t)},compileStyle(){const{id:t,commonStyle:e,globalStyle:n,views:r}=this,s=e?[`[data-cid="${t}"]{${e}}`]:[];n!==""&&s.push(n);for(const i in r){const{style:a}=r[i];a!==""&&s.push(`[data-cid="${t}"][data-vid="${i}"]{${a}}`)}return s.join(`
`)}},Kn=Symbol("BadValue"),ye=t=>null,xi=t=>t instanceof Map?new Map(t):Array.isArray(t)||I(t)?new Map(Array.isArray(t)?t:Object.entries(t)):null,Hn={any:[t=>!0,ye,()=>null],text:[t=>typeof t=="string",t=>t?.toString?.()??"",()=>""],int:[Number.isInteger,t=>Number.isFinite(t)?Math.trunc(t):null,()=>0],float:[Number.isFinite,ye,()=>0],bool:[t=>typeof t=="boolean",t=>!!t,()=>!1],list:[Array.isArray,t=>Array.isArray(t)?[...t]:null,()=>[]],object:[I,t=>I(t)?{...t}:null,()=>({})],map:[t=>t instanceof Map,xi,()=>new Map],set:[t=>t instanceof Set,t=>t instanceof Set||Array.isArray(t)?new Set(t):null,()=>new Set]},b=class{constructor(t,e,n,[r,s,i]=Hn[t]){this.type=t,this.name=e,this.typeCheck=r,this.coercer=s,this.defaultValue=n===void 0?i():n}isValid(t){return this.typeCheck(t)}coerceOr(t,e=null){if(this.isValid(t))return t;const n=this.coercer(t);return this.isValid(n)?n:e}coerceOrDefault(t){return this.coerceOr(t,this.defaultValue)}},Wn=t=>t?.constructor?.getMetaClass?.(),Di=t=>Wn(t)?.name??null,_e=class extends b{constructor(t,e,n){super(t,e,null,[r=>Di(r)===t,ye,()=>null]),this.args=n}};function zn(t,e,n){const r=e?.lookupComponent(t.type)??null;return r===null&&console.warn(e?`component field "${t.name}": component "${t.type}" not found in scope`:`component field "${t.name}": cannot resolve component "${t.type}" \u2014 built without a registered scope (use ${t.type}.make({}) as the default, or build via a registered component)`),r?.make({...t.args,...n},{scope:e})??null}function Vi(t,e){const n=typeof e;if(n==="string")return new b("text",t,e);if(n==="number")return new b("float",t,e);if(n==="boolean")return new b("bool",t,e);if(Array.isArray(e))return new b("list",t,[...e]);if(e instanceof Set)return new b("set",t,new Set(e));if(e instanceof Map)return new b("map",t,new Map(e));if(e?.type&&Object.hasOwn(e,"defaultValue")){const r=e.type in Hn?e.type:"any",s=new b(r,t);return new b(r,t,s.coerceOr(e.defaultValue,s.defaultValue))}return e?.component&&e?.args!==void 0?new _e(e.component,t,e.args):I(e)?new b("object",t,{...e}):new b("any",t,e)}function Fi(t,{fields:e={},methods:n={},statics:r={}}){const s={};for(const o in e)s[o]=Vi(o,e[o]);const i=Object.fromEntries(Object.entries(s).map(([o,l])=>[o,l.defaultValue])),a={[t]:class{constructor(o={}){Object.assign(this,i,o)}}}[t];return a[Ft]=!0,Object.assign(a.prototype,n),Object.assign(a,{fields:s,methods:n,getMetaClass:()=>a,make(o={},l={}){const c={},u=l.scope??this.scope;for(const h in o){const f=s[h];f===void 0?console.warn("extra argument to constructor:",t,h,o):f instanceof _e?c[h]=zn(f,u,o[h]):c[h]=f.coerceOrDefault(o[h])}for(const h in s)s[h]instanceof _e&&c[h]===void 0&&(c[h]=zn(s[h],u,void 0));return vt(new this(c),!0)}},r),a}function Mi(t,e){const n=Wn(t);if(n)for(const[r,s]of Object.entries(n.fields)){const i=e[r];if(s.isValid(i))continue;const a=s.coerceOr(i,Kn);a!==Kn?e[r]=a:(console.warn(`invalid value for ${n.name}.${r}`,i),e[r]=t[r])}}var Ri=new Set([..."name id fields methods views receive intent alter provide provideType lookup spec extra commonStyle globalStyle scope _rawProvide _rawLookup make getMetaClass".split(" "),...Object.keys($n)]);function Li(t={}){for(const e in t)if(Ri.has(e))throw new TypeError(`component static "${e}" is reserved by the framework`)}function Bi(t){return Li(t.statics),Ci(Fi(t.name??"UnkComp",t),t)}var $i=class{constructor(t){this.val=t,this.changeSubs=[]}onChange(t){this.changeSubs.push(t)}set(t,e){const n=this.val;this.val=t;for(const r of this.changeSubs)r({val:t,old:n,info:e,timestamp:Date.now()})}},Ki=class{constructor(t,e){this.comps=t,this.transactions=[],this.state=new $i(e),this.onTransactionPushed=()=>{},this._observers=[],this.refusals=[],this._refusalObservers=[],this._inflight=new Set}pushTransaction(t){this.transactions.push(t),this.onTransactionPushed(t)}observe(t){return jn(this._observers,t)}refuse(t,e={}){const n={kind:t,info:e,timestamp:Date.now()};this.refusals.push(n),this.refusals.length>ji&&this.refusals.shift(),console.warn(`tutuca refusal [${t}]`,e);for(const r of this._refusalObservers)r(n);return n}observeRefusals(t){return jn(this._refusalObservers,t)}_emitRecord(t,{kind:e,name:n,args:r,path:s,targetPath:i,handler:a,handlerName:o,matched:l,before:c,after:u,parent:h}){if(this._observers.length===0)return;const f=s.pinKeys(t),d={kind:e,name:n,args:r??null,path:f,pathKeys:f.toKeys(),targetPath:i,handler:a??null,handlerName:o??(a?.name||null),matched:l??null,before:c,after:u,parent:h,timestamp:Date.now()};for(const p of this._observers)p(d)}_emitTransaction(t,e){this._observers.length!==0&&this._emitRecord(e,{kind:t.observeKind,name:t.observeName,args:t.args,path:t.getTransactionPath(),targetPath:t.targetPath??t.path,handler:t._resolvedHandler,matched:t._matched,before:t._before,after:t._after,parent:t.parentTransaction})}pushSend(t,e,n=[],r=null,s=null,i=null){const a=new Yn(t,this,e,n,r);return a.txnPath=i,a.origin=s,a.originPinned=s===null?null:s.toTransactionPath().pinKeys(this.state.val),this.pushTransaction(a),r&&a.completion.carry(r.completion.track()),a}pushIntent(t,e,n=[],r={},s=null){const i=s?s.completion.track():null,a=new Gi(this,t,e,n,r,s,i);return a.advance(),a}async settle(t=1e4){for(;(this.hasPendingTransactions||this._inflight.size)&&t-- >0;){for(;this.hasPendingTransactions;)this.transactNext();this._inflight.size&&await Promise.allSettled([...this._inflight])}}get hasPendingTransactions(){return this.transactions.length>0}transactNext(){this.transact(this.transactions.shift())}transact(t){try{const e=this.state.val,n=t.run(e,this.comps);n!==void 0?(this.state.set(n,{transaction:t}),t.afterTransaction(),this._emitTransaction(t,e)):console.warn("undefined new state",{curState:e,transaction:t})}finally{t.ensureWalkAdvanced?.(),t._completion?.finish()}}transactInputNow(t,e,n,r){this.transact(new Wi(t,e,n,this,r))}};function Hi(){return this}function jn(t,e){return t.push(e),()=>{const n=t.indexOf(e);n!==-1&&t.splice(n,1)}}function Un(t,e){return console.warn(`unknown ${t} route leg`,e,'- expected "dyn" or "lex"'),null}var Gn=class{constructor(t,e,n=null){this.path=t,this.txnPath=null,this.transactor=e,this.parentTransaction=n,this._completion=null}get completion(){return this._completion??=new Xi,this._completion}whenSettled(){return this.completion.whenSettled()}whenSubtreeSettled(){return this.completion.whenSubtreeSettled()}callHandler(t,e,n,r){const[s,i]=this.getHandlerAndArgs(t,e,r);return this._resolvedHandler=s,s.apply(e,[n,...i])}forward(t){this._forward=t??{}}afterTransaction(){const t=this._forward;if(t===void 0)return;this._forward=void 0;const e=this._forwardName();if(e===void 0){this.transactor.refuse("FORWARD_NO_NAME",{});return}const{args:n=this._forwardArgs(),...r}=t;this.transactor.pushIntent(this._forwardPath(),e,n,r,this)}getTransactionPath(){return this.txnPath??this.path.toTransactionPath()}run(t,e){const n=this.getTransactionPath(),r=n.lookup(t),s=$e(r,i=>{const a=this.callHandler(t,r,i,e);return(a===void 0||a===i)&&Mi(r,i),a});return this._before=r,this._after=s,this._completion?.markSelfSettled({value:s,old:r}),r!==s?n.setValue(t,s):t}},Wi=class extends Gn{constructor(t,e,n,r,s){super(t,r),this.e=e,this.handler=n,this.dragInfo=s,this._dispatchPath=null}get dispatchPath(){return this._dispatchPath??=this.path.compact(),this._dispatchPath}getTransactionPath(){return this.dispatchPath.toTransactionPath()}get observeKind(){return"receive"}get observeName(){return this.e?.type??null}_forwardName(){return(this.handler?.handlerCall?.handlerVal??this.handler?.handlerVal)?.name}_forwardArgs(){return this._handlerArgs??[]}_forwardPath(){return this.dispatchPath}getHandlerAndArgs(t,e,n){const r=this.path.buildStack(ge.root(n,t,this)),[s,i]=this.handler.getHandlerAndArgs(r,this);this._handlerArgs=[...i];const a=this.dispatchPath;return i.push(new qn(a,this.transactor,this)),[s,i]}},Xn=class extends Gn{constructor(t,e,n,r,s){super(t,e,s),this.name=n,this.args=r,this.targetPath=t}handlerProp=null;get observeKind(){return this.handlerProp}get observeName(){return this.name}_forwardName(){return this.name}_forwardArgs(){return this.args}_forwardPath(){return this.path}getHandlerForName(t){const e=t?.[this.handlerProp],n=e?.[this.name];if(n)return this._matched="exact",n;const r=e?.$unknown;return r?(this._matched="unknown",r):(this._matched="none",Hi)}getHandlerAndArgs(t,e,n){return[this.getHandlerForName(n.getCompFor(e)),[...this.args,new qn(this.path,this.transactor,this)]]}},Yn=class extends Xn{handlerProp="receive";get observeKind(){return this._isAnswer?"answer":"receive"}},zi=class extends Xn{handlerProp="intent";constructor(t,e,n){super(t,e,n.name,n.args,n.parent),this.walk=n,this.targetPath=n.origin}forward(t){this.walk.amend(t,this.path)}afterTransaction(){this.ensureWalkAdvanced()}ensureWalkAdvanced(){this._advanced||(this._advanced=!0,this.walk.advance())}},Jn=Symbol.for("tutuca.intent.pass"),ji=200,Ui=64,Gi=class{constructor(t,e,n,r,s,i,a){this.transactor=t,this.name=n,this.args=r,this.route=s?.route??me,this.parent=i,this.release=a,this.origin=e,this.answerPath=s?.livePath?null:e.toTransactionPath().pinKeys(t.state.val),this.legIndex=0,this.dynAt=e,this.hops=0,this.ended=!1}advance(){if(!this.ended){if(this.hops++>=Ui)return this.exhaust("intentDepth");for(;this.legIndex<this.route.length;){const t=this.route[this.legIndex];if(t==="dyn"){if(!this.dynAt.canPop()){this.legIndex++;continue}this.dynAt=this.dynAt.popStep(),this.transactor.pushTransaction(new zi(this.dynAt,this.transactor,this));return}if(t==="lex")return this.legIndex++,this._tryLex();Un("intent",t),this.legIndex++}this.exhaust("noHandler")}}_tryLex(){const t=this.transactor.state.val,e=this.origin.toTransactionPath(),n=e.lookup(t),r=this.transactor.comps.getIntentChainFor(n,this.name);if(this.transactor._emitRecord(t,{kind:"intent",name:this.name,args:this.args,path:e,targetPath:this.origin,handler:r[0],handlerName:r[0]?.name||this.name,matched:r.length>0?"exact":"none",before:n,after:void 0,parent:this.parent}),r.length===0)return this.advance();const s=this._runLex(r,0);this.transactor._inflight.add(s),s.finally(()=>this.transactor._inflight.delete(s))}async _runLex(t,e){if(this.ended)return;if(e>=t.length)return this.advance();const n=new Se(this.origin,this.transactor,this.parent);try{const r=await t[e].apply(null,[...this.args,n]);if(r===Jn)return this._runLex(t,e+1);this.answer("Ok",r)}catch(r){this.answer("Error",r)}}answer(t,e){this.finish(`${this.name}${t}`,[e])}amend(t,e){t?.args!==void 0&&(this.args=t.args),t?.route!==void 0&&(this.route=t.route,this.legIndex=0,this.dynAt=e??this.dynAt)}exhaust(t){if(this.ended)return;const{name:e,args:n}=this,r=this.transactor.comps.getCompFor(this.origin.toTransactionPath().lookup(this.transactor.state.val)),s=i=>r?.receive?.[i]!==void 0;s(`${e}Unhandled`)?this.finish(`${e}Unhandled`,n):s(`${e}Error`)?this.finish(`${e}Error`,[t]):(s(`${e}Ok`)&&console.warn(`intent "${e}" was not answered (${t}) and this component declares only "${e}Ok" - add "${e}Unhandled" or "${e}Error" to handle it`),this.finish(null,null))}finish(t,e){if(this.ended)return;if(this.ended=!0,t===null)return this.release?.();const n=new Yn(this.origin,this.transactor,t,e,this.parent);n.txnPath=this.answerPath,n._isAnswer=!0,this.transactor.pushTransaction(n),this.release&&n.completion.carry(this.release)}},Xi=class{constructor(){this.val=void 0,this.selfSettled=!1,this.subtreeSettled=!1,this.pending=0,this._selfResolve=null,this._selfPromise=null,this._subtreeResolve=null,this._subtreePromise=null,this._releaseSelf=this.track()}whenSettled(){return this.selfSettled?Promise.resolve(this.val):(this._selfPromise??=new Promise(t=>{this._selfResolve=t}),this._selfPromise)}whenSubtreeSettled(){return this.subtreeSettled?Promise.resolve(this.val):(this._subtreePromise??=new Promise(t=>{this._subtreeResolve=t}),this._subtreePromise)}markSelfSettled(t){this.selfSettled||(this.selfSettled=!0,this.val=t,this._selfResolve?.(t))}finish(){this.markSelfSettled(this.val),this._releaseSelf()}track(){this.pending++;let t=!1;return()=>{t||(t=!0,--this.pending===0&&(this.subtreeSettled=!0,this._subtreeResolve?.(this.val)))}}carry(t){this.whenSubtreeSettled().then(t)}},Se=class{constructor(t,e,n){this.path=t,this.transactor=e,this.parent=n,this.root=e.state.val}walkPath(t){const e=this.transactor.comps,n=this.path.toTransactionPath().resolveChain(this.root);for(let r=n.length-1;r>=0;r--){const s=e.getCompFor(n[r]);if(s&&t(s,n[r])===!1)return}}get at(){return new Yi(this)}_stack(){return this._stackMemo??=this.path.buildStack(ge.root(this.transactor.comps,this.root,this.parent)),this._stackMemo}lookup(t,e){for(const n of e?.route??me){const r=n==="dyn"?this._stack()?.lookupDynamic(t)??null:n==="lex"?this._lookupLex(t):Un("lookup",n);if(r!=null)return r}return null}_lookupLex(t){let e=null;this.walkPath(r=>(e=r,!1));const n=e?.scope;return n==null?null:G(t)?n.lookupComponent(t)??null:n.lookupPath(t)?.lookup(this.root)??null}lookupType(t,e){const n=e?.route??me,r=this.lookup(t,{route:n});return r==null?(this.transactor.refuse("TYPE_NOT_FOUND",{name:t,route:n}),null):r?.[Ot]==null?(this.transactor.refuse("TYPE_NOT_COMPONENT",{name:t,got:typeof r}),null):r}send(t,e){return this.sendAtPath(this.path,t,e)}sendAtPath(t,e,n){return this.transactor.pushSend(t,e,n,this.parent,this.path)}intent(t,e,n){return this.intentAtPath(this.path,t,e,n)}intentAtPath(t,e,n,r){return this.transactor.pushIntent(t,e,n,r,this.parent)}},qn=class extends Se{get name(){return this.parent?.name??null}get targetPath(){return this.parent.targetPath}reply(t){return this.parent.walk===void 0?be("reply"):this.parent.walk.answer("Ok",t)}fail(t){return this.parent.walk===void 0?be("fail"):this.parent.walk.answer("Error",t)}sendReply(t,e){const n=this.parent?.origin??null;return n==null?(this.transactor.refuse("NO_SENDER",{name:t}),null):this.transactor.pushSend(n,t,e,this.parent,this.path,this.parent.originPinned)}stop(){return this.parent.walk===void 0?be("stop"):this.parent.walk.finish(null,null)}forward(t){return this.parent.forward(t)}};function be(t){console.warn(`ctx.${t}() is only meaningful in an "intent" handler - ignored`)}var Yi=class extends Ge{constructor(t){super(),this.dispatcher=t}send(t,e){return this.dispatcher.sendAtPath(this.buildPath(),t,e)}intent(t,e,n){return this.dispatcher.intentAtPath(this.buildPath(),t,e,n)}buildPath(){return this.dispatcher.path.concat(this.pathChanges)}};function Ji(t){return new Se(new St,t,null)}var qi="dragstart dragover dragend touchstart touchmove touchend touchcancel".split(" "),Zi=class{constructor(t,e,n,r){this.rootNode=t,this.comps=e,this.compStack=new ki(e),this.transactor=new Ki(e,null),this.ParseContext=r,this.renderer=n,this._transactNextBatchId=this._evictCacheId=null,this._eventNames=new Set(qi),this.dragInfo=this.curDragOver=null,this._touch=null,this.transactor.onTransactionPushed=s=>{this._transactNextBatchId===null&&this._scheduleNextTransactionBatchExecution()},this._compiled=!1,this._renderOpts={document:t.ownerDocument},this._renderState=null,this.rootViewName=null}get state(){return this.transactor.state}handleEvent(t){const{type:e}=t;if(e[0]==="t"&&e.startsWith("touch")){this._handleTouchEvent(t);return}this._dispatchEvent(t)}_dispatchEvent(t){const{type:e}=t,n=e==="dragover"||e==="dragstart"||e==="dragend"||e==="drop",{rootNode:r,comps:s,transactor:i}=this,[a,o]=St.fromNodeAndEventName(t.target,e,r,s,!n);if(n&&this._handleDragEvent(t,e,a),a!==null&&o!==null)for(const l of o)i.transactInputNow(a,t,l,this.dragInfo)}_handleTouchEvent(t){const{type:e}=t;if(e==="touchstart"){if(this._touch!==null||t.touches.length!==1)return;const l=t.touches[0],c=l.target?.closest?.('[draggable="true"]');if(!c)return;this._touch=ea(l.identifier,l.clientX,l.clientY,c,!1);return}if(this._touch===null)return;const n=ta(t,this._touch.id);if(n===null)return;const{rootNode:r,_touch:s}=this,{clientX:i,clientY:a}=n,o=(l,c)=>{const u={type:l,target:c,clientX:i,clientY:a,preventDefault:Qi};this._dispatchEvent(u)};if(e==="touchmove"){if(s.active)t.preventDefault(),o("dragover",tr(r,i,a));else{const l=i-s.startX,c=a-s.startY;if(l*l+c*c<100)return;s.active=!0,t.preventDefault(),o("dragstart",s.target)}return}(e==="touchend"||e==="touchcancel")&&(s.active&&(e==="touchend"&&o("drop",tr(r,i,a)),o("dragend",s.target)),this._touch=null)}_handleDragEvent(t,e,n){if(e==="dragover"){const r=na(t.target,this.rootNode,1/0);r!==null&&(t.preventDefault(),this._cleanDragOverAttrs(),this.curDragOver=r,r.dataset.draggingover=this.dragInfo?.type??"_external")}else if(e==="dragstart"){t.target.dataset.dragging=1;const r=this.state.val,i=n.compact().toTransactionPath().lookup(r),a=t.target.dataset.dragtype??"?",o=n.buildStack(this.makeStack(r));this.dragInfo=new ra(o,i,a,t.target)}else e==="drop"?(t.preventDefault(),this._cleanDragOverAttrs()):(this.dragInfo!==null&&(delete this.dragInfo.node.dataset.dragging,this.dragInfo=null),this._cleanDragOverAttrs())}makeStack(t){return ge.root(this.comps,t)}_cleanDragOverAttrs(){this.curDragOver!==null&&(delete this.curDragOver.dataset.draggingover,this.curDragOver=null)}render(){const t=this.state.val,e=this.makeStack(t),{renderer:n,rootNode:r,_renderOpts:s,_renderState:i}=this,a=Us(n.renderRoot(e,t,this.rootViewName),r,s,i);return this._renderState=a,a.dom}onChange(t){this.transactor.state.onChange(t)}observe(t){return this.transactor.observe(t)}compile(){for(const t of this.comps.byId.values()){t.compile(this.ParseContext);for(const e in t.views)for(const n of t.views[e].ctx.genEventNames())this._eventNames.add(n)}this._compiled=!0}subscribeToEvents(t){for(const e of t)this.rootNode.addEventListener(e,this,Qn(e))}recompileStyles(t){Zn("tutuca-app",this.comps.compileStyles(),t?.head??document.head)}start(t){this._compiled||this.compile(),this.subscribeToEvents(this._eventNames),this.onChange(e=>{e.val!==e.old&&this.render()}),this.recompileStyles(t),t?.noCache?this.renderer.setNullCache():this.startCacheEvictionInterval(),this.render()}stop(){this.stopCacheEvictionInterval(),clearTimeout(this._transactNextBatchId),this._transactNextBatchId=null;for(const t of this._eventNames)this.rootNode.removeEventListener(t,this,Qn(t))}sendAtRoot(t,e){this.transactor.pushSend(new St,t,e)}registerComponents(t,e){const n=this.compStack.enter();return n.registerComponents(t,e),n}_transactNextBatch(t=10){this._transactNextBatchId=null;const e=Date.now(),n=this.transactor;for(;n.hasPendingTransactions&&Date.now()-e<t;)n.transactNext();n.hasPendingTransactions&&this._scheduleNextTransactionBatchExecution()}_scheduleNextTransactionBatchExecution(){this._transactNextBatchId=setTimeout(()=>this._transactNextBatch(),0)}startCacheEvictionInterval(t=3e4){this._evictCacheId=setInterval(()=>this.renderer.cache.evict(),t)}stopCacheEvictionInterval(){clearInterval(this._evictCacheId),this._evictCacheId=null}};function Zn(t,e,n=document.head){const r=document.createElement("style"),s=n.querySelector(`#${t}`);s&&n.removeChild(s),r.id=t,r.innerHTML=e,n.appendChild(r)}var Qi=()=>{};function ta(t,e){for(const n of t.changedTouches)if(n.identifier===e)return n;for(const n of t.touches)if(n.identifier===e)return n;return null}var Qn=t=>t==="touchmove"?{passive:!1}:void 0;function ea(t,e,n,r,s){return{id:t,startX:e,startY:n,target:r,active:s}}function tr(t,e,n){let s=t.getRootNode().elementFromPoint?.(e,n)??null;for(;s?.shadowRoot;){const i=s.shadowRoot.elementFromPoint(e,n);if(i===null||i===s)break;s=i}return s??t}function na(t,e,n){let r=t;for(;n-- >0&&r!==e;){if(r.dataset?.droptarget!==void 0)return r;r=r.parentNode}return null}var ra=class{constructor(t,e,n,r){this.stack=t,this.val=e,this.type=n,this.node=r}lookupBind(t){return this.stack.lookupBind(t)}},er=t=>t!==null&&(typeof t=="object"||typeof t=="function"),sa=class{get(t,e){}set(t,e,n){}evict(){}},ia=class{constructor(){this.keysByLen=new Map}get(t,e){const n=t.length;let r=this.keysByLen.get(n);if(r){for(let s=0;s<n-1;s++)if(r=r.get(t[s]),!r)return;return r.get(t[n-1])?.[e]}}set(t,e,n){const r=t.length;let s=this.keysByLen.get(r);s||(s=new WeakMap,this.keysByLen.set(r,s));for(let o=0;o<r-1;o++){const l=t[o];let c=s.get(l);if(!c){if(!er(l))return;c=new WeakMap,s.set(l,c)}s=c}const i=t[r-1],a=s.get(i);a?a[e]=n:er(i)&&s.set(i,{[e]:n})}evict(){this.keysByLen=new Map}};function nr(t,e){return t instanceof kt?new kt(t.tag,{...t.attrs,"data-rp":e},t.childs,t.key,t.namespace):t instanceof E?new E(t.childs.map(n=>nr(n,e))):t}var aa=class{constructor(t){this.comps=t,this.cache=new ia}renderTag(t,e,n,r){return Gs(t,e,n,r)}renderFragment(t){return new E(t)}renderComment(t){return new ae(t)}setNullCache(){this.cache=new sa}renderRoot(t,e,n=null){const r=this.comps.getCompFor(e);return r===null?null:this._rValComp(t,e,r,r.getView(n).anode,"ROOT",n)}renderIt(t,e,n,r=null){const s=this.comps.getCompFor(t.it);return s?this._rValComp(t,t.it,s,e,"",n,r):null}_rValComp(t,e,n,r,s,i,a=null){const o=`${i??""}${t.viewsId??""}${s}${t.renderPath.addressKey}`,l=[r,e];t._pushDynBindValuesToArray(l,n);const c=this.cache.get(l,o);if(c)return c;const u=i?n.getView(i):t.lookupBestView(n.views,"main"),h=this.renderView(u,t);if(h==null)return null;const f=a===null?null:We(a),d=this._renderMetadata({$:"Comp",nid:r?.nodeId??null,cid:n.id,vid:u.name,...f===null?null:{base:f}}),p=new E([d,f===null?h:nr(h,JSON.stringify(f))]);return this.cache.set(l,o,p),p}pushEachEntry(t,e,n,r,s){t.push(this._renderMetadata({$:"Each",nid:e,[n]:r}),s)}renderEachWhen(t,e){const{val:n,node:r,nodeId:s}=e,{seq:i,filter:a,loopWith:o,enricher:l}=e.evalIter(t),c=n instanceof ot?t.lookupDynamicLocated(n.name)?.path??null:null,u=[],h=t.it,f=(d,p,S,B)=>{const P=c===null?null:Mr(c,d),O=P===null?e.itemStep(d):null,X=P!==null?t.renderPath.pushFrame(P):O!==null?t.renderPath.pushItem(O):t.renderPath,g=l?[r,h,p]:[r,p],Ie=`${t.viewsId??""}${s}${d}${X.addressKey}`,Ne=this.cache.get(g,Ie);if(Ne)this.pushEachEntry(u,s,S,d,Ne);else{const Vt=this.renderView(r,t.enter(p,B,!1,X,P!==null));Vt!=null&&this.pushEachEntry(u,s,S,d,Vt),this.cache.set(g,Ie,Vt)}};return Ls({seq:i,it:h,filter:a,loopWith:o,enricher:l,ctx:fn(t,a)},f),u}renderView(t,e){let n=e.binds[1];for(;n!==null;){const r=n[0];if(r.isFrame){if(e.it!==r.it)break;return console.error("recursion detected",e.it,r.it),new ae("RECURSION AVOIDED")}n=n[1]}return t.render(e,this)}_renderMetadata(t){return new ae(`\xA7${JSON.stringify(t)}\xA7`)}renderScopeMeta(t,e){return new E([this._renderMetadata({$:"Scope",nid:t}),e])}},oa=["send","intent"];function rr(t){const e=[];for(const n of oa)for(const r of t[n]??[])e.push({type:n,...r});for(const n of t.do??[])e.push(n);return e}function sr(t,e){return typeof t=="function"?t(e)??[]:t??[]}function la(t,e,n,r){if(n)for(const s of rr(n)){const i=sr(s.args,r);switch(s.type){case"send":t.sendAtPath(e,s.name,i);break;case"intent":t.intentAtPath(e,s.name,i,s.opts);break}}}var ca=String.raw,ua=String.raw,ha=(t,e)=>new ei(t,e),Pe=(t,e)=>(console.warn(`${t} is a no-op in the core tutuca build; import tutuca/dev for the real one`),e);function fa(t){return Pe("check",{error:0,warn:0,hint:0})}async function da(t){return Pe("test",null)}function pa(){return Pe("collectIterBindings",[])}function ma(t){const e=typeof t=="string"?document.querySelector(t):t,n=new Bn,r=new aa(n);return new Zi(e,n,r,Tn)}export{Ot as COMPONENT,Jn as PASS,Tn as ParseContext,cn as SEQ_INFO,fa as check,pa as collectIterBindings,Bi as component,ca as css,la as dispatchPhase,ua as html,Zn as injectCss,ha as macro,zr as path,rr as phaseOps,sr as resolveArgs,Ji as rootDispatcher,da as test,ma as tutuca};
//# sourceMappingURL=/sm/10d689aa37e6cff9121cc7d47e335ea7d94354e5b5d3d5c79dcf1c546e5cf4d5.map