nexus-dom 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/cjs/chunks/store-view-XF9oYnrs.js +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/owner.d.ts +6 -0
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/store-view.d.ts +10 -4
- package/dist/esm/chunks/store-view-DxtNNb3a.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/owner.d.ts +6 -0
- package/dist/esm/server.js +1 -1
- package/dist/esm/store-view.d.ts +10 -4
- package/package.json +1 -1
- package/dist/cjs/chunks/store-view-C2XX94et.js +0 -1
- package/dist/esm/chunks/store-view-BaScxKX5.js +0 -1
package/README.md
CHANGED
|
@@ -169,8 +169,9 @@ function SearchInput({ onResize }: { onResize: ResizeObserverCallback }) {
|
|
|
169
169
|
}
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
> **✦ Note:** For
|
|
173
|
-
> `store().
|
|
172
|
+
> **✦ Note:** For store resources, return a cleanup from `store().setup` or
|
|
173
|
+
> `store().mount`, or use their `onCleanup` callback. A store declared inside
|
|
174
|
+
> a JSX component is cleaned up when that component leaves the tree.
|
|
174
175
|
|
|
175
176
|
</div></ul>
|
|
176
177
|
</details>
|
|
@@ -184,9 +185,11 @@ function SearchInput({ onResize }: { onResize: ResizeObserverCallback }) {
|
|
|
184
185
|
**Description:**
|
|
185
186
|
|
|
186
187
|
Declares a lazy store. The app creates the store when a component first uses
|
|
187
|
-
its descriptor.
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
its descriptor. A descriptor declared outside a component is shared within
|
|
189
|
+
each app; its resources live until `app.dispose()`. A store declared while a
|
|
190
|
+
JSX component renders belongs to that component instance. Its state survives
|
|
191
|
+
updates of a parent while the component stays at the same position, and its
|
|
192
|
+
resources are released when the component is removed.
|
|
190
193
|
|
|
191
194
|
**Parameters:**
|
|
192
195
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("nexus-state"),t=require("./types-BLzRvYOk.js");function r(e){let t;const r=e=>{try{e()}catch(e){(t??(t=[])).push(e)}};if(r(()=>e(r)),1===t?.length)throw t[0];if(t)throw new AggregateError(t,"nexus-dom: Multiple errors during cleanup.")}function n(e,t){try{t()}catch(t){throw new AggregateError([e,t],"nexus-dom: Rendering and cleanup failed.")}}function s(e,t){throw n(e,t),e}class o extends Error{constructor(e,t){super(`[${e}]\n${t}`),this.code=e,this.name="nexus-dom"}}function i(e,t){return new o(e,t)}function a(e,t,r,n,s){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?s.call(e,r):s?s.value=r:t.set(e,r),r}function c(e,t,r){let n=new Set,s=!1;const o=new Proxy(e,{get:(e,t,s)=>(n&&t in e&&n.add(t),!n&&r&&Object.hasOwn(e,t)?r(t):Reflect.get(e,t,s)),has:(e,t)=>(t in e&&n?.add(t),Reflect.has(e,t)),ownKeys:e=>(n&&(s=!0),Reflect.ownKeys(e))});try{return{value:t(o),dependencies:s?["*"]:Array.from(n)}}finally{n=void 0}}function u(e,t){if(e.length!==t.length)return!1;const r=t;return e.every(e=>r.includes(e))}var l,d,f;"function"==typeof SuppressedError&&SuppressedError;const h=new WeakMap,p=new WeakMap,y=new WeakMap,m=Symbol("nexus-dom.render-subscribe");function g(e,t,r){const n=e[m];return"function"==typeof n?n.call(e,t,r):e.subscribe(t)}function w(e,t,r,n,s){let o=!1;const i=(e,t)=>{if(!s)throw e;o=!0,s(e,t)};return{fail:i,update(s,a){let c;try{if(c=t(s),!o&&r(e,c))return}catch(e){return void i(e,a)}o=!1,e=c,n(c,a)}}}function b(e,t,r){return A(e,Boolean).branch(e=>e?t:r)}class v{constructor(e,t,r){this.source=e,this.project=t,this.isEqual=r,this[l]=!0}get(){return this.project(this.source.get())}subscribe(e){return this[m](e)}[(l=t.LIVE_VALUE,m)](e,t){const r=this.project(this.source.get()),{update:n,fail:s}=w(r,this.project,this.isEqual,e,t);return g(this.source,n,t?s:void 0)}map(e,t){return A(this,e,t)}if(e,t){return b(this,e,t)}branch(e,t){return _(this,e,t)}each(e){return D(this,e)}}const x=(e,t)=>null==e?void 0:e[t];class S{constructor(e,t){this.source=e,this.property=t}get[t.LIVE_VALUE](){return!0}get(){return x(this.source.get(),this.property)}subscribe(e){this.addListener(e);let t=!0;return()=>{t&&(t=!1,this.removeListener(e))}}addListener(e){const t=this.listeners;t?t instanceof Set?t.add(e):this.listeners=new Set([t,e]):this.listeners=e}removeListener(e){const t=this.listeners;t===e?this.listeners=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this.listeners=t.values().next().value))}update(e,t,r){const n=x(e,this.property),s=x(t,this.property);if(Object.is(n,s))return;const o=this.listeners;if(o)if(o instanceof Set)for(const e of Array.from(o))"function"==typeof e?e(s,r):e.notify(s,r);else"function"==typeof o?o(s,r):o.notify(s,r)}map(e,t){return A(this,e,t)}if(e,t){return b(this,e,t)}branch(e,t){return _(this,e,t)}each(e){return D(this,e)}}function A(e,t,r=Object.is){return new v(e,t,r)}const E=Symbol("nexus-dom.mutable-current"),O=Symbol("nexus-dom.mutable-listeners"),I=Symbol("nexus-dom.mutable-fields");class T{constructor(e){this[d]=!0,this[E]=e}get(){return this[E]}subscribe(e){const t=this[O];t?t instanceof Set?t.add(e):this[O]=new Set([t,e]):this[O]=e;let r=!0;return()=>{if(!r)return;r=!1;const t=this[O];t===e?this[O]=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this[O]=t.values().next().value))}}map(e,t){return A(this,e,t)}if(e,t){return b(this,e,t)}branch(e,t){return _(this,e,t)}each(e){return D(this,e)}$field(e){const t=this[I];if(!t){const t=new S(this,e);return this[I]=t,t}if(t instanceof Map){let r=t.get(e);return r||(r=new S(this,e),t.set(e,r)),r}let r=t,n=1;for(;r.property!==e&&r.next;)r=r.next,n++;if(r.property===e)return r;const s=new S(this,e);if(r.next=s,4===n){const e=new Map;for(let r=t;r;r=r.next)e.set(r.property,r);this[I]=e}return s}set(e,t){const r=this[E];if(Object.is(r,e))return;this[E]=e;const n=this[O];if(n instanceof Set)for(const r of Array.from(n))r(e,t);else n&&n(e,t);const s=this[I];if(s)if(s instanceof Map)for(const n of s.values())n.update(r,e,t);else for(let n=s;n;n=n.next)n.update(r,e,t)}}d=t.LIVE_VALUE;const N={get(e,t,r){if(t!==m)return t in e?Reflect.get(e,t,r):e.$field(t)}};class ${constructor(e){f.set(this,void 0),a(this,f,e,"f")}get id(){const e=function(e,t){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}(this,f);return"string"==typeof e?e:a(this,f,e.id(),"f")}}function _(e,t,r){return{kind:"dynamic",source:e,project:t,...r?.key?{key:r.key}:{}}}function D(e,t){const r=p.get(e);return{kind:"keyed",source:e,...void 0===r?{}:{stateKey:r},project:t}}function L(e,r,n=Object.is,s,o=e=>c(e,r)){const i={[t.LIVE_VALUE]:!0,get:()=>r(e.get()),subscribe:e=>i[m](e),[m](t,r){const s=o(e.get());let i=s.dependencies,a=!1,c=()=>{};const{update:l}=w(s.value,t=>{const r=o(t);if(!u(i,r.dependencies)){const t=c;i=r.dependencies,c=e.subscribe(d,i),t()}return r.value},n,t,r),d=(e,t)=>{a||l(e,t)};return c=e.subscribe(d,i),()=>{a||(a=!0,c())}},map(e,t){return A(this,e,t)},if(e,t){return b(this,e,t)},branch(e,t){return _(this,e,t)},each(e){return D(this,e)}};return void 0!==s&&p.set(i,s),i}function k(e,t,r,n){const s=L(e,t,r,void 0,n);return y.set(s,e),s}f=new WeakMap;const C=new Set(["innerhtml","outerhtml","srcdoc","dangerouslysetinnerhtml"]),M=new Set(["href","src","action","formaction","poster","xlink:href","xlinkhref"]),j=new Set(["http:","https:","mailto:","tel:"]);function R(e){const t=Array.from(e.options),r=t.filter(e=>e.defaultSelected);if(e.multiple)return r;if(r.length)return r.slice(-1);if(e.size>1)return[];const n=t.find(e=>!(e.disabled||"optgroup"===e.parentElement?.localName&&e.parentElement.hasAttribute("disabled")));return n?[n]:[]}const P=Symbol("nexus-dom.owner-mounted"),V=e=>{"function"==typeof e?e():e.dispose()};let H;function Y(){if(!H)throw i("ID_OUTSIDE_COMPONENT","Component ids can only be created while a component is mounting.");const e=H;let t;return()=>t??(t=e.id())}function U(e){if(null===e||"object"!=typeof e)return;const t=e.id;return"string"==typeof t||"number"==typeof t||"symbol"==typeof t?t:void 0}let F=1;const z=new WeakMap,W=new WeakMap,K=new WeakMap;let q=1;const J=Symbol("nexus-dom.no-list-payload");function X(e){let t=W.get(e);return void 0===t&&W.set(e,t=q++),t}function B(e,t=J){const r={...e,id:F++};return t!==J&&z.set(r,t),r}function G(e,t,r=!1){const n=r?t:t-1;if(!Number.isInteger(e)||e<0||e>n)throw i("INVALID_LIST_INDEX",n<0?`List index ${e} is invalid. The list is empty.`:`List index ${e} is outside 0..${n}.`)}const Z="nxs:t",Q="nxs:/",ee="nxs:s",te=(e,t,r)=>{if(null===e||"string"==typeof e||"boolean"==typeof e)return;if("number"==typeof e){if(Number.isFinite(e))return;throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} must be a finite number.`)}if("object"!=typeof e)throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains unsupported ${typeof e}.`);if(r.has(e))throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a cycle.`);const n=Object.getPrototypeOf(e);if(!Array.isArray(e)&&n!==Object.prototype&&null!==n)throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} must contain only plain objects and arrays.`);if(r.add(e),Array.isArray(e))for(let n=0;n<e.length;n++)te(e[n],`${t}[${n}]`,r);else{if(Object.getOwnPropertySymbols(e).length>0)throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a symbol key.`);for(const[n,s]of Object.entries(e))te(s,`${t}.${n}`,r)}r.delete(e)},re=e=>{if(!e||"object"!=typeof e)return!1;const t=e;if(Array.isArray(t.keys)&&t.keys.every(e=>"string"==typeof e)&&t.state&&"object"==typeof t.state&&!Array.isArray(t.state)){const e=[...t.keys].sort(),r=Object.keys(t.state).sort();return e.length===r.length&&e.every((e,t)=>e===r[t])}return!1},ne=e=>{let t;try{t=JSON.parse(e)}catch{throw i("HYDRATION_STATE_INVALID","Hydration state is not valid JSON.")}if(!t||"object"!=typeof t||1!==t.v||"idPrefix"in t&&"string"!=typeof t.idPrefix||!Array.isArray(t.stores)||!t.stores.every(re))throw i("HYDRATION_STATE_INVALID","Hydration state does not match the supported versioned payload.");return t},se=Symbol("nexus-dom.store-options"),oe=Symbol("nexus-dom.store-release"),ie=Symbol("nexus-dom.store-local");function ae(e,t){if(Array.isArray(t))throw i("STORE_DEPENDENCY_CONFLICT","Use an object with named store dependencies.");for(const[r,n]of Object.entries(t)){if(""===r)throw i("STORE_DEPENDENCY_CONFLICT",`Store namespace "${r}" is reserved.`);if(e.has(r))throw i("STORE_DEPENDENCY_CONFLICT",`Store namespace "${r}" is already defined.`);e.set(r,[n])}return e}const ce=(e,r)=>{const n=function(e){const t=h.get(e);if(t)return t;const r=new Map,n=new Proxy(Object.create(null),{get(t,n){let s=r.get(n);return s||(s=L(e,e=>e[n],Object.is,n),r.set(n,s)),s}});return h.set(e,n),n}(e),s=new Map;return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;let i=s.get(o);if(i)return i;const a=n[o],c=r(o);return c?(i={[t.LIVE_VALUE]:!0,get:()=>a.get(),subscribe:e=>a.subscribe(e),[m]:(e,t)=>g(a,e,t),map:(e,t)=>a.map(e,t),if:(e,t)=>a.if(e,t),branch:(e,t)=>a.branch(e,t),each:a.each.bind(a),set(e,t="$.set"){"function"==typeof e?c.nexus.set(t=>({[o]:e(t[o])}),t):c.nexus.set({[o]:e},t)}},s.set(o,i),i):a}})};exports.NexusDOMError=o,exports.Owner=class{constructor(e,t=!0,r){this.parent=e,this.disposed=!1,this.nextIdChild=0,this.localStoreIndex=0,this.ids=e?.ids??{prefix:r??"r0",symbolIds:void 0,nextSymbolId:0,claims:void 0,localStores:void 0},this.idPath=e?`${e.idPath}/${r??e.reserveIdSegment("o")}`:"",e&&t&&(e.children??(e.children=new Set)).add(this)}setComponentIdentity(e,t){this.componentIdentity={type:e,key:t}}hasComponentIdentity(){return void 0!==this.componentIdentity}acquireLocalStore(e,t){var r;const n=this.componentIdentity;if(!n)return e();const s=(r=this.ids).localStores??(r.localStores=new Map),o=s.get(this.idPath)??[];let i=o.find(e=>e.type===n.type&&Object.is(e.key,n.key));i||(i={...n,slots:[]},o.push(i),s.set(this.idPath,o));const a=this.localStoreIndex++;let c=i.slots[a];c||(c={value:e(),claims:0,release:e=>t(e)},i.slots[a]=c),c.claims++;const u=c,l=i;return this.addCleanup(()=>{if(!(--u.claims>0)){l.slots[a]=void 0;try{u.release(u.value)}finally{if(l.slots.every(e=>!e)){const e=o.indexOf(l);e>=0&&o.splice(e,1),0===o.length&&s.delete(this.idPath)}}}}),c.value}reserveIdSegment(e){return`${e}${(this.nextIdChild++).toString(36)}`}keyedIdSegment(e,t){return"object"==typeof t?`${e}/a${t.slot.toString(36)}`:`${e}/k${((e,t)=>{if("string"==typeof e)return`s${e.length}:${e}`;if("number"==typeof e)return Object.is(e,-0)?"n:-0":`n:${String(e)}`;const r=Symbol.keyFor(e);if(void 0!==r)return`g${r.length}:${r}`;const n=t.symbolIds??(t.symbolIds=new Map);let s=n.get(e);return void 0===s&&(s=t.nextSymbolId++,n.set(e,s)),`y:${s.toString(36)}`})(t,this.ids)}`}id(){var e;const t=`v2\0${this.ids.prefix}\0${this.idPath}`,r=(e=>{let t=3735928559,r=1103547991;for(let n=0;n<e.length;n++){const s=e.charCodeAt(n);t=Math.imul(t^s,2654435761),r=Math.imul(r^s,1597334677)}t=Math.imul(t^t>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507)^Math.imul(t^t>>>13,3266489909);let n=4294967296*(2097151&r)+(t>>>0),s="";for(let e=0;e<7;e++)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[n%62]+s,n=Math.floor(n/62);return s})(t),n=(e=this.ids).claims??(e.claims=new Map),s=n.get(r);if(void 0!==s&&s.identity!==t)throw i("ID_HASH_COLLISION","Component id hash collision.");const o=s??{identity:t,owners:this};return s?s.owners instanceof Set?s.owners.add(this):s.owners!==this&&(s.owners=new Set([s.owners,this])):n.set(r,o),this.addCleanup(()=>{n.get(r)===o&&(o.owners instanceof Set?(o.owners.delete(this),0===o.owners.size?n.delete(r):1===o.owners.size&&(o.owners=o.owners.values().next().value)):o.owners===this&&n.delete(r))}),`nxs-${r}`}addCleanup(e){if(this.disposed)return void V(e);const t=this.cleanups;t?Array.isArray(t)?t.push(e):this.cleanups=[t,e]:this.cleanups=e}addMount(e){if(this.disposed)return;if(this.mounts===P)return void e();const t=this.mounts;t?Array.isArray(t)?t.push(e):this.mounts=[t,e]:this.mounts=e}isMounted(){return this.mounts===P}mount(){if(this.disposed||this.mounts===P)return;const e=this.mounts;if(this.mounts=P,Array.isArray(e))for(const t of e)t();else e?.();if(this.children)for(const e of this.children)e.mount()}setErrorHandler(e){this.errorHandler=e}handleError(e){if(this.errorHandler)try{return this.errorHandler(e),!0}catch(e){if(this.parent)return this.parent.handleError(e);throw e}return this.parent?.handleError(e)??!1}dispose(){if(this.disposed)return;this.disposed=!0,this.mounts=void 0;const e=this.cleanups;if(!this.children?.size&&!Array.isArray(e))return this.children=void 0,this.cleanups=void 0,this.parent?.children?.delete(this),void(e&&V(e));r(t=>{if(this.children){for(const e of Array.from(this.children))t(()=>e.dispose());this.children.clear(),this.children=void 0}if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--){const n=e[r];"function"==typeof n?t(n):n&&t(()=>n.dispose())}e.length=0}else"function"==typeof e?t(e):e&&t(()=>e.dispose());this.cleanups=void 0,this.parent?.children?.delete(this)})}},exports.TEXT_END=Q,exports.TEXT_START=Z,exports.checkedDOMValue=function(e,t,r){const n=t.toLowerCase();if(C.has(n)||n.startsWith("on"))throw i("UNSAFE_DOM_PROPERTY",`Cannot use "${t}" as a DOM property. Use JSX children or a function event handler.`);if("boolean"==typeof r&&n.startsWith("aria-"))return String(r);if(null==r||!1===r||!0===r||!M.has(n)&&("data"!==n||"object"!==e.toLowerCase()))return r;const s=String(r);let o;try{o=new URL(s,"https://nexus.invalid/").protocol}catch{}if(!o||!j.has(o))throw i("UNSAFE_DOM_URL",`"${t}" requires a relative URL or an http, https, mailto or tel URL.`);return s},exports.component=function(e,t=[]){const r=Array.isArray(t),n=r?void 0:ae(new Map,t);return s=>({kind:"store-view",dependencies:r?t:[],...n?{registry:n}:{},input:s,render:e,getId:Y()})},exports.componentScope=function(e){const t=ae(new Map,e);return(e,r)=>{const n=r?ae(new Map(t),r):t;return t=>({kind:"store-view",dependencies:[],registry:n,render:e,input:t,getId:Y()})}},exports.createActs=function(e){return e},exports.createMutableLiveItem=function(e,t){const r=new T(e);return{live:new Proxy(r,N),controller:r,row:new $(t)}},exports.createStoreViewRegistry=function(t={}){const n=new Map,o=[],a=new WeakMap,u=new Set,l=[];let d,f=0,h=!1;const p=e=>Object.keys(e).sort(),y=(e,t)=>e.length===t.length&&e.every((e,r)=>e===t[r]),m=a=>{const c=n.get(a);if(c)return c;if(u.has(a))throw i("STORE_DEPENDENCY_CYCLE","Store dependencies contain a cycle. Move shared state into a third store or remove one dependency.");u.add(a);const m=a[se];let g=!1;try{const c=w(a.dependencies),u={get:e=>{const t=c.source.get();return void 0===e?t:t[e]},$:c.$,select:c.select,acts:c.acts,refs:c.refs},v=(b=m.refs??{},Object.fromEntries(Object.entries(b).map(([e,t])=>[e,{current:t}]))),x=p(m.state),S=d?.[f];let A=m.state;if(d){if(!S||!S.state||"object"!=typeof S.state||Array.isArray(S.state)||!y(x,[...S.keys].sort())||!y(x,p(S.state)))throw i("HYDRATION_STATE_INVALID",`Hydration snapshot ${f} does not match store keys ${JSON.stringify(x)}.`);A=S.state,f++,g=!0}const E="function"==typeof m.acts?[m.acts]:m.acts,O=E&&E.length>1?new Map:void 0;let I,T;T=E?e.createNexus({state:A,acts:E.map((e,t)=>function(r,n){I??(I=function(e,t){const r=new Map;return{list(n){const s=r.get(n);if(s)return s;let o;const a=()=>{const t=o?.items??e(n);if(!Array.isArray(t))throw i("INVALID_LIST_FIELD",`The state field "${String(n)}" must be an array to use list().`);return t},c=(e,t,r)=>{if(o)return o.items=t,void o.operations.push(r);u(e,t,r)},u=(e,r,s)=>{K.set(s,{before:X(e),after:X(r)}),t({[n]:r},(e=>({source:`list.${e.type}`,meta:{nexusDOM:{list:e}}}))(s))},l={append(...e){if(0===e.length)return;const t=a();c(t,[...t,...e],B({key:n,type:"insert",index:t.length,count:e.length},[...e]))},insert(e,...t){if(0===t.length)return;const r=a();G(e,r.length,!0),c(r,[...r.slice(0,e),...t,...r.slice(e)],B({key:n,type:"insert",index:e,count:t.length},[...t]))},remove(e,t=1){const r=a();if(G(e,r.length),!Number.isInteger(t)||t<1||e+t>r.length)throw i("INVALID_LIST_REMOVE_COUNT",`Cannot remove ${t} item(s) from index ${e} in a list of ${r.length}.`);c(r,[...r.slice(0,e),...r.slice(e+t)],B({key:n,type:"remove",index:e,count:t}))},move(e,t){const r=a();if(G(e,r.length),G(t,r.length),e===t)return;const s=[...r],[o]=s.splice(e,1);s.splice(t,0,o),c(r,s,B({key:n,type:"move",from:e,to:t}))},replace(e,t){const r=a();G(e,r.length);const s=[...r];s[e]=t,c(r,s,B({key:n,type:"replace",index:e},t))},reverse(){const e=a();e.length<2||c(e,[...e].reverse(),B({key:n,type:"reorder"}))},batch(e){if(o)return void e(l,a);const t=a(),r={items:[...t],operations:[]};o=r;try{e(l,a)}finally{o=void 0}if(0===r.operations.length)return;if(a()!==t)throw i("LIST_BATCH_CONFLICT",`The "${String(n)}" array changed during list.batch(). Update it using the batch commands, or call set() outside the batch.`);const s=B({key:n,type:"batch",operations:r.operations});u(t,r.items,s)}};return r.set(n,l),l}}}(r,n));const s=e.call(this,{get:r,set:n,reset:(...e)=>T.reset(...e),refs:v,list:I.list,dependencies:u});if(O&&s)for(const e of Object.keys(s)){const r=O.get(e);if(void 0!==r)throw i("DUPLICATE_ACTION",`Action "${e}" appears in slices ${r+1} and ${t+1}. Give each action in store({ acts }) a unique name.`);O.set(e,t)}return s})}):e.createNexus({state:A});const N={nexus:T,refs:v};let $;if(n.set(a,N),o.push(N),a[ie]&&(a[oe]=()=>{if(delete a[oe],!n.delete(a))return;const e=o.indexOf(N);e>=0&&o.splice(e,1),$?.()}),!1!==t.runSetup&&(m.setup||m.mount)){const e=new Set,t=t=>(e.add(t),()=>e.delete(t));$=()=>{r(t=>{for(const r of Array.from(e).reverse())t(r);e.clear()})};const i=()=>({nexus:T,$:ce(T,()=>N),select:(e,t)=>k(T,e,t),acts:T.acts,refs:v,dependencies:u,onCleanup:t});try{const t=m.setup?.(i());t&&e.add(t),a[ie]||l.push($)}catch(e){n.delete(a),o.at(-1)===N&&o.pop(),delete a[oe],s(e,$)}let d=m.mount;(d||c.mount)&&(N.mount=()=>{if(h)return;if(c.mount?.(),h)return;const t=d;if(d=void 0,!t)return;const n=new Set,o=()=>{r(e=>{for(const t of Array.from(n).reverse())e(t);n.clear()})};try{const e=t({...i(),onCleanup:e=>(n.add(e),()=>n.delete(e))});e&&n.add(e)}catch(e){s(e,o)}h?o():e.add(o)})}else c.mount&&(N.mount=c.mount);return N}catch(e){throw g&&f--,e}finally{u.delete(a)}var b},g=(e,t,r)=>{for(const[n,s]of Object.entries(t)){if(Object.prototype.hasOwnProperty.call(e,n))throw i("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same ${r} key "${n}".`);e[n]=s}},w=e=>{const t=a.get(e);if(t)return t;const r=e.map(e=>m(e)),n={},s={},o=new Map,c=new Map;for(const e of r){const t=e.nexus.get();o.set(e,new Set(Object.keys(t)));for(const r of Object.keys(t)){if(c.has(r))throw i("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same state key "${r}".`);c.set(r,e)}g(n,e.nexus.acts,"acts"),g(s,e.refs,"refs")}const u={get(){const e={};for(const t of r)g(e,t.nexus.get(),"state");return e},subscribe(e,t){const n=r.flatMap(r=>{const n=o.get(r),s="*"===t[0]?["*"]:t.filter(e=>n.has(String(e)));return 0===s.length?[]:[r.nexus.subscribe((t,r)=>e(u.get(),r),s)]});return()=>n.forEach(e=>e())}};u.get();const l=r.flatMap(e=>e.mount?[e.mount]:[]),d={source:u,readField:e=>"string"==typeof e?c.get(e)?.nexus.get(e):void 0,$:ce(u,e=>c.get(e)),select:(e,t)=>k(u,e,t),acts:n,refs:s};return l.length&&(d.mount=()=>l.forEach(e=>e())),a.set(e,d),d};return{restore(e){if(n.size>0)throw i("HYDRATION_STATE_LATE","Hydration state must be restored before the first lazy store is resolved.");d=e,f=0},completeRestore(){if(d&&f!==d.length)throw i("HYDRATION_STATE_INVALID",`Hydration provided ${d.length} store snapshots, but the view resolved ${f}.`);d=void 0},snapshots:()=>o.map(({nexus:e})=>{const t=e.get();return{keys:p(t),state:t}}),resolve(e){if(e.registry)return((e,t)=>{const r=new Map;let n=!1;const s=e=>{let s=r.get(e);if(s)return s;if(h)throw i("APP_DISPOSED","Cannot resolve a store after app disposal.");return s=w(t.get(e)),r.set(e,s),n&&s.mount?.(),s},o=(e,r=Object.create(null))=>new Proxy(r,{get:(r,n)=>"string"==typeof n&&t.has(n)?e(n):Reflect.get(r,n),has:(e,r)=>"string"==typeof r&&t.has(r)||Reflect.has(e,r),ownKeys:e=>[...t.keys(),...Reflect.ownKeys(e)],getOwnPropertyDescriptor:(r,n)=>"string"==typeof n&&t.has(n)?{enumerable:!0,configurable:!0,get:()=>e(n)}:Reflect.getOwnPropertyDescriptor(r,n)}),a=(e=e=>s(e).source.get(),t)=>{let r;return o(n=>{if(t&&!t())return s(n).source.get();let o=r?.get(n);return o||(o=e(n),(r??(r=new Map)).set(n,o)),o})},c={get:()=>a(),subscribe(e,t){const r=t.map(t=>s(t).source.subscribe((t,r)=>e(a(),r),["*"]));return()=>r.forEach(e=>e())}},u={get:c.get,subscribe(e,t){const r=new Map;for(const e of t){const[t,n]=JSON.parse(e);let s=r.get(t);s||r.set(t,s=[]),s.push(n??"*")}const n=Array.from(r,([t,r])=>s(t).source.subscribe((t,r)=>e(a(),r),r));return()=>n.forEach(e=>e())}},l=o(e=>s(e).$),d=(e,t)=>k(u,e,t,()=>(e=>{const t=new Map,r=e(a(e=>{const r=new Set;t.set(e,r);const n=n=>{"string"==typeof n?r.add(n):t.set(e,null)};return new Proxy(s(e).source.get(),{get:(e,t,r)=>(n(t),Reflect.get(e,t,r)),has:(e,t)=>(n(t),Reflect.has(e,t)),getOwnPropertyDescriptor:(e,t)=>(n(t),Reflect.getOwnPropertyDescriptor(e,t)),ownKeys:r=>(t.set(e,null),Reflect.ownKeys(r))})})),n=[];for(const[e,r]of t)if(r?.size)for(const t of r)n.push(JSON.stringify([e,t]));else n.push(JSON.stringify([e,null]));return{value:r,dependencies:n}})(e)),f=o(e=>s(e).acts),p=o(e=>s(e).refs),y=t=>e.render({get id(){return e.getId()},state:t,$:l,select:d,acts:f,refs:p},e.input);return{kind:"tracked-view",source:c,project:y,track:()=>(e=>{let t=new Set;try{return{value:e(a(e=>(t?.add(e),s(e).source.get()),()=>void 0!==t)),dependencies:[...t]}}finally{t=void 0}})(y),mountStores(){n=!0;for(const e of r.values())e.mount?.()}}})(e,e.registry);const t=w(e.dependencies),r=r=>e.render({get id(){return e.getId()},state:r,$:t.$,select:t.select,acts:t.acts,refs:t.refs},e.input);return{kind:"tracked-view",source:t.source,...t.mount?{mountStores:t.mount}:{},project:r,track:()=>c(t.source.get(),r,t.readField)}},dispose(){h||(h=!0,r(e=>{for(let t=l.length-1;t>=0;t--)e(l[t]);l.length=0,n.clear(),o.length=0}))}}},exports.defaultSelectedOptions=R,exports.disposeAfterFailure=n,exports.disposeNodes=function(e,t){try{e?.dispose()}finally{for(const e of t)e.parentNode?.removeChild(e)}},exports.getRowField=function(e){return e instanceof S?e:void 0},exports.hasEditedValue=function(e,t){if("checked"===t&&"input"===e.localName){const t=e;return t.checked!==t.defaultChecked}if("value"!==t)return!1;if("input"===e.localName||"textarea"===e.localName){const t=e;return t.value!==t.defaultValue}if("select"===e.localName){const t=e,r=R(t),n=t.selectedOptions;return n.length!==r.length||r.some((e,t)=>e!==n[t])}return!1},exports.hasListOperationPayload=function(e){return z.has(e)},exports.hasTextareaValue=function(e,t){return"textarea"===e&&("value"in t||"defaultValue"in t)},exports.hydrationText=e=>`\x3c!--${Z}--\x3e${e}\x3c!--${Q}--\x3e`,exports.inferredRowKey=U,exports.isEventProperty=e=>/^on[A-Z]/.test(e),exports.isLiveValue=function(e){return"object"==typeof e&&null!==e&&!0===e[t.LIVE_VALUE]},exports.nexusDOMError=i,exports.onCleanup=function(e){if(!H)throw i("CLEANUP_OUTSIDE_COMPONENT","onCleanup() must run inside a component.");H.addCleanup(e)},exports.readListOperation=function(e,t,r,n){if(void 0===t||!e||"object"!=typeof e)return;const s=e.meta;if(!s||"object"!=typeof s)return;const o=s.nexusDOM;if(!o||"object"!=typeof o)return;const i=o.list;if(!i||"object"!=typeof i)return;const a=i,c=K.get(a);return c&&a.key===t&&c.before===W.get(r)&&c.after===W.get(n)?a:void 0},exports.readListOperationPayload=function(e){return z.get(e)},exports.resolveRowKeys=function(e,t){const r=e.map(U),n=new Set,s=new Set;for(const e of r)void 0!==e&&(n.has(e)&&s.add(e),n.add(e));return r.map((r,n)=>void 0===r||s.has(r)?t(e[n]):r)},exports.runDisposal=r,exports.sameDependencies=u,exports.sameListSource=function(e,t){if(e===t)return!0;const r=y.get(e);return void 0!==r&&r===y.get(t)},exports.selectionValues=function(e,t){return new Set(t&&Array.isArray(e)?e.map(String):[String(e??"")])},exports.serializeHydrationState=(e,t)=>{let r;e.forEach((e,t)=>te(e.state,`stores[${t}].state`,new Set));try{r=JSON.stringify({v:1,idPrefix:t,stores:e})}catch(e){throw i("HYDRATION_STATE_INVALID",`Hydration state could not be serialized: ${String(e)}`)}ne(r);const n=r.replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`).replaceAll("--","-\\u002d");return`\x3c!--${ee}${n}--\x3e`},exports.store=function(e,t=[]){return r=r=>({[se]:e,dependencies:t,[ie]:r}),n=e=>e[oe]?.(),H?.hasComponentIdentity()?H.acquireLocalStore(()=>r(!0),n):r(!1);var r,n},exports.subscribeForRender=g,exports.supportsRenderErrors=function(e){return m in e},exports.takeHydrationState=(e,t)=>{const r=Array.from(e.childNodes).filter(e=>8===e.nodeType&&(e.nodeValue??"").startsWith(ee));if(0===r.length)return;if(1!==r.length)throw i("HYDRATION_STATE_INVALID","Hydration root must contain at most one nxs:s payload.");const n=r[0],s=ne((n.nodeValue??"").slice(5));if(void 0!==t&&void 0!==s.idPrefix&&t!==s.idPrefix)throw i("HYDRATION_STATE_INVALID","The client idPrefix does not match the server's. Omit it to use the server prefix.");return n.parentNode?.removeChild(n),s},exports.throwAfterDisposal=s,exports.trackSelector=c,exports.withOwner=function(e,t){const r=H;H=e;try{return t()}finally{H=r}};
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nexus-state"),t=require("./chunks/store-view-C2XX94et.js");function r(e){return Array.isArray(e)?e[0]:e}function n(e){try{e.owner.dispose()}finally{!function(e){if(Array.isArray(e))for(const t of e)t.parentNode?.removeChild(t);else e.parentNode?.removeChild(e)}(e.nodes)}}function o(e,t){if(function(e){return Array.isArray(e)?e.at(-1):e}(e.nodes).nextSibling===t)return;const r=t.parentNode;if(!r)return;const n=Array.isArray(e.nodes)?e.nodes:[e.nodes];for(const e of n)r.moveBefore?r.moveBefore(e,t):r.insertBefore(e,t)}function s(e){const t=[],r=new Array(e.length).fill(-1);for(let n=0;n<e.length;n++){const o=e[n];if(void 0===o||o<0)continue;let s=0,i=t.length;for(;s<i;){const r=s+i>>1,n=t[r];(void 0===n?-1:e[n]??-1)<o?s=r+1:i=r}s>0&&(r[n]=t[s-1]??-1),t[s]=n}const n=new Set;let o=t.at(-1)??-1;for(;o>=0;)n.add(o),o=r[o]??-1;return n}function i(e,t){return!!t&&(Array.isArray(e.nodes)?e.nodes:[e.nodes]).some(e=>e===t||e.nodeType===Node.ELEMENT_NODE&&e.contains(t))}function c({target:e,owner:c,vnode:d,scheduler:l,renderInto:a,reconcileView:u,register:f,preparePatch:p,hydration:h}){const y=e.ownerDocument??e,v=f?y.createTextNode(""):void 0,g=y.createTextNode("");v&&e.insertBefore(v,h?h.node:null),h||e.appendChild(g);const m={},w=new Map;let x,b,k,N=[],S=!0,A=d.source,E=A,O=A.get(),D=O,T=O,C=!1,I=!1,M=d.project,j=M,V=h?void 0:y.createDocumentFragment(),L=h?.node,R=void 0!==h;const P=c.reserveIdSegment("l");let _=0;const B=()=>({slot:_++}),F=(r,o)=>{const s=new t.Owner(c,!1,c.keyedIdSegment(P,r)),i=t.createMutableLiveItem(o,s),d=f?{key:r,owner:s,nodes:g,controller:i.controller,live:i.live,row:i.row,view:void 0}:{key:r,owner:s,nodes:g,controller:i.controller};try{const t=M(i.live,i.row);if(f&&(p(s),d.view=t),R){const r=L?L.previousSibling:e.lastChild;L=h.hydrateInto(t,e,d.owner,L??null);const n=[];let o=r?r.nextSibling:e.firstChild;for(;o&&o!==L;)n.push(o),o=o.nextSibling;if(0===n.length){const t=y.createTextNode("");e.insertBefore(t,L??null),n.push(t)}d.nodes=1===n.length?n[0]:n}else if(V)d.nodes=((e,t)=>{const r=V,n=r.lastChild;a(e,r,t),r.lastChild===n&&r.appendChild(y.createTextNode(""));const o=n?n.nextSibling:r.firstChild;if(!o.nextSibling)return o;const s=[];let i=o;for(;i;)s.push(i),i=i.nextSibling;return s})(t,d.owner);else{const e=function(e,t,r,n){const o=e.createDocumentFragment();return n(t,o,r),0===o.childNodes.length&&o.appendChild(e.createTextNode("")),{fragment:o,nodes:1===o.childNodes.length?o.firstChild:Array.from(o.childNodes)}}(y,t,d.owner,a);d.nodes=e.nodes,g.parentNode?.insertBefore(e.fragment,g),c.isMounted()&&d.owner.mount()}}catch(e){t.throwAfterDisposal(e,()=>{R||d.nodes===g?d.owner.dispose():n(d)})}return d};c.addMount(()=>{for(const e of N)e.owner.mount()});const $=(e,t)=>{let n=-1;if(e.every(e=>{const r=t.get(e.key);return!(void 0===r||r<=n||(n=r,0))}))return void(N=e);const c=e.map(e=>t.get(e.key)??-1),d=g.parentNode,l=y.activeElement,a=d?.moveBefore?-1:e.findIndex(e=>i(e,l)),u=function(e,t){const r=void 0===t?void 0:e[t];if(void 0===t||void 0===r||r<0)return s(e);const n=e.map((e,n)=>n<t&&e<r?e:-1),o=e.map((e,n)=>n>t&&e>r?e:-1);return new Set([...s(n),t,...s(o)])}(c,a<0?void 0:a);for(let t=e.length-1;t>=0;t--){const n=e[t],s=e[t+1];-1!==c[t]&&u.has(t)||o(n,s?r(s.nodes):g)}N=e},q=(r,o,s)=>{if(!V&&!R&&r.length===N.length&&N.every((e,n)=>t.inferredRowKey(r[n])===e.key))return void N.forEach((e,t)=>{Object.is(e.controller.get(),r[t])||e.controller.set(r[t],s)});const i=[];let c,d;for(const e of N){if("object"!=typeof e.key)continue;const t=e.controller.get();c??(c=new Map),c.set(t,c.has(t)?null:e)}if(c){d=new Map;for(const e of r)d.set(e,(d.get(e)??0)+1)}const l=t.resolveRowKeys(r,e=>{const t=c?.get(e);return t&&1===d?.get(e)&&Object.is(t.controller.get(),e)?t.key:B()}),a=new Set(l),u=new Map(N.map((e,t)=>[e.key,t]));l.forEach((e,t)=>{const n=r[t];let o=w.get(e);o?Object.is(o.controller.get(),n)||o.controller.set(n,s):(o=F(e,n),w.set(e,o)),i.push(o)});for(const[e,t]of w)a.has(e)||(w.delete(e),o(()=>n(t)));return V?(g.parentNode?.insertBefore(V,g),V=void 0,void(N=i)):R?(e.insertBefore(g,L??null),R=!1,void(N=i)):void $(i,u)},H=(e,s,c,d,l=!0)=>{if("batch"===e.type){for(const t of e.operations)if(!H(t,s,c,d,!1))return!1;return!l||N.length===s.length}if("insert"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.index>N.length||e.count<1)return!1;if(l&&s.length!==N.length+e.count)return!1;const n=t.readListOperationPayload(e);if(!Array.isArray(n)||n.length!==e.count)return!1;const i=n.map(e=>({item:e,key:t.inferredRowKey(e)??B()})),c=new Set;for(const{key:e}of i){if(w.has(e)||c.has(e))return!1;c.add(e)}const d=[];for(const{item:e,key:t}of i){const r=F(t,e);w.set(t,r),d.push(r)}N.splice(e.index,0,...d);let a=N[e.index+d.length]?r(N[e.index+d.length].nodes):g;for(let e=d.length-1;e>=0;e--){const t=d[e];t&&(o(t,a),a=r(t.nodes))}return!0}if("remove"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.count<1||e.index+e.count>N.length)return!1;if(l&&s.length!==N.length-e.count)return!1;const t=N.splice(e.index,e.count);if(t.length!==e.count)return!1;for(const e of t)w.delete(e.key),c(()=>n(e));return!0}if("move"===e.type){if(!Number.isInteger(e.from)||!Number.isInteger(e.to)||e.from<0||e.from>=N.length||e.to<0||e.to>=N.length)return!1;if(l&&s.length!==N.length)return!1;const n=N[e.from];if(!n)return!1;if(l){const r=s[e.to];if(!("object"==typeof n.key?Object.is(r,n.controller.get()):t.inferredRowKey(r)===n.key))return!1}const c=g.parentNode,d=y.activeElement;if(!c?.moveBefore&&i(n,d)){if(e.from>e.to){let t=N[e.from+1]?r(N[e.from+1].nodes):g;for(let n=e.from-1;n>=e.to;n--){const e=N[n];e&&(o(e,t),t=r(e.nodes))}}else{const t=r(n.nodes);for(let r=e.from+1;r<=e.to;r++){const e=N[r];e&&o(e,t)}}return N.splice(e.from,1),N.splice(e.to,0,n),!0}return N.splice(e.from,1),N.splice(e.to,0,n),o(n,N[e.to+1]?r(N[e.to+1].nodes):g),!0}if("replace"===e.type){if(!Number.isInteger(e.index)||e.index<0||e.index>=N.length)return!1;if(l&&s.length!==N.length)return!1;const i=N[e.index],a=t.readListOperationPayload(e);if(!i||!t.hasListOperationPayload(e))return!1;const u=t.inferredRowKey(a)??("object"==typeof i.key?i.key:B());if(u===i.key)return i.controller.set(a,d),!0;if(w.has(u))return!1;const f=F(u,a);return w.delete(i.key),c(()=>n(i)),w.set(u,f),N[e.index]=f,o(f,N[e.index+1]?r(N[e.index+1].nodes):g),!0}if("reorder"===e.type){if(l&&s.length!==N.length)return!1;const e=new Map(N.map((e,t)=>[e.key,t]));return $([...N].reverse(),e),!0}return!1};try{t.runDisposal(e=>q(O,e))}catch(e){t.throwAfterDisposal(e,W)}function W(){t.runDisposal(e=>{for(const t of w.values())e(()=>n(t));w.clear(),N=[],v&&v.parentNode?.removeChild(v),g.parentNode?.removeChild(g)})}function K(){I=!0,l.enqueue(m,U,b,e=>c.handleError(e))}function U(){if(I=!1,!S)return;if(E!==A){const e=E,t=e.get(),r=J(e);X(),A=e,X=r,k=void 0,O=t,x=void 0,C=t!==D&&(!D||D.length!==t.length||t.some((e,t)=>!Object.is(e,D[t]))),C||(D=t)}if(k)throw k.error;const e=b;b=void 0;const s=j===M?void 0:new Set(N);M=j;const i=T===D?x:void 0,c=O,d=C;C=!1,x=void 0,t.runDisposal(t=>{if(d&&(D=void 0,(Array.isArray(i)?i.every((r,n)=>H(r,c,t,e,n===i.length-1)):i&&H(i,c,t,e))||q(c,t,e),D=c),s)for(let e=0;e<N.length;e++){const i=N[e];if(!s.has(i))continue;const c=M(i.live,i.row),d=Array.isArray(i.nodes)?i.nodes:[i.nodes];if(u(i.view,c,d,i.owner)){i.view=c;continue}const l=F(i.key,i.controller.get());o(l,r(i.nodes)),w.set(i.key,l),N[e]=l,t(()=>n(i))}})}v&&f?.({start:v,end:g,update(e){j===e.project&&E===e.source||(j=e.project,E=e.source,I||K())}});let X=()=>{};function J(e){return t.subscribeForRender(e,(e,r)=>{k=void 0;const n=O;O=e;const o=t.readListOperation(r,d.stateKey,n,e);C?x&&o?Array.isArray(x)?x.push(o):x=[x,o]:x=void 0:(T=n,x=o),C=!0,b=r,K()},(e,t)=>{k={error:e},b=t,x=void 0,C=!0,K()})}return c.addCleanup(()=>{S=!1,l.cancel(m),X(),W()}),X=J(A),L}require("./chunks/types-BLzRvYOk.js");const d=e=>e.slice(2).toLowerCase(),l=e=>null==e||!1===e?"":String(e);function a(e,r,n,o){const s=t.checkedDOMValue(e.localName,r,n);if("select"===e.localName&&("value"===r||"defaultValue"===r)){const n=e;if("value"===r&&!n.multiple){const e=String(s??"");return void(n.value!==e&&(n.value=e))}const o=t.selectionValues(s,n.multiple),i=Array.from(n.options);if("value"===r){for(const e of i)e.selected=o.has(e.value);return}const c=t.hasEditedValue(n,"value")?new Set(n.selectedOptions):void 0;for(const e of i){const t=o.has(e.value);e.defaultSelected=t,t&&!n.multiple&&o.delete(e.value)}if(n.multiple)for(const e of i)e.selected=c?c.has(e):e.defaultSelected;else{const e=c?i.find(e=>c.has(e)):t.defaultSelectedOptions(n)[0];n.selectedIndex=e?.index??-1}return}"className"!==r&&"class"!==r?"style"===r&&(e instanceof HTMLElement||e instanceof SVGElement)?function(e,t,r){if("string"!=typeof t)if(t&&"object"==typeof t){if(r&&"object"==typeof r)for(const n of Object.keys(r))n in t||(e.style.removeProperty(n),e.style[n]="");for(const[r,n]of Object.entries(t))r.startsWith("--")?e.style.setProperty(r,String(n)):e.style[r]=n}else e.removeAttribute("style");else e.style.cssText=t}(e,s,o):"htmlFor"!==r?r.startsWith("aria-")||r.startsWith("data-")||"http://www.w3.org/2000/svg"===e.namespaceURI||!(r in e)?null==s||!1===s?e.removeAttribute(r):!0===s?e.setAttribute(r,""):e.setAttribute(r,String(s)):e[r]=s??"":null==s||!1===s?e.removeAttribute("for"):e.setAttribute("for",String(s)):null==s||!1===s?e.removeAttribute("class"):e.setAttribute("class",String(s))}function u({target:e,owner:r,vnode:n,scheduler:o,renderInto:s,preparePatch:i,reconcile:c,hydration:d}){const l=e.ownerDocument??e,a=l.createTextNode("");d||e.appendChild(a);const u={};let f,p,h,y=!0,v=[],g=()=>{};const m=r.reserveIdSegment("t"),w=()=>{const e=f,r=v;f=void 0,v=[],t.disposeNodes(e,r)};function x(e,t){o.enqueue(u,k,t,e=>r.handleError(e))}const b=e=>{if(h&&t.sameDependencies(h,e))return;const r=g;h=e,g=n.source.subscribe(x,e),r()};function k(){if(!y)return;const e=n.track?.()??t.trackSelector(n.source.get(),n.project);if(f&&c(p,e.value,v,f))return p=e.value,void b(e.dependencies);const o=new t.Owner(r,!0,m);e.dependencies.length>0&&i(o);const d=l.createDocumentFragment();try{s(e.value,d,o),b(e.dependencies)}catch(e){t.throwAfterDisposal(e,()=>o.dispose())}const u=Array.from(d.childNodes);t.runDisposal(t=>{t(w),f=o,v=u,p=e.value,a.parentNode?.insertBefore(d,a),r.isMounted()&&o.mount()})}let N;if(d){const o=n.track?.()??t.trackSelector(n.source.get(),n.project),s=new t.Owner(r,!0,m);o.dependencies.length>0&&i(s);const c=d.node?d.node.previousSibling:e.lastChild;try{N=d.hydrateInto(o.value,e,s,d.node),b(o.dependencies)}catch(e){t.throwAfterDisposal(e,()=>s.dispose())}e.insertBefore(a,N);const l=[];let u=c?c.nextSibling:e.firstChild;for(;u&&u!==a;)l.push(u),u=u.nextSibling;f=s,v=l,p=o.value}else k();return r.addCleanup(()=>{y=!1,o.cancel(u),g();try{w()}finally{a.parentNode?.removeChild(a)}}),n.mountStores&&f?.addMount(n.mountStores),N}const f="http://www.w3.org/2000/svg";let p=0;const h=["defaultValue","value"],y=(e,t)=>"select"===e&&("value"===t||"defaultValue"===t);class v{constructor(e,t,r){this.field=e,this.owner=t,this.scheduler=r,this.active=!0}connect(e=!1){const t=this.field.get();e||this.write(t),this.field.addListener(this),this.owner.addCleanup(this)}notify(e,t){this.scheduler.enqueue(this,()=>{this.active&&this.write(e)},t,e=>this.owner.handleError(e))}dispose(){this.active=!1,this.scheduler.cancel(this),this.field.removeListener(this)}}class g extends v{constructor(e,t,r,n){super(e,r,n),this.node=t,this.connect()}write(e){this.node.data=l(e)}}class m extends v{constructor(e,t,r,n,o,s){super(e,n,o),this.element=t,this.property=r,this.connect(s)}write(e){const t=this.previousStyle;"style"===this.property&&(this.previousStyle=e),a(this.element,this.property,e,t)}}function w(e={},r){const n=function(e){const t=e.schedule??"microtask",r=new Map;let n=!1;const o=()=>{if(n=!1,0===r.size)return;let t=0;const o=[];let s;for(;r.size>0;){const n=Array.from(r.values());r.clear();for(const r of n)try{r.run(),t++,void 0!==r.context&&o.push(r.context)}catch(n){let i=n;try{if(r.handleError?.(n)){t++,void 0!==r.context&&o.push(r.context);continue}}catch(e){i=e}try{e.onError?e.onError(i):(s??(s=[])).push(i)}catch(e){(s??(s=[])).push(e)}}}if(t>0&&e.onCommit?.({updates:t,contexts:o}),1===s?.length)throw s[0];if(s)throw new AggregateError(s,"nexus-dom: Multiple errors during rendering.")};return{enqueue(e,s,i,c){r.set(e,{run:s,...void 0===i?{}:{context:i},...void 0===c?{}:{handleError:c}}),"manual"===t||n||(n=!0,"animationFrame"===t?requestAnimationFrame(o):queueMicrotask(o))},cancel(e){r.delete(e)},flush:o}}(e),o=new WeakMap,s=new WeakMap,i=new WeakMap,v=new WeakSet,w=e=>{v.add(e)},x=e=>i.set(e.start,e),b=(e,t)=>(r,o)=>{n.enqueue(e,()=>{throw r},o,e=>t.handleError(e))},k=(e,r,o,s=!1)=>{let i=!0,c=e.get(),d=c;s||o(c,void 0);const l=(e,t)=>{d=e,n.enqueue(l,()=>{if(!i)return;const e=c;c=d,o(c,e)},t,e=>r.handleError(e))},a=t.supportsRenderErrors(e)?t.subscribeForRender(e,l,b(l,r)):e.subscribe(l);r.addCleanup(()=>{i=!1,n.cancel(l),a()})},N=(e,r,o)=>{const s=t.getRowField(e);s?new g(s,r,o,n):k(e,o,e=>{r.data=l(e)})},S=(e,r,n,o,s)=>{const i=e.ownerDocument??e,c=new t.Owner(r),d=c.reserveIdSegment("b"),l=i.createTextNode("");s||e.appendChild(l);let a,u,f=!0,p=!1,h=[];const y=(e,r)=>{const n=new t.Owner(c,!0,d),o=i.createDocumentFragment();r&&n.setErrorHandler(g);try{B(e,o,n)}catch(e){t.throwAfterDisposal(e,()=>n.dispose())}const s=Array.from(o.childNodes);t.runDisposal(e=>{e(()=>t.disposeNodes(a,h)),a=n,h=s,l.parentNode?.insertBefore(o,l),c.isMounted()&&n.mount()})},v=()=>{if(f)try{y(n,!0)}catch(e){try{g(e)}catch(e){if(p&&c.parent?.handleError(e))return;throw e}}};function g(e){if(!f)return;const t="function"==typeof o?o(e,v):o;y(t,!1)}if(s){const r=(r,n)=>{const o=new t.Owner(c,!0,d);n&&o.setErrorHandler(g);const i=s.node?s.node.previousSibling:e.lastChild;try{u=s.hydrateInto(r,e,o,s.node)}catch(e){t.throwAfterDisposal(e,()=>o.dispose())}e.insertBefore(l,u);const f=[];let p=i?i.nextSibling:e.firstChild;for(;p&&p!==l;)f.push(p),p=p.nextSibling;a=o,h=f};try{r(n,!0)}catch(e){if(e instanceof t.NexusDOMError&&"HYDRATION_MISMATCH"===e.code)throw e;r("function"==typeof o?o(e,v):o,!1)}}else v();return p=!0,c.addCleanup(()=>{f=!1;const e=a,r=h;a=void 0,h=[];try{t.disposeNodes(e,r)}finally{l.parentNode?.removeChild(l)}}),u},A=(e,r,s,i)=>{if(t.isLiveValue(s)){let o=s.get();const c=e=>{"function"==typeof o&&o(e)},l=t.subscribeForRender(s,e=>{o=e,n.cancel(c)},b(c,i));return e.addEventListener(d(r),c),void i.addCleanup(()=>{l(),n.cancel(c),e.removeEventListener(d(r),c)})}const c=o.get(e)??new Map;o.set(e,c);const l={listener:"function"==typeof s?s:void 0};c.set(r,l),l.listener&&e.addEventListener(d(r),l.listener),i.addCleanup(()=>{l.listener&&e.removeEventListener(d(r),l.listener),c.get(r)===l&&c.delete(r)})},E=(e,t)=>{"function"==typeof e?e(t):e&&"object"==typeof e&&(e.current=t)},O=e=>"function"==typeof e||"object"==typeof e&&null!==e&&"current"in e,D=(e,t,r)=>{if(!O(t))return;const n={value:t,attached:!1};s.set(e,n),r.addMount(()=>{n.attached=!0,E(n.value,e)}),r.addCleanup(()=>{n.attached&&E(n.value,null),s.get(e)===n&&s.delete(e)})},T=(e,r)=>{if(null==e||!1===e||!0===e)return!0;if(Array.isArray(e))return e.every(e=>T(e,r));if(t.isLiveValue(e))return r.push(e),!0;if("object"!=typeof e)return r.push(e),!0;const n=e;return"fragment"===n.kind?T(n.props.children,r):("element"===n.kind||"keyed"===n.kind)&&(r.push(n),!0)},C=(e,r,n)=>{const o=[];let s=r;for(const r of e){if(!s||s===n)return;o.push(s);const e=i.get(s);if(e){if("object"!=typeof r||t.isLiveValue(r)||"keyed"!==r.kind)return;s=e.end.nextSibling}else s=s.nextSibling}if(s===n)return o},I=(e,r,n)=>{if(t.isLiveValue(e)||t.isLiveValue(r))return e===r;if("object"!=typeof e||"object"!=typeof r)return"object"!=typeof e&&"object"!=typeof r;if("keyed"===e.kind||"keyed"===r.kind)return"keyed"===e.kind&&"keyed"===r.kind&&t.sameListSource(e.source,r.source)&&i.has(n);if(e.type!==r.type||e.key!==r.key||!((e,r)=>{const n=new Set([...Object.keys(e),...Object.keys(r)]);for(const o of n){if("children"===o||"key"===o)continue;const n=e[o],s=r[o];if((t.isLiveValue(n)||t.isLiveValue(s))&&n!==s)return!1}return!0})(e.props,r.props))return!1;const o=t.hasTextareaValue(e.type,e.props);if(o!==t.hasTextareaValue(r.type,r.props))return!1;if(o)return!0;const s=[],c=[];if(!(n instanceof Element&&T(e.props.children,s)&&T(r.props.children,c)&&s.length===c.length))return!1;const d=C(s,n.firstChild,null);return!!d&&s.every((e,t)=>I(e,c[t],d[t]))},M=(e,t,r,n)=>{let s=o.get(e),i=s?.get(t);i?(i.listener&&e.removeEventListener(d(t),i.listener),i.listener="function"==typeof r?r:void 0,i.listener&&e.addEventListener(d(t),i.listener)):A(e,t,r,n)},j=(e,t,r)=>{const n=O(t)?t:void 0,o=s.get(e);o?o.value!==n&&(o.attached&&E(o.value,null),o.value=n,o.attached&&E(o.value,e)):n&&D(e,n,r)},V=(e,r,n,o)=>{if(t.isLiveValue(e)||t.isLiveValue(r))return;if("object"!=typeof e||"object"!=typeof r)return void(n.nodeType===Node.TEXT_NODE&&(n.nodeValue=l(r)));if("keyed"===e.kind||"keyed"===r.kind)return void("keyed"===r.kind&&i.get(n)?.update(r));if(!(n instanceof Element))return;const s=new Set([...Object.keys(e.props),...Object.keys(r.props)]);for(const i of s){if("children"===i||"key"===i||y(r.type,i))continue;const s=e.props[i],c=r.props[i];s!==c&&("ref"===i?j(n,c,o):t.isEventProperty(i)?M(n,i,c,o):t.isLiveValue(c)||a(n,i,c,s))}if(t.hasTextareaValue(r.type,r.props))return;const c=[],d=[];T(e.props.children,c),T(r.props.children,d);const u=C(c,n.firstChild,null);if(c.forEach((e,t)=>{V(e,d[t],u[t],o)}),"select"===r.type)for(const t of h)e.props[t]!==r.props[t]&&a(n,t,r.props[t],e.props[t])},L=(e,t,r,n)=>{const o=[],s=[];if(!T(e,o)||!T(t,s)||o.length!==s.length)return!1;const i=C(o,r[0]??null,r.at(-1)?.nextSibling??null);return!(!i||!o.every((e,t)=>I(e,s[t],i[t]))||(o.forEach((e,t)=>{V(e,s[t],i[t],n)}),0))},R=(e,r,o,s,i,c)=>{const d=e.ownerDocument??e,l=d.createTextNode("");c||e.appendChild(l);const a=r.reserveIdSegment("d");let u,f=!0,p=o.get(),h=i?.(p),y=[];const v={},g=()=>{const e=u,r=y;u=void 0,y=[],t.disposeNodes(e,r)},m=()=>{const e=new t.Owner(r,!0,a),n=d.createDocumentFragment();try{B(s(p),n,e)}catch(r){t.throwAfterDisposal(r,()=>e.dispose())}const o=Array.from(n.childNodes);t.runDisposal(t=>{t(g),u=e,y=o,l.parentNode?.insertBefore(n,l),r.isMounted()&&e.mount()})};let w;if(c){const n=new t.Owner(r,!0,a),o=c.node?c.node.previousSibling:e.lastChild;try{w=c.hydrateInto(s(p),e,n,c.node)}catch(e){t.throwAfterDisposal(e,()=>n.dispose())}e.insertBefore(l,w);const i=[];let d=o?o.nextSibling:e.firstChild;for(;d&&d!==l;)i.push(d),d=d.nextSibling;u=n,y=i}else m();const x=t.subscribeForRender(o,(e,t)=>{p=e,n.enqueue(v,()=>{if(f){if(i){const e=i(p);if(Object.is(h,e))return;h=e}m()}},t,e=>r.handleError(e))},b(v,r));return r.addCleanup(()=>{f=!1,n.cancel(v),x();try{g()}finally{l.parentNode?.removeChild(l)}}),w},P=(e,r,o,s,i=!1)=>{if("ref"===r)D(e,o,s);else if(t.isEventProperty(r))A(e,r,o,s);else if(t.isLiveValue(o)){const c=t.getRowField(o),d=i&&t.hasEditedValue(e,r);c?new m(c,e,r,s,n,d):k(o,s,(t,n)=>a(e,r,t,n),d)}else!i||"value"===r&&"select"===e.localName&&!t.hasEditedValue(e,r)?a(e,r,o,void 0):t.checkedDOMValue(e.localName,r,o)},_=(e,o,s)=>{if("store-view"===e.kind){if(!r)throw t.nexusDOMError("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be rendered through createApp().render().");return void _(r.resolve(e),o,s)}if("error-boundary"===e.kind)return void S(o,s,e.children,e.fallback);if("keyed"===e.kind)return void c({target:o,owner:s,vnode:e,scheduler:n,renderInto:B,reconcileView:L,preparePatch:w,...v.has(s)?{register:x}:{}});if("tracked-view"===e.kind)return void u({target:o,owner:s,vnode:e,scheduler:n,renderInto:B,preparePatch:w,reconcile:L});if("dynamic"===e.kind)return void R(o,s,e.source,e.project,e.key);if("fragment"===e.kind)return void B(e.props.children,o,s);if("component"===e.kind){const r=new t.Owner(s),n=t.withOwner(r,()=>e.type(e.props));return void B(n,o,r)}const i=function(e,t,r){const n=t instanceof Element?t:void 0;return"svg"===r||n?.namespaceURI===f&&"foreignObject"!==n.localName?e.createElementNS(f,r):e.createElement(r)}(o.ownerDocument??o,o,e.type);for(const[t,r]of Object.entries(e.props))"children"===t||"key"===t||y(e.type,t)||P(i,t,r,s);if(t.hasTextareaValue(e.type,e.props)||B(e.props.children,i,s),"select"===e.type)for(const t of h)t in e.props&&P(i,t,e.props[t],s);o.appendChild(i)},B=(e,r,n)=>{if(null==e||!1===e||!0===e)return;if(Array.isArray(e)){for(const t of e)B(t,r,n);return}const o=r.ownerDocument??r;if(t.isLiveValue(e)){const t=o.createTextNode("");return N(e,t,n),void r.appendChild(t)}"object"!=typeof e?r.appendChild(o.createTextNode(l(e))):_(e,r,n)},F=(e,r)=>{const n=r?1===r.nodeType?`<${r.localName}>`:3===r.nodeType?`text ${JSON.stringify(r.nodeValue)}`:8===r.nodeType?`comment ${JSON.stringify(r.nodeValue)}`:`node type ${r.nodeType}`:"the end of the container";throw t.nexusDOMError("HYDRATION_MISMATCH",`Expected ${e}, but found ${n}.`)},$=(e,o,s,i)=>{if(null==e||!1===e||!0===e)return i;if(Array.isArray(e)){let t=i;for(const r of e)t=$(r,o,s,t);return t}if(t.isLiveValue(e)){if(8!==i?.nodeType||i.nodeValue!==t.TEXT_START)return F(`the \x3c!--${t.TEXT_START}--\x3e marker`,i);const r=i;let n=r.nextSibling;if(8===n?.nodeType&&n.nodeValue===t.TEXT_END&&(n=(o.ownerDocument??o).createTextNode(""),o.insertBefore(n,r.nextSibling)),!n||3!==n.nodeType)return F("reactive text",n);const c=n.nextSibling;if(8!==c?.nodeType||c.nodeValue!==t.TEXT_END)return F(`the \x3c!--${t.TEXT_END}--\x3e marker`,c);const d=l(e.get());if(n.data!==d)return F(`reactive text ${JSON.stringify(d)}`,n);const a=c.nextSibling;return r.parentNode?.removeChild(r),c.parentNode?.removeChild(c),N(e,n,s),a}if("object"!=typeof e)return((e,t,r)=>{const n=t.ownerDocument??t;if(""===e)return t.insertBefore(n.createTextNode(""),r),r;r&&3===r.nodeType||F(`text ${JSON.stringify(e)}`,r);const o=r;return o.data===e?o.nextSibling:o.data.startsWith(e)?o.splitText(e.length):F(`text ${JSON.stringify(e)}`,r)})(l(e),o,i);const d=e;if("fragment"===d.kind)return $(d.props.children,o,s,i);if("component"===d.kind){const e=new t.Owner(s),r=t.withOwner(e,()=>d.type(d.props));return $(r,o,e,i)}if("store-view"===d.kind){if(!r)throw t.nexusDOMError("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be hydrated through createApp().hydrate().");return $(r.resolve(d),o,s,i)}if("tracked-view"===d.kind){const e=u({target:o,owner:s,vnode:d,scheduler:n,renderInto:B,preparePatch:w,reconcile:L,hydration:{node:i,hydrateInto:$}});return void 0===e?i:e}if("dynamic"===d.kind){const e=R(o,s,d.source,d.project,d.key,{node:i,hydrateInto:$});return void 0===e?i:e}if("keyed"===d.kind){const e=c({target:o,owner:s,vnode:d,scheduler:n,renderInto:B,reconcileView:L,preparePatch:w,...v.has(s)?{register:x}:{},hydration:{node:i,hydrateInto:$}});return void 0===e?i:e}if("error-boundary"===d.kind){const e=S(o,s,d.children,d.fallback,{node:i,hydrateInto:$});return void 0===e?i:e}if(!(i instanceof Element)||i.localName!==d.type)return F(`<${d.type}>`,i);for(const[e,t]of Object.entries(d.props))"children"===e||"key"===e||y(d.type,e)||P(i,e,t,s,!0);if(!t.hasTextareaValue(d.type,d.props)){const e=$(d.props.children,i,s,i.firstChild);e&&F(`the end of <${d.type}>`,e)}if("select"===d.type)for(const e of h)e in d.props&&P(i,e,d.props[e],s,!0);return i.nextSibling},q=()=>e.idPrefix??`r${(p++).toString(36)}`,H=(e,n,o,s=!1)=>{const i=new t.Owner(void 0,!0,o),c=(n.ownerDocument??n).createDocumentFragment();let d=[];try{B(e,c,i),s&&r?.completeRestore?.(),d=Array.from(c.childNodes),n.appendChild(c),i.mount()}catch(e){t.throwAfterDisposal(e,()=>t.disposeNodes(i,d))}let l=!1;return{dispose(){l||(l=!0,t.disposeNodes(i,d))}}};return{mount:(e,t)=>H(e,t,q()),hydrate(n,o){const s=q(),i=new t.Owner(void 0,!0,s);try{const e=$(n,o,i,o.firstChild);e&&F("the end of the hydration root",e)}catch(r){if(t.disposeAfterFailure(r,()=>i.dispose()),!(r instanceof t.NexusDOMError)||"HYDRATION_MISMATCH"!==r.code)throw r;for(e.onError?.(r);o.firstChild;)o.removeChild(o.firstChild);return H(n,o,s,!0)}const c=Array.from(o.childNodes);try{r?.completeRestore?.(),i.mount()}catch(e){t.throwAfterDisposal(e,()=>t.disposeNodes(i,c))}let d=!1;return{dispose(){d||(d=!0,t.disposeNodes(i,c))}}},flush:n.flush}}function x(e){if("string"!=typeof e)return e;const r=document.querySelector(e);if(!r)throw t.nexusDOMError("RENDER_TARGET_NOT_FOUND",`Render target "${e}" was not found.`);return r}const b=e.persist;exports.NexusDOMError=t.NexusDOMError,exports.component=t.component,exports.componentScope=t.componentScope,exports.createActs=t.createActs,exports.onCleanup=t.onCleanup,exports.store=t.store,exports.ErrorBoundary=function({fallback:e,children:t}){return{kind:"error-boundary",fallback:e,children:t}},exports.createApp=function(e,r){if(void 0!==e&&void 0===r)throw t.nexusDOMError("RENDER_TARGET_NOT_FOUND","Pass a target to createApp(view, target), or call createApp() to mount later.");const n=new Set,o=new Set,s=t.createStoreViewRegistry();let i=!1;const c={onCleanup:e=>i?(e(),()=>{}):(o.add(e),()=>o.delete(e)),dispose(){i||(i=!0,t.runDisposal(e=>{for(const t of Array.from(n))e(t.dispose);n.clear();for(const t of Array.from(o).reverse())e(t);o.clear(),e(s.dispose)}))},render(e,r,o){if(i)throw t.nexusDOMError("APP_DISPOSED","Cannot render a disposed app. app.dispose() has already run.");const c=function(e,t,r={},n){const o=w(r,n);return{dispose:o.mount(e,x(t)).dispose,flush:o.flush}}(e,r,o,s);let d=!1;const l={flush:c.flush,dispose(){d||(d=!0,n.delete(l),c.dispose())}};return i?l.dispose():n.add(l),l},hydrate(e,r,o){if(i)throw t.nexusDOMError("APP_DISPOSED","Cannot hydrate with a disposed app. app.dispose() has already run.");const c=function(e,r,n={},o){const s=x(r),i=t.takeHydrationState(s,n.idPrefix);if(i?.stores.length){if(!o?.restore)throw t.nexusDOMError("HYDRATION_STATE_INVALID","Lazy-store hydration state requires createApp().hydrate().");o.restore(i.stores)}const c=w(void 0===i?.idPrefix?n:{...n,idPrefix:i.idPrefix},o);return{dispose:c.hydrate(e,s).dispose,flush:c.flush}}(e,r,o,s);let d=!1;const l={flush:c.flush,dispose(){d||(d=!0,n.delete(l),c.dispose())}};return i?l.dispose():n.add(l),l}};if(void 0!==r)try{c.render(e,r)}catch(e){t.throwAfterDisposal(e,c.dispose)}return c},exports.persist=b;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nexus-state"),t=require("./chunks/store-view-XF9oYnrs.js");function r(e){return Array.isArray(e)?e[0]:e}function n(e){try{e.owner.dispose()}finally{!function(e){if(Array.isArray(e))for(const t of e)t.parentNode?.removeChild(t);else e.parentNode?.removeChild(e)}(e.nodes)}}function o(e,t){if(function(e){return Array.isArray(e)?e.at(-1):e}(e.nodes).nextSibling===t)return;const r=t.parentNode;if(!r)return;const n=Array.isArray(e.nodes)?e.nodes:[e.nodes];for(const e of n)r.moveBefore?r.moveBefore(e,t):r.insertBefore(e,t)}function s(e){const t=[],r=new Array(e.length).fill(-1);for(let n=0;n<e.length;n++){const o=e[n];if(void 0===o||o<0)continue;let s=0,i=t.length;for(;s<i;){const r=s+i>>1,n=t[r];(void 0===n?-1:e[n]??-1)<o?s=r+1:i=r}s>0&&(r[n]=t[s-1]??-1),t[s]=n}const n=new Set;let o=t.at(-1)??-1;for(;o>=0;)n.add(o),o=r[o]??-1;return n}function i(e,t){return!!t&&(Array.isArray(e.nodes)?e.nodes:[e.nodes]).some(e=>e===t||e.nodeType===Node.ELEMENT_NODE&&e.contains(t))}function c({target:e,owner:c,vnode:d,scheduler:l,renderInto:a,reconcileView:u,register:f,preparePatch:p,hydration:h}){const y=e.ownerDocument??e,v=f?y.createTextNode(""):void 0,g=y.createTextNode("");v&&e.insertBefore(v,h?h.node:null),h||e.appendChild(g);const m={},w=new Map;let x,b,k,N=[],S=!0,A=d.source,E=A,O=A.get(),D=O,T=O,C=!1,I=!1,M=d.project,j=M,V=h?void 0:y.createDocumentFragment(),L=h?.node,R=void 0!==h;const P=c.reserveIdSegment("l");let _=0;const B=()=>({slot:_++}),F=(r,o)=>{const s=new t.Owner(c,!1,c.keyedIdSegment(P,r)),i=t.createMutableLiveItem(o,s),d=f?{key:r,owner:s,nodes:g,controller:i.controller,live:i.live,row:i.row,view:void 0}:{key:r,owner:s,nodes:g,controller:i.controller};try{const t=M(i.live,i.row);if(f&&(p(s),d.view=t),R){const r=L?L.previousSibling:e.lastChild;L=h.hydrateInto(t,e,d.owner,L??null);const n=[];let o=r?r.nextSibling:e.firstChild;for(;o&&o!==L;)n.push(o),o=o.nextSibling;if(0===n.length){const t=y.createTextNode("");e.insertBefore(t,L??null),n.push(t)}d.nodes=1===n.length?n[0]:n}else if(V)d.nodes=((e,t)=>{const r=V,n=r.lastChild;a(e,r,t),r.lastChild===n&&r.appendChild(y.createTextNode(""));const o=n?n.nextSibling:r.firstChild;if(!o.nextSibling)return o;const s=[];let i=o;for(;i;)s.push(i),i=i.nextSibling;return s})(t,d.owner);else{const e=function(e,t,r,n){const o=e.createDocumentFragment();return n(t,o,r),0===o.childNodes.length&&o.appendChild(e.createTextNode("")),{fragment:o,nodes:1===o.childNodes.length?o.firstChild:Array.from(o.childNodes)}}(y,t,d.owner,a);d.nodes=e.nodes,g.parentNode?.insertBefore(e.fragment,g),c.isMounted()&&d.owner.mount()}}catch(e){t.throwAfterDisposal(e,()=>{R||d.nodes===g?d.owner.dispose():n(d)})}return d};c.addMount(()=>{for(const e of N)e.owner.mount()});const $=(e,t)=>{let n=-1;if(e.every(e=>{const r=t.get(e.key);return!(void 0===r||r<=n||(n=r,0))}))return void(N=e);const c=e.map(e=>t.get(e.key)??-1),d=g.parentNode,l=y.activeElement,a=d?.moveBefore?-1:e.findIndex(e=>i(e,l)),u=function(e,t){const r=void 0===t?void 0:e[t];if(void 0===t||void 0===r||r<0)return s(e);const n=e.map((e,n)=>n<t&&e<r?e:-1),o=e.map((e,n)=>n>t&&e>r?e:-1);return new Set([...s(n),t,...s(o)])}(c,a<0?void 0:a);for(let t=e.length-1;t>=0;t--){const n=e[t],s=e[t+1];-1!==c[t]&&u.has(t)||o(n,s?r(s.nodes):g)}N=e},q=(r,o,s)=>{if(!V&&!R&&r.length===N.length&&N.every((e,n)=>t.inferredRowKey(r[n])===e.key))return void N.forEach((e,t)=>{Object.is(e.controller.get(),r[t])||e.controller.set(r[t],s)});const i=[];let c,d;for(const e of N){if("object"!=typeof e.key)continue;const t=e.controller.get();c??(c=new Map),c.set(t,c.has(t)?null:e)}if(c){d=new Map;for(const e of r)d.set(e,(d.get(e)??0)+1)}const l=t.resolveRowKeys(r,e=>{const t=c?.get(e);return t&&1===d?.get(e)&&Object.is(t.controller.get(),e)?t.key:B()}),a=new Set(l),u=new Map(N.map((e,t)=>[e.key,t]));l.forEach((e,t)=>{const n=r[t];let o=w.get(e);o?Object.is(o.controller.get(),n)||o.controller.set(n,s):(o=F(e,n),w.set(e,o)),i.push(o)});for(const[e,t]of w)a.has(e)||(w.delete(e),o(()=>n(t)));return V?(g.parentNode?.insertBefore(V,g),V=void 0,void(N=i)):R?(e.insertBefore(g,L??null),R=!1,void(N=i)):void $(i,u)},H=(e,s,c,d,l=!0)=>{if("batch"===e.type){for(const t of e.operations)if(!H(t,s,c,d,!1))return!1;return!l||N.length===s.length}if("insert"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.index>N.length||e.count<1)return!1;if(l&&s.length!==N.length+e.count)return!1;const n=t.readListOperationPayload(e);if(!Array.isArray(n)||n.length!==e.count)return!1;const i=n.map(e=>({item:e,key:t.inferredRowKey(e)??B()})),c=new Set;for(const{key:e}of i){if(w.has(e)||c.has(e))return!1;c.add(e)}const d=[];for(const{item:e,key:t}of i){const r=F(t,e);w.set(t,r),d.push(r)}N.splice(e.index,0,...d);let a=N[e.index+d.length]?r(N[e.index+d.length].nodes):g;for(let e=d.length-1;e>=0;e--){const t=d[e];t&&(o(t,a),a=r(t.nodes))}return!0}if("remove"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.count<1||e.index+e.count>N.length)return!1;if(l&&s.length!==N.length-e.count)return!1;const t=N.splice(e.index,e.count);if(t.length!==e.count)return!1;for(const e of t)w.delete(e.key),c(()=>n(e));return!0}if("move"===e.type){if(!Number.isInteger(e.from)||!Number.isInteger(e.to)||e.from<0||e.from>=N.length||e.to<0||e.to>=N.length)return!1;if(l&&s.length!==N.length)return!1;const n=N[e.from];if(!n)return!1;if(l){const r=s[e.to];if(!("object"==typeof n.key?Object.is(r,n.controller.get()):t.inferredRowKey(r)===n.key))return!1}const c=g.parentNode,d=y.activeElement;if(!c?.moveBefore&&i(n,d)){if(e.from>e.to){let t=N[e.from+1]?r(N[e.from+1].nodes):g;for(let n=e.from-1;n>=e.to;n--){const e=N[n];e&&(o(e,t),t=r(e.nodes))}}else{const t=r(n.nodes);for(let r=e.from+1;r<=e.to;r++){const e=N[r];e&&o(e,t)}}return N.splice(e.from,1),N.splice(e.to,0,n),!0}return N.splice(e.from,1),N.splice(e.to,0,n),o(n,N[e.to+1]?r(N[e.to+1].nodes):g),!0}if("replace"===e.type){if(!Number.isInteger(e.index)||e.index<0||e.index>=N.length)return!1;if(l&&s.length!==N.length)return!1;const i=N[e.index],a=t.readListOperationPayload(e);if(!i||!t.hasListOperationPayload(e))return!1;const u=t.inferredRowKey(a)??("object"==typeof i.key?i.key:B());if(u===i.key)return i.controller.set(a,d),!0;if(w.has(u))return!1;const f=F(u,a);return w.delete(i.key),c(()=>n(i)),w.set(u,f),N[e.index]=f,o(f,N[e.index+1]?r(N[e.index+1].nodes):g),!0}if("reorder"===e.type){if(l&&s.length!==N.length)return!1;const e=new Map(N.map((e,t)=>[e.key,t]));return $([...N].reverse(),e),!0}return!1};try{t.runDisposal(e=>q(O,e))}catch(e){t.throwAfterDisposal(e,W)}function W(){t.runDisposal(e=>{for(const t of w.values())e(()=>n(t));w.clear(),N=[],v&&v.parentNode?.removeChild(v),g.parentNode?.removeChild(g)})}function K(){I=!0,l.enqueue(m,U,b,e=>c.handleError(e))}function U(){if(I=!1,!S)return;if(E!==A){const e=E,t=e.get(),r=J(e);X(),A=e,X=r,k=void 0,O=t,x=void 0,C=t!==D&&(!D||D.length!==t.length||t.some((e,t)=>!Object.is(e,D[t]))),C||(D=t)}if(k)throw k.error;const e=b;b=void 0;const s=j===M?void 0:new Set(N);M=j;const i=T===D?x:void 0,c=O,d=C;C=!1,x=void 0,t.runDisposal(t=>{if(d&&(D=void 0,(Array.isArray(i)?i.every((r,n)=>H(r,c,t,e,n===i.length-1)):i&&H(i,c,t,e))||q(c,t,e),D=c),s)for(let e=0;e<N.length;e++){const i=N[e];if(!s.has(i))continue;const c=M(i.live,i.row),d=Array.isArray(i.nodes)?i.nodes:[i.nodes];if(u(i.view,c,d,i.owner)){i.view=c;continue}const l=F(i.key,i.controller.get());o(l,r(i.nodes)),w.set(i.key,l),N[e]=l,t(()=>n(i))}})}v&&f?.({start:v,end:g,update(e){j===e.project&&E===e.source||(j=e.project,E=e.source,I||K())}});let X=()=>{};function J(e){return t.subscribeForRender(e,(e,r)=>{k=void 0;const n=O;O=e;const o=t.readListOperation(r,d.stateKey,n,e);C?x&&o?Array.isArray(x)?x.push(o):x=[x,o]:x=void 0:(T=n,x=o),C=!0,b=r,K()},(e,t)=>{k={error:e},b=t,x=void 0,C=!0,K()})}return c.addCleanup(()=>{S=!1,l.cancel(m),X(),W()}),X=J(A),L}require("./chunks/types-BLzRvYOk.js");const d=e=>e.slice(2).toLowerCase(),l=e=>null==e||!1===e?"":String(e);function a(e,r,n,o){const s=t.checkedDOMValue(e.localName,r,n);if("select"===e.localName&&("value"===r||"defaultValue"===r)){const n=e;if("value"===r&&!n.multiple){const e=String(s??"");return void(n.value!==e&&(n.value=e))}const o=t.selectionValues(s,n.multiple),i=Array.from(n.options);if("value"===r){for(const e of i)e.selected=o.has(e.value);return}const c=t.hasEditedValue(n,"value")?new Set(n.selectedOptions):void 0;for(const e of i){const t=o.has(e.value);e.defaultSelected=t,t&&!n.multiple&&o.delete(e.value)}if(n.multiple)for(const e of i)e.selected=c?c.has(e):e.defaultSelected;else{const e=c?i.find(e=>c.has(e)):t.defaultSelectedOptions(n)[0];n.selectedIndex=e?.index??-1}return}"className"!==r&&"class"!==r?"style"===r&&(e instanceof HTMLElement||e instanceof SVGElement)?function(e,t,r){if("string"!=typeof t)if(t&&"object"==typeof t){if(r&&"object"==typeof r)for(const n of Object.keys(r))n in t||(e.style.removeProperty(n),e.style[n]="");for(const[r,n]of Object.entries(t))r.startsWith("--")?e.style.setProperty(r,String(n)):e.style[r]=n}else e.removeAttribute("style");else e.style.cssText=t}(e,s,o):"htmlFor"!==r?r.startsWith("aria-")||r.startsWith("data-")||"http://www.w3.org/2000/svg"===e.namespaceURI||!(r in e)?null==s||!1===s?e.removeAttribute(r):!0===s?e.setAttribute(r,""):e.setAttribute(r,String(s)):e[r]=s??"":null==s||!1===s?e.removeAttribute("for"):e.setAttribute("for",String(s)):null==s||!1===s?e.removeAttribute("class"):e.setAttribute("class",String(s))}function u({target:e,owner:r,vnode:n,scheduler:o,renderInto:s,preparePatch:i,reconcile:c,hydration:d}){const l=e.ownerDocument??e,a=l.createTextNode("");d||e.appendChild(a);const u={};let f,p,h,y=!0,v=[],g=()=>{};const m=r.reserveIdSegment("t"),w=()=>{const e=f,r=v;f=void 0,v=[],t.disposeNodes(e,r)};function x(e,t){o.enqueue(u,k,t,e=>r.handleError(e))}const b=e=>{if(h&&t.sameDependencies(h,e))return;const r=g;h=e,g=n.source.subscribe(x,e),r()};function k(){if(!y)return;const e=n.track?.()??t.trackSelector(n.source.get(),n.project);if(f&&c(p,e.value,v,f))return p=e.value,void b(e.dependencies);const o=new t.Owner(r,!0,m);e.dependencies.length>0&&i(o);const d=l.createDocumentFragment();try{s(e.value,d,o),b(e.dependencies)}catch(e){t.throwAfterDisposal(e,()=>o.dispose())}const u=Array.from(d.childNodes);t.runDisposal(t=>{t(w),f=o,v=u,p=e.value,a.parentNode?.insertBefore(d,a),r.isMounted()&&o.mount()})}let N;if(d){const o=n.track?.()??t.trackSelector(n.source.get(),n.project),s=new t.Owner(r,!0,m);o.dependencies.length>0&&i(s);const c=d.node?d.node.previousSibling:e.lastChild;try{N=d.hydrateInto(o.value,e,s,d.node),b(o.dependencies)}catch(e){t.throwAfterDisposal(e,()=>s.dispose())}e.insertBefore(a,N);const l=[];let u=c?c.nextSibling:e.firstChild;for(;u&&u!==a;)l.push(u),u=u.nextSibling;f=s,v=l,p=o.value}else k();return r.addCleanup(()=>{y=!1,o.cancel(u),g();try{w()}finally{a.parentNode?.removeChild(a)}}),n.mountStores&&f?.addMount(n.mountStores),N}const f="http://www.w3.org/2000/svg";let p=0;const h=["defaultValue","value"],y=(e,t)=>"select"===e&&("value"===t||"defaultValue"===t);class v{constructor(e,t,r){this.field=e,this.owner=t,this.scheduler=r,this.active=!0}connect(e=!1){const t=this.field.get();e||this.write(t),this.field.addListener(this),this.owner.addCleanup(this)}notify(e,t){this.scheduler.enqueue(this,()=>{this.active&&this.write(e)},t,e=>this.owner.handleError(e))}dispose(){this.active=!1,this.scheduler.cancel(this),this.field.removeListener(this)}}class g extends v{constructor(e,t,r,n){super(e,r,n),this.node=t,this.connect()}write(e){this.node.data=l(e)}}class m extends v{constructor(e,t,r,n,o,s){super(e,n,o),this.element=t,this.property=r,this.connect(s)}write(e){const t=this.previousStyle;"style"===this.property&&(this.previousStyle=e),a(this.element,this.property,e,t)}}function w(e={},r){const n=function(e){const t=e.schedule??"microtask",r=new Map;let n=!1;const o=()=>{if(n=!1,0===r.size)return;let t=0;const o=[];let s;for(;r.size>0;){const n=Array.from(r.values());r.clear();for(const r of n)try{r.run(),t++,void 0!==r.context&&o.push(r.context)}catch(n){let i=n;try{if(r.handleError?.(n)){t++,void 0!==r.context&&o.push(r.context);continue}}catch(e){i=e}try{e.onError?e.onError(i):(s??(s=[])).push(i)}catch(e){(s??(s=[])).push(e)}}}if(t>0&&e.onCommit?.({updates:t,contexts:o}),1===s?.length)throw s[0];if(s)throw new AggregateError(s,"nexus-dom: Multiple errors during rendering.")};return{enqueue(e,s,i,c){r.set(e,{run:s,...void 0===i?{}:{context:i},...void 0===c?{}:{handleError:c}}),"manual"===t||n||(n=!0,"animationFrame"===t?requestAnimationFrame(o):queueMicrotask(o))},cancel(e){r.delete(e)},flush:o}}(e),o=new WeakMap,s=new WeakMap,i=new WeakMap,v=new WeakSet,w=e=>{v.add(e)},x=e=>i.set(e.start,e),b=(e,t)=>(r,o)=>{n.enqueue(e,()=>{throw r},o,e=>t.handleError(e))},k=(e,r,o,s=!1)=>{let i=!0,c=e.get(),d=c;s||o(c,void 0);const l=(e,t)=>{d=e,n.enqueue(l,()=>{if(!i)return;const e=c;c=d,o(c,e)},t,e=>r.handleError(e))},a=t.supportsRenderErrors(e)?t.subscribeForRender(e,l,b(l,r)):e.subscribe(l);r.addCleanup(()=>{i=!1,n.cancel(l),a()})},N=(e,r,o)=>{const s=t.getRowField(e);s?new g(s,r,o,n):k(e,o,e=>{r.data=l(e)})},S=(e,r,n,o,s)=>{const i=e.ownerDocument??e,c=new t.Owner(r),d=c.reserveIdSegment("b"),l=i.createTextNode("");s||e.appendChild(l);let a,u,f=!0,p=!1,h=[];const y=(e,r)=>{const n=new t.Owner(c,!0,d),o=i.createDocumentFragment();r&&n.setErrorHandler(g);try{B(e,o,n)}catch(e){t.throwAfterDisposal(e,()=>n.dispose())}const s=Array.from(o.childNodes);t.runDisposal(e=>{e(()=>t.disposeNodes(a,h)),a=n,h=s,l.parentNode?.insertBefore(o,l),c.isMounted()&&n.mount()})},v=()=>{if(f)try{y(n,!0)}catch(e){try{g(e)}catch(e){if(p&&c.parent?.handleError(e))return;throw e}}};function g(e){if(!f)return;const t="function"==typeof o?o(e,v):o;y(t,!1)}if(s){const r=(r,n)=>{const o=new t.Owner(c,!0,d);n&&o.setErrorHandler(g);const i=s.node?s.node.previousSibling:e.lastChild;try{u=s.hydrateInto(r,e,o,s.node)}catch(e){t.throwAfterDisposal(e,()=>o.dispose())}e.insertBefore(l,u);const f=[];let p=i?i.nextSibling:e.firstChild;for(;p&&p!==l;)f.push(p),p=p.nextSibling;a=o,h=f};try{r(n,!0)}catch(e){if(e instanceof t.NexusDOMError&&"HYDRATION_MISMATCH"===e.code)throw e;r("function"==typeof o?o(e,v):o,!1)}}else v();return p=!0,c.addCleanup(()=>{f=!1;const e=a,r=h;a=void 0,h=[];try{t.disposeNodes(e,r)}finally{l.parentNode?.removeChild(l)}}),u},A=(e,r,s,i)=>{if(t.isLiveValue(s)){let o=s.get();const c=e=>{"function"==typeof o&&o(e)},l=t.subscribeForRender(s,e=>{o=e,n.cancel(c)},b(c,i));return e.addEventListener(d(r),c),void i.addCleanup(()=>{l(),n.cancel(c),e.removeEventListener(d(r),c)})}const c=o.get(e)??new Map;o.set(e,c);const l={listener:"function"==typeof s?s:void 0};c.set(r,l),l.listener&&e.addEventListener(d(r),l.listener),i.addCleanup(()=>{l.listener&&e.removeEventListener(d(r),l.listener),c.get(r)===l&&c.delete(r)})},E=(e,t)=>{"function"==typeof e?e(t):e&&"object"==typeof e&&(e.current=t)},O=e=>"function"==typeof e||"object"==typeof e&&null!==e&&"current"in e,D=(e,t,r)=>{if(!O(t))return;const n={value:t,attached:!1};s.set(e,n),r.addMount(()=>{n.attached=!0,E(n.value,e)}),r.addCleanup(()=>{n.attached&&E(n.value,null),s.get(e)===n&&s.delete(e)})},T=(e,r)=>{if(null==e||!1===e||!0===e)return!0;if(Array.isArray(e))return e.every(e=>T(e,r));if(t.isLiveValue(e))return r.push(e),!0;if("object"!=typeof e)return r.push(e),!0;const n=e;return"fragment"===n.kind?T(n.props.children,r):("element"===n.kind||"keyed"===n.kind)&&(r.push(n),!0)},C=(e,r,n)=>{const o=[];let s=r;for(const r of e){if(!s||s===n)return;o.push(s);const e=i.get(s);if(e){if("object"!=typeof r||t.isLiveValue(r)||"keyed"!==r.kind)return;s=e.end.nextSibling}else s=s.nextSibling}if(s===n)return o},I=(e,r,n)=>{if(t.isLiveValue(e)||t.isLiveValue(r))return e===r;if("object"!=typeof e||"object"!=typeof r)return"object"!=typeof e&&"object"!=typeof r;if("keyed"===e.kind||"keyed"===r.kind)return"keyed"===e.kind&&"keyed"===r.kind&&t.sameListSource(e.source,r.source)&&i.has(n);if(e.type!==r.type||e.key!==r.key||!((e,r)=>{const n=new Set([...Object.keys(e),...Object.keys(r)]);for(const o of n){if("children"===o||"key"===o)continue;const n=e[o],s=r[o];if((t.isLiveValue(n)||t.isLiveValue(s))&&n!==s)return!1}return!0})(e.props,r.props))return!1;const o=t.hasTextareaValue(e.type,e.props);if(o!==t.hasTextareaValue(r.type,r.props))return!1;if(o)return!0;const s=[],c=[];if(!(n instanceof Element&&T(e.props.children,s)&&T(r.props.children,c)&&s.length===c.length))return!1;const d=C(s,n.firstChild,null);return!!d&&s.every((e,t)=>I(e,c[t],d[t]))},M=(e,t,r,n)=>{let s=o.get(e),i=s?.get(t);i?(i.listener&&e.removeEventListener(d(t),i.listener),i.listener="function"==typeof r?r:void 0,i.listener&&e.addEventListener(d(t),i.listener)):A(e,t,r,n)},j=(e,t,r)=>{const n=O(t)?t:void 0,o=s.get(e);o?o.value!==n&&(o.attached&&E(o.value,null),o.value=n,o.attached&&E(o.value,e)):n&&D(e,n,r)},V=(e,r,n,o)=>{if(t.isLiveValue(e)||t.isLiveValue(r))return;if("object"!=typeof e||"object"!=typeof r)return void(n.nodeType===Node.TEXT_NODE&&(n.nodeValue=l(r)));if("keyed"===e.kind||"keyed"===r.kind)return void("keyed"===r.kind&&i.get(n)?.update(r));if(!(n instanceof Element))return;const s=new Set([...Object.keys(e.props),...Object.keys(r.props)]);for(const i of s){if("children"===i||"key"===i||y(r.type,i))continue;const s=e.props[i],c=r.props[i];s!==c&&("ref"===i?j(n,c,o):t.isEventProperty(i)?M(n,i,c,o):t.isLiveValue(c)||a(n,i,c,s))}if(t.hasTextareaValue(r.type,r.props))return;const c=[],d=[];T(e.props.children,c),T(r.props.children,d);const u=C(c,n.firstChild,null);if(c.forEach((e,t)=>{V(e,d[t],u[t],o)}),"select"===r.type)for(const t of h)e.props[t]!==r.props[t]&&a(n,t,r.props[t],e.props[t])},L=(e,t,r,n)=>{const o=[],s=[];if(!T(e,o)||!T(t,s)||o.length!==s.length)return!1;const i=C(o,r[0]??null,r.at(-1)?.nextSibling??null);return!(!i||!o.every((e,t)=>I(e,s[t],i[t]))||(o.forEach((e,t)=>{V(e,s[t],i[t],n)}),0))},R=(e,r,o,s,i,c)=>{const d=e.ownerDocument??e,l=d.createTextNode("");c||e.appendChild(l);const a=r.reserveIdSegment("d");let u,f=!0,p=o.get(),h=i?.(p),y=[];const v={},g=()=>{const e=u,r=y;u=void 0,y=[],t.disposeNodes(e,r)},m=()=>{const e=new t.Owner(r,!0,a),n=d.createDocumentFragment();try{B(s(p),n,e)}catch(r){t.throwAfterDisposal(r,()=>e.dispose())}const o=Array.from(n.childNodes);t.runDisposal(t=>{t(g),u=e,y=o,l.parentNode?.insertBefore(n,l),r.isMounted()&&e.mount()})};let w;if(c){const n=new t.Owner(r,!0,a),o=c.node?c.node.previousSibling:e.lastChild;try{w=c.hydrateInto(s(p),e,n,c.node)}catch(e){t.throwAfterDisposal(e,()=>n.dispose())}e.insertBefore(l,w);const i=[];let d=o?o.nextSibling:e.firstChild;for(;d&&d!==l;)i.push(d),d=d.nextSibling;u=n,y=i}else m();const x=t.subscribeForRender(o,(e,t)=>{p=e,n.enqueue(v,()=>{if(f){if(i){const e=i(p);if(Object.is(h,e))return;h=e}m()}},t,e=>r.handleError(e))},b(v,r));return r.addCleanup(()=>{f=!1,n.cancel(v),x();try{g()}finally{l.parentNode?.removeChild(l)}}),w},P=(e,r,o,s,i=!1)=>{if("ref"===r)D(e,o,s);else if(t.isEventProperty(r))A(e,r,o,s);else if(t.isLiveValue(o)){const c=t.getRowField(o),d=i&&t.hasEditedValue(e,r);c?new m(c,e,r,s,n,d):k(o,s,(t,n)=>a(e,r,t,n),d)}else!i||"value"===r&&"select"===e.localName&&!t.hasEditedValue(e,r)?a(e,r,o,void 0):t.checkedDOMValue(e.localName,r,o)},_=(e,o,s)=>{if("store-view"===e.kind){if(!r)throw t.nexusDOMError("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be rendered through createApp().render().");return void _(r.resolve(e),o,s)}if("error-boundary"===e.kind)return void S(o,s,e.children,e.fallback);if("keyed"===e.kind)return void c({target:o,owner:s,vnode:e,scheduler:n,renderInto:B,reconcileView:L,preparePatch:w,...v.has(s)?{register:x}:{}});if("tracked-view"===e.kind)return void u({target:o,owner:s,vnode:e,scheduler:n,renderInto:B,preparePatch:w,reconcile:L});if("dynamic"===e.kind)return void R(o,s,e.source,e.project,e.key);if("fragment"===e.kind)return void B(e.props.children,o,s);if("component"===e.kind){const r=new t.Owner(s);r.setComponentIdentity(e.type,e.key);const n=t.withOwner(r,()=>e.type(e.props));return void B(n,o,r)}const i=function(e,t,r){const n=t instanceof Element?t:void 0;return"svg"===r||n?.namespaceURI===f&&"foreignObject"!==n.localName?e.createElementNS(f,r):e.createElement(r)}(o.ownerDocument??o,o,e.type);for(const[t,r]of Object.entries(e.props))"children"===t||"key"===t||y(e.type,t)||P(i,t,r,s);if(t.hasTextareaValue(e.type,e.props)||B(e.props.children,i,s),"select"===e.type)for(const t of h)t in e.props&&P(i,t,e.props[t],s);o.appendChild(i)},B=(e,r,n)=>{if(null==e||!1===e||!0===e)return;if(Array.isArray(e)){for(const t of e)B(t,r,n);return}const o=r.ownerDocument??r;if(t.isLiveValue(e)){const t=o.createTextNode("");return N(e,t,n),void r.appendChild(t)}"object"!=typeof e?r.appendChild(o.createTextNode(l(e))):_(e,r,n)},F=(e,r)=>{const n=r?1===r.nodeType?`<${r.localName}>`:3===r.nodeType?`text ${JSON.stringify(r.nodeValue)}`:8===r.nodeType?`comment ${JSON.stringify(r.nodeValue)}`:`node type ${r.nodeType}`:"the end of the container";throw t.nexusDOMError("HYDRATION_MISMATCH",`Expected ${e}, but found ${n}.`)},$=(e,o,s,i)=>{if(null==e||!1===e||!0===e)return i;if(Array.isArray(e)){let t=i;for(const r of e)t=$(r,o,s,t);return t}if(t.isLiveValue(e)){if(8!==i?.nodeType||i.nodeValue!==t.TEXT_START)return F(`the \x3c!--${t.TEXT_START}--\x3e marker`,i);const r=i;let n=r.nextSibling;if(8===n?.nodeType&&n.nodeValue===t.TEXT_END&&(n=(o.ownerDocument??o).createTextNode(""),o.insertBefore(n,r.nextSibling)),!n||3!==n.nodeType)return F("reactive text",n);const c=n.nextSibling;if(8!==c?.nodeType||c.nodeValue!==t.TEXT_END)return F(`the \x3c!--${t.TEXT_END}--\x3e marker`,c);const d=l(e.get());if(n.data!==d)return F(`reactive text ${JSON.stringify(d)}`,n);const a=c.nextSibling;return r.parentNode?.removeChild(r),c.parentNode?.removeChild(c),N(e,n,s),a}if("object"!=typeof e)return((e,t,r)=>{const n=t.ownerDocument??t;if(""===e)return t.insertBefore(n.createTextNode(""),r),r;r&&3===r.nodeType||F(`text ${JSON.stringify(e)}`,r);const o=r;return o.data===e?o.nextSibling:o.data.startsWith(e)?o.splitText(e.length):F(`text ${JSON.stringify(e)}`,r)})(l(e),o,i);const d=e;if("fragment"===d.kind)return $(d.props.children,o,s,i);if("component"===d.kind){const e=new t.Owner(s);e.setComponentIdentity(d.type,d.key);const r=t.withOwner(e,()=>d.type(d.props));return $(r,o,e,i)}if("store-view"===d.kind){if(!r)throw t.nexusDOMError("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be hydrated through createApp().hydrate().");return $(r.resolve(d),o,s,i)}if("tracked-view"===d.kind){const e=u({target:o,owner:s,vnode:d,scheduler:n,renderInto:B,preparePatch:w,reconcile:L,hydration:{node:i,hydrateInto:$}});return void 0===e?i:e}if("dynamic"===d.kind){const e=R(o,s,d.source,d.project,d.key,{node:i,hydrateInto:$});return void 0===e?i:e}if("keyed"===d.kind){const e=c({target:o,owner:s,vnode:d,scheduler:n,renderInto:B,reconcileView:L,preparePatch:w,...v.has(s)?{register:x}:{},hydration:{node:i,hydrateInto:$}});return void 0===e?i:e}if("error-boundary"===d.kind){const e=S(o,s,d.children,d.fallback,{node:i,hydrateInto:$});return void 0===e?i:e}if(!(i instanceof Element)||i.localName!==d.type)return F(`<${d.type}>`,i);for(const[e,t]of Object.entries(d.props))"children"===e||"key"===e||y(d.type,e)||P(i,e,t,s,!0);if(!t.hasTextareaValue(d.type,d.props)){const e=$(d.props.children,i,s,i.firstChild);e&&F(`the end of <${d.type}>`,e)}if("select"===d.type)for(const e of h)e in d.props&&P(i,e,d.props[e],s,!0);return i.nextSibling},q=()=>e.idPrefix??`r${(p++).toString(36)}`,H=(e,n,o,s=!1)=>{const i=new t.Owner(void 0,!0,o),c=(n.ownerDocument??n).createDocumentFragment();let d=[];try{B(e,c,i),s&&r?.completeRestore?.(),d=Array.from(c.childNodes),n.appendChild(c),i.mount()}catch(e){t.throwAfterDisposal(e,()=>t.disposeNodes(i,d))}let l=!1;return{dispose(){l||(l=!0,t.disposeNodes(i,d))}}};return{mount:(e,t)=>H(e,t,q()),hydrate(n,o){const s=q(),i=new t.Owner(void 0,!0,s);try{const e=$(n,o,i,o.firstChild);e&&F("the end of the hydration root",e)}catch(r){if(t.disposeAfterFailure(r,()=>i.dispose()),!(r instanceof t.NexusDOMError)||"HYDRATION_MISMATCH"!==r.code)throw r;for(e.onError?.(r);o.firstChild;)o.removeChild(o.firstChild);return H(n,o,s,!0)}const c=Array.from(o.childNodes);try{r?.completeRestore?.(),i.mount()}catch(e){t.throwAfterDisposal(e,()=>t.disposeNodes(i,c))}let d=!1;return{dispose(){d||(d=!0,t.disposeNodes(i,c))}}},flush:n.flush}}function x(e){if("string"!=typeof e)return e;const r=document.querySelector(e);if(!r)throw t.nexusDOMError("RENDER_TARGET_NOT_FOUND",`Render target "${e}" was not found.`);return r}const b=e.persist;exports.NexusDOMError=t.NexusDOMError,exports.component=t.component,exports.componentScope=t.componentScope,exports.createActs=t.createActs,exports.onCleanup=t.onCleanup,exports.store=t.store,exports.ErrorBoundary=function({fallback:e,children:t}){return{kind:"error-boundary",fallback:e,children:t}},exports.createApp=function(e,r){if(void 0!==e&&void 0===r)throw t.nexusDOMError("RENDER_TARGET_NOT_FOUND","Pass a target to createApp(view, target), or call createApp() to mount later.");const n=new Set,o=new Set,s=t.createStoreViewRegistry();let i=!1;const c={onCleanup:e=>i?(e(),()=>{}):(o.add(e),()=>o.delete(e)),dispose(){i||(i=!0,t.runDisposal(e=>{for(const t of Array.from(n))e(t.dispose);n.clear();for(const t of Array.from(o).reverse())e(t);o.clear(),e(s.dispose)}))},render(e,r,o){if(i)throw t.nexusDOMError("APP_DISPOSED","Cannot render a disposed app. app.dispose() has already run.");const c=function(e,t,r={},n){const o=w(r,n);return{dispose:o.mount(e,x(t)).dispose,flush:o.flush}}(e,r,o,s);let d=!1;const l={flush:c.flush,dispose(){d||(d=!0,n.delete(l),c.dispose())}};return i?l.dispose():n.add(l),l},hydrate(e,r,o){if(i)throw t.nexusDOMError("APP_DISPOSED","Cannot hydrate with a disposed app. app.dispose() has already run.");const c=function(e,r,n={},o){const s=x(r),i=t.takeHydrationState(s,n.idPrefix);if(i?.stores.length){if(!o?.restore)throw t.nexusDOMError("HYDRATION_STATE_INVALID","Lazy-store hydration state requires createApp().hydrate().");o.restore(i.stores)}const c=w(void 0===i?.idPrefix?n:{...n,idPrefix:i.idPrefix},o);return{dispose:c.hydrate(e,s).dispose,flush:c.flush}}(e,r,o,s);let d=!1;const l={flush:c.flush,dispose(){d||(d=!0,n.delete(l),c.dispose())}};return i?l.dispose():n.add(l),l}};if(void 0!==r)try{c.render(e,r)}catch(e){t.throwAfterDisposal(e,c.dispose)}return c},exports.persist=b;
|
package/dist/cjs/owner.d.ts
CHANGED
|
@@ -14,7 +14,12 @@ export declare class Owner {
|
|
|
14
14
|
private readonly ids;
|
|
15
15
|
private readonly idPath;
|
|
16
16
|
private nextIdChild;
|
|
17
|
+
private localStoreIndex;
|
|
18
|
+
private componentIdentity;
|
|
17
19
|
constructor(parent?: Owner | undefined, tracked?: boolean, identity?: string);
|
|
20
|
+
setComponentIdentity(type: unknown, key: unknown): void;
|
|
21
|
+
hasComponentIdentity(): boolean;
|
|
22
|
+
acquireLocalStore<T>(create: () => T, release: (value: T) => void): T;
|
|
18
23
|
reserveIdSegment(kind: string): string;
|
|
19
24
|
keyedIdSegment(region: string, key: RowKey): string;
|
|
20
25
|
id(): string;
|
|
@@ -27,6 +32,7 @@ export declare class Owner {
|
|
|
27
32
|
dispose(): void;
|
|
28
33
|
}
|
|
29
34
|
export declare function withOwner<T>(owner: Owner, run: () => T): T;
|
|
35
|
+
export declare function withLocalStore<T>(create: (local: boolean) => T, release: (value: T) => void): T;
|
|
30
36
|
export declare function captureOwnerId(): () => string;
|
|
31
37
|
/**---
|
|
32
38
|
* ## 
|
package/dist/cjs/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/store-view-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/store-view-XF9oYnrs.js");require("nexus-state"),require("./chunks/types-BLzRvYOk.js");const t=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/^[A-Za-z][A-Za-z0-9._:-]*$/,n=/^[A-Za-z_:][A-Za-z0-9:._-]*$/,i=e=>String(e).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),l=e=>i(e).replaceAll('"',"""),s=e=>"className"===e?"class":"htmlFor"===e?"for":e,o=t=>e.isLiveValue(t)?t.get():t,a=e=>Object.entries(e).filter(([,e])=>null!=e&&!1!==e).map(([e,t])=>`${e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}:${String(t)}`).join(";");exports.renderToString=function(u,c={}){const f=e.createStoreViewRegistry({runSetup:!1}),p=c.idPrefix??"ssr",d=new e.Owner(void 0,!0,p),y=(u,p,d)=>{if(null==u||!1===u||!0===u)return"";if(Array.isArray(u))return u.map(e=>y(e,p,d)).join("");if(e.isLiveValue(u)){const t=i(u.get());return c.hydration?e.hydrationText(t):t}if("object"!=typeof u)return i(u);const v=u;if("component"===v.kind){const t=new e.Owner(p);return t.setComponentIdentity(v.type,v.key),y(e.withOwner(t,()=>v.type(v.props)),t,d)}if("store-view"===v.kind)return y(f.resolve(v),p,d);if("tracked-view"===v.kind){const t=new e.Owner(p,!0,p.reserveIdSegment("t")),r=v.track?v.track().value:v.project(v.source.get());return y(r,t,d)}if("fragment"===v.kind)return y(v.props.children,p,d);if("dynamic"===v.kind){const t=new e.Owner(p,!0,p.reserveIdSegment("d"));return y(v.project(v.source.get()),t,d)}if("keyed"===v.kind){const t=p.reserveIdSegment("l"),r=v.source.get();let n=0;return e.resolveRowKeys(r,()=>({slot:n++})).map((n,i)=>{const l=new e.Owner(p,!0,p.keyedIdSegment(t,n)),{live:s,row:o}=e.createMutableLiveItem(r[i],l);return y(v.project(s,o),l,d)}).join("")}if("error-boundary"===v.kind){const t=new e.Owner(p),r=t.reserveIdSegment("b"),n=new e.Owner(t,!0,r),i=d&&{...d,values:new Set(d.values)};try{const e=y(v.children,n,i);return i&&(d.values=i.values),e}catch(i){n.dispose();const l="function"==typeof v.fallback?v.fallback(i,()=>{}):v.fallback,s=new e.Owner(t,!0,r);return y(l,s,d)}}if(!r.test(v.type))throw e.nexusDOMError("INVALID_SERVER_ELEMENT",`Cannot serialize the element name ${JSON.stringify(v.type)}.`);const{type:w,props:h}=v,m=e.hasTextareaValue(w,h),g="value"in h?"value":"defaultValue",k="select"===w,S="option"===w;let $,b="";for(const[t,r]of Object.entries(v.props)){if("children"===t||"key"===t||"ref"===t||e.isEventProperty(t)||(m||k)&&("value"===t||"defaultValue"===t)||S&&d&&"selected"===t)continue;let i=s(t),u=e.checkedDOMValue(w,t,o(r));if("input"===w){if("defaultValue"===t){if("value"in h)continue;i="value"}if("defaultChecked"===t){if("checked"in h)continue;i="checked"}"value"===i&&null!=u&&"function"!=typeof u&&(u=String(u))}if(S&&"value"===i&&($=u,null!=u&&"function"!=typeof u&&(u=String(u))),null!=u&&!1!==u&&"function"!=typeof u){if(!n.test(i))throw e.nexusDOMError("INVALID_SERVER_ATTRIBUTE",`Cannot serialize the attribute name ${JSON.stringify(i)}.`);if(!0===u)b+=` ${i}`;else if("style"===i&&"object"==typeof u){const e=a(u);e&&(b+=` style="${l(e)}"`)}else b+=` ${i}="${l(u)}"`}}if(t.has(w))return`<${w}${b}>`;if(m){const e=i(o(h[g])??"");return`<textarea${b}>${e.startsWith("\n")?"\n":""}${e}</textarea>`}let O=d;if(k){const t=Boolean(o(h.multiple));O=g in h?{multiple:t,values:new Set([...e.selectionValues(o(h[g]),t)].map(i))}:void 0}const A=y(h.children,p,O);if(S&&d){const e=null==$||"function"==typeof $?A.replace(/<[^>]*>/g,"").replace(/[\t\n\f\r ]+/g," ").replace(/^ | $/g,""):i($);d.values.has(e)&&(b+=" selected",d.multiple||d.values.delete(e))}return`<${w}${b}>${A}</${w}>`},v=()=>e.runDisposal(e=>{e(f.dispose),e(()=>d.dispose())});let w;try{w=y(u,d),c.hydration&&(w+=e.serializeHydrationState(f.snapshots(),p))}catch(t){e.throwAfterDisposal(t,v)}return v(),w};
|
package/dist/cjs/store-view.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type StoreRefs<R extends RecordAny> = {
|
|
|
24
24
|
};
|
|
25
25
|
type EmptyRecord = {};
|
|
26
26
|
declare const STORE_OPTIONS: unique symbol;
|
|
27
|
+
declare const STORE_RELEASE: unique symbol;
|
|
28
|
+
declare const STORE_LOCAL: unique symbol;
|
|
27
29
|
declare const STORE_TYPES: unique symbol;
|
|
28
30
|
/**---
|
|
29
31
|
* ## 
|
|
@@ -76,7 +78,7 @@ export interface StoreOptions<S extends RecordAny, A extends RecordAny, R extend
|
|
|
76
78
|
refs?: R;
|
|
77
79
|
/** Inline action factory, one `createActs` slice, or an array of slices. */
|
|
78
80
|
acts?: ((context: StoreActsContext<S, R, D>) => A) | StoreActsPart<S, A, R, D> | readonly StoreActsPart<S, A, R, D>[];
|
|
79
|
-
/** Prepares the first client render and may return
|
|
81
|
+
/** Prepares the first client render and may return cleanup for this store's lifetime. */
|
|
80
82
|
setup?: (context: StoreSetupContext<S, A, R, D>) => void | (() => void);
|
|
81
83
|
/**
|
|
82
84
|
* Connects client resources when the first consuming view mounts.
|
|
@@ -99,6 +101,8 @@ export interface StoreOptions<S extends RecordAny, A extends RecordAny, R extend
|
|
|
99
101
|
export interface StoreDefinition<S extends RecordAny, A extends RecordAny = EmptyRecord, R extends RecordAny = EmptyRecord, D extends readonly AnyStore[] = readonly []> {
|
|
100
102
|
readonly [STORE_OPTIONS]: StoreOptions<any, any, any, any>;
|
|
101
103
|
readonly dependencies: D;
|
|
104
|
+
[STORE_RELEASE]?: () => void;
|
|
105
|
+
readonly [STORE_LOCAL]?: boolean;
|
|
102
106
|
readonly [STORE_TYPES]: {
|
|
103
107
|
readonly state: S;
|
|
104
108
|
readonly acts: A;
|
|
@@ -108,10 +112,12 @@ export interface StoreDefinition<S extends RecordAny, A extends RecordAny = Empt
|
|
|
108
112
|
/**---
|
|
109
113
|
* ## 
|
|
110
114
|
* ### ***store***:
|
|
111
|
-
* declares a lazy store
|
|
115
|
+
* declares a lazy store for an application or a component instance.
|
|
112
116
|
* @description
|
|
113
|
-
*
|
|
114
|
-
*
|
|
117
|
+
* A descriptor declared outside a component is shared within each app and
|
|
118
|
+
* disposed with the app. A store declared while a JSX component renders
|
|
119
|
+
* belongs to that component instance: it survives parent updates at the
|
|
120
|
+
* same position and is disposed when the component leaves the tree.
|
|
115
121
|
* @param options initial state, actions, refs and lifecycle callbacks.
|
|
116
122
|
* @param dependencies optional stores available in actions and lifecycle callbacks.
|
|
117
123
|
* @returns the descriptor to pass to components or other stores.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createNexus as e}from"nexus-state";import{L as t}from"./types-DkNQRHR2.js";function n(e){let t;const n=e=>{try{e()}catch(e){(t??(t=[])).push(e)}};if(n(()=>e(n)),1===t?.length)throw t[0];if(t)throw new AggregateError(t,"nexus-dom: Multiple errors during cleanup.")}function r(e,t){try{t()}catch(t){throw new AggregateError([e,t],"nexus-dom: Rendering and cleanup failed.")}}function s(e,t){throw r(e,t),e}function o(e,t){try{e?.dispose()}finally{for(const e of t)e.parentNode?.removeChild(e)}}class i extends Error{constructor(e,t){super(`[${e}]\n${t}`),this.code=e,this.name="nexus-dom"}}function a(e,t){return new i(e,t)}function c(e,t,n,r,s){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?s.call(e,n):s?s.value=n:t.set(e,n),n}function u(e,t,n){let r=new Set,s=!1;const o=new Proxy(e,{get:(e,t,s)=>(r&&t in e&&r.add(t),!r&&n&&Object.hasOwn(e,t)?n(t):Reflect.get(e,t,s)),has:(e,t)=>(t in e&&r?.add(t),Reflect.has(e,t)),ownKeys:e=>(r&&(s=!0),Reflect.ownKeys(e))});try{return{value:t(o),dependencies:s?["*"]:Array.from(r)}}finally{r=void 0}}function l(e,t){if(e.length!==t.length)return!1;const n=t;return e.every(e=>n.includes(e))}var d,f,h;"function"==typeof SuppressedError&&SuppressedError;const p=new WeakMap,y=new WeakMap,m=new WeakMap;function g(e,t){if(e===t)return!0;const n=m.get(e);return void 0!==n&&n===m.get(t)}const w=Symbol("nexus-dom.render-subscribe");function b(e){return w in e}function v(e,t,n){const r=e[w];return"function"==typeof r?r.call(e,t,n):e.subscribe(t)}function S(e,t,n,r,s){let o=!1;const i=(e,t)=>{if(!s)throw e;o=!0,s(e,t)};return{fail:i,update(s,a){let c;try{if(c=t(s),!o&&n(e,c))return}catch(e){return void i(e,a)}o=!1,e=c,r(c,a)}}}function A(e,t,n){return N(e,Boolean).branch(e=>e?t:n)}class I{constructor(e,t,n){this.source=e,this.project=t,this.isEqual=n,this[d]=!0}get(){return this.project(this.source.get())}subscribe(e){return this[w](e)}[(d=t,w)](e,t){const n=this.project(this.source.get()),{update:r,fail:s}=S(n,this.project,this.isEqual,e,t);return v(this.source,r,t?s:void 0)}map(e,t){return N(this,e,t)}if(e,t){return A(this,e,t)}branch(e,t){return M(this,e,t)}each(e){return L(this,e)}}const O=(e,t)=>null==e?void 0:e[t];class x{constructor(e,t){this.source=e,this.property=t}get[t](){return!0}get(){return O(this.source.get(),this.property)}subscribe(e){this.addListener(e);let t=!0;return()=>{t&&(t=!1,this.removeListener(e))}}addListener(e){const t=this.listeners;t?t instanceof Set?t.add(e):this.listeners=new Set([t,e]):this.listeners=e}removeListener(e){const t=this.listeners;t===e?this.listeners=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this.listeners=t.values().next().value))}update(e,t,n){const r=O(e,this.property),s=O(t,this.property);if(Object.is(r,s))return;const o=this.listeners;if(o)if(o instanceof Set)for(const e of Array.from(o))"function"==typeof e?e(s,n):e.notify(s,n);else"function"==typeof o?o(s,n):o.notify(s,n)}map(e,t){return N(this,e,t)}if(e,t){return A(this,e,t)}branch(e,t){return M(this,e,t)}each(e){return L(this,e)}}function E(e){return e instanceof x?e:void 0}function N(e,t,n=Object.is){return new I(e,t,n)}const T=Symbol("nexus-dom.mutable-current"),$=Symbol("nexus-dom.mutable-listeners"),D=Symbol("nexus-dom.mutable-fields");class _{constructor(e){this[f]=!0,this[T]=e}get(){return this[T]}subscribe(e){const t=this[$];t?t instanceof Set?t.add(e):this[$]=new Set([t,e]):this[$]=e;let n=!0;return()=>{if(!n)return;n=!1;const t=this[$];t===e?this[$]=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this[$]=t.values().next().value))}}map(e,t){return N(this,e,t)}if(e,t){return A(this,e,t)}branch(e,t){return M(this,e,t)}each(e){return L(this,e)}$field(e){const t=this[D];if(!t){const t=new x(this,e);return this[D]=t,t}if(t instanceof Map){let n=t.get(e);return n||(n=new x(this,e),t.set(e,n)),n}let n=t,r=1;for(;n.property!==e&&n.next;)n=n.next,r++;if(n.property===e)return n;const s=new x(this,e);if(n.next=s,4===r){const e=new Map;for(let n=t;n;n=n.next)e.set(n.property,n);this[D]=e}return s}set(e,t){const n=this[T];if(Object.is(n,e))return;this[T]=e;const r=this[$];if(r instanceof Set)for(const n of Array.from(r))n(e,t);else r&&r(e,t);const s=this[D];if(s)if(s instanceof Map)for(const r of s.values())r.update(n,e,t);else for(let r=s;r;r=r.next)r.update(n,e,t)}}f=t;const k={get(e,t,n){if(t!==w)return t in e?Reflect.get(e,t,n):e.$field(t)}};class C{constructor(e){h.set(this,void 0),c(this,h,e,"f")}get id(){const e=function(e,t){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}(this,h);return"string"==typeof e?e:c(this,h,e.id(),"f")}}function j(e,t){const n=new _(e);return{live:new Proxy(n,k),controller:n,row:new C(t)}}function M(e,t,n){return{kind:"dynamic",source:e,project:t,...n?.key?{key:n.key}:{}}}function L(e,t){const n=y.get(e);return{kind:"keyed",source:e,...void 0===n?{}:{stateKey:n},project:t}}function P(e,n,r=Object.is,s,o=e=>u(e,n)){const i={[t]:!0,get:()=>n(e.get()),subscribe:e=>i[w](e),[w](t,n){const s=o(e.get());let i=s.dependencies,a=!1,c=()=>{};const{update:u}=S(s.value,t=>{const n=o(t);if(!l(i,n.dependencies)){const t=c;i=n.dependencies,c=e.subscribe(d,i),t()}return n.value},r,t,n),d=(e,t)=>{a||u(e,t)};return c=e.subscribe(d,i),()=>{a||(a=!0,c())}},map(e,t){return N(this,e,t)},if(e,t){return A(this,e,t)},branch(e,t){return M(this,e,t)},each(e){return L(this,e)}};return void 0!==s&&y.set(i,s),i}function R(e){return"object"==typeof e&&null!==e&&!0===e[t]}function H(e,t,n,r){const s=P(e,t,n,void 0,r);return m.set(s,e),s}h=new WeakMap;const Y=new Set(["innerhtml","outerhtml","srcdoc","dangerouslysetinnerhtml"]),V=new Set(["href","src","action","formaction","poster","xlink:href","xlinkhref"]),F=new Set(["http:","https:","mailto:","tel:"]),U=e=>/^on[A-Z]/.test(e);function z(e,t,n){const r=t.toLowerCase();if(Y.has(r)||r.startsWith("on"))throw a("UNSAFE_DOM_PROPERTY",`Cannot use "${t}" as a DOM property. Use JSX children or a function event handler.`);if("boolean"==typeof n&&r.startsWith("aria-"))return String(n);if(null==n||!1===n||!0===n||!V.has(r)&&("data"!==r||"object"!==e.toLowerCase()))return n;const s=String(n);let o;try{o=new URL(s,"https://nexus.invalid/").protocol}catch{}if(!o||!F.has(o))throw a("UNSAFE_DOM_URL",`"${t}" requires a relative URL or an http, https, mailto or tel URL.`);return s}function W(e,t){return"textarea"===e&&("value"in t||"defaultValue"in t)}function J(e,t){return new Set(t&&Array.isArray(e)?e.map(String):[String(e??"")])}function q(e){const t=Array.from(e.options),n=t.filter(e=>e.defaultSelected);if(e.multiple)return n;if(n.length)return n.slice(-1);if(e.size>1)return[];const r=t.find(e=>!(e.disabled||"optgroup"===e.parentElement?.localName&&e.parentElement.hasAttribute("disabled")));return r?[r]:[]}function K(e,t){if("checked"===t&&"input"===e.localName){const t=e;return t.checked!==t.defaultChecked}if("value"!==t)return!1;if("input"===e.localName||"textarea"===e.localName){const t=e;return t.value!==t.defaultValue}if("select"===e.localName){const t=e,n=q(t),r=t.selectedOptions;return r.length!==n.length||n.some((e,t)=>e!==r[t])}return!1}const B=Symbol("nexus-dom.owner-mounted"),G=e=>{"function"==typeof e?e():e.dispose()};class X{constructor(e,t=!0,n){this.parent=e,this.disposed=!1,this.nextIdChild=0,this.localStoreIndex=0,this.ids=e?.ids??{prefix:n??"r0",symbolIds:void 0,nextSymbolId:0,claims:void 0,localStores:void 0},this.idPath=e?`${e.idPath}/${n??e.reserveIdSegment("o")}`:"",e&&t&&(e.children??(e.children=new Set)).add(this)}setComponentIdentity(e,t){this.componentIdentity={type:e,key:t}}hasComponentIdentity(){return void 0!==this.componentIdentity}acquireLocalStore(e,t){var n;const r=this.componentIdentity;if(!r)return e();const s=(n=this.ids).localStores??(n.localStores=new Map),o=s.get(this.idPath)??[];let i=o.find(e=>e.type===r.type&&Object.is(e.key,r.key));i||(i={...r,slots:[]},o.push(i),s.set(this.idPath,o));const a=this.localStoreIndex++;let c=i.slots[a];c||(c={value:e(),claims:0,release:e=>t(e)},i.slots[a]=c),c.claims++;const u=c,l=i;return this.addCleanup(()=>{if(!(--u.claims>0)){l.slots[a]=void 0;try{u.release(u.value)}finally{if(l.slots.every(e=>!e)){const e=o.indexOf(l);e>=0&&o.splice(e,1),0===o.length&&s.delete(this.idPath)}}}}),c.value}reserveIdSegment(e){return`${e}${(this.nextIdChild++).toString(36)}`}keyedIdSegment(e,t){return"object"==typeof t?`${e}/a${t.slot.toString(36)}`:`${e}/k${((e,t)=>{if("string"==typeof e)return`s${e.length}:${e}`;if("number"==typeof e)return Object.is(e,-0)?"n:-0":`n:${String(e)}`;const n=Symbol.keyFor(e);if(void 0!==n)return`g${n.length}:${n}`;const r=t.symbolIds??(t.symbolIds=new Map);let s=r.get(e);return void 0===s&&(s=t.nextSymbolId++,r.set(e,s)),`y:${s.toString(36)}`})(t,this.ids)}`}id(){var e;const t=`v2\0${this.ids.prefix}\0${this.idPath}`,n=(e=>{let t=3735928559,n=1103547991;for(let r=0;r<e.length;r++){const s=e.charCodeAt(r);t=Math.imul(t^s,2654435761),n=Math.imul(n^s,1597334677)}t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909);let r=4294967296*(2097151&n)+(t>>>0),s="";for(let e=0;e<7;e++)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[r%62]+s,r=Math.floor(r/62);return s})(t),r=(e=this.ids).claims??(e.claims=new Map),s=r.get(n);if(void 0!==s&&s.identity!==t)throw a("ID_HASH_COLLISION","Component id hash collision.");const o=s??{identity:t,owners:this};return s?s.owners instanceof Set?s.owners.add(this):s.owners!==this&&(s.owners=new Set([s.owners,this])):r.set(n,o),this.addCleanup(()=>{r.get(n)===o&&(o.owners instanceof Set?(o.owners.delete(this),0===o.owners.size?r.delete(n):1===o.owners.size&&(o.owners=o.owners.values().next().value)):o.owners===this&&r.delete(n))}),`nxs-${n}`}addCleanup(e){if(this.disposed)return void G(e);const t=this.cleanups;t?Array.isArray(t)?t.push(e):this.cleanups=[t,e]:this.cleanups=e}addMount(e){if(this.disposed)return;if(this.mounts===B)return void e();const t=this.mounts;t?Array.isArray(t)?t.push(e):this.mounts=[t,e]:this.mounts=e}isMounted(){return this.mounts===B}mount(){if(this.disposed||this.mounts===B)return;const e=this.mounts;if(this.mounts=B,Array.isArray(e))for(const t of e)t();else e?.();if(this.children)for(const e of this.children)e.mount()}setErrorHandler(e){this.errorHandler=e}handleError(e){if(this.errorHandler)try{return this.errorHandler(e),!0}catch(e){if(this.parent)return this.parent.handleError(e);throw e}return this.parent?.handleError(e)??!1}dispose(){if(this.disposed)return;this.disposed=!0,this.mounts=void 0;const e=this.cleanups;if(!this.children?.size&&!Array.isArray(e))return this.children=void 0,this.cleanups=void 0,this.parent?.children?.delete(this),void(e&&G(e));n(t=>{if(this.children){for(const e of Array.from(this.children))t(()=>e.dispose());this.children.clear(),this.children=void 0}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=e[n];"function"==typeof r?t(r):r&&t(()=>r.dispose())}e.length=0}else"function"==typeof e?t(e):e&&t(()=>e.dispose());this.cleanups=void 0,this.parent?.children?.delete(this)})}}let Z;function Q(e,t){const n=Z;Z=e;try{return t()}finally{Z=n}}function ee(){if(!Z)throw a("ID_OUTSIDE_COMPONENT","Component ids can only be created while a component is mounting.");const e=Z;let t;return()=>t??(t=e.id())}function te(e){if(!Z)throw a("CLEANUP_OUTSIDE_COMPONENT","onCleanup() must run inside a component.");Z.addCleanup(e)}function ne(e){if(null===e||"object"!=typeof e)return;const t=e.id;return"string"==typeof t||"number"==typeof t||"symbol"==typeof t?t:void 0}function re(e,t){const n=e.map(ne),r=new Set,s=new Set;for(const e of n)void 0!==e&&(r.has(e)&&s.add(e),r.add(e));return n.map((n,r)=>void 0===n||s.has(n)?t(e[r]):n)}let se=1;const oe=new WeakMap,ie=new WeakMap,ae=new WeakMap;let ce=1;const ue=Symbol("nexus-dom.no-list-payload");function le(e){let t=ie.get(e);return void 0===t&&ie.set(e,t=ce++),t}function de(e,t=ue){const n={...e,id:se++};return t!==ue&&oe.set(n,t),n}function fe(e,t,n=!1){const r=n?t:t-1;if(!Number.isInteger(e)||e<0||e>r)throw a("INVALID_LIST_INDEX",r<0?`List index ${e} is invalid. The list is empty.`:`List index ${e} is outside 0..${r}.`)}function he(e,t,n,r){if(void 0===t||!e||"object"!=typeof e)return;const s=e.meta;if(!s||"object"!=typeof s)return;const o=s.nexusDOM;if(!o||"object"!=typeof o)return;const i=o.list;if(!i||"object"!=typeof i)return;const a=i,c=ae.get(a);return c&&a.key===t&&c.before===ie.get(n)&&c.after===ie.get(r)?a:void 0}function pe(e){return oe.get(e)}function ye(e){return oe.has(e)}const me="nxs:t",ge="nxs:/",we=e=>`\x3c!--${me}--\x3e${e}\x3c!--${ge}--\x3e`,be="nxs:s",ve=(e,t,n)=>{if(null===e||"string"==typeof e||"boolean"==typeof e)return;if("number"==typeof e){if(Number.isFinite(e))return;throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} must be a finite number.`)}if("object"!=typeof e)throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains unsupported ${typeof e}.`);if(n.has(e))throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a cycle.`);const r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&null!==r)throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} must contain only plain objects and arrays.`);if(n.add(e),Array.isArray(e))for(let r=0;r<e.length;r++)ve(e[r],`${t}[${r}]`,n);else{if(Object.getOwnPropertySymbols(e).length>0)throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a symbol key.`);for(const[r,s]of Object.entries(e))ve(s,`${t}.${r}`,n)}n.delete(e)},Se=e=>{if(!e||"object"!=typeof e)return!1;const t=e;if(Array.isArray(t.keys)&&t.keys.every(e=>"string"==typeof e)&&t.state&&"object"==typeof t.state&&!Array.isArray(t.state)){const e=[...t.keys].sort(),n=Object.keys(t.state).sort();return e.length===n.length&&e.every((e,t)=>e===n[t])}return!1},Ae=e=>{let t;try{t=JSON.parse(e)}catch{throw a("HYDRATION_STATE_INVALID","Hydration state is not valid JSON.")}if(!t||"object"!=typeof t||1!==t.v||"idPrefix"in t&&"string"!=typeof t.idPrefix||!Array.isArray(t.stores)||!t.stores.every(Se))throw a("HYDRATION_STATE_INVALID","Hydration state does not match the supported versioned payload.");return t},Ie=(e,t)=>{let n;e.forEach((e,t)=>ve(e.state,`stores[${t}].state`,new Set));try{n=JSON.stringify({v:1,idPrefix:t,stores:e})}catch(e){throw a("HYDRATION_STATE_INVALID",`Hydration state could not be serialized: ${String(e)}`)}Ae(n);const r=n.replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`).replaceAll("--","-\\u002d");return`\x3c!--${be}${r}--\x3e`},Oe=(e,t)=>{const n=Array.from(e.childNodes).filter(e=>8===e.nodeType&&(e.nodeValue??"").startsWith(be));if(0===n.length)return;if(1!==n.length)throw a("HYDRATION_STATE_INVALID","Hydration root must contain at most one nxs:s payload.");const r=n[0],s=Ae((r.nodeValue??"").slice(5));if(void 0!==t&&void 0!==s.idPrefix&&t!==s.idPrefix)throw a("HYDRATION_STATE_INVALID","The client idPrefix does not match the server's. Omit it to use the server prefix.");return r.parentNode?.removeChild(r),s},xe=Symbol("nexus-dom.store-options"),Ee=Symbol("nexus-dom.store-release"),Ne=Symbol("nexus-dom.store-local");function Te(e){return e}function $e(e,t=[]){return n=n=>({[xe]:e,dependencies:t,[Ne]:n}),r=e=>e[Ee]?.(),Z?.hasComponentIdentity()?Z.acquireLocalStore(()=>n(!0),r):n(!1);var n,r}function De(e,t=[]){const n=Array.isArray(t),r=n?void 0:ke(new Map,t);return s=>({kind:"store-view",dependencies:n?t:[],...r?{registry:r}:{},input:s,render:e,getId:ee()})}function _e(e){const t=ke(new Map,e);return(e,n)=>{const r=n?ke(new Map(t),n):t;return t=>({kind:"store-view",dependencies:[],registry:r,render:e,input:t,getId:ee()})}}function ke(e,t){if(Array.isArray(t))throw a("STORE_DEPENDENCY_CONFLICT","Use an object with named store dependencies.");for(const[n,r]of Object.entries(t)){if(""===n)throw a("STORE_DEPENDENCY_CONFLICT",`Store namespace "${n}" is reserved.`);if(e.has(n))throw a("STORE_DEPENDENCY_CONFLICT",`Store namespace "${n}" is already defined.`);e.set(n,[r])}return e}const Ce=(e,n)=>{const r=function(e){const t=p.get(e);if(t)return t;const n=new Map,r=new Proxy(Object.create(null),{get(t,r){let s=n.get(r);return s||(s=P(e,e=>e[r],Object.is,r),n.set(r,s)),s}});return p.set(e,r),r}(e),s=new Map;return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;let i=s.get(o);if(i)return i;const a=r[o],c=n(o);return c?(i={[t]:!0,get:()=>a.get(),subscribe:e=>a.subscribe(e),[w]:(e,t)=>v(a,e,t),map:(e,t)=>a.map(e,t),if:(e,t)=>a.if(e,t),branch:(e,t)=>a.branch(e,t),each:a.each.bind(a),set(e,t="$.set"){"function"==typeof e?c.nexus.set(t=>({[o]:e(t[o])}),t):c.nexus.set({[o]:e},t)}},s.set(o,i),i):a}})};function je(t={}){const r=new Map,o=[],i=new WeakMap,c=new Set,l=[];let d,f=0,h=!1;const p=e=>Object.keys(e).sort(),y=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),m=i=>{const u=r.get(i);if(u)return u;if(c.has(i))throw a("STORE_DEPENDENCY_CYCLE","Store dependencies contain a cycle. Move shared state into a third store or remove one dependency.");c.add(i);const m=i[xe];let g=!1;try{const c=w(i.dependencies),u={get:e=>{const t=c.source.get();return void 0===e?t:t[e]},$:c.$,select:c.select,acts:c.acts,refs:c.refs},v=(b=m.refs??{},Object.fromEntries(Object.entries(b).map(([e,t])=>[e,{current:t}]))),S=p(m.state),A=d?.[f];let I=m.state;if(d){if(!A||!A.state||"object"!=typeof A.state||Array.isArray(A.state)||!y(S,[...A.keys].sort())||!y(S,p(A.state)))throw a("HYDRATION_STATE_INVALID",`Hydration snapshot ${f} does not match store keys ${JSON.stringify(S)}.`);I=A.state,f++,g=!0}const O="function"==typeof m.acts?[m.acts]:m.acts,x=O&&O.length>1?new Map:void 0;let E,N;N=e(O?{state:I,acts:O.map((e,t)=>function(n,r){E??(E=function(e,t){const n=new Map;return{list(r){const s=n.get(r);if(s)return s;let o;const i=()=>{const t=o?.items??e(r);if(!Array.isArray(t))throw a("INVALID_LIST_FIELD",`The state field "${String(r)}" must be an array to use list().`);return t},c=(e,t,n)=>{if(o)return o.items=t,void o.operations.push(n);u(e,t,n)},u=(e,n,s)=>{ae.set(s,{before:le(e),after:le(n)}),t({[r]:n},(e=>({source:`list.${e.type}`,meta:{nexusDOM:{list:e}}}))(s))},l={append(...e){if(0===e.length)return;const t=i();c(t,[...t,...e],de({key:r,type:"insert",index:t.length,count:e.length},[...e]))},insert(e,...t){if(0===t.length)return;const n=i();fe(e,n.length,!0),c(n,[...n.slice(0,e),...t,...n.slice(e)],de({key:r,type:"insert",index:e,count:t.length},[...t]))},remove(e,t=1){const n=i();if(fe(e,n.length),!Number.isInteger(t)||t<1||e+t>n.length)throw a("INVALID_LIST_REMOVE_COUNT",`Cannot remove ${t} item(s) from index ${e} in a list of ${n.length}.`);c(n,[...n.slice(0,e),...n.slice(e+t)],de({key:r,type:"remove",index:e,count:t}))},move(e,t){const n=i();if(fe(e,n.length),fe(t,n.length),e===t)return;const s=[...n],[o]=s.splice(e,1);s.splice(t,0,o),c(n,s,de({key:r,type:"move",from:e,to:t}))},replace(e,t){const n=i();fe(e,n.length);const s=[...n];s[e]=t,c(n,s,de({key:r,type:"replace",index:e},t))},reverse(){const e=i();e.length<2||c(e,[...e].reverse(),de({key:r,type:"reorder"}))},batch(e){if(o)return void e(l,i);const t=i(),n={items:[...t],operations:[]};o=n;try{e(l,i)}finally{o=void 0}if(0===n.operations.length)return;if(i()!==t)throw a("LIST_BATCH_CONFLICT",`The "${String(r)}" array changed during list.batch(). Update it using the batch commands, or call set() outside the batch.`);const s=de({key:r,type:"batch",operations:n.operations});u(t,n.items,s)}};return n.set(r,l),l}}}(n,r));const s=e.call(this,{get:n,set:r,reset:(...e)=>N.reset(...e),refs:v,list:E.list,dependencies:u});if(x&&s)for(const e of Object.keys(s)){const n=x.get(e);if(void 0!==n)throw a("DUPLICATE_ACTION",`Action "${e}" appears in slices ${n+1} and ${t+1}. Give each action in store({ acts }) a unique name.`);x.set(e,t)}return s})}:{state:I});const T={nexus:N,refs:v};let $;if(r.set(i,T),o.push(T),i[Ne]&&(i[Ee]=()=>{if(delete i[Ee],!r.delete(i))return;const e=o.indexOf(T);e>=0&&o.splice(e,1),$?.()}),!1!==t.runSetup&&(m.setup||m.mount)){const e=new Set,t=t=>(e.add(t),()=>e.delete(t));$=()=>{n(t=>{for(const n of Array.from(e).reverse())t(n);e.clear()})};const a=()=>({nexus:N,$:Ce(N,()=>T),select:(e,t)=>H(N,e,t),acts:N.acts,refs:v,dependencies:u,onCleanup:t});try{const t=m.setup?.(a());t&&e.add(t),i[Ne]||l.push($)}catch(e){r.delete(i),o.at(-1)===T&&o.pop(),delete i[Ee],s(e,$)}let d=m.mount;(d||c.mount)&&(T.mount=()=>{if(h)return;if(c.mount?.(),h)return;const t=d;if(d=void 0,!t)return;const r=new Set,o=()=>{n(e=>{for(const t of Array.from(r).reverse())e(t);r.clear()})};try{const e=t({...a(),onCleanup:e=>(r.add(e),()=>r.delete(e))});e&&r.add(e)}catch(e){s(e,o)}h?o():e.add(o)})}else c.mount&&(T.mount=c.mount);return T}catch(e){throw g&&f--,e}finally{c.delete(i)}var b},g=(e,t,n)=>{for(const[r,s]of Object.entries(t)){if(Object.prototype.hasOwnProperty.call(e,r))throw a("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same ${n} key "${r}".`);e[r]=s}},w=e=>{const t=i.get(e);if(t)return t;const n=e.map(e=>m(e)),r={},s={},o=new Map,c=new Map;for(const e of n){const t=e.nexus.get();o.set(e,new Set(Object.keys(t)));for(const n of Object.keys(t)){if(c.has(n))throw a("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same state key "${n}".`);c.set(n,e)}g(r,e.nexus.acts,"acts"),g(s,e.refs,"refs")}const u={get(){const e={};for(const t of n)g(e,t.nexus.get(),"state");return e},subscribe(e,t){const r=n.flatMap(n=>{const r=o.get(n),s="*"===t[0]?["*"]:t.filter(e=>r.has(String(e)));return 0===s.length?[]:[n.nexus.subscribe((t,n)=>e(u.get(),n),s)]});return()=>r.forEach(e=>e())}};u.get();const l=n.flatMap(e=>e.mount?[e.mount]:[]),d={source:u,readField:e=>"string"==typeof e?c.get(e)?.nexus.get(e):void 0,$:Ce(u,e=>c.get(e)),select:(e,t)=>H(u,e,t),acts:r,refs:s};return l.length&&(d.mount=()=>l.forEach(e=>e())),i.set(e,d),d};return{restore(e){if(r.size>0)throw a("HYDRATION_STATE_LATE","Hydration state must be restored before the first lazy store is resolved.");d=e,f=0},completeRestore(){if(d&&f!==d.length)throw a("HYDRATION_STATE_INVALID",`Hydration provided ${d.length} store snapshots, but the view resolved ${f}.`);d=void 0},snapshots:()=>o.map(({nexus:e})=>{const t=e.get();return{keys:p(t),state:t}}),resolve(e){if(e.registry)return((e,t)=>{const n=new Map;let r=!1;const s=e=>{let s=n.get(e);if(s)return s;if(h)throw a("APP_DISPOSED","Cannot resolve a store after app disposal.");return s=w(t.get(e)),n.set(e,s),r&&s.mount?.(),s},o=(e,n=Object.create(null))=>new Proxy(n,{get:(n,r)=>"string"==typeof r&&t.has(r)?e(r):Reflect.get(n,r),has:(e,n)=>"string"==typeof n&&t.has(n)||Reflect.has(e,n),ownKeys:e=>[...t.keys(),...Reflect.ownKeys(e)],getOwnPropertyDescriptor:(n,r)=>"string"==typeof r&&t.has(r)?{enumerable:!0,configurable:!0,get:()=>e(r)}:Reflect.getOwnPropertyDescriptor(n,r)}),i=(e=e=>s(e).source.get(),t)=>{let n;return o(r=>{if(t&&!t())return s(r).source.get();let o=n?.get(r);return o||(o=e(r),(n??(n=new Map)).set(r,o)),o})},c={get:()=>i(),subscribe(e,t){const n=t.map(t=>s(t).source.subscribe((t,n)=>e(i(),n),["*"]));return()=>n.forEach(e=>e())}},u={get:c.get,subscribe(e,t){const n=new Map;for(const e of t){const[t,r]=JSON.parse(e);let s=n.get(t);s||n.set(t,s=[]),s.push(r??"*")}const r=Array.from(n,([t,n])=>s(t).source.subscribe((t,n)=>e(i(),n),n));return()=>r.forEach(e=>e())}},l=o(e=>s(e).$),d=(e,t)=>H(u,e,t,()=>(e=>{const t=new Map,n=e(i(e=>{const n=new Set;t.set(e,n);const r=r=>{"string"==typeof r?n.add(r):t.set(e,null)};return new Proxy(s(e).source.get(),{get:(e,t,n)=>(r(t),Reflect.get(e,t,n)),has:(e,t)=>(r(t),Reflect.has(e,t)),getOwnPropertyDescriptor:(e,t)=>(r(t),Reflect.getOwnPropertyDescriptor(e,t)),ownKeys:n=>(t.set(e,null),Reflect.ownKeys(n))})})),r=[];for(const[e,n]of t)if(n?.size)for(const t of n)r.push(JSON.stringify([e,t]));else r.push(JSON.stringify([e,null]));return{value:n,dependencies:r}})(e)),f=o(e=>s(e).acts),p=o(e=>s(e).refs),y=t=>e.render({get id(){return e.getId()},state:t,$:l,select:d,acts:f,refs:p},e.input);return{kind:"tracked-view",source:c,project:y,track:()=>(e=>{let t=new Set;try{return{value:e(i(e=>(t?.add(e),s(e).source.get()),()=>void 0!==t)),dependencies:[...t]}}finally{t=void 0}})(y),mountStores(){r=!0;for(const e of n.values())e.mount?.()}}})(e,e.registry);const t=w(e.dependencies),n=n=>e.render({get id(){return e.getId()},state:n,$:t.$,select:t.select,acts:t.acts,refs:t.refs},e.input);return{kind:"tracked-view",source:t.source,...t.mount?{mountStores:t.mount}:{},project:n,track:()=>u(t.source.get(),n,t.readField)}},dispose(){h||(h=!0,n(e=>{for(let t=l.length-1;t>=0;t--)e(l[t]);l.length=0,r.clear(),o.length=0}))}}}export{E as A,b as B,g as C,Oe as D,De as E,_e as F,Te as G,te as H,$e as I,i as N,X as O,me as T,U as a,z as b,j as c,J as d,je as e,n as f,W as g,we as h,R as i,v as j,ne as k,he as l,pe as m,a as n,ye as o,K as p,q,re as r,Ie as s,s as t,u,o as v,Q as w,l as x,r as y,ge as z};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{persist as e}from"nexus-state";import{f as t,t as n,j as r,k as o,r as s,l as i,O as c,c as d,m as l,o as a,b as u,d as f,p,q as h,u as y,v,x as m,y as g,N as w,i as k,T as b,z as x,w as N,n as S,g as A,a as C,A as T,B as j,C as O,D,e as M}from"./chunks/store-view-BaScxKX5.js";export{E as component,F as componentScope,G as createActs,H as onCleanup,I as store}from"./chunks/store-view-BaScxKX5.js";import"./chunks/types-DkNQRHR2.js";function P(e){return Array.isArray(e)?e[0]:e}function _(e){try{e.owner.dispose()}finally{!function(e){if(Array.isArray(e))for(const t of e)t.parentNode?.removeChild(t);else e.parentNode?.removeChild(e)}(e.nodes)}}function B(e,t){if(function(e){return Array.isArray(e)?e.at(-1):e}(e.nodes).nextSibling===t)return;const n=t.parentNode;if(!n)return;const r=Array.isArray(e.nodes)?e.nodes:[e.nodes];for(const e of r)n.moveBefore?n.moveBefore(e,t):n.insertBefore(e,t)}function R(e){const t=[],n=new Array(e.length).fill(-1);for(let r=0;r<e.length;r++){const o=e[r];if(void 0===o||o<0)continue;let s=0,i=t.length;for(;s<i;){const n=s+i>>1,r=t[n];(void 0===r?-1:e[r]??-1)<o?s=n+1:i=n}s>0&&(n[r]=t[s-1]??-1),t[s]=r}const r=new Set;let o=t.at(-1)??-1;for(;o>=0;)r.add(o),o=n[o]??-1;return r}function V(e,t){return!!t&&(Array.isArray(e.nodes)?e.nodes:[e.nodes]).some(e=>e===t||e.nodeType===Node.ELEMENT_NODE&&e.contains(t))}function $({target:e,owner:u,vnode:f,scheduler:p,renderInto:h,reconcileView:y,register:v,preparePatch:m,hydration:g}){const w=e.ownerDocument??e,k=v?w.createTextNode(""):void 0,b=w.createTextNode("");k&&e.insertBefore(k,g?g.node:null),g||e.appendChild(b);const x={},N=new Map;let S,A,E,C=[],T=!0,I=f.source,j=I,O=I.get(),D=O,M=O,$=!1,L=!1,q=f.project,F=q,H=g?void 0:w.createDocumentFragment(),W=g?.node,U=void 0!==g;const J=u.reserveIdSegment("l");let z=0;const G=()=>({slot:z++}),Y=(t,r)=>{const o=new c(u,!1,u.keyedIdSegment(J,t)),s=d(r,o),i=v?{key:t,owner:o,nodes:b,controller:s.controller,live:s.live,row:s.row,view:void 0}:{key:t,owner:o,nodes:b,controller:s.controller};try{const t=q(s.live,s.row);if(v&&(m(o),i.view=t),U){const n=W?W.previousSibling:e.lastChild;W=g.hydrateInto(t,e,i.owner,W??null);const r=[];let o=n?n.nextSibling:e.firstChild;for(;o&&o!==W;)r.push(o),o=o.nextSibling;if(0===r.length){const t=w.createTextNode("");e.insertBefore(t,W??null),r.push(t)}i.nodes=1===r.length?r[0]:r}else if(H)i.nodes=((e,t)=>{const n=H,r=n.lastChild;h(e,n,t),n.lastChild===r&&n.appendChild(w.createTextNode(""));const o=r?r.nextSibling:n.firstChild;if(!o.nextSibling)return o;const s=[];let i=o;for(;i;)s.push(i),i=i.nextSibling;return s})(t,i.owner);else{const e=function(e,t,n,r){const o=e.createDocumentFragment();return r(t,o,n),0===o.childNodes.length&&o.appendChild(e.createTextNode("")),{fragment:o,nodes:1===o.childNodes.length?o.firstChild:Array.from(o.childNodes)}}(w,t,i.owner,h);i.nodes=e.nodes,b.parentNode?.insertBefore(e.fragment,b),u.isMounted()&&i.owner.mount()}}catch(e){n(e,()=>{U||i.nodes===b?i.owner.dispose():_(i)})}return i};u.addMount(()=>{for(const e of C)e.owner.mount()});const K=(e,t)=>{let n=-1;if(e.every(e=>{const r=t.get(e.key);return!(void 0===r||r<=n||(n=r,0))}))return void(C=e);const r=e.map(e=>t.get(e.key)??-1),o=b.parentNode,s=w.activeElement,i=o?.moveBefore?-1:e.findIndex(e=>V(e,s)),c=function(e,t){const n=void 0===t?void 0:e[t];if(void 0===t||void 0===n||n<0)return R(e);const r=e.map((e,r)=>r<t&&e<n?e:-1),o=e.map((e,r)=>r>t&&e>n?e:-1);return new Set([...R(r),t,...R(o)])}(r,i<0?void 0:i);for(let t=e.length-1;t>=0;t--){const n=e[t],o=e[t+1];-1!==r[t]&&c.has(t)||B(n,o?P(o.nodes):b)}C=e},X=(t,n,r)=>{if(!H&&!U&&t.length===C.length&&C.every((e,n)=>o(t[n])===e.key))return void C.forEach((e,n)=>{Object.is(e.controller.get(),t[n])||e.controller.set(t[n],r)});const i=[];let c,d;for(const e of C){if("object"!=typeof e.key)continue;const t=e.controller.get();c??(c=new Map),c.set(t,c.has(t)?null:e)}if(c){d=new Map;for(const e of t)d.set(e,(d.get(e)??0)+1)}const l=s(t,e=>{const t=c?.get(e);return t&&1===d?.get(e)&&Object.is(t.controller.get(),e)?t.key:G()}),a=new Set(l),u=new Map(C.map((e,t)=>[e.key,t]));l.forEach((e,n)=>{const o=t[n];let s=N.get(e);s?Object.is(s.controller.get(),o)||s.controller.set(o,r):(s=Y(e,o),N.set(e,s)),i.push(s)});for(const[e,t]of N)a.has(e)||(N.delete(e),n(()=>_(t)));return H?(b.parentNode?.insertBefore(H,b),H=void 0,void(C=i)):U?(e.insertBefore(b,W??null),U=!1,void(C=i)):void K(i,u)},Q=(e,t,n,r,s=!0)=>{if("batch"===e.type){for(const o of e.operations)if(!Q(o,t,n,r,!1))return!1;return!s||C.length===t.length}if("insert"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.index>C.length||e.count<1)return!1;if(s&&t.length!==C.length+e.count)return!1;const n=l(e);if(!Array.isArray(n)||n.length!==e.count)return!1;const r=n.map(e=>({item:e,key:o(e)??G()})),i=new Set;for(const{key:e}of r){if(N.has(e)||i.has(e))return!1;i.add(e)}const c=[];for(const{item:e,key:t}of r){const n=Y(t,e);N.set(t,n),c.push(n)}C.splice(e.index,0,...c);let d=C[e.index+c.length]?P(C[e.index+c.length].nodes):b;for(let e=c.length-1;e>=0;e--){const t=c[e];t&&(B(t,d),d=P(t.nodes))}return!0}if("remove"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.count<1||e.index+e.count>C.length)return!1;if(s&&t.length!==C.length-e.count)return!1;const r=C.splice(e.index,e.count);if(r.length!==e.count)return!1;for(const e of r)N.delete(e.key),n(()=>_(e));return!0}if("move"===e.type){if(!Number.isInteger(e.from)||!Number.isInteger(e.to)||e.from<0||e.from>=C.length||e.to<0||e.to>=C.length)return!1;if(s&&t.length!==C.length)return!1;const n=C[e.from];if(!n)return!1;if(s){const r=t[e.to];if(!("object"==typeof n.key?Object.is(r,n.controller.get()):o(r)===n.key))return!1}const r=b.parentNode,i=w.activeElement;if(!r?.moveBefore&&V(n,i)){if(e.from>e.to){let t=C[e.from+1]?P(C[e.from+1].nodes):b;for(let n=e.from-1;n>=e.to;n--){const e=C[n];e&&(B(e,t),t=P(e.nodes))}}else{const t=P(n.nodes);for(let n=e.from+1;n<=e.to;n++){const e=C[n];e&&B(e,t)}}return C.splice(e.from,1),C.splice(e.to,0,n),!0}return C.splice(e.from,1),C.splice(e.to,0,n),B(n,C[e.to+1]?P(C[e.to+1].nodes):b),!0}if("replace"===e.type){if(!Number.isInteger(e.index)||e.index<0||e.index>=C.length)return!1;if(s&&t.length!==C.length)return!1;const i=C[e.index],c=l(e);if(!i||!a(e))return!1;const d=o(c)??("object"==typeof i.key?i.key:G());if(d===i.key)return i.controller.set(c,r),!0;if(N.has(d))return!1;const u=Y(d,c);return N.delete(i.key),n(()=>_(i)),N.set(d,u),C[e.index]=u,B(u,C[e.index+1]?P(C[e.index+1].nodes):b),!0}if("reorder"===e.type){if(s&&t.length!==C.length)return!1;const e=new Map(C.map((e,t)=>[e.key,t]));return K([...C].reverse(),e),!0}return!1};try{t(e=>X(O,e))}catch(e){n(e,Z)}function Z(){t(e=>{for(const t of N.values())e(()=>_(t));N.clear(),C=[],k&&k.parentNode?.removeChild(k),b.parentNode?.removeChild(b)})}function ee(){L=!0,p.enqueue(x,te,A,e=>u.handleError(e))}function te(){if(L=!1,!T)return;if(j!==I){const e=j,t=e.get(),n=re(e);ne(),I=e,ne=n,E=void 0,O=t,S=void 0,$=t!==D&&(!D||D.length!==t.length||t.some((e,t)=>!Object.is(e,D[t]))),$||(D=t)}if(E)throw E.error;const e=A;A=void 0;const n=F===q?void 0:new Set(C);q=F;const r=M===D?S:void 0,o=O,s=$;$=!1,S=void 0,t(t=>{if(s&&(D=void 0,(Array.isArray(r)?r.every((n,s)=>Q(n,o,t,e,s===r.length-1)):r&&Q(r,o,t,e))||X(o,t,e),D=o),n)for(let e=0;e<C.length;e++){const r=C[e];if(!n.has(r))continue;const o=q(r.live,r.row),s=Array.isArray(r.nodes)?r.nodes:[r.nodes];if(y(r.view,o,s,r.owner)){r.view=o;continue}const i=Y(r.key,r.controller.get());B(i,P(r.nodes)),N.set(r.key,i),C[e]=i,t(()=>_(r))}})}k&&v?.({start:k,end:b,update(e){F===e.project&&j===e.source||(F=e.project,j=e.source,L||ee())}});let ne=()=>{};function re(e){return r(e,(e,t)=>{E=void 0;const n=O;O=e;const r=i(t,f.stateKey,n,e);$?S&&r?Array.isArray(S)?S.push(r):S=[S,r]:S=void 0:(M=n,S=r),$=!0,A=t,ee()},(e,t)=>{E={error:e},A=t,S=void 0,$=!0,ee()})}return u.addCleanup(()=>{T=!1,p.cancel(x),ne(),Z()}),ne=re(I),W}const L=e=>e.slice(2).toLowerCase(),q=e=>null==e||!1===e?"":String(e);function W(e,t,n,r){const o=u(e.localName,t,n);if("select"===e.localName&&("value"===t||"defaultValue"===t)){const n=e;if("value"===t&&!n.multiple){const e=String(o??"");return void(n.value!==e&&(n.value=e))}const r=f(o,n.multiple),s=Array.from(n.options);if("value"===t){for(const e of s)e.selected=r.has(e.value);return}const i=p(n,"value")?new Set(n.selectedOptions):void 0;for(const e of s){const t=r.has(e.value);e.defaultSelected=t,t&&!n.multiple&&r.delete(e.value)}if(n.multiple)for(const e of s)e.selected=i?i.has(e):e.defaultSelected;else{const e=i?s.find(e=>i.has(e)):h(n)[0];n.selectedIndex=e?.index??-1}return}"className"!==t&&"class"!==t?"style"===t&&(e instanceof HTMLElement||e instanceof SVGElement)?function(e,t,n){if("string"!=typeof t)if(t&&"object"==typeof t){if(n&&"object"==typeof n)for(const r of Object.keys(n))r in t||(e.style.removeProperty(r),e.style[r]="");for(const[n,r]of Object.entries(t))n.startsWith("--")?e.style.setProperty(n,String(r)):e.style[n]=r}else e.removeAttribute("style");else e.style.cssText=t}(e,o,r):"htmlFor"!==t?t.startsWith("aria-")||t.startsWith("data-")||"http://www.w3.org/2000/svg"===e.namespaceURI||!(t in e)?null==o||!1===o?e.removeAttribute(t):!0===o?e.setAttribute(t,""):e.setAttribute(t,String(o)):e[t]=o??"":null==o||!1===o?e.removeAttribute("for"):e.setAttribute("for",String(o)):null==o||!1===o?e.removeAttribute("class"):e.setAttribute("class",String(o))}function U({target:e,owner:r,vnode:o,scheduler:s,renderInto:i,preparePatch:d,reconcile:l,hydration:a}){const u=e.ownerDocument??e,f=u.createTextNode("");a||e.appendChild(f);const p={};let h,g,w,k=!0,b=[],x=()=>{};const N=r.reserveIdSegment("t"),S=()=>{const e=h,t=b;h=void 0,b=[],v(e,t)};function A(e,t){s.enqueue(p,C,t,e=>r.handleError(e))}const E=e=>{if(w&&m(w,e))return;const t=x;w=e,x=o.source.subscribe(A,e),t()};function C(){if(!k)return;const e=o.track?.()??y(o.source.get(),o.project);if(h&&l(g,e.value,b,h))return g=e.value,void E(e.dependencies);const s=new c(r,!0,N);e.dependencies.length>0&&d(s);const a=u.createDocumentFragment();try{i(e.value,a,s),E(e.dependencies)}catch(e){n(e,()=>s.dispose())}const p=Array.from(a.childNodes);t(t=>{t(S),h=s,b=p,g=e.value,f.parentNode?.insertBefore(a,f),r.isMounted()&&s.mount()})}let T;if(a){const t=o.track?.()??y(o.source.get(),o.project),s=new c(r,!0,N);t.dependencies.length>0&&d(s);const i=a.node?a.node.previousSibling:e.lastChild;try{T=a.hydrateInto(t.value,e,s,a.node),E(t.dependencies)}catch(e){n(e,()=>s.dispose())}e.insertBefore(f,T);const l=[];let u=i?i.nextSibling:e.firstChild;for(;u&&u!==f;)l.push(u),u=u.nextSibling;h=s,b=l,g=t.value}else C();return r.addCleanup(()=>{k=!1,s.cancel(p),x();try{S()}finally{f.parentNode?.removeChild(f)}}),o.mountStores&&h?.addMount(o.mountStores),T}const J="http://www.w3.org/2000/svg";let z=0;const Y=["defaultValue","value"],K=(e,t)=>"select"===e&&("value"===t||"defaultValue"===t);class X{constructor(e,t,n){this.field=e,this.owner=t,this.scheduler=n,this.active=!0}connect(e=!1){const t=this.field.get();e||this.write(t),this.field.addListener(this),this.owner.addCleanup(this)}notify(e,t){this.scheduler.enqueue(this,()=>{this.active&&this.write(e)},t,e=>this.owner.handleError(e))}dispose(){this.active=!1,this.scheduler.cancel(this),this.field.removeListener(this)}}class Q extends X{constructor(e,t,n,r){super(e,n,r),this.node=t,this.connect()}write(e){this.node.data=q(e)}}class Z extends X{constructor(e,t,n,r,o,s){super(e,r,o),this.element=t,this.property=n,this.connect(s)}write(e){const t=this.previousStyle;"style"===this.property&&(this.previousStyle=e),W(this.element,this.property,e,t)}}function ee(e={},o){const s=function(e){const t=e.schedule??"microtask",n=new Map;let r=!1;const o=()=>{if(r=!1,0===n.size)return;let t=0;const o=[];let s;for(;n.size>0;){const r=Array.from(n.values());n.clear();for(const n of r)try{n.run(),t++,void 0!==n.context&&o.push(n.context)}catch(r){let i=r;try{if(n.handleError?.(r)){t++,void 0!==n.context&&o.push(n.context);continue}}catch(e){i=e}try{e.onError?e.onError(i):(s??(s=[])).push(i)}catch(e){(s??(s=[])).push(e)}}}if(t>0&&e.onCommit?.({updates:t,contexts:o}),1===s?.length)throw s[0];if(s)throw new AggregateError(s,"nexus-dom: Multiple errors during rendering.")};return{enqueue(e,s,i,c){n.set(e,{run:s,...void 0===i?{}:{context:i},...void 0===c?{}:{handleError:c}}),"manual"===t||r||(r=!0,"animationFrame"===t?requestAnimationFrame(o):queueMicrotask(o))},cancel(e){n.delete(e)},flush:o}}(e),i=new WeakMap,d=new WeakMap,l=new WeakMap,a=new WeakSet,f=e=>{a.add(e)},h=e=>l.set(e.start,e),y=(e,t)=>(n,r)=>{s.enqueue(e,()=>{throw n},r,e=>t.handleError(e))},m=(e,t,n,o=!1)=>{let i=!0,c=e.get(),d=c;o||n(c,void 0);const l=(e,r)=>{d=e,s.enqueue(l,()=>{if(!i)return;const e=c;c=d,n(c,e)},r,e=>t.handleError(e))},a=j(e)?r(e,l,y(l,t)):e.subscribe(l);t.addCleanup(()=>{i=!1,s.cancel(l),a()})},E=(e,t,n)=>{const r=T(e);r?new Q(r,t,n,s):m(e,n,e=>{t.data=q(e)})},I=(e,r,o,s,i)=>{const d=e.ownerDocument??e,l=new c(r),a=l.reserveIdSegment("b"),u=d.createTextNode("");i||e.appendChild(u);let f,p,h=!0,y=!1,m=[];const g=(e,r)=>{const o=new c(l,!0,a),s=d.createDocumentFragment();r&&o.setErrorHandler(b);try{re(e,s,o)}catch(e){n(e,()=>o.dispose())}const i=Array.from(s.childNodes);t(e=>{e(()=>v(f,m)),f=o,m=i,u.parentNode?.insertBefore(s,u),l.isMounted()&&o.mount()})},k=()=>{if(h)try{g(o,!0)}catch(e){try{b(e)}catch(e){if(y&&l.parent?.handleError(e))return;throw e}}};function b(e){if(!h)return;const t="function"==typeof s?s(e,k):s;g(t,!1)}if(i){const t=(t,r)=>{const o=new c(l,!0,a);r&&o.setErrorHandler(b);const s=i.node?i.node.previousSibling:e.lastChild;try{p=i.hydrateInto(t,e,o,i.node)}catch(e){n(e,()=>o.dispose())}e.insertBefore(u,p);const d=[];let h=s?s.nextSibling:e.firstChild;for(;h&&h!==u;)d.push(h),h=h.nextSibling;f=o,m=d};try{t(o,!0)}catch(e){if(e instanceof w&&"HYDRATION_MISMATCH"===e.code)throw e;t("function"==typeof s?s(e,k):s,!1)}}else k();return y=!0,l.addCleanup(()=>{h=!1;const e=f,t=m;f=void 0,m=[];try{v(e,t)}finally{u.parentNode?.removeChild(u)}}),p},D=(e,t,n,o)=>{if(k(n)){let i=n.get();const c=e=>{"function"==typeof i&&i(e)},d=r(n,e=>{i=e,s.cancel(c)},y(c,o));return e.addEventListener(L(t),c),void o.addCleanup(()=>{d(),s.cancel(c),e.removeEventListener(L(t),c)})}const c=i.get(e)??new Map;i.set(e,c);const d={listener:"function"==typeof n?n:void 0};c.set(t,d),d.listener&&e.addEventListener(L(t),d.listener),o.addCleanup(()=>{d.listener&&e.removeEventListener(L(t),d.listener),c.get(t)===d&&c.delete(t)})},M=(e,t)=>{"function"==typeof e?e(t):e&&"object"==typeof e&&(e.current=t)},P=e=>"function"==typeof e||"object"==typeof e&&null!==e&&"current"in e,_=(e,t,n)=>{if(!P(t))return;const r={value:t,attached:!1};d.set(e,r),n.addMount(()=>{r.attached=!0,M(r.value,e)}),n.addCleanup(()=>{r.attached&&M(r.value,null),d.get(e)===r&&d.delete(e)})},B=(e,t)=>{if(null==e||!1===e||!0===e)return!0;if(Array.isArray(e))return e.every(e=>B(e,t));if(k(e))return t.push(e),!0;if("object"!=typeof e)return t.push(e),!0;const n=e;return"fragment"===n.kind?B(n.props.children,t):("element"===n.kind||"keyed"===n.kind)&&(t.push(n),!0)},R=(e,t,n)=>{const r=[];let o=t;for(const t of e){if(!o||o===n)return;r.push(o);const e=l.get(o);if(e){if("object"!=typeof t||k(t)||"keyed"!==t.kind)return;o=e.end.nextSibling}else o=o.nextSibling}if(o===n)return r},V=(e,t,n)=>{if(k(e)||k(t))return e===t;if("object"!=typeof e||"object"!=typeof t)return"object"!=typeof e&&"object"!=typeof t;if("keyed"===e.kind||"keyed"===t.kind)return"keyed"===e.kind&&"keyed"===t.kind&&O(e.source,t.source)&&l.has(n);if(e.type!==t.type||e.key!==t.key||!((e,t)=>{const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n){if("children"===r||"key"===r)continue;const n=e[r],o=t[r];if((k(n)||k(o))&&n!==o)return!1}return!0})(e.props,t.props))return!1;const r=A(e.type,e.props);if(r!==A(t.type,t.props))return!1;if(r)return!0;const o=[],s=[];if(!(n instanceof Element&&B(e.props.children,o)&&B(t.props.children,s)&&o.length===s.length))return!1;const i=R(o,n.firstChild,null);return!!i&&o.every((e,t)=>V(e,s[t],i[t]))},F=(e,t,n,r)=>{let o=i.get(e),s=o?.get(t);s?(s.listener&&e.removeEventListener(L(t),s.listener),s.listener="function"==typeof n?n:void 0,s.listener&&e.addEventListener(L(t),s.listener)):D(e,t,n,r)},H=(e,t,n)=>{const r=P(t)?t:void 0,o=d.get(e);o?o.value!==r&&(o.attached&&M(o.value,null),o.value=r,o.attached&&M(o.value,e)):r&&_(e,r,n)},G=(e,t,n,r)=>{if(k(e)||k(t))return;if("object"!=typeof e||"object"!=typeof t)return void(n.nodeType===Node.TEXT_NODE&&(n.nodeValue=q(t)));if("keyed"===e.kind||"keyed"===t.kind)return void("keyed"===t.kind&&l.get(n)?.update(t));if(!(n instanceof Element))return;const o=new Set([...Object.keys(e.props),...Object.keys(t.props)]);for(const s of o){if("children"===s||"key"===s||K(t.type,s))continue;const o=e.props[s],i=t.props[s];o!==i&&("ref"===s?H(n,i,r):C(s)?F(n,s,i,r):k(i)||W(n,s,i,o))}if(A(t.type,t.props))return;const s=[],i=[];B(e.props.children,s),B(t.props.children,i);const c=R(s,n.firstChild,null);if(s.forEach((e,t)=>{G(e,i[t],c[t],r)}),"select"===t.type)for(const r of Y)e.props[r]!==t.props[r]&&W(n,r,t.props[r],e.props[r])},X=(e,t,n,r)=>{const o=[],s=[];if(!B(e,o)||!B(t,s)||o.length!==s.length)return!1;const i=R(o,n[0]??null,n.at(-1)?.nextSibling??null);return!(!i||!o.every((e,t)=>V(e,s[t],i[t]))||(o.forEach((e,t)=>{G(e,s[t],i[t],r)}),0))},ee=(e,o,i,d,l,a)=>{const u=e.ownerDocument??e,f=u.createTextNode("");a||e.appendChild(f);const p=o.reserveIdSegment("d");let h,m=!0,g=i.get(),w=l?.(g),k=[];const b={},x=()=>{const e=h,t=k;h=void 0,k=[],v(e,t)},N=()=>{const e=new c(o,!0,p),r=u.createDocumentFragment();try{re(d(g),r,e)}catch(t){n(t,()=>e.dispose())}const s=Array.from(r.childNodes);t(t=>{t(x),h=e,k=s,f.parentNode?.insertBefore(r,f),o.isMounted()&&e.mount()})};let S;if(a){const t=new c(o,!0,p),r=a.node?a.node.previousSibling:e.lastChild;try{S=a.hydrateInto(d(g),e,t,a.node)}catch(e){n(e,()=>t.dispose())}e.insertBefore(f,S);const s=[];let i=r?r.nextSibling:e.firstChild;for(;i&&i!==f;)s.push(i),i=i.nextSibling;h=t,k=s}else N();const A=r(i,(e,t)=>{g=e,s.enqueue(b,()=>{if(m){if(l){const e=l(g);if(Object.is(w,e))return;w=e}N()}},t,e=>o.handleError(e))},y(b,o));return o.addCleanup(()=>{m=!1,s.cancel(b),A();try{x()}finally{f.parentNode?.removeChild(f)}}),S},te=(e,t,n,r,o=!1)=>{if("ref"===t)_(e,n,r);else if(C(t))D(e,t,n,r);else if(k(n)){const i=T(n),c=o&&p(e,t);i?new Z(i,e,t,r,s,c):m(n,r,(n,r)=>W(e,t,n,r),c)}else!o||"value"===t&&"select"===e.localName&&!p(e,t)?W(e,t,n,void 0):u(e.localName,t,n)},ne=(e,t,n)=>{if("store-view"===e.kind){if(!o)throw S("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be rendered through createApp().render().");return void ne(o.resolve(e),t,n)}if("error-boundary"===e.kind)return void I(t,n,e.children,e.fallback);if("keyed"===e.kind)return void $({target:t,owner:n,vnode:e,scheduler:s,renderInto:re,reconcileView:X,preparePatch:f,...a.has(n)?{register:h}:{}});if("tracked-view"===e.kind)return void U({target:t,owner:n,vnode:e,scheduler:s,renderInto:re,preparePatch:f,reconcile:X});if("dynamic"===e.kind)return void ee(t,n,e.source,e.project,e.key);if("fragment"===e.kind)return void re(e.props.children,t,n);if("component"===e.kind){const r=new c(n),o=N(r,()=>e.type(e.props));return void re(o,t,r)}const r=function(e,t,n){const r=t instanceof Element?t:void 0;return"svg"===n||r?.namespaceURI===J&&"foreignObject"!==r.localName?e.createElementNS(J,n):e.createElement(n)}(t.ownerDocument??t,t,e.type);for(const[t,o]of Object.entries(e.props))"children"===t||"key"===t||K(e.type,t)||te(r,t,o,n);if(A(e.type,e.props)||re(e.props.children,r,n),"select"===e.type)for(const t of Y)t in e.props&&te(r,t,e.props[t],n);t.appendChild(r)},re=(e,t,n)=>{if(null==e||!1===e||!0===e)return;if(Array.isArray(e)){for(const r of e)re(r,t,n);return}const r=t.ownerDocument??t;if(k(e)){const o=r.createTextNode("");return E(e,o,n),void t.appendChild(o)}"object"!=typeof e?t.appendChild(r.createTextNode(q(e))):ne(e,t,n)},oe=(e,t)=>{const n=t?1===t.nodeType?`<${t.localName}>`:3===t.nodeType?`text ${JSON.stringify(t.nodeValue)}`:8===t.nodeType?`comment ${JSON.stringify(t.nodeValue)}`:`node type ${t.nodeType}`:"the end of the container";throw S("HYDRATION_MISMATCH",`Expected ${e}, but found ${n}.`)},se=(e,t,n,r)=>{if(null==e||!1===e||!0===e)return r;if(Array.isArray(e)){let o=r;for(const r of e)o=se(r,t,n,o);return o}if(k(e)){if(8!==r?.nodeType||r.nodeValue!==b)return oe(`the \x3c!--${b}--\x3e marker`,r);const o=r;let s=o.nextSibling;if(8===s?.nodeType&&s.nodeValue===x&&(s=(t.ownerDocument??t).createTextNode(""),t.insertBefore(s,o.nextSibling)),!s||3!==s.nodeType)return oe("reactive text",s);const i=s.nextSibling;if(8!==i?.nodeType||i.nodeValue!==x)return oe(`the \x3c!--${x}--\x3e marker`,i);const c=q(e.get());if(s.data!==c)return oe(`reactive text ${JSON.stringify(c)}`,s);const d=i.nextSibling;return o.parentNode?.removeChild(o),i.parentNode?.removeChild(i),E(e,s,n),d}if("object"!=typeof e)return((e,t,n)=>{const r=t.ownerDocument??t;if(""===e)return t.insertBefore(r.createTextNode(""),n),n;n&&3===n.nodeType||oe(`text ${JSON.stringify(e)}`,n);const o=n;return o.data===e?o.nextSibling:o.data.startsWith(e)?o.splitText(e.length):oe(`text ${JSON.stringify(e)}`,n)})(q(e),t,r);const i=e;if("fragment"===i.kind)return se(i.props.children,t,n,r);if("component"===i.kind){const e=new c(n),o=N(e,()=>i.type(i.props));return se(o,t,e,r)}if("store-view"===i.kind){if(!o)throw S("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be hydrated through createApp().hydrate().");return se(o.resolve(i),t,n,r)}if("tracked-view"===i.kind){const e=U({target:t,owner:n,vnode:i,scheduler:s,renderInto:re,preparePatch:f,reconcile:X,hydration:{node:r,hydrateInto:se}});return void 0===e?r:e}if("dynamic"===i.kind){const e=ee(t,n,i.source,i.project,i.key,{node:r,hydrateInto:se});return void 0===e?r:e}if("keyed"===i.kind){const e=$({target:t,owner:n,vnode:i,scheduler:s,renderInto:re,reconcileView:X,preparePatch:f,...a.has(n)?{register:h}:{},hydration:{node:r,hydrateInto:se}});return void 0===e?r:e}if("error-boundary"===i.kind){const e=I(t,n,i.children,i.fallback,{node:r,hydrateInto:se});return void 0===e?r:e}if(!(r instanceof Element)||r.localName!==i.type)return oe(`<${i.type}>`,r);for(const[e,t]of Object.entries(i.props))"children"===e||"key"===e||K(i.type,e)||te(r,e,t,n,!0);if(!A(i.type,i.props)){const e=se(i.props.children,r,n,r.firstChild);e&&oe(`the end of <${i.type}>`,e)}if("select"===i.type)for(const e of Y)e in i.props&&te(r,e,i.props[e],n,!0);return r.nextSibling},ie=()=>e.idPrefix??`r${(z++).toString(36)}`,ce=(e,t,r,s=!1)=>{const i=new c(void 0,!0,r),d=(t.ownerDocument??t).createDocumentFragment();let l=[];try{re(e,d,i),s&&o?.completeRestore?.(),l=Array.from(d.childNodes),t.appendChild(d),i.mount()}catch(e){n(e,()=>v(i,l))}let a=!1;return{dispose(){a||(a=!0,v(i,l))}}};return{mount:(e,t)=>ce(e,t,ie()),hydrate(t,r){const s=ie(),i=new c(void 0,!0,s);try{const e=se(t,r,i,r.firstChild);e&&oe("the end of the hydration root",e)}catch(n){if(g(n,()=>i.dispose()),!(n instanceof w)||"HYDRATION_MISMATCH"!==n.code)throw n;for(e.onError?.(n);r.firstChild;)r.removeChild(r.firstChild);return ce(t,r,s,!0)}const d=Array.from(r.childNodes);try{o?.completeRestore?.(),i.mount()}catch(e){n(e,()=>v(i,d))}let l=!1;return{dispose(){l||(l=!0,v(i,d))}}},flush:s.flush}}function te(e){if("string"!=typeof e)return e;const t=document.querySelector(e);if(!t)throw S("RENDER_TARGET_NOT_FOUND",`Render target "${e}" was not found.`);return t}function ne(e,r){if(void 0!==e&&void 0===r)throw S("RENDER_TARGET_NOT_FOUND","Pass a target to createApp(view, target), or call createApp() to mount later.");const o=new Set,s=new Set,i=M();let c=!1;const d={onCleanup:e=>c?(e(),()=>{}):(s.add(e),()=>s.delete(e)),dispose(){c||(c=!0,t(e=>{for(const t of Array.from(o))e(t.dispose);o.clear();for(const t of Array.from(s).reverse())e(t);s.clear(),e(i.dispose)}))},render(e,t,n){if(c)throw S("APP_DISPOSED","Cannot render a disposed app. app.dispose() has already run.");const r=function(e,t,n={},r){const o=ee(n,r);return{dispose:o.mount(e,te(t)).dispose,flush:o.flush}}(e,t,n,i);let s=!1;const d={flush:r.flush,dispose(){s||(s=!0,o.delete(d),r.dispose())}};return c?d.dispose():o.add(d),d},hydrate(e,t,n){if(c)throw S("APP_DISPOSED","Cannot hydrate with a disposed app. app.dispose() has already run.");const r=function(e,t,n={},r){const o=te(t),s=D(o,n.idPrefix);if(s?.stores.length){if(!r?.restore)throw S("HYDRATION_STATE_INVALID","Lazy-store hydration state requires createApp().hydrate().");r.restore(s.stores)}const i=ee(void 0===s?.idPrefix?n:{...n,idPrefix:s.idPrefix},r);return{dispose:i.hydrate(e,o).dispose,flush:i.flush}}(e,t,n,i);let s=!1;const d={flush:r.flush,dispose(){s||(s=!0,o.delete(d),r.dispose())}};return c?d.dispose():o.add(d),d}};if(void 0!==r)try{d.render(e,r)}catch(e){n(e,d.dispose)}return d}function re({fallback:e,children:t}){return{kind:"error-boundary",fallback:e,children:t}}const oe=e;export{re as ErrorBoundary,w as NexusDOMError,ne as createApp,oe as persist};
|
|
1
|
+
import{persist as e}from"nexus-state";import{f as t,t as n,j as r,k as o,r as s,l as i,O as c,c as d,m as l,o as a,b as u,d as f,p,q as h,u as y,v,x as m,y as g,N as w,i as k,T as b,z as x,w as N,n as S,g as A,a as C,A as T,B as j,C as O,D,e as M}from"./chunks/store-view-DxtNNb3a.js";export{E as component,F as componentScope,G as createActs,H as onCleanup,I as store}from"./chunks/store-view-DxtNNb3a.js";import"./chunks/types-DkNQRHR2.js";function P(e){return Array.isArray(e)?e[0]:e}function _(e){try{e.owner.dispose()}finally{!function(e){if(Array.isArray(e))for(const t of e)t.parentNode?.removeChild(t);else e.parentNode?.removeChild(e)}(e.nodes)}}function B(e,t){if(function(e){return Array.isArray(e)?e.at(-1):e}(e.nodes).nextSibling===t)return;const n=t.parentNode;if(!n)return;const r=Array.isArray(e.nodes)?e.nodes:[e.nodes];for(const e of r)n.moveBefore?n.moveBefore(e,t):n.insertBefore(e,t)}function R(e){const t=[],n=new Array(e.length).fill(-1);for(let r=0;r<e.length;r++){const o=e[r];if(void 0===o||o<0)continue;let s=0,i=t.length;for(;s<i;){const n=s+i>>1,r=t[n];(void 0===r?-1:e[r]??-1)<o?s=n+1:i=n}s>0&&(n[r]=t[s-1]??-1),t[s]=r}const r=new Set;let o=t.at(-1)??-1;for(;o>=0;)r.add(o),o=n[o]??-1;return r}function V(e,t){return!!t&&(Array.isArray(e.nodes)?e.nodes:[e.nodes]).some(e=>e===t||e.nodeType===Node.ELEMENT_NODE&&e.contains(t))}function $({target:e,owner:u,vnode:f,scheduler:p,renderInto:h,reconcileView:y,register:v,preparePatch:m,hydration:g}){const w=e.ownerDocument??e,k=v?w.createTextNode(""):void 0,b=w.createTextNode("");k&&e.insertBefore(k,g?g.node:null),g||e.appendChild(b);const x={},N=new Map;let S,A,C,E=[],T=!0,I=f.source,j=I,O=I.get(),D=O,M=O,$=!1,L=!1,q=f.project,F=q,H=g?void 0:w.createDocumentFragment(),W=g?.node,U=void 0!==g;const J=u.reserveIdSegment("l");let z=0;const G=()=>({slot:z++}),Y=(t,r)=>{const o=new c(u,!1,u.keyedIdSegment(J,t)),s=d(r,o),i=v?{key:t,owner:o,nodes:b,controller:s.controller,live:s.live,row:s.row,view:void 0}:{key:t,owner:o,nodes:b,controller:s.controller};try{const t=q(s.live,s.row);if(v&&(m(o),i.view=t),U){const n=W?W.previousSibling:e.lastChild;W=g.hydrateInto(t,e,i.owner,W??null);const r=[];let o=n?n.nextSibling:e.firstChild;for(;o&&o!==W;)r.push(o),o=o.nextSibling;if(0===r.length){const t=w.createTextNode("");e.insertBefore(t,W??null),r.push(t)}i.nodes=1===r.length?r[0]:r}else if(H)i.nodes=((e,t)=>{const n=H,r=n.lastChild;h(e,n,t),n.lastChild===r&&n.appendChild(w.createTextNode(""));const o=r?r.nextSibling:n.firstChild;if(!o.nextSibling)return o;const s=[];let i=o;for(;i;)s.push(i),i=i.nextSibling;return s})(t,i.owner);else{const e=function(e,t,n,r){const o=e.createDocumentFragment();return r(t,o,n),0===o.childNodes.length&&o.appendChild(e.createTextNode("")),{fragment:o,nodes:1===o.childNodes.length?o.firstChild:Array.from(o.childNodes)}}(w,t,i.owner,h);i.nodes=e.nodes,b.parentNode?.insertBefore(e.fragment,b),u.isMounted()&&i.owner.mount()}}catch(e){n(e,()=>{U||i.nodes===b?i.owner.dispose():_(i)})}return i};u.addMount(()=>{for(const e of E)e.owner.mount()});const K=(e,t)=>{let n=-1;if(e.every(e=>{const r=t.get(e.key);return!(void 0===r||r<=n||(n=r,0))}))return void(E=e);const r=e.map(e=>t.get(e.key)??-1),o=b.parentNode,s=w.activeElement,i=o?.moveBefore?-1:e.findIndex(e=>V(e,s)),c=function(e,t){const n=void 0===t?void 0:e[t];if(void 0===t||void 0===n||n<0)return R(e);const r=e.map((e,r)=>r<t&&e<n?e:-1),o=e.map((e,r)=>r>t&&e>n?e:-1);return new Set([...R(r),t,...R(o)])}(r,i<0?void 0:i);for(let t=e.length-1;t>=0;t--){const n=e[t],o=e[t+1];-1!==r[t]&&c.has(t)||B(n,o?P(o.nodes):b)}E=e},X=(t,n,r)=>{if(!H&&!U&&t.length===E.length&&E.every((e,n)=>o(t[n])===e.key))return void E.forEach((e,n)=>{Object.is(e.controller.get(),t[n])||e.controller.set(t[n],r)});const i=[];let c,d;for(const e of E){if("object"!=typeof e.key)continue;const t=e.controller.get();c??(c=new Map),c.set(t,c.has(t)?null:e)}if(c){d=new Map;for(const e of t)d.set(e,(d.get(e)??0)+1)}const l=s(t,e=>{const t=c?.get(e);return t&&1===d?.get(e)&&Object.is(t.controller.get(),e)?t.key:G()}),a=new Set(l),u=new Map(E.map((e,t)=>[e.key,t]));l.forEach((e,n)=>{const o=t[n];let s=N.get(e);s?Object.is(s.controller.get(),o)||s.controller.set(o,r):(s=Y(e,o),N.set(e,s)),i.push(s)});for(const[e,t]of N)a.has(e)||(N.delete(e),n(()=>_(t)));return H?(b.parentNode?.insertBefore(H,b),H=void 0,void(E=i)):U?(e.insertBefore(b,W??null),U=!1,void(E=i)):void K(i,u)},Q=(e,t,n,r,s=!0)=>{if("batch"===e.type){for(const o of e.operations)if(!Q(o,t,n,r,!1))return!1;return!s||E.length===t.length}if("insert"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.index>E.length||e.count<1)return!1;if(s&&t.length!==E.length+e.count)return!1;const n=l(e);if(!Array.isArray(n)||n.length!==e.count)return!1;const r=n.map(e=>({item:e,key:o(e)??G()})),i=new Set;for(const{key:e}of r){if(N.has(e)||i.has(e))return!1;i.add(e)}const c=[];for(const{item:e,key:t}of r){const n=Y(t,e);N.set(t,n),c.push(n)}E.splice(e.index,0,...c);let d=E[e.index+c.length]?P(E[e.index+c.length].nodes):b;for(let e=c.length-1;e>=0;e--){const t=c[e];t&&(B(t,d),d=P(t.nodes))}return!0}if("remove"===e.type){if(!Number.isInteger(e.index)||!Number.isInteger(e.count)||e.index<0||e.count<1||e.index+e.count>E.length)return!1;if(s&&t.length!==E.length-e.count)return!1;const r=E.splice(e.index,e.count);if(r.length!==e.count)return!1;for(const e of r)N.delete(e.key),n(()=>_(e));return!0}if("move"===e.type){if(!Number.isInteger(e.from)||!Number.isInteger(e.to)||e.from<0||e.from>=E.length||e.to<0||e.to>=E.length)return!1;if(s&&t.length!==E.length)return!1;const n=E[e.from];if(!n)return!1;if(s){const r=t[e.to];if(!("object"==typeof n.key?Object.is(r,n.controller.get()):o(r)===n.key))return!1}const r=b.parentNode,i=w.activeElement;if(!r?.moveBefore&&V(n,i)){if(e.from>e.to){let t=E[e.from+1]?P(E[e.from+1].nodes):b;for(let n=e.from-1;n>=e.to;n--){const e=E[n];e&&(B(e,t),t=P(e.nodes))}}else{const t=P(n.nodes);for(let n=e.from+1;n<=e.to;n++){const e=E[n];e&&B(e,t)}}return E.splice(e.from,1),E.splice(e.to,0,n),!0}return E.splice(e.from,1),E.splice(e.to,0,n),B(n,E[e.to+1]?P(E[e.to+1].nodes):b),!0}if("replace"===e.type){if(!Number.isInteger(e.index)||e.index<0||e.index>=E.length)return!1;if(s&&t.length!==E.length)return!1;const i=E[e.index],c=l(e);if(!i||!a(e))return!1;const d=o(c)??("object"==typeof i.key?i.key:G());if(d===i.key)return i.controller.set(c,r),!0;if(N.has(d))return!1;const u=Y(d,c);return N.delete(i.key),n(()=>_(i)),N.set(d,u),E[e.index]=u,B(u,E[e.index+1]?P(E[e.index+1].nodes):b),!0}if("reorder"===e.type){if(s&&t.length!==E.length)return!1;const e=new Map(E.map((e,t)=>[e.key,t]));return K([...E].reverse(),e),!0}return!1};try{t(e=>X(O,e))}catch(e){n(e,Z)}function Z(){t(e=>{for(const t of N.values())e(()=>_(t));N.clear(),E=[],k&&k.parentNode?.removeChild(k),b.parentNode?.removeChild(b)})}function ee(){L=!0,p.enqueue(x,te,A,e=>u.handleError(e))}function te(){if(L=!1,!T)return;if(j!==I){const e=j,t=e.get(),n=re(e);ne(),I=e,ne=n,C=void 0,O=t,S=void 0,$=t!==D&&(!D||D.length!==t.length||t.some((e,t)=>!Object.is(e,D[t]))),$||(D=t)}if(C)throw C.error;const e=A;A=void 0;const n=F===q?void 0:new Set(E);q=F;const r=M===D?S:void 0,o=O,s=$;$=!1,S=void 0,t(t=>{if(s&&(D=void 0,(Array.isArray(r)?r.every((n,s)=>Q(n,o,t,e,s===r.length-1)):r&&Q(r,o,t,e))||X(o,t,e),D=o),n)for(let e=0;e<E.length;e++){const r=E[e];if(!n.has(r))continue;const o=q(r.live,r.row),s=Array.isArray(r.nodes)?r.nodes:[r.nodes];if(y(r.view,o,s,r.owner)){r.view=o;continue}const i=Y(r.key,r.controller.get());B(i,P(r.nodes)),N.set(r.key,i),E[e]=i,t(()=>_(r))}})}k&&v?.({start:k,end:b,update(e){F===e.project&&j===e.source||(F=e.project,j=e.source,L||ee())}});let ne=()=>{};function re(e){return r(e,(e,t)=>{C=void 0;const n=O;O=e;const r=i(t,f.stateKey,n,e);$?S&&r?Array.isArray(S)?S.push(r):S=[S,r]:S=void 0:(M=n,S=r),$=!0,A=t,ee()},(e,t)=>{C={error:e},A=t,S=void 0,$=!0,ee()})}return u.addCleanup(()=>{T=!1,p.cancel(x),ne(),Z()}),ne=re(I),W}const L=e=>e.slice(2).toLowerCase(),q=e=>null==e||!1===e?"":String(e);function W(e,t,n,r){const o=u(e.localName,t,n);if("select"===e.localName&&("value"===t||"defaultValue"===t)){const n=e;if("value"===t&&!n.multiple){const e=String(o??"");return void(n.value!==e&&(n.value=e))}const r=f(o,n.multiple),s=Array.from(n.options);if("value"===t){for(const e of s)e.selected=r.has(e.value);return}const i=p(n,"value")?new Set(n.selectedOptions):void 0;for(const e of s){const t=r.has(e.value);e.defaultSelected=t,t&&!n.multiple&&r.delete(e.value)}if(n.multiple)for(const e of s)e.selected=i?i.has(e):e.defaultSelected;else{const e=i?s.find(e=>i.has(e)):h(n)[0];n.selectedIndex=e?.index??-1}return}"className"!==t&&"class"!==t?"style"===t&&(e instanceof HTMLElement||e instanceof SVGElement)?function(e,t,n){if("string"!=typeof t)if(t&&"object"==typeof t){if(n&&"object"==typeof n)for(const r of Object.keys(n))r in t||(e.style.removeProperty(r),e.style[r]="");for(const[n,r]of Object.entries(t))n.startsWith("--")?e.style.setProperty(n,String(r)):e.style[n]=r}else e.removeAttribute("style");else e.style.cssText=t}(e,o,r):"htmlFor"!==t?t.startsWith("aria-")||t.startsWith("data-")||"http://www.w3.org/2000/svg"===e.namespaceURI||!(t in e)?null==o||!1===o?e.removeAttribute(t):!0===o?e.setAttribute(t,""):e.setAttribute(t,String(o)):e[t]=o??"":null==o||!1===o?e.removeAttribute("for"):e.setAttribute("for",String(o)):null==o||!1===o?e.removeAttribute("class"):e.setAttribute("class",String(o))}function U({target:e,owner:r,vnode:o,scheduler:s,renderInto:i,preparePatch:d,reconcile:l,hydration:a}){const u=e.ownerDocument??e,f=u.createTextNode("");a||e.appendChild(f);const p={};let h,g,w,k=!0,b=[],x=()=>{};const N=r.reserveIdSegment("t"),S=()=>{const e=h,t=b;h=void 0,b=[],v(e,t)};function A(e,t){s.enqueue(p,E,t,e=>r.handleError(e))}const C=e=>{if(w&&m(w,e))return;const t=x;w=e,x=o.source.subscribe(A,e),t()};function E(){if(!k)return;const e=o.track?.()??y(o.source.get(),o.project);if(h&&l(g,e.value,b,h))return g=e.value,void C(e.dependencies);const s=new c(r,!0,N);e.dependencies.length>0&&d(s);const a=u.createDocumentFragment();try{i(e.value,a,s),C(e.dependencies)}catch(e){n(e,()=>s.dispose())}const p=Array.from(a.childNodes);t(t=>{t(S),h=s,b=p,g=e.value,f.parentNode?.insertBefore(a,f),r.isMounted()&&s.mount()})}let T;if(a){const t=o.track?.()??y(o.source.get(),o.project),s=new c(r,!0,N);t.dependencies.length>0&&d(s);const i=a.node?a.node.previousSibling:e.lastChild;try{T=a.hydrateInto(t.value,e,s,a.node),C(t.dependencies)}catch(e){n(e,()=>s.dispose())}e.insertBefore(f,T);const l=[];let u=i?i.nextSibling:e.firstChild;for(;u&&u!==f;)l.push(u),u=u.nextSibling;h=s,b=l,g=t.value}else E();return r.addCleanup(()=>{k=!1,s.cancel(p),x();try{S()}finally{f.parentNode?.removeChild(f)}}),o.mountStores&&h?.addMount(o.mountStores),T}const J="http://www.w3.org/2000/svg";let z=0;const Y=["defaultValue","value"],K=(e,t)=>"select"===e&&("value"===t||"defaultValue"===t);class X{constructor(e,t,n){this.field=e,this.owner=t,this.scheduler=n,this.active=!0}connect(e=!1){const t=this.field.get();e||this.write(t),this.field.addListener(this),this.owner.addCleanup(this)}notify(e,t){this.scheduler.enqueue(this,()=>{this.active&&this.write(e)},t,e=>this.owner.handleError(e))}dispose(){this.active=!1,this.scheduler.cancel(this),this.field.removeListener(this)}}class Q extends X{constructor(e,t,n,r){super(e,n,r),this.node=t,this.connect()}write(e){this.node.data=q(e)}}class Z extends X{constructor(e,t,n,r,o,s){super(e,r,o),this.element=t,this.property=n,this.connect(s)}write(e){const t=this.previousStyle;"style"===this.property&&(this.previousStyle=e),W(this.element,this.property,e,t)}}function ee(e={},o){const s=function(e){const t=e.schedule??"microtask",n=new Map;let r=!1;const o=()=>{if(r=!1,0===n.size)return;let t=0;const o=[];let s;for(;n.size>0;){const r=Array.from(n.values());n.clear();for(const n of r)try{n.run(),t++,void 0!==n.context&&o.push(n.context)}catch(r){let i=r;try{if(n.handleError?.(r)){t++,void 0!==n.context&&o.push(n.context);continue}}catch(e){i=e}try{e.onError?e.onError(i):(s??(s=[])).push(i)}catch(e){(s??(s=[])).push(e)}}}if(t>0&&e.onCommit?.({updates:t,contexts:o}),1===s?.length)throw s[0];if(s)throw new AggregateError(s,"nexus-dom: Multiple errors during rendering.")};return{enqueue(e,s,i,c){n.set(e,{run:s,...void 0===i?{}:{context:i},...void 0===c?{}:{handleError:c}}),"manual"===t||r||(r=!0,"animationFrame"===t?requestAnimationFrame(o):queueMicrotask(o))},cancel(e){n.delete(e)},flush:o}}(e),i=new WeakMap,d=new WeakMap,l=new WeakMap,a=new WeakSet,f=e=>{a.add(e)},h=e=>l.set(e.start,e),y=(e,t)=>(n,r)=>{s.enqueue(e,()=>{throw n},r,e=>t.handleError(e))},m=(e,t,n,o=!1)=>{let i=!0,c=e.get(),d=c;o||n(c,void 0);const l=(e,r)=>{d=e,s.enqueue(l,()=>{if(!i)return;const e=c;c=d,n(c,e)},r,e=>t.handleError(e))},a=j(e)?r(e,l,y(l,t)):e.subscribe(l);t.addCleanup(()=>{i=!1,s.cancel(l),a()})},E=(e,t,n)=>{const r=T(e);r?new Q(r,t,n,s):m(e,n,e=>{t.data=q(e)})},I=(e,r,o,s,i)=>{const d=e.ownerDocument??e,l=new c(r),a=l.reserveIdSegment("b"),u=d.createTextNode("");i||e.appendChild(u);let f,p,h=!0,y=!1,m=[];const g=(e,r)=>{const o=new c(l,!0,a),s=d.createDocumentFragment();r&&o.setErrorHandler(b);try{re(e,s,o)}catch(e){n(e,()=>o.dispose())}const i=Array.from(s.childNodes);t(e=>{e(()=>v(f,m)),f=o,m=i,u.parentNode?.insertBefore(s,u),l.isMounted()&&o.mount()})},k=()=>{if(h)try{g(o,!0)}catch(e){try{b(e)}catch(e){if(y&&l.parent?.handleError(e))return;throw e}}};function b(e){if(!h)return;const t="function"==typeof s?s(e,k):s;g(t,!1)}if(i){const t=(t,r)=>{const o=new c(l,!0,a);r&&o.setErrorHandler(b);const s=i.node?i.node.previousSibling:e.lastChild;try{p=i.hydrateInto(t,e,o,i.node)}catch(e){n(e,()=>o.dispose())}e.insertBefore(u,p);const d=[];let h=s?s.nextSibling:e.firstChild;for(;h&&h!==u;)d.push(h),h=h.nextSibling;f=o,m=d};try{t(o,!0)}catch(e){if(e instanceof w&&"HYDRATION_MISMATCH"===e.code)throw e;t("function"==typeof s?s(e,k):s,!1)}}else k();return y=!0,l.addCleanup(()=>{h=!1;const e=f,t=m;f=void 0,m=[];try{v(e,t)}finally{u.parentNode?.removeChild(u)}}),p},D=(e,t,n,o)=>{if(k(n)){let i=n.get();const c=e=>{"function"==typeof i&&i(e)},d=r(n,e=>{i=e,s.cancel(c)},y(c,o));return e.addEventListener(L(t),c),void o.addCleanup(()=>{d(),s.cancel(c),e.removeEventListener(L(t),c)})}const c=i.get(e)??new Map;i.set(e,c);const d={listener:"function"==typeof n?n:void 0};c.set(t,d),d.listener&&e.addEventListener(L(t),d.listener),o.addCleanup(()=>{d.listener&&e.removeEventListener(L(t),d.listener),c.get(t)===d&&c.delete(t)})},M=(e,t)=>{"function"==typeof e?e(t):e&&"object"==typeof e&&(e.current=t)},P=e=>"function"==typeof e||"object"==typeof e&&null!==e&&"current"in e,_=(e,t,n)=>{if(!P(t))return;const r={value:t,attached:!1};d.set(e,r),n.addMount(()=>{r.attached=!0,M(r.value,e)}),n.addCleanup(()=>{r.attached&&M(r.value,null),d.get(e)===r&&d.delete(e)})},B=(e,t)=>{if(null==e||!1===e||!0===e)return!0;if(Array.isArray(e))return e.every(e=>B(e,t));if(k(e))return t.push(e),!0;if("object"!=typeof e)return t.push(e),!0;const n=e;return"fragment"===n.kind?B(n.props.children,t):("element"===n.kind||"keyed"===n.kind)&&(t.push(n),!0)},R=(e,t,n)=>{const r=[];let o=t;for(const t of e){if(!o||o===n)return;r.push(o);const e=l.get(o);if(e){if("object"!=typeof t||k(t)||"keyed"!==t.kind)return;o=e.end.nextSibling}else o=o.nextSibling}if(o===n)return r},V=(e,t,n)=>{if(k(e)||k(t))return e===t;if("object"!=typeof e||"object"!=typeof t)return"object"!=typeof e&&"object"!=typeof t;if("keyed"===e.kind||"keyed"===t.kind)return"keyed"===e.kind&&"keyed"===t.kind&&O(e.source,t.source)&&l.has(n);if(e.type!==t.type||e.key!==t.key||!((e,t)=>{const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n){if("children"===r||"key"===r)continue;const n=e[r],o=t[r];if((k(n)||k(o))&&n!==o)return!1}return!0})(e.props,t.props))return!1;const r=A(e.type,e.props);if(r!==A(t.type,t.props))return!1;if(r)return!0;const o=[],s=[];if(!(n instanceof Element&&B(e.props.children,o)&&B(t.props.children,s)&&o.length===s.length))return!1;const i=R(o,n.firstChild,null);return!!i&&o.every((e,t)=>V(e,s[t],i[t]))},F=(e,t,n,r)=>{let o=i.get(e),s=o?.get(t);s?(s.listener&&e.removeEventListener(L(t),s.listener),s.listener="function"==typeof n?n:void 0,s.listener&&e.addEventListener(L(t),s.listener)):D(e,t,n,r)},H=(e,t,n)=>{const r=P(t)?t:void 0,o=d.get(e);o?o.value!==r&&(o.attached&&M(o.value,null),o.value=r,o.attached&&M(o.value,e)):r&&_(e,r,n)},G=(e,t,n,r)=>{if(k(e)||k(t))return;if("object"!=typeof e||"object"!=typeof t)return void(n.nodeType===Node.TEXT_NODE&&(n.nodeValue=q(t)));if("keyed"===e.kind||"keyed"===t.kind)return void("keyed"===t.kind&&l.get(n)?.update(t));if(!(n instanceof Element))return;const o=new Set([...Object.keys(e.props),...Object.keys(t.props)]);for(const s of o){if("children"===s||"key"===s||K(t.type,s))continue;const o=e.props[s],i=t.props[s];o!==i&&("ref"===s?H(n,i,r):C(s)?F(n,s,i,r):k(i)||W(n,s,i,o))}if(A(t.type,t.props))return;const s=[],i=[];B(e.props.children,s),B(t.props.children,i);const c=R(s,n.firstChild,null);if(s.forEach((e,t)=>{G(e,i[t],c[t],r)}),"select"===t.type)for(const r of Y)e.props[r]!==t.props[r]&&W(n,r,t.props[r],e.props[r])},X=(e,t,n,r)=>{const o=[],s=[];if(!B(e,o)||!B(t,s)||o.length!==s.length)return!1;const i=R(o,n[0]??null,n.at(-1)?.nextSibling??null);return!(!i||!o.every((e,t)=>V(e,s[t],i[t]))||(o.forEach((e,t)=>{G(e,s[t],i[t],r)}),0))},ee=(e,o,i,d,l,a)=>{const u=e.ownerDocument??e,f=u.createTextNode("");a||e.appendChild(f);const p=o.reserveIdSegment("d");let h,m=!0,g=i.get(),w=l?.(g),k=[];const b={},x=()=>{const e=h,t=k;h=void 0,k=[],v(e,t)},N=()=>{const e=new c(o,!0,p),r=u.createDocumentFragment();try{re(d(g),r,e)}catch(t){n(t,()=>e.dispose())}const s=Array.from(r.childNodes);t(t=>{t(x),h=e,k=s,f.parentNode?.insertBefore(r,f),o.isMounted()&&e.mount()})};let S;if(a){const t=new c(o,!0,p),r=a.node?a.node.previousSibling:e.lastChild;try{S=a.hydrateInto(d(g),e,t,a.node)}catch(e){n(e,()=>t.dispose())}e.insertBefore(f,S);const s=[];let i=r?r.nextSibling:e.firstChild;for(;i&&i!==f;)s.push(i),i=i.nextSibling;h=t,k=s}else N();const A=r(i,(e,t)=>{g=e,s.enqueue(b,()=>{if(m){if(l){const e=l(g);if(Object.is(w,e))return;w=e}N()}},t,e=>o.handleError(e))},y(b,o));return o.addCleanup(()=>{m=!1,s.cancel(b),A();try{x()}finally{f.parentNode?.removeChild(f)}}),S},te=(e,t,n,r,o=!1)=>{if("ref"===t)_(e,n,r);else if(C(t))D(e,t,n,r);else if(k(n)){const i=T(n),c=o&&p(e,t);i?new Z(i,e,t,r,s,c):m(n,r,(n,r)=>W(e,t,n,r),c)}else!o||"value"===t&&"select"===e.localName&&!p(e,t)?W(e,t,n,void 0):u(e.localName,t,n)},ne=(e,t,n)=>{if("store-view"===e.kind){if(!o)throw S("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be rendered through createApp().render().");return void ne(o.resolve(e),t,n)}if("error-boundary"===e.kind)return void I(t,n,e.children,e.fallback);if("keyed"===e.kind)return void $({target:t,owner:n,vnode:e,scheduler:s,renderInto:re,reconcileView:X,preparePatch:f,...a.has(n)?{register:h}:{}});if("tracked-view"===e.kind)return void U({target:t,owner:n,vnode:e,scheduler:s,renderInto:re,preparePatch:f,reconcile:X});if("dynamic"===e.kind)return void ee(t,n,e.source,e.project,e.key);if("fragment"===e.kind)return void re(e.props.children,t,n);if("component"===e.kind){const r=new c(n);r.setComponentIdentity(e.type,e.key);const o=N(r,()=>e.type(e.props));return void re(o,t,r)}const r=function(e,t,n){const r=t instanceof Element?t:void 0;return"svg"===n||r?.namespaceURI===J&&"foreignObject"!==r.localName?e.createElementNS(J,n):e.createElement(n)}(t.ownerDocument??t,t,e.type);for(const[t,o]of Object.entries(e.props))"children"===t||"key"===t||K(e.type,t)||te(r,t,o,n);if(A(e.type,e.props)||re(e.props.children,r,n),"select"===e.type)for(const t of Y)t in e.props&&te(r,t,e.props[t],n);t.appendChild(r)},re=(e,t,n)=>{if(null==e||!1===e||!0===e)return;if(Array.isArray(e)){for(const r of e)re(r,t,n);return}const r=t.ownerDocument??t;if(k(e)){const o=r.createTextNode("");return E(e,o,n),void t.appendChild(o)}"object"!=typeof e?t.appendChild(r.createTextNode(q(e))):ne(e,t,n)},oe=(e,t)=>{const n=t?1===t.nodeType?`<${t.localName}>`:3===t.nodeType?`text ${JSON.stringify(t.nodeValue)}`:8===t.nodeType?`comment ${JSON.stringify(t.nodeValue)}`:`node type ${t.nodeType}`:"the end of the container";throw S("HYDRATION_MISMATCH",`Expected ${e}, but found ${n}.`)},se=(e,t,n,r)=>{if(null==e||!1===e||!0===e)return r;if(Array.isArray(e)){let o=r;for(const r of e)o=se(r,t,n,o);return o}if(k(e)){if(8!==r?.nodeType||r.nodeValue!==b)return oe(`the \x3c!--${b}--\x3e marker`,r);const o=r;let s=o.nextSibling;if(8===s?.nodeType&&s.nodeValue===x&&(s=(t.ownerDocument??t).createTextNode(""),t.insertBefore(s,o.nextSibling)),!s||3!==s.nodeType)return oe("reactive text",s);const i=s.nextSibling;if(8!==i?.nodeType||i.nodeValue!==x)return oe(`the \x3c!--${x}--\x3e marker`,i);const c=q(e.get());if(s.data!==c)return oe(`reactive text ${JSON.stringify(c)}`,s);const d=i.nextSibling;return o.parentNode?.removeChild(o),i.parentNode?.removeChild(i),E(e,s,n),d}if("object"!=typeof e)return((e,t,n)=>{const r=t.ownerDocument??t;if(""===e)return t.insertBefore(r.createTextNode(""),n),n;n&&3===n.nodeType||oe(`text ${JSON.stringify(e)}`,n);const o=n;return o.data===e?o.nextSibling:o.data.startsWith(e)?o.splitText(e.length):oe(`text ${JSON.stringify(e)}`,n)})(q(e),t,r);const i=e;if("fragment"===i.kind)return se(i.props.children,t,n,r);if("component"===i.kind){const e=new c(n);e.setComponentIdentity(i.type,i.key);const o=N(e,()=>i.type(i.props));return se(o,t,e,r)}if("store-view"===i.kind){if(!o)throw S("STORE_VIEW_OUTSIDE_APP","A view with store dependencies must be hydrated through createApp().hydrate().");return se(o.resolve(i),t,n,r)}if("tracked-view"===i.kind){const e=U({target:t,owner:n,vnode:i,scheduler:s,renderInto:re,preparePatch:f,reconcile:X,hydration:{node:r,hydrateInto:se}});return void 0===e?r:e}if("dynamic"===i.kind){const e=ee(t,n,i.source,i.project,i.key,{node:r,hydrateInto:se});return void 0===e?r:e}if("keyed"===i.kind){const e=$({target:t,owner:n,vnode:i,scheduler:s,renderInto:re,reconcileView:X,preparePatch:f,...a.has(n)?{register:h}:{},hydration:{node:r,hydrateInto:se}});return void 0===e?r:e}if("error-boundary"===i.kind){const e=I(t,n,i.children,i.fallback,{node:r,hydrateInto:se});return void 0===e?r:e}if(!(r instanceof Element)||r.localName!==i.type)return oe(`<${i.type}>`,r);for(const[e,t]of Object.entries(i.props))"children"===e||"key"===e||K(i.type,e)||te(r,e,t,n,!0);if(!A(i.type,i.props)){const e=se(i.props.children,r,n,r.firstChild);e&&oe(`the end of <${i.type}>`,e)}if("select"===i.type)for(const e of Y)e in i.props&&te(r,e,i.props[e],n,!0);return r.nextSibling},ie=()=>e.idPrefix??`r${(z++).toString(36)}`,ce=(e,t,r,s=!1)=>{const i=new c(void 0,!0,r),d=(t.ownerDocument??t).createDocumentFragment();let l=[];try{re(e,d,i),s&&o?.completeRestore?.(),l=Array.from(d.childNodes),t.appendChild(d),i.mount()}catch(e){n(e,()=>v(i,l))}let a=!1;return{dispose(){a||(a=!0,v(i,l))}}};return{mount:(e,t)=>ce(e,t,ie()),hydrate(t,r){const s=ie(),i=new c(void 0,!0,s);try{const e=se(t,r,i,r.firstChild);e&&oe("the end of the hydration root",e)}catch(n){if(g(n,()=>i.dispose()),!(n instanceof w)||"HYDRATION_MISMATCH"!==n.code)throw n;for(e.onError?.(n);r.firstChild;)r.removeChild(r.firstChild);return ce(t,r,s,!0)}const d=Array.from(r.childNodes);try{o?.completeRestore?.(),i.mount()}catch(e){n(e,()=>v(i,d))}let l=!1;return{dispose(){l||(l=!0,v(i,d))}}},flush:s.flush}}function te(e){if("string"!=typeof e)return e;const t=document.querySelector(e);if(!t)throw S("RENDER_TARGET_NOT_FOUND",`Render target "${e}" was not found.`);return t}function ne(e,r){if(void 0!==e&&void 0===r)throw S("RENDER_TARGET_NOT_FOUND","Pass a target to createApp(view, target), or call createApp() to mount later.");const o=new Set,s=new Set,i=M();let c=!1;const d={onCleanup:e=>c?(e(),()=>{}):(s.add(e),()=>s.delete(e)),dispose(){c||(c=!0,t(e=>{for(const t of Array.from(o))e(t.dispose);o.clear();for(const t of Array.from(s).reverse())e(t);s.clear(),e(i.dispose)}))},render(e,t,n){if(c)throw S("APP_DISPOSED","Cannot render a disposed app. app.dispose() has already run.");const r=function(e,t,n={},r){const o=ee(n,r);return{dispose:o.mount(e,te(t)).dispose,flush:o.flush}}(e,t,n,i);let s=!1;const d={flush:r.flush,dispose(){s||(s=!0,o.delete(d),r.dispose())}};return c?d.dispose():o.add(d),d},hydrate(e,t,n){if(c)throw S("APP_DISPOSED","Cannot hydrate with a disposed app. app.dispose() has already run.");const r=function(e,t,n={},r){const o=te(t),s=D(o,n.idPrefix);if(s?.stores.length){if(!r?.restore)throw S("HYDRATION_STATE_INVALID","Lazy-store hydration state requires createApp().hydrate().");r.restore(s.stores)}const i=ee(void 0===s?.idPrefix?n:{...n,idPrefix:s.idPrefix},r);return{dispose:i.hydrate(e,o).dispose,flush:i.flush}}(e,t,n,i);let s=!1;const d={flush:r.flush,dispose(){s||(s=!0,o.delete(d),r.dispose())}};return c?d.dispose():o.add(d),d}};if(void 0!==r)try{d.render(e,r)}catch(e){n(e,d.dispose)}return d}function re({fallback:e,children:t}){return{kind:"error-boundary",fallback:e,children:t}}const oe=e;export{re as ErrorBoundary,w as NexusDOMError,ne as createApp,oe as persist};
|
package/dist/esm/owner.d.ts
CHANGED
|
@@ -14,7 +14,12 @@ export declare class Owner {
|
|
|
14
14
|
private readonly ids;
|
|
15
15
|
private readonly idPath;
|
|
16
16
|
private nextIdChild;
|
|
17
|
+
private localStoreIndex;
|
|
18
|
+
private componentIdentity;
|
|
17
19
|
constructor(parent?: Owner | undefined, tracked?: boolean, identity?: string);
|
|
20
|
+
setComponentIdentity(type: unknown, key: unknown): void;
|
|
21
|
+
hasComponentIdentity(): boolean;
|
|
22
|
+
acquireLocalStore<T>(create: () => T, release: (value: T) => void): T;
|
|
18
23
|
reserveIdSegment(kind: string): string;
|
|
19
24
|
keyedIdSegment(region: string, key: RowKey): string;
|
|
20
25
|
id(): string;
|
|
@@ -27,6 +32,7 @@ export declare class Owner {
|
|
|
27
32
|
dispose(): void;
|
|
28
33
|
}
|
|
29
34
|
export declare function withOwner<T>(owner: Owner, run: () => T): T;
|
|
35
|
+
export declare function withLocalStore<T>(create: (local: boolean) => T, release: (value: T) => void): T;
|
|
30
36
|
export declare function captureOwnerId(): () => string;
|
|
31
37
|
/**---
|
|
32
38
|
* ## 
|
package/dist/esm/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{O as e,s as t,t as n,i as r,h as s,w as a,r as i,c as l,n as o,a as c,b as u,d as f,e as p,f as d,g as m}from"./chunks/store-view-
|
|
1
|
+
import{O as e,s as t,t as n,i as r,h as s,w as a,r as i,c as l,n as o,a as c,b as u,d as f,e as p,f as d,g as m}from"./chunks/store-view-DxtNNb3a.js";import"nexus-state";import"./chunks/types-DkNQRHR2.js";const y=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),v=/^[A-Za-z][A-Za-z0-9._:-]*$/,g=/^[A-Za-z_:][A-Za-z0-9:._-]*$/,h=e=>String(e).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),k=e=>h(e).replaceAll('"',"""),$=e=>"className"===e?"class":"htmlFor"===e?"for":e,w=e=>r(e)?e.get():e,S=e=>Object.entries(e).filter(([,e])=>null!=e&&!1!==e).map(([e,t])=>`${e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}:${String(t)}`).join(";");function b(b,A={}){const j=p({runSetup:!1}),I=A.idPrefix??"ssr",E=new e(void 0,!0,I),V=(t,n,p)=>{if(null==t||!1===t||!0===t)return"";if(Array.isArray(t))return t.map(e=>V(e,n,p)).join("");if(r(t)){const e=h(t.get());return A.hydration?s(e):e}if("object"!=typeof t)return h(t);const d=t;if("component"===d.kind){const t=new e(n);return t.setComponentIdentity(d.type,d.key),V(a(t,()=>d.type(d.props)),t,p)}if("store-view"===d.kind)return V(j.resolve(d),n,p);if("tracked-view"===d.kind){const t=new e(n,!0,n.reserveIdSegment("t")),r=d.track?d.track().value:d.project(d.source.get());return V(r,t,p)}if("fragment"===d.kind)return V(d.props.children,n,p);if("dynamic"===d.kind){const t=new e(n,!0,n.reserveIdSegment("d"));return V(d.project(d.source.get()),t,p)}if("keyed"===d.kind){const t=n.reserveIdSegment("l"),r=d.source.get();let s=0;return i(r,()=>({slot:s++})).map((s,a)=>{const i=new e(n,!0,n.keyedIdSegment(t,s)),{live:o,row:c}=l(r[a],i);return V(d.project(o,c),i,p)}).join("")}if("error-boundary"===d.kind){const t=new e(n),r=t.reserveIdSegment("b"),s=new e(t,!0,r),a=p&&{...p,values:new Set(p.values)};try{const e=V(d.children,s,a);return a&&(p.values=a.values),e}catch(n){s.dispose();const a="function"==typeof d.fallback?d.fallback(n,()=>{}):d.fallback,i=new e(t,!0,r);return V(a,i,p)}}if(!v.test(d.type))throw o("INVALID_SERVER_ELEMENT",`Cannot serialize the element name ${JSON.stringify(d.type)}.`);const{type:b,props:I}=d,E=m(b,I),_="value"in I?"value":"defaultValue",z="select"===b,N="option"===b;let x,C="";for(const[e,t]of Object.entries(d.props)){if("children"===e||"key"===e||"ref"===e||c(e)||(E||z)&&("value"===e||"defaultValue"===e)||N&&p&&"selected"===e)continue;let n=$(e),r=u(b,e,w(t));if("input"===b){if("defaultValue"===e){if("value"in I)continue;n="value"}if("defaultChecked"===e){if("checked"in I)continue;n="checked"}"value"===n&&null!=r&&"function"!=typeof r&&(r=String(r))}if(N&&"value"===n&&(x=r,null!=r&&"function"!=typeof r&&(r=String(r))),null!=r&&!1!==r&&"function"!=typeof r){if(!g.test(n))throw o("INVALID_SERVER_ATTRIBUTE",`Cannot serialize the attribute name ${JSON.stringify(n)}.`);if(!0===r)C+=` ${n}`;else if("style"===n&&"object"==typeof r){const e=S(r);e&&(C+=` style="${k(e)}"`)}else C+=` ${n}="${k(r)}"`}}if(y.has(b))return`<${b}${C}>`;if(E){const e=h(w(I[_])??"");return`<textarea${C}>${e.startsWith("\n")?"\n":""}${e}</textarea>`}let O=p;if(z){const e=Boolean(w(I.multiple));O=_ in I?{multiple:e,values:new Set([...f(w(I[_]),e)].map(h))}:void 0}const R=V(I.children,n,O);if(N&&p){const e=null==x||"function"==typeof x?R.replace(/<[^>]*>/g,"").replace(/[\t\n\f\r ]+/g," ").replace(/^ | $/g,""):h(x);p.values.has(e)&&(C+=" selected",p.multiple||p.values.delete(e))}return`<${b}${C}>${R}</${b}>`},_=()=>d(e=>{e(j.dispose),e(()=>E.dispose())});let z;try{z=V(b,E),A.hydration&&(z+=t(j.snapshots(),I))}catch(e){n(e,_)}return _(),z}export{b as renderToString};
|
package/dist/esm/store-view.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export type StoreRefs<R extends RecordAny> = {
|
|
|
24
24
|
};
|
|
25
25
|
type EmptyRecord = {};
|
|
26
26
|
declare const STORE_OPTIONS: unique symbol;
|
|
27
|
+
declare const STORE_RELEASE: unique symbol;
|
|
28
|
+
declare const STORE_LOCAL: unique symbol;
|
|
27
29
|
declare const STORE_TYPES: unique symbol;
|
|
28
30
|
/**---
|
|
29
31
|
* ## 
|
|
@@ -76,7 +78,7 @@ export interface StoreOptions<S extends RecordAny, A extends RecordAny, R extend
|
|
|
76
78
|
refs?: R;
|
|
77
79
|
/** Inline action factory, one `createActs` slice, or an array of slices. */
|
|
78
80
|
acts?: ((context: StoreActsContext<S, R, D>) => A) | StoreActsPart<S, A, R, D> | readonly StoreActsPart<S, A, R, D>[];
|
|
79
|
-
/** Prepares the first client render and may return
|
|
81
|
+
/** Prepares the first client render and may return cleanup for this store's lifetime. */
|
|
80
82
|
setup?: (context: StoreSetupContext<S, A, R, D>) => void | (() => void);
|
|
81
83
|
/**
|
|
82
84
|
* Connects client resources when the first consuming view mounts.
|
|
@@ -99,6 +101,8 @@ export interface StoreOptions<S extends RecordAny, A extends RecordAny, R extend
|
|
|
99
101
|
export interface StoreDefinition<S extends RecordAny, A extends RecordAny = EmptyRecord, R extends RecordAny = EmptyRecord, D extends readonly AnyStore[] = readonly []> {
|
|
100
102
|
readonly [STORE_OPTIONS]: StoreOptions<any, any, any, any>;
|
|
101
103
|
readonly dependencies: D;
|
|
104
|
+
[STORE_RELEASE]?: () => void;
|
|
105
|
+
readonly [STORE_LOCAL]?: boolean;
|
|
102
106
|
readonly [STORE_TYPES]: {
|
|
103
107
|
readonly state: S;
|
|
104
108
|
readonly acts: A;
|
|
@@ -108,10 +112,12 @@ export interface StoreDefinition<S extends RecordAny, A extends RecordAny = Empt
|
|
|
108
112
|
/**---
|
|
109
113
|
* ## 
|
|
110
114
|
* ### ***store***:
|
|
111
|
-
* declares a lazy store
|
|
115
|
+
* declares a lazy store for an application or a component instance.
|
|
112
116
|
* @description
|
|
113
|
-
*
|
|
114
|
-
*
|
|
117
|
+
* A descriptor declared outside a component is shared within each app and
|
|
118
|
+
* disposed with the app. A store declared while a JSX component renders
|
|
119
|
+
* belongs to that component instance: it survives parent updates at the
|
|
120
|
+
* same position and is disposed when the component leaves the tree.
|
|
115
121
|
* @param options initial state, actions, refs and lifecycle callbacks.
|
|
116
122
|
* @param dependencies optional stores available in actions and lifecycle callbacks.
|
|
117
123
|
* @returns the descriptor to pass to components or other stores.
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("nexus-state"),t=require("./types-BLzRvYOk.js");function r(e){let t;const r=e=>{try{e()}catch(e){(t??(t=[])).push(e)}};if(r(()=>e(r)),1===t?.length)throw t[0];if(t)throw new AggregateError(t,"nexus-dom: Multiple errors during cleanup.")}function n(e,t){try{t()}catch(t){throw new AggregateError([e,t],"nexus-dom: Rendering and cleanup failed.")}}function s(e,t){throw n(e,t),e}class o extends Error{constructor(e,t){super(`[${e}]\n${t}`),this.code=e,this.name="nexus-dom"}}function i(e,t){return new o(e,t)}function a(e,t,r,n,s){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?s.call(e,r):s?s.value=r:t.set(e,r),r}function c(e,t,r){let n=new Set,s=!1;const o=new Proxy(e,{get:(e,t,s)=>(n&&t in e&&n.add(t),!n&&r&&Object.hasOwn(e,t)?r(t):Reflect.get(e,t,s)),has:(e,t)=>(t in e&&n?.add(t),Reflect.has(e,t)),ownKeys:e=>(n&&(s=!0),Reflect.ownKeys(e))});try{return{value:t(o),dependencies:s?["*"]:Array.from(n)}}finally{n=void 0}}function u(e,t){if(e.length!==t.length)return!1;const r=t;return e.every(e=>r.includes(e))}var l,d,f;"function"==typeof SuppressedError&&SuppressedError;const h=new WeakMap,p=new WeakMap,y=new WeakMap,g=Symbol("nexus-dom.render-subscribe");function m(e,t,r){const n=e[g];return"function"==typeof n?n.call(e,t,r):e.subscribe(t)}function w(e,t,r,n,s){let o=!1;const i=(e,t)=>{if(!s)throw e;o=!0,s(e,t)};return{fail:i,update(s,a){let c;try{if(c=t(s),!o&&r(e,c))return}catch(e){return void i(e,a)}o=!1,e=c,n(c,a)}}}function b(e,t,r){return A(e,Boolean).branch(e=>e?t:r)}class v{constructor(e,t,r){this.source=e,this.project=t,this.isEqual=r,this[l]=!0}get(){return this.project(this.source.get())}subscribe(e){return this[g](e)}[(l=t.LIVE_VALUE,g)](e,t){const r=this.project(this.source.get()),{update:n,fail:s}=w(r,this.project,this.isEqual,e,t);return m(this.source,n,t?s:void 0)}map(e,t){return A(this,e,t)}if(e,t){return b(this,e,t)}branch(e,t){return _(this,e,t)}each(e){return D(this,e)}}const x=(e,t)=>null==e?void 0:e[t];class S{constructor(e,t){this.source=e,this.property=t}get[t.LIVE_VALUE](){return!0}get(){return x(this.source.get(),this.property)}subscribe(e){this.addListener(e);let t=!0;return()=>{t&&(t=!1,this.removeListener(e))}}addListener(e){const t=this.listeners;t?t instanceof Set?t.add(e):this.listeners=new Set([t,e]):this.listeners=e}removeListener(e){const t=this.listeners;t===e?this.listeners=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this.listeners=t.values().next().value))}update(e,t,r){const n=x(e,this.property),s=x(t,this.property);if(Object.is(n,s))return;const o=this.listeners;if(o)if(o instanceof Set)for(const e of Array.from(o))"function"==typeof e?e(s,r):e.notify(s,r);else"function"==typeof o?o(s,r):o.notify(s,r)}map(e,t){return A(this,e,t)}if(e,t){return b(this,e,t)}branch(e,t){return _(this,e,t)}each(e){return D(this,e)}}function A(e,t,r=Object.is){return new v(e,t,r)}const E=Symbol("nexus-dom.mutable-current"),O=Symbol("nexus-dom.mutable-listeners"),I=Symbol("nexus-dom.mutable-fields");class T{constructor(e){this[d]=!0,this[E]=e}get(){return this[E]}subscribe(e){const t=this[O];t?t instanceof Set?t.add(e):this[O]=new Set([t,e]):this[O]=e;let r=!0;return()=>{if(!r)return;r=!1;const t=this[O];t===e?this[O]=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this[O]=t.values().next().value))}}map(e,t){return A(this,e,t)}if(e,t){return b(this,e,t)}branch(e,t){return _(this,e,t)}each(e){return D(this,e)}$field(e){const t=this[I];if(!t){const t=new S(this,e);return this[I]=t,t}if(t instanceof Map){let r=t.get(e);return r||(r=new S(this,e),t.set(e,r)),r}let r=t,n=1;for(;r.property!==e&&r.next;)r=r.next,n++;if(r.property===e)return r;const s=new S(this,e);if(r.next=s,4===n){const e=new Map;for(let r=t;r;r=r.next)e.set(r.property,r);this[I]=e}return s}set(e,t){const r=this[E];if(Object.is(r,e))return;this[E]=e;const n=this[O];if(n instanceof Set)for(const r of Array.from(n))r(e,t);else n&&n(e,t);const s=this[I];if(s)if(s instanceof Map)for(const n of s.values())n.update(r,e,t);else for(let n=s;n;n=n.next)n.update(r,e,t)}}d=t.LIVE_VALUE;const N={get(e,t,r){if(t!==g)return t in e?Reflect.get(e,t,r):e.$field(t)}};class ${constructor(e){f.set(this,void 0),a(this,f,e,"f")}get id(){const e=function(e,t){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}(this,f);return"string"==typeof e?e:a(this,f,e.id(),"f")}}function _(e,t,r){return{kind:"dynamic",source:e,project:t,...r?.key?{key:r.key}:{}}}function D(e,t){const r=p.get(e);return{kind:"keyed",source:e,...void 0===r?{}:{stateKey:r},project:t}}function L(e,r,n=Object.is,s,o=e=>c(e,r)){const i={[t.LIVE_VALUE]:!0,get:()=>r(e.get()),subscribe:e=>i[g](e),[g](t,r){const s=o(e.get());let i=s.dependencies,a=!1,c=()=>{};const{update:l}=w(s.value,t=>{const r=o(t);if(!u(i,r.dependencies)){const t=c;i=r.dependencies,c=e.subscribe(d,i),t()}return r.value},n,t,r),d=(e,t)=>{a||l(e,t)};return c=e.subscribe(d,i),()=>{a||(a=!0,c())}},map(e,t){return A(this,e,t)},if(e,t){return b(this,e,t)},branch(e,t){return _(this,e,t)},each(e){return D(this,e)}};return void 0!==s&&p.set(i,s),i}function k(e,t,r,n){const s=L(e,t,r,void 0,n);return y.set(s,e),s}f=new WeakMap;const M=new Set(["innerhtml","outerhtml","srcdoc","dangerouslysetinnerhtml"]),C=new Set(["href","src","action","formaction","poster","xlink:href","xlinkhref"]),j=new Set(["http:","https:","mailto:","tel:"]);function R(e){const t=Array.from(e.options),r=t.filter(e=>e.defaultSelected);if(e.multiple)return r;if(r.length)return r.slice(-1);if(e.size>1)return[];const n=t.find(e=>!(e.disabled||"optgroup"===e.parentElement?.localName&&e.parentElement.hasAttribute("disabled")));return n?[n]:[]}const P=Symbol("nexus-dom.owner-mounted"),V=e=>{"function"==typeof e?e():e.dispose()};let H;function Y(){if(!H)throw i("ID_OUTSIDE_COMPONENT","Component ids can only be created while a component is mounting.");const e=H;let t;return()=>t??(t=e.id())}function U(e){if(null===e||"object"!=typeof e)return;const t=e.id;return"string"==typeof t||"number"==typeof t||"symbol"==typeof t?t:void 0}let F=1;const z=new WeakMap,W=new WeakMap,K=new WeakMap;let J=1;const q=Symbol("nexus-dom.no-list-payload");function X(e){let t=W.get(e);return void 0===t&&W.set(e,t=J++),t}function B(e,t=q){const r={...e,id:F++};return t!==q&&z.set(r,t),r}function G(e,t,r=!1){const n=r?t:t-1;if(!Number.isInteger(e)||e<0||e>n)throw i("INVALID_LIST_INDEX",n<0?`List index ${e} is invalid. The list is empty.`:`List index ${e} is outside 0..${n}.`)}const Z="nxs:t",Q="nxs:/",ee="nxs:s",te=(e,t,r)=>{if(null===e||"string"==typeof e||"boolean"==typeof e)return;if("number"==typeof e){if(Number.isFinite(e))return;throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} must be a finite number.`)}if("object"!=typeof e)throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains unsupported ${typeof e}.`);if(r.has(e))throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a cycle.`);const n=Object.getPrototypeOf(e);if(!Array.isArray(e)&&n!==Object.prototype&&null!==n)throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} must contain only plain objects and arrays.`);if(r.add(e),Array.isArray(e))for(let n=0;n<e.length;n++)te(e[n],`${t}[${n}]`,r);else{if(Object.getOwnPropertySymbols(e).length>0)throw i("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a symbol key.`);for(const[n,s]of Object.entries(e))te(s,`${t}.${n}`,r)}r.delete(e)},re=e=>{if(!e||"object"!=typeof e)return!1;const t=e;if(Array.isArray(t.keys)&&t.keys.every(e=>"string"==typeof e)&&t.state&&"object"==typeof t.state&&!Array.isArray(t.state)){const e=[...t.keys].sort(),r=Object.keys(t.state).sort();return e.length===r.length&&e.every((e,t)=>e===r[t])}return!1},ne=e=>{let t;try{t=JSON.parse(e)}catch{throw i("HYDRATION_STATE_INVALID","Hydration state is not valid JSON.")}if(!t||"object"!=typeof t||1!==t.v||"idPrefix"in t&&"string"!=typeof t.idPrefix||!Array.isArray(t.stores)||!t.stores.every(re))throw i("HYDRATION_STATE_INVALID","Hydration state does not match the supported versioned payload.");return t},se=Symbol("nexus-dom.store-options");function oe(e,t){if(Array.isArray(t))throw i("STORE_DEPENDENCY_CONFLICT","Use an object with named store dependencies.");for(const[r,n]of Object.entries(t)){if(""===r)throw i("STORE_DEPENDENCY_CONFLICT",`Store namespace "${r}" is reserved.`);if(e.has(r))throw i("STORE_DEPENDENCY_CONFLICT",`Store namespace "${r}" is already defined.`);e.set(r,[n])}return e}const ie=(e,r)=>{const n=function(e){const t=h.get(e);if(t)return t;const r=new Map,n=new Proxy(Object.create(null),{get(t,n){let s=r.get(n);return s||(s=L(e,e=>e[n],Object.is,n),r.set(n,s)),s}});return h.set(e,n),n}(e),s=new Map;return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;let i=s.get(o);if(i)return i;const a=n[o],c=r(o);return c?(i={[t.LIVE_VALUE]:!0,get:()=>a.get(),subscribe:e=>a.subscribe(e),[g]:(e,t)=>m(a,e,t),map:(e,t)=>a.map(e,t),if:(e,t)=>a.if(e,t),branch:(e,t)=>a.branch(e,t),each:a.each.bind(a),set(e,t="$.set"){"function"==typeof e?c.nexus.set(t=>({[o]:e(t[o])}),t):c.nexus.set({[o]:e},t)}},s.set(o,i),i):a}})};exports.NexusDOMError=o,exports.Owner=class{constructor(e,t=!0,r){this.parent=e,this.disposed=!1,this.nextIdChild=0,this.ids=e?.ids??{prefix:r??"r0",symbolIds:void 0,nextSymbolId:0,claims:void 0},this.idPath=e?`${e.idPath}/${r??e.reserveIdSegment("o")}`:"",e&&t&&(e.children??(e.children=new Set)).add(this)}reserveIdSegment(e){return`${e}${(this.nextIdChild++).toString(36)}`}keyedIdSegment(e,t){return"object"==typeof t?`${e}/a${t.slot.toString(36)}`:`${e}/k${((e,t)=>{if("string"==typeof e)return`s${e.length}:${e}`;if("number"==typeof e)return Object.is(e,-0)?"n:-0":`n:${String(e)}`;const r=Symbol.keyFor(e);if(void 0!==r)return`g${r.length}:${r}`;const n=t.symbolIds??(t.symbolIds=new Map);let s=n.get(e);return void 0===s&&(s=t.nextSymbolId++,n.set(e,s)),`y:${s.toString(36)}`})(t,this.ids)}`}id(){var e;const t=`v2\0${this.ids.prefix}\0${this.idPath}`,r=(e=>{let t=3735928559,r=1103547991;for(let n=0;n<e.length;n++){const s=e.charCodeAt(n);t=Math.imul(t^s,2654435761),r=Math.imul(r^s,1597334677)}t=Math.imul(t^t>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507)^Math.imul(t^t>>>13,3266489909);let n=4294967296*(2097151&r)+(t>>>0),s="";for(let e=0;e<7;e++)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[n%62]+s,n=Math.floor(n/62);return s})(t),n=(e=this.ids).claims??(e.claims=new Map),s=n.get(r);if(void 0!==s&&s.identity!==t)throw i("ID_HASH_COLLISION","Component id hash collision.");const o=s??{identity:t,owners:this};return s?s.owners instanceof Set?s.owners.add(this):s.owners!==this&&(s.owners=new Set([s.owners,this])):n.set(r,o),this.addCleanup(()=>{n.get(r)===o&&(o.owners instanceof Set?(o.owners.delete(this),0===o.owners.size?n.delete(r):1===o.owners.size&&(o.owners=o.owners.values().next().value)):o.owners===this&&n.delete(r))}),`nxs-${r}`}addCleanup(e){if(this.disposed)return void V(e);const t=this.cleanups;t?Array.isArray(t)?t.push(e):this.cleanups=[t,e]:this.cleanups=e}addMount(e){if(this.disposed)return;if(this.mounts===P)return void e();const t=this.mounts;t?Array.isArray(t)?t.push(e):this.mounts=[t,e]:this.mounts=e}isMounted(){return this.mounts===P}mount(){if(this.disposed||this.mounts===P)return;const e=this.mounts;if(this.mounts=P,Array.isArray(e))for(const t of e)t();else e?.();if(this.children)for(const e of this.children)e.mount()}setErrorHandler(e){this.errorHandler=e}handleError(e){if(this.errorHandler)try{return this.errorHandler(e),!0}catch(e){if(this.parent)return this.parent.handleError(e);throw e}return this.parent?.handleError(e)??!1}dispose(){if(this.disposed)return;this.disposed=!0,this.mounts=void 0;const e=this.cleanups;if(!this.children?.size&&!Array.isArray(e))return this.children=void 0,this.cleanups=void 0,this.parent?.children?.delete(this),void(e&&V(e));r(t=>{if(this.children){for(const e of Array.from(this.children))t(()=>e.dispose());this.children.clear(),this.children=void 0}if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--){const n=e[r];"function"==typeof n?t(n):n&&t(()=>n.dispose())}e.length=0}else"function"==typeof e?t(e):e&&t(()=>e.dispose());this.cleanups=void 0,this.parent?.children?.delete(this)})}},exports.TEXT_END=Q,exports.TEXT_START=Z,exports.checkedDOMValue=function(e,t,r){const n=t.toLowerCase();if(M.has(n)||n.startsWith("on"))throw i("UNSAFE_DOM_PROPERTY",`Cannot use "${t}" as a DOM property. Use JSX children or a function event handler.`);if("boolean"==typeof r&&n.startsWith("aria-"))return String(r);if(null==r||!1===r||!0===r||!C.has(n)&&("data"!==n||"object"!==e.toLowerCase()))return r;const s=String(r);let o;try{o=new URL(s,"https://nexus.invalid/").protocol}catch{}if(!o||!j.has(o))throw i("UNSAFE_DOM_URL",`"${t}" requires a relative URL or an http, https, mailto or tel URL.`);return s},exports.component=function(e,t=[]){const r=Array.isArray(t),n=r?void 0:oe(new Map,t);return s=>({kind:"store-view",dependencies:r?t:[],...n?{registry:n}:{},input:s,render:e,getId:Y()})},exports.componentScope=function(e){const t=oe(new Map,e);return(e,r)=>{const n=r?oe(new Map(t),r):t;return t=>({kind:"store-view",dependencies:[],registry:n,render:e,input:t,getId:Y()})}},exports.createActs=function(e){return e},exports.createMutableLiveItem=function(e,t){const r=new T(e);return{live:new Proxy(r,N),controller:r,row:new $(t)}},exports.createStoreViewRegistry=function(t={}){const n=new Map,o=[],a=new WeakMap,u=new Set,l=[];let d,f=0,h=!1;const p=e=>Object.keys(e).sort(),y=(e,t)=>e.length===t.length&&e.every((e,r)=>e===t[r]),g=a=>{const c=n.get(a);if(c)return c;if(u.has(a))throw i("STORE_DEPENDENCY_CYCLE","Store dependencies contain a cycle. Move shared state into a third store or remove one dependency.");u.add(a);const g=a[se];let m=!1;try{const c=w(a.dependencies),u={get:e=>{const t=c.source.get();return void 0===e?t:t[e]},$:c.$,select:c.select,acts:c.acts,refs:c.refs},v=(b=g.refs??{},Object.fromEntries(Object.entries(b).map(([e,t])=>[e,{current:t}]))),x=p(g.state),S=d?.[f];let A=g.state;if(d){if(!S||!S.state||"object"!=typeof S.state||Array.isArray(S.state)||!y(x,[...S.keys].sort())||!y(x,p(S.state)))throw i("HYDRATION_STATE_INVALID",`Hydration snapshot ${f} does not match store keys ${JSON.stringify(x)}.`);A=S.state,f++,m=!0}const E="function"==typeof g.acts?[g.acts]:g.acts,O=E&&E.length>1?new Map:void 0;let I,T;T=E?e.createNexus({state:A,acts:E.map((e,t)=>function(r,n){I??(I=function(e,t){const r=new Map;return{list(n){const s=r.get(n);if(s)return s;let o;const a=()=>{const t=o?.items??e(n);if(!Array.isArray(t))throw i("INVALID_LIST_FIELD",`The state field "${String(n)}" must be an array to use list().`);return t},c=(e,t,r)=>{if(o)return o.items=t,void o.operations.push(r);u(e,t,r)},u=(e,r,s)=>{K.set(s,{before:X(e),after:X(r)}),t({[n]:r},(e=>({source:`list.${e.type}`,meta:{nexusDOM:{list:e}}}))(s))},l={append(...e){if(0===e.length)return;const t=a();c(t,[...t,...e],B({key:n,type:"insert",index:t.length,count:e.length},[...e]))},insert(e,...t){if(0===t.length)return;const r=a();G(e,r.length,!0),c(r,[...r.slice(0,e),...t,...r.slice(e)],B({key:n,type:"insert",index:e,count:t.length},[...t]))},remove(e,t=1){const r=a();if(G(e,r.length),!Number.isInteger(t)||t<1||e+t>r.length)throw i("INVALID_LIST_REMOVE_COUNT",`Cannot remove ${t} item(s) from index ${e} in a list of ${r.length}.`);c(r,[...r.slice(0,e),...r.slice(e+t)],B({key:n,type:"remove",index:e,count:t}))},move(e,t){const r=a();if(G(e,r.length),G(t,r.length),e===t)return;const s=[...r],[o]=s.splice(e,1);s.splice(t,0,o),c(r,s,B({key:n,type:"move",from:e,to:t}))},replace(e,t){const r=a();G(e,r.length);const s=[...r];s[e]=t,c(r,s,B({key:n,type:"replace",index:e},t))},reverse(){const e=a();e.length<2||c(e,[...e].reverse(),B({key:n,type:"reorder"}))},batch(e){if(o)return void e(l,a);const t=a(),r={items:[...t],operations:[]};o=r;try{e(l,a)}finally{o=void 0}if(0===r.operations.length)return;if(a()!==t)throw i("LIST_BATCH_CONFLICT",`The "${String(n)}" array changed during list.batch(). Update it using the batch commands, or call set() outside the batch.`);const s=B({key:n,type:"batch",operations:r.operations});u(t,r.items,s)}};return r.set(n,l),l}}}(r,n));const s=e.call(this,{get:r,set:n,reset:(...e)=>T.reset(...e),refs:v,list:I.list,dependencies:u});if(O&&s)for(const e of Object.keys(s)){const r=O.get(e);if(void 0!==r)throw i("DUPLICATE_ACTION",`Action "${e}" appears in slices ${r+1} and ${t+1}. Give each action in store({ acts }) a unique name.`);O.set(e,t)}return s})}):e.createNexus({state:A});const N={nexus:T,refs:v};if(n.set(a,N),o.push(N),!1!==t.runSetup&&(g.setup||g.mount)){const e=new Set,t=t=>(e.add(t),()=>e.delete(t)),i=()=>{r(t=>{for(const r of Array.from(e).reverse())t(r);e.clear()})},d=()=>({nexus:T,$:ie(T,()=>N),select:(e,t)=>k(T,e,t),acts:T.acts,refs:v,dependencies:u,onCleanup:t});try{const t=g.setup?.(d());t&&e.add(t),l.push(i)}catch(e){n.delete(a),o.at(-1)===N&&o.pop(),s(e,i)}let f=g.mount;(f||c.mount)&&(N.mount=()=>{if(h)return;if(c.mount?.(),h)return;const t=f;if(f=void 0,!t)return;const n=new Set,o=()=>{r(e=>{for(const t of Array.from(n).reverse())e(t);n.clear()})};try{const e=t({...d(),onCleanup:e=>(n.add(e),()=>n.delete(e))});e&&n.add(e)}catch(e){s(e,o)}h?o():e.add(o)})}else c.mount&&(N.mount=c.mount);return N}catch(e){throw m&&f--,e}finally{u.delete(a)}var b},m=(e,t,r)=>{for(const[n,s]of Object.entries(t)){if(Object.prototype.hasOwnProperty.call(e,n))throw i("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same ${r} key "${n}".`);e[n]=s}},w=e=>{const t=a.get(e);if(t)return t;const r=e.map(e=>g(e)),n={},s={},o=new Map,c=new Map;for(const e of r){const t=e.nexus.get();o.set(e,new Set(Object.keys(t)));for(const r of Object.keys(t)){if(c.has(r))throw i("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same state key "${r}".`);c.set(r,e)}m(n,e.nexus.acts,"acts"),m(s,e.refs,"refs")}const u={get(){const e={};for(const t of r)m(e,t.nexus.get(),"state");return e},subscribe(e,t){const n=r.flatMap(r=>{const n=o.get(r),s="*"===t[0]?["*"]:t.filter(e=>n.has(String(e)));return 0===s.length?[]:[r.nexus.subscribe((t,r)=>e(u.get(),r),s)]});return()=>n.forEach(e=>e())}};u.get();const l=r.flatMap(e=>e.mount?[e.mount]:[]),d={source:u,readField:e=>"string"==typeof e?c.get(e)?.nexus.get(e):void 0,$:ie(u,e=>c.get(e)),select:(e,t)=>k(u,e,t),acts:n,refs:s};return l.length&&(d.mount=()=>l.forEach(e=>e())),a.set(e,d),d};return{restore(e){if(n.size>0)throw i("HYDRATION_STATE_LATE","Hydration state must be restored before the first lazy store is resolved.");d=e,f=0},completeRestore(){if(d&&f!==d.length)throw i("HYDRATION_STATE_INVALID",`Hydration provided ${d.length} store snapshots, but the view resolved ${f}.`);d=void 0},snapshots:()=>o.map(({nexus:e})=>{const t=e.get();return{keys:p(t),state:t}}),resolve(e){if(e.registry)return((e,t)=>{const r=new Map;let n=!1;const s=e=>{let s=r.get(e);if(s)return s;if(h)throw i("APP_DISPOSED","Cannot resolve a store after app disposal.");return s=w(t.get(e)),r.set(e,s),n&&s.mount?.(),s},o=(e,r=Object.create(null))=>new Proxy(r,{get:(r,n)=>"string"==typeof n&&t.has(n)?e(n):Reflect.get(r,n),has:(e,r)=>"string"==typeof r&&t.has(r)||Reflect.has(e,r),ownKeys:e=>[...t.keys(),...Reflect.ownKeys(e)],getOwnPropertyDescriptor:(r,n)=>"string"==typeof n&&t.has(n)?{enumerable:!0,configurable:!0,get:()=>e(n)}:Reflect.getOwnPropertyDescriptor(r,n)}),a=(e=e=>s(e).source.get(),t)=>{let r;return o(n=>{if(t&&!t())return s(n).source.get();let o=r?.get(n);return o||(o=e(n),(r??(r=new Map)).set(n,o)),o})},c={get:()=>a(),subscribe(e,t){const r=t.map(t=>s(t).source.subscribe((t,r)=>e(a(),r),["*"]));return()=>r.forEach(e=>e())}},u={get:c.get,subscribe(e,t){const r=new Map;for(const e of t){const[t,n]=JSON.parse(e);let s=r.get(t);s||r.set(t,s=[]),s.push(n??"*")}const n=Array.from(r,([t,r])=>s(t).source.subscribe((t,r)=>e(a(),r),r));return()=>n.forEach(e=>e())}},l=o(e=>s(e).$),d=(e,t)=>k(u,e,t,()=>(e=>{const t=new Map,r=e(a(e=>{const r=new Set;t.set(e,r);const n=n=>{"string"==typeof n?r.add(n):t.set(e,null)};return new Proxy(s(e).source.get(),{get:(e,t,r)=>(n(t),Reflect.get(e,t,r)),has:(e,t)=>(n(t),Reflect.has(e,t)),getOwnPropertyDescriptor:(e,t)=>(n(t),Reflect.getOwnPropertyDescriptor(e,t)),ownKeys:r=>(t.set(e,null),Reflect.ownKeys(r))})})),n=[];for(const[e,r]of t)if(r?.size)for(const t of r)n.push(JSON.stringify([e,t]));else n.push(JSON.stringify([e,null]));return{value:r,dependencies:n}})(e)),f=o(e=>s(e).acts),p=o(e=>s(e).refs),y=t=>e.render({get id(){return e.getId()},state:t,$:l,select:d,acts:f,refs:p},e.input);return{kind:"tracked-view",source:c,project:y,track:()=>(e=>{let t=new Set;try{return{value:e(a(e=>(t?.add(e),s(e).source.get()),()=>void 0!==t)),dependencies:[...t]}}finally{t=void 0}})(y),mountStores(){n=!0;for(const e of r.values())e.mount?.()}}})(e,e.registry);const t=w(e.dependencies),r=r=>e.render({get id(){return e.getId()},state:r,$:t.$,select:t.select,acts:t.acts,refs:t.refs},e.input);return{kind:"tracked-view",source:t.source,...t.mount?{mountStores:t.mount}:{},project:r,track:()=>c(t.source.get(),r,t.readField)}},dispose(){h||(h=!0,r(e=>{for(let t=l.length-1;t>=0;t--)e(l[t]);l.length=0,n.clear(),o.length=0}))}}},exports.defaultSelectedOptions=R,exports.disposeAfterFailure=n,exports.disposeNodes=function(e,t){try{e?.dispose()}finally{for(const e of t)e.parentNode?.removeChild(e)}},exports.getRowField=function(e){return e instanceof S?e:void 0},exports.hasEditedValue=function(e,t){if("checked"===t&&"input"===e.localName){const t=e;return t.checked!==t.defaultChecked}if("value"!==t)return!1;if("input"===e.localName||"textarea"===e.localName){const t=e;return t.value!==t.defaultValue}if("select"===e.localName){const t=e,r=R(t),n=t.selectedOptions;return n.length!==r.length||r.some((e,t)=>e!==n[t])}return!1},exports.hasListOperationPayload=function(e){return z.has(e)},exports.hasTextareaValue=function(e,t){return"textarea"===e&&("value"in t||"defaultValue"in t)},exports.hydrationText=e=>`\x3c!--${Z}--\x3e${e}\x3c!--${Q}--\x3e`,exports.inferredRowKey=U,exports.isEventProperty=e=>/^on[A-Z]/.test(e),exports.isLiveValue=function(e){return"object"==typeof e&&null!==e&&!0===e[t.LIVE_VALUE]},exports.nexusDOMError=i,exports.onCleanup=function(e){if(!H)throw i("CLEANUP_OUTSIDE_COMPONENT","onCleanup() must run inside a component.");H.addCleanup(e)},exports.readListOperation=function(e,t,r,n){if(void 0===t||!e||"object"!=typeof e)return;const s=e.meta;if(!s||"object"!=typeof s)return;const o=s.nexusDOM;if(!o||"object"!=typeof o)return;const i=o.list;if(!i||"object"!=typeof i)return;const a=i,c=K.get(a);return c&&a.key===t&&c.before===W.get(r)&&c.after===W.get(n)?a:void 0},exports.readListOperationPayload=function(e){return z.get(e)},exports.resolveRowKeys=function(e,t){const r=e.map(U),n=new Set,s=new Set;for(const e of r)void 0!==e&&(n.has(e)&&s.add(e),n.add(e));return r.map((r,n)=>void 0===r||s.has(r)?t(e[n]):r)},exports.runDisposal=r,exports.sameDependencies=u,exports.sameListSource=function(e,t){if(e===t)return!0;const r=y.get(e);return void 0!==r&&r===y.get(t)},exports.selectionValues=function(e,t){return new Set(t&&Array.isArray(e)?e.map(String):[String(e??"")])},exports.serializeHydrationState=(e,t)=>{let r;e.forEach((e,t)=>te(e.state,`stores[${t}].state`,new Set));try{r=JSON.stringify({v:1,idPrefix:t,stores:e})}catch(e){throw i("HYDRATION_STATE_INVALID",`Hydration state could not be serialized: ${String(e)}`)}ne(r);const n=r.replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`).replaceAll("--","-\\u002d");return`\x3c!--${ee}${n}--\x3e`},exports.store=function(e,t=[]){return{[se]:e,dependencies:t}},exports.subscribeForRender=m,exports.supportsRenderErrors=function(e){return g in e},exports.takeHydrationState=(e,t)=>{const r=Array.from(e.childNodes).filter(e=>8===e.nodeType&&(e.nodeValue??"").startsWith(ee));if(0===r.length)return;if(1!==r.length)throw i("HYDRATION_STATE_INVALID","Hydration root must contain at most one nxs:s payload.");const n=r[0],s=ne((n.nodeValue??"").slice(5));if(void 0!==t&&void 0!==s.idPrefix&&t!==s.idPrefix)throw i("HYDRATION_STATE_INVALID","The client idPrefix does not match the server's. Omit it to use the server prefix.");return n.parentNode?.removeChild(n),s},exports.throwAfterDisposal=s,exports.trackSelector=c,exports.withOwner=function(e,t){const r=H;H=e;try{return t()}finally{H=r}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createNexus as e}from"nexus-state";import{L as t}from"./types-DkNQRHR2.js";function r(e){let t;const r=e=>{try{e()}catch(e){(t??(t=[])).push(e)}};if(r(()=>e(r)),1===t?.length)throw t[0];if(t)throw new AggregateError(t,"nexus-dom: Multiple errors during cleanup.")}function n(e,t){try{t()}catch(t){throw new AggregateError([e,t],"nexus-dom: Rendering and cleanup failed.")}}function s(e,t){throw n(e,t),e}function o(e,t){try{e?.dispose()}finally{for(const e of t)e.parentNode?.removeChild(e)}}class i extends Error{constructor(e,t){super(`[${e}]\n${t}`),this.code=e,this.name="nexus-dom"}}function a(e,t){return new i(e,t)}function c(e,t,r,n,s){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?s.call(e,r):s?s.value=r:t.set(e,r),r}function u(e,t,r){let n=new Set,s=!1;const o=new Proxy(e,{get:(e,t,s)=>(n&&t in e&&n.add(t),!n&&r&&Object.hasOwn(e,t)?r(t):Reflect.get(e,t,s)),has:(e,t)=>(t in e&&n?.add(t),Reflect.has(e,t)),ownKeys:e=>(n&&(s=!0),Reflect.ownKeys(e))});try{return{value:t(o),dependencies:s?["*"]:Array.from(n)}}finally{n=void 0}}function l(e,t){if(e.length!==t.length)return!1;const r=t;return e.every(e=>r.includes(e))}var f,d,h;"function"==typeof SuppressedError&&SuppressedError;const p=new WeakMap,y=new WeakMap,g=new WeakMap;function m(e,t){if(e===t)return!0;const r=g.get(e);return void 0!==r&&r===g.get(t)}const w=Symbol("nexus-dom.render-subscribe");function b(e){return w in e}function v(e,t,r){const n=e[w];return"function"==typeof n?n.call(e,t,r):e.subscribe(t)}function S(e,t,r,n,s){let o=!1;const i=(e,t)=>{if(!s)throw e;o=!0,s(e,t)};return{fail:i,update(s,a){let c;try{if(c=t(s),!o&&r(e,c))return}catch(e){return void i(e,a)}o=!1,e=c,n(c,a)}}}function A(e,t,r){return N(e,Boolean).branch(e=>e?t:r)}class O{constructor(e,t,r){this.source=e,this.project=t,this.isEqual=r,this[f]=!0}get(){return this.project(this.source.get())}subscribe(e){return this[w](e)}[(f=t,w)](e,t){const r=this.project(this.source.get()),{update:n,fail:s}=S(r,this.project,this.isEqual,e,t);return v(this.source,n,t?s:void 0)}map(e,t){return N(this,e,t)}if(e,t){return A(this,e,t)}branch(e,t){return M(this,e,t)}each(e){return L(this,e)}}const I=(e,t)=>null==e?void 0:e[t];class E{constructor(e,t){this.source=e,this.property=t}get[t](){return!0}get(){return I(this.source.get(),this.property)}subscribe(e){this.addListener(e);let t=!0;return()=>{t&&(t=!1,this.removeListener(e))}}addListener(e){const t=this.listeners;t?t instanceof Set?t.add(e):this.listeners=new Set([t,e]):this.listeners=e}removeListener(e){const t=this.listeners;t===e?this.listeners=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this.listeners=t.values().next().value))}update(e,t,r){const n=I(e,this.property),s=I(t,this.property);if(Object.is(n,s))return;const o=this.listeners;if(o)if(o instanceof Set)for(const e of Array.from(o))"function"==typeof e?e(s,r):e.notify(s,r);else"function"==typeof o?o(s,r):o.notify(s,r)}map(e,t){return N(this,e,t)}if(e,t){return A(this,e,t)}branch(e,t){return M(this,e,t)}each(e){return L(this,e)}}function x(e){return e instanceof E?e:void 0}function N(e,t,r=Object.is){return new O(e,t,r)}const T=Symbol("nexus-dom.mutable-current"),$=Symbol("nexus-dom.mutable-listeners"),D=Symbol("nexus-dom.mutable-fields");class _{constructor(e){this[d]=!0,this[T]=e}get(){return this[T]}subscribe(e){const t=this[$];t?t instanceof Set?t.add(e):this[$]=new Set([t,e]):this[$]=e;let r=!0;return()=>{if(!r)return;r=!1;const t=this[$];t===e?this[$]=void 0:t instanceof Set&&(t.delete(e),1===t.size&&(this[$]=t.values().next().value))}}map(e,t){return N(this,e,t)}if(e,t){return A(this,e,t)}branch(e,t){return M(this,e,t)}each(e){return L(this,e)}$field(e){const t=this[D];if(!t){const t=new E(this,e);return this[D]=t,t}if(t instanceof Map){let r=t.get(e);return r||(r=new E(this,e),t.set(e,r)),r}let r=t,n=1;for(;r.property!==e&&r.next;)r=r.next,n++;if(r.property===e)return r;const s=new E(this,e);if(r.next=s,4===n){const e=new Map;for(let r=t;r;r=r.next)e.set(r.property,r);this[D]=e}return s}set(e,t){const r=this[T];if(Object.is(r,e))return;this[T]=e;const n=this[$];if(n instanceof Set)for(const r of Array.from(n))r(e,t);else n&&n(e,t);const s=this[D];if(s)if(s instanceof Map)for(const n of s.values())n.update(r,e,t);else for(let n=s;n;n=n.next)n.update(r,e,t)}}d=t;const k={get(e,t,r){if(t!==w)return t in e?Reflect.get(e,t,r):e.$field(t)}};class j{constructor(e){h.set(this,void 0),c(this,h,e,"f")}get id(){const e=function(e,t){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}(this,h);return"string"==typeof e?e:c(this,h,e.id(),"f")}}function C(e,t){const r=new _(e);return{live:new Proxy(r,k),controller:r,row:new j(t)}}function M(e,t,r){return{kind:"dynamic",source:e,project:t,...r?.key?{key:r.key}:{}}}function L(e,t){const r=y.get(e);return{kind:"keyed",source:e,...void 0===r?{}:{stateKey:r},project:t}}function R(e,r,n=Object.is,s,o=e=>u(e,r)){const i={[t]:!0,get:()=>r(e.get()),subscribe:e=>i[w](e),[w](t,r){const s=o(e.get());let i=s.dependencies,a=!1,c=()=>{};const{update:u}=S(s.value,t=>{const r=o(t);if(!l(i,r.dependencies)){const t=c;i=r.dependencies,c=e.subscribe(f,i),t()}return r.value},n,t,r),f=(e,t)=>{a||u(e,t)};return c=e.subscribe(f,i),()=>{a||(a=!0,c())}},map(e,t){return N(this,e,t)},if(e,t){return A(this,e,t)},branch(e,t){return M(this,e,t)},each(e){return L(this,e)}};return void 0!==s&&y.set(i,s),i}function P(e){return"object"==typeof e&&null!==e&&!0===e[t]}function H(e,t,r,n){const s=R(e,t,r,void 0,n);return g.set(s,e),s}h=new WeakMap;const Y=new Set(["innerhtml","outerhtml","srcdoc","dangerouslysetinnerhtml"]),V=new Set(["href","src","action","formaction","poster","xlink:href","xlinkhref"]),F=new Set(["http:","https:","mailto:","tel:"]),U=e=>/^on[A-Z]/.test(e);function z(e,t,r){const n=t.toLowerCase();if(Y.has(n)||n.startsWith("on"))throw a("UNSAFE_DOM_PROPERTY",`Cannot use "${t}" as a DOM property. Use JSX children or a function event handler.`);if("boolean"==typeof r&&n.startsWith("aria-"))return String(r);if(null==r||!1===r||!0===r||!V.has(n)&&("data"!==n||"object"!==e.toLowerCase()))return r;const s=String(r);let o;try{o=new URL(s,"https://nexus.invalid/").protocol}catch{}if(!o||!F.has(o))throw a("UNSAFE_DOM_URL",`"${t}" requires a relative URL or an http, https, mailto or tel URL.`);return s}function W(e,t){return"textarea"===e&&("value"in t||"defaultValue"in t)}function J(e,t){return new Set(t&&Array.isArray(e)?e.map(String):[String(e??"")])}function K(e){const t=Array.from(e.options),r=t.filter(e=>e.defaultSelected);if(e.multiple)return r;if(r.length)return r.slice(-1);if(e.size>1)return[];const n=t.find(e=>!(e.disabled||"optgroup"===e.parentElement?.localName&&e.parentElement.hasAttribute("disabled")));return n?[n]:[]}function q(e,t){if("checked"===t&&"input"===e.localName){const t=e;return t.checked!==t.defaultChecked}if("value"!==t)return!1;if("input"===e.localName||"textarea"===e.localName){const t=e;return t.value!==t.defaultValue}if("select"===e.localName){const t=e,r=K(t),n=t.selectedOptions;return n.length!==r.length||r.some((e,t)=>e!==n[t])}return!1}const B=Symbol("nexus-dom.owner-mounted"),G=e=>{"function"==typeof e?e():e.dispose()};class X{constructor(e,t=!0,r){this.parent=e,this.disposed=!1,this.nextIdChild=0,this.ids=e?.ids??{prefix:r??"r0",symbolIds:void 0,nextSymbolId:0,claims:void 0},this.idPath=e?`${e.idPath}/${r??e.reserveIdSegment("o")}`:"",e&&t&&(e.children??(e.children=new Set)).add(this)}reserveIdSegment(e){return`${e}${(this.nextIdChild++).toString(36)}`}keyedIdSegment(e,t){return"object"==typeof t?`${e}/a${t.slot.toString(36)}`:`${e}/k${((e,t)=>{if("string"==typeof e)return`s${e.length}:${e}`;if("number"==typeof e)return Object.is(e,-0)?"n:-0":`n:${String(e)}`;const r=Symbol.keyFor(e);if(void 0!==r)return`g${r.length}:${r}`;const n=t.symbolIds??(t.symbolIds=new Map);let s=n.get(e);return void 0===s&&(s=t.nextSymbolId++,n.set(e,s)),`y:${s.toString(36)}`})(t,this.ids)}`}id(){var e;const t=`v2\0${this.ids.prefix}\0${this.idPath}`,r=(e=>{let t=3735928559,r=1103547991;for(let n=0;n<e.length;n++){const s=e.charCodeAt(n);t=Math.imul(t^s,2654435761),r=Math.imul(r^s,1597334677)}t=Math.imul(t^t>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507)^Math.imul(t^t>>>13,3266489909);let n=4294967296*(2097151&r)+(t>>>0),s="";for(let e=0;e<7;e++)s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[n%62]+s,n=Math.floor(n/62);return s})(t),n=(e=this.ids).claims??(e.claims=new Map),s=n.get(r);if(void 0!==s&&s.identity!==t)throw a("ID_HASH_COLLISION","Component id hash collision.");const o=s??{identity:t,owners:this};return s?s.owners instanceof Set?s.owners.add(this):s.owners!==this&&(s.owners=new Set([s.owners,this])):n.set(r,o),this.addCleanup(()=>{n.get(r)===o&&(o.owners instanceof Set?(o.owners.delete(this),0===o.owners.size?n.delete(r):1===o.owners.size&&(o.owners=o.owners.values().next().value)):o.owners===this&&n.delete(r))}),`nxs-${r}`}addCleanup(e){if(this.disposed)return void G(e);const t=this.cleanups;t?Array.isArray(t)?t.push(e):this.cleanups=[t,e]:this.cleanups=e}addMount(e){if(this.disposed)return;if(this.mounts===B)return void e();const t=this.mounts;t?Array.isArray(t)?t.push(e):this.mounts=[t,e]:this.mounts=e}isMounted(){return this.mounts===B}mount(){if(this.disposed||this.mounts===B)return;const e=this.mounts;if(this.mounts=B,Array.isArray(e))for(const t of e)t();else e?.();if(this.children)for(const e of this.children)e.mount()}setErrorHandler(e){this.errorHandler=e}handleError(e){if(this.errorHandler)try{return this.errorHandler(e),!0}catch(e){if(this.parent)return this.parent.handleError(e);throw e}return this.parent?.handleError(e)??!1}dispose(){if(this.disposed)return;this.disposed=!0,this.mounts=void 0;const e=this.cleanups;if(!this.children?.size&&!Array.isArray(e))return this.children=void 0,this.cleanups=void 0,this.parent?.children?.delete(this),void(e&&G(e));r(t=>{if(this.children){for(const e of Array.from(this.children))t(()=>e.dispose());this.children.clear(),this.children=void 0}if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--){const n=e[r];"function"==typeof n?t(n):n&&t(()=>n.dispose())}e.length=0}else"function"==typeof e?t(e):e&&t(()=>e.dispose());this.cleanups=void 0,this.parent?.children?.delete(this)})}}let Z;function Q(e,t){const r=Z;Z=e;try{return t()}finally{Z=r}}function ee(){if(!Z)throw a("ID_OUTSIDE_COMPONENT","Component ids can only be created while a component is mounting.");const e=Z;let t;return()=>t??(t=e.id())}function te(e){if(!Z)throw a("CLEANUP_OUTSIDE_COMPONENT","onCleanup() must run inside a component.");Z.addCleanup(e)}function re(e){if(null===e||"object"!=typeof e)return;const t=e.id;return"string"==typeof t||"number"==typeof t||"symbol"==typeof t?t:void 0}function ne(e,t){const r=e.map(re),n=new Set,s=new Set;for(const e of r)void 0!==e&&(n.has(e)&&s.add(e),n.add(e));return r.map((r,n)=>void 0===r||s.has(r)?t(e[n]):r)}let se=1;const oe=new WeakMap,ie=new WeakMap,ae=new WeakMap;let ce=1;const ue=Symbol("nexus-dom.no-list-payload");function le(e){let t=ie.get(e);return void 0===t&&ie.set(e,t=ce++),t}function fe(e,t=ue){const r={...e,id:se++};return t!==ue&&oe.set(r,t),r}function de(e,t,r=!1){const n=r?t:t-1;if(!Number.isInteger(e)||e<0||e>n)throw a("INVALID_LIST_INDEX",n<0?`List index ${e} is invalid. The list is empty.`:`List index ${e} is outside 0..${n}.`)}function he(e,t,r,n){if(void 0===t||!e||"object"!=typeof e)return;const s=e.meta;if(!s||"object"!=typeof s)return;const o=s.nexusDOM;if(!o||"object"!=typeof o)return;const i=o.list;if(!i||"object"!=typeof i)return;const a=i,c=ae.get(a);return c&&a.key===t&&c.before===ie.get(r)&&c.after===ie.get(n)?a:void 0}function pe(e){return oe.get(e)}function ye(e){return oe.has(e)}const ge="nxs:t",me="nxs:/",we=e=>`\x3c!--${ge}--\x3e${e}\x3c!--${me}--\x3e`,be="nxs:s",ve=(e,t,r)=>{if(null===e||"string"==typeof e||"boolean"==typeof e)return;if("number"==typeof e){if(Number.isFinite(e))return;throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} must be a finite number.`)}if("object"!=typeof e)throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains unsupported ${typeof e}.`);if(r.has(e))throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a cycle.`);const n=Object.getPrototypeOf(e);if(!Array.isArray(e)&&n!==Object.prototype&&null!==n)throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} must contain only plain objects and arrays.`);if(r.add(e),Array.isArray(e))for(let n=0;n<e.length;n++)ve(e[n],`${t}[${n}]`,r);else{if(Object.getOwnPropertySymbols(e).length>0)throw a("HYDRATION_STATE_INVALID",`Hydration state at ${t} contains a symbol key.`);for(const[n,s]of Object.entries(e))ve(s,`${t}.${n}`,r)}r.delete(e)},Se=e=>{if(!e||"object"!=typeof e)return!1;const t=e;if(Array.isArray(t.keys)&&t.keys.every(e=>"string"==typeof e)&&t.state&&"object"==typeof t.state&&!Array.isArray(t.state)){const e=[...t.keys].sort(),r=Object.keys(t.state).sort();return e.length===r.length&&e.every((e,t)=>e===r[t])}return!1},Ae=e=>{let t;try{t=JSON.parse(e)}catch{throw a("HYDRATION_STATE_INVALID","Hydration state is not valid JSON.")}if(!t||"object"!=typeof t||1!==t.v||"idPrefix"in t&&"string"!=typeof t.idPrefix||!Array.isArray(t.stores)||!t.stores.every(Se))throw a("HYDRATION_STATE_INVALID","Hydration state does not match the supported versioned payload.");return t},Oe=(e,t)=>{let r;e.forEach((e,t)=>ve(e.state,`stores[${t}].state`,new Set));try{r=JSON.stringify({v:1,idPrefix:t,stores:e})}catch(e){throw a("HYDRATION_STATE_INVALID",`Hydration state could not be serialized: ${String(e)}`)}Ae(r);const n=r.replace(/[<>&\u2028\u2029]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`).replaceAll("--","-\\u002d");return`\x3c!--${be}${n}--\x3e`},Ie=(e,t)=>{const r=Array.from(e.childNodes).filter(e=>8===e.nodeType&&(e.nodeValue??"").startsWith(be));if(0===r.length)return;if(1!==r.length)throw a("HYDRATION_STATE_INVALID","Hydration root must contain at most one nxs:s payload.");const n=r[0],s=Ae((n.nodeValue??"").slice(5));if(void 0!==t&&void 0!==s.idPrefix&&t!==s.idPrefix)throw a("HYDRATION_STATE_INVALID","The client idPrefix does not match the server's. Omit it to use the server prefix.");return n.parentNode?.removeChild(n),s},Ee=Symbol("nexus-dom.store-options");function xe(e){return e}function Ne(e,t=[]){return{[Ee]:e,dependencies:t}}function Te(e,t=[]){const r=Array.isArray(t),n=r?void 0:De(new Map,t);return s=>({kind:"store-view",dependencies:r?t:[],...n?{registry:n}:{},input:s,render:e,getId:ee()})}function $e(e){const t=De(new Map,e);return(e,r)=>{const n=r?De(new Map(t),r):t;return t=>({kind:"store-view",dependencies:[],registry:n,render:e,input:t,getId:ee()})}}function De(e,t){if(Array.isArray(t))throw a("STORE_DEPENDENCY_CONFLICT","Use an object with named store dependencies.");for(const[r,n]of Object.entries(t)){if(""===r)throw a("STORE_DEPENDENCY_CONFLICT",`Store namespace "${r}" is reserved.`);if(e.has(r))throw a("STORE_DEPENDENCY_CONFLICT",`Store namespace "${r}" is already defined.`);e.set(r,[n])}return e}const _e=(e,r)=>{const n=function(e){const t=p.get(e);if(t)return t;const r=new Map,n=new Proxy(Object.create(null),{get(t,n){let s=r.get(n);return s||(s=R(e,e=>e[n],Object.is,n),r.set(n,s)),s}});return p.set(e,n),n}(e),s=new Map;return new Proxy(Object.create(null),{get(e,o){if("string"!=typeof o)return;let i=s.get(o);if(i)return i;const a=n[o],c=r(o);return c?(i={[t]:!0,get:()=>a.get(),subscribe:e=>a.subscribe(e),[w]:(e,t)=>v(a,e,t),map:(e,t)=>a.map(e,t),if:(e,t)=>a.if(e,t),branch:(e,t)=>a.branch(e,t),each:a.each.bind(a),set(e,t="$.set"){"function"==typeof e?c.nexus.set(t=>({[o]:e(t[o])}),t):c.nexus.set({[o]:e},t)}},s.set(o,i),i):a}})};function ke(t={}){const n=new Map,o=[],i=new WeakMap,c=new Set,l=[];let f,d=0,h=!1;const p=e=>Object.keys(e).sort(),y=(e,t)=>e.length===t.length&&e.every((e,r)=>e===t[r]),g=i=>{const u=n.get(i);if(u)return u;if(c.has(i))throw a("STORE_DEPENDENCY_CYCLE","Store dependencies contain a cycle. Move shared state into a third store or remove one dependency.");c.add(i);const g=i[Ee];let m=!1;try{const c=w(i.dependencies),u={get:e=>{const t=c.source.get();return void 0===e?t:t[e]},$:c.$,select:c.select,acts:c.acts,refs:c.refs},v=(b=g.refs??{},Object.fromEntries(Object.entries(b).map(([e,t])=>[e,{current:t}]))),S=p(g.state),A=f?.[d];let O=g.state;if(f){if(!A||!A.state||"object"!=typeof A.state||Array.isArray(A.state)||!y(S,[...A.keys].sort())||!y(S,p(A.state)))throw a("HYDRATION_STATE_INVALID",`Hydration snapshot ${d} does not match store keys ${JSON.stringify(S)}.`);O=A.state,d++,m=!0}const I="function"==typeof g.acts?[g.acts]:g.acts,E=I&&I.length>1?new Map:void 0;let x,N;N=e(I?{state:O,acts:I.map((e,t)=>function(r,n){x??(x=function(e,t){const r=new Map;return{list(n){const s=r.get(n);if(s)return s;let o;const i=()=>{const t=o?.items??e(n);if(!Array.isArray(t))throw a("INVALID_LIST_FIELD",`The state field "${String(n)}" must be an array to use list().`);return t},c=(e,t,r)=>{if(o)return o.items=t,void o.operations.push(r);u(e,t,r)},u=(e,r,s)=>{ae.set(s,{before:le(e),after:le(r)}),t({[n]:r},(e=>({source:`list.${e.type}`,meta:{nexusDOM:{list:e}}}))(s))},l={append(...e){if(0===e.length)return;const t=i();c(t,[...t,...e],fe({key:n,type:"insert",index:t.length,count:e.length},[...e]))},insert(e,...t){if(0===t.length)return;const r=i();de(e,r.length,!0),c(r,[...r.slice(0,e),...t,...r.slice(e)],fe({key:n,type:"insert",index:e,count:t.length},[...t]))},remove(e,t=1){const r=i();if(de(e,r.length),!Number.isInteger(t)||t<1||e+t>r.length)throw a("INVALID_LIST_REMOVE_COUNT",`Cannot remove ${t} item(s) from index ${e} in a list of ${r.length}.`);c(r,[...r.slice(0,e),...r.slice(e+t)],fe({key:n,type:"remove",index:e,count:t}))},move(e,t){const r=i();if(de(e,r.length),de(t,r.length),e===t)return;const s=[...r],[o]=s.splice(e,1);s.splice(t,0,o),c(r,s,fe({key:n,type:"move",from:e,to:t}))},replace(e,t){const r=i();de(e,r.length);const s=[...r];s[e]=t,c(r,s,fe({key:n,type:"replace",index:e},t))},reverse(){const e=i();e.length<2||c(e,[...e].reverse(),fe({key:n,type:"reorder"}))},batch(e){if(o)return void e(l,i);const t=i(),r={items:[...t],operations:[]};o=r;try{e(l,i)}finally{o=void 0}if(0===r.operations.length)return;if(i()!==t)throw a("LIST_BATCH_CONFLICT",`The "${String(n)}" array changed during list.batch(). Update it using the batch commands, or call set() outside the batch.`);const s=fe({key:n,type:"batch",operations:r.operations});u(t,r.items,s)}};return r.set(n,l),l}}}(r,n));const s=e.call(this,{get:r,set:n,reset:(...e)=>N.reset(...e),refs:v,list:x.list,dependencies:u});if(E&&s)for(const e of Object.keys(s)){const r=E.get(e);if(void 0!==r)throw a("DUPLICATE_ACTION",`Action "${e}" appears in slices ${r+1} and ${t+1}. Give each action in store({ acts }) a unique name.`);E.set(e,t)}return s})}:{state:O});const T={nexus:N,refs:v};if(n.set(i,T),o.push(T),!1!==t.runSetup&&(g.setup||g.mount)){const e=new Set,t=t=>(e.add(t),()=>e.delete(t)),a=()=>{r(t=>{for(const r of Array.from(e).reverse())t(r);e.clear()})},f=()=>({nexus:N,$:_e(N,()=>T),select:(e,t)=>H(N,e,t),acts:N.acts,refs:v,dependencies:u,onCleanup:t});try{const t=g.setup?.(f());t&&e.add(t),l.push(a)}catch(e){n.delete(i),o.at(-1)===T&&o.pop(),s(e,a)}let d=g.mount;(d||c.mount)&&(T.mount=()=>{if(h)return;if(c.mount?.(),h)return;const t=d;if(d=void 0,!t)return;const n=new Set,o=()=>{r(e=>{for(const t of Array.from(n).reverse())e(t);n.clear()})};try{const e=t({...f(),onCleanup:e=>(n.add(e),()=>n.delete(e))});e&&n.add(e)}catch(e){s(e,o)}h?o():e.add(o)})}else c.mount&&(T.mount=c.mount);return T}catch(e){throw m&&d--,e}finally{c.delete(i)}var b},m=(e,t,r)=>{for(const[n,s]of Object.entries(t)){if(Object.prototype.hasOwnProperty.call(e,n))throw a("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same ${r} key "${n}".`);e[n]=s}},w=e=>{const t=i.get(e);if(t)return t;const r=e.map(e=>g(e)),n={},s={},o=new Map,c=new Map;for(const e of r){const t=e.nexus.get();o.set(e,new Set(Object.keys(t)));for(const r of Object.keys(t)){if(c.has(r))throw a("STORE_DEPENDENCY_CONFLICT",`Store dependencies define the same state key "${r}".`);c.set(r,e)}m(n,e.nexus.acts,"acts"),m(s,e.refs,"refs")}const u={get(){const e={};for(const t of r)m(e,t.nexus.get(),"state");return e},subscribe(e,t){const n=r.flatMap(r=>{const n=o.get(r),s="*"===t[0]?["*"]:t.filter(e=>n.has(String(e)));return 0===s.length?[]:[r.nexus.subscribe((t,r)=>e(u.get(),r),s)]});return()=>n.forEach(e=>e())}};u.get();const l=r.flatMap(e=>e.mount?[e.mount]:[]),f={source:u,readField:e=>"string"==typeof e?c.get(e)?.nexus.get(e):void 0,$:_e(u,e=>c.get(e)),select:(e,t)=>H(u,e,t),acts:n,refs:s};return l.length&&(f.mount=()=>l.forEach(e=>e())),i.set(e,f),f};return{restore(e){if(n.size>0)throw a("HYDRATION_STATE_LATE","Hydration state must be restored before the first lazy store is resolved.");f=e,d=0},completeRestore(){if(f&&d!==f.length)throw a("HYDRATION_STATE_INVALID",`Hydration provided ${f.length} store snapshots, but the view resolved ${d}.`);f=void 0},snapshots:()=>o.map(({nexus:e})=>{const t=e.get();return{keys:p(t),state:t}}),resolve(e){if(e.registry)return((e,t)=>{const r=new Map;let n=!1;const s=e=>{let s=r.get(e);if(s)return s;if(h)throw a("APP_DISPOSED","Cannot resolve a store after app disposal.");return s=w(t.get(e)),r.set(e,s),n&&s.mount?.(),s},o=(e,r=Object.create(null))=>new Proxy(r,{get:(r,n)=>"string"==typeof n&&t.has(n)?e(n):Reflect.get(r,n),has:(e,r)=>"string"==typeof r&&t.has(r)||Reflect.has(e,r),ownKeys:e=>[...t.keys(),...Reflect.ownKeys(e)],getOwnPropertyDescriptor:(r,n)=>"string"==typeof n&&t.has(n)?{enumerable:!0,configurable:!0,get:()=>e(n)}:Reflect.getOwnPropertyDescriptor(r,n)}),i=(e=e=>s(e).source.get(),t)=>{let r;return o(n=>{if(t&&!t())return s(n).source.get();let o=r?.get(n);return o||(o=e(n),(r??(r=new Map)).set(n,o)),o})},c={get:()=>i(),subscribe(e,t){const r=t.map(t=>s(t).source.subscribe((t,r)=>e(i(),r),["*"]));return()=>r.forEach(e=>e())}},u={get:c.get,subscribe(e,t){const r=new Map;for(const e of t){const[t,n]=JSON.parse(e);let s=r.get(t);s||r.set(t,s=[]),s.push(n??"*")}const n=Array.from(r,([t,r])=>s(t).source.subscribe((t,r)=>e(i(),r),r));return()=>n.forEach(e=>e())}},l=o(e=>s(e).$),f=(e,t)=>H(u,e,t,()=>(e=>{const t=new Map,r=e(i(e=>{const r=new Set;t.set(e,r);const n=n=>{"string"==typeof n?r.add(n):t.set(e,null)};return new Proxy(s(e).source.get(),{get:(e,t,r)=>(n(t),Reflect.get(e,t,r)),has:(e,t)=>(n(t),Reflect.has(e,t)),getOwnPropertyDescriptor:(e,t)=>(n(t),Reflect.getOwnPropertyDescriptor(e,t)),ownKeys:r=>(t.set(e,null),Reflect.ownKeys(r))})})),n=[];for(const[e,r]of t)if(r?.size)for(const t of r)n.push(JSON.stringify([e,t]));else n.push(JSON.stringify([e,null]));return{value:r,dependencies:n}})(e)),d=o(e=>s(e).acts),p=o(e=>s(e).refs),y=t=>e.render({get id(){return e.getId()},state:t,$:l,select:f,acts:d,refs:p},e.input);return{kind:"tracked-view",source:c,project:y,track:()=>(e=>{let t=new Set;try{return{value:e(i(e=>(t?.add(e),s(e).source.get()),()=>void 0!==t)),dependencies:[...t]}}finally{t=void 0}})(y),mountStores(){n=!0;for(const e of r.values())e.mount?.()}}})(e,e.registry);const t=w(e.dependencies),r=r=>e.render({get id(){return e.getId()},state:r,$:t.$,select:t.select,acts:t.acts,refs:t.refs},e.input);return{kind:"tracked-view",source:t.source,...t.mount?{mountStores:t.mount}:{},project:r,track:()=>u(t.source.get(),r,t.readField)}},dispose(){h||(h=!0,r(e=>{for(let t=l.length-1;t>=0;t--)e(l[t]);l.length=0,n.clear(),o.length=0}))}}}export{x as A,b as B,m as C,Ie as D,Te as E,$e as F,xe as G,te as H,Ne as I,i as N,X as O,ge as T,U as a,z as b,C as c,J as d,ke as e,r as f,W as g,we as h,P as i,v as j,re as k,he as l,pe as m,a as n,ye as o,q as p,K as q,ne as r,Oe as s,s as t,u,o as v,Q as w,l as x,n as y,me as z};
|