@atom.io/spa 0.0.2 → 0.0.4

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 (94) hide show
  1. package/README.md +144 -47
  2. package/README.mdx +37 -11
  3. package/dist/astro-application.d.ts +1 -1
  4. package/dist/astro-application.js +2 -2
  5. package/dist/astro-application.js.map +1 -1
  6. package/dist/astro-client.d.ts +1 -1
  7. package/dist/astro-client.js +4 -4
  8. package/dist/astro-client.js.map +1 -1
  9. package/dist/{astro-shared-DyzbUi6c.d.ts → astro-shared-CYSRrRr8.d.ts} +2 -2
  10. package/dist/{astro-shared-DyzbUi6c.d.ts.map → astro-shared-CYSRrRr8.d.ts.map} +1 -1
  11. package/dist/astro.d.ts +1 -1
  12. package/dist/capabilities-BkQ2i0vV.js +63 -0
  13. package/dist/capabilities-BkQ2i0vV.js.map +1 -0
  14. package/dist/{capabilities-yC9TsHDI.d.ts → capabilities-D3HObAIy.d.ts} +66 -11
  15. package/dist/capabilities-D3HObAIy.d.ts.map +1 -0
  16. package/dist/client.min.js +1 -1
  17. package/dist/{capabilities-BuZUQpiD.js → core-Bl1Ec1hY.js} +42 -79
  18. package/dist/core-Bl1Ec1hY.js.map +1 -0
  19. package/dist/development/astro-application.js +2 -2
  20. package/dist/development/astro-application.js.map +1 -1
  21. package/dist/development/astro-client.js +4 -4
  22. package/dist/development/astro-client.js.map +1 -1
  23. package/dist/development/capabilities-BkQ2i0vV.js +63 -0
  24. package/dist/development/capabilities-BkQ2i0vV.js.map +1 -0
  25. package/dist/development/{capabilities-DhOJmeoJ.js → core-DZFaOyTO.js} +42 -79
  26. package/dist/development/core-DZFaOyTO.js.map +1 -0
  27. package/dist/development/{dom-BKc6V_Kz.js → dom-Dwa2SFTn.js} +16 -7
  28. package/dist/development/dom-Dwa2SFTn.js.map +1 -0
  29. package/dist/development/index.js +4 -4
  30. package/dist/development/konva.js +25 -3
  31. package/dist/development/konva.js.map +1 -1
  32. package/dist/development/motion.js +392 -8
  33. package/dist/development/motion.js.map +1 -1
  34. package/dist/development/renderer.js +23 -10
  35. package/dist/development/renderer.js.map +1 -1
  36. package/dist/development/server.js +2 -1
  37. package/dist/development/server.js.map +1 -1
  38. package/dist/development/{src-Dh-d6w4y.js → src-BUtG4BgX.js} +4 -4
  39. package/dist/development/src-BUtG4BgX.js.map +1 -0
  40. package/dist/development/three.js +24 -10
  41. package/dist/development/three.js.map +1 -1
  42. package/dist/{dom-B2rm8o2L.js → dom-Cfj3GtQK.js} +16 -7
  43. package/dist/dom-Cfj3GtQK.js.map +1 -0
  44. package/dist/{index-BdwxmSKg.d.ts → index-YRZ79lN5.d.ts} +3 -3
  45. package/dist/{index-BdwxmSKg.d.ts.map → index-YRZ79lN5.d.ts.map} +1 -1
  46. package/dist/index.d.ts +4 -4
  47. package/dist/index.js +4 -4
  48. package/dist/{jsx-runtime-CZU7F8Qz.d.ts → jsx-runtime-Q-UBV97Y.d.ts} +2 -2
  49. package/dist/{jsx-runtime-CZU7F8Qz.d.ts.map → jsx-runtime-Q-UBV97Y.d.ts.map} +1 -1
  50. package/dist/jsx-runtime.d.ts +1 -1
  51. package/dist/konva.d.ts +3 -3
  52. package/dist/konva.d.ts.map +1 -1
  53. package/dist/konva.js +25 -3
  54. package/dist/konva.js.map +1 -1
  55. package/dist/motion.d.ts +2 -1
  56. package/dist/motion.d.ts.map +1 -1
  57. package/dist/motion.js +392 -8
  58. package/dist/motion.js.map +1 -1
  59. package/dist/renderer.d.ts +3 -3
  60. package/dist/renderer.d.ts.map +1 -1
  61. package/dist/renderer.js +23 -10
  62. package/dist/renderer.js.map +1 -1
  63. package/dist/server.d.ts +1 -1
  64. package/dist/server.js +2 -1
  65. package/dist/server.js.map +1 -1
  66. package/dist/size.json +12 -12
  67. package/dist/{src-BZxX4xbU.js → src-DvkUMuNW.js} +4 -4
  68. package/dist/src-DvkUMuNW.js.map +1 -0
  69. package/dist/three.d.ts +3 -3
  70. package/dist/three.d.ts.map +1 -1
  71. package/dist/three.js +24 -10
  72. package/dist/three.js.map +1 -1
  73. package/package.json +9 -7
  74. package/src/astro-application.ts +2 -2
  75. package/src/astro-client.ts +3 -3
  76. package/src/capabilities.ts +21 -2
  77. package/src/core.ts +66 -41
  78. package/src/dom.ts +35 -4
  79. package/src/index.ts +2 -2
  80. package/src/konva.ts +41 -14
  81. package/src/motion-tween.ts +106 -0
  82. package/src/motion.ts +122 -9
  83. package/src/presence.ts +324 -0
  84. package/src/renderer.ts +51 -14
  85. package/src/three-events.ts +13 -1
  86. package/src/three.ts +38 -15
  87. package/src/use-loadable.ts +3 -3
  88. package/dist/capabilities-BuZUQpiD.js.map +0 -1
  89. package/dist/capabilities-yC9TsHDI.d.ts.map +0 -1
  90. package/dist/development/capabilities-DhOJmeoJ.js.map +0 -1
  91. package/dist/development/dom-BKc6V_Kz.js.map +0 -1
  92. package/dist/development/src-Dh-d6w4y.js.map +0 -1
  93. package/dist/dom-B2rm8o2L.js.map +0 -1
  94. package/dist/src-BZxX4xbU.js.map +0 -1
@@ -1,12 +1,21 @@
1
- import { C as within, a as createScope, c as invalidate, f as owner, h as untrack, i as createRoot, l as observe, n as capabilityProps, o as dispose, s as fail } from "./capabilities-DhOJmeoJ.js";
1
+ import { n as capabilityProps } from "./capabilities-BkQ2i0vV.js";
2
+ import { a as invalidate, i as fail, n as createScope, o as isPresent, p as untrack, r as dispose, s as observe, t as createRoot, u as owner, x as within } from "./core-DZFaOyTO.js";
2
3
  import { Fragment, merge } from "./jsx-runtime.js";
3
4
  // src/renderer.ts
4
5
  /** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */
