@atom.io/spa 0.0.4 → 0.0.6

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 (151) hide show
  1. package/README.md +224 -105
  2. package/README.mdx +87 -20
  3. package/dist/astro-application.d.ts +1 -1
  4. package/dist/astro-client.d.ts +3 -2
  5. package/dist/astro-client.d.ts.map +1 -1
  6. package/dist/astro-client.js +9 -8
  7. package/dist/astro-client.js.map +1 -1
  8. package/dist/astro-request-DRKvDjsO.js.map +1 -1
  9. package/dist/astro-resumability-client.d.ts +10 -0
  10. package/dist/astro-resumability-client.d.ts.map +1 -0
  11. package/dist/astro-resumability-client.js +29 -0
  12. package/dist/astro-resumability-client.js.map +1 -0
  13. package/dist/astro-resumability-server.d.ts +3 -0
  14. package/dist/astro-resumability-server.d.ts.map +1 -0
  15. package/dist/astro-resumability-server.js +7 -0
  16. package/dist/astro-resumability-server.js.map +1 -0
  17. package/dist/astro-server.d.ts +3 -2
  18. package/dist/astro-server.d.ts.map +1 -1
  19. package/dist/astro-server.js +28 -9
  20. package/dist/astro-server.js.map +1 -1
  21. package/dist/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
  22. package/dist/astro-shared-83hxw7-M.js.map +1 -0
  23. package/dist/{astro-shared-CYSRrRr8.d.ts → astro-shared-B9wvGIkk.d.ts} +2 -2
  24. package/dist/{astro-shared-CYSRrRr8.d.ts.map → astro-shared-B9wvGIkk.d.ts.map} +1 -1
  25. package/dist/astro.d.ts +1 -1
  26. package/dist/astro.js +6 -8
  27. package/dist/astro.js.map +1 -1
  28. package/dist/{capabilities-D3HObAIy.d.ts → capabilities-_zOwNJ-2.d.ts} +12 -7
  29. package/dist/capabilities-_zOwNJ-2.d.ts.map +1 -0
  30. package/dist/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
  31. package/dist/capabilities-nOIitQ-_.js.map +1 -0
  32. package/dist/client.min.js +1 -1
  33. package/dist/{core-Bl1Ec1hY.js → core-DjFJ0aIJ.js} +4 -2
  34. package/dist/core-DjFJ0aIJ.js.map +1 -0
  35. package/dist/development/astro-client.js +9 -8
  36. package/dist/development/astro-client.js.map +1 -1
  37. package/dist/development/astro-request-DRKvDjsO.js.map +1 -1
  38. package/dist/development/astro-resumability-client.js +29 -0
  39. package/dist/development/astro-resumability-client.js.map +1 -0
  40. package/dist/development/astro-resumability-server.js +7 -0
  41. package/dist/development/astro-resumability-server.js.map +1 -0
  42. package/dist/development/astro-server.js +28 -9
  43. package/dist/development/astro-server.js.map +1 -1
  44. package/dist/development/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
  45. package/dist/development/astro-shared-83hxw7-M.js.map +1 -0
  46. package/dist/development/astro.js +6 -8
  47. package/dist/development/astro.js.map +1 -1
  48. package/dist/development/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
  49. package/dist/development/capabilities-nOIitQ-_.js.map +1 -0
  50. package/dist/development/{core-DZFaOyTO.js → core-DxPiKryn.js} +4 -2
  51. package/dist/development/core-DxPiKryn.js.map +1 -0
  52. package/dist/development/{dom-Dwa2SFTn.js → dom-BWy4dDss.js} +53 -20
  53. package/dist/development/dom-BWy4dDss.js.map +1 -0
  54. package/dist/development/floating.js +148 -0
  55. package/dist/development/floating.js.map +1 -0
  56. package/dist/development/index.js +3 -3
  57. package/dist/development/jsx-runtime.js +2 -2
  58. package/dist/development/jsx-runtime.js.map +1 -1
  59. package/dist/development/konva.js +2 -2
  60. package/dist/development/konva.js.map +1 -1
  61. package/dist/development/motion.js +7 -2
  62. package/dist/development/motion.js.map +1 -1
  63. package/dist/development/renderer.js +2 -2
  64. package/dist/development/renderer.js.map +1 -1
  65. package/dist/development/server-renderer-C7lGVhpo.js +90 -0
  66. package/dist/development/server-renderer-C7lGVhpo.js.map +1 -0
  67. package/dist/development/server.js +2 -83
  68. package/dist/development/server.js.map +1 -1
  69. package/dist/development/{src-BUtG4BgX.js → src-WSHJxR9b.js} +2 -2
  70. package/dist/development/{src-BUtG4BgX.js.map → src-WSHJxR9b.js.map} +1 -1
  71. package/dist/development/three.js +12 -9
  72. package/dist/development/three.js.map +1 -1
  73. package/dist/{vite-CSHoxzXU.js → development/vite-Bmyb6P5w.js} +32 -7
  74. package/dist/development/vite-Bmyb6P5w.js.map +1 -0
  75. package/dist/development/vite.js +1 -1
  76. package/dist/{dom-Cfj3GtQK.js → dom-BrPrxO97.js} +53 -20
  77. package/dist/dom-BrPrxO97.js.map +1 -0
  78. package/dist/floating.d.ts +16 -0
  79. package/dist/floating.d.ts.map +1 -0
  80. package/dist/floating.js +148 -0
  81. package/dist/floating.js.map +1 -0
  82. package/dist/{index-YRZ79lN5.d.ts → index-BFIjI7gF.d.ts} +5 -5
  83. package/dist/{index-YRZ79lN5.d.ts.map → index-BFIjI7gF.d.ts.map} +1 -1
  84. package/dist/index.d.ts +4 -4
  85. package/dist/index.js +3 -3
  86. package/dist/{jsx-runtime-Q-UBV97Y.d.ts → jsx-runtime-BhiCZOYZ.d.ts} +7 -7
  87. package/dist/{jsx-runtime-Q-UBV97Y.d.ts.map → jsx-runtime-BhiCZOYZ.d.ts.map} +1 -1
  88. package/dist/jsx-runtime.d.ts +1 -1
  89. package/dist/jsx-runtime.js +2 -2
  90. package/dist/jsx-runtime.js.map +1 -1
  91. package/dist/konva.d.ts +16 -16
  92. package/dist/konva.js +2 -2
  93. package/dist/konva.js.map +1 -1
  94. package/dist/motion.d.ts +1 -1
  95. package/dist/motion.d.ts.map +1 -1
  96. package/dist/motion.js +7 -2
  97. package/dist/motion.js.map +1 -1
  98. package/dist/renderer.d.ts +4 -4
  99. package/dist/renderer.d.ts.map +1 -1
  100. package/dist/renderer.js +2 -2
  101. package/dist/renderer.js.map +1 -1
  102. package/dist/server-renderer-D-uRg04V.js +90 -0
  103. package/dist/server-renderer-D-uRg04V.js.map +1 -0
  104. package/dist/server.d.ts +2 -2
  105. package/dist/server.d.ts.map +1 -1
  106. package/dist/server.js +2 -83
  107. package/dist/server.js.map +1 -1
  108. package/dist/size.json +16 -16
  109. package/dist/{src-DvkUMuNW.js → src-DWIqXCiz.js} +2 -2
  110. package/dist/{src-DvkUMuNW.js.map → src-DWIqXCiz.js.map} +1 -1
  111. package/dist/three.d.ts +17 -17
  112. package/dist/three.js +12 -9
  113. package/dist/three.js.map +1 -1
  114. package/dist/{development/vite-CSHoxzXU.js → vite-Bmyb6P5w.js} +32 -7
  115. package/dist/vite-Bmyb6P5w.js.map +1 -0
  116. package/dist/vite.js +1 -1
  117. package/package.json +39 -11
  118. package/src/astro-client.ts +17 -4
  119. package/src/astro-request.ts +1 -1
  120. package/src/astro-resumability-client.ts +40 -0
  121. package/src/astro-resumability-server.ts +7 -0
  122. package/src/astro-server.ts +58 -19
  123. package/src/astro-shared.ts +5 -2
  124. package/src/astro.ts +11 -3
  125. package/src/capabilities.ts +9 -4
  126. package/src/compiler.ts +28 -9
  127. package/src/core.ts +15 -10
  128. package/src/dom.ts +85 -50
  129. package/src/floating.ts +234 -0
  130. package/src/index.ts +2 -2
  131. package/src/jsx-runtime.ts +11 -7
  132. package/src/jsx-types.d.ts +2 -2
  133. package/src/konva.ts +3 -3
  134. package/src/motion.ts +11 -1
  135. package/src/presence.ts +1 -1
  136. package/src/renderer.ts +24 -18
  137. package/src/server-renderer.ts +162 -0
  138. package/src/server.ts +4 -153
  139. package/src/three-events.ts +14 -10
  140. package/src/three.ts +4 -4
  141. package/dist/astro-shared-BT45auwR.js.map +0 -1
  142. package/dist/capabilities-BkQ2i0vV.js.map +0 -1
  143. package/dist/capabilities-D3HObAIy.d.ts.map +0 -1
  144. package/dist/core-Bl1Ec1hY.js.map +0 -1
  145. package/dist/development/astro-shared-BT45auwR.js.map +0 -1
  146. package/dist/development/capabilities-BkQ2i0vV.js.map +0 -1
  147. package/dist/development/core-DZFaOyTO.js.map +0 -1
  148. package/dist/development/dom-Dwa2SFTn.js.map +0 -1
  149. package/dist/development/vite-CSHoxzXU.js.map +0 -1
  150. package/dist/dom-Cfj3GtQK.js.map +0 -1
  151. package/dist/vite-CSHoxzXU.js.map +0 -1
