@neta-art/cohub 9.0.0 → 10.0.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/README.md +100 -103
- package/dist/board/editor/align.d.ts +11 -0
- package/dist/board/editor/align.js +72 -0
- package/dist/board/editor/animation.d.ts +14 -0
- package/dist/board/editor/animation.js +172 -0
- package/dist/board/editor/camera.d.ts +32 -0
- package/dist/board/editor/camera.js +137 -0
- package/dist/board/editor/clipboard.d.ts +41 -0
- package/dist/board/editor/clipboard.js +122 -0
- package/dist/board/editor/connection-ports.d.ts +19 -0
- package/dist/board/editor/connection-ports.js +85 -0
- package/dist/board/editor/context.d.ts +111 -0
- package/dist/board/editor/context.js +30 -0
- package/dist/board/editor/copy.d.ts +17 -0
- package/dist/board/editor/copy.js +116 -0
- package/dist/board/editor/creation.d.ts +47 -0
- package/dist/board/editor/creation.js +224 -0
- package/dist/board/editor/deletion.d.ts +9 -0
- package/dist/board/editor/deletion.js +90 -0
- package/dist/board/editor/document-edits.d.ts +22 -0
- package/dist/board/editor/document-edits.js +193 -0
- package/dist/board/editor/document.d.ts +35 -0
- package/dist/board/editor/document.js +255 -0
- package/dist/board/editor/editor.d.ts +210 -0
- package/dist/board/editor/editor.js +429 -0
- package/dist/board/editor/index.d.ts +18 -0
- package/dist/board/editor/index.js +12 -0
- package/dist/board/editor/interaction.d.ts +115 -0
- package/dist/board/editor/interaction.js +584 -0
- package/dist/board/editor/query.d.ts +27 -0
- package/dist/board/editor/query.js +201 -0
- package/dist/board/editor/remote.d.ts +11 -0
- package/dist/board/editor/remote.js +55 -0
- package/dist/board/editor/selection-transform.d.ts +24 -0
- package/dist/board/editor/selection-transform.js +81 -0
- package/dist/board/editor/selection.d.ts +33 -0
- package/dist/board/editor/selection.js +196 -0
- package/dist/board/editor/snapping.d.ts +33 -0
- package/dist/board/editor/snapping.js +75 -0
- package/dist/board/editor/snapshots.d.ts +27 -0
- package/dist/board/editor/snapshots.js +132 -0
- package/dist/board/editor/spatial.d.ts +41 -0
- package/dist/board/editor/spatial.js +191 -0
- package/dist/board/editor/state.d.ts +12 -0
- package/dist/board/editor/state.js +49 -0
- package/dist/board/editor/tool.d.ts +10 -0
- package/dist/board/editor/tool.js +19 -0
- package/dist/board/editor/wheel.d.ts +5 -0
- package/dist/board/editor/wheel.js +17 -0
- package/dist/board/export/index.d.ts +5 -4
- package/dist/board/export/index.js +4 -3
- package/dist/board/export/node/index.d.ts +55 -0
- package/dist/board/{headless → export/node}/index.js +12 -12
- package/dist/board/export/node/sketch.d.ts +19 -0
- package/dist/board/{headless → export/node}/sketch.js +6 -6
- package/dist/board/export/scene.d.ts +6 -4
- package/dist/board/export/scene.js +4 -3
- package/dist/board/{animation.d.ts → model/animation.d.ts} +4 -4
- package/dist/board/{animation.js → model/animation.js} +3 -3
- package/dist/board/{core → model}/arrow-geometry.d.ts +2 -2
- package/dist/board/{core → model}/arrow-geometry.js +2 -2
- package/dist/board/{core → model}/draw-geometry.d.ts +2 -2
- package/dist/board/{core → model}/draw-geometry.js +1 -1
- package/dist/board/model/draw-input.d.ts +14 -0
- package/dist/board/model/draw-input.js +28 -0
- package/dist/board/{core → model}/export-assets.d.ts +1 -1
- package/dist/board/{core → model}/export-assets.js +1 -1
- package/dist/board/{core → model}/export-plan.d.ts +2 -2
- package/dist/board/{core → model}/export-plan.js +2 -2
- package/dist/board/{core → model}/file-preview.d.ts +1 -1
- package/dist/board/{core → model}/file-preview.js +1 -1
- package/dist/board/{core → model}/file-snapshot.d.ts +1 -1
- package/dist/board/{core → model}/file-snapshot.js +1 -1
- package/dist/board/{geometry.d.ts → model/geometry.d.ts} +3 -3
- package/dist/board/{geometry.js → model/geometry.js} +1 -1
- package/dist/board/{image-key.d.ts → model/image-key.d.ts} +2 -2
- package/dist/board/{image-key.js → model/image-key.js} +1 -1
- package/dist/board/model/index.d.ts +35 -0
- package/dist/board/{index.js → model/index.js} +26 -22
- package/dist/board/model/items/builtin.d.ts +5 -0
- package/dist/board/model/items/builtin.js +119 -0
- package/dist/board/model/items/create.d.ts +59 -0
- package/dist/board/model/items/create.js +271 -0
- package/dist/board/model/items/definition.d.ts +35 -0
- package/dist/board/model/items/definition.js +18 -0
- package/dist/board/model/items/id.d.ts +5 -0
- package/dist/board/model/items/id.js +11 -0
- package/dist/board/model/items/index.d.ts +6 -0
- package/dist/board/model/items/index.js +6 -0
- package/dist/board/model/items/registry.d.ts +35 -0
- package/dist/board/model/items/registry.js +84 -0
- package/dist/board/{media-playback.d.ts → model/media-playback.d.ts} +2 -2
- package/dist/board/{media-playback.js → model/media-playback.js} +1 -1
- package/dist/board/{media.d.ts → model/media.d.ts} +1 -1
- package/dist/board/{media.js → model/media.js} +1 -1
- package/dist/board/{core → model}/palette.d.ts +1 -1
- package/dist/board/{core → model}/palette.js +1 -1
- package/dist/board/{presets.d.ts → model/presets.d.ts} +3 -3
- package/dist/board/{presets.js → model/presets.js} +1 -1
- package/dist/board/{replay.d.ts → model/replay.d.ts} +5 -5
- package/dist/board/{replay.js → model/replay.js} +2 -2
- package/dist/board/{core → model}/scene.d.ts +1 -1
- package/dist/board/{core → model}/scene.js +1 -1
- package/dist/board/model/shape-types.d.ts +8 -0
- package/dist/board/model/shape-types.js +8 -0
- package/dist/board/{task.d.ts → model/task.d.ts} +4 -4
- package/dist/board/{task.js → model/task.js} +3 -3
- package/dist/board/{core → model}/text-metrics.d.ts +1 -1
- package/dist/board/{core → model}/text-metrics.js +1 -1
- package/dist/board/{core → model}/tool-styles.d.ts +1 -1
- package/dist/board/{core → model}/tool-styles.js +1 -1
- package/dist/board/{runtime/board-player.d.ts → player/index.d.ts} +2 -2
- package/dist/board/{runtime/board-player.js → player/index.js} +5 -4
- package/dist/board/render/board-background.d.ts +1 -1
- package/dist/board/render/clip.d.ts +1 -1
- package/dist/board/render/index.d.ts +2 -2
- package/dist/board/render/index.js +2 -2
- package/dist/board/render/media-interaction.d.ts +2 -2
- package/dist/board/render/media-interaction.js +1 -1
- package/dist/board/render/palette.d.ts +1 -1
- package/dist/board/render/palette.js +1 -1
- package/dist/board/render/renderers/arrow-card-renderer.js +1 -1
- package/dist/board/render/renderers/board-renderer-registry.d.ts +11 -6
- package/dist/board/render/renderers/board-renderer-registry.js +15 -15
- package/dist/board/render/renderers/draw-card-renderer.js +1 -1
- package/dist/board/render/renderers/far-plate.js +1 -1
- package/dist/board/render/renderers/file-card-renderer.d.ts +1 -1
- package/dist/board/render/renderers/file-card-renderer.js +2 -2
- package/dist/board/render/renderers/image-card-renderer.d.ts +1 -1
- package/dist/board/render/renderers/shape-card-renderer.js +1 -1
- package/dist/board/render/renderers/task-card-renderer.js +1 -1
- package/dist/board/render/renderers/text-card-renderer.js +1 -1
- package/dist/board/render/renderers/video-card-renderer.d.ts +1 -1
- package/dist/board/render/stroke.d.ts +1 -1
- package/dist/board/render/stroke.js +1 -1
- package/dist/board/render/text-measurement.js +1 -1
- package/dist/board/replica/index.d.ts +70 -0
- package/dist/board/replica/index.js +276 -0
- package/dist/board/stage/assets.d.ts +41 -0
- package/dist/board/stage/assets.js +350 -0
- package/dist/board/stage/index.d.ts +8 -0
- package/dist/board/stage/index.js +8 -0
- package/dist/board/stage/lru.d.ts +32 -0
- package/dist/board/stage/lru.js +29 -0
- package/dist/board/stage/pointer.d.ts +8 -0
- package/dist/board/stage/pointer.js +33 -0
- package/dist/board/stage/scene.d.ts +85 -0
- package/dist/board/stage/scene.js +512 -0
- package/dist/board/stage/stage.d.ts +66 -0
- package/dist/board/stage/stage.js +568 -0
- package/dist/board/stage/texture-pool.d.ts +24 -0
- package/dist/board/stage/texture-pool.js +154 -0
- package/dist/board/stage/views.d.ts +38 -0
- package/dist/board/stage/views.js +93 -0
- package/dist/chunks/environment.d.ts +25 -1
- package/dist/chunks/http.d.ts +99 -66
- package/dist/chunks/http.js +214 -207
- package/dist/chunks/websocket.d.ts +1 -1
- package/dist/http.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -4
- package/dist/media.d.ts +1 -10
- package/dist/media.js +16 -27
- package/dist/protocol/dist/board-patch.js +1 -1
- package/dist/protocol/dist/board.d.ts +28 -2
- package/dist/protocol/dist/board.js +3 -1
- package/dist/protocol/dist/core/media.d.ts +5 -0
- package/dist/protocol/dist/core/media.js +39 -0
- package/dist/protocol/dist/index.d.ts +5 -5
- package/dist/types.d.ts +1 -1
- package/package.json +26 -14
- package/dist/board/core/shape-definition.d.ts +0 -23
- package/dist/board/core/shape-definition.js +0 -45
- package/dist/board/core/shape-types.d.ts +0 -38
- package/dist/board/core/shape-types.js +0 -22
- package/dist/board/headless/index.d.ts +0 -55
- package/dist/board/headless/sketch.d.ts +0 -19
- package/dist/board/index.d.ts +0 -30
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { clampBoardStrokeSize } from "../../protocol/dist/board-constants.js";
|
|
2
|
+
import { normalizeViewport } from "../model/geometry.js";
|
|
3
|
+
import { isBoardColorId } from "../model/palette.js";
|
|
4
|
+
import { buildBoardScene } from "../model/scene.js";
|
|
5
|
+
import { isShapeKind } from "../model/shape-types.js";
|
|
6
|
+
import { createBoardToolStyles } from "../model/tool-styles.js";
|
|
7
|
+
import { titleForBoardItem } from "../model/items/create.js";
|
|
8
|
+
import { defaultBoardRegistry } from "../model/items/registry.js";
|
|
9
|
+
import { createAnimationModule } from "./animation.js";
|
|
10
|
+
import { createCameraModule } from "./camera.js";
|
|
11
|
+
import { STATE_CHANNELS } from "./context.js";
|
|
12
|
+
import { createCopyModule } from "./copy.js";
|
|
13
|
+
import { isCreationBoardTool } from "./tool.js";
|
|
14
|
+
import { createCreationModule } from "./creation.js";
|
|
15
|
+
import { createDeletionModule } from "./deletion.js";
|
|
16
|
+
import { createDocumentModule } from "./document.js";
|
|
17
|
+
import { createChannels, observable } from "./state.js";
|
|
18
|
+
import { createInteractionModule } from "./interaction.js";
|
|
19
|
+
import { createQueryModule } from "./query.js";
|
|
20
|
+
import { createRemoteModule } from "./remote.js";
|
|
21
|
+
import { createSelectionModule } from "./selection.js";
|
|
22
|
+
import { createSnapshotsModule } from "./snapshots.js";
|
|
23
|
+
//#region src/board/editor/editor.ts
|
|
24
|
+
function styledToolId(tool) {
|
|
25
|
+
switch (tool) {
|
|
26
|
+
case "text":
|
|
27
|
+
case "shape":
|
|
28
|
+
case "draw":
|
|
29
|
+
case "arrow":
|
|
30
|
+
case "frame": return tool;
|
|
31
|
+
default: return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function createBoardEditor(options) {
|
|
35
|
+
const registry = options.registry ?? defaultBoardRegistry;
|
|
36
|
+
const channels = createChannels();
|
|
37
|
+
const track = options.track ?? (() => {});
|
|
38
|
+
const preferences = options.preferences;
|
|
39
|
+
const state = observable({
|
|
40
|
+
base: options.document,
|
|
41
|
+
settingsPreview: null,
|
|
42
|
+
scene: buildBoardScene(options.document),
|
|
43
|
+
structureVersion: 0,
|
|
44
|
+
geometryVersion: 0,
|
|
45
|
+
selection: [],
|
|
46
|
+
camera: normalizeViewport(options.viewport ?? {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
zoom: 1
|
|
50
|
+
}),
|
|
51
|
+
surfaceSize: {
|
|
52
|
+
width: 0,
|
|
53
|
+
height: 0
|
|
54
|
+
},
|
|
55
|
+
cameraPolicy: preferences?.cameraPolicy ?? "follow",
|
|
56
|
+
tool: options.initialTool ?? "select",
|
|
57
|
+
toolStyles: preferences?.toolStyles ?? createBoardToolStyles(),
|
|
58
|
+
interaction: { type: "idle" },
|
|
59
|
+
snapGuides: [],
|
|
60
|
+
spaceHeld: false,
|
|
61
|
+
hoverId: null,
|
|
62
|
+
hoverPoint: null,
|
|
63
|
+
hoverPointerType: "mouse",
|
|
64
|
+
editingId: null,
|
|
65
|
+
draftTextId: null,
|
|
66
|
+
playhead: null,
|
|
67
|
+
recording: false,
|
|
68
|
+
undoStack: [],
|
|
69
|
+
redoStack: [],
|
|
70
|
+
saveError: null,
|
|
71
|
+
pendingCommits: 0
|
|
72
|
+
}, STATE_CHANNELS, channels);
|
|
73
|
+
const ctx = {
|
|
74
|
+
options,
|
|
75
|
+
registry,
|
|
76
|
+
state,
|
|
77
|
+
channels,
|
|
78
|
+
preferencesChanged() {
|
|
79
|
+
options.onPreferencesChange?.({
|
|
80
|
+
toolStyles: state.toolStyles,
|
|
81
|
+
cameraPolicy: state.cameraPolicy
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
ctx.document = createDocumentModule(ctx);
|
|
86
|
+
ctx.query = createQueryModule(ctx);
|
|
87
|
+
ctx.camera = createCameraModule(ctx);
|
|
88
|
+
ctx.selection = createSelectionModule(ctx);
|
|
89
|
+
ctx.creation = createCreationModule(ctx);
|
|
90
|
+
ctx.deletion = createDeletionModule(ctx);
|
|
91
|
+
ctx.copy = createCopyModule(ctx);
|
|
92
|
+
ctx.interaction = createInteractionModule(ctx);
|
|
93
|
+
ctx.animation = createAnimationModule(ctx);
|
|
94
|
+
ctx.snapshots = createSnapshotsModule(ctx);
|
|
95
|
+
ctx.remote = createRemoteModule(ctx);
|
|
96
|
+
const { document, query, camera, selection, creation, deletion, copy, interaction, animation, snapshots, remote } = ctx;
|
|
97
|
+
let viewStateQueued = false;
|
|
98
|
+
function emitViewState() {
|
|
99
|
+
viewStateQueued = false;
|
|
100
|
+
const onViewStateChange = options.onViewStateChange;
|
|
101
|
+
if (!onViewStateChange) return;
|
|
102
|
+
const selectedNodes = selection.items().map((item) => {
|
|
103
|
+
const title = titleForBoardItem(item).trim();
|
|
104
|
+
return {
|
|
105
|
+
id: item.id,
|
|
106
|
+
type: item.type,
|
|
107
|
+
...title ? { title } : {}
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
onViewStateChange({
|
|
111
|
+
visibleRect: camera.visibleRect(),
|
|
112
|
+
selectedNodes
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function queueViewState() {
|
|
116
|
+
if (viewStateQueued || !options.onViewStateChange) return;
|
|
117
|
+
viewStateQueued = true;
|
|
118
|
+
queueMicrotask(emitViewState);
|
|
119
|
+
}
|
|
120
|
+
const stopViewState = channels.subscribe([
|
|
121
|
+
"camera",
|
|
122
|
+
"selection",
|
|
123
|
+
"scene"
|
|
124
|
+
], queueViewState);
|
|
125
|
+
queueViewState();
|
|
126
|
+
function setToolStyle(tool, patch) {
|
|
127
|
+
state.toolStyles = {
|
|
128
|
+
...state.toolStyles,
|
|
129
|
+
[tool]: {
|
|
130
|
+
...state.toolStyles[tool],
|
|
131
|
+
...patch
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
ctx.preferencesChanged();
|
|
135
|
+
}
|
|
136
|
+
function read(channel, value) {
|
|
137
|
+
if (typeof channel === "string") track(channel);
|
|
138
|
+
else for (const each of channel) track(each);
|
|
139
|
+
return value();
|
|
140
|
+
}
|
|
141
|
+
function tracked(channels, query) {
|
|
142
|
+
return (...args) => read(channels, () => query(...args));
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
registry,
|
|
146
|
+
readonly: options.readonly === true,
|
|
147
|
+
subscribe: channels.subscribe,
|
|
148
|
+
get document() {
|
|
149
|
+
return read("document", () => state.base);
|
|
150
|
+
},
|
|
151
|
+
get settings() {
|
|
152
|
+
return read("document", () => state.settingsPreview ?? state.base.board);
|
|
153
|
+
},
|
|
154
|
+
get animations() {
|
|
155
|
+
return read("document", () => state.base.animations);
|
|
156
|
+
},
|
|
157
|
+
get scene() {
|
|
158
|
+
return read("scene", () => state.scene);
|
|
159
|
+
},
|
|
160
|
+
get items() {
|
|
161
|
+
return read("scene", () => state.scene.items);
|
|
162
|
+
},
|
|
163
|
+
get hasContent() {
|
|
164
|
+
return read("scene", () => state.scene.items.length > 0);
|
|
165
|
+
},
|
|
166
|
+
get structureVersion() {
|
|
167
|
+
return read("scene", () => state.structureVersion);
|
|
168
|
+
},
|
|
169
|
+
get geometryVersion() {
|
|
170
|
+
return read("scene", () => state.geometryVersion);
|
|
171
|
+
},
|
|
172
|
+
get selection() {
|
|
173
|
+
return read("selection", () => state.selection);
|
|
174
|
+
},
|
|
175
|
+
get selectedItems() {
|
|
176
|
+
return read(["scene", "selection"], selection.items);
|
|
177
|
+
},
|
|
178
|
+
get hasFocusableSelection() {
|
|
179
|
+
return read(["scene", "selection"], () => selection.items().length > 0);
|
|
180
|
+
},
|
|
181
|
+
get selectionLocked() {
|
|
182
|
+
return read(["scene", "selection"], () => {
|
|
183
|
+
const items = selection.items();
|
|
184
|
+
return items.length > 0 && items.every((item) => item.locked);
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
get bounds() {
|
|
188
|
+
return read(["scene", "selection"], selection.bounds);
|
|
189
|
+
},
|
|
190
|
+
get selectionTransform() {
|
|
191
|
+
return read(["scene", "selection"], selection.transform);
|
|
192
|
+
},
|
|
193
|
+
get camera() {
|
|
194
|
+
return read("camera", () => state.camera);
|
|
195
|
+
},
|
|
196
|
+
get cameraPolicy() {
|
|
197
|
+
return read("camera", () => state.cameraPolicy);
|
|
198
|
+
},
|
|
199
|
+
get playhead() {
|
|
200
|
+
return read("playback", () => state.playhead);
|
|
201
|
+
},
|
|
202
|
+
get recording() {
|
|
203
|
+
return read("playback", () => state.recording);
|
|
204
|
+
},
|
|
205
|
+
get tool() {
|
|
206
|
+
return read("tool", () => state.tool);
|
|
207
|
+
},
|
|
208
|
+
set tool(value) {
|
|
209
|
+
if (options.readonly && value !== "hand" && value !== "select") {
|
|
210
|
+
state.tool = "hand";
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
state.tool = value;
|
|
214
|
+
if (isCreationBoardTool(value)) state.hoverId = null;
|
|
215
|
+
if (value === "draw" || value === "arrow") {
|
|
216
|
+
state.selection = [];
|
|
217
|
+
state.editingId = null;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
get activeColor() {
|
|
221
|
+
return read("tool", () => state.toolStyles[styledToolId(state.tool) ?? "text"].color);
|
|
222
|
+
},
|
|
223
|
+
set activeColor(value) {
|
|
224
|
+
const tool = styledToolId(state.tool);
|
|
225
|
+
if (tool && isBoardColorId(value)) setToolStyle(tool, { color: value });
|
|
226
|
+
},
|
|
227
|
+
get activeShape() {
|
|
228
|
+
return read("tool", () => state.toolStyles.shape.geometry);
|
|
229
|
+
},
|
|
230
|
+
set activeShape(value) {
|
|
231
|
+
if (isShapeKind(value)) setToolStyle("shape", { geometry: value });
|
|
232
|
+
},
|
|
233
|
+
get activeStrokeSize() {
|
|
234
|
+
return read("tool", () => (state.tool === "arrow" ? state.toolStyles.arrow : state.toolStyles.draw).size);
|
|
235
|
+
},
|
|
236
|
+
set activeStrokeSize(value) {
|
|
237
|
+
if (!Number.isFinite(value) || state.tool !== "arrow" && state.tool !== "draw") return;
|
|
238
|
+
setToolStyle(state.tool, { size: clampBoardStrokeSize(value) });
|
|
239
|
+
},
|
|
240
|
+
get interaction() {
|
|
241
|
+
return read("interaction", () => state.interaction);
|
|
242
|
+
},
|
|
243
|
+
get gestureActive() {
|
|
244
|
+
return read("interaction", () => state.interaction.type !== "idle");
|
|
245
|
+
},
|
|
246
|
+
get marquee() {
|
|
247
|
+
return read("interaction", interaction.marquee);
|
|
248
|
+
},
|
|
249
|
+
get snapGuides() {
|
|
250
|
+
return read("interaction", () => state.snapGuides);
|
|
251
|
+
},
|
|
252
|
+
get spaceHeld() {
|
|
253
|
+
return read("interaction", () => state.spaceHeld);
|
|
254
|
+
},
|
|
255
|
+
set spaceHeld(value) {
|
|
256
|
+
state.spaceHeld = value;
|
|
257
|
+
},
|
|
258
|
+
get arrowDraft() {
|
|
259
|
+
return read(["interaction", "scene"], () => {
|
|
260
|
+
const gesture = state.interaction;
|
|
261
|
+
if (gesture.type !== "creatingArrow") return null;
|
|
262
|
+
const target = gesture.targetItemId ? state.scene.get(gesture.targetItemId) : null;
|
|
263
|
+
return {
|
|
264
|
+
from: gesture.start,
|
|
265
|
+
to: gesture.current,
|
|
266
|
+
size: gesture.size,
|
|
267
|
+
color: gesture.color,
|
|
268
|
+
targetFrame: target?.frame ?? null
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
get bindTargetFrame() {
|
|
273
|
+
return read(["interaction", "scene"], () => {
|
|
274
|
+
const gesture = state.interaction;
|
|
275
|
+
const id = gesture.type === "draggingArrowHandle" ? gesture.targetItemId : null;
|
|
276
|
+
return id ? state.scene.get(id)?.frame ?? null : null;
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
get hoverId() {
|
|
280
|
+
return read("hover", () => state.hoverId);
|
|
281
|
+
},
|
|
282
|
+
get pointerType() {
|
|
283
|
+
return read("hover", () => state.hoverPointerType);
|
|
284
|
+
},
|
|
285
|
+
get hoveredTransformControl() {
|
|
286
|
+
return read([
|
|
287
|
+
"interaction",
|
|
288
|
+
"hover",
|
|
289
|
+
"tool",
|
|
290
|
+
"camera",
|
|
291
|
+
"scene",
|
|
292
|
+
"selection"
|
|
293
|
+
], interaction.hoveredControl);
|
|
294
|
+
},
|
|
295
|
+
get connectionPorts() {
|
|
296
|
+
return read([
|
|
297
|
+
"interaction",
|
|
298
|
+
"hover",
|
|
299
|
+
"tool",
|
|
300
|
+
"camera",
|
|
301
|
+
"scene",
|
|
302
|
+
"selection",
|
|
303
|
+
"editing"
|
|
304
|
+
], interaction.ports);
|
|
305
|
+
},
|
|
306
|
+
get hoveredConnectionPort() {
|
|
307
|
+
return read([
|
|
308
|
+
"interaction",
|
|
309
|
+
"hover",
|
|
310
|
+
"tool",
|
|
311
|
+
"camera",
|
|
312
|
+
"scene",
|
|
313
|
+
"selection",
|
|
314
|
+
"editing"
|
|
315
|
+
], interaction.hoveredPort);
|
|
316
|
+
},
|
|
317
|
+
get editingId() {
|
|
318
|
+
return read("editing", () => state.editingId);
|
|
319
|
+
},
|
|
320
|
+
set editingId(value) {
|
|
321
|
+
state.editingId = value;
|
|
322
|
+
},
|
|
323
|
+
get canUndo() {
|
|
324
|
+
return read("history", () => state.undoStack.length > 0);
|
|
325
|
+
},
|
|
326
|
+
get canRedo() {
|
|
327
|
+
return read("history", () => state.redoStack.length > 0);
|
|
328
|
+
},
|
|
329
|
+
get saveError() {
|
|
330
|
+
return read("status", () => state.saveError);
|
|
331
|
+
},
|
|
332
|
+
get saving() {
|
|
333
|
+
return read("status", () => state.pendingCommits > 0);
|
|
334
|
+
},
|
|
335
|
+
set surfaceSize(value) {
|
|
336
|
+
state.surfaceSize = value;
|
|
337
|
+
},
|
|
338
|
+
loadDocument: remote.loadDocument,
|
|
339
|
+
undo: document.undo,
|
|
340
|
+
redo: document.redo,
|
|
341
|
+
retrySave: () => {
|
|
342
|
+
state.saveError = null;
|
|
343
|
+
},
|
|
344
|
+
setSettings: document.setSettings,
|
|
345
|
+
previewSettings: document.previewSettings,
|
|
346
|
+
setPlayedItems: document.setPlayedItems,
|
|
347
|
+
consumeRecentlyAdded: document.consumeRecentlyAdded,
|
|
348
|
+
itemAt: tracked(["scene", "camera"], query.itemAt),
|
|
349
|
+
itemById: tracked(["scene"], query.itemById),
|
|
350
|
+
labelItemAt: tracked([
|
|
351
|
+
"scene",
|
|
352
|
+
"camera",
|
|
353
|
+
"selection"
|
|
354
|
+
], query.labelItemAt),
|
|
355
|
+
idsInRect: tracked(["scene"], query.idsInRect),
|
|
356
|
+
setCamera: camera.setCamera,
|
|
357
|
+
setCameraPolicy: camera.setCameraPolicy,
|
|
358
|
+
takeCameraControl: camera.takeCameraControl,
|
|
359
|
+
viewCenter: tracked(["camera"], camera.viewCenter),
|
|
360
|
+
zoomAt: camera.zoomAt,
|
|
361
|
+
zoomIn: camera.zoomIn,
|
|
362
|
+
zoomOut: camera.zoomOut,
|
|
363
|
+
resetZoom: camera.resetZoom,
|
|
364
|
+
fitView: camera.fitView,
|
|
365
|
+
focusRect: camera.focusRect,
|
|
366
|
+
focusItems: camera.focusItems,
|
|
367
|
+
focusNode: camera.focusNode,
|
|
368
|
+
focusSelection: camera.focusSelection,
|
|
369
|
+
wheel: camera.wheel,
|
|
370
|
+
setSelection: selection.set,
|
|
371
|
+
clearSelection: selection.clear,
|
|
372
|
+
selectAll: selection.selectAll,
|
|
373
|
+
nudgeSelection: selection.nudge,
|
|
374
|
+
alignSelection: selection.align,
|
|
375
|
+
distributeSelection: selection.distribute,
|
|
376
|
+
toggleSelectionLock: selection.toggleLock,
|
|
377
|
+
setSelectionColor: selection.setColor,
|
|
378
|
+
setSelectionStyle: selection.setStyle,
|
|
379
|
+
setSelectionProps: selection.setProps,
|
|
380
|
+
bringToFront: selection.bringToFront,
|
|
381
|
+
sendToBack: selection.sendToBack,
|
|
382
|
+
addItem: creation.addItem,
|
|
383
|
+
addApp: creation.addApp,
|
|
384
|
+
addFile: creation.addFile,
|
|
385
|
+
addTask: creation.addTask,
|
|
386
|
+
addTaskWithSources: creation.addTaskWithSources,
|
|
387
|
+
addText: creation.addText,
|
|
388
|
+
addShape: creation.addShape,
|
|
389
|
+
addFrame: creation.addFrame,
|
|
390
|
+
beginTextDraft: creation.beginTextDraft,
|
|
391
|
+
commitTextEdit: creation.commitTextEdit,
|
|
392
|
+
updateText: creation.updateText,
|
|
393
|
+
previewTextLayout: creation.previewTextLayout,
|
|
394
|
+
deleteSelection: deletion.deleteSelection,
|
|
395
|
+
deleteItem: deletion.deleteItem,
|
|
396
|
+
duplicateSelection: copy.duplicateSelection,
|
|
397
|
+
copySelection: copy.copySelection,
|
|
398
|
+
cutSelection: copy.cutSelection,
|
|
399
|
+
pasteClipboard: copy.pasteClipboard,
|
|
400
|
+
applyMediaFileChange: snapshots.applyMediaFileChange,
|
|
401
|
+
adoptMediaNaturalSizes: snapshots.adoptMediaNaturalSizes,
|
|
402
|
+
applyFileSnapshots: snapshots.applyFileSnapshots,
|
|
403
|
+
applyTaskSnapshots: snapshots.applyTaskSnapshots,
|
|
404
|
+
setPlayhead: animation.setPlayhead,
|
|
405
|
+
setRecording: animation.setRecording,
|
|
406
|
+
keyframeState: tracked([
|
|
407
|
+
"document",
|
|
408
|
+
"scene",
|
|
409
|
+
"selection",
|
|
410
|
+
"playback"
|
|
411
|
+
], animation.keyframeState),
|
|
412
|
+
toggleKeyframe: animation.toggleKeyframe,
|
|
413
|
+
removeKeyframe: animation.removeKeyframe,
|
|
414
|
+
setKeyframeEase: animation.setKeyframeEase,
|
|
415
|
+
createAnimation: animation.createAnimation,
|
|
416
|
+
pointerDown: interaction.pointerDown,
|
|
417
|
+
pointerMove: interaction.pointerMove,
|
|
418
|
+
pointerUp: interaction.pointerUp,
|
|
419
|
+
pointerLeave: interaction.pointerLeave,
|
|
420
|
+
cancelPointerInteraction: interaction.cancel,
|
|
421
|
+
destroy() {
|
|
422
|
+
stopViewState();
|
|
423
|
+
camera.cancelAnimation();
|
|
424
|
+
interaction.destroy();
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
//#endregion
|
|
429
|
+
export { createBoardEditor };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BOARD_CLIPBOARD_MIME } from "../../protocol/dist/board.js";
|
|
2
|
+
import { AlignMode, DistributeAxis, alignFrames, distributeFrames, framesBounds } from "./align.js";
|
|
3
|
+
import { BoardFocusOptions } from "./camera.js";
|
|
4
|
+
import { BoardSelectionTransform, BoardTransformControl, resizeCursorForHandle, resolveSelectionTransform, selectionTransformControlAt } from "./selection-transform.js";
|
|
5
|
+
import { BoardInteraction, BoardPointerEvent } from "./interaction.js";
|
|
6
|
+
import { BoardAppMetadata, BoardTaskSource } from "./creation.js";
|
|
7
|
+
import { BOARD_CLIPBOARD_VERSION, BoardClipboardPayload, DUPLICATE_OFFSET, MAX_CLIPBOARD_CHARS, MAX_CLIPBOARD_ITEMS, defaultPasteOffset, encodeClipboard, materializeClipboard, parseClipboard, remapItems } from "./clipboard.js";
|
|
8
|
+
import { BoardNaturalSize } from "./snapshots.js";
|
|
9
|
+
import { SnapAxis, SnapGuide, SnapOptions, SnapResult, computeSnap } from "./snapping.js";
|
|
10
|
+
import { BoardEditorChannel, BoardEditorListener } from "./state.js";
|
|
11
|
+
import { BOARD_HAND_TAP_SLOP, BoardToolId, canTapSelectWithHand, defaultBoardTool, isContinuousBoardTool, isCreationBoardTool, isWithinHandTapSlop } from "./tool.js";
|
|
12
|
+
import { BoardCameraPolicy, BoardEditorOptions, BoardEditorPreferences, BoardPlayhead, BoardViewState } from "./context.js";
|
|
13
|
+
import { CONNECTION_PORT_HIT_RADIUS, CONNECTION_PORT_OFFSET, CONNECTION_PORT_RADIUS, CONNECTION_PORT_TOUCH_HIT_RADIUS, CONNECTION_SIDES, ConnectionPort, connectionPortAt, connectionPorts, portHitRadius } from "./connection-ports.js";
|
|
14
|
+
import { BoardEditPlayhead, diffBoardEdits, isEmptyBoardPatch, readPath, routeBoardEdits, sameJson, writePath } from "./document-edits.js";
|
|
15
|
+
import { BoardEditor, createBoardEditor } from "./editor.js";
|
|
16
|
+
import { SpatialEntry, SpatialIndex, createSpatialIndex } from "./spatial.js";
|
|
17
|
+
import { normalizeWheelDelta, wheelZoomFactor } from "./wheel.js";
|
|
18
|
+
export { AlignMode, BOARD_CLIPBOARD_MIME, BOARD_CLIPBOARD_VERSION, BOARD_HAND_TAP_SLOP, type BoardAppMetadata, type BoardCameraPolicy, BoardClipboardPayload, BoardEditPlayhead, type BoardEditor, type BoardEditorChannel, type BoardEditorListener, type BoardEditorOptions, type BoardEditorPreferences, type BoardFocusOptions, type BoardInteraction, type BoardNaturalSize, type BoardPlayhead, type BoardPointerEvent, BoardSelectionTransform, type BoardTaskSource, BoardToolId, BoardTransformControl, type BoardViewState, CONNECTION_PORT_HIT_RADIUS, CONNECTION_PORT_OFFSET, CONNECTION_PORT_RADIUS, CONNECTION_PORT_TOUCH_HIT_RADIUS, CONNECTION_SIDES, ConnectionPort, DUPLICATE_OFFSET, DistributeAxis, MAX_CLIPBOARD_CHARS, MAX_CLIPBOARD_ITEMS, SnapAxis, SnapGuide, SnapOptions, SnapResult, SpatialEntry, SpatialIndex, alignFrames, canTapSelectWithHand, computeSnap, connectionPortAt, connectionPorts, createBoardEditor, createSpatialIndex, defaultBoardTool, defaultPasteOffset, diffBoardEdits, distributeFrames, encodeClipboard, framesBounds, isContinuousBoardTool, isCreationBoardTool, isEmptyBoardPatch, isWithinHandTapSlop, materializeClipboard, normalizeWheelDelta, parseClipboard, portHitRadius, readPath, remapItems, resizeCursorForHandle, resolveSelectionTransform, routeBoardEdits, sameJson, selectionTransformControlAt, wheelZoomFactor, writePath };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BOARD_CLIPBOARD_MIME } from "../../protocol/dist/board.js";
|
|
2
|
+
import { alignFrames, distributeFrames, framesBounds } from "./align.js";
|
|
3
|
+
import { diffBoardEdits, isEmptyBoardPatch, readPath, routeBoardEdits, sameJson, writePath } from "./document-edits.js";
|
|
4
|
+
import { normalizeWheelDelta, wheelZoomFactor } from "./wheel.js";
|
|
5
|
+
import { BOARD_CLIPBOARD_VERSION, DUPLICATE_OFFSET, MAX_CLIPBOARD_CHARS, MAX_CLIPBOARD_ITEMS, defaultPasteOffset, encodeClipboard, materializeClipboard, parseClipboard, remapItems } from "./clipboard.js";
|
|
6
|
+
import { CONNECTION_PORT_HIT_RADIUS, CONNECTION_PORT_OFFSET, CONNECTION_PORT_RADIUS, CONNECTION_PORT_TOUCH_HIT_RADIUS, CONNECTION_SIDES, connectionPortAt, connectionPorts, portHitRadius } from "./connection-ports.js";
|
|
7
|
+
import { BOARD_HAND_TAP_SLOP, canTapSelectWithHand, defaultBoardTool, isContinuousBoardTool, isCreationBoardTool, isWithinHandTapSlop } from "./tool.js";
|
|
8
|
+
import { resizeCursorForHandle, resolveSelectionTransform, selectionTransformControlAt } from "./selection-transform.js";
|
|
9
|
+
import { computeSnap } from "./snapping.js";
|
|
10
|
+
import { createSpatialIndex } from "./spatial.js";
|
|
11
|
+
import { createBoardEditor } from "./editor.js";
|
|
12
|
+
export { BOARD_CLIPBOARD_MIME, BOARD_CLIPBOARD_VERSION, BOARD_HAND_TAP_SLOP, CONNECTION_PORT_HIT_RADIUS, CONNECTION_PORT_OFFSET, CONNECTION_PORT_RADIUS, CONNECTION_PORT_TOUCH_HIT_RADIUS, CONNECTION_SIDES, DUPLICATE_OFFSET, MAX_CLIPBOARD_CHARS, MAX_CLIPBOARD_ITEMS, alignFrames, canTapSelectWithHand, computeSnap, connectionPortAt, connectionPorts, createBoardEditor, createSpatialIndex, defaultBoardTool, defaultPasteOffset, diffBoardEdits, distributeFrames, encodeClipboard, framesBounds, isContinuousBoardTool, isCreationBoardTool, isEmptyBoardPatch, isWithinHandTapSlop, materializeClipboard, normalizeWheelDelta, parseClipboard, portHitRadius, readPath, remapItems, resizeCursorForHandle, resolveSelectionTransform, routeBoardEdits, sameJson, selectionTransformControlAt, wheelZoomFactor, writePath };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { BoardArrowItem, BoardDrawPoint } from "../../protocol/dist/board-model.js";
|
|
2
|
+
import { BoardFrame } from "../../protocol/dist/board-layout.js";
|
|
3
|
+
import { BoardViewport, Rect, ResizeHandle, ScreenPoint, WorldPoint } from "../model/geometry.js";
|
|
4
|
+
import { BoardDrawInputSample } from "../model/draw-input.js";
|
|
5
|
+
import "../model/index.js";
|
|
6
|
+
import { BoardTransformControl } from "./selection-transform.js";
|
|
7
|
+
import { EditorContext } from "./context.js";
|
|
8
|
+
//#region src/board/editor/interaction.d.ts
|
|
9
|
+
type BoardInteraction = {
|
|
10
|
+
type: "idle";
|
|
11
|
+
} | {
|
|
12
|
+
type: "panning";
|
|
13
|
+
start: ScreenPoint;
|
|
14
|
+
origin: BoardViewport;
|
|
15
|
+
moved: boolean;
|
|
16
|
+
tapSelection: {
|
|
17
|
+
targetId: string | null;
|
|
18
|
+
} | null;
|
|
19
|
+
} | {
|
|
20
|
+
type: "translating";
|
|
21
|
+
start: WorldPoint;
|
|
22
|
+
origin: Map<string, BoardFrame>;
|
|
23
|
+
moved: boolean;
|
|
24
|
+
duplicate: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
type: "resizing";
|
|
27
|
+
handle: ResizeHandle;
|
|
28
|
+
single: BoardFrame | null;
|
|
29
|
+
bounds: Rect;
|
|
30
|
+
origin: Map<string, BoardFrame>;
|
|
31
|
+
moved: boolean;
|
|
32
|
+
} | {
|
|
33
|
+
type: "rotating";
|
|
34
|
+
pivot: WorldPoint;
|
|
35
|
+
startAngle: number;
|
|
36
|
+
current: WorldPoint;
|
|
37
|
+
origin: Map<string, BoardFrame>;
|
|
38
|
+
moved: boolean;
|
|
39
|
+
} | {
|
|
40
|
+
type: "brushing";
|
|
41
|
+
start: WorldPoint;
|
|
42
|
+
current: WorldPoint;
|
|
43
|
+
additive: boolean;
|
|
44
|
+
baseSelection: string[];
|
|
45
|
+
} | {
|
|
46
|
+
type: "drawing";
|
|
47
|
+
id: string;
|
|
48
|
+
pointerId: number;
|
|
49
|
+
points: BoardDrawPoint[];
|
|
50
|
+
color: string;
|
|
51
|
+
size: number;
|
|
52
|
+
} | {
|
|
53
|
+
type: "creatingArrow";
|
|
54
|
+
id: string;
|
|
55
|
+
start: WorldPoint;
|
|
56
|
+
current: WorldPoint;
|
|
57
|
+
startItemId: string | null;
|
|
58
|
+
startSide: "top" | "right" | "bottom" | "left" | null;
|
|
59
|
+
targetItemId: string | null;
|
|
60
|
+
color: string;
|
|
61
|
+
size: number;
|
|
62
|
+
} | {
|
|
63
|
+
type: "creatingBox";
|
|
64
|
+
id: string;
|
|
65
|
+
kind: "shape" | "frame";
|
|
66
|
+
start: WorldPoint;
|
|
67
|
+
current: WorldPoint;
|
|
68
|
+
color: string;
|
|
69
|
+
geometry: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: "draggingArrowHandle";
|
|
72
|
+
arrowId: string;
|
|
73
|
+
which: "start" | "end" | "mid";
|
|
74
|
+
origin: BoardArrowItem;
|
|
75
|
+
targetItemId: string | null;
|
|
76
|
+
moved: boolean;
|
|
77
|
+
};
|
|
78
|
+
type BoardPointerEvent = {
|
|
79
|
+
pointerId: number;
|
|
80
|
+
screen: ScreenPoint;
|
|
81
|
+
world: WorldPoint;
|
|
82
|
+
shiftKey: boolean;
|
|
83
|
+
metaKey: boolean;
|
|
84
|
+
ctrlKey: boolean;
|
|
85
|
+
altKey: boolean;
|
|
86
|
+
button: number;
|
|
87
|
+
buttons: number;
|
|
88
|
+
pointerType: string;
|
|
89
|
+
cancelled: boolean;
|
|
90
|
+
pressure: number;
|
|
91
|
+
samples?: readonly BoardDrawInputSample[];
|
|
92
|
+
};
|
|
93
|
+
declare function createInteractionModule(ctx: EditorContext): {
|
|
94
|
+
marquee: () => Rect | null;
|
|
95
|
+
hoveredControl: () => BoardTransformControl | null;
|
|
96
|
+
ports: () => {
|
|
97
|
+
itemId: string;
|
|
98
|
+
x: number;
|
|
99
|
+
y: number;
|
|
100
|
+
radius: number;
|
|
101
|
+
}[];
|
|
102
|
+
hoveredPort: () => {
|
|
103
|
+
x: number;
|
|
104
|
+
y: number;
|
|
105
|
+
} | null;
|
|
106
|
+
pointerDown: (event: BoardPointerEvent) => void;
|
|
107
|
+
pointerMove: (event: BoardPointerEvent) => void;
|
|
108
|
+
pointerUp: (event: BoardPointerEvent) => void;
|
|
109
|
+
pointerLeave: () => void;
|
|
110
|
+
cancel: () => void;
|
|
111
|
+
destroy: () => void;
|
|
112
|
+
};
|
|
113
|
+
type InteractionModule = ReturnType<typeof createInteractionModule>;
|
|
114
|
+
//#endregion
|
|
115
|
+
export { BoardInteraction, BoardPointerEvent, InteractionModule, createInteractionModule };
|