@vectojs/core 0.1.0 → 0.2.1
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/animation/drivers.d.ts +48 -0
- package/dist/animation/easing.d.ts +16 -0
- package/dist/{chunk-M2IZPGOL.mjs → chunk-H3QIE77O.mjs} +316 -12
- package/dist/{chunk-53DAQC3U.js → chunk-LA3FJLP2.js} +369 -65
- package/dist/components/GridTextEntity.d.ts +15 -0
- package/dist/components/SplineEntity.d.ts +144 -0
- package/dist/components/TextEntity.d.ts +35 -0
- package/dist/index.d.ts +26 -577
- package/dist/index.js +121 -136
- package/dist/index.mjs +19 -34
- package/dist/{layout.d.mts → layout/LayoutEngine.d.ts} +15 -70
- package/dist/layout/LayoutWorker.d.ts +23 -0
- package/dist/layout/LayoutWorkerManager.d.ts +22 -0
- package/dist/layout/LayoutWorkerSource.d.ts +1 -0
- package/dist/layout/index.d.ts +3 -0
- package/dist/layout/measure.d.ts +20 -0
- package/dist/math/SpatialHashGrid.d.ts +53 -0
- package/dist/math/SpringPhysics.d.ts +13 -0
- package/dist/renderer/CanvasRenderer.d.ts +81 -0
- package/dist/renderer/IRenderer.d.ts +178 -0
- package/dist/renderer/SVGRenderer.d.ts +69 -0
- package/dist/renderer/WebGLPointRenderer.d.ts +62 -0
- package/dist/renderer/WebGPUParticleSystemManager.d.ts +14 -0
- package/dist/renderer/colorParse.d.ts +17 -0
- package/dist/renderer/index.d.ts +6 -0
- package/dist/text/ArabicShaper.d.ts +10 -0
- package/dist/text/BidiResolver.d.ts +6 -0
- package/dist/{text.d.ts → text/MSDFFont.d.ts} +10 -82
- package/dist/text/MSDFTextEntity.d.ts +30 -0
- package/dist/text/SVGEntity.d.ts +22 -0
- package/dist/text/index.d.ts +5 -0
- package/dist/text.js +2 -2
- package/dist/text.mjs +1 -1
- package/dist/tree/ComputeParticleEntity.d.ts +118 -0
- package/dist/tree/DOMPortalEntity.d.ts +18 -0
- package/dist/{Entity-D-rfAFCf.d.mts → tree/Entity.d.ts} +71 -201
- package/dist/tree/Scene.d.ts +302 -0
- package/package.json +5 -5
- package/dist/Entity-D-rfAFCf.d.ts +0 -572
- package/dist/index-ByBDSmMK.d.mts +0 -365
- package/dist/index-C3Fd_XmG.d.ts +0 -365
- package/dist/index.d.mts +0 -577
- package/dist/layout.d.ts +0 -319
- package/dist/renderer.d.mts +0 -2
- package/dist/renderer.d.ts +0 -2
- package/dist/text.d.mts +0 -201
package/dist/index.d.mts
DELETED
|
@@ -1,577 +0,0 @@
|
|
|
1
|
-
import { E as Entity, I as IRenderer, B as Bounds } from './Entity-D-rfAFCf.mjs';
|
|
2
|
-
export { A as A11yAttributes, a as BatchCircle, b as BatchRect, L as ListenerOptions, P as Point, V as VectoEvent, c as VectoJSEvent } from './Entity-D-rfAFCf.mjs';
|
|
3
|
-
export { C as CanvasRenderer, a as ComputeParticleEntity, b as ComputeParticleOptions, P as PARTICLE_OFFSET_LIFE, c as PARTICLE_OFFSET_ORIGIN_X, d as PARTICLE_OFFSET_ORIGIN_Y, e as PARTICLE_OFFSET_POSITION_X, f as PARTICLE_OFFSET_POSITION_Y, g as PARTICLE_OFFSET_SIZE, h as PARTICLE_OFFSET_VELOCITY_X, i as PARTICLE_OFFSET_VELOCITY_Y, j as PARTICLE_STRIDE_FLOATS, k as PointRenderer, R as RGBA, S as SVGLinearGradient, l as SVGRenderer, W as WebGPUParticleSystemManager, m as createWebGLPointRenderer, p as parseColorToRGBA } from './index-ByBDSmMK.mjs';
|
|
4
|
-
export { ExclusionRect, GlyphAtlas, GlyphMeasurer, LayoutEngine, LayoutNode, LayoutResult, LayoutResultBuffer, LayoutWorkerManager, LineSegment, PreparedGlyph, PreparedParagraph, PreparedText, PreparedWord, StyledSpan, TextStyle, computeLineSegments, createCanvasMeasurer } from './layout.mjs';
|
|
5
|
-
export { ArabicShaper, BidiResolver, MSDFAtlasInfo, MSDFBounds, MSDFFont, MSDFFontData, MSDFGlyphDef, MSDFKerning, MSDFLayoutOptions, MSDFLayoutResult, MSDFMetrics, MSDFTextEntity, MSDFTextEntityOptions, PositionedGlyph, SVGEntity, ShapedResult } from './text.mjs';
|
|
6
|
-
|
|
7
|
-
interface IWebGLPointRenderer {
|
|
8
|
-
resize(width: number, height: number): void;
|
|
9
|
-
}
|
|
10
|
-
type WebGLPointRendererCreator = (canvas: HTMLCanvasElement) => any;
|
|
11
|
-
interface IWebGPUParticleSystemManager {
|
|
12
|
-
new (device: GPUDevice): any;
|
|
13
|
-
initPipelines(format: GPUTextureFormat): Promise<void> | void;
|
|
14
|
-
setupEntityResources(entity: any): void;
|
|
15
|
-
recordComputePass(pass: GPUComputePassEncoder, entity: any, dt: number, mouseX: number, mouseY: number, width: number, height: number): void;
|
|
16
|
-
recordRenderPass(renderPassEncoder: GPURenderPassEncoder, entity: any): void;
|
|
17
|
-
destroy(): void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Options for {@link Scene}.
|
|
22
|
-
*/
|
|
23
|
-
interface SceneOptions {
|
|
24
|
-
/**
|
|
25
|
-
* Backend for `getBatchCircle()` point-cloud entities:
|
|
26
|
-
* - `'canvas'` (default): the Canvas2D order-preserving same-color batch.
|
|
27
|
-
* - `'webgl'`: a stacked WebGL2 layer drawing all such circles in one draw
|
|
28
|
-
* call (10–100× throughput for 100k+). Auto-falls back to `'canvas'` when
|
|
29
|
-
* WebGL2 is unavailable. The GL layer composites above the 2D content, so its
|
|
30
|
-
* points don't interleave per-entity with 2D draws.
|
|
31
|
-
*/
|
|
32
|
-
pointBackend?: 'canvas' | 'webgl';
|
|
33
|
-
/**
|
|
34
|
-
* Backend for particle simulation and rendering:
|
|
35
|
-
* - `'auto'` (default): tries WebGPU first, falls back to CPU if WebGPU is unavailable or fails.
|
|
36
|
-
* - `'webgpu'`: forces WebGPU.
|
|
37
|
-
* - `'cpu'`: forces CPU simulation and rendering (disabling WebGPU completely).
|
|
38
|
-
*/
|
|
39
|
-
particleBackend?: 'auto' | 'webgpu' | 'cpu';
|
|
40
|
-
/**
|
|
41
|
-
* Render the accessibility/automation shadow nodes with a visible blue dashed
|
|
42
|
-
* outline (development aid). Default `false`: shadow nodes are transparent
|
|
43
|
-
* (`opacity:0`) — still operable by Playwright/assistive tech, but the canvas
|
|
44
|
-
* is the only thing seen.
|
|
45
|
-
*/
|
|
46
|
-
debugA11y?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Cap the render loop to at most this many frames per second (power saving —
|
|
49
|
-
* e.g. a quieter fan in a library). `0` (default) means uncapped (native
|
|
50
|
-
* refresh rate). Continuous animations still run, just less often. Also
|
|
51
|
-
* settable later via {@link Scene.maxFPS}.
|
|
52
|
-
*/
|
|
53
|
-
maxFPS?: number;
|
|
54
|
-
/**
|
|
55
|
-
* When `true` (default), a system **prefers-reduced-motion** setting auto-caps
|
|
56
|
-
* the loop to {@link REDUCED_MOTION_FPS} (or the lower of that and `maxFPS`).
|
|
57
|
-
* Set `false` to ignore the OS setting.
|
|
58
|
-
*/
|
|
59
|
-
respectReducedMotion?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Throttle the accessibility/automation shadow-DOM sync to at most once per this
|
|
62
|
-
* many milliseconds. `0` (default) syncs every rendered frame. During heavy
|
|
63
|
-
* animation, a small value (e.g. `100`) keeps the a11y layer eventually
|
|
64
|
-
* consistent while sparing the per-frame DOM writes that can drag Canvas FPS.
|
|
65
|
-
* Also settable later via {@link Scene.a11ySyncInterval}.
|
|
66
|
-
*/
|
|
67
|
-
a11ySyncInterval?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Custom renderer implementation (e.g., ThreeRenderer from @vectojs/three).
|
|
70
|
-
* If provided, this renderer will be used for drawing rather than the default CanvasRenderer.
|
|
71
|
-
*/
|
|
72
|
-
renderer?: IRenderer;
|
|
73
|
-
/**
|
|
74
|
-
* Disable the automatic registration of window resize listener.
|
|
75
|
-
* Useful when Vecto is running inside a custom layout container or offscreen canvas.
|
|
76
|
-
*/
|
|
77
|
-
disableWindowResize?: boolean;
|
|
78
|
-
}
|
|
79
|
-
/** Frame-rate the loop is capped to when the OS requests reduced motion. */
|
|
80
|
-
declare const REDUCED_MOTION_FPS = 30;
|
|
81
|
-
interface A11yTreeNode {
|
|
82
|
-
id: string;
|
|
83
|
-
tag: string;
|
|
84
|
-
role?: string;
|
|
85
|
-
label?: string;
|
|
86
|
-
value?: string;
|
|
87
|
-
checked?: boolean;
|
|
88
|
-
expanded?: boolean;
|
|
89
|
-
valuemin?: string;
|
|
90
|
-
valuemax?: string;
|
|
91
|
-
children: A11yTreeNode[];
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Top-level orchestrator that owns the entity tree, drive the render loop,
|
|
95
|
-
* and maintains the accessibility/automation shadow layer.
|
|
96
|
-
*
|
|
97
|
-
* Create one `Scene` per `<canvas>` element. Add {@link Entity} objects via
|
|
98
|
-
* {@link add}, then call {@link start} to begin the 60-FPS render loop.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* const scene = new Scene(document.querySelector('canvas')!);
|
|
102
|
-
* scene.add(new CircleEntity().setPosition(100, 100));
|
|
103
|
-
* scene.start();
|
|
104
|
-
*/
|
|
105
|
-
declare class Scene {
|
|
106
|
-
private static webglCreator;
|
|
107
|
-
private static webgpuManagerClass;
|
|
108
|
-
static registerWebGLPointRendererCreator(creator: WebGLPointRendererCreator): void;
|
|
109
|
-
static registerWebGPUParticleSystemManager(managerClass: any): void;
|
|
110
|
-
private root;
|
|
111
|
-
overlayRoot: Entity;
|
|
112
|
-
private renderer;
|
|
113
|
-
private isRunning;
|
|
114
|
-
private lastTime;
|
|
115
|
-
canvas: HTMLCanvasElement;
|
|
116
|
-
/**
|
|
117
|
-
* Redraw strategy:
|
|
118
|
-
* - `'always'` (default): re-render every animation frame (legacy behavior).
|
|
119
|
-
* - `'onDemand'`: only re-render when the scene is marked dirty (via
|
|
120
|
-
* {@link markDirty}) or while an animation is pending. Ideal for static /
|
|
121
|
-
* event-driven UIs where idle frames should cost ~0.
|
|
122
|
-
*/
|
|
123
|
-
renderMode: 'always' | 'onDemand';
|
|
124
|
-
private dirty;
|
|
125
|
-
/**
|
|
126
|
-
* Frame-rate cap (power saving). `0` = uncapped (native refresh). When set,
|
|
127
|
-
* the loop renders at most `maxFPS` times per second; animations still run,
|
|
128
|
-
* just less often. See {@link SceneOptions.maxFPS}.
|
|
129
|
-
*/
|
|
130
|
-
maxFPS: number;
|
|
131
|
-
/** Whether the OS prefers-reduced-motion setting auto-caps the loop. */
|
|
132
|
-
respectReducedMotion: boolean;
|
|
133
|
-
/** Cached media-query list; `.matches` is read live each frame. */
|
|
134
|
-
private reducedMotionQuery;
|
|
135
|
-
/**
|
|
136
|
-
* Throttle interval (ms) for the a11y/automation shadow sync. `0` = every
|
|
137
|
-
* frame. See {@link SceneOptions.a11ySyncInterval}.
|
|
138
|
-
*/
|
|
139
|
-
a11ySyncInterval: number;
|
|
140
|
-
/** Timestamp of the last a11y sync, for throttling. */
|
|
141
|
-
private lastA11ySync;
|
|
142
|
-
/** True if we skipped an a11y sync during animation and need to sync when at rest. */
|
|
143
|
-
private a11yPendingSyncAfterAnimation;
|
|
144
|
-
private a11yRoot;
|
|
145
|
-
private a11yElements;
|
|
146
|
-
private resizeHandler;
|
|
147
|
-
private focusedA11yElement;
|
|
148
|
-
private caretBlinkTimer;
|
|
149
|
-
a11yNeedsReorder: boolean;
|
|
150
|
-
private portalRoot;
|
|
151
|
-
private fullViewportElements;
|
|
152
|
-
private normalElements;
|
|
153
|
-
private activeIds;
|
|
154
|
-
private activePortalsThisFrame;
|
|
155
|
-
private activePortalsPrevFrame;
|
|
156
|
-
private portalEntities;
|
|
157
|
-
private renderOrderCounter;
|
|
158
|
-
private pointRenderer;
|
|
159
|
-
private glCanvas;
|
|
160
|
-
private debugA11y;
|
|
161
|
-
width: number;
|
|
162
|
-
height: number;
|
|
163
|
-
private disableWindowResize;
|
|
164
|
-
private destroyed;
|
|
165
|
-
private device;
|
|
166
|
-
private deviceLost;
|
|
167
|
-
particleBackend: 'auto' | 'webgpu' | 'cpu';
|
|
168
|
-
private _webgpuDisabled;
|
|
169
|
-
get webgpuDisabled(): boolean;
|
|
170
|
-
set webgpuDisabled(value: boolean);
|
|
171
|
-
private recoveryTimerId;
|
|
172
|
-
private manager;
|
|
173
|
-
private initializingWebGPU;
|
|
174
|
-
private gpuCanvas;
|
|
175
|
-
private gpuContext;
|
|
176
|
-
private mouseX;
|
|
177
|
-
private mouseY;
|
|
178
|
-
private pointerMoveListener;
|
|
179
|
-
private pointerLeaveListener;
|
|
180
|
-
private hasWarnedZeroSize;
|
|
181
|
-
constructor(canvas: HTMLCanvasElement, options?: SceneOptions);
|
|
182
|
-
/**
|
|
183
|
-
* Expose the underlying {@link IRenderer} for advanced direct-draw operations.
|
|
184
|
-
*
|
|
185
|
-
* @returns The active renderer instance.
|
|
186
|
-
*/
|
|
187
|
-
getRenderer(): IRenderer;
|
|
188
|
-
/**
|
|
189
|
-
* Add a top-level entity to the scene graph.
|
|
190
|
-
*
|
|
191
|
-
* @param entity - The entity to attach to the scene root.
|
|
192
|
-
* @returns `this` for method chaining.
|
|
193
|
-
* @example scene.add(new CircleEntity());
|
|
194
|
-
*/
|
|
195
|
-
add(entity: Entity): this;
|
|
196
|
-
private removeA11yRecursively;
|
|
197
|
-
/**
|
|
198
|
-
* Remove a top-level entity from the scene graph and clean up its
|
|
199
|
-
* accessibility shadow elements recursively.
|
|
200
|
-
*
|
|
201
|
-
* @param entity - The entity to detach from the scene root.
|
|
202
|
-
* @returns `this` for method chaining.
|
|
203
|
-
*/
|
|
204
|
-
remove(entity: Entity): this;
|
|
205
|
-
/**
|
|
206
|
-
* Tear down the a11y/automation shadow nodes for `entity` and its descendants
|
|
207
|
-
* without removing it from the scene graph. Components that manage dynamic
|
|
208
|
-
* interactive *child* entities (e.g. a {@link Entity}'s per-link hotspots) call
|
|
209
|
-
* this before discarding those children so their shadow `<a>`/controls don't
|
|
210
|
-
* leak (the per-frame `syncA11y` only creates/updates, it never prunes).
|
|
211
|
-
*
|
|
212
|
-
* @param entity - The subtree whose shadow nodes should be removed.
|
|
213
|
-
*/
|
|
214
|
-
detachA11y(entity: Entity): void;
|
|
215
|
-
/**
|
|
216
|
-
* Add an overlay entity to the overlay root, bypassing main tree clipping bounds.
|
|
217
|
-
*/
|
|
218
|
-
showOverlay(overlay: Entity): void;
|
|
219
|
-
/**
|
|
220
|
-
* Remove an overlay entity from the overlay root.
|
|
221
|
-
*/
|
|
222
|
-
hideOverlay(overlay: Entity): void;
|
|
223
|
-
/**
|
|
224
|
-
* Tear down the Scene, halt the loop, and clean up event listeners and DOM elements.
|
|
225
|
-
*/
|
|
226
|
-
destroy(): void;
|
|
227
|
-
private setupEvents;
|
|
228
|
-
/**
|
|
229
|
-
* Begin the `requestAnimationFrame` render loop.
|
|
230
|
-
*
|
|
231
|
-
* Idempotent — calling `start()` on an already-running scene is a no-op.
|
|
232
|
-
*/
|
|
233
|
-
start(): void;
|
|
234
|
-
/** Schedule the next frame, or no-op where `requestAnimationFrame` is absent (SSR). */
|
|
235
|
-
private scheduleFrame;
|
|
236
|
-
/**
|
|
237
|
-
* Halt the render loop after the current frame completes.
|
|
238
|
-
*
|
|
239
|
-
* Call {@link start} again to resume rendering.
|
|
240
|
-
*/
|
|
241
|
-
stop(): void;
|
|
242
|
-
/**
|
|
243
|
-
* Mark the scene as needing a redraw on the next frame.
|
|
244
|
-
*
|
|
245
|
-
* Only meaningful in `onDemand` {@link renderMode}: call it after mutating
|
|
246
|
-
* entity state outside of {@link Entity.animate} so the change is rendered.
|
|
247
|
-
*/
|
|
248
|
-
markDirty(): void;
|
|
249
|
-
/** True when any node in the subtree has a pending animation. */
|
|
250
|
-
private hasAnyPendingAnimation;
|
|
251
|
-
/** True when any node in the subtree is interactive (drives a11y sync). */
|
|
252
|
-
private hasAnyInteractive;
|
|
253
|
-
private syncA11y;
|
|
254
|
-
private enforceA11yDomOrder;
|
|
255
|
-
getA11yTree(): A11yTreeNode[];
|
|
256
|
-
private renderPortalDOM;
|
|
257
|
-
private reconcilePortals;
|
|
258
|
-
/**
|
|
259
|
-
* The frame-rate cap actually in effect: the explicit {@link maxFPS}, further
|
|
260
|
-
* lowered to {@link REDUCED_MOTION_FPS} when the OS requests reduced motion
|
|
261
|
-
* (and {@link respectReducedMotion} is on). `0` means uncapped.
|
|
262
|
-
*/
|
|
263
|
-
private effectiveMaxFPS;
|
|
264
|
-
private loop;
|
|
265
|
-
/**
|
|
266
|
-
* Render the entire scene graph onto the specified renderer.
|
|
267
|
-
*
|
|
268
|
-
* @param renderer - The renderer instance to draw to.
|
|
269
|
-
* @param dt - Delta time in milliseconds (default 0).
|
|
270
|
-
* @param time - Current absolute time in milliseconds (default 0).
|
|
271
|
-
*/
|
|
272
|
-
render(renderer: IRenderer, dt?: number, time?: number): void;
|
|
273
|
-
/**
|
|
274
|
-
* Export the current scene state to a lightweight, flat SVG XML string.
|
|
275
|
-
*/
|
|
276
|
-
toSVG(): string;
|
|
277
|
-
/**
|
|
278
|
-
* Manually resize the Scene's viewport.
|
|
279
|
-
*/
|
|
280
|
-
resize(width: number, height: number): void;
|
|
281
|
-
/**
|
|
282
|
-
* Gets the accessibility DOM element projected for the given entity ID.
|
|
283
|
-
*/
|
|
284
|
-
getA11yElement(entityId: string): HTMLElement | undefined;
|
|
285
|
-
/**
|
|
286
|
-
* Gets the root entity of the scene.
|
|
287
|
-
*/
|
|
288
|
-
getRoot(): Entity;
|
|
289
|
-
/**
|
|
290
|
-
* Finds the topmost interactive entity at the given coordinates.
|
|
291
|
-
*/
|
|
292
|
-
findEntityAt(x: number, y: number): Entity | null;
|
|
293
|
-
private initWebGPUContext;
|
|
294
|
-
private setupDeviceLostHandler;
|
|
295
|
-
private recreateWebGPUDeviceWithRetry;
|
|
296
|
-
private renderCPUParticles;
|
|
297
|
-
private findHitRecursively;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
declare class TextEntity extends Entity {
|
|
301
|
-
text: string;
|
|
302
|
-
private atlas;
|
|
303
|
-
private layout;
|
|
304
|
-
private prepared;
|
|
305
|
-
private nodes;
|
|
306
|
-
fontSize: number;
|
|
307
|
-
fillStyle: string | any;
|
|
308
|
-
strokeStyle: string | any;
|
|
309
|
-
hoveredFillStyle: string | any;
|
|
310
|
-
lineWidth: number;
|
|
311
|
-
private isHovered;
|
|
312
|
-
constructor(text: string, atlas: any, maxWidth: number, fontSize?: number);
|
|
313
|
-
/**
|
|
314
|
-
* Replace the text content. Runs the **cold** measurement pass (re-segment +
|
|
315
|
-
* re-measure) since the glyphs changed, then re-lays out.
|
|
316
|
-
*
|
|
317
|
-
* @returns `this` for chaining.
|
|
318
|
-
*/
|
|
319
|
-
setText(text: string): this;
|
|
320
|
-
/**
|
|
321
|
-
* Change the wrap width and reflow. Cheap **hot** path only — reuses the
|
|
322
|
-
* cached {@link PreparedText}, doing no re-segmentation or re-measurement.
|
|
323
|
-
* Ideal for responsive resize.
|
|
324
|
-
*
|
|
325
|
-
* @returns `this` for chaining.
|
|
326
|
-
*/
|
|
327
|
-
setMaxWidth(maxWidth: number): this;
|
|
328
|
-
/** Hot pass: place the cached {@link PreparedText} and refresh the a11y box. */
|
|
329
|
-
private applyLayout;
|
|
330
|
-
isPointInside(globalX: number, globalY: number): boolean;
|
|
331
|
-
render(renderer: IRenderer): void;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
declare class GridTextEntity extends Entity {
|
|
335
|
-
fontSize: number;
|
|
336
|
-
fillStyle: string;
|
|
337
|
-
grid: string[];
|
|
338
|
-
cols: number;
|
|
339
|
-
rows: number;
|
|
340
|
-
charWidth: number;
|
|
341
|
-
charHeight: number;
|
|
342
|
-
constructor(_atlas: any, fontSize?: number);
|
|
343
|
-
updateGrid(ascii: string[]): void;
|
|
344
|
-
isPointInside(_globalX: number, _globalY: number): boolean;
|
|
345
|
-
render(renderer: IRenderer): void;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/** One piecewise-cubic segment: x(t) and y(t) as `[a,b,c,d]` polynomial coefficients. */
|
|
349
|
-
interface SplineSegment {
|
|
350
|
-
start_t: number;
|
|
351
|
-
end_t: number;
|
|
352
|
-
x_poly: number[];
|
|
353
|
-
y_poly: number[];
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Color of a spline equation: an `[r,g,b]` triple in `0..1`, a linear-gradient
|
|
357
|
-
* descriptor, or `null` (use the entity's default color).
|
|
358
|
-
*/
|
|
359
|
-
type SplineColor = [number, number, number] | {
|
|
360
|
-
stops: [number, [number, number, number]][];
|
|
361
|
-
start_pos: [number, number];
|
|
362
|
-
end_pos: [number, number];
|
|
363
|
-
} | null;
|
|
364
|
-
/** A single curve (one stroke color) made of consecutive {@link SplineSegment}s. */
|
|
365
|
-
interface SplineEquation {
|
|
366
|
-
color_rgb: SplineColor;
|
|
367
|
-
data: SplineSegment[];
|
|
368
|
-
}
|
|
369
|
-
/** The native vectomancy `Spline` document. */
|
|
370
|
-
interface SplineDocument {
|
|
371
|
-
type: 'Spline' | 'Polyline';
|
|
372
|
-
equations?: SplineEquation[];
|
|
373
|
-
paths?: {
|
|
374
|
-
color_rgb: SplineColor;
|
|
375
|
-
data: {
|
|
376
|
-
x: number;
|
|
377
|
-
y: number;
|
|
378
|
-
}[];
|
|
379
|
-
}[];
|
|
380
|
-
bounding_box?: [number, number, number, number];
|
|
381
|
-
}
|
|
382
|
-
/** Construction options for {@link SplineEntity}. */
|
|
383
|
-
interface SplineOptions {
|
|
384
|
-
/** Stroke width in local units. Default `2`. */
|
|
385
|
-
lineWidth?: number;
|
|
386
|
-
/** Bake to an OffscreenCanvas once and `drawImage` each frame. Default `true`. */
|
|
387
|
-
cache?: boolean;
|
|
388
|
-
/** Color used when an equation's `color_rgb` is `null`. Default `#e2e8f0`. */
|
|
389
|
-
defaultColor?: string;
|
|
390
|
-
/**
|
|
391
|
-
* Hit-test strategy:
|
|
392
|
-
* - `'curve'` (default): precise — a point hits only within `lineWidth/2 +
|
|
393
|
-
* hitTolerance` of an actual curve.
|
|
394
|
-
* - `'aabb'`: coarse — anywhere in the bounding box hits.
|
|
395
|
-
*/
|
|
396
|
-
hitTest?: 'curve' | 'aabb';
|
|
397
|
-
/** Extra pick padding (local units) added to `lineWidth/2` in `'curve'` mode. Default `0`. */
|
|
398
|
-
hitTolerance?: number;
|
|
399
|
-
}
|
|
400
|
-
/** Cubic Bézier control points produced from a {@link SplineSegment}. */
|
|
401
|
-
interface BezierControlPoints {
|
|
402
|
-
x0: number;
|
|
403
|
-
y0: number;
|
|
404
|
-
cp1x: number;
|
|
405
|
-
cp1y: number;
|
|
406
|
-
cp2x: number;
|
|
407
|
-
cp2y: number;
|
|
408
|
-
x3: number;
|
|
409
|
-
y3: number;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Convert one cubic-polynomial segment to Bézier control points.
|
|
413
|
-
*
|
|
414
|
-
* For a coefficient vector `[a,b,c,d]` describing `f(t)=a+bt+ct²+dt³` on `t∈[0,1]`,
|
|
415
|
-
* the equivalent Bézier control values are `a`, `a+b/3`, `a+2b/3+c/3`, `a+b+c+d`.
|
|
416
|
-
* Applied independently to the x and y polynomials.
|
|
417
|
-
*
|
|
418
|
-
* @param seg - The polynomial segment.
|
|
419
|
-
* @returns The cubic Bézier control points.
|
|
420
|
-
*/
|
|
421
|
-
declare function polySegmentToBezier(seg: SplineSegment): BezierControlPoints;
|
|
422
|
-
/**
|
|
423
|
-
* Renders a native vectomancy `Spline` document (piecewise-cubic curves) to canvas.
|
|
424
|
-
*
|
|
425
|
-
* Bounds come from the document's `bounding_box` (or are computed from segment
|
|
426
|
-
* endpoints), so the entity participates in {@link Scene} viewport culling. By
|
|
427
|
-
* default the curves are baked once into an `OffscreenCanvas` and blitted each
|
|
428
|
-
* frame; without `OffscreenCanvas` it strokes the Bézier paths per frame.
|
|
429
|
-
*
|
|
430
|
-
* @example
|
|
431
|
-
* const doc = await loadSpline('/ast/logo.json');
|
|
432
|
-
* scene.add(new SplineEntity(doc).setPosition(100, 100));
|
|
433
|
-
*/
|
|
434
|
-
declare class SplineEntity extends Entity {
|
|
435
|
-
doc: SplineDocument;
|
|
436
|
-
lineWidth: number;
|
|
437
|
-
defaultColor: string;
|
|
438
|
-
hitTolerance: number;
|
|
439
|
-
private cache;
|
|
440
|
-
private hitMode;
|
|
441
|
-
private bounds;
|
|
442
|
-
private offscreen;
|
|
443
|
-
private baked;
|
|
444
|
-
/** Lazily-flattened polylines (one Float32Array of [x,y,...] per segment) for hit-testing. */
|
|
445
|
-
private polylines;
|
|
446
|
-
/**
|
|
447
|
-
* When `true`, the renderer draws a rounded-rect outline of the entity's
|
|
448
|
-
* local bounds after painting the curves. Useful for drag feedback and
|
|
449
|
-
* debugging hit areas. Defaults to `false`.
|
|
450
|
-
*/
|
|
451
|
-
showBounds: boolean;
|
|
452
|
-
constructor(doc: SplineDocument, opts?: SplineOptions);
|
|
453
|
-
private computeBounds;
|
|
454
|
-
/** @inheritdoc */
|
|
455
|
-
getBounds(): Bounds;
|
|
456
|
-
/**
|
|
457
|
-
* AABB hit-test against the document bounds in world space.
|
|
458
|
-
*
|
|
459
|
-
* Curve-accurate hit-testing can be layered on later via {@link hitTestCurve};
|
|
460
|
-
* this method already calls it as a refinement when it is overridden.
|
|
461
|
-
*/
|
|
462
|
-
isPointInside(globalX: number, globalY: number): boolean;
|
|
463
|
-
/**
|
|
464
|
-
* Curve-accurate refinement of {@link isPointInside}: hit only when the local
|
|
465
|
-
* point lies within `lineWidth/2 + hitTolerance` of an actual curve.
|
|
466
|
-
*
|
|
467
|
-
* Returns `null` in `hitTest: 'aabb'` mode (keep the bounding-box result).
|
|
468
|
-
* Curves are flattened to polylines once and cached. Override for custom logic.
|
|
469
|
-
*
|
|
470
|
-
* @param localX - X in the entity's local space.
|
|
471
|
-
* @param localY - Y in the entity's local space.
|
|
472
|
-
* @returns `true`/`false`, or `null` to keep the AABB result.
|
|
473
|
-
*/
|
|
474
|
-
protected hitTestCurve(localX: number, localY: number): boolean | null;
|
|
475
|
-
/** Flatten every Bézier segment into a sampled polyline once, then cache. */
|
|
476
|
-
private getPolylines;
|
|
477
|
-
private resolveColor;
|
|
478
|
-
private strokeEquations;
|
|
479
|
-
/** Bake all equations into an OffscreenCanvas once (when available). */
|
|
480
|
-
private bake;
|
|
481
|
-
render(r: IRenderer): void;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Fetch and parse a vectomancy `Spline` JSON document (browser only).
|
|
485
|
-
*
|
|
486
|
-
* @param url - URL of the `.json` spline document.
|
|
487
|
-
* @returns The parsed {@link SplineDocument}.
|
|
488
|
-
*/
|
|
489
|
-
declare function loadSpline(url: string): Promise<SplineDocument>;
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Fixed-cell Spatial Hash Grid for O(1) average-case AABB neighbor queries.
|
|
493
|
-
* Insert entities each frame, then query by AABB to find nearby entity IDs.
|
|
494
|
-
*/
|
|
495
|
-
declare class SpatialHashGrid {
|
|
496
|
-
private cellSize;
|
|
497
|
-
private grid;
|
|
498
|
-
private entityCells;
|
|
499
|
-
constructor(cellSize?: number);
|
|
500
|
-
private hash;
|
|
501
|
-
private cellsForAABB;
|
|
502
|
-
/**
|
|
503
|
-
* Insert or update an entity's axis-aligned bounding box in the grid.
|
|
504
|
-
*
|
|
505
|
-
* If the entity is already registered its old cell memberships are removed
|
|
506
|
-
* before the new ones are computed, so this method is safe to call every
|
|
507
|
-
* frame.
|
|
508
|
-
*
|
|
509
|
-
* @param id - Unique string identifier for the entity.
|
|
510
|
-
* @param x - Left edge of the AABB in world space.
|
|
511
|
-
* @param y - Top edge of the AABB in world space.
|
|
512
|
-
* @param w - Width of the AABB.
|
|
513
|
-
* @param h - Height of the AABB.
|
|
514
|
-
*/
|
|
515
|
-
insert(id: string, x: number, y: number, w: number, h: number): void;
|
|
516
|
-
/**
|
|
517
|
-
* Remove an entity from all grid cells it currently occupies.
|
|
518
|
-
*
|
|
519
|
-
* Silently does nothing if the entity is not registered.
|
|
520
|
-
*
|
|
521
|
-
* @param id - Unique string identifier of the entity to remove.
|
|
522
|
-
*/
|
|
523
|
-
remove(id: string): void;
|
|
524
|
-
/**
|
|
525
|
-
* Return all entity IDs whose grid cells overlap the given AABB.
|
|
526
|
-
*
|
|
527
|
-
* Time complexity: O(k) where k is the number of cells the query AABB spans
|
|
528
|
-
* plus the number of results — O(1) average for small, similarly-sized entities.
|
|
529
|
-
*
|
|
530
|
-
* @param x - Left edge of the query AABB.
|
|
531
|
-
* @param y - Top edge of the query AABB.
|
|
532
|
-
* @param w - Width of the query AABB.
|
|
533
|
-
* @param h - Height of the query AABB.
|
|
534
|
-
* @returns A `Set` of entity ID strings whose cells intersect the query region.
|
|
535
|
-
*/
|
|
536
|
-
query(x: number, y: number, w: number, h: number): Set<string>;
|
|
537
|
-
/**
|
|
538
|
-
* Clear all cells and entity registrations, resetting the grid to an empty state.
|
|
539
|
-
*
|
|
540
|
-
* Call once per frame before re-inserting all dynamic entities.
|
|
541
|
-
*/
|
|
542
|
-
clear(): void;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
declare class SpringPhysics {
|
|
546
|
-
value: number;
|
|
547
|
-
target: number;
|
|
548
|
-
velocity: number;
|
|
549
|
-
stiffness: number;
|
|
550
|
-
damping: number;
|
|
551
|
-
mass: number;
|
|
552
|
-
private readonly valEpsilon;
|
|
553
|
-
private readonly velEpsilon;
|
|
554
|
-
constructor(initial: number);
|
|
555
|
-
update(dt: number): void;
|
|
556
|
-
isAtRest(): boolean;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
declare class DOMPortalEntity extends Entity {
|
|
560
|
-
domElement: HTMLElement;
|
|
561
|
-
isDOMPortal: boolean;
|
|
562
|
-
private domListeners;
|
|
563
|
-
private resizeObserver;
|
|
564
|
-
cachedWidth: number;
|
|
565
|
-
cachedHeight: number;
|
|
566
|
-
lastWidth: string;
|
|
567
|
-
lastHeight: string;
|
|
568
|
-
lastTransform: string;
|
|
569
|
-
lastZIndex: string;
|
|
570
|
-
constructor(domElement: HTMLElement, width?: number, height?: number, id?: string);
|
|
571
|
-
isPointInside(globalX: number, globalY: number): boolean;
|
|
572
|
-
add(child: Entity): this;
|
|
573
|
-
render(): void;
|
|
574
|
-
destroy(): void;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
export { type A11yTreeNode, type BezierControlPoints, Bounds, DOMPortalEntity, Entity, GridTextEntity, IRenderer, type IWebGLPointRenderer, type IWebGPUParticleSystemManager, REDUCED_MOTION_FPS, Scene, type SceneOptions, SpatialHashGrid, type SplineColor, type SplineDocument, SplineEntity, type SplineEquation, type SplineOptions, type SplineSegment, SpringPhysics, TextEntity, type WebGLPointRendererCreator, loadSpline, polySegmentToBezier };
|