package/dist/three.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"three.js","names":[],"sources":["../src/three-events.ts","../src/three.ts"],"sourcesContent":["import * as THREE from \"three\"\n\nexport interface ThreePointerEvent<N extends THREE.Object3D = THREE.Object3D> {\n\ttype: string\n\tnativeEvent: PointerEvent\n\ttarget: THREE.Object3D\n\tcurrentTarget: N\n\tintersection: THREE.Intersection\n\tray: THREE.Ray\n\tpointerId: number\n\tbutton: number\n\tbuttons: number\n\tclientX: number\n\tclientY: number\n\tstopPropagation(): void\n\tpreventDefault(): void\n\tsetPointerCapture(): void\n\treleasePointerCapture(): void\n\thasPointerCapture(): boolean\n}\nexport type ThreeEventHandler<N extends THREE.Object3D = THREE.Object3D> = (\n\tevent: ThreePointerEvent<N>,\n) => void\nexport interface ThreeEventAttributes<\n\tN extends THREE.Object3D = THREE.Object3D,\n> {\n\tonPointerDown?: ThreeEventHandler<N>\n\tonPointerUp?: ThreeEventHandler<N>\n\tonPointerMove?: ThreeEventHandler<N>\n\tonPointerEnter?: ThreeEventHandler<N>\n\tonPointerLeave?: ThreeEventHandler<N>\n\tonPointerOver?: ThreeEventHandler<N>\n\tonPointerOut?: ThreeEventHandler<N>\n\tonPointerCancel?: ThreeEventHandler<N>\n\tonClick?: ThreeEventHandler<N>\n}\ntype Hit = { node: THREE.Object3D; intersection: THREE.Intersection }\ntype Handler = ThreeEventHandler\nconst suspended = new WeakSet<THREE.Object3D>()\nexport function suspendThree(node: THREE.Object3D): () => void {\n\tsuspended.add(node)\n\tfor (const manager of managers) manager.remove(node)\n\treturn () => {\n\t\tsuspended.delete(node)\n\t}\n}\nconst listeners = new WeakMap<THREE.Object3D, Map<string, Set<Handler>>>()\nconst managers = new Set<{ remove(node: THREE.Object3D): void }>()\n\nexport function listenThree(\n\tnode: THREE.Object3D,\n\ttype: string,\n\thandler: Handler,\n): () => void {\n\tconst events = listeners.get(node) ?? new Map<string, Set<Handler>>()\n\tlisteners.set(node, events)\n\tconst handlers = events.get(type) ?? new Set<Handler>()\n\tevents.set(type, handlers)\n\thandlers.add(handler)\n\treturn () => {\n\t\thandlers.delete(handler)\n\t\tif (!handlers.size) events.delete(type)\n\t}\n}\nexport function forgetThree(node: THREE.Object3D): void {\n\tconst errors: unknown[] = []\n\tfor (const manager of managers) {\n\t\ttry {\n\t\t\tmanager.remove(node)\n\t\t} catch (error) {\n\t\t\terrors.push(error)\n\t\t}\n\t}\n\tlisteners.delete(node)\n\tif (errors.length) throw new AggregateError(errors)\n}\n\nexport interface ThreeEventManager {\n\tupdate(): void\n\t/** Release hover, press, and capture state for a removed subtree. */\n\tremove(node: THREE.Object3D): void\n\tdispose(): void\n}\n\n/** Attach raycast pointer routing to a canvas; usable with borrowed scene roots. */\nexport function createThreeEvents(\n\tcanvas: HTMLCanvasElement,\n\tscene: THREE.Object3D,\n\tcamera: () => THREE.Camera,\n\tonError: (error: unknown) => void = (error) => {\n\t\tthrow error\n\t},\n): ThreeEventManager {\n\tconst raycaster = new THREE.Raycaster()\n\tconst pointer = new THREE.Vector2()\n\tconst hovering = new Map<number, Hit>()\n\tconst pressed = new Map<number, Hit>()\n\tconst captures = new Map<number, Hit>()\n\tconst last = new Map<number, PointerEvent>()\n\tlet dead = false\n\tconst path = (node: THREE.Object3D) => {\n\t\tconst nodes: THREE.Object3D[] = []\n\t\tfor (let at: THREE.Object3D | null = node; at; at = at.parent) {\n\t\t\tnodes.push(at)\n\t\t\tif (at === scene) return nodes\n\t\t}\n\t\treturn []\n\t}\n\tconst contains = (node: THREE.Object3D, child: THREE.Object3D) => {\n\t\tfor (let at: THREE.Object3D | null = child; at; at = at.parent)\n\t\t\tif (at === node) return true\n\t\treturn false\n\t}\n\tconst eligible = (intersection: THREE.Intersection) => {\n\t\tconst nodes = path(intersection.object)\n\t\tif (\n\t\t\t!nodes.length ||\n\t\t\tnodes.some((node) => !node.visible || suspended.has(node))\n\t\t)\n\t\t\treturn false\n\t\tconst material = (intersection.object as THREE.Mesh).material\n\t\treturn (\n\t\t\t!material ||\n\t\t\t(Array.isArray(material)\n\t\t\t\t? material[intersection.face?.materialIndex ?? 0]?.visible !== false\n\t\t\t\t: material.visible)\n\t\t)\n\t}\n\tconst pick = (event: PointerEvent): Hit | undefined => {\n\t\tconst bounds = canvas.getBoundingClientRect()\n\t\tif (!bounds.width || !bounds.height) return undefined\n\t\tconst active = camera()\n\t\tscene.updateWorldMatrix(true, true)\n\t\tactive.updateWorldMatrix(true, false)\n\t\tpointer.set(\n\t\t\t((event.clientX - bounds.left) / bounds.width) * 2 - 1,\n\t\t\t1 - ((event.clientY - bounds.top) / bounds.height) * 2,\n\t\t)\n\t\traycaster.layers.mask = active.layers.mask\n\t\traycaster.setFromCamera(pointer, active)\n\t\tif (\n\t\t\tevent.clientX < bounds.left ||\n\t\t\tevent.clientX > bounds.right ||\n\t\t\tevent.clientY < bounds.top ||\n\t\t\tevent.clientY > bounds.bottom\n\t\t)\n\t\t\treturn undefined\n\t\tconst intersection = raycaster.intersectObject(scene, true).find(eligible)\n\t\treturn intersection ? { node: intersection.object, intersection } : undefined\n\t}\n\tconst nativeCapture = (id: number) => {\n\t\tif (canvas.hasPointerCapture?.(id)) canvas.releasePointerCapture(id)\n\t}\n\tconst dispatch = (\n\t\ttype: string,\n\t\thit: Hit,\n\t\tnativeEvent: PointerEvent,\n\t\tnodes = path(hit.node),\n\t) => {\n\t\tlet stopped = false\n\t\tfor (const node of nodes) {\n\t\t\tif (dead) break\n\t\t\tconst event: ThreePointerEvent = {\n\t\t\t\ttype,\n\t\t\t\tnativeEvent,\n\t\t\t\ttarget: hit.node,\n\t\t\t\tcurrentTarget: node,\n\t\t\t\tintersection: hit.intersection,\n\t\t\t\tray: raycaster.ray.clone(),\n\t\t\t\tpointerId: nativeEvent.pointerId,\n\t\t\t\tbutton: nativeEvent.button,\n\t\t\t\tbuttons: nativeEvent.buttons,\n\t\t\t\tclientX: nativeEvent.clientX,\n\t\t\t\tclientY: nativeEvent.clientY,\n\t\t\t\tstopPropagation() {\n\t\t\t\t\tstopped = true\n\t\t\t\t},\n\t\t\t\tpreventDefault() {\n\t\t\t\t\tnativeEvent.preventDefault()\n\t\t\t\t},\n\t\t\t\tsetPointerCapture() {\n\t\t\t\t\tcanvas.setPointerCapture(nativeEvent.pointerId)\n\t\t\t\t\tcaptures.set(nativeEvent.pointerId, {\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tintersection: hit.intersection,\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t\treleasePointerCapture() {\n\t\t\t\t\tif (captures.get(nativeEvent.pointerId)?.node === node) {\n\t\t\t\t\t\tcaptures.delete(nativeEvent.pointerId)\n\t\t\t\t\t\tnativeCapture(nativeEvent.pointerId)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\thasPointerCapture() {\n\t\t\t\t\treturn captures.get(nativeEvent.pointerId)?.node === node\n\t\t\t\t},\n\t\t\t}\n\t\t\tfor (const handler of [...(listeners.get(node)?.get(type) ?? [])])\n\t\t\t\tif (!dead && listeners.get(node)?.get(type)?.has(handler)) handler(event)\n\t\t\tif (stopped) break\n\t\t}\n\t}\n\tconst hover = (event: PointerEvent, next?: Hit) => {\n\t\tconst previous = hovering.get(event.pointerId)\n\t\tif (previous?.node === next?.node) {\n\t\t\tif (next) hovering.set(event.pointerId, next)\n\t\t\treturn\n\t\t}\n\t\tconst oldPath = previous ? path(previous.node) : []\n\t\tconst newPath = next ? path(next.node) : []\n\t\t// Publish state first so handlers may remove nodes or dispose this manager safely.\n\t\tif (next) hovering.set(event.pointerId, next)\n\t\telse hovering.delete(event.pointerId)\n\t\tif (previous) {\n\t\t\tdispatch(`pointerout`, previous, event)\n\t\t\tfor (const node of oldPath)\n\t\t\t\tif (!newPath.includes(node))\n\t\t\t\t\tdispatch(`pointerleave`, previous, event, [node])\n\t\t}\n\t\tif (next && path(next.node).length) {\n\t\t\tdispatch(`pointerover`, next, event)\n\t\t\tfor (const node of newPath.reverse())\n\t\t\t\tif (!oldPath.includes(node))\n\t\t\t\t\tdispatch(`pointerenter`, next, event, [node])\n\t\t}\n\t}\n\tconst cancel = (event: PointerEvent) => {\n\t\tconst hit = captures.get(event.pointerId) ?? pressed.get(event.pointerId)\n\t\tcaptures.delete(event.pointerId)\n\t\tpressed.delete(event.pointerId)\n\t\ttry {\n\t\t\tif (hit) dispatch(`pointercancel`, hit, event)\n\t\t} finally {\n\t\t\tnativeCapture(event.pointerId)\n\t\t}\n\t}\n\tconst handle = (event: PointerEvent) => {\n\t\ttry {\n\t\t\tif (event.type === `lostpointercapture`) {\n\t\t\t\tcancel(event)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (event.type === `pointercancel`) {\n\t\t\t\tcancel(event)\n\t\t\t\thover(event)\n\t\t\t\tlast.delete(event.pointerId)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (event.type === `pointerleave`) {\n\t\t\t\tlast.set(event.pointerId, event)\n\t\t\t\thover(event)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlast.set(event.pointerId, event)\n\t\t\tconst hit = pick(event)\n\t\t\thover(event, hit)\n\t\t\tif (dead) return\n\t\t\tconst capture = captures.get(event.pointerId)\n\t\t\tif (capture && hit && contains(capture.node, hit.node))\n\t\t\t\tcapture.intersection = hit.intersection\n\t\t\tconst delivery = capture ?? hit\n\t\t\tif (event.type === `pointerdown`) {\n\t\t\t\tif (hit) {\n\t\t\t\t\tpressed.set(event.pointerId, hit)\n\t\t\t\t\tcanvas.setPointerCapture?.(event.pointerId)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (event.type === `pointerup`) {\n\t\t\t\tconst down = pressed.get(event.pointerId)\n\t\t\t\tpressed.delete(event.pointerId)\n\t\t\t\tif (down && down.node !== delivery?.node)\n\t\t\t\t\tdispatch(`pointercancel`, down, event)\n\t\t\t\tif (delivery) dispatch(`pointerup`, delivery, event)\n\t\t\t\tif (down && down.node === hit?.node && event.button === 0)\n\t\t\t\t\tdispatch(`click`, hit, event)\n\t\t\t\tcaptures.delete(event.pointerId)\n\t\t\t\tnativeCapture(event.pointerId)\n\t\t\t\tif (event.pointerType === `touch`) {\n\t\t\t\t\thover(event)\n\t\t\t\t\tlast.delete(event.pointerId)\n\t\t\t\t}\n\t\t\t} else if (delivery) dispatch(event.type, delivery, event)\n\t\t} catch (error) {\n\t\t\tonError(error)\n\t\t}\n\t}\n\tconst events = [\n\t\t`pointerdown`,\n\t\t`pointerup`,\n\t\t`pointermove`,\n\t\t`pointerleave`,\n\t\t`pointercancel`,\n\t\t`lostpointercapture`,\n\t] as const\n\tfor (const type of events) canvas.addEventListener(type, handle)\n\tconst manager = {\n\t\t/** Re-pick stationary pointers after camera, geometry, or transforms change. */\n\t\tupdate() {\n\t\t\tif (dead) return\n\t\t\ttry {\n\t\t\t\tfor (const event of last.values())\n\t\t\t\t\tif (event.type !== `pointerleave`) hover(event, pick(event))\n\t\t\t} catch (error) {\n\t\t\t\tonError(error)\n\t\t\t}\n\t\t},\n\t\tremove(node: THREE.Object3D) {\n\t\t\tconst errors: unknown[] = []\n\t\t\tfor (const [id, hit] of hovering)\n\t\t\t\tif (contains(node, hit.node)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\thover(last.get(id)!)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (const [id, hit] of [...pressed, ...captures])\n\t\t\t\tif (contains(node, hit.node)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcancel(last.get(id)!)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (errors.length) throw new AggregateError(errors)\n\t\t},\n\t\tdispose() {\n\t\t\tif (dead) return\n\t\t\tdead = true\n\t\t\tfor (const type of events) canvas.removeEventListener(type, handle)\n\t\t\tfor (const id of new Set([...pressed.keys(), ...captures.keys()]))\n\t\t\t\tnativeCapture(id)\n\t\t\thovering.clear()\n\t\t\tpressed.clear()\n\t\t\tcaptures.clear()\n\t\t\tlast.clear()\n\t\t\tmanagers.delete(manager)\n\t\t},\n\t}\n\tmanagers.add(manager)\n\treturn manager\n}\n","import { fail, isPresent, owner } from \"./core.ts\"\nimport type { ThreeEventAttributes, ThreeEventHandler } from \"./three-events.ts\"\nimport {\n\tcreateThreeEvents,\n\tforgetThree,\n\tlistenThree,\n\tsuspendThree,\n} from \"./three-events.ts\"\n\nexport type {\n\tThreeEventAttributes,\n\tThreeEventHandler,\n\tThreeEventManager,\n\tThreePointerEvent,\n} from \"./three-events.ts\"\nexport { createThreeEvents } from \"./three-events.ts\"\nimport * as THREE from \"three\"\n\nimport type { Child, VNode } from \"./index.ts\"\nimport { onCleanup, onMount } from \"./index.ts\"\nimport type { CapabilityAttributes } from \"./jsx-runtime.ts\"\nimport { jsx } from \"./jsx-runtime.ts\"\nimport {\n\tbindScene,\n\tcreateSceneRenderer,\n\tonSceneFrame,\n\tsceneComponent,\n} from \"./renderer.ts\"\n\ntype Resource = THREE.Object3D | THREE.BufferGeometry | THREE.Material\ntype Vector3 = readonly [number, number, number]\nexport interface ObjectProps<N extends THREE.Object3D = THREE.Object3D>\n\textends CapabilityAttributes<`three`>, ThreeEventAttributes<N> {\n\tchildren?: Child\n\tposition?: Vector3\n\trotation?: Vector3\n\tscale?: Vector3 | number\n\tvisible?: boolean\n\tname?: string\n\tref?: (object: N | null) => void\n}\nconst constructors = {\n\tGroup: THREE.Group,\n\tMesh: THREE.Mesh,\n\tPerspectiveCamera: THREE.PerspectiveCamera,\n\tAmbientLight: THREE.AmbientLight,\n\tDirectionalLight: THREE.DirectionalLight,\n\tBoxGeometry: THREE.BoxGeometry,\n\tSphereGeometry: THREE.SphereGeometry,\n\tPlaneGeometry: THREE.PlaneGeometry,\n\tMeshStandardMaterial: THREE.MeshStandardMaterial,\n\tMeshBasicMaterial: THREE.MeshBasicMaterial,\n\tMeshNormalMaterial: THREE.MeshNormalMaterial,\n}\nconst meshDefaults = new WeakMap<\n\tTHREE.Mesh,\n\t{ geometry: THREE.BufferGeometry; material: THREE.Material }\n>()\nconst borrowedMeshDefaults = new WeakMap<\n\tTHREE.Mesh,\n\t{\n\t\tgeometry: THREE.BufferGeometry\n\t\tmaterial: THREE.Material | THREE.Material[]\n\t}\n>()\nconst constructorArgs = new WeakMap<Resource, unknown[]>()\nconst eventHandlers = new WeakMap<Resource, Map<string, () => void>>()\nconst defaults = new WeakMap<Resource, Map<string, any>>()\nfunction writeProperty(node: Resource, key: string, value: any): void {\n\tconst target = node as any\n\tif (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)\n\tconst current = target[key]\n\tif (current?.isColor) current.set(value)\n\telse if (Array.isArray(value) && typeof current?.set === `function`)\n\t\tcurrent.set(...value)\n\telse if (key === `scale` && typeof value === `number`) current.setScalar(value)\n\telse if (current?.copy && value?.constructor === current.constructor)\n\t\tcurrent.copy(value)\n\telse target[key] = value\n\tif (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix()\n}\nconst renderer = createSceneRenderer<Resource>({\n\ttarget(node) {\n\t\treturn {\n\t\t\tkind: `three`,\n\t\t\tnode,\n\t\t\t...(node instanceof THREE.Object3D\n\t\t\t\t? {\n\t\t\t\t\t\tsuspend: () => suspendThree(node),\n\t\t\t\t\t\tlisten: (type: string, listener: () => void) =>\n\t\t\t\t\t\t\tlistenThree(node, type, listener),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\tread(key) {\n\t\t\t\tconst value = (node as any)[key]\n\t\t\t\treturn value?.isColor\n\t\t\t\t\t? value.getStyle()\n\t\t\t\t\t: value?.isVector3 || value?.isEuler\n\t\t\t\t\t\t? [value.x, value.y, value.z]\n\t\t\t\t\t\t: value\n\t\t\t},\n\t\t\twrite(key, value) {\n\t\t\t\twriteProperty(node, key, value)\n\t\t\t},\n\t\t}\n\t},\n\tcreate(type, props) {\n\t\tconst Constructor = constructors[type as keyof typeof constructors]\n\t\tif (!Constructor) throw new Error(`spa/three: unknown node ${type}`)\n\t\tconst node = new (Constructor as any)(...(props[`args`] ?? [])) as Resource\n\t\t// Mesh's implicit resources are replaced by owned JSX resources below.\n\t\tif (node instanceof THREE.Mesh)\n\t\t\tmeshDefaults.set(node, {\n\t\t\t\tgeometry: node.geometry,\n\t\t\t\tmaterial: node.material as THREE.Material,\n\t\t\t})\n\t\tconstructorArgs.set(node, [...(props[`args`] ?? [])])\n\t\tdefaults.set(node, new Map())\n\t\teventHandlers.set(node, new Map())\n\t\treturn node\n\t},\n\tupdate(node, props, previous) {\n\t\tif (!equalArgs(constructorArgs.get(node)!, props[`args`]))\n\t\t\tthrow new Error(\n\t\t\t\t`spa/three: change the component key to replace constructor args`,\n\t\t\t)\n\t\tconst target = node as any\n\t\tconst saved = defaults.get(node)!\n\t\tfor (const key of new Set([\n\t\t\t...Object.keys(previous),\n\t\t\t...Object.keys(props),\n\t\t])) {\n\t\t\tif (\n\t\t\t\t/^(key|children|ref|args)$/.test(key) ||\n\t\t\t\tObject.is(props[key], previous[key])\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tif (key.startsWith(`on`)) {\n\t\t\t\tif (\n\t\t\t\t\t!(node instanceof THREE.Object3D) ||\n\t\t\t\t\t!/^on(Pointer(Down|Up|Move|Enter|Leave|Over|Out|Cancel)|Click)$/.test(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(`spa/three: unknown event ${key}`)\n\t\t\t\tconst handlers = eventHandlers.get(node)!\n\t\t\t\thandlers.get(key)?.()\n\t\t\t\thandlers.delete(key)\n\t\t\t\tif (props[key])\n\t\t\t\t\thandlers.set(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tlistenThree(\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tkey.slice(2).toLowerCase(),\n\t\t\t\t\t\t\tprops[key] as ThreeEventHandler,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)\n\t\t\tconst current = target[key]\n\t\t\tif (!saved.has(key))\n\t\t\t\tsaved.set(key, current?.clone ? current.clone() : current)\n\t\t\tconst value = props[key] === undefined ? saved.get(key) : props[key]\n\t\t\twriteProperty(node, key, value)\n\t\t}\n\t\tif (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix()\n\t},\n\tchildren(parent, children, activeChildren) {\n\t\tif (!(parent instanceof THREE.Object3D)) {\n\t\t\tif (children.length)\n\t\t\t\tthrow new Error(`spa/three: resources cannot contain children`)\n\t\t\treturn\n\t\t}\n\t\tconst objects = children.filter(\n\t\t\t(child): child is THREE.Object3D => child instanceof THREE.Object3D,\n\t\t)\n\t\tfor (const child of [...parent.children])\n\t\t\tif (!objects.includes(child)) parent.remove(child)\n\t\tfor (const child of objects) if (child.parent !== parent) parent.add(child)\n\t\tparent.children.splice(0, parent.children.length, ...objects)\n\t\tconst resources = children.filter(\n\t\t\t(child) => !(child instanceof THREE.Object3D),\n\t\t)\n\t\tif (resources.length && !(parent instanceof THREE.Mesh))\n\t\t\tthrow new Error(`spa/three: geometry and material require a Mesh parent`)\n\t\tif (parent instanceof THREE.Mesh) {\n\t\t\tconst geometries = resources.filter(\n\t\t\t\t(child) => child instanceof THREE.BufferGeometry,\n\t\t\t)\n\t\t\tconst materials = resources.filter(\n\t\t\t\t(child) => child instanceof THREE.Material,\n\t\t\t)\n\t\t\tconst activeGeometries = activeChildren.filter(\n\t\t\t\t(child) => child instanceof THREE.BufferGeometry,\n\t\t\t)\n\t\t\tconst activeMaterials = activeChildren.filter(\n\t\t\t\t(child) => child instanceof THREE.Material,\n\t\t\t)\n\t\t\tif (activeGeometries.length > 1 || activeMaterials.length > 1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`spa/three: each Mesh accepts one geometry and one material`,\n\t\t\t\t)\n\t\t\tconst owned = meshDefaults.get(parent)\n\t\t\tlet baseline = owned ?? borrowedMeshDefaults.get(parent)\n\t\t\tif (!baseline) {\n\t\t\t\tbaseline = { geometry: parent.geometry, material: parent.material }\n\t\t\t\tborrowedMeshDefaults.set(parent, baseline)\n\t\t\t}\n\t\t\t// Retention owns outgoing resources without occupying incoming attachment slots.\n\t\t\tparent.geometry =\n\t\t\t\tactiveGeometries[0] ??\n\t\t\t\tgeometries.find((geometry) => geometry === parent.geometry) ??\n\t\t\t\tgeometries.at(-1) ??\n\t\t\t\tbaseline.geometry\n\t\t\tparent.material =\n\t\t\t\tactiveMaterials[0] ??\n\t\t\t\tmaterials.find((material) => material === parent.material) ??\n\t\t\t\tmaterials.at(-1) ??\n\t\t\t\tbaseline.material\n\t\t\tif (!owned && children.length === 0) borrowedMeshDefaults.delete(parent)\n\t\t}\n\t},\n\tdestroy(node) {\n\t\teventHandlers.get(node)!.clear()\n\t\tif (node instanceof THREE.Object3D) {\n\t\t\ttry {\n\t\t\t\tforgetThree(node)\n\t\t\t} finally {\n\t\t\t\tnode.removeFromParent()\n\t\t\t\tif (node instanceof THREE.Mesh) {\n\t\t\t\t\tconst owned = meshDefaults.get(node)!\n\t\t\t\t\towned.geometry.dispose()\n\t\t\t\t\towned.material.dispose()\n\t\t\t\t}\n\t\t\t}\n\t\t} else node.dispose()\n\t},\n})\nfunction equalArgs(a: unknown[], b: unknown[] = []): boolean {\n\treturn (\n\t\ta.length === b.length &&\n\t\ta.every((value, index) => Object.is(value, b[index]))\n\t)\n}\n\nexport interface CanvasProps {\n\tchildren?: Child\n\twidth?: number\n\theight?: number\n\tcamera?: THREE.Camera\n\tonFrame?: (state: {\n\t\tscene: THREE.Scene\n\t\tcamera: THREE.Camera\n\t\trenderer: THREE.WebGLRenderer\n\t\tdelta: number\n\t\ttime: number\n\t}) => void\n}\n/** Browser-only scene boundary. The camera prop is borrowed and never disposed. */\nexport function Canvas(props: CanvasProps): VNode {\n\tlet canvas: HTMLCanvasElement | null = null\n\tonMount(() => {\n\t\tconst webgl = new THREE.WebGLRenderer({ canvas: canvas!, antialias: true })\n\t\tonCleanup(() => {\n\t\t\twebgl.dispose()\n\t\t})\n\t\tconst scene = new THREE.Scene()\n\t\tconst camera = new THREE.PerspectiveCamera(50, 1, 0.1, 1000)\n\t\tcamera.position.z = 5\n\t\tbindScene(\n\t\t\t() => [props.width ?? 800, props.height ?? 600] as const,\n\t\t\t([width, height]) => {\n\t\t\t\twebgl.setSize(width, height)\n\t\t\t\tcamera.aspect = width / height\n\t\t\t\tcamera.updateProjectionMatrix()\n\t\t\t},\n\t\t)\n\t\trenderer.mount(() => props.children, scene)\n\t\tconst scope = owner!\n\t\tconst root = scope._root\n\t\tconst events = createThreeEvents(\n\t\t\tcanvas!,\n\t\t\tscene,\n\t\t\t() => props.camera ?? camera,\n\t\t\t(error) => {\n\t\t\t\ttry {\n\t\t\t\t\tfail(root, error)\n\t\t\t\t} catch (failure) {\n\t\t\t\t\troot.error(failure)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tonCleanup(() => {\n\t\t\tevents.dispose()\n\t\t})\n\t\tlet last: number | undefined\n\t\tonSceneFrame((time) => {\n\t\t\tconst active = props.camera ?? camera\n\t\t\tconst delta = last === undefined ? 0 : (time - last) / 1000\n\t\t\tlast = time\n\t\t\tif (isPresent(scope))\n\t\t\t\tprops.onFrame?.({\n\t\t\t\t\tscene,\n\t\t\t\t\tcamera: active,\n\t\t\t\t\trenderer: webgl,\n\t\t\t\t\tdelta,\n\t\t\t\t\ttime: time / 1000,\n\t\t\t\t})\n\t\t\tevents.update()\n\t\t\twebgl.render(scene, active)\n\t\t}, true)\n\t})\n\treturn jsx(`canvas`, {\n\t\tref: (element: HTMLCanvasElement | null) => {\n\t\t\tcanvas = element\n\t\t},\n\t})\n}\nexport const Group = sceneComponent<ObjectProps>(`Group`)\nexport const Mesh = sceneComponent<ObjectProps<THREE.Mesh>>(`Mesh`)\nexport const PerspectiveCamera = sceneComponent<\n\tObjectProps<THREE.PerspectiveCamera> & {\n\t\targs?: ConstructorParameters<typeof THREE.PerspectiveCamera>\n\t\tfov?: number\n\t\taspect?: number\n\t\tnear?: number\n\t\tfar?: number\n\t}\n>(`PerspectiveCamera`)\nexport const AmbientLight = sceneComponent<\n\tObjectProps<THREE.Light> & {\n\t\tcolor?: THREE.ColorRepresentation\n\t\tintensity?: number\n\t}\n>(`AmbientLight`)\nexport const DirectionalLight = sceneComponent<\n\tObjectProps<THREE.Light> & {\n\t\tcolor?: THREE.ColorRepresentation\n\t\tintensity?: number\n\t}\n>(`DirectionalLight`)\nexport const BoxGeometry = sceneComponent<{\n\targs?: ConstructorParameters<typeof THREE.BoxGeometry>\n\tref?: (node: THREE.BoxGeometry | null) => void\n}>(`BoxGeometry`)\nexport const SphereGeometry = sceneComponent<{\n\targs?: ConstructorParameters<typeof THREE.SphereGeometry>\n\tref?: (node: THREE.SphereGeometry | null) => void\n}>(`SphereGeometry`)\nexport const PlaneGeometry = sceneComponent<{\n\targs?: ConstructorParameters<typeof THREE.PlaneGeometry>\n\tref?: (node: THREE.PlaneGeometry | null) => void\n}>(`PlaneGeometry`)\nexport const MeshStandardMaterial = sceneComponent<\n\tTHREE.MeshStandardMaterialParameters &\n\t\tCapabilityAttributes<`three`> & {\n\t\t\tref?: (node: THREE.MeshStandardMaterial | null) => void\n\t\t}\n>(`MeshStandardMaterial`)\nexport const MeshBasicMaterial = sceneComponent<\n\tTHREE.MeshBasicMaterialParameters &\n\t\tCapabilityAttributes<`three`> & {\n\t\t\tref?: (node: THREE.MeshBasicMaterial | null) => void\n\t\t}\n>(`MeshBasicMaterial`)\nexport const MeshNormalMaterial = sceneComponent<\n\tTHREE.MeshNormalMaterialParameters &\n\t\tCapabilityAttributes<`three`> & {\n\t\t\tref?: (node: THREE.MeshNormalMaterial | null) => void\n\t\t}\n>(`MeshNormalMaterial`)\nexport { renderer as threeRenderer }\n"],"mappings":";;;;;AAsCA,MAAM,4BAAY,IAAI,QAAwB;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,UAAU;IACf;IACA,QAAQ;IACR,UAAU;IACV;IACA,MAAM,OAAO;GACd,CAAC;GACF,OAAO,OAAO;GACd,MAAM,OAAO,OAAO,MAAM;EAC3B,GAAG,IAAI;CACR,CAAC;CACD,OAAO,IAAI,UAAU,EACpB,MAAM,YAAsC;EAC3C,SAAS;CACV,EACD,CAAC;AACF;AACA,MAAa,QAAQ,eAA4B,OAAO;AACxD,MAAa,OAAO,eAAwC,MAAM;AAClE,MAAa,oBAAoB,eAQ/B,mBAAmB;AACrB,MAAa,eAAe,eAK1B,cAAc;AAChB,MAAa,mBAAmB,eAK9B,kBAAkB;AACpB,MAAa,cAAc,eAGxB,aAAa;AAChB,MAAa,iBAAiB,eAG3B,gBAAgB;AACnB,MAAa,gBAAgB,eAG1B,eAAe;AAClB,MAAa,uBAAuB,eAKlC,sBAAsB;AACxB,MAAa,oBAAoB,eAK/B,mBAAmB;AACrB,MAAa,qBAAqB,eAKhC,oBAAoB"}
1
+ {"version":3,"file":"three.js","names":[],"sources":["../src/three-events.ts","../src/three.ts"],"sourcesContent":["import * as THREE from \"three\"\n\nexport interface ThreePointerEvent<N extends THREE.Object3D = THREE.Object3D> {\n\ttype: string\n\tnativeEvent: PointerEvent\n\ttarget: THREE.Object3D\n\tcurrentTarget: N\n\tintersection: THREE.Intersection\n\tray: THREE.Ray\n\tpointerId: number\n\tbutton: number\n\tbuttons: number\n\tclientX: number\n\tclientY: number\n\tstopPropagation(): void\n\tpreventDefault(): void\n\tsetPointerCapture(): void\n\treleasePointerCapture(): void\n\thasPointerCapture(): boolean\n}\nexport type ThreeEventHandler<N extends THREE.Object3D = THREE.Object3D> = (\n\tevent: ThreePointerEvent<N>,\n) => void\nexport interface ThreeEventAttributes<\n\tN extends THREE.Object3D = THREE.Object3D,\n> {\n\tonPointerDown?: ThreeEventHandler<N>\n\tonPointerUp?: ThreeEventHandler<N>\n\tonPointerMove?: ThreeEventHandler<N>\n\tonPointerEnter?: ThreeEventHandler<N>\n\tonPointerLeave?: ThreeEventHandler<N>\n\tonPointerOver?: ThreeEventHandler<N>\n\tonPointerOut?: ThreeEventHandler<N>\n\tonPointerCancel?: ThreeEventHandler<N>\n\tonClick?: ThreeEventHandler<N>\n}\ntype Hit = { node: THREE.Object3D; intersection: THREE.Intersection }\ntype Handler = ThreeEventHandler\nconst suspended = new WeakSet<THREE.Object3D>()\nexport function suspendThree(node: THREE.Object3D): () => void {\n\tsuspended.add(node)\n\tfor (const manager of managers) manager.remove(node)\n\treturn () => {\n\t\tsuspended.delete(node)\n\t}\n}\nconst listeners = new WeakMap<THREE.Object3D, Map<string, Set<Handler>>>()\nconst managers = new Set<{ remove(node: THREE.Object3D): void }>()\n\nexport function listenThree(\n\tnode: THREE.Object3D,\n\ttype: string,\n\thandler: Handler,\n): () => void {\n\tconst events = listeners.get(node) ?? new Map<string, Set<Handler>>()\n\tlisteners.set(node, events)\n\tconst handlers = events.get(type) ?? new Set<Handler>()\n\tevents.set(type, handlers)\n\thandlers.add(handler)\n\treturn () => {\n\t\thandlers.delete(handler)\n\t\tif (!handlers.size) events.delete(type)\n\t}\n}\nexport function forgetThree(node: THREE.Object3D): void {\n\tconst errors: unknown[] = []\n\tfor (const manager of managers) {\n\t\ttry {\n\t\t\tmanager.remove(node)\n\t\t} catch (error) {\n\t\t\terrors.push(error)\n\t\t}\n\t}\n\tlisteners.delete(node)\n\tif (errors.length) throw new AggregateError(errors)\n}\n\nexport interface ThreeEventManager {\n\tupdate(): void\n\t/** Release hover, press, and capture state for a removed subtree. */\n\tremove(node: THREE.Object3D): void\n\tdispose(): void\n}\n\n/** Attach raycast pointer routing to a canvas; usable with borrowed scene roots. */\nexport function createThreeEvents(\n\tcanvas: HTMLCanvasElement,\n\tscene: THREE.Object3D,\n\tcamera: () => THREE.Camera,\n\tonError: (error: unknown) => void = (error) => {\n\t\tthrow error\n\t},\n): ThreeEventManager {\n\tconst raycaster = new THREE.Raycaster()\n\tconst pointer = new THREE.Vector2()\n\tconst hovering = new Map<number, Hit>()\n\tconst pressed = new Map<number, Hit>()\n\tconst captures = new Map<number, Hit>()\n\tconst last = new Map<number, PointerEvent>()\n\tlet dead = false\n\tconst path = (node: THREE.Object3D) => {\n\t\tconst nodes: THREE.Object3D[] = []\n\t\tfor (let at: THREE.Object3D | null = node; at; at = at.parent) {\n\t\t\tnodes.push(at)\n\t\t\tif (at === scene) return nodes\n\t\t}\n\t\treturn []\n\t}\n\tconst contains = (node: THREE.Object3D, child: THREE.Object3D) => {\n\t\tfor (let at: THREE.Object3D | null = child; at; at = at.parent)\n\t\t\tif (at === node) return true\n\t\treturn false\n\t}\n\tconst eligible = (intersection: THREE.Intersection) => {\n\t\tconst nodes = path(intersection.object)\n\t\tif (\n\t\t\t!nodes.length ||\n\t\t\tnodes.some((node) => !node.visible || suspended.has(node))\n\t\t)\n\t\t\treturn false\n\t\tconst material = (intersection.object as THREE.Mesh).material\n\t\treturn (\n\t\t\t!material ||\n\t\t\t(Array.isArray(material)\n\t\t\t\t? material[intersection.face?.materialIndex ?? 0]?.visible !== false\n\t\t\t\t: material.visible)\n\t\t)\n\t}\n\tconst pick = (event: PointerEvent): Hit | undefined => {\n\t\tconst bounds = canvas.getBoundingClientRect()\n\t\tif (!bounds.width || !bounds.height) return undefined\n\t\tconst active = camera()\n\t\tscene.updateWorldMatrix(true, true)\n\t\tactive.updateWorldMatrix(true, false)\n\t\tpointer.set(\n\t\t\t((event.clientX - bounds.left) / bounds.width) * 2 - 1,\n\t\t\t1 - ((event.clientY - bounds.top) / bounds.height) * 2,\n\t\t)\n\t\traycaster.layers.mask = active.layers.mask\n\t\traycaster.setFromCamera(pointer, active)\n\t\tif (\n\t\t\tevent.clientX < bounds.left ||\n\t\t\tevent.clientX > bounds.right ||\n\t\t\tevent.clientY < bounds.top ||\n\t\t\tevent.clientY > bounds.bottom\n\t\t)\n\t\t\treturn undefined\n\t\tconst intersection = raycaster.intersectObject(scene, true).find(eligible)\n\t\treturn intersection ? { node: intersection.object, intersection } : undefined\n\t}\n\tconst nativeCapture = (id: number) => {\n\t\tif (canvas.hasPointerCapture?.(id)) canvas.releasePointerCapture(id)\n\t}\n\tconst dispatch = (\n\t\ttype: string,\n\t\thit: Hit,\n\t\tnativeEvent: PointerEvent,\n\t\tnodes = path(hit.node),\n\t) => {\n\t\tlet stopped = false\n\t\tfor (const node of nodes) {\n\t\t\tif (dead) break\n\t\t\tconst event: ThreePointerEvent = {\n\t\t\t\ttype,\n\t\t\t\tnativeEvent,\n\t\t\t\ttarget: hit.node,\n\t\t\t\tcurrentTarget: node,\n\t\t\t\tintersection: hit.intersection,\n\t\t\t\tray: raycaster.ray.clone(),\n\t\t\t\tpointerId: nativeEvent.pointerId,\n\t\t\t\tbutton: nativeEvent.button,\n\t\t\t\tbuttons: nativeEvent.buttons,\n\t\t\t\tclientX: nativeEvent.clientX,\n\t\t\t\tclientY: nativeEvent.clientY,\n\t\t\t\tstopPropagation() {\n\t\t\t\t\tstopped = true\n\t\t\t\t},\n\t\t\t\tpreventDefault() {\n\t\t\t\t\tnativeEvent.preventDefault()\n\t\t\t\t},\n\t\t\t\tsetPointerCapture() {\n\t\t\t\t\tcanvas.setPointerCapture(nativeEvent.pointerId)\n\t\t\t\t\tcaptures.set(nativeEvent.pointerId, {\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\tintersection: hit.intersection,\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t\treleasePointerCapture() {\n\t\t\t\t\tif (captures.get(nativeEvent.pointerId)?.node === node) {\n\t\t\t\t\t\tcaptures.delete(nativeEvent.pointerId)\n\t\t\t\t\t\tnativeCapture(nativeEvent.pointerId)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\thasPointerCapture() {\n\t\t\t\t\treturn captures.get(nativeEvent.pointerId)?.node === node\n\t\t\t\t},\n\t\t\t}\n\t\t\tfor (const handler of [...(listeners.get(node)?.get(type) ?? [])])\n\t\t\t\tif (!dead && listeners.get(node)?.get(type)?.has(handler)) handler(event)\n\t\t\tif (stopped) break\n\t\t}\n\t}\n\tconst hover = (event: PointerEvent, next?: Hit) => {\n\t\tconst previous = hovering.get(event.pointerId)\n\t\tif (previous?.node === next?.node) {\n\t\t\tif (next) hovering.set(event.pointerId, next)\n\t\t\treturn\n\t\t}\n\t\tconst oldPath = previous ? path(previous.node) : []\n\t\tconst newPath = next ? path(next.node) : []\n\t\t// Publish state first so handlers may remove nodes or dispose this manager safely.\n\t\tif (next) hovering.set(event.pointerId, next)\n\t\telse hovering.delete(event.pointerId)\n\t\tif (previous) {\n\t\t\tdispatch(`pointerout`, previous, event)\n\t\t\tfor (const node of oldPath)\n\t\t\t\tif (!newPath.includes(node))\n\t\t\t\t\tdispatch(`pointerleave`, previous, event, [node])\n\t\t}\n\t\tif (next && path(next.node).length) {\n\t\t\tdispatch(`pointerover`, next, event)\n\t\t\tfor (const node of newPath.reverse())\n\t\t\t\tif (!oldPath.includes(node))\n\t\t\t\t\tdispatch(`pointerenter`, next, event, [node])\n\t\t}\n\t}\n\tconst cancel = (event: PointerEvent) => {\n\t\tconst hit = captures.get(event.pointerId) ?? pressed.get(event.pointerId)\n\t\tcaptures.delete(event.pointerId)\n\t\tpressed.delete(event.pointerId)\n\t\ttry {\n\t\t\tif (hit) dispatch(`pointercancel`, hit, event)\n\t\t} finally {\n\t\t\tnativeCapture(event.pointerId)\n\t\t}\n\t}\n\tconst handle = (event: PointerEvent) => {\n\t\ttry {\n\t\t\tif (event.type === `lostpointercapture`) {\n\t\t\t\tcancel(event)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (event.type === `pointercancel`) {\n\t\t\t\tcancel(event)\n\t\t\t\thover(event)\n\t\t\t\tlast.delete(event.pointerId)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (event.type === `pointerleave`) {\n\t\t\t\tlast.set(event.pointerId, event)\n\t\t\t\thover(event)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlast.set(event.pointerId, event)\n\t\t\tconst hit = pick(event)\n\t\t\thover(event, hit)\n\t\t\tif (dead) return\n\t\t\tconst capture = captures.get(event.pointerId)\n\t\t\tif (capture && hit && contains(capture.node, hit.node))\n\t\t\t\tcapture.intersection = hit.intersection\n\t\t\tconst delivery = capture ?? hit\n\t\t\tif (event.type === `pointerdown`) {\n\t\t\t\tif (hit) {\n\t\t\t\t\tpressed.set(event.pointerId, hit)\n\t\t\t\t\tcanvas.setPointerCapture?.(event.pointerId)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (event.type === `pointerup`) {\n\t\t\t\tconst down = pressed.get(event.pointerId)\n\t\t\t\tpressed.delete(event.pointerId)\n\t\t\t\ttry {\n\t\t\t\t\t// Capture may belong to an ancestor of the original hit.\n\t\t\t\t\tif (down && !capture && down.node !== hit?.node)\n\t\t\t\t\t\tdispatch(`pointercancel`, down, event)\n\t\t\t\t\tif (delivery) dispatch(`pointerup`, delivery, event)\n\t\t\t\t\tif (down && down.node === hit?.node && event.button === 0)\n\t\t\t\t\t\tdispatch(`click`, hit, event)\n\t\t\t\t} finally {\n\t\t\t\t\tcaptures.delete(event.pointerId)\n\t\t\t\t\tnativeCapture(event.pointerId)\n\t\t\t\t\tif (event.pointerType === `touch`) {\n\t\t\t\t\t\thover(event)\n\t\t\t\t\t\tlast.delete(event.pointerId)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (delivery) dispatch(event.type, delivery, event)\n\t\t} catch (error) {\n\t\t\tonError(error)\n\t\t}\n\t}\n\tconst events = [\n\t\t`pointerdown`,\n\t\t`pointerup`,\n\t\t`pointermove`,\n\t\t`pointerleave`,\n\t\t`pointercancel`,\n\t\t`lostpointercapture`,\n\t] as const\n\tfor (const type of events) canvas.addEventListener(type, handle)\n\tconst manager = {\n\t\t/** Re-pick stationary pointers after camera, geometry, or transforms change. */\n\t\tupdate() {\n\t\t\tif (dead) return\n\t\t\ttry {\n\t\t\t\tfor (const event of last.values())\n\t\t\t\t\tif (event.type !== `pointerleave`) hover(event, pick(event))\n\t\t\t} catch (error) {\n\t\t\t\tonError(error)\n\t\t\t}\n\t\t},\n\t\tremove(node: THREE.Object3D) {\n\t\t\tconst errors: unknown[] = []\n\t\t\tfor (const [id, hit] of hovering)\n\t\t\t\tif (contains(node, hit.node)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\thover(last.get(id)!)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tfor (const [id, hit] of [...pressed, ...captures])\n\t\t\t\tif (contains(node, hit.node)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcancel(last.get(id)!)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\terrors.push(error)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (errors.length) throw new AggregateError(errors)\n\t\t},\n\t\tdispose() {\n\t\t\tif (dead) return\n\t\t\tdead = true\n\t\t\tfor (const type of events) canvas.removeEventListener(type, handle)\n\t\t\tfor (const id of new Set([...pressed.keys(), ...captures.keys()]))\n\t\t\t\tnativeCapture(id)\n\t\t\thovering.clear()\n\t\t\tpressed.clear()\n\t\t\tcaptures.clear()\n\t\t\tlast.clear()\n\t\t\tmanagers.delete(manager)\n\t\t},\n\t}\n\tmanagers.add(manager)\n\treturn manager\n}\n","import { fail, isPresent, owner } from \"./core.ts\"\nimport type { ThreeEventAttributes, ThreeEventHandler } from \"./three-events.ts\"\nimport {\n\tcreateThreeEvents,\n\tforgetThree,\n\tlistenThree,\n\tsuspendThree,\n} from \"./three-events.ts\"\n\nexport type {\n\tThreeEventAttributes,\n\tThreeEventHandler,\n\tThreeEventManager,\n\tThreePointerEvent,\n} from \"./three-events.ts\"\nexport { createThreeEvents } from \"./three-events.ts\"\nimport * as THREE from \"three\"\n\nimport type { Children, SpaElement } from \"./index.ts\"\nimport { onCleanup, onMount } from \"./index.ts\"\nimport type { CapabilityAttributes } from \"./jsx-runtime.ts\"\nimport { jsx } from \"./jsx-runtime.ts\"\nimport {\n\tbindScene,\n\tcreateSceneRenderer,\n\tonSceneFrame,\n\tsceneComponent,\n} from \"./renderer.ts\"\n\ntype Resource = THREE.Object3D | THREE.BufferGeometry | THREE.Material\ntype Vector3 = readonly [number, number, number]\nexport interface ObjectProps<N extends THREE.Object3D = THREE.Object3D>\n\textends CapabilityAttributes<`three`>, ThreeEventAttributes<N> {\n\tchildren?: Children\n\tposition?: Vector3\n\trotation?: Vector3\n\tscale?: Vector3 | number\n\tvisible?: boolean\n\tname?: string\n\tref?: (object: N | null) => void\n}\nconst constructors = {\n\tGroup: THREE.Group,\n\tMesh: THREE.Mesh,\n\tPerspectiveCamera: THREE.PerspectiveCamera,\n\tAmbientLight: THREE.AmbientLight,\n\tDirectionalLight: THREE.DirectionalLight,\n\tBoxGeometry: THREE.BoxGeometry,\n\tSphereGeometry: THREE.SphereGeometry,\n\tPlaneGeometry: THREE.PlaneGeometry,\n\tMeshStandardMaterial: THREE.MeshStandardMaterial,\n\tMeshBasicMaterial: THREE.MeshBasicMaterial,\n\tMeshNormalMaterial: THREE.MeshNormalMaterial,\n}\nconst meshDefaults = new WeakMap<\n\tTHREE.Mesh,\n\t{ geometry: THREE.BufferGeometry; material: THREE.Material }\n>()\nconst borrowedMeshDefaults = new WeakMap<\n\tTHREE.Mesh,\n\t{\n\t\tgeometry: THREE.BufferGeometry\n\t\tmaterial: THREE.Material | THREE.Material[]\n\t}\n>()\nconst constructorArgs = new WeakMap<Resource, unknown[]>()\nconst eventHandlers = new WeakMap<Resource, Map<string, () => void>>()\nconst defaults = new WeakMap<Resource, Map<string, any>>()\nfunction writeProperty(node: Resource, key: string, value: any): void {\n\tconst target = node as any\n\tif (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)\n\tconst current = target[key]\n\tif (current?.isColor) current.set(value)\n\telse if (Array.isArray(value) && typeof current?.set === `function`)\n\t\tcurrent.set(...value)\n\telse if (key === `scale` && typeof value === `number`) current.setScalar(value)\n\telse if (current?.copy && value?.constructor === current.constructor)\n\t\tcurrent.copy(value)\n\telse target[key] = value\n\tif (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix()\n}\nconst renderer = createSceneRenderer<Resource>({\n\ttarget(node) {\n\t\treturn {\n\t\t\tkind: `three`,\n\t\t\tnode,\n\t\t\t...(node instanceof THREE.Object3D\n\t\t\t\t? {\n\t\t\t\t\t\tsuspend: () => suspendThree(node),\n\t\t\t\t\t\tlisten: (type: string, listener: () => void) =>\n\t\t\t\t\t\t\tlistenThree(node, type, listener),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\tread(key) {\n\t\t\t\tconst value = (node as any)[key]\n\t\t\t\treturn value?.isColor\n\t\t\t\t\t? value.getStyle()\n\t\t\t\t\t: value?.isVector3 || value?.isEuler\n\t\t\t\t\t\t? [value.x, value.y, value.z]\n\t\t\t\t\t\t: value\n\t\t\t},\n\t\t\twrite(key, value) {\n\t\t\t\twriteProperty(node, key, value)\n\t\t\t},\n\t\t}\n\t},\n\tcreate(type, props) {\n\t\tconst Constructor = constructors[type as keyof typeof constructors]\n\t\tif (!Constructor) throw new Error(`spa/three: unknown node ${type}`)\n\t\tconst node = new (Constructor as any)(...(props[`args`] ?? [])) as Resource\n\t\t// Mesh's implicit resources are replaced by owned JSX resources below.\n\t\tif (node instanceof THREE.Mesh)\n\t\t\tmeshDefaults.set(node, {\n\t\t\t\tgeometry: node.geometry,\n\t\t\t\tmaterial: node.material as THREE.Material,\n\t\t\t})\n\t\tconstructorArgs.set(node, [...(props[`args`] ?? [])])\n\t\tdefaults.set(node, new Map())\n\t\teventHandlers.set(node, new Map())\n\t\treturn node\n\t},\n\tupdate(node, props, previous) {\n\t\tif (!equalArgs(constructorArgs.get(node)!, props[`args`]))\n\t\t\tthrow new Error(\n\t\t\t\t`spa/three: change the component key to replace constructor args`,\n\t\t\t)\n\t\tconst target = node as any\n\t\tconst saved = defaults.get(node)!\n\t\tfor (const key of new Set([\n\t\t\t...Object.keys(previous),\n\t\t\t...Object.keys(props),\n\t\t])) {\n\t\t\tif (\n\t\t\t\t/^(key|children|ref|args)$/.test(key) ||\n\t\t\t\tObject.is(props[key], previous[key])\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tif (key.startsWith(`on`)) {\n\t\t\t\tif (\n\t\t\t\t\t!(node instanceof THREE.Object3D) ||\n\t\t\t\t\t!/^on(Pointer(Down|Up|Move|Enter|Leave|Over|Out|Cancel)|Click)$/.test(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(`spa/three: unknown event ${key}`)\n\t\t\t\tconst handlers = eventHandlers.get(node)!\n\t\t\t\thandlers.get(key)?.()\n\t\t\t\thandlers.delete(key)\n\t\t\t\tif (props[key])\n\t\t\t\t\thandlers.set(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tlistenThree(\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\tkey.slice(2).toLowerCase(),\n\t\t\t\t\t\t\tprops[key] as ThreeEventHandler,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)\n\t\t\tconst current = target[key]\n\t\t\tif (!saved.has(key))\n\t\t\t\tsaved.set(key, current?.clone ? current.clone() : current)\n\t\t\tconst value = props[key] === undefined ? saved.get(key) : props[key]\n\t\t\twriteProperty(node, key, value)\n\t\t}\n\t\tif (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix()\n\t},\n\tchildren(parent, children, activeChildren) {\n\t\tif (!(parent instanceof THREE.Object3D)) {\n\t\t\tif (children.length)\n\t\t\t\tthrow new Error(`spa/three: resources cannot contain children`)\n\t\t\treturn\n\t\t}\n\t\tconst objects = children.filter(\n\t\t\t(child): child is THREE.Object3D => child instanceof THREE.Object3D,\n\t\t)\n\t\tfor (const child of [...parent.children])\n\t\t\tif (!objects.includes(child)) parent.remove(child)\n\t\tfor (const child of objects) if (child.parent !== parent) parent.add(child)\n\t\tparent.children.splice(0, parent.children.length, ...objects)\n\t\tconst resources = children.filter(\n\t\t\t(child) => !(child instanceof THREE.Object3D),\n\t\t)\n\t\tif (resources.length && !(parent instanceof THREE.Mesh))\n\t\t\tthrow new Error(`spa/three: geometry and material require a Mesh parent`)\n\t\tif (parent instanceof THREE.Mesh) {\n\t\t\tconst geometries = resources.filter(\n\t\t\t\t(child) => child instanceof THREE.BufferGeometry,\n\t\t\t)\n\t\t\tconst materials = resources.filter(\n\t\t\t\t(child) => child instanceof THREE.Material,\n\t\t\t)\n\t\t\tconst activeGeometries = activeChildren.filter(\n\t\t\t\t(child) => child instanceof THREE.BufferGeometry,\n\t\t\t)\n\t\t\tconst activeMaterials = activeChildren.filter(\n\t\t\t\t(child) => child instanceof THREE.Material,\n\t\t\t)\n\t\t\tif (activeGeometries.length > 1 || activeMaterials.length > 1)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`spa/three: each Mesh accepts one geometry and one material`,\n\t\t\t\t)\n\t\t\tconst owned = meshDefaults.get(parent)\n\t\t\tlet baseline = owned ?? borrowedMeshDefaults.get(parent)\n\t\t\tif (!baseline) {\n\t\t\t\tbaseline = { geometry: parent.geometry, material: parent.material }\n\t\t\t\tborrowedMeshDefaults.set(parent, baseline)\n\t\t\t}\n\t\t\t// Retention owns outgoing resources without occupying incoming attachment slots.\n\t\t\tparent.geometry =\n\t\t\t\tactiveGeometries[0] ??\n\t\t\t\tgeometries.find((geometry) => geometry === parent.geometry) ??\n\t\t\t\tgeometries.at(-1) ??\n\t\t\t\tbaseline.geometry\n\t\t\tparent.material =\n\t\t\t\tactiveMaterials[0] ??\n\t\t\t\tmaterials.find((material) => material === parent.material) ??\n\t\t\t\tmaterials.at(-1) ??\n\t\t\t\tbaseline.material\n\t\t\tif (!owned && children.length === 0) borrowedMeshDefaults.delete(parent)\n\t\t}\n\t},\n\tdestroy(node) {\n\t\teventHandlers.get(node)!.clear()\n\t\tif (node instanceof THREE.Object3D) {\n\t\t\ttry {\n\t\t\t\tforgetThree(node)\n\t\t\t} finally {\n\t\t\t\tnode.removeFromParent()\n\t\t\t\tif (node instanceof THREE.Mesh) {\n\t\t\t\t\tconst owned = meshDefaults.get(node)!\n\t\t\t\t\towned.geometry.dispose()\n\t\t\t\t\towned.material.dispose()\n\t\t\t\t}\n\t\t\t}\n\t\t} else node.dispose()\n\t},\n})\nfunction equalArgs(a: unknown[], b: unknown[] = []): boolean {\n\treturn (\n\t\ta.length === b.length &&\n\t\ta.every((value, index) => Object.is(value, b[index]))\n\t)\n}\n\nexport interface CanvasProps {\n\tchildren?: Children\n\twidth?: number\n\theight?: number\n\tcamera?: THREE.Camera\n\tonFrame?: (state: {\n\t\tscene: THREE.Scene\n\t\tcamera: THREE.Camera\n\t\trenderer: THREE.WebGLRenderer\n\t\tdelta: number\n\t\ttime: number\n\t}) => void\n}\n/** Browser-only scene boundary. The camera prop is borrowed and never disposed. */\nexport function Canvas(props: CanvasProps): SpaElement {\n\tlet canvas: HTMLCanvasElement | null = null\n\tonMount(() => {\n\t\tconst webgl = new THREE.WebGLRenderer({ canvas: canvas!, antialias: true })\n\t\tonCleanup(() => {\n\t\t\twebgl.dispose()\n\t\t})\n\t\tconst scene = new THREE.Scene()\n\t\tconst camera = new THREE.PerspectiveCamera(50, 1, 0.1, 1000)\n\t\tcamera.position.z = 5\n\t\tbindScene(\n\t\t\t() => [props.width ?? 800, props.height ?? 600] as const,\n\t\t\t([width, height]) => {\n\t\t\t\twebgl.setSize(width, height)\n\t\t\t\tcamera.aspect = width / height\n\t\t\t\tcamera.updateProjectionMatrix()\n\t\t\t},\n\t\t)\n\t\trenderer.mount(() => props.children, scene)\n\t\tconst scope = owner!\n\t\tconst root = scope._root\n\t\tconst events = createThreeEvents(\n\t\t\tcanvas!,\n\t\t\tscene,\n\t\t\t() => props.camera ?? camera,\n\t\t\t(error) => {\n\t\t\t\ttry {\n\t\t\t\t\tfail(root, error)\n\t\t\t\t} catch (failure) {\n\t\t\t\t\troot.error(failure)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tonCleanup(() => {\n\t\t\tevents.dispose()\n\t\t})\n\t\tlet last: number | undefined\n\t\tonSceneFrame((time) => {\n\t\t\tconst active = props.camera ?? camera\n\t\t\tconst delta = last === undefined ? 0 : (time - last) / 1000\n\t\t\tlast = time\n\t\t\tif (isPresent(scope))\n\t\t\t\tprops.onFrame?.({\n\t\t\t\t\tscene,\n\t\t\t\t\tcamera: active,\n\t\t\t\t\trenderer: webgl,\n\t\t\t\t\tdelta,\n\t\t\t\t\ttime: time / 1000,\n\t\t\t\t})\n\t\t\tevents.update()\n\t\t\twebgl.render(scene, active)\n\t\t}, true)\n\t})\n\treturn jsx(`canvas`, {\n\t\tref: (element: HTMLCanvasElement | null) => {\n\t\t\tcanvas = element\n\t\t},\n\t})\n}\nexport const Group = sceneComponent<ObjectProps>(`Group`)\nexport const Mesh = sceneComponent<ObjectProps<THREE.Mesh>>(`Mesh`)\nexport const PerspectiveCamera = sceneComponent<\n\tObjectProps<THREE.PerspectiveCamera> & {\n\t\targs?: ConstructorParameters<typeof THREE.PerspectiveCamera>\n\t\tfov?: number\n\t\taspect?: number\n\t\tnear?: number\n\t\tfar?: number\n\t}\n>(`PerspectiveCamera`)\nexport const AmbientLight = sceneComponent<\n\tObjectProps<THREE.Light> & {\n\t\tcolor?: THREE.ColorRepresentation\n\t\tintensity?: number\n\t}\n>(`AmbientLight`)\nexport const DirectionalLight = sceneComponent<\n\tObjectProps<THREE.Light> & {\n\t\tcolor?: THREE.ColorRepresentation\n\t\tintensity?: number\n\t}\n>(`DirectionalLight`)\nexport const BoxGeometry = sceneComponent<{\n\targs?: ConstructorParameters<typeof THREE.BoxGeometry>\n\tref?: (node: THREE.BoxGeometry | null) => void\n}>(`BoxGeometry`)\nexport const SphereGeometry = sceneComponent<{\n\targs?: ConstructorParameters<typeof THREE.SphereGeometry>\n\tref?: (node: THREE.SphereGeometry | null) => void\n}>(`SphereGeometry`)\nexport const PlaneGeometry = sceneComponent<{\n\targs?: ConstructorParameters<typeof THREE.PlaneGeometry>\n\tref?: (node: THREE.PlaneGeometry | null) => void\n}>(`PlaneGeometry`)\nexport const MeshStandardMaterial = sceneComponent<\n\tTHREE.MeshStandardMaterialParameters &\n\t\tCapabilityAttributes<`three`> & {\n\t\t\tref?: (node: THREE.MeshStandardMaterial | null) => void\n\t\t}\n>(`MeshStandardMaterial`)\nexport const MeshBasicMaterial = sceneComponent<\n\tTHREE.MeshBasicMaterialParameters &\n\t\tCapabilityAttributes<`three`> & {\n\t\t\tref?: (node: THREE.MeshBasicMaterial | null) => void\n\t\t}\n>(`MeshBasicMaterial`)\nexport const MeshNormalMaterial = sceneComponent<\n\tTHREE.MeshNormalMaterialParameters &\n\t\tCapabilityAttributes<`three`> & {\n\t\t\tref?: (node: THREE.MeshNormalMaterial | null) => void\n\t\t}\n>(`MeshNormalMaterial`)\nexport { renderer as threeRenderer }\n"],"mappings":";;;;;AAsCA,MAAM,4BAAY,IAAI,QAAwB;AAC9C,SAAgB,aAAa,MAAkC;CAC9D,UAAU,IAAI,IAAI;CAClB,KAAK,MAAM,WAAW,UAAU,QAAQ,OAAO,IAAI;CACnD,aAAa;EACZ,UAAU,OAAO,IAAI;CACtB;AACD;AACA,MAAM,4BAAY,IAAI,QAAmD;AACzE,MAAM,2BAAW,IAAI,IAA4C;AAEjE,SAAgB,YACf,MACA,MACA,SACa;CACb,MAAM,SAAS,UAAU,IAAI,IAAI,qBAAK,IAAI,IAA0B;CACpE,UAAU,IAAI,MAAM,MAAM;CAC1B,MAAM,WAAW,OAAO,IAAI,IAAI,qBAAK,IAAI,IAAa;CACtD,OAAO,IAAI,MAAM,QAAQ;CACzB,SAAS,IAAI,OAAO;CACpB,aAAa;EACZ,SAAS,OAAO,OAAO;EACvB,IAAI,CAAC,SAAS,MAAM,OAAO,OAAO,IAAI;CACvC;AACD;AACA,SAAgB,YAAY,MAA4B;CACvD,MAAM,SAAoB,CAAC;CAC3B,KAAK,MAAM,WAAW,UACrB,IAAI;E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BAAoB"}
@@ -132,19 +132,44 @@ function compile(code, filename) {
132
132
  ]);
