@grida/canvas-wasm 0.0.56 → 0.0.57
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/grida-canvas-wasm.js +1 -1
- package/dist/grida_canvas_wasm.wasm +0 -0
- package/dist/index.d.mts +350 -245
- package/dist/index.d.ts +350 -245
- package/dist/index.js +344 -134
- package/dist/index.mjs +343 -133
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,274 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/// - https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts
|
|
7
|
-
///
|
|
1
|
+
declare namespace fonts {
|
|
2
|
+
export namespace types {
|
|
3
|
+
// ====================================================================================================
|
|
4
|
+
// #region: Core Type Definitions
|
|
5
|
+
// ====================================================================================================
|
|
8
6
|
|
|
7
|
+
/** Axis value pair for variable font recipes */
|
|
8
|
+
export interface AxisValue {
|
|
9
|
+
tag: string;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
9
12
|
|
|
13
|
+
/** Family-level axis information (no default values as they vary per face) */
|
|
14
|
+
export interface FontFamilyAxis {
|
|
15
|
+
tag: string;
|
|
16
|
+
name: string;
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
}
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
/** Face-specific axis information (includes default values) */
|
|
22
|
+
export interface FontAxis {
|
|
23
|
+
tag: string;
|
|
24
|
+
name: string;
|
|
25
|
+
min: number;
|
|
26
|
+
default: number;
|
|
27
|
+
max: number;
|
|
28
|
+
}
|
|
12
29
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
/** Variable font recipe */
|
|
31
|
+
export interface VfRecipe {
|
|
32
|
+
axis_values: Array<AxisValue>;
|
|
33
|
+
}
|
|
16
34
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
/** Italic recipe for UI consumption */
|
|
36
|
+
export interface ItalicRecipe {
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
is_italic: boolean;
|
|
40
|
+
face_id: string;
|
|
41
|
+
vf_recipe?: VfRecipe;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Italic capability analysis for UI consumption */
|
|
45
|
+
export interface ItalicCapability {
|
|
46
|
+
has_italic: boolean;
|
|
47
|
+
has_upright: boolean;
|
|
48
|
+
strategy: string;
|
|
49
|
+
recipes: Array<ItalicRecipe>;
|
|
50
|
+
scenario: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Variable font instance information */
|
|
54
|
+
export interface FontInstance {
|
|
55
|
+
name: string;
|
|
56
|
+
postscript_name: string | null;
|
|
57
|
+
coordinates: Record<string, number>;
|
|
58
|
+
}
|
|
30
59
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
/** Font feature information for UI consumption */
|
|
61
|
+
export interface FontFeature {
|
|
62
|
+
tag: string;
|
|
63
|
+
name: string;
|
|
64
|
+
tooltip: string | null;
|
|
65
|
+
sample_text: string | null;
|
|
66
|
+
glyphs: string[];
|
|
67
|
+
script: string;
|
|
68
|
+
language: string;
|
|
69
|
+
source_table: string;
|
|
70
|
+
}
|
|
39
71
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
72
|
+
/** Face-level information for UI consumption */
|
|
73
|
+
export interface FontFaceInfo {
|
|
74
|
+
face_id: string;
|
|
75
|
+
family_name: string;
|
|
76
|
+
subfamily_name: string;
|
|
77
|
+
postscript_name: string;
|
|
78
|
+
weight_class: number;
|
|
79
|
+
width_class: number;
|
|
80
|
+
is_variable: boolean;
|
|
81
|
+
is_strict_italic: boolean;
|
|
82
|
+
axes: Array<FontAxis>;
|
|
83
|
+
instances?: Array<FontInstance>;
|
|
84
|
+
features: Array<FontFeature>;
|
|
85
|
+
}
|
|
43
86
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
87
|
+
/** Font style instance for UI consumption */
|
|
88
|
+
export interface FontStyle {
|
|
89
|
+
name: string;
|
|
90
|
+
postscript_name: string | null;
|
|
91
|
+
italic: boolean;
|
|
92
|
+
}
|
|
47
93
|
|
|
48
|
-
|
|
94
|
+
/** Complete family-level analysis result for UI consumption */
|
|
95
|
+
export interface FontFamilyAnalysisResult {
|
|
96
|
+
family_name: string;
|
|
97
|
+
axes: Array<FontFamilyAxis>;
|
|
98
|
+
italic_capability: ItalicCapability;
|
|
99
|
+
faces: Array<FontFaceInfo>;
|
|
100
|
+
styles: Array<FontStyle>;
|
|
101
|
+
}
|
|
49
102
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
103
|
+
export type FontFamilyAnalysisResponse =
|
|
104
|
+
| {
|
|
105
|
+
success: true;
|
|
106
|
+
data: FontFamilyAnalysisResult;
|
|
107
|
+
}
|
|
108
|
+
| FontError;
|
|
53
109
|
|
|
110
|
+
/** Face record for single font parsing */
|
|
111
|
+
export interface FaceRecord {
|
|
112
|
+
face_id: string;
|
|
113
|
+
ps_name: string;
|
|
114
|
+
family_name: string;
|
|
115
|
+
subfamily_name: string;
|
|
116
|
+
is_variable: boolean;
|
|
117
|
+
os2_italic_bit: boolean;
|
|
118
|
+
weight_class: number;
|
|
119
|
+
width_class: number;
|
|
120
|
+
user_font_style_italic: boolean | null;
|
|
121
|
+
axes_count: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Error response for failed operations */
|
|
125
|
+
export interface FontError {
|
|
126
|
+
success: false;
|
|
127
|
+
error: {
|
|
128
|
+
message: string;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ====================================================================================================
|
|
134
|
+
// #region: WASM Function Declarations
|
|
135
|
+
// ====================================================================================================
|
|
136
|
+
|
|
137
|
+
export interface FontsModule {
|
|
54
138
|
// ====================================================================================================
|
|
55
|
-
//
|
|
139
|
+
// #region: Core Font Analysis APIs
|
|
56
140
|
// ====================================================================================================
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Analyzes a font family and returns comprehensive family information as JSON.
|
|
144
|
+
* This is the main API for working with multiple font files under the same family.
|
|
145
|
+
*
|
|
146
|
+
* @param family_name - Family name (can be null for auto-detection)
|
|
147
|
+
* @param font_count - Number of font faces
|
|
148
|
+
* @param face_ids - Array of face IDs (null-terminated strings)
|
|
149
|
+
* @param font_data_ptrs - Array of pointers to font data
|
|
150
|
+
* @param font_data_sizes - Array of font data sizes
|
|
151
|
+
* @param user_italic_flags - Array of user italic declarations (-1 = null, 0 = false, 1 = true)
|
|
152
|
+
* @returns JSON string containing {@link FontFamilyAnalysisResponse}
|
|
153
|
+
*/
|
|
154
|
+
_grida_fonts_analyze_family(
|
|
155
|
+
family_name: number | null,
|
|
156
|
+
font_count: number,
|
|
157
|
+
face_ids: number,
|
|
158
|
+
font_data_ptrs: number,
|
|
159
|
+
font_data_sizes: number,
|
|
160
|
+
user_italic_flags: number | null
|
|
161
|
+
): number;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Parses a single font file and extracts basic metadata.
|
|
165
|
+
* This is exposed for fast, single font analysis.
|
|
166
|
+
*
|
|
167
|
+
* @param font_data_ptr - Pointer to font data
|
|
168
|
+
* @param font_data_size - Size of font data
|
|
169
|
+
* @param face_id - Unique identifier for this font face
|
|
170
|
+
* @param user_font_style_italic - User-declared italic style (can be null for auto-detection)
|
|
171
|
+
* @returns JSON string containing FaceRecord
|
|
172
|
+
*/
|
|
173
|
+
_grida_fonts_parse_font(
|
|
174
|
+
font_data_ptr: number,
|
|
175
|
+
font_data_size: number,
|
|
176
|
+
face_id: number,
|
|
177
|
+
user_font_style_italic: number | null
|
|
178
|
+
): number;
|
|
62
179
|
|
|
63
180
|
// ====================================================================================================
|
|
64
|
-
//
|
|
181
|
+
// #region: Utility Functions
|
|
65
182
|
// ====================================================================================================
|
|
66
|
-
_tick(state: GridaCanvasWebGlApplicationPtr, time: number): void;
|
|
67
|
-
_resize_surface(
|
|
68
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
69
|
-
width: number,
|
|
70
|
-
height: number
|
|
71
|
-
): void;
|
|
72
|
-
_redraw(state: GridaCanvasWebGlApplicationPtr): void;
|
|
73
|
-
_load_scene_json(
|
|
74
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
75
|
-
ptr: number,
|
|
76
|
-
len: number
|
|
77
|
-
): void;
|
|
78
|
-
_load_dummy_scene(state: GridaCanvasWebGlApplicationPtr): void;
|
|
79
|
-
_load_benchmark_scene(
|
|
80
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
81
|
-
cols: number,
|
|
82
|
-
rows: number
|
|
83
|
-
): void;
|
|
84
|
-
_pointer_move(
|
|
85
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
86
|
-
x: number,
|
|
87
|
-
y: number
|
|
88
|
-
): void;
|
|
89
|
-
_add_font(
|
|
90
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
91
|
-
family_ptr: number,
|
|
92
|
-
family_len: number,
|
|
93
|
-
data_ptr: number,
|
|
94
|
-
data_len: number
|
|
95
|
-
): void;
|
|
96
|
-
_add_image(
|
|
97
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
98
|
-
data_ptr: number,
|
|
99
|
-
data_len: number
|
|
100
|
-
): Ptr;
|
|
101
|
-
_has_missing_fonts(state: GridaCanvasWebGlApplicationPtr): boolean;
|
|
102
|
-
_list_missing_fonts(state: GridaCanvasWebGlApplicationPtr): Ptr;
|
|
103
|
-
_list_available_fonts(state: GridaCanvasWebGlApplicationPtr): Ptr;
|
|
104
|
-
_set_default_fallback_fonts(
|
|
105
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
106
|
-
ptr: number,
|
|
107
|
-
len: number
|
|
108
|
-
): void;
|
|
109
|
-
_get_default_fallback_fonts(state: GridaCanvasWebGlApplicationPtr): Ptr;
|
|
110
|
-
_set_main_camera_transform(
|
|
111
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
112
|
-
a: number,
|
|
113
|
-
c: number,
|
|
114
|
-
e: number,
|
|
115
|
-
b: number,
|
|
116
|
-
d: number,
|
|
117
|
-
f: number
|
|
118
|
-
): void;
|
|
119
|
-
_get_node_id_from_point(
|
|
120
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
121
|
-
x: number,
|
|
122
|
-
y: number
|
|
123
|
-
): Ptr;
|
|
124
|
-
_get_node_ids_from_point(
|
|
125
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
126
|
-
x: number,
|
|
127
|
-
y: number
|
|
128
|
-
): Ptr;
|
|
129
|
-
_get_node_ids_from_envelope(
|
|
130
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
131
|
-
x: number,
|
|
132
|
-
y: number,
|
|
133
|
-
w: number,
|
|
134
|
-
h: number
|
|
135
|
-
): Ptr;
|
|
136
|
-
_get_node_absolute_bounding_box(
|
|
137
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
138
|
-
ptr: number,
|
|
139
|
-
len: number
|
|
140
|
-
): Ptr;
|
|
141
183
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Frees memory allocated by WASM functions.
|
|
186
|
+
*
|
|
187
|
+
* @param ptr - Pointer to memory allocated by a WASM function
|
|
188
|
+
*/
|
|
189
|
+
_grida_fonts_free(ptr: number): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Returns the version of the font parsing library.
|
|
193
|
+
* This is a ping function to verify the WASM module is working.
|
|
194
|
+
*
|
|
195
|
+
* @returns Version string
|
|
196
|
+
*/
|
|
197
|
+
_grida_fonts_version(): number;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
149
200
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
201
|
+
///
|
|
202
|
+
/// @grida/canvas-wasm grida-canvas-wasm.js typescript definitions
|
|
203
|
+
/// this is NOT generated by emscripten. update manually.
|
|
204
|
+
///
|
|
205
|
+
/// see also:
|
|
206
|
+
/// - https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts
|
|
207
|
+
///
|
|
155
208
|
|
|
156
|
-
_command(
|
|
157
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
158
|
-
id: number,
|
|
159
|
-
a: number,
|
|
160
|
-
b: number
|
|
161
|
-
): void;
|
|
162
209
|
|
|
163
|
-
_highlight_strokes(
|
|
164
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
165
|
-
ptr: number,
|
|
166
|
-
len: number
|
|
167
|
-
): void;
|
|
168
210
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
_devtools_rendering_set_show_tiles(
|
|
173
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
174
|
-
show: boolean
|
|
175
|
-
): void;
|
|
176
|
-
_devtools_rendering_set_show_fps_meter(
|
|
177
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
178
|
-
show: boolean
|
|
179
|
-
): void;
|
|
180
|
-
_devtools_rendering_set_show_stats(
|
|
181
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
182
|
-
show: boolean
|
|
183
|
-
): void;
|
|
184
|
-
_devtools_rendering_set_show_hit_testing(
|
|
185
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
186
|
-
show: boolean
|
|
187
|
-
): void;
|
|
188
|
-
_devtools_rendering_set_show_ruler(
|
|
189
|
-
state: GridaCanvasWebGlApplicationPtr,
|
|
190
|
-
show: boolean
|
|
191
|
-
): void;
|
|
211
|
+
declare function createGridaCanvas$1(moduleArg?: {
|
|
212
|
+
locateFile?: (path: string, scriptDirectory: string) => string;
|
|
213
|
+
}): Promise<createGridaCanvas$1.GridaCanvasWasmBindings>;
|
|
192
214
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
215
|
+
declare namespace createGridaCanvas$1 {
|
|
216
|
+
interface GridaCanvasWasmBindings
|
|
217
|
+
extends emscripten.emscripten_EXPORTED_RUNTIME_METHODS,
|
|
218
|
+
canvas.CanvasModule,
|
|
219
|
+
fonts.FontsModule {}
|
|
198
220
|
}
|
|
199
221
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
222
|
+
declare class FontsAPI {
|
|
223
|
+
private module;
|
|
224
|
+
constructor(module: any);
|
|
203
225
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* @
|
|
226
|
+
* Allocates memory for a string and returns pointer and length.
|
|
227
|
+
* @param txt - String to allocate
|
|
228
|
+
* @returns [pointer, length] tuple
|
|
229
|
+
*/
|
|
230
|
+
private _alloc_string;
|
|
231
|
+
/**
|
|
232
|
+
* Frees memory allocated for a string.
|
|
233
|
+
* @param ptr - Pointer to free
|
|
234
|
+
* @param len - Length of allocated memory
|
|
235
|
+
*/
|
|
236
|
+
private _free_string;
|
|
237
|
+
/**
|
|
238
|
+
* Allocates memory for binary data and returns pointer.
|
|
239
|
+
* @param data - Binary data to allocate
|
|
240
|
+
* @returns [pointer, length] tuple
|
|
241
|
+
*/
|
|
242
|
+
private _alloc_data;
|
|
243
|
+
/**
|
|
244
|
+
* Converts a WASM-allocated string to JavaScript string and frees the WASM memory.
|
|
245
|
+
* @param ptr - Pointer to WASM string
|
|
246
|
+
* @returns JavaScript string
|
|
247
|
+
*/
|
|
248
|
+
private _string_from_wasm;
|
|
249
|
+
/**
|
|
250
|
+
* Analyzes a font family with JavaScript-friendly interface.
|
|
251
|
+
* This is the main API for working with multiple font files under the same family.
|
|
207
252
|
*
|
|
208
|
-
* @
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* locateFile: (file) => `custom-binary-path/${file}`,
|
|
212
|
-
* ```
|
|
253
|
+
* @param fontFaces - Array of font face objects
|
|
254
|
+
* @param familyName - Family name (optional)
|
|
255
|
+
* @returns Promise resolving to FontAnalysisResult or FontError
|
|
213
256
|
*/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
x: number;
|
|
220
|
-
y: number;
|
|
221
|
-
width: number;
|
|
222
|
-
height: number;
|
|
223
|
-
};
|
|
224
|
-
type ExportConstraints = {
|
|
225
|
-
type: "SCALE" | "WIDTH" | "HEIGHT";
|
|
226
|
-
value: number;
|
|
227
|
-
};
|
|
228
|
-
type ExportAs = ExportAsImage | ExportAsPDF | ExportAsSVG;
|
|
229
|
-
type ExportAsPDF = {
|
|
230
|
-
format: "PDF";
|
|
231
|
-
};
|
|
232
|
-
type ExportAsSVG = {
|
|
233
|
-
format: "SVG";
|
|
234
|
-
};
|
|
235
|
-
type ExportAsImage = {
|
|
236
|
-
format: "PNG" | "JPEG" | "WEBP" | "BMP";
|
|
237
|
-
constraints: ExportConstraints;
|
|
238
|
-
};
|
|
239
|
-
type FontKey = {
|
|
240
|
-
family: string;
|
|
241
|
-
};
|
|
242
|
-
type VectorNetworkVertex = Vector2;
|
|
243
|
-
type VectorNetworkSegment = {
|
|
244
|
-
a: number;
|
|
245
|
-
b: number;
|
|
246
|
-
ta: Vector2;
|
|
247
|
-
tb: Vector2;
|
|
248
|
-
};
|
|
249
|
-
interface VectorNetwork {
|
|
250
|
-
vertices: VectorNetworkVertex[];
|
|
251
|
-
segments: VectorNetworkSegment[];
|
|
252
|
-
}
|
|
253
|
-
declare function init(opts?: GridaCanvasModuleInitOptions): Promise<ApplicationFactory>;
|
|
254
|
-
interface CreateWebGLCanvasSurfaceOptions {
|
|
257
|
+
analyzeFamily(fontFaces: Array<{
|
|
258
|
+
faceId: string;
|
|
259
|
+
data: ArrayBuffer | Uint8Array;
|
|
260
|
+
userFontStyleItalic?: boolean;
|
|
261
|
+
}>, familyName?: string): Promise<fonts.types.FontFamilyAnalysisResponse>;
|
|
255
262
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
263
|
+
* Parses a single font file with JavaScript-friendly interface.
|
|
264
|
+
* This is exposed for fast, single font analysis.
|
|
265
|
+
*
|
|
266
|
+
* @param fontData - Font data as ArrayBuffer or Uint8Array
|
|
267
|
+
* @param faceId - Unique identifier for this font face
|
|
268
|
+
* @param userFontStyleItalic - User-declared italic style (optional)
|
|
269
|
+
* @returns Promise resolving to FaceRecord
|
|
258
270
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
271
|
+
parseFont(fontData: ArrayBuffer | Uint8Array, faceId: string, userFontStyleItalic?: boolean): Promise<fonts.types.FaceRecord>;
|
|
272
|
+
/**
|
|
273
|
+
* Gets the version of the font parsing library.
|
|
274
|
+
* This is a ping function to verify the WASM module is working.
|
|
275
|
+
*
|
|
276
|
+
* @returns Version string
|
|
277
|
+
*/
|
|
278
|
+
getVersion(): string;
|
|
266
279
|
}
|
|
267
|
-
|
|
280
|
+
|
|
281
|
+
declare class Scene {
|
|
268
282
|
private appptr;
|
|
269
283
|
private module;
|
|
284
|
+
readonly fontskit: FontsAPI;
|
|
270
285
|
constructor(module: createGridaCanvas.GridaCanvasWasmBindings, ptr: number);
|
|
286
|
+
/**
|
|
287
|
+
* Allocates memory for a string and returns pointer and length.
|
|
288
|
+
* @param txt - String to allocate
|
|
289
|
+
* @returns [pointer, length] tuple
|
|
290
|
+
*/
|
|
271
291
|
_alloc_string(txt: string): [number, number];
|
|
292
|
+
/**
|
|
293
|
+
* Frees memory allocated for a string.
|
|
294
|
+
* @param ptr - Pointer to free
|
|
295
|
+
* @param len - Length of allocated memory
|
|
296
|
+
*/
|
|
272
297
|
_free_string(ptr: number, len: number): void;
|
|
273
298
|
/**
|
|
274
299
|
* Load a scene from a JSON string.
|
|
@@ -295,8 +320,8 @@ declare class Grida2D {
|
|
|
295
320
|
addFont(family: string, data: Uint8Array): void;
|
|
296
321
|
addImage(data: Uint8Array): string;
|
|
297
322
|
hasMissingFonts(): boolean;
|
|
298
|
-
listMissingFonts(): FontKey[];
|
|
299
|
-
listAvailableFonts(): FontKey[];
|
|
323
|
+
listMissingFonts(): types.FontKey[];
|
|
324
|
+
listAvailableFonts(): types.FontKey[];
|
|
300
325
|
setFallbackFonts(fonts: string[]): void;
|
|
301
326
|
getFallbackFonts(): string[];
|
|
302
327
|
/**
|
|
@@ -313,16 +338,16 @@ declare class Grida2D {
|
|
|
313
338
|
*/
|
|
314
339
|
resize(width: number, height: number): void;
|
|
315
340
|
redraw(): void;
|
|
316
|
-
setMainCameraTransform(transform: Transform2D): void;
|
|
341
|
+
setMainCameraTransform(transform: types.Transform2D): void;
|
|
317
342
|
getNodeIdFromPoint(x: number, y: number): string | null;
|
|
318
343
|
getNodeIdsFromPoint(x: number, y: number): string[];
|
|
319
|
-
getNodeIdsFromEnvelope(envelope: Rectangle): string[];
|
|
320
|
-
getNodeAbsoluteBoundingBox(id: string): Rectangle | null;
|
|
344
|
+
getNodeIdsFromEnvelope(envelope: types.Rectangle): string[];
|
|
345
|
+
getNodeAbsoluteBoundingBox(id: string): types.Rectangle | null;
|
|
321
346
|
/**
|
|
322
347
|
* @deprecated not fully implemented yet
|
|
323
348
|
*/
|
|
324
|
-
toVectorNetwork(id: string): VectorNetwork | null;
|
|
325
|
-
exportNodeAs(id: string, format: ExportAs): {
|
|
349
|
+
toVectorNetwork(id: string): types.VectorNetwork | null;
|
|
350
|
+
exportNodeAs(id: string, format: types.ExportAs): {
|
|
326
351
|
data: Uint8Array;
|
|
327
352
|
};
|
|
328
353
|
execCommand(command: "ZoomIn" | "ZoomOut"): void;
|
|
@@ -367,4 +392,84 @@ declare class Grida2D {
|
|
|
367
392
|
devtools_rendering_set_show_ruler(show: boolean): void;
|
|
368
393
|
}
|
|
369
394
|
|
|
370
|
-
|
|
395
|
+
declare const version: string;
|
|
396
|
+
interface GridaCanvasModuleInitOptions {
|
|
397
|
+
/**
|
|
398
|
+
* This callback will be invoked when the loader needs to fetch a file (e.g.
|
|
399
|
+
* the blob of WASM code). The correct url prefix should be applied.
|
|
400
|
+
* @param file - the name of the file that is about to be loaded.
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* locateFile: (file) => `https://unpkg.com/@grida/canvas-wasm@$latest/bin/${file}`,
|
|
405
|
+
* locateFile: (file) => `custom-binary-path/${file}`,
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
locateFile(file: string, version: string): string;
|
|
409
|
+
}
|
|
410
|
+
declare namespace types {
|
|
411
|
+
type Vector2 = [number, number];
|
|
412
|
+
type Transform2D = [
|
|
413
|
+
[
|
|
414
|
+
number,
|
|
415
|
+
number,
|
|
416
|
+
number
|
|
417
|
+
],
|
|
418
|
+
[
|
|
419
|
+
number,
|
|
420
|
+
number,
|
|
421
|
+
number
|
|
422
|
+
]
|
|
423
|
+
];
|
|
424
|
+
type Rectangle = {
|
|
425
|
+
x: number;
|
|
426
|
+
y: number;
|
|
427
|
+
width: number;
|
|
428
|
+
height: number;
|
|
429
|
+
};
|
|
430
|
+
type ExportConstraints = {
|
|
431
|
+
type: "SCALE" | "WIDTH" | "HEIGHT";
|
|
432
|
+
value: number;
|
|
433
|
+
};
|
|
434
|
+
type ExportAs = ExportAsImage | ExportAsPDF | ExportAsSVG;
|
|
435
|
+
type ExportAsPDF = {
|
|
436
|
+
format: "PDF";
|
|
437
|
+
};
|
|
438
|
+
type ExportAsSVG = {
|
|
439
|
+
format: "SVG";
|
|
440
|
+
};
|
|
441
|
+
type ExportAsImage = {
|
|
442
|
+
format: "PNG" | "JPEG" | "WEBP" | "BMP";
|
|
443
|
+
constraints: ExportConstraints;
|
|
444
|
+
};
|
|
445
|
+
type FontKey = {
|
|
446
|
+
family: string;
|
|
447
|
+
};
|
|
448
|
+
type VectorNetworkVertex = Vector2;
|
|
449
|
+
type VectorNetworkSegment = {
|
|
450
|
+
a: number;
|
|
451
|
+
b: number;
|
|
452
|
+
ta: Vector2;
|
|
453
|
+
tb: Vector2;
|
|
454
|
+
};
|
|
455
|
+
interface VectorNetwork {
|
|
456
|
+
vertices: VectorNetworkVertex[];
|
|
457
|
+
segments: VectorNetworkSegment[];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
declare function init(opts?: GridaCanvasModuleInitOptions): Promise<ApplicationFactory>;
|
|
461
|
+
interface CreateWebGLCanvasSurfaceOptions {
|
|
462
|
+
/**
|
|
463
|
+
* when true, embedded fonts will be registered and used for text rendering.
|
|
464
|
+
* @default true
|
|
465
|
+
*/
|
|
466
|
+
use_embedded_fonts?: boolean;
|
|
467
|
+
}
|
|
468
|
+
declare class ApplicationFactory {
|
|
469
|
+
readonly module: createGridaCanvas$1.GridaCanvasWasmBindings;
|
|
470
|
+
constructor(module: createGridaCanvas$1.GridaCanvasWasmBindings);
|
|
471
|
+
createWebGLCanvasSurface(canvas: HTMLCanvasElement, options?: CreateWebGLCanvasSurfaceOptions): Scene;
|
|
472
|
+
createWebGLCanvasSurfaceById(htmlcanvasid: string): Scene;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export { type GridaCanvasModuleInitOptions, Scene, init as default, types, version };
|