@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,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,9 @@
1
+ import { a as Island } from "./astro-shared-DkZaqX7L.js";
2
+ type Props = Record<string, any>;
3
+ type Slots = Record<string, string>;
4
+ type Hydrator = (component: Island, props: Props, slots: Slots, metadata: {
5
+ client: string;
6
+ }) => Promise<void>;
7
+ declare function _default(element: HTMLElement): Hydrator;
8
+ export { _default as default };
9
+ //# sourceMappingURL=astro-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-client.d.ts","names":[],"sources":["../src/astro-client.ts"],"mappings":";KAiBK,QAAQ;KACR,QAAQ;KACR,YACJ,WAAW,QACX,OAAO,OACP,OAAO,OACP;EAAY;MACR;iBAcW,SAAA,SAAS,cAAc"}
@@ -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-Dvqm7w2y.js";
5
+ import { n as render, t as hydrate } from "./dom-BR9o9wZW.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;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,WAAW;EACf,IAAI;GACH,MAAM,QAAQ,MAAM,QAAQ,KAAK,CAChC,YACC,WACA,OACA,SAAS,SACT,SAAS,SAAS,QAAQ,KAAA,CAC3B,GACA,SAAS,SACV,CAAC;GACD,IAAI,SAAS,QAAQ,OAAO,SAAS;GACrC,WAAW;GACX,MAAM,UACL,WAAW,UACX,aAAa,KAAA,KACb,aAAa,cAAc;GAE5B,MAAM,WAAW,QAAQ;GACzB,IAAI,UAAU,aAAa,KAAK,SAAS,cAAc,aACtD,SAAS,OAAO;GACjB,IAAI,SAAS,OAAO,IAAI,KAAM;GAC9B,IAAI,CAAC,QAAQ;IACZ,SAAS,wBAA8C,OAAQ;KAC9D,KAAK;KACL,SAAS;MAAE,OAAO,CAAC;MAAG,OAAO,CAAC;KAAE;IACjC,CAAC;IACD,OAAO,IAAI,OAAQ,MAAM;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,4 @@
1
+ import { MiddlewareHandler } from "astro";
2
+ /** Keep request resources alive until the streamed response is finished. */
3
+ export declare const onRequest: MiddlewareHandler;
4
+ //# sourceMappingURL=astro-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-middleware.d.ts","names":[],"sources":["../src/astro-middleware.ts"],"mappings":";;qBAMa,WAAW"}
@@ -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"}
@@ -0,0 +1,70 @@
1
+ import { t as applicationContext } from "./astro-context-OdlexHR4.js";
2
+ import { IMPLICIT, Store } from "atom.io/internal";
3
+ // src/astro-request.ts
4
+ const requests = /* @__PURE__ */ new WeakMap();
5
+ function createRequest() {
6
+ const application = applicationContext();
7
+ let store;
8
+ return {
9
+ application,
10
+ get store() {
11
+ application.signal.throwIfAborted();
12
+ if (!store) {
13
+ store = new Store({
14
+ name: `spa-request`,
15
+ lifespan: `ephemeral`,
16
+ isProduction: true
17
+ }, IMPLICIT.STORE);
18
+ const selected = store;
19
+ application.onCleanup(() => {
20
+ const errors = [];
21
+ for (const state of selected.atoms.values()) try {
22
+ state.cleanup?.();
23
+ } catch (error) {
24
+ errors.push(error);
25
+ }
26
+ for (const resource of selected.miscResources.values()) try {
27
+ resource[Symbol.dispose]();
28
+ } catch (error) {
29
+ errors.push(error);
30
+ }
31
+ if (errors.length) throw new AggregateError(errors, `spa: request cleanup failed`);
32
+ });
33
+ }
34
+ syncDefinitions(store);
35
+ return store;
36
+ }
37
+ };
38
+ }
39
+ function requestApplication(request) {
40
+ let app = requests.get(request);
41
+ if (!app) {
42
+ app = createRequest();
43
+ requests.set(request, app);
44
+ const dispose = () => {
45
+ app.application.dispose();
46
+ };
47
+ request.signal.addEventListener(`abort`, dispose, { once: true });
48
+ app.application.onCleanup(() => {
49
+ request.signal.removeEventListener(`abort`, dispose);
50
+ });
51
+ if (request.signal.aborted) dispose();
52
+ }
53
+ return app;
54
+ }
55
+ /** Install definitions imported after an earlier island started this request. */
56
+ function syncDefinitions(store) {
57
+ const source = IMPLICIT.STORE;
58
+ for (const field of [
59
+ `families`,
60
+ `atoms`,
61
+ `readonlySelectors`,
62
+ `writableSelectors`,
63
+ `transactions`,
64
+ `timelineFamilies`,
65
+ `timelines`
66
+ ]) for (const [key, resource] of source[field]) if (!store[field].has(key)) resource.install(store);
67
+ }
68
+ export { requestApplication as t };
69
+
70
+ //# sourceMappingURL=astro-request-DRKvDjsO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-request-DRKvDjsO.js","names":[],"sources":["../src/astro-request.ts"],"sourcesContent":["import type { RootStore } from \"atom.io/internal\"\nimport { IMPLICIT, Store } from \"atom.io/internal\"\n\nimport { applicationContext } from \"./astro-context.ts\"\n\nconst requests = new WeakMap<Request, ReturnType<typeof createRequest>>()\nfunction createRequest() {\n\tconst application = applicationContext()\n\tlet store: RootStore | undefined\n\treturn {\n\t\tapplication,\n\t\tget store(): RootStore {\n\t\t\tapplication.signal.throwIfAborted()\n\t\t\tif (!store) {\n\t\t\t\tstore = new Store(\n\t\t\t\t\t{ name: `spa-request`, lifespan: `ephemeral`, isProduction: true },\n\t\t\t\t\tIMPLICIT.STORE,\n\t\t\t\t) as RootStore\n\t\t\t\tconst selected = store\n\t\t\t\tapplication.onCleanup(() => {\n\t\t\t\t\tconst errors: unknown[] = []\n\t\t\t\t\tfor (const state of selected.atoms.values()) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tstate.cleanup?.()\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const resource of selected.miscResources.values()) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tresource[Symbol.dispose]()\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (errors.length)\n\t\t\t\t\t\tthrow new AggregateError(errors, `spa: request cleanup failed`)\n\t\t\t\t})\n\t\t\t}\n\t\t\tsyncDefinitions(store)\n\t\t\treturn store\n\t\t},\n\t}\n}\nexport function requestApplication(\n\trequest: Request,\n): ReturnType<typeof createRequest> {\n\tlet app = requests.get(request)\n\tif (!app) {\n\t\tapp = createRequest()\n\t\trequests.set(request, app)\n\t\tconst dispose = () => {\n\t\t\tapp!.application.dispose()\n\t\t}\n\t\trequest.signal.addEventListener(`abort`, dispose, { once: true })\n\t\tapp.application.onCleanup(() => {\n\t\t\trequest.signal.removeEventListener(`abort`, dispose)\n\t\t})\n\t\tif (request.signal.aborted) dispose()\n\t}\n\treturn app\n}\n/** Install definitions imported after an earlier island started this request. */\nexport function syncDefinitions(store: RootStore): void {\n\tconst source = IMPLICIT.STORE\n\tfor (const field of [\n\t\t`families`,\n\t\t`atoms`,\n\t\t`readonlySelectors`,\n\t\t`writableSelectors`,\n\t\t`transactions`,\n\t\t`timelineFamilies`,\n\t\t`timelines`,\n\t] as const) {\n\t\tfor (const [key, resource] of source[field]) {\n\t\t\tif (!store[field].has(key)) resource.install(store)\n\t\t}\n\t}\n}\n"],"mappings":";;;AAKA,MAAM,2BAAW,IAAI,QAAmD;AACxE,SAAS,gBAAgB;CACxB,MAAM,cAAc,mBAAmB;CACvC,IAAI;CACJ,OAAO;EACN;EACA,IAAI,QAAmB;GACtB,YAAY,OAAO,eAAe;GAClC,IAAI,CAAC,OAAO;IACX,QAAQ,IAAI,MACX;KAAE,MAAM;KAAe,UAAU;KAAa,cAAc;IAAK,GACjE,SAAS,KACV;IACA,MAAM,WAAW;IACjB,YAAY,gBAAgB;KAC3B,MAAM,SAAoB,CAAC;KAC3B,KAAK,MAAM,SAAS,SAAS,MAAM,OAAO,GACzC,IAAI;MACH,MAAM,UAAU;KACjB,SAAS,OAAO;MACf,OAAO,KAAK,KAAK;KAClB;KAED,KAAK,MAAM,YAAY,SAAS,cAAc,OAAO,GACpD,IAAI;MACH,SAAS,OAAO,QAAQ,CAAC;KAC1B,SAAS,OAAO;MACf,OAAO,KAAK,KAAK;KAClB;KAED,IAAI,OAAO,QACV,MAAM,IAAI,eAAe,QAAQ,6BAA6B;IAChE,CAAC;GACF;GACA,gBAAgB,KAAK;GACrB,OAAO;EACR;CACD;AACD;AACA,SAAgB,mBACf,SACmC;CACnC,IAAI,MAAM,SAAS,IAAI,OAAO;CAC9B,IAAI,CAAC,KAAK;EACT,MAAM,cAAc;EACpB,SAAS,IAAI,SAAS,GAAG;EACzB,MAAM,gBAAgB;GACrB,IAAK,YAAY,QAAQ;EAC1B;EACA,QAAQ,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EAChE,IAAI,YAAY,gBAAgB;GAC/B,QAAQ,OAAO,oBAAoB,SAAS,OAAO;EACpD,CAAC;EACD,IAAI,QAAQ,OAAO,SAAS,QAAQ;CACrC;CACA,OAAO;AACR;;AAEA,SAAgB,gBAAgB,OAAwB;CACvD,MAAM,SAAS,SAAS;CACxB,KAAK,MAAM,SAAS;EACnB;EACA;EACA;EACA;EACA;EACA;EACA;CACD,GACC,KAAK,MAAM,CAAC,KAAK,aAAa,OAAO,QACpC,IAAI,CAAC,MAAM,MAAM,CAAC,IAAI,GAAG,GAAG,SAAS,QAAQ,KAAK;AAGrD"}
@@ -0,0 +1,4 @@
1
+ import { NamedSSRLoadedRendererValue } from "astro";
2
+ declare const renderer: NamedSSRLoadedRendererValue;
3
+ export { renderer as default };
4
+ //# sourceMappingURL=astro-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-server.d.ts","names":[],"sources":["../src/astro-server.ts"],"mappings":";cASM,UAAU"}
@@ -0,0 +1,30 @@
1
+ import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
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";
5
+ // src/astro-server.ts
6
+ const renderer = {
7
+ name: `spa`,
8
+ async check(component) {
9
+ return component?.spa === true;
10
+ },
11
+ async renderToStaticMarkup(component, props, slots) {
12
+ const request = this.result?.request;
13
+ const shared = !component.createStore && !component.isolate && request ? requestApplication(request) : void 0;
14
+ const lifetime = storeContext(void 0, shared?.application);
15
+ try {
16
+ const store = await islandStore(component, props, lifetime.context, shared?.store);
17
+ return { html: renderToString(() => () => island(component, props, slots), {
18
+ store,
19
+ idPrefix: crypto.randomUUID()
20
+ }) };
21
+ } catch (error) {
22
+ failPreparation(error, lifetime.dispose);
23
+ } finally {
24
+ lifetime.dispose();
25
+ }
26
+ }
27
+ };
28
+ export { renderer as default };
29
+
30
+ //# sourceMappingURL=astro-server.js.map
@@ -0,0 +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}),\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;GAC7B,CAAC,EACF;EACD,SAAS,OAAO;GACf,gBAAgB,OAAO,SAAS,OAAO;EACxC,UAAU;GACT,SAAS,QAAQ;EAClB;CACD;AACD"}
@@ -0,0 +1,29 @@
1
+ import { jsx } from "./jsx-runtime.js";
2
+ import { IMPLICIT, Store } from "atom.io/internal";
3
+ // src/astro-shared.ts
4
+ async function islandStore(component, props, context, shared) {
5
+ const store = await (component.createStore?.(props, context) ?? shared ?? new Store({
6
+ name: `spa-island`,
7
+ lifespan: `ephemeral`,
8
+ isProduction: true
9
+ }, IMPLICIT.STORE));
10
+ context.signal.throwIfAborted();
11
+ await component.prepareStore?.(store, props, context);
12
+ context.signal.throwIfAborted();
13
+ return store;
14
+ }
15
+ function island(component, props, slots) {
16
+ const children = Object.fromEntries(Object.entries(slots).map(([name, html]) => [name, jsx(`astro-slot`, {
17
+ key: html,
18
+ name: name === `default` ? void 0 : name,
19
+ innerHTML: html
20
+ })]));
21
+ return jsx(component, {
22
+ ...props,
23
+ slots: children,
24
+ children: children[`default`]
25
+ });
26
+ }
27
+ export { islandStore as n, island as t };
28
+
29
+ //# sourceMappingURL=astro-shared-BT45auwR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-shared-BT45auwR.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 { Component, VNode } 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/** 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): 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 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): VNode {\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":";;;AAwCA,eAAsB,YACrB,WACA,OACA,SACA,QACqB;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,eAAe,OAAO,OAAO,OAAO;CACpD,QAAQ,OAAO,eAAe;CAC9B,OAAO;AACR;AACA,SAAgB,OACf,WACA,OACA,OACQ;CACR,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"}
@@ -0,0 +1,31 @@
1
+ import { r as Component } from "./core-BhiA9fFi.js";
2
+ import { RootStore } from "atom.io/internal";
3
+ interface AstroApplicationContext {
4
+ /** Whether the application still represents its initial server snapshot. */
5
+ readonly canResume: boolean;
6
+ readonly signal: AbortSignal;
7
+ onCleanup(cleanup: () => void): void;
8
+ /** Initialize a resource once for this application lifetime. */
9
+ get<T>(key: unknown, initialize: () => T): T;
10
+ }
11
+ interface AstroStoreContext {
12
+ /** Shared across default islands; private for explicitly isolated islands. */
13
+ application: AstroApplicationContext;
14
+ /** The browser island host; undefined during server rendering. */
15
+ element: HTMLElement | undefined;
16
+ /** Aborted when preparation is cancelled or the island is released. */
17
+ signal: AbortSignal;
18
+ /** Release resources even if preparation or rendering fails. */
19
+ onCleanup(cleanup: () => void): void;
20
+ }
21
+ type AstroStoreFactory<P = Record<string, any>> = (props: P, context: AstroStoreContext) => RootStore | Promise<RootStore>;
22
+ type AstroStorePreparation<P = Record<string, any>> = (store: RootStore, props: P, context: AstroStoreContext) => void | Promise<void>;
23
+ type Island<P = any> = Component<P> & {
24
+ spa?: boolean;
25
+ /** Opt into a private island store instead of the shared application store. */
26
+ isolate?: boolean;
27
+ createStore?: AstroStoreFactory<P>;
28
+ prepareStore?: AstroStorePreparation<P>;
29
+ };
30
+ export { Island as a, AstroStorePreparation as i, AstroStoreContext as n, AstroStoreFactory as r, AstroApplicationContext as t };
31
+ //# sourceMappingURL=astro-shared-DkZaqX7L.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro-shared-DkZaqX7L.d.ts","names":[],"sources":["../src/astro-shared.ts"],"mappings":";;UAMiB;;WAEP;WACA,QAAQ;EACjB,UAAU;;EAEV,IAAI,GAAG,cAAc,kBAAkB,IAAI;;UAE3B;;EAEhB,aAAa;;EAEb,SAAS;;EAET,QAAQ;;EAER,UAAU;;KAEC,kBAAkB,IAAI,wBACjC,OAAO,GACP,SAAS,sBACL,YAAY,QAAQ;KACb,sBAAsB,IAAI,wBACrC,OAAO,WACP,OAAO,GACP,SAAS,6BACE;KACA,OAAO,WAAW,UAAU;EACvC;;EAEA;EACA,cAAc,kBAAkB;EAChC,eAAe,sBAAsB"}
@@ -0,0 +1,6 @@
1
+ import { SpaPluginOptions } from "./vite.js";
2
+ import { a as Island, i as AstroStorePreparation, n as AstroStoreContext, r as AstroStoreFactory, t as AstroApplicationContext } from "./astro-shared-DkZaqX7L.js";
3
+ import { AstroIntegration } from "astro";
4
+ export default function integration(options?: SpaPluginOptions): AstroIntegration;
5
+ export type { AstroApplicationContext, AstroStoreContext, AstroStoreFactory, AstroStorePreparation, Island };
6
+ //# sourceMappingURL=astro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.d.ts","names":[],"sources":["../src/astro.ts"],"mappings":";;;wBAawB,YACvB,UAAS,mBACP"}
package/dist/astro.js ADDED
@@ -0,0 +1,26 @@
1
+ import { t as spa } from "./vite-CQchIQ_-.js";
2
+ // src/astro.ts
3
+ function integration(options = {}) {
4
+ return {
5
+ name: `spa`,
6
+ hooks: { "astro:config:setup"({ addRenderer, addMiddleware, injectScript, updateConfig }) {
7
+ addMiddleware({
8
+ entrypoint: `@atom.io/spa/astro-middleware`,
9
+ order: `pre`
10
+ });
11
+ injectScript(`page`, `import { browserApplication } from '@atom.io/spa/astro-application'; browserApplication(document);`);
12
+ addRenderer({
13
+ name: `spa`,
14
+ clientEntrypoint: `@atom.io/spa/astro-client`,
15
+ serverEntrypoint: `@atom.io/spa/astro-server`
16
+ });
17
+ updateConfig({ vite: { plugins: [spa({
18
+ include: /\.spa\.[jt]sx$/,
19
+ ...options
20
+ })] } });
21
+ } }
22
+ };
23
+ }
24
+ export { integration as default };
25
+
26
+ //# sourceMappingURL=astro.js.map
@@ -0,0 +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"}
@@ -0,0 +1 @@
1
+ export * from './index.js'; export * from './jsx-runtime.js'
@@ -0,0 +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=[];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(e._dead)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={_store:t.store??e.STORE,_prefix:t.idPrefix??`w${g++}`,_id:0,...y(),_queue:new Set,_mounts:n?void 0:[]};return r._root=r,r.error=t.onError??(e=>{throw e}),r.flush=()=>{try{for(;r._queue.size||r._mounts.length;){for(let e of[...r._queue])r._queue.delete(e)&&e();for(let e of r._mounts.splice(0))e()}}catch(e){b(r,e)}},r}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(e._dead)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)}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})})}var U=`http://www.w3.org/1999/xhtml`,W=`http://www.w3.org/2000/svg`;function G(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 K(e,t,n,r,i){return G(t.ownerDocument.createComment(e),t,n,r,i)}function q(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===U&&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 J(e,t,n,r,i,a,o=()=>e){if(typeof e==`function`){K(`{`,t,n,r,a);let e=null,s=new Map,c=a;k(r,()=>o()(),a=>{let o=[a].flat(1/0),l=new Map,u=t.ownerDocument.activeElement;for(let a=0;a<o.length;a++){let u=o[a],d=u,f=d?.props?.key,p=f==null?a:String(f),m=s.get(p);if(m&&(typeof m._value!=typeof u||m._value?.type!==d?.type)&&(x(m._scope),m=void 0),m)m._value=u,S(m._scope);else{let a=y(r);m={_value:u,_scope:a,_start:K(`[`,t,e??n,a,c),_end:null};let o=m;J(u,t,e??n,a,i,c,()=>o._value),m._end=K(`]`,t,e??n,a,c)}l.set(p,m)}for(let[e,t]of s)l.has(e)||x(t._scope);if(!c){let r=e??n;for(let e of[...l.values()].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}u?.isConnected&&u!==t.ownerDocument.activeElement&&u.focus({preventScroll:!0})}c=void 0,s=l}),e=K(`}`,t,n,r,a);return}if(Array.isArray(e)){for(let o of e)J(o,t,n,r,i,a);return}if(e==null||typeof e==`boolean`)return;if(typeof e!=`object`){K(`t`,t,n,r,a);let i=G(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=H(()=>o().props);if(!s.type||s.type===R){J(()=>c.children,t,n,r,i,a);return}if(typeof s.type==`function`){let e=y(r);J(_(e,()=>v(()=>s.type(c))),t,n,e,i,a);return}let l=s.type===`svg`?W:i,u=G(t.ownerDocument.createElementNS(l,s.type),t,n,r,a);if(s.type===`astro-slot`)a||(u.innerHTML=c.innerHTML??``);else if(l===U&&/^(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===U||J(()=>c.children,u,null,r,s.type===`foreignObject`?U:l,e),e?.node)throw Error(void 0)}let d={};r._cleanups.add(()=>{for(let e in d)e.startsWith(`on`)&&q(u,e,null,d[e])}),k(r,()=>({...c}),e=>{for(let t in{...d,...e})Object.is(d[t],e[t])&&typeof e[t]!=`object`||(q(u,t,e[t],d[t]),d[t]=e[t]);d=e});let f=v(()=>c.ref);f&&r._root._mounts.unshift(()=>{r._dead||(r._cleanups.add(()=>f(null)),f(u))})}function Y(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(K(`w:${o._prefix}`,t,null,o,i),_(o,()=>{J(v(e),t,null,o,t.namespaceURI===W?W:U,i)}),K(`/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 X(e,t,n={}){return Y(e,t,n,!1)}function Z(e,t,n={}){return Y(e,t,n,!0)}function Q(...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{R as Fragment,Z as hydrate,z as jsx,V as jsxDEV,B as jsxs,H as merge,E as onCleanup,D as onMount,X as render,O as useId,Q as useLoadable,F as useRef,M as useSetter,T as useStore,I as useTimeline,N as useTransaction,j as useValue};