@vectojs/core 1.20.0 → 1.21.0

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/dist/renderer.mjs CHANGED
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  CanvasRenderer,
3
+ GlyphRasterAtlas,
3
4
  SVGRenderer,
4
5
  TextRasterCache,
5
6
  WebGPUParticleSystemManager,
6
7
  createWebGLPointRenderer,
7
8
  parseColorToRGBA
8
- } from "./chunk-QS3CUV7H.mjs";
9
+ } from "./chunk-RTENOAYT.mjs";
9
10
  export {
10
11
  CanvasRenderer,
12
+ GlyphRasterAtlas,
11
13
  SVGRenderer,
12
14
  TextRasterCache,
13
15
  WebGPUParticleSystemManager,
package/dist/text.js CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkYLH7F4ZVjs = require('./chunk-YLH7F4ZV.js');
5
+ var _chunkAGP4VLF4js = require('./chunk-AGP4VLF4.js');
6
6
 
7
7
  // src/text/index.ts
8
8
  var _text = require('@vectojs/text'); _createStarExport(_text);
9
9
 
10
10
 
11
11
 
12
- exports.MSDFTextEntity = _chunkYLH7F4ZVjs.MSDFTextEntity; exports.SVGEntity = _chunkYLH7F4ZVjs.SVGEntity;
12
+ exports.MSDFTextEntity = _chunkAGP4VLF4js.MSDFTextEntity; exports.SVGEntity = _chunkAGP4VLF4js.SVGEntity;
package/dist/text.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MSDFTextEntity,
3
3
  SVGEntity
4
- } from "./chunk-TJCXB2F6.mjs";
4
+ } from "./chunk-FRMLD4PP.mjs";
5
5
 
6
6
  // src/text/index.ts
7
7
  export * from "@vectojs/text";
