@grida/canvas-wasm 0.0.1 → 0.0.2
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/index.d.mts +143 -2
- package/dist/index.d.ts +143 -2
- package/dist/index.js +113 -4
- package/dist/index.mjs +113 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
+
declare function createGridaCanvas(moduleArg?: {
|
|
2
|
+
locateFile?: (path: string, scriptDirectory: string) => string;
|
|
3
|
+
}): Promise<createGridaCanvas.GridaCanvasWasmBindings>;
|
|
4
|
+
|
|
5
|
+
declare namespace createGridaCanvas {
|
|
6
|
+
interface GridaCanvasWasmBindings {
|
|
7
|
+
// ====================================================================================================
|
|
8
|
+
// EMSCRIPTEN EXPOSED METHODS
|
|
9
|
+
// ====================================================================================================
|
|
10
|
+
GL: {
|
|
11
|
+
registerContext(
|
|
12
|
+
context: WebGLRenderingContext,
|
|
13
|
+
options: { majorVersion: number }
|
|
14
|
+
): number;
|
|
15
|
+
makeContextCurrent(handle: number): void;
|
|
16
|
+
};
|
|
17
|
+
stringToUTF8(str: string, outPtr: number, maxBytesToWrite: number): void;
|
|
18
|
+
lengthBytesUTF8(str: string): number;
|
|
19
|
+
___wbindgen_malloc(a0: number, a1: number): number;
|
|
20
|
+
___wbindgen_free(a0: number, a1: number, a2: number): void;
|
|
21
|
+
___wbindgen_realloc(a0: number, a1: number, a2: number, a3: number): number;
|
|
22
|
+
|
|
23
|
+
// core memory wrapper
|
|
24
|
+
_allocate(len: number): number;
|
|
25
|
+
_deallocate(ptr: number, len: number): void;
|
|
26
|
+
|
|
27
|
+
// ====================================================================================================
|
|
28
|
+
// INITIALIZATION
|
|
29
|
+
// ====================================================================================================
|
|
30
|
+
_init(width: number, height: number): GridaCanvasWebGlApplicationPtr;
|
|
31
|
+
|
|
32
|
+
// ====================================================================================================
|
|
33
|
+
// APPLICATION METHODS
|
|
34
|
+
// ====================================================================================================
|
|
35
|
+
_tick(state: GridaCanvasWebGlApplicationPtr): void;
|
|
36
|
+
_resize_surface(
|
|
37
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
38
|
+
width: number,
|
|
39
|
+
height: number
|
|
40
|
+
): void;
|
|
41
|
+
_redraw(state: GridaCanvasWebGlApplicationPtr): void;
|
|
42
|
+
_load_scene_json(
|
|
43
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
44
|
+
ptr: number,
|
|
45
|
+
len: number
|
|
46
|
+
): void;
|
|
47
|
+
_load_dummy_scene(state: GridaCanvasWebGlApplicationPtr): void;
|
|
48
|
+
_load_benchmark_scene(
|
|
49
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
50
|
+
cols: number,
|
|
51
|
+
rows: number
|
|
52
|
+
): void;
|
|
53
|
+
_pointer_move(
|
|
54
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
55
|
+
x: number,
|
|
56
|
+
y: number
|
|
57
|
+
): void;
|
|
58
|
+
_command(
|
|
59
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
60
|
+
id: number,
|
|
61
|
+
a: number,
|
|
62
|
+
b: number
|
|
63
|
+
): void;
|
|
64
|
+
_devtools_rendering_set_show_tiles(
|
|
65
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
66
|
+
show: boolean
|
|
67
|
+
): void;
|
|
68
|
+
_devtools_rendering_set_show_fps_meter(
|
|
69
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
70
|
+
show: boolean
|
|
71
|
+
): void;
|
|
72
|
+
_devtools_rendering_set_show_stats(
|
|
73
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
74
|
+
show: boolean
|
|
75
|
+
): void;
|
|
76
|
+
_devtools_rendering_set_show_hit_testing(
|
|
77
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
78
|
+
show: boolean
|
|
79
|
+
): void;
|
|
80
|
+
_devtools_rendering_set_show_ruler(
|
|
81
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
82
|
+
show: boolean
|
|
83
|
+
): void;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type GridaCanvasWebGlApplicationPtr = number;
|
|
88
|
+
|
|
1
89
|
interface GridaCanvasInitOptions {
|
|
2
90
|
/**
|
|
3
91
|
* This callback will be invoked when the loader needs to fetch a file (e.g.
|
|
@@ -16,17 +104,70 @@ interface GridaCanvasInitOptions {
|
|
|
16
104
|
declare function init(opts?: GridaCanvasInitOptions): Promise<ApplicationFactory>;
|
|
17
105
|
declare class ApplicationFactory {
|
|
18
106
|
private readonly module;
|
|
19
|
-
constructor(module: GridaCanvasWasmBindings);
|
|
107
|
+
constructor(module: createGridaCanvas.GridaCanvasWasmBindings);
|
|
108
|
+
createCanvasSurface(htmlcanvasid: string): Grida2D;
|
|
20
109
|
createSurface(width: number, height: number): Grida2D;
|
|
21
110
|
}
|
|
22
111
|
declare class Grida2D {
|
|
23
112
|
private ptr;
|
|
24
113
|
private module;
|
|
25
|
-
constructor(module: GridaCanvasWasmBindings, ptr:
|
|
114
|
+
constructor(module: createGridaCanvas.GridaCanvasWasmBindings, ptr: number);
|
|
115
|
+
_alloc_string(txt: string): [number, number];
|
|
116
|
+
_free_string(ptr: number, len: number): void;
|
|
117
|
+
/**
|
|
118
|
+
* Load a scene from a JSON string.
|
|
119
|
+
* @param data - The JSON string to load.
|
|
120
|
+
*/
|
|
121
|
+
loadScene(data: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated - test use only
|
|
124
|
+
*/
|
|
125
|
+
loadDummyScene(): void;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated - test use only
|
|
128
|
+
*/
|
|
129
|
+
loadBenchmarkScene(cols: number, rows: number): void;
|
|
130
|
+
/**
|
|
131
|
+
* Tick the application clock.
|
|
132
|
+
* bind this to requestAnimationFrame loop or similar
|
|
133
|
+
*/
|
|
26
134
|
tick(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Resize the surface.
|
|
137
|
+
* @param width - The width of the surface.
|
|
138
|
+
* @param height - The height of the surface.
|
|
139
|
+
*/
|
|
27
140
|
resize(width: number, height: number): void;
|
|
28
141
|
redraw(): void;
|
|
29
142
|
execCommand(command: "ZoomIn" | "ZoomOut"): void;
|
|
143
|
+
execCommandPan(tx: number, ty: number): void;
|
|
144
|
+
execCommandZoomDelta(tz: number): void;
|
|
145
|
+
pointermove(x: number, y: number): void;
|
|
146
|
+
/**
|
|
147
|
+
* Set the visibility of the tiles.
|
|
148
|
+
* @param show - The visibility of the tiles.
|
|
149
|
+
*/
|
|
150
|
+
devtools_rendering_set_show_tiles(show: boolean): void;
|
|
151
|
+
/**
|
|
152
|
+
* Set the visibility of the FPS meter.
|
|
153
|
+
* @param show - The visibility of the FPS meter.
|
|
154
|
+
*/
|
|
155
|
+
devtools_rendering_set_show_fps_meter(show: boolean): void;
|
|
156
|
+
/**
|
|
157
|
+
* Set the visibility of the stats.
|
|
158
|
+
* @param show - The visibility of the stats.
|
|
159
|
+
*/
|
|
160
|
+
devtools_rendering_set_show_stats(show: boolean): void;
|
|
161
|
+
/**
|
|
162
|
+
* Set the visibility of the hit testing.
|
|
163
|
+
* @param show - The visibility of the hit testing.
|
|
164
|
+
*/
|
|
165
|
+
devtools_rendering_set_show_hit_testing(show: boolean): void;
|
|
166
|
+
/**
|
|
167
|
+
* Set the visibility of the ruler.
|
|
168
|
+
* @param show - The visibility of the ruler.
|
|
169
|
+
*/
|
|
170
|
+
devtools_rendering_set_show_ruler(show: boolean): void;
|
|
30
171
|
}
|
|
31
172
|
|
|
32
173
|
export { init as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
+
declare function createGridaCanvas(moduleArg?: {
|
|
2
|
+
locateFile?: (path: string, scriptDirectory: string) => string;
|
|
3
|
+
}): Promise<createGridaCanvas.GridaCanvasWasmBindings>;
|
|
4
|
+
|
|
5
|
+
declare namespace createGridaCanvas {
|
|
6
|
+
interface GridaCanvasWasmBindings {
|
|
7
|
+
// ====================================================================================================
|
|
8
|
+
// EMSCRIPTEN EXPOSED METHODS
|
|
9
|
+
// ====================================================================================================
|
|
10
|
+
GL: {
|
|
11
|
+
registerContext(
|
|
12
|
+
context: WebGLRenderingContext,
|
|
13
|
+
options: { majorVersion: number }
|
|
14
|
+
): number;
|
|
15
|
+
makeContextCurrent(handle: number): void;
|
|
16
|
+
};
|
|
17
|
+
stringToUTF8(str: string, outPtr: number, maxBytesToWrite: number): void;
|
|
18
|
+
lengthBytesUTF8(str: string): number;
|
|
19
|
+
___wbindgen_malloc(a0: number, a1: number): number;
|
|
20
|
+
___wbindgen_free(a0: number, a1: number, a2: number): void;
|
|
21
|
+
___wbindgen_realloc(a0: number, a1: number, a2: number, a3: number): number;
|
|
22
|
+
|
|
23
|
+
// core memory wrapper
|
|
24
|
+
_allocate(len: number): number;
|
|
25
|
+
_deallocate(ptr: number, len: number): void;
|
|
26
|
+
|
|
27
|
+
// ====================================================================================================
|
|
28
|
+
// INITIALIZATION
|
|
29
|
+
// ====================================================================================================
|
|
30
|
+
_init(width: number, height: number): GridaCanvasWebGlApplicationPtr;
|
|
31
|
+
|
|
32
|
+
// ====================================================================================================
|
|
33
|
+
// APPLICATION METHODS
|
|
34
|
+
// ====================================================================================================
|
|
35
|
+
_tick(state: GridaCanvasWebGlApplicationPtr): void;
|
|
36
|
+
_resize_surface(
|
|
37
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
38
|
+
width: number,
|
|
39
|
+
height: number
|
|
40
|
+
): void;
|
|
41
|
+
_redraw(state: GridaCanvasWebGlApplicationPtr): void;
|
|
42
|
+
_load_scene_json(
|
|
43
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
44
|
+
ptr: number,
|
|
45
|
+
len: number
|
|
46
|
+
): void;
|
|
47
|
+
_load_dummy_scene(state: GridaCanvasWebGlApplicationPtr): void;
|
|
48
|
+
_load_benchmark_scene(
|
|
49
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
50
|
+
cols: number,
|
|
51
|
+
rows: number
|
|
52
|
+
): void;
|
|
53
|
+
_pointer_move(
|
|
54
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
55
|
+
x: number,
|
|
56
|
+
y: number
|
|
57
|
+
): void;
|
|
58
|
+
_command(
|
|
59
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
60
|
+
id: number,
|
|
61
|
+
a: number,
|
|
62
|
+
b: number
|
|
63
|
+
): void;
|
|
64
|
+
_devtools_rendering_set_show_tiles(
|
|
65
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
66
|
+
show: boolean
|
|
67
|
+
): void;
|
|
68
|
+
_devtools_rendering_set_show_fps_meter(
|
|
69
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
70
|
+
show: boolean
|
|
71
|
+
): void;
|
|
72
|
+
_devtools_rendering_set_show_stats(
|
|
73
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
74
|
+
show: boolean
|
|
75
|
+
): void;
|
|
76
|
+
_devtools_rendering_set_show_hit_testing(
|
|
77
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
78
|
+
show: boolean
|
|
79
|
+
): void;
|
|
80
|
+
_devtools_rendering_set_show_ruler(
|
|
81
|
+
state: GridaCanvasWebGlApplicationPtr,
|
|
82
|
+
show: boolean
|
|
83
|
+
): void;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type GridaCanvasWebGlApplicationPtr = number;
|
|
88
|
+
|
|
1
89
|
interface GridaCanvasInitOptions {
|
|
2
90
|
/**
|
|
3
91
|
* This callback will be invoked when the loader needs to fetch a file (e.g.
|
|
@@ -16,17 +104,70 @@ interface GridaCanvasInitOptions {
|
|
|
16
104
|
declare function init(opts?: GridaCanvasInitOptions): Promise<ApplicationFactory>;
|
|
17
105
|
declare class ApplicationFactory {
|
|
18
106
|
private readonly module;
|
|
19
|
-
constructor(module: GridaCanvasWasmBindings);
|
|
107
|
+
constructor(module: createGridaCanvas.GridaCanvasWasmBindings);
|
|
108
|
+
createCanvasSurface(htmlcanvasid: string): Grida2D;
|
|
20
109
|
createSurface(width: number, height: number): Grida2D;
|
|
21
110
|
}
|
|
22
111
|
declare class Grida2D {
|
|
23
112
|
private ptr;
|
|
24
113
|
private module;
|
|
25
|
-
constructor(module: GridaCanvasWasmBindings, ptr:
|
|
114
|
+
constructor(module: createGridaCanvas.GridaCanvasWasmBindings, ptr: number);
|
|
115
|
+
_alloc_string(txt: string): [number, number];
|
|
116
|
+
_free_string(ptr: number, len: number): void;
|
|
117
|
+
/**
|
|
118
|
+
* Load a scene from a JSON string.
|
|
119
|
+
* @param data - The JSON string to load.
|
|
120
|
+
*/
|
|
121
|
+
loadScene(data: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated - test use only
|
|
124
|
+
*/
|
|
125
|
+
loadDummyScene(): void;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated - test use only
|
|
128
|
+
*/
|
|
129
|
+
loadBenchmarkScene(cols: number, rows: number): void;
|
|
130
|
+
/**
|
|
131
|
+
* Tick the application clock.
|
|
132
|
+
* bind this to requestAnimationFrame loop or similar
|
|
133
|
+
*/
|
|
26
134
|
tick(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Resize the surface.
|
|
137
|
+
* @param width - The width of the surface.
|
|
138
|
+
* @param height - The height of the surface.
|
|
139
|
+
*/
|
|
27
140
|
resize(width: number, height: number): void;
|
|
28
141
|
redraw(): void;
|
|
29
142
|
execCommand(command: "ZoomIn" | "ZoomOut"): void;
|
|
143
|
+
execCommandPan(tx: number, ty: number): void;
|
|
144
|
+
execCommandZoomDelta(tz: number): void;
|
|
145
|
+
pointermove(x: number, y: number): void;
|
|
146
|
+
/**
|
|
147
|
+
* Set the visibility of the tiles.
|
|
148
|
+
* @param show - The visibility of the tiles.
|
|
149
|
+
*/
|
|
150
|
+
devtools_rendering_set_show_tiles(show: boolean): void;
|
|
151
|
+
/**
|
|
152
|
+
* Set the visibility of the FPS meter.
|
|
153
|
+
* @param show - The visibility of the FPS meter.
|
|
154
|
+
*/
|
|
155
|
+
devtools_rendering_set_show_fps_meter(show: boolean): void;
|
|
156
|
+
/**
|
|
157
|
+
* Set the visibility of the stats.
|
|
158
|
+
* @param show - The visibility of the stats.
|
|
159
|
+
*/
|
|
160
|
+
devtools_rendering_set_show_stats(show: boolean): void;
|
|
161
|
+
/**
|
|
162
|
+
* Set the visibility of the hit testing.
|
|
163
|
+
* @param show - The visibility of the hit testing.
|
|
164
|
+
*/
|
|
165
|
+
devtools_rendering_set_show_hit_testing(show: boolean): void;
|
|
166
|
+
/**
|
|
167
|
+
* Set the visibility of the ruler.
|
|
168
|
+
* @param show - The visibility of the ruler.
|
|
169
|
+
*/
|
|
170
|
+
devtools_rendering_set_show_ruler(show: boolean): void;
|
|
30
171
|
}
|
|
31
172
|
|
|
32
173
|
export { init as default };
|
package/dist/index.js
CHANGED
|
@@ -7384,20 +7384,43 @@ __export(index_exports, {
|
|
|
7384
7384
|
module.exports = __toCommonJS(index_exports);
|
|
7385
7385
|
var import_grida_canvas_wasm = __toESM(require_grida_canvas_wasm());
|
|
7386
7386
|
async function init(opts) {
|
|
7387
|
-
const bindings = await
|
|
7388
|
-
return new ApplicationFactory(
|
|
7387
|
+
const bindings = await (0, import_grida_canvas_wasm.default)({ locateFile: opts == null ? void 0 : opts.locateFile });
|
|
7388
|
+
return new ApplicationFactory(
|
|
7389
|
+
bindings
|
|
7390
|
+
);
|
|
7389
7391
|
}
|
|
7390
7392
|
var ApplicationFactory = class {
|
|
7391
7393
|
module;
|
|
7392
7394
|
constructor(module2) {
|
|
7393
7395
|
this.module = module2;
|
|
7394
7396
|
}
|
|
7397
|
+
createCanvasSurface(htmlcanvasid) {
|
|
7398
|
+
const canvas = document.getElementById(htmlcanvasid);
|
|
7399
|
+
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
7400
|
+
throw new Error(`Element with id ${htmlcanvasid} is not a <canvas>`);
|
|
7401
|
+
}
|
|
7402
|
+
const context = canvas.getContext("webgl2", {
|
|
7403
|
+
antialias: true,
|
|
7404
|
+
depth: true,
|
|
7405
|
+
stencil: true,
|
|
7406
|
+
alpha: true
|
|
7407
|
+
});
|
|
7408
|
+
if (!context) {
|
|
7409
|
+
throw new Error("Failed to get WebGL2 context");
|
|
7410
|
+
}
|
|
7411
|
+
const handle = this.module.GL.registerContext(context, {
|
|
7412
|
+
majorVersion: 2
|
|
7413
|
+
});
|
|
7414
|
+
this.module.GL.makeContextCurrent(handle);
|
|
7415
|
+
const ptr = this.module._init(canvas.width, canvas.height);
|
|
7416
|
+
return new Grida2D(this.module, ptr);
|
|
7417
|
+
}
|
|
7395
7418
|
createSurface(width, height) {
|
|
7396
7419
|
const ptr = this.module._init(width, height);
|
|
7397
7420
|
return new Grida2D(this.module, ptr);
|
|
7398
7421
|
}
|
|
7399
7422
|
};
|
|
7400
|
-
var
|
|
7423
|
+
var ApplicationCommandID = {
|
|
7401
7424
|
ZoomIn: 1,
|
|
7402
7425
|
ZoomOut: 2,
|
|
7403
7426
|
ZoomDelta: 3,
|
|
@@ -7410,9 +7433,48 @@ var Grida2D = class {
|
|
|
7410
7433
|
this.module = module2;
|
|
7411
7434
|
this.ptr = ptr;
|
|
7412
7435
|
}
|
|
7436
|
+
_alloc_string(txt) {
|
|
7437
|
+
const len = this.module.lengthBytesUTF8(txt) + 1;
|
|
7438
|
+
const ptr = this.module._allocate(len);
|
|
7439
|
+
this.module.stringToUTF8(txt, ptr, len);
|
|
7440
|
+
return [ptr, len];
|
|
7441
|
+
}
|
|
7442
|
+
_free_string(ptr, len) {
|
|
7443
|
+
this.module._deallocate(ptr, len);
|
|
7444
|
+
}
|
|
7445
|
+
/**
|
|
7446
|
+
* Load a scene from a JSON string.
|
|
7447
|
+
* @param data - The JSON string to load.
|
|
7448
|
+
*/
|
|
7449
|
+
loadScene(data) {
|
|
7450
|
+
const [ptr, len] = this._alloc_string(data);
|
|
7451
|
+
this.module._load_scene_json(this.ptr, ptr, len - 1);
|
|
7452
|
+
this._free_string(ptr, len);
|
|
7453
|
+
}
|
|
7454
|
+
/**
|
|
7455
|
+
* @deprecated - test use only
|
|
7456
|
+
*/
|
|
7457
|
+
loadDummyScene() {
|
|
7458
|
+
this.module._load_dummy_scene(this.ptr);
|
|
7459
|
+
}
|
|
7460
|
+
/**
|
|
7461
|
+
* @deprecated - test use only
|
|
7462
|
+
*/
|
|
7463
|
+
loadBenchmarkScene(cols, rows) {
|
|
7464
|
+
this.module._load_benchmark_scene(this.ptr, cols, rows);
|
|
7465
|
+
}
|
|
7466
|
+
/**
|
|
7467
|
+
* Tick the application clock.
|
|
7468
|
+
* bind this to requestAnimationFrame loop or similar
|
|
7469
|
+
*/
|
|
7413
7470
|
tick() {
|
|
7414
7471
|
this.module._tick(this.ptr);
|
|
7415
7472
|
}
|
|
7473
|
+
/**
|
|
7474
|
+
* Resize the surface.
|
|
7475
|
+
* @param width - The width of the surface.
|
|
7476
|
+
* @param height - The height of the surface.
|
|
7477
|
+
*/
|
|
7416
7478
|
resize(width, height) {
|
|
7417
7479
|
this.module._resize_surface(this.ptr, width, height);
|
|
7418
7480
|
}
|
|
@@ -7420,6 +7482,53 @@ var Grida2D = class {
|
|
|
7420
7482
|
this.module._redraw(this.ptr);
|
|
7421
7483
|
}
|
|
7422
7484
|
execCommand(command) {
|
|
7423
|
-
this.module._command(this.ptr,
|
|
7485
|
+
this.module._command(this.ptr, ApplicationCommandID[command], 0, 0);
|
|
7486
|
+
}
|
|
7487
|
+
execCommandPan(tx, ty) {
|
|
7488
|
+
this.module._command(this.ptr, ApplicationCommandID.Pan, tx, ty);
|
|
7489
|
+
}
|
|
7490
|
+
execCommandZoomDelta(tz) {
|
|
7491
|
+
this.module._command(this.ptr, ApplicationCommandID.ZoomDelta, tz, 0);
|
|
7492
|
+
}
|
|
7493
|
+
pointermove(x, y) {
|
|
7494
|
+
this.module._pointer_move(this.ptr, x, y);
|
|
7495
|
+
}
|
|
7496
|
+
// ====================================================================================================
|
|
7497
|
+
// DEVTOOLS
|
|
7498
|
+
// ====================================================================================================
|
|
7499
|
+
/**
|
|
7500
|
+
* Set the visibility of the tiles.
|
|
7501
|
+
* @param show - The visibility of the tiles.
|
|
7502
|
+
*/
|
|
7503
|
+
devtools_rendering_set_show_tiles(show) {
|
|
7504
|
+
this.module._devtools_rendering_set_show_tiles(this.ptr, show);
|
|
7505
|
+
}
|
|
7506
|
+
/**
|
|
7507
|
+
* Set the visibility of the FPS meter.
|
|
7508
|
+
* @param show - The visibility of the FPS meter.
|
|
7509
|
+
*/
|
|
7510
|
+
devtools_rendering_set_show_fps_meter(show) {
|
|
7511
|
+
this.module._devtools_rendering_set_show_fps_meter(this.ptr, show);
|
|
7512
|
+
}
|
|
7513
|
+
/**
|
|
7514
|
+
* Set the visibility of the stats.
|
|
7515
|
+
* @param show - The visibility of the stats.
|
|
7516
|
+
*/
|
|
7517
|
+
devtools_rendering_set_show_stats(show) {
|
|
7518
|
+
this.module._devtools_rendering_set_show_stats(this.ptr, show);
|
|
7519
|
+
}
|
|
7520
|
+
/**
|
|
7521
|
+
* Set the visibility of the hit testing.
|
|
7522
|
+
* @param show - The visibility of the hit testing.
|
|
7523
|
+
*/
|
|
7524
|
+
devtools_rendering_set_show_hit_testing(show) {
|
|
7525
|
+
this.module._devtools_rendering_set_show_hit_testing(this.ptr, show);
|
|
7526
|
+
}
|
|
7527
|
+
/**
|
|
7528
|
+
* Set the visibility of the ruler.
|
|
7529
|
+
* @param show - The visibility of the ruler.
|
|
7530
|
+
*/
|
|
7531
|
+
devtools_rendering_set_show_ruler(show) {
|
|
7532
|
+
this.module._devtools_rendering_set_show_ruler(this.ptr, show);
|
|
7424
7533
|
}
|
|
7425
7534
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -7380,20 +7380,43 @@ var require_grida_canvas_wasm = __commonJS({
|
|
|
7380
7380
|
// lib/index.ts
|
|
7381
7381
|
var import_grida_canvas_wasm = __toESM(require_grida_canvas_wasm());
|
|
7382
7382
|
async function init(opts) {
|
|
7383
|
-
const bindings = await
|
|
7384
|
-
return new ApplicationFactory(
|
|
7383
|
+
const bindings = await (0, import_grida_canvas_wasm.default)({ locateFile: opts == null ? void 0 : opts.locateFile });
|
|
7384
|
+
return new ApplicationFactory(
|
|
7385
|
+
bindings
|
|
7386
|
+
);
|
|
7385
7387
|
}
|
|
7386
7388
|
var ApplicationFactory = class {
|
|
7387
7389
|
module;
|
|
7388
7390
|
constructor(module) {
|
|
7389
7391
|
this.module = module;
|
|
7390
7392
|
}
|
|
7393
|
+
createCanvasSurface(htmlcanvasid) {
|
|
7394
|
+
const canvas = document.getElementById(htmlcanvasid);
|
|
7395
|
+
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
7396
|
+
throw new Error(`Element with id ${htmlcanvasid} is not a <canvas>`);
|
|
7397
|
+
}
|
|
7398
|
+
const context = canvas.getContext("webgl2", {
|
|
7399
|
+
antialias: true,
|
|
7400
|
+
depth: true,
|
|
7401
|
+
stencil: true,
|
|
7402
|
+
alpha: true
|
|
7403
|
+
});
|
|
7404
|
+
if (!context) {
|
|
7405
|
+
throw new Error("Failed to get WebGL2 context");
|
|
7406
|
+
}
|
|
7407
|
+
const handle = this.module.GL.registerContext(context, {
|
|
7408
|
+
majorVersion: 2
|
|
7409
|
+
});
|
|
7410
|
+
this.module.GL.makeContextCurrent(handle);
|
|
7411
|
+
const ptr = this.module._init(canvas.width, canvas.height);
|
|
7412
|
+
return new Grida2D(this.module, ptr);
|
|
7413
|
+
}
|
|
7391
7414
|
createSurface(width, height) {
|
|
7392
7415
|
const ptr = this.module._init(width, height);
|
|
7393
7416
|
return new Grida2D(this.module, ptr);
|
|
7394
7417
|
}
|
|
7395
7418
|
};
|
|
7396
|
-
var
|
|
7419
|
+
var ApplicationCommandID = {
|
|
7397
7420
|
ZoomIn: 1,
|
|
7398
7421
|
ZoomOut: 2,
|
|
7399
7422
|
ZoomDelta: 3,
|
|
@@ -7406,9 +7429,48 @@ var Grida2D = class {
|
|
|
7406
7429
|
this.module = module;
|
|
7407
7430
|
this.ptr = ptr;
|
|
7408
7431
|
}
|
|
7432
|
+
_alloc_string(txt) {
|
|
7433
|
+
const len = this.module.lengthBytesUTF8(txt) + 1;
|
|
7434
|
+
const ptr = this.module._allocate(len);
|
|
7435
|
+
this.module.stringToUTF8(txt, ptr, len);
|
|
7436
|
+
return [ptr, len];
|
|
7437
|
+
}
|
|
7438
|
+
_free_string(ptr, len) {
|
|
7439
|
+
this.module._deallocate(ptr, len);
|
|
7440
|
+
}
|
|
7441
|
+
/**
|
|
7442
|
+
* Load a scene from a JSON string.
|
|
7443
|
+
* @param data - The JSON string to load.
|
|
7444
|
+
*/
|
|
7445
|
+
loadScene(data) {
|
|
7446
|
+
const [ptr, len] = this._alloc_string(data);
|
|
7447
|
+
this.module._load_scene_json(this.ptr, ptr, len - 1);
|
|
7448
|
+
this._free_string(ptr, len);
|
|
7449
|
+
}
|
|
7450
|
+
/**
|
|
7451
|
+
* @deprecated - test use only
|
|
7452
|
+
*/
|
|
7453
|
+
loadDummyScene() {
|
|
7454
|
+
this.module._load_dummy_scene(this.ptr);
|
|
7455
|
+
}
|
|
7456
|
+
/**
|
|
7457
|
+
* @deprecated - test use only
|
|
7458
|
+
*/
|
|
7459
|
+
loadBenchmarkScene(cols, rows) {
|
|
7460
|
+
this.module._load_benchmark_scene(this.ptr, cols, rows);
|
|
7461
|
+
}
|
|
7462
|
+
/**
|
|
7463
|
+
* Tick the application clock.
|
|
7464
|
+
* bind this to requestAnimationFrame loop or similar
|
|
7465
|
+
*/
|
|
7409
7466
|
tick() {
|
|
7410
7467
|
this.module._tick(this.ptr);
|
|
7411
7468
|
}
|
|
7469
|
+
/**
|
|
7470
|
+
* Resize the surface.
|
|
7471
|
+
* @param width - The width of the surface.
|
|
7472
|
+
* @param height - The height of the surface.
|
|
7473
|
+
*/
|
|
7412
7474
|
resize(width, height) {
|
|
7413
7475
|
this.module._resize_surface(this.ptr, width, height);
|
|
7414
7476
|
}
|
|
@@ -7416,7 +7478,54 @@ var Grida2D = class {
|
|
|
7416
7478
|
this.module._redraw(this.ptr);
|
|
7417
7479
|
}
|
|
7418
7480
|
execCommand(command) {
|
|
7419
|
-
this.module._command(this.ptr,
|
|
7481
|
+
this.module._command(this.ptr, ApplicationCommandID[command], 0, 0);
|
|
7482
|
+
}
|
|
7483
|
+
execCommandPan(tx, ty) {
|
|
7484
|
+
this.module._command(this.ptr, ApplicationCommandID.Pan, tx, ty);
|
|
7485
|
+
}
|
|
7486
|
+
execCommandZoomDelta(tz) {
|
|
7487
|
+
this.module._command(this.ptr, ApplicationCommandID.ZoomDelta, tz, 0);
|
|
7488
|
+
}
|
|
7489
|
+
pointermove(x, y) {
|
|
7490
|
+
this.module._pointer_move(this.ptr, x, y);
|
|
7491
|
+
}
|
|
7492
|
+
// ====================================================================================================
|
|
7493
|
+
// DEVTOOLS
|
|
7494
|
+
// ====================================================================================================
|
|
7495
|
+
/**
|
|
7496
|
+
* Set the visibility of the tiles.
|
|
7497
|
+
* @param show - The visibility of the tiles.
|
|
7498
|
+
*/
|
|
7499
|
+
devtools_rendering_set_show_tiles(show) {
|
|
7500
|
+
this.module._devtools_rendering_set_show_tiles(this.ptr, show);
|
|
7501
|
+
}
|
|
7502
|
+
/**
|
|
7503
|
+
* Set the visibility of the FPS meter.
|
|
7504
|
+
* @param show - The visibility of the FPS meter.
|
|
7505
|
+
*/
|
|
7506
|
+
devtools_rendering_set_show_fps_meter(show) {
|
|
7507
|
+
this.module._devtools_rendering_set_show_fps_meter(this.ptr, show);
|
|
7508
|
+
}
|
|
7509
|
+
/**
|
|
7510
|
+
* Set the visibility of the stats.
|
|
7511
|
+
* @param show - The visibility of the stats.
|
|
7512
|
+
*/
|
|
7513
|
+
devtools_rendering_set_show_stats(show) {
|
|
7514
|
+
this.module._devtools_rendering_set_show_stats(this.ptr, show);
|
|
7515
|
+
}
|
|
7516
|
+
/**
|
|
7517
|
+
* Set the visibility of the hit testing.
|
|
7518
|
+
* @param show - The visibility of the hit testing.
|
|
7519
|
+
*/
|
|
7520
|
+
devtools_rendering_set_show_hit_testing(show) {
|
|
7521
|
+
this.module._devtools_rendering_set_show_hit_testing(this.ptr, show);
|
|
7522
|
+
}
|
|
7523
|
+
/**
|
|
7524
|
+
* Set the visibility of the ruler.
|
|
7525
|
+
* @param show - The visibility of the ruler.
|
|
7526
|
+
*/
|
|
7527
|
+
devtools_rendering_set_show_ruler(show) {
|
|
7528
|
+
this.module._devtools_rendering_set_show_ruler(this.ptr, show);
|
|
7420
7529
|
}
|
|
7421
7530
|
};
|
|
7422
7531
|
export {
|