133
133
  }
134
134
  }
135
+ const component = node.type === `JSXElement` && !tag(node.openingElement.name).startsWith(`"`);
135
136
  const children = [];
137
+ let lazyChildren = false;
136
138
  for (const child of node.children) if (child.type === `JSXText`) {
137
139
  const value = text(decodeJsx(child.value));
138
140
  if (value) children.push([JSON.stringify(value)]);
139
141
  } else if (child.type === `JSXElement` || child.type === `JSXFragment`) children.push([child]);
140
142
  else if (child.type === `JSXExpressionContainer`) {
141
- if (child.expression.type !== `JSXEmptyExpression`) children.push(expression(child.expression));
143
+ if (child.expression.type !== `JSXEmptyExpression`) {
144
+ if (component) {
145
+ children.push([
146
+ `(`,
147
+ child.expression,
148
+ `)`
149
+ ]);
150
+ if (!eager(child.expression, true)) lazyChildren = true;
151
+ } else children.push(expression(child.expression));
152
+ }
142
153
  } else throw new SyntaxError(`${filename}: JSX spread children are unsupported`);
143
- if (children.length) properties.push([`children: `, ...children.length === 1 ? children[0] : [
144
- `[`,
145
- ...join(children, `, `),
146
- `]`
147
- ]]);
154
+ if (children.length) {
155
+ const value = children.length === 1 ? children[0] : [
156
+ `[`,
157
+ ...join(children, `, `),
158
+ `]`
159
+ ];
160
+ if (lazyChildren) {
161
+ const read = uid(`children`);
162
+ properties.push([`get children(){ return ${read}(); }`]);
163
+ chunks.push([
164
+ `((${read}) => ({`,
165
+ ...join(properties, `, `),
166
+ `}))(() => (`,
167
+ ...value,
168
+ `))`
169
+ ]);
170
+ properties = [];
171
+ } else properties.push([`children: `, ...value]);
172
+ }
148
173
  flush();
