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,91 @@
|
|
|
1
|
+
type vector2 = [number, number];
|
|
2
|
+
type transform = [number, number, number, number, number, number];
|
|
3
|
+
type rectangle = [number, number, number, number];
|
|
4
|
+
type circle = [number, number, number];
|
|
5
|
+
type color = [number, number, number, number];
|
|
6
|
+
declare const path_move = 0;
|
|
7
|
+
declare const path_line = 1;
|
|
8
|
+
declare const path_cubic = 2;
|
|
9
|
+
declare const path_close = 3;
|
|
10
|
+
type path_command_move = [typeof path_move, number, number];
|
|
11
|
+
type path_command_line = [typeof path_line, number, number];
|
|
12
|
+
type path_command_cubic = [typeof path_cubic, number, number, number, number, number, number];
|
|
13
|
+
type path_command_close = [typeof path_close];
|
|
14
|
+
type path_command = path_command_move | path_command_line | path_command_cubic | path_command_close;
|
|
15
|
+
type path = {
|
|
16
|
+
readonly commands: readonly path_command[];
|
|
17
|
+
readonly bounds: rectangle;
|
|
18
|
+
};
|
|
19
|
+
declare function create_path(): path;
|
|
20
|
+
declare function clone_path(p: path): path;
|
|
21
|
+
declare function move_to_path(p: path, x: number, y: number): path;
|
|
22
|
+
declare function line_to_path(p: path, x: number, y: number): path;
|
|
23
|
+
declare function cubic_to_path(p: path, c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): path;
|
|
24
|
+
declare function close_path(p: path): path;
|
|
25
|
+
declare function bounds_of_path(p: path): rectangle;
|
|
26
|
+
declare function is_empty_path(p: path): boolean;
|
|
27
|
+
declare function command_count_of_path(p: path): number;
|
|
28
|
+
declare function transform_path(p: path, t: transform, out: path): path;
|
|
29
|
+
declare function hash_of_path(p: path): number;
|
|
30
|
+
declare function from_rectangle_path(r: rectangle): path;
|
|
31
|
+
declare function from_circle_path(c: circle, segments: number): path;
|
|
32
|
+
declare function from_polyline_path(points: readonly vector2[], closed: boolean): path;
|
|
33
|
+
type draw_style = {
|
|
34
|
+
readonly fill: color | null;
|
|
35
|
+
readonly stroke: color | null;
|
|
36
|
+
readonly stroke_width: number;
|
|
37
|
+
readonly line_cap: number;
|
|
38
|
+
readonly line_join: number;
|
|
39
|
+
readonly miter_limit: number;
|
|
40
|
+
readonly alpha: number;
|
|
41
|
+
};
|
|
42
|
+
declare const line_cap_butt = 0;
|
|
43
|
+
declare const line_cap_round = 1;
|
|
44
|
+
declare const line_cap_square = 2;
|
|
45
|
+
declare const line_join_miter = 0;
|
|
46
|
+
declare const line_join_round = 1;
|
|
47
|
+
declare const line_join_bevel = 2;
|
|
48
|
+
declare function create_draw_style(): draw_style;
|
|
49
|
+
declare function clone_draw_style(s: draw_style): draw_style;
|
|
50
|
+
declare function copy_draw_style(s: draw_style, out: draw_style): draw_style;
|
|
51
|
+
declare function set_draw_style(fill: color | null, stroke: color | null, stroke_width: number, line_cap: number, line_join: number, miter_limit: number, alpha: number, out: draw_style): draw_style;
|
|
52
|
+
declare function with_fill_draw_style(s: draw_style, fill: color | null, out: draw_style): draw_style;
|
|
53
|
+
declare function with_stroke_draw_style(s: draw_style, stroke: color | null, stroke_width: number, out: draw_style): draw_style;
|
|
54
|
+
declare function with_alpha_draw_style(s: draw_style, alpha: number, out: draw_style): draw_style;
|
|
55
|
+
declare function with_line_cap_draw_style(s: draw_style, line_cap: number, out: draw_style): draw_style;
|
|
56
|
+
declare function with_line_join_draw_style(s: draw_style, line_join: number, miter_limit: number, out: draw_style): draw_style;
|
|
57
|
+
declare function equals_draw_style(a: draw_style, b: draw_style): boolean;
|
|
58
|
+
declare const renderer_kind_canvas = 0;
|
|
59
|
+
declare const renderer_kind_webgl = 1;
|
|
60
|
+
type renderer_config = {
|
|
61
|
+
readonly prefer_webgl: boolean;
|
|
62
|
+
readonly path_cache_size: number;
|
|
63
|
+
};
|
|
64
|
+
type image_source = HTMLImageElement | HTMLCanvasElement | ImageBitmap;
|
|
65
|
+
type renderer = {
|
|
66
|
+
readonly kind: number;
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
readonly pixel_ratio: number;
|
|
70
|
+
begin_frame: () => void;
|
|
71
|
+
end_frame: () => void;
|
|
72
|
+
set_transform: (t: transform) => void;
|
|
73
|
+
reset_transform: () => void;
|
|
74
|
+
save: () => void;
|
|
75
|
+
restore: () => void;
|
|
76
|
+
draw_path: (p: path, s: draw_style) => void;
|
|
77
|
+
draw_rectangle: (r: rectangle, s: draw_style) => void;
|
|
78
|
+
draw_circle: (c: circle, s: draw_style) => void;
|
|
79
|
+
draw_line: (a: vector2, b: vector2, s: draw_style) => void;
|
|
80
|
+
draw_polyline: (points: readonly vector2[], s: draw_style) => void;
|
|
81
|
+
draw_image: (image: image_source, r: rectangle, opacity: number, version?: number) => void;
|
|
82
|
+
clip_rectangle: (r: rectangle) => void;
|
|
83
|
+
clear: (c: color) => void;
|
|
84
|
+
resize: (width: number, height: number, pixel_ratio: number) => void;
|
|
85
|
+
dispose: () => void;
|
|
86
|
+
};
|
|
87
|
+
declare function create_renderer_config(): renderer_config;
|
|
88
|
+
declare function create_renderer(canvas: HTMLCanvasElement, config: renderer_config): renderer | null;
|
|
89
|
+
declare function create_renderer_canvas(canvas: HTMLCanvasElement, config: renderer_config): renderer | null;
|
|
90
|
+
declare function create_renderer_webgl(canvas: HTMLCanvasElement, config: renderer_config): renderer | null;
|
|
91
|
+
export { with_stroke_draw_style, with_line_join_draw_style, with_line_cap_draw_style, with_fill_draw_style, with_alpha_draw_style, transform_path, set_draw_style, renderer_kind_webgl, renderer_kind_canvas, renderer_config, renderer, path_move, path_line, path_cubic, path_command_move, path_command_line, path_command_cubic, path_command_close, path_command, path_close, path, move_to_path, line_to_path, line_join_round, line_join_miter, line_join_bevel, line_cap_square, line_cap_round, line_cap_butt, is_empty_path, image_source, hash_of_path, from_rectangle_path, from_polyline_path, from_circle_path, equals_draw_style, draw_style, cubic_to_path, create_renderer_webgl, create_renderer_config, create_renderer_canvas, create_renderer, create_path, create_draw_style, copy_draw_style, command_count_of_path, close_path, clone_path, clone_draw_style, bounds_of_path };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
type vector2 = [number, number];
|
|
2
|
+
type transform = [number, number, number, number, number, number];
|
|
3
|
+
type rectangle = [number, number, number, number];
|
|
4
|
+
type circle = [number, number, number];
|
|
5
|
+
type color = [number, number, number, number];
|
|
6
|
+
declare const path_move = 0;
|
|
7
|
+
declare const path_line = 1;
|
|
8
|
+
declare const path_cubic = 2;
|
|
9
|
+
declare const path_close = 3;
|
|
10
|
+
type path_command_move = [typeof path_move, number, number];
|
|
11
|
+
type path_command_line = [typeof path_line, number, number];
|
|
12
|
+
type path_command_cubic = [typeof path_cubic, number, number, number, number, number, number];
|
|
13
|
+
type path_command_close = [typeof path_close];
|
|
14
|
+
type path_command = path_command_move | path_command_line | path_command_cubic | path_command_close;
|
|
15
|
+
type path = {
|
|
16
|
+
readonly commands: readonly path_command[];
|
|
17
|
+
readonly bounds: rectangle;
|
|
18
|
+
};
|
|
19
|
+
declare function create_path(): path;
|
|
20
|
+
declare function clone_path(p: path): path;
|
|
21
|
+
declare function move_to_path(p: path, x: number, y: number): path;
|
|
22
|
+
declare function line_to_path(p: path, x: number, y: number): path;
|
|
23
|
+
declare function cubic_to_path(p: path, c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): path;
|
|
24
|
+
declare function close_path(p: path): path;
|
|
25
|
+
declare function bounds_of_path(p: path): rectangle;
|
|
26
|
+
declare function is_empty_path(p: path): boolean;
|
|
27
|
+
declare function command_count_of_path(p: path): number;
|
|
28
|
+
declare function transform_path(p: path, t: transform, out: path): path;
|
|
29
|
+
declare function hash_of_path(p: path): number;
|
|
30
|
+
declare function from_rectangle_path(r: rectangle): path;
|
|
31
|
+
declare function from_circle_path(c: circle, segments: number): path;
|
|
32
|
+
declare function from_polyline_path(points: readonly vector2[], closed: boolean): path;
|
|
33
|
+
type draw_style = {
|
|
34
|
+
readonly fill: color | null;
|
|
35
|
+
readonly stroke: color | null;
|
|
36
|
+
readonly stroke_width: number;
|
|
37
|
+
readonly line_cap: number;
|
|
38
|
+
readonly line_join: number;
|
|
39
|
+
readonly miter_limit: number;
|
|
40
|
+
readonly alpha: number;
|
|
41
|
+
};
|
|
42
|
+
declare const line_cap_butt = 0;
|
|
43
|
+
declare const line_cap_round = 1;
|
|
44
|
+
declare const line_cap_square = 2;
|
|
45
|
+
declare const line_join_miter = 0;
|
|
46
|
+
declare const line_join_round = 1;
|
|
47
|
+
declare const line_join_bevel = 2;
|
|
48
|
+
declare function create_draw_style(): draw_style;
|
|
49
|
+
declare function clone_draw_style(s: draw_style): draw_style;
|
|
50
|
+
declare function copy_draw_style(s: draw_style, out: draw_style): draw_style;
|
|
51
|
+
declare function set_draw_style(fill: color | null, stroke: color | null, stroke_width: number, line_cap: number, line_join: number, miter_limit: number, alpha: number, out: draw_style): draw_style;
|
|
52
|
+
declare function with_fill_draw_style(s: draw_style, fill: color | null, out: draw_style): draw_style;
|
|
53
|
+
declare function with_stroke_draw_style(s: draw_style, stroke: color | null, stroke_width: number, out: draw_style): draw_style;
|
|
54
|
+
declare function with_alpha_draw_style(s: draw_style, alpha: number, out: draw_style): draw_style;
|
|
55
|
+
declare function with_line_cap_draw_style(s: draw_style, line_cap: number, out: draw_style): draw_style;
|
|
56
|
+
declare function with_line_join_draw_style(s: draw_style, line_join: number, miter_limit: number, out: draw_style): draw_style;
|
|
57
|
+
declare function equals_draw_style(a: draw_style, b: draw_style): boolean;
|
|
58
|
+
declare const renderer_kind_canvas = 0;
|
|
59
|
+
declare const renderer_kind_webgl = 1;
|
|
60
|
+
type renderer_config = {
|
|
61
|
+
readonly prefer_webgl: boolean;
|
|
62
|
+
readonly path_cache_size: number;
|
|
63
|
+
};
|
|
64
|
+
type image_source = HTMLImageElement | HTMLCanvasElement | ImageBitmap;
|
|
65
|
+
type renderer = {
|
|
66
|
+
readonly kind: number;
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
readonly pixel_ratio: number;
|
|
70
|
+
begin_frame: () => void;
|
|
71
|
+
end_frame: () => void;
|
|
72
|
+
set_transform: (t: transform) => void;
|
|
73
|
+
reset_transform: () => void;
|
|
74
|
+
save: () => void;
|
|
75
|
+
restore: () => void;
|
|
76
|
+
draw_path: (p: path, s: draw_style) => void;
|
|
77
|
+
draw_rectangle: (r: rectangle, s: draw_style) => void;
|
|
78
|
+
draw_circle: (c: circle, s: draw_style) => void;
|
|
79
|
+
draw_line: (a: vector2, b: vector2, s: draw_style) => void;
|
|
80
|
+
draw_polyline: (points: readonly vector2[], s: draw_style) => void;
|
|
81
|
+
draw_image: (image: image_source, r: rectangle, opacity: number, version?: number) => void;
|
|
82
|
+
clip_rectangle: (r: rectangle) => void;
|
|
83
|
+
clear: (c: color) => void;
|
|
84
|
+
resize: (width: number, height: number, pixel_ratio: number) => void;
|
|
85
|
+
dispose: () => void;
|
|
86
|
+
};
|
|
87
|
+
declare function create_renderer_config(): renderer_config;
|
|
88
|
+
declare function create_renderer(canvas: HTMLCanvasElement, config: renderer_config): renderer | null;
|
|
89
|
+
declare function create_renderer_canvas(canvas: HTMLCanvasElement, config: renderer_config): renderer | null;
|
|
90
|
+
declare function create_renderer_webgl(canvas: HTMLCanvasElement, config: renderer_config): renderer | null;
|
|
91
|
+
export { with_stroke_draw_style, with_line_join_draw_style, with_line_cap_draw_style, with_fill_draw_style, with_alpha_draw_style, transform_path, set_draw_style, renderer_kind_webgl, renderer_kind_canvas, renderer_config, renderer, path_move, path_line, path_cubic, path_command_move, path_command_line, path_command_cubic, path_command_close, path_command, path_close, path, move_to_path, line_to_path, line_join_round, line_join_miter, line_join_bevel, line_cap_square, line_cap_round, line_cap_butt, is_empty_path, image_source, hash_of_path, from_rectangle_path, from_polyline_path, from_circle_path, equals_draw_style, draw_style, cubic_to_path, create_renderer_webgl, create_renderer_config, create_renderer_canvas, create_renderer, create_path, create_draw_style, copy_draw_style, command_count_of_path, close_path, clone_path, clone_draw_style, bounds_of_path };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bounds_of_path,
|
|
3
|
+
clone_path,
|
|
4
|
+
close_path,
|
|
5
|
+
command_count_of_path,
|
|
6
|
+
create_path,
|
|
7
|
+
create_renderer,
|
|
8
|
+
create_renderer_canvas,
|
|
9
|
+
create_renderer_config,
|
|
10
|
+
create_renderer_webgl,
|
|
11
|
+
cubic_to_path,
|
|
12
|
+
from_circle_path,
|
|
13
|
+
from_polyline_path,
|
|
14
|
+
from_rectangle_path,
|
|
15
|
+
hash_of_path,
|
|
16
|
+
is_empty_path,
|
|
17
|
+
line_to_path,
|
|
18
|
+
move_to_path,
|
|
19
|
+
path_close,
|
|
20
|
+
path_cubic,
|
|
21
|
+
path_line,
|
|
22
|
+
path_move,
|
|
23
|
+
renderer_kind_canvas,
|
|
24
|
+
renderer_kind_webgl,
|
|
25
|
+
transform_path
|
|
26
|
+
} from "../shared/chunk-s3qdcmcq.js";
|
|
27
|
+
import"../shared/chunk-8ynnz57m.js";
|
|
28
|
+
import"../shared/chunk-35pkr0zs.js";
|
|
29
|
+
import {
|
|
30
|
+
clone_draw_style,
|
|
31
|
+
copy_draw_style,
|
|
32
|
+
create_draw_style,
|
|
33
|
+
equals_draw_style,
|
|
34
|
+
line_cap_butt,
|
|
35
|
+
line_cap_round,
|
|
36
|
+
line_cap_square,
|
|
37
|
+
line_join_bevel,
|
|
38
|
+
line_join_miter,
|
|
39
|
+
line_join_round,
|
|
40
|
+
set_draw_style,
|
|
41
|
+
with_alpha_draw_style,
|
|
42
|
+
with_fill_draw_style,
|
|
43
|
+
with_line_cap_draw_style,
|
|
44
|
+
with_line_join_draw_style,
|
|
45
|
+
with_stroke_draw_style
|
|
46
|
+
} from "../shared/chunk-wa3772hp.js";
|
|
47
|
+
import"../shared/chunk-v53jprrn.js";
|
|
48
|
+
export {
|
|
49
|
+
with_stroke_draw_style,
|
|
50
|
+
with_line_join_draw_style,
|
|
51
|
+
with_line_cap_draw_style,
|
|
52
|
+
with_fill_draw_style,
|
|
53
|
+
with_alpha_draw_style,
|
|
54
|
+
transform_path,
|
|
55
|
+
set_draw_style,
|
|
56
|
+
renderer_kind_webgl,
|
|
57
|
+
renderer_kind_canvas,
|
|
58
|
+
path_move,
|
|
59
|
+
path_line,
|
|
60
|
+
path_cubic,
|
|
61
|
+
path_close,
|
|
62
|
+
move_to_path,
|
|
63
|
+
line_to_path,
|
|
64
|
+
line_join_round,
|
|
65
|
+
line_join_miter,
|
|
66
|
+
line_join_bevel,
|
|
67
|
+
line_cap_square,
|
|
68
|
+
line_cap_round,
|
|
69
|
+
line_cap_butt,
|
|
70
|
+
is_empty_path,
|
|
71
|
+
hash_of_path,
|
|
72
|
+
from_rectangle_path,
|
|
73
|
+
from_polyline_path,
|
|
74
|
+
from_circle_path,
|
|
75
|
+
equals_draw_style,
|
|
76
|
+
cubic_to_path,
|
|
77
|
+
create_renderer_webgl,
|
|
78
|
+
create_renderer_config,
|
|
79
|
+
create_renderer_canvas,
|
|
80
|
+
create_renderer,
|
|
81
|
+
create_path,
|
|
82
|
+
create_draw_style,
|
|
83
|
+
copy_draw_style,
|
|
84
|
+
command_count_of_path,
|
|
85
|
+
close_path,
|
|
86
|
+
clone_path,
|
|
87
|
+
clone_draw_style,
|
|
88
|
+
bounds_of_path
|
|
89
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// math/rectangle.ts
|
|
2
|
+
function create_rectangle(x = 0, y = 0, width = 0, height = 0) {
|
|
3
|
+
return [x, y, width, height];
|
|
4
|
+
}
|
|
5
|
+
function clone_rectangle(r) {
|
|
6
|
+
return [r[0], r[1], r[2], r[3]];
|
|
7
|
+
}
|
|
8
|
+
function from_center_rectangle(center, width, height, out) {
|
|
9
|
+
out[0] = center[0] - width / 2;
|
|
10
|
+
out[1] = center[1] - height / 2;
|
|
11
|
+
out[2] = width;
|
|
12
|
+
out[3] = height;
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
function top_of_rectangle(r) {
|
|
16
|
+
return r[1] + r[3];
|
|
17
|
+
}
|
|
18
|
+
function left_of_rectangle(r) {
|
|
19
|
+
return r[0];
|
|
20
|
+
}
|
|
21
|
+
function right_of_rectangle(r) {
|
|
22
|
+
return r[0] + r[2];
|
|
23
|
+
}
|
|
24
|
+
function bottom_of_rectangle(r) {
|
|
25
|
+
return r[1];
|
|
26
|
+
}
|
|
27
|
+
function center_of_rectangle(r, out) {
|
|
28
|
+
out[0] = r[0] + r[2] / 2;
|
|
29
|
+
out[1] = r[1] + r[3] / 2;
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function width_of_rectangle(r) {
|
|
33
|
+
return r[2];
|
|
34
|
+
}
|
|
35
|
+
function height_of_rectangle(r) {
|
|
36
|
+
return r[3];
|
|
37
|
+
}
|
|
38
|
+
function area_of_rectangle(r) {
|
|
39
|
+
return r[2] * r[3];
|
|
40
|
+
}
|
|
41
|
+
function set_rectangle(x, y, width, height, out) {
|
|
42
|
+
out[0] = x;
|
|
43
|
+
out[1] = y;
|
|
44
|
+
out[2] = width;
|
|
45
|
+
out[3] = height;
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
function translate_rectangle(r, dx, dy, out) {
|
|
49
|
+
out[0] = r[0] + dx;
|
|
50
|
+
out[1] = r[1] + dy;
|
|
51
|
+
out[2] = r[2];
|
|
52
|
+
out[3] = r[3];
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function scale_rectangle(r, scale, out) {
|
|
56
|
+
out[0] = r[0] * scale;
|
|
57
|
+
out[1] = r[1] * scale;
|
|
58
|
+
out[2] = r[2] * scale;
|
|
59
|
+
out[3] = r[3] * scale;
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
function contains_point_rectangle(r, x, y) {
|
|
63
|
+
return x >= r[0] && x <= r[0] + r[2] && y >= r[1] && y <= r[1] + r[3];
|
|
64
|
+
}
|
|
65
|
+
function contains_rectangle(r1, r2) {
|
|
66
|
+
return r2[0] >= r1[0] && r2[1] >= r1[1] && r2[0] + r2[2] <= r1[0] + r1[2] && r2[1] + r2[3] <= r1[1] + r1[3];
|
|
67
|
+
}
|
|
68
|
+
function intersects_rectangle(r1, r2) {
|
|
69
|
+
return r1[0] < r2[0] + r2[2] && r1[0] + r1[2] > r2[0] && r1[1] < r2[1] + r2[3] && r1[1] + r1[3] > r2[1];
|
|
70
|
+
}
|
|
71
|
+
function intersection_rectangle(r1, r2, out) {
|
|
72
|
+
const x1 = Math.max(r1[0], r2[0]);
|
|
73
|
+
const y1 = Math.max(r1[1], r2[1]);
|
|
74
|
+
const x2 = Math.min(r1[0] + r1[2], r2[0] + r2[2]);
|
|
75
|
+
const y2 = Math.min(r1[1] + r1[3], r2[1] + r2[3]);
|
|
76
|
+
if (x2 <= x1 || y2 <= y1) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
out[0] = x1;
|
|
80
|
+
out[1] = y1;
|
|
81
|
+
out[2] = x2 - x1;
|
|
82
|
+
out[3] = y2 - y1;
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function union_rectangle(r1, r2, out) {
|
|
86
|
+
const x1 = Math.min(r1[0], r2[0]);
|
|
87
|
+
const y1 = Math.min(r1[1], r2[1]);
|
|
88
|
+
const x2 = Math.max(r1[0] + r1[2], r2[0] + r2[2]);
|
|
89
|
+
const y2 = Math.max(r1[1] + r1[3], r2[1] + r2[3]);
|
|
90
|
+
out[0] = x1;
|
|
91
|
+
out[1] = y1;
|
|
92
|
+
out[2] = x2 - x1;
|
|
93
|
+
out[3] = y2 - y1;
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
function expand_rectangle(r, amount, out) {
|
|
97
|
+
out[0] = r[0] - amount;
|
|
98
|
+
out[1] = r[1] - amount;
|
|
99
|
+
out[2] = r[2] + amount * 2;
|
|
100
|
+
out[3] = r[3] + amount * 2;
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function is_empty_rectangle(r) {
|
|
104
|
+
return r[2] <= 0 || r[3] <= 0;
|
|
105
|
+
}
|
|
106
|
+
function equals_rectangle(r1, r2) {
|
|
107
|
+
return r1[0] === r2[0] && r1[1] === r2[1] && r1[2] === r2[2] && r1[3] === r2[3];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { create_rectangle, clone_rectangle, from_center_rectangle, top_of_rectangle, left_of_rectangle, right_of_rectangle, bottom_of_rectangle, center_of_rectangle, width_of_rectangle, height_of_rectangle, area_of_rectangle, set_rectangle, translate_rectangle, scale_rectangle, contains_point_rectangle, contains_rectangle, intersects_rectangle, intersection_rectangle, union_rectangle, expand_rectangle, is_empty_rectangle, equals_rectangle };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// math/vector2.ts
|
|
2
|
+
function create_vector2(x, y) {
|
|
3
|
+
return [x, y];
|
|
4
|
+
}
|
|
5
|
+
function zero_vector2() {
|
|
6
|
+
return [0, 0];
|
|
7
|
+
}
|
|
8
|
+
function unit_vector2() {
|
|
9
|
+
return [1, 1];
|
|
10
|
+
}
|
|
11
|
+
function clone_vector2(v) {
|
|
12
|
+
return [v[0], v[1]];
|
|
13
|
+
}
|
|
14
|
+
function copy_vector2(v, out) {
|
|
15
|
+
out[0] = v[0];
|
|
16
|
+
out[1] = v[1];
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function set_vector2(x, y, out) {
|
|
20
|
+
out[0] = x;
|
|
21
|
+
out[1] = y;
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
function add_vector2(a, b, out) {
|
|
25
|
+
out[0] = a[0] + b[0];
|
|
26
|
+
out[1] = a[1] + b[1];
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function subtract_vector2(a, b, out) {
|
|
30
|
+
out[0] = a[0] - b[0];
|
|
31
|
+
out[1] = a[1] - b[1];
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function multiply_vector2(a, b, out) {
|
|
35
|
+
out[0] = a[0] * b;
|
|
36
|
+
out[1] = a[1] * b;
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function divide_vector2(a, b, out) {
|
|
40
|
+
out[0] = a[0] / b;
|
|
41
|
+
out[1] = a[1] / b;
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
function normalize_vector2(a, out) {
|
|
45
|
+
const len = length_vector2(a);
|
|
46
|
+
if (len > 0) {
|
|
47
|
+
divide_vector2(a, len, out);
|
|
48
|
+
} else {
|
|
49
|
+
set_vector2(0, 0, out);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function lerp_vector2(a, b, t, out) {
|
|
54
|
+
out[0] = a[0] + t * (b[0] - a[0]);
|
|
55
|
+
out[1] = a[1] + t * (b[1] - a[1]);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
function dot_vector2(a, b) {
|
|
59
|
+
return a[0] * b[0] + a[1] * b[1];
|
|
60
|
+
}
|
|
61
|
+
function cross_vector2(a, b) {
|
|
62
|
+
return a[0] * b[1] - a[1] * b[0];
|
|
63
|
+
}
|
|
64
|
+
function length_squared_vector2(a) {
|
|
65
|
+
return a[0] * a[0] + a[1] * a[1];
|
|
66
|
+
}
|
|
67
|
+
function length_vector2(a) {
|
|
68
|
+
return Math.sqrt(length_squared_vector2(a));
|
|
69
|
+
}
|
|
70
|
+
function distance_squared_vector2(a, b) {
|
|
71
|
+
return length_squared_vector2(subtract_vector2(a, b, zero_vector2()));
|
|
72
|
+
}
|
|
73
|
+
function distance_vector2(a, b) {
|
|
74
|
+
return Math.sqrt(distance_squared_vector2(a, b));
|
|
75
|
+
}
|
|
76
|
+
function is_equal_vector2(a, b, epsilon = 0.0001) {
|
|
77
|
+
return Math.abs(a[0] - b[0]) < epsilon && Math.abs(a[1] - b[1]) < epsilon;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { create_vector2, zero_vector2, unit_vector2, clone_vector2, copy_vector2, set_vector2, add_vector2, subtract_vector2, multiply_vector2, divide_vector2, normalize_vector2, lerp_vector2, dot_vector2, cross_vector2, length_squared_vector2, length_vector2, distance_squared_vector2, distance_vector2, is_equal_vector2 };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
build_natural_spline_from_points,
|
|
3
|
+
estimate_epsilon_from_points,
|
|
4
|
+
simplify_douglas_peucker,
|
|
5
|
+
simplify_points_for_spline
|
|
6
|
+
} from "./chunk-rzxyjwk8.js";
|
|
7
|
+
|
|
8
|
+
// stroke/process.ts
|
|
9
|
+
var default_simplify_epsilon = 1;
|
|
10
|
+
var default_lod_simplify_factor = 3;
|
|
11
|
+
function simplify_stroke_points(points, epsilon = default_simplify_epsilon, out) {
|
|
12
|
+
return simplify_douglas_peucker(points, epsilon, out);
|
|
13
|
+
}
|
|
14
|
+
function simplify_stroke_points_auto(points, out) {
|
|
15
|
+
const epsilon = estimate_epsilon_from_points(points, 0.1);
|
|
16
|
+
return simplify_douglas_peucker(points, epsilon, out);
|
|
17
|
+
}
|
|
18
|
+
function fit_spline_to_stroke(points, out_spline) {
|
|
19
|
+
if (points.length < 2) {
|
|
20
|
+
out_spline.segments_x = [];
|
|
21
|
+
out_spline.segments_y = [];
|
|
22
|
+
out_spline.point_count = 0;
|
|
23
|
+
return out_spline;
|
|
24
|
+
}
|
|
25
|
+
const simplified_for_spline = simplify_points_for_spline(points, 2);
|
|
26
|
+
return build_natural_spline_from_points(simplified_for_spline, out_spline);
|
|
27
|
+
}
|
|
28
|
+
function compute_stroke_bounds(points, width, out) {
|
|
29
|
+
if (points.length === 0) {
|
|
30
|
+
out[0] = 0;
|
|
31
|
+
out[1] = 0;
|
|
32
|
+
out[2] = 0;
|
|
33
|
+
out[3] = 0;
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
let min_x = Infinity;
|
|
37
|
+
let min_y = Infinity;
|
|
38
|
+
let max_x = -Infinity;
|
|
39
|
+
let max_y = -Infinity;
|
|
40
|
+
for (let i = 0;i < points.length; i++) {
|
|
41
|
+
const point = points[i];
|
|
42
|
+
if (point === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
min_x = Math.min(min_x, point[0]);
|
|
45
|
+
min_y = Math.min(min_y, point[1]);
|
|
46
|
+
max_x = Math.max(max_x, point[0]);
|
|
47
|
+
max_y = Math.max(max_y, point[1]);
|
|
48
|
+
}
|
|
49
|
+
const half_width = width / 2;
|
|
50
|
+
out[0] = min_x - half_width;
|
|
51
|
+
out[1] = min_y - half_width;
|
|
52
|
+
out[2] = max_x - min_x + width;
|
|
53
|
+
out[3] = max_y - min_y + width;
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
function process_stroke(points, pressure, style, out_simplified, out_spline) {
|
|
57
|
+
let epsilon = default_simplify_epsilon;
|
|
58
|
+
if (pressure && pressure.length > 1 && style.pressure_sensitivity > 0) {
|
|
59
|
+
const variance = calculate_pressure_variance(pressure);
|
|
60
|
+
epsilon = epsilon / (1 + variance * style.pressure_sensitivity * 2);
|
|
61
|
+
}
|
|
62
|
+
const simplified_count = simplify_stroke_points(points, epsilon, out_simplified);
|
|
63
|
+
const simplified = out_simplified.slice(0, simplified_count);
|
|
64
|
+
fit_spline_to_stroke(simplified, out_spline);
|
|
65
|
+
return {
|
|
66
|
+
simplified,
|
|
67
|
+
spline: out_spline
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function calculate_pressure_variance(pressure) {
|
|
71
|
+
if (pressure.length < 2)
|
|
72
|
+
return 0;
|
|
73
|
+
let sum = 0;
|
|
74
|
+
let sum_sq = 0;
|
|
75
|
+
for (let i = 0;i < pressure.length; i++) {
|
|
76
|
+
const p = pressure[i];
|
|
77
|
+
sum += p;
|
|
78
|
+
sum_sq += p * p;
|
|
79
|
+
}
|
|
80
|
+
const mean = sum / pressure.length;
|
|
81
|
+
return Math.sqrt(Math.max(0, sum_sq / pressure.length - mean * mean));
|
|
82
|
+
}
|
|
83
|
+
function get_simplified_for_lod(points, lod_level, out) {
|
|
84
|
+
const lod_epsilon = default_simplify_epsilon * (lod_level * default_lod_simplify_factor);
|
|
85
|
+
const simplified_count = simplify_douglas_peucker(points, lod_epsilon, out);
|
|
86
|
+
return out.slice(0, simplified_count);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { default_simplify_epsilon, default_lod_simplify_factor, simplify_stroke_points, simplify_stroke_points_auto, fit_spline_to_stroke, compute_stroke_bounds, process_stroke, get_simplified_for_lod };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// math/transform.ts
|
|
2
|
+
function create_transform(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
|
|
3
|
+
return [a, b, c, d, tx, ty];
|
|
4
|
+
}
|
|
5
|
+
function clone_transform(t) {
|
|
6
|
+
return [t[0], t[1], t[2], t[3], t[4], t[5]];
|
|
7
|
+
}
|
|
8
|
+
function set_transform(a, b, c, d, tx, ty, out) {
|
|
9
|
+
out[0] = a;
|
|
10
|
+
out[1] = b;
|
|
11
|
+
out[2] = c;
|
|
12
|
+
out[3] = d;
|
|
13
|
+
out[4] = tx;
|
|
14
|
+
out[5] = ty;
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
function copy_transform(t, out) {
|
|
18
|
+
out[0] = t[0];
|
|
19
|
+
out[1] = t[1];
|
|
20
|
+
out[2] = t[2];
|
|
21
|
+
out[3] = t[3];
|
|
22
|
+
out[4] = t[4];
|
|
23
|
+
out[5] = t[5];
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
function identity_transform() {
|
|
27
|
+
return [1, 0, 0, 1, 0, 0];
|
|
28
|
+
}
|
|
29
|
+
function set_identity_transform(out) {
|
|
30
|
+
out[0] = 1;
|
|
31
|
+
out[1] = 0;
|
|
32
|
+
out[2] = 0;
|
|
33
|
+
out[3] = 1;
|
|
34
|
+
out[4] = 0;
|
|
35
|
+
out[5] = 0;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function translate_transform(x, y) {
|
|
39
|
+
return [1, 0, 0, 1, x, y];
|
|
40
|
+
}
|
|
41
|
+
function scale_transform(sx, sy = sx) {
|
|
42
|
+
return [sx, 0, 0, sy, 0, 0];
|
|
43
|
+
}
|
|
44
|
+
function rotate_transform(angle) {
|
|
45
|
+
const cos = Math.cos(angle);
|
|
46
|
+
const sin = Math.sin(angle);
|
|
47
|
+
return [cos, sin, -sin, cos, 0, 0];
|
|
48
|
+
}
|
|
49
|
+
function from_trs_transform(translation, rotation, scale) {
|
|
50
|
+
const cos = Math.cos(rotation);
|
|
51
|
+
const sin = Math.sin(rotation);
|
|
52
|
+
return [
|
|
53
|
+
cos * scale[0],
|
|
54
|
+
sin * scale[0],
|
|
55
|
+
-sin * scale[1],
|
|
56
|
+
cos * scale[1],
|
|
57
|
+
translation[0],
|
|
58
|
+
translation[1]
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
function multiply_transform(t1, t2, out) {
|
|
62
|
+
out[0] = t1[0] * t2[0] + t1[2] * t2[1];
|
|
63
|
+
out[1] = t1[1] * t2[0] + t1[3] * t2[1];
|
|
64
|
+
out[2] = t1[0] * t2[2] + t1[2] * t2[3];
|
|
65
|
+
out[3] = t1[1] * t2[2] + t1[3] * t2[3];
|
|
66
|
+
out[4] = t1[0] * t2[4] + t1[2] * t2[5] + t1[4];
|
|
67
|
+
out[5] = t1[1] * t2[4] + t1[3] * t2[5] + t1[5];
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function determinant_transform(t) {
|
|
71
|
+
return t[0] * t[3] - t[1] * t[2];
|
|
72
|
+
}
|
|
73
|
+
function invert_transform(t, out) {
|
|
74
|
+
const det = determinant_transform(t);
|
|
75
|
+
if (Math.abs(det) < 0.0000000001) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const inverse_det = 1 / det;
|
|
79
|
+
out[0] = t[3] * inverse_det;
|
|
80
|
+
out[1] = -t[1] * inverse_det;
|
|
81
|
+
out[2] = -t[2] * inverse_det;
|
|
82
|
+
out[3] = t[0] * inverse_det;
|
|
83
|
+
out[4] = (t[2] * t[5] - t[3] * t[4]) * inverse_det;
|
|
84
|
+
out[5] = (t[1] * t[4] - t[0] * t[5]) * inverse_det;
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
function transform_point_transform(t, point, out) {
|
|
88
|
+
out[0] = t[0] * point[0] + t[2] * point[1] + t[4];
|
|
89
|
+
out[1] = t[1] * point[0] + t[3] * point[1] + t[5];
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
function transform_vector_transform(t, vector, out) {
|
|
93
|
+
out[0] = t[0] * vector[0] + t[2] * vector[1];
|
|
94
|
+
out[1] = t[1] * vector[0] + t[3] * vector[1];
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
function append_translation_transform(t, x, y, out) {
|
|
98
|
+
const translation = translate_transform(x, y);
|
|
99
|
+
return multiply_transform(t, translation, out);
|
|
100
|
+
}
|
|
101
|
+
function append_rotation_transform(t, angle, out) {
|
|
102
|
+
const rotation = rotate_transform(angle);
|
|
103
|
+
return multiply_transform(t, rotation, out);
|
|
104
|
+
}
|
|
105
|
+
function append_scale_transform(t, sx, sy = sx, out) {
|
|
106
|
+
const scale = scale_transform(sx, sy);
|
|
107
|
+
return multiply_transform(t, scale, out);
|
|
108
|
+
}
|
|
109
|
+
function prepend_translation_transform(x, y, t, out) {
|
|
110
|
+
const translation = translate_transform(x, y);
|
|
111
|
+
return multiply_transform(translation, t, out);
|
|
112
|
+
}
|
|
113
|
+
function prepend_rotation_transform(angle, t, out) {
|
|
114
|
+
const rotation = rotate_transform(angle);
|
|
115
|
+
return multiply_transform(rotation, t, out);
|
|
116
|
+
}
|
|
117
|
+
function prepend_scale_transform(sx, sy = sx, t, out) {
|
|
118
|
+
const scale = scale_transform(sx, sy);
|
|
119
|
+
return multiply_transform(scale, t, out);
|
|
120
|
+
}
|
|
121
|
+
function equals_transform(t1, t2, epsilon = 0.0001) {
|
|
122
|
+
return Math.abs(t1[0] - t2[0]) < epsilon && Math.abs(t1[1] - t2[1]) < epsilon && Math.abs(t1[2] - t2[2]) < epsilon && Math.abs(t1[3] - t2[3]) < epsilon && Math.abs(t1[4] - t2[4]) < epsilon && Math.abs(t1[5] - t2[5]) < epsilon;
|
|
123
|
+
}
|
|
124
|
+
function is_identity_transform(t, epsilon = 0.0001) {
|
|
125
|
+
const identity = identity_transform();
|
|
126
|
+
return equals_transform(t, identity, epsilon);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { create_transform, clone_transform, set_transform, copy_transform, identity_transform, set_identity_transform, translate_transform, scale_transform, rotate_transform, from_trs_transform, multiply_transform, determinant_transform, invert_transform, transform_point_transform, transform_vector_transform, append_translation_transform, append_rotation_transform, append_scale_transform, prepend_translation_transform, prepend_rotation_transform, prepend_scale_transform, equals_transform, is_identity_transform };
|