@neta-art/cohub 8.24.0 → 9.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/dist/board/animation.d.ts +57 -181
- package/dist/board/animation.js +374 -220
- package/dist/board/core/arrow-geometry.d.ts +33 -18
- package/dist/board/core/arrow-geometry.js +283 -52
- package/dist/board/core/draw-geometry.d.ts +22 -36
- package/dist/board/core/draw-geometry.js +148 -85
- package/dist/board/core/export-assets.d.ts +3 -6
- package/dist/board/core/export-assets.js +0 -2
- package/dist/board/core/export-plan.d.ts +12 -63
- package/dist/board/core/export-plan.js +55 -94
- package/dist/board/core/palette.d.ts +4 -21
- package/dist/board/core/palette.js +8 -13
- package/dist/board/core/scene.d.ts +33 -0
- package/dist/board/core/scene.js +302 -0
- package/dist/board/core/shape-definition.d.ts +12 -24
- package/dist/board/core/shape-definition.js +0 -19
- package/dist/board/core/shape-types.d.ts +6 -120
- package/dist/board/core/shape-types.js +5 -5
- package/dist/board/core/text-metrics.d.ts +8 -11
- package/dist/board/core/text-metrics.js +5 -34
- package/dist/board/core/tool-styles.d.ts +6 -16
- package/dist/board/core/tool-styles.js +17 -25
- package/dist/board/export/index.d.ts +10 -17
- package/dist/board/export/index.js +22 -21
- package/dist/board/export/scene.d.ts +10 -16
- package/dist/board/export/scene.js +17 -30
- package/dist/board/geometry.d.ts +27 -56
- package/dist/board/geometry.js +7 -67
- package/dist/board/headless/index.d.ts +6 -27
- package/dist/board/headless/index.js +4 -19
- package/dist/board/headless/sketch.d.ts +19 -0
- package/dist/board/headless/sketch.js +146 -0
- package/dist/board/image-key.d.ts +2 -12
- package/dist/board/image-key.js +3 -13
- package/dist/board/index.d.ts +18 -20
- package/dist/board/index.js +17 -17
- package/dist/board/media-playback.d.ts +3 -6
- package/dist/board/media-playback.js +6 -6
- package/dist/board/presets.d.ts +150 -0
- package/dist/board/presets.js +226 -0
- package/dist/board/render/board-background.d.ts +5 -3
- package/dist/board/render/board-background.js +8 -7
- package/dist/board/render/clip.d.ts +14 -0
- package/dist/board/render/clip.js +47 -0
- package/dist/board/render/index.d.ts +8 -5
- package/dist/board/render/index.js +7 -4
- package/dist/board/render/media-interaction.d.ts +4 -5
- package/dist/board/render/media-interaction.js +1 -2
- package/dist/board/render/palette.d.ts +6 -2
- package/dist/board/render/palette.js +7 -1
- package/dist/board/render/renderers/arrow-card-renderer.js +69 -71
- package/dist/board/render/renderers/audio-card-renderer.js +3 -3
- package/dist/board/render/renderers/base-card-renderer.d.ts +6 -17
- package/dist/board/render/renderers/base-card-renderer.js +1 -24
- package/dist/board/render/renderers/board-renderer-registry.d.ts +20 -50
- package/dist/board/render/renderers/board-renderer-registry.js +6 -7
- package/dist/board/render/renderers/draw-card-renderer.js +89 -56
- package/dist/board/render/renderers/effect-card-renderer.d.ts +6 -0
- package/dist/board/render/renderers/effect-card-renderer.js +197 -0
- package/dist/board/render/renderers/far-plate.d.ts +4 -21
- package/dist/board/render/renderers/far-plate.js +15 -34
- package/dist/board/render/renderers/file-card-renderer.d.ts +4 -25
- package/dist/board/render/renderers/file-card-renderer.js +8 -58
- package/dist/board/render/renderers/frame-card-renderer.js +28 -28
- package/dist/board/render/renderers/image-card-renderer.d.ts +4 -3
- package/dist/board/render/renderers/image-card-renderer.js +0 -9
- package/dist/board/render/renderers/shape-card-renderer.d.ts +9 -0
- package/dist/board/render/renderers/shape-card-renderer.js +240 -0
- package/dist/board/render/renderers/sketch-card-renderer.d.ts +5 -0
- package/dist/board/render/renderers/sketch-card-renderer.js +98 -0
- package/dist/board/render/renderers/task-card-renderer.d.ts +0 -1
- package/dist/board/render/renderers/task-card-renderer.js +14 -16
- package/dist/board/render/renderers/text-card-renderer.d.ts +1 -3
- package/dist/board/render/renderers/text-card-renderer.js +56 -46
- package/dist/board/render/renderers/unknown-card-renderer.js +4 -10
- package/dist/board/render/renderers/video-card-renderer.d.ts +4 -2
- package/dist/board/render/renderers/video-card-renderer.js +2 -1
- package/dist/board/render/sketch-host.d.ts +14 -0
- package/dist/board/render/sketch-host.js +216 -0
- package/dist/board/render/stroke.d.ts +12 -0
- package/dist/board/render/stroke.js +90 -0
- package/dist/board/render/text-measurement.d.ts +6 -26
- package/dist/board/render/text-measurement.js +11 -30
- package/dist/board/replay.d.ts +6 -31
- package/dist/board/replay.js +45 -203
- package/dist/board/runtime/board-player.d.ts +24 -0
- package/dist/board/runtime/board-player.js +161 -0
- package/dist/board/task.d.ts +2 -10
- package/dist/board/task.js +1 -10
- package/dist/chunks/environment.d.ts +2291 -3864
- package/dist/chunks/host-bridge.d.ts +253 -0
- package/dist/chunks/http.d.ts +233 -58
- package/dist/chunks/http.js +1046 -1028
- package/dist/chunks/transport.js +113 -59
- package/dist/chunks/websocket.d.ts +1 -1
- package/dist/chunks/websocket.js +1 -1
- package/dist/host-bridge.d.ts +54 -0
- package/dist/host-bridge.js +322 -0
- package/dist/http.d.ts +3 -3
- package/dist/index.d.ts +74 -191
- package/dist/index.js +2032 -1186
- package/dist/protocol/dist/board-constants.d.ts +1 -29
- package/dist/protocol/dist/board-constants.js +2 -115
- package/dist/protocol/dist/board-layout.d.ts +59 -0
- package/dist/protocol/dist/board-layout.js +482 -0
- package/dist/protocol/dist/board-model.d.ts +2052 -0
- package/dist/protocol/dist/board-model.js +592 -0
- package/dist/protocol/dist/board-patch.d.ts +86 -0
- package/dist/protocol/dist/board-patch.js +734 -0
- package/dist/protocol/dist/board-schema.d.ts +33 -0
- package/dist/protocol/dist/board-schema.js +59 -0
- package/dist/protocol/dist/board-upgrade.d.ts +1 -0
- package/dist/protocol/dist/board-url.d.ts +1 -3
- package/dist/protocol/dist/board-url.js +2 -2
- package/dist/protocol/dist/board.d.ts +37 -232
- package/dist/protocol/dist/board.js +62 -160
- package/dist/protocol/dist/display/actions.d.ts +1 -0
- package/dist/protocol/dist/display/index.d.ts +2 -0
- package/dist/protocol/dist/index.d.ts +11 -12
- package/dist/protocol/dist/model/metrics.d.ts +2 -0
- package/dist/protocol/dist/model/session.d.ts +2 -1
- package/dist/protocol/dist/realtime/types.d.ts +2 -2
- package/dist/protocol/dist/runtime/index.d.ts +1 -0
- package/dist/space-picker.d.ts +1 -0
- package/dist/space-picker.js +1 -0
- package/dist/types.d.ts +2 -5
- package/package.json +9 -1
- package/dist/board/core/connections.d.ts +0 -108
- package/dist/board/core/connections.js +0 -455
- package/dist/board/mutation.d.ts +0 -6
- package/dist/board/mutation.js +0 -14
- package/dist/board/render/connection-layer.d.ts +0 -53
- package/dist/board/render/connection-layer.js +0 -375
- package/dist/board/render/renderers/geo-card-renderer.d.ts +0 -5
- package/dist/board/render/renderers/geo-card-renderer.js +0 -127
- package/dist/board/semantic-document.d.ts +0 -37
- package/dist/board/semantic-document.js +0 -288
- package/dist/board/semantic-mutation.d.ts +0 -10
- package/dist/board/semantic-mutation.js +0 -209
- package/dist/protocol/dist/board-animation.js +0 -34
- package/dist/protocol/dist/board-authoring.d.ts +0 -1326
- package/dist/protocol/dist/board-authoring.js +0 -302
- package/dist/protocol/dist/board-capability-registry.d.ts +0 -2
- package/dist/protocol/dist/board-capability-registry.js +0 -123
- package/dist/protocol/dist/board-codec.d.ts +0 -3
- package/dist/protocol/dist/board-codec.js +0 -383
- package/dist/protocol/dist/board-composition.d.ts +0 -383
- package/dist/protocol/dist/board-composition.js +0 -310
- package/dist/protocol/dist/board-connection.d.ts +0 -317
- package/dist/protocol/dist/board-connection.js +0 -219
- package/dist/protocol/dist/board-document.d.ts +0 -1566
- package/dist/protocol/dist/board-document.js +0 -456
- package/dist/protocol/dist/board-effect.d.ts +0 -96
- package/dist/protocol/dist/board-effect.js +0 -54
- package/dist/protocol/dist/board-geometry.d.ts +0 -15
- package/dist/protocol/dist/board-geometry.js +0 -137
- package/dist/protocol/dist/board-node.d.ts +0 -8
- package/dist/protocol/dist/board-node.js +0 -252
- /package/dist/protocol/dist/{board-animation.d.ts → host-bridge.d.ts} +0 -0
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import { BoardAuthoringItemSchema } from "../protocol/dist/board-authoring.js";
|
|
2
|
-
import { BOARD_DOCUMENT_KIND } from "../protocol/dist/board.js";
|
|
3
|
-
import { BoardAppearanceSchema, UNKNOWN_BOARD_ITEM_TYPE, isUnknownItem, parseBoardDocument } from "../protocol/dist/board-document.js";
|
|
4
|
-
import { boardDrawPointsToWorld } from "../protocol/dist/board-geometry.js";
|
|
5
|
-
import { boardAuthoringItemToNode } from "../protocol/dist/board-codec.js";
|
|
6
|
-
//#region src/board/semantic-document.ts
|
|
7
|
-
const DEFAULT_BOARD_APPEARANCE = BoardAppearanceSchema.parse({
|
|
8
|
-
background: { kind: "solid" },
|
|
9
|
-
grid: {
|
|
10
|
-
visible: false,
|
|
11
|
-
size: 24,
|
|
12
|
-
opacity: .12
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
/** Convert a public authoring Item to the renderer/editor document shape. */
|
|
16
|
-
function boardAuthoringItemToDocumentItem(item) {
|
|
17
|
-
const node = boardAuthoringItemToNode(item);
|
|
18
|
-
const base = {
|
|
19
|
-
id: item.id,
|
|
20
|
-
frame: {
|
|
21
|
-
x: node.x,
|
|
22
|
-
y: node.y,
|
|
23
|
-
width: node.width,
|
|
24
|
-
height: node.height,
|
|
25
|
-
rotation: node.rotation
|
|
26
|
-
},
|
|
27
|
-
...item.parentId !== void 0 ? { parentId: item.parentId } : {},
|
|
28
|
-
...item.locked ? { locked: true } : {},
|
|
29
|
-
...item.metadata ? { metadata: item.metadata } : {}
|
|
30
|
-
};
|
|
31
|
-
const props = item.props;
|
|
32
|
-
const style = "style" in item ? item.style : void 0;
|
|
33
|
-
const source = "source" in item ? item.source : void 0;
|
|
34
|
-
switch (item.type) {
|
|
35
|
-
case "text": return {
|
|
36
|
-
...base,
|
|
37
|
-
type: "text",
|
|
38
|
-
text: String(props.text ?? ""),
|
|
39
|
-
fontSize: Number(props.fontSize ?? 24),
|
|
40
|
-
color: String(style?.color ?? "neutral")
|
|
41
|
-
};
|
|
42
|
-
case "geo": return {
|
|
43
|
-
...base,
|
|
44
|
-
type: "geo",
|
|
45
|
-
geo: String(props.shape ?? "rectangle"),
|
|
46
|
-
text: String(props.text ?? ""),
|
|
47
|
-
color: String(style?.color ?? "brand"),
|
|
48
|
-
fillOpacity: Number(style?.fillOpacity ?? 0)
|
|
49
|
-
};
|
|
50
|
-
case "draw": return {
|
|
51
|
-
...base,
|
|
52
|
-
type: "draw",
|
|
53
|
-
points: node.data.points,
|
|
54
|
-
color: String(style?.color ?? "brand"),
|
|
55
|
-
size: Number(style?.strokeWidth ?? 4)
|
|
56
|
-
};
|
|
57
|
-
case "arrow": return {
|
|
58
|
-
...base,
|
|
59
|
-
type: "arrow",
|
|
60
|
-
...props,
|
|
61
|
-
color: String(style?.color ?? "brand"),
|
|
62
|
-
size: Number(style?.strokeWidth ?? 2.5)
|
|
63
|
-
};
|
|
64
|
-
case "frame": return {
|
|
65
|
-
...base,
|
|
66
|
-
type: "frame",
|
|
67
|
-
label: String(props.label ?? "Frame"),
|
|
68
|
-
color: String(style?.color ?? "neutral")
|
|
69
|
-
};
|
|
70
|
-
case "image": return {
|
|
71
|
-
...base,
|
|
72
|
-
type: "image",
|
|
73
|
-
ref: {
|
|
74
|
-
kind: "space-file",
|
|
75
|
-
path: String(source?.path ?? "")
|
|
76
|
-
},
|
|
77
|
-
...source?.snapshot ? { snapshot: source.snapshot } : {},
|
|
78
|
-
...props.crop ? { crop: props.crop } : {}
|
|
79
|
-
};
|
|
80
|
-
case "video": return {
|
|
81
|
-
...base,
|
|
82
|
-
type: "video",
|
|
83
|
-
ref: {
|
|
84
|
-
kind: "space-file",
|
|
85
|
-
path: String(source?.path ?? "")
|
|
86
|
-
},
|
|
87
|
-
...source?.snapshot ? { snapshot: source.snapshot } : {}
|
|
88
|
-
};
|
|
89
|
-
case "audio": return {
|
|
90
|
-
...base,
|
|
91
|
-
type: "audio",
|
|
92
|
-
ref: {
|
|
93
|
-
kind: "space-file",
|
|
94
|
-
path: String(source?.path ?? "")
|
|
95
|
-
},
|
|
96
|
-
...source?.snapshot ? { snapshot: source.snapshot } : {}
|
|
97
|
-
};
|
|
98
|
-
case "file": return {
|
|
99
|
-
...base,
|
|
100
|
-
type: "file",
|
|
101
|
-
ref: {
|
|
102
|
-
kind: "space-file",
|
|
103
|
-
path: String(source?.path ?? "")
|
|
104
|
-
},
|
|
105
|
-
...source?.snapshot ? { snapshot: source.snapshot } : {}
|
|
106
|
-
};
|
|
107
|
-
case "task": return {
|
|
108
|
-
...base,
|
|
109
|
-
type: "task",
|
|
110
|
-
taskRunId: String(props.taskRunId ?? ""),
|
|
111
|
-
snapshot: props.snapshot
|
|
112
|
-
};
|
|
113
|
-
default: return {
|
|
114
|
-
...base,
|
|
115
|
-
type: UNKNOWN_BOARD_ITEM_TYPE,
|
|
116
|
-
raw: item
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/** Convert the renderer/editor item back to the public authoring envelope. */
|
|
121
|
-
function boardItemToAuthoringItem(item) {
|
|
122
|
-
if (isUnknownItem(item)) {
|
|
123
|
-
const parsed = BoardAuthoringItemSchema.safeParse(item.raw);
|
|
124
|
-
return parsed.success ? parsed.data : null;
|
|
125
|
-
}
|
|
126
|
-
const base = {
|
|
127
|
-
id: item.id,
|
|
128
|
-
...item.type === "draw" || item.type === "arrow" ? {} : {
|
|
129
|
-
position: {
|
|
130
|
-
x: item.frame.x,
|
|
131
|
-
y: item.frame.y
|
|
132
|
-
},
|
|
133
|
-
size: {
|
|
134
|
-
width: item.frame.width,
|
|
135
|
-
height: item.frame.height
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
rotation: item.frame.rotation,
|
|
139
|
-
...item.parentId !== void 0 ? { parentId: item.parentId } : {},
|
|
140
|
-
...item.locked ? { locked: true } : {},
|
|
141
|
-
...item.metadata ? { metadata: item.metadata } : {}
|
|
142
|
-
};
|
|
143
|
-
switch (item.type) {
|
|
144
|
-
case "text": return {
|
|
145
|
-
...base,
|
|
146
|
-
type: "text",
|
|
147
|
-
props: {
|
|
148
|
-
text: item.text,
|
|
149
|
-
fontSize: item.fontSize
|
|
150
|
-
},
|
|
151
|
-
style: { color: item.color }
|
|
152
|
-
};
|
|
153
|
-
case "geo": return {
|
|
154
|
-
...base,
|
|
155
|
-
type: "geo",
|
|
156
|
-
props: {
|
|
157
|
-
shape: item.geo,
|
|
158
|
-
text: item.text
|
|
159
|
-
},
|
|
160
|
-
style: {
|
|
161
|
-
color: item.color,
|
|
162
|
-
fillOpacity: item.fillOpacity
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
case "draw": return {
|
|
166
|
-
...base,
|
|
167
|
-
type: "draw",
|
|
168
|
-
props: { points: boardDrawPointsToWorld(item.points, item.frame.x, item.frame.y) },
|
|
169
|
-
style: {
|
|
170
|
-
color: item.color,
|
|
171
|
-
strokeWidth: item.size
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
case "arrow": return {
|
|
175
|
-
...base,
|
|
176
|
-
type: "arrow",
|
|
177
|
-
props: {
|
|
178
|
-
start: item.start,
|
|
179
|
-
end: item.end,
|
|
180
|
-
bend: item.bend,
|
|
181
|
-
arrowStart: item.arrowStart,
|
|
182
|
-
arrowEnd: item.arrowEnd,
|
|
183
|
-
label: item.label
|
|
184
|
-
},
|
|
185
|
-
style: {
|
|
186
|
-
color: item.color,
|
|
187
|
-
strokeWidth: item.size
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
case "frame": return {
|
|
191
|
-
...base,
|
|
192
|
-
type: "frame",
|
|
193
|
-
props: { label: item.label },
|
|
194
|
-
style: { color: item.color }
|
|
195
|
-
};
|
|
196
|
-
case "image": return {
|
|
197
|
-
...base,
|
|
198
|
-
type: "image",
|
|
199
|
-
props: item.crop ? { crop: item.crop } : {},
|
|
200
|
-
source: {
|
|
201
|
-
kind: "space-file",
|
|
202
|
-
path: item.ref.path,
|
|
203
|
-
...item.snapshot ? { snapshot: item.snapshot } : {}
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
case "video": return {
|
|
207
|
-
...base,
|
|
208
|
-
type: "video",
|
|
209
|
-
props: {},
|
|
210
|
-
source: {
|
|
211
|
-
kind: "space-file",
|
|
212
|
-
path: item.ref.path,
|
|
213
|
-
...item.snapshot ? { snapshot: item.snapshot } : {}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
case "audio": return {
|
|
217
|
-
...base,
|
|
218
|
-
type: "audio",
|
|
219
|
-
props: {},
|
|
220
|
-
source: {
|
|
221
|
-
kind: "space-file",
|
|
222
|
-
path: item.ref.path,
|
|
223
|
-
...item.snapshot ? { snapshot: item.snapshot } : {}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
case "file": return {
|
|
227
|
-
...base,
|
|
228
|
-
type: "file",
|
|
229
|
-
props: {},
|
|
230
|
-
source: {
|
|
231
|
-
kind: "space-file",
|
|
232
|
-
path: item.ref.path,
|
|
233
|
-
snapshot: item.snapshot
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
case "task": return {
|
|
237
|
-
...base,
|
|
238
|
-
type: "task",
|
|
239
|
-
props: {
|
|
240
|
-
taskRunId: item.taskRunId,
|
|
241
|
-
snapshot: item.snapshot
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function boardAuthoringSnapshotToDocument(input) {
|
|
247
|
-
const appearance = BoardAppearanceSchema.safeParse(input.board.metadata.appearance);
|
|
248
|
-
return parseBoardDocument({
|
|
249
|
-
kind: BOARD_DOCUMENT_KIND,
|
|
250
|
-
version: 1,
|
|
251
|
-
appearance: appearance.success ? appearance.data : DEFAULT_BOARD_APPEARANCE,
|
|
252
|
-
viewport: {
|
|
253
|
-
x: 0,
|
|
254
|
-
y: 0,
|
|
255
|
-
zoom: 1
|
|
256
|
-
},
|
|
257
|
-
items: (input.items ?? []).map(boardAuthoringItemToDocumentItem),
|
|
258
|
-
connections: input.connections ?? []
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
function applyBoardAuthoringSnapshot(document, input, changed) {
|
|
262
|
-
let items = document.items;
|
|
263
|
-
if (changed.orderChanged && input.items) items = input.items.map(boardAuthoringItemToDocumentItem);
|
|
264
|
-
else if (input.items !== void 0 || changed.items.length > 0) {
|
|
265
|
-
const received = new Map((input.items ?? []).map((item) => [item.id, item]));
|
|
266
|
-
const changedIds = new Set(changed.items);
|
|
267
|
-
items = document.items.filter((item) => !changedIds.has(item.id) || received.has(item.id)).map((item) => received.has(item.id) ? boardAuthoringItemToDocumentItem(received.get(item.id)) : item);
|
|
268
|
-
const present = new Set(items.map((item) => item.id));
|
|
269
|
-
for (const item of received.values()) if (!present.has(item.id)) items.push(boardAuthoringItemToDocumentItem(item));
|
|
270
|
-
}
|
|
271
|
-
let connections = document.connections;
|
|
272
|
-
if (input.connections !== void 0 || changed.connections.length > 0) {
|
|
273
|
-
const received = new Map((input.connections ?? []).map((connection) => [connection.id, connection]));
|
|
274
|
-
const changedIds = new Set(changed.connections);
|
|
275
|
-
connections = document.connections.filter((connection) => !changedIds.has(connection.id) || received.has(connection.id)).map((connection) => received.get(connection.id) ?? connection);
|
|
276
|
-
const present = new Set(connections.map((connection) => connection.id));
|
|
277
|
-
for (const connection of received.values()) if (!present.has(connection.id)) connections.push(connection);
|
|
278
|
-
}
|
|
279
|
-
const appearance = changed.board ? BoardAppearanceSchema.safeParse(input.board.metadata.appearance) : null;
|
|
280
|
-
return parseBoardDocument({
|
|
281
|
-
...document,
|
|
282
|
-
...appearance?.success ? { appearance: appearance.data } : {},
|
|
283
|
-
items,
|
|
284
|
-
connections
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
//#endregion
|
|
288
|
-
export { DEFAULT_BOARD_APPEARANCE, applyBoardAuthoringSnapshot, boardAuthoringItemToDocumentItem, boardAuthoringSnapshotToDocument, boardItemToAuthoringItem };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BoardSemanticCommand } from "../protocol/dist/board-authoring.js";
|
|
2
|
-
import { BoardDocument } from "../protocol/dist/board-document.js";
|
|
3
|
-
import "../protocol/dist/index.js";
|
|
4
|
-
//#region src/board/semantic-mutation.d.ts
|
|
5
|
-
/** Compile an editor document delta to the public semantic mutation command set. */
|
|
6
|
-
declare function boardDocumentToSemanticCommands(before: BoardDocument, after: BoardDocument): BoardSemanticCommand[];
|
|
7
|
-
/** Apply public semantic commands to the local render document (undo/rebase). */
|
|
8
|
-
declare function applyBoardSemanticCommands(document: BoardDocument, commands: readonly BoardSemanticCommand[]): BoardDocument;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { applyBoardSemanticCommands, boardDocumentToSemanticCommands };
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { BoardAuthoringItemSchema } from "../protocol/dist/board-authoring.js";
|
|
2
|
-
import { BoardAppearanceSchema, isUnknownItem } from "../protocol/dist/board-document.js";
|
|
3
|
-
import { applyBoardItemPatch } from "../protocol/dist/board-codec.js";
|
|
4
|
-
import { boardJsonEquals } from "../protocol/dist/board-json.js";
|
|
5
|
-
import { boardAuthoringItemToDocumentItem, boardItemToAuthoringItem } from "./semantic-document.js";
|
|
6
|
-
//#region src/board/semantic-mutation.ts
|
|
7
|
-
function semanticItem(item) {
|
|
8
|
-
const value = boardItemToAuthoringItem(item);
|
|
9
|
-
if (value) return value;
|
|
10
|
-
const raw = isUnknownItem(item) ? BoardAuthoringItemSchema.safeParse(item.raw) : null;
|
|
11
|
-
if (raw?.success) return raw.data;
|
|
12
|
-
throw new Error(`Cannot author unknown Board item ${item.id}; the item has no semantic extension schema`);
|
|
13
|
-
}
|
|
14
|
-
function mergePatchValue(before, after) {
|
|
15
|
-
if (boardJsonEquals(before, after)) return void 0;
|
|
16
|
-
if (after === void 0) return null;
|
|
17
|
-
if (before && after && typeof before === "object" && typeof after === "object" && !Array.isArray(before) && !Array.isArray(after)) {
|
|
18
|
-
const patch = {};
|
|
19
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
20
|
-
for (const key of keys) {
|
|
21
|
-
const value = mergePatchValue(before[key], after[key]);
|
|
22
|
-
if (value !== void 0) patch[key] = value;
|
|
23
|
-
}
|
|
24
|
-
return patch;
|
|
25
|
-
}
|
|
26
|
-
return after;
|
|
27
|
-
}
|
|
28
|
-
function itemPatch(before, after) {
|
|
29
|
-
const beforeAuthoring = semanticItem(before);
|
|
30
|
-
const afterAuthoring = semanticItem(after);
|
|
31
|
-
const patch = {};
|
|
32
|
-
const beforePosition = "position" in beforeAuthoring ? beforeAuthoring.position : void 0;
|
|
33
|
-
const afterPosition = "position" in afterAuthoring ? afterAuthoring.position : void 0;
|
|
34
|
-
if (!boardJsonEquals(beforePosition, afterPosition) && afterPosition) patch.position = afterPosition;
|
|
35
|
-
const beforeSize = "size" in beforeAuthoring ? beforeAuthoring.size : void 0;
|
|
36
|
-
const afterSize = "size" in afterAuthoring ? afterAuthoring.size : void 0;
|
|
37
|
-
if (!boardJsonEquals(beforeSize, afterSize)) patch.size = afterSize ?? null;
|
|
38
|
-
if (beforeAuthoring.rotation !== afterAuthoring.rotation) patch.rotation = afterAuthoring.rotation;
|
|
39
|
-
const beforeParent = before.parentId ?? null;
|
|
40
|
-
const afterParent = after.parentId ?? null;
|
|
41
|
-
if (beforeParent !== afterParent) patch.parentId = afterParent;
|
|
42
|
-
if ((before.locked ?? false) !== (after.locked ?? false)) patch.locked = after.locked ?? null;
|
|
43
|
-
const metadata = mergePatchValue(before.metadata, after.metadata);
|
|
44
|
-
if (metadata !== void 0) patch.metadata = after.metadata === void 0 ? null : metadata;
|
|
45
|
-
const props = mergePatchValue(beforeAuthoring.props, afterAuthoring.props);
|
|
46
|
-
if (props !== void 0) patch.props = props;
|
|
47
|
-
const beforeStyle = "style" in beforeAuthoring ? beforeAuthoring.style : void 0;
|
|
48
|
-
const afterStyle = "style" in afterAuthoring ? afterAuthoring.style : void 0;
|
|
49
|
-
const style = mergePatchValue(beforeStyle, afterStyle);
|
|
50
|
-
if (style !== void 0) patch.style = afterStyle === void 0 ? null : style;
|
|
51
|
-
const beforeSource = "source" in beforeAuthoring ? beforeAuthoring.source : void 0;
|
|
52
|
-
const afterSource = "source" in afterAuthoring ? afterAuthoring.source : void 0;
|
|
53
|
-
const source = mergePatchValue(beforeSource, afterSource);
|
|
54
|
-
if (source !== void 0) patch.source = afterSource === void 0 ? null : source;
|
|
55
|
-
return Object.keys(patch).length ? patch : null;
|
|
56
|
-
}
|
|
57
|
-
function connectionPatch(before, after) {
|
|
58
|
-
const patch = {};
|
|
59
|
-
for (const key of [
|
|
60
|
-
"source",
|
|
61
|
-
"target",
|
|
62
|
-
"relation",
|
|
63
|
-
"direction",
|
|
64
|
-
"label",
|
|
65
|
-
"routing",
|
|
66
|
-
"style",
|
|
67
|
-
"metadata"
|
|
68
|
-
]) if (!boardJsonEquals(before[key], after[key])) patch[key] = after[key];
|
|
69
|
-
return Object.keys(patch).length ? patch : null;
|
|
70
|
-
}
|
|
71
|
-
/** Compile an editor document delta to the public semantic mutation command set. */
|
|
72
|
-
function boardDocumentToSemanticCommands(before, after) {
|
|
73
|
-
const commands = [];
|
|
74
|
-
if (!boardJsonEquals(before.appearance, after.appearance)) commands.push({
|
|
75
|
-
type: "board.patch",
|
|
76
|
-
patch: { metadataPatch: { appearance: after.appearance } }
|
|
77
|
-
});
|
|
78
|
-
const beforeConnections = new Map(before.connections.map((connection) => [connection.id, connection]));
|
|
79
|
-
const afterConnections = new Map(after.connections.map((connection) => [connection.id, connection]));
|
|
80
|
-
const beforeItems = new Map(before.items.map((item) => [item.id, item]));
|
|
81
|
-
const afterItems = new Map(after.items.map((item) => [item.id, item]));
|
|
82
|
-
for (const [id] of beforeConnections) if (!afterConnections.has(id)) commands.push({
|
|
83
|
-
type: "connection.delete",
|
|
84
|
-
connectionId: id
|
|
85
|
-
});
|
|
86
|
-
for (const item of after.items) {
|
|
87
|
-
const previous = beforeItems.get(item.id);
|
|
88
|
-
if (!previous) {
|
|
89
|
-
commands.push({
|
|
90
|
-
type: "item.create",
|
|
91
|
-
item: semanticItem(item)
|
|
92
|
-
});
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (previous.type !== item.type) {
|
|
96
|
-
commands.push({
|
|
97
|
-
type: "item.replace",
|
|
98
|
-
itemId: item.id,
|
|
99
|
-
item: semanticItem(item)
|
|
100
|
-
});
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const patch = itemPatch(previous, item);
|
|
104
|
-
if (patch) commands.push({
|
|
105
|
-
type: "item.patch",
|
|
106
|
-
itemId: item.id,
|
|
107
|
-
patch
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
for (const [id] of beforeItems) if (!afterItems.has(id)) commands.push({
|
|
111
|
-
type: "item.delete",
|
|
112
|
-
itemId: id,
|
|
113
|
-
cascade: false
|
|
114
|
-
});
|
|
115
|
-
const workingOrder = before.items.map((item) => item.id);
|
|
116
|
-
for (const item of after.items) if (!beforeItems.has(item.id)) workingOrder.push(item.id);
|
|
117
|
-
for (const [id] of beforeItems) if (!afterItems.has(id)) workingOrder.splice(workingOrder.indexOf(id), 1);
|
|
118
|
-
for (let index = 0; index < after.items.length; index += 1) {
|
|
119
|
-
const id = after.items[index]?.id;
|
|
120
|
-
if (!id || workingOrder[index] === id) continue;
|
|
121
|
-
const previousIndex = workingOrder.indexOf(id);
|
|
122
|
-
if (previousIndex < 0) continue;
|
|
123
|
-
workingOrder.splice(previousIndex, 1);
|
|
124
|
-
workingOrder.splice(index, 0, id);
|
|
125
|
-
commands.push({
|
|
126
|
-
type: "item.reorder",
|
|
127
|
-
itemId: id,
|
|
128
|
-
index
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
for (const connection of after.connections) {
|
|
132
|
-
const previous = beforeConnections.get(connection.id);
|
|
133
|
-
if (!previous) {
|
|
134
|
-
commands.push({
|
|
135
|
-
type: "connection.create",
|
|
136
|
-
connection
|
|
137
|
-
});
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const patch = connectionPatch(previous, connection);
|
|
141
|
-
if (patch) commands.push({
|
|
142
|
-
type: "connection.patch",
|
|
143
|
-
connectionId: connection.id,
|
|
144
|
-
patch
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return commands;
|
|
148
|
-
}
|
|
149
|
-
/** Apply public semantic commands to the local render document (undo/rebase). */
|
|
150
|
-
function applyBoardSemanticCommands(document, commands) {
|
|
151
|
-
let items = [...document.items];
|
|
152
|
-
let connections = [...document.connections];
|
|
153
|
-
let appearance = document.appearance;
|
|
154
|
-
for (const command of commands) {
|
|
155
|
-
if (command.type === "board.patch") {
|
|
156
|
-
const candidate = command.patch.metadataPatch?.appearance ?? command.patch.metadata?.appearance;
|
|
157
|
-
if (candidate !== void 0) {
|
|
158
|
-
const parsed = BoardAppearanceSchema.safeParse(candidate);
|
|
159
|
-
if (parsed.success) appearance = parsed.data;
|
|
160
|
-
}
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
if (command.type === "item.create") {
|
|
164
|
-
if (!items.some((item) => item.id === command.item.id)) items.push(boardAuthoringItemToDocumentItem(command.item));
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
if (command.type === "item.patch") {
|
|
168
|
-
items = items.map((item) => item.id === command.itemId ? boardAuthoringItemToDocumentItem(applyBoardItemPatch(semanticItem(item), command.patch)) : item);
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (command.type === "item.replace") {
|
|
172
|
-
items = items.map((item) => item.id === command.itemId ? boardAuthoringItemToDocumentItem(command.item) : item);
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
if (command.type === "item.delete") {
|
|
176
|
-
items = items.filter((item) => item.id !== command.itemId);
|
|
177
|
-
connections = connections.filter((connection) => connection.source.itemId !== command.itemId && connection.target.itemId !== command.itemId);
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
if (command.type === "item.reorder") {
|
|
181
|
-
const index = items.findIndex((item) => item.id === command.itemId);
|
|
182
|
-
if (index < 0) continue;
|
|
183
|
-
const [item] = items.splice(index, 1);
|
|
184
|
-
if (item) items.splice(Math.min(command.index, items.length), 0, item);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
if (command.type === "connection.create") {
|
|
188
|
-
if (!connections.some((connection) => connection.id === command.connection.id)) connections.push(command.connection);
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (command.type === "connection.patch") {
|
|
192
|
-
connections = connections.map((connection) => connection.id === command.connectionId ? {
|
|
193
|
-
...connection,
|
|
194
|
-
...command.patch,
|
|
195
|
-
id: connection.id
|
|
196
|
-
} : connection);
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (command.type === "connection.delete") connections = connections.filter((connection) => connection.id !== command.connectionId);
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
...document,
|
|
203
|
-
appearance,
|
|
204
|
-
items,
|
|
205
|
-
connections
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
//#endregion
|
|
209
|
-
export { applyBoardSemanticCommands, boardDocumentToSemanticCommands };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
//#region ../protocol/dist/board-animation.js
|
|
3
|
-
const extensionKindSchema = z.string().regex(/^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)+$/).max(160);
|
|
4
|
-
const jsonObjectSchema = z.record(z.string(), z.unknown());
|
|
5
|
-
const finiteSchema = z.number().finite();
|
|
6
|
-
/** Parameters shared by the built-in deal entrance preset. */
|
|
7
|
-
const BoardDealParamsSchema = z.object({
|
|
8
|
-
lift: finiteSchema.nonnegative().max(2e3).optional(),
|
|
9
|
-
swing: finiteSchema.nonnegative().max(2e3).optional(),
|
|
10
|
-
curve: finiteSchema.nonnegative().max(2e3).optional(),
|
|
11
|
-
tilt: finiteSchema.nonnegative().max(180).optional(),
|
|
12
|
-
scale: finiteSchema.positive().max(2).optional(),
|
|
13
|
-
duration: finiteSchema.positive().max(1e4).optional(),
|
|
14
|
-
landing: finiteSchema.nonnegative().max(1e4).optional()
|
|
15
|
-
}).strict();
|
|
16
|
-
/** A versioned, reusable animation preset reference. */
|
|
17
|
-
const BoardAnimationSpecSchema = z.object({
|
|
18
|
-
kind: extensionKindSchema,
|
|
19
|
-
kindVersion: z.number().int().positive().default(1),
|
|
20
|
-
params: jsonObjectSchema.default({})
|
|
21
|
-
}).strict().superRefine((spec, context) => {
|
|
22
|
-
if (spec.kind !== "effects.deal" || spec.kindVersion !== 1) return;
|
|
23
|
-
const parsed = BoardDealParamsSchema.safeParse(spec.params);
|
|
24
|
-
if (parsed.success) return;
|
|
25
|
-
context.addIssue({
|
|
26
|
-
code: "custom",
|
|
27
|
-
message: parsed.error.issues[0]?.message ?? "invalid effects.deal parameters",
|
|
28
|
-
path: ["params", ...parsed.error.issues[0]?.path ?? []]
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
/** Board-wide default motion policies. Omitted policies mean no motion. */
|
|
32
|
-
const BoardMotionSchema = z.object({ enter: BoardAnimationSpecSchema.optional() }).strict();
|
|
33
|
-
//#endregion
|
|
34
|
-
export { BoardAnimationSpecSchema, BoardDealParamsSchema, BoardMotionSchema };
|