149
174
  const props = node.type === `JSXElement` && node.openingElement.attributes.some((attr) => attr.type === `JSXSpreadAttribute`) ? [
150
175
  `${merge}(`,
@@ -237,4 +262,4 @@ function spa(options = {}) {
237
262
  }
238
263
  export { spa as t };
239
264
 
240
- //# sourceMappingURL=vite-CSHoxzXU.js.map
265
+ //# sourceMappingURL=vite-Bmyb6P5w.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-Bmyb6P5w.js","names":[],"sources":["../src/compiler.ts","../src/vite.ts"],"sourcesContent":["import { decode } from \"html-entities\"\nimport type { SourceMap } from \"magic-string\"\nimport MagicString from \"magic-string\"\nimport type {\n\tExpression,\n\tJSXElement,\n\tJSXElementName,\n\tJSXFragment,\n\tNode,\n} from \"oxc-parser\"\nimport { parseSync, visitorKeys } from \"oxc-parser\"\n\ntype Part = string | Node\n\nconst decodeJsx = (value: string): string =>\n\tdecode(value, { level: `html4`, scope: `strict` })\n\n/** Match JSX's multiline whitespace rules without reprinting JavaScript. */\nfunction text(value: string): string {\n\tconst lines = value.split(/\\r\\n|\\n|\\r/)\n\tlet last = 0\n\tfor (let i = 0; i < lines.length; i++) if (/[^ \\t]/.test(lines[i])) last = i\n\treturn lines\n\t\t.map((line, i) => {\n\t\t\tline = line.replace(/\\t/g, ` `)\n\t\t\tif (i > 0) line = line.replace(/^ +/, ``)\n\t\t\tif (i < lines.length - 1) line = line.replace(/ +$/, ``)\n\t\t\treturn line && i < last ? `${line} ` : line\n\t\t})\n\t\t.join(``)\n}\n\nfunction eager(node: Node, allowJsx = false): boolean {\n\tif (node.type === `ParenthesizedExpression`)\n\t\treturn eager(node.expression, allowJsx)\n\treturn (\n\t\tnode.type === `Literal` ||\n\t\tnode.type === `FunctionExpression` ||\n\t\tnode.type === `ArrowFunctionExpression` ||\n\t\t(allowJsx && (node.type === `JSXElement` || node.type === `JSXFragment`)) ||\n\t\t(node.type === `TemplateLiteral` && node.expressions.length === 0)\n\t)\n}\n\nexport function compile(\n\tcode: string,\n\tfilename: string,\n): { code: string; map: SourceMap } {\n\tconst parsed = parseSync(filename, code, {\n\t\tlang: `tsx`,\n\t\tpreserveParens: true,\n\t})\n\tif (parsed.errors.length) {\n\t\tconst error = parsed.errors[0]\n\t\tthrow new SyntaxError(\n\t\t\t[`${filename}: ${error.message}`, error.codeframe]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(`\\n`),\n\t\t)\n\t}\n\tconst output = new MagicString(code)\n\tconst parents = new WeakMap<Node, Node>()\n\tconst identifiers = new Set<string>()\n\tconst elements: (JSXElement | JSXFragment)[] = []\n\tconst functions = new Set<Node>()\n\tfunction walk(node: Node, parent?: Node, outerFunction?: Node): void {\n\t\tif (parent) parents.set(node, parent)\n\t\toutput.addSourcemapLocation(node.start)\n\t\toutput.addSourcemapLocation(node.end)\n\t\tif (node.type === `Identifier` || node.type === `JSXIdentifier`)\n\t\t\tidentifiers.add(node.name)\n\t\tif (\n\t\t\t!outerFunction &&\n\t\t\t(node.type === `FunctionDeclaration` ||\n\t\t\t\tnode.type === `FunctionExpression` ||\n\t\t\t\tnode.type === `ArrowFunctionExpression`)\n\t\t)\n\t\t\touterFunction = node\n\t\tif (node.type === `JSXElement` || node.type === `JSXFragment`) {\n\t\t\telements.push(node)\n\t\t\tif (outerFunction) functions.add(outerFunction)\n\t\t}\n\t\tfor (const key of visitorKeys[node.type]) {\n\t\t\tconst value = (node as unknown as Record<string, unknown>)[key]\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const child of value) if (child) walk(child, node, outerFunction)\n\t\t\t} else if (value) walk(value as Node, node, outerFunction)\n\t\t}\n\t}\n\twalk(parsed.program)\n\tfunction uid(base: string): string {\n\t\tlet name = `_${base}`\n\t\tlet suffix = 1\n\t\twhile (identifiers.has(name)) name = `_${base}${++suffix}`\n\t\tidentifiers.add(name)\n\t\treturn name\n\t}\n\tconst create = uid(`spa`)\n\tconst merge = uid(`props`)\n\tconst join = (parts: Part[][], separator: string): Part[] =>\n\t\tparts.flatMap((part, i) => (i ? [separator, ...part] : part))\n\tconst expression = (node: Expression): Part[] =>\n\t\teager(node, true) ? [`(`, node, `)`] : [`() => (`, node, `)`]\n\tfunction tag(node: JSXElementName): string {\n\t\tif (node.type === `JSXNamespacedName`)\n\t\t\treturn JSON.stringify(`${node.namespace.name}:${node.name.name}`)\n\t\tif (node.type === `JSXMemberExpression`)\n\t\t\treturn code.slice(node.start, node.end)\n\t\treturn /^[a-z]/.test(node.name) || node.name.includes(`-`)\n\t\t\t? JSON.stringify(node.name)\n\t\t\t: node.name\n\t}\n\t/** Rewrite syntax around untouched expression spans, including nested JSX. */\n\tfunction rewrite(node: JSXElement | JSXFragment, parts: Part[]): void {\n\t\tlet cursor = node.start\n\t\tlet replacement = ``\n\t\tfor (const part of parts) {\n\t\t\tif (typeof part === `string`) {\n\t\t\t\treplacement += part\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (cursor < part.start) output.update(cursor, part.start, replacement)\n\t\t\telse output.appendLeft(cursor, replacement)\n\t\t\tcursor = part.end\n\t\t\treplacement = ``\n\t\t}\n\t\t// Every JSX node ends with closing syntax after its last expression span.\n\t\toutput.update(cursor, node.end, replacement)\n\t}\n\tfor (const node of elements) {\n\t\tconst chunks: Part[][] = []\n\t\tlet properties: Part[][] = []\n\t\tconst flush = () => {\n\t\t\tif (properties.length) chunks.push([`{`, ...join(properties, `, `), `}`])\n\t\t\tproperties = []\n\t\t}\n\t\tif (node.type === `JSXElement`) {\n\t\t\tfor (const attribute of node.openingElement.attributes) {\n\t\t\t\tif (attribute.type === `JSXSpreadAttribute`) {\n\t\t\t\t\tflush()\n\t\t\t\t\tchunks.push([`() => (`, attribute.argument, `)`])\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst key = JSON.stringify(\n\t\t\t\t\tattribute.name.type === `JSXNamespacedName`\n\t\t\t\t\t\t? `${attribute.name.namespace.name}:${attribute.name.name.name}`\n\t\t\t\t\t\t: attribute.name.name,\n\t\t\t\t)\n\t\t\t\tconst value = attribute.value\n\t\t\t\tif (!value) properties.push([`${key}: true`])\n\t\t\t\telse if (value.type === `Literal`)\n\t\t\t\t\tproperties.push([`${key}: ${JSON.stringify(decodeJsx(value.value))}`])\n\t\t\t\telse {\n\t\t\t\t\tconst expr =\n\t\t\t\t\t\tvalue.type === `JSXExpressionContainer` ? value.expression : value\n\t\t\t\t\tproperties.push(\n\t\t\t\t\t\tkey === `\"key\"` || eager(expr)\n\t\t\t\t\t\t\t? [`${key}: (`, expr, `)`]\n\t\t\t\t\t\t\t: [`get ${key}(){ return (`, expr, `); }`],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst component =\n\t\t\tnode.type === `JSXElement` &&\n\t\t\t!tag(node.openingElement.name).startsWith(`\"`)\n\t\tconst children: Part[][] = []\n\t\tlet lazyChildren = false\n\t\tfor (const child of node.children) {\n\t\t\tif (child.type === `JSXText`) {\n\t\t\t\tconst value = text(decodeJsx(child.value))\n\t\t\t\tif (value) children.push([JSON.stringify(value)])\n\t\t\t} else if (child.type === `JSXElement` || child.type === `JSXFragment`)\n\t\t\t\tchildren.push([child])\n\t\t\telse if (child.type === `JSXExpressionContainer`) {\n\t\t\t\tif (child.expression.type !== `JSXEmptyExpression`) {\n\t\t\t\t\tif (component) {\n\t\t\t\t\t\t// Component props expose their declared values, including callbacks.\n\t\t\t\t\t\tchildren.push([`(`, child.expression, `)`])\n\t\t\t\t\t\tif (!eager(child.expression, true)) lazyChildren = true\n\t\t\t\t\t} else children.push(expression(child.expression))\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tthrow new SyntaxError(`${filename}: JSX spread children are unsupported`)\n\t\t}\n\t\tif (children.length) {\n\t\t\tconst value =\n\t\t\t\tchildren.length === 1 ? children[0] : [`[`, ...join(children, `, `), `]`]\n\t\t\tif (lazyChildren) {\n\t\t\t\t// Capture the computation outside the getter's method scope.\n\t\t\t\tconst read = uid(`children`)\n\t\t\t\tproperties.push([`get children(){ return ${read}(); }`])\n\t\t\t\tchunks.push([\n\t\t\t\t\t`((${read}) => ({`,\n\t\t\t\t\t...join(properties, `, `),\n\t\t\t\t\t`}))(() => (`,\n\t\t\t\t\t...value,\n\t\t\t\t\t`))`,\n\t\t\t\t])\n\t\t\t\tproperties = []\n\t\t\t} else properties.push([`children: `, ...value])\n\t\t}\n\t\tflush()\n\t\tconst spreads =\n\t\t\tnode.type === `JSXElement` &&\n\t\t\tnode.openingElement.attributes.some(\n\t\t\t\t(attr) => attr.type === `JSXSpreadAttribute`,\n\t\t\t)\n\t\tconst props = spreads\n\t\t\t? [`${merge}(`, ...join(chunks, `, `), `)`]\n\t\t\t: (chunks[0] ?? [`{}`])\n\t\trewrite(node, [\n\t\t\t`${create}(${node.type === `JSXElement` ? tag(node.openingElement.name) : `null`}, `,\n\t\t\t...props,\n\t\t\t`)`,\n\t\t])\n\t}\n\tconst components = new Set<string>()\n\tfor (const fn of functions) {\n\t\tlet node = fn\n\t\tlet parent = parents.get(node)\n\t\twhile (parent?.type === `ParenthesizedExpression`) {\n\t\t\tnode = parent\n\t\t\tparent = parents.get(node)\n\t\t}\n\t\tif (fn.type === `FunctionDeclaration` && fn.id) components.add(fn.id.name)\n\t\telse if (\n\t\t\tparent?.type === `VariableDeclarator` &&\n\t\t\tparent.id.type === `Identifier`\n\t\t)\n\t\t\tcomponents.add(parent.id.name)\n\t\telse if (parent?.type === `ExportDefaultDeclaration`) {\n\t\t\tconst name = uid(`Component`)\n\t\t\tif (fn.type === `FunctionDeclaration`) {\n\t\t\t\t// Keep anonymous default function declarations hoisted.\n\t\t\t\tconst token = [\n\t\t\t\t\t...code\n\t\t\t\t\t\t.slice(fn.start, fn.body!.start)\n\t\t\t\t\t\t.matchAll(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*|\\bfunction\\b|\\*/g),\n\t\t\t\t].find((match) => match[0] === (fn.generator ? `*` : `function`))!\n\t\t\t\toutput.appendLeft(fn.start + token.index + token[0].length, ` ${name}`)\n\t\t\t} else {\n\t\t\t\t// Replace only keywords so intervening comments and annotations survive.\n\t\t\t\tconst prefix = code.slice(parent.start, node.start)\n\t\t\t\tfor (const token of prefix.matchAll(\n\t\t\t\t\t/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*|\\b(?:export|default)\\b/g,\n\t\t\t\t)) {\n\t\t\t\t\tif (token[0] !== `export` && token[0] !== `default`) continue\n\t\t\t\t\toutput.update(\n\t\t\t\t\t\tparent.start + token.index,\n\t\t\t\t\t\tparent.start + token.index + token[0].length,\n\t\t\t\t\t\ttoken[0] === `export` ? `const ${name} =` : ``,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\toutput.appendLeft(parent.end, `;\\nexport default ${name};`)\n\t\t\t}\n\t\t\tcomponents.add(name)\n\t\t}\n\t}\n\tif (elements.length) {\n\t\t// Keep hashbangs and directive prologues ahead of generated imports.\n\t\tlet position = parsed.program.hashbang?.end ?? 0\n\t\tfor (const statement of parsed.program.body) {\n\t\t\tif (statement.type !== `ExpressionStatement` || !statement.directive) break\n\t\t\tposition = statement.end\n\t\t}\n\t\toutput.appendLeft(\n\t\t\tposition,\n\t\t\t`\\nimport { jsx as ${create}, merge as ${merge} } from \"@atom.io/spa/jsx-runtime\";\\n`,\n\t\t)\n\t\tfor (const component of components)\n\t\t\toutput.append(`\\n;${component}.spa = true;`)\n\t}\n\treturn {\n\t\tcode: output.toString(),\n\t\tmap: output.generateMap({\n\t\t\tsource: filename,\n\t\t\tincludeContent: true,\n\t\t\thires: true,\n\t\t}),\n\t}\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":";;;;AAcA,MAAM,aAAa,UAClB,OAAO,OAAO;CAAE,OAAO;CAAS,OAAO;AAAS,CAAC;;AAGlD,SAAS,KAAK,OAAuB;CACpC,MAAM,QAAQ,MAAM,MAAM,YAAY;CACtC,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,IAAI,SAAS,KAAK,MAAM,EAAE,GAAG,OAAO;CAC3E,OAAO,MACL,KAAK,MAAM,MAAM;EACjB,OAAO,KAAK,QAAQ,OAAO,GAAG;EAC9B,IAAI,IAAI,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE;EACxC,IAAI,IAAI,MAAM,SAAS,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE;EACvD,OAAO,QAAQ,IAAI,OAAO,GAAG,KAAK,KAAK;CACxC,CAAC,CAAC,CACD,KAAK,EAAE;AACV;AAEA,SAAS,MAAM,MAAY,WAAW,OAAgB;CACrD,IAAI,KAAK,SAAS,2BACjB,OAAO,MAAM,KAAK,YAAY,QAAQ;CACvC,OACC,KAAK,SAAS,aACd,KAAK,SAAS,wBAC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OAAO;EACR,CAAC;CACF;AACD;;AClRA,SAAwB,IAAI,UAA4B,CAAC,GAAW;CACnE,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,WAAW,OAAwB;EACxC,QAAQ,YAAY;EACpB,OAAO,CAAC,GAAG,SAAS,gBAAgB,KAAK,QAAQ,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE;CACvE;CACA,OAAO;EACN,MAAM;EACN,SAAS;EACT,SAAS;GACR,OAAO;IACN,SAAS,EAAE,QAAQ,CAAC,gBAAgB,SAAS,EAAE;IAC/C,cAAc,EAAE,SAAS,CAAC,gBAAgB,SAAS,EAAE;GACtD;EACD;EACA,mBAAmB;GAClB,OAAO;GACP,QAAQ,OAAO,QAAQ;IAItB,IAAI,OAAO,cAAc,SACxB,OAAO,aAAa,UAAU,OAAO,aAAa,QAAQ,QACxD,OAAO,CAAC,mCAAmC,KAAK,EAAE,CACpD;GAEF;EACD;EACA,UAAU,MAAM,IAAI;GACnB,IAAI,CAAC,QAAQ,EAAE,GAAG;GAClB,OAAO,QAAQ,MAAM,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"}
package/dist/vite.js CHANGED
@@ -1 +1 @@
1
- export { t as default } from "./vite-CSHoxzXU.js";
1
+ export { t as default } from "./vite-Bmyb6P5w.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atom.io/spa",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "An atom.io-driven JSX renderer.",
5
5
  "homepage": "https://atom.io.fyi/docs/spa",
6
6
  "repository": {
@@ -83,6 +83,21 @@
83
83
  "types": "./dist/motion.d.ts",
84
84
  "development": "./dist/development/motion.js",
85
85
  "import": "./dist/motion.js"
86
+ },
87
+ "./floating": {
88
+ "types": "./dist/floating.d.ts",
89
+ "development": "./dist/development/floating.js",
90
+ "import": "./dist/floating.js"
91
+ },
92
+ "./astro-resumability-client": {
93
+ "types": "./dist/astro-resumability-client.d.ts",
94
+ "development": "./dist/development/astro-resumability-client.js",
95
+ "import": "./dist/astro-resumability-client.js"
96
+ },
97
+ "./astro-resumability-server": {
98
+ "types": "./dist/astro-resumability-server.d.ts",
99
+ "development": "./dist/development/astro-resumability-server.js",
100
+ "import": "./dist/astro-resumability-server.js"
86
101
  }
87
102
  },
