@atom.io/spa 0.0.7 → 0.0.9
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 +169 -25
- package/README.mdx +62 -15
- 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/{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/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/core-DrUd8x25.js +465 -0
- package/dist/development/core-DrUd8x25.js.map +1 -0
- package/dist/development/{dom-DQ0M3rLL.js → dom-BRFv7FP_.js} +150 -35
- package/dist/development/dom-BRFv7FP_.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-DwB8MTM1.js +121 -0
- package/dist/development/identity-DwB8MTM1.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 +4 -21
- 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-u1-c5PGd.js} +8 -18
- package/dist/development/server-renderer-u1-c5PGd.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.js +20 -19
- package/dist/development/three.js.map +1 -1
- 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--HZvmgqd.js} +139 -32
- package/dist/dom--HZvmgqd.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-oFU5p-Qj.js +121 -0
- package/dist/identity-oFU5p-Qj.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 +1 -1
- package/dist/motion.js +4 -21
- 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-BYFDmqnM.js} +8 -18
- package/dist/server-renderer-BYFDmqnM.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.d.ts +3 -3
- package/dist/three.d.ts.map +1 -1
- package/dist/three.js +20 -19
- package/dist/three.js.map +1 -1
- 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 +16 -9
- package/src/astro-client.ts +3 -2
- package/src/astro-server.ts +2 -2
- 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 +116 -52
- package/src/floating.ts +2 -6
- package/src/hot.ts +190 -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/motion.ts +3 -1
- 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 +23 -24
- 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/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/vite-Bmyb6P5w.js +0 -265
- package/dist/vite-Bmyb6P5w.js.map +0 -1
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,
|
|
@@ -153,15 +153,18 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
153
153
|
const handlers = eventHandlers.get(node)!
|
|
154
154
|
handlers.get(key)?.()
|
|
155
155
|
handlers.delete(key)
|
|
156
|
-
|
|
156
|
+
const handler = props[key] as ThreeEventHandler | undefined
|
|
157
|
+
if (handler) {
|
|
158
|
+
const scope = owner!
|
|
157
159
|
handlers.set(
|
|
158
160
|
key,
|
|
159
|
-
listenThree(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
),
|
|
161
|
+
listenThree(node, key.slice(2).toLowerCase(), (event) => {
|
|
162
|
+
within(scope, () => {
|
|
163
|
+
handler(event)
|
|
164
|
+
})
|
|
165
|
+
}),
|
|
164
166
|
)
|
|
167
|
+
}
|
|
165
168
|
continue
|
|
166
169
|
}
|
|
167
170
|
if (!(key in target)) throw new Error(`spa/three: unknown property ${key}`)
|
|
@@ -182,10 +185,16 @@ const renderer = createSceneRenderer<Resource>({
|
|
|
182
185
|
const objects = children.filter(
|
|
183
186
|
(child): child is THREE.Object3D => child instanceof THREE.Object3D,
|
|
184
187
|
)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
if (
|
|
189
|
+
parent.children.length !== objects.length ||
|
|
190
|
+
objects.some((child, index) => child !== parent.children[index])
|
|
191
|
+
) {
|
|
192
|
+
const wanted = new Set(objects)
|
|
193
|
+
for (const child of [...parent.children])
|
|
194
|
+
if (!wanted.has(child)) parent.remove(child)
|
|
195
|
+
for (const child of objects) if (child.parent !== parent) parent.add(child)
|
|
196
|
+
parent.children.splice(0, parent.children.length, ...objects)
|
|
197
|
+
}
|
|
189
198
|
const resources = children.filter(
|
|
190
199
|
(child) => !(child instanceof THREE.Object3D),
|
|
191
200
|
)
|
|
@@ -342,35 +351,25 @@ export function Canvas(props: CanvasProps): SpaElement {
|
|
|
342
351
|
})
|
|
343
352
|
}
|
|
344
353
|
bindScene(size, resize)
|
|
354
|
+
const scope = owner!
|
|
345
355
|
const resized = () => {
|
|
346
356
|
try {
|
|
347
357
|
resize(size())
|
|
348
358
|
} catch (error) {
|
|
349
|
-
|
|
350
|
-
fail(ownerRoot, error)
|
|
351
|
-
} catch (failure) {
|
|
352
|
-
ownerRoot.error(failure)
|
|
353
|
-
}
|
|
359
|
+
reportScopeError(scope, error)
|
|
354
360
|
}
|
|
355
361
|
}
|
|
356
|
-
const ownerRoot = owner!._root
|
|
357
362
|
view.addEventListener(`resize`, resized)
|
|
358
363
|
onCleanup(() => {
|
|
359
364
|
view.removeEventListener(`resize`, resized)
|
|
360
365
|
})
|
|
361
366
|
renderer.mount(() => props.children, scene)
|
|
362
|
-
const scope = owner!
|
|
363
|
-
const root = scope._root
|
|
364
367
|
const events = createThreeEvents(
|
|
365
368
|
canvas,
|
|
366
369
|
scene,
|
|
367
370
|
() => props.camera ?? camera,
|
|
368
371
|
(error) => {
|
|
369
|
-
|
|
370
|
-
fail(root, error)
|
|
371
|
-
} catch (failure) {
|
|
372
|
-
root.error(failure)
|
|
373
|
-
}
|
|
372
|
+
reportScopeError(scope, error)
|
|
374
373
|
},
|
|
375
374
|
)
|
|
376
375
|
onCleanup(() => {
|
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)
|
package/src/vite.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { Plugin } from "vite"
|
|
2
2
|
|
|
3
3
|
import { compile } from "./compiler.ts"
|
|
4
|
+
import { hotModule, requiresModuleReload } from "./compiler-hmr.ts"
|
|
4
5
|
|
|
5
6
|
export interface SpaPluginOptions {
|
|
6
7
|
include?: RegExp
|
|
7
8
|
}
|
|
8
9
|
export default function spa(options: SpaPluginOptions = {}): Plugin {
|
|
9
10
|
const include = options.include ?? /\.[jt]sx$/
|
|
11
|
+
let development = false
|
|
12
|
+
const signatures = new Map<string, string>()
|
|
10
13
|
const matches = (id: string): boolean => {
|
|
11
14
|
include.lastIndex = 0
|
|
12
15
|
return !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0])
|
|
@@ -14,6 +17,9 @@ export default function spa(options: SpaPluginOptions = {}): Plugin {
|
|
|
14
17
|
return {
|
|
15
18
|
name: `spa`,
|
|
16
19
|
enforce: `pre`,
|
|
20
|
+
configResolved(config) {
|
|
21
|
+
development = config.command === `serve` && config.mode !== `test`
|
|
22
|
+
},
|
|
17
23
|
config() {
|
|
18
24
|
return {
|
|
19
25
|
resolve: { dedupe: [`@atom.io/spa`, `atom.io`] },
|
|
@@ -33,13 +39,47 @@ export default function spa(options: SpaPluginOptions = {}): Plugin {
|
|
|
33
39
|
}
|
|
34
40
|
},
|
|
35
41
|
},
|
|
36
|
-
transform(code, id) {
|
|
42
|
+
transform(code, id, environment) {
|
|
37
43
|
if (!matches(id)) return
|
|
38
|
-
|
|
44
|
+
const compiled = compile(code, id)
|
|
45
|
+
if (development && !environment?.ssr) {
|
|
46
|
+
const key = id.split(`?`)[0]
|
|
47
|
+
const hot = hotModule(compiled.code, id, compiled.map)
|
|
48
|
+
if (hot) {
|
|
49
|
+
signatures.set(key, hot.exports.join(`\0`))
|
|
50
|
+
return { code: hot.code, map: hot.map }
|
|
51
|
+
}
|
|
52
|
+
if (id === key) signatures.delete(key)
|
|
53
|
+
}
|
|
54
|
+
return compiled
|
|
39
55
|
},
|
|
40
|
-
|
|
41
|
-
handleHotUpdate({ server, file }) {
|
|
56
|
+
async handleHotUpdate({ server, file, read }) {
|
|
42
57
|
if (matches(file)) {
|
|
58
|
+
try {
|
|
59
|
+
const compiled = compile(await read(), file)
|
|
60
|
+
const hot = development
|
|
61
|
+
? hotModule(compiled.code, file, compiled.map)
|
|
62
|
+
: undefined
|
|
63
|
+
if (hot && signatures.get(file) === hot.exports.join(`\0`)) return
|
|
64
|
+
} catch (error) {
|
|
65
|
+
server.ws.send({
|
|
66
|
+
type: `error`,
|
|
67
|
+
err: {
|
|
68
|
+
message: String(error),
|
|
69
|
+
stack: error instanceof Error ? (error.stack ?? ``) : ``,
|
|
70
|
+
id: file,
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
return []
|
|
74
|
+
}
|
|
75
|
+
server.ws.send({ type: `full-reload` })
|
|
76
|
+
return []
|
|
77
|
+
}
|
|
78
|
+
if (
|
|
79
|
+
!file.includes(`/node_modules/`) &&
|
|
80
|
+
/\.[cm]?[jt]sx?$/.test(file) &&
|
|
81
|
+
requiresModuleReload(await read(), file)
|
|
82
|
+
) {
|
|
43
83
|
server.ws.send({ type: `full-reload` })
|
|
44
84
|
return []
|
|
45
85
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-DNcnGRv_.d.ts","names":[],"sources":["../src/presence.ts","../src/core.ts","../src/capabilities.ts"],"mappings":";;;UAIiB;EAChB,UAAU;EACV;;UAEgB;EAChB,QAAQ;EACR;;UAEgB;EAChB;EACA;EACA,YAAY;;UAEH,mBAAmB,GAAG;EAC/B,KAAK,cAAc,OAAO,IAAI;EAC9B,OACC,QAAQ,GACR,cACA,mBACA,eACA,MAAM;EAEP,MAAM,SAAS,MAAM;;UAEL;EAChB,WAAW,GAAG,GACb,QAAQ,QAAQ,MAAM,OACtB,aAAa,QAAQ,GAAG,OAAO,gBAC7B,mBAAmB,GAAG;EACzB,OAAO,OAAO,OAAO,QAAQ;EAC7B,KACC,OAAO,OACP,S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IAAoB,OAAO;IAAS,OAAO;;;iBAE5B,YAAY,UAAU,oBACrC,OAAO,cAAc,KACnB;iBACa,YAAY,UAAU,WAAW,UAAU,oBAC1D,QAAQ,oBAAoB,GAAG,IAC/B,KAAK,QAAQ,KACX;;UC5Xc;EAChB;EACA;EACA,YAAY;EACZ,MAAM;EACN,OAAO,aAAa;EACpB,QAAQ,eAAe,uBAAuB;;UAE9B;EAChB,MAAM,OAAO,0BAA0B;EACvC;;EAEA,OAAO,OAAO,yBAAyB;EACvC;;UAEgB;EAChB;;EAEA,cAAc,MAAM,OAAO;EAC3B,UAAU,MAAM,OAAO;EACvB,eAAe,WAAW,wBAAwB;;EAElD,OAAO,QAAQ,kBAAkB,QAAQ,QAAQ"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/capabilities.ts
|
|
2
|
-
function capabilityNamespace(key) {
|
|
3
|
-
const colon = key.indexOf(`:`);
|
|
4
|
-
if (colon < 0) return void 0;
|
|
5
|
-
const namespace = key.slice(0, colon);
|
|
6
|
-
return /^(xml|xmlns|xlink)$/.test(namespace) ? void 0 : namespace;
|
|
7
|
-
}
|
|
8
|
-
function validateCapabilities(scope, props) {
|
|
9
|
-
for (const key of Object.keys(props)) {
|
|
10
|
-
const namespace = capabilityNamespace(key);
|
|
11
|
-
if (namespace && !scope._root._capabilities.has(namespace)) throw new Error(`spa: capability "${namespace}" is not registered for this root`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** Separate framework properties from native attributes and own their bindings. */
|
|
15
|
-
function capabilityProps(scope, target, read, applyNative) {
|
|
16
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
17
|
-
scope._root._presence?.target(scope, target);
|
|
18
|
-
const cleanup = () => {
|
|
19
|
-
const errors = [];
|
|
20
|
-
for (const binding of [...bindings.values()].reverse()) try {
|
|
21
|
-
binding.dispose();
|
|
22
|
-
} catch (error) {
|
|
23
|
-
errors.push(error);
|
|
24
|
-
}
|
|
25
|
-
bindings.clear();
|
|
26
|
-
if (errors.length) throw new AggregateError(errors);
|
|
27
|
-
};
|
|
28
|
-
scope._cleanups.add(cleanup);
|
|
29
|
-
return (props) => {
|
|
30
|
-
validateCapabilities(scope, props);
|
|
31
|
-
const native = {};
|
|
32
|
-
const groups = /* @__PURE__ */ new Map();
|
|
33
|
-
for (const key of Object.keys(props)) {
|
|
34
|
-
const namespace = capabilityNamespace(key);
|
|
35
|
-
if (!namespace) {
|
|
36
|
-
const value = props[key];
|
|
37
|
-
native[key] = key.startsWith(`on`) && typeof value === `function` ? scope._root._presence?.event(scope, value) ?? value : value;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const group = groups.get(namespace) ?? {};
|
|
41
|
-
group[key.slice(namespace.length + 1)] = props[key];
|
|
42
|
-
groups.set(namespace, group);
|
|
43
|
-
}
|
|
44
|
-
const previousStyle = applyNative?.(native);
|
|
45
|
-
for (const [namespace, values] of groups) {
|
|
46
|
-
let binding = bindings.get(namespace);
|
|
47
|
-
if (!binding) {
|
|
48
|
-
binding = scope._root._capabilities.get(namespace).attach(target, scope);
|
|
49
|
-
bindings.set(namespace, binding);
|
|
50
|
-
scope._root._presence?.bind(scope, binding, read ?? (() => props), namespace);
|
|
51
|
-
}
|
|
52
|
-
if (previousStyle !== void 0) binding.update(values, previousStyle);
|
|
53
|
-
else binding.update(values);
|
|
54
|
-
}
|
|
55
|
-
for (const [namespace, binding] of bindings) if (!groups.has(namespace)) {
|
|
56
|
-
bindings.delete(namespace);
|
|
57
|
-
scope._root._presence?.unbind(binding);
|
|
58
|
-
binding.dispose();
|
|
59
|
-
}
|
|
60
|
-
return native;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export { capabilityProps as n, validateCapabilities as r, capabilityNamespace as t };
|
|
64
|
-
|
|
65
|
-
//# sourceMappingURL=capabilities-nOIitQ-_.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-nOIitQ-_.js","names":[],"sources":["../src/capabilities.ts"],"sourcesContent":["import type { Cleanup, Root, Scope } from \"./core.ts\"\nimport type { ExitHandle, PresenceCoordinator } from \"./presence.ts\"\n\n/** Native renderers expose property access without importing capability engines. */\nexport interface CapabilityTarget {\n\tkind: string\n\tnode: unknown\n\tsuspend?(): Cleanup\n\tread?(key: string): unknown\n\twrite?(key: string, value: unknown): void\n\tlisten?(event: string, listener: () => void): Cleanup\n}\nexport interface CapabilityBinding {\n\texit?(props: Record<string, unknown>): ExitHandle | undefined\n\tresume?(): void\n\t/** Inline CSS before native style replacement, for restoring capability-owned values. */\n\tupdate(props: Record<string, unknown>, previousStyle?: string): void\n\tdispose(): void\n}\nexport interface Capability {\n\tnamespace: string\n\t/** Prepare a synchronous update batch and return its commit callback. */\n\tbeforeUpdate?(root: Root): Cleanup\n\tpresence?(root: Root): PresenceCoordinator\n\tscheduleFrame?(callback: (time: number) => void): Cleanup\n\t/** SPA supplies ownership for integrations that measure after mount or report async errors. */\n\tattach(target: CapabilityTarget, scope?: Scope): CapabilityBinding\n}\n\nexport function capabilityNamespace(key: string): string | undefined {\n\tconst colon = key.indexOf(`:`)\n\tif (colon < 0) return undefined\n\tconst namespace = key.slice(0, colon)\n\treturn /^(xml|xmlns|xlink)$/.test(namespace) ? undefined : namespace\n}\nexport function validateCapabilities(\n\tscope: Scope,\n\tprops: Record<string, unknown>,\n): void {\n\tfor (const key of Object.keys(props)) {\n\t\tconst namespace = capabilityNamespace(key)\n\t\tif (namespace && !scope._root._capabilities.has(namespace))\n\t\t\tthrow new Error(\n\t\t\t\t`spa: capability \"${namespace}\" is not registered for this root`,\n\t\t\t)\n\t}\n}\n\n/** Separate framework properties from native attributes and own their bindings. */\nexport function capabilityProps(\n\tscope: Scope,\n\ttarget: CapabilityTarget,\n\tread?: () => Record<string, any>,\n\tapplyNative?: (props: Record<string, any>) => string | undefined,\n): (props: Record<string, any>) => Record<string, any> {\n\tconst bindings = new Map<string, CapabilityBinding>()\n\n\tscope._root._presence?.target(scope, target)\n\tconst cleanup: Cleanup = () => {\n\t\tconst errors: unknown[] = []\n\t\tfor (const binding of [...bindings.values()].reverse()) {\n\t\t\ttry {\n\t\t\t\tbinding.dispose()\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error)\n\t\t\t}\n\t\t}\n\t\tbindings.clear()\n\t\tif (errors.length) throw new AggregateError(errors)\n\t}\n\tscope._cleanups.add(cleanup)\n\treturn (props) => {\n\t\tvalidateCapabilities(scope, props)\n\t\tconst native: Record<string, any> = {}\n\t\tconst groups = new Map<string, Record<string, unknown>>()\n\t\tfor (const key of Object.keys(props)) {\n\t\t\tconst namespace = capabilityNamespace(key)\n\t\t\tif (!namespace) {\n\t\t\t\tconst value = props[key]\n\t\t\t\tnative[key] =\n\t\t\t\t\tkey.startsWith(`on`) && typeof value === `function`\n\t\t\t\t\t\t? (scope._root._presence?.event(scope, value) ?? value)\n\t\t\t\t\t\t: value\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst group = groups.get(namespace) ?? {}\n\t\t\tgroup[key.slice(namespace.length + 1)] = props[key]\n\t\t\tgroups.set(namespace, group)\n\t\t}\n\t\tconst previousStyle = applyNative?.(native)\n\t\tfor (const [namespace, values] of groups) {\n\t\t\tlet binding = bindings.get(namespace)\n\t\t\tif (!binding) {\n\t\t\t\tbinding = scope._root._capabilities.get(namespace)!.attach(target, scope)\n\t\t\t\tbindings.set(namespace, binding)\n\t\t\t\tscope._root._presence?.bind(\n\t\t\t\t\tscope,\n\t\t\t\t\tbinding,\n\t\t\t\t\tread ?? (() => props),\n\t\t\t\t\tnamespace,\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (previousStyle !== undefined) binding.update(values, previousStyle)\n\t\t\telse binding.update(values)\n\t\t}\n\t\tfor (const [namespace, binding] of bindings)\n\t\t\tif (!groups.has(namespace)) {\n\t\t\t\tbindings.delete(namespace)\n\t\t\t\tscope._root._presence?.unbind(binding)\n\t\t\t\tbinding.dispose()\n\t\t\t}\n\t\treturn native\n\t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O,IAAI,SAAS,KAAK,CAAC;GACxC,MAAM,IAAI,MAAM,UAAU,SAAS,CAAC,KAAK,MAAM;GAC/C,OAAO,IAAI,WAAW,KAAK;EAC5B;EACA,MAAM,gBAAgB,cAAc,MAAM;EAC1C,KAAK,MAAM,CAAC,WAAW,WAAW,QAAQ;GACzC,IAAI,UAAU,SAAS,IAAI,SAAS;GACpC,IAAI,CAAC,SAAS;IACb,UAAU,MAAM,MAAM,cAAc,IAAI,SAAS,CAAC,CAAE,OAAO,QAAQ,KAAK;IACxE,SAAS,IAAI,WAAW,OAAO;IAC/B,MAAM,MAAM,WAAW,KACtB,OACA,SACA,eAAe,QACf,SACD;GACD;GACA,IAAI,kBAAkB,KAAA,GAAW,QAAQ,OAAO,QAAQ,aAAa;QAChE,QAAQ,OAAO,MAAM;EAC3B;EACA,KAAK,MAAM,CAAC,WAAW,YAAY,UAClC,IAAI,CAAC,OAAO,IAAI,SAAS,GAAG;GAC3B,SAAS,OAAO,SAAS;GACzB,MAAM,MAAM,WAAW,OAAO,OAAO;GACrC,QAAQ,QAAQ;EACjB;EACD,OAAO;CACR;AACD"}
|
package/dist/core-B4rJ0xdc.js
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { IMPLICIT, actUponStore, clearTimelineInStore, disposeFromStore, findInStore, findTimelineInStore, getFromStore, getTimelineTransactionAtHead, setIntoStore, subscribeToState, subscribeToTimeline, timeTravel, timeTravelTransactionGroupInStore, withdraw } from "atom.io/internal";
|
|
2
|
-
// src/core.ts
|
|
3
|
-
let owner;
|
|
4
|
-
let tracking;
|
|
5
|
-
let serial = 0;
|
|
6
|
-
function within(scope, run) {
|
|
7
|
-
const previous = owner;
|
|
8
|
-
owner = scope;
|
|
9
|
-
try {
|
|
10
|
-
return run();
|
|
11
|
-
} finally {
|
|
12
|
-
owner = previous;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function untrack(run) {
|
|
16
|
-
const previous = tracking;
|
|
17
|
-
tracking = void 0;
|
|
18
|
-
try {
|
|
19
|
-
return run();
|
|
20
|
-
} finally {
|
|
21
|
-
tracking = previous;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function createScope(parent) {
|
|
25
|
-
const child = {
|
|
26
|
-
_root: parent?._root,
|
|
27
|
-
_parent: parent,
|
|
28
|
-
_cleanups: /* @__PURE__ */ new Set(),
|
|
29
|
-
_updates: [],
|
|
30
|
-
_dead: false
|
|
31
|
-
};
|
|
32
|
-
parent?._cleanups.add(child);
|
|
33
|
-
return child;
|
|
34
|
-
}
|
|
35
|
-
function fail(scope, error) {
|
|
36
|
-
try {
|
|
37
|
-
dispose(scope);
|
|
38
|
-
} catch (cleanup) {
|
|
39
|
-
throw new AggregateError([error, cleanup]);
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
function dispose(scope) {
|
|
44
|
-
if (scope._dead) return;
|
|
45
|
-
scope._dead = true;
|
|
46
|
-
const errors = [];
|
|
47
|
-
try {
|
|
48
|
-
scope._root._presence?.forget(scope);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
errors.push(error);
|
|
51
|
-
}
|
|
52
|
-
for (const cleanup of [...scope._cleanups].reverse()) try {
|
|
53
|
-
typeof cleanup === `function` ? cleanup() : dispose(cleanup);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
errors.push(error);
|
|
56
|
-
}
|
|
57
|
-
scope._parent?._cleanups.delete(scope);
|
|
58
|
-
scope._cleanups.clear();
|
|
59
|
-
scope._updates.length = 0;
|
|
60
|
-
if (errors.length) throw new AggregateError(errors);
|
|
61
|
-
}
|
|
62
|
-
function invalidate(scope) {
|
|
63
|
-
for (const run of scope._updates) enqueue(scope, run);
|
|
64
|
-
for (const child of scope._cleanups) if (typeof child !== `function`) invalidate(child);
|
|
65
|
-
}
|
|
66
|
-
function enqueue(scope, run) {
|
|
67
|
-
if (!isPresent(scope)) return;
|
|
68
|
-
const root = scope._root;
|
|
69
|
-
if (!root._queue.size) queueMicrotask(() => {
|
|
70
|
-
try {
|
|
71
|
-
root.flush();
|
|
72
|
-
} catch (error) {
|
|
73
|
-
root.error(error);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
root._queue.add(run);
|
|
77
|
-
}
|
|
78
|
-
function createRoot(options = {}, server = false) {
|
|
79
|
-
const capabilities = /* @__PURE__ */ new Map();
|
|
80
|
-
for (const capability of options.capabilities ?? []) {
|
|
81
|
-
if (capabilities.has(capability.namespace)) throw new Error(`spa: duplicate capability ${capability.namespace}`);
|
|
82
|
-
capabilities.set(capability.namespace, capability);
|
|
83
|
-
}
|
|
84
|
-
const root = {
|
|
85
|
-
_capabilities: capabilities,
|
|
86
|
-
_store: options.store ?? IMPLICIT.STORE,
|
|
87
|
-
_prefix: options.idPrefix ?? `w${serial++}`,
|
|
88
|
-
_id: 0,
|
|
89
|
-
...createScope(),
|
|
90
|
-
_queue: /* @__PURE__ */ new Set(),
|
|
91
|
-
_mounts: server ? void 0 : []
|
|
92
|
-
};
|
|
93
|
-
root._root = root;
|
|
94
|
-
root.error = options.onError ?? ((error) => {
|
|
95
|
-
throw error;
|
|
96
|
-
});
|
|
97
|
-
for (const capability of capabilities.values()) if (capability.presence) {
|
|
98
|
-
if (root._presence) throw new Error(`spa: multiple presence coordinators`);
|
|
99
|
-
root._presence = capability.presence(root);
|
|
100
|
-
}
|
|
101
|
-
root.flush = () => {
|
|
102
|
-
if (!root._queue.size && !root._mounts.length) return;
|
|
103
|
-
try {
|
|
104
|
-
const commits = [...capabilities.values()].map((capability) => capability.beforeUpdate?.(root));
|
|
105
|
-
try {
|
|
106
|
-
while (root._queue.size || root._mounts.length) {
|
|
107
|
-
for (const run of [...root._queue]) if (root._queue.delete(run)) run();
|
|
108
|
-
for (const run of root._mounts.splice(0)) run();
|
|
109
|
-
}
|
|
110
|
-
} finally {
|
|
111
|
-
for (const commit of commits) commit?.();
|
|
112
|
-
}
|
|
113
|
-
} catch (error) {
|
|
114
|
-
fail(root, error);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return root;
|
|
118
|
-
}
|
|
119
|
-
/** Return the atom.io store selected by the current root. */
|
|
120
|
-
function useStore() {
|
|
121
|
-
return owner._root._store;
|
|
122
|
-
}
|
|
123
|
-
/** Return atom.io disposal bound to the current root's store. */
|
|
124
|
-
function useDisposal() {
|
|
125
|
-
return disposeFromStore.bind(null, useStore());
|
|
126
|
-
}
|
|
127
|
-
function onCleanup(cleanup) {
|
|
128
|
-
owner._cleanups.add(cleanup);
|
|
129
|
-
}
|
|
130
|
-
function onMount(run) {
|
|
131
|
-
const scope = owner;
|
|
132
|
-
scope._root._mounts?.push(() => {
|
|
133
|
-
if (!scope._dead) within(scope, () => {
|
|
134
|
-
untrack(run);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
function useId() {
|
|
139
|
-
const root = owner._root;
|
|
140
|
-
return `${root._prefix}-${root._id++}`;
|
|
141
|
-
}
|
|
142
|
-
function observe(scope, read, apply) {
|
|
143
|
-
const subscriptions = /* @__PURE__ */ new Map();
|
|
144
|
-
const run = () => {
|
|
145
|
-
if (!isPresent(scope)) return;
|
|
146
|
-
const used = /* @__PURE__ */ new Set();
|
|
147
|
-
const previous = tracking;
|
|
148
|
-
tracking = (subscribe) => {
|
|
149
|
-
used.add(subscribe);
|
|
150
|
-
if (!subscriptions.has(subscribe)) subscriptions.set(subscribe, subscribe(() => {
|
|
151
|
-
enqueue(scope, run);
|
|
152
|
-
}));
|
|
153
|
-
};
|
|
154
|
-
let value;
|
|
155
|
-
try {
|
|
156
|
-
value = within(scope, read);
|
|
157
|
-
} finally {
|
|
158
|
-
tracking = previous;
|
|
159
|
-
for (const [subscribe, unsubscribe] of subscriptions) if (!used.has(subscribe)) {
|
|
160
|
-
unsubscribe();
|
|
161
|
-
subscriptions.delete(subscribe);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
untrack(() => {
|
|
165
|
-
apply(value);
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
scope._updates.push(run);
|
|
169
|
-
scope._cleanups.add(() => {
|
|
170
|
-
scope._root._queue.delete(run);
|
|
171
|
-
for (const unsubscribe of subscriptions.values()) unsubscribe();
|
|
172
|
-
});
|
|
173
|
-
run();
|
|
174
|
-
}
|
|
175
|
-
/** Resolve a fixed family key in the current owner's store. */
|
|
176
|
-
function resolveStateToken(token, key) {
|
|
177
|
-
const store = useStore();
|
|
178
|
-
return token.type.endsWith(`_family`) ? findInStore(store, token, key) : token;
|
|
179
|
-
}
|
|
180
|
-
function useGetter(token, key) {
|
|
181
|
-
token = resolveStateToken(token, key);
|
|
182
|
-
const root = owner._root;
|
|
183
|
-
const store = useStore();
|
|
184
|
-
const subscribe = (notify) => subscribeToState(store, token, `spa:${serial++}`, notify);
|
|
185
|
-
return () => {
|
|
186
|
-
const value = getFromStore(store, token);
|
|
187
|
-
root._onRead?.(value, token);
|
|
188
|
-
tracking?.(subscribe);
|
|
189
|
-
return value;
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function useSetter(token, key) {
|
|
193
|
-
token = resolveStateToken(token, key);
|
|
194
|
-
const store = useStore();
|
|
195
|
-
return (value) => {
|
|
196
|
-
setIntoStore(store, token, value);
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function useTransaction(token) {
|
|
200
|
-
return actUponStore(useStore(), token, `spa:${serial++}`);
|
|
201
|
-
}
|
|
202
|
-
const refs = /* @__PURE__ */ new WeakMap();
|
|
203
|
-
function useRef(token, key) {
|
|
204
|
-
token = resolveStateToken(token, key);
|
|
205
|
-
const store = useStore();
|
|
206
|
-
const owners = refs.get(store) ?? /* @__PURE__ */ new Map();
|
|
207
|
-
refs.set(store, owners);
|
|
208
|
-
const identity = {};
|
|
209
|
-
let held = null;
|
|
210
|
-
return (element) => {
|
|
211
|
-
if (element) {
|
|
212
|
-
held = element;
|
|
213
|
-
owners.set(token.key, identity);
|
|
214
|
-
setIntoStore(store, token, element);
|
|
215
|
-
} else if (owners.get(token.key) === identity) {
|
|
216
|
-
owners.delete(token.key);
|
|
217
|
-
if (getFromStore(store, token) === held) setIntoStore(store, token, null);
|
|
218
|
-
held = null;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function useTimeline(token, key) {
|
|
223
|
-
const store = useStore();
|
|
224
|
-
const selected = token.type === `timeline_family` ? findTimelineInStore(store, token, key) : token;
|
|
225
|
-
const subscribe = (notify) => subscribeToTimeline(store, selected, `spa:${serial++}`, notify);
|
|
226
|
-
const read = () => {
|
|
227
|
-
const timeline = withdraw(store, selected);
|
|
228
|
-
tracking?.(subscribe);
|
|
229
|
-
return timeline;
|
|
230
|
-
};
|
|
231
|
-
return {
|
|
232
|
-
getCursor: () => read().at,
|
|
233
|
-
getLength: () => read().history.length,
|
|
234
|
-
undo: () => {
|
|
235
|
-
timeTravel(store, `undo`, selected);
|
|
236
|
-
},
|
|
237
|
-
redo: () => {
|
|
238
|
-
timeTravel(store, `redo`, selected);
|
|
239
|
-
},
|
|
240
|
-
clear: () => {
|
|
241
|
-
clearTimelineInStore(store, selected);
|
|
242
|
-
},
|
|
243
|
-
getTransaction: () => {
|
|
244
|
-
const timeline = read();
|
|
245
|
-
const controls = {};
|
|
246
|
-
for (const direction of [`undo`, `redo`]) {
|
|
247
|
-
const group = getTimelineTransactionAtHead(timeline, direction);
|
|
248
|
-
if (group) controls[direction] = () => {
|
|
249
|
-
timeTravelTransactionGroupInStore(store, direction, group);
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
return controls;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
function plain(value) {
|
|
257
|
-
if (typeof value === `function`) return plain(value());
|
|
258
|
-
if (Array.isArray(value)) return value.map(plain).join(``);
|
|
259
|
-
if (value == null || typeof value === `boolean`) return ``;
|
|
260
|
-
return String(value);
|
|
261
|
-
}
|
|
262
|
-
function isPresent(scope) {
|
|
263
|
-
for (let at = scope; at; at = at._parent) if (at._dead || at._exiting) return false;
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
export { within as S, useRef as _, invalidate as a, useTimeline as b, onCleanup as c, plain as d, resolveStateToken as f, useId as g, useGetter as h, fail as i, onMount as l, useDisposal as m, createScope as n, isPresent as o, untrack as p, dispose as r, observe as s, createRoot as t, owner as u, useSetter as v, useTransaction as x, useStore as y };
|
|
267
|
-
|
|
268
|
-
//# sourceMappingURL=core-B4rJ0xdc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core-B4rJ0xdc.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n\tdisposeState,\n\tReadableFamilyToken,\n\tReadableToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSetter,\n\tTimelineFamilyToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tViewOf,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tclearTimelineInStore,\n\tdisposeFromStore,\n\tfindInStore,\n\tfindTimelineInStore,\n\tgetFromStore,\n\tgetTimelineTransactionAtHead,\n\tIMPLICIT,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\ttimeTravel,\n\ttimeTravelTransactionGroupInStore,\n\twithdraw,\n} from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type {\n\tExitParticipant,\n\tPresenceCoordinator,\n\tPresenceTarget,\n} from \"./presence.ts\"\n\nexport type Cleanup = () => void\n// A callable interface permits the recursive Children union. A type alias does not.\n/* oxlint-disable typescript/prefer-function-type -- A callable interface is required for recursive Children. */\nexport interface Accessor<T> {\n\t(): T\n}\n/* oxlint-enable typescript/prefer-function-type */\nexport type Component<P = any> = (props: P) => Children\n/** A JSX descriptor for an intrinsic tag, component, or fragment. */\nexport interface SpaElement {\n\ttype: string | Component | null\n\tprops: Record<string, any>\n}\n/** Renderable content, including nested groups and reactive accessors. */\nexport type Children =\n\t| SpaElement\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| readonly Children[]\n\t| Accessor<Children>\nexport interface RootOptions {\n\tcapabilities?: readonly Capability[]\n\tstore?: RootStore\n\tidPrefix?: string\n\tonError?: (error: unknown) => void\n}\nexport interface Scope {\n\t_exiting?: boolean\n\t_exits?: Set<ExitParticipant>\n\t_targets?: Set<PresenceTarget>\n\t_root: Root\n\t_parent?: Scope | undefined\n\t_cleanups: Set<Cleanup | Scope>\n\t_updates: Cleanup[]\n\t_dead: boolean\n}\nexport interface Root extends Scope {\n\t_onRead?: ((value: unknown, token: ReadableToken<unknown>) => void) | undefined\n\t_presence?: PresenceCoordinator\n\t_capabilities: Map<string, Capability>\n\t_store: RootStore\n\t_prefix: string\n\t_id: number\n\t_queue: Set<Cleanup>\n\t_mounts: Cleanup[] | undefined\n\tflush: Cleanup\n\terror: (error: unknown) => void\n}\n\nexport let owner: Scope | undefined\ntype Subscribe = (notify: Cleanup) => Cleanup\nlet tracking: ((subscribe: Subscribe) => void) | undefined\nlet serial = 0\n\nexport function within<T>(scope: Scope, run: () => T): T {\n\tconst previous = owner\n\towner = scope\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\towner = previous\n\t}\n}\nexport function untrack<T>(run: () => T): T {\n\tconst previous = tracking\n\ttracking = undefined\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\ttracking = previous\n\t}\n}\nexport function createScope(parent?: Scope): Scope {\n\tconst child: Scope = {\n\t\t_root: parent?._root as Root,\n\t\t_parent: parent,\n\t\t_cleanups: new Set(),\n\t\t_updates: [],\n\t\t_dead: false,\n\t}\n\tparent?._cleanups.add(child)\n\treturn child\n}\nexport function fail(scope: Scope, error: unknown): never {\n\ttry {\n\t\tdispose(scope)\n\t} catch (cleanup) {\n\t\tthrow new AggregateError([error, cleanup])\n\t}\n\tthrow error\n}\nexport function dispose(scope: Scope): void {\n\tif (scope._dead) return\n\tscope._dead = true\n\tconst errors: unknown[] = []\n\ttry {\n\t\tscope._root._presence?.forget(scope)\n\t} catch (error) {\n\t\terrors.push(error)\n\t}\n\tfor (const cleanup of [...scope._cleanups].reverse()) {\n\t\ttry {\n\t\t\ttypeof cleanup === `function` ? cleanup() : dispose(cleanup)\n\t\t} catch (error) {\n\t\t\terrors.push(error)\n\t\t}\n\t}\n\tscope._parent?._cleanups.delete(scope)\n\tscope._cleanups.clear()\n\tscope._updates.length = 0\n\tif (errors.length) throw new AggregateError(errors)\n}\nexport function invalidate(scope: Scope): void {\n\tfor (const run of scope._updates) enqueue(scope, run)\n\tfor (const child of scope._cleanups)\n\t\tif (typeof child !== `function`) invalidate(child)\n}\nfunction enqueue(scope: Scope, run: Cleanup): void {\n\tif (!isPresent(scope)) return\n\tconst root = scope._root\n\tif (!root._queue.size)\n\t\tqueueMicrotask(() => {\n\t\t\ttry {\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\troot.error(error)\n\t\t\t}\n\t\t})\n\troot._queue.add(run)\n}\nexport function createRoot(options: RootOptions = {}, server = false): Root {\n\tconst capabilities = new Map<string, Capability>()\n\tfor (const capability of options.capabilities ?? []) {\n\t\tif (capabilities.has(capability.namespace))\n\t\t\tthrow new Error(`spa: duplicate capability ${capability.namespace}`)\n\t\tcapabilities.set(capability.namespace, capability)\n\t}\n\tconst root = {\n\t\t_capabilities: capabilities,\n\t\t_store: options.store ?? IMPLICIT.STORE,\n\t\t_prefix: options.idPrefix ?? `w${serial++}`,\n\t\t_id: 0,\n\t\t...createScope(),\n\t\t_queue: new Set(),\n\t\t_mounts: server ? undefined : [],\n\t} as unknown as Root\n\troot._root = root\n\troot.error =\n\t\toptions.onError ??\n\t\t((error) => {\n\t\t\tthrow error\n\t\t})\n\tfor (const capability of capabilities.values())\n\t\tif (capability.presence) {\n\t\t\tif (root._presence) throw new Error(`spa: multiple presence coordinators`)\n\t\t\troot._presence = capability.presence(root)\n\t\t}\n\troot.flush = () => {\n\t\tif (!root._queue.size && !root._mounts!.length) return\n\t\ttry {\n\t\t\tconst commits = [...capabilities.values()].map((capability) =>\n\t\t\t\tcapability.beforeUpdate?.(root),\n\t\t\t)\n\t\t\ttry {\n\t\t\t\tlet passes = 0\n\t\t\t\twhile (root._queue.size || root._mounts!.length) {\n\t\t\t\t\tif (import.meta.env.DEV && ++passes > 100)\n\t\t\t\t\t\tthrow new Error(`spa: update loop`)\n\t\t\t\t\tfor (const run of [...root._queue]) if (root._queue.delete(run)) run()\n\t\t\t\t\tfor (const run of root._mounts!.splice(0)) run()\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tfor (const commit of commits) commit?.()\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfail(root, error)\n\t\t}\n\t}\n\treturn root\n}\n/** Return the atom.io store selected by the current root. */\nexport function useStore(): RootStore {\n\treturn owner!._root._store\n}\n/** Return atom.io disposal bound to the current root's store. */\nexport function useDisposal(): typeof disposeState {\n\treturn disposeFromStore.bind(null, useStore()) as typeof disposeState\n}\nexport function onCleanup(cleanup: Cleanup): void {\n\towner!._cleanups.add(cleanup)\n}\nexport function onMount(run: Cleanup): void {\n\tconst scope = owner!\n\tscope._root._mounts?.push(() => {\n\t\tif (!scope._dead)\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(run)\n\t\t\t})\n\t})\n}\nexport function useId(): string {\n\tconst root = owner!._root\n\treturn `${root._prefix}-${root._id++}`\n}\n\nexport function observe<T>(\n\tscope: Scope,\n\tread: Accessor<T>,\n\tapply: (value: T) => void,\n): void {\n\tconst subscriptions = new Map<Subscribe, Cleanup>()\n\tconst run = () => {\n\t\tif (!isPresent(scope)) return\n\t\tconst used = new Set<Subscribe>()\n\t\tconst previous = tracking\n\t\ttracking = (subscribe) => {\n\t\t\tused.add(subscribe)\n\t\t\tif (!subscriptions.has(subscribe))\n\t\t\t\tsubscriptions.set(\n\t\t\t\t\tsubscribe,\n\t\t\t\t\tsubscribe(() => {\n\t\t\t\t\t\tenqueue(scope, run)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t}\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = within(scope, read)\n\t\t} finally {\n\t\t\ttracking = previous\n\t\t\tfor (const [subscribe, unsubscribe] of subscriptions)\n\t\t\t\tif (!used.has(subscribe)) {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tsubscriptions.delete(subscribe)\n\t\t\t\t}\n\t\t}\n\t\tuntrack(() => {\n\t\t\tapply(value)\n\t\t})\n\t}\n\tscope._updates.push(run)\n\tscope._cleanups.add(() => {\n\t\tscope._root._queue.delete(run)\n\t\tfor (const unsubscribe of subscriptions.values()) unsubscribe()\n\t})\n\trun()\n}\n\n/** Resolve a fixed family key in the current owner's store. */\nexport function resolveStateToken(token: any, key?: Canonical): any {\n\tconst store = useStore()\n\treturn token.type.endsWith(`_family`) ? findInStore(store, token, key!) : token\n}\n\n/** Capture a token for this instance. Change the component key to change its token. */\nexport function useGetter<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter<T, K extends Canonical, E = never>(\n\tfamily: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter(token: any, key?: Canonical): Accessor<any> {\n\ttoken = resolveStateToken(token, key)\n\tconst root = owner!._root\n\tconst store = useStore()\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToState(store, token, `spa:${serial++}`, notify)\n\treturn () => {\n\t\tconst value = getFromStore(store, token)\n\t\troot._onRead?.(value, token)\n\t\ttracking?.(subscribe)\n\t\treturn value\n\t}\n}\nexport function useSetter<T>(\n\ttoken: WritableToken<T, any, any>,\n): (value: T | Setter<T>) => void\nexport function useSetter<T, K extends Canonical>(\n\tfamily: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): (value: T | Setter<T>) => void\nexport function useSetter(token: any, key?: Canonical): (value: any) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = useStore()\n\treturn (value) => {\n\t\tsetIntoStore(store, token, value)\n\t}\n}\nexport function useTransaction<F extends (...args: any[]) => any>(\n\ttoken: TransactionToken<F>,\n): (...args: Parameters<F>) => ReturnType<F> {\n\treturn actUponStore(useStore(), token, `spa:${serial++}`)\n}\n\nconst refs = new WeakMap<RootStore, Map<string, object>>()\nexport function useRef<E extends Element>(\n\ttoken: RegularAtomToken<E | null>,\n): (element: E | null) => void\nexport function useRef<E extends Element, K extends Canonical>(\n\tfamily: RegularAtomFamilyToken<E | null, K>,\n\tkey: NoInfer<K>,\n): (element: E | null) => void\nexport function useRef<E extends Element>(\n\ttoken: any,\n\tkey?: Canonical,\n): (element: E | null) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = useStore()\n\tconst owners = refs.get(store) ?? new Map<string, object>()\n\trefs.set(store, owners)\n\tconst identity = {}\n\tlet held: E | null = null\n\treturn (element) => {\n\t\tif (element) {\n\t\t\theld = element\n\t\t\towners.set(token.key, identity)\n\t\t\tsetIntoStore(store, token, element)\n\t\t} else if (owners.get(token.key) === identity) {\n\t\t\towners.delete(token.key)\n\t\t\tif (getFromStore(store, token) === held) setIntoStore(store, token, null)\n\t\t\theld = null\n\t\t}\n\t}\n}\nexport interface TimelineControls {\n\tgetCursor(): number\n\tgetLength(): number\n\tundo(): void\n\tredo(): void\n\tclear(): void\n\tgetTransaction(): { undo?: Cleanup; redo?: Cleanup }\n}\nexport function useTimeline<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n): TimelineControls\nexport function useTimeline<K extends Canonical, M extends TimelineManageable>(\n\tfamily: TimelineFamilyToken<K, M>,\n\tkey: NoInfer<K>,\n): TimelineControls\nexport function useTimeline(token: any, key?: Canonical): TimelineControls {\n\tconst store = useStore()\n\tconst selected: TimelineToken<any> =\n\t\ttoken.type === `timeline_family`\n\t\t\t? findTimelineInStore(store, token, key!)\n\t\t\t: token\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToTimeline(store, selected, `spa:${serial++}`, notify)\n\tconst read = () => {\n\t\tconst timeline = withdraw(store, selected)\n\t\ttracking?.(subscribe)\n\t\treturn timeline\n\t}\n\treturn {\n\t\tgetCursor: () => read().at,\n\t\tgetLength: () => read().history.length,\n\t\tundo: () => {\n\t\t\ttimeTravel(store, `undo`, selected)\n\t\t},\n\t\tredo: () => {\n\t\t\ttimeTravel(store, `redo`, selected)\n\t\t},\n\t\tclear: () => {\n\t\t\tclearTimelineInStore(store, selected)\n\t\t},\n\t\tgetTransaction: () => {\n\t\t\tconst timeline = read()\n\t\t\tconst controls: ReturnType<TimelineControls[`getTransaction`]> = {}\n\t\t\tfor (const direction of [`undo`, `redo`] as const) {\n\t\t\t\tconst group = getTimelineTransactionAtHead(timeline, direction)\n\t\t\t\tif (group)\n\t\t\t\t\tcontrols[direction] = () => {\n\t\t\t\t\t\ttimeTravelTransactionGroupInStore(store, direction, group)\n\t\t\t\t\t}\n\t\t\t}\n\t\t\treturn controls\n\t\t},\n\t}\n}\n\nexport function plain(value: Children): string {\n\tif (typeof value === `function`) return plain(value())\n\tif (Array.isArray(value)) return value.map(plain).join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (import.meta.env.DEV && typeof value === `object`)\n\t\tthrow new Error(`spa: text required`)\n\t// oxlint-disable-next-line typescript/no-base-to-string -- Valid text children are primitives here; development rejects malformed object children.\n\treturn String(value)\n}\n\nexport function isPresent(scope: Scope): boolean {\n\tfor (let at: Scope | undefined = scope; at; at = at._parent)\n\t\tif (at._dead || at._exiting) return false\n\treturn true\n}\n"],"mappings":";;AA8FA,IAAW;AAEX,IAAI;AACJ,IAAI,SAAS;AAEb,SAAgB,OAAU,OAAc,KAAiB;CACxD,MAAM,WAAW;CACjB,QAAQ;CACR,IAAI;EACH,OAAO,IAAI;CACZ,UAAU;EACT,QAAQ;CACT;AACD;AACA,SAAgB,QA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capabilities.ts
|
|
2
|
-
function capabilityNamespace(key) {
|
|
3
|
-
const colon = key.indexOf(`:`);
|
|
4
|
-
if (colon < 0) return void 0;
|
|
5
|
-
const namespace = key.slice(0, colon);
|
|
6
|
-
return /^(xml|xmlns|xlink)$/.test(namespace) ? void 0 : namespace;
|
|
7
|
-
}
|
|
8
|
-
function validateCapabilities(scope, props) {
|
|
9
|
-
for (const key of Object.keys(props)) {
|
|
10
|
-
const namespace = capabilityNamespace(key);
|
|
11
|
-
if (namespace && !scope._root._capabilities.has(namespace)) throw new Error(`spa: capability "${namespace}" is not registered for this root`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** Separate framework properties from native attributes and own their bindings. */
|
|
15
|
-
function capabilityProps(scope, target, read, applyNative) {
|
|
16
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
17
|
-
scope._root._presence?.target(scope, target);
|
|
18
|
-
const cleanup = () => {
|
|
19
|
-
const errors = [];
|
|
20
|
-
for (const binding of [...bindings.values()].reverse()) try {
|
|
21
|
-
binding.dispose();
|
|
22
|
-
} catch (error) {
|
|
23
|
-
errors.push(error);
|
|
24
|
-
}
|
|
25
|
-
bindings.clear();
|
|
26
|
-
if (errors.length) throw new AggregateError(errors);
|
|
27
|
-
};
|
|
28
|
-
scope._cleanups.add(cleanup);
|
|
29
|
-
return (props) => {
|
|
30
|
-
validateCapabilities(scope, props);
|
|
31
|
-
const native = {};
|
|
32
|
-
const groups = /* @__PURE__ */ new Map();
|
|
33
|
-
for (const key of Object.keys(props)) {
|
|
34
|
-
const namespace = capabilityNamespace(key);
|
|
35
|
-
if (!namespace) {
|
|
36
|
-
const value = props[key];
|
|
37
|
-
native[key] = key.startsWith(`on`) && typeof value === `function` ? scope._root._presence?.event(scope, value) ?? value : value;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const group = groups.get(namespace) ?? {};
|
|
41
|
-
group[key.slice(namespace.length + 1)] = props[key];
|
|
42
|
-
groups.set(namespace, group);
|
|
43
|
-
}
|
|
44
|
-
const previousStyle = applyNative?.(native);
|
|
45
|
-
for (const [namespace, values] of groups) {
|
|
46
|
-
let binding = bindings.get(namespace);
|
|
47
|
-
if (!binding) {
|
|
48
|
-
binding = scope._root._capabilities.get(namespace).attach(target, scope);
|
|
49
|
-
bindings.set(namespace, binding);
|
|
50
|
-
scope._root._presence?.bind(scope, binding, read ?? (() => props), namespace);
|
|
51
|
-
}
|
|
52
|
-
if (previousStyle !== void 0) binding.update(values, previousStyle);
|
|
53
|
-
else binding.update(values);
|
|
54
|
-
}
|
|
55
|
-
for (const [namespace, binding] of bindings) if (!groups.has(namespace)) {
|
|
56
|
-
bindings.delete(namespace);
|
|
57
|
-
scope._root._presence?.unbind(binding);
|
|
58
|
-
binding.dispose();
|
|
59
|
-
}
|
|
60
|
-
return native;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export { capabilityProps as n, validateCapabilities as r, capabilityNamespace as t };
|
|
64
|
-
|
|
65
|
-
//# sourceMappingURL=capabilities-nOIitQ-_.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities-nOIitQ-_.js","names":[],"sources":["../../src/capabilities.ts"],"sourcesContent":["import type { Cleanup, Root, Scope } from \"./core.ts\"\nimport type { ExitHandle, PresenceCoordinator } from \"./presence.ts\"\n\n/** Native renderers expose property access without importing capability engines. */\nexport interface CapabilityTarget {\n\tkind: string\n\tnode: unknown\n\tsuspend?(): Cleanup\n\tread?(key: string): unknown\n\twrite?(key: string, value: unknown): void\n\tlisten?(event: string, listener: () => void): Cleanup\n}\nexport interface CapabilityBinding {\n\texit?(props: Record<string, unknown>): ExitHandle | undefined\n\tresume?(): void\n\t/** Inline CSS before native style replacement, for restoring capability-owned values. */\n\tupdate(props: Record<string, unknown>, previousStyle?: string): void\n\tdispose(): void\n}\nexport interface Capability {\n\tnamespace: string\n\t/** Prepare a synchronous update batch and return its commit callback. */\n\tbeforeUpdate?(root: Root): Cleanup\n\tpresence?(root: Root): PresenceCoordinator\n\tscheduleFrame?(callback: (time: number) => void): Cleanup\n\t/** SPA supplies ownership for integrations that measure after mount or report async errors. */\n\tattach(target: CapabilityTarget, scope?: Scope): CapabilityBinding\n}\n\nexport function capabilityNamespace(key: string): string | undefined {\n\tconst colon = key.indexOf(`:`)\n\tif (colon < 0) return undefined\n\tconst namespace = key.slice(0, colon)\n\treturn /^(xml|xmlns|xlink)$/.test(namespace) ? undefined : namespace\n}\nexport function validateCapabilities(\n\tscope: Scope,\n\tprops: Record<string, unknown>,\n): void {\n\tfor (const key of Object.keys(props)) {\n\t\tconst namespace = capabilityNamespace(key)\n\t\tif (namespace && !scope._root._capabilities.has(namespace))\n\t\t\tthrow new Error(\n\t\t\t\t`spa: capability \"${namespace}\" is not registered for this root`,\n\t\t\t)\n\t}\n}\n\n/** Separate framework properties from native attributes and own their bindings. */\nexport function capabilityProps(\n\tscope: Scope,\n\ttarget: CapabilityTarget,\n\tread?: () => Record<string, any>,\n\tapplyNative?: (props: Record<string, any>) => string | undefined,\n): (props: Record<string, any>) => Record<string, any> {\n\tconst bindings = new Map<string, CapabilityBinding>()\n\n\tscope._root._presence?.target(scope, target)\n\tconst cleanup: Cleanup = () => {\n\t\tconst errors: unknown[] = []\n\t\tfor (const binding of [...bindings.values()].reverse()) {\n\t\t\ttry {\n\t\t\t\tbinding.dispose()\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error)\n\t\t\t}\n\t\t}\n\t\tbindings.clear()\n\t\tif (errors.length) throw new AggregateError(errors)\n\t}\n\tscope._cleanups.add(cleanup)\n\treturn (props) => {\n\t\tvalidateCapabilities(scope, props)\n\t\tconst native: Record<string, any> = {}\n\t\tconst groups = new Map<string, Record<string, unknown>>()\n\t\tfor (const key of Object.keys(props)) {\n\t\t\tconst namespace = capabilityNamespace(key)\n\t\t\tif (!namespace) {\n\t\t\t\tconst value = props[key]\n\t\t\t\tnative[key] =\n\t\t\t\t\tkey.startsWith(`on`) && typeof value === `function`\n\t\t\t\t\t\t? (scope._root._presence?.event(scope, value) ?? value)\n\t\t\t\t\t\t: value\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst group = groups.get(namespace) ?? {}\n\t\t\tgroup[key.slice(namespace.length + 1)] = props[key]\n\t\t\tgroups.set(namespace, group)\n\t\t}\n\t\tconst previousStyle = applyNative?.(native)\n\t\tfor (const [namespace, values] of groups) {\n\t\t\tlet binding = bindings.get(namespace)\n\t\t\tif (!binding) {\n\t\t\t\tbinding = scope._root._capabilities.get(namespace)!.attach(target, scope)\n\t\t\t\tbindings.set(namespace, binding)\n\t\t\t\tscope._root._presence?.bind(\n\t\t\t\t\tscope,\n\t\t\t\t\tbinding,\n\t\t\t\t\tread ?? (() => props),\n\t\t\t\t\tnamespace,\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (previousStyle !== undefined) binding.update(values, previousStyle)\n\t\t\telse binding.update(values)\n\t\t}\n\t\tfor (const [namespace, binding] of bindings)\n\t\t\tif (!groups.has(namespace)) {\n\t\t\t\tbindings.delete(namespace)\n\t\t\t\tscope._root._presence?.unbind(binding)\n\t\t\t\tbinding.dispose()\n\t\t\t}\n\t\treturn native\n\t}\n}\n"],"mappings":";AA6BA,SAAgB,oBAAoB,KAAiC;CACpE,MAAM,QAAQ,IAAI,QAAQ,GAAG;CAC7B,IAAI,QAAQ,GAAG,OAAO,KAAA;CACtB,MAAM,YAAY,IAAI,MAAM,GAAG,KAAK;CACpC,OAAO,sBAAsB,KAAK,SAAS,IAAI,KAAA,IAAY;AAC5D;AACA,SAAgB,qBACf,OACA,OACO;CACP,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACrC,MAAM,YAAY,oBAAoB,GAAG;EACzC,IAAI,aAAa,CAAC,MAAM,MAAM,cAAc,IAAI,SAAS,GACxD,MAAM,IAAI,MACT,oBAAoB,UAAU,kCAC/B;CACF;AACD;;AAGA,SAAgB,gBACf,OACA,QACA,MACA,aACsD;CACtD,MAAM,2BAAW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