@wcstack/state 3.5.2 → 3.5.3

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.
@@ -1,2 +1,2 @@
1
- import{W as t,w as e,F as n,G as s,g as a,q as o,D as l,d as r,H as i,J as d,t as c,K as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aP as h,l as p,aQ as g,aR as I,aS as y,j as w,m as x,aT as m,N as P,P as b,O as v,aU as A,aV as $,av as k,aW as R,h as E,k as S,aX as j,aY as M,aZ as C,a_ as O,a$ as D,b0 as L,b1 as q,b2 as V,ai as T,b3 as B,b4 as H,a1 as W,b5 as z,b6 as G,b7 as N,b8 as U,b9 as K,ba as F,bb as J,bc as Q,p as X,bd as Y,be as Z,bf as _,bg as tt,bh as et,c as nt,bi as st,bj as at,a2 as ot,bk as lt,o as rt}from"./binder.js";import{c as it,a as dt}from"./checkDependency.js";import{N as ct}from"./getAllPropertyDescriptors.js";import{c as ft}from"./filterRegistry.js";const ut=new WeakMap;function ht(t,e){let n=ut.get(t);void 0===n&&(n=new Map,ut.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const pt=new WeakMap;function gt(t){const e=pt.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return ht(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:ht(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return pt.set(t,n),n}function It(t){pt.delete(t)}function yt(t){"readonly"===t.mutability&&u("This state is readonly.")}function wt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function xt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==ct)return r}}return ct}function mt(a,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(gt(i),o.pathInfo.segments);if(!(o.pathInfo.path in a)){if(null===o.parentAddress){const t=xt(i,o,null,l,r);if(t!==ct)return t;u(n(o.pathInfo.path,a,i.getterPaths))}const e=At(a,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==t&&!(d in Object(e))){const t=xt(i,o,Object(e),l,r);if(t!==ct)return t}if(d===t){const t=o.listIndex?.index??u(s(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(a,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(a,o.pathInfo.path,l)}finally{r.popAddress()}}function Pt(e,n,s,o,l){const r=p(l,n),i=g(r),d=l.stateGeneration,c=n.pathInfo.lastSegment===t?void 0:I(n.listIndex);if(null!==i&&!1===i.dirty&&i.generation===d&&i.rowStamp===c)return i.value;const f=mt(e,n,s,o,l);"function"!=typeof f&&y(r,{value:f,dirty:!1,generation:d,rowStamp:c});const u=i?.value;return Array.isArray(f)&&f!==u&&l.getterPaths.has(n.pathInfo.path)&&function(t,e,n,s,o,l){const{path:r,wildcardCount:i}=e.pathInfo;l.beginUntrack();try{for(const[d,c]of l.stateElement.dynamicDependency){const f=a(d);if(!c.includes(r)||f.wildcardCount>i)continue;const u=At(t,w(f,x(e.listIndex,f.wildcardCount-1,i)),o,l);u===n?bt.add(e.pathInfo):u===s&&m(n,s)}}finally{l.endUntrack()}}(e,n,f,u,s,o),f}const bt=new WeakSet;function vt(t){return bt.has(t)}function At(t,e,n,s){it(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==ct)return l}}return wt(a,e)?Pt(t,e,n,s,a):mt(t,e,n,s,a)}function $t(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const g=w(h,o),I=p(n.stateElement,g),y=b(I),x=At(t,g,e,n),m=v(o,y,x).newIndexes,P=i[d]??null;if(l.set(I,x),null===P)for(let t=0;t<m.length;t++){const e=m[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=m[P]??u(`ListIndex not found at index ${P} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())P(t,Array.isArray(e)?e:[]);return i}function kt(t,e,n){const s=A(n,e.listIndex);if(null!==s)return s;const a=p(t.stateElement,e),o=v(e.listIndex,b(a),n);return P(a,Array.isArray(n)?n:[]),o.newIndexes}function Rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=w(r,o),d=kt(n,i,At(t,i,e,n)),c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function Et(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function St(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function jt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];Et(i,n,s,r);const d=St(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function Mt(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function Ct(e,n,s,a){if(n.pathInfo.path in e)return!0;const o=n.parentAddress;if(null===o)return!1;const l=At(e,o,s,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=n.pathInfo.lastSegment;if(r===t){const t=n.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const Ot=new WeakMap;function Dt(t){return Ot.get(t)??null}function Lt(t,e){null===e?Ot.delete(t):($(e.listIndexes),Ot.set(t,e))}function qt(t,e,n){const s=t.wildcardParentPaths[e],o=a(s),l=w(o,n),r=p(t.stateElement,l),i=b(r),d=t.stateProxy[E](l),c=v(l.listIndex,i,d);t.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return ft.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...f);else for(const n of f)qt(t,e+1,n)}function Vt(t,e,n,s){n?t.result.has(e)||t.quiet.add(e):t.quiet.delete(e),t.result.add(e),s.push(e)}const Tt=[];function Bt(t,e,n){return"full"!==t.listExpansion&&t.listPathSet.has(e)?t.stateElement.crossRowListPaths?.has(e)?{fullRows:n.newIndexes,movedRows:null}:0===n.addIndexSet.size&&0===n.changeIndexSet.size?0===n.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Tt,movedRows:null}:{fullRows:n.newIndexes,movedRows:null}:{fullRows:Tt,movedRows:null}:{fullRows:n.addIndexSet,movedRows:n.changeIndexSet}:{fullRows:n.newIndexes,movedRows:null}}const Ht=[];function Wt(t,e,n){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Ht;let o=null;const r=e+l;for(const t of s){if(t!==e&&!t.startsWith(r))continue;const s=a(t);if(s.wildcardCount!==n.wildcardCount)return null;(o??=[]).push(s)}return o??Ht}function zt(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),t.quiet.has(r)?k(p(t.stateElement,r)):n(r),l.length=0,Gt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Gt(e,n,s){const o=n.pathInfo.path,l=e.quiet.has(n),r=e.staticMap.get(o);if(r)for(const i of r){const r=a(i);if(r.lastSegment===t){const t=e.stateProxy[E](n),a=Array.isArray(t)?t:[],d=p(e.stateElement,n),c=b(d),f=e.listPathSet.has(o);if(!f&&"diff"===e.listExpansion&&(e.keyedMergePath===o||S(a)?.length!==a.length&&!j(c,a)))continue;const u=v(n.listIndex,c,a);e.observedListValueByAbsAddress.set(d,a);const h=Bt(e,o,u);for(const t of h.fullRows)Vt(e,w(r,t),l||!f,s);for(const t of u.valueChangeIndexes??Tt)Vt(e,w(r,t),l||!f,s);if(null!==h.movedRows){const t=Wt(e,i,r);if(null===t)for(const t of h.movedRows)Vt(e,w(r,t),l,s);else if(t.length>0)for(const n of h.movedRows)for(const a of t)Vt(e,w(a,n),l,s)}}else Vt(e,w(r,n.listIndex),l,s)}const i=e.dynamicMap.get(o);if(i)for(const t of i){const o=a(t),r=[];if(o.wildcardCount>0){const t=M(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=x(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};qt(a,t,s),r.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=x(n.listIndex,t-1,n.pathInfo.wildcardCount);r.push(e)}}else r.push(null);for(const t of r)Vt(e,w(o,t),l,s)}}function Nt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null,quiet:new Set};zt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=R(t.stateElement);if(null===n)return;n.forEach(n=>{zt(t,w(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)P(t,e);return Array.from(f.result)}function Ut(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function Kt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Ft(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Jt(t,e,n,s,a,o){const l=D(t,e),r=L(t,e);if(!l&&!r)return null;const i=[],d=Xt(i);return l&&q(t,e,n,s,a).forEach(d),r&&V(t,e,n?s:o(),a).forEach(d),i}function Qt(){return ft.enablePropagationContext?K()??null:null}function Xt(t){const e=nt(),n=Qt();return s=>{k(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function Yt(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=nt(),r=Qt();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=w(i.pathInfo,t[n].listIndex);Nt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=p(s,t);k(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function Zt(t,e,n,s,a){const o=D(t,e),l=L(t,e);if(!o&&!l)return;const r=n(),i=[],d=Xt(i);o&&q(t,e,!1,void 0,r).forEach(d),l&&V(t,e,void 0,r,!1).forEach(d),Yt(i,s,a)}function _t(e,n,s,o,r,i,d="diff"){const c=ft.enablePropagationContext?K()??F(-1):null,f=nt(),u=o.stateElement;f.enqueueAbsoluteAddress(n,c),i&&k(n);const h=t=>Nt(u,t,u.staticDependency,u.dynamicDependency,u.listPaths,s,"new",t=>{if(t===e)return;const n=p(u,t);k(n),f.enqueueAbsoluteAddress(n,c)},{listExpansion:d,keyedMergePath:r});if(h(e),e.pathInfo.lastSegment!==t&&null!==e.listIndex&&null!==e.listIndex.parentListIndex){const n=e.listIndex,o=e.pathInfo.wildcardParentPathInfos[n.position],r=w(o,n.parentListIndex),i=()=>s[E](r),d=t=>{k(t),f.enqueueRenderOnlyAddress(t)};for(const t of J(n,i))d(p(u,w(e.pathInfo,t)));const c=e.pathInfo.path.slice(e.pathInfo.wildcardPaths[n.position].length);for(const e of Q(p(u,r),i())){const s=e.absolutePathInfo.pathInfo;s!==o&&s.wildcardCount===o.wildcardCount&&d(X(u,a(s.path+l+t+c),n))}}const{path:g,lastSegment:I,wildcardCount:y,wildcardParentPaths:m,wildcardParentPathInfos:P}=e.pathInfo,b=e.listIndex;for(let e=0;b&&e<y;e++){const n=x(b,e-1,y);for(const o of u.dynamicDependency.get(m[e])??[]){const l=a(o);if(u.listPaths.has(o)&&l.wildcardCount===e&&vt(l)&&s[E](w(l,n))===s[E](w(P[e],n))){const n=w(a(o+g.slice(m[e].length)),b);h(n),I===t&&f.enqueueRenderOnlyAddress(p(u,n.parentAddress))}}}}function te(e,n,s,a,o){o&&(e.getterPaths.has(n)?k(s):y(s,{value:a,dirty:!1,generation:e.stateGeneration,rowStamp:s.absolutePathInfo.pathInfo.lastSegment===t?void 0:I(s.listIndex)}))}function ee(e,n,a,o,l,r,i,d,c=!0){try{if(!(n.pathInfo.path in e)){const a=n.parentAddress;if(null===a)return Reflect.set(e,n.pathInfo.path,o);const i=At(e,a,l,r),d=n.pathInfo.segments[n.pathInfo.segments.length-1];if(d===t){const t=n.listIndex?.index??u(s(`path "${n.pathInfo.path}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(n.pathInfo.path))return Reflect.set(e,n.pathInfo.path,o);r.pushAddress(n),r.beginUntrack();try{return Reflect.set(e,n.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{c&&_t(n,a,l,r,i,d)}}function ne(e,n,s,o,r,i,d,c,f){const h=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),g=At(e,h,r,i)??[],I=Dt(g);if(f)return I&&(I.value[n.listIndex.index]=o),Y(n.listIndex,o),ee(e,n,s,o,r,i,d,c);const y=n.listIndex,x=I??{value:[...g],listIndexes:S(g)??[],written:new Map};try{return ee(e,n,s,o,r,i,d,c,!1)}finally{const e=function(t,e,n){const{value:s,listIndexes:a}=t,o=new Map;a.forEach((t,n)=>{if(e[n]!==s[n]){const e=o.get(s[n]);e?e.push(t):o.set(s[n],[t])}});let l,r=0;const i=[];for(let t=0;t<a.length;t++){const n=e[t]===s[t]?a[t]:o.get(e[t])?.shift();if(!n&&(r++?(l??=new Set(s)).has(e[t]):s.includes(e[t])))return null;i.push(n)}return i.map((t,e)=>t??T(n,e))}(x,g,h.listIndex);if(null===e)Lt(g,x),Y(y,o),x.written.set(y,Z),_(y),_t(n,s,r,i,d,c);else{Lt(g,null);const n=[y.index];tt(y),x.written.forEach((t,e)=>{tt(e),Y(e,x.value[e.index]),t===Z&&n.push(e.index)}),x.written.delete(y),e.forEach((t,e)=>{t.index=e}),W(g,e),N(x.listIndexes,e),function(e,n,s,o,r,i,d){const c=i.stateElement,f=nt(),u=p(c,e);W(n.value,n.listIndexes),st(n.value),z(s,n.value),at(u)===s&&ot(u,n.value);f.enqueueRenderOnlyAddress(u);for(const t of Q(u,s))lt(t,s)&&f.enqueueRenderOnlyAddress(t);const h=new Map;n.listIndexes.forEach((t,e)=>h.set(t,e));const g=a(e.pathInfo.path+l+t);for(let t=0;t<o.length;t++){const e=o[t],s=h.get(e);if(s===t)continue;const a=w(g,e),l=p(c,a);if(void 0===s){const e=X(c,g,n.listIndexes[t]);Ft(c,l,e),_t(a,l,r,i,null,wt(c,a),"full");continue}Nt(c,a,c.staticDependency,c.dynamicDependency,c.listPaths,r,"new",t=>{const e=p(c,t);k(e),f.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}for(const t of d){const e=o[t];if(h.has(e)&&n.written.get(e)!==Z){const s=w(g,e),a=p(c,s);Ft(c,a,X(c,g,n.listIndexes[t])),_t(s,a,r,i,null,wt(c,s))}}}(h,x,g,e,r,i,n)}}}function se(e,n,s,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(s)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=At(e,n,o,r),c=function(t,e,n,s){const a=jt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=jt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,s);if(null!==c)return function(e,n,s,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===S(o)&&v(c,null,o);const f=v(c,o,s.list),u=ae(e,n,s.list,r,i,d),h=a(d+l+t);for(const t of s.matched){const n=Mt(t.oldRow,t.newRow);if(0===n.length)continue;const s=f.newIndexes[t.position];for(const o of n){if(void 0===s){t.oldRow[o.field]=o.value;continue}const n=a(h.path+l+o.field);se(e,w(n,s),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return ae(e,n,s,o,r,null)}function ae(e,n,a,o,l,i){const d=l.stateElement,c=n.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let e=0;e<t.length;e++){const s=t[e](d,n,a,o,l);if(s!==ct)return s}}const h=et(),g=h>1;if(!(c in e)&&null!==n.parentAddress&&!d.elementPaths.has(c)){const h=At(e,n.parentAddress,o,l);if("object"==typeof h&&null!==h){const e=n.pathInfo.lastSegment,I=e===t?n.listIndex?.index:e;let y,x=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=void 0!==I&&I in h,e=void 0!==I?h[I]:void 0;if(t&&Object.is(e,a))return!0;y=e,x=!0}e===t&&(n=function(t,e,n,s,a){const o=e.listIndex,l=S(n);if(l?.[s]!==o||n[s]===a)return e;const r=T(o.parentListIndex,s,B(o));if(H(n)){const t=Dt(n)??{value:n.slice(),listIndexes:l};W(t.value,t.listIndexes),z(n,t.value)}const i=G(l)?l:l.slice();i[s]=r,W(n,i,!0),N(l,i),U([o]);const d=w(e.pathInfo,r);return Ft(t,p(t,d),p(t,e)),d}(d,n,h,I,a));const P=Jt(d,c,x,y,a,()=>h[I]),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:y,hasOldValue:x}),Ut(d,c,v,y,x);let A=!1;try{if(void 0===I&&u(s(`path "${c}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0)),f&&0!==f.writeMissing.length&&e!==t&&!(I in h)){const t=f.writeMissing;for(let e=0;e<t.length;e++){A=!0;const s=t[e](d,n,h,I,a,o,l);if(s!==ct)return s;A=!1}}if(e!==t&&null!==n.listIndex){const t=h[I];t!==a&&(C(t,n.listIndex,h,e)&&Array.isArray(a)&&m(a,t),O(a,n.listIndex))}return Reflect.set(h,I,a)}finally{_t(n,v,o,l,i,b),Yt(P,o,l),A?k(v):te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}}let I,y=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=At(e,n,o,l);if(Ct(e,n,o,l)&&Object.is(t,a))return!0;I=t,y=!0}const x=Jt(d,c,y,I,a,()=>At(e,n,o,l)),P=d.elementPaths.has(n.pathInfo.path),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:I,hasOldValue:y}),Ut(d,c,v,I,y);try{return P?ne(e,n,v,a,o,l,i,b,h):ee(e,n,v,a,o,l,i,b)}finally{Yt(x,o,l),P||te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}function oe(t,e,n,s){return(e,o,...l)=>{Array.isArray(o)||u(`$resolve("${e}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${e}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);const r=a(e);if(s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",e,r.wildcardParentPathInfos.length,o.length));const d=Rt(t,n,s,r,o),c=w(r,d);if(0===l.length)return At(t,c,n,s);yt(s),se(t,c,l[0],n,s)}}function le(t,e,n,s){const o=oe(t,0,n,s);return(e,l)=>{const r=a(e);if(void 0===l||Array.isArray(l)||u(`$getAll("${e}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",e,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=dt(s,r.wildcardPaths[t]);if(e){l=rt(e,e.length);break}}if(void 0===l){const t=s.addressStackLength>0?s.lastAddressStack:null,n=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==n&&n.length>0&&u(d(e,t.pathInfo.path)),l=[]}}const c=$t(t,n,s,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function re(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":{const t=a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`);return dt(s,t)??u(`ListIndex not found: ${e.pathInfo.path}`)}case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=w(l,a),i=kt(s,r,At(t,r,n,s)),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function ie(e,n,s,o){return(n,l,r,d)=>{yt(o);const h=a(n);Array.isArray(l)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),l.length>h.wildcardParentPathInfos.length&&u(i("$setAll",n,h.wildcardParentPathInfos.length,l.length));const p=!0===d?.spread,g="function"==typeof r;p&&g&&u(c(n,"cannot combine { spread: true } with a mapper function.")),p&&!Array.isArray(r)&&u(c(n,"requires an array as the value when { spread: true } is set."));const I=$t(e,s,o,h,l,{commitDiffBaseline:!1});p&&r.length!==I.length&&u(f(n,I.length,r.length));const y=[];for(let t=0;t<I.length;t++){const n=Rt(e,s,o,h,I[t]);y.push(w(h,n))}const x=h.lastSegment===t;let m=0;for(let t=0;t<y.length;t++){const n=x?w(h,Rt(e,s,o,h,I[t])):y[t];let a;if(g){a=r(At(e,n,s,o),...I[t])}else a=p?r[t]:r;void 0!==a&&(se(e,n,a,s,o),m++)}return m}}export{yt as a,le as b,ie as c,re as d,gt as e,It as f,At as g,Ct as h,Zt as n,oe as r,se as s,Nt as w};
1
+ import{W as t,w as e,F as n,G as s,g as a,q as o,D as l,d as r,H as i,J as d,t as c,K as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aP as h,l as p,aQ as g,aR as I,aS as y,j as w,m as x,aT as m,N as P,P as b,O as v,aU as A,aV as $,av as k,aW as R,h as E,k as S,aX as j,aY as M,aZ as C,a_ as O,a$ as D,b0 as L,b1 as q,b2 as V,aj as T,b3 as B,b4 as H,a2 as W,b5 as z,b6 as G,b7 as N,b8 as U,b9 as K,ba as F,bb as J,bc as Q,p as X,bd as Y,be as Z,bf as _,bg as tt,bh as et,c as nt,bi as st,bj as at,a3 as ot,bk as lt,o as rt}from"./binder.js";import{c as it,a as dt}from"./checkDependency.js";import{N as ct}from"./getAllPropertyDescriptors.js";import{c as ft}from"./filterRegistry.js";const ut=new WeakMap;function ht(t,e){let n=ut.get(t);void 0===n&&(n=new Map,ut.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const pt=new WeakMap;function gt(t){const e=pt.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return ht(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:ht(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return pt.set(t,n),n}function It(t){pt.delete(t)}function yt(t){"readonly"===t.mutability&&u("This state is readonly.")}function wt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function xt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==ct)return r}}return ct}function mt(a,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(gt(i),o.pathInfo.segments);if(!(o.pathInfo.path in a)){if(null===o.parentAddress){const t=xt(i,o,null,l,r);if(t!==ct)return t;u(n(o.pathInfo.path,a,i.getterPaths))}const e=At(a,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==t&&!(d in Object(e))){const t=xt(i,o,Object(e),l,r);if(t!==ct)return t}if(d===t){const t=o.listIndex?.index??u(s(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(a,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(a,o.pathInfo.path,l)}finally{r.popAddress()}}function Pt(e,n,s,o,l){const r=p(l,n),i=g(r),d=l.stateGeneration,c=n.pathInfo.lastSegment===t?void 0:I(n.listIndex);if(null!==i&&!1===i.dirty&&i.generation===d&&i.rowStamp===c)return i.value;const f=mt(e,n,s,o,l);"function"!=typeof f&&y(r,{value:f,dirty:!1,generation:d,rowStamp:c});const u=i?.value;return Array.isArray(f)&&f!==u&&l.getterPaths.has(n.pathInfo.path)&&function(t,e,n,s,o,l){const{path:r,wildcardCount:i}=e.pathInfo;l.beginUntrack();try{for(const[d,c]of l.stateElement.dynamicDependency){const f=a(d);if(!c.includes(r)||f.wildcardCount>i)continue;const u=At(t,w(f,x(e.listIndex,f.wildcardCount-1,i)),o,l);u===n?bt.add(e.pathInfo):u===s&&m(n,s)}}finally{l.endUntrack()}}(e,n,f,u,s,o),f}const bt=new WeakSet;function vt(t){return bt.has(t)}function At(t,e,n,s){it(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==ct)return l}}return wt(a,e)?Pt(t,e,n,s,a):mt(t,e,n,s,a)}function $t(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const g=w(h,o),I=p(n.stateElement,g),y=b(I),x=At(t,g,e,n),m=v(o,y,x).newIndexes,P=i[d]??null;if(l.set(I,x),null===P)for(let t=0;t<m.length;t++){const e=m[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=m[P]??u(`ListIndex not found at index ${P} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())P(t,Array.isArray(e)?e:[]);return i}function kt(t,e,n){const s=A(n,e.listIndex);if(null!==s)return s;const a=p(t.stateElement,e),o=v(e.listIndex,b(a),n);return P(a,Array.isArray(n)?n:[]),o.newIndexes}function Rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=w(r,o),d=kt(n,i,At(t,i,e,n)),c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function Et(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function St(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function jt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];Et(i,n,s,r);const d=St(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function Mt(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function Ct(e,n,s,a){if(n.pathInfo.path in e)return!0;const o=n.parentAddress;if(null===o)return!1;const l=At(e,o,s,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=n.pathInfo.lastSegment;if(r===t){const t=n.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const Ot=new WeakMap;function Dt(t){return Ot.get(t)??null}function Lt(t,e){null===e?Ot.delete(t):($(e.listIndexes),Ot.set(t,e))}function qt(t,e,n){const s=t.wildcardParentPaths[e],o=a(s),l=w(o,n),r=p(t.stateElement,l),i=b(r),d=t.stateProxy[E](l),c=v(l.listIndex,i,d);t.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return ft.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...f);else for(const n of f)qt(t,e+1,n)}function Vt(t,e,n,s){n?t.result.has(e)||t.quiet.add(e):t.quiet.delete(e),t.result.add(e),s.push(e)}const Tt=[];function Bt(t,e,n){return"full"!==t.listExpansion&&t.listPathSet.has(e)?t.stateElement.crossRowListPaths?.has(e)?{fullRows:n.newIndexes,movedRows:null}:0===n.addIndexSet.size&&0===n.changeIndexSet.size?0===n.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Tt,movedRows:null}:{fullRows:n.newIndexes,movedRows:null}:{fullRows:Tt,movedRows:null}:{fullRows:n.addIndexSet,movedRows:n.changeIndexSet}:{fullRows:n.newIndexes,movedRows:null}}const Ht=[];function Wt(t,e,n){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Ht;let o=null;const r=e+l;for(const t of s){if(t!==e&&!t.startsWith(r))continue;const s=a(t);if(s.wildcardCount!==n.wildcardCount)return null;(o??=[]).push(s)}return o??Ht}function zt(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),t.quiet.has(r)?k(p(t.stateElement,r)):n(r),l.length=0,Gt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Gt(e,n,s){const o=n.pathInfo.path,l=e.quiet.has(n),r=e.staticMap.get(o);if(r)for(const i of r){const r=a(i);if(r.lastSegment===t){const t=e.stateProxy[E](n),a=Array.isArray(t)?t:[],d=p(e.stateElement,n),c=b(d),f=e.listPathSet.has(o);if(!f&&"diff"===e.listExpansion&&(e.keyedMergePath===o||S(a)?.length!==a.length&&!j(c,a)))continue;const u=v(n.listIndex,c,a);e.observedListValueByAbsAddress.set(d,a);const h=Bt(e,o,u);for(const t of h.fullRows)Vt(e,w(r,t),l||!f,s);for(const t of u.valueChangeIndexes??Tt)Vt(e,w(r,t),l||!f,s);if(null!==h.movedRows){const t=Wt(e,i,r);if(null===t)for(const t of h.movedRows)Vt(e,w(r,t),l,s);else if(t.length>0)for(const n of h.movedRows)for(const a of t)Vt(e,w(a,n),l,s)}}else Vt(e,w(r,n.listIndex),l,s)}const i=e.dynamicMap.get(o);if(i)for(const t of i){const o=a(t),r=[];if(o.wildcardCount>0){const t=M(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=x(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};qt(a,t,s),r.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=x(n.listIndex,t-1,n.pathInfo.wildcardCount);r.push(e)}}else r.push(null);for(const t of r)Vt(e,w(o,t),l,s)}}function Nt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null,quiet:new Set};zt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=R(t.stateElement);if(null===n)return;n.forEach(n=>{zt(t,w(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)P(t,e);return Array.from(f.result)}function Ut(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function Kt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Ft(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Jt(t,e,n,s,a,o){const l=D(t,e),r=L(t,e);if(!l&&!r)return null;const i=[],d=Xt(i);return l&&q(t,e,n,s,a).forEach(d),r&&V(t,e,n?s:o(),a).forEach(d),i}function Qt(){return ft.enablePropagationContext?K()??null:null}function Xt(t){const e=nt(),n=Qt();return s=>{k(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function Yt(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=nt(),r=Qt();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=w(i.pathInfo,t[n].listIndex);Nt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=p(s,t);k(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function Zt(t,e,n,s,a){const o=D(t,e),l=L(t,e);if(!o&&!l)return;const r=n(),i=[],d=Xt(i);o&&q(t,e,!1,void 0,r).forEach(d),l&&V(t,e,void 0,r,!1).forEach(d),Yt(i,s,a)}function _t(e,n,s,o,r,i,d="diff"){const c=ft.enablePropagationContext?K()??F(-1):null,f=nt(),u=o.stateElement;f.enqueueAbsoluteAddress(n,c),i&&k(n);const h=t=>Nt(u,t,u.staticDependency,u.dynamicDependency,u.listPaths,s,"new",t=>{if(t===e)return;const n=p(u,t);k(n),f.enqueueAbsoluteAddress(n,c)},{listExpansion:d,keyedMergePath:r});if(h(e),e.pathInfo.lastSegment!==t&&null!==e.listIndex&&null!==e.listIndex.parentListIndex){const n=e.listIndex,o=e.pathInfo.wildcardParentPathInfos[n.position],r=w(o,n.parentListIndex),i=()=>s[E](r),d=t=>{k(t),f.enqueueRenderOnlyAddress(t)};for(const t of J(n,i))d(p(u,w(e.pathInfo,t)));const c=e.pathInfo.path.slice(e.pathInfo.wildcardPaths[n.position].length);for(const e of Q(p(u,r),i())){const s=e.absolutePathInfo.pathInfo;s!==o&&s.wildcardCount===o.wildcardCount&&d(X(u,a(s.path+l+t+c),n))}}const{path:g,lastSegment:I,wildcardCount:y,wildcardParentPaths:m,wildcardParentPathInfos:P}=e.pathInfo,b=e.listIndex;for(let e=0;b&&e<y;e++){const n=x(b,e-1,y);for(const o of u.dynamicDependency.get(m[e])??[]){const l=a(o);if(u.listPaths.has(o)&&l.wildcardCount===e&&vt(l)&&s[E](w(l,n))===s[E](w(P[e],n))){const n=w(a(o+g.slice(m[e].length)),b);h(n),I===t&&f.enqueueRenderOnlyAddress(p(u,n.parentAddress))}}}}function te(e,n,s,a,o){o&&(e.getterPaths.has(n)?k(s):y(s,{value:a,dirty:!1,generation:e.stateGeneration,rowStamp:s.absolutePathInfo.pathInfo.lastSegment===t?void 0:I(s.listIndex)}))}function ee(e,n,a,o,l,r,i,d,c=!0){try{if(!(n.pathInfo.path in e)){const a=n.parentAddress;if(null===a)return Reflect.set(e,n.pathInfo.path,o);const i=At(e,a,l,r),d=n.pathInfo.segments[n.pathInfo.segments.length-1];if(d===t){const t=n.listIndex?.index??u(s(`path "${n.pathInfo.path}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(n.pathInfo.path))return Reflect.set(e,n.pathInfo.path,o);r.pushAddress(n),r.beginUntrack();try{return Reflect.set(e,n.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{c&&_t(n,a,l,r,i,d)}}function ne(e,n,s,o,r,i,d,c,f){const h=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),g=At(e,h,r,i)??[],I=Dt(g);if(f)return I&&(I.value[n.listIndex.index]=o),Y(n.listIndex,o),ee(e,n,s,o,r,i,d,c);const y=n.listIndex,x=I??{value:[...g],listIndexes:S(g)??[],written:new Map};try{return ee(e,n,s,o,r,i,d,c,!1)}finally{const e=function(t,e,n){const{value:s,listIndexes:a}=t,o=new Map;a.forEach((t,n)=>{if(e[n]!==s[n]){const e=o.get(s[n]);e?e.push(t):o.set(s[n],[t])}});let l,r=0;const i=[];for(let t=0;t<a.length;t++){const n=e[t]===s[t]?a[t]:o.get(e[t])?.shift();if(!n&&(r++?(l??=new Set(s)).has(e[t]):s.includes(e[t])))return null;i.push(n)}return i.map((t,e)=>t??T(n,e))}(x,g,h.listIndex);if(null===e)Lt(g,x),Y(y,o),x.written.set(y,Z),_(y),_t(n,s,r,i,d,c);else{Lt(g,null);const n=[y.index];tt(y),x.written.forEach((t,e)=>{tt(e),Y(e,x.value[e.index]),t===Z&&n.push(e.index)}),x.written.delete(y),e.forEach((t,e)=>{t.index=e}),W(g,e),N(x.listIndexes,e),function(e,n,s,o,r,i,d){const c=i.stateElement,f=nt(),u=p(c,e);W(n.value,n.listIndexes),st(n.value),z(s,n.value),at(u)===s&&ot(u,n.value);f.enqueueRenderOnlyAddress(u);for(const t of Q(u,s))lt(t,s)&&f.enqueueRenderOnlyAddress(t);const h=new Map;n.listIndexes.forEach((t,e)=>h.set(t,e));const g=a(e.pathInfo.path+l+t);for(let t=0;t<o.length;t++){const e=o[t],s=h.get(e);if(s===t)continue;const a=w(g,e),l=p(c,a);if(void 0===s){const e=X(c,g,n.listIndexes[t]);Ft(c,l,e),_t(a,l,r,i,null,wt(c,a),"full");continue}Nt(c,a,c.staticDependency,c.dynamicDependency,c.listPaths,r,"new",t=>{const e=p(c,t);k(e),f.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}for(const t of d){const e=o[t];if(h.has(e)&&n.written.get(e)!==Z){const s=w(g,e),a=p(c,s);Ft(c,a,X(c,g,n.listIndexes[t])),_t(s,a,r,i,null,wt(c,s))}}}(h,x,g,e,r,i,n)}}}function se(e,n,s,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(s)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=At(e,n,o,r),c=function(t,e,n,s){const a=jt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=jt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,s);if(null!==c)return function(e,n,s,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===S(o)&&v(c,null,o);const f=v(c,o,s.list),u=ae(e,n,s.list,r,i,d),h=a(d+l+t);for(const t of s.matched){const n=Mt(t.oldRow,t.newRow);if(0===n.length)continue;const s=f.newIndexes[t.position];for(const o of n){if(void 0===s){t.oldRow[o.field]=o.value;continue}const n=a(h.path+l+o.field);se(e,w(n,s),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return ae(e,n,s,o,r,null)}function ae(e,n,a,o,l,i){const d=l.stateElement,c=n.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let e=0;e<t.length;e++){const s=t[e](d,n,a,o,l);if(s!==ct)return s}}const h=et(),g=h>1;if(!(c in e)&&null!==n.parentAddress&&!d.elementPaths.has(c)){const h=At(e,n.parentAddress,o,l);if("object"==typeof h&&null!==h){const e=n.pathInfo.lastSegment,I=e===t?n.listIndex?.index:e;let y,x=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=void 0!==I&&I in h,e=void 0!==I?h[I]:void 0;if(t&&Object.is(e,a))return!0;y=e,x=!0}e===t&&(n=function(t,e,n,s,a){const o=e.listIndex,l=S(n);if(l?.[s]!==o||n[s]===a)return e;const r=T(o.parentListIndex,s,B(o));if(H(n)){const t=Dt(n)??{value:n.slice(),listIndexes:l};W(t.value,t.listIndexes),z(n,t.value)}const i=G(l)?l:l.slice();i[s]=r,W(n,i,!0),N(l,i),U([o]);const d=w(e.pathInfo,r);return Ft(t,p(t,d),p(t,e)),d}(d,n,h,I,a));const P=Jt(d,c,x,y,a,()=>h[I]),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:y,hasOldValue:x}),Ut(d,c,v,y,x);let A=!1;try{if(void 0===I&&u(s(`path "${c}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0)),f&&0!==f.writeMissing.length&&e!==t&&!(I in h)){const t=f.writeMissing;for(let e=0;e<t.length;e++){A=!0;const s=t[e](d,n,h,I,a,o,l);if(s!==ct)return s;A=!1}}if(e!==t&&null!==n.listIndex){const t=h[I];t!==a&&(C(t,n.listIndex,h,e)&&Array.isArray(a)&&m(a,t),O(a,n.listIndex))}return Reflect.set(h,I,a)}finally{_t(n,v,o,l,i,b),Yt(P,o,l),A?k(v):te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}}let I,y=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=At(e,n,o,l);if(Ct(e,n,o,l)&&Object.is(t,a))return!0;I=t,y=!0}const x=Jt(d,c,y,I,a,()=>At(e,n,o,l)),P=d.elementPaths.has(n.pathInfo.path),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:I,hasOldValue:y}),Ut(d,c,v,I,y);try{return P?ne(e,n,v,a,o,l,i,b,h):ee(e,n,v,a,o,l,i,b)}finally{Yt(x,o,l),P||te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}function oe(t,e,n,s){return(e,o,...l)=>{Array.isArray(o)||u(`$resolve("${e}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${e}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);const r=a(e);if(s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",e,r.wildcardParentPathInfos.length,o.length));const d=Rt(t,n,s,r,o),c=w(r,d);if(0===l.length)return At(t,c,n,s);yt(s),se(t,c,l[0],n,s)}}function le(t,e,n,s){const o=oe(t,0,n,s);return(e,l)=>{const r=a(e);if(void 0===l||Array.isArray(l)||u(`$getAll("${e}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",e,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=dt(s,r.wildcardPaths[t]);if(e){l=rt(e,e.length);break}}if(void 0===l){const t=s.addressStackLength>0?s.lastAddressStack:null,n=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==n&&n.length>0&&u(d(e,t.pathInfo.path)),l=[]}}const c=$t(t,n,s,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function re(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":{const t=a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`);return dt(s,t)??u(`ListIndex not found: ${e.pathInfo.path}`)}case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=w(l,a),i=kt(s,r,At(t,r,n,s)),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function ie(e,n,s,o){return(n,l,r,d)=>{yt(o);const h=a(n);Array.isArray(l)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),l.length>h.wildcardParentPathInfos.length&&u(i("$setAll",n,h.wildcardParentPathInfos.length,l.length));const p=!0===d?.spread,g="function"==typeof r;p&&g&&u(c(n,"cannot combine { spread: true } with a mapper function.")),p&&!Array.isArray(r)&&u(c(n,"requires an array as the value when { spread: true } is set."));const I=$t(e,s,o,h,l,{commitDiffBaseline:!1});p&&r.length!==I.length&&u(f(n,I.length,r.length));const y=[];for(let t=0;t<I.length;t++){const n=Rt(e,s,o,h,I[t]);y.push(w(h,n))}const x=h.lastSegment===t;let m=0;for(let t=0;t<y.length;t++){const n=x?w(h,Rt(e,s,o,h,I[t])):y[t];let a;if(g){a=r(At(e,n,s,o),...I[t])}else a=p?r[t]:r;void 0!==a&&(se(e,n,a,s,o),m++)}return m}}export{yt as a,le as b,ie as c,re as d,gt as e,It as f,At as g,Ct as h,Zt as n,oe as r,se as s,Nt as w};
2
2
  //# sourceMappingURL=setAll.js.map
@@ -1,2 +1,2 @@
1
- const o="3.5.2";export{o as V};
1
+ const o="3.5.3";export{o as V};
2
2
  //# sourceMappingURL=version.js.map
@@ -1,2 +1,2 @@
1
- import{c as t,a as e,S as n}from"../chunks/filterRegistry.js";import{Q as s,R as o,S as r,U as a,V as i,W as c,X as l,Y as d,Z as u,y as f,_ as p,$ as m,G as h,a0 as g,a1 as y,a2 as b,a3 as N,N as S,x as w,a4 as x,a5 as A,L as v,a6 as T,a7 as k,a8 as C,D,a9 as O,aa as _,ab as j,ac as $,ad as P,ae as E,af as M,ag as B,ah as q,ai as R,aj as F,ak as I,al as H,j as z,am as W,v as J,an as V,ao as L,ap as G,aq as Q,ar as U,as as X,at as Y,au as Z,g as K}from"../chunks/binder.js";import{H as tt,a as et}from"../chunks/registerComponents.js";import{V as nt}from"../chunks/version.js";import{W as st,g as ot}from"../chunks/pathDiagnostics.js";import"../chunks/errorGuidance.js";import"../chunks/lifecycleHooks.js";import"../chunks/declarationAliases.js";import"../chunks/setAll.js";import"../chunks/checkDependency.js";import"../chunks/getAllPropertyDescriptors.js";import"../chunks/declarationHooks.js";import"../chunks/diagnosticsHooks.js";const rt=/^@@wcs-(?:for|if|elseif|else):[^-]/,at=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,it=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,ct=/^@@wcs-text-start:(.+)$/;function lt(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function dt(t,e){const n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),s=[];for(;n.nextNode();){const t=n.currentNode;e(t.data)&&s.push(t)}return s}const ut=t=>rt.test(t),ft=t=>at.test(t),pt=t=>at.test(t)||it.test(t);function mt(t){if("else"===t.bindingType)return"else:";let e=`${t.bindingType}: ${t.statePathName}`;for(const n of t.outFilters){const t=n.literals??n.args;e+=`|${n.filterName}`,n.args.length>0&&(e+=`(${n.args.map((e,n)=>"string"==typeof t[n]?`'${e.split("'").join("'\"'\"'")}'`:e).join(",")})`)}return e}function ht(t){const e=t.fragment.cloneNode(!0);for(const n of t.nodeInfos){const s=i(c(t.fragment,n.nodePath));if(null===s)continue;const o=c(e,n.nodePath);o.parentNode.replaceChild(document.createComment(s),o)}return e}class gt extends tt{_stateData=null;_templates=null;_hydrateProps=null;get version(){return this.getAttribute("version")||""}get stateData(){return null===this._stateData&&(this._stateData=this._loadStateData()),this._stateData}get templates(){return null===this._templates&&(this._templates=this._loadTemplates()),this._templates}get hydrateProps(){return null===this._hydrateProps&&(this._hydrateProps=this._loadHydrateProps()),this._hydrateProps}getTemplate(t){return this.templates.get(t)??null}verifyVersion(){const t=this.version;if(!t)return!0;const e=t.split("."),n=nt.split(".");return e[0]===n[0]&&e[1]===n[1]}setStateData(t){this._stateData=t}setHydrateProps(t){this._hydrateProps=t}_loadStateData(){const t=this.querySelector('script[type="application/json"]:not([data-wcs-ssr-props])');if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}_loadTemplates(){const t=new Map,e=this.querySelectorAll("template[id]");for(const n of e){const e=n.getAttribute("id");e&&t.set(e,n)}return t}_loadHydrateProps(){const t=this.querySelector("script[data-wcs-ssr-props]");if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}static find(e){const n=t.tagNames.ssr,s=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!s)return null;return s.querySelector(n)}static extractStateData(t){const e=t.__state;if(!e||"object"!=typeof e)return{};const n={};for(const t of Object.keys(e)){if(t.startsWith("$"))continue;const s=Object.getOwnPropertyDescriptor(e,t);if(void 0!==s&&"function"==typeof s.get)continue;const o=e[t];"function"!=typeof o&&(n[t]=o)}return n}static buildContent(n,i,c){const l=c??n.ownerDocument;e.seen&&function(t){const e=new Map;for(const n of dt(t,ft)){if(null===n.parentNode)continue;const[,t,s]=at.exec(n.data),o=s.split(":")[0],r=n.previousSibling?.data,a=`@@wcs-${t}-end:${s}`;if(r!==`@@wcs-${t}:${o}`&&e.get(r)!==o)for(let t=n;null!==t;){const e=t.nextSibling;t.remove(),t=t.data===a?null:e}else"for"===t&&e.set(a,o)}}(l);const d=document.createElement("script");d.setAttribute("type","application/json"),d.textContent=lt(JSON.stringify(i)),n.appendChild(d);for(const[e,s]of function(t){const e=new Map,n=[t];for(;n.length>0;)for(const t of dt(n.shift(),ut)){const s=t.data,o=s.slice(s.indexOf(":")+1);if(e.has(o))continue;const r=a(o);null!==r&&(e.set(o,r),n.push(r.fragment))}return e}(l)){const o=document.createElement("template");o.setAttribute("id",e),o.setAttribute(t.bindAttributeName,mt(s.parseBindTextResult)),o.content.appendChild(ht(s)),n.appendChild(o)}const u=n.ownerDocument,f=s();if(f.length>0){const t={};for(let e=0;e<f.length;e++){const n=f[e];if(!n.isConnected||n.ownerDocument!==u)continue;const s=o(n);if(0===s.length)continue;const r=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",r);const a={};for(const t of s)a[t.propName]=t.value;t[r]=a}if(Object.keys(t).length>0){const e=document.createElement("script");e.setAttribute("type","application/json"),e.setAttribute("data-wcs-ssr-props",""),e.textContent=lt(JSON.stringify(t)),n.appendChild(e)}}r()}static removeBlockBoundaryComments(t){for(const e of dt(t,pt))e.remove()}static removeStructuralComments(t){for(const e of dt(t,ut))e.remove()}static restoreTextBindings(t){for(const e of dt(t,t=>ct.test(t))){const t=ct.exec(e.data)[1],n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let s=e.nextSibling;e.remove();const o=`@@wcs-text-end:${t}`;for(;s;){const t=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===o){s.parentNode.removeChild(s);break}s.parentNode.removeChild(s),s=t}}}static cleanupDom(e){const n=document.body,s=e.querySelectorAll(t.tagNames.ssr),o=new Map;for(const t of s){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&o.set(e,t)}}for(const t of dt(n,ft)){const e=at.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let s=t.nextSibling;for(;s;){const t=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===n){s.remove();break}s.remove(),s=t}t.remove()}gt.restoreTextBindings(n);const r=e=>{for(const n of dt(e,ut)){const e=o.get(n.data.split(":")[1]);if(e){const s=document.createElement("template"),o=e.getAttribute(t.bindAttributeName);o&&s.setAttribute(t.bindAttributeName,o);const a=document.importNode(e.content,!0);if(a.childNodes.length>0)s.content.appendChild(a);else for(const t of Array.from(e.childNodes))s.content.appendChild(document.importNode(t,!0));r(s.content),n.parentNode.replaceChild(s,n)}}};r(n);const a=e.querySelectorAll("[data-wcs-ssr-id]");for(const t of a)t.removeAttribute("data-wcs-ssr-id");for(const t of s)t.remove()}}const yt={protocol:"wcs-ssr-snapshot",version:1,build:function(e){const n=t.tagNames.state,s=t.tagNames.ssr,o=e.querySelectorAll(`${n}[enable-ssr]:not([mount]):not([bind-component])`);for(const t of o){const e=t.previousElementSibling;if(null!==e&&e.tagName.toLowerCase()===s)continue;const n=document.createElement(s);n.setAttribute("version",nt),gt.buildContent(n,gt.extractStateData(t),t.getRootNode()),t.parentNode?.insertBefore(n,t)}r()},reset:function(){l(),r(),e.seen=!1}};const bt=new Set(["for","if","elseif","else"]);function Nt(t){const[,e,n]=at.exec(t),[s,...o]=n.split(":");return"for"===e?{type:e,uuid:s,path:o[0],index:parseInt(o[1],10),nodes:[]}:{type:e,uuid:s,path:o.join(":"),index:null,nodes:[]}}function St(e){const n=[];for(const s of e)if(s.nodeType===Node.ELEMENT_NODE){const e=s;e.hasAttribute(t.bindAttributeName)&&n.push(e),Array.from(e.children).some(e=>e.localName===t.tagNames.state&&V(e))||n.push(...L(e))}else null!==G(s)&&n.push(s);return n}function wt(t){const[e,n,s]=Q(t),o=new U;return{bindingInfos:o.initialize(n,{registerAddress:!1,applyOnReconnect:!1}),subscriberNodes:e,bindingSession:o,deferredSpreads:s}}const xt=/^\s*@@\s*(?:wcs-text)?\s*:/;function At(t,e){for(const n of e)"event"===n.bindingType||bt.has(n.bindingType)||(n.node.nodeType!==Node.COMMENT_NODE||"text"===n.bindingType&&xt.test(n.node.data))&&t.push(n)}function vt(t,e){const n=[];for(let s=0;s<t.nodes.length;s++){const o=e.get(t.nodes[s]);o?s+=o.nodes.length+1:n.push(t.nodes[s])}return n}function Tt(t,e,n,s,o,r){e.length>0&&(t.spreads=e);for(const t of e)Y(t.node);p(e,n,s,o,r)}function kt(t,e){const n=a(e),s=h(t.getRootNode());let o=null;if(n&&s){const{statePathName:t,outFilters:e}=n.parseBindTextResult;s.createState("readonly",n=>{const s=g(n[t],X(e,"output"));Array.isArray(s)&&(o=s)})}return o}function Ct(e,n){return`@@${{for:t.commentForPrefix,if:t.commentIfPrefix,elseif:t.commentElseIfPrefix,else:t.commentElsePrefix}[e]}:${n}`}function Dt(t,e,n){const s=Ct(e,n);return dt(t,t=>t===s)[0]??null}function Ot(e,n){const s=e,o=n.templates,r=new Map;for(const[t,e]of o)for(const n of dt(e.content,ut))r.set(n.data.slice(n.data.indexOf(":")+1),t);const a=new Set(A(e));if(a.size>0)for(const t of dt(s,ut)){const e=t.data.slice(t.data.indexOf(":")+1);let n=t.parentNode;for(;null!==n&&!a.has(n);)n=n.parentNode;null===n||r.has(e)||r.set(e,n)}const i=new Map,c=[];for(const[e,n]of o){const s=n.getAttribute(t.bindAttributeName)||"";let o=v(s)[0];const a=o.bindingType,l=r.get(e),d=i.get(l);"else"===a&&d&&(o={...d,outFilters:[...d.outFilters,T()],bindingType:"else"}),"if"===a||"elseif"===a?i.set(l,o):"else"===a&&i.set(l,null),c.push([e,n,o])}for(const[t,e,n]of c.reverse()){const o=document.importNode(e.content,!0),r="for"===n.bindingType?n.statePathName:void 0;k(o),"string"==typeof r&&C(o,r),D(s,o,r);const a={fragment:o,parseBindTextResult:n,nodeInfos:O(o)};_(t,s,a)}}const _t={hydrate:async function(e){await d(e);const n=e.querySelectorAll(t.tagNames.ssr);for(const t of n){const n=t;if(!n.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${n.version}", client="${nt}". Falling back to full render.`),gt.cleanupDom(e),!1}const s=function(t){const e=[];for(const n of dt(t,pt)){if(!ft(n.data)){e.pop();continue}const t=Nt(n.data),s=e.at(-1);if("for"===t.type&&s&&s.uuid!==t.uuid)return[t,s];e.push(t)}return null}(document.body);if(null!==s){const[t,n]=s;return console.warn(`[@wcstack/state] SSR: "for: ${t.path}" in "${n.type}: ${n.path}" (known limitation). Falling back to full render.`),gt.cleanupDom(e),!1}for(const t of n)Ot(e,t);gt.restoreTextBindings(document.body);const o=function(t){const e=[];for(const n of dt(t,ft)){const t=Nt(n.data);t.start=n;const s=n.data.replace("-start:","-end:");let o=n.nextSibling;for(;o&&(o.nodeType!==Node.COMMENT_NODE||o.data!==s);)t.nodes.push(o),o=o.nextSibling;e.push(t)}return e}(document.body),r=new Map,a=function(t,e,n=new Map){const s=new Map,o=[],r=new Map(e.map(t=>[t.start,t])),a=new Set;for(let t=e.length-1;t>=0;t--){const n=St(e[t].nodes).filter(t=>!a.has(t));for(const t of n)a.add(t);e[t].subscribers=n}for(const a of e){const e=vt(a,r);if(0===e.length)continue;const i=e.some(t=>ut(t.data));if(i){const t=document.createComment(`wcs-row-end:${a.uuid}`);a.nodes[a.nodes.length-1].after(t),e.push(t)}const{bindingInfos:c,subscriberNodes:l,bindingSession:d,deferredSpreads:u}=wt(a.subscribers);for(const t of c)if(t.node!==t.replaceNode){const n=e.indexOf(t.node);n>=0&&(e[n]=t.replaceNode)}const f=j(e,i);$(f,d),P(f,c),E(f,l);const p=c.filter(t=>M(t,B));if(q(f,p),"for"===a.type&&null!==a.index){const e=Dt(t,"for",a.uuid);if(e){let t=n.get(a.uuid);if(!t){const o=kt(e,a.uuid)??a.path;t=s.get(o),t||s.set(o,t=[]),n.set(a.uuid,t)}const r=t[a.index]??=R(null,a.index);F(e,r,f),I(e,f.lastNode),H(e,f);const i=ot(a.path+"."+st),l=z(i,r);W(f,l),d.initialize(c,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),At(o,c),Tt(f,u,l,d,c,p)}}else{const e=a.start.previousSibling,n=e?.data===Ct(a.type,a.uuid)?e:Dt(t,a.type,a.uuid);if(n){H(n,f);const t=J(n);W(f,t),d.initialize(c,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),At(o,c),Tt(f,u,t,d,c,p)}}}return o}(document.body,o,r);gt.removeBlockBoundaryComments(document.body);const i=[];for(const t of n)t.parentNode&&(i.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());const[,c,l]=u(document.body),A=[],v=[],T=f(document.body),k=T.initialize(c);p(l,null,T);for(const t of k)if("event"!==t.bindingType)if(bt.has(t.bindingType))v.push(t);else{if(t.statePathName.includes(st))continue;A.push(t)}for(const t of v)if("for"===t.bindingType){const e=m(t),n=t.replaceNode.getRootNode(),s=h(n);s&&s.createState("readonly",n=>{const s=g(n[t.statePathName],t.outFilters);if(Array.isArray(s)){const n=r.get(t.uuid);n&&y(s,n),b(e,s),N(t.node,s),S(e,s)}})}w([...A,...a]);for(const{el:t,parent:e,next:n}of i)e.insertBefore(t,n);const C=new Map;for(const t of e.querySelectorAll("[data-wcs-ssr-id]"))C.set(t.getAttribute("data-wcs-ssr-id"),t);for(const n of e.querySelectorAll(t.tagNames.ssr))for(const[t,e]of Object.entries(n.hydrateProps)){const n=C.get(t);if(n)for(const[t,s]of Object.entries(e))x?.isDeclared(n,t)||(n[t]=s)}for(const t of e.querySelectorAll("[data-wcs-ssr-id]"))t.removeAttribute("data-wcs-ssr-id");return!0},loadState(t){const e=t.parentNode;if(!e)return null;const n=gt.find(e);if(!n)return null;const s=n.stateData;return Object.keys(s).length>0?s:null},async emitSnapshot(e){await K(e.rootNode);const n=gt.extractStateData(e),s=document.createElement(t.tagNames.ssr);s.setAttribute("version",nt),gt.buildContent(s,n,e.rootNode),e.parentNode?.insertBefore(s,e)}};let jt=!1;function $t(){jt||(jt=!0,Z(_t),et(e=>{e.get(t.tagNames.ssr)||e.define(t.tagNames.ssr,gt)}),function(){const t=globalThis;void 0===t[n]&&(t[n]=yt)}())}const Pt={name:"ssr",install(){$t()}};export{Pt as default,Pt as ssr};
1
+ import{c as t,a as e,S as n}from"../chunks/filterRegistry.js";import{Q as s,R as o,S as r,U as a,V as i,W as c,X as l,Y as d,Z as u,_ as f,y as p,$ as m,a0 as h,G as g,a1 as y,a2 as b,a3 as N,a4 as S,N as w,x,a5 as A,a6 as v,L as T,a7 as k,a8 as C,a9 as D,D as O,aa as _,ab as $,ac as j,ad as P,ae as E,af as M,ag as B,ah as q,ai as R,aj as F,ak as I,al as H,am as z,j as W,an as J,v as V,ao as L,ap as G,aq as Q,ar as U,as as X,at as Y,au as Z,g as K}from"../chunks/binder.js";import{H as tt,a as et}from"../chunks/registerComponents.js";import{V as nt}from"../chunks/version.js";import{W as st,g as ot}from"../chunks/pathDiagnostics.js";import"../chunks/errorGuidance.js";import"../chunks/lifecycleHooks.js";import"../chunks/declarationAliases.js";import"../chunks/setAll.js";import"../chunks/checkDependency.js";import"../chunks/getAllPropertyDescriptors.js";import"../chunks/declarationHooks.js";import"../chunks/diagnosticsHooks.js";const rt=/^@@wcs-(?:for|if|elseif|else):[^-]/,at=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,it=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,ct=/^@@wcs-text-start:(.+)$/;function lt(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function dt(t,e){const n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),s=[];for(;n.nextNode();){const t=n.currentNode;e(t.data)&&s.push(t)}return s}const ut=t=>rt.test(t),ft=t=>at.test(t),pt=t=>at.test(t)||it.test(t);function mt(t){return"else"===t.bindingType?"else:":`${t.bindingType}: ${ht(t.statePathName,t.outFilters)}`}function ht(t,e){let n=t;for(const t of e){const e=t.literals??t.args;n+=`|${t.filterName}`,t.args.length>0&&(n+=`(${t.args.map((t,n)=>"string"==typeof e[n]?`'${t.split("'").join("'\"'\"'")}'`:t).join(",")})`)}return n}const gt=/--|-$|[\0\n\r\u2028\u2029]/;function yt(t){const e=t.fragment.cloneNode(!0);for(const n of t.nodeInfos){const s=i(c(t.fragment,n.nodePath));if(null===s)continue;const o=c(e,n.nodePath);o.parentNode.replaceChild(document.createComment(s),o)}return e}class bt extends tt{_stateData=null;_templates=null;_hydrateProps=null;get version(){return this.getAttribute("version")||""}get stateData(){return null===this._stateData&&(this._stateData=this._loadStateData()),this._stateData}get templates(){return null===this._templates&&(this._templates=this._loadTemplates()),this._templates}get hydrateProps(){return null===this._hydrateProps&&(this._hydrateProps=this._loadHydrateProps()),this._hydrateProps}getTemplate(t){return this.templates.get(t)??null}verifyVersion(){const t=this.version;if(!t)return!0;const e=t.split("."),n=nt.split(".");return e[0]===n[0]&&e[1]===n[1]}setStateData(t){this._stateData=t}setHydrateProps(t){this._hydrateProps=t}_loadStateData(){const t=this.querySelector('script[type="application/json"]:not([data-wcs-ssr-props])');if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}_loadTemplates(){const t=new Map,e=this.querySelectorAll("template[id]");for(const n of e){const e=n.getAttribute("id");e&&t.set(e,n)}return t}_loadHydrateProps(){const t=this.querySelector("script[data-wcs-ssr-props]");if(!t)return{};try{return JSON.parse(t.textContent||"{}")}catch{return{}}}static find(e){const n=t.tagNames.ssr,s=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!s)return null;return s.querySelector(n)}static extractStateData(t){const e=t.__state;if(!e||"object"!=typeof e)return{};const n={};for(const t of Object.keys(e)){if(t.startsWith("$"))continue;const s=Object.getOwnPropertyDescriptor(e,t);if(void 0!==s&&"function"==typeof s.get)continue;const o=e[t];"function"!=typeof o&&(n[t]=o)}return n}static buildContent(n,i,c){const l=c??n.ownerDocument;e.seen&&function(t){const e=new Map;for(const n of dt(t,ft)){if(null===n.parentNode)continue;const[,t,s]=at.exec(n.data),o=s.split(":")[0],r=n.previousSibling?.data,a=`@@wcs-${t}-end:${s}`;if(r!==`@@wcs-${t}:${o}`&&e.get(r)!==o)for(let t=n;null!==t;){const e=t.nextSibling;t.remove(),t=t.data===a?null:e}else"for"===t&&e.set(a,o)}}(l);const d=document.createElement("script");d.setAttribute("type","application/json"),d.textContent=lt(JSON.stringify(i)),n.appendChild(d);for(const[e,s]of function(t){const e=new Map,n=[t];for(;n.length>0;)for(const t of dt(n.shift(),ut)){const s=t.data,o=s.slice(s.indexOf(":")+1);if(e.has(o))continue;const r=a(o);null!==r&&(e.set(o,r),n.push(r.fragment))}return e}(l)){const o=document.createElement("template");o.setAttribute("id",e),o.setAttribute(t.bindAttributeName,mt(s.parseBindTextResult)),o.content.appendChild(yt(s)),n.appendChild(o)}const u=n.ownerDocument,f=s();if(f.length>0){const t={};for(let e=0;e<f.length;e++){const n=f[e];if(!n.isConnected||n.ownerDocument!==u)continue;const s=o(n);if(0===s.length)continue;const r=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",r);const a={};for(const t of s)a[t.propName]=t.value;t[r]=a}if(Object.keys(t).length>0){const e=document.createElement("script");e.setAttribute("type","application/json"),e.setAttribute("data-wcs-ssr-props",""),e.textContent=lt(JSON.stringify(t)),n.appendChild(e)}}r()}static removeBlockBoundaryComments(t){for(const e of dt(t,pt))e.remove()}static removeStructuralComments(t){for(const e of dt(t,ut))e.remove()}static restoreTextBindings(t){for(const e of dt(t,t=>ct.test(t))){const t=ct.exec(e.data)[1],n=document.createComment(`@@: ${t}`);e.parentNode.insertBefore(n,e);let s=e.nextSibling;e.remove();const o=`@@wcs-text-end:${t}`;for(;s;){const t=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===o){s.parentNode.removeChild(s);break}s.parentNode.removeChild(s),s=t}}}static cleanupDom(e){const n=document.body,s=e.querySelectorAll(t.tagNames.ssr),o=new Map;for(const t of s){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&o.set(e,t)}}for(const t of dt(n,ft)){const e=at.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let s=t.nextSibling;for(;s;){const t=s.nextSibling;if(s.nodeType===Node.COMMENT_NODE&&s.data===n){s.remove();break}s.remove(),s=t}t.remove()}bt.restoreTextBindings(n);const r=e=>{for(const n of dt(e,ut)){const e=o.get(n.data.split(":")[1]);if(e){const s=document.createElement("template"),o=e.getAttribute(t.bindAttributeName);o&&s.setAttribute(t.bindAttributeName,o);const a=document.importNode(e.content,!0);if(a.childNodes.length>0)s.content.appendChild(a);else for(const t of Array.from(e.childNodes))s.content.appendChild(document.importNode(t,!0));r(s.content),n.parentNode.replaceChild(s,n)}}};r(n);const a=e.querySelectorAll("[data-wcs-ssr-id]");for(const t of a)t.removeAttribute("data-wcs-ssr-id");for(const t of s)t.remove()}}const Nt={protocol:"wcs-ssr-snapshot",version:1,build:function(e){const n=t.tagNames.state,s=t.tagNames.ssr,o=e.querySelectorAll(`${n}[enable-ssr]:not([mount]):not([bind-component])`);for(const t of o){const e=t.previousElementSibling;if(null!==e&&e.tagName.toLowerCase()===s)continue;const n=document.createElement(s);n.setAttribute("version",nt),bt.buildContent(n,bt.extractStateData(t),t.getRootNode()),t.parentNode?.insertBefore(n,t)}r()},reset:function(){d(),r(),e.seen=!1}};const St=new Set(["for","if","elseif","else"]);function wt(t){const[,e,n]=at.exec(t),[s,...o]=n.split(":");return"for"===e?{type:e,uuid:s,path:o[0],index:parseInt(o[1],10),nodes:[]}:{type:e,uuid:s,path:o.join(":"),index:null,nodes:[]}}function xt(e){const n=[];for(const s of e)if(s.nodeType===Node.ELEMENT_NODE){const e=s;e.hasAttribute(t.bindAttributeName)&&n.push(e),Array.from(e.children).some(e=>e.localName===t.tagNames.state&&L(e))||n.push(...G(e))}else null!==l(s)&&n.push(s);return n}function At(t){const[e,n,s]=Q(t),o=new U;return{bindingInfos:o.initialize(n,{registerAddress:!1,applyOnReconnect:!1}),subscriberNodes:e,bindingSession:o,deferredSpreads:s}}const vt=/^\s*@@\s*(?:wcs-text)?\s*:/;function Tt(t,e){for(const n of e)"event"===n.bindingType||St.has(n.bindingType)||(n.node.nodeType!==Node.COMMENT_NODE||"text"===n.bindingType&&vt.test(n.node.data))&&t.push(n)}function kt(t,e){const n=[];for(let s=0;s<t.nodes.length;s++){const o=e.get(t.nodes[s]);o?s+=o.nodes.length+1:n.push(t.nodes[s])}return n}function Ct(t,e,n,s,o,r){e.length>0&&(t.spreads=e);for(const t of e)Y(t.node);m(e,n,s,o,r)}function Dt(t,e){const n=a(e),s=g(t.getRootNode());let o=null;if(n&&s){const{statePathName:t,outFilters:e}=n.parseBindTextResult;s.createState("readonly",n=>{const s=y(n[t],X(e,"output"));Array.isArray(s)&&(o=s)})}return o}function Ot(e,n){return`@@${{for:t.commentForPrefix,if:t.commentIfPrefix,elseif:t.commentElseIfPrefix,else:t.commentElsePrefix}[e]}:${n}`}function _t(t,e,n){const s=Ot(e,n);return dt(t,t=>t===s)[0]??null}function $t(e,n){const s=e,o=n.templates,r=new Map;for(const[t,e]of o)for(const n of dt(e.content,ut))r.set(n.data.slice(n.data.indexOf(":")+1),t);const a=new Set(v(e));if(a.size>0)for(const t of dt(s,ut)){const e=t.data.slice(t.data.indexOf(":")+1);let n=t.parentNode;for(;null!==n&&!a.has(n);)n=n.parentNode;null===n||r.has(e)||r.set(e,n)}const i=new Map,c=[];for(const[e,n]of o){const s=n.getAttribute(t.bindAttributeName)||"";let o=T(s)[0];const a=o.bindingType,l=r.get(e),d=i.get(l);"else"===a&&d&&(o={...d,outFilters:[...d.outFilters,k()],bindingType:"else"}),"if"===a||"elseif"===a?i.set(l,o):"else"===a&&i.set(l,null),c.push([e,n,o])}for(const[t,e,n]of c.reverse()){const o=document.importNode(e.content,!0),r="for"===n.bindingType?n.statePathName:void 0;C(o),"string"==typeof r&&D(o,r),O(s,o,r);const a={fragment:o,parseBindTextResult:n,nodeInfos:_(o)};$(t,s,a)}}const jt={hydrate:async function(e){await u(e);const n=e.querySelectorAll(t.tagNames.ssr);for(const t of n){const n=t;if(!n.verifyVersion())return console.warn(`[@wcstack/state] SSR version mismatch: server="${n.version}", client="${nt}". Falling back to full render.`),bt.cleanupDom(e),!1}const s=function(t){const e=[];for(const n of dt(t,pt)){if(!ft(n.data)){e.pop();continue}const t=wt(n.data),s=e.at(-1);if("for"===t.type&&s&&s.uuid!==t.uuid)return[t,s];e.push(t)}return null}(document.body);if(null!==s){const[t,n]=s;return console.warn(`[@wcstack/state] SSR: "for: ${t.path}" in "${n.type}: ${n.path}" (known limitation). Falling back to full render.`),bt.cleanupDom(e),!1}for(const t of n)$t(e,t);bt.restoreTextBindings(document.body);const o=function(t){const e=[];for(const n of dt(t,ft)){const t=wt(n.data);t.start=n;const s=n.data.replace("-start:","-end:");let o=n.nextSibling;for(;o&&(o.nodeType!==Node.COMMENT_NODE||o.data!==s);)t.nodes.push(o),o=o.nextSibling;e.push(t)}return e}(document.body),r=new Map,a=function(t,e,n=new Map){const s=new Map,o=[],r=new Map(e.map(t=>[t.start,t])),a=new Set;for(let t=e.length-1;t>=0;t--){const n=xt(e[t].nodes).filter(t=>!a.has(t));for(const t of n)a.add(t);e[t].subscribers=n}for(const a of e){const e=kt(a,r);if(0===e.length)continue;const i=e.some(t=>ut(t.data));if(i){const t=document.createComment(`wcs-row-end:${a.uuid}`);a.nodes[a.nodes.length-1].after(t),e.push(t)}const{bindingInfos:c,subscriberNodes:l,bindingSession:d,deferredSpreads:u}=At(a.subscribers);for(const t of c)if(t.node!==t.replaceNode){const n=e.indexOf(t.node);n>=0&&(e[n]=t.replaceNode)}const f=j(e,i);P(f,d),E(f,c),M(f,l);const p=c.filter(t=>B(t,q));if(R(f,p),"for"===a.type&&null!==a.index){const e=_t(t,"for",a.uuid);if(e){let t=n.get(a.uuid);if(!t){const o=Dt(e,a.uuid)??a.path;t=s.get(o),t||s.set(o,t=[]),n.set(a.uuid,t)}const r=t[a.index]??=F(null,a.index);I(e,r,f),H(e,f.lastNode),z(e,f);const i=ot(a.path+"."+st),l=W(i,r);J(f,l),d.initialize(c,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),Tt(o,c),Ct(f,u,l,d,c,p)}}else{const e=a.start.previousSibling,n=e?.data===Ot(a.type,a.uuid)?e:_t(t,a.type,a.uuid);if(n){z(n,f);const t=V(n);J(f,t),d.initialize(c,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),Tt(o,c),Ct(f,u,t,d,c,p)}}}return o}(document.body,o,r);bt.removeBlockBoundaryComments(document.body);const i=[];for(const t of n)t.parentNode&&(i.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());const[,c,l]=f(document.body),d=[],v=[],T=p(document.body),k=T.initialize(c);m(l,null,T);for(const t of k)if("event"!==t.bindingType)if(St.has(t.bindingType))v.push(t);else{if(t.statePathName.includes(st))continue;d.push(t)}for(const t of v)if("for"===t.bindingType){const e=h(t),n=t.replaceNode.getRootNode(),s=g(n);s&&s.createState("readonly",n=>{const s=y(n[t.statePathName],t.outFilters);if(Array.isArray(s)){const n=r.get(t.uuid);n&&b(s,n),N(e,s),S(t.node,s),w(e,s)}})}x([...d,...a]);for(const{el:t,parent:e,next:n}of i)e.insertBefore(t,n);const C=new Map;for(const t of e.querySelectorAll("[data-wcs-ssr-id]"))C.set(t.getAttribute("data-wcs-ssr-id"),t);for(const n of e.querySelectorAll(t.tagNames.ssr))for(const[t,e]of Object.entries(n.hydrateProps)){const n=C.get(t);if(n)for(const[t,s]of Object.entries(e))A?.isDeclared(n,t)||(n[t]=s)}for(const t of e.querySelectorAll("[data-wcs-ssr-id]"))t.removeAttribute("data-wcs-ssr-id");return!0},textMarker:function(t){const e=t.node.nodeType===Node.COMMENT_NODE?l(t.node)??t.statePathName:ht(t.statePathName,t.outFilters);return gt.test(e)?t.statePathName:e},loadState(t){const e=t.parentNode;if(!e)return null;const n=bt.find(e);if(!n)return null;const s=n.stateData;return Object.keys(s).length>0?s:null},async emitSnapshot(e){await K(e.rootNode);const n=bt.extractStateData(e),s=document.createElement(t.tagNames.ssr);s.setAttribute("version",nt),bt.buildContent(s,n,e.rootNode),e.parentNode?.insertBefore(s,e)}};let Pt=!1;function Et(){Pt||(Pt=!0,Z(jt),et(e=>{e.get(t.tagNames.ssr)||e.define(t.tagNames.ssr,bt)}),function(){const t=globalThis;void 0===t[n]&&(t[n]=Nt)}())}const Mt={name:"ssr",install(){Et()}};export{Mt as default,Mt as ssr};
2
2
  //# sourceMappingURL=ssr.js.map