88
103
  "main": "./dist/index.js",
@@ -98,37 +113,44 @@
98
113
  },
99
114
  "devDependencies": {
100
115
  "@breakage/changesets": "0.1.0",
116
+ "@floating-ui/dom": "1.8.0",
101
117
  "@jridgewell/trace-mapping": "0.3.31",
102
118
  "@types/node": "26.6.6",
103
119
  "@types/three": "0.187.0",
104
120
  "@vitest/coverage-v8": "5.1.0",
105
- "astro": "7.4.5",
106
- "atom.io": "0.54.5",
121
+ "astro": "7.4.7",
122
+ "atom.io": "0.54.7",
107
123
  "breakage": "0.10.2",
108
124
  "esbuild": "0.28.2",
109
125
  "eslint": "10.14.0",
110
126
  "happy-dom": "21.0.4",
111
127
  "konva": "10.9.1",
112
- "motion": "14.9.1",
113
- "playwright": "1.64.1",
114
- "preact": "11.1.1",
115
- "rolldown": "1.2.16",
128
+ "motion": "14.10.1",
129
+ "playwright": "1.65.0",
130
+ "preact": "11.2.0",
131
+ "resumability": "0.0.2",
132
+ "rolldown": "1.3.0",
116
133
  "three": "0.187.0",
117
- "tsdown": "0.23.5",
134
+ "tsdown": "0.23.7",
118
135
  "typescript": "7.0.2",
119
- "vite": "8.3.5",
136
+ "vite": "8.3.6",
120
137
  "vitest": "5.1.0"
121
138
  },
