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,500 @@
|
|
|
1
|
+
import {
|
|
2
|
+
camera_frustum,
|
|
3
|
+
pan_camera,
|
|
4
|
+
screen_to_world_camera,
|
|
5
|
+
set_camera,
|
|
6
|
+
world_to_screen_camera,
|
|
7
|
+
zoom_at_camera,
|
|
8
|
+
zoom_camera
|
|
9
|
+
} from "./chunk-hewznwbd.js";
|
|
10
|
+
import {
|
|
11
|
+
element_type_image,
|
|
12
|
+
element_type_shape,
|
|
13
|
+
element_type_stroke,
|
|
14
|
+
element_type_text,
|
|
15
|
+
shape_type_arrow,
|
|
16
|
+
shape_type_ellipse,
|
|
17
|
+
shape_type_frame,
|
|
18
|
+
shape_type_line,
|
|
19
|
+
shape_type_rectangle,
|
|
20
|
+
text_align_center,
|
|
21
|
+
text_align_right
|
|
22
|
+
} from "./chunk-jdvrd5tv.js";
|
|
23
|
+
import {
|
|
24
|
+
to_rgba_string_color
|
|
25
|
+
} from "./chunk-v53jprrn.js";
|
|
26
|
+
|
|
27
|
+
// engine/shared.ts
|
|
28
|
+
var default_background = [1, 1, 1, 1];
|
|
29
|
+
var default_element_fill = [0.95, 0.97, 1, 1];
|
|
30
|
+
var default_element_stroke = [0.18, 0.22, 0.31, 1];
|
|
31
|
+
var min_zoom_engine = 0.0001;
|
|
32
|
+
var max_zoom_engine = 1e6;
|
|
33
|
+
var scratch_camera = [0, 0, 1, 0];
|
|
34
|
+
var scratch_frustum = [0, 0, 0, 0, 0, 0];
|
|
35
|
+
var scratch_transform = [1, 0, 0, 1, 0, 0];
|
|
36
|
+
var scratch_world = [0, 0];
|
|
37
|
+
var scratch_screen = [0, 0];
|
|
38
|
+
|
|
39
|
+
// engine/camera.ts
|
|
40
|
+
function set_camera_engine(state, x, y, zoom, rotation = 0) {
|
|
41
|
+
set_camera(sanitize_number_engine(x, state.camera[0]), sanitize_number_engine(y, state.camera[1]), sanitize_zoom_engine(zoom, state.camera[2]), sanitize_number_engine(rotation, state.camera[3]), state.camera);
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
function pan_engine(state, dx, dy) {
|
|
45
|
+
pan_camera(state.camera, dx, dy, scratch_camera);
|
|
46
|
+
copy_camera_into_engine(state, scratch_camera);
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
function zoom_engine(state, factor) {
|
|
50
|
+
zoom_camera(state.camera, factor, scratch_camera);
|
|
51
|
+
copy_camera_into_engine(state, scratch_camera);
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
function zoom_at_engine(state, factor, screen_x, screen_y) {
|
|
55
|
+
scratch_screen[0] = screen_x;
|
|
56
|
+
scratch_screen[1] = screen_y;
|
|
57
|
+
screen_to_world_camera(state.camera, state.viewport, scratch_screen, scratch_world);
|
|
58
|
+
zoom_at_camera(state.camera, factor, {
|
|
59
|
+
screen_x,
|
|
60
|
+
screen_y,
|
|
61
|
+
world_x: scratch_world[0],
|
|
62
|
+
world_y: scratch_world[1]
|
|
63
|
+
}, scratch_camera);
|
|
64
|
+
copy_camera_into_engine(state, scratch_camera);
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
function resize_engine(state, width, height, pixel_ratio = Math.max(1, globalThis.devicePixelRatio || 1)) {
|
|
68
|
+
const safe_width = Math.max(1, width);
|
|
69
|
+
const safe_height = Math.max(1, height);
|
|
70
|
+
const safe_pixel_ratio = Math.max(1, pixel_ratio);
|
|
71
|
+
state.viewport[0] = safe_width;
|
|
72
|
+
state.viewport[1] = safe_height;
|
|
73
|
+
state.viewport[2] = safe_pixel_ratio;
|
|
74
|
+
state.renderer.resize(safe_width, safe_height, safe_pixel_ratio);
|
|
75
|
+
return state;
|
|
76
|
+
}
|
|
77
|
+
function world_to_screen_engine(state, world, out) {
|
|
78
|
+
return world_to_screen_camera(state.camera, state.viewport, world, out);
|
|
79
|
+
}
|
|
80
|
+
function screen_to_world_engine(state, screen, out) {
|
|
81
|
+
return screen_to_world_camera(state.camera, state.viewport, screen, out);
|
|
82
|
+
}
|
|
83
|
+
function visible_bounds_world_engine(state) {
|
|
84
|
+
camera_frustum(state.camera, state.viewport, scratch_frustum);
|
|
85
|
+
return [
|
|
86
|
+
scratch_frustum[0],
|
|
87
|
+
scratch_frustum[3],
|
|
88
|
+
scratch_frustum[1] - scratch_frustum[0],
|
|
89
|
+
scratch_frustum[2] - scratch_frustum[3]
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
function camera_to_screen_transform_engine(c, v, out) {
|
|
93
|
+
const cos_r = Math.cos(c[3]);
|
|
94
|
+
const sin_r = Math.sin(c[3]);
|
|
95
|
+
const zoom = c[2];
|
|
96
|
+
out[0] = cos_r * zoom;
|
|
97
|
+
out[1] = sin_r * zoom;
|
|
98
|
+
out[2] = -sin_r * zoom;
|
|
99
|
+
out[3] = cos_r * zoom;
|
|
100
|
+
out[4] = v[0] / 2 - c[0] * cos_r * zoom + c[1] * sin_r * zoom;
|
|
101
|
+
out[5] = v[1] / 2 - c[0] * sin_r * zoom - c[1] * cos_r * zoom;
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
function sanitize_number_engine(value, fallback) {
|
|
105
|
+
if (Number.isFinite(value)) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
return Number.isFinite(fallback) ? fallback : 0;
|
|
109
|
+
}
|
|
110
|
+
function sanitize_zoom_engine(value, fallback) {
|
|
111
|
+
const safe_value = Number.isFinite(value) ? value : fallback;
|
|
112
|
+
if (!Number.isFinite(safe_value) || safe_value <= 0) {
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
return Math.min(max_zoom_engine, Math.max(min_zoom_engine, safe_value));
|
|
116
|
+
}
|
|
117
|
+
function copy_camera_into_engine(state, value) {
|
|
118
|
+
state.camera[0] = sanitize_number_engine(value[0], state.camera[0]);
|
|
119
|
+
state.camera[1] = sanitize_number_engine(value[1], state.camera[1]);
|
|
120
|
+
state.camera[2] = sanitize_zoom_engine(value[2], state.camera[2]);
|
|
121
|
+
state.camera[3] = sanitize_number_engine(value[3], state.camera[3]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// document/query.ts
|
|
125
|
+
function elements_in_bounds_document(doc, bounds) {
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const el of doc.elements.values()) {
|
|
128
|
+
const el_bounds = el.bounds;
|
|
129
|
+
if (el_bounds[0] < bounds[0] + bounds[2] && el_bounds[0] + el_bounds[2] > bounds[0] && el_bounds[1] < bounds[1] + bounds[3] && el_bounds[1] + el_bounds[3] > bounds[1]) {
|
|
130
|
+
results.push(el);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return results;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// engine/elements.ts
|
|
137
|
+
var loaded_images_engine = new Map;
|
|
138
|
+
var text_bitmap_cache_engine = new Map;
|
|
139
|
+
var text_bitmap_cache_limit_engine = 128;
|
|
140
|
+
function render_element_engine(drawer, el, asset_src = null) {
|
|
141
|
+
if (el.type === element_type_stroke) {
|
|
142
|
+
render_stroke_element_engine(drawer, el);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (el.type === element_type_shape) {
|
|
146
|
+
render_shape_element_engine(drawer, el);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (el.type === element_type_image) {
|
|
150
|
+
render_image_element_engine(drawer, el, asset_src);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (el.type === element_type_text) {
|
|
154
|
+
render_text_element_engine(drawer, el);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function render_stroke_element_engine(drawer, el) {
|
|
158
|
+
const style = {
|
|
159
|
+
fill: null,
|
|
160
|
+
stroke: el.color,
|
|
161
|
+
stroke_width: el.width,
|
|
162
|
+
line_cap: 1,
|
|
163
|
+
line_join: 1,
|
|
164
|
+
miter_limit: 10,
|
|
165
|
+
alpha: el.color[3]
|
|
166
|
+
};
|
|
167
|
+
const points = el.simplified_points && el.simplified_points.length > 1 ? el.simplified_points : el.points;
|
|
168
|
+
if (points.length === 1) {
|
|
169
|
+
const p = points[0];
|
|
170
|
+
if (p !== undefined) {
|
|
171
|
+
drawer.draw_circle([p[0], p[1], Math.max(0.5, el.width * 0.5)], style);
|
|
172
|
+
}
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (points.length > 1) {
|
|
176
|
+
drawer.draw_polyline(points, style);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function render_shape_element_engine(drawer, el) {
|
|
180
|
+
const style = {
|
|
181
|
+
fill: el.fill_color,
|
|
182
|
+
stroke: el.stroke_color,
|
|
183
|
+
stroke_width: el.stroke_width,
|
|
184
|
+
line_cap: 1,
|
|
185
|
+
line_join: 1,
|
|
186
|
+
miter_limit: 10,
|
|
187
|
+
alpha: 1
|
|
188
|
+
};
|
|
189
|
+
if (el.shape_type === shape_type_rectangle) {
|
|
190
|
+
drawer.draw_rectangle(el.bounds, style);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (el.shape_type === shape_type_frame) {
|
|
194
|
+
const header_height = Math.max(20, Math.min(36, el.bounds[3] * 0.18));
|
|
195
|
+
const header_style = {
|
|
196
|
+
fill: style.stroke,
|
|
197
|
+
stroke: style.stroke,
|
|
198
|
+
stroke_width: Math.max(1, style.stroke_width),
|
|
199
|
+
line_cap: style.line_cap,
|
|
200
|
+
line_join: style.line_join,
|
|
201
|
+
miter_limit: style.miter_limit,
|
|
202
|
+
alpha: 0.12
|
|
203
|
+
};
|
|
204
|
+
const outline_style = {
|
|
205
|
+
...style,
|
|
206
|
+
fill: null,
|
|
207
|
+
alpha: 1
|
|
208
|
+
};
|
|
209
|
+
drawer.draw_rectangle(el.bounds, outline_style);
|
|
210
|
+
drawer.draw_rectangle([el.bounds[0], el.bounds[1], el.bounds[2], header_height], header_style);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (el.shape_type === shape_type_ellipse) {
|
|
214
|
+
const cx = el.bounds[0] + el.bounds[2] / 2;
|
|
215
|
+
const cy = el.bounds[1] + el.bounds[3] / 2;
|
|
216
|
+
const rx = Math.max(0.5, Math.abs(el.bounds[2]) / 2);
|
|
217
|
+
const ry = Math.max(0.5, Math.abs(el.bounds[3]) / 2);
|
|
218
|
+
const segments = 40;
|
|
219
|
+
const points = [];
|
|
220
|
+
for (let i = 0;i <= segments; i = i + 1) {
|
|
221
|
+
const t = i / segments * Math.PI * 2;
|
|
222
|
+
points.push([cx + Math.cos(t) * rx, cy + Math.sin(t) * ry]);
|
|
223
|
+
}
|
|
224
|
+
drawer.draw_polyline(points, style);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (el.shape_type === shape_type_line || el.shape_type === shape_type_arrow) {
|
|
228
|
+
const from = el.start_point ?? [el.bounds[0], el.bounds[1]];
|
|
229
|
+
const to = el.end_point ?? [el.bounds[0] + el.bounds[2], el.bounds[1] + el.bounds[3]];
|
|
230
|
+
drawer.draw_line(from, to, style);
|
|
231
|
+
if (el.shape_type === shape_type_arrow) {
|
|
232
|
+
draw_arrowhead_engine(drawer, from, to, style);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function render_image_element_engine(drawer, el, asset_src) {
|
|
237
|
+
const image = resolve_image_source_engine(el, asset_src);
|
|
238
|
+
const opacity = Math.max(0, Math.min(1, el.opacity));
|
|
239
|
+
if (image.status === "loaded" && image.source !== null) {
|
|
240
|
+
drawer.draw_image(image.source, fit_image_bounds_engine(el.bounds, image.source), opacity);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const style = {
|
|
244
|
+
fill: default_element_fill,
|
|
245
|
+
stroke: default_element_stroke,
|
|
246
|
+
stroke_width: 1,
|
|
247
|
+
line_cap: 1,
|
|
248
|
+
line_join: 1,
|
|
249
|
+
miter_limit: 10,
|
|
250
|
+
alpha: opacity
|
|
251
|
+
};
|
|
252
|
+
drawer.draw_rectangle(el.bounds, style);
|
|
253
|
+
if (image.status === "error") {
|
|
254
|
+
const mark_style = {
|
|
255
|
+
fill: null,
|
|
256
|
+
stroke: default_element_stroke,
|
|
257
|
+
stroke_width: 1.5,
|
|
258
|
+
line_cap: 1,
|
|
259
|
+
line_join: 1,
|
|
260
|
+
miter_limit: 10,
|
|
261
|
+
alpha: opacity
|
|
262
|
+
};
|
|
263
|
+
const inset = Math.max(8, Math.min(el.bounds[2], el.bounds[3]) * 0.12);
|
|
264
|
+
const x0 = el.bounds[0] + inset;
|
|
265
|
+
const y0 = el.bounds[1] + inset;
|
|
266
|
+
const x1 = el.bounds[0] + el.bounds[2] - inset;
|
|
267
|
+
const y1 = el.bounds[1] + el.bounds[3] - inset;
|
|
268
|
+
drawer.draw_line([x0, y0], [x1, y1], mark_style);
|
|
269
|
+
drawer.draw_line([x1, y0], [x0, y1], mark_style);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function render_text_element_engine(drawer, el) {
|
|
273
|
+
const key = [
|
|
274
|
+
el.content,
|
|
275
|
+
el.font_family,
|
|
276
|
+
el.font_size,
|
|
277
|
+
el.color.join(","),
|
|
278
|
+
el.align,
|
|
279
|
+
Math.max(1, Math.round(el.bounds[2])),
|
|
280
|
+
Math.max(1, Math.round(el.bounds[3])),
|
|
281
|
+
Math.max(1, Math.round(drawer.pixel_ratio))
|
|
282
|
+
].join("|");
|
|
283
|
+
let bitmap = text_bitmap_cache_engine.get(key);
|
|
284
|
+
if (bitmap === undefined) {
|
|
285
|
+
bitmap = rasterize_text_engine(el, Math.max(1, Math.round(drawer.pixel_ratio)));
|
|
286
|
+
text_bitmap_cache_engine.set(key, bitmap);
|
|
287
|
+
trim_text_bitmap_cache_engine();
|
|
288
|
+
}
|
|
289
|
+
drawer.draw_image(bitmap, el.bounds, 1);
|
|
290
|
+
}
|
|
291
|
+
function resolve_image_source_engine(el, asset_src) {
|
|
292
|
+
if (el.bitmap !== null) {
|
|
293
|
+
return { status: "loaded", source: el.bitmap };
|
|
294
|
+
}
|
|
295
|
+
const src = (asset_src ?? el.src).trim();
|
|
296
|
+
if (src.length === 0 || typeof Image === "undefined") {
|
|
297
|
+
return { status: "empty", source: null };
|
|
298
|
+
}
|
|
299
|
+
let cached = loaded_images_engine.get(src);
|
|
300
|
+
if (cached === undefined) {
|
|
301
|
+
const image = new Image;
|
|
302
|
+
cached = { image, status: "loading" };
|
|
303
|
+
loaded_images_engine.set(src, cached);
|
|
304
|
+
image.onload = () => {
|
|
305
|
+
const current = loaded_images_engine.get(src);
|
|
306
|
+
if (current !== undefined)
|
|
307
|
+
current.status = "loaded";
|
|
308
|
+
};
|
|
309
|
+
image.onerror = () => {
|
|
310
|
+
const current = loaded_images_engine.get(src);
|
|
311
|
+
if (current !== undefined)
|
|
312
|
+
current.status = "error";
|
|
313
|
+
};
|
|
314
|
+
image.src = src;
|
|
315
|
+
return { status: "loading", source: null };
|
|
316
|
+
}
|
|
317
|
+
if (cached.status === "loaded") {
|
|
318
|
+
return { status: "loaded", source: cached.image };
|
|
319
|
+
}
|
|
320
|
+
return { status: cached.status, source: null };
|
|
321
|
+
}
|
|
322
|
+
function fit_image_bounds_engine(bounds, source) {
|
|
323
|
+
const source_w = source instanceof HTMLImageElement ? source.naturalWidth : source.width;
|
|
324
|
+
const source_h = source instanceof HTMLImageElement ? source.naturalHeight : source.height;
|
|
325
|
+
const x = bounds[0];
|
|
326
|
+
const y = bounds[1];
|
|
327
|
+
const w = Math.max(1, bounds[2]);
|
|
328
|
+
const h = Math.max(1, bounds[3]);
|
|
329
|
+
if (source_w <= 0 || source_h <= 0) {
|
|
330
|
+
return [x, y, w, h];
|
|
331
|
+
}
|
|
332
|
+
const scale = Math.min(w / source_w, h / source_h);
|
|
333
|
+
const draw_w = source_w * scale;
|
|
334
|
+
const draw_h = source_h * scale;
|
|
335
|
+
const draw_x = x + (w - draw_w) * 0.5;
|
|
336
|
+
const draw_y = y + (h - draw_h) * 0.5;
|
|
337
|
+
return [draw_x, draw_y, draw_w, draw_h];
|
|
338
|
+
}
|
|
339
|
+
function draw_arrowhead_engine(drawer, from, to, style) {
|
|
340
|
+
const dx = to[0] - from[0];
|
|
341
|
+
const dy = to[1] - from[1];
|
|
342
|
+
const len = Math.hypot(dx, dy);
|
|
343
|
+
if (len < 0.0001)
|
|
344
|
+
return;
|
|
345
|
+
const ux = dx / len;
|
|
346
|
+
const uy = dy / len;
|
|
347
|
+
const size = Math.max(8, style.stroke_width * 5);
|
|
348
|
+
const wing_angle = Math.PI / 7;
|
|
349
|
+
const cos = Math.cos(wing_angle);
|
|
350
|
+
const sin = Math.sin(wing_angle);
|
|
351
|
+
const lx = to[0] - (ux * cos - uy * sin) * size;
|
|
352
|
+
const ly = to[1] - (uy * cos + ux * sin) * size;
|
|
353
|
+
const rx = to[0] - (ux * cos + uy * sin) * size;
|
|
354
|
+
const ry = to[1] - (uy * cos - ux * sin) * size;
|
|
355
|
+
drawer.draw_line(to, [lx, ly], style);
|
|
356
|
+
drawer.draw_line(to, [rx, ry], style);
|
|
357
|
+
}
|
|
358
|
+
function rasterize_text_engine(el, scale) {
|
|
359
|
+
const canvas = document.createElement("canvas");
|
|
360
|
+
const width = Math.max(1, Math.ceil(el.bounds[2] * scale));
|
|
361
|
+
const height = Math.max(1, Math.ceil(el.bounds[3] * scale));
|
|
362
|
+
canvas.width = width;
|
|
363
|
+
canvas.height = height;
|
|
364
|
+
const ctx = canvas.getContext("2d");
|
|
365
|
+
if (ctx === null)
|
|
366
|
+
return canvas;
|
|
367
|
+
const font_size = Math.max(1, el.font_size);
|
|
368
|
+
const line_height = font_size * 1.3;
|
|
369
|
+
const padding = Math.max(4, Math.round(font_size * 0.35));
|
|
370
|
+
const max_text_width = Math.max(1, el.bounds[2] - padding * 2);
|
|
371
|
+
ctx.scale(scale, scale);
|
|
372
|
+
ctx.font = `${font_size}px ${el.font_family}`;
|
|
373
|
+
ctx.textBaseline = "top";
|
|
374
|
+
ctx.fillStyle = to_rgba_string_color(el.color);
|
|
375
|
+
const lines = wrap_text_lines_engine(ctx, el.content, max_text_width);
|
|
376
|
+
const base_x = el.bounds[0];
|
|
377
|
+
const base_y = el.bounds[1];
|
|
378
|
+
const text_top = base_y + padding;
|
|
379
|
+
const text_bottom = base_y + el.bounds[3] - padding;
|
|
380
|
+
let y = text_top;
|
|
381
|
+
for (let i = 0;i < lines.length; i = i + 1) {
|
|
382
|
+
const line = lines[i];
|
|
383
|
+
if (line === undefined)
|
|
384
|
+
continue;
|
|
385
|
+
if (y + line_height > text_bottom + 0.5)
|
|
386
|
+
break;
|
|
387
|
+
const line_width = ctx.measureText(line).width;
|
|
388
|
+
let x = base_x + padding;
|
|
389
|
+
if (el.align === text_align_center) {
|
|
390
|
+
x = base_x + el.bounds[2] * 0.5 - line_width * 0.5;
|
|
391
|
+
} else if (el.align === text_align_right) {
|
|
392
|
+
x = base_x + el.bounds[2] - padding - line_width;
|
|
393
|
+
}
|
|
394
|
+
ctx.fillText(line, x - base_x, y - base_y);
|
|
395
|
+
y = y + line_height;
|
|
396
|
+
}
|
|
397
|
+
return canvas;
|
|
398
|
+
}
|
|
399
|
+
function wrap_text_lines_engine(ctx, content, max_width) {
|
|
400
|
+
const normalized = content.length > 0 ? content : "";
|
|
401
|
+
const paragraphs = normalized.split(/\r?\n/);
|
|
402
|
+
const lines = [];
|
|
403
|
+
for (let i = 0;i < paragraphs.length; i = i + 1) {
|
|
404
|
+
const paragraph = paragraphs[i];
|
|
405
|
+
if (paragraph === undefined)
|
|
406
|
+
continue;
|
|
407
|
+
if (paragraph.length === 0) {
|
|
408
|
+
lines.push("");
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
const words = paragraph.split(/(\s+)/).filter((word) => word.length > 0);
|
|
412
|
+
let current = "";
|
|
413
|
+
for (let j = 0;j < words.length; j = j + 1) {
|
|
414
|
+
const word = words[j];
|
|
415
|
+
if (word === undefined)
|
|
416
|
+
continue;
|
|
417
|
+
const candidate = current.length === 0 ? word : `${current}${word}`;
|
|
418
|
+
if (ctx.measureText(candidate).width <= max_width || current.length === 0) {
|
|
419
|
+
current = candidate;
|
|
420
|
+
} else {
|
|
421
|
+
lines.push(current.trimEnd());
|
|
422
|
+
current = word.trimStart();
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
lines.push(current.length > 0 ? current : "");
|
|
426
|
+
}
|
|
427
|
+
return lines;
|
|
428
|
+
}
|
|
429
|
+
function trim_text_bitmap_cache_engine() {
|
|
430
|
+
if (text_bitmap_cache_engine.size <= text_bitmap_cache_limit_engine) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const remove_count = Math.ceil(text_bitmap_cache_engine.size / 3);
|
|
434
|
+
let removed = 0;
|
|
435
|
+
for (const key of text_bitmap_cache_engine.keys()) {
|
|
436
|
+
text_bitmap_cache_engine.delete(key);
|
|
437
|
+
removed = removed + 1;
|
|
438
|
+
if (removed >= remove_count)
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// engine/render.ts
|
|
444
|
+
function render_engine(state) {
|
|
445
|
+
render_engine_with_overlay(state, null);
|
|
446
|
+
}
|
|
447
|
+
function render_engine_with_overlay(state, overlay) {
|
|
448
|
+
const view_bounds = visible_bounds_world_engine(state);
|
|
449
|
+
const visible_elements = elements_in_bounds_document(state.document, view_bounds);
|
|
450
|
+
const layer_info = build_layer_render_info_map_engine(state.document);
|
|
451
|
+
const renderable_elements = [];
|
|
452
|
+
for (let i = 0;i < visible_elements.length; i = i + 1) {
|
|
453
|
+
const el = visible_elements[i];
|
|
454
|
+
if (el === undefined) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const info = layer_info.get(el.layer_id);
|
|
458
|
+
if (info === undefined || info.visible) {
|
|
459
|
+
renderable_elements.push(el);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
renderable_elements.sort((a, b) => {
|
|
463
|
+
const a_order = layer_info.get(a.layer_id)?.order ?? Number.MAX_SAFE_INTEGER;
|
|
464
|
+
const b_order = layer_info.get(b.layer_id)?.order ?? Number.MAX_SAFE_INTEGER;
|
|
465
|
+
if (a_order !== b_order) {
|
|
466
|
+
return a_order - b_order;
|
|
467
|
+
}
|
|
468
|
+
return a.z_index - b.z_index;
|
|
469
|
+
});
|
|
470
|
+
state.renderer.begin_frame();
|
|
471
|
+
state.renderer.clear(state.background);
|
|
472
|
+
camera_to_screen_transform_engine(state.camera, state.viewport, scratch_transform);
|
|
473
|
+
state.renderer.set_transform(scratch_transform);
|
|
474
|
+
if (state.background_image !== null) {
|
|
475
|
+
state.renderer.draw_image(state.background_image, [0, 0, state.background_image.width, state.background_image.height], 1);
|
|
476
|
+
}
|
|
477
|
+
for (let i = 0;i < renderable_elements.length; i = i + 1) {
|
|
478
|
+
const el = renderable_elements[i];
|
|
479
|
+
if (el !== undefined) {
|
|
480
|
+
const asset_src = el.type === element_type_image && el.asset_id !== null ? state.document.assets.get(el.asset_id)?.src ?? null : null;
|
|
481
|
+
render_element_engine(state.renderer, el, asset_src);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (overlay !== null) {
|
|
485
|
+
overlay(state.renderer);
|
|
486
|
+
}
|
|
487
|
+
state.renderer.end_frame();
|
|
488
|
+
}
|
|
489
|
+
function build_layer_render_info_map_engine(doc) {
|
|
490
|
+
const map = new Map;
|
|
491
|
+
for (let i = 0;i < doc.layers.length; i = i + 1) {
|
|
492
|
+
const layer = doc.layers[i];
|
|
493
|
+
if (layer !== undefined) {
|
|
494
|
+
map.set(layer.id, { order: i, visible: layer.visible });
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return map;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export { default_background, set_camera_engine, pan_engine, zoom_engine, zoom_at_engine, resize_engine, world_to_screen_engine, screen_to_world_engine, visible_bounds_world_engine, sanitize_number_engine, sanitize_zoom_engine, elements_in_bounds_document, render_engine, render_engine_with_overlay };
|