@atom.io/spa 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +201 -6
  2. package/README.mdx +62 -1
  3. package/dist/astro-application.d.ts +1 -1
  4. package/dist/astro-client.d.ts +1 -1
  5. package/dist/astro-client.js +6 -3
  6. package/dist/astro-client.js.map +1 -1
  7. package/dist/astro-server.js +2 -1
  8. package/dist/astro-server.js.map +1 -1
  9. package/dist/astro-shared-BT45auwR.js.map +1 -1
  10. package/dist/{astro-shared-DkZaqX7L.d.ts → astro-shared-DyzbUi6c.d.ts} +4 -2
  11. package/dist/astro-shared-DyzbUi6c.d.ts.map +1 -0
  12. package/dist/astro.d.ts +1 -1
  13. package/dist/astro.js +1 -1
  14. package/dist/{core-Dvqm7w2y.js → capabilities-BuZUQpiD.js} +64 -2
  15. package/dist/capabilities-BuZUQpiD.js.map +1 -0
  16. package/dist/{core-BhiA9fFi.d.ts → capabilities-yC9TsHDI.d.ts} +20 -2
  17. package/dist/capabilities-yC9TsHDI.d.ts.map +1 -0
  18. package/dist/client.min.js +1 -1
  19. package/dist/development/astro-client.js +6 -3
  20. package/dist/development/astro-client.js.map +1 -1
  21. package/dist/development/astro-server.js +2 -1
  22. package/dist/development/astro-server.js.map +1 -1
  23. package/dist/development/astro-shared-BT45auwR.js.map +1 -1
  24. package/dist/development/astro.js +1 -1
  25. package/dist/development/{core-DB3sQz4h.js → capabilities-DhOJmeoJ.js} +64 -2
  26. package/dist/development/capabilities-DhOJmeoJ.js.map +1 -0
  27. package/dist/development/{dom-D9cY6l1R.js → dom-BKc6V_Kz.js} +8 -3
  28. package/dist/development/dom-BKc6V_Kz.js.map +1 -0
  29. package/dist/development/index.js +3 -38
  30. package/dist/development/jsx-runtime.js.map +1 -1
  31. package/dist/development/konva.js +121 -0
  32. package/dist/development/konva.js.map +1 -0
  33. package/dist/development/motion.js +217 -0
  34. package/dist/development/motion.js.map +1 -0
  35. package/dist/development/renderer.js +177 -0
  36. package/dist/development/renderer.js.map +1 -0
  37. package/dist/development/server.js +3 -2
  38. package/dist/development/server.js.map +1 -1
  39. package/dist/development/src-Dh-d6w4y.js +38 -0
  40. package/dist/development/src-Dh-d6w4y.js.map +1 -0
  41. package/dist/development/three.js +438 -0
  42. package/dist/development/three.js.map +1 -0
  43. package/dist/development/vite-CSHoxzXU.js +240 -0
  44. package/dist/development/vite-CSHoxzXU.js.map +1 -0
  45. package/dist/development/vite.js +1 -1
  46. package/dist/{dom-BR9o9wZW.js → dom-B2rm8o2L.js} +8 -3
  47. package/dist/dom-B2rm8o2L.js.map +1 -0
  48. package/dist/index-BdwxmSKg.d.ts +24 -0
  49. package/dist/index-BdwxmSKg.d.ts.map +1 -0
  50. package/dist/index.d.ts +4 -24
  51. package/dist/index.js +3 -38
  52. package/dist/{jsx-runtime-BzGV18VO.d.ts → jsx-runtime-CZU7F8Qz.d.ts} +6 -4
  53. package/dist/jsx-runtime-CZU7F8Qz.d.ts.map +1 -0
  54. package/dist/jsx-runtime.d.ts +2 -2
  55. package/dist/jsx-runtime.js.map +1 -1
  56. package/dist/konva.d.ts +32 -0
  57. package/dist/konva.d.ts.map +1 -0
  58. package/dist/konva.js +121 -0
  59. package/dist/konva.js.map +1 -0
  60. package/dist/motion.d.ts +44 -0
  61. package/dist/motion.d.ts.map +1 -0
  62. package/dist/motion.js +217 -0
  63. package/dist/motion.js.map +1 -0
  64. package/dist/renderer.d.ts +24 -0
  65. package/dist/renderer.d.ts.map +1 -0
  66. package/dist/renderer.js +177 -0
  67. package/dist/renderer.js.map +1 -0
  68. package/dist/server.d.ts +1 -1
  69. package/dist/server.d.ts.map +1 -1
  70. package/dist/server.js +3 -2
  71. package/dist/server.js.map +1 -1
  72. package/dist/size.json +16 -16
  73. package/dist/src-BZxX4xbU.js +38 -0
  74. package/dist/src-BZxX4xbU.js.map +1 -0
  75. package/dist/three.d.ts +110 -0
  76. package/dist/three.d.ts.map +1 -0
  77. package/dist/three.js +438 -0
  78. package/dist/three.js.map +1 -0
  79. package/dist/vite-CSHoxzXU.js +240 -0
  80. package/dist/vite-CSHoxzXU.js.map +1 -0
  81. package/dist/vite.js +1 -1
  82. package/package.json +56 -11
  83. package/src/astro-client.ts +1 -0
  84. package/src/astro-server.ts +1 -0
  85. package/src/astro-shared.ts +3 -0
  86. package/src/capabilities.ts +88 -0
  87. package/src/compiler.ts +251 -178
  88. package/src/core.ts +11 -0
  89. package/src/dom.ts +4 -1
  90. package/src/index.ts +5 -0
  91. package/src/jsx-runtime.ts +4 -0
  92. package/src/jsx-types.d.ts +3 -1
  93. package/src/konva.ts +159 -0
  94. package/src/motion.ts +406 -0
  95. package/src/renderer.ts +241 -0
  96. package/src/server.ts +3 -0
  97. package/src/three-events.ts +330 -0
  98. package/src/three.ts +350 -0
  99. package/dist/astro-shared-DkZaqX7L.d.ts.map +0 -1
  100. package/dist/core-BhiA9fFi.d.ts.map +0 -1
  101. package/dist/core-Dvqm7w2y.js.map +0 -1
  102. package/dist/development/core-DB3sQz4h.js.map +0 -1
  103. package/dist/development/dom-D9cY6l1R.js.map +0 -1
  104. package/dist/development/index.js.map +0 -1
  105. package/dist/development/vite-CQchIQ_-.js +0 -126
  106. package/dist/development/vite-CQchIQ_-.js.map +0 -1
  107. package/dist/dom-BR9o9wZW.js.map +0 -1
  108. package/dist/index.d.ts.map +0 -1
  109. package/dist/index.js.map +0 -1
  110. package/dist/jsx-runtime-BzGV18VO.d.ts.map +0 -1
  111. package/dist/vite-CQchIQ_-.js +0 -126
  112. package/dist/vite-CQchIQ_-.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-Dvqm7w2y.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSetter,\n\tTimelineFamilyToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tViewOf,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tclearTimelineInStore,\n\tfindInStore,\n\tfindTimelineInStore,\n\tgetFromStore,\n\tgetTimelineTransactionAtHead,\n\tIMPLICIT,\n\tinspectTimelineInStore,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\ttimeTravel,\n\ttimeTravelTransactionGroupInStore,\n} from \"atom.io/internal\"\n\nexport type Cleanup = () => void\n// A callable interface permits the recursive Child union. A type alias does not.\n/* oxlint-disable typescript/prefer-function-type -- A callable interface is required for recursive Child. */\nexport interface Accessor<T> {\n\t(): T\n}\n/* oxlint-enable typescript/prefer-function-type */\nexport type Component<P = any> = (props: P) => Child\nexport interface VNode {\n\ttype: string | Component | null\n\tprops: Record<string, any>\n}\nexport type Child =\n\t| VNode\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| readonly Child[]\n\t| Accessor<Child>\nexport interface RootOptions {\n\tstore?: RootStore\n\tidPrefix?: string\n\tonError?: (error: unknown) => void\n}\nexport interface Scope {\n\t_root: Root\n\t_parent?: Scope | undefined\n\t_cleanups: Set<Cleanup | Scope>\n\t_updates: Cleanup[]\n\t_dead: boolean\n}\nexport interface Root extends Scope {\n\t_store: RootStore\n\t_prefix: string\n\t_id: number\n\t_queue: Set<Cleanup>\n\t_mounts: Cleanup[] | undefined\n\tflush: Cleanup\n\terror: (error: unknown) => void\n}\n\nexport let owner: Scope | undefined\ntype Subscribe = (notify: Cleanup) => Cleanup\nlet tracking: ((subscribe: Subscribe) => void) | undefined\nlet serial = 0\n\nexport function within<T>(scope: Scope, run: () => T): T {\n\tconst previous = owner\n\towner = scope\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\towner = previous\n\t}\n}\nexport function untrack<T>(run: () => T): T {\n\tconst previous = tracking\n\ttracking = undefined\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\ttracking = previous\n\t}\n}\nexport function createScope(parent?: Scope): Scope {\n\tconst child: Scope = {\n\t\t_root: parent?._root as Root,\n\t\t_parent: parent,\n\t\t_cleanups: new Set(),\n\t\t_updates: [],\n\t\t_dead: false,\n\t}\n\tparent?._cleanups.add(child)\n\treturn child\n}\nexport function fail(scope: Scope, error: unknown): never {\n\ttry {\n\t\tdispose(scope)\n\t} catch (cleanup) {\n\t\tthrow new AggregateError([error, cleanup])\n\t}\n\tthrow error\n}\nexport function dispose(scope: Scope): void {\n\tif (scope._dead) return\n\tscope._dead = true\n\tconst errors: unknown[] = []\n\tfor (const cleanup of [...scope._cleanups].reverse()) {\n\t\ttry {\n\t\t\ttypeof cleanup === `function` ? cleanup() : dispose(cleanup)\n\t\t} catch (error) {\n\t\t\terrors.push(error)\n\t\t}\n\t}\n\tscope._parent?._cleanups.delete(scope)\n\tscope._cleanups.clear()\n\tscope._updates.length = 0\n\tif (errors.length) throw new AggregateError(errors)\n}\nexport function invalidate(scope: Scope): void {\n\tfor (const run of scope._updates) enqueue(scope, run)\n\tfor (const child of scope._cleanups)\n\t\tif (typeof child !== `function`) invalidate(child)\n}\nfunction enqueue(scope: Scope, run: Cleanup): void {\n\tif (scope._dead) return\n\tconst root = scope._root\n\tif (!root._queue.size)\n\t\tqueueMicrotask(() => {\n\t\t\ttry {\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\troot.error(error)\n\t\t\t}\n\t\t})\n\troot._queue.add(run)\n}\nexport function createRoot(options: RootOptions = {}, server = false): Root {\n\tconst root = {\n\t\t_store: options.store ?? IMPLICIT.STORE,\n\t\t_prefix: options.idPrefix ?? `w${serial++}`,\n\t\t_id: 0,\n\t\t...createScope(),\n\t\t_queue: new Set(),\n\t\t_mounts: server ? undefined : [],\n\t} as unknown as Root\n\troot._root = root\n\troot.error =\n\t\toptions.onError ??\n\t\t((error) => {\n\t\t\tthrow error\n\t\t})\n\troot.flush = () => {\n\t\ttry {\n\t\t\tlet passes = 0\n\t\t\twhile (root._queue.size || root._mounts!.length) {\n\t\t\t\tif (import.meta.env.DEV && ++passes > 100)\n\t\t\t\t\tthrow new Error(`spa: update loop`)\n\t\t\t\tfor (const run of [...root._queue]) if (root._queue.delete(run)) run()\n\t\t\t\tfor (const run of root._mounts!.splice(0)) run()\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfail(root, error)\n\t\t}\n\t}\n\treturn root\n}\n/** Return the atom.io store selected by the current root. */\nexport function useStore(): RootStore {\n\treturn owner!._root._store\n}\nexport function onCleanup(cleanup: Cleanup): void {\n\towner!._cleanups.add(cleanup)\n}\nexport function onMount(run: Cleanup): void {\n\tconst scope = owner!\n\tscope._root._mounts?.push(() => {\n\t\tif (!scope._dead)\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(run)\n\t\t\t})\n\t})\n}\nexport function useId(): string {\n\tconst root = owner!._root\n\treturn `${root._prefix}-${root._id++}`\n}\n\nexport function observe<T>(\n\tscope: Scope,\n\tread: Accessor<T>,\n\tapply: (value: T) => void,\n): void {\n\tconst subscriptions = new Map<Subscribe, Cleanup>()\n\tconst run = () => {\n\t\tif (scope._dead) return\n\t\tconst used = new Set<Subscribe>()\n\t\tconst previous = tracking\n\t\ttracking = (subscribe) => {\n\t\t\tused.add(subscribe)\n\t\t\tif (!subscriptions.has(subscribe))\n\t\t\t\tsubscriptions.set(\n\t\t\t\t\tsubscribe,\n\t\t\t\t\tsubscribe(() => {\n\t\t\t\t\t\tenqueue(scope, run)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t}\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = within(scope, read)\n\t\t} finally {\n\t\t\ttracking = previous\n\t\t\tfor (const [subscribe, unsubscribe] of subscriptions)\n\t\t\t\tif (!used.has(subscribe)) {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tsubscriptions.delete(subscribe)\n\t\t\t\t}\n\t\t}\n\t\tuntrack(() => {\n\t\t\tapply(value)\n\t\t})\n\t}\n\tscope._updates.push(run)\n\tscope._cleanups.add(() => {\n\t\tscope._root._queue.delete(run)\n\t\tfor (const unsubscribe of subscriptions.values()) unsubscribe()\n\t})\n\trun()\n}\n\n/** Resolve a fixed family key in the current owner's store. */\nexport function resolveStateToken(token: any, key?: Canonical): any {\n\tconst store = owner!._root._store\n\treturn token.type.endsWith(`_family`) ? findInStore(store, token, key!) : token\n}\n\n/** Capture a token for this instance. Change the component key to change its token. */\nexport function useValue<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): Accessor<ViewOf<T | E>>\nexport function useValue<T, K extends Canonical, E = never>(\n\tfamily: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<ViewOf<T | E>>\nexport function useValue(token: any, key?: Canonical): Accessor<any> {\n\ttoken = resolveStateToken(token, key)\n\tconst store = owner!._root._store\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToState(store, token, `spa:${serial++}`, notify)\n\treturn () => {\n\t\tconst value = getFromStore(store, token)\n\t\ttracking?.(subscribe)\n\t\treturn value\n\t}\n}\nexport function useSetter<T>(\n\ttoken: WritableToken<T, any, any>,\n): (value: T | Setter<T>) => void\nexport function useSetter<T, K extends Canonical>(\n\tfamily: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): (value: T | Setter<T>) => void\nexport function useSetter(token: any, key?: Canonical): (value: any) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = owner!._root._store\n\treturn (value) => {\n\t\tsetIntoStore(store, token, value)\n\t}\n}\nexport function useTransaction<F extends (...args: any[]) => any>(\n\ttoken: TransactionToken<F>,\n): (...args: Parameters<F>) => ReturnType<F> {\n\treturn actUponStore(owner!._root._store, token, `spa:${serial++}`)\n}\n\nconst refs = new WeakMap<RootStore, Map<string, object>>()\nexport function useRef<E extends Element>(\n\ttoken: RegularAtomToken<E | null>,\n): (element: E | null) => void\nexport function useRef<E extends Element, K extends Canonical>(\n\tfamily: RegularAtomFamilyToken<E | null, K>,\n\tkey: NoInfer<K>,\n): (element: E | null) => void\nexport function useRef<E extends Element>(\n\ttoken: any,\n\tkey?: Canonical,\n): (element: E | null) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = owner!._root._store\n\tconst owners = refs.get(store) ?? new Map<string, object>()\n\trefs.set(store, owners)\n\tconst identity = {}\n\tlet held: E | null = null\n\treturn (element) => {\n\t\tif (element) {\n\t\t\theld = element\n\t\t\towners.set(token.key, identity)\n\t\t\tsetIntoStore(store, token, element)\n\t\t} else if (owners.get(token.key) === identity) {\n\t\t\towners.delete(token.key)\n\t\t\tif (getFromStore(store, token) === held) setIntoStore(store, token, null)\n\t\t\theld = null\n\t\t}\n\t}\n}\nexport interface TimelineValue {\n\tat: number\n\tlength: number\n\tundo(): void\n\tredo(): void\n\tclear(): void\n\tundoTransaction?: Cleanup\n\tredoTransaction?: Cleanup\n}\nexport function useTimeline<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n): Accessor<TimelineValue>\nexport function useTimeline<K extends Canonical, M extends TimelineManageable>(\n\tfamily: TimelineFamilyToken<K, M>,\n\tkey: NoInfer<K>,\n): Accessor<TimelineValue>\nexport function useTimeline(\n\ttoken: any,\n\tkey?: Canonical,\n): Accessor<TimelineValue> {\n\tconst store = owner!._root._store\n\tif (token.type === `timeline_family`)\n\t\ttoken = findTimelineInStore(store, token, key!)\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToTimeline(store, token, `spa:${serial++}`, notify)\n\tconst controls = {\n\t\tundo: () => {\n\t\t\ttimeTravel(store, `undo`, token)\n\t\t},\n\t\tredo: () => {\n\t\t\ttimeTravel(store, `redo`, token)\n\t\t},\n\t\tclear: () => {\n\t\t\tclearTimelineInStore(store, token)\n\t\t},\n\t}\n\treturn () => {\n\t\tconst value: TimelineValue = {\n\t\t\t...inspectTimelineInStore(store, token),\n\t\t\t...controls,\n\t\t}\n\t\ttracking?.(subscribe)\n\t\tfor (const direction of [`undo`, `redo`] as const) {\n\t\t\tconst group = getTimelineTransactionAtHead(\n\t\t\t\tstore.timelines.get(token.key)!,\n\t\t\t\tdirection,\n\t\t\t)\n\t\t\tif (group)\n\t\t\t\tvalue[`${direction}Transaction`] = () =>\n\t\t\t\t\ttimeTravelTransactionGroupInStore(store, direction, group)\n\t\t}\n\t\treturn value\n\t}\n}\n\nexport function plain(value: Child): string {\n\tif (typeof value === `function`) return plain(value())\n\tif (Array.isArray(value)) return value.map(plain).join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (import.meta.env.DEV && typeof value === `object`)\n\t\tthrow new Error(`spa: text required`)\n\t// oxlint-disable-next-line typescript/no-base-to-string -- Valid text children are primitives here; development rejects malformed object children.\n\treturn String(value)\n}\n"],"mappings":";;AA4EA,IAAW;AAEX,IAAI;AACJ,IAAI,SAAS;AAEb,SAAgB,OAAU,OAAc,KAAiB;CACxD,MAAM,WAAW;CACjB,QAAQ;CACR,IAAI;EACH,OAAO,IAAI;CACZ,UAAU;EACT,QAAQ;CACT;AACD;AACA,SAAgB,QAAW,KAAiB;CAC3C,MAAM,WAAW;CACjB,WAAW,KAAA;CACX,IAAI;EACH,OAAO,IAAI;CACZ,UAAU;EACT,WAAW;CACZ;AACD;AACA,SAAgB,YAAY,QAAuB;CAClD,MAAM,QAAe;EACpB,OAAO,QAAQ;EACf,SAAS;EACT,2BAAW,IAAI,IAAI;EACnB,UAAU,CAAC;EACX,OAAO;CACR;CACA,QAAQ,UAAU,IAAI,KAAK;CAC3B,OAAO;AACR;AACA,SAAgB,KAAK,OAAc,OAAuB;CACzD,IAAI;EACH,QAAQ,KAAK;CACd,SAAS,SAAS;EACjB,MAAM,IAAI,eAAe,CAAC,OAAO,OAAO,CAAC;CAC1C;CACA,MAAM;AACP;AACA,SAAgB,QAAQ,OAAoB;CAC3C,IAAI,MAAM,OAAO;CACjB,MAAM,QAAQ;CACd,MAAM,SAAoB,CAAC;CAC3B,KAAK,MAAM,WAAW,CAA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AClB,QAAQ,oBAAoB,OAAO,OAAO,GAAI;CAC/C,MAAM,aAAwB,WAC7B,oBAAoB,OAAO,OAAO,OAAO,YAAY,MAAM;CAC5D,MAAM,WAAW;EAChB,YAAY;GACX,WAAW,OAAO,QAAQ,KAAK;EAChC;EACA,YAAY;GACX,WAAW,OAAO,QAAQ,KAAK;EAChC;EACA,aAAa;GACZ,qBAAqB,OAAO,KAAK;EAClC;CACD;CACA,aAAa;EACZ,MAAM,QAAuB;GAC5B,GAAG,uBAAuB,OAAO,KAAK;GACtC,GAAG;EACJ;EACA,WAAW,SAAS;EACpB,KAAK,MAAM,aAAa,CAAC,QAAQ,MAAM,GAAY;GAClD,MAAM,QAAQ,6BACb,MAAM,UAAU,IAAI,MAAM,GAAG,GAC7B,SACD;GACA,IAAI,OACH,MAAM,GAAG,UAAU,sBAClB,kCAAkC,OAAO,WAAW,KAAK;EAC5D;EACA,OAAO;CACR;AACD;AAEA,SAAgB,MAAM,OAAsB;CAC3C,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAAC;CACrD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE;CACzD,IAAI,SAAS,QAAQ,OAAO,UAAU,WAAW,OAAO;CAIxD,OAAO,OAAO,KAAK;AACpB"}