122
139
  "peerDependencies": {
140
+ "@floating-ui/dom": "^1.8.0",
123
141
  "@types/three": "^0.187.0",
124
142
  "astro": "^7.4.2",
125
143
  "atom.io": "^0.54.4",
126
144
  "konva": "^10.9.1",
127
145
  "motion": "^14.9.0",
146
+ "resumability": "^0.0.2",
128
147
  "three": "^0.187.0",
129
148
  "vite": "^8.3.5"
130
149
  },
131
150
  "peerDependenciesMeta": {
151
+ "@floating-ui/dom": {
152
+ "optional": true
153
+ },
132
154
  "@types/three": {
133
155
  "optional": true
134
156
  },
@@ -141,6 +163,9 @@
141
163
  "motion": {
142
164
  "optional": true
143
165
  },
166
+ "resumability": {
167
+ "optional": true
168
+ },
144
169
  "three": {
145
170
  "optional": true
146
171
  },
@@ -163,7 +188,7 @@
163
188
  "test:once": "vitest run --config vitest.config.ts && pnpm test:consumer && pnpm test:optional-peers",
164
189
  "test:consumer": "node __tests__/fixtures/consumer/check.ts",
165
190
  "test:production": "node scripts/production-test.ts",
166
- "test:browser": "astro build --root __tests__/astro && node scripts/browser-test.mjs && node scripts/dev-browser-test.mjs && node scripts/graphics-browser-test.mjs",
191
+ "test:browser": "astro build --root __tests__/astro && node scripts/browser-test.mjs && node scripts/dev-browser-test.mjs && node scripts/graphics-browser-test.mjs && pnpm test:browser:resumption",
167
192
  "test:browser:dev": "node scripts/dev-browser-test.mjs",
168
193
  "cov": "vitest run --config vitest.config.ts --coverage",
169
194
  "readme:write": "galley write README.mdx",
@@ -174,6 +199,9 @@
174
199
  "test:optional-peers": "node scripts/optional-peers-check.mjs && node __tests__/fixtures/graphics-consumer/check.ts",
175
200
  "bench:compiler": "node scripts/compiler-benchmark.ts",
176
201
  "example:motion": "vite --config examples/motion/vite.config.ts",
177
- "test:browser:motion": "node scripts/motion-browser-test.mjs"
202
+ "test:browser:motion": "node scripts/motion-browser-test.mjs",
203
+ "example:floating": "vite --config examples/floating/vite.config.ts",
204
+ "test:browser:floating": "node scripts/floating-browser-test.mjs",
205
+ "test:browser:resumption": "astro build --root __tests__/resumption && node scripts/resumption-browser-test.mjs && node scripts/resumption-browser-test.mjs --dev"
178
206
  }
