ranuts 0.2.0-alpha.1 → 0.4.0-alpha.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/CLAUDE.md +126 -24
- package/README.md +7 -5
- package/README.zh-CN.md +7 -5
- package/dist/chain-CTywmh_H.js +1 -0
- package/dist/{color-CRdlaDqQ.js → color-Dohr9BXX.js} +1 -1
- package/dist/enums-BAgbyGdH.js +1 -0
- package/dist/i18n-Cf5TtRb4.js +1 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -1
- package/dist/src/node/appendFile.d.ts +3 -3
- package/dist/src/node/fileInfo.d.ts +2 -2
- package/dist/src/node/index.js +1 -1
- package/dist/src/node/paresUrl.d.ts +1 -1
- package/dist/src/node/readFile.d.ts +3 -3
- package/dist/src/node/traverse.d.ts +2 -2
- package/dist/src/node/watchFile.d.ts +3 -3
- package/dist/src/node/writeFile.d.ts +3 -3
- package/dist/src/sw/index.d.ts +109 -0
- package/dist/src/sw/index.js +1 -0
- package/dist/src/utils/async.d.ts +81 -0
- package/dist/src/utils/audioRecorder.d.ts +1 -1
- package/dist/src/utils/behavior.d.ts +12 -3
- package/dist/src/utils/bom.d.ts +68 -178
- package/dist/src/utils/bridge.d.ts +153 -0
- package/dist/src/utils/canvas.d.ts +54 -0
- package/dist/src/utils/chain.d.ts +80 -0
- package/dist/src/utils/color.d.ts +76 -4
- package/dist/src/utils/compose.d.ts +1 -1
- package/dist/src/utils/console.d.ts +19 -1
- package/dist/src/utils/debounce.d.ts +27 -5
- package/dist/src/utils/device.d.ts +31 -3
- package/dist/src/utils/dom.d.ts +5 -84
- package/dist/src/utils/error.d.ts +18 -1
- package/dist/src/utils/event.d.ts +61 -0
- package/dist/src/utils/file.d.ts +35 -0
- package/dist/src/utils/i18n/index.js +1 -0
- package/dist/src/utils/i18n.d.ts +69 -0
- package/dist/src/utils/idb.d.ts +218 -0
- package/dist/src/utils/img.d.ts +60 -4
- package/dist/src/utils/index.d.ts +50 -16
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/lang.d.ts +69 -0
- package/dist/src/utils/localePath.d.ts +62 -0
- package/dist/src/utils/memoize.d.ts +53 -5
- package/dist/src/utils/monitor.d.ts +55 -26
- package/dist/src/utils/number.d.ts +46 -9
- package/dist/src/utils/obj.d.ts +56 -31
- package/dist/src/utils/paginate.d.ts +73 -0
- package/dist/src/utils/prefetch.d.ts +81 -0
- package/dist/src/utils/queue.d.ts +53 -23
- package/dist/src/utils/report.d.ts +51 -3
- package/dist/src/utils/request.d.ts +26 -7
- package/dist/src/utils/script.d.ts +26 -4
- package/dist/src/utils/segment.d.ts +62 -0
- package/dist/src/utils/signal.d.ts +35 -3
- package/dist/src/utils/storage.d.ts +57 -0
- package/dist/src/utils/str.d.ts +112 -88
- package/dist/src/utils/style.d.ts +31 -0
- package/dist/src/utils/subscribe.d.ts +5 -5
- package/dist/src/utils/throttle.d.ts +26 -13
- package/dist/src/utils/time.d.ts +38 -6
- package/dist/src/utils/tween.d.ts +40 -0
- package/dist/src/utils/visual/application.d.ts +4 -4
- package/dist/src/utils/visual/enums.d.ts +4 -4
- package/dist/src/utils/visual/graphics/graphics.d.ts +25 -25
- package/dist/src/utils/visual/graphics/graphicsData.d.ts +1 -1
- package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +6 -6
- package/dist/src/utils/visual/index.js +1 -1
- package/dist/src/utils/visual/math/matrix.d.ts +8 -8
- package/dist/src/utils/visual/math/transform.d.ts +1 -1
- package/dist/src/utils/visual/render/batchRenderer.d.ts +20 -18
- package/dist/src/utils/visual/render/utils/batch/index.d.ts +13 -13
- package/dist/src/utils/visual/render/utils/float.d.ts +13 -13
- package/dist/src/utils/visual/render/utils/verticy.d.ts +3 -3
- package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +3 -2
- package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +2 -2
- package/dist/src/utils/visual/render/webGPURenderer.d.ts +8 -8
- package/dist/src/utils/visual/vertex/container.d.ts +17 -16
- package/dist/src/utils/worker.d.ts +125 -0
- package/dist/src/utils/zip.d.ts +162 -0
- package/dist/src/vnode/index.d.ts +1 -1
- package/dist/src/vnode/index.js +1 -1
- package/dist/src/vnode/is.d.ts +4 -0
- package/dist/test/canvas.test.d.ts +1 -0
- package/dist/test/color.test.d.ts +1 -0
- package/dist/test/sw.test.d.ts +1 -0
- package/dist/test/tween.test.d.ts +1 -0
- package/dist/test/utils/async.test.d.ts +1 -0
- package/dist/test/utils/file-read.test.d.ts +1 -0
- package/dist/test/utils/format.test.d.ts +1 -0
- package/dist/test/utils/idb-collection.test.d.ts +1 -0
- package/dist/test/utils/idb.test.d.ts +1 -0
- package/dist/test/utils/instrumentation.test.d.ts +1 -0
- package/dist/test/utils/lang.test.d.ts +1 -0
- package/dist/test/utils/locale-path.test.d.ts +1 -0
- package/dist/test/utils/media-query.test.d.ts +1 -0
- package/dist/test/utils/number-parse.test.d.ts +1 -0
- package/dist/test/utils/paginate.test.d.ts +1 -0
- package/dist/test/utils/prefetch.test.d.ts +1 -0
- package/dist/test/utils/query-storage.test.d.ts +1 -0
- package/dist/test/utils/queue.test.d.ts +1 -0
- package/dist/test/utils/report-config.test.d.ts +1 -0
- package/dist/test/utils/report-image.test.d.ts +1 -0
- package/dist/test/utils/segment.test.d.ts +1 -0
- package/dist/test/utils/signal-once.test.d.ts +1 -0
- package/dist/test/utils/single-flight.test.d.ts +1 -0
- package/dist/test/utils/timing.test.d.ts +1 -0
- package/dist/test/utils/worker-client.test.d.ts +1 -0
- package/dist/test/utils/worker-serve.test.d.ts +1 -0
- package/dist/test/utils/zip.test.d.ts +1 -0
- package/dist/umd/index.umd.cjs +1 -1
- package/dist/umd/node/node.umd.cjs +1 -1
- package/dist/umd/utils/utils.umd.cjs +1 -1
- package/dist/utils-8TVtLBjA.js +1 -0
- package/docs/API.md +341 -147
- package/package.json +13 -6
- package/dist/src/vnode/chainDom.d.ts +0 -47
- package/dist/subscribe-CINWsor3.js +0 -1
- package/dist/utils-_OxsVZmz.js +0 -1
|
@@ -4,39 +4,41 @@ import type { Batch } from '@/utils/visual/render/utils/batch';
|
|
|
4
4
|
import type { IApplicationOptions } from '@/utils/visual/types';
|
|
5
5
|
export declare abstract class BatchRenderer extends Renderer {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The scene structure version at the last rebuild, held per renderer instance. When it
|
|
8
|
+
* differs from the root's structureVersion the scene changed (a node was added or removed,
|
|
9
|
+
* or a shape redrawn) and the big array must be rebuilt; otherwise only per-frame transform
|
|
10
|
+
* updates are needed. Starting at -1 guarantees a build on the first frame. Comparing
|
|
11
|
+
* versions rather than consuming a dirty flag lets several renderers share one scene.
|
|
10
12
|
*/
|
|
11
13
|
protected builtVersion: number;
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
15
|
+
* Vertex count
|
|
14
16
|
*/
|
|
15
17
|
protected vertexCount: number;
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
19
|
+
* Index count
|
|
18
20
|
*/
|
|
19
21
|
protected indexCount: number;
|
|
20
22
|
protected batches: Array<Batch | undefined>;
|
|
21
23
|
protected batchesCount: number;
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
25
|
+
* Float32 view over the vertex array
|
|
24
26
|
*/
|
|
25
27
|
protected vertFloatView: Float32Array;
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* Uint32 view over the vertex array
|
|
28
30
|
*/
|
|
29
31
|
protected vertIntView: Uint32Array;
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
33
|
+
* Index array
|
|
32
34
|
*/
|
|
33
35
|
protected indexBuffer: Uint32Array;
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
37
|
+
* Current length of the WebGL/WebGPU vertex buffer
|
|
36
38
|
*/
|
|
37
39
|
protected curVertBufferLength: number;
|
|
38
40
|
/**
|
|
39
|
-
*
|
|
41
|
+
* Current length of the WebGL/WebGPU index buffer
|
|
40
42
|
*/
|
|
41
43
|
protected curIndexBufferLength: number;
|
|
42
44
|
constructor(options: IApplicationOptions);
|
|
@@ -44,35 +46,35 @@ export declare abstract class BatchRenderer extends Renderer {
|
|
|
44
46
|
protected startBuild(): void;
|
|
45
47
|
protected buildEnd(): void;
|
|
46
48
|
/**
|
|
47
|
-
*
|
|
49
|
+
* Allocate a bigger typed array when the current one can no longer hold the data
|
|
48
50
|
*/
|
|
49
51
|
protected resizeBufferIfNeeded(): void;
|
|
50
52
|
/**
|
|
51
|
-
*
|
|
53
|
+
* Pack the data into the big array
|
|
52
54
|
*/
|
|
53
55
|
protected packData(): void;
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
57
|
+
* Draw via the WebGL or WebGPU drawing API
|
|
56
58
|
*/
|
|
57
59
|
protected abstract draw(): void;
|
|
58
60
|
/**
|
|
59
|
-
*
|
|
61
|
+
* Update the vertex and index buffers
|
|
60
62
|
*/
|
|
61
63
|
protected abstract updateBuffer(): void;
|
|
62
64
|
/**
|
|
63
|
-
*
|
|
65
|
+
* Set the projection matrix, which adapts to the canvas element's size
|
|
64
66
|
*/
|
|
65
67
|
protected abstract setProjectionMatrix(): void;
|
|
66
68
|
/**
|
|
67
|
-
*
|
|
69
|
+
* Update the uniform holding the stage's transform
|
|
68
70
|
*/
|
|
69
71
|
protected abstract setRootTransform(a: number, b: number, c: number, d: number, tx: number, ty: number): void;
|
|
70
72
|
/**
|
|
71
|
-
*
|
|
73
|
+
* Update the children's transforms
|
|
72
74
|
*/
|
|
73
75
|
protected updateChildrenTransform(rootContainer: Container): void;
|
|
74
76
|
/**
|
|
75
|
-
*
|
|
77
|
+
* Update node positions and render
|
|
76
78
|
*/
|
|
77
79
|
render(rootContainer: Container): void;
|
|
78
80
|
}
|
|
@@ -3,44 +3,44 @@ import type { Container } from '@/utils/visual/vertex/container';
|
|
|
3
3
|
import type { Fill } from '@/utils/visual/style';
|
|
4
4
|
import type { Graphics } from '@/utils/visual/graphics';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Build the big array
|
|
7
7
|
*/
|
|
8
8
|
export declare const buildArray: (batchRenderer: BatchRenderer, container: Container) => void;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Update the big array
|
|
11
11
|
*/
|
|
12
12
|
export declare const updateArray: (floatView: Float32Array, container: Container) => void;
|
|
13
13
|
export declare abstract class Batch {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Vertex count
|
|
16
16
|
*/
|
|
17
17
|
vertexCount: number;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Index count
|
|
20
20
|
*/
|
|
21
21
|
indexCount: number;
|
|
22
22
|
/**
|
|
23
|
-
* rgba
|
|
23
|
+
* rgba packed little-endian
|
|
24
24
|
*/
|
|
25
25
|
rgba: number;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Where this batch's vertices start in the big array
|
|
28
28
|
*/
|
|
29
29
|
vertexStart: number;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Where this batch's indices start in the big array
|
|
32
32
|
*/
|
|
33
33
|
indexStart: number;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Write the vertex data into the big array
|
|
36
36
|
*/
|
|
37
37
|
abstract packVertices(floatView: Float32Array, intView: Uint32Array): void;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Write the index data into the big array
|
|
40
40
|
*/
|
|
41
41
|
abstract packIndices(int32: Uint32Array): void;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Update the vertex positions inside the big array
|
|
44
44
|
*/
|
|
45
45
|
abstract updateVertices(floatView: Float32Array): void;
|
|
46
46
|
}
|
|
@@ -66,15 +66,15 @@ export declare class GraphicsBatchPool extends BatchPool {
|
|
|
66
66
|
}
|
|
67
67
|
export declare class GraphicsBatch extends Batch {
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Where this part's vertices start in geometry.vertices
|
|
70
70
|
*/
|
|
71
71
|
vertexOffset: number;
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Where this part's indices start in geometry.indices
|
|
74
74
|
*/
|
|
75
75
|
indexOffset: number;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* The Graphics instance this belongs to
|
|
78
78
|
*/
|
|
79
79
|
graphics: Graphics;
|
|
80
80
|
packVertices(floatView: Float32Array, intView: Uint32Array): void;
|
|
@@ -5,28 +5,28 @@ export declare class CustomFloatArray {
|
|
|
5
5
|
private float32;
|
|
6
6
|
private _data;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Current length
|
|
9
9
|
*/
|
|
10
10
|
get length(): number;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Append an array of numbers
|
|
13
13
|
*/
|
|
14
14
|
concat(arr: number[]): void;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param num
|
|
16
|
+
* Push one value
|
|
17
|
+
* @param num the value to push
|
|
18
18
|
*/
|
|
19
19
|
push(num: number): void;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Grow the backing buffer
|
|
22
22
|
*/
|
|
23
23
|
expandCapacity(): void;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* A Float32Array view over the buffer from 0 to this.length
|
|
26
26
|
*/
|
|
27
27
|
get data(): Float32Array;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Clear
|
|
30
30
|
*/
|
|
31
31
|
clear(): void;
|
|
32
32
|
}
|
|
@@ -37,27 +37,27 @@ export declare class CustomIntArray {
|
|
|
37
37
|
private int32;
|
|
38
38
|
private _data;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Current length
|
|
41
41
|
*/
|
|
42
42
|
get length(): number;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Append an array of numbers
|
|
45
45
|
*/
|
|
46
46
|
concat(arr: number[]): void;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Append a UInt16 array
|
|
49
49
|
*/
|
|
50
50
|
concatUInt16(uint16: Uint32Array): void;
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Grow the backing buffer
|
|
53
53
|
*/
|
|
54
54
|
expandCapacity(): void;
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* A Uint32Array view over the buffer from 0 to this.length
|
|
57
57
|
*/
|
|
58
58
|
get data(): Uint32Array;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Clear
|
|
61
61
|
*/
|
|
62
62
|
clear(): void;
|
|
63
63
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { GraphicsData } from '@/utils/visual/graphics/graphicsData';
|
|
2
2
|
import type { GraphicsGeometry } from '@/utils/visual/graphics/graphicsGeometry';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param data
|
|
4
|
+
* Turn a shape into vertices
|
|
5
|
+
* @param data the sub-shape's data
|
|
6
6
|
*/
|
|
7
7
|
export declare const buildVertices: (data: GraphicsData) => void;
|
|
8
8
|
export declare const triangulateFill: (data: GraphicsData, geometry: GraphicsGeometry) => void;
|
|
9
9
|
export declare const getNormalVector: (x: number, y: number, lineWidth: number) => [number, number];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Build the stroke's vertices and triangulate them
|
|
12
12
|
*/
|
|
13
13
|
export declare const triangulateStroke: (data: GraphicsData, geometry: GraphicsGeometry) => void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { WebGLRenderer } from '@/utils/visual/render/webGlRenderer';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Set the vertex attribute layout. The target ARRAY_BUFFER must already be bound.
|
|
4
|
+
* The vertex format matches the shared batching pipeline (BatchRenderer):
|
|
5
|
+
* position (2×Float32) + colour (4×Uint8, normalised), stride = BYTES_PER_VERTEX.
|
|
5
6
|
*/
|
|
6
7
|
export declare const setupVertexLayout: (gl: WebGLRenderingContext, program: WebGLProgram) => void;
|
|
7
8
|
export declare const initShader: (renderer: WebGLRenderer) => WebGLProgram;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Vertex shader
|
|
3
3
|
*/
|
|
4
4
|
export declare const vertexShaderSource = "\n@group(0) @binding(0) var<uniform> u_root_transform: mat3x3<f32>;\n@group(0) @binding(1) var<uniform> u_projection_matrix: mat3x3<f32>;\n\nstruct VertOutput {\n @builtin(position) v_position: vec4<f32>,\n @location(0) v_color : vec4<f32>,\n};\n\n@vertex\nfn main(\n @location(0) a_position: vec2<f32>,\n @location(1) a_color: vec4<f32>,\n) -> VertOutput {\n let v_position = vec4<f32>((u_projection_matrix * u_root_transform * vec3<f32>(a_position, 1.0)).xy, 0.0, 1.0);\n\n let v_color = a_color;\n\n return VertOutput(v_position, v_color);\n}\n";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Fragment shader
|
|
7
7
|
*/
|
|
8
8
|
export declare const fragmentShaderSource = "\n@fragment\nfn main(\n @location(0) v_color : vec4<f32>,\n) -> @location(0) vec4<f32> {\n return v_color;\n}\n";
|
|
@@ -7,23 +7,23 @@ export declare class WebGPURenderer extends BatchRenderer {
|
|
|
7
7
|
private renderPassDescriptor;
|
|
8
8
|
private options;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* WebGPU buffer holding the vertices
|
|
11
11
|
*/
|
|
12
12
|
private gpuVertexBuffer;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* WebGPU buffer holding the vertex indices
|
|
15
15
|
*/
|
|
16
16
|
private gpuIndexBuffer;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* WebGPU buffer holding the projection matrix
|
|
19
19
|
*/
|
|
20
20
|
private projectionMatBuffer;
|
|
21
21
|
/**
|
|
22
|
-
* stage
|
|
22
|
+
* WebGPU buffer holding the stage's transform matrix
|
|
23
23
|
*/
|
|
24
24
|
private stageMatBuffer;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Bind group for the uniforms
|
|
27
27
|
*/
|
|
28
28
|
private uniformBindGroup;
|
|
29
29
|
constructor(options: IApplicationOptions);
|
|
@@ -35,15 +35,15 @@ export declare class WebGPURenderer extends BatchRenderer {
|
|
|
35
35
|
protected setRootTransform(a: number, b: number, c: number, d: number, tx: number, ty: number): void;
|
|
36
36
|
protected setProjectionMatrix(): void;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Initialise the pipeline
|
|
39
39
|
*/
|
|
40
40
|
private createPipeline;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Initialise the device
|
|
43
43
|
*/
|
|
44
44
|
private initDevice;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Initialise the renderPassDescriptor
|
|
47
47
|
*/
|
|
48
48
|
private initRenderPassDescriptor;
|
|
49
49
|
}
|
|
@@ -7,68 +7,69 @@ export declare class Container extends Vertex {
|
|
|
7
7
|
isSort: boolean;
|
|
8
8
|
type: string;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Every child
|
|
11
11
|
*/
|
|
12
12
|
readonly children: Container[];
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Marks whether worldTransform changed
|
|
15
15
|
*/
|
|
16
16
|
protected worldId: number;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Every batch
|
|
19
19
|
*/
|
|
20
20
|
protected batches: Batch[];
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Number of batches
|
|
23
23
|
*/
|
|
24
24
|
protected batchCount: number;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* Scene structure version (only meaningful on the root). Anything that changes what the
|
|
27
|
+
* big array should look like — adding or removing a child, a Graphics redraw — bubbles to
|
|
28
|
+
* the root and increments it, and the renderer uses that to decide whether to rebuild.
|
|
28
29
|
*/
|
|
29
30
|
structureVersion: number;
|
|
30
31
|
constructor();
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
+
* Mark the scene structure as changed: bubble to the root and bump its version, so the next frame rebuilds the big array.
|
|
33
34
|
*/
|
|
34
35
|
protected markStructureDirty: () => void;
|
|
35
36
|
/**
|
|
36
|
-
* @description:
|
|
37
|
+
* @description: Add a child
|
|
37
38
|
* @param {Container} child
|
|
38
39
|
* @return {*}
|
|
39
40
|
*/
|
|
40
41
|
addChild: (child: Container) => void;
|
|
41
42
|
/**
|
|
42
|
-
* @description
|
|
43
|
+
* @description: Remove a child
|
|
43
44
|
* @param {Container} child
|
|
44
45
|
* @return {void}
|
|
45
46
|
*/
|
|
46
47
|
removeChild: (child: Container) => void;
|
|
47
48
|
/**
|
|
48
|
-
* @description:
|
|
49
|
+
* @description: Sort children by z-index
|
|
49
50
|
* @return {*}
|
|
50
51
|
*/
|
|
51
52
|
sortChildren: () => void;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
+
* Render itself — a container has nothing to render, so this is empty
|
|
54
55
|
*/
|
|
55
56
|
protected renderCanvas(_render: CanvasRenderer): void;
|
|
56
57
|
/**
|
|
57
|
-
*
|
|
58
|
+
* Recursively render the whole tree rooted here
|
|
58
59
|
*/
|
|
59
60
|
renderCanvasRecursive: (render: CanvasRenderer) => void;
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
+
* Recursively update this element's transform and every child's
|
|
62
63
|
*/
|
|
63
64
|
updateTransform: () => void;
|
|
64
65
|
containsPoint: (p: Point) => boolean;
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
67
|
+
* Build its own batches. A group has no content of its own, so subclasses such as
|
|
68
|
+
* Graphics override this. Both GPU backends reach it through BatchRenderer's buildArray.
|
|
68
69
|
*/
|
|
69
70
|
buildBatches(_batchRenderer: BatchRenderer): void;
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
+
* Update this node's batched vertices inside the big array
|
|
72
73
|
*/
|
|
73
74
|
updateBatches(_floatView: Float32Array): void;
|
|
74
75
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request/response wrapper over a Web Worker.
|
|
3
|
+
*
|
|
4
|
+
* A native worker only knows "post a message" and "receive a message" — there is no notion
|
|
5
|
+
* of a request and its response: send two tasks concurrently, get two messages back, and
|
|
6
|
+
* there is no way to tell which is which. The standard fix is to number each request and
|
|
7
|
+
* echo that number in the response; this class packages that correlation logic (ids, a
|
|
8
|
+
* pending table, progress events, rejecting every in-flight request when the worker
|
|
9
|
+
* crashes) into something reusable.
|
|
10
|
+
*
|
|
11
|
+
* It also owns the worker's lifecycle: **the worker is created on the first `send`** (heavy
|
|
12
|
+
* work should not start at page load), and `dispose()` terminates it and rejects in-flight
|
|
13
|
+
* requests; a later `send` rebuilds it.
|
|
14
|
+
*/
|
|
15
|
+
/** A response must at least echo the request id so the two can be paired */
|
|
16
|
+
export interface WorkerResponseBase {
|
|
17
|
+
operationId: number;
|
|
18
|
+
type?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface WorkerClientOptions<Res extends WorkerResponseBase, Progress> {
|
|
21
|
+
/** How to create the worker, e.g. `() => new Worker(new URL('./my.worker.ts', import.meta.url), { type: 'module' })` */
|
|
22
|
+
create: () => Worker;
|
|
23
|
+
/** Whether this is a progress message — it does not settle the request, it only calls onProgress. Defaults to `type === 'progress'` */
|
|
24
|
+
isProgress?: (response: Res) => boolean;
|
|
25
|
+
/** Extract the progress payload from a progress message. Defaults to `response.progress` */
|
|
26
|
+
getProgress?: (response: Res) => Progress;
|
|
27
|
+
/** Whether this is an error message. Defaults to `type === 'error'` */
|
|
28
|
+
isError?: (response: Res) => boolean;
|
|
29
|
+
/** Error message text. Defaults to `response.message` */
|
|
30
|
+
getErrorMessage?: (response: Res) => string;
|
|
31
|
+
/** Per-request timeout in milliseconds; omit for none. A timeout only rejects that request, it does not terminate the worker */
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @description: A worker client with request ids. The request type `Req` is defined by the
|
|
36
|
+
* caller; the client only fills in `operationId` and routes each response back to the right
|
|
37
|
+
* promise.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const client = new WorkerClient<MyRequest, MyResponse, { progress: number }>({
|
|
42
|
+
* create: () => new Worker(new URL('./nlp.worker.ts', import.meta.url), { type: 'module' }),
|
|
43
|
+
* });
|
|
44
|
+
* const loaded = await client.send({ type: 'load', modelId }, (p) => render(p.progress));
|
|
45
|
+
* client.dispose();
|
|
46
|
+
* ```
|
|
47
|
+
* The worker side only has to echo the `operationId` it received:
|
|
48
|
+
* ```ts
|
|
49
|
+
* self.onmessage = ({ data }) => self.postMessage({ operationId: data.operationId, type: 'result', ... });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class WorkerClient<Req extends object, Res extends WorkerResponseBase, Progress = unknown> {
|
|
53
|
+
private worker;
|
|
54
|
+
private nextOperationId;
|
|
55
|
+
private pending;
|
|
56
|
+
private options;
|
|
57
|
+
constructor(options: WorkerClientOptions<Res, Progress>);
|
|
58
|
+
/** Whether the worker has been created (it is created on the first `send`) */
|
|
59
|
+
get active(): boolean;
|
|
60
|
+
/** Number of in-flight requests */
|
|
61
|
+
get pendingCount(): number;
|
|
62
|
+
/**
|
|
63
|
+
* @description: Send one request and await its matching response
|
|
64
|
+
* @param {Req} request request body (`operationId` is filled in by the client — do not pass it)
|
|
65
|
+
* @param {Function} onProgress progress callback, fired on progress messages without settling the request
|
|
66
|
+
* @param {Transferable[]} transfer objects whose ownership is transferred (ArrayBuffer and friends, avoiding the structured-clone copy)
|
|
67
|
+
* @return {Promise<Res>}
|
|
68
|
+
*/
|
|
69
|
+
send: (request: Req, onProgress?: (progress: Progress) => void, transfer?: Transferable[]) => Promise<Res>;
|
|
70
|
+
/** @description: Terminate the worker and reject every in-flight request; the next `send` rebuilds it */
|
|
71
|
+
dispose: () => void;
|
|
72
|
+
private getWorker;
|
|
73
|
+
private settle;
|
|
74
|
+
private handleMessage;
|
|
75
|
+
private rejectAll;
|
|
76
|
+
}
|
|
77
|
+
/** A request always carries the id the client stamped on it */
|
|
78
|
+
export interface WorkerRequestBase {
|
|
79
|
+
operationId: number;
|
|
80
|
+
type?: string;
|
|
81
|
+
}
|
|
82
|
+
/** Handed to the handler so it can stream progress for the request it is currently serving */
|
|
83
|
+
export interface WorkerHandlerContext<Progress> {
|
|
84
|
+
/** Post a progress update. Does not settle the request; may be called any number of times. */
|
|
85
|
+
progress: (payload: Progress) => void;
|
|
86
|
+
}
|
|
87
|
+
export interface ServeWorkerOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Where to listen. Defaults to `self` — override for a `MessagePort`, a nested worker, or
|
|
90
|
+
* a test double.
|
|
91
|
+
*/
|
|
92
|
+
scope?: {
|
|
93
|
+
addEventListener: (type: 'message', listener: (event: MessageEvent) => void) => void;
|
|
94
|
+
removeEventListener: (type: 'message', listener: (event: MessageEvent) => void) => void;
|
|
95
|
+
postMessage: (message: unknown, transfer?: Transferable[]) => void;
|
|
96
|
+
};
|
|
97
|
+
/** Response `type` for a successful reply that the handler returned bare (non-object). Default `'result'`. */
|
|
98
|
+
resultType?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @description: Serve requests inside a Web Worker, mirroring {@link WorkerClient} on the
|
|
102
|
+
* other end. Reads `operationId` off each request, awaits your handler, and posts the reply
|
|
103
|
+
* back with that same id.
|
|
104
|
+
*
|
|
105
|
+
* Failures become `{ operationId, type: 'error', message }` — the envelope `WorkerClient`
|
|
106
|
+
* rejects on by default. **Both synchronous throws and rejected promises are caught**: a sync
|
|
107
|
+
* throw inside `onmessage` would otherwise escape to the worker's error handler, which carries
|
|
108
|
+
* no id, so the client could only fail *every* in-flight request instead of the one that broke.
|
|
109
|
+
*
|
|
110
|
+
* @param {Function} handler receives the request and a context whose `progress()` streams updates
|
|
111
|
+
* @param {ServeWorkerOptions} options
|
|
112
|
+
* @return {Function} stop — removes the listener
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* // my.worker.ts
|
|
116
|
+
* serveWorker<MyRequest, MyResponse, ModelProgress>(async (request, { progress }) => {
|
|
117
|
+
* if (request.type === 'load') {
|
|
118
|
+
* const device = await load(request.modelId, (p) => progress(p));
|
|
119
|
+
* return { type: 'loaded', device };
|
|
120
|
+
* }
|
|
121
|
+
* return { type: 'result', scores: await classify(request.lines) };
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const serveWorker: <Req extends WorkerRequestBase, Res extends object = object, Progress = unknown>(handler: (request: Req, context: WorkerHandlerContext<Progress>) => Promise<Res> | Res, options?: ServeWorkerOptions) => (() => void);
|