@vectojs/core 0.1.0 → 0.2.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/animation/drivers.d.ts +48 -0
- package/dist/animation/easing.d.ts +16 -0
- package/dist/{chunk-53DAQC3U.js → chunk-W3SFIVXO.js} +356 -60
- package/dist/{chunk-M2IZPGOL.mjs → chunk-Y2N7TGEH.mjs} +303 -7
- 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 +60 -78
- package/dist/index.mjs +15 -33
- 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} +59 -197
- package/dist/tree/Scene.d.ts +295 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WORKER_SOURCE_STRING = "\"use strict\";(()=>{var b=new Map;self.onmessage=x=>{let{id:S,seqId:k,text:A,fontId:i,fontData:c,maxWidth:d,maxHeight:H,fontSize:o,lineHeight:F,letterSpacing:C}=x.data;c&&b.set(i,c);let n=b.get(i);if(!n)return;let f=[],u=[],y=[],l=[],e=0,r=0,h=n.metrics?.ascender??.8,D=n.metrics?.descender??-.2,m=F??o*(h-D),p=Array.from(A);for(let s=0;s<p.length;s++){let a=p[s].codePointAt(0),g=(n.glyphs?.find(w=>w.unicode===a)?.advance??1)*o;e+g>d&&a===32&&(e=0,r++),f.push(a),u.push(e);let M=r*m+h*o;y.push(M),l.push(-256),e+=g+(C??0)}let t={id:S,seqId:k,width:Math.min(e,d),height:(r+1)*m,codePoints:new Uint32Array(f),xCoords:new Float32Array(u),yCoords:new Float32Array(y),packedStyles:new Uint32Array(l)};self.postMessage(t,[t.codePoints.buffer,t.xCoords.buffer,t.yCoords.buffer,t.packedStyles.buffer])};})();\n";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GlyphMeasurer } from './LayoutEngine';
|
|
2
|
+
/**
|
|
3
|
+
* Create a {@link GlyphMeasurer} backed by a single lazily-created offscreen
|
|
4
|
+
* Canvas 2D context.
|
|
5
|
+
*
|
|
6
|
+
* Each grapheme is measured once at `baseSize` and cached; because canvas
|
|
7
|
+
* `measureText` advance width is linear in font size, later queries at any
|
|
8
|
+
* `fontSize` are derived by pure arithmetic (no re-measure). This gives the
|
|
9
|
+
* {@link LayoutEngine} real per-glyph metrics for text that has no pre-baked
|
|
10
|
+
* vector atlas, fixing the coarse `0.5em` line-breaking fallback.
|
|
11
|
+
*
|
|
12
|
+
* Returns `null` in DOM-free environments (SSR, workers without a canvas) so
|
|
13
|
+
* callers stay portable and the engine keeps its `0.5em` fallback.
|
|
14
|
+
*
|
|
15
|
+
* @param fontFamily - CSS font family used for measurement; should match what
|
|
16
|
+
* the renderer actually draws (e.g. `TextEntity` falls back to `sans-serif`).
|
|
17
|
+
* @param baseSize - Pixel size at which each glyph is measured and cached.
|
|
18
|
+
* @returns A measurer, or `null` when no Canvas 2D context is available.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createCanvasMeasurer(fontFamily?: string, baseSize?: number): GlyphMeasurer | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-cell Spatial Hash Grid for O(1) average-case AABB neighbor queries.
|
|
3
|
+
* Insert entities each frame, then query by AABB to find nearby entity IDs.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SpatialHashGrid {
|
|
6
|
+
private cellSize;
|
|
7
|
+
private grid;
|
|
8
|
+
private entityCells;
|
|
9
|
+
constructor(cellSize?: number);
|
|
10
|
+
private hash;
|
|
11
|
+
private cellsForAABB;
|
|
12
|
+
/**
|
|
13
|
+
* Insert or update an entity's axis-aligned bounding box in the grid.
|
|
14
|
+
*
|
|
15
|
+
* If the entity is already registered its old cell memberships are removed
|
|
16
|
+
* before the new ones are computed, so this method is safe to call every
|
|
17
|
+
* frame.
|
|
18
|
+
*
|
|
19
|
+
* @param id - Unique string identifier for the entity.
|
|
20
|
+
* @param x - Left edge of the AABB in world space.
|
|
21
|
+
* @param y - Top edge of the AABB in world space.
|
|
22
|
+
* @param w - Width of the AABB.
|
|
23
|
+
* @param h - Height of the AABB.
|
|
24
|
+
*/
|
|
25
|
+
insert(id: string, x: number, y: number, w: number, h: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Remove an entity from all grid cells it currently occupies.
|
|
28
|
+
*
|
|
29
|
+
* Silently does nothing if the entity is not registered.
|
|
30
|
+
*
|
|
31
|
+
* @param id - Unique string identifier of the entity to remove.
|
|
32
|
+
*/
|
|
33
|
+
remove(id: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Return all entity IDs whose grid cells overlap the given AABB.
|
|
36
|
+
*
|
|
37
|
+
* Time complexity: O(k) where k is the number of cells the query AABB spans
|
|
38
|
+
* plus the number of results — O(1) average for small, similarly-sized entities.
|
|
39
|
+
*
|
|
40
|
+
* @param x - Left edge of the query AABB.
|
|
41
|
+
* @param y - Top edge of the query AABB.
|
|
42
|
+
* @param w - Width of the query AABB.
|
|
43
|
+
* @param h - Height of the query AABB.
|
|
44
|
+
* @returns A `Set` of entity ID strings whose cells intersect the query region.
|
|
45
|
+
*/
|
|
46
|
+
query(x: number, y: number, w: number, h: number): Set<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Clear all cells and entity registrations, resetting the grid to an empty state.
|
|
49
|
+
*
|
|
50
|
+
* Call once per frame before re-inserting all dynamic entities.
|
|
51
|
+
*/
|
|
52
|
+
clear(): void;
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class SpringPhysics {
|
|
2
|
+
value: number;
|
|
3
|
+
target: number;
|
|
4
|
+
velocity: number;
|
|
5
|
+
stiffness: number;
|
|
6
|
+
damping: number;
|
|
7
|
+
mass: number;
|
|
8
|
+
private readonly valEpsilon;
|
|
9
|
+
private readonly velEpsilon;
|
|
10
|
+
constructor(initial: number);
|
|
11
|
+
update(dt: number): void;
|
|
12
|
+
isAtRest(): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { IRenderer } from './IRenderer';
|
|
2
|
+
export declare class CanvasRenderer implements IRenderer {
|
|
3
|
+
private ctx;
|
|
4
|
+
private width;
|
|
5
|
+
private height;
|
|
6
|
+
/**
|
|
7
|
+
* Max circles per batched `fill()`. A single Canvas 2D `fill()` over a path is
|
|
8
|
+
* superlinear in sub-path count, so an unbounded batch is *slower* than many
|
|
9
|
+
* small fills at high entity counts. Capping bounds each fill's path
|
|
10
|
+
* complexity while still amortizing per-draw overhead. Tuned via the benchmark.
|
|
11
|
+
*/
|
|
12
|
+
static readonly MAX_BATCH = 64;
|
|
13
|
+
private batchActive;
|
|
14
|
+
private batchColor;
|
|
15
|
+
private batchAlpha;
|
|
16
|
+
private batchCount;
|
|
17
|
+
constructor(canvas: HTMLCanvasElement);
|
|
18
|
+
/**
|
|
19
|
+
* Expose the underlying `CanvasRenderingContext2D` for operations not
|
|
20
|
+
* covered by the {@link IRenderer} interface.
|
|
21
|
+
*
|
|
22
|
+
* @returns The raw 2D rendering context.
|
|
23
|
+
*/
|
|
24
|
+
getContext(): CanvasRenderingContext2D;
|
|
25
|
+
/**
|
|
26
|
+
* Resize the backing canvas buffer and re-apply DPR scaling.
|
|
27
|
+
*
|
|
28
|
+
* Called automatically by {@link Scene} on `window.resize` events.
|
|
29
|
+
*
|
|
30
|
+
* @param width - New logical width in CSS pixels.
|
|
31
|
+
* @param height - New logical height in CSS pixels.
|
|
32
|
+
*/
|
|
33
|
+
resize(width: number, height: number): void;
|
|
34
|
+
/** @inheritdoc */
|
|
35
|
+
clear(): void;
|
|
36
|
+
/** @inheritdoc */
|
|
37
|
+
save(): void;
|
|
38
|
+
/** @inheritdoc */
|
|
39
|
+
restore(): void;
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
translate(x: number, y: number): void;
|
|
42
|
+
/** @inheritdoc */
|
|
43
|
+
scale(x: number, y: number): void;
|
|
44
|
+
/** @inheritdoc */
|
|
45
|
+
rotate(angle: number): void;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
setGlobalAlpha(alpha: number): void;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
clip(x: number, y: number, width: number, height: number): void;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
beginPath(): void;
|
|
52
|
+
/** @inheritdoc */
|
|
53
|
+
moveTo(x: number, y: number): void;
|
|
54
|
+
/** @inheritdoc */
|
|
55
|
+
lineTo(x: number, y: number): void;
|
|
56
|
+
/** @inheritdoc */
|
|
57
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
58
|
+
/** @inheritdoc */
|
|
59
|
+
closePath(): void;
|
|
60
|
+
/** @inheritdoc */
|
|
61
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
|
|
62
|
+
/** @inheritdoc */
|
|
63
|
+
roundRect(x: number, y: number, width: number, height: number, radii: number | number[]): void;
|
|
64
|
+
/** @inheritdoc */
|
|
65
|
+
drawImage(source: CanvasImageSource, dx: number, dy: number, dw: number, dh: number): void;
|
|
66
|
+
/** @inheritdoc */
|
|
67
|
+
fillCircle(cx: number, cy: number, radius: number, color: string, alpha?: number): void;
|
|
68
|
+
/** @inheritdoc */
|
|
69
|
+
flush(): void;
|
|
70
|
+
/** @inheritdoc */
|
|
71
|
+
fill(color: string | any): void;
|
|
72
|
+
/** @inheritdoc */
|
|
73
|
+
stroke(color: string | any, lineWidth?: number): void;
|
|
74
|
+
/** @inheritdoc */
|
|
75
|
+
fillText(text: string, x: number, y: number, font: string, color: string | any): void;
|
|
76
|
+
/** @inheritdoc */
|
|
77
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number, colorStops: {
|
|
78
|
+
stop: number;
|
|
79
|
+
color: string;
|
|
80
|
+
}[]): any;
|
|
81
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renderer abstraction consumed by every {@link Entity}.
|
|
3
|
+
*
|
|
4
|
+
* Implementations wrap a concrete drawing backend (Canvas 2D, WebGL, …) and
|
|
5
|
+
* expose a path-based drawing API. Entities must only depend on `IRenderer`
|
|
6
|
+
* so they remain backend-agnostic.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Inside an Entity.render() implementation:
|
|
10
|
+
* render(r: IRenderer) {
|
|
11
|
+
* r.beginPath();
|
|
12
|
+
* r.fill('#38bdf8');
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export interface IRenderer {
|
|
16
|
+
/** Clear the entire drawing surface to transparent / background color. */
|
|
17
|
+
clear(): void;
|
|
18
|
+
/** Push the current transform + state onto the renderer's stack. */
|
|
19
|
+
save(): void;
|
|
20
|
+
/** Pop the last saved transform + state from the renderer's stack. */
|
|
21
|
+
restore(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Apply a translation to the current transform matrix.
|
|
24
|
+
*
|
|
25
|
+
* @param x - Horizontal offset in pixels.
|
|
26
|
+
* @param y - Vertical offset in pixels.
|
|
27
|
+
*/
|
|
28
|
+
translate(x: number, y: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Apply a scale to the current transform matrix.
|
|
31
|
+
*
|
|
32
|
+
* @param x - Horizontal scale factor.
|
|
33
|
+
* @param y - Vertical scale factor.
|
|
34
|
+
*/
|
|
35
|
+
scale(x: number, y: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Apply a clockwise rotation to the current transform matrix.
|
|
38
|
+
*
|
|
39
|
+
* @param angle - Rotation angle in radians.
|
|
40
|
+
*/
|
|
41
|
+
rotate(angle: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Set the global opacity applied to all subsequent draw calls.
|
|
44
|
+
*
|
|
45
|
+
* @param alpha - Opacity in the range `[0, 1]`.
|
|
46
|
+
*/
|
|
47
|
+
setGlobalAlpha(alpha: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Intersect the current clip region with a rectangle. Affects all subsequent
|
|
50
|
+
* draws until the next {@link restore}; wrap in {@link save}/{@link restore}.
|
|
51
|
+
*
|
|
52
|
+
* @param x - Left edge.
|
|
53
|
+
* @param y - Top edge.
|
|
54
|
+
* @param width - Rectangle width.
|
|
55
|
+
* @param height - Rectangle height.
|
|
56
|
+
*/
|
|
57
|
+
clip(x: number, y: number, width: number, height: number): void;
|
|
58
|
+
/** Begin a new sub-path, discarding the current path. */
|
|
59
|
+
beginPath(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Move the pen to the given point without drawing a line.
|
|
62
|
+
*
|
|
63
|
+
* @param x - Target X coordinate.
|
|
64
|
+
* @param y - Target Y coordinate.
|
|
65
|
+
*/
|
|
66
|
+
moveTo(x: number, y: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Add a straight line segment from the current pen position to the given point.
|
|
69
|
+
*
|
|
70
|
+
* @param x - Target X coordinate.
|
|
71
|
+
* @param y - Target Y coordinate.
|
|
72
|
+
*/
|
|
73
|
+
lineTo(x: number, y: number): void;
|
|
74
|
+
/**
|
|
75
|
+
* Add a cubic Bézier curve to the current path.
|
|
76
|
+
*
|
|
77
|
+
* @param cp1x - X of the first control point.
|
|
78
|
+
* @param cp1y - Y of the first control point.
|
|
79
|
+
* @param cp2x - X of the second control point.
|
|
80
|
+
* @param cp2y - Y of the second control point.
|
|
81
|
+
* @param x - X of the end point.
|
|
82
|
+
* @param y - Y of the end point.
|
|
83
|
+
*/
|
|
84
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
85
|
+
/** Close the current sub-path by drawing a line back to its starting point. */
|
|
86
|
+
closePath(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Add a circular arc to the current path.
|
|
89
|
+
*
|
|
90
|
+
* @param x - X of the arc center.
|
|
91
|
+
* @param y - Y of the arc center.
|
|
92
|
+
* @param radius - Arc radius in pixels.
|
|
93
|
+
* @param startAngle - Start angle in radians (0 = 3 o'clock).
|
|
94
|
+
* @param endAngle - End angle in radians.
|
|
95
|
+
* @param counterclockwise - If `true`, draws the arc counter-clockwise.
|
|
96
|
+
*/
|
|
97
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
|
|
98
|
+
/**
|
|
99
|
+
* Add a rounded rectangle to the current path.
|
|
100
|
+
*
|
|
101
|
+
* @param x - Left edge.
|
|
102
|
+
* @param y - Top edge.
|
|
103
|
+
* @param width - Rectangle width.
|
|
104
|
+
* @param height - Rectangle height.
|
|
105
|
+
* @param radii - Corner radius (uniform) or per-corner array as accepted by `CanvasRenderingContext2D.roundRect()`.
|
|
106
|
+
*/
|
|
107
|
+
roundRect(x: number, y: number, width: number, height: number, radii: number | number[]): void;
|
|
108
|
+
/**
|
|
109
|
+
* Draw an image or video frame into the canvas.
|
|
110
|
+
*
|
|
111
|
+
* @param source - The image source (HTMLImageElement, HTMLVideoElement, HTMLCanvasElement, etc.).
|
|
112
|
+
* @param dx - Destination X.
|
|
113
|
+
* @param dy - Destination Y.
|
|
114
|
+
* @param dw - Destination width.
|
|
115
|
+
* @param dh - Destination height.
|
|
116
|
+
*/
|
|
117
|
+
drawImage(source: CanvasImageSource, dx: number, dy: number, dw: number, dh: number): void;
|
|
118
|
+
/**
|
|
119
|
+
* Fill the current path with the given color or gradient.
|
|
120
|
+
*
|
|
121
|
+
* @param colorOrGradient - CSS color string or a gradient object.
|
|
122
|
+
*/
|
|
123
|
+
fill(colorOrGradient: string | any): void;
|
|
124
|
+
/**
|
|
125
|
+
* Stroke the current path with the given color or gradient.
|
|
126
|
+
*
|
|
127
|
+
* @param colorOrGradient - CSS color string or a gradient object.
|
|
128
|
+
* @param lineWidth - Stroke width in pixels (default: `1`).
|
|
129
|
+
*/
|
|
130
|
+
stroke(colorOrGradient: string | any, lineWidth?: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Render a text string at the given position.
|
|
133
|
+
*
|
|
134
|
+
* @param text - The string to draw.
|
|
135
|
+
* @param x - Left edge of the text baseline.
|
|
136
|
+
* @param y - Baseline Y coordinate.
|
|
137
|
+
* @param font - CSS font shorthand, e.g. `'16px monospace'`.
|
|
138
|
+
* @param color - CSS color string or gradient.
|
|
139
|
+
*/
|
|
140
|
+
fillText(text: string, x: number, y: number, font: string, color: string | any): void;
|
|
141
|
+
/**
|
|
142
|
+
* Draw a filled circle through the order-preserving batch.
|
|
143
|
+
*
|
|
144
|
+
* Consecutive calls sharing the same `color` and `alpha` are coalesced into a
|
|
145
|
+
* single path and committed with one `fill()` on {@link flush} (or when the
|
|
146
|
+
* style changes / another draw call intervenes). Coordinates are in the
|
|
147
|
+
* current transform space. This collapses the per-entity
|
|
148
|
+
* `beginPath`/`arc`/`fill` of large point clouds into a handful of draw calls
|
|
149
|
+
* while preserving painter's-order semantics.
|
|
150
|
+
*
|
|
151
|
+
* @param cx - Center X in the current transform space.
|
|
152
|
+
* @param cy - Center Y in the current transform space.
|
|
153
|
+
* @param radius - Circle radius.
|
|
154
|
+
* @param color - CSS color string.
|
|
155
|
+
* @param alpha - Opacity in `[0, 1]` (default `1`).
|
|
156
|
+
*/
|
|
157
|
+
fillCircle(cx: number, cy: number, radius: number, color: string, alpha?: number): void;
|
|
158
|
+
/**
|
|
159
|
+
* Commit any pending batched draws (see {@link fillCircle}). Safe to call when
|
|
160
|
+
* no batch is active (no-op). The {@link Scene} flushes at the end of each
|
|
161
|
+
* sibling group and frame.
|
|
162
|
+
*/
|
|
163
|
+
flush(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Create a linear gradient between two points with the given color stops.
|
|
166
|
+
*
|
|
167
|
+
* @param x0 - X of the gradient start point.
|
|
168
|
+
* @param y0 - Y of the gradient start point.
|
|
169
|
+
* @param x1 - X of the gradient end point.
|
|
170
|
+
* @param y1 - Y of the gradient end point.
|
|
171
|
+
* @param colorStops - Array of `{ stop, color }` pairs where `stop` is in `[0, 1]`.
|
|
172
|
+
* @returns An opaque gradient object suitable for {@link fill} or {@link stroke}.
|
|
173
|
+
*/
|
|
174
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number, colorStops: {
|
|
175
|
+
stop: number;
|
|
176
|
+
color: string;
|
|
177
|
+
}[]): any;
|
|
178
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { IRenderer } from './IRenderer';
|
|
2
|
+
export interface SVGLinearGradient {
|
|
3
|
+
type: 'linear';
|
|
4
|
+
id?: string;
|
|
5
|
+
x0: number;
|
|
6
|
+
y0: number;
|
|
7
|
+
x1: number;
|
|
8
|
+
y1: number;
|
|
9
|
+
colorStops: {
|
|
10
|
+
stop: number;
|
|
11
|
+
color: string;
|
|
12
|
+
}[];
|
|
13
|
+
createMatrix: number[];
|
|
14
|
+
}
|
|
15
|
+
export declare class SVGRenderer implements IRenderer {
|
|
16
|
+
private width;
|
|
17
|
+
private height;
|
|
18
|
+
private buffer;
|
|
19
|
+
private defsBuffer;
|
|
20
|
+
private currentPath;
|
|
21
|
+
private mStack;
|
|
22
|
+
private ma;
|
|
23
|
+
private mb;
|
|
24
|
+
private mc;
|
|
25
|
+
private md;
|
|
26
|
+
private me;
|
|
27
|
+
private mf;
|
|
28
|
+
private alphaStack;
|
|
29
|
+
private globalAlpha;
|
|
30
|
+
private clipDepthStack;
|
|
31
|
+
private clipDepth;
|
|
32
|
+
private clipCounter;
|
|
33
|
+
private batchCircles;
|
|
34
|
+
private batchMatrix;
|
|
35
|
+
private batchColor;
|
|
36
|
+
private batchAlpha;
|
|
37
|
+
private batchActive;
|
|
38
|
+
private gradientCounter;
|
|
39
|
+
private gradientCache;
|
|
40
|
+
constructor(width: number, height: number);
|
|
41
|
+
clear(): void;
|
|
42
|
+
save(): void;
|
|
43
|
+
restore(): void;
|
|
44
|
+
translate(dx: number, dy: number): void;
|
|
45
|
+
scale(sx: number, sy: number): void;
|
|
46
|
+
rotate(angle: number): void;
|
|
47
|
+
setGlobalAlpha(alpha: number): void;
|
|
48
|
+
beginPath(): void;
|
|
49
|
+
moveTo(x: number, y: number): void;
|
|
50
|
+
lineTo(x: number, y: number): void;
|
|
51
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
52
|
+
closePath(): void;
|
|
53
|
+
arc(x: number, y: number, r: number, startAngle: number, endAngle: number, ccw?: boolean): void;
|
|
54
|
+
roundRect(x: number, y: number, w: number, h: number, radii: number | number[]): void;
|
|
55
|
+
fill(colorOrGradient: string | SVGLinearGradient): void;
|
|
56
|
+
stroke(colorOrGradient: string | SVGLinearGradient, lineWidth?: number): void;
|
|
57
|
+
fillText(text: string, x: number, y: number, font: string, color: string | SVGLinearGradient): void;
|
|
58
|
+
fillCircle(cx: number, cy: number, radius: number, color: string, alpha?: number): void;
|
|
59
|
+
drawImage(source: any, dx: number, dy: number, dw: number, dh: number): void;
|
|
60
|
+
flush(): void;
|
|
61
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number, colorStops: {
|
|
62
|
+
stop: number;
|
|
63
|
+
color: string;
|
|
64
|
+
}[]): SVGLinearGradient;
|
|
65
|
+
clip(x: number, y: number, width: number, height: number): void;
|
|
66
|
+
toXMLString(): string;
|
|
67
|
+
private resolveGradient;
|
|
68
|
+
private escapeXML;
|
|
69
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A GPU-accelerated layer that draws large sets of circles and rectangles in a
|
|
3
|
+
* couple of draw calls. Used by {@link Scene} (via `pointBackend: 'webgl'`) to
|
|
4
|
+
* render `getBatchCircle()` / `getBatchRect()` entities — the point-cloud /
|
|
5
|
+
* particle case where Canvas2D tops out at ~7 fps for 100k primitives.
|
|
6
|
+
*/
|
|
7
|
+
export interface PointRenderer {
|
|
8
|
+
/** Resize the backing buffer + GL viewport to a logical `w × h` (DPR applied). */
|
|
9
|
+
resize(width: number, height: number): void;
|
|
10
|
+
/** Begin a frame: reset the accumulated primitive buffers. */
|
|
11
|
+
begin(): void;
|
|
12
|
+
/** Add one circle in world (CSS-pixel) coordinates; `alpha` multiplies the color's. */
|
|
13
|
+
addCircle(x: number, y: number, radius: number, color: string, alpha?: number): void;
|
|
14
|
+
/**
|
|
15
|
+
* Add one rectangle: top-left at world `(x, y)`, `width × height` in world units,
|
|
16
|
+
* rotated `rotation` radians about `(x, y)`; `alpha` multiplies the color's.
|
|
17
|
+
*/
|
|
18
|
+
addRect(x: number, y: number, width: number, height: number, color: string, alpha?: number, rotation?: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Upload a texture atlas used by {@link addSprite}. Pass any `TexImageSource`
|
|
21
|
+
* (HTMLImageElement, HTMLCanvasElement, ImageBitmap, …). Call once (or whenever
|
|
22
|
+
* the atlas changes) before adding sprites.
|
|
23
|
+
*/
|
|
24
|
+
setTexture(source: TexImageSource): void;
|
|
25
|
+
/**
|
|
26
|
+
* Add one textured sprite sampling the atlas region `[u0,v0]–[u1,v1]` (UVs in
|
|
27
|
+
* `0..1`): top-left at world `(x, y)`, `width × height` in world units, rotated
|
|
28
|
+
* `rotation` radians about `(x, y)`. `color` multiplies the sampled texel
|
|
29
|
+
* (white = unchanged; use it to tint white glyphs); `alpha` multiplies further.
|
|
30
|
+
* No-op until a texture is set via {@link setTexture}.
|
|
31
|
+
*/
|
|
32
|
+
addSprite(x: number, y: number, width: number, height: number, u0: number, v0: number, u1: number, v1: number, color?: string, alpha?: number, rotation?: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Upload an MSDF (multi-channel signed distance field) glyph atlas used by
|
|
35
|
+
* {@link addGlyph}, kept separate from the {@link setTexture} atlas so both can
|
|
36
|
+
* be active. `distanceRange` is the field's pixel range (the atlas JSON's
|
|
37
|
+
* `atlas.distanceRange`) — it drives the shader's edge sharpness. Pair with
|
|
38
|
+
* `MSDFFont.layout` to position the glyphs.
|
|
39
|
+
*/
|
|
40
|
+
setMSDFTexture(source: TexImageSource, distanceRange: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Add one MSDF glyph quad sampling `[u0,v0]–[u1,v1]` (UVs in `0..1`): top-left
|
|
43
|
+
* at world `(x, y)`, `width × height` in world units. The fragment shader
|
|
44
|
+
* reconstructs a crisp, resolution-independent edge from the distance field, so
|
|
45
|
+
* glyphs stay sharp at any scale. `color` tints the glyph (default white);
|
|
46
|
+
* `alpha` multiplies coverage. No-op until {@link setMSDFTexture} is called.
|
|
47
|
+
*/
|
|
48
|
+
addGlyph(x: number, y: number, width: number, height: number, u0: number, v0: number, u1: number, v1: number, color?: string, alpha?: number, rotation?: number): void;
|
|
49
|
+
/** Clear the layer and draw all accumulated primitives. */
|
|
50
|
+
flush(): void;
|
|
51
|
+
/** Release GL resources. */
|
|
52
|
+
destroy(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a WebGL2-backed {@link PointRenderer} on `canvas`, or `null` when WebGL2
|
|
56
|
+
* (or shader compilation) is unavailable — callers fall back to Canvas2D.
|
|
57
|
+
*
|
|
58
|
+
* @param canvas - A dedicated canvas (WebGL2 context); should be stacked over the
|
|
59
|
+
* scene's 2D canvas.
|
|
60
|
+
* @returns A point renderer, or `null` if WebGL2 isn't supported.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createWebGLPointRenderer(canvas: HTMLCanvasElement): PointRenderer | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComputeParticleEntity } from '../tree/ComputeParticleEntity';
|
|
2
|
+
export declare class WebGPUParticleSystemManager {
|
|
3
|
+
private device;
|
|
4
|
+
private computePipeline;
|
|
5
|
+
private renderPipeline;
|
|
6
|
+
private computeBindGroupLayout;
|
|
7
|
+
private renderBindGroupLayout;
|
|
8
|
+
constructor(device: GPUDevice);
|
|
9
|
+
initPipelines(format: GPUTextureFormat): void;
|
|
10
|
+
setupEntityResources(entity: ComputeParticleEntity): void;
|
|
11
|
+
recordComputePass(pass: GPUComputePassEncoder, entity: ComputeParticleEntity, dt: number, mouseX: number, mouseY: number, width: number, height: number): void;
|
|
12
|
+
recordRenderPass(pass: GPURenderPassEncoder, entity: ComputeParticleEntity): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed color as normalized `[r, g, b, a]` floats in `[0, 1]`.
|
|
3
|
+
*/
|
|
4
|
+
export type RGBA = [number, number, number, number];
|
|
5
|
+
/**
|
|
6
|
+
* Parse a CSS color string into normalized `[r, g, b, a]` floats.
|
|
7
|
+
*
|
|
8
|
+
* Fast paths handle `#rgb`/`#rgba`/`#rrggbb`/`#rrggbbaa` and `rgb()`/`rgba()`;
|
|
9
|
+
* other forms (named colors, `hsl()`, …) resolve via a cached 1×1 canvas when a
|
|
10
|
+
* DOM is available. Results are cached per input string and shared by identity,
|
|
11
|
+
* so callers must treat the returned array as read-only. Unparseable input with
|
|
12
|
+
* no DOM yields opaque black `[0, 0, 0, 1]`.
|
|
13
|
+
*
|
|
14
|
+
* @param css - A CSS color string, e.g. `'#38bdf8'` or `'rgba(0,0,0,.5)'`.
|
|
15
|
+
* @returns The cached `[r, g, b, a]` tuple in `[0, 1]`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseColorToRGBA(css: string): RGBA;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ShapedResult {
|
|
2
|
+
shapedText: string;
|
|
3
|
+
indexMap: Int32Array;
|
|
4
|
+
}
|
|
5
|
+
export declare class ArabicShaper {
|
|
6
|
+
private static MAPPINGS;
|
|
7
|
+
private static isHarakat;
|
|
8
|
+
private static getJoiningType;
|
|
9
|
+
static shapeArabic(text: string): ShapedResult;
|
|
10
|
+
}
|