@atom.io/spa 0.0.3 → 0.0.5

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.
Files changed (120) hide show
  1. package/README.md +202 -138
  2. package/README.mdx +62 -26
  3. package/dist/astro-application.d.ts +1 -1
  4. package/dist/astro-client.d.ts +3 -2
  5. package/dist/astro-client.d.ts.map +1 -1
  6. package/dist/astro-client.js +11 -10
  7. package/dist/astro-client.js.map +1 -1
  8. package/dist/astro-resumability-client.d.ts +10 -0
  9. package/dist/astro-resumability-client.d.ts.map +1 -0
  10. package/dist/astro-resumability-client.js +29 -0
  11. package/dist/astro-resumability-client.js.map +1 -0
  12. package/dist/astro-resumability-server.d.ts +3 -0
  13. package/dist/astro-resumability-server.d.ts.map +1 -0
  14. package/dist/astro-resumability-server.js +7 -0
  15. package/dist/astro-resumability-server.js.map +1 -0
  16. package/dist/astro-server.d.ts +3 -2
  17. package/dist/astro-server.d.ts.map +1 -1
  18. package/dist/astro-server.js +28 -9
  19. package/dist/astro-server.js.map +1 -1
  20. package/dist/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
  21. package/dist/astro-shared-83hxw7-M.js.map +1 -0
  22. package/dist/{astro-shared-BkWvVZWZ.d.ts → astro-shared-DHIpjNIG.d.ts} +2 -2
  23. package/dist/{astro-shared-BkWvVZWZ.d.ts.map → astro-shared-DHIpjNIG.d.ts.map} +1 -1
  24. package/dist/astro.d.ts +1 -1
  25. package/dist/astro.js +5 -7
  26. package/dist/astro.js.map +1 -1
  27. package/dist/{capabilities-CFP-HIuY.d.ts → capabilities-BCtBG-ni.d.ts} +19 -14
  28. package/dist/capabilities-BCtBG-ni.d.ts.map +1 -0
  29. package/dist/client.min.js +1 -1
  30. package/dist/{core-DCmqLZQP.js → core-DjFJ0aIJ.js} +31 -23
  31. package/dist/core-DjFJ0aIJ.js.map +1 -0
  32. package/dist/development/astro-client.js +11 -10
  33. package/dist/development/astro-client.js.map +1 -1
  34. package/dist/development/astro-resumability-client.js +29 -0
  35. package/dist/development/astro-resumability-client.js.map +1 -0
  36. package/dist/development/astro-resumability-server.js +7 -0
  37. package/dist/development/astro-resumability-server.js.map +1 -0
  38. package/dist/development/astro-server.js +28 -9
  39. package/dist/development/astro-server.js.map +1 -1
  40. package/dist/development/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
  41. package/dist/development/astro-shared-83hxw7-M.js.map +1 -0
  42. package/dist/development/astro.js +5 -7
  43. package/dist/development/astro.js.map +1 -1
  44. package/dist/development/{core-p9vciX9C.js → core-DxPiKryn.js} +31 -23
  45. package/dist/development/core-DxPiKryn.js.map +1 -0
  46. package/dist/development/{dom-Ci1XvbVJ.js → dom-BytVV6Rp.js} +44 -12
  47. package/dist/development/dom-BytVV6Rp.js.map +1 -0
  48. package/dist/development/index.js +4 -4
  49. package/dist/development/jsx-runtime.js.map +1 -1
  50. package/dist/development/konva.js +1 -1
  51. package/dist/development/konva.js.map +1 -1
  52. package/dist/development/motion.js +1 -1
  53. package/dist/development/renderer.js +1 -1
  54. package/dist/development/renderer.js.map +1 -1
  55. package/dist/development/server-renderer-CUQXh9oF.js +90 -0
  56. package/dist/development/server-renderer-CUQXh9oF.js.map +1 -0
  57. package/dist/development/server.js +2 -83
  58. package/dist/development/server.js.map +1 -1
  59. package/dist/{src-DCQa6qxs.js → development/src-WSHJxR9b.js} +4 -4
  60. package/dist/development/src-WSHJxR9b.js.map +1 -0
  61. package/dist/development/three.js +1 -1
  62. package/dist/development/three.js.map +1 -1
  63. package/dist/{dom-dHQM0O7Q.js → dom-B5OxgHkr.js} +44 -12
  64. package/dist/dom-B5OxgHkr.js.map +1 -0
  65. package/dist/{index-CJJXcKaw.d.ts → index-DufwkB6W.d.ts} +5 -5
  66. package/dist/{index-CJJXcKaw.d.ts.map → index-DufwkB6W.d.ts.map} +1 -1
  67. package/dist/index.d.ts +4 -4
  68. package/dist/index.js +4 -4
  69. package/dist/{jsx-runtime-CREZYKDC.d.ts → jsx-runtime-DMDVr7A5.d.ts} +7 -7
  70. package/dist/{jsx-runtime-CREZYKDC.d.ts.map → jsx-runtime-DMDVr7A5.d.ts.map} +1 -1
  71. package/dist/jsx-runtime.d.ts +1 -1
  72. package/dist/jsx-runtime.js.map +1 -1
  73. package/dist/konva.d.ts +16 -16
  74. package/dist/konva.js +1 -1
  75. package/dist/konva.js.map +1 -1
  76. package/dist/motion.d.ts +1 -1
  77. package/dist/motion.js +1 -1
  78. package/dist/renderer.d.ts +4 -4
  79. package/dist/renderer.d.ts.map +1 -1
  80. package/dist/renderer.js +1 -1
  81. package/dist/renderer.js.map +1 -1
  82. package/dist/server-renderer-DcU55e6s.js +90 -0
  83. package/dist/server-renderer-DcU55e6s.js.map +1 -0
  84. package/dist/server.d.ts +2 -2
  85. package/dist/server.d.ts.map +1 -1
  86. package/dist/server.js +2 -83
  87. package/dist/server.js.map +1 -1
  88. package/dist/size.json +16 -16
  89. package/dist/{development/src-DG0xjuS5.js → src-DWIqXCiz.js} +4 -4
  90. package/dist/src-DWIqXCiz.js.map +1 -0
  91. package/dist/three.d.ts +17 -17
  92. package/dist/three.js +1 -1
  93. package/dist/three.js.map +1 -1
  94. package/package.json +27 -11
  95. package/src/astro-client.ts +20 -7
  96. package/src/astro-resumability-client.ts +40 -0
  97. package/src/astro-resumability-server.ts +7 -0
  98. package/src/astro-server.ts +58 -19
  99. package/src/astro-shared.ts +5 -2
  100. package/src/astro.ts +11 -3
  101. package/src/core.ts +54 -49
  102. package/src/dom.ts +73 -39
  103. package/src/index.ts +4 -4
  104. package/src/jsx-runtime.ts +7 -6
  105. package/src/jsx-types.d.ts +2 -2
  106. package/src/konva.ts +3 -3
  107. package/src/renderer.ts +24 -18
  108. package/src/server-renderer.ts +162 -0
  109. package/src/server.ts +4 -153
  110. package/src/three.ts +4 -4
  111. package/src/use-loadable.ts +3 -3
  112. package/dist/astro-shared-BT45auwR.js.map +0 -1
  113. package/dist/capabilities-CFP-HIuY.d.ts.map +0 -1
  114. package/dist/core-DCmqLZQP.js.map +0 -1
  115. package/dist/development/astro-shared-BT45auwR.js.map +0 -1
  116. package/dist/development/core-p9vciX9C.js.map +0 -1
  117. package/dist/development/dom-Ci1XvbVJ.js.map +0 -1
  118. package/dist/development/src-DG0xjuS5.js.map +0 -1
  119. package/dist/dom-dHQM0O7Q.js.map +0 -1
  120. package/dist/src-DCQa6qxs.js.map +0 -1
package/dist/astro.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"astro.js","names":[],"sources":["../src/astro.ts"],"sourcesContent":["import type { AstroIntegration } from \"astro\"\n\nimport type { SpaPluginOptions } from \"./vite.ts\"\nimport spa from \"./vite.ts\"\n\nexport type {\n\tAstroApplicationContext,\n\tAstroStoreContext,\n\tAstroStoreFactory,\n\tAstroStorePreparation,\n\tIsland,\n} from \"./astro-shared.ts\"\n\nexport default function integration(\n\toptions: SpaPluginOptions = {},\n): AstroIntegration {\n\treturn {\n\t\tname: `spa`,\n\t\thooks: {\n\t\t\t\"astro:config:setup\"({\n\t\t\t\taddRenderer,\n\t\t\t\taddMiddleware,\n\t\t\t\tinjectScript,\n\t\t\t\tupdateConfig,\n\t\t\t}) {\n\t\t\t\taddMiddleware({\n\t\t\t\t\tentrypoint: `@atom.io/spa/astro-middleware`,\n\t\t\t\t\torder: `pre`,\n\t\t\t\t})\n\t\t\t\tinjectScript(\n\t\t\t\t\t`page`,\n\t\t\t\t\t`import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`,\n\t\t\t\t)\n\t\t\t\taddRenderer({\n\t\t\t\t\tname: `spa`,\n\t\t\t\t\tclientEntrypoint: `@atom.io/spa/astro-client`,\n\t\t\t\t\tserverEntrypoint: `@atom.io/spa/astro-server`,\n\t\t\t\t})\n\t\t\t\tupdateConfig({\n\t\t\t\t\tvite: {\n\t\t\t\t\t\tplugins: [spa({ include: /\\.spa\\.[jt]sx$/, ...options })],\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t},\n\t\t},\n\t}\n}\n"],"mappings":";;AAaA,SAAwB,YACvB,UAA4B,CAAC,GACV;CACnB,OAAO;EACN,MAAM;EACN,OAAO,EACN,qBAAqB,EACpB,aACA,eACA,cACA,gBACE;GACF,cAAc;IACb,YAAY;IACZ,OAAO;GACR,CAAC;GACD,aACC,QACA,oGACD;GACA,YAAY;IACX,MAAM;IACN,kBAAkB;IAClB,kBAAkB;GACnB,CAAC;GACD,aAAa,EACZ,MAAM,EACL,SAAS,CAAC,IAAI;IAAE,SAAS;IAAkB,GAAG;GAAQ,CAAC,CAAC,EACzD,EACD,CAAC;EACF,EACD;CACD;AACD"}
1
+ {"version":3,"file":"astro.js","names":[],"sources":["../src/astro.ts"],"sourcesContent":["import type { AstroIntegration } from \"astro\"\n\nimport type { SpaPluginOptions } from \"./vite.ts\"\nimport spa from \"./vite.ts\"\n\nexport type {\n\tAstroApplicationContext,\n\tAstroStoreContext,\n\tAstroStoreFactory,\n\tAstroStorePreparation,\n\tIsland,\n} from \"./astro-shared.ts\"\n\nexport default function integration(\n\toptions: SpaPluginOptions = {},\n): AstroIntegration {\n\treturn {\n\t\tname: `spa`,\n\t\thooks: {\n\t\t\t\"astro:config:setup\"({\n\t\t\t\tconfig,\n\t\t\t\taddRenderer,\n\t\t\t\taddMiddleware,\n\t\t\t\tinjectScript,\n\t\t\t\tupdateConfig,\n\t\t\t}) {\n\t\t\t\taddMiddleware({\n\t\t\t\t\tentrypoint: `@atom.io/spa/astro-middleware`,\n\t\t\t\t\torder: `pre`,\n\t\t\t\t})\n\t\t\t\tinjectScript(\n\t\t\t\t\t`page`,\n\t\t\t\t\t`import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`,\n\t\t\t\t)\n\t\t\t\tconst resumable = config.integrations.some(\n\t\t\t\t\t({ name }) => name === `resumability`,\n\t\t\t\t)\n\t\t\t\taddRenderer({\n\t\t\t\t\tname: `spa`,\n\t\t\t\t\tclientEntrypoint: resumable\n\t\t\t\t\t\t? `@atom.io/spa/astro-resumability-client`\n\t\t\t\t\t\t: `@atom.io/spa/astro-client`,\n\t\t\t\t\tserverEntrypoint: resumable\n\t\t\t\t\t\t? `@atom.io/spa/astro-resumability-server`\n\t\t\t\t\t\t: `@atom.io/spa/astro-server`,\n\t\t\t\t})\n\t\t\t\tupdateConfig({\n\t\t\t\t\tvite: {\n\t\t\t\t\t\tplugins: [spa(options)],\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t},\n\t\t},\n\t}\n}\n"],"mappings":";;AAaA,SAAwB,YACvB,UAA4B,CAAC,GACV;CACnB,OAAO;EACN,MAAM;EACN,OAAO,EACN,qBAAqB,EACpB,QACA,aACA,eACA,cACA,gBACE;GACF,cAAc;IACb,YAAY;IACZ,OAAO;GACR,CAAC;GACD,aACC,QACA,oGACD;GACA,MAAM,YAAY,OAAO,aAAa,MACpC,EAAE,WAAW,SAAS,cACxB;GACA,YAAY;IACX,MAAM;IACN,kBAAkB,YACf,2CACA;IACH,kBAAkB,YACf,2CACA;GACJ,CAAC;GACD,aAAa,EACZ,MAAM,EACL,SAAS,CAAC,IAAI,OAAO,CAAC,EACvB,EACD,CAAC;EACF,EACD;CACD;AACD"}
@@ -33,12 +33,14 @@ type Cleanup = () => void;
33
33
  interface Accessor<T> {
34
34
  (): T;
35
35
  }
