samcan 0.0.2 → 0.1.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 → LICENSE} +3 -1
- package/README.md +3 -0
- package/dist/camera/index.cjs +370 -0
- package/dist/camera/index.d.cts +54 -0
- package/dist/camera/index.d.ts +54 -0
- package/dist/camera/index.js +70 -0
- package/dist/document/index.cjs +735 -0
- package/dist/document/index.d.cts +174 -0
- package/dist/document/index.d.ts +174 -0
- package/dist/document/index.js +161 -0
- package/dist/editor/index.cjs +5007 -0
- package/dist/editor/index.d.cts +374 -0
- package/dist/editor/index.d.ts +374 -0
- package/dist/editor/index.js +2401 -0
- package/dist/engine/index.cjs +3752 -0
- package/dist/engine/index.d.cts +183 -0
- package/dist/engine/index.d.ts +183 -0
- package/dist/engine/index.js +111 -0
- package/dist/index.cjs +8899 -0
- package/dist/index.d.cts +962 -0
- package/dist/index.d.ts +962 -46
- package/dist/index.js +1008 -49
- package/dist/math/index.cjs +2230 -0
- package/dist/math/index.d.cts +302 -0
- package/dist/math/index.d.ts +302 -0
- package/dist/math/index.js +1109 -0
- package/dist/renderer/index.cjs +1865 -0
- package/dist/renderer/index.d.cts +91 -0
- package/dist/renderer/index.d.ts +91 -0
- package/dist/renderer/index.js +89 -0
- package/dist/shared/chunk-35pkr0zs.js +110 -0
- package/dist/shared/chunk-7sr7q84y.js +80 -0
- package/dist/shared/chunk-87399bz7.js +89 -0
- package/dist/shared/chunk-8ynnz57m.js +129 -0
- package/dist/shared/chunk-d6gxvapt.js +500 -0
- package/dist/shared/chunk-hewznwbd.js +305 -0
- package/dist/shared/chunk-jdvrd5tv.js +623 -0
- package/dist/shared/chunk-rvag1j46.js +461 -0
- package/dist/shared/chunk-rzxyjwk8.js +397 -0
- package/dist/shared/chunk-s3qdcmcq.js +1392 -0
- package/dist/shared/chunk-v53jprrn.js +68 -0
- package/dist/shared/chunk-wa3772hp.js +117 -0
- package/dist/spatial/index.cjs +954 -0
- package/dist/spatial/index.d.cts +136 -0
- package/dist/spatial/index.d.ts +136 -0
- package/dist/spatial/index.js +301 -0
- package/dist/stroke/index.cjs +1010 -0
- package/dist/stroke/index.d.cts +143 -0
- package/dist/stroke/index.d.ts +143 -0
- package/dist/stroke/index.js +343 -0
- package/package.json +122 -58
- package/dist/bundle.js +0 -5888
- package/dist/core/animation/animationruntime.d.ts +0 -238
- package/dist/core/animation/animationruntime.d.ts.map +0 -1
- package/dist/core/animation/animationruntime.js +0 -530
- package/dist/core/animation/animationruntime.js.map +0 -1
- package/dist/core/animation/animationstate.d.ts +0 -85
- package/dist/core/animation/animationstate.d.ts.map +0 -1
- package/dist/core/animation/animationstate.js +0 -119
- package/dist/core/animation/animationstate.js.map +0 -1
- package/dist/core/animation/animationtrack.d.ts +0 -55
- package/dist/core/animation/animationtrack.d.ts.map +0 -1
- package/dist/core/animation/animationtrack.js +0 -185
- package/dist/core/animation/animationtrack.js.map +0 -1
- package/dist/core/animation/easing.d.ts +0 -80
- package/dist/core/animation/easing.d.ts.map +0 -1
- package/dist/core/animation/easing.js +0 -126
- package/dist/core/animation/easing.js.map +0 -1
- package/dist/core/animation/index.d.ts +0 -11
- package/dist/core/animation/index.d.ts.map +0 -1
- package/dist/core/animation/index.js +0 -10
- package/dist/core/animation/index.js.map +0 -1
- package/dist/core/animation/interpolator.d.ts +0 -82
- package/dist/core/animation/interpolator.d.ts.map +0 -1
- package/dist/core/animation/interpolator.js +0 -108
- package/dist/core/animation/interpolator.js.map +0 -1
- package/dist/core/animation/keyframe.d.ts +0 -52
- package/dist/core/animation/keyframe.d.ts.map +0 -1
- package/dist/core/animation/keyframe.js +0 -65
- package/dist/core/animation/keyframe.js.map +0 -1
- package/dist/core/animation/logger.d.ts +0 -8
- package/dist/core/animation/logger.d.ts.map +0 -1
- package/dist/core/animation/logger.js +0 -20
- package/dist/core/animation/logger.js.map +0 -1
- package/dist/core/animation/statemachine.d.ts +0 -178
- package/dist/core/animation/statemachine.d.ts.map +0 -1
- package/dist/core/animation/statemachine.js +0 -378
- package/dist/core/animation/statemachine.js.map +0 -1
- package/dist/core/animation/statetransition.d.ts +0 -142
- package/dist/core/animation/statetransition.d.ts.map +0 -1
- package/dist/core/animation/statetransition.js +0 -189
- package/dist/core/animation/statetransition.js.map +0 -1
- package/dist/core/animation/timeline.d.ts +0 -62
- package/dist/core/animation/timeline.d.ts.map +0 -1
- package/dist/core/animation/timeline.js +0 -102
- package/dist/core/animation/timeline.js.map +0 -1
- package/dist/core/api.d.ts +0 -245
- package/dist/core/api.d.ts.map +0 -1
- package/dist/core/api.js +0 -369
- package/dist/core/api.js.map +0 -1
- package/dist/core/asset/assetmanager.d.ts +0 -196
- package/dist/core/asset/assetmanager.d.ts.map +0 -1
- package/dist/core/asset/assetmanager.js +0 -502
- package/dist/core/asset/assetmanager.js.map +0 -1
- package/dist/core/asset/index.d.ts +0 -3
- package/dist/core/asset/index.d.ts.map +0 -1
- package/dist/core/asset/index.js +0 -3
- package/dist/core/asset/index.js.map +0 -1
- package/dist/core/asset/types.d.ts +0 -36
- package/dist/core/asset/types.d.ts.map +0 -1
- package/dist/core/asset/types.js +0 -1
- package/dist/core/asset/types.js.map +0 -1
- package/dist/core/command/basecommand.d.ts +0 -29
- package/dist/core/command/basecommand.d.ts.map +0 -1
- package/dist/core/command/basecommand.js +0 -36
- package/dist/core/command/basecommand.js.map +0 -1
- package/dist/core/command/command.d.ts +0 -55
- package/dist/core/command/command.d.ts.map +0 -1
- package/dist/core/command/command.js +0 -1
- package/dist/core/command/command.js.map +0 -1
- package/dist/core/command/commandhistory.d.ts +0 -76
- package/dist/core/command/commandhistory.d.ts.map +0 -1
- package/dist/core/command/commandhistory.js +0 -122
- package/dist/core/command/commandhistory.js.map +0 -1
- package/dist/core/command/editorcommands.d.ts +0 -108
- package/dist/core/command/editorcommands.d.ts.map +0 -1
- package/dist/core/command/editorcommands.js +0 -274
- package/dist/core/command/editorcommands.js.map +0 -1
- package/dist/core/command/index.d.ts +0 -5
- package/dist/core/command/index.d.ts.map +0 -1
- package/dist/core/command/index.js +0 -5
- package/dist/core/command/index.js.map +0 -1
- package/dist/core/editor/events/emitter.d.ts +0 -45
- package/dist/core/editor/events/emitter.d.ts.map +0 -1
- package/dist/core/editor/events/emitter.js +0 -88
- package/dist/core/editor/events/emitter.js.map +0 -1
- package/dist/core/error/animationerror.d.ts +0 -27
- package/dist/core/error/animationerror.d.ts.map +0 -1
- package/dist/core/error/animationerror.js +0 -41
- package/dist/core/error/animationerror.js.map +0 -1
- package/dist/core/error/asseterror.d.ts +0 -32
- package/dist/core/error/asseterror.d.ts.map +0 -1
- package/dist/core/error/asseterror.js +0 -48
- package/dist/core/error/asseterror.js.map +0 -1
- package/dist/core/error/index.d.ts +0 -7
- package/dist/core/error/index.d.ts.map +0 -1
- package/dist/core/error/index.js +0 -7
- package/dist/core/error/index.js.map +0 -1
- package/dist/core/error/pluginerror.d.ts +0 -22
- package/dist/core/error/pluginerror.d.ts.map +0 -1
- package/dist/core/error/pluginerror.js +0 -33
- package/dist/core/error/pluginerror.js.map +0 -1
- package/dist/core/error/renderererror.d.ts +0 -26
- package/dist/core/error/renderererror.d.ts.map +0 -1
- package/dist/core/error/renderererror.js +0 -40
- package/dist/core/error/renderererror.js.map +0 -1
- package/dist/core/error/samcanerror.d.ts +0 -72
- package/dist/core/error/samcanerror.d.ts.map +0 -1
- package/dist/core/error/samcanerror.js +0 -108
- package/dist/core/error/samcanerror.js.map +0 -1
- package/dist/core/error/serializationerror.d.ts +0 -31
- package/dist/core/error/serializationerror.d.ts.map +0 -1
- package/dist/core/error/serializationerror.js +0 -46
- package/dist/core/error/serializationerror.js.map +0 -1
- package/dist/core/index.d.ts +0 -12
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -12
- package/dist/core/index.js.map +0 -1
- package/dist/core/math/color.d.ts +0 -56
- package/dist/core/math/color.d.ts.map +0 -1
- package/dist/core/math/color.js +0 -125
- package/dist/core/math/color.js.map +0 -1
- package/dist/core/math/index.d.ts +0 -14
- package/dist/core/math/index.d.ts.map +0 -1
- package/dist/core/math/index.js +0 -14
- package/dist/core/math/index.js.map +0 -1
- package/dist/core/math/matrix.d.ts +0 -101
- package/dist/core/math/matrix.d.ts.map +0 -1
- package/dist/core/math/matrix.js +0 -177
- package/dist/core/math/matrix.js.map +0 -1
- package/dist/core/math/paint.d.ts +0 -104
- package/dist/core/math/paint.d.ts.map +0 -1
- package/dist/core/math/paint.js +0 -204
- package/dist/core/math/paint.js.map +0 -1
- package/dist/core/math/path/index.d.ts +0 -94
- package/dist/core/math/path/index.d.ts.map +0 -1
- package/dist/core/math/path/index.js +0 -180
- package/dist/core/math/path/index.js.map +0 -1
- package/dist/core/math/path/operations.d.ts +0 -38
- package/dist/core/math/path/operations.d.ts.map +0 -1
- package/dist/core/math/path/operations.js +0 -149
- package/dist/core/math/path/operations.js.map +0 -1
- package/dist/core/math/pool.d.ts +0 -54
- package/dist/core/math/pool.d.ts.map +0 -1
- package/dist/core/math/pool.js +0 -97
- package/dist/core/math/pool.js.map +0 -1
- package/dist/core/math/pools.d.ts +0 -29
- package/dist/core/math/pools.d.ts.map +0 -1
- package/dist/core/math/pools.js +0 -50
- package/dist/core/math/pools.js.map +0 -1
- package/dist/core/math/rectangle.d.ts +0 -68
- package/dist/core/math/rectangle.d.ts.map +0 -1
- package/dist/core/math/rectangle.js +0 -124
- package/dist/core/math/rectangle.js.map +0 -1
- package/dist/core/math/utils.d.ts +0 -68
- package/dist/core/math/utils.d.ts.map +0 -1
- package/dist/core/math/utils.js +0 -110
- package/dist/core/math/utils.js.map +0 -1
- package/dist/core/math/vector2.d.ts +0 -85
- package/dist/core/math/vector2.d.ts.map +0 -1
- package/dist/core/math/vector2.js +0 -134
- package/dist/core/math/vector2.js.map +0 -1
- package/dist/core/plugin/animationcontroller.d.ts +0 -43
- package/dist/core/plugin/animationcontroller.d.ts.map +0 -1
- package/dist/core/plugin/animationcontroller.js +0 -11
- package/dist/core/plugin/animationcontroller.js.map +0 -1
- package/dist/core/plugin/index.d.ts +0 -6
- package/dist/core/plugin/index.d.ts.map +0 -1
- package/dist/core/plugin/index.js +0 -4
- package/dist/core/plugin/index.js.map +0 -1
- package/dist/core/plugin/plugin.d.ts +0 -53
- package/dist/core/plugin/plugin.d.ts.map +0 -1
- package/dist/core/plugin/plugin.js +0 -29
- package/dist/core/plugin/plugin.js.map +0 -1
- package/dist/core/plugin/pluginregistry.d.ts +0 -71
- package/dist/core/plugin/pluginregistry.d.ts.map +0 -1
- package/dist/core/plugin/pluginregistry.js +0 -143
- package/dist/core/plugin/pluginregistry.js.map +0 -1
- package/dist/core/renderer/batchmanager.d.ts +0 -68
- package/dist/core/renderer/batchmanager.d.ts.map +0 -1
- package/dist/core/renderer/batchmanager.js +0 -82
- package/dist/core/renderer/batchmanager.js.map +0 -1
- package/dist/core/renderer/canvas2drenderer.d.ts +0 -139
- package/dist/core/renderer/canvas2drenderer.d.ts.map +0 -1
- package/dist/core/renderer/canvas2drenderer.js +0 -499
- package/dist/core/renderer/canvas2drenderer.js.map +0 -1
- package/dist/core/renderer/dirtyregionmanager.d.ts +0 -54
- package/dist/core/renderer/dirtyregionmanager.d.ts.map +0 -1
- package/dist/core/renderer/dirtyregionmanager.js +0 -129
- package/dist/core/renderer/dirtyregionmanager.js.map +0 -1
- package/dist/core/renderer/index.d.ts +0 -8
- package/dist/core/renderer/index.d.ts.map +0 -1
- package/dist/core/renderer/index.js +0 -6
- package/dist/core/renderer/index.js.map +0 -1
- package/dist/core/renderer/renderer.d.ts +0 -154
- package/dist/core/renderer/renderer.d.ts.map +0 -1
- package/dist/core/renderer/renderer.js +0 -1
- package/dist/core/renderer/renderer.js.map +0 -1
- package/dist/core/renderer/rendererfactory.d.ts +0 -66
- package/dist/core/renderer/rendererfactory.d.ts.map +0 -1
- package/dist/core/renderer/rendererfactory.js +0 -219
- package/dist/core/renderer/rendererfactory.js.map +0 -1
- package/dist/core/renderer/webglrenderer.d.ts +0 -185
- package/dist/core/renderer/webglrenderer.d.ts.map +0 -1
- package/dist/core/renderer/webglrenderer.js +0 -1007
- package/dist/core/renderer/webglrenderer.js.map +0 -1
- package/dist/core/scene/index.d.ts +0 -4
- package/dist/core/scene/index.d.ts.map +0 -1
- package/dist/core/scene/index.js +0 -4
- package/dist/core/scene/index.js.map +0 -1
- package/dist/core/scene/node.d.ts +0 -162
- package/dist/core/scene/node.d.ts.map +0 -1
- package/dist/core/scene/node.js +0 -402
- package/dist/core/scene/node.js.map +0 -1
- package/dist/core/scene/nodes/artboard.d.ts +0 -42
- package/dist/core/scene/nodes/artboard.d.ts.map +0 -1
- package/dist/core/scene/nodes/artboard.js +0 -64
- package/dist/core/scene/nodes/artboard.js.map +0 -1
- package/dist/core/scene/nodes/groupnode.d.ts +0 -10
- package/dist/core/scene/nodes/groupnode.d.ts.map +0 -1
- package/dist/core/scene/nodes/groupnode.js +0 -12
- package/dist/core/scene/nodes/groupnode.js.map +0 -1
- package/dist/core/scene/nodes/imagenode.d.ts +0 -38
- package/dist/core/scene/nodes/imagenode.d.ts.map +0 -1
- package/dist/core/scene/nodes/imagenode.js +0 -77
- package/dist/core/scene/nodes/imagenode.js.map +0 -1
- package/dist/core/scene/nodes/index.d.ts +0 -5
- package/dist/core/scene/nodes/index.d.ts.map +0 -1
- package/dist/core/scene/nodes/index.js +0 -5
- package/dist/core/scene/nodes/index.js.map +0 -1
- package/dist/core/scene/nodes/shapenode.d.ts +0 -76
- package/dist/core/scene/nodes/shapenode.d.ts.map +0 -1
- package/dist/core/scene/nodes/shapenode.js +0 -212
- package/dist/core/scene/nodes/shapenode.js.map +0 -1
- package/dist/core/scene/transform.d.ts +0 -27
- package/dist/core/scene/transform.d.ts.map +0 -1
- package/dist/core/scene/transform.js +0 -52
- package/dist/core/scene/transform.js.map +0 -1
- package/dist/core/serialization/index.d.ts +0 -3
- package/dist/core/serialization/index.d.ts.map +0 -1
- package/dist/core/serialization/index.js +0 -2
- package/dist/core/serialization/index.js.map +0 -1
- package/dist/core/serialization/serializer.d.ts +0 -323
- package/dist/core/serialization/serializer.d.ts.map +0 -1
- package/dist/core/serialization/serializer.js +0 -1173
- package/dist/core/serialization/serializer.js.map +0 -1
- package/dist/core/serialization/types.d.ts +0 -242
- package/dist/core/serialization/types.d.ts.map +0 -1
- package/dist/core/serialization/types.js +0 -1
- package/dist/core/serialization/types.js.map +0 -1
- package/dist/core/timing/clock.d.ts +0 -43
- package/dist/core/timing/clock.d.ts.map +0 -1
- package/dist/core/timing/clock.js +0 -78
- package/dist/core/timing/clock.js.map +0 -1
- package/dist/core/timing/index.d.ts +0 -3
- package/dist/core/timing/index.d.ts.map +0 -1
- package/dist/core/timing/index.js +0 -3
- package/dist/core/timing/index.js.map +0 -1
- package/dist/core/timing/scheduler.d.ts +0 -72
- package/dist/core/timing/scheduler.d.ts.map +0 -1
- package/dist/core/timing/scheduler.js +0 -163
- package/dist/core/timing/scheduler.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/wrapper/react/index.d.ts +0 -5
- package/dist/wrapper/react/index.d.ts.map +0 -1
- package/dist/wrapper/react/index.js +0 -3
- package/dist/wrapper/react/index.js.map +0 -1
- package/dist/wrapper/react/samcan-player.d.ts +0 -26
- package/dist/wrapper/react/samcan-player.d.ts.map +0 -1
- package/dist/wrapper/react/samcan-player.js +0 -19
- package/dist/wrapper/react/samcan-player.js.map +0 -1
- package/dist/wrapper/react/use-samcan-player.d.ts +0 -33
- package/dist/wrapper/react/use-samcan-player.d.ts.map +0 -1
- package/dist/wrapper/react/use-samcan-player.js +0 -65
- package/dist/wrapper/react/use-samcan-player.js.map +0 -1
- package/readme.md +0 -96
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
type vector2 = [number, number];
|
|
2
|
+
type rectangle = [number, number, number, number];
|
|
3
|
+
type color = [number, number, number, number];
|
|
4
|
+
type spline_segment = {
|
|
5
|
+
a: number;
|
|
6
|
+
b: number;
|
|
7
|
+
c: number;
|
|
8
|
+
d: number;
|
|
9
|
+
x_start: number;
|
|
10
|
+
x_end: number;
|
|
11
|
+
};
|
|
12
|
+
type spline = {
|
|
13
|
+
segments_x: spline_segment[];
|
|
14
|
+
segments_y: spline_segment[];
|
|
15
|
+
point_count: number;
|
|
16
|
+
};
|
|
17
|
+
type circle = [number, number, number];
|
|
18
|
+
type transform = [number, number, number, number, number, number];
|
|
19
|
+
declare const path_move = 0;
|
|
20
|
+
declare const path_line = 1;
|
|
21
|
+
declare const path_cubic = 2;
|
|
22
|
+
declare const path_close = 3;
|
|
23
|
+
type path_command_move = [typeof path_move, number, number];
|
|
24
|
+
type path_command_line = [typeof path_line, number, number];
|
|
25
|
+
type path_command_cubic = [typeof path_cubic, number, number, number, number, number, number];
|
|
26
|
+
type path_command_close = [typeof path_close];
|
|
27
|
+
type path_command = path_command_move | path_command_line | path_command_cubic | path_command_close;
|
|
28
|
+
type path = {
|
|
29
|
+
readonly commands: readonly path_command[];
|
|
30
|
+
readonly bounds: rectangle;
|
|
31
|
+
};
|
|
32
|
+
type stroke_style = {
|
|
33
|
+
color: color;
|
|
34
|
+
width: number;
|
|
35
|
+
opacity: number;
|
|
36
|
+
pressure_sensitivity: number;
|
|
37
|
+
};
|
|
38
|
+
type stroke_point = {
|
|
39
|
+
position: vector2;
|
|
40
|
+
pressure: number;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
};
|
|
43
|
+
type live_stroke = {
|
|
44
|
+
id: string;
|
|
45
|
+
points: stroke_point[];
|
|
46
|
+
style: stroke_style;
|
|
47
|
+
stabilizer_state: stabilizer_state;
|
|
48
|
+
};
|
|
49
|
+
type stroke = {
|
|
50
|
+
id: string;
|
|
51
|
+
bounds: rectangle;
|
|
52
|
+
z_index: number;
|
|
53
|
+
layer_id: string;
|
|
54
|
+
points: vector2[];
|
|
55
|
+
pressure: number[] | null;
|
|
56
|
+
style: stroke_style;
|
|
57
|
+
simplified_points: vector2[];
|
|
58
|
+
spline: spline | null;
|
|
59
|
+
path_cache: path_command[] | null;
|
|
60
|
+
};
|
|
61
|
+
type stabilizer_state = {
|
|
62
|
+
history: vector2[];
|
|
63
|
+
smoothing_factor: number;
|
|
64
|
+
};
|
|
65
|
+
declare const default_stroke_style: stroke_style;
|
|
66
|
+
declare function create_stroke_style(color: color, width: number, opacity?: number, pressure_sensitivity?: number): stroke_style;
|
|
67
|
+
declare function clone_stroke_style(s: stroke_style): stroke_style;
|
|
68
|
+
declare const default_smoothing_factor = .3;
|
|
69
|
+
declare const default_stabilizer_history_size = 5;
|
|
70
|
+
declare function create_stabilizer(smoothing_factor?: number): stabilizer_state;
|
|
71
|
+
declare function stabilize_point(state: stabilizer_state, raw: vector2, out: vector2): vector2;
|
|
72
|
+
declare function reset_stabilizer(state: stabilizer_state): void;
|
|
73
|
+
declare function get_stabilized_history(state: stabilizer_state): readonly vector2[];
|
|
74
|
+
type draw_style = {
|
|
75
|
+
readonly fill: color | null;
|
|
76
|
+
readonly stroke: color | null;
|
|
77
|
+
readonly stroke_width: number;
|
|
78
|
+
readonly line_cap: number;
|
|
79
|
+
readonly line_join: number;
|
|
80
|
+
readonly miter_limit: number;
|
|
81
|
+
readonly alpha: number;
|
|
82
|
+
};
|
|
83
|
+
type image_source = HTMLImageElement | HTMLCanvasElement | ImageBitmap;
|
|
84
|
+
type renderer = {
|
|
85
|
+
readonly kind: number;
|
|
86
|
+
readonly width: number;
|
|
87
|
+
readonly height: number;
|
|
88
|
+
readonly pixel_ratio: number;
|
|
89
|
+
begin_frame: () => void;
|
|
90
|
+
end_frame: () => void;
|
|
91
|
+
set_transform: (t: transform) => void;
|
|
92
|
+
reset_transform: () => void;
|
|
93
|
+
save: () => void;
|
|
94
|
+
restore: () => void;
|
|
95
|
+
draw_path: (p: path, s: draw_style) => void;
|
|
96
|
+
draw_rectangle: (r: rectangle, s: draw_style) => void;
|
|
97
|
+
draw_circle: (c: circle, s: draw_style) => void;
|
|
98
|
+
draw_line: (a: vector2, b: vector2, s: draw_style) => void;
|
|
99
|
+
draw_polyline: (points: readonly vector2[], s: draw_style) => void;
|
|
100
|
+
draw_image: (image: image_source, r: rectangle, opacity: number, version?: number) => void;
|
|
101
|
+
clip_rectangle: (r: rectangle) => void;
|
|
102
|
+
clear: (c: color) => void;
|
|
103
|
+
resize: (width: number, height: number, pixel_ratio: number) => void;
|
|
104
|
+
dispose: () => void;
|
|
105
|
+
};
|
|
106
|
+
declare function generate_stroke_id(): string;
|
|
107
|
+
declare function create_live_stroke(style: stroke_style, id?: string): live_stroke;
|
|
108
|
+
declare function add_point_live_stroke(live: live_stroke, position: vector2, pressure?: number, timestamp?: number): live_stroke;
|
|
109
|
+
declare function add_raw_point_live_stroke(live: live_stroke, raw_position: vector2, pressure?: number, timestamp?: number): live_stroke;
|
|
110
|
+
declare function get_points_from_live_stroke(live: live_stroke): vector2[];
|
|
111
|
+
declare function get_pressure_from_live_stroke(live: live_stroke): number[] | null;
|
|
112
|
+
declare function render_live_stroke(live: live_stroke, renderer: renderer): void;
|
|
113
|
+
declare function finalize_live_stroke(live: live_stroke, z_index: number, layer_id: string): {
|
|
114
|
+
points: vector2[];
|
|
115
|
+
pressure: number[] | null;
|
|
116
|
+
style: stroke_style;
|
|
117
|
+
id: string;
|
|
118
|
+
z_index: number;
|
|
119
|
+
layer_id: string;
|
|
120
|
+
};
|
|
121
|
+
declare const default_simplify_epsilon = 1;
|
|
122
|
+
declare const default_lod_simplify_factor = 3;
|
|
123
|
+
declare function simplify_stroke_points(points: vector2[], epsilon: number | undefined, out: vector2[]): number;
|
|
124
|
+
declare function simplify_stroke_points_auto(points: vector2[], out: vector2[]): number;
|
|
125
|
+
declare function fit_spline_to_stroke(points: vector2[], out_spline: spline): spline;
|
|
126
|
+
declare function compute_stroke_bounds(points: vector2[], width: number, out: rectangle): rectangle;
|
|
127
|
+
declare function process_stroke(points: vector2[], pressure: number[] | null, style: stroke_style, out_simplified: vector2[], out_spline: spline): {
|
|
128
|
+
simplified: vector2[];
|
|
129
|
+
spline: spline;
|
|
130
|
+
};
|
|
131
|
+
declare function get_simplified_for_lod(points: vector2[], lod_level: number, out: vector2[]): vector2[];
|
|
132
|
+
declare const lod_high = 1;
|
|
133
|
+
declare const lod_medium = .5;
|
|
134
|
+
declare const lod_low = .25;
|
|
135
|
+
declare const spline_evaluation_interval_high = 2;
|
|
136
|
+
declare const spline_evaluation_interval_medium = 4;
|
|
137
|
+
declare const spline_evaluation_interval_low = 8;
|
|
138
|
+
declare function select_lod_from_zoom(zoom: number): number;
|
|
139
|
+
declare function get_spline_evaluation_interval(lod: number): number;
|
|
140
|
+
declare function stroke_to_path_commands(stroke: stroke, lod: number, out_commands: number[]): number;
|
|
141
|
+
declare function render_stroke(stroke: stroke, renderer: renderer, zoom?: number): void;
|
|
142
|
+
declare function render_stroke_with_pressure(stroke: stroke, renderer: renderer, _zoom?: number): void;
|
|
143
|
+
export { stroke_to_path_commands, stroke_style, stroke_point, stroke, stabilizer_state, stabilize_point, spline_evaluation_interval_medium, spline_evaluation_interval_low, spline_evaluation_interval_high, simplify_stroke_points_auto, simplify_stroke_points, select_lod_from_zoom, reset_stabilizer, render_stroke_with_pressure, render_stroke, render_live_stroke, process_stroke, lod_medium, lod_low, lod_high, live_stroke, get_stabilized_history, get_spline_evaluation_interval, get_simplified_for_lod, get_pressure_from_live_stroke, get_points_from_live_stroke, generate_stroke_id, fit_spline_to_stroke, finalize_live_stroke, default_stroke_style, default_stabilizer_history_size, default_smoothing_factor, default_simplify_epsilon, default_lod_simplify_factor, create_stroke_style, create_stabilizer, create_live_stroke, compute_stroke_bounds, clone_stroke_style, add_raw_point_live_stroke, add_point_live_stroke };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
type vector2 = [number, number];
|
|
2
|
+
type rectangle = [number, number, number, number];
|
|
3
|
+
type color = [number, number, number, number];
|
|
4
|
+
type spline_segment = {
|
|
5
|
+
a: number;
|
|
6
|
+
b: number;
|
|
7
|
+
c: number;
|
|
8
|
+
d: number;
|
|
9
|
+
x_start: number;
|
|
10
|
+
x_end: number;
|
|
11
|
+
};
|
|
12
|
+
type spline = {
|
|
13
|
+
segments_x: spline_segment[];
|
|
14
|
+
segments_y: spline_segment[];
|
|
15
|
+
point_count: number;
|
|
16
|
+
};
|
|
17
|
+
type circle = [number, number, number];
|
|
18
|
+
type transform = [number, number, number, number, number, number];
|
|
19
|
+
declare const path_move = 0;
|
|
20
|
+
declare const path_line = 1;
|
|
21
|
+
declare const path_cubic = 2;
|
|
22
|
+
declare const path_close = 3;
|
|
23
|
+
type path_command_move = [typeof path_move, number, number];
|
|
24
|
+
type path_command_line = [typeof path_line, number, number];
|
|
25
|
+
type path_command_cubic = [typeof path_cubic, number, number, number, number, number, number];
|
|
26
|
+
type path_command_close = [typeof path_close];
|
|
27
|
+
type path_command = path_command_move | path_command_line | path_command_cubic | path_command_close;
|
|
28
|
+
type path = {
|
|
29
|
+
readonly commands: readonly path_command[];
|
|
30
|
+
readonly bounds: rectangle;
|
|
31
|
+
};
|
|
32
|
+
type stroke_style = {
|
|
33
|
+
color: color;
|
|
34
|
+
width: number;
|
|
35
|
+
opacity: number;
|
|
36
|
+
pressure_sensitivity: number;
|
|
37
|
+
};
|
|
38
|
+
type stroke_point = {
|
|
39
|
+
position: vector2;
|
|
40
|
+
pressure: number;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
};
|
|
43
|
+
type live_stroke = {
|
|
44
|
+
id: string;
|
|
45
|
+
points: stroke_point[];
|
|
46
|
+
style: stroke_style;
|
|
47
|
+
stabilizer_state: stabilizer_state;
|
|
48
|
+
};
|
|
49
|
+
type stroke = {
|
|
50
|
+
id: string;
|
|
51
|
+
bounds: rectangle;
|
|
52
|
+
z_index: number;
|
|
53
|
+
layer_id: string;
|
|
54
|
+
points: vector2[];
|
|
55
|
+
pressure: number[] | null;
|
|
56
|
+
style: stroke_style;
|
|
57
|
+
simplified_points: vector2[];
|
|
58
|
+
spline: spline | null;
|
|
59
|
+
path_cache: path_command[] | null;
|
|
60
|
+
};
|
|
61
|
+
type stabilizer_state = {
|
|
62
|
+
history: vector2[];
|
|
63
|
+
smoothing_factor: number;
|
|
64
|
+
};
|
|
65
|
+
declare const default_stroke_style: stroke_style;
|
|
66
|
+
declare function create_stroke_style(color: color, width: number, opacity?: number, pressure_sensitivity?: number): stroke_style;
|
|
67
|
+
declare function clone_stroke_style(s: stroke_style): stroke_style;
|
|
68
|
+
declare const default_smoothing_factor = .3;
|
|
69
|
+
declare const default_stabilizer_history_size = 5;
|
|
70
|
+
declare function create_stabilizer(smoothing_factor?: number): stabilizer_state;
|
|
71
|
+
declare function stabilize_point(state: stabilizer_state, raw: vector2, out: vector2): vector2;
|
|
72
|
+
declare function reset_stabilizer(state: stabilizer_state): void;
|
|
73
|
+
declare function get_stabilized_history(state: stabilizer_state): readonly vector2[];
|
|
74
|
+
type draw_style = {
|
|
75
|
+
readonly fill: color | null;
|
|
76
|
+
readonly stroke: color | null;
|
|
77
|
+
readonly stroke_width: number;
|
|
78
|
+
readonly line_cap: number;
|
|
79
|
+
readonly line_join: number;
|
|
80
|
+
readonly miter_limit: number;
|
|
81
|
+
readonly alpha: number;
|
|
82
|
+
};
|
|
83
|
+
type image_source = HTMLImageElement | HTMLCanvasElement | ImageBitmap;
|
|
84
|
+
type renderer = {
|
|
85
|
+
readonly kind: number;
|
|
86
|
+
readonly width: number;
|
|
87
|
+
readonly height: number;
|
|
88
|
+
readonly pixel_ratio: number;
|
|
89
|
+
begin_frame: () => void;
|
|
90
|
+
end_frame: () => void;
|
|
91
|
+
set_transform: (t: transform) => void;
|
|
92
|
+
reset_transform: () => void;
|
|
93
|
+
save: () => void;
|
|
94
|
+
restore: () => void;
|
|
95
|
+
draw_path: (p: path, s: draw_style) => void;
|
|
96
|
+
draw_rectangle: (r: rectangle, s: draw_style) => void;
|
|
97
|
+
draw_circle: (c: circle, s: draw_style) => void;
|
|
98
|
+
draw_line: (a: vector2, b: vector2, s: draw_style) => void;
|
|
99
|
+
draw_polyline: (points: readonly vector2[], s: draw_style) => void;
|
|
100
|
+
draw_image: (image: image_source, r: rectangle, opacity: number, version?: number) => void;
|
|
101
|
+
clip_rectangle: (r: rectangle) => void;
|
|
102
|
+
clear: (c: color) => void;
|
|
103
|
+
resize: (width: number, height: number, pixel_ratio: number) => void;
|
|
104
|
+
dispose: () => void;
|
|
105
|
+
};
|
|
106
|
+
declare function generate_stroke_id(): string;
|
|
107
|
+
declare function create_live_stroke(style: stroke_style, id?: string): live_stroke;
|
|
108
|
+
declare function add_point_live_stroke(live: live_stroke, position: vector2, pressure?: number, timestamp?: number): live_stroke;
|
|
109
|
+
declare function add_raw_point_live_stroke(live: live_stroke, raw_position: vector2, pressure?: number, timestamp?: number): live_stroke;
|
|
110
|
+
declare function get_points_from_live_stroke(live: live_stroke): vector2[];
|
|
111
|
+
declare function get_pressure_from_live_stroke(live: live_stroke): number[] | null;
|
|
112
|
+
declare function render_live_stroke(live: live_stroke, renderer: renderer): void;
|
|
113
|
+
declare function finalize_live_stroke(live: live_stroke, z_index: number, layer_id: string): {
|
|
114
|
+
points: vector2[];
|
|
115
|
+
pressure: number[] | null;
|
|
116
|
+
style: stroke_style;
|
|
117
|
+
id: string;
|
|
118
|
+
z_index: number;
|
|
119
|
+
layer_id: string;
|
|
120
|
+
};
|
|
121
|
+
declare const default_simplify_epsilon = 1;
|
|
122
|
+
declare const default_lod_simplify_factor = 3;
|
|
123
|
+
declare function simplify_stroke_points(points: vector2[], epsilon: number | undefined, out: vector2[]): number;
|
|
124
|
+
declare function simplify_stroke_points_auto(points: vector2[], out: vector2[]): number;
|
|
125
|
+
declare function fit_spline_to_stroke(points: vector2[], out_spline: spline): spline;
|
|
126
|
+
declare function compute_stroke_bounds(points: vector2[], width: number, out: rectangle): rectangle;
|
|
127
|
+
declare function process_stroke(points: vector2[], pressure: number[] | null, style: stroke_style, out_simplified: vector2[], out_spline: spline): {
|
|
128
|
+
simplified: vector2[];
|
|
129
|
+
spline: spline;
|
|
130
|
+
};
|
|
131
|
+
declare function get_simplified_for_lod(points: vector2[], lod_level: number, out: vector2[]): vector2[];
|
|
132
|
+
declare const lod_high = 1;
|
|
133
|
+
declare const lod_medium = .5;
|
|
134
|
+
declare const lod_low = .25;
|
|
135
|
+
declare const spline_evaluation_interval_high = 2;
|
|
136
|
+
declare const spline_evaluation_interval_medium = 4;
|
|
137
|
+
declare const spline_evaluation_interval_low = 8;
|
|
138
|
+
declare function select_lod_from_zoom(zoom: number): number;
|
|
139
|
+
declare function get_spline_evaluation_interval(lod: number): number;
|
|
140
|
+
declare function stroke_to_path_commands(stroke: stroke, lod: number, out_commands: number[]): number;
|
|
141
|
+
declare function render_stroke(stroke: stroke, renderer: renderer, zoom?: number): void;
|
|
142
|
+
declare function render_stroke_with_pressure(stroke: stroke, renderer: renderer, _zoom?: number): void;
|
|
143
|
+
export { stroke_to_path_commands, stroke_style, stroke_point, stroke, stabilizer_state, stabilize_point, spline_evaluation_interval_medium, spline_evaluation_interval_low, spline_evaluation_interval_high, simplify_stroke_points_auto, simplify_stroke_points, select_lod_from_zoom, reset_stabilizer, render_stroke_with_pressure, render_stroke, render_live_stroke, process_stroke, lod_medium, lod_low, lod_high, live_stroke, get_stabilized_history, get_spline_evaluation_interval, get_simplified_for_lod, get_pressure_from_live_stroke, get_points_from_live_stroke, generate_stroke_id, fit_spline_to_stroke, finalize_live_stroke, default_stroke_style, default_stabilizer_history_size, default_smoothing_factor, default_simplify_epsilon, default_lod_simplify_factor, create_stroke_style, create_stabilizer, create_live_stroke, compute_stroke_bounds, clone_stroke_style, add_raw_point_live_stroke, add_point_live_stroke };
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compute_stroke_bounds,
|
|
3
|
+
default_lod_simplify_factor,
|
|
4
|
+
default_simplify_epsilon,
|
|
5
|
+
fit_spline_to_stroke,
|
|
6
|
+
get_simplified_for_lod,
|
|
7
|
+
process_stroke,
|
|
8
|
+
simplify_stroke_points,
|
|
9
|
+
simplify_stroke_points_auto
|
|
10
|
+
} from "../shared/chunk-87399bz7.js";
|
|
11
|
+
import {
|
|
12
|
+
evaluate_spline_at_t,
|
|
13
|
+
get_spline_length
|
|
14
|
+
} from "../shared/chunk-rzxyjwk8.js";
|
|
15
|
+
import {
|
|
16
|
+
line_cap_round,
|
|
17
|
+
line_join_round
|
|
18
|
+
} from "../shared/chunk-wa3772hp.js";
|
|
19
|
+
import"../shared/chunk-v53jprrn.js";
|
|
20
|
+
|
|
21
|
+
// stroke/stroke.ts
|
|
22
|
+
var default_stroke_style = {
|
|
23
|
+
color: [0, 0, 0, 1],
|
|
24
|
+
width: 3,
|
|
25
|
+
opacity: 1,
|
|
26
|
+
pressure_sensitivity: 0.5
|
|
27
|
+
};
|
|
28
|
+
function create_stroke_style(color, width, opacity = 1, pressure_sensitivity = 0.5) {
|
|
29
|
+
return {
|
|
30
|
+
color: [color[0], color[1], color[2], color[3]],
|
|
31
|
+
width,
|
|
32
|
+
opacity,
|
|
33
|
+
pressure_sensitivity
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function clone_stroke_style(s) {
|
|
37
|
+
return {
|
|
38
|
+
color: [s.color[0], s.color[1], s.color[2], s.color[3]],
|
|
39
|
+
width: s.width,
|
|
40
|
+
opacity: s.opacity,
|
|
41
|
+
pressure_sensitivity: s.pressure_sensitivity
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// stroke/stabilizer.ts
|
|
45
|
+
var default_smoothing_factor = 0.3;
|
|
46
|
+
var default_stabilizer_history_size = 5;
|
|
47
|
+
function create_stabilizer(smoothing_factor = default_smoothing_factor) {
|
|
48
|
+
return {
|
|
49
|
+
history: [],
|
|
50
|
+
smoothing_factor
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function stabilize_point(state, raw, out) {
|
|
54
|
+
if (state.history.length === 0) {
|
|
55
|
+
out[0] = raw[0];
|
|
56
|
+
out[1] = raw[1];
|
|
57
|
+
} else {
|
|
58
|
+
const last = state.history[state.history.length - 1];
|
|
59
|
+
out[0] = last[0] + state.smoothing_factor * (raw[0] - last[0]);
|
|
60
|
+
out[1] = last[1] + state.smoothing_factor * (raw[1] - last[1]);
|
|
61
|
+
}
|
|
62
|
+
state.history.push([out[0], out[1]]);
|
|
63
|
+
if (state.history.length > default_stabilizer_history_size) {
|
|
64
|
+
state.history.shift();
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function reset_stabilizer(state) {
|
|
69
|
+
state.history = [];
|
|
70
|
+
}
|
|
71
|
+
function get_stabilized_history(state) {
|
|
72
|
+
return state.history;
|
|
73
|
+
}
|
|
74
|
+
// stroke/live.ts
|
|
75
|
+
var live_stroke_counter = 0;
|
|
76
|
+
function generate_stroke_id() {
|
|
77
|
+
live_stroke_counter = live_stroke_counter + 1;
|
|
78
|
+
return `stroke_${Date.now()}_${live_stroke_counter}`;
|
|
79
|
+
}
|
|
80
|
+
function create_live_stroke(style, id) {
|
|
81
|
+
return {
|
|
82
|
+
id: id ?? generate_stroke_id(),
|
|
83
|
+
points: [],
|
|
84
|
+
style: clone_stroke_style(style),
|
|
85
|
+
stabilizer_state: create_stabilizer()
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function add_point_live_stroke(live, position, pressure = 0.5, timestamp = Date.now()) {
|
|
89
|
+
const next_stabilizer_state = {
|
|
90
|
+
...live.stabilizer_state,
|
|
91
|
+
history: live.stabilizer_state.history.map((p) => [p[0], p[1]])
|
|
92
|
+
};
|
|
93
|
+
const stabilized = [0, 0];
|
|
94
|
+
stabilize_point(next_stabilizer_state, position, stabilized);
|
|
95
|
+
return add_point_to_live_stroke_internal(live, stabilized, pressure, timestamp, next_stabilizer_state);
|
|
96
|
+
}
|
|
97
|
+
function add_raw_point_live_stroke(live, raw_position, pressure = 0.5, timestamp = Date.now()) {
|
|
98
|
+
return add_point_to_live_stroke_internal(live, raw_position, pressure, timestamp);
|
|
99
|
+
}
|
|
100
|
+
function add_point_to_live_stroke_internal(live, position, pressure, timestamp, next_stabilizer_state) {
|
|
101
|
+
const point = {
|
|
102
|
+
position: [position[0], position[1]],
|
|
103
|
+
pressure,
|
|
104
|
+
timestamp
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
...live,
|
|
108
|
+
points: [...live.points, point],
|
|
109
|
+
stabilizer_state: next_stabilizer_state ?? {
|
|
110
|
+
...live.stabilizer_state,
|
|
111
|
+
history: live.stabilizer_state.history.map((p) => [p[0], p[1]])
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function get_points_from_live_stroke(live) {
|
|
116
|
+
return live.points.map((p) => p.position);
|
|
117
|
+
}
|
|
118
|
+
function get_pressure_from_live_stroke(live) {
|
|
119
|
+
if (live.points.length === 0)
|
|
120
|
+
return null;
|
|
121
|
+
return live.points.map((p) => p.pressure);
|
|
122
|
+
}
|
|
123
|
+
function render_live_stroke(live, renderer) {
|
|
124
|
+
if (live.points.length < 2) {
|
|
125
|
+
if (live.points.length === 1) {
|
|
126
|
+
const point = live.points[0];
|
|
127
|
+
const radius = live.style.width * (0.5 + point.pressure * live.style.pressure_sensitivity * 0.5);
|
|
128
|
+
renderer.draw_circle([point.position[0], point.position[1], radius], create_live_style(live.style, true));
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const points = get_points_from_live_stroke(live);
|
|
133
|
+
const style = create_live_style(live.style, false);
|
|
134
|
+
renderer.draw_polyline(points, style);
|
|
135
|
+
}
|
|
136
|
+
function create_live_style(style, is_dot) {
|
|
137
|
+
return {
|
|
138
|
+
fill: is_dot ? style.color : null,
|
|
139
|
+
stroke: style.color,
|
|
140
|
+
stroke_width: style.width,
|
|
141
|
+
line_cap: line_cap_round,
|
|
142
|
+
line_join: line_join_round,
|
|
143
|
+
miter_limit: 10,
|
|
144
|
+
alpha: style.opacity
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function finalize_live_stroke(live, z_index, layer_id) {
|
|
148
|
+
const points = get_points_from_live_stroke(live);
|
|
149
|
+
const pressure = get_pressure_from_live_stroke(live);
|
|
150
|
+
return {
|
|
151
|
+
id: live.id,
|
|
152
|
+
points,
|
|
153
|
+
pressure,
|
|
154
|
+
style: live.style,
|
|
155
|
+
z_index,
|
|
156
|
+
layer_id
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// stroke/render.ts
|
|
160
|
+
var lod_scratch_buffer = [];
|
|
161
|
+
function ensure_lod_scratch(size) {
|
|
162
|
+
while (lod_scratch_buffer.length < size) {
|
|
163
|
+
lod_scratch_buffer.push([0, 0]);
|
|
164
|
+
}
|
|
165
|
+
return lod_scratch_buffer;
|
|
166
|
+
}
|
|
167
|
+
var lod_high = 1;
|
|
168
|
+
var lod_medium = 0.5;
|
|
169
|
+
var lod_low = 0.25;
|
|
170
|
+
var spline_evaluation_interval_high = 2;
|
|
171
|
+
var spline_evaluation_interval_medium = 4;
|
|
172
|
+
var spline_evaluation_interval_low = 8;
|
|
173
|
+
function select_lod_from_zoom(zoom) {
|
|
174
|
+
if (zoom >= 1.5)
|
|
175
|
+
return lod_high;
|
|
176
|
+
if (zoom >= 0.5)
|
|
177
|
+
return lod_medium;
|
|
178
|
+
return lod_low;
|
|
179
|
+
}
|
|
180
|
+
function get_spline_evaluation_interval(lod) {
|
|
181
|
+
if (lod >= lod_medium)
|
|
182
|
+
return spline_evaluation_interval_high;
|
|
183
|
+
if (lod >= lod_low)
|
|
184
|
+
return spline_evaluation_interval_medium;
|
|
185
|
+
return spline_evaluation_interval_low;
|
|
186
|
+
}
|
|
187
|
+
function stroke_to_path_commands(stroke, lod, out_commands) {
|
|
188
|
+
let command_count = 0;
|
|
189
|
+
if (stroke.points.length === 0)
|
|
190
|
+
return 0;
|
|
191
|
+
if (stroke.points.length === 1) {
|
|
192
|
+
out_commands[command_count++] = 0;
|
|
193
|
+
out_commands[command_count++] = stroke.points[0][0];
|
|
194
|
+
out_commands[command_count++] = stroke.points[0][1];
|
|
195
|
+
return command_count;
|
|
196
|
+
}
|
|
197
|
+
const use_spline = stroke.spline !== null && stroke.spline.point_count >= 2;
|
|
198
|
+
const use_lod = lod < lod_high;
|
|
199
|
+
if (use_spline && !use_lod) {
|
|
200
|
+
const interval = get_spline_evaluation_interval(lod);
|
|
201
|
+
const spline_length = get_spline_length(stroke.spline);
|
|
202
|
+
const first_segment = stroke.spline.segments_x[0];
|
|
203
|
+
const last_segment = stroke.spline.segments_x[stroke.spline.segments_x.length - 1];
|
|
204
|
+
const t_start = first_segment.x_start;
|
|
205
|
+
const t_end = last_segment.x_end;
|
|
206
|
+
const steps = Math.max(2, Math.floor(spline_length / interval));
|
|
207
|
+
const dt = (t_end - t_start) / steps;
|
|
208
|
+
const temp_point = [0, 0];
|
|
209
|
+
for (let i = 0;i <= steps; i++) {
|
|
210
|
+
const t = t_start + i * dt;
|
|
211
|
+
evaluate_spline_at_t(stroke.spline, t, temp_point);
|
|
212
|
+
if (i === 0) {
|
|
213
|
+
out_commands[command_count++] = 0;
|
|
214
|
+
} else {
|
|
215
|
+
out_commands[command_count++] = 1;
|
|
216
|
+
}
|
|
217
|
+
out_commands[command_count++] = temp_point[0];
|
|
218
|
+
out_commands[command_count++] = temp_point[1];
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
const points_to_use = use_lod ? get_simplified_for_lod(stroke.points, 1 / lod, ensure_lod_scratch(stroke.points.length)) : stroke.points;
|
|
222
|
+
for (let i = 0;i < points_to_use.length; i++) {
|
|
223
|
+
const point = points_to_use[i];
|
|
224
|
+
if (point === undefined)
|
|
225
|
+
continue;
|
|
226
|
+
if (i === 0) {
|
|
227
|
+
out_commands[command_count++] = 0;
|
|
228
|
+
} else {
|
|
229
|
+
out_commands[command_count++] = 1;
|
|
230
|
+
}
|
|
231
|
+
out_commands[command_count++] = point[0];
|
|
232
|
+
out_commands[command_count++] = point[1];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return command_count;
|
|
236
|
+
}
|
|
237
|
+
function render_stroke(stroke, renderer, zoom = 1) {
|
|
238
|
+
if (stroke.points.length === 0)
|
|
239
|
+
return;
|
|
240
|
+
const lod = select_lod_from_zoom(zoom);
|
|
241
|
+
const style = create_stroke_draw_style(stroke.style);
|
|
242
|
+
if (stroke.points.length === 1) {
|
|
243
|
+
const point = stroke.points[0];
|
|
244
|
+
const radius = stroke.style.width / 2;
|
|
245
|
+
renderer.draw_circle([point[0], point[1], radius], style);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const use_spline = stroke.spline !== null && stroke.spline.point_count >= 2;
|
|
249
|
+
const use_lod = lod < lod_high;
|
|
250
|
+
if (use_spline && !use_lod) {
|
|
251
|
+
const interval = get_spline_evaluation_interval(lod);
|
|
252
|
+
const spline_length = get_spline_length(stroke.spline);
|
|
253
|
+
const first_segment = stroke.spline.segments_x[0];
|
|
254
|
+
const last_segment = stroke.spline.segments_x[stroke.spline.segments_x.length - 1];
|
|
255
|
+
const t_start = first_segment.x_start;
|
|
256
|
+
const t_end = last_segment.x_end;
|
|
257
|
+
const steps = Math.max(2, Math.floor(spline_length / interval));
|
|
258
|
+
const dt = (t_end - t_start) / steps;
|
|
259
|
+
const temp_point = [0, 0];
|
|
260
|
+
const points = ensure_lod_scratch(steps + 1);
|
|
261
|
+
for (let i = 0;i <= steps; i++) {
|
|
262
|
+
const t = t_start + i * dt;
|
|
263
|
+
evaluate_spline_at_t(stroke.spline, t, temp_point);
|
|
264
|
+
const p = points[i];
|
|
265
|
+
p[0] = temp_point[0];
|
|
266
|
+
p[1] = temp_point[1];
|
|
267
|
+
}
|
|
268
|
+
renderer.draw_polyline(points.slice(0, steps + 1), style);
|
|
269
|
+
} else {
|
|
270
|
+
const points_to_use = use_lod ? get_simplified_for_lod(stroke.points, 1 / lod, ensure_lod_scratch(stroke.points.length)) : stroke.points;
|
|
271
|
+
renderer.draw_polyline(points_to_use, style);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function create_stroke_draw_style(style) {
|
|
275
|
+
return {
|
|
276
|
+
fill: null,
|
|
277
|
+
stroke: style.color,
|
|
278
|
+
stroke_width: style.width,
|
|
279
|
+
line_cap: line_cap_round,
|
|
280
|
+
line_join: line_join_round,
|
|
281
|
+
miter_limit: 10,
|
|
282
|
+
alpha: style.opacity
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function render_stroke_with_pressure(stroke, renderer, _zoom = 1) {
|
|
286
|
+
if (stroke.points.length < 2 || stroke.pressure === null) {
|
|
287
|
+
render_stroke(stroke, renderer, _zoom);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const points = stroke.points;
|
|
291
|
+
const pressure = stroke.pressure;
|
|
292
|
+
const base_style = create_stroke_draw_style(stroke.style);
|
|
293
|
+
const base_width = stroke.style.width;
|
|
294
|
+
const sensitivity = stroke.style.pressure_sensitivity;
|
|
295
|
+
for (let i = 0;i < points.length - 1; i++) {
|
|
296
|
+
const p1 = points[i];
|
|
297
|
+
const p2 = points[i + 1];
|
|
298
|
+
const pr1 = pressure[i] ?? 0.5;
|
|
299
|
+
const pr2 = pressure[i + 1] ?? pr1;
|
|
300
|
+
const avg_pressure = (pr1 + pr2) / 2;
|
|
301
|
+
const width = base_width * (1 + avg_pressure * sensitivity);
|
|
302
|
+
renderer.draw_line(p1, p2, { ...base_style, stroke_width: width });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
export {
|
|
306
|
+
stroke_to_path_commands,
|
|
307
|
+
stabilize_point,
|
|
308
|
+
spline_evaluation_interval_medium,
|
|
309
|
+
spline_evaluation_interval_low,
|
|
310
|
+
spline_evaluation_interval_high,
|
|
311
|
+
simplify_stroke_points_auto,
|
|
312
|
+
simplify_stroke_points,
|
|
313
|
+
select_lod_from_zoom,
|
|
314
|
+
reset_stabilizer,
|
|
315
|
+
render_stroke_with_pressure,
|
|
316
|
+
render_stroke,
|
|
317
|
+
render_live_stroke,
|
|
318
|
+
process_stroke,
|
|
319
|
+
lod_medium,
|
|
320
|
+
lod_low,
|
|
321
|
+
lod_high,
|
|
322
|
+
get_stabilized_history,
|
|
323
|
+
get_spline_evaluation_interval,
|
|
324
|
+
get_simplified_for_lod,
|
|
325
|
+
get_pressure_from_live_stroke,
|
|
326
|
+
get_points_from_live_stroke,
|
|
327
|
+
generate_stroke_id,
|
|
328
|
+
fit_spline_to_stroke,
|
|
329
|
+
finalize_live_stroke,
|
|
330
|
+
default_stroke_style,
|
|
331
|
+
default_stabilizer_history_size,
|
|
332
|
+
default_smoothing_factor,
|
|
333
|
+
default_simplify_epsilon,
|
|
334
|
+
default_lod_simplify_factor,
|
|
335
|
+
create_stroke_style,
|
|
336
|
+
create_stabilizer,
|
|
337
|
+
create_live_stroke,
|
|
338
|
+
compute_stroke_bounds,
|
|
339
|
+
clone_stroke_style,
|
|
340
|
+
add_raw_point_live_stroke,
|
|
341
|
+
add_point_live_stroke
|
|
342
|
+
};
|
|
343
|
+
export { default_stroke_style, create_stroke_style, clone_stroke_style, default_smoothing_factor, default_stabilizer_history_size, create_stabilizer, stabilize_point, reset_stabilizer, get_stabilized_history, generate_stroke_id, create_live_stroke, add_point_live_stroke, add_raw_point_live_stroke, get_points_from_live_stroke, get_pressure_from_live_stroke, render_live_stroke, finalize_live_stroke, lod_high, lod_medium, lod_low, spline_evaluation_interval_high, spline_evaluation_interval_medium, spline_evaluation_interval_low, select_lod_from_zoom, get_spline_evaluation_interval, stroke_to_path_commands, render_stroke, render_stroke_with_pressure };
|