@atom.io/spa 0.0.0 → 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 +7 -4
  6. package/dist/astro-client.js.map +1 -1
  7. package/dist/astro-server.js +4 -3
  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 +7 -4
  20. package/dist/development/astro-client.js.map +1 -1
  21. package/dist/development/astro-server.js +4 -3
  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 +17 -7
  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 +17 -7
  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 +176 -131
  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 -177
  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 +21 -13
  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-BadrFSIM.js +0 -126
  106. package/dist/development/vite-BadrFSIM.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-BadrFSIM.js +0 -126
  112. package/dist/vite-BadrFSIM.js.map +0 -1
package/src/three.ts ADDED
@@ -0,0 +1,350 @@
1
+ import { fail, owner } from "./core.ts"
2
+ import type { ThreeEventAttributes, ThreeEventHandler } from "./three-events.ts"
3
+ import { createThreeEvents, forgetThree, listenThree } from "./three-events.ts"
4
+
5
+ export type {
6
+ ThreeEventAttributes,
7
+ ThreeEventHandler,
8
+ ThreeEventManager,
9
+ ThreePointerEvent,
10
+ } from "./three-events.ts"
11
+ export { createThreeEvents } from "./three-events.ts"
12
+ import * as THREE from "three"
13
+
14
+ import type { Child, VNode } from "./index.ts"
15
+ import { onCleanup, onMount } from "./index.ts"
16
+ import type { CapabilityAttributes } from "./jsx-runtime.ts"
17
+ import { jsx } from "./jsx-runtime.ts"
18
+ import {
19
+ bindScene,
20
+ createSceneRenderer,
21
+ onSceneFrame,
22
+ sceneComponent,
23
+ } from "./renderer.ts"
24
+
25
+ type Resource = THREE.Object3D | THREE.BufferGeometry | THREE.Material
26
+ type Vector3 = readonly [number, number, number]
27
+ export interface ObjectProps<N extends THREE.Object3D = THREE.Object3D>
28
+ extends CapabilityAttributes<`three`>, ThreeEventAttributes<N> {
29
+ children?: Child
30
+ position?: Vector3
31
+ rotation?: Vector3
32
+ scale?: Vector3 | number
33
+ visible?: boolean
34
+ name?: string
35
+ ref?: (object: N | null) => void
36
+ }
37
+ const constructors = {
38
+ Group: THREE.Group,
39
+ Mesh: THREE.Mesh,
40
+ PerspectiveCamera: THREE.PerspectiveCamera,
41
+ AmbientLight: THREE.AmbientLight,
42
+ DirectionalLight: THREE.DirectionalLight,
43
+ BoxGeometry: THREE.BoxGeometry,
44
+ SphereGeometry: THREE.SphereGeometry,
45
+ PlaneGeometry: THREE.PlaneGeometry,
46
+ MeshStandardMaterial: THREE.MeshStandardMaterial,
47
+ MeshBasicMaterial: THREE.MeshBasicMaterial,
48
+ MeshNormalMaterial: THREE.MeshNormalMaterial,
49
+ }
50
+ const meshDefaults = new WeakMap<
51
+ THREE.Mesh,
52
+ { geometry: THREE.BufferGeometry; material: THREE.Material }
53
+ >()
54
+ const borrowedMeshDefaults = new WeakMap<
55
+ THREE.Mesh,
56
+ {
57
+ geometry: THREE.BufferGeometry
58
+ material: THREE.Material | THREE.Material[]
59
+ }
60
+ >()
61
+ const constructorArgs = new WeakMap<Resource, unknown[]>()
62
+ const eventHandlers = new WeakMap<Resource, Map<string, () => void>>()
63
+ const defaults = new WeakMap<Resource, Map<string, any>>()
64
+ function writeProperty(node: Resource, key: string, value: any): void {
65
+ const target = node as any
66
+ if (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)
67
+ const current = target[key]
68
+ if (current?.isColor) current.set(value)
69
+ else if (Array.isArray(value) && typeof current?.set === `function`)
70
+ current.set(...value)
71
+ else if (key === `scale` && typeof value === `number`) current.setScalar(value)
72
+ else if (current?.copy && value?.constructor === current.constructor)
73
+ current.copy(value)
74
+ else target[key] = value
75
+ if (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix()
76
+ }
77
+ const renderer = createSceneRenderer<Resource>({
78
+ target(node) {
79
+ return {
80
+ kind: `three`,
81
+ node,
82
+ ...(node instanceof THREE.Object3D
83
+ ? {
84
+ listen: (type: string, listener: () => void) =>
85
+ listenThree(node, type, listener),
86
+ }
87
+ : {}),
88
+ read(key) {
89
+ const value = (node as any)[key]
90
+ return value?.isColor
91
+ ? value.getStyle()
92
+ : value?.isVector3 || value?.isEuler
93
+ ? [value.x, value.y, value.z]
94
+ : value
95
+ },
96
+ write(key, value) {
97
+ writeProperty(node, key, value)
98
+ },
99
+ }
100
+ },
101
+ create(type, props) {
102
+ const Constructor = constructors[type as keyof typeof constructors]
103
+ if (!Constructor) throw new Error(`spa/three: unknown node ${type}`)
104
+ const node = new (Constructor as any)(...(props[`args`] ?? [])) as Resource
105
+ // Mesh's implicit resources are replaced by owned JSX resources below.
106
+ if (node instanceof THREE.Mesh)
107
+ meshDefaults.set(node, {
108
+ geometry: node.geometry,
109
+ material: node.material as THREE.Material,
110
+ })
111
+ constructorArgs.set(node, [...(props[`args`] ?? [])])
112
+ defaults.set(node, new Map())
113
+ eventHandlers.set(node, new Map())
114
+ return node
115
+ },
116
+ update(node, props, previous) {
117
+ if (!equalArgs(constructorArgs.get(node)!, props[`args`]))
118
+ throw new Error(
119
+ `spa/three: change the component key to replace constructor args`,
120
+ )
121
+ const target = node as any
122
+ const saved = defaults.get(node)!
123
+ for (const key of new Set([
124
+ ...Object.keys(previous),
125
+ ...Object.keys(props),
126
+ ])) {
127
+ if (
128
+ /^(key|children|ref|args)$/.test(key) ||
129
+ Object.is(props[key], previous[key])
130
+ )
131
+ continue
132
+ if (key.startsWith(`on`)) {
133
+ if (
134
+ !(node instanceof THREE.Object3D) ||
135
+ !/^on(Pointer(Down|Up|Move|Enter|Leave|Over|Out|Cancel)|Click)$/.test(
136
+ key,
137
+ )
138
+ )
139
+ throw new Error(`spa/three: unknown event ${key}`)
140
+ const handlers = eventHandlers.get(node)!
141
+ handlers.get(key)?.()
142
+ handlers.delete(key)
143
+ if (props[key])
144
+ handlers.set(
145
+ key,
146
+ listenThree(
147
+ node,
148
+ key.slice(2).toLowerCase(),
149
+ props[key] as ThreeEventHandler,
150
+ ),
151
+ )
152
+ continue
153
+ }
154
+ if (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)
155
+ const current = target[key]
156
+ if (!saved.has(key))
157
+ saved.set(key, current?.clone ? current.clone() : current)
158
+ const value = props[key] === undefined ? saved.get(key) : props[key]
159
+ writeProperty(node, key, value)
160
+ }
161
+ if (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix()
162
+ },
163
+ children(parent, children) {
164
+ if (!(parent instanceof THREE.Object3D)) {
165
+ if (children.length)
166
+ throw new Error(`spa/three: resources cannot contain children`)
167
+ return
168
+ }
169
+ const objects = children.filter(
170
+ (child): child is THREE.Object3D => child instanceof THREE.Object3D,
171
+ )
172
+ for (const child of [...parent.children])
173
+ if (!objects.includes(child)) parent.remove(child)
174
+ for (const child of objects) if (child.parent !== parent) parent.add(child)
175
+ parent.children.splice(0, parent.children.length, ...objects)
176
+ const resources = children.filter(
177
+ (child) => !(child instanceof THREE.Object3D),
178
+ )
179
+ if (resources.length && !(parent instanceof THREE.Mesh))
180
+ throw new Error(`spa/three: geometry and material require a Mesh parent`)
181
+ if (parent instanceof THREE.Mesh) {
182
+ const geometries = resources.filter(
183
+ (child) => child instanceof THREE.BufferGeometry,
184
+ )
185
+ const materials = resources.filter(
186
+ (child) => child instanceof THREE.Material,
187
+ )
188
+ if (geometries.length > 1 || materials.length > 1)
189
+ throw new Error(
190
+ `spa/three: each Mesh accepts one geometry and one material`,
191
+ )
192
+ const owned = meshDefaults.get(parent)
193
+ let baseline = owned ?? borrowedMeshDefaults.get(parent)
194
+ if (!baseline) {
195
+ baseline = { geometry: parent.geometry, material: parent.material }
196
+ borrowedMeshDefaults.set(parent, baseline)
197
+ }
198
+ parent.geometry = geometries[0] ?? baseline.geometry
199
+ parent.material = materials[0] ?? baseline.material
200
+ if (!owned && children.length === 0) borrowedMeshDefaults.delete(parent)
201
+ }
202
+ },
203
+ destroy(node) {
204
+ eventHandlers.get(node)!.clear()
205
+ if (node instanceof THREE.Object3D) {
206
+ try {
207
+ forgetThree(node)
208
+ } finally {
209
+ node.removeFromParent()
210
+ if (node instanceof THREE.Mesh) {
211
+ const owned = meshDefaults.get(node)!
212
+ owned.geometry.dispose()
213
+ owned.material.dispose()
214
+ }
215
+ }
216
+ } else node.dispose()
217
+ },
218
+ })
219
+ function equalArgs(a: unknown[], b: unknown[] = []): boolean {
220
+ return (
221
+ a.length === b.length &&
222
+ a.every((value, index) => Object.is(value, b[index]))
223
+ )
224
+ }
225
+
226
+ export interface CanvasProps {
227
+ children?: Child
228
+ width?: number
229
+ height?: number
230
+ camera?: THREE.Camera
231
+ onFrame?: (state: {
232
+ scene: THREE.Scene
233
+ camera: THREE.Camera
234
+ renderer: THREE.WebGLRenderer
235
+ delta: number
236
+ time: number
237
+ }) => void
238
+ }
239
+ /** Browser-only scene boundary. The camera prop is borrowed and never disposed. */
240
+ export function Canvas(props: CanvasProps): VNode {
241
+ let canvas: HTMLCanvasElement | null = null
242
+ onMount(() => {
243
+ const webgl = new THREE.WebGLRenderer({ canvas: canvas!, antialias: true })
244
+ onCleanup(() => {
245
+ webgl.dispose()
246
+ })
247
+ const scene = new THREE.Scene()
248
+ const camera = new THREE.PerspectiveCamera(50, 1, 0.1, 1000)
249
+ camera.position.z = 5
250
+ bindScene(
251
+ () => [props.width ?? 800, props.height ?? 600] as const,
252
+ ([width, height]) => {
253
+ webgl.setSize(width, height)
254
+ camera.aspect = width / height
255
+ camera.updateProjectionMatrix()
256
+ },
257
+ )
258
+ renderer.mount(() => props.children, scene)
259
+ const root = owner!._root
260
+ const events = createThreeEvents(
261
+ canvas!,
262
+ scene,
263
+ () => props.camera ?? camera,
264
+ (error) => {
265
+ try {
266
+ fail(root, error)
267
+ } catch (failure) {
268
+ root.error(failure)
269
+ }
270
+ },
271
+ )
272
+ onCleanup(() => {
273
+ events.dispose()
274
+ })
275
+ let last: number | undefined
276
+ onSceneFrame((time) => {
277
+ const active = props.camera ?? camera
278
+ const delta = last === undefined ? 0 : (time - last) / 1000
279
+ last = time
280
+ props.onFrame?.({
281
+ scene,
282
+ camera: active,
283
+ renderer: webgl,
284
+ delta,
285
+ time: time / 1000,
286
+ })
287
+ events.update()
288
+ webgl.render(scene, active)
289
+ })
290
+ })
291
+ return jsx(`canvas`, {
292
+ ref: (element: HTMLCanvasElement | null) => {
293
+ canvas = element
294
+ },
295
+ })
296
+ }
297
+ export const Group = sceneComponent<ObjectProps>(`Group`)
298
+ export const Mesh = sceneComponent<ObjectProps<THREE.Mesh>>(`Mesh`)
299
+ export const PerspectiveCamera = sceneComponent<
300
+ ObjectProps<THREE.PerspectiveCamera> & {
301
+ args?: ConstructorParameters<typeof THREE.PerspectiveCamera>
302
+ fov?: number
303
+ aspect?: number
304
+ near?: number
305
+ far?: number
306
+ }
307
+ >(`PerspectiveCamera`)
308
+ export const AmbientLight = sceneComponent<
309
+ ObjectProps<THREE.Light> & {
310
+ color?: THREE.ColorRepresentation
311
+ intensity?: number
312
+ }
313
+ >(`AmbientLight`)
314
+ export const DirectionalLight = sceneComponent<
315
+ ObjectProps<THREE.Light> & {
316
+ color?: THREE.ColorRepresentation
317
+ intensity?: number
318
+ }
319
+ >(`DirectionalLight`)
320
+ export const BoxGeometry = sceneComponent<{
321
+ args?: ConstructorParameters<typeof THREE.BoxGeometry>
322
+ ref?: (node: THREE.BoxGeometry | null) => void
323
+ }>(`BoxGeometry`)
324
+ export const SphereGeometry = sceneComponent<{
325
+ args?: ConstructorParameters<typeof THREE.SphereGeometry>
326
+ ref?: (node: THREE.SphereGeometry | null) => void
327
+ }>(`SphereGeometry`)
328
+ export const PlaneGeometry = sceneComponent<{
329
+ args?: ConstructorParameters<typeof THREE.PlaneGeometry>
330
+ ref?: (node: THREE.PlaneGeometry | null) => void
331
+ }>(`PlaneGeometry`)
332
+ export const MeshStandardMaterial = sceneComponent<
333
+ THREE.MeshStandardMaterialParameters &
334
+ CapabilityAttributes<`three`> & {
335
+ ref?: (node: THREE.MeshStandardMaterial | null) => void
336
+ }
337
+ >(`MeshStandardMaterial`)
338
+ export const MeshBasicMaterial = sceneComponent<
339
+ THREE.MeshBasicMaterialParameters &
340
+ CapabilityAttributes<`three`> & {
341
+ ref?: (node: THREE.MeshBasicMaterial | null) => void
342
+ }
343
+ >(`MeshBasicMaterial`)
344
+ export const MeshNormalMaterial = sceneComponent<
345
+ THREE.MeshNormalMaterialParameters &
346
+ CapabilityAttributes<`three`> & {
347
+ ref?: (node: THREE.MeshNormalMaterial | null) => void
348
+ }
349
+ >(`MeshNormalMaterial`)
350
+ export { renderer as threeRenderer }
@@ -1 +0,0 @@
1
- {"version":3,"file":"astro-shared-DkZaqX7L.d.ts","names":[],"sources":["../src/astro-shared.ts"],"mappings":";;UAMiB;;WAEP;WACA,QAAQ;EACjB,UAAU;;EAEV,IAAI,GAAG,cAAc,kBAAkB,IAAI;;UAE3B;;EAEhB,aAAa;;EAEb,SAAS;;EAET,QAAQ;;EAER,UAAU;;KAEC,kBAAkB,IAAI,wBACjC,OAAO,GACP,SAAS,sBACL,YAAY,QAAQ;KACb,sBAAsB,IAAI,wBACrC,OAAO,WACP,OAAO,GACP,SAAS,6BACE;KACA,OAAO,WAAW,UAAU;EACvC;;EAEA;EACA,cAAc,kBAAkB;EAChC,eAAe,sBAAsB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-BhiA9fFi.d.ts","names":[],"sources":["../src/core.ts"],"mappings":";;;KAgCY;UAGK,SAAS;MACrB;;KAGO,UAAU,YAAY,OAAO,MAAM;UAC9B;EAChB,eAAe;EACf,OAAO;;KAEI,QACT,yEAOS,UACT,SAAS;UACK;EAChB,QAAQ;EACR;EACA,WAAW;;;iBA8HI,YAAY;iBAGZ,UAAU,SAAS;iBAGnB,QAAQ,KAAK;iBASb;;iBAuDA,SAAS,GAAG,WAC3B,OAAO,cAAc,QAAQ,KAC3B,SAAS,OAAO,IAAI;iBACP,SAAS,GAAG,UAAU,WAAW,WAChD,QAAQ,oBAAoB,GAAG,GAAG,IAClC,KAAK,QAAQ,KACX,SAAS,OAAO,IAAI;iBAYP,UAAU,GACzB,OAAO,cAAc,gBAClB,OAAO,IAAI,OAAO;iBACN,UAAU,GAAG,UAAU,WACtC,QAAQ,oBAAoB,GAAG,SAC/B,KAAK,QAAQ,MACV,OAAO,IAAI,OAAO;iBAQN,eAAe,cAAc,qBAC5C,OAAO,iBAAiB,SAClB,MAAM,WAAW,OAAO,WAAW;iBAK1B,OAAO,UAAU,SAChC,OAAO,iBAAiB,aACrB,SAAS;iBACG,OAAO,UAAU,SAAS,UAAU,WACnD,QAAQ,uBAAuB,UAAU,IACzC,KAAK,QAAQ,MACV,SAAS;UAuBI;EAChB;EACA;EACA;EACA;EACA;EACA,kBAAkB;EAClB,kBAAkB;;iBAEH,YAAY,UAAU,oBACrC,OAAO,cAAc,KACnB,SAAS;iBACI,YAAY,UAAU,WAAW,UAAU,oBAC1D,QAAQ,oBAAoB,GAAG,IAC/B,KAAK,QAAQ,KACX,SAAS"}
@@ -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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B,MAAM,QAAQ,MAAO,MAAM;CAC3B,IAAI,MAAM,SAAS,mBAClB,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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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;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;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Q,MACX,MAAM,IAAI,MACa,yBACvB;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.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.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.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-BadrFSIM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-BadrFSIM.js","names":["t"],"sources":["../../src/compiler.ts","../../src/vite.ts"],"sourcesContent":["import type { PluginObj } 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 = (): PluginObj => {\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\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.node.id) components.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,eAA0B;EAC/B,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;IAC9B,IACCA,MAAE,0BAA0B,KAAK,KAAK,WAAW,KACjDA,MAAE,qBAA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