@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/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
An experimental JSX framework whose state engine is atom.io. Components run once per mounted instance. Calls to accessors inside compiled JSX subscribe the affected DOM computations; atom.io updates those computations without rerunning component setup.
|
|
6
6
|
|
|
7
|
-
The npm package is named @atom.io/spa. Its browser runtime, Vite compiler, server renderer, and Astro integration are implemented here.
|
|
7
|
+
The npm package is named @atom.io/spa. Its browser runtime, Vite compiler, server renderer, and Astro integration are implemented here. State and general reactions belong to atom.io.
|
|
8
8
|
|
|
9
9
|
## Start with the Astro template
|
|
10
10
|
|
|
@@ -160,7 +160,44 @@ render(() => <Counter />, document.getElementById(`app`)!)
|
|
|
160
160
|
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
The development plugin keeps SPA and atom.io outside dependency prebundling so renderer entrypoints, component hooks, and stores share one runtime, including Astro adapter environments.
|
|
163
|
+
The development plugin keeps SPA and atom.io outside dependency prebundling so renderer entrypoints, component hooks, and stores share one runtime, including Astro adapter environments. Component-only JSX modules refresh affected roots against their existing atom.io stores; production builds omit hot registration. Components and render computations are synchronous. Modern browsers with ES2022 and DOM Range support are the target.
|
|
164
|
+
|
|
165
|
+
Hot updates rerun affected roots, including scene roots and independent Astro islands, with the same store and props source. Old scopes release subscriptions, listeners, refs, and onCleanup callbacks before replacement. Atoms, persistent family members, and timeline history remain; DOM-local values and component-owned family members disposed by cleanup reset. A failed hot setup displays an error while keeping its store available for the next edit.
|
|
166
|
+
|
|
167
|
+
Keep state definitions and Astro store factories in separate modules from component-only views. State declarations, mixed runtime exports, re-exports, changed export boundaries, and top-level side effects use full reloads. Type-only exports are allowed. The first implementation refreshes complete roots rather than replacing individual component instances.
|
|
168
|
+
|
|
169
|
+
Define persistent tokens in their own state module:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { atom } from "atom.io"
|
|
173
|
+
|
|
174
|
+
export const editCountAtom = atom<number>({ key: `editCount`, default: 0 })
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Import the token from a component-only view. Editing this view's JSX or handler preserves the counter value:
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
182
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
183
|
+
|
|
184
|
+
import { editCountAtom } from "./hmr-state.ts"
|
|
185
|
+
|
|
186
|
+
export function HotCounter(): SpaElement {
|
|
187
|
+
const getEditCount = useGetter(editCountAtom)
|
|
188
|
+
const setEditCount = useSetter(editCountAtom)
|
|
189
|
+
return (
|
|
190
|
+
<button
|
|
191
|
+
onClick={() => {
|
|
192
|
+
setEditCount((value) => value + 1)
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
{getEditCount()}
|
|
196
|
+
</button>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
```
|
|
164
201
|
|
|
165
202
|
## Hooks
|
|
166
203
|
|
|
@@ -168,17 +205,59 @@ The development plugin keeps SPA and atom.io outside dependency prebundling so r
|
|
|
168
205
|
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
169
206
|
| useLoadable(token, fallback?) | Return a tracked accessor for loading, last-observed values, and handled errors. |
|
|
170
207
|
| useGetter(token) | Return a live accessor for an atom or selector, bound to this instance's store. |
|
|
171
|
-
| useDisposal() | Return atom.io state disposal bound to the current
|
|
208
|
+
| useDisposal() | Return atom.io state disposal bound to the current store. |
|
|
172
209
|
| useSetter(token) | Return a stable atom.io writer. |
|
|
173
210
|
| useTimeline(token) | Return a stable object with getCursor/getLength readers, undo/redo/clear commands, and transaction-group controls. |
|
|
174
211
|
| useTransaction(token) | Bind an atom.io transaction, preserving its arguments and result. |
|
|
175
212
|
| useRef(token) | Return an attachment callback for a nullable element atom. Clear it only while this attachment still owns the reference. |
|
|
176
|
-
| useId() | Allocate an instance-stable ID using the root's
|
|
213
|
+
| useId() | Allocate an instance-stable ID using the current prefix and the root's shared sequence. |
|
|
177
214
|
| onCleanup(callback) | Register synchronous teardown with the current owner. |
|
|
178
215
|
| onMount(callback) | Run once after attachment and ref publication; omitted during server rendering. |
|
|
179
|
-
|
|
|
216
|
+
| onCommit(read, apply) | Track a value and apply changes after renderer writes, within the same flush. |
|
|
217
|
+
| useStore() | Return the current atom.io store without creating a store or subscribing. |
|
|
218
|
+
|
|
219
|
+
Call setup helpers synchronously during component setup or owned mount callbacks. Capture their results for event handlers. Tokens are fixed for an instance. Change the component's key when it needs to bind a different token. Read data props through the props object in JSX or a tracked binding to get updates. Destructuring data props during setup takes a snapshot.
|
|
220
|
+
|
|
221
|
+
### onCommit
|
|
222
|
+
|
|
223
|
+
Use onCommit to measure a ref after the root finishes its DOM writes.
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
227
|
+
import { onCommit, useGetter, useSetter } from "@atom.io/spa"
|
|
228
|
+
import { atom } from "atom.io"
|
|
229
|
+
|
|
230
|
+
export const captionAtom = atom<string>({ key: `caption`, default: `Hello` })
|
|
231
|
+
export const captionHeightAtom = atom<number>({
|
|
232
|
+
key: `captionHeight`,
|
|
233
|
+
default: 0,
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
export function Caption(): SpaElement {
|
|
237
|
+
const getCaption = useGetter(captionAtom)
|
|
238
|
+
const setCaptionHeight = useSetter(captionHeightAtom)
|
|
239
|
+
let caption: HTMLParagraphElement | null = null
|
|
180
240
|
|
|
181
|
-
|
|
241
|
+
onCommit(getCaption, () => {
|
|
242
|
+
setCaptionHeight(caption!.getBoundingClientRect().height)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<p
|
|
247
|
+
ref={(element) => {
|
|
248
|
+
caption = element
|
|
249
|
+
}}
|
|
250
|
+
>
|
|
251
|
+
{getCaption()}
|
|
252
|
+
</p>
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Call onCommit during setup. Its read function tracks state and compares the result with the last applied value using Object.is. The untracked apply callback receives the value and the previous applied value, which is undefined on mount. It runs after ref publication, mount callbacks, controlled form restoration, and capability commits. A flush inside a controlled form handler defers apply until restoration can finish. Children run before parents, with sibling callbacks in setup order.
|
|
259
|
+
|
|
260
|
+
A cleanup returned by apply runs before the next apply and when the owner is disposed. State writes from apply drain in another round of the same flush. Development detects feedback loops and reports the callback's registration stack. Scene callbacks run after host updates. Server rendering skips both callbacks, and scopes retained for exit skip apply while absent.
|
|
182
261
|
|
|
183
262
|
useTimeline returns a TimelineControls object whose methods can be destructured during setup. getCursor and getLength read the current cursor position and recorded checkpoint count; calls inside JSX subscribe the computation, while calls during setup or in event handlers are untracked. undo, redo, and clear are stable commands. history.getTransaction() is a tracked reader that returns an object with optional undo and redo callbacks for the adjacent transaction groups. At a cursor between transactions, both callbacks may be present and target different groups. A missing callback means no transaction group is available in that direction; the reader returns an empty object when neither is available. Calling a returned callback travels its captured group across participating timelines where it remains at the relevant history head, leaving diverged timelines unchanged. Use history.getTransaction().undo?.() or history.getTransaction().redo?.() to retrieve and invoke the current action together.
|
|
184
263
|
|
|
@@ -229,15 +308,25 @@ export function TimelineExample(): SpaElement {
|
|
|
229
308
|
|
|
230
309
|
```
|
|
231
310
|
|
|
232
|
-
Arrays support keyed components and elements. Reordering preserves instances and nodes; removed ranges release subscriptions, events, refs, and cleanup callbacks. Application keys must be unique among siblings. Explicit keys are compared as strings; unkeyed positions occupy a separate namespace. Unkeyed arrays use positions. A key identifies a row in a reactive child collection; it is not an independent reactive binding.
|
|
233
|
-
|
|
234
311
|
HTML and SVG use native DOM properties and attributes, plus className/htmlFor aliases. Events use onClick/onInput-style names, with Capture suffixes and onDoubleClick support. Styles are CSS strings. Mutable atom values still invalidate their consumers; project primitive fields for precise DOM writes. Refs attach once per element instance.
|
|
235
312
|
|
|
236
313
|
HTML and SVG tags have element-specific attribute, event, and ref types. Event handlers receive native events with currentTarget typed as the attached element; target remains EventTarget because events can bubble from descendants. Ref callbacks receive the element on attachment and null on cleanup. Hyphenated custom tags use generic HTML attributes and HTMLElement refs and event targets. SVG presentation attributes use their literal markup spellings. Shared HTML/SVG tag names use HTML types because JSX cannot infer a namespace from parent elements.
|
|
237
314
|
|
|
315
|
+
Non-null value and checked props control form state: rejected edits are restored after native handlers run, and select values are reapplied after option updates. Use defaultValue/defaultChecked for uncontrolled fields. onChange follows native input events for text, number, range inputs and textareas; selects, checkboxes, radios, and file inputs use native change events. Handlers still receive native events. onFocus/onBlur bubble through focusin/focusout, including Capture variants; explicit onFocusIn/onFocusOut names remain available. autoFocus focuses newly mounted elements. Null or undefined reflected attributes are removed.
|
|
316
|
+
|
|
317
|
+
## Component identity
|
|
318
|
+
|
|
319
|
+
Keys accept the same Canonical values as atom.io families, including nested tuples, booleans, and null. Sibling keys must be unique by canonical serialization. A fresh tuple with the same contents preserves the instance, and a number and its string representation identify separate instances. Only undefined uses positional identity. Reordering preserves keyed instances and nodes. Changing a key replaces the instance in both DOM and scene trees, including when the element stands alone.
|
|
320
|
+
|
|
321
|
+
Freezing both a JSX element object and its props opts into reuse in DOM collections without refreshing unchanged descendant props. Its tracked getters remain reactive. Create a new JSX element object when replacing frozen props; the key still preserves the mounted instance. Mutable descriptors continue to refresh when their collection updates.
|
|
322
|
+
|
|
323
|
+
A component can declare a required, narrowed key in its props. The instance receives the original key by reference and can read props.key during setup, rendering, mount, and cleanup. Spreading the props forwards the key to an inner component or element. A spread follows normal JSX precedence, so forwarding the same key to multiple siblings reports a duplicate key.
|
|
324
|
+
|
|
325
|
+
Direct DOM component and root output opt into key tracking when they first mount. Include the key property initially when a direct spread needs later identity changes. An explicit key attribute or a spread containing key with an initial undefined value enables that tracking. Keyless spreads keep their data props live as the instance updates.
|
|
326
|
+
|
|
238
327
|
## Store access
|
|
239
328
|
|
|
240
|
-
useStore returns the
|
|
329
|
+
useStore returns the nearest Root boundary's atom.io store. When no boundary supplies one, it returns the store supplied to the renderer, the Astro island store, or the implicit atom.io store.
|
|
241
330
|
|
|
242
331
|
```tsx
|
|
243
332
|
import type { SpaElement } from "@atom.io/spa"
|
|
@@ -264,6 +353,53 @@ export function InspectCount(): SpaElement {
|
|
|
264
353
|
|
|
265
354
|
For family-member disposal, useDisposal() captures this store and returns a bound disposal command; see [ambient UI state](#ambient-ui-state-and-ownership). Capture the store during component setup or an owned onMount callback, then pass it to other store-aware atom.io operations or integrations. Getting the store creates no subscription. Direct reads such as getFromStore do not participate in SPA's dependency tracking; useGetter and useLoadable provide tracked reads. The returned object is a store, not a Silo or a new wrapper.
|
|
266
355
|
|
|
356
|
+
### Subtree root options
|
|
357
|
+
|
|
358
|
+
Render a Root boundary around each editor to give it a separate store with the document token installed in both stores.
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
362
|
+
import { Root, useGetter, useSetter } from "@atom.io/spa"
|
|
363
|
+
import { atom } from "atom.io"
|
|
364
|
+
import type { RootStore } from "atom.io/internal"
|
|
365
|
+
|
|
366
|
+
export const textAtom = atom<string>({ key: `text`, default: `` })
|
|
367
|
+
|
|
368
|
+
function Editor() {
|
|
369
|
+
const getText = useGetter(textAtom)
|
|
370
|
+
const setText = useSetter(textAtom)
|
|
371
|
+
return (
|
|
372
|
+
<textarea
|
|
373
|
+
value={getText()}
|
|
374
|
+
onInput={(event) => {
|
|
375
|
+
setText(event.currentTarget.value)
|
|
376
|
+
}}
|
|
377
|
+
/>
|
|
378
|
+
)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function Documents(props: {
|
|
382
|
+
left: RootStore
|
|
383
|
+
right: RootStore
|
|
384
|
+
}): SpaElement {
|
|
385
|
+
return (
|
|
386
|
+
<>
|
|
387
|
+
<Root store={props.left}>
|
|
388
|
+
<Editor />
|
|
389
|
+
</Root>
|
|
390
|
+
<Root store={props.right}>
|
|
391
|
+
<Editor />
|
|
392
|
+
</Root>
|
|
393
|
+
</>
|
|
394
|
+
)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Root shares its parent's scheduler and uses normal child markers and adds no DOM element. Components passed as children bind their hooks to the store where they mount. The boundary captures options at setup, so give it a new key to replace its store. Removing the boundary releases owned subscriptions and refs. The borrowed store remains available.
|
|
400
|
+
|
|
401
|
+
Omitted options inherit from the parent. An idPrefix override uses the root's shared ID sequence. A capabilities list replaces the inherited list within the subtree and shares the root's update and presence coordination. An onError override receives asynchronous errors from the subtree under the usual root failure policy. Scene mounts inherit these options. For SSR and hydration, supply equivalent boundary options and store state on both sides.
|
|
402
|
+
|
|
267
403
|
## Families
|
|
268
404
|
|
|
269
405
|
useGetter, useSetter, useRef, and useTimeline accept a family token followed by its key. useLoadable accepts a family, key, and optional fallback. Keys retain their declared types, including tuples, numbers, booleans, and null. Members resolve in the component's store, so isolated roots can use the same family tokens independently.
|
|
@@ -283,11 +419,11 @@ const historyTimelines = timelineFamily<string>({
|
|
|
283
419
|
scope: [scopeFamily(countAtoms, { timelineKey: (id) => id })],
|
|
284
420
|
})
|
|
285
421
|
|
|
286
|
-
|
|
287
|
-
const getCount = useGetter(countAtoms, props.
|
|
288
|
-
const setCount = useSetter(countAtoms, props.
|
|
289
|
-
const ref = useRef(buttonAtoms, props.
|
|
290
|
-
const history = useTimeline(historyTimelines, props.
|
|
422
|
+
function FamilyCounter(props: { key: string }): SpaElement {
|
|
423
|
+
const getCount = useGetter(countAtoms, props.key)
|
|
424
|
+
const setCount = useSetter(countAtoms, props.key)
|
|
425
|
+
const ref = useRef(buttonAtoms, props.key)
|
|
426
|
+
const history = useTimeline(historyTimelines, props.key)
|
|
291
427
|
return (
|
|
292
428
|
<section>
|
|
293
429
|
<button
|
|
@@ -305,9 +441,19 @@ export function FamilyCounter(props: { id: string }): SpaElement {
|
|
|
305
441
|
)
|
|
306
442
|
}
|
|
307
443
|
|
|
444
|
+
export function Counters(props: { ids: readonly string[] }): SpaElement {
|
|
445
|
+
return (
|
|
446
|
+
<section>
|
|
447
|
+
{props.ids.map((id) => (
|
|
448
|
+
<FamilyCounter key={id} />
|
|
449
|
+
))}
|
|
450
|
+
</section>
|
|
451
|
+
)
|
|
452
|
+
}
|
|
453
|
+
|
|
308
454
|
```
|
|
309
455
|
|
|
310
|
-
|
|
456
|
+
Use props.key as the family key to keep the binding and the component's identity in sync. When the key changes, the new instance binds to the new member during setup. A tuple can include a family key alongside a discriminator when the same member appears more than once among siblings. Ref ownership and subscription cleanup follow the member just as they do for individual tokens. useTransaction takes an individual transaction token.
|
|
311
457
|
|
|
312
458
|
### Ambient UI state and ownership
|
|
313
459
|
|
|
@@ -480,7 +626,7 @@ The production build omits development-only diagnostics and invalid-input checks
|
|
|
480
626
|
|
|
481
627
|
## Astro state and data
|
|
482
628
|
|
|
483
|
-
The integration compiles .tsx and .jsx files by default. Use the include option to limit compilation to SPA component directories when another JSX renderer is present. Top-level functions containing JSX are branded by the compiler for renderer detection.
|
|
629
|
+
The integration compiles .tsx and .jsx files by default. Use the include option to limit compilation to SPA component directories when another JSX renderer is present. Top-level functions containing JSX are branded by the compiler for renderer detection. Lazy JSX attributes preserve this from their enclosing function, including through nested arrows and receiver tags. Nested normal functions and methods retain their own receiver. Direct await and yield expressions in lazy attributes are compile errors naming the attribute; nested async and generator functions remain supported.
|
|
484
630
|
|
|
485
631
|
Default islands share the normal implicit atom.io store in the browser. Module-scoped tokens, SPA hooks, and ordinary getState/setState calls all address the same graph. SSR shares a separate store within each request; concurrent requests never share values. Definitions imported after an earlier island started are installed into that request's store before the next island prepares. Server reads and writes must use the selected store (through SPA hooks or store-aware atom.io operations); free getState/setState calls still target the process-global implicit store.
|
|
486
632
|
|
|
@@ -546,7 +692,7 @@ The checked Astro fixture demonstrates default/named slots and custom independen
|
|
|
546
692
|
|
|
547
693
|
The build audits every browser export, including the JSX runtime, from the built JavaScript. Atom.io is an external peer in the incremental measurement. Compiler, server, and integration code have separate entrypoints. The report also includes the complete client plus atom.io, the Astro client entrypoint, and the installed Preact version under the same bundling/minification settings. These are full exported surfaces, not equivalent application benchmarks.
|
|
548
694
|
|
|
549
|
-
The hard budget is under
|
|
695
|
+
The hard budget is under 6,250 bytes of ordinary level-9 gzip for the complete client export surface, including hydration recovery and its production diagnostics. Tsdown builds the package JavaScript and declarations, with separate production and development outputs that each share their runtime across entrypoints. The size audit then bundles the built exports with esbuild, minifies with Oxc, and measures compression using Node's gzip and Brotli implementations. The complete client export surface measures approximately 6.2 kB with gzip. The exact measurements appear in dist/size.json. Actual application bundles add atom.io and compiler-generated application code.
|
|
550
696
|
|
|
551
697
|
Build output includes the minified audit entrypoint and machine-readable dist/size.json. These audit files are a bundled measurement; use the package exports in applications so the bundler preserves one runtime instance across entrypoints. Source tests exercise development behavior; the production test executes the audited minified artifact. Chromium checks exercise the actual Astro build, island isolation, hydration, keyed identity, focus/selection, SVG namespaces, and teardown. A fresh-cache Astro development check also covers mount hooks, shared state, and ClientRouter navigation.
|
|
552
698
|
|
|
@@ -578,11 +724,11 @@ Sizes are exact minified and level-9 gzip JavaScript byte counts. Declarations,
|
|
|
578
724
|
|
|
579
725
|
| Recipe | Entry | Minified JS | Gzip JS |
|
|
580
726
|
| -------------------------------- | --------------------------------- | ----------: | -------: |
|
|
581
|
-
| Family app with refs and history | `tonnage-recipes/family-app.ts` |
|
|
582
|
-
| Async interactive client app | `tonnage-recipes/async-app.ts` |
|
|
583
|
-
| Interactive client app | `tonnage-recipes/client-app.ts` |
|
|
584
|
-
| Hydrated interactive app | `tonnage-recipes/hydrated-app.ts` |
|
|
585
|
-
| Interactive Astro island | `tonnage-recipes/astro-island.ts` |
|
|
727
|
+
| Family app with refs and history | `tonnage-recipes/family-app.ts` | 68,896 B | 20,908 B |
|
|
728
|
+
| Async interactive client app | `tonnage-recipes/async-app.ts` | 47,332 B | 15,151 B |
|
|
729
|
+
| Interactive client app | `tonnage-recipes/client-app.ts` | 47,004 B | 15,001 B |
|
|
730
|
+
| Hydrated interactive app | `tonnage-recipes/hydrated-app.ts` | 47,005 B | 14,999 B |
|
|
731
|
+
| Interactive Astro island | `tonnage-recipes/astro-island.ts` | 53,544 B | 17,059 B |
|
|
586
732
|
|
|
587
733
|
Report maintained with [tonnage](https://github.com/jeremybanka/tonnage).
|
|
588
734
|
|
|
@@ -596,7 +742,7 @@ SPA includes Konva, Three.js, and Motion integrations behind separate entrypoint
|
|
|
596
742
|
|
|
597
743
|
### Konva
|
|
598
744
|
|
|
599
|
-
Import Stage, Layer, Group, Rect, Circle, Ellipse, Line, Text, Image, Path, Star, and Transformer from @atom.io/spa/konva. Stage renders a DOM container and creates its native stage after browser mounting. Compiled atom reads update native attributes; keyed children preserve node identity. Native configuration attributes and
|
|
745
|
+
Import Stage, Layer, Group, Rect, Circle, Ellipse, Line, Text, Image, Path, Star, and Transformer from @atom.io/spa/konva. Stage renders a DOM container and creates its native stage after browser mounting. Compiled atom reads update native attributes; keyed children preserve node identity. Native configuration attributes and mouse, pointer, touch, wheel, context-menu, drag, and transform handlers are supported with typed native Konva events and node-specific currentTarget values. Use onDblClick/onDblTap for double clicks/taps. Both onGotPointerCapture and onLostPointerCapture expose PointerEvent values. onTransformEnd may receive an undefined evt when stopTransform() ends a transform programmatically; check evt before reading native event fields. Handler names and configuration fields are checked for misspellings. Refs receive native nodes and null on cleanup. Removal destroys owned nodes and listeners.
|
|
600
746
|
|
|
601
747
|
```tsx
|
|
602
748
|
import type { SpaElement } from "@atom.io/spa"
|
|
@@ -635,7 +781,7 @@ Konva owns hit testing, dragging, and draw batching. Write drag results back int
|
|
|
635
781
|
|
|
636
782
|
### Three.js
|
|
637
783
|
|
|
638
|
-
Import Canvas, Group, Mesh, PerspectiveCamera, AmbientLight, DirectionalLight, BoxGeometry, SphereGeometry, PlaneGeometry, MeshStandardMaterial, MeshBasicMaterial, and
|
|
784
|
+
Import Canvas, Group, Mesh, PerspectiveCamera, AmbientLight, DirectionalLight, PointLight, BoxGeometry, SphereGeometry, PlaneGeometry, MeshStandardMaterial, MeshBasicMaterial, MeshNormalMaterial, LineSegments, BufferGeometry, and LineBasicMaterial from @atom.io/spa/three. Canvas creates a WebGL renderer after browser mounting. Geometry and material children attach to their Mesh or LineSegments, with one of each supported. Position and rotation accept three-number tuples; scale also accepts a scalar. Point lights expose color, intensity, distance and decay.
|
|
639
785
|
|
|
640
786
|
```tsx
|
|
641
787
|
import type { SpaElement } from "@atom.io/spa"
|
|
@@ -667,11 +813,11 @@ export function Scene(): SpaElement {
|
|
|
667
813
|
|
|
668
814
|
```
|
|
669
815
|
|
|
670
|
-
Mesh
|
|
816
|
+
Mesh and LineSegments accept optional constructor args typed from Three.js, including custom BufferGeometry and a Material or material array. Resources supplied in args are borrowed: their application owner disposes them after all consumers finish. JSX geometry/material children and implicit drawable defaults remain renderer-owned. Constructor args are fixed for the mounted instance; use a new reconciliation key to replace them.
|
|
671
817
|
|
|
672
|
-
Constructor args are fixed for an instance.
|
|
818
|
+
Constructor args are fixed for an instance. Change the resource's key to replace it with new constructor args. Refs expose native objects. Owned geometries and materials are disposed on removal; textures passed through material properties remain borrowed. Canvas stops drawing and disposes its renderer on removal. The exported threeRenderer renders into a borrowed parent dedicated to its children without creating a WebGL renderer.
|
|
673
819
|
|
|
674
|
-
Canvas accepts rendererOptions for constructor-time settings such as alpha and powerPreference, or createRenderer to construct the renderer with the supplied canvas. Both paths are exclusively owned by Canvas: it disposes the renderer on removal or setup failure, and the factory must return a renderer using that canvas. Shared/borrowed renderers are not supported by this boundary; use threeRenderer for a separately owned renderer. Options and the factory are captured at mount; replace the keyed Canvas to reconstruct its context.
|
|
820
|
+
Canvas accepts rendererOptions for constructor-time settings such as alpha and powerPreference, or createRenderer to construct the renderer with the supplied canvas. Both paths are exclusively owned by Canvas: it disposes the renderer on removal or setup failure, and the factory must return a renderer using that canvas. Shared/borrowed renderers are not supported by this boundary; use threeRenderer for a separately owned renderer. An optional onError callback handles renderer creation failures locally so an application can offer a fallback; later setup or frame errors still reach the owning error boundary. Options and the factory are captured at mount; replace the keyed Canvas to reconstruct its context.
|
|
675
821
|
|
|
676
822
|
Use onCreated to configure tone mapping, output color space, scene background, or controls after the scene mounts and sizes, before the first draw. Return a cleanup callback for controls or other acquired resources. Numeric dpr selects a fixed positive ratio; a min/max tuple clamps devicePixelRatio and follows window resize events. The default remains 1. Width and height remain reactive positive CSS-pixel dimensions. Canvas updates its default perspective camera projection; supplied cameras are borrowed and retain their own projection. Use onResize to update an external perspective/orthographic camera explicitly. onFrame and pointer routing always use the current camera prop, with one frame loop using the installed Motion clock or requestAnimationFrame.
|
|
677
823
|
|
|
@@ -703,7 +849,25 @@ export function BoardCanvas(): SpaElement {
|
|
|
703
849
|
|
|
704
850
|
```
|
|
705
851
|
|
|
706
|
-
Canvas defaults to a perspective camera at z = 5. Its optional camera prop borrows an external camera; a PerspectiveCamera child does not automatically become active. Width and height update the renderer and default camera. Canvas renders continuously and accepts an onFrame callback with scene, camera, renderer, delta seconds, and timestamp seconds. Controls
|
|
852
|
+
Canvas defaults to a perspective camera at z = 5. Its optional camera prop borrows an external camera; a PerspectiveCamera child does not automatically become active. Width and height update the renderer and default camera. Canvas renders continuously by default. A renderWhen predicate can skip idle GPU draws while frame callbacks and pointer updates continue; the caller makes it true when drawing is needed, and Canvas checks it before onFrame. Canvas accepts an onFrame callback with scene, camera, renderer, delta seconds, and timestamp seconds. Controls and asset loading remain application-owned.
|
|
853
|
+
|
|
854
|
+
### Shared brand mark
|
|
855
|
+
|
|
856
|
+
Import BrandMark from @atom.io/spa/brand and its stylesheet from @atom.io/spa/brand/css. The compact mark defaults to 22 CSS pixels; size sets its width and height. Use variant="splash" for the viewport backdrop used on atom.io.fyi. Both variants share the same orbital model and honor reduced motion. Three.js loads after browser mounting; server rendering, unavailable WebGL and failed graphics imports retain the static mark. Install the optional three peer to animate it. The base SPA entrypoint does not include branding or its stylesheet.
|
|
857
|
+
|
|
858
|
+
```tsx
|
|
859
|
+
import "@atom.io/spa/brand/css"
|
|
860
|
+
|
|
861
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
862
|
+
import { BrandMark } from "@atom.io/spa/brand"
|
|
863
|
+
|
|
864
|
+
export function AppBrand(): SpaElement {
|
|
865
|
+
return <BrandMark size={32} />
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
Contributor tools can import the canonical geometry, camera and lighting helpers from @atom.io/spa/brand/model without importing the component or CSS.
|
|
707
871
|
|
|
708
872
|
### Three.js pointer events
|
|
709
873
|
|
|
@@ -812,7 +976,7 @@ export function SpringCube(): SpaElement {
|
|
|
812
976
|
|
|
813
977
|
```
|
|
814
978
|
|
|
815
|
-
When the motion capability is installed, Canvas draws in Motion's render phase after animated scene values update. Without it, Canvas uses requestAnimationFrame. Both drawing subscriptions and animations end with their owners. The base runtime imports no motion engine or retention coordinator.
|
|
979
|
+
When the motion capability is installed, Canvas draws in Motion's post-render phase after animated scene values update. Without it, Canvas uses requestAnimationFrame. Both drawing subscriptions and animations end with their owners. The base runtime imports no motion engine or retention coordinator. The optional Motion entrypoint owns the retention machinery. The client budget includes controlled form restoration and native event normalization. The full client budget is 5,500 bytes.
|
|
816
980
|
|
|
817
981
|
### Exit animations and re-entry
|
|
818
982
|
|
|
@@ -944,7 +1108,7 @@ export function ReadinessBoard(): SpaElement {
|
|
|
944
1108
|
|
|
945
1109
|
motion:layout enables position and size projection; position or size restricts the animated dimensions. motion:layoutId enables layout animation implicitly and carries a visual identity between outgoing/incoming nodes, while reconciliation keys continue to own component instances. Shared identities are isolated by root and by an explicit motion:layoutGroup on each shared node; group is not inherited. Use distinct group values for separate boards in one root. Reusing an ID within a group coordinates a shared transition, with the latest mounted member leading.
|
|
946
1110
|
|
|
947
|
-
SPA snapshots registered targets before each synchronous update batch and projects after the DOM commits. Per-target ResizeObserver subscriptions also handle external size changes; no document-wide mutation observer or consumer measurement loop is needed. Mark scrolling layout ancestors with motion:layoutScroll. Nested projections preserve authored transforms and transform origins; Floating UI retains its independent translate positioning. Avoid multiple layout/projection owners or direct writes to a projected element's transform while the capability is active.
|
|
1111
|
+
SPA snapshots registered targets before each synchronous update batch and projects after the DOM commits. Per-target ResizeObserver subscriptions also handle external size changes; no document-wide mutation observer or consumer measurement loop is needed. Mark scrolling layout ancestors with motion:layoutScroll. Mark a movable window or fixed layout ancestor with motion:layoutRoot so it moves immediately while its descendants animate relative to it. Nested projections preserve authored transforms and transform origins; Floating UI retains its independent translate positioning. Avoid multiple layout/projection owners or direct writes to a projected element's transform while the capability is active.
|
|
948
1112
|
|
|
949
1113
|
The default transition is a 0.3-second tween; the capability option layoutTransition sets defaults and motion:layoutTransition replaces them for a target. Use finite duration/delay values or settling spring parameters. Retargeting uses the current projection. Outgoing nodes remain available for shared handoff until replacements mount in the same batch. With Motion exits, layout follows the retained node's lifetime; keyed re-entry resumes the existing instance. Shared identity transfers appearance, not component state or DOM ownership, and nodes are not automatically reparented.
|
|
950
1114
|
|