@atom.io/spa 0.0.0-stage → 0.0.1

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 (106) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +401 -2
  3. package/README.mdx +150 -0
  4. package/dist/astro-application.d.ts +15 -0
  5. package/dist/astro-application.d.ts.map +1 -0
  6. package/dist/astro-application.js +62 -0
  7. package/dist/astro-application.js.map +1 -0
  8. package/dist/astro-client.d.ts +9 -0
  9. package/dist/astro-client.d.ts.map +1 -0
  10. package/dist/astro-client.js +98 -0
  11. package/dist/astro-client.js.map +1 -0
  12. package/dist/astro-context-OdlexHR4.js +79 -0
  13. package/dist/astro-context-OdlexHR4.js.map +1 -0
  14. package/dist/astro-middleware.d.ts +4 -0
  15. package/dist/astro-middleware.d.ts.map +1 -0
  16. package/dist/astro-middleware.js +49 -0
  17. package/dist/astro-middleware.js.map +1 -0
  18. package/dist/astro-request-DRKvDjsO.js +70 -0
  19. package/dist/astro-request-DRKvDjsO.js.map +1 -0
  20. package/dist/astro-server.d.ts +4 -0
  21. package/dist/astro-server.d.ts.map +1 -0
  22. package/dist/astro-server.js +30 -0
  23. package/dist/astro-server.js.map +1 -0
  24. package/dist/astro-shared-BT45auwR.js +29 -0
  25. package/dist/astro-shared-BT45auwR.js.map +1 -0
  26. package/dist/astro-shared-DkZaqX7L.d.ts +31 -0
  27. package/dist/astro-shared-DkZaqX7L.d.ts.map +1 -0
  28. package/dist/astro.d.ts +6 -0
  29. package/dist/astro.d.ts.map +1 -0
  30. package/dist/astro.js +26 -0
  31. package/dist/astro.js.map +1 -0
  32. package/dist/client.min.d.ts +1 -0
  33. package/dist/client.min.js +1 -0
  34. package/dist/core-BhiA9fFi.d.ts +44 -0
  35. package/dist/core-BhiA9fFi.d.ts.map +1 -0
  36. package/dist/core-Dvqm7w2y.js +231 -0
  37. package/dist/core-Dvqm7w2y.js.map +1 -0
  38. package/dist/development/astro-application.js +62 -0
  39. package/dist/development/astro-application.js.map +1 -0
  40. package/dist/development/astro-client.js +98 -0
  41. package/dist/development/astro-client.js.map +1 -0
  42. package/dist/development/astro-context-OdlexHR4.js +79 -0
  43. package/dist/development/astro-context-OdlexHR4.js.map +1 -0
  44. package/dist/development/astro-middleware.js +49 -0
  45. package/dist/development/astro-middleware.js.map +1 -0
  46. package/dist/development/astro-request-DRKvDjsO.js +70 -0
  47. package/dist/development/astro-request-DRKvDjsO.js.map +1 -0
  48. package/dist/development/astro-server.js +30 -0
  49. package/dist/development/astro-server.js.map +1 -0
  50. package/dist/development/astro-shared-BT45auwR.js +29 -0
  51. package/dist/development/astro-shared-BT45auwR.js.map +1 -0
  52. package/dist/development/astro.js +26 -0
  53. package/dist/development/astro.js.map +1 -0
  54. package/dist/development/core-DB3sQz4h.js +234 -0
  55. package/dist/development/core-DB3sQz4h.js.map +1 -0
  56. package/dist/development/dom-D9cY6l1R.js +194 -0
  57. package/dist/development/dom-D9cY6l1R.js.map +1 -0
  58. package/dist/development/index.js +40 -0
  59. package/dist/development/index.js.map +1 -0
  60. package/dist/development/jsx-runtime.js +25 -0
  61. package/dist/development/jsx-runtime.js.map +1 -0
  62. package/dist/development/server.js +87 -0
  63. package/dist/development/server.js.map +1 -0
  64. package/dist/development/vite-CQchIQ_-.js +126 -0
  65. package/dist/development/vite-CQchIQ_-.js.map +1 -0
  66. package/dist/development/vite.js +1 -0
  67. package/dist/dom-BR9o9wZW.js +188 -0
  68. package/dist/dom-BR9o9wZW.js.map +1 -0
  69. package/dist/index.d.ts +24 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +40 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/jsx-runtime-BzGV18VO.d.ts +965 -0
  74. package/dist/jsx-runtime-BzGV18VO.d.ts.map +1 -0
  75. package/dist/jsx-runtime.d.ts +2 -0
  76. package/dist/jsx-runtime.js +25 -0
  77. package/dist/jsx-runtime.js.map +1 -0
  78. package/dist/server.d.ts +3 -0
  79. package/dist/server.d.ts.map +1 -0
  80. package/dist/server.js +87 -0
  81. package/dist/server.js.map +1 -0
  82. package/dist/size.json +30 -0
  83. package/dist/vite-CQchIQ_-.js +126 -0
  84. package/dist/vite-CQchIQ_-.js.map +1 -0
  85. package/dist/vite.d.ts +6 -0
  86. package/dist/vite.d.ts.map +1 -0
  87. package/dist/vite.js +1 -0
  88. package/package.json +129 -3
  89. package/src/astro-application.ts +71 -0
  90. package/src/astro-client.ts +136 -0
  91. package/src/astro-context.ts +102 -0
  92. package/src/astro-middleware.ts +48 -0
  93. package/src/astro-request.ts +79 -0
  94. package/src/astro-server.ts +43 -0
  95. package/src/astro-shared.ts +78 -0
  96. package/src/astro.ts +47 -0
  97. package/src/compiler.ts +190 -0
  98. package/src/core.ts +385 -0
  99. package/src/dom.ts +385 -0
  100. package/src/env.d.ts +1 -0
  101. package/src/index.ts +24 -0
  102. package/src/jsx-runtime.ts +63 -0
  103. package/src/jsx-types.d.ts +909 -0
  104. package/src/server.ts +155 -0
  105. package/src/use-loadable.ts +67 -0
  106. package/src/vite.ts +48 -0