36
- type Component<P = any> = (props: P) => Child;
37
- interface VNode {
36
+ type Component<P = any> = (props: P) => Children;
37
+ /** A JSX descriptor for an intrinsic tag, component, or fragment. */
38
+ interface SpaElement {
38
39
  type: string | Component | null;
39
40
  props: Record<string, any>;
40
41
  }
41
- type Child = VNode | string | number | bigint | boolean | null | undefined | readonly Child[] | Accessor<Child>;
42
+ /** Renderable content, including nested groups and reactive accessors. */
43
+ type Children = SpaElement | string | number | bigint | boolean | null | undefined | readonly Children[] | Accessor<Children>;
42
44
  interface RootOptions {
43
45
  capabilities?: readonly Capability[];
44
46
  store?: RootStore;
@@ -56,6 +58,7 @@ interface Scope {
56
58
  _dead: boolean;
57
59
  }
58
60
  interface Root extends Scope {
61
+ _onRead?: ((value: unknown, token: ReadableToken<unknown>) => void) | undefined;
59
62
  _presence?: PresenceCoordinator;
60
63
  _capabilities: Map<string, Capability>;
61
64
  _store: RootStore;
@@ -72,24 +75,26 @@ declare function onCleanup(cleanup: Cleanup): void;
72
75
  declare function onMount(run: Cleanup): void;
73
76
  declare function useId(): string;
74
77
  /** Capture a token for this instance. Change the component key to change its token. */
75
- declare function useValue<T, E = never>(token: ReadableToken<T, any, E>): Accessor<ViewOf<T | E>>;
76
- declare function useValue<T, K extends Canonical, E = never>(family: ReadableFamilyToken<T, K, E>, key: NoInfer<K>): Accessor<ViewOf<T | E>>;
78
+ declare function useGetter<T, E = never>(token: ReadableToken<T, any, E>): Accessor<ViewOf<T | E>>;
79
+ declare function useGetter<T, K extends Canonical, E = never>(family: ReadableFamilyToken<T, K, E>, key: NoInfer<K>): Accessor<ViewOf<T | E>>;
77
80
  declare function useSetter<T>(token: WritableToken<T, any, any>): (value: T | Setter<T>) => void;
78
81
  declare function useSetter<T, K extends Canonical>(family: WritableFamilyToken<T, K, any>, key: NoInfer<K>): (value: T | Setter<T>) => void;
79
82
  declare function useTransaction<F extends (...args: any[]) => any>(token: TransactionToken<F>): (...args: Parameters<F>) => ReturnType<F>;
80
83
  declare function useRef<E extends Element>(token: RegularAtomToken<E | null>): (element: E | null) => void;
81
84
  declare function useRef<E extends Element, K extends Canonical>(family: RegularAtomFamilyToken<E | null, K>, key: NoInfer<K>): (element: E | null) => void;
82
- interface TimelineValue {
83
- at: number;
84
- length: number;
85
+ interface TimelineControls {
86
+ getCursor(): number;
87
+ getLength(): number;
85
88
  undo(): void;
86
89
  redo(): void;
87
90
  clear(): void;
88
- undoTransaction?: Cleanup;
89
- redoTransaction?: Cleanup;
91
+ getTransaction(): {
92
+ undo?: Cleanup;
93
+ redo?: Cleanup;
94
+ };
90
95
  }
91
- declare function useTimeline<M extends TimelineManageable>(token: TimelineToken<M>): Accessor<TimelineValue>;
92
- declare function useTimeline<K extends Canonical, M extends TimelineManageable>(family: TimelineFamilyToken<K, M>, key: NoInfer<K>): Accessor<TimelineValue>;
96
+ declare function useTimeline<M extends TimelineManageable>(token: TimelineToken<M>): TimelineControls;
97
+ declare function useTimeline<K extends Canonical, M extends TimelineManageable>(family: TimelineFamilyToken<K, M>, key: NoInfer<K>): TimelineControls;
93
98
  /** Native renderers expose property access without importing capability engines. */
94
99
  interface CapabilityTarget {
95
100
  kind: string;
@@ -111,5 +116,5 @@ interface Capability {
111
116
  scheduleFrame?(callback: (time: number) => void): Cleanup;
112
117
  attach(target: CapabilityTarget): CapabilityBinding;
113
118
  }
114
- export { useTransaction as _, Child as a, TimelineValue as c, onMount as d, useId as f, useTimeline as g, useStore as h, Accessor as i, VNode as l, useSetter as m, CapabilityBinding as n, Component as o, useRef as p, CapabilityTarget as r, RootOptions as s, Capability as t, onCleanup as u, useValue as v };
115
- //# sourceMappingURL=capabilities-CFP-HIuY.d.ts.map
119
+ export { useTimeline as _, Children as a, SpaElement as c, onMount as d, useGetter as f, useStore as g, useSetter as h, Accessor as i, TimelineControls as l, useRef as m, CapabilityBinding as n, Component as o, useId as p, CapabilityTarget as r, RootOptions as s, Capability as t, onCleanup as u, useTransaction as v };
120
+ //# sourceMappingURL=capabilities-BCtBG-ni.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities-BCtBG-ni.d.ts","names":[],"sources":["../src/presence.ts","../src/core.ts","../src/capabilities.ts"],"mappings":";;;UAIiB;EAChB,UAAU;EACV;;UAEgB;EAChB,QAAQ;EACR;;UAEgB;EAChB;EACA;EACA,YAAY;;UAEI,mBAAmB,GAAG;EACtC,KAAK,cAAc,OAAO,IAAI;EAC9B,OACC,QAAQ,GACR,cACA,mBACA,eACA,MAAM;EAEP,MAAM,SAAS,MAAM;;UAEL;EAChB,WAAW,GAAG,GACb,QAAQ,QAAQ,MAAM,OACtB,aAAa,QAAQ,GAAG,OAAO,gBAC7B,mBAAmB,GAAG;EACzB,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;EAChB;EACA;EACA;EACA;EACA;EACA;IAAoB,OAAO;IAAS,OAAO;;;iBAE5B,YAAY,UAAU,oBACrC,OAAO,cAAc,KACnB;iBACa,YAAY,UAAU,WAAW,UAAU,oBAC1D,QAAQ,oBAAoB,GAAG,IAC/B,KAAK,QAAQ,KACX;;UC9Wc;EAChB;EACA;EACA,YAAY;EACZ,MAAM;EACN,OAAO,aAAa;EACpB,QAAQ,eAAe,uBAAuB;;UAE9B;EAChB,MAAM,OAAO,0BAA0B;EACvC;EACA,OAAO,OAAO;EACd;;UAEgB;EAChB;EACA,UAAU,MAAM,OAAO;EACvB,eAAe,WAAW,wBAAwB;EAClD,OAAO,QAAQ,mBAAmB"}
@@ -1 +1 @@
1
- import{IMPLICIT as e,actUponStore as t,clearTimelineInStore as n,findInStore as r,findTimelineInStore as i,getFromStore as a,getTimelineTransactionAtHead as o,inspectTimelineInStore as s,setIntoStore as c,subscribeToState as l,subscribeToTimeline as u,timeTravel as d,timeTravelTransactionGroupInStore as f,withdraw as p}from"atom.io/internal";var m,h,g=0;function _(e,t){let n=m;m=e;try{return t()}finally{m=n}}function v(e){let t=h;h=void 0;try{return e()}finally{h=t}}function y(e){let t={_root:e?._root,_parent:e,_cleanups:new Set,_updates:[],_dead:!1};return e?._cleanups.add(t),t}function b(e,t){try{x(e)}catch(e){throw AggregateError([t,e])}throw t}function x(e){if(e._dead)return;e._dead=!0;let t=[];try{e._root._presence?.forget(e)}catch(e){t.push(e)}for(let n of[...e._cleanups].reverse())try{typeof n==`function`?n():x(n)}catch(e){t.push(e)}if(e._parent?._cleanups.delete(e),e._cleanups.clear(),e._updates.length=0,t.length)throw AggregateError(t)}function S(e){for(let t of e._updates)C(e,t);for(let t of e._cleanups)typeof t!=`function`&&S(t)}function C(e,t){if(!R(e))return;let n=e._root;n._queue.size||queueMicrotask(()=>{try{n.flush()}catch(e){n.error(e)}}),n._queue.add(t)}function w(t={},n=!1){let r=new Map;for(let e of t.capabilities??[]){if(r.has(e.namespace))throw Error(`spa: duplicate capability ${e.namespace}`);r.set(e.namespace,e)}let i={_capabilities:r,_store:t.store??e.STORE,_prefix:t.idPrefix??`w${g++}`,_id:0,...y(),_queue:new Set,_mounts:n?void 0:[]};i._root=i,i.error=t.onError??(e=>{throw e});for(let e of r.values())if(e.presence){if(i._presence)throw Error(`spa: multiple presence coordinators`);i._presence=e.presence(i)}return i.flush=()=>{try{for(;i._queue.size||i._mounts.length;){for(let e of[...i._queue])i._queue.delete(e)&&e();for(let e of i._mounts.splice(0))e()}}catch(e){b(i,e)}},i}function T(){return m._root._store}function E(e){m._cleanups.add(e)}function D(e){let t=m;t._root._mounts?.push(()=>{t._dead||_(t,()=>{v(e)})})}function O(){let e=m._root;return`${e._prefix}-${e._id++}`}function k(e,t,n){let r=new Map,i=()=>{if(!R(e))return;let a=new Set,o=h;h=t=>{a.add(t),r.has(t)||r.set(t,t(()=>{C(e,i)}))};let s;try{s=_(e,t)}finally{h=o;for(let[e,t]of r)a.has(e)||(t(),r.delete(e))}v(()=>{n(s)})};e._updates.push(i),e._cleanups.add(()=>{e._root._queue.delete(i);for(let e of r.values())e()}),i()}function A(e,t){let n=m._root._store;return e.type.endsWith(`_family`)?r(n,e,t):e}function j(e,t){e=A(e,t);let n=m._root._store,r=t=>l(n,e,`spa:${g++}`,t);return()=>{let t=a(n,e);return h?.(r),t}}function M(e,t){e=A(e,t);let n=m._root._store;return t=>{c(n,e,t)}}function N(e){return t(m._root._store,e,`spa:${g++}`)}var P=new WeakMap;function F(e,t){e=A(e,t);let n=m._root._store,r=P.get(n)??new Map;P.set(n,r);let i={},o=null;return t=>{t?(o=t,r.set(e.key,i),c(n,e,t)):r.get(e.key)===i&&(r.delete(e.key),a(n,e)===o&&c(n,e,null),o=null)}}function I(e,t){let r=m._root._store;e.type===`timeline_family`&&(e=i(r,e,t));let a=t=>u(r,e,`spa:${g++}`,t),c={undo:()=>{d(r,`undo`,e)},redo:()=>{d(r,`redo`,e)},clear:()=>{n(r,e)}};return()=>{let t={...s(r,e),...c};h?.(a);for(let n of[`undo`,`redo`]){let i=o(r.timelines.get(e.key),n);i&&(t[`${n}Transaction`]=()=>f(r,n,i))}return t}}function L(e){return typeof e==`function`?L(e()):Array.isArray(e)?e.map(L).join(``):e==null||typeof e==`boolean`?``:String(e)}function R(e){for(let t=e;t;t=t._parent)if(t._dead||t._exiting)return!1;return!0}var z=e=>e.children;function B(e,t,n){return{type:e,props:n===void 0?t??{}:U(t??{},{key:n})}}var V=B,H=B;function U(...e){let t=()=>e.map(e=>(typeof e==`function`?e():e)??{});return new Proxy({},{get:(e,n)=>t().reverse().find(e=>Object.hasOwn(e,n))?.[n],ownKeys:()=>[...new Set(t().flatMap(Object.keys))],getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0})})}function W(e){let t=e.indexOf(`:`);if(t<0)return;let n=e.slice(0,t);return/^(xml|xmlns|xlink)$/.test(n)?void 0:n}function G(e,t){for(let n of Object.keys(t)){let t=W(n);if(t&&!e._root._capabilities.has(t))throw Error(`spa: capability "${t}" is not registered for this root`)}}function K(e,t,n){let r=new Map;return e._root._presence?.target(e,t),e._cleanups.add(()=>{let e=[];for(let t of[...r.values()].reverse())try{t.dispose()}catch(t){e.push(t)}if(r.clear(),e.length)throw AggregateError(e)}),i=>{G(e,i);let a={},o=new Map;for(let t of Object.keys(i)){let n=W(t);if(!n){let n=i[t];a[t]=t.startsWith(`on`)&&typeof n==`function`?e._root._presence?.event(e,n)??n:n;continue}let r=o.get(n)??{};r[t.slice(n.length+1)]=i[t],o.set(n,r)}for(let[a,s]of o){let o=r.get(a);o||(o=e._root._capabilities.get(a).attach(t),r.set(a,o),e._root._presence?.bind(e,o,n??(()=>i),a)),o.update(s)}for(let[t,n]of r)o.has(t)||(r.delete(t),e._root._presence?.unbind(n),n.dispose());return a}}var q=`http://www.w3.org/1999/xhtml`,J=`http://www.w3.org/2000/svg`;function Y(e,t,n,r,i){if(i&&(e.nodeType!==3||e.nodeValue||i.node?.nodeType===3)){let t=i.node;if(!t||t.nodeType!==e.nodeType||t.nodeName!==e.nodeName||t.namespaceURI!==e.namespaceURI||e.nodeType!==1&&t.nodeValue!==e.nodeValue)throw Error(void 0);e=t,i.node=t.nextSibling}else t.insertBefore(e,i?i.node:n);return r._cleanups.add(()=>{e.remove()}),e}function X(e,t,n,r,i){return Y(t.ownerDocument.createComment(e),t,n,r,i)}function Z(e,t,n,r){if(!/^(key|children|ref)$/.test(t)&&(t!==`innerHTML`||e.localName!==`astro-slot`)){if(/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(t))throw Error(void 0);if(t.startsWith(`on`)){let i=/(?<!Pointer)Capture$/.test(t),a=t.slice(2,i?-7:void 0).toLowerCase().replace(`doubleclick`,`dblclick`);r&&e.removeEventListener(a,r,i),n!=null&&e.addEventListener(a,n,i)}else if(t===`className`&&(t=`class`),t===`htmlFor`&&(t=`for`),e.namespaceURI===q&&t in e&&!/^(style|form|list)$/.test(t)){let r=e;r[t]=n??(typeof r[t]!=`boolean`&&``)}else n==null||n===!1&&!/^(aria-|data-)/.test(t)?e.removeAttribute(t):e.setAttribute(t,n===!0&&!/^(aria-|data-)/.test(t)?``:String(n))}}function Q(e,t,n,r,i,a,o=()=>e){if(typeof e==`function`){X(`{`,t,n,r,a);let e=null,s=new Map,c=r._root._presence?.collection(e=>e._scope,(e,t)=>typeof e._value==typeof t&&e._value?.type===t?.type),l=(e,t,n,r)=>{c?c.remove(e,t,n,r,()=>{}):x(e._scope)},u=a;k(r,()=>o()(),a=>{let o=[a].flat(1/0),d=new Map,f=t.ownerDocument.activeElement;for(let a=0;a<o.length;a++){let f=o[a],p=f,m=p?.props?.key,h=m==null?a:String(m),g=s.get(h);if(g&&(typeof g._value!=typeof f||g._value?.type!==p?.type)&&(l(g,h,f==null||typeof f==`boolean`,[...s.keys()].indexOf(h)),g=void 0),g??=c?.take(h,f),g)g._value=f,r._root._presence?.resume(g._scope),S(g._scope);else{let a=y(r);g={_value:f,_scope:a,_start:X(`[`,t,e??n,a,u),_end:null};let o=g;Q(f,t,e??n,a,i,u,()=>o._value),g._end=X(`]`,t,e??n,a,u)}d.set(h,g)}for(let[e,t]of s)d.has(e)||l(t,e,!0,[...s.keys()].indexOf(e));if(!u){let r=e??n,i=c?.merge([...d.values()])??[...d.values()];for(let e of i.reverse()){if(e._end.nextSibling!==r){let n=t.ownerDocument.createRange();n.setStartBefore(e._start),n.setEndAfter(e._end),t.insertBefore(n.extractContents(),r)}r=e._start}f?.isConnected&&!f.closest(`[inert]`)&&f!==t.ownerDocument.activeElement&&f.focus({preventScroll:!0})}u=void 0,s=d}),e=X(`}`,t,n,r,a);return}if(Array.isArray(e)){for(let o of e)Q(o,t,n,r,i,a);return}if(e==null||typeof e==`boolean`)return;if(typeof e!=`object`){X(`t`,t,n,r,a);let i=Y(t.ownerDocument.createTextNode(String(e)),t,n,r,a);k(r,o,e=>{let t=String(e);i.nodeValue!==t&&(i.nodeValue=t)});return}let s=e,c=U(()=>o().props);if(!s.type||s.type===z){Q(()=>c.children,t,n,r,i,a);return}if(typeof s.type==`function`){let e=y(r);Q(_(e,()=>v(()=>s.type(c))),t,n,e,i,a);return}let l=s.type===`svg`?J:i,u=Y(t.ownerDocument.createElementNS(l,s.type),t,n,r,a);if(s.type===`astro-slot`)a||(u.innerHTML=c.innerHTML??``);else if(l===q&&/^(textarea|title|style|script)$/.test(s.type))k(r,()=>L(s.type===`textarea`?c.value??c.children:c.children),e=>{u.textContent!==e&&(u.textContent=e)});else{let e=a?{node:u.firstChild}:void 0;if(/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(s.type)&&l===q||Q(()=>c.children,u,null,r,s.type===`foreignObject`?q:l,e),e?.node)throw Error(void 0)}let d=K(r,{kind:`dom`,node:u},()=>({...c})),f={};r._cleanups.add(()=>{for(let e in f)e.startsWith(`on`)&&Z(u,e,null,f[e])}),k(r,()=>({...c}),e=>{let t=d(e);for(let e in{...f,...t})Object.is(f[e],t[e])&&typeof t[e]!=`object`||(Z(u,e,t[e],f[e]),f[e]=t[e]);f=t});let p=v(()=>c.ref);p&&r._root._mounts.unshift(()=>{r._dead||(r._cleanups.add(()=>p(null)),p(u))})}function $(e,t,n,r){let i=r?{node:t.firstChild}:void 0,a=i?.node?.nodeValue?.slice(2);if(r&&(a===void 0||n.idPrefix!==void 0&&a!==n.idPrefix))throw Error(void 0);let o=w(n);a!==void 0&&(o._prefix=a);try{if(X(`w:${o._prefix}`,t,null,o,i),_(o,()=>{Q(v(e),t,null,o,t.namespaceURI===J?J:q,i)}),X(`/w`,t,null,o,i),i?.node)throw Error(void 0);o.flush()}catch(e){b(o,e)}return{dispose:()=>{x(o)},flush:o.flush}}function ee(e,t,n={}){return $(e,t,n,!1)}function te(e,t,n={}){return $(e,t,n,!0)}function ne(...e){let t=m._root._store,[n]=e,r=n.type.endsWith(`_family`),i=A(n,e[1]),a=j(i),o=r?2:1,s=e[o],c=e.length>o,l=c,u=s,d;return()=>{let e=a(),n=e instanceof Promise;if(!n){u=e,l=!0;let n=p(t,i);d=c&&`catch`in n&&n.catch.some(t=>e instanceof t)?e:void 0}return l?d?{loading:n,value:s,error:d}:{loading:n,value:u}:`LOADING`}}export{z as Fragment,te as hydrate,B as jsx,H as jsxDEV,V as jsxs,U as merge,E as onCleanup,D as onMount,ee as render,O as useId,ne as useLoadable,F as useRef,M as useSetter,T as useStore,I as useTimeline,N as useTransaction,j as useValue};
1
+ import{IMPLICIT as e,actUponStore as t,clearTimelineInStore as n,findInStore as r,findTimelineInStore as i,getFromStore as a,getTimelineTransactionAtHead as o,setIntoStore as s,subscribeToState as c,subscribeToTimeline as l,timeTravel as u,timeTravelTransactionGroupInStore as d,withdraw as f,withdraw as p}from"atom.io/internal";var m,h,g=0;function _(e,t){let n=m;m=e;try{return t()}finally{m=n}}function v(e){let t=h;h=void 0;try{return e()}finally{h=t}}function y(e){let t={_root:e?._root,_parent:e,_cleanups:new Set,_updates:[],_dead:!1};return e?._cleanups.add(t),t}function b(e,t){try{x(e)}catch(e){throw AggregateError([t,e])}throw t}function x(e){if(e._dead)return;e._dead=!0;let t=[];try{e._root._presence?.forget(e)}catch(e){t.push(e)}for(let n of[...e._cleanups].reverse())try{typeof n==`function`?n():x(n)}catch(e){t.push(e)}if(e._parent?._cleanups.delete(e),e._cleanups.clear(),e._updates.length=0,t.length)throw AggregateError(t)}function S(e){for(let t of e._updates)C(e,t);for(let t of e._cleanups)typeof t!=`function`&&S(t)}function C(e,t){if(!L(e))return;let n=e._root;n._queue.size||queueMicrotask(()=>{try{n.flush()}catch(e){n.error(e)}}),n._queue.add(t)}function w(t={},n=!1){let r=new Map;for(let e of t.capabilities??[]){if(r.has(e.namespace))throw Error(`spa: duplicate capability ${e.namespace}`);r.set(e.namespace,e)}let i={_capabilities:r,_store:t.store??e.STORE,_prefix:t.idPrefix??`w${g++}`,_id:0,...y(),_queue:new Set,_mounts:n?void 0:[]};i._root=i,i.error=t.onError??(e=>{throw e});for(let e of r.values())if(e.presence){if(i._presence)throw Error(`spa: multiple presence coordinators`);i._presence=e.presence(i)}return i.flush=()=>{try{for(;i._queue.size||i._mounts.length;){for(let e of[...i._queue])i._queue.delete(e)&&e();for(let e of i._mounts.splice(0))e()}}catch(e){b(i,e)}},i}function T(){return m._root._store}function E(e){m._cleanups.add(e)}function D(e){let t=m;t._root._mounts?.push(()=>{t._dead||_(t,()=>{v(e)})})}function ee(){let e=m._root;return`${e._prefix}-${e._id++}`}function O(e,t,n){let r=new Map,i=()=>{if(!L(e))return;let a=new Set,o=h;h=t=>{a.add(t),r.has(t)||r.set(t,t(()=>{C(e,i)}))};let s;try{s=_(e,t)}finally{h=o;for(let[e,t]of r)a.has(e)||(t(),r.delete(e))}v(()=>{n(s)})};e._updates.push(i),e._cleanups.add(()=>{e._root._queue.delete(i);for(let e of r.values())e()}),i()}function k(e,t){let n=m._root._store;return e.type.endsWith(`_family`)?r(n,e,t):e}function A(e,t){e=k(e,t);let n=m._root,r=n._store,i=t=>c(r,e,`spa:${g++}`,t);return()=>{let t=a(r,e);return n._onRead?.(t,e),h?.(i),t}}function j(e,t){e=k(e,t);let n=m._root._store;return t=>{s(n,e,t)}}function M(e){return t(m._root._store,e,`spa:${g++}`)}var N=new WeakMap;function P(e,t){e=k(e,t);let n=m._root._store,r=N.get(n)??new Map;N.set(n,r);let i={},o=null;return t=>{t?(o=t,r.set(e.key,i),s(n,e,t)):r.get(e.key)===i&&(r.delete(e.key),a(n,e)===o&&s(n,e,null),o=null)}}function F(e,t){let r=m._root._store,a=e.type===`timeline_family`?i(r,e,t):e,s=e=>l(r,a,`spa:${g++}`,e),c=()=>{let e=f(r,a);return h?.(s),e};return{getCursor:()=>c().at,getLength:()=>c().history.length,undo:()=>{u(r,`undo`,a)},redo:()=>{u(r,`redo`,a)},clear:()=>{n(r,a)},getTransaction:()=>{let e=c(),t={};for(let n of[`undo`,`redo`]){let i=o(e,n);i&&(t[n]=()=>{d(r,n,i)})}return t}}}function I(e){return typeof e==`function`?I(e()):Array.isArray(e)?e.map(I).join(``):e==null||typeof e==`boolean`?``:String(e)}function L(e){for(let t=e;t;t=t._parent)if(t._dead||t._exiting)return!1;return!0}var R=e=>e.children;function z(e,t,n){return{type:e,props:n===void 0?t??{}:H(t??{},{key:n})}}var B=z,V=z;function H(...e){let t=()=>e.map(e=>(typeof e==`function`?e():e)??{});return new Proxy({},{get:(e,n)=>t().reverse().find(e=>Object.hasOwn(e,n))?.[n],ownKeys:()=>[...new Set(t().flatMap(Object.keys))],getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0})})}function U(e){let t=e.indexOf(`:`);if(t<0)return;let n=e.slice(0,t);return/^(xml|xmlns|xlink)$/.test(n)?void 0:n}function W(e,t){for(let n of Object.keys(t)){let t=U(n);if(t&&!e._root._capabilities.has(t))throw Error(`spa: capability "${t}" is not registered for this root`)}}function G(e,t,n){let r=new Map;return e._root._presence?.target(e,t),e._cleanups.add(()=>{let e=[];for(let t of[...r.values()].reverse())try{t.dispose()}catch(t){e.push(t)}if(r.clear(),e.length)throw AggregateError(e)}),i=>{W(e,i);let a={},o=new Map;for(let t of Object.keys(i)){let n=U(t);if(!n){let n=i[t];a[t]=t.startsWith(`on`)&&typeof n==`function`?e._root._presence?.event(e,n)??n:n;continue}let r=o.get(n)??{};r[t.slice(n.length+1)]=i[t],o.set(n,r)}for(let[a,s]of o){let o=r.get(a);o||(o=e._root._capabilities.get(a).attach(t),r.set(a,o),e._root._presence?.bind(e,o,n??(()=>i),a)),o.update(s)}for(let[t,n]of r)o.has(t)||(r.delete(t),e._root._presence?.unbind(n),n.dispose());return a}}var K=`http://www.w3.org/1999/xhtml`,q=`http://www.w3.org/2000/svg`;function J(e){if(e?.node)for(e.report(null,e.node);e.node;){let t=e.node;e.node=t.nextSibling,t.remove()}}function Y(e,t,n,r,i){if(i&&(e.nodeType!==3||e.nodeValue||i.node?.nodeType===3)){let n=i.node;!n||n.nodeType!==e.nodeType||n.nodeName!==e.nodeName||n.namespaceURI!==e.namespaceURI||e.nodeType!==1&&n.nodeValue!==e.nodeValue?(i.report(e,n),t.insertBefore(e,n),i.node=n?.nextSibling??null,n?.remove()):(e=n,i.node=n.nextSibling)}else t.insertBefore(e,i?i.node:n);return r._cleanups.add(()=>{e.remove()}),e}function X(e,t,n,r,i){return Y(t.ownerDocument.createComment(e),t,n,r,i)}function Z(e,t,n,r){if(!/^(key|children|ref)$/.test(t)&&(t!==`innerHTML`||e.localName!==`astro-slot`)){if(/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(t))throw Error(void 0);if(t.startsWith(`on`)){let i=/(?<!Pointer)Capture$/.test(t),a=t.slice(2,i?-7:void 0).toLowerCase().replace(`doubleclick`,`dblclick`);r&&e.removeEventListener(a,r,i),n!=null&&e.addEventListener(a,n,i)}else if(t===`className`&&(t=`class`),t===`htmlFor`&&(t=`for`),e.namespaceURI===K&&t in e&&!/^(style|form|list)$/.test(t)){let r=e;r[t]=n??(typeof r[t]!=`boolean`&&``)}else n==null||n===!1&&!/^(aria-|data-)/.test(t)?e.removeAttribute(t):e.setAttribute(t,n===!0&&!/^(aria-|data-)/.test(t)?``:String(n))}}function Q(e,t,n,r,i,a,o=()=>e){if(typeof e==`function`){X(`{`,t,n,r,a);let e=null,s=new Map,c=r._root._presence?.collection(e=>e._scope,(e,t)=>typeof e._value==typeof t&&e._value?.type===t?.type),l=(e,t,n,r)=>{c?c.remove(e,t,n,r,()=>{}):x(e._scope)},u=a;O(r,()=>o()(),a=>{let o=[a].flat(1/0),d=new Map,f=t.ownerDocument.activeElement;for(let a=0;a<o.length;a++){let f=o[a],p=f,m=p?.props?.key,h=m==null?a:String(m),g=s.get(h);if(g&&(typeof g._value!=typeof f||g._value?.type!==p?.type)&&(l(g,h,f==null||typeof f==`boolean`,[...s.keys()].indexOf(h)),g=void 0),g??=c?.take(h,f),g)g._value=f,r._root._presence?.resume(g._scope),S(g._scope);else{let a=y(r);g={_value:f,_scope:a,_start:X(`[`,t,e??n,a,u),_end:null};let o=g;Q(f,t,e??n,a,i,u,()=>o._value),g._end=X(`]`,t,e??n,a,u)}d.set(h,g)}for(let[e,t]of s)d.has(e)||l(t,e,!0,[...s.keys()].indexOf(e));if(!u){let r=e??n,i=c?.merge([...d.values()])??[...d.values()];for(let e of i.reverse()){if(e._end.nextSibling!==r){let n=t.ownerDocument.createRange();n.setStartBefore(e._start),n.setEndAfter(e._end),t.insertBefore(n.extractContents(),r)}r=e._start}f?.isConnected&&!f.closest(`[inert]`)&&f!==t.ownerDocument.activeElement&&f.focus({preventScroll:!0})}u=void 0,s=d}),e=X(`}`,t,n,r,a);return}if(Array.isArray(e)){for(let o of e)Q(o,t,n,r,i,a);return}if(e==null||typeof e==`boolean`)return;if(typeof e!=`object`){X(`t`,t,n,r,a);let i=Y(t.ownerDocument.createTextNode(String(e)),t,n,r,a);O(r,o,e=>{let t=String(e);i.nodeValue!==t&&(i.nodeValue=t)});return}let s=e,c=H(()=>o().props);if(!s.type||s.type===R){Q(()=>c.children,t,n,r,i,a);return}if(typeof s.type==`function`){let e=y(r);Q(_(e,()=>v(()=>s.type(c))),t,n,e,i,a);return}let l=s.type===`svg`?q:i,u=Y(t.ownerDocument.createElementNS(l,s.type),t,n,r,a);if(s.type===`astro-slot`)a||(u.innerHTML=c.innerHTML??``);else if(l===K&&/^(textarea|title|style|script)$/.test(s.type))O(r,()=>I(s.type===`textarea`?c.value??c.children:c.children),e=>{u.textContent!==e&&(u.textContent=e)});else{let e=a?{node:u.firstChild,report:a.report}:void 0;/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(s.type)&&l===K||Q(()=>c.children,u,null,r,s.type===`foreignObject`?K:l,e),J(e)}let d=G(r,{kind:`dom`,node:u},()=>({...c})),f={};r._cleanups.add(()=>{for(let e in f)e.startsWith(`on`)&&Z(u,e,null,f[e])}),O(r,()=>({...c}),e=>{let t=d(e);for(let e in{...f,...t})Object.is(f[e],t[e])&&typeof t[e]!=`object`||(Z(u,e,t[e],f[e]),f[e]=t[e]);f=t});let p=v(()=>c.ref);p&&r._root._mounts.unshift(()=>{r._dead||(r._cleanups.add(()=>p(null)),p(u))})}function $(e,t,n,r){let i=!1,a=r?{node:t.firstChild,report(e,n){i||(i=!0,console.warn(`spa: hydration mismatch. Repairing server HTML to match the browser view; replaced nodes may lose focus or unsaved input.`,{host:t,expected:e,found:n}))}}:void 0,o=a?.node,s=o?.nodeType===8&&o.nodeValue?.startsWith(`w:`)?o.nodeValue.slice(2):void 0,c=w(n);s!==void 0&&n.idPrefix===void 0&&(c._prefix=s);try{X(`w:${c._prefix}`,t,null,c,a),_(c,()=>{Q(v(e),t,null,c,t.namespaceURI===q?q:K,a)}),X(`/w`,t,null,c,a),J(a),c.flush()}catch(e){b(c,e)}return{dispose:()=>{x(c)},flush:c.flush}}function te(e,t,n={}){return $(e,t,n,!1)}function ne(e,t,n={}){return $(e,t,n,!0)}function re(...e){let t=m._root._store,[n]=e,r=n.type.endsWith(`_family`),i=k(n,e[1]),a=A(i),o=r?2:1,s=e[o],c=e.length>o,l=c,u=s,d;return()=>{let e=a(),n=e instanceof Promise;if(!n){u=e,l=!0;let n=p(t,i);d=c&&`catch`in n&&n.catch.some(t=>e instanceof t)?e:void 0}return l?d?{loading:n,value:s,error:d}:{loading:n,value:u}:`LOADING`}}export{R as Fragment,ne as hydrate,z as jsx,V as jsxDEV,B as jsxs,H as merge,E as onCleanup,D as onMount,te as render,A as useGetter,ee as useId,re as useLoadable,P as useRef,j as useSetter,T as useStore,F as useTimeline,M as useTransaction};
@@ -1,4 +1,4 @@
1
- import { IMPLICIT, actUponStore, clearTimelineInStore, findInStore, findTimelineInStore, getFromStore, getTimelineTransactionAtHead, inspectTimelineInStore, setIntoStore, subscribeToState, subscribeToTimeline, timeTravel, timeTravelTransactionGroupInStore } from "atom.io/internal";
1
+ import { IMPLICIT, actUponStore, clearTimelineInStore, findInStore, findTimelineInStore, getFromStore, getTimelineTransactionAtHead, setIntoStore, subscribeToState, subscribeToTimeline, timeTravel, timeTravelTransactionGroupInStore, withdraw } from "atom.io/internal";
2
2
  // src/core.ts
3
3
  let owner;
4
4
  let tracking;
@@ -167,12 +167,14 @@ function resolveStateToken(token, key) {
167
167
  const store = owner._root._store;
168
168
  return token.type.endsWith(`_family`) ? findInStore(store, token, key) : token;
169
169
  }
170
- function useValue(token, key) {
170
+ function useGetter(token, key) {
171
171
  token = resolveStateToken(token, key);
172
- const store = owner._root._store;
172
+ const root = owner._root;
173
+ const store = root._store;
173
174
  const subscribe = (notify) => subscribeToState(store, token, `spa:${serial++}`, notify);
174
175
  return () => {
175
176
  const value = getFromStore(store, token);
177
+ root._onRead?.(value, token);
176
178
  tracking?.(subscribe);
177
179
  return value;
178
180
  };
@@ -209,30 +211,36 @@ function useRef(token, key) {
209
211
  }
210
212
  function useTimeline(token, key) {
211
213
  const store = owner._root._store;
212
- if (token.type === `timeline_family`) token = findTimelineInStore(store, token, key);
213
- const subscribe = (notify) => subscribeToTimeline(store, token, `spa:${serial++}`, notify);
214
- const controls = {
214
+ const selected = token.type === `timeline_family` ? findTimelineInStore(store, token, key) : token;
215
+ const subscribe = (notify) => subscribeToTimeline(store, selected, `spa:${serial++}`, notify);
216
+ const read = () => {
217
+ const timeline = withdraw(store, selected);
218
+ tracking?.(subscribe);
219
+ return timeline;
220
+ };
221
+ return {
222
+ getCursor: () => read().at,
223
+ getLength: () => read().history.length,
215
224
  undo: () => {
216
- timeTravel(store, `undo`, token);
225
+ timeTravel(store, `undo`, selected);
217
226
  },
218
227
  redo: () => {
219
- timeTravel(store, `redo`, token);
228
+ timeTravel(store, `redo`, selected);
220
229
  },
221
230
  clear: () => {
222
- clearTimelineInStore(store, token);
223
- }
224
- };
225
- return () => {
226
- const value = {
227
- ...inspectTimelineInStore(store, token),
228
- ...controls
229
- };
230
- tracking?.(subscribe);
231
- for (const direction of [`undo`, `redo`]) {
232
- const group = getTimelineTransactionAtHead(store.timelines.get(token.key), direction);
233
- if (group) value[`${direction}Transaction`] = () => timeTravelTransactionGroupInStore(store, direction, group);
231
+ clearTimelineInStore(store, selected);
232
+ },
233
+ getTransaction: () => {
234
+ const timeline = read();
235
+ const controls = {};
236
+ for (const direction of [`undo`, `redo`]) {
237
+ const group = getTimelineTransactionAtHead(timeline, direction);
238
+ if (group) controls[direction] = () => {
239
+ timeTravelTransactionGroupInStore(store, direction, group);
240
+ };
241
+ }
242
+ return controls;
234
243
  }
235
- return value;
236
244
  };
237
245
  }
238
246
  function plain(value) {
@@ -245,6 +253,6 @@ function isPresent(scope) {
245
253
  for (let at = scope; at; at = at._parent) if (at._dead || at._exiting) return false;
246
254
  return true;
247
255
  }
248
- export { useStore as _, invalidate as a, useValue as b, onCleanup as c, plain as d, resolveStateToken as f, useSetter as g, useRef as h, fail as i, onMount as l, useId as m, createScope as n, isPresent as o, untrack as p, dispose as r, observe as s, createRoot as t, owner as u, useTimeline as v, within as x, useTransaction as y };
256
+ export { useSetter as _, invalidate as a, useTransaction as b, onCleanup as c, plain as d, resolveStateToken as f, useRef as g, useId as h, fail as i, onMount as l, useGetter as m, createScope as n, isPresent as o, untrack as p, dispose as r, observe as s, createRoot as t, owner as u, useStore as v, within as x, useTimeline as y };
249
257
 
250
- //# sourceMappingURL=core-DCmqLZQP.js.map
258
+ //# sourceMappingURL=core-DjFJ0aIJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-DjFJ0aIJ.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSetter,\n\tTimelineFamilyToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tViewOf,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tclearTimelineInStore,\n\tfindInStore,\n\tfindTimelineInStore,\n\tgetFromStore,\n\tgetTimelineTransactionAtHead,\n\tIMPLICIT,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\ttimeTravel,\n\ttimeTravelTransactionGroupInStore,\n\twithdraw,\n} from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type {\n\tExitParticipant,\n\tPresenceCoordinator,\n\tPresenceTarget,\n} from \"./presence.ts\"\n\nexport type Cleanup = () => void\n// A callable interface permits the recursive Children union. A type alias does not.\n/* oxlint-disable typescript/prefer-function-type -- A callable interface is required for recursive Children. */\nexport interface Accessor<T> {\n\t(): T\n}\n/* oxlint-enable typescript/prefer-function-type */\nexport type Component<P = any> = (props: P) => Children\n/** A JSX descriptor for an intrinsic tag, component, or fragment. */\nexport interface SpaElement {\n\ttype: string | Component | null\n\tprops: Record<string, any>\n}\n/** Renderable content, including nested groups and reactive accessors. */\nexport type Children =\n\t| SpaElement\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| readonly Children[]\n\t| Accessor<Children>\nexport interface RootOptions {\n\tcapabilities?: readonly Capability[]\n\tstore?: RootStore\n\tidPrefix?: string\n\tonError?: (error: unknown) => void\n}\nexport interface Scope {\n\t_exiting?: boolean\n\t_exits?: Set<ExitParticipant>\n\t_targets?: Set<PresenceTarget>\n\t_root: Root\n\t_parent?: Scope | undefined\n\t_cleanups: Set<Cleanup | Scope>\n\t_updates: Cleanup[]\n\t_dead: boolean\n}\nexport interface Root extends Scope {\n\t_onRead?: ((value: unknown, token: ReadableToken<unknown>) => void) | undefined\n\t_presence?: PresenceCoordinator\n\t_capabilities: Map<string, Capability>\n\t_store: RootStore\n\t_prefix: string\n\t_id: number\n\t_queue: Set<Cleanup>\n\t_mounts: Cleanup[] | undefined\n\tflush: Cleanup\n\terror: (error: unknown) => void\n}\n\nexport let owner: Scope | undefined\ntype Subscribe = (notify: Cleanup) => Cleanup\nlet tracking: ((subscribe: Subscribe) => void) | undefined\nlet serial = 0\n\nexport function within<T>(scope: Scope, run: () => T): T {\n\tconst previous = owner\n\towner = scope\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\towner = previous\n\t}\n}\nexport function untrack<T>(run: () => T): T {\n\tconst previous = tracking\n\ttracking = undefined\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\ttracking = previous\n\t}\n}\nexport function createScope(parent?: Scope): Scope {\n\tconst child: Scope = {\n\t\t_root: parent?._root as Root,\n\t\t_parent: parent,\n\t\t_cleanups: new Set(),\n\t\t_updates: [],\n\t\t_dead: false,\n\t}\n\tparent?._cleanups.add(child)\n\treturn child\n}\nexport function fail(scope: Scope, error: unknown): never {\n\ttry {\n\t\tdispose(scope)\n\t} catch (cleanup) {\n\t\tthrow new AggregateError([error, cleanup])\n\t}\n\tthrow error\n}\nexport function dispose(scope: Scope): void {\n\tif (scope._dead) return\n\tscope._dead = true\n\tconst errors: unknown[] = []\n\ttry {\n\t\tscope._root._presence?.forget(scope)\n\t} catch (error) {\n\t\terrors.push(error)\n\t}\n\tfor (const cleanup of [...scope._cleanups].reverse()) {\n\t\ttry {\n\t\t\ttypeof cleanup === `function` ? cleanup() : dispose(cleanup)\n\t\t} catch (error) {\n\t\t\terrors.push(error)\n\t\t}\n\t}\n\tscope._parent?._cleanups.delete(scope)\n\tscope._cleanups.clear()\n\tscope._updates.length = 0\n\tif (errors.length) throw new AggregateError(errors)\n}\nexport function invalidate(scope: Scope): void {\n\tfor (const run of scope._updates) enqueue(scope, run)\n\tfor (const child of scope._cleanups)\n\t\tif (typeof child !== `function`) invalidate(child)\n}\nfunction enqueue(scope: Scope, run: Cleanup): void {\n\tif (!isPresent(scope)) return\n\tconst root = scope._root\n\tif (!root._queue.size)\n\t\tqueueMicrotask(() => {\n\t\t\ttry {\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\troot.error(error)\n\t\t\t}\n\t\t})\n\troot._queue.add(run)\n}\nexport function createRoot(options: RootOptions = {}, server = false): Root {\n\tconst capabilities = new Map<string, Capability>()\n\tfor (const capability of options.capabilities ?? []) {\n\t\tif (capabilities.has(capability.namespace))\n\t\t\tthrow new Error(`spa: duplicate capability ${capability.namespace}`)\n\t\tcapabilities.set(capability.namespace, capability)\n\t}\n\tconst root = {\n\t\t_capabilities: capabilities,\n\t\t_store: options.store ?? IMPLICIT.STORE,\n\t\t_prefix: options.idPrefix ?? `w${serial++}`,\n\t\t_id: 0,\n\t\t...createScope(),\n\t\t_queue: new Set(),\n\t\t_mounts: server ? undefined : [],\n\t} as unknown as Root\n\troot._root = root\n\troot.error =\n\t\toptions.onError ??\n\t\t((error) => {\n\t\t\tthrow error\n\t\t})\n\tfor (const capability of capabilities.values())\n\t\tif (capability.presence) {\n\t\t\tif (root._presence) throw new Error(`spa: multiple presence coordinators`)\n\t\t\troot._presence = capability.presence(root)\n\t\t}\n\troot.flush = () => {\n\t\ttry {\n\t\t\tlet passes = 0\n\t\t\twhile (root._queue.size || root._mounts!.length) {\n\t\t\t\tif (import.meta.env.DEV && ++passes > 100)\n\t\t\t\t\tthrow new Error(`spa: update loop`)\n\t\t\t\tfor (const run of [...root._queue]) if (root._queue.delete(run)) run()\n\t\t\t\tfor (const run of root._mounts!.splice(0)) run()\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfail(root, error)\n\t\t}\n\t}\n\treturn root\n}\n/** Return the atom.io store selected by the current root. */\nexport function useStore(): RootStore {\n\treturn owner!._root._store\n}\nexport function onCleanup(cleanup: Cleanup): void {\n\towner!._cleanups.add(cleanup)\n}\nexport function onMount(run: Cleanup): void {\n\tconst scope = owner!\n\tscope._root._mounts?.push(() => {\n\t\tif (!scope._dead)\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(run)\n\t\t\t})\n\t})\n}\nexport function useId(): string {\n\tconst root = owner!._root\n\treturn `${root._prefix}-${root._id++}`\n}\n\nexport function observe<T>(\n\tscope: Scope,\n\tread: Accessor<T>,\n\tapply: (value: T) => void,\n): void {\n\tconst subscriptions = new Map<Subscribe, Cleanup>()\n\tconst run = () => {\n\t\tif (!isPresent(scope)) return\n\t\tconst used = new Set<Subscribe>()\n\t\tconst previous = tracking\n\t\ttracking = (subscribe) => {\n\t\t\tused.add(subscribe)\n\t\t\tif (!subscriptions.has(subscribe))\n\t\t\t\tsubscriptions.set(\n\t\t\t\t\tsubscribe,\n\t\t\t\t\tsubscribe(() => {\n\t\t\t\t\t\tenqueue(scope, run)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t}\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = within(scope, read)\n\t\t} finally {\n\t\t\ttracking = previous\n\t\t\tfor (const [subscribe, unsubscribe] of subscriptions)\n\t\t\t\tif (!used.has(subscribe)) {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tsubscriptions.delete(subscribe)\n\t\t\t\t}\n\t\t}\n\t\tuntrack(() => {\n\t\t\tapply(value)\n\t\t})\n\t}\n\tscope._updates.push(run)\n\tscope._cleanups.add(() => {\n\t\tscope._root._queue.delete(run)\n\t\tfor (const unsubscribe of subscriptions.values()) unsubscribe()\n\t})\n\trun()\n}\n\n/** Resolve a fixed family key in the current owner's store. */\nexport function resolveStateToken(token: any, key?: Canonical): any {\n\tconst store = owner!._root._store\n\treturn token.type.endsWith(`_family`) ? findInStore(store, token, key!) : token\n}\n\n/** Capture a token for this instance. Change the component key to change its token. */\nexport function useGetter<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter<T, K extends Canonical, E = never>(\n\tfamily: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter(token: any, key?: Canonical): Accessor<any> {\n\ttoken = resolveStateToken(token, key)\n\tconst root = owner!._root\n\tconst store = root._store\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToState(store, token, `spa:${serial++}`, notify)\n\treturn () => {\n\t\tconst value = getFromStore(store, token)\n\t\troot._onRead?.(value, token)\n\t\ttracking?.(subscribe)\n\t\treturn value\n\t}\n}\nexport function useSetter<T>(\n\ttoken: WritableToken<T, any, any>,\n): (value: T | Setter<T>) => void\nexport function useSetter<T, K extends Canonical>(\n\tfamily: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): (value: T | Setter<T>) => void\nexport function useSetter(token: any, key?: Canonical): (value: any) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = owner!._root._store\n\treturn (value) => {\n\t\tsetIntoStore(store, token, value)\n\t}\n}\nexport function useTransaction<F extends (...args: any[]) => any>(\n\ttoken: TransactionToken<F>,\n): (...args: Parameters<F>) => ReturnType<F> {\n\treturn actUponStore(owner!._root._store, token, `spa:${serial++}`)\n}\n\nconst refs = new WeakMap<RootStore, Map<string, object>>()\nexport function useRef<E extends Element>(\n\ttoken: RegularAtomToken<E | null>,\n): (element: E | null) => void\nexport function useRef<E extends Element, K extends Canonical>(\n\tfamily: RegularAtomFamilyToken<E | null, K>,\n\tkey: NoInfer<K>,\n): (element: E | null) => void\nexport function useRef<E extends Element>(\n\ttoken: any,\n\tkey?: Canonical,\n): (element: E | null) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = owner!._root._store\n\tconst owners = refs.get(store) ?? new Map<string, object>()\n\trefs.set(store, owners)\n\tconst identity = {}\n\tlet held: E | null = null\n\treturn (element) => {\n\t\tif (element) {\n\t\t\theld = element\n\t\t\towners.set(token.key, identity)\n\t\t\tsetIntoStore(store, token, element)\n\t\t} else if (owners.get(token.key) === identity) {\n\t\t\towners.delete(token.key)\n\t\t\tif (getFromStore(store, token) === held) setIntoStore(store, token, null)\n\t\t\theld = null\n\t\t}\n\t}\n}\nexport interface TimelineControls {\n\tgetCursor(): number\n\tgetLength(): number\n\tundo(): void\n\tredo(): void\n\tclear(): void\n\tgetTransaction(): { undo?: Cleanup; redo?: Cleanup }\n}\nexport function useTimeline<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n): TimelineControls\nexport function useTimeline<K extends Canonical, M extends TimelineManageable>(\n\tfamily: TimelineFamilyToken<K, M>,\n\tkey: NoInfer<K>,\n): TimelineControls\nexport function useTimeline(token: any, key?: Canonical): TimelineControls {\n\tconst store = owner!._root._store\n\tconst selected: TimelineToken<any> =\n\t\ttoken.type === `timeline_family`\n\t\t\t? findTimelineInStore(store, token, key!)\n\t\t\t: token\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToTimeline(store, selected, `spa:${serial++}`, notify)\n\tconst read = () => {\n\t\tconst timeline = withdraw(store, selected)\n\t\ttracking?.(subscribe)\n\t\treturn timeline\n\t}\n\treturn {\n\t\tgetCursor: () => read().at,\n\t\tgetLength: () => read().history.length,\n\t\tundo: () => {\n\t\t\ttimeTravel(store, `undo`, selected)\n\t\t},\n\t\tredo: () => {\n\t\t\ttimeTravel(store, `redo`, selected)\n\t\t},\n\t\tclear: () => {\n\t\t\tclearTimelineInStore(store, selected)\n\t\t},\n\t\tgetTransaction: () => {\n\t\t\tconst timeline = read()\n\t\t\tconst controls: ReturnType<TimelineControls[`getTransaction`]> = {}\n\t\t\tfor (const direction of [`undo`, `redo`] as const) {\n\t\t\t\tconst group = getTimelineTransactionAtHead(timeline, direction)\n\t\t\t\tif (group)\n\t\t\t\t\tcontrols[direction] = () => {\n\t\t\t\t\t\ttimeTravelTransactionGroupInStore(store, direction, group)\n\t\t\t\t\t}\n\t\t\t}\n\t\t\treturn controls\n\t\t},\n\t}\n}\n\nexport function plain(value: Children): string {\n\tif (typeof value === `function`) return plain(value())\n\tif (Array.isArray(value)) return value.map(plain).join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (import.meta.env.DEV && typeof value === `object`)\n\t\tthrow new Error(`spa: text required`)\n\t// oxlint-disable-next-line typescript/no-base-to-string -- Valid text children are primitives here; development rejects malformed object children.\n\treturn String(value)\n}\n\nexport function isPresent(scope: Scope): boolean {\n\tfor (let at: Scope | undefined = scope; at; at = at._parent)\n\t\tif (at._dead || at._exiting) return false\n\treturn true\n}\n"],"mappings":";;AA4FA,IAAW;AAEX,IAAI;AACJ,IAAI,SAAS;AAEb,SAAgB,OAAU,OAAc,KAAiB;CACxD,MAAM,WAAW;CACjB,QAAQ;CACR,IAAI;EACH,OAAO,IAAI;CACZ,UAAU;EACT,QAAQ;CACT;AACD;AACA,SAAgB,QAAW,KAAiB;CAC3C,MAAM,WAAW;CACjB,WAAW,KAAA;CACX,IAAI;EACH,OAAO,IAAI;CACZ,UAAU;EACT,WAAW;CACZ;AACD;AACA,SAAgB,YAAY,QAAuB;CAClD,MAAM,QAAe;EACpB,OAAO,QAAQ;EACf,SAAS;EACT,2BAAW,IAAI,IAAI;EACnB,UAAU,CAAC;EACX,OAAO;CACR;CACA,QAAQ,UAAU,IAAI,KAAK;CAC3B,OAAO;AACR;AACA,SAAgB,KAAK,OAAc,OAAuB;CACzD,IAAI;EACH,QAAQ,KAAK;CACd,SAAS,SAAS;EACjB,MAAM,IAAI,eAAe,CAAC,OAAO,OAAO,CAAC;CAC1C;CACA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6B,UAAU,SAAS;IAC9D,IAAI,OACH,SAAS,mBAAmB;KAC3B,kCAAkC,OAAO,WAAW,KAAK;IAC1D;GACF;GACA,OAAO;EACR;CACD;AACD;AAEA,SAAgB,MAAM,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAAC;CACrD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE;CACzD,IAAI,SAAS,QAAQ,OAAO,UAAU,WAAW,OAAO;CAIxD,OAAO,OAAO,KAAK;AACpB;AAEA,SAAgB,UAAU,OAAuB;CAChD,KAAK,IAAI,KAAwB,OAAO,IAAI,KAAK,GAAG,SACnD,IAAI,GAAG,SAAS,GAAG,UAAU,OAAO;CACrC,OAAO;AACR"}
@@ -1,14 +1,14 @@
1
1
  import { browserApplication } from "./astro-application.js";
2
2
  import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
3
- import { n as islandStore, t as island } from "./astro-shared-BT45auwR.js";
4
- import { b as useValue, c as onCleanup } from "./core-p9vciX9C.js";
5
- import { n as render, t as hydrate } from "./dom-Ci1XvbVJ.js";
6
- import { IMPLICIT, createRegularAtomFamily, disposeFromStore, findInStore, setIntoStore } from "atom.io/internal";
3
+ import { n as islandStore, t as island } from "./astro-shared-83hxw7-M.js";
4
+ import { c as onCleanup, m as useGetter } from "./core-DxPiKryn.js";
5
+ import { n as render, t as hydrate } from "./dom-BytVV6Rp.js";
6
+ import { IMPLICIT, createRegularAtomFamily, disposeFromStore, findInStore, getFromStore, setIntoStore } from "atom.io/internal";
7
7
  // src/astro-client.ts
8
8
  const roots = /* @__PURE__ */ new WeakMap();
9
9
  const states = /* @__PURE__ */ new WeakMap();
10
10
  let serial = 0;
11
- var astro_client_default = (element) => async (component, props, slots, { client }) => {
11
+ const createHydrator = (prepare) => (element) => async (component, props, slots, { client }) => {
12
12
  const previous = roots.get(element);
13
13
  if (previous?.component === component) {
14
14
  previous.update(props, slots);
@@ -37,10 +37,10 @@ var astro_client_default = (element) => async (component, props, slots, { client
37
37
  if (lifetime.context.signal.aborted) return;
38
38
  let mounting = false;
39
39
  try {
40
- const store = await Promise.race([islandStore(component, props, lifetime.context, shared ? IMPLICIT.STORE : void 0), lifetime.cancelled]);
40
+ const store = await Promise.race([islandStore(component, props, lifetime.context, shared ? IMPLICIT.STORE : void 0, prepare), lifetime.cancelled]);
41
41
  if (lifetime.context.signal.aborted) return;
42
42
  mounting = true;
43
- const replace = client === `only` || previous !== void 0 || application?.canResume === false;
43
+ const replace = client === `only` || previous !== void 0 || application?.canResume === false || JSON.parse(element.getAttribute(`data-spa-reads`) ?? `[]`).some((token) => getFromStore(store, token) instanceof Promise);
44
44
  const sentinel = element.lastChild;
45
45
  if (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`) sentinel.remove();
46
46
  let family = states.get(store);
@@ -61,8 +61,8 @@ var astro_client_default = (element) => async (component, props, slots, { client
61
61
  });
62
62
  const mount = () => {
63
63
  onCleanup(dispose);
64
- const value = useValue(state);
65
- return () => island(component, value().props, value().slots);
64
+ const getState = useGetter(state);
65
+ return () => island(component, getState().props, getState().slots);
66
66
  };
67
67
  if (replace) element.replaceChildren();
68
68
  const root = (replace ? render : hydrate)(mount, element, {
@@ -96,6 +96,7 @@ var astro_client_default = (element) => async (component, props, slots, { client
96
96
  lifetime.context.onCleanup(dispose);
97
97
  return ready;
98
98
  };
99
- export { astro_client_default as default };
99
+ var astro_client_default = createHydrator();
100
+ export { createHydrator, astro_client_default as default };
100
101
 
101
102
  //# sourceMappingURL=astro-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-client.js","names":[],"sources":["../../src/astro-client.ts"],"sourcesContent":["import type { RegularAtomFamilyToken } from \"atom.io\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tcreateRegularAtomFamily,\n\tdisposeFromStore,\n\tfindInStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { onCleanup, useValue } from \"./core.ts\"\nimport { hydrate, render } from \"./dom.ts\"\n\ntype Props = Record<string, any>\ntype Slots = Record<string, string>\ntype Hydrator = (\n\tcomponent: Island,\n\tprops: Props,\n\tslots: Slots,\n\tmetadata: { client: string },\n) => Promise<void>\nconst roots = new WeakMap<\n\tElement,\n\t{\n\t\tcomponent: Island\n\t\tready: Promise<void>\n\t\tupdate(props: Props, slots: Slots): void\n\t\tdispose(): void\n\t}\n>()\ntype State = { props: Props; slots: Slots }\nconst states = new WeakMap<RootStore, RegularAtomFamilyToken<State, number>>()\nlet serial = 0\n\nexport default (element: HTMLElement): Hydrator =>\n\tasync (component, props, slots, { client }) => {\n\t\tconst previous = roots.get(element)\n\t\tif (previous?.component === component) {\n\t\t\tprevious.update(props, slots)\n\t\t\treturn previous.ready\n\t\t}\n\t\tprevious?.dispose()\n\t\tconst shared = !component.createStore && !component.isolate\n\t\tconst application = shared\n\t\t\t? browserApplication(element.ownerDocument)\n\t\t\t: undefined\n\t\tif (application && client === `only`) application.canResume = false\n\t\tconst lifetime = storeContext(element, application)\n\t\tconst initial = { props, slots }\n\t\tlet current = initial\n\t\tlet update: ((value: State) => void) | undefined\n\t\tlet disposed = false\n\t\tconst dispose = () => {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\telement.removeEventListener(`astro:unmount`, dispose)\n\t\t\troots.delete(element)\n\t\t\tlifetime.dispose()\n\t\t}\n\t\t// Publish the pending owner before invoking user code. Repeated hydration\n\t\t// calls update its props and share its preparation rather than racing stores.\n\t\tconst ready = Promise.resolve().then(async () => {\n\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\tlet mounting = false\n\t\t\ttry {\n\t\t\t\tconst store = await Promise.race([\n\t\t\t\t\tislandStore(\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t\tlifetime.context,\n\t\t\t\t\t\tshared ? IMPLICIT.STORE : undefined,\n\t\t\t\t\t),\n\t\t\t\t\tlifetime.cancelled,\n\t\t\t\t])\n\t\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\t\tmounting = true\n\t\t\t\tconst replace =\n\t\t\t\t\tclient === `only` ||\n\t\t\t\t\tprevious !== undefined ||\n\t\t\t\t\tapplication?.canResume === false\n\t\t\t\t// Astro leaves this sentinel on islands inserted by ClientRouter.\n\t\t\t\tconst sentinel = element.lastChild\n\t\t\t\tif (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`)\n\t\t\t\t\tsentinel.remove()\n\t\t\t\tlet family = states.get(store!)\n\t\t\t\tif (!family) {\n\t\t\t\t\tfamily = createRegularAtomFamily<State, number, never>(store!, {\n\t\t\t\t\t\tkey: `🔍 spa islands`,\n\t\t\t\t\t\tdefault: { props: {}, slots: {} },\n\t\t\t\t\t})\n\t\t\t\t\tstates.set(store!, family)\n\t\t\t\t}\n\t\t\t\tconst state = findInStore(store!, family, serial++)\n\t\t\t\tsetIntoStore(store!, state, replace ? current : initial)\n\t\t\t\tlifetime.context.onCleanup(() => {\n\t\t\t\t\tdisposeFromStore(store!, state)\n\t\t\t\t})\n\t\t\t\tconst mount = () => {\n\t\t\t\t\tonCleanup(dispose)\n\t\t\t\t\tconst value = useValue(state)\n\t\t\t\t\treturn () => island(component, value().props, value().slots)\n\t\t\t\t}\n\t\t\t\tif (replace) element.replaceChildren()\n\t\t\t\tconst root = (replace ? render : hydrate)(mount, element, {\n\t\t\t\t\tstore: store!,\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t})\n\t\t\t\tlifetime.context.onCleanup(root.dispose)\n\t\t\t\tupdate = (next) => {\n\t\t\t\t\tsetIntoStore(store!, state, next)\n\t\t\t\t\troot.flush()\n\t\t\t\t}\n\t\t\t\t// Match the existing SSR tree before applying a structural prop update\n\t\t\t\t// that arrived while its store was still being prepared.\n\t\t\t\tif (!replace && current !== initial) update(current)\n\t\t\t} catch (error) {\n\t\t\t\tif (lifetime.context.signal.aborted && !mounting) return\n\t\t\t\tfailPreparation(error, dispose)\n\t\t\t}\n\t\t})\n\t\troots.set(element, {\n\t\t\tcomponent,\n\t\t\tready,\n\t\t\tupdate(nextProps, nextSlots) {\n\t\t\t\tcurrent = { props: nextProps, slots: nextSlots }\n\t\t\t\tupdate?.(current)\n\t\t\t},\n\t\t\tdispose,\n\t\t})\n\t\telement.addEventListener(`astro:unmount`, dispose, { once: true })\n\t\tlifetime.context.onCleanup(dispose)\n\t\treturn ready\n\t}\n"],"mappings":";;;;;;;AAyBA,MAAM,wBAAQ,IAAI,QAQhB;AAEF,MAAM,yBAAS,IAAI,QAA0D;AAC7E,IAAI,SAAS;AAEb,IAAA,wBAAgB,YACf,OAAO,WAAW,OAAO,OAAO,EAAE,aAAa;CAC9C,MAAM,WAAW,MAAM,IAAI,OAAO;CAClC,IAAI,UAAU,cAAc,WAAW;EACtC,SAAS,OAAO,OAAO,KAAK;EAC5B,OAAO,SAAS;CACjB;CACA,UAAU,QAAQ;CAClB,MAAM,SAAS,CAAC,UAAU,eAAe,CAAC,UAAU;CACpD,MAAM,cAAc,SACjB,mBAAmB,QAAQ,aAAa,IACxC,KAAA;CACH,IAAI,eAAe,WAAW,QAAQ,YAAY,YAAY;CAC9D,MAAM,WAAW,aAAa,SAAS,WAAW;CAClD,MAAM,UAAU;EAAE;EAAO;CAAM;CAC/B,IAAI,UAAU;CACd,IAAI;CACJ,IAAI,WAAW;CACf,MAAM,gBAAgB;EACrB,IAAI,UAAU;EACd,WAAW;EACX,QAAQ,oBAAoB,iBAAiB,OAAO;EACpD,MAAM,OAAO,OAAO;EACpB,SAAS,QAAQ;CAClB;CAGA,MAAM,QAAQ,QAAQ,QAAQ,CAAC,CAAC,KAAK,YAAY;EAChD,IAAI,SAAS,QAAQ,OAAO,SAAS;EACrC,IAAI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C/B;CACD,CAAC;CACD,MAAM,IAAI,SAAS;EAClB;EACA;EACA,OAAO,WAAW,WAAW;GAC5B,UAAU;IAAE,OAAO;IAAW,OAAO;GAAU;GAC/C,SAAS,OAAO;EACjB;EACA;CACD,CAAC;CACD,QAAQ,iBAAiB,iBAAiB,SAAS,EAAE,MAAM,KAAK,CAAC;CACjE,SAAS,QAAQ,UAAU,OAAO;CAClC,OAAO;AACR"}
1
+ {"version":3,"file":"astro-client.js","names":[],"sources":["../../src/astro-client.ts"],"sourcesContent":["import type { ReadableToken, RegularAtomFamilyToken } from \"atom.io\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tcreateRegularAtomFamily,\n\tdisposeFromStore,\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport type { AstroStorePreparation, Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { onCleanup, useGetter } from \"./core.ts\"\nimport { hydrate, render } from \"./dom.ts\"\n\ntype Props = Record<string, any>\ntype Slots = Record<string, string>\ntype Hydrator = (\n\tcomponent: Island,\n\tprops: Props,\n\tslots: Slots,\n\tmetadata: { client: string },\n) => Promise<void>\nconst roots = new WeakMap<\n\tElement,\n\t{\n\t\tcomponent: Island\n\t\tready: Promise<void>\n\t\tupdate(props: Props, slots: Slots): void\n\t\tdispose(): void\n\t}\n>()\ntype State = { props: Props; slots: Slots }\nconst states = new WeakMap<RootStore, RegularAtomFamilyToken<State, number>>()\nlet serial = 0\n\nexport const createHydrator =\n\t(prepare?: AstroStorePreparation) =>\n\t(element: HTMLElement): Hydrator =>\n\tasync (component, props, slots, { client }) => {\n\t\tconst previous = roots.get(element)\n\t\tif (previous?.component === component) {\n\t\t\tprevious.update(props, slots)\n\t\t\treturn previous.ready\n\t\t}\n\t\tprevious?.dispose()\n\t\tconst shared = !component.createStore && !component.isolate\n\t\tconst application = shared\n\t\t\t? browserApplication(element.ownerDocument)\n\t\t\t: undefined\n\t\tif (application && client === `only`) application.canResume = false\n\t\tconst lifetime = storeContext(element, application)\n\t\tconst initial = { props, slots }\n\t\tlet current = initial\n\t\tlet update: ((value: State) => void) | undefined\n\t\tlet disposed = false\n\t\tconst dispose = () => {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\telement.removeEventListener(`astro:unmount`, dispose)\n\t\t\troots.delete(element)\n\t\t\tlifetime.dispose()\n\t\t}\n\t\t// Publish the pending owner before invoking user code. Repeated hydration\n\t\t// calls update its props and share its preparation rather than racing stores.\n\t\tconst ready = Promise.resolve().then(async () => {\n\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\tlet mounting = false\n\t\t\ttry {\n\t\t\t\tconst store = await Promise.race([\n\t\t\t\t\tislandStore(\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t\tlifetime.context,\n\t\t\t\t\t\tshared ? IMPLICIT.STORE : undefined,\n\t\t\t\t\t\tprepare,\n\t\t\t\t\t),\n\t\t\t\t\tlifetime.cancelled,\n\t\t\t\t])\n\t\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\t\tmounting = true\n\t\t\t\tconst replace =\n\t\t\t\t\tclient === `only` ||\n\t\t\t\t\tprevious !== undefined ||\n\t\t\t\t\tapplication?.canResume === false ||\n\t\t\t\t\t// Server-settled state without a synchronous browser seed needs a\n\t\t\t\t\t// fresh view, whose loading state can differ from the SSR markup.\n\t\t\t\t\t(\n\t\t\t\t\t\tJSON.parse(\n\t\t\t\t\t\t\telement.getAttribute(`data-spa-reads`) ?? `[]`,\n\t\t\t\t\t\t) as ReadableToken<unknown>[]\n\t\t\t\t\t).some((token) => getFromStore(store!, token) instanceof Promise)\n\t\t\t\t// Astro leaves this sentinel on islands inserted by ClientRouter.\n\t\t\t\tconst sentinel = element.lastChild\n\t\t\t\tif (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`)\n\t\t\t\t\tsentinel.remove()\n\t\t\t\tlet family = states.get(store!)\n\t\t\t\tif (!family) {\n\t\t\t\t\tfamily = createRegularAtomFamily<State, number, never>(store!, {\n\t\t\t\t\t\tkey: `🔍 spa islands`,\n\t\t\t\t\t\tdefault: { props: {}, slots: {} },\n\t\t\t\t\t})\n\t\t\t\t\tstates.set(store!, family)\n\t\t\t\t}\n\t\t\t\tconst state = findInStore(store!, family, serial++)\n\t\t\t\tsetIntoStore(store!, state, replace ? current : initial)\n\t\t\t\tlifetime.context.onCleanup(() => {\n\t\t\t\t\tdisposeFromStore(store!, state)\n\t\t\t\t})\n\t\t\t\tconst mount = () => {\n\t\t\t\t\tonCleanup(dispose)\n\t\t\t\t\tconst getState = useGetter(state)\n\t\t\t\t\treturn () => island(component, getState().props, getState().slots)\n\t\t\t\t}\n\t\t\t\tif (replace) element.replaceChildren()\n\t\t\t\tconst root = (replace ? render : hydrate)(mount, element, {\n\t\t\t\t\tstore: store!,\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t})\n\t\t\t\tlifetime.context.onCleanup(root.dispose)\n\t\t\t\tupdate = (next) => {\n\t\t\t\t\tsetIntoStore(store!, state, next)\n\t\t\t\t\troot.flush()\n\t\t\t\t}\n\t\t\t\t// Match the existing SSR tree before applying a structural prop update\n\t\t\t\t// that arrived while its store was still being prepared.\n\t\t\t\tif (!replace && current !== initial) update(current)\n\t\t\t} catch (error) {\n\t\t\t\tif (lifetime.context.signal.aborted && !mounting) return\n\t\t\t\tfailPreparation(error, dispose)\n\t\t\t}\n\t\t})\n\t\troots.set(element, {\n\t\t\tcomponent,\n\t\t\tready,\n\t\t\tupdate(nextProps, nextSlots) {\n\t\t\t\tcurrent = { props: nextProps, slots: nextSlots }\n\t\t\t\tupdate?.(current)\n\t\t\t},\n\t\t\tdispose,\n\t\t})\n\t\telement.addEventListener(`astro:unmount`, dispose, { once: true })\n\t\tlifetime.context.onCleanup(disp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IAAA,uBAAe,eAAe"}
@@ -0,0 +1,29 @@
1
+ import { browserApplication } from "./astro-application.js";
2
+ import { createHydrator } from "./astro-client.js";
3
+ import { browserResumption, captureElement, createResumption } from "resumability/astro-client";
4
+ // src/astro-resumability-client.ts
5
+ var astro_resumability_client_default = createHydrator((store, _props, { element, application }) => {
6
+ const scopes = application.get(createResumption, () => /* @__PURE__ */ new WeakMap());
7
+ let scope = scopes.get(store);
8
+ if (!scope) {
9
+ if (application === browserApplication(element.ownerDocument)) {
10
+ const host = browserResumption(element.ownerDocument);
11
+ application.onCleanup(host.resumeWhen(() => application.canResume));
12
+ scope = host;
13
+ } else {
14
+ const original = store.runDefault;
15
+ const local = createResumption();
16
+ store.runDefault = (run) => local.run(() => original.call(store, run), { resume: application.canResume });
17
+ application.onCleanup(() => {
18
+ local.dispose();
19
+ store.runDefault = original;
20
+ });
21
+ scope = local;
22
+ }
23
+ scopes.set(store, scope);
24
+ }
25
+ captureElement(scope, element);
26
+ });
27
+ export { astro_resumability_client_default as default };
28
+
29
+ //# sourceMappingURL=astro-resumability-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-resumability-client.js","names":[],"sources":["../../src/astro-resumability-client.ts"],"sourcesContent":["import {\n\tbrowserResumption,\n\tcaptureElement,\n\tcreateResumption,\n} from \"resumability/astro-client\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { createHydrator } from \"./astro-client.ts\"\n\nexport default createHydrator((store, _props, { element, application }) => {\n\tconst scopes = application.get(\n\t\tcreateResumption,\n\t\t() => new WeakMap<object, ReturnType<typeof createResumption>>(),\n\t)\n\tlet scope = scopes.get(store)\n\tif (!scope) {\n\t\tconst shared = application === browserApplication(element!.ownerDocument)\n\t\tif (shared) {\n\t\t\tconst host = browserResumption(element!.ownerDocument)\n\t\t\tapplication.onCleanup(host.resumeWhen(() => application.canResume))\n\t\t\tscope = host\n\t\t} else {\n\t\t\t// Lazy defaults can run after component setup. Bind their private owner so\n\t\t\t// refreshes and pending work end with this island instead of the page.\n\t\t\tconst original = store.runDefault\n\t\t\tconst local = createResumption()\n\t\t\tstore.runDefault = <T>(run: () => T): T =>\n\t\t\t\tlocal.run(() => original.call(store, run) as T, {\n\t\t\t\t\tresume: application.canResume,\n\t\t\t\t})\n\t\t\tapplication.onCleanup(() => {\n\t\t\t\tlocal.dispose()\n\t\t\t\tstore.runDefault = original\n\t\t\t})\n\t\t\tscope = local\n\t\t}\n\t\tscopes.set(store, scope)\n\t}\n\tcaptureElement(scope, element!)\n})\n"],"mappings":";;;;AASA,IAAA,oCAAe,gBAAgB,OAAO,QAAQ,EAAE,SAAS,kBAAkB;CAC1E,MAAM,SAAS,YAAY,IAC1B,wCACM,IAAI,QAAqD,CAChE;CACA,IAAI,QAAQ,OAAO,IAAI,KAAK;CAC5B,IAAI,CAAC,OAAO;EAEX,IADe,gBAAgB,mBAAmB,QAAS,aAAa,GAC5D;GACX,MAAM,OAAO,kBAAkB,QAAS,aAAa;GACrD,YAAY,UAAU,KAAK,iBAAiB,YAAY,SAAS,CAAC;GAClE,QAAQ;EACT,OAAO;GAGN,MAAM,WAAW,MAAM;GACvB,MAAM,QAAQ,iBAAiB;GAC/B,MAAM,cAAiB,QACtB,MAAM,UAAU,SAAS,KAAK,OAAO,GAAG,GAAQ,EAC/C,QAAQ,YAAY,UACrB,CAAC;GACF,YAAY,gBAAgB;IAC3B,MAAM,QAAQ;IACd,MAAM,aAAa;GACpB,CAAC;GACD,QAAQ;EACT;EACA,OAAO,IAAI,OAAO,KAAK;CACxB;CACA,eAAe,OAAO,OAAQ;AAC/B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { createRenderer } from "./astro-server.js";
2
+ import { resumableRenderer } from "resumability/astro-server";
3
+ // src/astro-resumability-server.ts
4
+ var astro_resumability_server_default = resumableRenderer(createRenderer(true), { isolate: (component) => Boolean(component.createStore ?? component.isolate) });
5
+ export { astro_resumability_server_default as default };
6
+
7
+ //# sourceMappingURL=astro-resumability-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-resumability-server.js","names":[],"sources":["../../src/astro-resumability-server.ts"],"sourcesContent":["import { resumableRenderer } from \"resumability/astro-server\"\n\nimport { createRenderer } from \"./astro-server.ts\"\n\nexport default resumableRenderer(createRenderer(true), {\n\tisolate: (component) => Boolean(component.createStore ?? component.isolate),\n})\n"],"mappings":";;;AAIA,IAAA,oCAAe,kBAAkB,eAAe,IAAI,GAAG,EACtD,UAAU,cAAc,QAAQ,UAAU,eAAe,UAAU,OAAO,EAC3E,CAAC"}
@@ -1,31 +1,50 @@
1
1
  import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
2
2
  import { t as requestApplication } from "./astro-request-DRKvDjsO.js";
3
- import { n as islandStore, t as island } from "./astro-shared-BT45auwR.js";
4
- import { renderToString } from "./server.js";
3
+ import { n as islandStore, t as island } from "./astro-shared-83hxw7-M.js";
4
+ import { t as renderToStringWithReads } from "./server-renderer-CUQXh9oF.js";
5
5
  // src/astro-server.ts
6
- const renderer = {
6
+ const createRenderer = (awaitState = false) => ({
7
7
  name: `spa`,
8
8
  async check(component) {
9
9
  return component?.spa === true;
10
10
  },
11
11
  async renderToStaticMarkup(component, props, slots) {
12
12
  const request = this.result?.request;
13
- const shared = !component.createStore && !component.isolate && request ? requestApplication(request) : void 0;
13
+ const requestOwner = request ? requestApplication(request) : void 0;
14
+ const shared = !component.createStore && !component.isolate ? requestOwner : void 0;
14
15
  const lifetime = storeContext(void 0, shared?.application);
16
+ if (requestOwner && !shared) lifetime.context.onCleanup(requestOwner.application.onCleanup(lifetime.dispose));
15
17
  try {
16
- const store = await islandStore(component, props, lifetime.context, shared?.store);
17
- return { html: renderToString(() => () => island(component, props, slots), {
18
+ lifetime.context.signal.throwIfAborted();
19
+ const store = await Promise.race([islandStore(component, props, lifetime.context, shared?.store), lifetime.cancelled]);
20
+ lifetime.context.signal.throwIfAborted();
21
+ const options = {
18
22
  store,
19
23
  idPrefix: crypto.randomUUID(),
20
24
  capabilities: component.capabilities ?? []
21
- }) };
25
+ };
26
+ for (;;) {
27
+ lifetime.context.signal.throwIfAborted();
28
+ const reads = /* @__PURE__ */ new Map();
29
+ const pending = /* @__PURE__ */ new Set();
30
+ const html = renderToStringWithReads(() => () => island(component, props, slots), options, awaitState ? (value, token) => {
31
+ reads.set(token.key, token);
32
+ if (value instanceof Promise) pending.add(value);
33
+ } : void 0);
34
+ if (!pending.size) return {
35
+ html,
36
+ ...reads.size ? { attrs: { "data-spa-reads": JSON.stringify([...reads.values()]) } } : {}
37
+ };
38
+ await Promise.race([Promise.all(pending), lifetime.cancelled]);
39
+ }
22
40
  } catch (error) {
23
41
  failPreparation(error, lifetime.dispose);
24
42
  } finally {
25
43
  lifetime.dispose();
26
44
  }
27
45
  }
28
- };
29
- export { renderer as default };
46
+ });
47
+ var astro_server_default = createRenderer();
48
+ export { createRenderer, astro_server_default as default };
30
49
 
31
50
  //# sourceMappingURL=astro-server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"astro-server.js","names":[],"sources":["../../src/astro-server.ts"],"sourcesContent":["/* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */\nimport type { NamedSSRLoadedRendererValue } from \"astro\"\n\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { renderToString } from \"./server.ts\"\n\nconst renderer: NamedSSRLoadedRendererValue = {\n\tname: `spa`,\n\tasync check(component: Island) {\n\t\treturn component?.spa === true\n\t},\n\tasync renderToStaticMarkup(component: Island, props, slots) {\n\t\tconst request = (this as unknown as { result?: { request: Request } }).result\n\t\t\t?.request\n\t\tconst shared =\n\t\t\t!component.createStore && !component.isolate && request\n\t\t\t\t? requestApplication(request)\n\t\t\t\t: undefined\n\t\tconst lifetime = storeContext(undefined, shared?.application)\n\t\ttry {\n\t\t\tconst store = await islandStore(\n\t\t\t\tcomponent,\n\t\t\t\tprops,\n\t\t\t\tlifetime.context,\n\t\t\t\tshared?.store,\n\t\t\t)\n\t\t\treturn {\n\t\t\t\thtml: renderToString(() => () => island(component, props, slots), {\n\t\t\t\t\tstore,\n\t\t\t\t\tidPrefix: crypto.randomUUID(),\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t}),\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailPreparation(error, lifetime.dispose)\n\t\t} finally {\n\t\t\tlifetime.dispose()\n\t\t}\n\t},\n}\nexport default renderer\n"],"mappings":";;;;;AASA,MAAM,WAAwC;CAC7C,MAAM;CACN,MAAM,MAAM,WAAmB;EAC9B,OAAO,WAAW,QAAQ;CAC3B;CACA,MAAM,qBAAqB,WAAmB,OAAO,OAAO;EAC3D,MAAM,UAAW,KAAsD,QACpE;EACH,MAAM,SACL,CAAC,UAAU,eAAe,CAAC,UAAU,WAAW,UAC7C,mBAAmB,OAAO,IAC1B,KAAA;EACJ,MAAM,WAAW,aAAa,KAAA,GAAW,QAAQ,WAAW;EAC5D,IAAI;GACH,MAAM,QAAQ,MAAM,YACnB,WACA,OACA,SAAS,SACT,QAAQ,KACT;GACA,OAAO,EACN,MAAM,2BAA2B,OAAO,WAAW,OAAO,KAAK,GAAG;IACjE;IACA,UAAU,OAAO,WAAW;IAC5B,cAAc,UAAU,gBAAgB,CAAC;GAC1C,CAAC,EACF;EACD,SAAS,OAAO;GACf,gBAAgB,OAAO,SAAS,OAAO;EACxC,UAAU;GACT,SAAS,QAAQ;EAClB;CACD;AACD"}
1
+ {"version":3,"file":"astro-server.js","names":[],"sources":["../../src/astro-server.ts"],"sourcesContent":["/* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */\nimport type { NamedSSRLoadedRendererValue } from \"astro\"\nimport type { ReadableToken } from \"atom.io\"\n\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { renderToStringWithReads } from \"./server-renderer.ts\"\n\nexport const createRenderer = (\n\tawaitState = false,\n): NamedSSRLoadedRendererValue => ({\n\tname: `spa`,\n\tasync check(component: Island) {\n\t\treturn component?.spa === true\n\t},\n\tasync renderToStaticMarkup(component: Island, props, slots) {\n\t\tconst request = (this as unknown as { result?: { request: Request } }).result\n\t\t\t?.request\n\t\tconst requestOwner = request ? requestApplication(request) : undefined\n\t\tconst shared =\n\t\t\t!component.createStore && !component.isolate ? requestOwner : undefined\n\t\tconst lifetime = storeContext(undefined, shared?.application)\n\t\tif (requestOwner && !shared) {\n\t\t\tlifetime.context.onCleanup(\n\t\t\t\trequestOwner.application.onCleanup(lifetime.dispose),\n\t\t\t)\n\t\t}\n\t\ttry {\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst store = await Promise.race([\n\t\t\t\tislandStore(component, props, lifetime.context, shared?.store),\n\t\t\t\tlifetime.cancelled,\n\t\t\t])\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst options = {\n\t\t\t\tstore: store!,\n\t\t\t\tidPrefix: crypto.randomUUID(),\n\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t}\n\t\t\t// Retry only after reads made by this view settle. Each discarded render\n\t\t\t// releases its scopes; conditional branches can discover more async state.\n\t\t\tfor (;;) {\n\t\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\t\tconst reads = new Map<string, ReadableToken<unknown>>()\n\t\t\t\tconst pending = new Set<Promise<unknown>>()\n\t\t\t\tconst html = renderToStringWithReads(\n\t\t\t\t\t() => () => island(component, props, slots),\n\t\t\t\t\toptions,\n\t\t\t\t\tawaitState\n\t\t\t\t\t\t? (value, token) => {\n\t\t\t\t\t\t\t\treads.set(token.key, token)\n\t\t\t\t\t\t\t\tif (value instanceof Promise) {\n\t\t\t\t\t\t\t\t\tpending.add(value)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined,\n\t\t\t\t)\n\t\t\t\tif (!pending.size)\n\t\t\t\t\treturn {\n\t\t\t\t\t\thtml,\n\t\t\t\t\t\t// Even a cached synchronous server read can be async in the browser.\n\t\t\t\t\t\t...(reads.size\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tattrs: {\n\t\t\t\t\t\t\t\t\t\t\"data-spa-reads\": JSON.stringify([...reads.values()]),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t// Caught producer errors resolve as state values. An uncaught failure\n\t\t\t\t// must reject this render with its original error.\n\t\t\t\tawait Promise.race([Promise.all(pending), lifetime.cancelled])\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailPreparation(error, lifetime.dispose)\n\t\t} finally {\n\t\t\tlifetime.dispose()\n\t\t}\n\t},\n})\nexport default createRenderer()\n"],"mappings":";;;;;AAUA,MAAa,kBACZ,aAAa,WACqB;CAClC,MAAM;CACN,MAAM,MAAM,WAAmB;EAC9B,OAAO,WAAW,QAAQ;CAC3B;CACA,MAAM,qBAAqB,WAAmB,OAAO,OAAO;EAC3D,MAAM,UAAW,KAAsD,QACpE;EACH,MAAM,eAAe,UAAU,mBAAmB,OAAO,IAAI,KAAA;EAC7D,MAAM,SACL,CAAC,UAAU,eAAe,CAAC,UAAU,UAAU,eAAe,KAAA;EAC/D,MAAM,WAAW,aAAa,KAAA,GAAW,QAAQ,WAAW;EAC5D,IAAI,gBAAgB,CAAC,QACpB,SAAS,QAAQ,UAChB,aAAa,YAAY,UAAU,SAAS,OAAO,CACpD;EAED,IAAI;GACH,SAAS,QAAQ,OAAO,eAAe;GACvC,MAAM,QAAQ,MAAM,QAAQ,KAAK,CAChC,YAAY,WAAW,OAAO,SAAS,SAAS,QAAQ,KAAK,GAC7D,SAAS,SACV,CAAC;GACD,SAAS,QAAQ,OAAO,eAAe;GACvC,MAAM,UAAU;IACR;IACP,UAAU,OAAO,WAAW;IAC5B,cAAc,UAAU,gBAAgB,CAAC;GAC1C;GAGA,SAAS;IACR,SAAS,QAAQ,OAAO,eAAe;IACvC,MAAM,wBAAQ,IAAI,IAAoC;IACtD,MAAM,0BAAU,IAAI,IAAsB;IAC1C,MAAM,OAAO,oCACA,OAAO,WAAW,OAAO,KAAK,GAC1C,SACA,cACI,OAAO,UAAU;KAClB,MAAM,IAAI,MAAM,KAAK,KAAK;KAC1B,IAAI,iBAAiB,SACpB,QAAQ,IAAI,KAAK;IAEnB,IACC,KAAA,CACJ;IACA,IAAI,CAAC,QAAQ,MACZ,OAAO;KACN;KAEA,GAAI,MAAM,OACP,EACA,OAAO,EACN,kBAAkB,KAAK,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,EACrD,EACD,IACC,CAAC;IACL;IAGD,MAAM,QAAQ,KAAK,CAAC,QAAQ,IAAI,OAAO,GAAG,SAAS,SAAS,CAAC;GAC9D;EACD,SAAS,OAAO;GACf,gBAAgB,OAAO,SAAS,OAAO;EACxC,UAAU;GACT,SAAS,QAAQ;EAClB;CACD;AACD;AACA,IAAA,uBAAe,eAAe"}
@@ -1,13 +1,15 @@
1
1
  import { jsx } from "./jsx-runtime.js";
2
2
  import { IMPLICIT, Store } from "atom.io/internal";
3
3
  // src/astro-shared.ts
4
- async function islandStore(component, props, context, shared) {
4
+ async function islandStore(component, props, context, shared, prepare) {
5
5
  const store = await (component.createStore?.(props, context) ?? shared ?? new Store({
6
6
  name: `spa-island`,
7
7
  lifespan: `ephemeral`,
8
8
  isProduction: true
9
9
  }, IMPLICIT.STORE));
10
10
  context.signal.throwIfAborted();
11
+ await prepare?.(store, props, context);
12
+ context.signal.throwIfAborted();
11
13
  await component.prepareStore?.(store, props, context);
12
14
  context.signal.throwIfAborted();
13
15
  return store;
@@ -26,4 +28,4 @@ function island(component, props, slots) {
26
28
  }
27
29
  export { islandStore as n, island as t };
28
30
 
29
- //# sourceMappingURL=astro-shared-BT45auwR.js.map
31
+ //# sourceMappingURL=astro-shared-83hxw7-M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-shared-83hxw7-M.js","names":[],"sources":["../../src/astro-shared.ts"],"sourcesContent":["import type { RootStore } from \"atom.io/internal\"\nimport { IMPLICIT, Store } from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type { Component, SpaElement } from \"./core.ts\"\nimport { jsx } from \"./jsx-runtime.ts\"\n\nexport interface AstroApplicationContext {\n\t/** Whether the application still represents its initial server snapshot. */\n\treadonly canResume: boolean\n\treadonly signal: AbortSignal\n\tonCleanup(cleanup: () => void): void\n\t/** Initialize a resource once for this application lifetime. */\n\tget<T>(key: unknown, initialize: () => T): T\n}\nexport interface AstroStoreContext {\n\t/** Shared across default islands; private for explicitly isolated islands. */\n\tapplication: AstroApplicationContext\n\t/** The browser island host; undefined during server rendering. */\n\telement: HTMLElement | undefined\n\t/** Aborted when preparation is cancelled or the island is released. */\n\tsignal: AbortSignal\n\t/** Release resources even if preparation or rendering fails. */\n\tonCleanup(cleanup: () => void): void\n}\nexport type AstroStoreFactory<P = Record<string, any>> = (\n\tprops: P,\n\tcontext: AstroStoreContext,\n) => RootStore | Promise<RootStore>\nexport type AstroStorePreparation<P = Record<string, any>> = (\n\tstore: RootStore,\n\tprops: P,\n\tcontext: AstroStoreContext,\n) => void | Promise<void>\nexport type Island<P = any> = Component<P> & {\n\tspa?: boolean\n\t/** Capabilities are scoped to this island root on the server and client. */\n\tcapabilities?: readonly Capability[]\n\t/** Opt into a private island store instead of the shared application store. */\n\tisolate?: boolean\n\tcreateStore?: AstroStoreFactory<P>\n\tprepareStore?: AstroStorePreparation<P>\n}\nexport async function islandStore(\n\tcomponent: Island,\n\tprops: Record<string, any>,\n\tcontext: AstroStoreContext,\n\tshared?: RootStore,\n\tprepare?: AstroStorePreparation,\n): Promise<RootStore> {\n\tconst store = await (component.createStore?.(props, context) ??\n\t\tshared ??\n\t\t(new Store(\n\t\t\t{ name: `spa-island`, lifespan: `ephemeral`, isProduction: true },\n\t\t\tIMPLICIT.STORE,\n\t\t) as RootStore))\n\tcontext.signal.throwIfAborted()\n\tawait prepare?.(store, props, context)\n\tcontext.signal.throwIfAborted()\n\tawait component.prepareStore?.(store, props, context)\n\tcontext.signal.throwIfAborted()\n\treturn store\n}\nexport function island(\n\tcomponent: Island,\n\tprops: Record<string, any>,\n\tslots: Record<string, string>,\n): SpaElement {\n\tconst children = Object.fromEntries(\n\t\tObject.entries(slots).map(([name, html]) => [\n\t\t\tname,\n\t\t\tjsx(`astro-slot`, {\n\t\t\t\tkey: html,\n\t\t\t\tname: name === `default` ? undefined : name,\n\t\t\t\tinnerHTML: html,\n\t\t\t}),\n\t\t]),\n\t)\n\treturn jsx(component, {\n\t\t...props,\n\t\tslots: children,\n\t\tchildren: children[`default`],\n\t})\n}\n"],"mappings":";;;AA2CA,eAAsB,YACrB,WACA,OACA,SACA,QACA,SACqB;CACrB,MAAM,QAAQ,OAAO,UAAU,cAAc,OAAO,OAAO,KAC1D,UACC,IAAI,MACJ;EAAE,MAAM;EAAc,UAAU;EAAa,cAAc;CAAK,GAChE,SAAS,KACV;CACD,QAAQ,OAAO,eAAe;CAC9B,MAAM,UAAU,OAAO,OAAO,OAAO;CACrC,QAAQ,OAAO,eAAe;CAC9B,MAAM,UAAU,eAAe,OAAO,OAAO,OAAO;CACpD,QAAQ,OAAO,eAAe;CAC9B,OAAO;AACR;AACA,SAAgB,OACf,WACA,OACA,OACa;CACb,MAAM,WAAW,OAAO,YACvB,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAC3C,MACA,IAAI,cAAc;EACjB,KAAK;EACL,MAAM,SAAS,YAAY,KAAA,IAAY;EACvC,WAAW;CACZ,CAAC,CACF,CAAC,CACF;CACA,OAAO,IAAI,WAAW;EACrB,GAAG;EACH,OAAO;EACP,UAAU,SAAS;CACpB,CAAC;AACF"}
@@ -3,21 +3,19 @@ import { t as spa } from "./vite-CSHoxzXU.js";
3
3
  function integration(options = {}) {
4
4
  return {
5
5
  name: `spa`,
6
- hooks: { "astro:config:setup"({ addRenderer, addMiddleware, injectScript, updateConfig }) {
6
+ hooks: { "astro:config:setup"({ config, addRenderer, addMiddleware, injectScript, updateConfig }) {
7
7
  addMiddleware({
8
8
  entrypoint: `@atom.io/spa/astro-middleware`,
9
9
  order: `pre`
10
10
  });
11
11
  injectScript(`page`, `import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`);
12
+ const resumable = config.integrations.some(({ name }) => name === `resumability`);
12
13
  addRenderer({
13
14
  name: `spa`,
14
- clientEntrypoint: `@atom.io/spa/astro-client`,
15
- serverEntrypoint: `@atom.io/spa/astro-server`
15
+ clientEntrypoint: resumable ? `@atom.io/spa/astro-resumability-client` : `@atom.io/spa/astro-client`,
16
+ serverEntrypoint: resumable ? `@atom.io/spa/astro-resumability-server` : `@atom.io/spa/astro-server`
16
17
  });
17
- updateConfig({ vite: { plugins: [spa({
18
- include: /\.spa\.[jt]sx$/,
19
- ...options
20
- })] } });
18
+ updateConfig({ vite: { plugins: [spa(options)] } });
21
19
  } }
22
20
  };
23
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"astro.js","names":[],"sources":["../../src/astro.ts"],"sourcesContent":["import type { AstroIntegration } from \"astro\"\n\nimport type { SpaPluginOptions } from \"./vite.ts\"\nimport spa from \"./vite.ts\"\n\nexport type {\n\tAstroApplicationContext,\n\tAstroStoreContext,\n\tAstroStoreFactory,\n\tAstroStorePreparation,\n\tIsland,\n} from \"./astro-shared.ts\"\n\nexport default function integration(\n\toptions: SpaPluginOptions = {},\n): AstroIntegration {\n\treturn {\n\t\tname: `spa`,\n\t\thooks: {\n\t\t\t\"astro:config:setup\"({\n\t\t\t\taddRenderer,\n\t\t\t\taddMiddleware,\n\t\t\t\tinjectScript,\n\t\t\t\tupdateConfig,\n\t\t\t}) {\n\t\t\t\taddMiddleware({\n\t\t\t\t\tentrypoint: `@atom.io/spa/astro-middleware`,\n\t\t\t\t\torder: `pre`,\n\t\t\t\t})\n\t\t\t\tinjectScript(\n\t\t\t\t\t`page`,\n\t\t\t\t\t`import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`,\n\t\t\t\t)\n\t\t\t\taddRenderer({\n\t\t\t\t\tname: `spa`,\n\t\t\t\t\tclientEntrypoint: `@atom.io/spa/astro-client`,\n\t\t\t\t\tserverEntrypoint: `@atom.io/spa/astro-server`,\n\t\t\t\t})\n\t\t\t\tupdateConfig({\n\t\t\t\t\tvite: {\n\t\t\t\t\t\tplugins: [spa({ include: /\\.spa\\.[jt]sx$/, ...options })],\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t},\n\t\t},\n\t}\n}\n"],"mappings":";;AAaA,SAAwB,YACvB,UAA4B,CAAC,GACV;CACnB,OAAO;EACN,MAAM;EACN,OAAO,EACN,qBAAqB,EACpB,aACA,eACA,cACA,gBACE;GACF,cAAc;IACb,YAAY;IACZ,OAAO;GACR,CAAC;GACD,aACC,QACA,oGACD;GACA,YAAY;IACX,MAAM;IACN,kBAAkB;IAClB,kBAAkB;GACnB,CAAC;GACD,aAAa,EACZ,MAAM,EACL,SAAS,CAAC,IAAI;IAAE,SAAS;IAAkB,GAAG;GAAQ,CAAC,CAAC,EACzD,EACD,CAAC;EACF,EACD;CACD;AACD"}
1
+ {"version":3,"file":"astro.js","names":[],"sources":["../../src/astro.ts"],"sourcesContent":["import type { AstroIntegration } from \"astro\"\n\nimport type { SpaPluginOptions } from \"./vite.ts\"\nimport spa from \"./vite.ts\"\n\nexport type {\n\tAstroApplicationContext,\n\tAstroStoreContext,\n\tAstroStoreFactory,\n\tAstroStorePreparation,\n\tIsland,\n} from \"./astro-shared.ts\"\n\nexport default function integration(\n\toptions: SpaPluginOptions = {},\n): AstroIntegration {\n\treturn {\n\t\tname: `spa`,\n\t\thooks: {\n\t\t\t\"astro:config:setup\"({\n\t\t\t\tconfig,\n\t\t\t\taddRenderer,\n\t\t\t\taddMiddleware,\n\t\t\t\tinjectScript,\n\t\t\t\tupdateConfig,\n\t\t\t}) {\n\t\t\t\taddMiddleware({\n\t\t\t\t\tentrypoint: `@atom.io/spa/astro-middleware`,\n\t\t\t\t\torder: `pre`,\n\t\t\t\t})\n\t\t\t\tinjectScript(\n\t\t\t\t\t`page`,\n\t\t\t\t\t`import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`,\n\t\t\t\t)\n\t\t\t\tconst resumable = config.integrations.some(\n\t\t\t\t\t({ name }) => name === `resumability`,\n\t\t\t\t)\n\t\t\t\taddRenderer({\n\t\t\t\t\tname: `spa`,\n\t\t\t\t\tclientEntrypoint: resumable\n\t\t\t\t\t\t? `@atom.io/spa/astro-resumability-client`\n\t\t\t\t\t\t: `@atom.io/spa/astro-client`,\n\t\t\t\t\tserverEntrypoint: resumable\n\t\t\t\t\t\t? `@atom.io/spa/astro-resumability-server`\n\t\t\t\t\t\t: `@atom.io/spa/astro-server`,\n\t\t\t\t})\n\t\t\t\tupdateConfig({\n\t\t\t\t\tvite: {\n\t\t\t\t\t\tplugins: [spa(options)],\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t},\n\t\t},\n\t}\n}\n"],"mappings":";;AAaA,SAAwB,YACvB,UAA4B,CAAC,GACV;CACnB,OAAO;EACN,MAAM;EACN,OAAO,EACN,qBAAqB,EACpB,QACA,aACA,eACA,cACA,gBACE;GACF,cAAc;IACb,YAAY;IACZ,OAAO;GACR,CAAC;GACD,aACC,QACA,oGACD;GACA,MAAM,YAAY,OAAO,aAAa,MACpC,EAAE,WAAW,SAAS,cACxB;GACA,YAAY;IACX,MAAM;IACN,kBAAkB,YACf,2CACA;IACH,kBAAkB,YACf,2CACA;GACJ,CAAC;GACD,aAAa,EACZ,MAAM,EACL,SAAS,CAAC,IAAI,OAAO,CAAC,EACvB,EACD,CAAC;EACF,EACD;CACD;AACD"}