@@ -159,6 +159,105 @@ export interface TextInputStyle {
159
159
  * to create and label the shadow DOM node (e.g. a real `<button>` or `<a href>`)
160
160
  * so the canvas stays accessible and clickable by automation/agents.
161
161
  */
162
+ /**
163
+ * One value in a {@link DevtoolsDescriptor} group.
164
+ *
165
+ * JSON-safe by construction: DevTools serializes descriptors to render a panel,
166
+ * to write a snapshot, and to cross a `postMessage` bridge, so a value that
167
+ * cannot survive `structuredClone` is a bug rather than a limitation.
168
+ */
169
+ export interface DevtoolsField {
170
+ /** Field name as shown in the inspector, e.g. `'scrollTop'`. */
171
+ label: string;
172
+ /** Current value. Keep to primitives, or short arrays/records of primitives. */
173
+ value: string | number | boolean | null | ReadonlyArray<string | number> | Record<string, string | number | boolean>;
174
+ /**
175
+ * Optional one-line explanation, shown as a tooltip.
176
+ *
177
+ * Worth spending: a reader looking at `visibleRange: [12, 34]` cannot tell
178
+ * whether the bounds are inclusive without being told.
179
+ */
180
+ hint?: string;
181
+ /**
182
+ * Mark a value that reflects derived or externally-owned state, so the panel
183
+ * can show it as read-only rather than inviting an edit that will be silently
184
+ * reverted. A `Stack`-laid-out child's `x` is the canonical example.
185
+ */
186
+ readOnly?: boolean;
187
+ }
188
+ /**
189
+ * A component's self-description for DevTools.
190
+ *
191
+ * Without this, the inspector can only show generic `Entity` properties —
192
+ * position, size, opacity — so everything that makes a component a component is
193
+ * invisible: `Input.value`, `Slider.min`/`max`, `ScrollView.scrollTop`,
194
+ * `VirtualList.visibleRange`, a `Markdown` block's token counts. The alternative
195
+ * is DevTools carrying a table of component types, which inverts the dependency
196
+ * (a debug tool would gate every new component) and breaks under minified builds
197
+ * where `constructor.name` is unreliable.
198
+ *
199
+ * Implement {@link Entity.getDevtoolsDescriptor} to opt in. Cost is paid only
200
+ * when a panel actually inspects the entity, so a descriptor may compute values
201
+ * it would not compute per frame.
202
+ *
203
+ * @example
204
+ * ```ts
205
+ * public override getDevtoolsDescriptor(): DevtoolsDescriptor {
206
+ * return {
207
+ * kind: 'ScrollView',
208
+ * groups: [{
209
+ * label: 'Scroll',
210
+ * fields: [
211
+ * { label: 'scrollTop', value: this.scrollTop },
212
+ * { label: 'contentHeight', value: this.contentHeight, readOnly: true },
213
+ * ],
214
+ * }],
215
+ * };
216
+ * }
217
+ * ```
218
+ */
219
+ export interface DevtoolsDescriptor {
220
+ /**
221
+ * Component kind for display, e.g. `'VirtualList'`.
222
+ *
223
+ * Provided explicitly rather than read from `constructor.name`, which minifies
224
+ * to something meaningless in a production bundle.
225
+ */
226
+ kind: string;
227
+ /** Grouped fields, rendered as sections in the order given. */
228
+ groups: ReadonlyArray<{
229
+ label: string;
230
+ fields: ReadonlyArray<DevtoolsField>;
231
+ }>;
232
+ /**
233
+ * Free-form notes: a caveat, a known-slow path, a link to a doc section.
234
+ * Rendered under the groups.
235
+ */
236
+ notes?: ReadonlyArray<string>;
237
+ /**
238
+ * Stable identity for snapshot diffing, independent of tree position.
239
+ *
240
+ * Snapshot paths are structural indices (`root > Card[0] > Text[2]`), so
241
+ * inserting at the head of a list renames every sibling and cascades into a
242
+ * large diff. A key that survives reordering — a row id, a message id — keeps
243
+ * the diff proportional to what actually changed. Most relevant to
244
+ * `VirtualList` and `Table`, where recycling moves entities constantly.
245
+ */
246
+ devtoolsKey?: string;
247
+ }
248
+ /**
249
+ * Entity properties a parent computes for its children.
250
+ *
251
+ * Editing one of these on a child is silently reverted by the next layout pass,
252
+ * which looks like the editor being broken rather than the value being owned
253
+ * elsewhere. A container declares what it controls so a tool can say so up front
254
+ * instead of letting a user discover it by watching their change disappear.
255
+ *
256
+ * Declared by the parent rather than detected by the tool: only the container
257
+ * knows whether it writes `x` unconditionally, and a table of container types
258
+ * inside DevTools would gate every new layout component on a debug-tool change.
259
+ */
260
+ export type LayoutControlledProperty = 'x' | 'y' | 'width' | 'height' | 'scaleX' | 'scaleY' | 'rotation' | 'opacity';
162
261
  export interface A11yAttributes {
163
262
  /** Shadow element tag to create. Defaults to `'div'`. */
164
263
  tag?: 'div' | 'a' | 'button' | 'img' | 'input' | 'textarea';
@@ -726,6 +825,33 @@ export declare abstract class Entity {
726
825
  *
727
826
  * @returns The {@link A11yAttributes} for this entity's shadow node.
728
827
  */
828
+ /**
829
+ * Describe this entity's own debug surface for DevTools.
830
+ *
831
+ * Returns `null` by default, meaning "nothing beyond the generic `Entity`
832
+ * fields the inspector already shows". Override in a component to expose the
833
+ * state that makes it inspectable — see {@link DevtoolsDescriptor}.
834
+ *
835
+ * Called only while a panel is inspecting this entity, never per frame, so it
836
+ * may compute values that would be too expensive to track continuously.
837
+ *
838
+ * @returns A descriptor, or `null` to opt out.
839
+ */
840
+ getDevtoolsDescriptor(): DevtoolsDescriptor | null;
841
+ /**
842
+ * Which of a child's properties this entity computes during layout.
843
+ *
844
+ * Returns an empty array by default, meaning "this entity does not position its
845
+ * children". A container that lays out children — `Stack`, `Table`, `Tabs` —
846
+ * overrides it so tooling can mark those values as parent-owned: editing `x` on
847
+ * a `Stack` child is reverted by the next layout, and knowing that in advance is
848
+ * the difference between a confusing tool and a correct one.
849
+ *
850
+ * @param child - The child being asked about. Containers whose control depends
851
+ * on the child (a `Table` cell versus its header) can answer per child.
852
+ * @returns Property names this entity overwrites on that child.
853
+ */
854
+ getLayoutControlledProperties(child: Entity): ReadonlyArray<LayoutControlledProperty>;
729
855
  getA11yAttributes(): A11yAttributes;
730
856
  /**
731
857
  * Local-space axis-aligned bounding box of what this entity's {@link render}
@@ -25,7 +25,41 @@ import { type ParticleModuleSource, type ParticleBackend } from '../wasm/particl
25
25
  * `a11ySync` and `a11yOrder` run after `render` in the frame loop, so they are
26
26
  * siblings of it, not children.
27
27
  */
28
- export type RenderPhase = 'render' | 'transform' | 'drawWalk' | 'flush' | 'a11ySync' | 'a11yOrder'
28
+ export type RenderPhase = 'render' | 'transform' | 'drawWalk' | 'flush' | 'a11ySync'
29
+ /**
30
+ * Time inside {@link Scene.syncContentGridProjection} materializing DOM
31
+ * carriers, nested inside `a11ySync`.
32
+ *
33
+ * Split out because `a11ySync` for a streaming code block measured 1661-1875 ms
34
+ * against a 210-671 ms render, and attributing that to grid materialization was
35
+ * an assumption. Nothing should be optimised here on the strength of the parent
36
+ * phase alone.
37
+ */
38
+ | 'gridMaterialize'
39
+ /**
40
+ * Whole of {@link Scene.syncContentProjection}, nested inside `a11ySync`.
41
+ *
42
+ * Measured at 99.8-99.9% of `a11ySync` for a streaming code block, so per-node
43
+ * a11y attribute and geometry work is not where that phase's cost lives.
44
+ */
45
+ | 'contentProjection'
46
+ /** Per-node a11y attribute/geometry work, excluding content projection and descendants. */
47
+ | 'a11yNodes'
48
+ /** Whole of `syncContentGridProjection`, of which `gridMaterialize` is one part. */
49
+ | 'gridSync'
50
+ /**
51
+ * Synchronous part of `scheduleContentGridCalibration` — building the probe DOM.
52
+ *
53
+ * The measurement itself is deferred to a rAF, but the probe is constructed
54
+ * here. Measured at 77-80% of `gridSync` on Chrome (3.7-4.5 ms per frame, i.e.
55
+ * the entire 240Hz budget) against about 1 ms on Firefox, making it the largest
56
+ * remaining cost of projecting a streaming code block once carrier reuse landed.
57
+ */
58
+ | 'gridCalibrateSchedule'
59
+ /** The `querySelectorAll` + per-cell scan inside calibration scheduling. */
60
+ | 'calibScan'
61
+ /** Probe DOM construction and insertion inside calibration scheduling. */
62
+ | 'calibProbeBuild' | 'a11yOrder'
29
63
  /** Sum of every entity's own render(), nested inside drawWalk. */
30
64
  | 'entityPaint';
31
65
  export interface RenderPhaseEntry {
@@ -358,6 +392,29 @@ export declare class Scene {
358
392
  private contentGridCalibrationFrames;
359
393
  /** Detached, untransformed font probes used by the cold calibration pass. */
360
394
  private contentGridCalibrationProbes;
395
+ /**
396
+ * Monotonic stamp identifying the conditions grid cells were calibrated under.
397
+ *
398
+ * Calibration measures the difference between the advance the canvas grid assigns
399
+ * a cluster and the width the browser lays it out at, then writes a per-cell
400
+ * `scaleX`. That result stays valid until the font or the page scale changes, and
401
+ * it lives on the cell element — so a cell carrying this stamp needs no further
402
+ * work.
403
+ *
404
+ * The scan that feeds calibration was O(cells) on every revision bump: for a
405
+ * streaming code block it re-derived a measurement key for every cell in the
406
+ * block each frame in order to produce only ~20 distinct keys, costing about
407
+ * 2.5 ms/frame after the `style.font` fix and still over half of `a11ySync`. Since
408
+ * carrier reuse (#244) leaves untouched lines — and therefore their calibrated
409
+ * transforms — in place, cells stamped with the current generation can simply be
410
+ * skipped, making the scan O(new cells) instead.
411
+ *
412
+ * A plain incrementing integer rather than the descriptive calibration key,
413
+ * because it goes into an attribute selector and must not need escaping.
414
+ */
415
+ private contentGridCalibrationGeneration;
416
+ /** The `(fontEpoch, pageScale)` pair the current generation corresponds to. */
417
+ private contentGridCalibrationStamp;
361
418
  /** Invalidates grid font calibration after browser font availability changes. */
362
419
  private contentFontEpoch;
363
420
  /** Cached Canvas-to-client scale for the current font/viewport epoch. */
@@ -800,6 +857,15 @@ export declare class Scene {
800
857
  */
801
858
  private setupGLContextRecovery;
802
859
  private endContentSelectionDrag;
860
+ /**
861
+ * Index of the carrier line currently holding a selection inside `el`, or
862
+ * `null`.
863
+ *
864
+ * Lets a partial re-materialization decide whether the user's selection is even
865
+ * affected. Checks the tracked anchor first (it survives a drag) and falls back
866
+ * to the live DOM selection.
867
+ */
868
+ private contentGridSelectionLine;
803
869
  private releaseContentSelectionForRebuild;
804
870
  /**
805
871
  * Rebuild a content-projection element's DOM (`rebuild`) while preserving a
@@ -836,6 +902,17 @@ export declare class Scene {
836
902
  * @example scene.add(new CircleEntity());
837
903
  */
838
904
  add(entity: Entity): this;
905
+ /**
906
+ * Reset per-grid calibration and bookkeeping before a (re)materialization.
907
+ *
908
+ * @param entityId - Owning entity, keyed into the calibration maps.
909
+ * @param el - The projection element.
910
+ * @param releaseSelection - Whether to drop a selection this element owns.
911
+ * Pass `false` when carrier lines are being reused: the selection's DOM nodes
912
+ * survive the pass, so tearing it down would wipe a user's selection on every
913
+ * streamed chunk — the exact bug `preserveContentSelectionAcrossRebuild`
914
+ * exists to prevent on the non-grid path.
915
+ */
839
916
  private clearContentGridState;
840
917
  /**
841
918
  * Drop any projected elements under `node` without touching the entity tree.
@@ -933,6 +1010,26 @@ export declare class Scene {
933
1010
  get rootEntity(): Entity;
934
1011
  /** The overlay layer root (see {@link showOverlay}), read-only for tooling. */
935
1012
  get overlayRootEntity(): Entity;
1013
+ /**
1014
+ * Advance and render exactly one frame, synchronously.
1015
+ *
1016
+ * This renders UNCONDITIONALLY: it consults neither {@link renderMode} nor
1017
+ * {@link dirty}, and it does not apply the `always`-mode idle auto-throttle.
1018
+ * That is deliberate — a deterministic driver (video export, a test, a
1019
+ * fixed-step benchmark) asks for a frame because it wants that frame, not a
1020
+ * scheduler opinion about whether it is needed.
1021
+ *
1022
+ * The consequence is a measurement footgun worth stating explicitly: a
1023
+ * benchmark that drives frames through `step()` CANNOT observe frame skipping,
1024
+ * so `always` and `onDemand` produce byte-identical draw counts through this
1025
+ * path. An investigation into whether `onDemand` skips redundant repaints once
1026
+ * concluded "it does not" on exactly that basis; on the real rAF loop the same
1027
+ * workload rendered ~1.0 frames per content change. To measure anything about
1028
+ * scheduling, use {@link start} and let `requestAnimationFrame` drive.
1029
+ *
1030
+ * @param dt Seconds to advance. Not clamped by `MAX_FRAME_DT` — the caller
1031
+ * chooses the step, since determinism is the point.
1032
+ */
936
1033
  step(dt: number): void;
937
1034
  /**
938
1035
  * Mark the scene as needing a redraw on the next frame.
@@ -941,6 +1038,22 @@ export declare class Scene {
941
1038
  * entity state outside of {@link Entity.animate} so the change is rendered.
942
1039
  */
943
1040
  markDirty(source?: DirtySource): void;
1041
+ /**
1042
+ * Increments whenever the tree's shape changes: add, remove or reparent.
1043
+ *
1044
+ * Already maintained for the resident WASM transform store (see
1045
+ * {@link markStructureChanged}, called from `Entity.add`/`remove`), and exposed
1046
+ * here because a cache of the tree's shape — a DevTools tree model, a serialized
1047
+ * snapshot — is valid exactly as long as this value is unchanged. Comparing it is
1048
+ * O(1) against re-walking the tree, which is what it replaces: DevTools rebuilt
1049
+ * both trees on a fixed 500 ms interval, a constant cost proportional to entity
1050
+ * count, purely because it had no way to ask whether the shape had changed.
1051
+ *
1052
+ * Property changes do NOT bump it. Moving or restyling an entity leaves the
1053
+ * shape intact, so a consumer that also cares about values must read those
1054
+ * directly rather than rebuilding a tree.
1055
+ */
1056
+ get structureVersion(): number;
944
1057
  /**
945
1058
  * Record who marked the scene dirty and why.
946
1059
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectojs/core",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },