@wcstack/state 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +25 -3
- package/README.md +25 -3
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.esm.js +1 -0
- package/dist/parser.esm.js +25 -0
- package/dist/split/chunks/binder.js +1 -1
- package/dist/split/chunks/binder.js.map +1 -1
- package/dist/split/chunks/checkDependency.js +1 -1
- package/dist/split/chunks/mount.js +1 -1
- package/dist/split/chunks/mount.js.map +1 -1
- package/dist/split/chunks/pathDiagnostics.js +1 -1
- package/dist/split/chunks/pathDiagnostics.js.map +1 -1
- package/dist/split/chunks/registerComponents.js +1 -1
- package/dist/split/chunks/setAll.js +1 -1
- package/dist/split/chunks/version.js +1 -1
- package/dist/split/chunks/watchRuntime.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/diagnostics.js +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/scopes.js.map +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/wcs-manifest.json +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as t,S as e}from"../chunks/filterRegistry.js";import{O as n,P as o,Q as s,R as r,S as a,U as c,V as i,n as l,m as d,W as u,y as f,X as p,K as m,o as h,Y as N,Z as g,_ as y,v as b,$ as S,a0 as T,a1 as x,a2 as A,a3 as O,a4 as C,a5 as v,a6 as _,a7 as E,a8 as w,a9 as k,k as M,aa as P,ab as D,ac as j,ad as $,ae as W,g as B}from"../chunks/binder.js";import{H,a as q}from"../chunks/registerComponents.js";import{V as F}from"../chunks/version.js";import{W as R,I,g as z}from"../chunks/pathDiagnostics.js";import"../chunks/errorGuidance.js";import"../chunks/lifecycleHooks.js";import"../chunks/setAll.js";import"../chunks/getAllPropertyDescriptors.js";import"../chunks/checkDependency.js";import"../chunks/diagnosticsHooks.js";const J=/^@@wcs-(?:for|if|elseif|else):[^-]/,V=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,L=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,G=/^@@wcs-text-start:(.+)$/;function K(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class Q extends H{_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=F.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,o=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!o)return null;return o.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 o=Object.getOwnPropertyDescriptor(e,t);if(void 0!==o&&"function"==typeof o.get)continue;const s=e[t];"function"!=typeof s&&(n[t]=s)}return n}static buildContent(e,c){const i=document.createElement("script");i.setAttribute("type","application/json"),i.textContent=K(JSON.stringify(c)),e.appendChild(i);const l=n();for(const n of l){const s=o(n);if(!s)continue;const r=document.createElement("template");r.setAttribute("id",n);const a=s.parseBindTextResult,c="else"===a.bindingType?"else:":`${a.bindingType}: ${a.statePathName}`;r.setAttribute(t.bindAttributeName,c);const i=s.fragment.cloneNode(!0);r.content.appendChild(i),e.appendChild(r)}const d=s();if(d.length>0){const t={};for(let e=0;e<d.length;e++){const n=d[e],o=r(n);if(0===o.length)continue;const s=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",s);const a={};for(const t of o)a[t.propName]=t.value;t[s]=a}if(Object.keys(t).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=K(JSON.stringify(t)),e.appendChild(n)}}a()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(V.test(t.data)||L.test(t.data))&&n.push(t)}for(const t of n)t.remove()}static removeStructuralComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;J.test(t.data)&&n.push(t)}for(const t of n)t.remove()}static restoreTextBindings(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode,o=G.exec(t.data);o&&n.push({comment:t,path:o[1]})}for(const{comment:t,path:e}of n){const n=document.createComment(`@@: ${e}`);t.parentNode.insertBefore(n,t);let o=t.nextSibling;t.remove();const s=`@@wcs-text-end:${e}`;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=t}}}static cleanupDom(e){const n=document.body,o=e.querySelectorAll(t.tagNames.ssr),s=new Map;for(const t of o){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&s.set(e,t)}}const r=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),a=[];for(;r.nextNode();){const t=r.currentNode;V.test(t.data)&&a.push(t)}for(const t of a){const e=V.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let o=t.nextSibling;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=t}t.remove()}Q.restoreTextBindings(n);const c=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),i=[];for(;c.nextNode();){const t=c.currentNode;if(J.test(t.data)){const e=t.data.split(":")[1];i.push({comment:t,uuid:e})}}for(const{comment:e,uuid:n}of i){const o=s.get(n);if(o){const n=document.createElement("template"),s=o.getAttribute(t.bindAttributeName);s&&n.setAttribute(t.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)n.content.appendChild(r);else for(const t of Array.from(o.childNodes))n.content.appendChild(document.importNode(t,!0));e.parentNode.replaceChild(n,e)}}const l=e.querySelectorAll("[data-wcs-ssr-id]");for(const t of l)t.removeAttribute("data-wcs-ssr-id");for(const t of o)t.remove()}}const U={protocol:"wcs-ssr-snapshot",version:1,build:function(e){const n=t.tagNames.state,o=t.tagNames.ssr,s=e.querySelectorAll(`${n}[enable-ssr]:not([mount]):not([bind-component])`);for(const t of s){const e=t.previousElementSibling;if(null!==e&&e.tagName.toLowerCase()===o)continue;const n=document.createElement(o);n.setAttribute("version",F),Q.buildContent(n,Q.extractStateData(t)),t.parentNode?.insertBefore(n,t)}}};const X=new Set(["for","if","elseif","else"]);function Y(t){const e=new j;if(0===t.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:e};const n=t[0].parentNode,o=t[t.length-1].nextSibling,s=document.createElement("div");for(const e of t)s.appendChild(e);const[r,a]=i(s),c=e.initialize(a,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:c,subscriberNodes:r,bindingSession:e}}function Z(t,e,n){for(const o of e)"event"===o.bindingType||X.has(o.bindingType)||o.node.nodeType===Node.COMMENT_NODE||o.statePathName in I||z(o.statePathName).wildcardCount>n||t.push(o)}function tt(e,n,o){const s={for:t.commentForPrefix,if:t.commentIfPrefix,elseif:t.commentElseIfPrefix,else:t.commentElsePrefix}[n];if(!s)return null;const r=`@@${s}:${o}`,a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;a.nextNode();){const t=a.currentNode;if(t.data===r)return t}return null}function et(e,n){const o=e;let s=null;for(const[e,r]of n.templates){const n=r.getAttribute(t.bindAttributeName)||"";let a=N(n)[0];const c=a.bindingType;"else"===c&&s&&(a={...s,outFilters:[...s.outFilters,$()],bindingType:"else"}),"if"===c||"elseif"===c?s=a:"else"===c&&(s=null);const i=document.importNode(r.content,!0),l="for"===c?a.statePathName:void 0;g(i),"string"==typeof l&&y(i,l),b(o,i,l);const d={fragment:i,parseBindTextResult:a,nodeInfos:S(i)};T(e,o,d)}}const nt={hydrate:async function(e){await c(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="${F}". Falling back to full render.`),Q.cleanupDom(e),!1}for(const t of n)et(e,t);const s=function(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const t of o){const n=V.exec(t.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let a,c,i=null;"for"===o?(a=r[0],c=r[1],i=parseInt(r[2],10)):(a=r[0],c=r.slice(1).join(":"));const l=[];let d=t.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)l.push(d),d=d.nextSibling;e.push({type:o,uuid:a,path:c,index:i,nodes:l})}return e}(document.body),r=function(t,e){const n=new Map,s=[];for(const o of e){if(0===o.nodes.length)continue;const e=x(o.nodes),{bindingInfos:r,subscriberNodes:a,bindingSession:c}=Y(o.nodes);A(e,c);for(const t of a)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");O(e,r),C(e,a);const i=[];for(const t of r)t.statePathName in I&&i.push(t);if(v(e,i),"for"===o.type&&null!==o.index){const a=tt(t,"for",o.uuid);if(a){const t=_(null,o.index);E(a,t,e);const i=o.nodes[o.nodes.length-1];w(a,i),k(a,e);const l=z(o.path+"."+R),d=M(l,t);P(e,d),c.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),Z(s,r,l.wildcardCount);let u=n.get(o.uuid);u||(u=[],n.set(o.uuid,u)),u.push(t)}}else{const n=tt(t,o.type,o.uuid);n&&(k(n,e),c.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),Z(s,r,0))}}for(const[e,s]of n){const n=tt(t,"for",e);if(!n)continue;const r=n.getRootNode(),a=o(e);if(!a)continue;const c=a.parseBindTextResult.statePathName,i=f(r);i&&i.createState("readonly",t=>{const e=t[c];Array.isArray(e)&&D(e,s)})}return s}(document.body,s);Q.removeBlockBoundaryComments(document.body);const a=[];for(const t of n)t.parentNode&&(a.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());Q.restoreTextBindings(document.body);const[N,g]=i(document.body);for(const t of N)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(l(t,null),e.setAttribute("data-wcs-completed",""))}else l(t,null);const y=[],b=[],S=d(document.body).initialize(g);for(const t of S)if("event"!==t.bindingType)if(X.has(t.bindingType))b.push(t);else{if(t.statePathName.includes(R))continue;y.push(t)}for(const t of b)if("for"===t.bindingType){const e=u(t),n=t.replaceNode.getRootNode(),o=f(n);o&&o.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&(p(e,o),m(e,o))})}h([...y,...r]);for(const{el:t,parent:e,next:n}of a)e.insertBefore(t,n);const T=e.querySelectorAll(t.tagNames.ssr);for(const t of T){const n=t.hydrateProps;for(const[t,o]of Object.entries(n)){const n=e.querySelector(`[data-wcs-ssr-id="${t}"]`);if(n)for(const[t,e]of Object.entries(o))n[t]=e}}const j=e.querySelectorAll("[data-wcs-completed]");for(const t of j)t.removeAttribute("data-wcs-completed");return!0},loadState(t){const e=t.parentNode;if(!e)return null;const n=Q.find(e);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null},async emitSnapshot(e){await B(e.rootNode);const n=Q.extractStateData(e),o=document.createElement(t.tagNames.ssr);o.setAttribute("version",F),Q.buildContent(o,n),e.parentNode?.insertBefore(o,e)}};let ot=!1;function st(){ot||(ot=!0,W(nt),q(e=>{e.get(t.tagNames.ssr)||e.define(t.tagNames.ssr,Q)}),function(){const t=globalThis;void 0===t[e]&&(t[e]=U)}())}const rt={name:"ssr",install(){st()}};export{rt as default,rt as ssr};
|
|
1
|
+
import{c as t,S as e}from"../chunks/filterRegistry.js";import{P as n,Q as o,R as s,S as r,U as a,V as c,W as i,n as l,m as d,X as u,y as f,Y as p,L as m,o as h,D as N,Z as g,_ as y,v as b,$ as S,a0 as T,a1 as x,a2 as A,a3 as C,a4 as O,a5 as v,a6 as _,a7 as E,a8 as w,a9 as k,k as D,aa as M,ab as P,ac as j,ad as $,ae as W,g as B}from"../chunks/binder.js";import{H,a as q}from"../chunks/registerComponents.js";import{V as F}from"../chunks/version.js";import{W as R,I,g as z}from"../chunks/pathDiagnostics.js";import"../chunks/errorGuidance.js";import"../chunks/lifecycleHooks.js";import"../chunks/setAll.js";import"../chunks/getAllPropertyDescriptors.js";import"../chunks/checkDependency.js";import"../chunks/diagnosticsHooks.js";const J=/^@@wcs-(?:for|if|elseif|else):[^-]/,L=/^@@wcs-(for|if|elseif|else)-start:(.+)$/,V=/^@@wcs-(for|if|elseif|else)-end:(.+)$/,G=/^@@wcs-text-start:(.+)$/;function Q(t){return t.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}class U extends H{_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=F.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,o=e instanceof Element?e:e instanceof Document?e.documentElement:null;if(!o)return null;return o.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 o=Object.getOwnPropertyDescriptor(e,t);if(void 0!==o&&"function"==typeof o.get)continue;const s=e[t];"function"!=typeof s&&(n[t]=s)}return n}static buildContent(e,c){const i=document.createElement("script");i.setAttribute("type","application/json"),i.textContent=Q(JSON.stringify(c)),e.appendChild(i);const l=n();for(const n of l){const s=o(n);if(!s)continue;const r=document.createElement("template");r.setAttribute("id",n);const a=s.parseBindTextResult,c="else"===a.bindingType?"else:":`${a.bindingType}: ${a.statePathName}`;r.setAttribute(t.bindAttributeName,c);const i=s.fragment.cloneNode(!0);r.content.appendChild(i),e.appendChild(r)}const d=s();if(d.length>0){const t={};for(let e=0;e<d.length;e++){const n=d[e],o=r(n);if(0===o.length)continue;const s=`wcs-ssr-${e}`;n.setAttribute("data-wcs-ssr-id",s);const a={};for(const t of o)a[t.propName]=t.value;t[s]=a}if(Object.keys(t).length>0){const n=document.createElement("script");n.setAttribute("type","application/json"),n.setAttribute("data-wcs-ssr-props",""),n.textContent=Q(JSON.stringify(t)),e.appendChild(n)}}a()}static removeBlockBoundaryComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;(L.test(t.data)||V.test(t.data))&&n.push(t)}for(const t of n)t.remove()}static removeStructuralComments(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode;J.test(t.data)&&n.push(t)}for(const t of n)t.remove()}static restoreTextBindings(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(;e.nextNode();){const t=e.currentNode,o=G.exec(t.data);o&&n.push({comment:t,path:o[1]})}for(const{comment:t,path:e}of n){const n=document.createComment(`@@: ${e}`);t.parentNode.insertBefore(n,t);let o=t.nextSibling;t.remove();const s=`@@wcs-text-end:${e}`;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===s){o.parentNode.removeChild(o);break}o.parentNode.removeChild(o),o=t}}}static cleanupDom(e){const n=document.body,o=e.querySelectorAll(t.tagNames.ssr),s=new Map;for(const t of o){const e=t.querySelectorAll("template[id]");for(const t of e){const e=t.getAttribute("id");e&&s.set(e,t)}}const r=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),a=[];for(;r.nextNode();){const t=r.currentNode;L.test(t.data)&&a.push(t)}for(const t of a){const e=L.exec(t.data),n=`@@wcs-${e[1]}-end:${e[2]}`;let o=t.nextSibling;for(;o;){const t=o.nextSibling;if(o.nodeType===Node.COMMENT_NODE&&o.data===n){o.remove();break}o.remove(),o=t}t.remove()}U.restoreTextBindings(n);const c=document.createTreeWalker(n,NodeFilter.SHOW_COMMENT),i=[];for(;c.nextNode();){const t=c.currentNode;if(J.test(t.data)){const e=t.data.split(":")[1];i.push({comment:t,uuid:e})}}for(const{comment:e,uuid:n}of i){const o=s.get(n);if(o){const n=document.createElement("template"),s=o.getAttribute(t.bindAttributeName);s&&n.setAttribute(t.bindAttributeName,s);const r=document.importNode(o.content,!0);if(r.childNodes.length>0)n.content.appendChild(r);else for(const t of Array.from(o.childNodes))n.content.appendChild(document.importNode(t,!0));e.parentNode.replaceChild(n,e)}}const l=e.querySelectorAll("[data-wcs-ssr-id]");for(const t of l)t.removeAttribute("data-wcs-ssr-id");for(const t of o)t.remove()}}const X={protocol:"wcs-ssr-snapshot",version:1,build:function(e){const n=t.tagNames.state,o=t.tagNames.ssr,s=e.querySelectorAll(`${n}[enable-ssr]:not([mount]):not([bind-component])`);for(const t of s){const e=t.previousElementSibling;if(null!==e&&e.tagName.toLowerCase()===o)continue;const n=document.createElement(o);n.setAttribute("version",F),U.buildContent(n,U.extractStateData(t)),t.parentNode?.insertBefore(n,t)}}};const Y=new Set(["for","if","elseif","else"]);function Z(t){const e=new j;if(0===t.length)return{bindingInfos:[],subscriberNodes:[],bindingSession:e};const n=t[0].parentNode,o=t[t.length-1].nextSibling,s=document.createElement("div");for(const e of t)s.appendChild(e);const[r,a]=i(s),c=e.initialize(a,{registerAddress:!1,applyOnReconnect:!1});if(n)for(;s.firstChild;)n.insertBefore(s.firstChild,o);return{bindingInfos:c,subscriberNodes:r,bindingSession:e}}function K(t,e,n){for(const o of e)"event"===o.bindingType||Y.has(o.bindingType)||o.node.nodeType===Node.COMMENT_NODE||o.statePathName in I||z(o.statePathName).wildcardCount>n||t.push(o)}function tt(e,n,o){const s={for:t.commentForPrefix,if:t.commentIfPrefix,elseif:t.commentElseIfPrefix,else:t.commentElsePrefix}[n];if(!s)return null;const r=`@@${s}:${o}`,a=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;a.nextNode();){const t=a.currentNode;if(t.data===r)return t}return null}function et(e,n){const o=e;let s=null;for(const[e,r]of n.templates){const n=r.getAttribute(t.bindAttributeName)||"";let a=N(n)[0];const c=a.bindingType;"else"===c&&s&&(a={...s,outFilters:[...s.outFilters,$()],bindingType:"else"}),"if"===c||"elseif"===c?s=a:"else"===c&&(s=null);const i=document.importNode(r.content,!0),l="for"===c?a.statePathName:void 0;g(i),"string"==typeof l&&y(i,l),b(o,i,l);const d={fragment:i,parseBindTextResult:a,nodeInfos:S(i)};T(e,o,d)}}const nt={hydrate:async function(e){await c(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="${F}". Falling back to full render.`),U.cleanupDom(e),!1}for(const t of n)et(e,t);const s=function(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const t of o){const n=L.exec(t.data);if(!n)continue;const o=n[1],s=n[2],r=s.split(":");let a,c,i=null;"for"===o?(a=r[0],c=r[1],i=parseInt(r[2],10)):(a=r[0],c=r.slice(1).join(":"));const l=[];let d=t.nextSibling;const u=`@@wcs-${o}-end:${s}`;for(;d&&(d.nodeType!==Node.COMMENT_NODE||d.data!==u);)l.push(d),d=d.nextSibling;e.push({type:o,uuid:a,path:c,index:i,nodes:l})}return e}(document.body),r=function(t,e){const n=new Map,s=[];for(const o of e){if(0===o.nodes.length)continue;const e=x(o.nodes),{bindingInfos:r,subscriberNodes:a,bindingSession:c}=Z(o.nodes);A(e,c);for(const t of a)t.nodeType===Node.ELEMENT_NODE&&t.setAttribute("data-wcs-completed","");C(e,r),O(e,a);const i=[];for(const t of r)t.statePathName in I&&i.push(t);if(v(e,i),"for"===o.type&&null!==o.index){const a=tt(t,"for",o.uuid);if(a){const t=_(null,o.index);E(a,t,e);const i=o.nodes[o.nodes.length-1];w(a,i),k(a,e);const l=z(o.path+"."+R),d=D(l,t);M(e,d),c.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),K(s,r,l.wildcardCount);let u=n.get(o.uuid);u||(u=[],n.set(o.uuid,u)),u.push(t)}}else{const n=tt(t,o.type,o.uuid);n&&(k(n,e),c.initialize(r,{registerAddress:!0,registerPathInfo:!1,applyOnReconnect:!1}),K(s,r,0))}}for(const[e,s]of n){const n=tt(t,"for",e);if(!n)continue;const r=n.getRootNode(),a=o(e);if(!a)continue;const c=a.parseBindTextResult.statePathName,i=f(r);i&&i.createState("readonly",t=>{const e=t[c];Array.isArray(e)&&P(e,s)})}return s}(document.body,s);U.removeBlockBoundaryComments(document.body);const a=[];for(const t of n)t.parentNode&&(a.push({el:t,parent:t.parentNode,next:t.nextSibling}),t.remove());U.restoreTextBindings(document.body);const[N,g]=i(document.body);for(const t of N)if(t.nodeType===Node.ELEMENT_NODE){const e=t;e.hasAttribute("data-wcs-completed")||(l(t,null),e.setAttribute("data-wcs-completed",""))}else l(t,null);const y=[],b=[],S=d(document.body).initialize(g);for(const t of S)if("event"!==t.bindingType)if(Y.has(t.bindingType))b.push(t);else{if(t.statePathName.includes(R))continue;y.push(t)}for(const t of b)if("for"===t.bindingType){const e=u(t),n=t.replaceNode.getRootNode(),o=f(n);o&&o.createState("readonly",n=>{const o=n[t.statePathName];Array.isArray(o)&&(p(e,o),m(e,o))})}h([...y,...r]);for(const{el:t,parent:e,next:n}of a)e.insertBefore(t,n);const T=e.querySelectorAll(t.tagNames.ssr);for(const t of T){const n=t.hydrateProps;for(const[t,o]of Object.entries(n)){const n=e.querySelector(`[data-wcs-ssr-id="${t}"]`);if(n)for(const[t,e]of Object.entries(o))n[t]=e}}const j=e.querySelectorAll("[data-wcs-completed]");for(const t of j)t.removeAttribute("data-wcs-completed");return!0},loadState(t){const e=t.parentNode;if(!e)return null;const n=U.find(e);if(!n)return null;const o=n.stateData;return Object.keys(o).length>0?o:null},async emitSnapshot(e){await B(e.rootNode);const n=U.extractStateData(e),o=document.createElement(t.tagNames.ssr);o.setAttribute("version",F),U.buildContent(o,n),e.parentNode?.insertBefore(o,e)}};let ot=!1;function st(){ot||(ot=!0,W(nt),q(e=>{e.get(t.tagNames.ssr)||e.define(t.tagNames.ssr,U)}),function(){const t=globalThis;void 0===t[e]&&(t[e]=X)}())}const rt={name:"ssr",install(){st()}};export{rt as default,rt as ssr};
|
|
2
2
|
//# sourceMappingURL=ssr.js.map
|
package/dist/wcs-manifest.json
CHANGED
package/package.json
CHANGED