@@ -0,0 +1,44 @@
1
+ import { RootStore } from "atom.io/internal";
2
+ import { ReadableFamilyToken, ReadableToken, RegularAtomFamilyToken, RegularAtomToken, Setter, TimelineFamilyToken, TimelineManageable, TimelineToken, TransactionToken, ViewOf, WritableFamilyToken, WritableToken } from "atom.io";
3
+ import { Canonical } from "atom.io/foundations/canonical";
4
+ type Cleanup = () => void;
5
+ interface Accessor<T> {
6
+ (): T;
7
+ }
8
+ type Component<P = any> = (props: P) => Child;
9
+ interface VNode {
10
+ type: string | Component | null;
11
+ props: Record<string, any>;
12
+ }
13
+ type Child = VNode | string | number | bigint | boolean | null | undefined | readonly Child[] | Accessor<Child>;
14
+ interface RootOptions {
15
+ store?: RootStore;
16
+ idPrefix?: string;
17
+ onError?: (error: unknown) => void;
18
+ }
19
+ /** Return the atom.io store selected by the current root. */
20
+ declare function useStore(): RootStore;
21
+ declare function onCleanup(cleanup: Cleanup): void;
22
+ declare function onMount(run: Cleanup): void;
23
+ declare function useId(): string;
24
+ /** Capture a token for this instance. Change the component key to change its token. */
25
+ declare function useValue<T, E = never>(token: ReadableToken<T, any, E>): Accessor<ViewOf<T | E>>;
26
+ declare function useValue<T, K extends Canonical, E = never>(family: ReadableFamilyToken<T, K, E>, key: NoInfer<K>): Accessor<ViewOf<T | E>>;
27
+ declare function useSetter<T>(token: WritableToken<T, any, any>): (value: T | Setter<T>) => void;
28
+ declare function useSetter<T, K extends Canonical>(family: WritableFamilyToken<T, K, any>, key: NoInfer<K>): (value: T | Setter<T>) => void;
29
+ declare function useTransaction<F extends (...args: any[]) => any>(token: TransactionToken<F>): (...args: Parameters<F>) => ReturnType<F>;
30
+ declare function useRef<E extends Element>(token: RegularAtomToken<E | null>): (element: E | null) => void;
31
+ declare function useRef<E extends Element, K extends Canonical>(family: RegularAtomFamilyToken<E | null, K>, key: NoInfer<K>): (element: E | null) => void;
32
+ interface TimelineValue {
33
+ at: number;
34
+ length: number;
35
+ undo(): void;
36
+ redo(): void;
37
+ clear(): void;
38
+ undoTransaction?: Cleanup;
39
+ redoTransaction?: Cleanup;
40
+ }
41
+ declare function useTimeline<M extends TimelineManageable>(token: TimelineToken<M>): Accessor<TimelineValue>;
42
+ declare function useTimeline<K extends Canonical, M extends TimelineManageable>(family: TimelineFamilyToken<K, M>, key: NoInfer<K>): Accessor<TimelineValue>;
43
+ export { TimelineValue as a, onMount as c, useSetter as d, useStore as f, useValue as h, RootOptions as i, useId as l, useTransaction as m, Child as n, VNode as o, useTimeline as p, Component as r, onCleanup as s, Accessor as t, useRef as u };
44
+ //# sourceMappingURL=core-BhiA9fFi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-BhiA9fFi.d.ts","names":[],"sources":["../src/core.ts"],"mappings":";;;KAgCY;UAGK,SAAS;MACrB;;KAGO,UAAU,YAAY,OAAO,MAAM;UAC9B;EAChB,eAAe;EACf,OAAO;;KAEI,QACT,yEAOS,UACT,SAAS;UACK;EAChB,QAAQ;EACR;EACA,WAAW;;;iBA8HI,YAAY;iBAGZ,UAAU,SAAS;iBAGnB,QAAQ,KAAK;iBASb;;iBAuDA,SAAS,GAAG,WAC3B,OAAO,cAAc,QAAQ,KAC3B,SAAS,OAAO,IAAI;iBACP,SAAS,GAAG,UAAU,WAAW,WAChD,QAAQ,oBAAoB,GAAG,GAAG,IAClC,KAAK,QAAQ,KACX,SAAS,OAAO,IAAI;iBAYP,UAAU,GACzB,OAAO,cAAc,gBAClB,OAAO,IAAI,OAAO;iBACN,UAAU,GAAG,UAAU,WACtC,QAAQ,oBAAoB,GAAG,SAC/B,KAAK,QAAQ,MACV,OAAO,IAAI,OAAO;iBAQN,eAAe,cAAc,qBAC5C,OAAO,iBAAiB,SAClB,MAAM,WAAW,OAAO,WAAW;iBAK1B,OAAO,UAAU,SAChC,OAAO,iBAAiB,aACrB,SAAS;iBACG,OAAO,UAAU,SAAS,UAAU,WACnD,QAAQ,uBAAuB,UAAU,IACzC,KAAK,QAAQ,MACV,SAAS;UAuBI;EAChB;EACA;EACA;EACA;EACA;EACA,kBAAkB;EAClB,kBAAkB;;iBAEH,YAAY,UAAU,oBACrC,OAAO,cAAc,KACnB,SAAS;iBACI,YAAY,UAAU,WAAW,UAAU,oBAC1D,QAAQ,oBAAoB,GAAG,IAC/B,KAAK,QAAQ,KACX,SAAS"}
@@ -0,0 +1,231 @@
1
+ import { IMPLICIT, actUponStore, clearTimelineInStore, findInStore, findTimelineInStore, getFromStore, getTimelineTransactionAtHead, inspectTimelineInStore, setIntoStore, subscribeToState, subscribeToTimeline, timeTravel, timeTravelTransactionGroupInStore } from "atom.io/internal";
2
+ // src/core.ts
3
+ let owner;
4
+ let tracking;
5
+ let serial = 0;
6
+ function within(scope, run) {
7
+ const previous = owner;
8
+ owner = scope;
9
+ try {
10
+ return run();
11
+ } finally {
12
+ owner = previous;
13
+ }
14
+ }
15
+ function untrack(run) {
16
+ const previous = tracking;
17
+ tracking = void 0;
18
+ try {
19
+ return run();
20
+ } finally {
21
+ tracking = previous;
22
+ }
23
+ }
24
+ function createScope(parent) {
25
+ const child = {
26
+ _root: parent?._root,
27
+ _parent: parent,
28
+ _cleanups: /* @__PURE__ */ new Set(),
29
+ _updates: [],
30
+ _dead: false
31
+ };
32
+ parent?._cleanups.add(child);
33
+ return child;
34
+ }
35
+ function fail(scope, error) {
36
+ try {
37
+ dispose(scope);
38
+ } catch (cleanup) {
39
+ throw new AggregateError([error, cleanup]);
40
+ }
41
+ throw error;
42
+ }
43
+ function dispose(scope) {
44
+ if (scope._dead) return;
45
+ scope._dead = true;
46
+ const errors = [];
47
+ for (const cleanup of [...scope._cleanups].reverse()) try {
48
+ typeof cleanup === `function` ? cleanup() : dispose(cleanup);
49
+ } catch (error) {
50
+ errors.push(error);
51
+ }
52
+ scope._parent?._cleanups.delete(scope);
53
+ scope._cleanups.clear();
54
+ scope._updates.length = 0;
55
+ if (errors.length) throw new AggregateError(errors);
56
+ }
57
+ function invalidate(scope) {
58
+ for (const run of scope._updates) enqueue(scope, run);
59
+ for (const child of scope._cleanups) if (typeof child !== `function`) invalidate(child);
60
+ }
61
+ function enqueue(scope, run) {
62
+ if (scope._dead) return;
63
+ const root = scope._root;
64
+ if (!root._queue.size) queueMicrotask(() => {
65
+ try {
66
+ root.flush();
67
+ } catch (error) {
68
+ root.error(error);
69
+ }
70
+ });
71
+ root._queue.add(run);
72
+ }
73
+ function createRoot(options = {}, server = false) {
74
+ const root = {
75
+ _store: options.store ?? IMPLICIT.STORE,
76
+ _prefix: options.idPrefix ?? `w${serial++}`,
77
+ _id: 0,
78
+ ...createScope(),
79
+ _queue: /* @__PURE__ */ new Set(),
80
+ _mounts: server ? void 0 : []
81
+ };
82
+ root._root = root;
83
+ root.error = options.onError ?? ((error) => {
84
+ throw error;
85
+ });
86
+ root.flush = () => {
87
+ try {
88
+ while (root._queue.size || root._mounts.length) {
89
+ for (const run of [...root._queue]) if (root._queue.delete(run)) run();
90
+ for (const run of root._mounts.splice(0)) run();
91
+ }
92
+ } catch (error) {
93
+ fail(root, error);
94
+ }
95
+ };
96
+ return root;
97
+ }
98
+ /** Return the atom.io store selected by the current root. */
99
+ function useStore() {
100
+ return owner._root._store;
101
+ }
102
+ function onCleanup(cleanup) {
103
+ owner._cleanups.add(cleanup);
104
+ }
105
+ function onMount(run) {
106
+ const scope = owner;
107
+ scope._root._mounts?.push(() => {
108
+ if (!scope._dead) within(scope, () => {
109
+ untrack(run);
110
+ });
111
+ });
112
+ }
113
+ function useId() {
114
+ const root = owner._root;
115
+ return `${root._prefix}-${root._id++}`;
116
+ }
117
+ function observe(scope, read, apply) {
118
+ const subscriptions = /* @__PURE__ */ new Map();
119
+ const run = () => {
120
+ if (scope._dead) return;
121
+ const used = /* @__PURE__ */ new Set();
122
+ const previous = tracking;
123
+ tracking = (subscribe) => {
124
+ used.add(subscribe);
125
+ if (!subscriptions.has(subscribe)) subscriptions.set(subscribe, subscribe(() => {
126
+ enqueue(scope, run);
127
+ }));
128
+ };
129
+ let value;
130
+ try {
131
+ value = within(scope, read);
132
+ } finally {
133
+ tracking = previous;
134
+ for (const [subscribe, unsubscribe] of subscriptions) if (!used.has(subscribe)) {
135
+ unsubscribe();
136
+ subscriptions.delete(subscribe);
137
+ }
138
+ }
139
+ untrack(() => {
140
+ apply(value);
141
+ });
142
+ };
143
+ scope._updates.push(run);
144
+ scope._cleanups.add(() => {
145
+ scope._root._queue.delete(run);
146
+ for (const unsubscribe of subscriptions.values()) unsubscribe();
147
+ });
148
+ run();
149
+ }
150
+ /** Resolve a fixed family key in the current owner's store. */
151
+ function resolveStateToken(token, key) {
152
+ const store = owner._root._store;
153
+ return token.type.endsWith(`_family`) ? findInStore(store, token, key) : token;
154
+ }
155
+ function useValue(token, key) {
156
+ token = resolveStateToken(token, key);
157
+ const store = owner._root._store;
158
+ const subscribe = (notify) => subscribeToState(store, token, `spa:${serial++}`, notify);
159
+ return () => {
160
+ const value = getFromStore(store, token);
161
+ tracking?.(subscribe);
162
+ return value;
163
+ };
164
+ }
165
+ function useSetter(token, key) {
166
+ token = resolveStateToken(token, key);
167
+ const store = owner._root._store;
168
+ return (value) => {
169
+ setIntoStore(store, token, value);
170
+ };
171
+ }
172
+ function useTransaction(token) {
173
+ return actUponStore(owner._root._store, token, `spa:${serial++}`);
174
+ }
175
+ const refs = /* @__PURE__ */ new WeakMap();
176
+ function useRef(token, key) {
177
+ token = resolveStateToken(token, key);
178
+ const store = owner._root._store;
179
+ const owners = refs.get(store) ?? /* @__PURE__ */ new Map();
180
+ refs.set(store, owners);
181
+ const identity = {};
182
+ let held = null;
183
+ return (element) => {
184
+ if (element) {
185
+ held = element;
186
+ owners.set(token.key, identity);
187
+ setIntoStore(store, token, element);
188
+ } else if (owners.get(token.key) === identity) {
189
+ owners.delete(token.key);
190
+ if (getFromStore(store, token) === held) setIntoStore(store, token, null);
191
+ held = null;
192
+ }
193
+ };
194
+ }
195
+ function useTimeline(token, key) {
196
+ const store = owner._root._store;
197
+ if (token.type === `timeline_family`) token = findTimelineInStore(store, token, key);
198
+ const subscribe = (notify) => subscribeToTimeline(store, token, `spa:${serial++}`, notify);
199
+ const controls = {
200
+ undo: () => {
201
+ timeTravel(store, `undo`, token);
202
+ },
203
+ redo: () => {
204
+ timeTravel(store, `redo`, token);
205
+ },
206
+ clear: () => {
207
+ clearTimelineInStore(store, token);
208
+ }
209
+ };
210
+ return () => {
211
+ const value = {
212
+ ...inspectTimelineInStore(store, token),
213
+ ...controls
214
+ };
215
+ tracking?.(subscribe);
216
+ for (const direction of [`undo`, `redo`]) {
217
+ const group = getTimelineTransactionAtHead(store.timelines.get(token.key), direction);
218
+ if (group) value[`${direction}Transaction`] = () => timeTravelTransactionGroupInStore(store, direction, group);
219
+ }
220
+ return value;
221
+ };
222
+ }
223
+ function plain(value) {
224
+ if (typeof value === `function`) return plain(value());
225
+ if (Array.isArray(value)) return value.map(plain).join(``);
226
+ if (value == null || typeof value === `boolean`) return ``;
227
+ return String(value);
228
+ }
229
+ export { useTimeline as _, invalidate as a, within as b, onMount as c, resolveStateToken as d, untrack as f, useStore as g, useSetter as h, fail as i, owner as l, useRef as m, createScope as n, observe as o, useId as p, dispose as r, onCleanup as s, createRoot as t, plain as u, useTransaction as v, useValue as y };
230
+
231
+ //# sourceMappingURL=core-Dvqm7w2y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-Dvqm7w2y.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\tinspectTimelineInStore,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\ttimeTravel,\n\ttimeTravelTransactionGroupInStore,\n} from \"atom.io/internal\"\n\nexport type Cleanup = () => void\n// A callable interface permits the recursive Child union. A type alias does not.\n/* oxlint-disable typescript/prefer-function-type -- A callable interface is required for recursive Child. */\nexport interface Accessor<T> {\n\t(): T\n}\n/* oxlint-enable typescript/prefer-function-type */\nexport type Component<P = any> = (props: P) => Child\nexport interface VNode {\n\ttype: string | Component | null\n\tprops: Record<string, any>\n}\nexport type Child =\n\t| VNode\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| readonly Child[]\n\t| Accessor<Child>\nexport interface RootOptions {\n\tstore?: RootStore\n\tidPrefix?: string\n\tonError?: (error: unknown) => void\n}\nexport interface Scope {\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_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\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 (scope._dead) 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 root = {\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\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 (scope._dead) 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 useValue<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): Accessor<ViewOf<T | E>>\nexport function useValue<T, K extends Canonical, E = never>(\n\tfamily: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<ViewOf<T | E>>\nexport function useValue(token: any, key?: Canonical): Accessor<any> {\n\ttoken = resolveStateToken(token, key)\n\tconst store = owner!._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\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 TimelineValue {\n\tat: number\n\tlength: number\n\tundo(): void\n\tredo(): void\n\tclear(): void\n\tundoTransaction?: Cleanup\n\tredoTransaction?: Cleanup\n}\nexport function useTimeline<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n): Accessor<TimelineValue>\nexport function useTimeline<K extends Canonical, M extends TimelineManageable>(\n\tfamily: TimelineFamilyToken<K, M>,\n\tkey: NoInfer<K>,\n): Accessor<TimelineValue>\nexport function useTimeline(\n\ttoken: any,\n\tkey?: Canonical,\n): Accessor<TimelineValue> {\n\tconst store = owner!._root._store\n\tif (token.type === `timeline_family`)\n\t\ttoken = findTimelineInStore(store, token, key!)\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToTimeline(store, token, `spa:${serial++}`, notify)\n\tconst controls = {\n\t\tundo: () => {\n\t\t\ttimeTravel(store, `undo`, token)\n\t\t},\n\t\tredo: () => {\n\t\t\ttimeTravel(store, `redo`, token)\n\t\t},\n\t\tclear: () => {\n\t\t\tclearTimelineInStore(store, token)\n\t\t},\n\t}\n\treturn () => {\n\t\tconst value: TimelineValue = {\n\t\t\t...inspectTimelineInStore(store, token),\n\t\t\t...controls,\n\t\t}\n\t\ttracking?.(subscribe)\n\t\tfor (const direction of [`undo`, `redo`] as const) {\n\t\t\tconst group = getTimelineTransactionAtHead(\n\t\t\t\tstore.timelines.get(token.key)!,\n\t\t\t\tdirection,\n\t\t\t)\n\t\t\tif (group)\n\t\t\t\tvalue[`${direction}Transaction`] = () =>\n\t\t\t\t\ttimeTravelTransactionGroupInStore(store, direction, group)\n\t\t}\n\t\treturn value\n\t}\n}\n\nexport function plain(value: Child): 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"],"mappings":";;AA4EA,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,SAAg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AAO;CAIxD,OAAO,OAAO,KAAK;AACpB"}
@@ -0,0 +1,62 @@
1
+ import { t as applicationContext } from "./astro-context-OdlexHR4.js";
2
+ import { IMPLICIT, withdraw } from "atom.io/internal";
3
+ // src/astro-application.ts
4
+ const applications = /* @__PURE__ */ new WeakMap();
5
+ /** Called by the integration's early page script, before island preparation. */
6
+ function browserApplication(document) {
7
+ let application = applications.get(document);
8
+ if (application) return application;
9
+ application = applicationContext();
10
+ const app = application;
11
+ const store = IMPLICIT.STORE;
12
+ const originalDefault = store.runDefault;
13
+ applications.set(document, app);
14
+ const changed = () => {
15
+ app.canResume = false;
16
+ };
17
+ const internal = (key) => key.startsWith(`🔍 spa islands`);
18
+ const subscriptions = /* @__PURE__ */ new Map();
19
+ const watch = (token) => {
20
+ if (internal(token.key)) return;
21
+ if (store.valueMap.has(token.key)) changed();
22
+ subscriptions.get(token.key)?.();
23
+ const state = withdraw(store, token);
24
+ subscriptions.set(token.key, state.subject.subscribe(`spa:bootstrap`, changed));
25
+ };
26
+ for (const state of [
27
+ ...store.atoms.values(),
28
+ ...store.readonlySelectors.values(),
29
+ ...store.writableSelectors.values()
30
+ ]) watch(state);
31
+ const removed = (token) => {
32
+ if (!internal(token.key)) {
33
+ changed();
34
+ subscriptions.get(token.key)?.();
35
+ subscriptions.delete(token.key);
36
+ }
37
+ };
38
+ const events = [
39
+ store.on.atomCreation.subscribe(`spa:bootstrap`, watch),
40
+ store.on.selectorCreation.subscribe(`spa:bootstrap`, watch),
41
+ store.on.atomDisposal.subscribe(`spa:bootstrap`, removed),
42
+ store.on.selectorDisposal.subscribe(`spa:bootstrap`, removed),
43
+ store.on.transactionCommit.subscribe(`spa:bootstrap`, changed)
44
+ ];
45
+ document.addEventListener(`astro:before-swap`, changed);
46
+ const pagehide = (event) => {
47
+ if (!event.persisted) app.dispose();
48
+ };
49
+ document.defaultView?.addEventListener(`pagehide`, pagehide);
50
+ app.onCleanup(() => {
51
+ for (const unsubscribe of subscriptions.values()) unsubscribe();
52
+ for (const unsubscribe of events) unsubscribe();
53
+ document.removeEventListener(`astro:before-swap`, changed);
54
+ document.defaultView?.removeEventListener(`pagehide`, pagehide);
55
+ store.runDefault = originalDefault;
56
+ applications.delete(document);
57
+ });
58
+ return app;
59
+ }
60
+ export { browserApplication };
61
+
62
+ //# sourceMappingURL=astro-application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-application.js","names":[],"sources":["../../src/astro-application.ts"],"sourcesContent":["import type { ReadableToken } from \"atom.io\"\nimport { IMPLICIT, withdraw } from \"atom.io/internal\"\n\nimport { applicationContext } from \"./astro-context.ts\"\n\nconst applications = new WeakMap<\n\tDocument,\n\tReturnType<typeof applicationContext>\n>()\n\n/** Called by the integration's early page script, before island preparation. */\nexport function browserApplication(\n\tdocument: Document,\n): ReturnType<typeof applicationContext> {\n\tlet application = applications.get(document)\n\tif (application) return application\n\tapplication = applicationContext()\n\tconst app = application\n\tconst store = IMPLICIT.STORE\n\tconst originalDefault = store.runDefault\n\tapplications.set(document, app)\n\tconst changed = () => {\n\t\tapp.canResume = false\n\t}\n\tconst internal = (key: string) => key.startsWith(`🔍 spa islands`)\n\tconst subscriptions = new Map<string, () => void>()\n\tconst watch = (token: ReadableToken<unknown, any, any>) => {\n\t\tif (internal(token.key)) return\n\t\tif (store.valueMap.has(token.key)) changed()\n\t\tsubscriptions.get(token.key)?.()\n\t\tconst state = withdraw(store, token)\n\t\tsubscriptions.set(\n\t\t\ttoken.key,\n\t\t\tstate.subject.subscribe(`spa:bootstrap`, changed),\n\t\t)\n\t}\n\tfor (const state of [\n\t\t...store.atoms.values(),\n\t\t...store.readonlySelectors.values(),\n\t\t...store.writableSelectors.values(),\n\t])\n\t\twatch(state)\n\tconst removed = (token: ReadableToken<unknown, any, any>) => {\n\t\tif (!internal(token.key)) {\n\t\t\tchanged()\n\t\t\tsubscriptions.get(token.key)?.()\n\t\t\tsubscriptions.delete(token.key)\n\t\t}\n\t}\n\tconst events = [\n\t\tstore.on.atomCreation.subscribe(`spa:bootstrap`, watch),\n\t\tstore.on.selectorCreation.subscribe(`spa:bootstrap`, watch),\n\t\tstore.on.atomDisposal.subscribe(`spa:bootstrap`, removed),\n\t\tstore.on.selectorDisposal.subscribe(`spa:bootstrap`, removed),\n\t\tstore.on.transactionCommit.subscribe(`spa:bootstrap`, changed),\n\t]\n\tdocument.addEventListener(`astro:before-swap`, changed)\n\tconst pagehide = (event: PageTransitionEvent) => {\n\t\tif (!event.persisted) app.dispose()\n\t}\n\tdocument.defaultView?.addEventListener(`pagehide`, pagehide)\n\tapp.onCleanup(() => {\n\t\tfor (const unsubscribe of subscriptions.values()) unsubscribe()\n\t\tfor (const unsubscribe of events) unsubscribe()\n\t\tdocument.removeEventListener(`astro:before-swap`, changed)\n\t\tdocument.defaultView?.removeEventListener(`pagehide`, pagehide)\n\t\tstore.runDefault = originalDefault\n\t\tapplications.delete(document)\n\t})\n\treturn app\n}\n"],"mappings":";;;AAKA,MAAM,+BAAe,IAAI,QAGvB;;AAGF,SAAgB,mBACf,UACwC;CACxC,IAAI,cAAc,aAAa,IAAI,QAAQ;CAC3C,IAAI,aAAa,OAAO;CACxB,cAAc,mBAAmB;CACjC,MAAM,MAAM;CACZ,MAAM,QAAQ,SAAS;CACvB,MAAM,kBAAkB,MAAM;CAC9B,aAAa,IAAI,UAAU,GAAG;CAC9B,MAAM,gBAAgB;EACrB,IAAI,YAAY;CACjB;CACA,MAAM,YAAY,QAAgB,IAAI,WAAW,gBAAgB;CACjE,MAAM,gCAAgB,IAAI,IAAwB;CAClD,MAAM,SAAS,UAA4C;EAC1D,IAAI,SAAS,MAAM,GAAG,GAAG;EACzB,IAAI,MAAM,SAAS,IAAI,MAAM,GAAG,GAAG,QAAQ;EAC3C,cAAc,IAAI,MAAM,GAAG,CAAC,GAAG;EAC/B,MAAM,QAAQ,SAAS,OAAO,KAAK;EACnC,cAAc,IACb,MAAM,KACN,MAAM,QAAQ,UAAU,iBAAiB,OAAO,CACjD;CACD;CACA,KAAK,MAAM,SAAS;EACnB,GAAG,MAAM,MAAM,OAAO;EACtB,GAAG,MAAM,kBAAkB,OAAO;EAClC,GAAG,MAAM,kBAAkB,OAAO;CACnC,GACC,MAAM,KAAK;CACZ,MAAM,WAAW,UAA4C;EAC5D,IAAI,CAAC,SAAS,MAAM,GAAG,GAAG;GACzB,QAAQ;GACR,cAAc,IAAI,MAAM,GAAG,CAAC,GAAG;GAC/B,cAAc,OAAO,MAAM,GAAG;EAC/B;CACD;CACA,MAAM,SAAS;EACd,MAAM,GAAG,aAAa,UAAU,iBAAiB,KAAK;EACtD,MAAM,GAAG,iBAAiB,UAAU,iBAAiB,KAAK;EAC1D,MAAM,GAAG,aAAa,UAAU,iBAAiB,OAAO;EACxD,MAAM,GAAG,iBAAiB,UAAU,iBAAiB,OAAO;EAC5D,MAAM,GAAG,kBAAkB,UAAU,iBAAiB,OAAO;CAC9D;CACA,SAAS,iBAAiB,qBAAqB,OAAO;CACtD,MAAM,YAAY,UAA+B;EAChD,IAAI,CAAC,MAAM,WAAW,IAAI,QAAQ;CACnC;CACA,SAAS,aAAa,iBAAiB,YAAY,QAAQ;CAC3D,IAAI,gBAAgB;EACnB,KAAK,MAAM,eAAe,cAAc,OAAO,GAAG,YAAY;EAC9D,KAAK,MAAM,eAAe,QAAQ,YAAY;EAC9C,SAAS,oBAAoB,qBAAqB,OAAO;EACzD,SAAS,aAAa,oBAAoB,YAAY,QAAQ;EAC9D,MAAM,aAAa;EACnB,aAAa,OAAO,QAAQ;CAC7B,CAAC;CACD,OAAO;AACR"}
@@ -0,0 +1,98 @@
1
+ import { browserApplication } from "./astro-application.js";
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 { s as onCleanup, y as useValue } from "./core-DB3sQz4h.js";
5
+ import { n as render, t as hydrate } from "./dom-D9cY6l1R.js";
6
+ import { IMPLICIT, createRegularAtomFamily, disposeFromStore, findInStore, setIntoStore } from "atom.io/internal";
7
+ // src/astro-client.ts
8
+ const roots = /* @__PURE__ */ new WeakMap();
9
+ const states = /* @__PURE__ */ new WeakMap();
10
+ let serial = 0;
11
+ var astro_client_default = (element) => async (component, props, slots, { client }) => {
12
+ const previous = roots.get(element);
13
+ if (previous?.component === component) {
14
+ previous.update(props, slots);
15
+ return previous.ready;
16
+ }
17
+ previous?.dispose();
18
+ const shared = !component.createStore && !component.isolate;
19
+ const application = shared ? browserApplication(element.ownerDocument) : void 0;
20
+ if (application && client === `only`) application.canResume = false;
21
+ const lifetime = storeContext(element, application);
22
+ const initial = {
23
+ props,
24
+ slots
25
+ };
26
+ let current = initial;
27
+ let update;
28
+ let disposed = false;
29
+ const dispose = () => {
30
+ if (disposed) return;
31
+ disposed = true;
32
+ element.removeEventListener(`astro:unmount`, dispose);
33
+ roots.delete(element);
34
+ lifetime.dispose();
35
+ };
36
+ const ready = Promise.resolve().then(async () => {
37
+ if (lifetime.context.signal.aborted) return;
38
+ let mounting = false;
39
+ try {
40
+ const store = await Promise.race([islandStore(component, props, lifetime.context, shared ? IMPLICIT.STORE : void 0), lifetime.cancelled]);
41
+ if (lifetime.context.signal.aborted) return;
42
+ mounting = true;
43
+ const replace = client === `only` || previous !== void 0 || application?.canResume === false;
44
+ const sentinel = element.lastChild;
45
+ if (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`) sentinel.remove();
46
+ let family = states.get(store);
47
+ if (!family) {
48
+ family = createRegularAtomFamily(store, {
49
+ key: `🔍 spa islands`,
50
+ default: {
51
+ props: {},
52
+ slots: {}
53
+ }
54
+ });
55
+ states.set(store, family);
56
+ }
57
+ const state = findInStore(store, family, serial++);
58
+ setIntoStore(store, state, replace ? current : initial);
59
+ lifetime.context.onCleanup(() => {
60
+ disposeFromStore(store, state);
61
+ });
62
+ const mount = () => {
63
+ onCleanup(dispose);
64
+ const value = useValue(state);
65
+ return () => island(component, value().props, value().slots);
66
+ };
67
+ if (replace) element.replaceChildren();
68
+ const root = (replace ? render : hydrate)(mount, element, { store });
69
+ lifetime.context.onCleanup(root.dispose);
70
+ update = (next) => {
71
+ setIntoStore(store, state, next);
72
+ root.flush();
73
+ };
74
+ if (!replace && current !== initial) update(current);
75
+ } catch (error) {
76
+ if (lifetime.context.signal.aborted && !mounting) return;
77
+ failPreparation(error, dispose);
78
+ }
79
+ });
80
+ roots.set(element, {
81
+ component,
82
+ ready,
83
+ update(nextProps, nextSlots) {
84
+ current = {
85
+ props: nextProps,
86
+ slots: nextSlots
87
+ };
88
+ update?.(current);
89
+ },
90
+ dispose
91
+ });
92
+ element.addEventListener(`astro:unmount`, dispose, { once: true });
93
+ lifetime.context.onCleanup(dispose);
94
+ return ready;
95
+ };
96
+ export { astro_client_default as default };
97
+
98
+ //# sourceMappingURL=astro-client.js.map
@@ -0,0 +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})\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;AAE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AM;GAC1B;GACA,MAAM,QAAQ,YAAY,OAAQ,QAAQ,QAAQ;GAClD,aAAa,OAAQ,OAAO,UAAU,UAAU,OAAO;GACvD,SAAS,QAAQ,gBAAgB;IAChC,iBAAiB,OAAQ,KAAK;GAC/B,CAAC;GACD,MAAM,cAAc;IACnB,UAAU,OAAO;IACjB,MAAM,QAAQ,SAAS,KAAK;IAC5B,aAAa,OAAO,WAAW,MAAM,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,KAAK;GAC5D;GACA,IAAI,SAAS,QAAQ,gBAAgB;GACrC,MAAM,QAAQ,UAAU,SAAS,QAAA,CAAS,OAAO,SAAS,EAClD,MACR,CAAC;GACD,SAAS,QAAQ,UAAU,KAAK,OAAO;GACvC,UAAU,SAAS;IAClB,aAAa,OAAQ,OAAO,IAAI;IAChC,KAAK,MAAM;GACZ;GAGA,IAAI,CAAC,WAAW,YAAY,SAAS,OAAO,OAAO;EACpD,SAAS,OAAO;GACf,IAAI,SAAS,QAAQ,OAAO,WAAW,CAAC,UAAU;GAClD,gBAAgB,OAAO,OAAO;EAC/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"}
@@ -0,0 +1,79 @@
1
+ // src/astro-context.ts
2
+ function lifetime() {
3
+ const controller = new AbortController();
4
+ const cleanups = /* @__PURE__ */ new Set();
5
+ let cancel;
6
+ const cancelled = new Promise((resolve) => {
7
+ cancel = () => {
8
+ resolve(void 0);
9
+ };
10
+ });
11
+ return {
12
+ signal: controller.signal,
13
+ onCleanup(cleanup) {
14
+ if (controller.signal.aborted) cleanup();
15
+ else cleanups.add(cleanup);
16
+ return () => {
17
+ cleanups.delete(cleanup);
18
+ };
19
+ },
20
+ cancelled,
21
+ dispose() {
22
+ if (controller.signal.aborted) return;
23
+ controller.abort();
24
+ cancel();
25
+ const errors = [];
26
+ for (const cleanup of [...cleanups].reverse()) try {
27
+ cleanup();
28
+ } catch (error) {
29
+ errors.push(error);
30
+ }
31
+ cleanups.clear();
32
+ if (errors.length) throw new AggregateError(errors, `spa: Astro store cleanup failed`);
33
+ }
34
+ };
35
+ }
36
+ function applicationContext() {
37
+ const life = lifetime();
38
+ const resources = /* @__PURE__ */ new Map();
39
+ life.onCleanup(() => {
40
+ resources.clear();
41
+ });
42
+ return {
43
+ ...life,
44
+ canResume: true,
45
+ get(key, initialize) {
46
+ life.signal.throwIfAborted();
47
+ if (!resources.has(key)) resources.set(key, initialize());
48
+ return resources.get(key);
49
+ }
50
+ };
51
+ }
52
+ /** Island resources and shared application resources have distinct owners. */
53
+ function storeContext(element, shared) {
54
+ const life = lifetime();
55
+ const application = shared ?? applicationContext();
56
+ if (shared) life.onCleanup(shared.onCleanup(life.dispose));
57
+ else life.onCleanup(application.dispose);
58
+ return {
59
+ context: {
60
+ element,
61
+ signal: life.signal,
62
+ onCleanup: life.onCleanup,
63
+ application
64
+ },
65
+ dispose: life.dispose,
66
+ cancelled: life.cancelled
67
+ };
68
+ }
69
+ function failPreparation(error, dispose) {
70
+ try {
71
+ dispose();
72
+ } catch (cleanup) {
73
+ throw new AggregateError([error, cleanup]);
74
+ }
75
+ throw error;
76
+ }
77
+ export { failPreparation as n, storeContext as r, applicationContext as t };
78
+
79
+ //# sourceMappingURL=astro-context-OdlexHR4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-context-OdlexHR4.js","names":[],"sources":["../../src/astro-context.ts"],"sourcesContent":["import type {\n\tAstroApplicationContext,\n\tAstroStoreContext,\n} from \"./astro-shared.ts\"\n\ntype Lifetime = {\n\tsignal: AbortSignal\n\tonCleanup(cleanup: () => void): () => void\n\tdispose(): void\n\tcancelled: Promise<undefined>\n}\n\nfunction lifetime(): Lifetime {\n\tconst controller = new AbortController()\n\tconst cleanups = new Set<() => void>()\n\tlet cancel!: () => void\n\tconst cancelled = new Promise<undefined>((resolve) => {\n\t\tcancel = () => {\n\t\t\tresolve(undefined)\n\t\t}\n\t})\n\treturn {\n\t\tsignal: controller.signal,\n\t\tonCleanup(cleanup) {\n\t\t\tif (controller.signal.aborted) cleanup()\n\t\t\telse cleanups.add(cleanup)\n\t\t\treturn () => {\n\t\t\t\tcleanups.delete(cleanup)\n\t\t\t}\n\t\t},\n\t\tcancelled,\n\t\tdispose() {\n\t\t\tif (controller.signal.aborted) return\n\t\t\tcontroller.abort()\n\t\t\tcancel()\n\t\t\tconst errors: unknown[] = []\n\t\t\tfor (const cleanup of [...cleanups].reverse()) {\n\t\t\t\ttry {\n\t\t\t\t\tcleanup()\n\t\t\t\t} catch (error) {\n\t\t\t\t\terrors.push(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\tcleanups.clear()\n\t\t\tif (errors.length)\n\t\t\t\tthrow new AggregateError(errors, `spa: Astro store cleanup failed`)\n\t\t},\n\t}\n}\n\nexport type Application = Lifetime &\n\tAstroApplicationContext & { canResume: boolean }\nexport function applicationContext(): Application {\n\tconst life = lifetime()\n\tconst resources = new Map<unknown, unknown>()\n\tlife.onCleanup(() => {\n\t\tresources.clear()\n\t})\n\treturn {\n\t\t...life,\n\t\tcanResume: true,\n\t\tget<T>(key: unknown, initialize: () => T): T {\n\t\t\tlife.signal.throwIfAborted()\n\t\t\tif (!resources.has(key)) resources.set(key, initialize())\n\t\t\treturn resources.get(key) as T\n\t\t},\n\t}\n}\n\n/** Island resources and shared application resources have distinct owners. */\nexport function storeContext(\n\telement?: HTMLElement,\n\tshared?: ReturnType<typeof applicationContext>,\n): {\n\tcontext: AstroStoreContext\n\tdispose(): void\n\tcancelled: Promise<undefined>\n} {\n\tconst life = lifetime()\n\tconst application = shared ?? applicationContext()\n\tif (shared) life.onCleanup(shared.onCleanup(life.dispose))\n\telse life.onCleanup(application.dispose)\n\treturn {\n\t\tcontext: {\n\t\t\telement,\n\t\t\tsignal: life.signal,\n\t\t\tonCleanup: life.onCleanup,\n\t\t\tapplication,\n\t\t},\n\t\tdispose: life.dispose,\n\t\tcancelled: life.cancelled,\n\t}\n}\n\nexport function failPreparation(error: unknown, dispose: () => void): never {\n\ttry {\n\t\tdispose()\n\t} catch (cleanup) {\n\t\tthrow new AggregateError([error, cleanup])\n\t}\n\tthrow error\n}\n"],"mappings":";AAYA,SAAS,WAAqB;CAC7B,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,2BAAW,IAAI,IAAgB;CACrC,IAAI;CACJ,MAAM,YAAY,IAAI,SAAoB,YAAY;EACrD,eAAe;GACd,QAAQ,KAAA,CAAS;EAClB;CACD,CAAC;CACD,OAAO;EACN,QAAQ,WAAW;EACnB,UAAU,SAAS;GAClB,IAAI,WAAW,OAAO,SAAS,QAAQ;QAClC,SAAS,IAAI,OAAO;GACzB,aAAa;IACZ,SAAS,OAAO,OAAO;GACxB;EACD;EACA;EACA,UAAU;GACT,IAAI,WAAW,OAAO,SAAS;GAC/B,WAAW,MAAM;GACjB,OAAO;GACP,MAAM,SAAoB,CAAC;GAC3B,KAAK,MAAM,WAAW,CAAC,GAAG,QAAQ,CAAC,CAAC,QAAQ,GAC3C,IAAI;IACH,QAAQ;GACT,SAAS,OAAO;IACf,OAAO,KAAK,KAAK;GAClB;GAED,SAAS,MAAM;GACf,IAAI,OAAO,QACV,MAAM,IAAI,eAAe,QAAQ,iCAAiC;EACpE;CACD;AACD;AAIA,SAAgB,qBAAkC;CACjD,MAAM,OAAO,SAAS;CACtB,MAAM,4BAAY,IAAI,IAAsB;CAC5C,KAAK,gBAAgB;EACpB,UAAU,MAAM;CACjB,CAAC;CACD,OAAO;EACN,GAAG;EACH,WAAW;EACX,IAAO,KAAc,YAAwB;GAC5C,KAAK,OAAO,eAAe;GAC3B,IAAI,CAAC,UAAU,IAAI,GAAG,GAAG,UAAU,IAAI,KAAK,WAAW,CAAC;GACxD,OAAO,UAAU,IAAI,GAAG;EACzB;CACD;AACD;;AAGA,SAAgB,aACf,SACA,QAKC;CACD,MAAM,OAAO,SAAS;CACtB,MAAM,cAAc,UAAU,mBAAmB;CACjD,IAAI,QAAQ,KAAK,UAAU,OAAO,UAAU,KAAK,OAAO,CAAC;MACpD,KAAK,UAAU,YAAY,OAAO;CACvC,OAAO;EACN,SAAS;GACR;GACA,QAAQ,KAAK;GACb,WAAW,KAAK;GAChB;EACD;EACA,SAAS,KAAK;EACd,WAAW,KAAK;CACjB;AACD;AAEA,SAAgB,gBAAgB,OAAgB,SAA4B;CAC3E,IAAI;EACH,QAAQ;CACT,SAAS,SAAS;EACjB,MAAM,IAAI,eAAe,CAAC,OAAO,OAAO,CAAC;CAC1C;CACA,MAAM;AACP"}
@@ -0,0 +1,49 @@
1
+ import { n as failPreparation } from "./astro-context-OdlexHR4.js";
2
+ import { t as requestApplication } from "./astro-request-DRKvDjsO.js";
3
+ // src/astro-middleware.ts
4
+ /** Keep request resources alive until the streamed response is finished. */
5
+ const onRequest = async ({ request }, next) => {
6
+ const { application } = requestApplication(request);
7
+ try {
8
+ const response = await next();
9
+ if (!response.body) {
10
+ application.dispose();
11
+ return response;
12
+ }
13
+ const reader = response.body.getReader();
14
+ const body = new ReadableStream({
15
+ async pull(controller) {
16
+ try {
17
+ const result = await reader.read();
18
+ if (result.done) {
19
+ application.dispose();
20
+ controller.close();
21
+ } else controller.enqueue(result.value);
22
+ } catch (error) {
23
+ try {
24
+ failPreparation(error, application.dispose);
25
+ } catch (failure) {
26
+ controller.error(failure);
27
+ }
28
+ }
29
+ },
30
+ async cancel(reason) {
31
+ try {
32
+ await reader.cancel(reason);
33
+ } finally {
34
+ application.dispose();
35
+ }
36
+ }
37
+ });
38
+ return new Response(body, {
39
+ status: response.status,
40
+ statusText: response.statusText,
41
+ headers: response.headers
42
+ });
43
+ } catch (error) {
44
+ return failPreparation(error, application.dispose);
45
+ }
46
+ };
47
+ export { onRequest };
48
+
49
+ //# sourceMappingURL=astro-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-middleware.js","names":[],"sources":["../../src/astro-middleware.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"astro\"\n\nimport { failPreparation } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\n\n/** Keep request resources alive until the streamed response is finished. */\nexport const onRequest: MiddlewareHandler = async ({ request }, next) => {\n\tconst { application } = requestApplication(request)\n\ttry {\n\t\tconst response = await next()\n\t\tif (!response.body) {\n\t\t\tapplication.dispose()\n\t\t\treturn response\n\t\t}\n\t\tconst reader = response.body.getReader()\n\t\tconst body = new ReadableStream<Uint8Array>({\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await reader.read()\n\t\t\t\t\tif (result.done) {\n\t\t\t\t\t\tapplication.dispose()\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t} else controller.enqueue(result.value)\n\t\t\t\t} catch (error) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfailPreparation(error, application.dispose)\n\t\t\t\t\t} catch (failure) {\n\t\t\t\t\t\tcontroller.error(failure)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync cancel(reason) {\n\t\t\t\ttry {\n\t\t\t\t\tawait reader.cancel(reason)\n\t\t\t\t} finally {\n\t\t\t\t\tapplication.dispose()\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t\treturn new Response(body, {\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t})\n\t} catch (error) {\n\t\treturn failPreparation(error, application.dispose)\n\t}\n}\n"],"mappings":";;;;AAMA,MAAa,YAA+B,OAAO,EAAE,WAAW,SAAS;CACxE,MAAM,EAAE,gBAAgB,mBAAmB,OAAO;CAClD,IAAI;EACH,MAAM,WAAW,MAAM,KAAK;EAC5B,IAAI,CAAC,SAAS,MAAM;GACnB,YAAY,QAAQ;GACpB,OAAO;EACR;EACA,MAAM,SAAS,SAAS,KAAK,UAAU;EACvC,MAAM,OAAO,IAAI,eAA2B;GAC3C,MAAM,KAAK,YAAY;IACtB,IAAI;KACH,MAAM,SAAS,MAAM,OAAO,KAAK;KACjC,IAAI,OAAO,MAAM;MAChB,YAAY,QAAQ;MACpB,WAAW,MAAM;KAClB,OAAO,WAAW,QAAQ,OAAO,KAAK;IACvC,SAAS,OAAO;KACf,IAAI;MACH,gBAAgB,OAAO,YAAY,OAAO;KAC3C,SAAS,SAAS;MACjB,WAAW,MAAM,OAAO;KACzB;IACD;GACD;GACA,MAAM,OAAO,QAAQ;IACpB,IAAI;KACH,MAAM,OAAO,OAAO,MAAM;IAC3B,UAAU;KACT,YAAY,QAAQ;IACrB;GACD;EACD,CAAC;EACD,OAAO,IAAI,SAAS,MAAM;GACzB,QAAQ,SAAS;GACjB,YAAY,SAAS;GACrB,SAAS,SAAS;EACnB,CAAC;CACF,SAAS,OAAO;EACf,OAAO,gBAAgB,OAAO,YAAY,OAAO;CAClD;AACD"}