179
207
  }
@@ -1,16 +1,17 @@
1
- import type { RegularAtomFamilyToken } from "atom.io"
1
+ import type { ReadableToken, RegularAtomFamilyToken } from "atom.io"
2
2
  import type { RootStore } from "atom.io/internal"
3
3
  import {
4
4
  createRegularAtomFamily,
5
5
  disposeFromStore,
6
6
  findInStore,
7
+ getFromStore,
7
8
  IMPLICIT,
8
9
  setIntoStore,
9
10
  } from "atom.io/internal"
10
11
 
11
12
  import { browserApplication } from "./astro-application.ts"
12
13
  import { failPreparation, storeContext } from "./astro-context.ts"
13
- import type { Island } from "./astro-shared.ts"
14
+ import type { AstroStorePreparation, Island } from "./astro-shared.ts"
14
15
  import { island, islandStore } from "./astro-shared.ts"
15
16
  import { onCleanup, useGetter } from "./core.ts"
16
17
  import { hydrate, render } from "./dom.ts"
@@ -36,7 +37,9 @@ type State = { props: Props; slots: Slots }
36
37
  const states = new WeakMap<RootStore, RegularAtomFamilyToken<State, number>>()
37
38
  let serial = 0
38
39
 
39
- export default (element: HTMLElement): Hydrator =>
40
+ export const createHydrator =
41
+ (prepare?: AstroStorePreparation) =>
42
+ (element: HTMLElement): Hydrator =>
40
43
  async (component, props, slots, { client }) => {
41
44
  const previous = roots.get(element)
42
45
  if (previous?.component === component) {
@@ -73,6 +76,7 @@ export default (element: HTMLElement): Hydrator =>
73
76
  props,
74
77
  lifetime.context,
75
78
  shared ? IMPLICIT.STORE : undefined,
79
+ prepare,
76
80
  ),
77
81
  lifetime.cancelled,
78
82
  ])
