@atom.io/spa 0.0.8 → 0.0.10
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.
- package/README.md +194 -30
- package/README.mdx +78 -20
- package/dist/BrandMarkScene-CBYk-RJ2.js +140 -0
- package/dist/BrandMarkScene-CBYk-RJ2.js.map +1 -0
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +1 -1
- package/dist/astro-client.d.ts.map +1 -1
- package/dist/astro-client.js +5 -4
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-resumability-client.d.ts +1 -1
- package/dist/astro-server.js +4 -4
- package/dist/astro-server.js.map +1 -1
- package/dist/{astro-shared-83hxw7-M.js → astro-shared-DBwINQav.js} +2 -2
- package/dist/{astro-shared-83hxw7-M.js.map → astro-shared-DBwINQav.js.map} +1 -1
- package/dist/{astro-shared-DZp1x8RQ.d.ts → astro-shared-KxK9OUSj.d.ts} +2 -2
- package/dist/{astro-shared-DZp1x8RQ.d.ts.map → astro-shared-KxK9OUSj.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/brand-css.d.ts +2 -0
- package/dist/brand-model.d.ts +32 -0
- package/dist/brand-model.d.ts.map +1 -0
- package/dist/brand-model.js +120 -0
- package/dist/brand-model.js.map +1 -0
- package/dist/brand.css +37 -0
- package/dist/brand.d.ts +13 -0
- package/dist/brand.d.ts.map +1 -0
- package/dist/brand.js +94 -0
- package/dist/brand.js.map +1 -0
- package/dist/{capabilities-DNcnGRv_.d.ts → capabilities-ChgSs6bp.d.ts} +34 -6
- package/dist/capabilities-ChgSs6bp.d.ts.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/core-DD2giR6E.js +451 -0
- package/dist/core-DD2giR6E.js.map +1 -0
- package/dist/development/BrandMarkScene-BDdC7K5M.js +140 -0
- package/dist/development/BrandMarkScene-BDdC7K5M.js.map +1 -0
- package/dist/development/astro-client.js +5 -4
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-server.js +4 -4
- package/dist/development/astro-server.js.map +1 -1
- package/dist/development/{astro-shared-83hxw7-M.js → astro-shared-DBwINQav.js} +2 -2
- package/dist/development/{astro-shared-83hxw7-M.js.map → astro-shared-DBwINQav.js.map} +1 -1
- package/dist/development/astro.js +1 -1
- package/dist/development/brand-model.js +120 -0
- package/dist/development/brand-model.js.map +1 -0
- package/dist/development/brand.css +37 -0
- package/dist/development/brand.js +94 -0
- package/dist/development/brand.js.map +1 -0
- package/dist/development/core-DrUd8x25.js +465 -0
- package/dist/development/core-DrUd8x25.js.map +1 -0
- package/dist/development/{dom-DQ0M3rLL.js → dom-CEVtlaav.js} +152 -36
- package/dist/development/dom-CEVtlaav.js.map +1 -0
- package/dist/development/floating.js +2 -6
- package/dist/development/floating.js.map +1 -1
- package/dist/development/hot.js +164 -0
- package/dist/development/hot.js.map +1 -0
- package/dist/development/identity-B8wTFkyW.js +121 -0
- package/dist/development/identity-B8wTFkyW.js.map +1 -0
- package/dist/development/index.js +5 -5
- package/dist/development/jsx-runtime-BGDPK50B.js +49 -0
- package/dist/development/jsx-runtime-BGDPK50B.js.map +1 -0
- package/dist/development/jsx-runtime.js +1 -25
- package/dist/development/konva.js +12 -5
- package/dist/development/konva.js.map +1 -1
- package/dist/development/motion.js +41 -39
- package/dist/development/motion.js.map +1 -1
- package/dist/development/renderer.js +41 -40
- package/dist/development/renderer.js.map +1 -1
- package/dist/development/{server-renderer-DCLoMdOX.js → server-renderer-zAqEL1g1.js} +8 -18
- package/dist/development/server-renderer-zAqEL1g1.js.map +1 -0
- package/dist/development/server.js +1 -1
- package/dist/{src-Bme1kz2b.js → development/src-CB7ruwRs.js} +3 -3
- package/dist/development/src-CB7ruwRs.js.map +1 -0
- package/dist/development/three-CsZ6Od1C.js +527 -0
- package/dist/development/three-CsZ6Od1C.js.map +1 -0
- package/dist/development/three.js +1 -508
- package/dist/development/vite-WUiz1ju6.js +545 -0
- package/dist/development/vite-WUiz1ju6.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-D8g3roX9.js → dom-DUpa3Sj2.js} +141 -33
- package/dist/dom-DUpa3Sj2.js.map +1 -0
- package/dist/floating.d.ts +1 -1
- package/dist/floating.d.ts.map +1 -1
- package/dist/floating.js +2 -6
- package/dist/floating.js.map +1 -1
- package/dist/hot.d.ts +15 -0
- package/dist/hot.d.ts.map +1 -0
- package/dist/hot.js +19 -0
- package/dist/hot.js.map +1 -0
- package/dist/identity-ByJswZtF.js +121 -0
- package/dist/identity-ByJswZtF.js.map +1 -0
- package/dist/{index-BFnXIfOj.d.ts → index-DdA39aMv.d.ts} +4 -4
- package/dist/{index-BFnXIfOj.d.ts.map → index-DdA39aMv.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/jsx-runtime-BGDPK50B.js +49 -0
- package/dist/jsx-runtime-BGDPK50B.js.map +1 -0
- package/dist/{jsx-runtime-DQnpyT_g.d.ts → jsx-runtime-CCvcEosg.d.ts} +14 -9
- package/dist/jsx-runtime-CCvcEosg.d.ts.map +1 -0
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -25
- package/dist/konva.d.ts +46 -9
- package/dist/konva.d.ts.map +1 -1
- package/dist/konva.js +12 -5
- package/dist/konva.js.map +1 -1
- package/dist/motion.d.ts +3 -1
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +41 -39
- package/dist/motion.js.map +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +39 -40
- package/dist/renderer.js.map +1 -1
- package/dist/{server-renderer-D0rsFL_-.js → server-renderer-D7CdyOMo.js} +8 -18
- package/dist/server-renderer-D7CdyOMo.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/size.json +12 -12
- package/dist/{development/src-DoQgCX-O.js → src-B2W_TA_X.js} +3 -3
- package/dist/src-B2W_TA_X.js.map +1 -0
- package/dist/three-DcYxRXPW.js +527 -0
- package/dist/three-DcYxRXPW.js.map +1 -0
- package/dist/three.d.ts +24 -3
- package/dist/three.d.ts.map +1 -1
- package/dist/three.js +1 -508
- package/dist/vite-WUiz1ju6.js +545 -0
- package/dist/vite-WUiz1ju6.js.map +1 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +1 -1
- package/package.json +45 -18
- package/src/BrandMark.module.css +25 -0
- package/src/BrandMark.tsx +106 -0
- package/src/BrandMarkScene.module.css +10 -0
- package/src/BrandMarkScene.tsx +116 -0
- package/src/astro-client.ts +3 -2
- package/src/astro-server.ts +2 -2
- package/src/brand-css.d.ts +2 -0
- package/src/brand-model.ts +177 -0
- package/src/brand.ts +3 -0
- package/src/capabilities.ts +48 -21
- package/src/compiler-hmr.ts +297 -0
- package/src/compiler.ts +127 -25
- package/src/core.ts +282 -33
- package/src/dom-forms.ts +127 -0
- package/src/dom.ts +124 -53
- package/src/floating.ts +2 -6
- package/src/hot.ts +191 -0
- package/src/identity.ts +39 -0
- package/src/index.ts +2 -0
- package/src/jsx-runtime.ts +6 -26
- package/src/jsx-types.d.ts +8 -3
- package/src/konva.ts +66 -10
- package/src/lasertag.d.ts +1 -0
- package/src/motion-layout.ts +55 -26
- package/src/motion.ts +3 -0
- package/src/presence.ts +11 -23
- package/src/props.ts +55 -0
- package/src/renderer.ts +91 -71
- package/src/server-renderer.ts +18 -13
- package/src/three.ts +92 -46
- package/src/use-loadable.ts +2 -2
- package/src/vite.ts +44 -4
- package/dist/capabilities-DNcnGRv_.d.ts.map +0 -1
- package/dist/capabilities-nOIitQ-_.js +0 -65
- package/dist/capabilities-nOIitQ-_.js.map +0 -1
- package/dist/core-B4rJ0xdc.js +0 -268
- package/dist/core-B4rJ0xdc.js.map +0 -1
- package/dist/development/capabilities-nOIitQ-_.js +0 -65
- package/dist/development/capabilities-nOIitQ-_.js.map +0 -1
- package/dist/development/core-BHA7I1nf.js +0 -271
- package/dist/development/core-BHA7I1nf.js.map +0 -1
- package/dist/development/dom-DQ0M3rLL.js.map +0 -1
- package/dist/development/jsx-runtime.js.map +0 -1
- package/dist/development/server-renderer-DCLoMdOX.js.map +0 -1
- package/dist/development/src-DoQgCX-O.js.map +0 -1
- package/dist/development/three.js.map +0 -1
- package/dist/development/vite-Bmyb6P5w.js +0 -265
- package/dist/development/vite-Bmyb6P5w.js.map +0 -1
- package/dist/dom-D8g3roX9.js.map +0 -1
- package/dist/jsx-runtime-DQnpyT_g.d.ts.map +0 -1
- package/dist/jsx-runtime.js.map +0 -1
- package/dist/server-renderer-D0rsFL_-.js.map +0 -1
- package/dist/src-Bme1kz2b.js.map +0 -1
- package/dist/three.js.map +0 -1
- package/dist/vite-Bmyb6P5w.js +0 -265
- package/dist/vite-Bmyb6P5w.js.map +0 -1
package/src/renderer.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Canonical } from "atom.io/foundations/canonical"
|
|
2
|
+
|
|
1
3
|
import type { CapabilityTarget } from "./capabilities.ts"
|
|
2
4
|
import { capabilityProps } from "./capabilities.ts"
|
|
3
5
|
import type {
|
|
@@ -16,10 +18,15 @@ import {
|
|
|
16
18
|
isPresent,
|
|
17
19
|
observe,
|
|
18
20
|
owner,
|
|
21
|
+
reportScopeError,
|
|
22
|
+
scopeCapabilities,
|
|
19
23
|
untrack,
|
|
20
24
|
within,
|
|
21
25
|
} from "./core.ts"
|
|
22
|
-
import {
|
|
26
|
+
import { hotRoot, trackRoot } from "./hot.ts"
|
|
27
|
+
import { identifyChildren } from "./identity.ts"
|
|
28
|
+
import { Fragment } from "./jsx-runtime.ts"
|
|
29
|
+
import { instanceProps } from "./props.ts"
|
|
23
30
|
|
|
24
31
|
export interface SceneHost<N> {
|
|
25
32
|
target?(node: N): CapabilityTarget
|
|
@@ -35,6 +42,7 @@ export interface SceneHost<N> {
|
|
|
35
42
|
type SceneNodes<N> = (activeOnly?: boolean) => N[]
|
|
36
43
|
|
|
37
44
|
interface Entry<N> {
|
|
45
|
+
id: string | number
|
|
38
46
|
scope: Scope
|
|
39
47
|
value: Children
|
|
40
48
|
nodes: SceneNodes<N>
|
|
@@ -57,13 +65,19 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
57
65
|
changed: () => void,
|
|
58
66
|
): SceneNodes<N> {
|
|
59
67
|
let entries: Entry<N>[] = []
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(
|
|
63
|
-
|
|
68
|
+
let reconciling = false
|
|
69
|
+
const report = () => {
|
|
70
|
+
if (!reconciling) changed()
|
|
71
|
+
}
|
|
72
|
+
const collection = () =>
|
|
73
|
+
scope._root._presence?.collection<Entry<N>, Children>(
|
|
74
|
+
(entry) => entry.scope,
|
|
75
|
+
(entry, value) => same(entry.value, value),
|
|
76
|
+
)
|
|
77
|
+
let presence: ReturnType<typeof collection>
|
|
64
78
|
const retire = (
|
|
65
79
|
entry: Entry<N>,
|
|
66
|
-
id: string,
|
|
80
|
+
id: string | number,
|
|
67
81
|
eligible: boolean,
|
|
68
82
|
index: number,
|
|
69
83
|
) => {
|
|
@@ -73,46 +87,53 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
73
87
|
})
|
|
74
88
|
else dispose(entry.scope)
|
|
75
89
|
}
|
|
76
|
-
observe(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
observe(
|
|
91
|
+
scope,
|
|
92
|
+
() => identifyChildren(source(), `spa: duplicate scene key`),
|
|
93
|
+
(values) => {
|
|
94
|
+
presence ??= collection()
|
|
95
|
+
reconciling = true
|
|
96
|
+
const previous = entries
|
|
97
|
+
const old = new Map(entries.map((entry) => [entry.id, entry]))
|
|
98
|
+
entries = values.map(({ value, key, id }) => {
|
|
99
|
+
let entry = old.get(id)
|
|
100
|
+
old.delete(id)
|
|
101
|
+
if (entry && !same(entry.value, value)) {
|
|
102
|
+
retire(
|
|
103
|
+
entry,
|
|
104
|
+
id,
|
|
105
|
+
value == null || typeof value === `boolean`,
|
|
106
|
+
previous.indexOf(entry),
|
|
107
|
+
)
|
|
108
|
+
entry = undefined
|
|
109
|
+
}
|
|
110
|
+
entry ??= presence?.take(id, value)
|
|
111
|
+
if (entry) {
|
|
112
|
+
entry.value = value
|
|
113
|
+
scope._root._presence?.resume(entry.scope)
|
|
114
|
+
invalidate(entry.scope)
|
|
115
|
+
return entry
|
|
116
|
+
}
|
|
117
|
+
const childScope = createScope(scope)
|
|
118
|
+
const created: Entry<N> = {
|
|
94
119
|
id,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for (const [id, entry] of old)
|
|
113
|
-
retire(entry, id, true, previous.indexOf(entry))
|
|
114
|
-
changed()
|
|
115
|
-
})
|
|
120
|
+
scope: childScope,
|
|
121
|
+
value,
|
|
122
|
+
nodes: null!,
|
|
123
|
+
}
|
|
124
|
+
created.nodes = build(() => created.value, childScope, report, key)
|
|
125
|
+
return created
|
|
126
|
+
})
|
|
127
|
+
for (const [id, entry] of old)
|
|
128
|
+
retire(entry, id, true, previous.indexOf(entry))
|
|
129
|
+
reconciling = false
|
|
130
|
+
if (
|
|
131
|
+
entries.length !== previous.length ||
|
|
132
|
+
entries.some((entry, i) => entry !== previous[i])
|
|
133
|
+
)
|
|
134
|
+
changed()
|
|
135
|
+
},
|
|
136
|
+
)
|
|
116
137
|
return (activeOnly = false) => {
|
|
117
138
|
const rendered = activeOnly
|
|
118
139
|
? entries
|
|
@@ -120,10 +141,6 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
120
141
|
return rendered.flatMap((entry) => entry.nodes(activeOnly))
|
|
121
142
|
}
|
|
122
143
|
}
|
|
123
|
-
function key(value: Children, i: number): string {
|
|
124
|
-
const explicit = (value as SpaElement | null)?.props?.[`key`]
|
|
125
|
-
return explicit == null ? `index:${i}` : `key:${explicit}`
|
|
126
|
-
}
|
|
127
144
|
function same(a: Children, b: Children): boolean {
|
|
128
145
|
return (
|
|
129
146
|
typeof a === typeof b &&
|
|
@@ -134,6 +151,7 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
134
151
|
source: () => Children,
|
|
135
152
|
scope: Scope,
|
|
136
153
|
changed: () => void,
|
|
154
|
+
key: Canonical | undefined,
|
|
137
155
|
): SceneNodes<N> {
|
|
138
156
|
const value = untrack(source)
|
|
139
157
|
if (typeof value === `function`)
|
|
@@ -144,7 +162,7 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
144
162
|
if (!(`type` in value) || !(`props` in value))
|
|
145
163
|
throw new Error(`spa: invalid scene child`)
|
|
146
164
|
const vnode = value
|
|
147
|
-
const props =
|
|
165
|
+
const props = instanceProps(() => (source() as SpaElement).props, key)
|
|
148
166
|
if (!vnode.type || vnode.type === Fragment)
|
|
149
167
|
return mount(() => props[`children`], scope, changed)
|
|
150
168
|
if (typeof vnode.type === `function`) {
|
|
@@ -186,7 +204,7 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
186
204
|
scope._root._mounts!.unshift(() => {
|
|
187
205
|
if (!scope._dead) {
|
|
188
206
|
scope._cleanups.add(() => ref(null))
|
|
189
|
-
ref(node)
|
|
207
|
+
within(scope, () => ref(node))
|
|
190
208
|
}
|
|
191
209
|
})
|
|
192
210
|
return () => [node]
|
|
@@ -214,21 +232,27 @@ export function createSceneRenderer<N>(host: SceneHost<N>): SceneRenderer<N> {
|
|
|
214
232
|
}
|
|
215
233
|
},
|
|
216
234
|
render(setup: () => Children, parent: N, options: RootOptions = {}) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
235
|
+
const mountRoot = (next: RootOptions) => {
|
|
236
|
+
const root = createRoot(next)
|
|
237
|
+
if (import.meta.env.DEV) trackRoot(root)
|
|
238
|
+
try {
|
|
239
|
+
within(root, () => {
|
|
240
|
+
attach(setup, parent, root)
|
|
241
|
+
})
|
|
242
|
+
root.flush()
|
|
243
|
+
} catch (error) {
|
|
244
|
+
fail(root, error)
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
flush: root.flush,
|
|
248
|
+
dispose: () => {
|
|
249
|
+
dispose(root)
|
|
250
|
+
},
|
|
251
|
+
}
|
|
231
252
|
}
|
|
253
|
+
return import.meta.env.DEV
|
|
254
|
+
? hotRoot(mountRoot, options)
|
|
255
|
+
: mountRoot(options)
|
|
232
256
|
},
|
|
233
257
|
}
|
|
234
258
|
}
|
|
@@ -249,7 +273,7 @@ export function onSceneFrame(
|
|
|
249
273
|
infrastructure = false,
|
|
250
274
|
): void {
|
|
251
275
|
const scope = owner!
|
|
252
|
-
const clocks = [...scope.
|
|
276
|
+
const clocks = [...scopeCapabilities(scope).values()].filter(
|
|
253
277
|
(capability) => capability.scheduleFrame,
|
|
254
278
|
)
|
|
255
279
|
if (clocks.length > 1)
|
|
@@ -259,11 +283,7 @@ export function onSceneFrame(
|
|
|
259
283
|
try {
|
|
260
284
|
callback(time)
|
|
261
285
|
} catch (error) {
|
|
262
|
-
|
|
263
|
-
fail(scope._root, error)
|
|
264
|
-
} catch (failure) {
|
|
265
|
-
scope._root.error(failure)
|
|
266
|
-
}
|
|
286
|
+
reportScopeError(scope, error)
|
|
267
287
|
}
|
|
268
288
|
}
|
|
269
289
|
let stop: () => void
|
package/src/server-renderer.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { ReadableToken } from "atom.io"
|
|
2
|
+
import type { Canonical } from "atom.io/foundations/canonical"
|
|
3
|
+
import type { RootStore } from "atom.io/internal"
|
|
2
4
|
|
|
3
5
|
import { capabilityNamespace, validateCapabilities } from "./capabilities.ts"
|
|
4
|
-
import type { Children, RootOptions, Scope
|
|
6
|
+
import type { Children, RootOptions, Scope } from "./core.ts"
|
|
5
7
|
import {
|
|
6
8
|
createRoot,
|
|
7
9
|
createScope,
|
|
@@ -10,7 +12,9 @@ import {
|
|
|
10
12
|
untrack,
|
|
11
13
|
within,
|
|
12
14
|
} from "./core.ts"
|
|
15
|
+
import { identifyChildren, trackKeys } from "./identity.ts"
|
|
13
16
|
import { Fragment } from "./jsx-runtime.ts"
|
|
17
|
+
import { instanceProps } from "./props.ts"
|
|
14
18
|
|
|
15
19
|
const escape = (value: unknown): string =>
|
|
16
20
|
String(value).replace(
|
|
@@ -32,20 +36,17 @@ function stringify(
|
|
|
32
36
|
owner: Scope,
|
|
33
37
|
namespace = `html`,
|
|
34
38
|
selectValue?: string | number,
|
|
39
|
+
initialKey?: Canonical,
|
|
35
40
|
): string {
|
|
36
41
|
if (typeof value === `function`) {
|
|
37
|
-
const values = (
|
|
38
|
-
const keys = new Set<unknown>()
|
|
42
|
+
const values = within(owner, () => untrack(() => identifyChildren(value())))
|
|
39
43
|
return (
|
|
40
44
|
`<!--{-->` +
|
|
41
45
|
values
|
|
42
|
-
.map(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
keys.add(key)
|
|
47
|
-
return `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`
|
|
48
|
-
})
|
|
46
|
+
.map(
|
|
47
|
+
({ value: child, key }) =>
|
|
48
|
+
`<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue, key))}<!--]-->`,
|
|
49
|
+
)
|
|
49
50
|
.join(``) +
|
|
50
51
|
`<!--}-->`
|
|
51
52
|
)
|
|
@@ -65,7 +66,7 @@ function stringify(
|
|
|
65
66
|
const childOwner = createScope(owner)
|
|
66
67
|
return within(childOwner, () =>
|
|
67
68
|
stringify(
|
|
68
|
-
untrack(() => type(props)),
|
|
69
|
+
trackKeys(untrack(() => type(instanceProps(() => props, initialKey)))),
|
|
69
70
|
childOwner,
|
|
70
71
|
namespace,
|
|
71
72
|
selectValue,
|
|
@@ -149,13 +150,17 @@ function stringify(
|
|
|
149
150
|
export function renderToStringWithReads(
|
|
150
151
|
setup: () => Children,
|
|
151
152
|
options: RootOptions = {},
|
|
152
|
-
onRead?: (
|
|
153
|
+
onRead?: (
|
|
154
|
+
value: unknown,
|
|
155
|
+
token: ReadableToken<unknown>,
|
|
156
|
+
store: RootStore,
|
|
157
|
+
) => void,
|
|
153
158
|
): string {
|
|
154
159
|
const root = createRoot(options, true)
|
|
155
160
|
root._onRead = onRead
|
|
156
161
|
if (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)
|
|
157
162
|
try {
|
|
158
|
-
return `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`
|
|
163
|
+
return `<!--w:${root._prefix}-->${within(root, () => stringify(trackKeys(untrack(setup)), root))}<!--/w-->`
|
|
159
164
|
} finally {
|
|
160
165
|
dispose(root)
|
|
161
166
|
}
|
package/src/three.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPresent, owner, reportScopeError, within } from "./core.ts"
|
|
2
2
|
import type { ThreeEventAttributes, ThreeEventHandler } from "./three-events.ts"
|
|
3
3
|
import {
|
|
4
4
|
createThreeEvents,
|
|
@@ -42,8 +42,12 @@ export interface ObjectProps<N extends THREE.Object3D = THREE.Object3D>
|
|
|
42
42
|
const constructors = {
|
|
43
43
|
Group: THREE.Group,
|
|
44
44
|
Mesh: THREE.Mesh,
|
|
45
|
+
LineSegments: THREE.LineSegments,
|
|
46
|
+
BufferGeometry: THREE.BufferGeometry,
|
|
47
|
+
LineBasicMaterial: THREE.LineBasicMaterial,
|
|
45
48
|
PerspectiveCamera: THREE.PerspectiveCamera,
|
|
46
49
|
AmbientLight: THREE.AmbientLight,
|
|
50
|
+
PointLight: THREE.PointLight,
|
|
47
51
|
DirectionalLight: THREE.DirectionalLight,
|
|
48
52
|
BoxGeometry: THREE.BoxGeometry,
|
|
49
53
|
SphereGeometry: THREE.SphereGeometry,
|
|
@@ -52,8 +56,8 @@ const constructors = {
|
|
|
52
56
|
MeshBasicMaterial: THREE.MeshBasicMaterial,
|
|
53
57
|
MeshNormalMaterial: THREE.MeshNormalMaterial,
|
|
54
58
|
}
|
|
55
|
-
const
|
|
56
|
-
THREE.Mesh,
|
|
59
|
+
const drawableDefaults = new WeakMap<
|
|
60
|
+
THREE.Mesh | THREE.LineSegments,
|
|
57
61
|
{
|
|
58
62
|
geometry: THREE.BufferGeometry
|
|
59
63
|
material: THREE.Material | THREE.Material[]
|
|
@@ -61,8 +65,8 @@ const meshDefaults = new WeakMap<
|
|
|
61
65
|
ownsMaterial: boolean
|
|
62
66
|
}
|
|
63
67
|
>()
|
|
64
|
-
const
|
|
65
|
-
THREE.Mesh,
|
|
68
|
+
const borrowedDrawableDefaults = new WeakMap<
|
|
69
|
+
THREE.Mesh | THREE.LineSegments,
|
|
66
70
|
{
|
|
67
71
|
geometry: THREE.BufferGeometry
|
|
68
72
|
material: THREE.Material | THREE.Material[]
|
|
@@ -113,9 +117,9 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
113
117
|
const Constructor = constructors[type as keyof typeof constructors]
|
|
114
118
|
if (!Constructor) throw new Error(`spa/three: unknown node ${type}`)
|
|
115
119
|
const node = new (Constructor as any)(...(props[`args`] ?? [])) as Resource
|
|
116
|
-
//
|
|
117
|
-
if (node instanceof THREE.Mesh)
|
|
118
|
-
|
|
120
|
+
// Drawables' implicit resources are replaced by owned JSX resources below.
|
|
121
|
+
if (node instanceof THREE.Mesh || node instanceof THREE.LineSegments)
|
|
122
|
+
drawableDefaults.set(node, {
|
|
119
123
|
geometry: node.geometry,
|
|
120
124
|
material: node.material,
|
|
121
125
|
ownsGeometry: props[`args`]?.[0] === undefined,
|
|
@@ -153,15 +157,18 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
153
157
|
const handlers = eventHandlers.get(node)!
|
|
154
158
|
handlers.get(key)?.()
|
|
155
159
|
handlers.delete(key)
|
|
156
|
-
|
|
160
|
+
const handler = props[key] as ThreeEventHandler | undefined
|
|
161
|
+
if (handler) {
|
|
162
|
+
const scope = owner!
|
|
157
163
|
handlers.set(
|
|
158
164
|
key,
|
|
159
|
-
listenThree(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
),
|
|
165
|
+
listenThree(node, key.slice(2).toLowerCase(), (event) => {
|
|
166
|
+
within(scope, () => {
|
|
167
|
+
handler(event)
|
|
168
|
+
})
|
|
169
|
+
}),
|
|
164
170
|
)
|
|
171
|
+
}
|
|
165
172
|
continue
|
|
166
173
|
}
|
|
167
174
|
if (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)
|
|
@@ -182,16 +189,27 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
182
189
|
const objects = children.filter(
|
|
183
190
|
(child): child is THREE.Object3D => child instanceof THREE.Object3D,
|
|
184
191
|
)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
192
|
+
if (
|
|
193
|
+
parent.children.length !== objects.length ||
|
|
194
|
+
objects.some((child, index) => child !== parent.children[index])
|
|
195
|
+
) {
|
|
196
|
+
const wanted = new Set(objects)
|
|
197
|
+
for (const child of [...parent.children])
|
|
198
|
+
if (!wanted.has(child)) parent.remove(child)
|
|
199
|
+
for (const child of objects) if (child.parent !== parent) parent.add(child)
|
|
200
|
+
parent.children.splice(0, parent.children.length, ...objects)
|
|
201
|
+
}
|
|
189
202
|
const resources = children.filter(
|
|
190
203
|
(child) => !(child instanceof THREE.Object3D),
|
|
191
204
|
)
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
|
|
205
|
+
if (
|
|
206
|
+
resources.length &&
|
|
207
|
+
!(parent instanceof THREE.Mesh || parent instanceof THREE.LineSegments)
|
|
208
|
+
)
|
|
209
|
+
throw new Error(
|
|
210
|
+
`spa/three: geometry and material require a Mesh or LineSegments parent`,
|
|
211
|
+
)
|
|
212
|
+
if (parent instanceof THREE.Mesh || parent instanceof THREE.LineSegments) {
|
|
195
213
|
const geometries = resources.filter(
|
|
196
214
|
(child) => child instanceof THREE.BufferGeometry,
|
|
197
215
|
)
|
|
@@ -206,13 +224,13 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
206
224
|
)
|
|
207
225
|
if (activeGeometries.length > 1 || activeMaterials.length > 1)
|
|
208
226
|
throw new Error(
|
|
209
|
-
`spa/three: each Mesh accepts one geometry and one material`,
|
|
227
|
+
`spa/three: each ${parent instanceof THREE.Mesh ? `Mesh` : `LineSegments`} accepts one geometry and one material`,
|
|
210
228
|
)
|
|
211
|
-
const owned =
|
|
212
|
-
let baseline = owned ??
|
|
229
|
+
const owned = drawableDefaults.get(parent)
|
|
230
|
+
let baseline = owned ?? borrowedDrawableDefaults.get(parent)
|
|
213
231
|
if (!baseline) {
|
|
214
232
|
baseline = { geometry: parent.geometry, material: parent.material }
|
|
215
|
-
|
|
233
|
+
borrowedDrawableDefaults.set(parent, baseline)
|
|
216
234
|
}
|
|
217
235
|
// Retention owns outgoing resources without occupying incoming attachment slots.
|
|
218
236
|
parent.geometry =
|
|
@@ -225,7 +243,8 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
225
243
|
materials.find((material) => material === parent.material) ??
|
|
226
244
|
materials.at(-1) ??
|
|
227
245
|
baseline.material
|
|
228
|
-
if (!owned && children.length === 0)
|
|
246
|
+
if (!owned && children.length === 0)
|
|
247
|
+
borrowedDrawableDefaults.delete(parent)
|
|
229
248
|
}
|
|
230
249
|
},
|
|
231
250
|
destroy(node) {
|
|
@@ -235,8 +254,8 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
235
254
|
forgetThree(node)
|
|
236
255
|
} finally {
|
|
237
256
|
node.removeFromParent()
|
|
238
|
-
if (node instanceof THREE.Mesh) {
|
|
239
|
-
const owned =
|
|
257
|
+
if (node instanceof THREE.Mesh || node instanceof THREE.LineSegments) {
|
|
258
|
+
const owned = drawableDefaults.get(node)!
|
|
240
259
|
if (owned.ownsGeometry) owned.geometry.dispose()
|
|
241
260
|
if (owned.ownsMaterial) (owned.material as THREE.Material).dispose()
|
|
242
261
|
}
|
|
@@ -278,12 +297,16 @@ export interface CanvasProps {
|
|
|
278
297
|
createRenderer?: (
|
|
279
298
|
options: THREE.WebGLRendererParameters,
|
|
280
299
|
) => THREE.WebGLRenderer
|
|
300
|
+
/** Handle renderer creation failure locally, for example by offering an accessible fallback. */
|
|
301
|
+
onError?: (error: unknown) => void
|
|
281
302
|
/** A fixed ratio, or a device-pixel-ratio clamp. Defaults to 1. */
|
|
282
303
|
dpr?: number | readonly [min: number, max: number]
|
|
283
304
|
/** Runs after sizing and scene mounting, before the first draw. May return cleanup. */
|
|
284
305
|
onCreated?: (state: CanvasState) => void | (() => void)
|
|
285
306
|
/** Supplied cameras keep their projection; update it explicitly here if desired. */
|
|
286
307
|
onResize?: (state: CanvasResizeState) => void
|
|
308
|
+
/** Skip an idle GPU draw. Frame callbacks and pointer updates still run. */
|
|
309
|
+
renderWhen?: () => boolean
|
|
287
310
|
onFrame?: (state: CanvasState & { delta: number; time: number }) => void
|
|
288
311
|
}
|
|
289
312
|
/** Browser-only scene boundary. The camera prop is borrowed and never disposed. */
|
|
@@ -295,9 +318,16 @@ export function Canvas(props: CanvasProps): SpaElement {
|
|
|
295
318
|
...props.rendererOptions,
|
|
296
319
|
canvas: canvas!,
|
|
297
320
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
321
|
+
let webgl: THREE.WebGLRenderer
|
|
322
|
+
try {
|
|
323
|
+
webgl = props.createRenderer
|
|
324
|
+
? props.createRenderer(parameters)
|
|
325
|
+
: new THREE.WebGLRenderer(parameters)
|
|
326
|
+
} catch (error) {
|
|
327
|
+
if (!props.onError) throw error
|
|
328
|
+
props.onError(error)
|
|
329
|
+
return
|
|
330
|
+
}
|
|
301
331
|
onCleanup(() => {
|
|
302
332
|
webgl.dispose()
|
|
303
333
|
})
|
|
@@ -342,35 +372,25 @@ export function Canvas(props: CanvasProps): SpaElement {
|
|
|
342
372
|
})
|
|
343
373
|
}
|
|
344
374
|
bindScene(size, resize)
|
|
375
|
+
const scope = owner!
|
|
345
376
|
const resized = () => {
|
|
346
377
|
try {
|
|
347
378
|
resize(size())
|
|
348
379
|
} catch (error) {
|
|
349
|
-
|
|
350
|
-
fail(ownerRoot, error)
|
|
351
|
-
} catch (failure) {
|
|
352
|
-
ownerRoot.error(failure)
|
|
353
|
-
}
|
|
380
|
+
reportScopeError(scope, error)
|
|
354
381
|
}
|
|
355
382
|
}
|
|
356
|
-
const ownerRoot = owner!._root
|
|
357
383
|
view.addEventListener(`resize`, resized)
|
|
358
384
|
onCleanup(() => {
|
|
359
385
|
view.removeEventListener(`resize`, resized)
|
|
360
386
|
})
|
|
361
387
|
renderer.mount(() => props.children, scene)
|
|
362
|
-
const scope = owner!
|
|
363
|
-
const root = scope._root
|
|
364
388
|
const events = createThreeEvents(
|
|
365
389
|
canvas,
|
|
366
390
|
scene,
|
|
367
391
|
() => props.camera ?? camera,
|
|
368
392
|
(error) => {
|
|
369
|
-
|
|
370
|
-
fail(root, error)
|
|
371
|
-
} catch (failure) {
|
|
372
|
-
root.error(failure)
|
|
373
|
-
}
|
|
393
|
+
reportScopeError(scope, error)
|
|
374
394
|
},
|
|
375
395
|
)
|
|
376
396
|
onCleanup(() => {
|
|
@@ -389,7 +409,9 @@ export function Canvas(props: CanvasProps): SpaElement {
|
|
|
389
409
|
const active = props.camera ?? camera
|
|
390
410
|
const delta = last === undefined ? 0 : (time - last) / 1000
|
|
391
411
|
last = time
|
|
392
|
-
|
|
412
|
+
const present = isPresent(scope)
|
|
413
|
+
const draw = !present || (props.renderWhen?.() ?? true)
|
|
414
|
+
if (present)
|
|
393
415
|
props.onFrame?.({
|
|
394
416
|
scene,
|
|
395
417
|
camera: active,
|
|
@@ -398,7 +420,7 @@ export function Canvas(props: CanvasProps): SpaElement {
|
|
|
398
420
|
time: time / 1000,
|
|
399
421
|
})
|
|
400
422
|
events.update()
|
|
401
|
-
webgl.render(scene, active)
|
|
423
|
+
if (draw) webgl.render(scene, active)
|
|
402
424
|
}, true)
|
|
403
425
|
})
|
|
404
426
|
})
|
|
@@ -435,6 +457,14 @@ export const DirectionalLight = sceneComponent<
|
|
|
435
457
|
intensity?: number
|
|
436
458
|
}
|
|
437
459
|
>(`DirectionalLight`)
|
|
460
|
+
export const PointLight = sceneComponent<
|
|
461
|
+
ObjectProps<THREE.PointLight> & {
|
|
462
|
+
color?: THREE.ColorRepresentation
|
|
463
|
+
intensity?: number
|
|
464
|
+
distance?: number
|
|
465
|
+
decay?: number
|
|
466
|
+
}
|
|
467
|
+
>(`PointLight`)
|
|
438
468
|
export const BoxGeometry = sceneComponent<{
|
|
439
469
|
args?: ConstructorParameters<typeof THREE.BoxGeometry>
|
|
440
470
|
ref?: (node: THREE.BoxGeometry | null) => void
|
|
@@ -466,3 +496,19 @@ export const MeshNormalMaterial = sceneComponent<
|
|
|
466
496
|
}
|
|
467
497
|
>(`MeshNormalMaterial`)
|
|
468
498
|
export { renderer as threeRenderer }
|
|
499
|
+
|
|
500
|
+
/** Batched line geometry, with the same attachment and ownership rules as Mesh. */
|
|
501
|
+
export const LineSegments = sceneComponent<
|
|
502
|
+
ObjectProps<THREE.LineSegments> & {
|
|
503
|
+
args?: ConstructorParameters<typeof THREE.LineSegments>
|
|
504
|
+
frustumCulled?: boolean
|
|
505
|
+
}
|
|
506
|
+
>(`LineSegments`)
|
|
507
|
+
export const BufferGeometry = sceneComponent<{
|
|
508
|
+
ref?: (node: THREE.BufferGeometry | null) => void
|
|
509
|
+
}>(`BufferGeometry`)
|
|
510
|
+
export const LineBasicMaterial = sceneComponent<
|
|
511
|
+
THREE.LineBasicMaterialParameters & {
|
|
512
|
+
ref?: (node: THREE.LineBasicMaterial | null) => void
|
|
513
|
+
}
|
|
514
|
+
>(`LineBasicMaterial`)
|
package/src/use-loadable.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import type { Canonical } from "atom.io/foundations/canonical"
|
|
8
8
|
import { withdraw } from "atom.io/internal"
|
|
9
9
|
|
|
10
|
-
import { type Accessor,
|
|
10
|
+
import { type Accessor, resolveStateToken, useGetter, useStore } from "./core.ts"
|
|
11
11
|
|
|
12
12
|
export type LoadableValue<T> = { loading: boolean; value: T }
|
|
13
13
|
|
|
@@ -34,7 +34,7 @@ export function useLoadable(
|
|
|
34
34
|
| [ReadableFamilyToken<any, Canonical, any>, Canonical]
|
|
35
35
|
| [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]
|
|
36
36
|
): Accessor<`LOADING` | (LoadableValue<unknown> & { error?: unknown })> {
|
|
37
|
-
const store =
|
|
37
|
+
const store = useStore()
|
|
38
38
|
const [token] = params
|
|
39
39
|
const family = token.type.endsWith(`_family`)
|
|
40
40
|
const selected = resolveStateToken(token, params[1] as Canonical)
|