@@ -1 +0,0 @@
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;CACA,QAAQ,UAAU,IAAI,KAAK;CAC3B,OAAO;AACR;AACA,SAAgB,KAAK,OAAc,OAAuB;CACzD,IAAI;EACH,QAAQ,KAAK;CACd,SAAS,SAAS;EACjB,MAAM,IAAI,eAAe,CAAC,OAAO,OAAO,CAAC;CAC1C;CACA,MAAM;AACP;AACA,SAAgB,QAAQ,OAAoB;CAC3C,IAAI,MAAM,OAAO;CACjB,MAAM,QAAQ;CACd,MAAM,SAAoB,CAAC;CAC3B,KAAK,MAAM,WAAW,CAAC,GAAG,MAAM,SAAS,CAAC,CAAC,QAAQ,GAClD,IAAI;EACH,OAAO,YAAY,aAAa,QAAQ,IAAI,QAAQ,OAAO;CAC5D,SAAS,OAAO;EACf,OAAO,KAAK,KAAK;CAClB;CAED,MAAM,SAAS,UAAU,OAAO,K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C5D,MAAM,WAAW;EAChB,YAAY;GACX,WAAW,OAAO,QAAQ,KAAK;EAChC;EACA,YAAY;GACX,WAAW,OAAO,QAAQ,KAAK;EAChC;EACA,aAAa;GACZ,qBAAqB,OAAO,KAAK;EAClC;CACD;CACA,aAAa;EACZ,MAAM,QAAuB;GAC5B,GAAG,uBAAuB,OAAO,KAAK;GACtC,GAAG;EACJ;EACA,WAAW,SAAS;EACpB,KAAK,MAAM,aAAa,CAAC,QAAQ,MAAM,GAAY;GAClD,MAAM,QAAQ,6BACb,MAAM,UAAU,IAAI,MAAM,GAAG,GAC7B,SACD;GACA,IAAI,OACH,MAAM,GAAG,UAAU,sBAClB,kCAAkC,OAAO,WAAW,KAAK;EAC5D;EACA,OAAO;CACR;AACD;AAEA,SAAgB,MAAM,OAAsB;CAC3C,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAAC;CACrD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE;CACzD,IAAI,SAAS,QAAQ,OAAO,UAAU,WAAW,OAAO;CACxD,IAA2B,OAAO,UAAU,UAC3C,MAAM,IAAI,MAAM,oBAAoB;CAErC,OAAO,OAAO,KAAK;AACpB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dom-D9cY6l1R.js","names":[],"sources":["../../src/dom.ts"],"sourcesContent":["import type { Accessor, Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tobserve,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nconst HTML = `http://www.w3.org/1999/xhtml`\nconst SVG = `http://www.w3.org/2000/svg`\ntype Cursor = { node: Node | null }\ntype RecordNode = { _value: Child; _scope: Scope; _start: Node; _end: Node }\n\nfunction take(\n\tnode: Node,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\tif (\n\t\tcursor &&\n\t\t!(node.nodeType === 3 && !node.nodeValue && cursor.node?.nodeType !== 3)\n\t) {\n\t\tconst found = cursor.node\n\t\tif (\n\t\t\t!found ||\n\t\t\tfound.nodeType !== node.nodeType ||\n\t\t\tfound.nodeName !== node.nodeName ||\n\t\t\t(found as Element).namespaceURI !== (node as Element).namespaceURI ||\n\t\t\t(node.nodeType !== 1 && found.nodeValue !== node.nodeValue)\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\tnode = found\n\t\tcursor.node = found.nextSibling\n\t} else parent.insertBefore(node, cursor ? cursor.node : before)\n\towner._cleanups.add(() => {\n\t\t;(node as ChildNode).remove()\n\t})\n\treturn node\n}\nfunction comment(\n\tvalue: string,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\treturn take(\n\t\tparent.ownerDocument!.createComment(value),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t)\n}\nfunction property(\n\telement: Element,\n\tkey: string,\n\tvalue: any,\n\tprevious: any,\n): void {\n\tif (/^(key|children|ref)$/.test(key)) return\n\tif (key === `innerHTML` && element.localName === `astro-slot`) return\n\tif (\n\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\tkey,\n\t\t)\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: owned content` : undefined)\n\tif (key.startsWith(`on`)) {\n\t\tconst capture = /(?<!Pointer)Capture$/.test(key)\n\t\tconst event = key\n\t\t\t.slice(2, capture ? -7 : undefined)\n\t\t\t.toLowerCase()\n\t\t\t.replace(`doubleclick`, `dblclick`)\n\t\tif (previous) element.removeEventListener(event, previous, capture)\n\t\tif (value != null) {\n\t\t\tif (import.meta.env.DEV && typeof value !== `function`)\n\t\t\t\tthrow new Error(`spa: event handler`)\n\t\t\telement.addEventListener(event, value, capture)\n\t\t}\n\t\treturn\n\t}\n\tif (key === `className`) key = `class`\n\tif (key === `htmlFor`) key = `for`\n\tif (\n\t\timport.meta.env.DEV &&\n\t\tkey === `style` &&\n\t\tvalue != null &&\n\t\ttypeof value !== `string`\n\t)\n\t\tthrow new Error(`spa: CSS string required`)\n\tif (\n\t\telement.namespaceURI === HTML &&\n\t\tkey in element &&\n\t\t!/^(style|form|list)$/.test(key)\n\t) {\n\t\tconst target = element as any\n\t\ttarget[key] = value ?? (typeof target[key] === `boolean` ? false : ``)\n\t} else if (value == null || (value === false && !/^(aria-|data-)/.test(key)))\n\t\telement.removeAttribute(key)\n\telse\n\t\telement.setAttribute(\n\t\t\tkey,\n\t\t\tvalue === true && !/^(aria-|data-)/.test(key) ? `` : String(value),\n\t\t)\n}\n\nfunction mount(\n\tvalue: Child,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tnamespace: string,\n\tcursor?: Cursor,\n\tsource = () => value,\n): void {\n\tif (typeof value === `function`) {\n\t\tcomment(`{`, parent, before, owner, cursor)\n\t\tlet end: Node | null = null\n\t\tlet records = new Map<unknown, RecordNode>()\n\t\tlet initial = cursor\n\t\tobserve(\n\t\t\towner,\n\t\t\t() => (source() as () => Child)(),\n\t\t\t(next) => {\n\t\t\t\tconst values = ([next] as unknown[]).flat(Infinity) as Child[]\n\t\t\t\tconst kept = new Map<unknown, RecordNode>()\n\t\t\t\tconst focus = parent.ownerDocument!.activeElement as HTMLElement | null\n\t\t\t\tfor (let index = 0; index < values.length; index++) {\n\t\t\t\t\tconst child = values[index]\n\t\t\t\t\tconst vnode = child as VNode | null\n\t\t\t\t\tconst explicit = vnode?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (import.meta.env.DEV && kept.has(key))\n\t\t\t\t\t\tthrow new Error(`spa: duplicate key`)\n\t\t\t\t\tlet record = records.get(key)\n\t\t\t\t\tif (\n\t\t\t\t\t\trecord &&\n\t\t\t\t\t\t(typeof record._value !== typeof child ||\n\t\t\t\t\t\t\t(record._value as VNode | null)?.type !== vnode?.type)\n\t\t\t\t\t) {\n\t\t\t\t\t\tdispose(record._scope)\n\t\t\t\t\t\trecord = undefined\n\t\t\t\t\t}\n\t\t\t\t\tif (!record) {\n\t\t\t\t\t\tconst childOwner = createScope(owner)\n\t\t\t\t\t\trecord = {\n\t\t\t\t\t\t\t_value: child,\n\t\t\t\t\t\t\t_scope: childOwner,\n\t\t\t\t\t\t\t_start: comment(`[`, parent, end ?? before, childOwner, initial),\n\t\t\t\t\t\t\t_end: null!,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst held = record\n\t\t\t\t\t\tmount(\n\t\t\t\t\t\t\tchild,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t\t() => held._value,\n\t\t\t\t\t\t)\n\t\t\t\t\t\trecord._end = comment(\n\t\t\t\t\t\t\t`]`,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trecord._value = child\n\t\t\t\t\t\tinvalidate(record._scope)\n\t\t\t\t\t}\n\t\t\t\t\tkept.set(key, record)\n\t\t\t\t}\n\t\t\t\tfor (const [key, record] of records)\n\t\t\t\t\tif (!kept.has(key)) dispose(record._scope)\n\t\t\t\tif (!initial) {\n\t\t\t\t\tlet at = end ?? before\n\t\t\t\t\tfor (const record of [...kept.values()].reverse()) {\n\t\t\t\t\t\tif (record._end.nextSibling !== at) {\n\t\t\t\t\t\t\tconst range = parent.ownerDocument!.createRange()\n\t\t\t\t\t\t\trange.setStartBefore(record._start)\n\t\t\t\t\t\t\trange.setEndAfter(record._end)\n\t\t\t\t\t\t\tparent.insertBefore(range.extractContents(), at)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tat = record._start\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tfocus?.isConnected &&\n\t\t\t\t\t\tfocus !== parent.ownerDocument!.activeElement\n\t\t\t\t\t)\n\t\t\t\t\t\tfocus.focus({ preventScroll: true })\n\t\t\t\t}\n\t\t\t\tinitial = undefined\n\t\t\t\trecords = kept\n\t\t\t},\n\t\t)\n\t\tend = comment(`}`, parent, before, owner, cursor)\n\t\treturn\n\t}\n\tif (Array.isArray(value)) {\n\t\tfor (const child of value)\n\t\t\tmount(child, parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (value == null || typeof value === `boolean`) return\n\tif (typeof value !== `object`) {\n\t\tcomment(`t`, parent, before, owner, cursor)\n\t\tconst text = take(\n\t\t\tparent.ownerDocument!.createTextNode(String(value)),\n\t\t\tparent,\n\t\t\tbefore,\n\t\t\towner,\n\t\t\tcursor,\n\t\t)\n\t\tobserve(owner, source as Accessor<string | number | bigint>, (next) => {\n\t\t\tconst data = String(next)\n\t\t\tif (text.nodeValue !== data) text.nodeValue = data\n\t\t})\n\t\treturn\n\t}\n\tif (import.meta.env.DEV && (!(`type` in value) || !(`props` in value)))\n\t\tthrow new Error(`spa: invalid child`)\n\tconst vnode = value as VNode\n\tconst props = merge(() => (source() as VNode).props)\n\tif (!vnode.type || vnode.type === Fragment) {\n\t\tmount(() => props[`children`], parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (typeof vnode.type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\tconst output = within(childOwner, () =>\n\t\t\tuntrack(() => (vnode.type as Function)(props)),\n\t\t)\n\t\tmount(output, parent, before, childOwner, namespace, cursor)\n\t\treturn\n\t}\n\tconst ns = vnode.type === `svg` ? SVG : namespace\n\tconst element = take(\n\t\tparent.ownerDocument!.createElementNS(ns, vnode.type),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t) as Element\n\tif (vnode.type === `astro-slot`) {\n\t\tif (!cursor) element.innerHTML = props[`innerHTML`] ?? ``\n\t} else if (ns === HTML && /^(textarea|title|style|script)$/.test(vnode.type)) {\n\t\tobserve(\n\t\t\towner,\n\t\t\t() =>\n\t\t\t\tplain(\n\t\t\t\t\tvnode.type === `textarea`\n\t\t\t\t\t\t? (props[`value`] ?? props[`children`])\n\t\t\t\t\t\t: props[`children`],\n\t\t\t\t),\n\t\t\t(text) => {\n\t\t\t\tif (element.textContent !== text) element.textContent = text\n\t\t\t},\n\t\t)\n\t} else {\n\t\tconst children = cursor ? { node: element.firstChild } : undefined\n\t\tif (\n\t\t\t!/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(\n\t\t\t\tvnode.type,\n\t\t\t) ||\n\t\t\tns !== HTML\n\t\t)\n\t\t\tmount(\n\t\t\t\t() => props[`children`],\n\t\t\t\telement,\n\t\t\t\tnull,\n\t\t\t\towner,\n\t\t\t\tvnode.type === `foreignObject` ? HTML : ns,\n\t\t\t\tchildren,\n\t\t\t)\n\t\tif (children?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t}\n\tlet previous: Record<string, any> = {}\n\towner._cleanups.add(() => {\n\t\tfor (const key in previous)\n\t\t\tif (key.startsWith(`on`)) property(element, key, null, previous[key])\n\t})\n\tobserve(\n\t\towner,\n\t\t() => ({ ...props }),\n\t\t(next) => {\n\t\t\tfor (const key in { ...previous, ...next })\n\t\t\t\tif (\n\t\t\t\t\t!Object.is(previous[key], next[key]) ||\n\t\t\t\t\ttypeof next[key] === `object`\n\t\t\t\t) {\n\t\t\t\t\tproperty(element, key, next[key], previous[key])\n\t\t\t\t\tprevious[key] = next[key]\n\t\t\t\t}\n\t\t\tprevious = next\n\t\t},\n\t)\n\tconst ref = untrack(() => props[`ref`])\n\tif (ref) {\n\t\towner._root._mounts!.unshift(() => {\n\t\t\tif (!owner._dead) {\n\t\t\t\towner._cleanups.add(() => ref(null))\n\t\t\t\tref(element)\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport interface SpaRoot {\n\tdispose(): void\n\tflush(): void\n}\nfunction start(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions,\n\thydrating: boolean,\n): SpaRoot {\n\tconst cursor = hydrating ? { node: host.firstChild } : undefined\n\tconst prefix = cursor?.node?.nodeValue?.slice(2)\n\tif (\n\t\thydrating &&\n\t\t(prefix === undefined ||\n\t\t\t(options.idPrefix !== undefined && prefix !== options.idPrefix))\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: hydration mismatch` : undefined)\n\tconst root = createRoot(options)\n\tif (prefix !== undefined) root._prefix = prefix\n\ttry {\n\t\tcomment(`w:${root._prefix}`, host, null, root, cursor)\n\t\twithin(root, () => {\n\t\t\tmount(\n\t\t\t\tuntrack(setup),\n\t\t\t\thost,\n\t\t\t\tnull,\n\t\t\t\troot,\n\t\t\t\thost.namespaceURI === SVG ? SVG : HTML,\n\t\t\t\tcursor,\n\t\t\t)\n\t\t})\n\t\tcomment(`/w`, host, null, root, cursor)\n\t\tif (cursor?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\troot.flush()\n\t} catch (error) {\n\t\tfail(root, error)\n\t}\n\treturn {\n\t\tdispose: () => {\n\t\t\tdispose(root)\n\t\t},\n\t\tflush: root.flush,\n\t}\n}\nexport function render(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, false)\n}\nexport function hydrate(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, true)\n}\n"],"mappings":";;;AAcA,MAAM,OAAO;AACb,MAAM,MAAM;AAIZ,SAAS,KACR,MACA,QACA,QACA,OACA,Q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SAAS,OAAO;EACf,KAAK,MAAM,KAAK;CACjB;CACA,OAAO;EACN,eAAe;GACd,QAAQ,IAAI;EACb;EACA,OAAO,KAAK;CACb;AACD;AACA,SAAgB,OACf,OACA,MACA,UAAuB,CAAC,GACd;CACV,OAAO,MAAM,OAAO,MAAM,SAAS,KAAK;AACzC;AACA,SAAgB,QACf,OACA,MACA,UAAuB,CAAC,GACd;CACV,OAAO,MAAM,OAAO,MAAM,SAAS,IAAI;AACxC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/use-loadable.ts"],"sourcesContent":["import type {\n\tLoadable,\n\tReadableFamilyToken,\n\tReadableToken,\n\tViewOf,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport { withdraw } from \"atom.io/internal\"\n\nimport { type Accessor, owner, resolveStateToken, useValue } from \"./core.ts\"\n\nexport type LoadableValue<T> = { loading: boolean; value: T }\n\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable(\n\t...params:\n\t\t| [ReadableToken<any, any, any>]\n\t\t| [ReadableToken<any, any, any>, unknown]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]\n): Accessor<`LOADING` | (LoadableValue<unknown> & { error?: unknown })> {\n\tconst store = owner!._root._store\n\tconst [token] = params\n\tconst family = token.type.endsWith(`_family`)\n\tconst selected = resolveStateToken(token, params[1] as Canonical)\n\tconst read = useValue(selected)\n\tconst fallbackIndex = family ? 2 : 1\n\tconst fallback = params[fallbackIndex]\n\tconst hasFallback = params.length > fallbackIndex\n\tlet available = hasFallback\n\tlet previous = fallback\n\tlet error: unknown\n\treturn () => {\n\t\tconst value = read()\n\t\tconst loading = value instanceof Promise\n\t\tif (!loading) {\n\t\t\tprevious = value\n\t\t\tavailable = true\n\t\t\tconst state = withdraw(store, selected)\n\t\t\terror =\n\t\t\t\thasFallback &&\n\t\t\t\t`catch` in state &&\n\t\t\t\tstate.catch.some((ErrorType) => value instanceof ErrorType)\n\t\t\t\t\t? value\n\t\t\t\t\t: undefined\n\t\t}\n\t\tif (!available) return `LOADING`\n\t\treturn error\n\t\t\t? { loading, value: fallback, error }\n\t\t\t: { loading, value: previous }\n\t}\n}\n"],"mappings":";;;;;AA6BA,SAAgB,YACf,GAAG,QAKoE;CACvE,MAAM,QAAQ,MAAO,MAAM;CAC3B,MAAM,CAAC,SAAS;CAChB,MAAM,SAAS,MAAM,KAAK,SAAS,SAAS;CAC5C,MAAM,WAAW,kBAAkB,OAAO,OAAO,EAAe;CAChE,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,gBAAgB,SAAS,IAAI;CACnC,MAAM,WAAW,OAAO;CACxB,MAAM,cAAc,OAAO,SAAS;CACpC,IAAI,YAAY;CAChB,IAAI,WAAW;CACf,IAAI;CACJ,aAAa;EACZ,MAAM,QAAQ,KAAK;EACnB,MAAM,UAAU,iBAAiB;EACjC,IAAI,CAAC,SAAS;GACb,WAAW;GACX,YAAY;GACZ,MAAM,QAAQ,SAAS,OAAO,QAAQ;GACtC,QACC,eACA,WAAW,SACX,MAAM,MAAM,MAAM,cAAc,iBAAiB,SAAS,IACvD,QACA,KAAA;EACL;EACA,IAAI,CAAC,WAAW,OAAO;EACvB,OAAO,QACJ;GAAE;GAAS,OAAO;GAAU;EAAM,IAClC;GAAE;GAAS,OAAO;EAAS;CAC/B;AACD"}
@@ -1,126 +0,0 @@
1
- import { transformSync, types } from "@babel/core";
2
- // src/compiler.ts
3
- function compile(code, filename) {
4
- const plugin = () => {
5
- let create;
6
- let merge;
7
- const generated = /* @__PURE__ */ new WeakSet();
8
- const components = /* @__PURE__ */ new Set();
9
- function name(node) {
10
- if (types.isJSXMemberExpression(node)) return types.memberExpression(types.isJSXIdentifier(node.object) ? node.object.name === `this` ? types.thisExpression() : types.identifier(node.object.name) : name(node.object), types.identifier(node.property.name));
11
- if (types.isJSXNamespacedName(node)) return types.stringLiteral(`${node.namespace.name}:${node.name.name}`);
12
- return /^[a-z]/.test(node.name) || node.name.includes(`-`) ? types.stringLiteral(node.name) : types.identifier(node.name);
13
- }
14
- function literal(node) {
15
- return types.isLiteral(node) && (!types.isTemplateLiteral(node) || node.expressions.length === 0);
16
- }
17
- function child(node) {
18
- return generated.has(node) || literal(node) || types.isFunction(node) ? node : types.arrowFunctionExpression([], node);
19
- }
20
- return { visitor: {
21
- ExportDefaultDeclaration(path) {
22
- if (types.isArrowFunctionExpression(path.node.declaration) || types.isFunctionExpression(path.node.declaration)) {
23
- const id = path.scope.generateUidIdentifier(`Component`);
24
- path.replaceWithMultiple([types.variableDeclaration(`const`, [types.variableDeclarator(id, path.node.declaration)]), types.exportDefaultDeclaration(id)]);
25
- }
26
- },
27
- Program: {
28
- enter(path) {
29
- create = path.scope.generateUidIdentifier(`spa`);
30
- merge = path.scope.generateUidIdentifier(`props`);
31
- },
32
- exit(path) {
33
- path.unshiftContainer(`body`, types.importDeclaration([types.importSpecifier(create, types.identifier(`jsx`)), types.importSpecifier(merge, types.identifier(`merge`))], types.stringLiteral(`@atom.io/spa/jsx-runtime`)));
34
- for (const component of components) path.pushContainer(`body`, types.expressionStatement(types.assignmentExpression(`=`, types.memberExpression(types.identifier(component), types.identifier(`spa`)), types.booleanLiteral(true))));
35
- }
36
- },
37
- "JSXElement|JSXFragment": { exit(path) {
38
- const node = path.node;
39
- const chunks = [];
40
- let properties = [];
41
- const flush = () => {
42
- if (properties.length) {
43
- chunks.push(types.objectExpression(properties));
44
- properties = [];
45
- }
46
- };
47
- if (types.isJSXElement(node)) for (const attribute of node.openingElement.attributes) {
48
- if (types.isJSXSpreadAttribute(attribute)) {
49
- flush();
50
- chunks.push(types.arrowFunctionExpression([], attribute.argument));
51
- continue;
52
- }
53
- const key = types.isJSXNamespacedName(attribute.name) ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name;
54
- const expression = attribute.value == null ? types.booleanLiteral(true) : types.isJSXExpressionContainer(attribute.value) ? attribute.value.expression : attribute.value;
55
- properties.push(key === `key` || literal(expression) || types.isFunction(expression) ? types.objectProperty(types.stringLiteral(key), expression) : types.objectMethod(`get`, types.stringLiteral(key), [], types.blockStatement([types.returnStatement(expression)])));
56
- }
57
- const children = types.react.buildChildren(node).map((value) => child(value));
58
- if (children.length) properties.push(types.objectProperty(types.identifier(`children`), children.length === 1 ? children[0] : types.arrayExpression(children)));
59
- flush();
60
- const props = chunks.length > 1 || types.isArrowFunctionExpression(chunks[0]) ? types.callExpression(merge, chunks) : chunks[0] ?? types.objectExpression([]);
61
- const result = types.callExpression(create, [types.isJSXElement(node) ? name(node.openingElement.name) : types.nullLiteral(), props]);
62
- generated.add(result);
63
- let fn = path.findParent((parent) => parent.isFunction());
64
- while (fn?.findParent((parent) => parent.isFunction())) fn = fn.findParent((parent) => parent.isFunction());
65
- if (fn) {
66
- if (fn.isFunctionDeclaration() && fn.node.id) components.add(fn.node.id.name);
67
- else if (fn.parentPath.isVariableDeclarator() && types.isIdentifier(fn.parentPath.node.id)) components.add(fn.parentPath.node.id.name);
68
- else if (fn.parentPath.isExportDefaultDeclaration() && types.isFunctionDeclaration(fn.node)) {
69
- fn.node.id = path.scope.generateUidIdentifier(`Component`);
70
- components.add(fn.node.id.name);
71
- }
72
- }
73
- path.replaceWith(result);
74
- } }
75
- } };
76
- };
77
- const result = transformSync(code, {
78
- filename,
79
- babelrc: false,
80
- configFile: false,
81
- sourceMaps: true,
82
- parserOpts: { plugins: [`jsx`, `typescript`] },
83
- plugins: [plugin]
84
- });
85
- return {
86
- code: result.code,
87
- map: result.map
88
- };
89
- }
90
- // src/vite.ts
91
- function spa(options = {}) {
92
- const include = options.include ?? /\.[jt]sx$/;
93
- const matches = (id) => {
94
- include.lastIndex = 0;
95
- return !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0]);
96
- };
97
- return {
98
- name: `spa`,
99
- enforce: `pre`,
100
- config() {
101
- return {
102
- resolve: { dedupe: [`@atom.io/spa`, `atom.io`] },
103
- optimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] }
104
- };
105
- },
106
- configEnvironment: {
107
- order: `post`,
108
- handler(_name, config) {
109
- if (config.optimizeDeps?.include) config.optimizeDeps.include = config.optimizeDeps.include.filter((id) => !/^(@atom\.io\/spa|atom\.io)(\/|$)/.test(id));
110
- }
111
- },
112
- transform(code, id) {
113
- if (!matches(id)) return;
114
- return compile(code, id);
115
- },
116
- handleHotUpdate({ server, file }) {
117
- if (matches(file)) {
118
- server.ws.send({ type: `full-reload` });
119
- return [];
120
- }
121
- }
122
- };
123
- }
124
- export { spa as t };
125
-
126
- //# sourceMappingURL=vite-CQchIQ_-.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-CQchIQ_-.js","names":["t"],"sources":["../../src/compiler.ts","../../src/vite.ts"],"sourcesContent":["import type { PluginObject } from \"@babel/core\"\nimport { transformSync, types as t } from \"@babel/core\"\n\nexport function compile(\n\tcode: string,\n\tfilename: string,\n): { code: string; map: any } {\n\tconst plugin = (): PluginObject => {\n\t\tlet create: t.Identifier\n\t\tlet merge: t.Identifier\n\t\tconst generated = new WeakSet<object>()\n\t\tconst components = new Set<string>()\n\t\tfunction name(\n\t\t\tnode: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n\t\t): t.Expression {\n\t\t\tif (t.isJSXMemberExpression(node))\n\t\t\t\treturn t.memberExpression(\n\t\t\t\t\tt.isJSXIdentifier(node.object)\n\t\t\t\t\t\t? node.object.name === `this`\n\t\t\t\t\t\t\t? t.thisExpression()\n\t\t\t\t\t\t\t: t.identifier(node.object.name)\n\t\t\t\t\t\t: name(node.object),\n\t\t\t\t\tt.identifier(node.property.name),\n\t\t\t\t)\n\t\t\tif (t.isJSXNamespacedName(node))\n\t\t\t\treturn t.stringLiteral(`${node.namespace.name}:${node.name.name}`)\n\t\t\treturn /^[a-z]/.test(node.name) || node.name.includes(`-`)\n\t\t\t\t? t.stringLiteral(node.name)\n\t\t\t\t: t.identifier(node.name)\n\t\t}\n\t\tfunction literal(node: t.Node): boolean {\n\t\t\treturn (\n\t\t\t\tt.isLiteral(node) &&\n\t\t\t\t(!t.isTemplateLiteral(node) || node.expressions.length === 0)\n\t\t\t)\n\t\t}\n\t\tfunction child(node: t.Expression): t.Expression {\n\t\t\treturn generated.has(node) || literal(node) || t.isFunction(node)\n\t\t\t\t? node\n\t\t\t\t: t.arrowFunctionExpression([], node)\n\t\t}\n\t\treturn {\n\t\t\tvisitor: {\n\t\t\t\tExportDefaultDeclaration(path) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tt.isArrowFunctionExpression(path.node.declaration) ||\n\t\t\t\t\t\tt.isFunctionExpression(path.node.declaration)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\tpath.replaceWithMultiple([\n\t\t\t\t\t\t\tt.variableDeclaration(`const`, [\n\t\t\t\t\t\t\t\tt.variableDeclarator(id, path.node.declaration),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\tt.exportDefaultDeclaration(id),\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tProgram: {\n\t\t\t\t\tenter(path) {\n\t\t\t\t\t\tcreate = path.scope.generateUidIdentifier(`spa`)\n\t\t\t\t\t\tmerge = path.scope.generateUidIdentifier(`props`)\n\t\t\t\t\t},\n\t\t\t\t\texit(path) {\n\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\tt.importDeclaration(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tt.importSpecifier(create, t.identifier(`jsx`)),\n\t\t\t\t\t\t\t\t\tt.importSpecifier(merge, t.identifier(`merge`)),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tt.stringLiteral(`@atom.io/spa/jsx-runtime`),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tfor (const component of components)\n\t\t\t\t\t\t\tpath.pushContainer(\n\t\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\t\tt.expressionStatement(\n\t\t\t\t\t\t\t\t\tt.assignmentExpression(\n\t\t\t\t\t\t\t\t\t\t`=`,\n\t\t\t\t\t\t\t\t\t\tt.memberExpression(\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(component),\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(`spa`),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\tt.booleanLiteral(true),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t\"JSXElement|JSXFragment\": {\n\t\t\t\t\texit(path: any) {\n\t\t\t\t\t\tconst node = path.node as t.JSXElement | t.JSXFragment\n\t\t\t\t\t\tconst chunks: t.Expression[] = []\n\t\t\t\t\t\tlet properties: (t.ObjectProperty | t.ObjectMethod)[] = []\n\t\t\t\t\t\tconst flush = () => {\n\t\t\t\t\t\t\tif (properties.length) {\n\t\t\t\t\t\t\t\tchunks.push(t.objectExpression(properties))\n\t\t\t\t\t\t\t\tproperties = []\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (t.isJSXElement(node))\n\t\t\t\t\t\t\tfor (const attribute of node.openingElement.attributes) {\n\t\t\t\t\t\t\t\tif (t.isJSXSpreadAttribute(attribute)) {\n\t\t\t\t\t\t\t\t\tflush()\n\t\t\t\t\t\t\t\t\tchunks.push(t.arrowFunctionExpression([], attribute.argument))\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst key = t.isJSXNamespacedName(attribute.name)\n\t\t\t\t\t\t\t\t\t? `${attribute.name.namespace.name}:${attribute.name.name.name}`\n\t\t\t\t\t\t\t\t\t: attribute.name.name\n\t\t\t\t\t\t\t\tconst value =\n\t\t\t\t\t\t\t\t\tattribute.value == null\n\t\t\t\t\t\t\t\t\t\t? t.booleanLiteral(true)\n\t\t\t\t\t\t\t\t\t\t: t.isJSXExpressionContainer(attribute.value)\n\t\t\t\t\t\t\t\t\t\t\t? attribute.value.expression\n\t\t\t\t\t\t\t\t\t\t\t: attribute.value\n\t\t\t\t\t\t\t\t// The parser rejects empty attribute expressions.\n\t\t\t\t\t\t\t\tconst expression = value as t.Expression\n\t\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\t\tkey === `key` ||\n\t\t\t\t\t\t\t\t\t\tliteral(expression) ||\n\t\t\t\t\t\t\t\t\t\tt.isFunction(expression)\n\t\t\t\t\t\t\t\t\t\t? t.objectProperty(t.stringLiteral(key), expression)\n\t\t\t\t\t\t\t\t\t\t: t.objectMethod(\n\t\t\t\t\t\t\t\t\t\t\t\t`get`,\n\t\t\t\t\t\t\t\t\t\t\t\tt.stringLiteral(key),\n\t\t\t\t\t\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\t\t\t\t\tt.blockStatement([t.returnStatement(expression)]),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tconst children = t.react\n\t\t\t\t\t\t\t.buildChildren(node)\n\t\t\t\t\t\t\t.map((value) => child(value as t.Expression))\n\t\t\t\t\t\tif (children.length)\n\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\tt.objectProperty(\n\t\t\t\t\t\t\t\t\tt.identifier(`children`),\n\t\t\t\t\t\t\t\t\tchildren.length === 1\n\t\t\t\t\t\t\t\t\t\t? children[0]\n\t\t\t\t\t\t\t\t\t\t: t.arrayExpression(children),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tflush()\n\t\t\t\t\t\tconst props =\n\t\t\t\t\t\t\tchunks.length > 1 || t.isArrowFunctionExpression(chunks[0])\n\t\t\t\t\t\t\t\t? t.callExpression(merge, chunks)\n\t\t\t\t\t\t\t\t: (chunks[0] ?? t.objectExpression([]))\n\t\t\t\t\t\tconst result = t.callExpression(create, [\n\t\t\t\t\t\t\tt.isJSXElement(node)\n\t\t\t\t\t\t\t\t? name(node.openingElement.name)\n\t\t\t\t\t\t\t\t: t.nullLiteral(),\n\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t])\n\t\t\t\t\t\tgenerated.add(result)\n\t\t\t\t\t\tlet fn = path.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\twhile (fn?.findParent((parent: any) => parent.isFunction()))\n\t\t\t\t\t\t\tfn = fn.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\tif (fn) {\n\t\t\t\t\t\t\tif (fn.isFunctionDeclaration() && fn.node.id)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isVariableDeclarator() &&\n\t\t\t\t\t\t\t\tt.isIdentifier(fn.parentPath.node.id)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tcomponents.add(fn.parentPath.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isExportDefaultDeclaration() &&\n\t\t\t\t\t\t\t\tt.isFunctionDeclaration(fn.node)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tfn.node.id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpath.replaceWith(result)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\tconst result = transformSync(code, {\n\t\tfilename,\n\t\tbabelrc: false,\n\t\tconfigFile: false,\n\t\tsourceMaps: true,\n\t\tparserOpts: { plugins: [`jsx`, `typescript`] },\n\t\tplugins: [plugin],\n\t})!\n\treturn { code: result.code!, map: result.map }\n}\n","import type { Plugin } from \"vite\"\n\nimport { compile } from \"./compiler.ts\"\n\nexport interface SpaPluginOptions {\n\tinclude?: RegExp\n}\nexport default function spa(options: SpaPluginOptions = {}): Plugin {\n\tconst include = options.include ?? /\\.[jt]sx$/\n\tconst matches = (id: string): boolean => {\n\t\tinclude.lastIndex = 0\n\t\treturn !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0])\n\t}\n\treturn {\n\t\tname: `spa`,\n\t\tenforce: `pre`,\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\tresolve: { dedupe: [`@atom.io/spa`, `atom.io`] },\n\t\t\t\toptimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] },\n\t\t\t}\n\t\t},\n\t\tconfigEnvironment: {\n\t\t\torder: `post`,\n\t\t\thandler(_name, config) {\n\t\t\t\t// Astro and its adapters force renderer entries into the optimizer.\n\t\t\t\t// Vite processes explicit includes even when their package is excluded.\n\t\t\t\t// Keep the renderer, hooks, and store in one unbundled module graph.\n\t\t\t\tif (config.optimizeDeps?.include) {\n\t\t\t\t\tconfig.optimizeDeps.include = config.optimizeDeps.include.filter(\n\t\t\t\t\t\t(id) => !/^(@atom\\.io\\/spa|atom\\.io)(\\/|$)/.test(id),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\ttransform(code, id) {\n\t\t\tif (!matches(id)) return\n\t\t\treturn compile(code, id)\n\t\t},\n\t\t// A reload disposes the whole document. No state-preserving HMR is promised.\n\t\thandleHotUpdate({ server, file }) {\n\t\t\tif (matches(file)) {\n\t\t\t\tserver.ws.send({ type: `full-reload` })\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;AAGA,SAAgB,QACf,MACA,UAC6B;CAC7B,MAAM,eAA6B;EAClC,IAAI;EACJ,IAAI;EACJ,MAAM,4BAAY,IAAI,QAAgB;EACtC,MAAM,6BAAa,IAAI,IAAY;EACnC,SAAS,KACR,MACe;GACf,IAAIA,MAAE,sBAAsB,IAAI,GAC/B,OAAOA,MAAE,iBACRA,MAAE,gBAAgB,KAAK,MAAM,IAC1B,KAAK,OAAO,SAAS,SACpBA,MAAE,eAAe,IACjBA,MAAE,WAAW,KAAK,OAAO,IAAI,IAC9B,KAAK,KAAK,MAAM,GACnBA,MAAE,WAAW,KAAK,SAAS,IAAI,CAChC;GACD,IAAIA,MAAE,oBAAoB,IAAI,GAC7B,OAAOA,MAAE,cAAc,GAAG,KAAK,UAAU,KAAK,GAAG,KAAK,KAAK,MAAM;GAClE,OAAO,SAAS,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,SAAS,GAAG,IACtDA,MAAE,cAAc,KAAK,IAAI,IACzBA,MAAE,WAAW,KAAK,IAAI;EAC1B;EACA,SAAS,QAAQ,MAAuB;GACvC,OACCA,MAAE,UAAU,IAAI,MACf,CAACA,MAAE,kBAAkB,IAAI,KAAK,KAAK,YAAY,WAAW;EAE7D;EACA,SAAS,MAAM,MAAkC;GAChD,OAAO,UAAU,IAAI,IAAI,KAAK,QAAQ,IAAI,KAAKA,MAAE,WAAW,IAAI,IAC7D,OACAA,MAAE,wBAAwB,CAAC,GAAG,IAAI;EACtC;EACA,OAAO,EACN,SAAS;GACR,yBAAyB,MAAM;IAC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M,EAAE;EACxB;EAEA,gBAAgB,EAAE,QAAQ,QAAQ;GACjC,IAAI,QAAQ,IAAI,GAAG;IAClB,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IACtC,OAAO,CAAC;GACT;EACD;CACD;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dom-BR9o9wZW.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { Accessor, Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tobserve,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nconst HTML = `http://www.w3.org/1999/xhtml`\nconst SVG = `http://www.w3.org/2000/svg`\ntype Cursor = { node: Node | null }\ntype RecordNode = { _value: Child; _scope: Scope; _start: Node; _end: Node }\n\nfunction take(\n\tnode: Node,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\tif (\n\t\tcursor &&\n\t\t!(node.nodeType === 3 && !node.nodeValue && cursor.node?.nodeType !== 3)\n\t) {\n\t\tconst found = cursor.node\n\t\tif (\n\t\t\t!found ||\n\t\t\tfound.nodeType !== node.nodeType ||\n\t\t\tfound.nodeName !== node.nodeName ||\n\t\t\t(found as Element).namespaceURI !== (node as Element).namespaceURI ||\n\t\t\t(node.nodeType !== 1 && found.nodeValue !== node.nodeValue)\n\t\t)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\tnode = found\n\t\tcursor.node = found.nextSibling\n\t} else parent.insertBefore(node, cursor ? cursor.node : before)\n\towner._cleanups.add(() => {\n\t\t;(node as ChildNode).remove()\n\t})\n\treturn node\n}\nfunction comment(\n\tvalue: string,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tcursor?: Cursor,\n): Node {\n\treturn take(\n\t\tparent.ownerDocument!.createComment(value),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t)\n}\nfunction property(\n\telement: Element,\n\tkey: string,\n\tvalue: any,\n\tprevious: any,\n): void {\n\tif (/^(key|children|ref)$/.test(key)) return\n\tif (key === `innerHTML` && element.localName === `astro-slot`) return\n\tif (\n\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\tkey,\n\t\t)\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: owned content` : undefined)\n\tif (key.startsWith(`on`)) {\n\t\tconst capture = /(?<!Pointer)Capture$/.test(key)\n\t\tconst event = key\n\t\t\t.slice(2, capture ? -7 : undefined)\n\t\t\t.toLowerCase()\n\t\t\t.replace(`doubleclick`, `dblclick`)\n\t\tif (previous) element.removeEventListener(event, previous, capture)\n\t\tif (value != null) {\n\t\t\tif (import.meta.env.DEV && typeof value !== `function`)\n\t\t\t\tthrow new Error(`spa: event handler`)\n\t\t\telement.addEventListener(event, value, capture)\n\t\t}\n\t\treturn\n\t}\n\tif (key === `className`) key = `class`\n\tif (key === `htmlFor`) key = `for`\n\tif (\n\t\timport.meta.env.DEV &&\n\t\tkey === `style` &&\n\t\tvalue != null &&\n\t\ttypeof value !== `string`\n\t)\n\t\tthrow new Error(`spa: CSS string required`)\n\tif (\n\t\telement.namespaceURI === HTML &&\n\t\tkey in element &&\n\t\t!/^(style|form|list)$/.test(key)\n\t) {\n\t\tconst target = element as any\n\t\ttarget[key] = value ?? (typeof target[key] === `boolean` ? false : ``)\n\t} else if (value == null || (value === false && !/^(aria-|data-)/.test(key)))\n\t\telement.removeAttribute(key)\n\telse\n\t\telement.setAttribute(\n\t\t\tkey,\n\t\t\tvalue === true && !/^(aria-|data-)/.test(key) ? `` : String(value),\n\t\t)\n}\n\nfunction mount(\n\tvalue: Child,\n\tparent: Node,\n\tbefore: Node | null,\n\towner: Scope,\n\tnamespace: string,\n\tcursor?: Cursor,\n\tsource = () => value,\n): void {\n\tif (typeof value === `function`) {\n\t\tcomment(`{`, parent, before, owner, cursor)\n\t\tlet end: Node | null = null\n\t\tlet records = new Map<unknown, RecordNode>()\n\t\tlet initial = cursor\n\t\tobserve(\n\t\t\towner,\n\t\t\t() => (source() as () => Child)(),\n\t\t\t(next) => {\n\t\t\t\tconst values = ([next] as unknown[]).flat(Infinity) as Child[]\n\t\t\t\tconst kept = new Map<unknown, RecordNode>()\n\t\t\t\tconst focus = parent.ownerDocument!.activeElement as HTMLElement | null\n\t\t\t\tfor (let index = 0; index < values.length; index++) {\n\t\t\t\t\tconst child = values[index]\n\t\t\t\t\tconst vnode = child as VNode | null\n\t\t\t\t\tconst explicit = vnode?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (import.meta.env.DEV && kept.has(key))\n\t\t\t\t\t\tthrow new Error(`spa: duplicate key`)\n\t\t\t\t\tlet record = records.get(key)\n\t\t\t\t\tif (\n\t\t\t\t\t\trecord &&\n\t\t\t\t\t\t(typeof record._value !== typeof child ||\n\t\t\t\t\t\t\t(record._value as VNode | null)?.type !== vnode?.type)\n\t\t\t\t\t) {\n\t\t\t\t\t\tdispose(record._scope)\n\t\t\t\t\t\trecord = undefined\n\t\t\t\t\t}\n\t\t\t\t\tif (!record) {\n\t\t\t\t\t\tconst childOwner = createScope(owner)\n\t\t\t\t\t\trecord = {\n\t\t\t\t\t\t\t_value: child,\n\t\t\t\t\t\t\t_scope: childOwner,\n\t\t\t\t\t\t\t_start: comment(`[`, parent, end ?? before, childOwner, initial),\n\t\t\t\t\t\t\t_end: null!,\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst held = record\n\t\t\t\t\t\tmount(\n\t\t\t\t\t\t\tchild,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tnamespace,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t\t() => held._value,\n\t\t\t\t\t\t)\n\t\t\t\t\t\trecord._end = comment(\n\t\t\t\t\t\t\t`]`,\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tend ?? before,\n\t\t\t\t\t\t\tchildOwner,\n\t\t\t\t\t\t\tinitial,\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trecord._value = child\n\t\t\t\t\t\tinvalidate(record._scope)\n\t\t\t\t\t}\n\t\t\t\t\tkept.set(key, record)\n\t\t\t\t}\n\t\t\t\tfor (const [key, record] of records)\n\t\t\t\t\tif (!kept.has(key)) dispose(record._scope)\n\t\t\t\tif (!initial) {\n\t\t\t\t\tlet at = end ?? before\n\t\t\t\t\tfor (const record of [...kept.values()].reverse()) {\n\t\t\t\t\t\tif (record._end.nextSibling !== at) {\n\t\t\t\t\t\t\tconst range = parent.ownerDocument!.createRange()\n\t\t\t\t\t\t\trange.setStartBefore(record._start)\n\t\t\t\t\t\t\trange.setEndAfter(record._end)\n\t\t\t\t\t\t\tparent.insertBefore(range.extractContents(), at)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tat = record._start\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tfocus?.isConnected &&\n\t\t\t\t\t\tfocus !== parent.ownerDocument!.activeElement\n\t\t\t\t\t)\n\t\t\t\t\t\tfocus.focus({ preventScroll: true })\n\t\t\t\t}\n\t\t\t\tinitial = undefined\n\t\t\t\trecords = kept\n\t\t\t},\n\t\t)\n\t\tend = comment(`}`, parent, before, owner, cursor)\n\t\treturn\n\t}\n\tif (Array.isArray(value)) {\n\t\tfor (const child of value)\n\t\t\tmount(child, parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (value == null || typeof value === `boolean`) return\n\tif (typeof value !== `object`) {\n\t\tcomment(`t`, parent, before, owner, cursor)\n\t\tconst text = take(\n\t\t\tparent.ownerDocument!.createTextNode(String(value)),\n\t\t\tparent,\n\t\t\tbefore,\n\t\t\towner,\n\t\t\tcursor,\n\t\t)\n\t\tobserve(owner, source as Accessor<string | number | bigint>, (next) => {\n\t\t\tconst data = String(next)\n\t\t\tif (text.nodeValue !== data) text.nodeValue = data\n\t\t})\n\t\treturn\n\t}\n\tif (import.meta.env.DEV && (!(`type` in value) || !(`props` in value)))\n\t\tthrow new Error(`spa: invalid child`)\n\tconst vnode = value as VNode\n\tconst props = merge(() => (source() as VNode).props)\n\tif (!vnode.type || vnode.type === Fragment) {\n\t\tmount(() => props[`children`], parent, before, owner, namespace, cursor)\n\t\treturn\n\t}\n\tif (typeof vnode.type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\tconst output = within(childOwner, () =>\n\t\t\tuntrack(() => (vnode.type as Function)(props)),\n\t\t)\n\t\tmount(output, parent, before, childOwner, namespace, cursor)\n\t\treturn\n\t}\n\tconst ns = vnode.type === `svg` ? SVG : namespace\n\tconst element = take(\n\t\tparent.ownerDocument!.createElementNS(ns, vnode.type),\n\t\tparent,\n\t\tbefore,\n\t\towner,\n\t\tcursor,\n\t) as Element\n\tif (vnode.type === `astro-slot`) {\n\t\tif (!cursor) element.innerHTML = props[`innerHTML`] ?? ``\n\t} else if (ns === HTML && /^(textarea|title|style|script)$/.test(vnode.type)) {\n\t\tobserve(\n\t\t\towner,\n\t\t\t() =>\n\t\t\t\tplain(\n\t\t\t\t\tvnode.type === `textarea`\n\t\t\t\t\t\t? (props[`value`] ?? props[`children`])\n\t\t\t\t\t\t: props[`children`],\n\t\t\t\t),\n\t\t\t(text) => {\n\t\t\t\tif (element.textContent !== text) element.textContent = text\n\t\t\t},\n\t\t)\n\t} else {\n\t\tconst children = cursor ? { node: element.firstChild } : undefined\n\t\tif (\n\t\t\t!/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/.test(\n\t\t\t\tvnode.type,\n\t\t\t) ||\n\t\t\tns !== HTML\n\t\t)\n\t\t\tmount(\n\t\t\t\t() => props[`children`],\n\t\t\t\telement,\n\t\t\t\tnull,\n\t\t\t\towner,\n\t\t\t\tvnode.type === `foreignObject` ? HTML : ns,\n\t\t\t\tchildren,\n\t\t\t)\n\t\tif (children?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t}\n\tlet previous: Record<string, any> = {}\n\towner._cleanups.add(() => {\n\t\tfor (const key in previous)\n\t\t\tif (key.startsWith(`on`)) property(element, key, null, previous[key])\n\t})\n\tobserve(\n\t\towner,\n\t\t() => ({ ...props }),\n\t\t(next) => {\n\t\t\tfor (const key in { ...previous, ...next })\n\t\t\t\tif (\n\t\t\t\t\t!Object.is(previous[key], next[key]) ||\n\t\t\t\t\ttypeof next[key] === `object`\n\t\t\t\t) {\n\t\t\t\t\tproperty(element, key, next[key], previous[key])\n\t\t\t\t\tprevious[key] = next[key]\n\t\t\t\t}\n\t\t\tprevious = next\n\t\t},\n\t)\n\tconst ref = untrack(() => props[`ref`])\n\tif (ref) {\n\t\towner._root._mounts!.unshift(() => {\n\t\t\tif (!owner._dead) {\n\t\t\t\towner._cleanups.add(() => ref(null))\n\t\t\t\tref(element)\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport interface SpaRoot {\n\tdispose(): void\n\tflush(): void\n}\nfunction start(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions,\n\thydrating: boolean,\n): SpaRoot {\n\tconst cursor = hydrating ? { node: host.firstChild } : undefined\n\tconst prefix = cursor?.node?.nodeValue?.slice(2)\n\tif (\n\t\thydrating &&\n\t\t(prefix === undefined ||\n\t\t\t(options.idPrefix !== undefined && prefix !== options.idPrefix))\n\t)\n\t\tthrow new Error(import.meta.env.DEV ? `spa: hydration mismatch` : undefined)\n\tconst root = createRoot(options)\n\tif (prefix !== undefined) root._prefix = prefix\n\ttry {\n\t\tcomment(`w:${root._prefix}`, host, null, root, cursor)\n\t\twithin(root, () => {\n\t\t\tmount(\n\t\t\t\tuntrack(setup),\n\t\t\t\thost,\n\t\t\t\tnull,\n\t\t\t\troot,\n\t\t\t\thost.namespaceURI === SVG ? SVG : HTML,\n\t\t\t\tcursor,\n\t\t\t)\n\t\t})\n\t\tcomment(`/w`, host, null, root, cursor)\n\t\tif (cursor?.node)\n\t\t\tthrow new Error(\n\t\t\t\timport.meta.env.DEV ? `spa: hydration mismatch` : undefined,\n\t\t\t)\n\t\troot.flush()\n\t} catch (error) {\n\t\tfail(root, error)\n\t}\n\treturn {\n\t\tdispose: () => {\n\t\t\tdispose(root)\n\t\t},\n\t\tflush: root.flush,\n\t}\n}\nexport function render(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, false)\n}\nexport function hydrate(\n\tsetup: () => Child,\n\thost: Element,\n\toptions: RootOptions = {},\n): SpaRoot {\n\treturn start(setup, host, options, true)\n}\n"],"mappings":";;;AAcA,MAAM,OAAO;AACb,MAAM,MAAM;AAIZ,SAAS,KACR,MACA,QACA,QACA,OACA,QACO;CACP,IACC,UACA,EAAE,KAAK,aAAa,KAAK,CAAC,KAAK,aAAa,OAAO,MAAM,aAAa,IACrE;EACD,MAAM,QAAQ,OAAO;EACrB,IACC,CAAC,SACD,MAAM,aAAa,KAAK,YACxB,MAAM,aAAa,KAAK,YACvB,MAAkB,iBAAkB,KAAiB,gBACrD,KAAK,aAAa,KAAK,MAAM,cAAc,KAAK,WAEjD,MAAM,IAAI,MACyC,KAAA,CACnD;EACD,OAAO;EACP,OAAO,OAAO,MAAM;CACrB,OAAO,OAAO,aAAa,MAAM,SAAS,OAAO,OAAO,MAAM;CAC9D,MAAM,UAAU,UAAU;EACxB,KAAoB,OAAO;CAC7B,CAAC;CACD,OAAO;AACR;AACA,SAAS,QACR,OACA,QACA,QACA,OACA,QACO;CACP,OAAO,KACN,OAAO,cAAe,cAAc,KAAK,GACzC,QACA,QACA,OACA,MACD;AACD;AACA,SAAS,SACR,SACA,KACA,OACA,UACO;CACP,IAAI,uBAAuB,KAAK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M,OAAO,WAAW,OAAO;CAC/B,IAAI,WAAW,KAAA,GAAW,KAAK,UAAU;CACzC,IAAI;EACH,QAAQ,KAAK,KAAK,WAAW,MAAM,MAAM,MAAM,MAAM;EACrD,OAAO,YAAY;GAClB,MACC,QAAQ,KAAK,GACb,MACA,MACA,MACA,KAAK,iBAAiB,MAAM,MAAM,MAClC,MACD;EACD,CAAC;EACD,QAAQ,MAAM,MAAM,MAAM,MAAM,MAAM;EACtC,IAAI,QAAQ,MACX,MAAM,IAAI,MACyC,KAAA,CACnD;EACD,KAAK,MAAM;CACZ,SAAS,OAAO;EACf,KAAK,MAAM,KAAK;CACjB;CACA,OAAO;EACN,eAAe;GACd,QAAQ,IAAI;EACb;EACA,OAAO,KAAK;CACb;AACD;AACA,SAAgB,OACf,OACA,MACA,UAAuB,CAAC,GACd;CACV,OAAO,MAAM,OAAO,MAAM,SAAS,KAAK;AACzC;AACA,SAAgB,QACf,OACA,MACA,UAAuB,CAAC,GACd;CACV,OAAO,MAAM,OAAO,MAAM,SAAS,IAAI;AACxC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/dom.ts","../src/use-loadable.ts"],"mappings":";;;;UAmUiB;EAChB;EACA;;wBA8Ce,OACf,aAAa,OACb,MAAM,SACN,UAAS,cACP;wBAGa,QACf,aAAa,OACb,MAAM,SACN,UAAS,cACP;KCnXS,cAAc;EAAO;EAAkB,OAAO;;wBAE1C,YAAY,GAAG,GAC9B,OAAO,cAAc,SAAS,SAAS,KACrC,qBAAqB,cAAc,OAAO,IAAI;wBACjC,YAAY,GAAG,UAAU,WAAW,GACnD,OAAO,oBAAoB,SAAS,IAAI,GAAG,IAC3C,KAAK,QAAQ,KACX,qBAAqB,cAAc,OAAO,IAAI;wBACjC,YAAY,GAAG,GAC9B,OAAO,cAAc,SAAS,SAAS,IACvC,UAAU,QAAQ,KAChB,SAAS,cAAc,OAAO;EAAQ,QAAQ;;wBACjC,YAAY,GAAG,UAAU,WAAW,GACnD,OAAO,oBAAoB,SAAS,IAAI,GAAG,IAC3C,KAAK,QAAQ,IACb,UAAU,QAAQ,KAChB,SAAS,cAAc,OAAO;EAAQ,QAAQ"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/use-loadable.ts"],"sourcesContent":["import type {\n\tLoadable,\n\tReadableFamilyToken,\n\tReadableToken,\n\tViewOf,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport { withdraw } from \"atom.io/internal\"\n\nimport { type Accessor, owner, resolveStateToken, useValue } from \"./core.ts\"\n\nexport type LoadableValue<T> = { loading: boolean; value: T }\n\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<`LOADING` | LoadableValue<ViewOf<T | E>>>\nexport function useLoadable<T, E>(\n\ttoken: ReadableToken<Loadable<T>, any, E>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable<T, K extends Canonical, E>(\n\ttoken: ReadableFamilyToken<Loadable<T>, K, E>,\n\tkey: NoInfer<K>,\n\tfallback: NoInfer<T>,\n): Accessor<LoadableValue<ViewOf<T>> & { error?: E }>\nexport function useLoadable(\n\t...params:\n\t\t| [ReadableToken<any, any, any>]\n\t\t| [ReadableToken<any, any, any>, unknown]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical]\n\t\t| [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]\n): Accessor<`LOADING` | (LoadableValue<unknown> & { error?: unknown })> {\n\tconst store = owner!._root._store\n\tconst [token] = params\n\tconst family = token.type.endsWith(`_family`)\n\tconst selected = resolveStateToken(token, params[1] as Canonical)\n\tconst read = useValue(selected)\n\tconst fallbackIndex = family ? 2 : 1\n\tconst fallback = params[fallbackIndex]\n\tconst hasFallback = params.length > fallbackIndex\n\tlet available = hasFallback\n\tlet previous = fallback\n\tlet error: unknown\n\treturn () => {\n\t\tconst value = read()\n\t\tconst loading = value instanceof Promise\n\t\tif (!loading) {\n\t\t\tprevious = value\n\t\t\tavailable = true\n\t\t\tconst state = withdraw(store, selected)\n\t\t\terror =\n\t\t\t\thasFallback &&\n\t\t\t\t`catch` in state &&\n\t\t\t\tstate.catch.some((ErrorType) => value instanceof ErrorType)\n\t\t\t\t\t? value\n\t\t\t\t\t: undefined\n\t\t}\n\t\tif (!available) return `LOADING`\n\t\treturn error\n\t\t\t? { loading, value: fallback, error }\n\t\t\t: { loading, value: previous }\n\t}\n}\n"],"mappings":";;;;;AA6BA,SAAgB,YACf,GAAG,QAKoE;CACvE,MAAM,QAAQ,MAAO,MAAM;CAC3B,MAAM,CAAC,SAAS;CAChB,MAAM,SAAS,MAAM,KAAK,SAAS,SAAS;CAC5C,MAAM,WAAW,kBAAkB,OAAO,OAAO,EAAe;CAChE,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,gBAAgB,SAAS,IAAI;CACnC,MAAM,WAAW,OAAO;CACxB,MAAM,cAAc,OAAO,SAAS;CACpC,IAAI,YAAY;CAChB,IAAI,WAAW;CACf,IAAI;CACJ,aAAa;EACZ,MAAM,QAAQ,KAAK;EACnB,MAAM,UAAU,iBAAiB;EACjC,IAAI,CAAC,SAAS;GACb,WAAW;GACX,YAAY;GACZ,MAAM,QAAQ,SAAS,OAAO,QAAQ;GACtC,QACC,eACA,WAAW,SACX,MAAM,MAAM,MAAM,cAAc,iBAAiB,SAAS,IACvD,QACA,KAAA;EACL;EACA,IAAI,CAAC,WAAW,OAAO;EACvB,OAAO,QACJ;GAAE;GAAS,OAAO;GAAU;EAAM,IAClC;GAAE;GAAS,OAAO;EAAS;CAC/B;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsx-runtime-BzGV18VO.d.ts","names":[],"sources":["../src/jsx-types.d.ts","../src/jsx-runtime.ts"],"mappings":";;KAGY,cAAc,UAAU,SAAS,UAAU,QAAQ,SAAS,KACvE;WAEc,eAAe;;KAClB,aAAa,UAAU,SAAS,UAAU,QAAQ,UAC7D,OAAO,cAAc,GAAG;KAEb,IAAI,UAAU,YAAY,SAAS;KAE1C,WAAW,QAAQ,WAAW,KAAK,EAAE;;UAGhC;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAEI,UAAU,oBACZ,IACA,WAAW,MACV,gBAAgB,aAAa,WAAW;KACvC,cAAc,UAAU,WAAW,UAAU,mBAC/C,2BACA,UAAU,mBACT,2BACA,UAAU,kBACT,0BACA,UAAU,sBACT,8BACA,UAAU,gBACT,wBACA,UAAU,aACT,qBACA;KACI,gBAAgB,UAAU,cAEpC,WAAW,cAAc,oBAAoB,UAAU,yBACpD,aAAa,GAAG,QAAQ,cAAc,GAAG,IAAI;KAG7C;KACO,iBAAiB;GAC3B;GACA,gBAAgB;GAChB;GACA;GACA;GACA,cAAc;GACd,iBAAiB;GACjB;GACA;GACA;GACA;GACA;GACA,iBAAiB;GACjB;GACA;GACA;GACA,kBAAkB;GAClB;GACA;GACA,kBAAkB;GAClB;GACA,iBAAiB;GACjB,kBAAkB;GAClB,gBAAgB;GAChB,iBAAiB;GACjB;GACA;GACA;GACA;GACA;GACA,eAAe;GACf,mBAAmB;GACnB,yBAAyB;GACzB;GACA;GACA;GACA;GACA,iBAAiB;GACjB,kBAAkB;GAClB;GAWA,kBAAkB;GAClB;GACA;GACA;GACA;GACA;GACA,kBAAkB;GAClB;GACA;GACA;GACA;GACA;GACA;;KAGU,cAAc,UAAU,WAAW,gBAAgB,KAC9D,iBACA;EACC,UAAU;EACV;EACA,KAAK,IAAI;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;QACO;;;KAIJ,YAAY,KAAK,WAAW,QAC/B,WAAW,KAAK,mBAAmB,UAAU,cAC3C,EAAE;KAIM,eAAe,UAAU,cAAc,eAClD,cAAc,KACb;EACC;EACA;EAOA;EACA;EACA;EACA;EACA;EACA;EAQA;EACA;EACA;EACA;EASA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGE;KACA;KAUA;KACA;EACJ;EACA;EACA;EACA;EACA;EACA;;KAEI;EACJ;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;;KAEI;EACJ;EACA;EACA;EACA;EACA,gBAAgB;EAChB;EACA;EACA;;KAEI;EACJ;EACA;EACA;EACA;EACA;;;UAIS;EACT,GAAG;EACH,MAAM;IACL;IACA;IACA;;EAED,OAAO;EACP;IAAQ;IAAc;;EACtB;IAAc;;EACd,QAAQ;IACP;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;;EAED;IAAU,QAAQ;IAAgB,OAAO;;EACzC;IAAO;;EACP;IAAY;;EACZ;IAAQ,OAAO;;EACf;IAAO;IAAc;;EACrB;IAAW;IAAc;;EACzB;IAAU;IAAe;;EACzB;IACC,QAAQ;IACR;IACA;IACA,OAAO;;EAER;IAAY;IAAmB;IAAc;;EAC7C;IACC;KACC;IACD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAED;IAAQ;;EACR;IACC;IACA;IACA;IACA,QAAQ;IACR;IACA;IACA,gBAAgB;IAChB;IACA;IACA;IACA,OAAO;;EAER;IACC;IACA,aAAa;IACb;IACA;IACA,QAAQ;IACR;IACA;IACA,gBAAgB;IAChB;IACA;IACA;IACA;IACA,OAAO;;EAER,OAAO;IACN;IACA;IACA;IACA;IACA;IACA;IACA,cAAc;IACd;IACA;IACA,QAAQ;IACR;IACA,KAAK;IACL;IACA,KAAK;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAM;IACN;IACA,OAAO;IACP,OAAO;;EAER;IAAO;IAAc;;EACrB;IAAS;IAAa;IAAiB;;EACvC;IAAM;;EACN;IACC;IACA;IACA,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,gBAAgB;IAChB;IACA;IACA;;EAED;IAAO;;EACP;IACC;IACA;IACA;KACC;IACD;IACA;;EAED;IACC;IACA;IACA;IACA;IACA;IACA;;EAED;IACC;IACA;IACA,QAAQ;IACR;IACA;IACA;IACA,OAAO;;EAER;IAAM;IAAmB;IAAe;;EACxC;IAAY;IAAmB;;EAC/B;IACC;IACA;IACA;IACA,OAAO;;EAER;IAAU;IAAa;IAAiB;IAAc;;EACtD;IAAY;IAAa;;EACzB;IAAK;;EACL;IACC;IACA;IACA;IACA,aAAa;IACb;IACA;IACA;IACA;IACA,gBAAgB;IAChB;IACA;;EAED;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;;EAER;IAAQ;;EACR;IACC,QAAQ;IACR;IACA;IACA;IACA;IACA;IACA,OAAO;;EAER;IAAS;IAAkB;IAAe;IAAe;;EACzD;IAAS,aAAa;IAAgB,aAAa;;EACnD,IAAI;EACJ;IACC;IACA;IACA;IACA;;EAED;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,IAAI;EACJ;IAAQ;;EACR;IACC;IACA;IACA;IACA;IACA;;EAED,OAAO;IACN;IACA,QAAQ;IACR;IACA;IACA,OAAO;;;KAIG,2BACV,aAAa,wBAAwB,eACrC,sBAAsB,SAErB,kBAAkB,oBAChB,YAAY,kBAAkB;;KAKvB,cAAc,UAAU,aAAa,cAAc,cAAc,KAC5E;EACC;GACC;GACA;EACD;GACC;GACA;GACA,mBAAmB;EACpB;GACC;GACA;EACD;GACC;GACA;GACA;EACD;EACA;EACA;GACC;EACD;GACC,iBAAiB;GACjB;EACD;GACC;GACA,kBAAkB;GAClB;GACA,cAAc;GACd,qBAAqB;GACrB;GACA;GACA;GACA,gBAAgB;GAChB;GACA,mBAAmB;GACnB;GACA;GACA;GACA;EACD;EACA,SAAS;EACT;GACC;GACA;GACA;GACA;GACA,iBAAiB;EAClB;GACC,qBAAqB;GACrB,sBAAsB;GACtB;GACA;GACA,sBAAsB;GACtB,mBAAmB;GACnB,iBAAiB;GACjB;GACA;GACA;EACD;GACC;GACA;GACA;EACD;GACC,iBAAiB;GACjB;;KAGE;EACJ,GAAG;EACH,GAAG;EACH,OAAO;EACP,QAAQ;;KAEJ;EAAe;EAAiB;;KAChC;EAAY;GAAe;;KAC3B,qBAAqB;EAAW;;KAChC,eAAe;EACnB;EACA;EACA,OAAO;EACP,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL;EACA,aAAa;EACb,WAAW;EACX;EACA;EACA;EACA;EACA,MAAM;EACN,IAAI;EACJ,IAAI;EACJ;EACA;;KAEI;EACJ,GAAG;EACH,GAAG;EACH,IAAI;EACJ,IAAI;EACJ,QAAQ;EACR,YAAY;EACZ;;UAES;EACT,GAAG;IACF;IACA;IACA;IACA;IACA;;EAED,SAAS;EACT,eAAe;IACd;IACA;IACA,QAAQ;IACR;;EAED,kBAAkB;IACjB;;EAED;IACC,IAAI;IACJ,IAAI;IACJ,GAAG;IACH;;EAED;IAAY;;EACZ;IACC,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ;;EAED,SAAS;IAAuB;IAAY;IAAa;;EACzD,eAAe;IACd;IACA;IACA;;EAED,qBAAqB;IAAuB;;EAC5C,aAAa;IACZ;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,kBAAkB;IACjB;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACA;IACA,eAAe;;EAEhB,mBAAmB;IAClB;IACA;IACA;IACA,kBAAkB;;EAEnB,mBAAmB;IAClB;IACA;IACA;IACA;IACA;;EAED;IAAkB;IAAiB;;EACnC,cAAc;IACb,IAAI;IACJ,IAAI;IACJ,cAAc;;EAEf,SAAS;EACT;IACC;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,SAAS;EACT,SAAS;EACT,SAAS;EACT,gBAAgB;IACf;IACA,cAAc;IACd;;EAED,SAAS,qBACR;IAAY;IAA6B,aAAa;;EACvD,SAAS;EACT;IAAe;;EACf,cAAc;IACb;IACA;IACA,QAAQ;;EAET,UAAU;IACT;IACA,IAAI;IACJ,IAAI;;EAEL;IAAgB;IAAW;IAAW;;EACtC,oBAAoB;IACnB;IACA;IACA;IACA;IACA,kBAAkB;;EAEnB;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,QAAQ;IAAuB;;EAC/B,cAAc;IACb,eAAe;IACf;IACA;IACA;IACA;;EAED,QAAQ;IAAW;IAAqB;;EACxC,eAAe;EACf,OAAO,SACN;IACC;IACA,aAAa;IACb;;EAEF;IACC,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ;;EAED,gBAAgB;IACf,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ;IACA;IACA;;EAED,QAAQ;IACP,MAAM;IACN,MAAM;IACN,aAAa;IACb,cAAc;IACd;IACA,QAAQ;;EAET,MAAM;IAAW;IAAmB;;EACpC,OAAO;EACP;IAAQ;IAAW;;EACnB,SAAS,SACR,aACA;IACC;IACA;IACA;;EAEF;IAAW;IAAgB;;EAC3B,UAAU;EACV,gBAAgB;IACf,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ;IACA;IACA;;EAED,MAAM;IAAW,IAAI;IAAgB,IAAI;IAAgB;;EACzD,QAAQ;IAAY;IAAc,aAAa;;EAC/C,KAAK;EACL;IAAQ,QAAQ;;EAChB;IAAS;IAAc;IAAe;;EACtC,KAAK,SAAS;IAAe;;EAC7B,QAAQ,SAAS;IAAe,MAAM;IAAgB,MAAM;;EAC5D,MAAM;EACN,UAAU;IACT,aAAa;IACb;IACA;IACA;IACA,YAAY;IACZ;;EAED,OAAO;EACP,KAAK,SAAS;EACd,MAAM;IAAe;;;KAEV,0BACV,aAAa,uBAAuB,cAAc,qBAAqB,SACtE,kBAAkB,mBAAmB,WAAW,iBAAiB;;;KAKxD,iBAAiB,wBAC5B,KAAK,4BAA4B;cC93BrB,WAAQ;EAAa,WAAW;MAAU;iBACvC,IACf,MAAM,eACN,OAAO,uBACP,gBACE;cAMU,aAAI;cACJ,eAAM;;iBAGH,SACZ,UAAU,6BAA6B,0BACxC;kBAkBc;OACJ,UAAU;OACV,oBAAoB,oBAAoB;YACnC;IAChB;;YAEgB;IAChB;;;YAGgB,0BAA0B;KACzC,6BAA6B,eAAe"}
@@ -1,126 +0,0 @@
1
- import { transformSync, types } from "@babel/core";
2
- // src/compiler.ts
3
- function compile(code, filename) {
4
- const plugin = () => {
5
- let create;
6
- let merge;
7
- const generated = /* @__PURE__ */ new WeakSet();
8
- const components = /* @__PURE__ */ new Set();
9
- function name(node) {
10
- if (types.isJSXMemberExpression(node)) return types.memberExpression(types.isJSXIdentifier(node.object) ? node.object.name === `this` ? types.thisExpression() : types.identifier(node.object.name) : name(node.object), types.identifier(node.property.name));
11
- if (types.isJSXNamespacedName(node)) return types.stringLiteral(`${node.namespace.name}:${node.name.name}`);
12
- return /^[a-z]/.test(node.name) || node.name.includes(`-`) ? types.stringLiteral(node.name) : types.identifier(node.name);
13
- }
14
- function literal(node) {
15
- return types.isLiteral(node) && (!types.isTemplateLiteral(node) || node.expressions.length === 0);
16
- }
17
- function child(node) {
18
- return generated.has(node) || literal(node) || types.isFunction(node) ? node : types.arrowFunctionExpression([], node);
19
- }
20
- return { visitor: {
21
- ExportDefaultDeclaration(path) {
22
- if (types.isArrowFunctionExpression(path.node.declaration) || types.isFunctionExpression(path.node.declaration)) {
23
- const id = path.scope.generateUidIdentifier(`Component`);
24
- path.replaceWithMultiple([types.variableDeclaration(`const`, [types.variableDeclarator(id, path.node.declaration)]), types.exportDefaultDeclaration(id)]);
25
- }
26
- },
27
- Program: {
28
- enter(path) {
29
- create = path.scope.generateUidIdentifier(`spa`);
30
- merge = path.scope.generateUidIdentifier(`props`);
31
- },
32
- exit(path) {
33
- path.unshiftContainer(`body`, types.importDeclaration([types.importSpecifier(create, types.identifier(`jsx`)), types.importSpecifier(merge, types.identifier(`merge`))], types.stringLiteral(`@atom.io/spa/jsx-runtime`)));
34
- for (const component of components) path.pushContainer(`body`, types.expressionStatement(types.assignmentExpression(`=`, types.memberExpression(types.identifier(component), types.identifier(`spa`)), types.booleanLiteral(true))));
35
- }
36
- },
37
- "JSXElement|JSXFragment": { exit(path) {
38
- const node = path.node;
39
- const chunks = [];
40
- let properties = [];
41
- const flush = () => {
42
- if (properties.length) {
43
- chunks.push(types.objectExpression(properties));
44
- properties = [];
45
- }
46
- };
47
- if (types.isJSXElement(node)) for (const attribute of node.openingElement.attributes) {
48
- if (types.isJSXSpreadAttribute(attribute)) {
49
- flush();
50
- chunks.push(types.arrowFunctionExpression([], attribute.argument));
51
- continue;
52
- }
53
- const key = types.isJSXNamespacedName(attribute.name) ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name;
54
- const expression = attribute.value == null ? types.booleanLiteral(true) : types.isJSXExpressionContainer(attribute.value) ? attribute.value.expression : attribute.value;
55
- properties.push(key === `key` || literal(expression) || types.isFunction(expression) ? types.objectProperty(types.stringLiteral(key), expression) : types.objectMethod(`get`, types.stringLiteral(key), [], types.blockStatement([types.returnStatement(expression)])));
56
- }
57
- const children = types.react.buildChildren(node).map((value) => child(value));
58
- if (children.length) properties.push(types.objectProperty(types.identifier(`children`), children.length === 1 ? children[0] : types.arrayExpression(children)));
59
- flush();
60
- const props = chunks.length > 1 || types.isArrowFunctionExpression(chunks[0]) ? types.callExpression(merge, chunks) : chunks[0] ?? types.objectExpression([]);
61
- const result = types.callExpression(create, [types.isJSXElement(node) ? name(node.openingElement.name) : types.nullLiteral(), props]);
62
- generated.add(result);
63
- let fn = path.findParent((parent) => parent.isFunction());
64
- while (fn?.findParent((parent) => parent.isFunction())) fn = fn.findParent((parent) => parent.isFunction());
65
- if (fn) {
66
- if (fn.isFunctionDeclaration() && fn.node.id) components.add(fn.node.id.name);
67
- else if (fn.parentPath.isVariableDeclarator() && types.isIdentifier(fn.parentPath.node.id)) components.add(fn.parentPath.node.id.name);
68
- else if (fn.parentPath.isExportDefaultDeclaration() && types.isFunctionDeclaration(fn.node)) {
69
- fn.node.id = path.scope.generateUidIdentifier(`Component`);
70
- components.add(fn.node.id.name);
71
- }
72
- }
73
- path.replaceWith(result);
74
- } }
75
- } };
76
- };
77
- const result = transformSync(code, {
78
- filename,
79
- babelrc: false,
80
- configFile: false,
81
- sourceMaps: true,
82
- parserOpts: { plugins: [`jsx`, `typescript`] },
83
- plugins: [plugin]
84
- });
85
- return {
86
- code: result.code,
87
- map: result.map
88
- };
89
- }
90
- // src/vite.ts
91
- function spa(options = {}) {
92
- const include = options.include ?? /\.[jt]sx$/;
93
- const matches = (id) => {
94
- include.lastIndex = 0;
95
- return !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0]);
96
- };
97
- return {
98
- name: `spa`,
99
- enforce: `pre`,
100
- config() {
101
- return {
102
- resolve: { dedupe: [`@atom.io/spa`, `atom.io`] },
103
- optimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] }
104
- };
105
- },
106
- configEnvironment: {
107
- order: `post`,
108
- handler(_name, config) {
109
- if (config.optimizeDeps?.include) config.optimizeDeps.include = config.optimizeDeps.include.filter((id) => !/^(@atom\.io\/spa|atom\.io)(\/|$)/.test(id));
110
- }
111
- },
112
- transform(code, id) {
113
- if (!matches(id)) return;
114
- return compile(code, id);
115
- },
116
- handleHotUpdate({ server, file }) {
117
- if (matches(file)) {
118
- server.ws.send({ type: `full-reload` });
119
- return [];
120
- }
121
- }
122
- };
123
- }
124
- export { spa as t };
125
-
126
- //# sourceMappingURL=vite-CQchIQ_-.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-CQchIQ_-.js","names":["t"],"sources":["../src/compiler.ts","../src/vite.ts"],"sourcesContent":["import type { PluginObject } from \"@babel/core\"\nimport { transformSync, types as t } from \"@babel/core\"\n\nexport function compile(\n\tcode: string,\n\tfilename: string,\n): { code: string; map: any } {\n\tconst plugin = (): PluginObject => {\n\t\tlet create: t.Identifier\n\t\tlet merge: t.Identifier\n\t\tconst generated = new WeakSet<object>()\n\t\tconst components = new Set<string>()\n\t\tfunction name(\n\t\t\tnode: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n\t\t): t.Expression {\n\t\t\tif (t.isJSXMemberExpression(node))\n\t\t\t\treturn t.memberExpression(\n\t\t\t\t\tt.isJSXIdentifier(node.object)\n\t\t\t\t\t\t? node.object.name === `this`\n\t\t\t\t\t\t\t? t.thisExpression()\n\t\t\t\t\t\t\t: t.identifier(node.object.name)\n\t\t\t\t\t\t: name(node.object),\n\t\t\t\t\tt.identifier(node.property.name),\n\t\t\t\t)\n\t\t\tif (t.isJSXNamespacedName(node))\n\t\t\t\treturn t.stringLiteral(`${node.namespace.name}:${node.name.name}`)\n\t\t\treturn /^[a-z]/.test(node.name) || node.name.includes(`-`)\n\t\t\t\t? t.stringLiteral(node.name)\n\t\t\t\t: t.identifier(node.name)\n\t\t}\n\t\tfunction literal(node: t.Node): boolean {\n\t\t\treturn (\n\t\t\t\tt.isLiteral(node) &&\n\t\t\t\t(!t.isTemplateLiteral(node) || node.expressions.length === 0)\n\t\t\t)\n\t\t}\n\t\tfunction child(node: t.Expression): t.Expression {\n\t\t\treturn generated.has(node) || literal(node) || t.isFunction(node)\n\t\t\t\t? node\n\t\t\t\t: t.arrowFunctionExpression([], node)\n\t\t}\n\t\treturn {\n\t\t\tvisitor: {\n\t\t\t\tExportDefaultDeclaration(path) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tt.isArrowFunctionExpression(path.node.declaration) ||\n\t\t\t\t\t\tt.isFunctionExpression(path.node.declaration)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\tpath.replaceWithMultiple([\n\t\t\t\t\t\t\tt.variableDeclaration(`const`, [\n\t\t\t\t\t\t\t\tt.variableDeclarator(id, path.node.declaration),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\tt.exportDefaultDeclaration(id),\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tProgram: {\n\t\t\t\t\tenter(path) {\n\t\t\t\t\t\tcreate = path.scope.generateUidIdentifier(`spa`)\n\t\t\t\t\t\tmerge = path.scope.generateUidIdentifier(`props`)\n\t\t\t\t\t},\n\t\t\t\t\texit(path) {\n\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\tt.importDeclaration(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tt.importSpecifier(create, t.identifier(`jsx`)),\n\t\t\t\t\t\t\t\t\tt.importSpecifier(merge, t.identifier(`merge`)),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tt.stringLiteral(`@atom.io/spa/jsx-runtime`),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tfor (const component of components)\n\t\t\t\t\t\t\tpath.pushContainer(\n\t\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\t\tt.expressionStatement(\n\t\t\t\t\t\t\t\t\tt.assignmentExpression(\n\t\t\t\t\t\t\t\t\t\t`=`,\n\t\t\t\t\t\t\t\t\t\tt.memberExpression(\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(component),\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(`spa`),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\tt.booleanLiteral(true),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t\"JSXElement|JSXFragment\": {\n\t\t\t\t\texit(path: any) {\n\t\t\t\t\t\tconst node = path.node as t.JSXElement | t.JSXFragment\n\t\t\t\t\t\tconst chunks: t.Expression[] = []\n\t\t\t\t\t\tlet properties: (t.ObjectProperty | t.ObjectMethod)[] = []\n\t\t\t\t\t\tconst flush = () => {\n\t\t\t\t\t\t\tif (properties.length) {\n\t\t\t\t\t\t\t\tchunks.push(t.objectExpression(properties))\n\t\t\t\t\t\t\t\tproperties = []\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (t.isJSXElement(node))\n\t\t\t\t\t\t\tfor (const attribute of node.openingElement.attributes) {\n\t\t\t\t\t\t\t\tif (t.isJSXSpreadAttribute(attribute)) {\n\t\t\t\t\t\t\t\t\tflush()\n\t\t\t\t\t\t\t\t\tchunks.push(t.arrowFunctionExpression([], attribute.argument))\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst key = t.isJSXNamespacedName(attribute.name)\n\t\t\t\t\t\t\t\t\t? `${attribute.name.namespace.name}:${attribute.name.name.name}`\n\t\t\t\t\t\t\t\t\t: attribute.name.name\n\t\t\t\t\t\t\t\tconst value =\n\t\t\t\t\t\t\t\t\tattribute.value == null\n\t\t\t\t\t\t\t\t\t\t? t.booleanLiteral(true)\n\t\t\t\t\t\t\t\t\t\t: t.isJSXExpressionContainer(attribute.value)\n\t\t\t\t\t\t\t\t\t\t\t? attribute.value.expression\n\t\t\t\t\t\t\t\t\t\t\t: attribute.value\n\t\t\t\t\t\t\t\t// The parser rejects empty attribute expressions.\n\t\t\t\t\t\t\t\tconst expression = value as t.Expression\n\t\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\t\tkey === `key` ||\n\t\t\t\t\t\t\t\t\t\tliteral(expression) ||\n\t\t\t\t\t\t\t\t\t\tt.isFunction(expression)\n\t\t\t\t\t\t\t\t\t\t? t.objectProperty(t.stringLiteral(key), expression)\n\t\t\t\t\t\t\t\t\t\t: t.objectMethod(\n\t\t\t\t\t\t\t\t\t\t\t\t`get`,\n\t\t\t\t\t\t\t\t\t\t\t\tt.stringLiteral(key),\n\t\t\t\t\t\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\t\t\t\t\tt.blockStatement([t.returnStatement(expression)]),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tconst children = t.react\n\t\t\t\t\t\t\t.buildChildren(node)\n\t\t\t\t\t\t\t.map((value) => child(value as t.Expression))\n\t\t\t\t\t\tif (children.length)\n\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\tt.objectProperty(\n\t\t\t\t\t\t\t\t\tt.identifier(`children`),\n\t\t\t\t\t\t\t\t\tchildren.length === 1\n\t\t\t\t\t\t\t\t\t\t? children[0]\n\t\t\t\t\t\t\t\t\t\t: t.arrayExpression(children),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tflush()\n\t\t\t\t\t\tconst props =\n\t\t\t\t\t\t\tchunks.length > 1 || t.isArrowFunctionExpression(chunks[0])\n\t\t\t\t\t\t\t\t? t.callExpression(merge, chunks)\n\t\t\t\t\t\t\t\t: (chunks[0] ?? t.objectExpression([]))\n\t\t\t\t\t\tconst result = t.callExpression(create, [\n\t\t\t\t\t\t\tt.isJSXElement(node)\n\t\t\t\t\t\t\t\t? name(node.openingElement.name)\n\t\t\t\t\t\t\t\t: t.nullLiteral(),\n\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t])\n\t\t\t\t\t\tgenerated.add(result)\n\t\t\t\t\t\tlet fn = path.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\twhile (fn?.findParent((parent: any) => parent.isFunction()))\n\t\t\t\t\t\t\tfn = fn.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\tif (fn) {\n\t\t\t\t\t\t\tif (fn.isFunctionDeclaration() && fn.node.id)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isVariableDeclarator() &&\n\t\t\t\t\t\t\t\tt.isIdentifier(fn.parentPath.node.id)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tcomponents.add(fn.parentPath.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isExportDefaultDeclaration() &&\n\t\t\t\t\t\t\t\tt.isFunctionDeclaration(fn.node)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tfn.node.id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpath.replaceWith(result)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\tconst result = transformSync(code, {\n\t\tfilename,\n\t\tbabelrc: false,\n\t\tconfigFile: false,\n\t\tsourceMaps: true,\n\t\tparserOpts: { plugins: [`jsx`, `typescript`] },\n\t\tplugins: [plugin],\n\t})!\n\treturn { code: result.code!, map: result.map }\n}\n","import type { Plugin } from \"vite\"\n\nimport { compile } from \"./compiler.ts\"\n\nexport interface SpaPluginOptions {\n\tinclude?: RegExp\n}\nexport default function spa(options: SpaPluginOptions = {}): Plugin {\n\tconst include = options.include ?? /\\.[jt]sx$/\n\tconst matches = (id: string): boolean => {\n\t\tinclude.lastIndex = 0\n\t\treturn !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0])\n\t}\n\treturn {\n\t\tname: `spa`,\n\t\tenforce: `pre`,\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\tresolve: { dedupe: [`@atom.io/spa`, `atom.io`] },\n\t\t\t\toptimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] },\n\t\t\t}\n\t\t},\n\t\tconfigEnvironment: {\n\t\t\torder: `post`,\n\t\t\thandler(_name, config) {\n\t\t\t\t// Astro and its adapters force renderer entries into the optimizer.\n\t\t\t\t// Vite processes explicit includes even when their package is excluded.\n\t\t\t\t// Keep the renderer, hooks, and store in one unbundled module graph.\n\t\t\t\tif (config.optimizeDeps?.include) {\n\t\t\t\t\tconfig.optimizeDeps.include = config.optimizeDeps.include.filter(\n\t\t\t\t\t\t(id) => !/^(@atom\\.io\\/spa|atom\\.io)(\\/|$)/.test(id),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\ttransform(code, id) {\n\t\t\tif (!matches(id)) return\n\t\t\treturn compile(code, id)\n\t\t},\n\t\t// A reload disposes the whole document. No state-preserving HMR is promised.\n\t\thandleHotUpdate({ server, file }) {\n\t\t\tif (matches(file)) {\n\t\t\t\tserver.ws.send({ type: `full-reload` })\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;AAGA,SAAgB,QACf,MACA,UAC6B;CAC7B,MAAM,eAA6B;EAClC,IAAI;EACJ,IAAI;EACJ,MAAM,4BAAY,IAAI,QAAgB;EACtC,MAAM,6BAAa,IAAI,IAAY;EACnC,SAAS,KACR,MACe;GACf,IAAIA,MAAE,sBAAsB,IAAI,GAC/B,OAAOA,MAAE,iBACRA,MAAE,gBAAgB,KAAK,MAAM,IAC1B,KAAK,OAAO,SAAS,SACpBA,MAAE,eAAe,IACjBA,MAAE,WAAW,KAAK,OAAO,IAAI,IAC9B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