@@ -81,7 +85,14 @@ export default (element: HTMLElement): Hydrator =>
81
85
  const replace =
82
86
  client === `only` ||
83
87
  previous !== undefined ||
84
- application?.canResume === false
88
+ application?.canResume === false ||
89
+ // Server-settled state without a synchronous browser seed needs a
90
+ // fresh view, whose loading state can differ from the SSR markup.
91
+ (
92
+ JSON.parse(
93
+ element.getAttribute(`data-spa-reads`) ?? `[]`,
94
+ ) as ReadableToken<unknown>[]
95
+ ).some((token) => getFromStore(store!, token) instanceof Promise)
85
96
  // Astro leaves this sentinel on islands inserted by ClientRouter.
86
97
  const sentinel = element.lastChild
87
98
  if (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`)
@@ -135,3 +146,5 @@ export default (element: HTMLElement): Hydrator =>
135
146
  lifetime.context.onCleanup(dispose)
136
147
  return ready
137
148
  }
149
+
150
+ export default createHydrator()
@@ -61,7 +61,7 @@ export function requestApplication(
61
61
  return app
62
62
  }
63
63
  /** Install definitions imported after an earlier island started this request. */
64
- export function syncDefinitions(store: RootStore): void {
64
+ function syncDefinitions(store: RootStore): void {
65
65
  const source = IMPLICIT.STORE
66
66
  for (const field of [
67
67
  `families`,
@@ -0,0 +1,40 @@
1
+ import {
2
+ browserResumption,
3
+ captureElement,
4
+ createResumption,
5
+ } from "resumability/astro-client"
6
+
7
+ import { browserApplication } from "./astro-application.ts"
8
+ import { createHydrator } from "./astro-client.ts"
9
+
10
+ export default createHydrator((store, _props, { element, application }) => {
11
+ const scopes = application.get(
12
+ createResumption,
13
+ () => new WeakMap<object, ReturnType<typeof createResumption>>(),
14
+ )
15
+ let scope = scopes.get(store)
16
+ if (!scope) {
17
+ const shared = application === browserApplication(element!.ownerDocument)
18
+ if (shared) {
19
+ const host = browserResumption(element!.ownerDocument)
20
+ application.onCleanup(host.resumeWhen(() => application.canResume))
21
+ scope = host
22
+ } else {
23
+ // Lazy defaults can run after component setup. Bind their private owner so
24
+ // refreshes and pending work end with this island instead of the page.
25
+ const original = store.runDefault
26
+ const local = createResumption()
27
+ store.runDefault = <T>(run: () => T): T =>
28
+ local.run(() => original.call(store, run) as T, {
29
+ resume: application.canResume,
30
+ })
31
+ application.onCleanup(() => {
32
+ local.dispose()
33
+ store.runDefault = original
34
+ })
35
+ scope = local
36
+ }
37
+ scopes.set(store, scope)
38
+ }
39
+ captureElement(scope, element!)
40
+ })
@@ -0,0 +1,7 @@
1
+ import { resumableRenderer } from "resumability/astro-server"
2
+
3
+ import { createRenderer } from "./astro-server.ts"
4
+
5
+ export default resumableRenderer(createRenderer(true), {
6
+ isolate: (component) => Boolean(component.createStore ?? component.isolate),
7
+ })
@@ -1,13 +1,16 @@
1
1
  /* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */
2
2
  import type { NamedSSRLoadedRendererValue } from "astro"
3
+ import type { ReadableToken } from "atom.io"
3
4
 
4
5
  import { failPreparation, storeContext } from "./astro-context.ts"
5
6
  import { requestApplication } from "./astro-request.ts"
6
7
  import type { Island } from "./astro-shared.ts"
7
8
  import { island, islandStore } from "./astro-shared.ts"
8
- import { renderToString } from "./server.ts"
9
+ import { renderToStringWithReads } from "./server-renderer.ts"
9
10
 
10
- const renderer: NamedSSRLoadedRendererValue = {
11
+ export const createRenderer = (
12
+ awaitState = false,
13
+ ): NamedSSRLoadedRendererValue => ({
11
14
  name: `spa`,
12
15
  async check(component: Island) {
13
16
  return component?.spa === true
@@ -15,24 +18,60 @@ const renderer: NamedSSRLoadedRendererValue = {
15
18
  async renderToStaticMarkup(component: Island, props, slots) {
16
19
  const request = (this as unknown as { result?: { request: Request } }).result
17
20
  ?.request
21
+ const requestOwner = request ? requestApplication(request) : undefined
18
22
  const shared =
19
- !component.createStore && !component.isolate && request
20
- ? requestApplication(request)
21
- : undefined
23
+ !component.createStore && !component.isolate ? requestOwner : undefined
22
24
  const lifetime = storeContext(undefined, shared?.application)
23
- try {
24
- const store = await islandStore(
25
- component,
26
- props,
27
- lifetime.context,
28
- shared?.store,
25
+ if (requestOwner && !shared) {
26
+ lifetime.context.onCleanup(
27
+ requestOwner.application.onCleanup(lifetime.dispose),
29
28
  )
30
- return {
31
- html: renderToString(() => () => island(component, props, slots), {
32
- store,
33
- idPrefix: crypto.randomUUID(),
34
- capabilities: component.capabilities ?? [],
35
- }),
29
+ }
30
+ try {
31
+ lifetime.context.signal.throwIfAborted()
32
+ const store = await Promise.race([
33
+ islandStore(component, props, lifetime.context, shared?.store),
34
+ lifetime.cancelled,
35
+ ])
36
+ lifetime.context.signal.throwIfAborted()
37
+ const options = {
38
+ store: store!,
39
+ idPrefix: crypto.randomUUID(),
40
+ capabilities: component.capabilities ?? [],
41
+ }
42
+ // Retry only after reads made by this view settle. Each discarded render
43
+ // releases its scopes; conditional branches can discover more async state.
44
+ for (;;) {
45
+ lifetime.context.signal.throwIfAborted()
46
+ const reads = new Map<string, ReadableToken<unknown>>()
47
+ const pending = new Set<Promise<unknown>>()
48
+ const html = renderToStringWithReads(
49
+ () => () => island(component, props, slots),
50
+ options,
51
+ awaitState
52
+ ? (value, token) => {
53
+ reads.set(token.key, token)
54
+ if (value instanceof Promise) {
55
+ pending.add(value)
56
+ }
57
+ }
58
+ : undefined,
59
+ )
60
+ if (!pending.size)
61
+ return {
62
+ html,
63
+ // Even a cached synchronous server read can be async in the browser.
64
+ ...(reads.size
65
+ ? {
66
+ attrs: {
67
+ "data-spa-reads": JSON.stringify([...reads.values()]),
68
+ },
69
+ }
70
+ : {}),
71
+ }
72
+ // Caught producer errors resolve as state values. An uncaught failure
73
+ // must reject this render with its original error.
74
+ await Promise.race([Promise.all(pending), lifetime.cancelled])
36
75
  }
37
76
  } catch (error) {
38
77
  failPreparation(error, lifetime.dispose)
@@ -40,5 +79,5 @@ const renderer: NamedSSRLoadedRendererValue = {
40
79
  lifetime.dispose()
41
80
  }
42
81
  },
43
- }
44
- export default renderer
82
+ })
83
+ export default createRenderer()