@open-artifact/canvas-engine 0.0.0-stage → 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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +44 -4
- package/src/camera.d.ts +71 -0
- package/src/camera.js +89 -0
- package/src/engine.d.ts +132 -0
- package/src/engine.js +738 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +6 -0
- package/src/protocol.d.ts +146 -0
- package/src/protocol.js +736 -0
- package/src/types.d.ts +355 -0
- package/src/types.js +6 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @open-artifact/canvas-engine: a generic WebGL2 canvas engine in Rust/WASM
|
|
3
|
+
* (`crates/open-artifact-canvas`) with a TypeScript API. See `CanvasEngine`.
|
|
4
|
+
*/
|
|
5
|
+
export { CanvasEngine } from './engine.ts';
|
|
6
|
+
export { parseColor, parseSvgPath, polylineCommands, PatchEncoder, IdRegistry, MAX_CUTS } from './protocol.ts';
|
|
7
|
+
export type * from './types.ts';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @open-artifact/canvas-engine: a generic WebGL2 canvas engine in Rust/WASM
|
|
3
|
+
* (`crates/open-artifact-canvas`) with a TypeScript API. See `CanvasEngine`.
|
|
4
|
+
*/
|
|
5
|
+
export { CanvasEngine } from "./engine.js";
|
|
6
|
+
export { parseColor, parseSvgPath, polylineCommands, PatchEncoder, IdRegistry, MAX_CUTS } from "./protocol.js";
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The binary protocol between TypeScript and the wasm core: id handles, colours,
|
|
3
|
+
* path commands and patch records. Everything here is GPU-free and runs in Node.
|
|
4
|
+
*
|
|
5
|
+
* A patch is a Float64Array of REC-sized records plus a Float32Array of path
|
|
6
|
+
* commands. Record layout (index: field):
|
|
7
|
+
* 0 op (1 upsert, 2 remove, 3 clear) 1 handle 2 kind (0 box, 1 hole, 2 path)
|
|
8
|
+
* 3 layer 4 z 5 x 6 y 7 w 8 h 9 rotation 10 flags 11 opacity
|
|
9
|
+
* 12 fill 13 stroke (0xRRGGBBAA) 14 stroke width 15 radius 16 dash on 17 dash off
|
|
10
|
+
* 18 shadow colour 19 shadow blur 20 shadow dx 21 shadow dy 22 texture handle (-1 none)
|
|
11
|
+
* 23 path offset 24 path length 25 viewBox w 26 viewBox h 27 cap 28 join 29 miter limit
|
|
12
|
+
* 30 fill rule 31 reserved
|
|
13
|
+
* Path commands (f32): 0 M x y, 1 L x y, 2 Q cx cy x y, 3 C c1x c1y c2x c2y x y, 4 Z.
|
|
14
|
+
*/
|
|
15
|
+
import type { CanvasItem, Color, ItemFlags, Patch } from './types.ts';
|
|
16
|
+
export declare const REC = 32;
|
|
17
|
+
export declare const OP_UPSERT = 1;
|
|
18
|
+
export declare const OP_REMOVE = 2;
|
|
19
|
+
export declare const OP_CLEAR = 3;
|
|
20
|
+
export declare const KIND_BOX = 0;
|
|
21
|
+
export declare const KIND_HOLE = 1;
|
|
22
|
+
export declare const KIND_PATH = 2;
|
|
23
|
+
export declare const F_VISIBLE = 1;
|
|
24
|
+
export declare const F_HITTABLE = 2;
|
|
25
|
+
export declare const F_SELECTABLE = 4;
|
|
26
|
+
export declare const F_MOVABLE = 8;
|
|
27
|
+
export declare const F_RESIZABLE = 16;
|
|
28
|
+
export declare const F_SNAP = 32;
|
|
29
|
+
export declare const F_LOCK_ASPECT = 64;
|
|
30
|
+
export declare const F_HIT_STROKE_ONLY = 128;
|
|
31
|
+
export declare const F_STROKE_SCREEN = 256;
|
|
32
|
+
export declare const F_NO_HOVER = 512;
|
|
33
|
+
export declare const F_NO_OUTLINE = 1024;
|
|
34
|
+
export declare const F_HANDLES_CORNERS = 2048;
|
|
35
|
+
export declare const F_HANDLES_WIDTH = 4096;
|
|
36
|
+
export declare const F_MULTIPLY = 8192;
|
|
37
|
+
/** Most cut-out rects a path takes (`PathItem.cuts`). */
|
|
38
|
+
export declare const MAX_CUTS = 2;
|
|
39
|
+
export declare const CMD_M = 0;
|
|
40
|
+
export declare const CMD_L = 1;
|
|
41
|
+
export declare const CMD_Q = 2;
|
|
42
|
+
export declare const CMD_C = 3;
|
|
43
|
+
export declare const CMD_Z = 4;
|
|
44
|
+
/** Option keys for `CanvasCore.set_option`. */
|
|
45
|
+
export declare const OPTION: {
|
|
46
|
+
readonly minZoom: 1;
|
|
47
|
+
readonly maxZoom: 2;
|
|
48
|
+
readonly snap: 3;
|
|
49
|
+
readonly snapDistance: 4;
|
|
50
|
+
readonly dragThreshold: 5;
|
|
51
|
+
readonly hitTolerance: 6;
|
|
52
|
+
readonly handleSize: 7;
|
|
53
|
+
readonly settleMs: 8;
|
|
54
|
+
readonly cameraEventMs: 9;
|
|
55
|
+
readonly wheelZoom: 10;
|
|
56
|
+
readonly selection: 11;
|
|
57
|
+
readonly marquee: 12;
|
|
58
|
+
readonly fadeMs: 13;
|
|
59
|
+
readonly dragEvents: 14;
|
|
60
|
+
readonly grid: 15;
|
|
61
|
+
readonly gridSpacing: 16;
|
|
62
|
+
readonly textureBudget: 17;
|
|
63
|
+
readonly zoomSpeed: 18;
|
|
64
|
+
readonly wheelZoomMax: 19;
|
|
65
|
+
readonly gridMajor: 20;
|
|
66
|
+
readonly gridFadeStart: 21;
|
|
67
|
+
readonly gridFadeEnd: 22;
|
|
68
|
+
};
|
|
69
|
+
export declare const THEME_OPTION: {
|
|
70
|
+
readonly background: 30;
|
|
71
|
+
readonly grid: 31;
|
|
72
|
+
readonly selection: 32;
|
|
73
|
+
readonly handle: 33;
|
|
74
|
+
readonly guide: 34;
|
|
75
|
+
readonly marquee: 35;
|
|
76
|
+
readonly hover: 36;
|
|
77
|
+
};
|
|
78
|
+
export declare const MOD_SHIFT = 1;
|
|
79
|
+
export declare const MOD_ALT = 2;
|
|
80
|
+
export declare const MOD_CTRL = 4;
|
|
81
|
+
export declare const MOD_META = 8;
|
|
82
|
+
export declare const KEY_SPACE = 1;
|
|
83
|
+
export declare const KEY_ESCAPE = 2;
|
|
84
|
+
export declare const KEY_MODIFIER = 3;
|
|
85
|
+
export declare const TOOLS: {
|
|
86
|
+
readonly select: 0;
|
|
87
|
+
readonly pan: 1;
|
|
88
|
+
readonly none: 2;
|
|
89
|
+
};
|
|
90
|
+
export declare const POINTER_TYPES: {
|
|
91
|
+
readonly mouse: 0;
|
|
92
|
+
readonly pen: 1;
|
|
93
|
+
readonly touch: 2;
|
|
94
|
+
};
|
|
95
|
+
/** Engine cursor codes → CSS cursors. */
|
|
96
|
+
export declare const CURSORS: string[];
|
|
97
|
+
export declare const FRAME_RENDER = 1;
|
|
98
|
+
export declare const FRAME_MORE = 2;
|
|
99
|
+
export declare const FRAME_HOLES = 4;
|
|
100
|
+
/**
|
|
101
|
+
* Parses a colour to 0xRRGGBBAA (unsigned). Reads numbers (already packed),
|
|
102
|
+
* every CSS named colour, `transparent`, `#rgb`/`#rgba`/`#rrggbb`/`#rrggbbaa`,
|
|
103
|
+
* and `rgb()`/`rgba()`/`hsl()`/`hsla()` in comma or space syntax with
|
|
104
|
+
* percentages, hue units and `/ alpha`. In a browser, other colour spaces
|
|
105
|
+
* and `color-mix()` are resolved by painting them ({@link paintedColor}).
|
|
106
|
+
* Throws on anything else (`currentColor`, `var()`, and any of those outside
|
|
107
|
+
* a browser).
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseColor(c: Color | undefined | null, fallback?: number): number;
|
|
110
|
+
/** Behaviour flags with their defaults. */
|
|
111
|
+
export declare function encodeFlags(f: ItemFlags): number;
|
|
112
|
+
/**
|
|
113
|
+
* SVG path data → engine path commands (absolute M/L/Q/C/Z). Supports every SVG
|
|
114
|
+
* command, relative forms and implicit repeats; arcs become cubics.
|
|
115
|
+
*/
|
|
116
|
+
export declare function parseSvgPath(d: string): number[];
|
|
117
|
+
/** A polyline ([x0, y0, x1, y1, …]) → engine path commands. */
|
|
118
|
+
export declare function polylineCommands(points: ArrayLike<number>, closed?: boolean): number[];
|
|
119
|
+
/** String ids ↔ u32 handles. Freed handles are reused only after `flush` (the end of a patch). */
|
|
120
|
+
export declare class IdRegistry {
|
|
121
|
+
#private;
|
|
122
|
+
get size(): number;
|
|
123
|
+
get(id: string): number | undefined;
|
|
124
|
+
/** The handle for `id`, assigning one if it has none. */
|
|
125
|
+
ensure(id: string): number;
|
|
126
|
+
id(handle: number): string | undefined;
|
|
127
|
+
ids(handles: ArrayLike<number>): string[];
|
|
128
|
+
release(id: string): number | undefined;
|
|
129
|
+
clear(): void;
|
|
130
|
+
/** Makes released handles reusable. */
|
|
131
|
+
flush(): void;
|
|
132
|
+
}
|
|
133
|
+
export interface EncodedPatch {
|
|
134
|
+
ops: Float64Array;
|
|
135
|
+
paths: Float32Array;
|
|
136
|
+
records: number;
|
|
137
|
+
}
|
|
138
|
+
/** Encodes patches; keeps the id registries and a per-item path parse cache. */
|
|
139
|
+
export declare class PatchEncoder {
|
|
140
|
+
#private;
|
|
141
|
+
readonly items: IdRegistry;
|
|
142
|
+
readonly textures: IdRegistry;
|
|
143
|
+
encode(patch: Patch): EncodedPatch;
|
|
144
|
+
}
|
|
145
|
+
/** Every item kind the encoder accepts (for exhaustiveness in callers). */
|
|
146
|
+
export type EncodableItem = CanvasItem;
|