5
6
  function createSceneRenderer(host) {
6
7
  function mount(source, scope, changed) {
7
8
  let entries = [];
9
+ const presence = scope._root._presence?.collection((entry) => entry.scope, (entry, value) => same(entry.value, value));
10
+ const retire = (entry, id, eligible, index) => {
11
+ if (presence) presence.remove(entry, id, eligible, index, () => {
12
+ if (!scope._dead) changed();
13
+ });
14
+ else dispose(entry.scope);
15
+ };
8
16
  observe(scope, source, (next) => {
9
17
  const values = Array.isArray(next) ? next.flat(Infinity) : [next];
18
+ const previous = entries;
10
19
  const old = new Map(entries.map((entry, i) => [key(entry.value, i), entry]));
11
20
  const seen = /* @__PURE__ */ new Set();
12
21
  entries = values.map((value, i) => {
@@ -16,11 +25,13 @@ function createSceneRenderer(host) {
16
25
  let entry = old.get(id);
17
26
  old.delete(id);
18
27
  if (entry && !same(entry.value, value)) {
19
- dispose(entry.scope);
28
+ retire(entry, id, value == null || typeof value === `boolean`, previous.indexOf(entry));
20
29
  entry = void 0;
21
30
  }
31
+ entry ??= presence?.take(id, value);
22
32
  if (entry) {
23
33
  entry.value = value;
34
+ scope._root._presence?.resume(entry.scope);
24
35
  invalidate(entry.scope);
25
36
  return entry;
26
37
  }
@@ -33,10 +44,12 @@ function createSceneRenderer(host) {
33
44
  created.nodes = build(() => created.value, childScope, changed);
34
45
  return created;
35
46
  });
36
- for (const entry of old.values()) dispose(entry.scope);
47
+ for (const [id, entry] of old) retire(entry, id, true, previous.indexOf(entry));
37
48
  changed();
38
49
  });
39
- return () => entries.flatMap((entry) => entry.nodes());
50
+ return (activeOnly = false) => {
51
+ return (activeOnly ? entries : presence?.merge(entries) ?? entries).flatMap((entry) => entry.nodes(activeOnly));
52
+ };
40
53
  }
41
54
  function key(value, i) {
42
55
  const explicit = value?.props?.[`key`];
@@ -65,7 +78,7 @@ function createSceneRenderer(host) {
65
78
  const nativeProps = capabilityProps(scope, host.target?.(node) ?? {
66
79
  kind: `scene`,
67
80
  node
68
- });
81
+ }, () => ({ ...props }));
69
82
  let previous = {};
70
83
  observe(scope, () => ({ ...props }), (all) => {
71
84
  const next = nativeProps(all);
@@ -74,7 +87,7 @@ function createSceneRenderer(host) {
74
87
  });
75
88
  let children = () => [];
76
89
  const sync = () => {
77
- host.children(node, children());
90
+ host.children(node, children(), children(true));
78
91
  };
79
92
  children = mount(() => props[`children`], scope, sync);
80
93
  sync();
@@ -90,12 +103,12 @@ function createSceneRenderer(host) {
90
103
  function attach(setup, parent, scope) {
91
104
  let nodes = () => [];
92
105
  const sync = () => {
93
- host.children(parent, nodes());
106
+ host.children(parent, nodes(), nodes(true));
94
107
  };
95
108
  nodes = mount(() => untrack(setup), scope, sync);
96
109
  sync();
97
110
  scope._cleanups.add(() => {
98
- host.children(parent, []);
111
+ host.children(parent, [], []);
99
112
  });
100
113
  }
101
114
  return {
@@ -140,12 +153,12 @@ function bindScene(read, apply) {
140
153
  observe(owner, read, apply);
141
154
  }
142
155
  /** Scene drawing follows an installed capability clock, or the browser clock. */
143
- function onSceneFrame(callback) {
156
+ function onSceneFrame(callback, infrastructure = false) {
144
157
  const scope = owner;
145
158
  const clocks = [...scope._root._capabilities.values()].filter((capability) => capability.scheduleFrame);
146
159
  if (clocks.length > 1) throw new Error(`spa: multiple frame clock capabilities`);
147
160
  const draw = (time) => {
148
- if (scope._dead) return;
161
+ if (scope._dead || !infrastructure && !isPresent(scope)) return;
149
162
  try {
150
163
  callback(time);
151
164
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","names":[],"sources":["../../src/renderer.ts"],"sourcesContent":["import type { CapabilityTarget } from \"./capabilities.ts\"\nimport { capabilityProps } from \"./capabilities.ts\"\nimport type { Child, Component, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tobserve,\n\towner,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nexport interface SceneHost<N> {\n\ttarget?(node: N): CapabilityTarget\n\tcreate(type: string, props: Record<string, any>): N\n\tupdate(\n\t\tnode: N,\n\t\tprops: Record<string, any>,\n\t\tprevious: Record<string, any>,\n\t): void\n\tchildren(parent: N, children: N[]): void\n\tdestroy(node: N): void\n}\ninterface Entry<N> {\n\tscope: Scope\n\tvalue: Child\n\tnodes: () => N[]\n}\n\nexport interface SceneRenderer<N> {\n\tmount(setup: () => Child, parent: N): void\n\trender(\n\t\tsetup: () => Child,\n\t\tparent: N,\n\t\toptions?: RootOptions,\n\t): { flush(): void; dispose(): void }\n}\n\n/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */\nexport function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {\n\tfunction mount(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): () => N[] {\n\t\tlet entries: Entry<N>[] = []\n\t\tobserve(scope, source, (next) => {\n\t\t\tconst values = (\n\t\t\t\tArray.isArray(next) ? next.flat(Infinity) : [next]\n\t\t\t) as Child[]\n\t\t\tconst old = new Map(\n\t\t\t\tentries.map((entry, i) => [key(entry.value, i), entry]),\n\t\t\t)\n\t\t\tconst seen = new Set<string>()\n\t\t\tentries = values.map((value, i) => {\n\t\t\t\tconst id = key(value, i)\n\t\t\t\tif (seen.has(id)) throw new Error(`spa: duplicate scene key`)\n\t\t\t\tseen.add(id)\n\t\t\t\tlet entry = old.get(id)\n\t\t\t\told.delete(id)\n\t\t\t\tif (entry && !same(entry.value, value)) {\n\t\t\t\t\tdispose(entry.scope)\n\t\t\t\t\tentry = undefined\n\t\t\t\t}\n\t\t\t\tif (entry) {\n\t\t\t\t\tentry.value = value\n\t\t\t\t\tinvalidate(entry.scope)\n\t\t\t\t\treturn entry\n\t\t\t\t}\n\t\t\t\tconst childScope = createScope(scope)\n\t\t\t\tconst created: Entry<N> = { scope: childScope, value, nodes: null! }\n\t\t\t\tcreated.nodes = build(() => created.value, childScope, changed)\n\t\t\t\treturn created\n\t\t\t})\n\t\t\tfor (const entry of old.values()) dispose(entry.scope)\n\t\t\tchanged()\n\t\t})\n\t\treturn () => entries.flatMap((entry) => entry.nodes())\n\t}\n\tfunction key(value: Child, i: number): string {\n\t\tconst explicit = (value as VNode | null)?.props?.[`key`]\n\t\treturn explicit == null ? `index:${i}` : `key:${explicit}`\n\t}\n\tfunction same(a: Child, b: Child): boolean {\n\t\treturn (\n\t\t\ttypeof a === typeof b &&\n\t\t\t(a as VNode | null)?.type === (b as VNode | null)?.type\n\t\t)\n\t}\n\tfunction build(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): () => N[] {\n\t\tconst value = untrack(source)\n\t\tif (typeof value === `function`)\n\t\t\treturn mount(() => (source() as () => Child)(), scope, changed)\n\t\tif (value == null || typeof value === `boolean`) return () => []\n\t\tif (typeof value !== `object`)\n\t\t\tthrow new Error(`spa: scene children must be nodes`)\n\t\tif (!(`type` in value) || !(`props` in value))\n\t\t\tthrow new Error(`spa: invalid scene child`)\n\t\tconst vnode = value\n\t\tconst props = merge(() => (source() as VNode).props)\n\t\tif (!vnode.type || vnode.type === Fragment)\n\t\t\treturn mount(() => props[`children`], scope, changed)\n\t\tif (typeof vnode.type === `function`) {\n\t\t\tconst output = within(scope, () =>\n\t\t\t\tuntrack(() => (vnode.type as Component)(props)),\n\t\t\t)\n\t\t\treturn mount(() => output, scope, changed)\n\t\t}\n\t\tconst node = host.create(\n\t\t\tvnode.type,\n\t\t\tuntrack(() => props),\n\t\t)\n\t\tscope._cleanups.add(() => {\n\t\t\thost.destroy(node)\n\t\t})\n\t\tconst nativeProps = capabilityProps(\n\t\t\tscope,\n\t\t\thost.target?.(node) ?? { kind: `scene`, node },\n\t\t)\n\t\tlet previous: Record<string, any> = {}\n\t\tobserve(\n\t\t\tscope,\n\t\t\t() => ({ ...props }),\n\t\t\t(all) => {\n\t\t\t\tconst next = nativeProps(all)\n\t\t\t\thost.update(node, next, previous)\n\t\t\t\tprevious = next\n\t\t\t},\n\t\t)\n\t\tlet children: () => N[] = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(node, children())\n\t\t}\n\t\tchildren = mount(() => props[`children`], scope, sync)\n\t\tsync()\n\t\tconst ref = untrack(() => props[`ref`])\n\t\tif (ref)\n\t\t\tscope._root._mounts!.unshift(() => {\n\t\t\t\tif (!scope._dead) {\n\t\t\t\t\tscope._cleanups.add(() => ref(null))\n\t\t\t\t\tref(node)\n\t\t\t\t}\n\t\t\t})\n\t\treturn () => [node]\n\t}\n\tfunction attach(setup: () => Child, parent: N, scope: Scope) {\n\t\tlet nodes: () => N[] = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(parent, nodes())\n\t\t}\n\t\tnodes = mount(() => untrack(setup), scope, sync)\n\t\tsync()\n\t\tscope._cleanups.add(() => {\n\t\t\thost.children(parent, [])\n\t\t})\n\t}\n\treturn {\n\t\t/** Attach beneath the current component; disposal follows its lifetime. */\n\t\tmount(setup: () => Child, parent: N): void {\n\t\t\tif (!owner) throw new Error(`spa: scene mount requires an owner`)\n\t\t\tconst scope = createScope(owner)\n\t\t\ttry {\n\t\t\t\tattach(setup, parent, scope)\n\t\t\t} catch (error) {\n\t\t\t\tfail(scope, error)\n\t\t\t}\n\t\t},\n\t\trender(setup: () => Child, parent: N, options: RootOptions = {}) {\n\t\t\tconst root = createRoot(options)\n\t\t\ttry {\n\t\t\t\twithin(root, () => {\n\t\t\t\t\tattach(setup, parent, root)\n\t\t\t\t})\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tfail(root, error)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tflush: root.flush,\n\t\t\t\tdispose: () => {\n\t\t\t\t\tdispose(root)\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\n/** Define a typed scene component without introducing another JSX runtime. */\nexport function sceneComponent<P>(type: string): (props: P) => VNode {\n\treturn (props) => ({ type, props: props as Record<string, any> })\n}\n\n/** Bind imperative scene work to the current owner and its reactive dependencies. */\nexport function bindScene<T>(read: () => T, apply: (value: T) => void): void {\n\tobserve(owner!, read, apply)\n}\n\n/** Scene drawing follows an installed capability clock, or the browser clock. */\nexport function onSceneFrame(callback: (time: number) => void): void {\n\tconst scope = owner!\n\tconst clocks = [...scope._root._capabilities.values()].filter(\n\t\t(capability) => capability.scheduleFrame,\n\t)\n\tif (clocks.length > 1)\n\t\tthrow new Error(`spa: multiple frame clock capabilities`)\n\tconst draw = (time: number) => {\n\t\tif (scope._dead) return\n\t\ttry {\n\t\t\tcallback(time)\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tfail(scope._root, error)\n\t\t\t} catch (failure) {\n\t\t\t\tscope._root.error(failure)\n\t\t\t}\n\t\t}\n\t}\n\tlet stop: () => void\n\tif (clocks[0]) stop = clocks[0].scheduleFrame!(draw)\n\telse {\n\t\tlet frame = 0\n\t\tconst tick = (time: number) => {\n\t\t\tif (scope._dead) return\n\t\t\tdraw(time)\n\t\t\tif (!scope._dead) frame = requestAnimationFrame(tick)\n\t\t}\n\t\tframe = requestAnimationFrame(tick)\n\t\tstop = () => {\n\t\t\tcancelAnimationFrame(frame)\n\t\t}\n\t}\n\tscope._cleanups.add(stop)\n}\n"],"mappings":";;;;AA2CA,SAAgB,oBAAuB,MAAsC;CAC5E,SAAS,MACR,QACA,OACA,SACY;EACZ,IAAI,UAAsB,CAAC;EAC3B,QAAQ,OAAO,SAAS,SAAS;GAChC,MAAM,SACL,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,QAAQ,IAAI,CAAC,IAAI;GAElD,MAAM,MAAM,IAAI,IACf,QAAQ,KAAK,OAAO,MAAM,CAAC,IAAI,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CACvD;GACA,MAAM,uBAAO,IAAI,IAAY;GAC7B,UAAU,OAAO,KAAK,OAAO,MAAM;IAClC,MAAM,KAAK,IAAI,OAAO,CAAC;IACvB,IAAI,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,0BAA0B;IAC5D,KAAK,IAAI,EAAE;IACX,IAAI,QAAQ,IAAI,IAAI,EAAE;IACtB,IAAI,OAAO,EAAE;IACb,IAAI,SAAS,CAAC,KAAK,MAAM,OAAO,KAAK,GAAG;KACvC,QAAQ,MAAM,KAAK;KACnB,QAAQ,KAAA;IACT;IACA,IAAI,OAAO;KACV,MAAM,QAAQ;KACd,WAAW,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Y;KAClB,OAAO,OAAO,QAAQ,IAAI;IAC3B,CAAC;IACD,KAAK,MAAM;GACZ,SAAS,OAAO;IACf,KAAK,MAAM,KAAK;GACjB;GACA,OAAO;IACN,OAAO,KAAK;IACZ,eAAe;KACd,QAAQ,IAAI;IACb;GACD;EACD;CACD;AACD;;AAGA,SAAgB,eAAkB,MAAmC;CACpE,QAAQ,WAAW;EAAE;EAAa;CAA6B;AAChE;;AAGA,SAAgB,UAAa,MAAe,OAAiC;CAC5E,QAAQ,OAAQ,MAAM,KAAK;AAC5B;;AAGA,SAAgB,aAAa,UAAwC;CACpE,MAAM,QAAQ;CACd,MAAM,SAAS,CAAC,GAAG,MAAM,MAAM,cAAc,OAAO,CAAC,CAAC,CAAC,QACrD,eAAe,WAAW,aAC5B;CACA,IAAI,OAAO,SAAS,GACnB,MAAM,IAAI,MAAM,wCAAwC;CACzD,MAAM,QAAQ,SAAiB;EAC9B,IAAI,MAAM,OAAO;EACjB,IAAI;GACH,SAAS,IAAI;EACd,SAAS,OAAO;GACf,IAAI;IACH,KAAK,MAAM,OAAO,KAAK;GACxB,SAAS,SAAS;IACjB,MAAM,MAAM,MAAM,OAAO;GAC1B;EACD;CACD;CACA,IAAI;CACJ,IAAI,OAAO,IAAI,OAAO,OAAO,EAAE,CAAC,cAAe,IAAI;MAC9C;EACJ,IAAI,QAAQ;EACZ,MAAM,QAAQ,SAAiB;GAC9B,IAAI,MAAM,OAAO;GACjB,KAAK,IAAI;GACT,IAAI,CAAC,MAAM,OAAO,QAAQ,sBAAsB,IAAI;EACrD;EACA,QAAQ,sBAAsB,IAAI;EAClC,aAAa;GACZ,qBAAqB,KAAK;EAC3B;CACD;CACA,MAAM,UAAU,IAAI,IAAI;AACzB"}
1
+ {"version":3,"file":"renderer.js","names":[],"sources":["../../src/renderer.ts"],"sourcesContent":["import type { CapabilityTarget } from \"./capabilities.ts\"\nimport { capabilityProps } from \"./capabilities.ts\"\nimport type { Child, Component, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tfail,\n\tinvalidate,\n\tisPresent,\n\tobserve,\n\towner,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment, merge } from \"./jsx-runtime.ts\"\n\nexport interface SceneHost<N> {\n\ttarget?(node: N): CapabilityTarget\n\tcreate(type: string, props: Record<string, any>): N\n\tupdate(\n\t\tnode: N,\n\t\tprops: Record<string, any>,\n\t\tprevious: Record<string, any>,\n\t): void\n\tchildren(parent: N, children: N[], activeChildren: N[]): void\n\tdestroy(node: N): void\n}\ntype SceneNodes<N> = (activeOnly?: boolean) => N[]\n\ninterface Entry<N> {\n\tscope: Scope\n\tvalue: Child\n\tnodes: SceneNodes<N>\n}\n\nexport interface SceneRenderer<N> {\n\tmount(setup: () => Child, parent: N): void\n\trender(\n\t\tsetup: () => Child,\n\t\tparent: N,\n\t\toptions?: RootOptions,\n\t): { flush(): void; dispose(): void }\n}\n\n/** A scene renderer shares SPA's owner, store, scheduler, and component lifecycle. */\nexport function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {\n\tfunction mount(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): SceneNodes<N> {\n\t\tlet entries: Entry<N>[] = []\n\t\tconst presence = scope._root._presence?.collection<Entry<N>, Child>(\n\t\t\t(entry) => entry.scope,\n\t\t\t(entry, value) => same(entry.value, value),\n\t\t)\n\t\tconst retire = (\n\t\t\tentry: Entry<N>,\n\t\t\tid: string,\n\t\t\teligible: boolean,\n\t\t\tindex: number,\n\t\t) => {\n\t\t\tif (presence)\n\t\t\t\tpresence.remove(entry, id, eligible, index, () => {\n\t\t\t\t\tif (!scope._dead) changed()\n\t\t\t\t})\n\t\t\telse dispose(entry.scope)\n\t\t}\n\t\tobserve(scope, source, (next) => {\n\t\t\tconst values = (\n\t\t\t\tArray.isArray(next) ? next.flat(Infinity) : [next]\n\t\t\t) as Child[]\n\t\t\tconst previous = entries\n\t\t\tconst old = new Map(\n\t\t\t\tentries.map((entry, i) => [key(entry.value, i), entry]),\n\t\t\t)\n\t\t\tconst seen = new Set<string>()\n\t\t\tentries = values.map((value, i) => {\n\t\t\t\tconst id = key(value, i)\n\t\t\t\tif (seen.has(id)) throw new Error(`spa: duplicate scene key`)\n\t\t\t\tseen.add(id)\n\t\t\t\tlet entry = old.get(id)\n\t\t\t\told.delete(id)\n\t\t\t\tif (entry && !same(entry.value, value)) {\n\t\t\t\t\tretire(\n\t\t\t\t\t\tentry,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tvalue == null || typeof value === `boolean`,\n\t\t\t\t\t\tprevious.indexOf(entry),\n\t\t\t\t\t)\n\t\t\t\t\tentry = undefined\n\t\t\t\t}\n\t\t\t\tentry ??= presence?.take(id, value)\n\t\t\t\tif (entry) {\n\t\t\t\t\tentry.value = value\n\t\t\t\t\tscope._root._presence?.resume(entry.scope)\n\t\t\t\t\tinvalidate(entry.scope)\n\t\t\t\t\treturn entry\n\t\t\t\t}\n\t\t\t\tconst childScope = createScope(scope)\n\t\t\t\tconst created: Entry<N> = { scope: childScope, value, nodes: null! }\n\t\t\t\tcreated.nodes = build(() => created.value, childScope, changed)\n\t\t\t\treturn created\n\t\t\t})\n\t\t\tfor (const [id, entry] of old)\n\t\t\t\tretire(entry, id, true, previous.indexOf(entry))\n\t\t\tchanged()\n\t\t})\n\t\treturn (activeOnly = false) => {\n\t\t\tconst rendered = activeOnly\n\t\t\t\t? entries\n\t\t\t\t: (presence?.merge(entries) ?? entries)\n\t\t\treturn rendered.flatMap((entry) => entry.nodes(activeOnly))\n\t\t}\n\t}\n\tfunction key(value: Child, i: number): string {\n\t\tconst explicit = (value as VNode | null)?.props?.[`key`]\n\t\treturn explicit == null ? `index:${i}` : `key:${explicit}`\n\t}\n\tfunction same(a: Child, b: Child): boolean {\n\t\treturn (\n\t\t\ttypeof a === typeof b &&\n\t\t\t(a as VNode | null)?.type === (b as VNode | null)?.type\n\t\t)\n\t}\n\tfunction build(\n\t\tsource: () => Child,\n\t\tscope: Scope,\n\t\tchanged: () => void,\n\t): SceneNodes<N> {\n\t\tconst value = untrack(source)\n\t\tif (typeof value === `function`)\n\t\t\treturn mount(() => (source() as () => Child)(), scope, changed)\n\t\tif (value == null || typeof value === `boolean`) return () => []\n\t\tif (typeof value !== `object`)\n\t\t\tthrow new Error(`spa: scene children must be nodes`)\n\t\tif (!(`type` in value) || !(`props` in value))\n\t\t\tthrow new Error(`spa: invalid scene child`)\n\t\tconst vnode = value\n\t\tconst props = merge(() => (source() as VNode).props)\n\t\tif (!vnode.type || vnode.type === Fragment)\n\t\t\treturn mount(() => props[`children`], scope, changed)\n\t\tif (typeof vnode.type === `function`) {\n\t\t\tconst output = within(scope, () =>\n\t\t\t\tuntrack(() => (vnode.type as Component)(props)),\n\t\t\t)\n\t\t\treturn mount(() => output, scope, changed)\n\t\t}\n\t\tconst node = host.create(\n\t\t\tvnode.type,\n\t\t\tuntrack(() => props),\n\t\t)\n\t\tscope._cleanups.add(() => {\n\t\t\thost.destroy(node)\n\t\t})\n\t\tconst nativeProps = capabilityProps(\n\t\t\tscope,\n\t\t\thost.target?.(node) ?? { kind: `scene`, node },\n\t\t\t() => ({ ...props }),\n\t\t)\n\t\tlet previous: Record<string, any> = {}\n\t\tobserve(\n\t\t\tscope,\n\t\t\t() => ({ ...props }),\n\t\t\t(all) => {\n\t\t\t\tconst next = nativeProps(all)\n\t\t\t\thost.update(node, next, previous)\n\t\t\t\tprevious = next\n\t\t\t},\n\t\t)\n\t\tlet children: SceneNodes<N> = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(node, children(), children(true))\n\t\t}\n\t\tchildren = mount(() => props[`children`], scope, sync)\n\t\tsync()\n\t\tconst ref = untrack(() => props[`ref`])\n\t\tif (ref)\n\t\t\tscope._root._mounts!.unshift(() => {\n\t\t\t\tif (!scope._dead) {\n\t\t\t\t\tscope._cleanups.add(() => ref(null))\n\t\t\t\t\tref(node)\n\t\t\t\t}\n\t\t\t})\n\t\treturn () => [node]\n\t}\n\tfunction attach(setup: () => Child, parent: N, scope: Scope) {\n\t\tlet nodes: SceneNodes<N> = () => []\n\t\tconst sync = () => {\n\t\t\thost.children(parent, nodes(), nodes(true))\n\t\t}\n\t\tnodes = mount(() => untrack(setup), scope, sync)\n\t\tsync()\n\t\tscope._cleanups.add(() => {\n\t\t\thost.children(parent, [], [])\n\t\t})\n\t}\n\treturn {\n\t\t/** Attach beneath the current component; disposal follows its lifetime. */\n\t\tmount(setup: () => Child, parent: N): void {\n\t\t\tif (!owner) throw new Error(`spa: scene mount requires an owner`)\n\t\t\tconst scope = createScope(owner)\n\t\t\ttry {\n\t\t\t\tattach(setup, parent, scope)\n\t\t\t} catch (error) {\n\t\t\t\tfail(scope, error)\n\t\t\t}\n\t\t},\n\t\trender(setup: () => Child, parent: N, options: RootOptions = {}) {\n\t\t\tconst root = createRoot(options)\n\t\t\ttry {\n\t\t\t\twithin(root, () => {\n\t\t\t\t\tattach(setup, parent, root)\n\t\t\t\t})\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tfail(root, error)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tflush: root.flush,\n\t\t\t\tdispose: () => {\n\t\t\t\t\tdispose(root)\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n\n/** Define a typed scene component without introducing another JSX runtime. */\nexport function sceneComponent<P>(type: string): (props: P) => VNode {\n\treturn (props) => ({ type, props: props as Record<string, any> })\n}\n\n/** Bind imperative scene work to the current owner and its reactive dependencies. */\nexport function bindScene<T>(read: () => T, apply: (value: T) => void): void {\n\tobserve(owner!, read, apply)\n}\n\n/** Scene drawing follows an installed capability clock, or the browser clock. */\nexport function onSceneFrame(\n\tcallback: (time: number) => void,\n\tinfrastructure = false,\n): void {\n\tconst scope = owner!\n\tconst clocks = [...scope._root._capabilities.values()].filter(\n\t\t(capability) => capability.scheduleFrame,\n\t)\n\tif (clocks.length > 1)\n\t\tthrow new Error(`spa: multiple frame clock capabilities`)\n\tconst draw = (time: number) => {\n\t\tif (scope._dead || (!infrastructure && !isPresent(scope))) return\n\t\ttry {\n\t\t\tcallback(time)\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tfail(scope._root, error)\n\t\t\t} catch (failure) {\n\t\t\t\tscope._root.error(failure)\n\t\t\t}\n\t\t}\n\t}\n\tlet stop: () => void\n\tif (clocks[0]) stop = clocks[0].scheduleFrame!(draw)\n\telse {\n\t\tlet frame = 0\n\t\tconst tick = (time: number) => {\n\t\t\tif (scope._dead) return\n\t\t\tdraw(time)\n\t\t\tif (!scope._dead) frame = requestAnimationFrame(tick)\n\t\t}\n\t\tframe = requestAnimationFrame(tick)\n\t\tstop = () => {\n\t\t\tcancelAnimationFrame(frame)\n\t\t}\n\t}\n\tscope._cleanups.add(stop)\n}\n"],"mappings":";;;;;AA8CA,SAAgB,oBAAuB,MAAsC;CAC5E,SAAS,MACR,QACA,OACA,SACgB;EAChB,IAAI,UAAsB,CAAC;EAC3B,MAAM,WAAW,MAAM,MAAM,WAAW,YACtC,UAAU,MAAM,QAChB,OAAO,UAAU,KAAK,MAAM,OAAO,KAAK,CAC1C;EACA,MAAM,UACL,OACA,IACA,UACA,UACI;GACJ,IAAI,UACH,SAAS,OAAO,OAAO,IAAI,UAAU,aAAa;IACjD,IAAI,CAAC,MAAM,OAAO,QAAQ;GAC3B,CAAC;QACG,QAAQ,MAAM,KAAK;EACzB;EACA,QAAQ,OAAO,SAAS,SAAS;GAChC,MAAM,SACL,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,QAAQ,IAAI,CAAC,IAAI;GAElD,MAAM,WAAW;GACjB,MAAM,MAAM,IAAI,IACf,QAAQ,KAAK,OAAO,MAAM,CAAC,IAAI,MAAM,OAAO,CAAC,GAAG,KAAK,CAAC,CACvD;GACA,MAAM,uBAAO,IAAI,IAAY;GAC7B,UAAU,OAAO,KAAK,OAAO,MAAM;IAClC,MAAM,KAAK,IAAI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CAAC,UAAU,KAAK,GAAI;EAC3D,IAAI;GACH,SAAS,IAAI;EACd,SAAS,OAAO;GACf,IAAI;IACH,KAAK,MAAM,OAAO,KAAK;GACxB,SAAS,SAAS;IACjB,MAAM,MAAM,MAAM,OAAO;GAC1B;EACD;CACD;CACA,IAAI;CACJ,IAAI,OAAO,IAAI,OAAO,OAAO,EAAE,CAAC,cAAe,IAAI;MAC9C;EACJ,IAAI,QAAQ;EACZ,MAAM,QAAQ,SAAiB;GAC9B,IAAI,MAAM,OAAO;GACjB,KAAK,IAAI;GACT,IAAI,CAAC,MAAM,OAAO,QAAQ,sBAAsB,IAAI;EACrD;EACA,QAAQ,sBAAsB,IAAI;EAClC,aAAa;GACZ,qBAAqB,KAAK;EAC3B;CACD;CACA,MAAM,UAAU,IAAI,IAAI;AACzB"}
@@ -1,4 +1,5 @@
1
- import { C as within, a as createScope, h as untrack, i as createRoot, o as dispose, p as plain, r as validateCapabilities, t as capabilityNamespace } from "./capabilities-DhOJmeoJ.js";
1
+ import { r as validateCapabilities, t as capabilityNamespace } from "./capabilities-BkQ2i0vV.js";
2
+ import { d as plain, n as createScope, p as untrack, r as dispose, t as createRoot, x as within } from "./core-DZFaOyTO.js";
2
3
  import { Fragment } from "./jsx-runtime.js";
3
4
  // src/server.ts
4
5
  const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","names":[],"sources":["../../src/server.ts"],"sourcesContent":["import { capabilityNamespace, validateCapabilities } from \"./capabilities.ts\"\nimport type { Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&amp;`, \"<\": `&lt;`, \">\": `&gt;`, '\"': `&quot;`, \"'\": `&#39;` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Child,\n\towner: Scope,\n\tnamespace = `html`,\n\tselectValue?: string | number,\n): string {\n\tif (typeof value === `function`) {\n\t\tconst values = ([untrack(value)] as unknown[]).flat(Infinity) as Child[]\n\t\tconst keys = new Set<unknown>()\n\t\treturn (\n\t\t\t`<!--{-->` +\n\t\t\tvalues\n\t\t\t\t.map((child, index) => {\n\t\t\t\t\tconst explicit = (child as VNode | null)?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (keys.has(key)) throw new Error(`spa: duplicate key`)\n\t\t\t\t\tkeys.add(key)\n\t\t\t\t\treturn `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`\n\t\t\t\t})\n\t\t\t\t.join(``) +\n\t\t\t`<!--}-->`\n\t\t)\n\t}\n\tif (Array.isArray(value))\n\t\treturn value\n\t\t\t.map((child) => stringify(child, owner, namespace, selectValue))\n\t\t\t.join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (typeof value !== `object`) return `<!--t-->${escape(value)}`\n\tif (!(`type` in value) || !(`props` in value))\n\t\tthrow new TypeError(`spa: invalid child`)\n\tconst { type, props } = value\n\tif (!type || type === Fragment)\n\t\treturn stringify(() => props[`children`], owner, namespace, selectValue)\n\tif (typeof type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\treturn within(childOwner, () =>\n\t\t\tstringify(\n\t\t\t\tuntrack(() => type(props)),\n\t\t\t\tchildOwner,\n\t\t\t\tnamespace,\n\t\t\t\tselectValue,\n\t\t\t),\n\t\t)\n\t}\n\tif (!/^[A-Za-z][\\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`)\n\tif (type === `astro-slot`)\n\t\treturn `<astro-slot${props[`name`] ? ` name=\"${escape(props[`name`])}\"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`\n\tconst ns = type === `svg` ? `svg` : namespace\n\tvalidateCapabilities(owner, props)\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tcapabilityNamespace(key) !== undefined ||\n\t\t\tkey === `children` ||\n\t\t\tkey === `ref` ||\n\t\t\tkey === `key` ||\n\t\t\tkey.startsWith(`on`)\n\t\t)\n\t\t\tcontinue\n\t\tif (\n\t\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`spa: owned content`)\n\t\tlet attribute = props[key]\n\t\tif (ns === `html`) {\n\t\t\tif (key === `defaultValue` && (type === `input` || type === `textarea`)) {\n\t\t\t\tif (props[`value`] != null) continue\n\t\t\t\tkey = `value`\n\t\t\t} else if (key === `defaultChecked` && type === `input`) {\n\t\t\t\tif (props[`checked`] != null) continue\n\t\t\t\tkey = `checked`\n\t\t\t}\n\t\t}\n\t\tif (key === `className`) key = `class`\n\t\tif (key === `htmlFor`) key = `for`\n\t\tif (!/^[^\\s\"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`)\n\t\tif (key === `value` && (type === `select` || type === `textarea`)) {\n\t\t\ttextValue = attribute ?? textValue\n\t\t\tcontinue\n\t\t}\n\t\tif (key === `style` && attribute != null && typeof attribute !== `string`)\n\t\t\tthrow new TypeError(`spa: CSS string required`)\n\t\tconst boolean =\n\t\t\tns === `html` &&\n\t\t\t(booleans.has(key.toLowerCase()) ||\n\t\t\t\t(/^(capture|download|hidden)$/.test(key) &&\n\t\t\t\t\ttypeof attribute === `boolean`))\n\t\tif (attribute == null || (boolean && !attribute)) continue\n\t\tattrs += boolean ? ` ${key}=\"\"` : ` ${key}=\"${escape(attribute)}\"`\n\t}\n\tif (\n\t\ttype === `option` &&\n\t\tselectValue !== undefined &&\n\t\tString(props[`value`]) === String(selectValue)\n\t)\n\t\tattrs += ` selected=\"\"`\n\tif (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`\n\tif (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {\n\t\tlet text = plain(\n\t\t\ttype === `textarea` ? (textValue ?? props[`children`]) : props[`children`],\n\t\t)\n\t\tif (type === `textarea` && text.startsWith(`\\n`)) text = `\\n${text}`\n\t\tif (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text))\n\t\t\tthrow new Error(`spa: unsafe raw text`)\n\t\treturn `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`\n\t}\n\tconst children = stringify(\n\t\t() => props[`children`],\n\t\towner,\n\t\ttype === `foreignObject` ? `html` : ns,\n\t\ttype === `select` ? textValue : selectValue,\n\t)\n\treturn `<${type}${attrs}>${children}</${type}>`\n}\n\nexport function renderToString(\n\tsetup: () => Child,\n\toptions: RootOptions = {},\n): string {\n\tconst root = createRoot(options, true)\n\tif (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)\n\ttry {\n\t\treturn `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`\n\t} finally {\n\t\tdispose(root)\n\t}\n}\n"],"mappings":";;;AAYA,MAAM,UAAU,UACf,OAAO,KAAK,CAAC,CAAC,QACb,aACC,UACC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;CAAU,KAAK;AAAQ,EAAA,CACtE,KAEH;AACD,MAAM,WACL;AACD,MAAM,WAAW,IAAI,IACpB,qVAAqV,MACpV,GACD,CACD;AACA,SAAS,UACR,OACA,OACA,YAAY,Q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AAI,OAAO,UAAU,kCAAkC,KAAK,IAAI,GAAG;EAClE,IAAI,OAAO,MACV,SAAS,aAAc,aAAa,MAAM,cAAe,MAAM,WAChE;EACA,IAAI,SAAS,cAAc,KAAK,WAAW,IAAI,GAAG,OAAO,KAAK;EAC9D,IAAI,mBAAmB,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,GAC1E,MAAM,IAAI,MAAM,sBAAsB;EACvC,OAAO,IAAI,OAAO,MAAM,GAAG,mBAAmB,KAAK,IAAI,IAAI,OAAO,OAAO,IAAI,EAAE,IAAI,KAAK;CACzF;CACA,MAAM,WAAW,gBACV,MAAM,aACZ,OACA,SAAS,kBAAkB,SAAS,IACpC,SAAS,WAAW,YAAY,WACjC;CACA,OAAO,IAAI,OAAO,MAAM,GAAG,SAAS,IAAI,KAAK;AAC9C;AAEA,SAAgB,eACf,OACA,UAAuB,CAAC,GACf;CACT,MAAM,OAAO,WAAW,SAAS,IAAI;CACrC,IAAI,UAAU,KAAK,KAAK,OAAO,GAAG,MAAM,IAAI,MAAM,uBAAuB;CACzE,IAAI;EACH,OAAO,SAAS,KAAK,QAAQ,KAAK,OAAO,YAAY,UAAU,QAAQ,KAAK,GAAG,IAAI,CAAC,EAAE;CACvF,UAAU;EACT,QAAQ,IAAI;CACb;AACD"}
1
+ {"version":3,"file":"server.js","names":[],"sources":["../../src/server.ts"],"sourcesContent":["import { capabilityNamespace, validateCapabilities } from \"./capabilities.ts\"\nimport type { Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&amp;`, \"<\": `&lt;`, \">\": `&gt;`, '\"': `&quot;`, \"'\": `&#39;` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Child,\n\towner: Scope,\n\tnamespace = `html`,\n\tselectValue?: string | number,\n): string {\n\tif (typeof value === `function`) {\n\t\tconst values = ([untrack(value)] as unknown[]).flat(Infinity) as Child[]\n\t\tconst keys = new Set<unknown>()\n\t\treturn (\n\t\t\t`<!--{-->` +\n\t\t\tvalues\n\t\t\t\t.map((child, index) => {\n\t\t\t\t\tconst explicit = (child as VNode | null)?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (keys.has(key)) throw new Error(`spa: duplicate key`)\n\t\t\t\t\tkeys.add(key)\n\t\t\t\t\treturn `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`\n\t\t\t\t})\n\t\t\t\t.join(``) +\n\t\t\t`<!--}-->`\n\t\t)\n\t}\n\tif (Array.isArray(value))\n\t\treturn value\n\t\t\t.map((child) => stringify(child, owner, namespace, selectValue))\n\t\t\t.join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (typeof value !== `object`) return `<!--t-->${escape(value)}`\n\tif (!(`type` in value) || !(`props` in value))\n\t\tthrow new TypeError(`spa: invalid child`)\n\tconst { type, props } = value\n\tif (!type || type === Fragment)\n\t\treturn stringify(() => props[`children`], owner, namespace, selectValue)\n\tif (typeof type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\treturn within(childOwner, () =>\n\t\t\tstringify(\n\t\t\t\tuntrack(() => type(props)),\n\t\t\t\tchildOwner,\n\t\t\t\tnamespace,\n\t\t\t\tselectValue,\n\t\t\t),\n\t\t)\n\t}\n\tif (!/^[A-Za-z][\\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`)\n\tif (type === `astro-slot`)\n\t\treturn `<astro-slot${props[`name`] ? ` name=\"${escape(props[`name`])}\"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`\n\tconst ns = type === `svg` ? `svg` : namespace\n\tvalidateCapabilities(owner, props)\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tcapabilityNamespace(key) !== undefined ||\n\t\t\tkey === `children` ||\n\t\t\tkey === `ref` ||\n\t\t\tkey === `key` ||\n\t\t\tkey.startsWith(`on`)\n\t\t)\n\t\t\tcontinue\n\t\tif (\n\t\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`spa: owned content`)\n\t\tlet attribute = props[key]\n\t\tif (ns === `html`) {\n\t\t\tif (key === `defaultValue` && (type === `input` || type === `textarea`)) {\n\t\t\t\tif (props[`value`] != null) continue\n\t\t\t\tkey = `value`\n\t\t\t} else if (key === `defaultChecked` && type === `input`) {\n\t\t\t\tif (props[`checked`] != null) continue\n\t\t\t\tkey = `checked`\n\t\t\t}\n\t\t}\n\t\tif (key === `className`) key = `class`\n\t\tif (key === `htmlFor`) key = `for`\n\t\tif (!/^[^\\s\"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`)\n\t\tif (key === `value` && (type === `select` || type === `textarea`)) {\n\t\t\ttextValue = attribute ?? textValue\n\t\t\tcontinue\n\t\t}\n\t\tif (key === `style` && attribute != null && typeof attribute !== `string`)\n\t\t\tthrow new TypeError(`spa: CSS string required`)\n\t\tconst boolean =\n\t\t\tns === `html` &&\n\t\t\t(booleans.has(key.toLowerCase()) ||\n\t\t\t\t(/^(capture|download|hidden)$/.test(key) &&\n\t\t\t\t\ttypeof attribute === `boolean`))\n\t\tif (attribute == null || (boolean && !attribute)) continue\n\t\tattrs += boolean ? ` ${key}=\"\"` : ` ${key}=\"${escape(attribute)}\"`\n\t}\n\tif (\n\t\ttype === `option` &&\n\t\tselectValue !== undefined &&\n\t\tString(props[`value`]) === String(selectValue)\n\t)\n\t\tattrs += ` selected=\"\"`\n\tif (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`\n\tif (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {\n\t\tlet text = plain(\n\t\t\ttype === `textarea` ? (textValue ?? props[`children`]) : props[`children`],\n\t\t)\n\t\tif (type === `textarea` && text.startsWith(`\\n`)) text = `\\n${text}`\n\t\tif (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text))\n\t\t\tthrow new Error(`spa: unsafe raw text`)\n\t\treturn `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`\n\t}\n\tconst children = stringify(\n\t\t() => props[`children`],\n\t\towner,\n\t\ttype === `foreignObject` ? `html` : ns,\n\t\ttype === `select` ? textValue : selectValue,\n\t)\n\treturn `<${type}${attrs}>${children}</${type}>`\n}\n\nexport function renderToString(\n\tsetup: () => Child,\n\toptions: RootOptions = {},\n): string {\n\tconst root = createRoot(options, true)\n\tif (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)\n\ttry {\n\t\treturn `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`\n\t} finally {\n\t\tdispose(root)\n\t}\n}\n"],"mappings":";;;;AAYA,MAAM,UAAU,UACf,OAAO,KAAK,CAAC,CAAC,QACb,aACC,UACC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;CAAU,KAAK;AAAQ,EAAA,CACtE,KAEH;AACD,MAAM,WACL;AACD,MAAM,WAAW,IAAI,IACpB,qVAAqV,MACpV,GACD,CACD;AACA,SAAS,UACR,OACA,OACA,YAAY,QACZ,aACS;CACT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AU,kCAAkC,KAAK,IAAI,GAAG;EAClE,IAAI,OAAO,MACV,SAAS,aAAc,aAAa,MAAM,cAAe,MAAM,WAChE;EACA,IAAI,SAAS,cAAc,KAAK,WAAW,IAAI,GAAG,OAAO,KAAK;EAC9D,IAAI,mBAAmB,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,GAC1E,MAAM,IAAI,MAAM,sBAAsB;EACvC,OAAO,IAAI,OAAO,MAAM,GAAG,mBAAmB,KAAK,IAAI,IAAI,OAAO,OAAO,IAAI,EAAE,IAAI,KAAK;CACzF;CACA,MAAM,WAAW,gBACV,MAAM,aACZ,OACA,SAAS,kBAAkB,SAAS,IACpC,SAAS,WAAW,YAAY,WACjC;CACA,OAAO,IAAI,OAAO,MAAM,GAAG,SAAS,IAAI,KAAK;AAC9C;AAEA,SAAgB,eACf,OACA,UAAuB,CAAC,GACf;CACT,MAAM,OAAO,WAAW,SAAS,IAAI;CACrC,IAAI,UAAU,KAAK,KAAK,OAAO,GAAG,MAAM,IAAI,MAAM,uBAAuB;CACzE,IAAI;EACH,OAAO,SAAS,KAAK,QAAQ,KAAK,OAAO,YAAY,UAAU,QAAQ,KAAK,GAAG,IAAI,CAAC,EAAE;CACvF,UAAU;EACT,QAAQ,IAAI;CACb;AACD"}
@@ -1,4 +1,4 @@
1
- import { S as useValue, f as owner, m as resolveStateToken } from "./capabilities-DhOJmeoJ.js";
1
+ import { f as resolveStateToken, m as useGetter, u as owner } from "./core-DZFaOyTO.js";
2
2
  import { withdraw } from "atom.io/internal";
3
3
  // src/use-loadable.ts
4
4
  function useLoadable(...params) {
@@ -6,7 +6,7 @@ function useLoadable(...params) {
6
6
  const [token] = params;
7
7
  const family = token.type.endsWith(`_family`);
8
8
  const selected = resolveStateToken(token, params[1]);
9
- const read = useValue(selected);
9
+ const getValue = useGetter(selected);
10
10
  const fallbackIndex = family ? 2 : 1;
11
11
  const fallback = params[fallbackIndex];
12
12
  const hasFallback = params.length > fallbackIndex;
@@ -14,7 +14,7 @@ function useLoadable(...params) {
14
14
  let previous = fallback;
15
15
  let error;
16
16
  return () => {
17
- const value = read();
17
+ const value = getValue();
18
18
  const loading = value instanceof Promise;
19
19
  if (!loading) {
20
20
  previous = value;
@@ -35,4 +35,4 @@ function useLoadable(...params) {
35
35
  }
36
36
  export { useLoadable as t };
37
37
 
38
- //# sourceMappingURL=src-Dh-d6w4y.js.map
38
+ //# sourceMappingURL=src-BUtG4BgX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-BUtG4BgX.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, useGetter } 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 getValue = useGetter(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 = getValue()\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,WAAW,UAAU,QAAQ;CACnC,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,SAAS;EACvB,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,8 +1,16 @@
1
- import { d as onMount, f as owner, s as fail, u as onCleanup } from "./capabilities-DhOJmeoJ.js";
1
+ import { c as onCleanup, i as fail, l as onMount, o as isPresent, u as owner } from "./core-DZFaOyTO.js";
2
2
  import { jsx } from "./jsx-runtime.js";
3
3
  import { bindScene, createSceneRenderer, onSceneFrame, sceneComponent } from "./renderer.js";
4
4
  import * as THREE from "three";
5
5
  // src/three-events.ts
6
+ const suspended = /* @__PURE__ */ new WeakSet();
7
+ function suspendThree(node) {
8
+ suspended.add(node);
9
+ for (const manager of managers) manager.remove(node);
10
+ return () => {
11
+ suspended.delete(node);
12
+ };
13
+ }
6
14
  const listeners = /* @__PURE__ */ new WeakMap();
7
15
  const managers = /* @__PURE__ */ new Set();
8
16
  function listenThree(node, type, handler) {
@@ -51,7 +59,7 @@ function createThreeEvents(canvas, scene, camera, onError = (error) => {
51
59
  };
52
60
  const eligible = (intersection) => {
53
61
  const nodes = path(intersection.object);
54
- if (!nodes.length || nodes.some((node) => !node.visible)) return false;
62
+ if (!nodes.length || nodes.some((node) => !node.visible || suspended.has(node))) return false;
55
63
  const material = intersection.object.material;
56
64
  return !material || (Array.isArray(material) ? material[intersection.face?.materialIndex ?? 0]?.visible !== false : material.visible);
57
65
  };
@@ -276,7 +284,10 @@ const renderer = createSceneRenderer({
276
284
  return {
277
285
  kind: `three`,
278
286
  node,
279
- ...node instanceof THREE.Object3D ? { listen: (type, listener) => listenThree(node, type, listener) } : {},
287
+ ...node instanceof THREE.Object3D ? {
288
+ suspend: () => suspendThree(node),
289
+ listen: (type, listener) => listenThree(node, type, listener)
290
+ } : {},
280
291
  read(key) {
281
292
  const value = node[key];
282
293
  return value?.isColor ? value.getStyle() : value?.isVector3 || value?.isEuler ? [
@@ -324,7 +335,7 @@ const renderer = createSceneRenderer({
324
335
  }
325
336
  if (node instanceof THREE.PerspectiveCamera) node.updateProjectionMatrix();
326
337
  },
327
- children(parent, children) {
338
+ children(parent, children, activeChildren) {
328
339
  if (!(parent instanceof THREE.Object3D)) {
329
340
  if (children.length) throw new Error(`spa/three: resources cannot contain children`);
330
341
  return;
@@ -338,7 +349,9 @@ const renderer = createSceneRenderer({
338
349
  if (parent instanceof THREE.Mesh) {
339
350
  const geometries = resources.filter((child) => child instanceof THREE.BufferGeometry);
340
351
  const materials = resources.filter((child) => child instanceof THREE.Material);
341
- if (geometries.length > 1 || materials.length > 1) throw new Error(`spa/three: each Mesh accepts one geometry and one material`);
352
+ const activeGeometries = activeChildren.filter((child) => child instanceof THREE.BufferGeometry);
353
+ const activeMaterials = activeChildren.filter((child) => child instanceof THREE.Material);
354
+ if (activeGeometries.length > 1 || activeMaterials.length > 1) throw new Error(`spa/three: each Mesh accepts one geometry and one material`);
342
355
  const owned = meshDefaults.get(parent);
343
356
  let baseline = owned ?? borrowedMeshDefaults.get(parent);
344
357
  if (!baseline) {
@@ -348,8 +361,8 @@ const renderer = createSceneRenderer({
348
361
  };
349
362
  borrowedMeshDefaults.set(parent, baseline);
350
363
  }
351
- parent.geometry = geometries[0] ?? baseline.geometry;
352
- parent.material = materials[0] ?? baseline.material;
364
+ parent.geometry = activeGeometries[0] ?? geometries.find((geometry) => geometry === parent.geometry) ?? geometries.at(-1) ?? baseline.geometry;
365
+ parent.material = activeMaterials[0] ?? materials.find((material) => material === parent.material) ?? materials.at(-1) ?? baseline.material;
353
366
  if (!owned && children.length === 0) borrowedMeshDefaults.delete(parent);
354
367
  }
355
368
  },
@@ -391,7 +404,8 @@ function Canvas(props) {
391
404
  camera.updateProjectionMatrix();
392
405
  });
393
406
  renderer.mount(() => props.children, scene);
394
- const root = owner._root;
407
+ const scope = owner;
408
+ const root = scope._root;
395
409
  const events = createThreeEvents(canvas, scene, () => props.camera ?? camera, (error) => {
396
410
  try {
397
411
  fail(root, error);
@@ -407,7 +421,7 @@ function Canvas(props) {
407
421
  const active = props.camera ?? camera;
408
422
  const delta = last === void 0 ? 0 : (time - last) / 1e3;
409
423
  last = time;
410
- props.onFrame?.({
424
+ if (isPresent(scope)) props.onFrame?.({
411
425
  scene,
412
426
  camera: active,
413
427
  renderer: webgl,
@@ -416,7 +430,7 @@ function Canvas(props) {
416
430
  });
417
431
  events.update();
418
432
  webgl.render(scene, active);
419
- });
433
+ }, true);
420
434
  });
421
435
  return jsx(`canvas`, { ref: (element) => {
422
436
  canvas = element;
@@ -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 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 (!nodes.length || nodes.some((node) => !node.visible)) return 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, owner } from \"./core.ts\"\nimport type { ThreeEventAttributes, ThreeEventHandler } from \"./three-events.ts\"\nimport { createThreeEvents, forgetThree, listenThree } 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\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) {\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\tif (geometries.length > 1 || materials.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\tparent.geometry = geometries[0] ?? baseline.geometry\n\t\t\tparent.material = materials[0] ?? baseline.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 root = owner!._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\tprops.onFrame?.({\n\t\t\t\tscene,\n\t\t\t\tcamera: active,\n\t\t\t\trenderer: webgl,\n\t\t\t\tdelta,\n\t\t\t\ttime: time / 1000,\n\t\t\t})\n\t\t\tevents.update()\n\t\t\twebgl.render(scene, active)\n\t\t})\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,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;EACH,QAAQ,O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K;GACjB,SAAS,SAAS;IACjB,KAAK,MAAM,OAAO;GACnB;EACD,CACD;EACA,gBAAgB;GACf,OAAO,QAAQ;EAChB,CAAC;EACD,IAAI;EACJ,cAAc,SAAS;GACtB,MAAM,SAAS,MAAM,UAAU;GAC/B,MAAM,QAAQ,SAAS,KAAA,IAAY,KAAK,OAAO,QAAQ;GACvD,OAAO;GACP,MAAM,UAAU;IACf;IACA,QAAQ;IACR,UAAU;IACV;IACA,MAAM,OAAO;GACd,CAAC;GACD,OAAO,OAAO;GACd,MAAM,OAAO,OAAO,MAAM;EAC3B,CAAC;CACF,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\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;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,MAA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eAKlC,sBAAsB;AACxB,MAAa,oBAAoB,eAK/B,mBAAmB;AACrB,MAAa,qBAAqB,eAKhC,oBAAoB"}
@@ -1,4 +1,5 @@
1
- import { C as within, a as createScope, c as invalidate, h as untrack, i as createRoot, l as observe, n as capabilityProps, o as dispose, p as plain, s as fail } from "./capabilities-BuZUQpiD.js";
1
+ import { n as capabilityProps } from "./capabilities-BkQ2i0vV.js";
2
+ import { a as invalidate, d as plain, i as fail, n as createScope, p as untrack, r as dispose, s as observe, t as createRoot, x as within } from "./core-Bl1Ec1hY.js";
2
3
  import { Fragment, merge } from "./jsx-runtime.js";
3
4
  // src/dom.ts
4
5
  const HTML = `http://www.w3.org/1999/xhtml`;
@@ -42,6 +43,11 @@ function mount(value, parent, before, owner, namespace, cursor, source = () => v
42
43
  comment(`{`, parent, before, owner, cursor);
43
44
  let end = null;
44
45
  let records = /* @__PURE__ */ new Map();
46
+ const presence = owner._root._presence?.collection((record) => record._scope, (record, child) => typeof record._value === typeof child && record._value?.type === child?.type);
47
+ const retire = (record, key, eligible, index) => {
48
+ if (presence) presence.remove(record, key, eligible, index, () => {});
49
+ else dispose(record._scope);
50
+ };
45
51
  let initial = cursor;
46
52
  observe(owner, () => source()(), (next) => {
47
53
  const values = [next].flat(Infinity);
@@ -54,9 +60,10 @@ function mount(value, parent, before, owner, namespace, cursor, source = () => v
54
60
  const key = explicit == null ? index : String(explicit);
55
61
  let record = records.get(key);
56
62
  if (record && (typeof record._value !== typeof child || record._value?.type !== vnode?.type)) {
57
- dispose(record._scope);
63
+ retire(record, key, child == null || typeof child === `boolean`, [...records.keys()].indexOf(key));
58
64
  record = void 0;
59
65
  }
66
+ record ??= presence?.take(key, child);
60
67
  if (!record) {
61
68
  const childOwner = createScope(owner);
62
69
  record = {
@@ -70,14 +77,16 @@ function mount(value, parent, before, owner, namespace, cursor, source = () => v
70
77
  record._end = comment(`]`, parent, end ?? before, childOwner, initial);
71
78
  } else {
72
79
  record._value = child;
80
+ owner._root._presence?.resume(record._scope);
73
81
  invalidate(record._scope);
74
82
  }
75
83
  kept.set(key, record);
76
84
  }
77
- for (const [key, record] of records) if (!kept.has(key)) dispose(record._scope);
85
+ for (const [key, record] of records) if (!kept.has(key)) retire(record, key, true, [...records.keys()].indexOf(key));
78
86
  if (!initial) {
79
87
  let at = end ?? before;
80
- for (const record of [...kept.values()].reverse()) {
88
+ const rendered = presence?.merge([...kept.values()]) ?? [...kept.values()];
89
+ for (const record of rendered.reverse()) {
81
90
  if (record._end.nextSibling !== at) {
82
91
  const range = parent.ownerDocument.createRange();
83
92
  range.setStartBefore(record._start);
@@ -86,7 +95,7 @@ function mount(value, parent, before, owner, namespace, cursor, source = () => v
86
95
  }
87
96
  at = record._start;
88
97
  }
89
- if (focus?.isConnected && focus !== parent.ownerDocument.activeElement) focus.focus({ preventScroll: true });
98
+ if (focus?.isConnected && !focus.closest(`[inert]`) && focus !== parent.ownerDocument.activeElement) focus.focus({ preventScroll: true });
90
99
  }
91
100
  initial = void 0;
92
101
  records = kept;
@@ -134,7 +143,7 @@ function mount(value, parent, before, owner, namespace, cursor, source = () => v
134
143
  const nativeProps = capabilityProps(owner, {
135
144
  kind: `dom`,
136
145
  node: element
137
- });
146
+ }, () => ({ ...props }));
138
147
  let previous = {};
139
148
  owner._cleanups.add(() => {
140
149
  for (const key in previous) if (key.startsWith(`on`)) property(element, key, null, previous[key]);
@@ -190,4 +199,4 @@ function hydrate(setup, host, options = {}) {
190
199
  }
191
200
  export { render as n, hydrate as t };
192
201
 
193
- //# sourceMappingURL=dom-B2rm8o2L.js.map
202
+ //# sourceMappingURL=dom-Cfj3GtQK.js.map