@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,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;G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} 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,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,234 @@
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
+ let passes = 0;
89
+ while (root._queue.size || root._mounts.length) {
90
+ if (++passes > 100) throw new Error(`spa: update loop`);
91
+ for (const run of [...root._queue]) if (root._queue.delete(run)) run();
92
+ for (const run of root._mounts.splice(0)) run();
93
+ }
94
+ } catch (error) {
95
+ fail(root, error);
96
+ }
97
+ };
98
+ return root;
99
+ }
100
+ /** Return the atom.io store selected by the current root. */
101
+ function useStore() {
102
+ return owner._root._store;
103
+ }
104
+ function onCleanup(cleanup) {
105
+ owner._cleanups.add(cleanup);
106
+ }
107
+ function onMount(run) {
108
+ const scope = owner;
109
+ scope._root._mounts?.push(() => {
110
+ if (!scope._dead) within(scope, () => {
111
+ untrack(run);
112
+ });
113
+ });
114
+ }
115
+ function useId() {
116
+ const root = owner._root;
117
+ return `${root._prefix}-${root._id++}`;
118
+ }
119
+ function observe(scope, read, apply) {
120
+ const subscriptions = /* @__PURE__ */ new Map();
121
+ const run = () => {
122
+ if (scope._dead) return;
123
+ const used = /* @__PURE__ */ new Set();
124
+ const previous = tracking;
125
+ tracking = (subscribe) => {
126
+ used.add(subscribe);
127
+ if (!subscriptions.has(subscribe)) subscriptions.set(subscribe, subscribe(() => {
128
+ enqueue(scope, run);
129
+ }));
130
+ };
131
+ let value;
132
+ try {
133
+ value = within(scope, read);
134
+ } finally {
135
+ tracking = previous;
136
+ for (const [subscribe, unsubscribe] of subscriptions) if (!used.has(subscribe)) {
137
+ unsubscribe();
138
+ subscriptions.delete(subscribe);
139
+ }
140
+ }
141
+ untrack(() => {
142
+ apply(value);
143
+ });
144
+ };
145
+ scope._updates.push(run);
146
+ scope._cleanups.add(() => {
147
+ scope._root._queue.delete(run);
148
+ for (const unsubscribe of subscriptions.values()) unsubscribe();
149
+ });
150
+ run();
151
+ }
152
+ /** Resolve a fixed family key in the current owner's store. */
153
+ function resolveStateToken(token, key) {
154
+ const store = owner._root._store;
155
+ return token.type.endsWith(`_family`) ? findInStore(store, token, key) : token;
156
+ }
157
+ function useValue(token, key) {
158
+ token = resolveStateToken(token, key);
159
+ const store = owner._root._store;
160
+ const subscribe = (notify) => subscribeToState(store, token, `spa:${serial++}`, notify);
161
+ return () => {
162
+ const value = getFromStore(store, token);
163
+ tracking?.(subscribe);
164
+ return value;
165
+ };
166
+ }
167
+ function useSetter(token, key) {
168
+ token = resolveStateToken(token, key);
169
+ const store = owner._root._store;
170
+ return (value) => {
171
+ setIntoStore(store, token, value);
172
+ };
173
+ }
174
+ function useTransaction(token) {
175
+ return actUponStore(owner._root._store, token, `spa:${serial++}`);
176
+ }
177
+ const refs = /* @__PURE__ */ new WeakMap();
178
+ function useRef(token, key) {
179
+ token = resolveStateToken(token, key);
180
+ const store = owner._root._store;
181
+ const owners = refs.get(store) ?? /* @__PURE__ */ new Map();
182
+ refs.set(store, owners);
183
+ const identity = {};
184
+ let held = null;
185
+ return (element) => {
186
+ if (element) {
187
+ held = element;
188
+ owners.set(token.key, identity);
189
+ setIntoStore(store, token, element);
190
+ } else if (owners.get(token.key) === identity) {
191
+ owners.delete(token.key);
192
+ if (getFromStore(store, token) === held) setIntoStore(store, token, null);
193
+ held = null;
194
+ }
195
+ };
196
+ }
197
+ function useTimeline(token, key) {
198
+ const store = owner._root._store;
199
+ if (token.type === `timeline_family`) token = findTimelineInStore(store, token, key);
200
+ const subscribe = (notify) => subscribeToTimeline(store, token, `spa:${serial++}`, notify);
201
+ const controls = {
202
+ undo: () => {
203
+ timeTravel(store, `undo`, token);
204
+ },
205
+ redo: () => {
206
+ timeTravel(store, `redo`, token);
207
+ },
208
+ clear: () => {
209
+ clearTimelineInStore(store, token);
210
+ }
211
+ };
212
+ return () => {
213
+ const value = {
214
+ ...inspectTimelineInStore(store, token),
215
+ ...controls
216
+ };
217
+ tracking?.(subscribe);
218
+ for (const direction of [`undo`, `redo`]) {
219
+ const group = getTimelineTransactionAtHead(store.timelines.get(token.key), direction);
220
+ if (group) value[`${direction}Transaction`] = () => timeTravelTransactionGroupInStore(store, direction, group);
221
+ }
222
+ return value;
223
+ };
224
+ }
225
+ function plain(value) {
226
+ if (typeof value === `function`) return plain(value());
227
+ if (Array.isArray(value)) return value.map(plain).join(``);
228
+ if (value == null || typeof value === `boolean`) return ``;
229
+ if (typeof value === `object`) throw new Error(`spa: text required`);
230
+ return String(value);
231
+ }
232
+ 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 };
233
+
234
+ //# sourceMappingURL=core-DB3sQz4h.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-DB3sQz4h.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,SAAgB,YAAY,QAAuB;CAClD,MAAM,QAAe;EACpB,OAAO,QAAQ;EACf,SAAS;EACT,2BAAW,IAAI,IAAI;EACnB,UAAU,CAAC;EACX,OAAO;CACR;C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AAM,oBAAoB;CAErC,OAAO,OAAO,KAAK;AACpB"}
@@ -0,0 +1,194 @@
1
+ import { a as invalidate, b as within, f as untrack, i as fail, n as createScope, o as observe, r as dispose, t as createRoot, u as plain } from "./core-DB3sQz4h.js";
2
+ import { Fragment, merge } from "./jsx-runtime.js";
3
+ // src/dom.ts
4
+ const HTML = `http://www.w3.org/1999/xhtml`;
5
+ const SVG = `http://www.w3.org/2000/svg`;
6
+ function take(node, parent, before, owner, cursor) {
7
+ if (cursor && !(node.nodeType === 3 && !node.nodeValue && cursor.node?.nodeType !== 3)) {
8
+ const found = cursor.node;
9
+ if (!found || found.nodeType !== node.nodeType || found.nodeName !== node.nodeName || found.namespaceURI !== node.namespaceURI || node.nodeType !== 1 && found.nodeValue !== node.nodeValue) throw new Error(`spa: hydration mismatch`);
10
+ node = found;
11
+ cursor.node = found.nextSibling;
12
+ } else parent.insertBefore(node, cursor ? cursor.node : before);
13
+ owner._cleanups.add(() => {
14
+ node.remove();
15
+ });
16
+ return node;
17
+ }
18
+ function comment(value, parent, before, owner, cursor) {
19
+ return take(parent.ownerDocument.createComment(value), parent, before, owner, cursor);
20
+ }
21
+ function property(element, key, value, previous) {
22
+ if (/^(key|children|ref)$/.test(key)) return;
23
+ if (key === `innerHTML` && element.localName === `astro-slot`) return;
24
+ if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
25
+ if (key.startsWith(`on`)) {
26
+ const capture = /(?<!Pointer)Capture$/.test(key);
27
+ const event = key.slice(2, capture ? -7 : void 0).toLowerCase().replace(`doubleclick`, `dblclick`);
28
+ if (previous) element.removeEventListener(event, previous, capture);
29
+ if (value != null) {
30
+ if (typeof value !== `function`) throw new Error(`spa: event handler`);
31
+ element.addEventListener(event, value, capture);
32
+ }
33
+ return;
34
+ }
35
+ if (key === `className`) key = `class`;
36
+ if (key === `htmlFor`) key = `for`;
37
+ if (key === `style` && value != null && typeof value !== `string`) throw new Error(`spa: CSS string required`);
38
+ if (element.namespaceURI === HTML && key in element && !/^(style|form|list)$/.test(key)) {
39
+ const target = element;
40
+ target[key] = value ?? (typeof target[key] === `boolean` ? false : ``);
41
+ } else if (value == null || value === false && !/^(aria-|data-)/.test(key)) element.removeAttribute(key);
42
+ else element.setAttribute(key, value === true && !/^(aria-|data-)/.test(key) ? `` : String(value));
43
+ }
44
+ function mount(value, parent, before, owner, namespace, cursor, source = () => value) {
45
+ if (typeof value === `function`) {
46
+ comment(`{`, parent, before, owner, cursor);
47
+ let end = null;
48
+ let records = /* @__PURE__ */ new Map();
49
+ let initial = cursor;
50
+ observe(owner, () => source()(), (next) => {
51
+ const values = [next].flat(Infinity);
52
+ const kept = /* @__PURE__ */ new Map();
53
+ const focus = parent.ownerDocument.activeElement;
54
+ for (let index = 0; index < values.length; index++) {
55
+ const child = values[index];
56
+ const vnode = child;
57
+ const explicit = vnode?.props?.[`key`];
58
+ const key = explicit == null ? index : String(explicit);
59
+ if (kept.has(key)) throw new Error(`spa: duplicate key`);
60
+ let record = records.get(key);
61
+ if (record && (typeof record._value !== typeof child || record._value?.type !== vnode?.type)) {
62
+ dispose(record._scope);
63
+ record = void 0;
64
+ }
65
+ if (!record) {
66
+ const childOwner = createScope(owner);
67
+ record = {
68
+ _value: child,
69
+ _scope: childOwner,
70
+ _start: comment(`[`, parent, end ?? before, childOwner, initial),
71
+ _end: null
72
+ };
73
+ const held = record;
74
+ mount(child, parent, end ?? before, childOwner, namespace, initial, () => held._value);
75
+ record._end = comment(`]`, parent, end ?? before, childOwner, initial);
76
+ } else {
77
+ record._value = child;
78
+ invalidate(record._scope);
79
+ }
80
+ kept.set(key, record);
81
+ }
82
+ for (const [key, record] of records) if (!kept.has(key)) dispose(record._scope);
83
+ if (!initial) {
84
+ let at = end ?? before;
85
+ for (const record of [...kept.values()].reverse()) {
86
+ if (record._end.nextSibling !== at) {
87
+ const range = parent.ownerDocument.createRange();
88
+ range.setStartBefore(record._start);
89
+ range.setEndAfter(record._end);
90
+ parent.insertBefore(range.extractContents(), at);
91
+ }
92
+ at = record._start;
93
+ }
94
+ if (focus?.isConnected && focus !== parent.ownerDocument.activeElement) focus.focus({ preventScroll: true });
95
+ }
96
+ initial = void 0;
97
+ records = kept;
98
+ });
99
+ end = comment(`}`, parent, before, owner, cursor);
100
+ return;
101
+ }
102
+ if (Array.isArray(value)) {
103
+ for (const child of value) mount(child, parent, before, owner, namespace, cursor);
104
+ return;
105
+ }
106
+ if (value == null || typeof value === `boolean`) return;
107
+ if (typeof value !== `object`) {
108
+ comment(`t`, parent, before, owner, cursor);
109
+ const text = take(parent.ownerDocument.createTextNode(String(value)), parent, before, owner, cursor);
110
+ observe(owner, source, (next) => {
111
+ const data = String(next);
112
+ if (text.nodeValue !== data) text.nodeValue = data;
113
+ });
114
+ return;
115
+ }
116
+ if (!(`type` in value) || !(`props` in value)) throw new Error(`spa: invalid child`);
117
+ const vnode = value;
118
+ const props = merge(() => source().props);
119
+ if (!vnode.type || vnode.type === Fragment) {
120
+ mount(() => props[`children`], parent, before, owner, namespace, cursor);
121
+ return;
122
+ }
123
+ if (typeof vnode.type === `function`) {
124
+ const childOwner = createScope(owner);
125
+ mount(within(childOwner, () => untrack(() => vnode.type(props))), parent, before, childOwner, namespace, cursor);
126
+ return;
127
+ }
128
+ const ns = vnode.type === `svg` ? SVG : namespace;
129
+ const element = take(parent.ownerDocument.createElementNS(ns, vnode.type), parent, before, owner, cursor);
130
+ if (vnode.type === `astro-slot`) {
131
+ if (!cursor) element.innerHTML = props[`innerHTML`] ?? ``;
132
+ } else if (ns === HTML && /^(textarea|title|style|script)$/.test(vnode.type)) observe(owner, () => plain(vnode.type === `textarea` ? props[`value`] ?? props[`children`] : props[`children`]), (text) => {
133
+ if (element.textContent !== text) element.textContent = text;
134
+ });
135
+ else {
136
+ const children = cursor ? { node: element.firstChild } : void 0;
137
+ if (!/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(vnode.type) || ns !== HTML) mount(() => props[`children`], element, null, owner, vnode.type === `foreignObject` ? HTML : ns, children);
138
+ if (children?.node) throw new Error(`spa: hydration mismatch`);
139
+ }
140
+ let previous = {};
141
+ owner._cleanups.add(() => {
142
+ for (const key in previous) if (key.startsWith(`on`)) property(element, key, null, previous[key]);
143
+ });
144
+ observe(owner, () => ({ ...props }), (next) => {
145
+ for (const key in {
146
+ ...previous,
147
+ ...next
148
+ }) if (!Object.is(previous[key], next[key]) || typeof next[key] === `object`) {
149
+ property(element, key, next[key], previous[key]);
150
+ previous[key] = next[key];
151
+ }
152
+ previous = next;
153
+ });
154
+ const ref = untrack(() => props[`ref`]);
155
+ if (ref) owner._root._mounts.unshift(() => {
156
+ if (!owner._dead) {
157
+ owner._cleanups.add(() => ref(null));
158
+ ref(element);
159
+ }
160
+ });
161
+ }
162
+ function start(setup, host, options, hydrating) {
163
+ const cursor = hydrating ? { node: host.firstChild } : void 0;
164
+ const prefix = cursor?.node?.nodeValue?.slice(2);
165
+ if (hydrating && (prefix === void 0 || options.idPrefix !== void 0 && prefix !== options.idPrefix)) throw new Error(`spa: hydration mismatch`);
166
+ const root = createRoot(options);
167
+ if (prefix !== void 0) root._prefix = prefix;
168
+ try {
169
+ comment(`w:${root._prefix}`, host, null, root, cursor);
170
+ within(root, () => {
171
+ mount(untrack(setup), host, null, root, host.namespaceURI === SVG ? SVG : HTML, cursor);
172
+ });
173
+ comment(`/w`, host, null, root, cursor);
174
+ if (cursor?.node) throw new Error(`spa: hydration mismatch`);
175
+ root.flush();
176
+ } catch (error) {
177
+ fail(root, error);
178
+ }
179
+ return {
180
+ dispose: () => {
181
+ dispose(root);
182
+ },
183
+ flush: root.flush
184
+ };
185
+ }
186
+ function render(setup, host, options = {}) {
187
+ return start(setup, host, options, false);
188
+ }
189
+ function hydrate(setup, host, options = {}) {
190
+ return start(setup, host, options, true);
191
+ }
192
+ export { render as n, hydrate as t };
193
+
194
+ //# sourceMappingURL=dom-D9cY6l1R.js.map