@dou-ui/flow 0.1.0-alpha.3 → 0.1.0-alpha.30
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/collaboration/index.js +114 -6
- package/dist/collaboration/index.js.map +1 -1
- package/dist/comments.js +257 -0
- package/dist/comments.js.map +1 -0
- package/dist/components/default-node.js.map +1 -1
- package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/components/default-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/flow-comments.js +6 -0
- package/dist/components/flow-comments.js.map +1 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js +218 -0
- package/dist/components/flow-comments.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/flow-port.js.map +1 -1
- package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js +7 -42
- package/dist/components/flow-port.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/flow-toolbar.js.map +1 -1
- package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js +300 -9
- package/dist/components/flow-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/node-view.js.map +1 -1
- package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/components/node-view.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/port-view.js +6 -0
- package/dist/components/port-view.js.map +1 -0
- package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js +60 -0
- package/dist/components/port-view.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/context.js.map +1 -1
- package/dist/core/extension.js.map +1 -1
- package/dist/core/history.js +26 -0
- package/dist/core/history.js.map +1 -1
- package/dist/core/model.js.map +1 -1
- package/dist/core/node-types.js +39 -1
- package/dist/core/node-types.js.map +1 -1
- package/dist/core/transaction.js +5 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/document.js +1 -1
- package/dist/export/color.js +49 -6
- package/dist/export/color.js.map +1 -1
- package/dist/export/context.js +16 -9
- package/dist/export/context.js.map +1 -1
- package/dist/export/draw.js +6 -5
- package/dist/export/draw.js.map +1 -1
- package/dist/export/render.js +78 -0
- package/dist/export/render.js.map +1 -0
- package/dist/flow-editor.js.map +1 -1
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +757 -129
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/kit.js +1 -1
- package/dist/locale.js +102 -3
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +2 -1
- package/dist/types/collaboration/index.d.ts +32 -4
- package/dist/types/comments.d.ts +73 -0
- package/dist/types/components/flow-comments.vue.d.ts +35 -0
- package/dist/types/components/flow-port.vue.d.ts +8 -2
- package/dist/types/components/port-view.vue.d.ts +10 -0
- package/dist/types/components/port.d.ts +2 -2
- package/dist/types/context.d.ts +48 -1
- package/dist/types/core/extension.d.ts +9 -1
- package/dist/types/core/history.d.ts +10 -0
- package/dist/types/core/menu.d.ts +60 -0
- package/dist/types/core/model.d.ts +22 -0
- package/dist/types/core/node-types.d.ts +18 -2
- package/dist/types/core/transaction.d.ts +2 -1
- package/dist/types/export/color.d.ts +6 -1
- package/dist/types/export/render.d.ts +27 -0
- package/dist/types/flow-editor.vue.d.ts +11 -1
- package/dist/types/index.d.ts +36 -7
- package/dist/types/locale.d.ts +27 -1
- package/dist/types/whiteboard/board-node.vue.d.ts +5 -0
- package/dist/types/whiteboard/colors.d.ts +36 -0
- package/dist/types/whiteboard/index.d.ts +2 -2
- package/dist/types/whiteboard/model.d.ts +24 -14
- package/dist/types/whiteboard/state.d.ts +2 -0
- package/dist/types/whiteboard/toolbar.d.ts +46 -0
- package/dist/whiteboard/board-node.js.map +1 -1
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js +76 -20
- package/dist/whiteboard/board-node.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/whiteboard/colors.js +84 -0
- package/dist/whiteboard/colors.js.map +1 -0
- package/dist/whiteboard/connector.js +47 -13
- package/dist/whiteboard/connector.js.map +1 -1
- package/dist/whiteboard/draw.js +26 -9
- package/dist/whiteboard/draw.js.map +1 -1
- package/dist/whiteboard/index.js +2 -1
- package/dist/whiteboard/kit.js +65 -8
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/model.js +5 -31
- package/dist/whiteboard/model.js.map +1 -1
- package/dist/whiteboard/state.js +6 -1
- package/dist/whiteboard/state.js.map +1 -1
- package/dist/whiteboard/toolbar.js +296 -0
- package/dist/whiteboard/toolbar.js.map +1 -0
- package/dist/whiteboard/whiteboard-toolbar.js.map +1 -1
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js +14 -7
- package/dist/whiteboard/whiteboard-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useFlowEditor } from "../context.js";
|
|
2
2
|
import { DouFlowPort } from "../components/port.js";
|
|
3
|
+
import { isNoneColor, resolveFillColor, resolveStrokeColor, resolveTextColor } from "./colors.js";
|
|
3
4
|
import { fitInk, inkOutline, unpack } from "./ink.js";
|
|
4
5
|
import { anchorSides } from "./model.js";
|
|
5
6
|
import { boardState } from "./state.js";
|
|
@@ -8,7 +9,12 @@ import { Fragment, Teleport, computed, createBlock, createCommentVNode, createEl
|
|
|
8
9
|
import { ImageOffIcon } from "@dou-ui/icons";
|
|
9
10
|
// src/whiteboard/board-node.vue?vue&type=script&setup=true&lang.ts
|
|
10
11
|
var _hoisted_1 = ["viewBox"];
|
|
11
|
-
var _hoisted_2 = [
|
|
12
|
+
var _hoisted_2 = [
|
|
13
|
+
"x",
|
|
14
|
+
"y",
|
|
15
|
+
"width",
|
|
16
|
+
"height"
|
|
17
|
+
];
|
|
12
18
|
var _hoisted_3 = [
|
|
13
19
|
"cx",
|
|
14
20
|
"cy",
|
|
@@ -53,6 +59,33 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
53
59
|
const kind = computed(() => KINDS.find((k) => k === props.node.type) ?? "shape");
|
|
54
60
|
const shape = computed(() => props.data.shape ?? "rect");
|
|
55
61
|
const tone = computed(() => props.data.tone ?? (kind.value === "sticky" ? "warning" : "neutral"));
|
|
62
|
+
const borderless = computed(() => kind.value === "shape" && isNoneColor(props.data.stroke));
|
|
63
|
+
const transparentSticky = computed(() => kind.value === "sticky" && isNoneColor(props.data.fill));
|
|
64
|
+
const colorStyle = computed(() => {
|
|
65
|
+
const vars = {};
|
|
66
|
+
if (kind.value === "shape") {
|
|
67
|
+
const fill = resolveFillColor(props.data.fill, "shape");
|
|
68
|
+
if (fill) vars["--dou-whiteboard-shape-fill"] = fill;
|
|
69
|
+
if (!borderless.value) {
|
|
70
|
+
const stroke = resolveStrokeColor(props.data.stroke);
|
|
71
|
+
if (stroke && stroke !== "none") vars["--dou-whiteboard-shape-stroke"] = stroke;
|
|
72
|
+
}
|
|
73
|
+
const textColor = resolveTextColor(props.data.textColor);
|
|
74
|
+
if (textColor) vars["--dou-whiteboard-text-color"] = textColor;
|
|
75
|
+
} else if (kind.value === "sticky") {
|
|
76
|
+
const fill = resolveFillColor(props.data.fill, "sticky");
|
|
77
|
+
if (fill) vars["--dou-whiteboard-sticky-fill"] = fill === "none" ? "transparent" : fill;
|
|
78
|
+
const textColor = resolveTextColor(props.data.textColor);
|
|
79
|
+
if (textColor) vars["--dou-whiteboard-text-color"] = textColor;
|
|
80
|
+
} else if (kind.value === "text") {
|
|
81
|
+
const textColor = resolveTextColor(props.data.color);
|
|
82
|
+
if (textColor) vars["--dou-whiteboard-text-color"] = textColor;
|
|
83
|
+
} else if (kind.value === "ink") {
|
|
84
|
+
const stroke = resolveStrokeColor(props.data.color);
|
|
85
|
+
if (stroke && stroke !== "none") vars["--dou-whiteboard-ink-color"] = stroke;
|
|
86
|
+
}
|
|
87
|
+
return vars;
|
|
88
|
+
});
|
|
56
89
|
const writable = computed(() => [
|
|
57
90
|
"shape",
|
|
58
91
|
"sticky",
|
|
@@ -79,17 +112,27 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
79
112
|
const resizeHandles = computed(() => kind.value === "image" ? RESIZE_HANDLES.filter((h) => h.x && h.y) : kind.value === "text" ? RESIZE_HANDLES.filter((h) => h.x) : RESIZE_HANDLES);
|
|
80
113
|
const sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y));
|
|
81
114
|
const cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y));
|
|
115
|
+
const rect = computed(() => ctx.getNodeRect(props.node.id) ?? {
|
|
116
|
+
...props.node,
|
|
117
|
+
width: 0,
|
|
118
|
+
height: 0
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* The node's size, for the anchors and the corner handles to share the
|
|
122
|
+
* corners of a small node: each keeps short of the other.
|
|
123
|
+
*/
|
|
124
|
+
const sizeStyle = computed(() => ({
|
|
125
|
+
"--dou-whiteboard-frame-width": `${rect.value.width}px`,
|
|
126
|
+
"--dou-whiteboard-frame-height": `${rect.value.height}px`
|
|
127
|
+
}));
|
|
82
128
|
/** The node's box, turned with it, for the handles drawn above every node. */
|
|
83
129
|
const frameStyle = computed(() => {
|
|
84
|
-
const
|
|
85
|
-
...props.node,
|
|
86
|
-
width: 0,
|
|
87
|
-
height: 0
|
|
88
|
-
};
|
|
130
|
+
const box = rect.value;
|
|
89
131
|
return {
|
|
90
|
-
translate: `${
|
|
91
|
-
width: `${
|
|
92
|
-
height: `${
|
|
132
|
+
translate: `${box.x}px ${box.y}px`,
|
|
133
|
+
width: `${box.width}px`,
|
|
134
|
+
height: `${box.height}px`,
|
|
135
|
+
...sizeStyle.value,
|
|
93
136
|
rotate: rotation.value ? `${rotation.value}deg` : void 0
|
|
94
137
|
};
|
|
95
138
|
});
|
|
@@ -130,9 +173,10 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
130
173
|
w: props.node.width ?? 160,
|
|
131
174
|
h: props.node.height ?? 100
|
|
132
175
|
}));
|
|
176
|
+
const shapeInset = computed(() => borderless.value ? 0 : .75);
|
|
133
177
|
const diamond = computed(() => {
|
|
134
178
|
const { w, h } = shown.value;
|
|
135
|
-
const i = 1;
|
|
179
|
+
const i = borderless.value ? 0 : 1;
|
|
136
180
|
return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`;
|
|
137
181
|
});
|
|
138
182
|
const textEl = useTemplateRef("textEl");
|
|
@@ -206,10 +250,16 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
206
250
|
"is-turned": !!rotation.value,
|
|
207
251
|
"is-turning": unref(turning) !== null,
|
|
208
252
|
"is-selected": __props.selected,
|
|
209
|
-
"is-erasing": erasing.value
|
|
253
|
+
"is-erasing": erasing.value,
|
|
254
|
+
"is-borderless": borderless.value,
|
|
255
|
+
"is-transparent": transparentSticky.value
|
|
210
256
|
}
|
|
211
257
|
]]),
|
|
212
|
-
style: normalizeStyle(
|
|
258
|
+
style: normalizeStyle([
|
|
259
|
+
transform.value,
|
|
260
|
+
sizeStyle.value,
|
|
261
|
+
colorStyle.value
|
|
262
|
+
]),
|
|
213
263
|
onDblclick: withModifiers(edit, ["stop"])
|
|
214
264
|
}, [
|
|
215
265
|
kind.value === "shape" ? (openBlock(), createElementBlock("svg", {
|
|
@@ -219,17 +269,17 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
219
269
|
"aria-hidden": "true"
|
|
220
270
|
}, [shape.value === "rect" ? (openBlock(), createElementBlock("rect", {
|
|
221
271
|
key: 0,
|
|
222
|
-
x:
|
|
223
|
-
y:
|
|
224
|
-
width: Math.max(0, shown.value.w -
|
|
225
|
-
height: Math.max(0, shown.value.h -
|
|
272
|
+
x: shapeInset.value,
|
|
273
|
+
y: shapeInset.value,
|
|
274
|
+
width: Math.max(0, shown.value.w - shapeInset.value * 2),
|
|
275
|
+
height: Math.max(0, shown.value.h - shapeInset.value * 2),
|
|
226
276
|
rx: "8"
|
|
227
277
|
}, null, 8, _hoisted_2)) : shape.value === "ellipse" ? (openBlock(), createElementBlock("ellipse", {
|
|
228
278
|
key: 1,
|
|
229
279
|
cx: shown.value.w / 2,
|
|
230
280
|
cy: shown.value.h / 2,
|
|
231
|
-
rx: Math.max(0, shown.value.w / 2 - .
|
|
232
|
-
ry: Math.max(0, shown.value.h / 2 - .
|
|
281
|
+
rx: Math.max(0, shown.value.w / 2 - shapeInset.value),
|
|
282
|
+
ry: Math.max(0, shown.value.h / 2 - shapeInset.value)
|
|
233
283
|
}, null, 8, _hoisted_3)) : (openBlock(), createElementBlock("polygon", {
|
|
234
284
|
key: 2,
|
|
235
285
|
points: diamond.value
|
|
@@ -304,6 +354,7 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
304
354
|
"aria-hidden": "true"
|
|
305
355
|
}, [createElementVNode("span", {
|
|
306
356
|
class: "dou-whiteboard-node__turn",
|
|
357
|
+
"data-flow-handle": "",
|
|
307
358
|
"data-dou-nodrag": "",
|
|
308
359
|
onPointerdown: _cache[3] || (_cache[3] = (...args) => unref(startTurn) && unref(startTurn)(...args))
|
|
309
360
|
}, [..._cache[4] || (_cache[4] = [createElementVNode("span", {
|
|
@@ -312,16 +363,21 @@ var board_node_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defin
|
|
|
312
363
|
}, null, -1)])], 32), (openBlock(true), createElementBlock(Fragment, null, renderList(cornerHandles.value, (handle) => {
|
|
313
364
|
return openBlock(), createElementBlock("span", {
|
|
314
365
|
key: `${handle.x},${handle.y}`,
|
|
315
|
-
class:
|
|
366
|
+
class: normalizeClass([
|
|
367
|
+
"dou-whiteboard-node__corner",
|
|
368
|
+
handle.x < 0 ? "is-left" : "is-right",
|
|
369
|
+
handle.y < 0 ? "is-top" : "is-bottom"
|
|
370
|
+
]),
|
|
316
371
|
style: normalizeStyle({
|
|
317
372
|
left: place(handle.x),
|
|
318
373
|
top: place(handle.y),
|
|
319
374
|
cursor: cursorOf(handle)
|
|
320
375
|
}),
|
|
321
376
|
"data-handle": `${handle.x},${handle.y}`,
|
|
377
|
+
"data-flow-handle": "",
|
|
322
378
|
"data-dou-nodrag": "",
|
|
323
379
|
onPointerdown: ($event) => onResize($event, handle)
|
|
324
|
-
}, null,
|
|
380
|
+
}, null, 46, _hoisted_14);
|
|
325
381
|
}), 128))], 4)], 8, ["to", "disabled"]))], 64)) : createCommentVNode("", true)
|
|
326
382
|
], 38);
|
|
327
383
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-node.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_withModifiers","_createElementVNode","_createVNode","_createCommentVNode","_withDirectives","_vModelText","_toDisplayString","_Fragment","_renderList","_createBlock","_Teleport"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const rect = ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 }\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${rect.x}px ${rect.y}px`,\n width: `${rect.width}px`,\n height: `${rect.height}px`,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n },\n ]\"\n :style=\"transform\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n x=\"0.75\"\n y=\"0.75\"\n :width=\"Math.max(0, shown.w - 1.5)\"\n :height=\"Math.max(0, shown.h - 1.5)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - 0.75)\"\n :ry=\"Math.max(0, shown.h / 2 - 0.75)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span class=\"dou-whiteboard-node__turn\" data-dou-nodrag @pointerdown=\"startTurn\">\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n class=\"dou-whiteboard-node__corner\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BA,MAAM,QAAQ;EACd,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAE5B,MAAM,QAAyB;GAAC;GAAU;GAAQ;GAAO;EAAO;;EAEhE,MAAM,OAAO,eAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,K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,QAAQ,MAAM;;I,YAEvCJ,UAAA,GAAAc,YAkBWC,UAAA;KAlBA,IAAIZ,MAAA,KAAA,CAAK,CAAC,QAAQ;KAAQ,UAAQ,CAAGA,MAAA,KAAA,CAAK,CAAC,QAAQ;I,IAC5DG,mBAgBM,OAAA;KAhBD,OAAM;KAA8B,OAAKF,eAAE,WAAA,KAAU;KAAE,eAAY;I,IAItEE,mBAEO,QAAA;KAFD,OAAM;KAA4B,mBAAA;KAAiB,eAAW,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAH,MAAA,SAAA,KAAAA,MAAA,SAAA,CAAA,CAAA,GAAA,IAAA;I,kCACpEG,mBAA8D,QAAA;KAAxD,OAAM;KAA8B,qBAAA;I,uBAE5CN,UAAA,IAAA,GAAAC,mBAQEW,UAAA,MAAAC,WAPiB,cAAA,QAAV,WAAM;KADf,OAAAb,UAAA,GAAAC,mBAQE,QAAA;MANC,KAAG,GAAK,OAAO,EAAC,GAAI,OAAO;MAC5B,OAAM;MACL,OAAKG,eAAA;OAAA,MAAU,MAAM,OAAO,CAAC;OAAA,KAAQ,MAAM,OAAO,CAAC;OAAA,QAAW,SAAS,MAAM;MAAA,CAAA;MAC7E,eAAW,GAAK,OAAO,EAAC,GAAI,OAAO;MACpC,mBAAA;MACC,gBAAW,WAAE,SAAS,QAAQ,MAAM"}
|
|
1
|
+
{"version":3,"file":"board-node.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_withModifiers","_createElementVNode","_createVNode","_createCommentVNode","_withDirectives","_vModelText","_toDisplayString","_Fragment","_renderList","_createBlock","_Teleport"],"sources":["../../src/whiteboard/board-node.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageOffIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'\nimport { DouFlowPort } from '../components/port'\nimport { useFlowEditor } from '../context'\nimport type { NodeViewProps } from '../core/node-types'\nimport type { Tone } from 'dou-ui'\nimport {\n isNoneColor,\n resolveFillColor,\n resolveStrokeColor,\n resolveTextColor,\n type WhiteboardColor,\n type WhiteboardFill,\n type WhiteboardStroke,\n} from './colors'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport { anchorSides, type WhiteboardShape } from './model'\nimport { boardState } from './state'\nimport { RESIZE_HANDLES, useTransformHandles, type ResizeHandle } from './transform'\n\ntype BoardData = {\n [key: string]: unknown\n text?: string\n shape?: WhiteboardShape\n tone?: Tone\n fill?: WhiteboardFill\n stroke?: WhiteboardStroke\n textColor?: WhiteboardColor\n color?: WhiteboardColor\n rotation?: number\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n alt?: string\n}\n\ntype Kind = 'shape' | 'sticky' | 'text' | 'ink' | 'image'\n\nconst props = defineProps<NodeViewProps<BoardData>>()\nconst ctx = useFlowEditor()\nconst state = boardState(ctx)\n\nconst KINDS: readonly Kind[] = ['sticky', 'text', 'ink', 'image']\n/** What the node is: one of the shapes, a note, text, a pen stroke or an image. */\nconst kind = computed<Kind>(() => KINDS.find((k) => k === props.node.type) ?? 'shape')\nconst shape = computed<WhiteboardShape>(() => props.data.shape ?? 'rect')\nconst tone = computed<Tone>(\n () => props.data.tone ?? (kind.value === 'sticky' ? 'warning' : 'neutral'),\n)\nconst borderless = computed(() => kind.value === 'shape' && isNoneColor(props.data.stroke))\nconst transparentSticky = computed(() => kind.value === 'sticky' && isNoneColor(props.data.fill))\nconst colorStyle = computed(() => {\n const vars: Record<string, string> = {}\n if (kind.value === 'shape') {\n const fill = resolveFillColor(props.data.fill, 'shape')\n if (fill) vars['--dou-whiteboard-shape-fill'] = fill\n if (!borderless.value) {\n const stroke = resolveStrokeColor(props.data.stroke)\n if (stroke && stroke !== 'none') vars['--dou-whiteboard-shape-stroke'] = stroke\n }\n const textColor = resolveTextColor(props.data.textColor)\n if (textColor) vars['--dou-whiteboard-text-color'] = textColor\n } else if (kind.value === 'sticky') {\n const fill = resolveFillColor(props.data.fill, 'sticky')\n if (fill) vars['--dou-whiteboard-sticky-fill'] = fill === 'none' ? 'transparent' : fill\n const textColor = resolveTextColor(props.data.textColor)\n if (textColor) vars['--dou-whiteboard-text-color'] = textColor\n } else if (kind.value === 'text') {\n const textColor = resolveTextColor(props.data.color)\n if (textColor) vars['--dou-whiteboard-text-color'] = textColor\n } else if (kind.value === 'ink') {\n const stroke = resolveStrokeColor(props.data.color)\n if (stroke && stroke !== 'none') vars['--dou-whiteboard-ink-color'] = stroke\n }\n return vars\n})\nconst writable = computed(() => ['shape', 'sticky', 'text'].includes(kind.value))\n\nconst MIN: Record<Kind, number> = { shape: 24, sticky: 64, text: 40, ink: 8, image: 24 }\nconst rotation = computed(() => props.data.rotation ?? 0)\nconst { turning, startTurn, startResize } = useTransformHandles(\n ctx,\n toRef(props, 'node'),\n rotation,\n { width: MIN[kind.value], height: MIN[kind.value] },\n)\n/*\n * A handle being dragged shows the node changed through the editor, so\n * `node` and `data` already are what it is dragged to: the node's own frame,\n * its ports and its edges follow along with it.\n */\nconst transform = computed(() => (rotation.value ? { rotate: `${rotation.value}deg` } : undefined))\n/**\n * The resize handles: an image keeps its proportions, from its corners; text\n * only widens, so it has no top or bottom side; the rest has every corner\n * and side.\n */\nconst resizeHandles = computed(() =>\n kind.value === 'image'\n ? RESIZE_HANDLES.filter((h) => h.x && h.y)\n : kind.value === 'text'\n ? RESIZE_HANDLES.filter((h) => h.x)\n : RESIZE_HANDLES,\n)\nconst sideHandles = computed(() => resizeHandles.value.filter((h) => !h.x || !h.y))\nconst cornerHandles = computed(() => resizeHandles.value.filter((h) => h.x && h.y))\nconst rect = computed(\n () => ctx.getNodeRect(props.node.id) ?? { ...props.node, width: 0, height: 0 },\n)\n/**\n * The node's size, for the anchors and the corner handles to share the\n * corners of a small node: each keeps short of the other.\n */\nconst sizeStyle = computed(() => ({\n '--dou-whiteboard-frame-width': `${rect.value.width}px`,\n '--dou-whiteboard-frame-height': `${rect.value.height}px`,\n}))\n/** The node's box, turned with it, for the handles drawn above every node. */\nconst frameStyle = computed(() => {\n const box = rect.value\n return {\n // `translate`, not `transform`: it applies before `rotate`, so the box\n // turns about its own centre and its offset is not turned with it\n translate: `${box.x}px ${box.y}px`,\n width: `${box.width}px`,\n height: `${box.height}px`,\n ...sizeStyle.value,\n rotate: rotation.value ? `${rotation.value}deg` : undefined,\n }\n})\nconst CURSORS = ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'] as const\n/** The resize cursor along a handle's way out, turned with the node. */\nfunction cursorOf(handle: ResizeHandle) {\n // text only widens, from a corner too\n if (kind.value === 'text') handle = { x: handle.x, y: 0 }\n const degrees = (Math.atan2(handle.y, handle.x) * 180) / Math.PI + rotation.value\n return CURSORS[((Math.round(degrees / 45) % 4) + 4) % 4]\n}\nfunction onResize(event: PointerEvent, handle: ResizeHandle) {\n startResize(event, handle, {\n keepRatio: kind.value === 'image',\n widthOnly: kind.value === 'text',\n })\n}\n/** Where a handle sits on the box: `-1` is the start, `1` the end. */\nconst place = (v: -1 | 0 | 1) => `${(v + 1) * 50}%`\n\n/** Handles show on the one selected node, while the select tool is in hand. */\nconst handles = computed(\n () =>\n props.selected &&\n !props.readonly &&\n !editing.value &&\n state.tool.value === 'select' &&\n ctx.selection.value.nodes.length === 1,\n)\n\n/** The stroke fitted to the box shown, so stretching it keeps its thickness. */\nconst ink = computed(() => {\n const { points, box: inkBox } = props.data\n if (kind.value !== 'ink' || !points || !inkBox) return ''\n const size = props.data.size ?? INK_SIZE\n return inkOutline(fitInk(unpack(points), inkBox, shown.value.w, shown.value.h, size), size)\n})\nconst erasing = computed(() => state.erasing.value.has(props.node.id))\n\n// drawn in the node's own units, half the 1.5px stroke in from the edge (0 when borderless)\nconst shown = computed(() => ({ w: props.node.width ?? 160, h: props.node.height ?? 100 }))\nconst shapeInset = computed(() => (borderless.value ? 0 : 0.75))\nconst diamond = computed(() => {\n const { w, h } = shown.value\n const i = borderless.value ? 0 : 1\n return `${w / 2},${i} ${w - i},${h / 2} ${w / 2},${h - i} ${i},${h / 2}`\n})\n\n// Whole lines that fit, the last one ending in an ellipsis, as an export draws them.\nconst textEl = useTemplateRef<HTMLElement>('textEl')\nconst textMetrics = ref<{ line: number; padding: number } | null>(null)\nwatch(\n textEl,\n (el) => {\n if (!el) return\n const s = getComputedStyle(el)\n const line = Number.parseFloat(s.lineHeight)\n if (!line) return\n const padding = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom)\n textMetrics.value = { line, padding: padding || 0 }\n },\n { flush: 'post' },\n)\nconst textStyle = computed(() => {\n const m = textMetrics.value\n if (!m || kind.value === 'text') return undefined\n const height = shown.value.h\n return { '-webkit-line-clamp': Math.max(1, Math.floor((height - m.padding + 0.5) / m.line)) }\n})\n\n// An image that can't be loaded: a plain box with a sign, as an export draws it.\nconst broken = ref(false)\nwatch(\n () => props.data.src,\n () => (broken.value = false),\n)\n\nconst editing = computed(() => state.editing.value === props.node.id)\nconst draft = ref('')\nconst field = useTemplateRef<HTMLTextAreaElement>('field')\n\nwatch(\n editing,\n (on) => {\n if (!on) return\n draft.value = props.data.text ?? ''\n void nextTick(() => {\n fit()\n field.value?.focus()\n field.value?.select()\n })\n },\n { immediate: true },\n)\n\n// browsers without `field-sizing` grow the field by hand\nfunction fit() {\n const el = field.value\n if (!el || CSS.supports?.('field-sizing', 'content')) return\n el.style.height = 'auto'\n el.style.height = `${el.scrollHeight}px`\n}\nwatch(draft, () => void nextTick(fit))\n\nfunction edit() {\n if (props.readonly || !writable.value) return\n state.editing.value = props.node.id\n}\n\nfunction finish() {\n if (!editing.value) return\n state.editing.value = null\n const text = draft.value.replace(/\\s+$/, '')\n // text with nothing written in it is nothing at all\n if (!text && kind.value === 'text') ctx.transact((tr) => tr.removeNode(props.node.id))\n else if (text !== (props.data.text ?? '')) props.updateData({ text: text || undefined })\n // back to the canvas, so the keys go on working\n ctx.root.value?.focus({ preventScroll: true })\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (event.isComposing) return\n // Escape, or mod+Enter, puts the text down; Enter is a new line\n if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey))) {\n event.preventDefault()\n event.stopPropagation()\n finish()\n }\n}\n</script>\n\n<template>\n <div\n class=\"dou-whiteboard-node\"\n :class=\"[\n `is-${kind}`,\n kind === 'shape' && `is-${shape}`,\n `is-${tone}`,\n {\n 'is-editing': editing,\n 'is-turned': !!rotation,\n 'is-turning': turning !== null,\n 'is-selected': selected,\n 'is-erasing': erasing,\n 'is-borderless': borderless,\n 'is-transparent': transparentSticky,\n },\n ]\"\n :style=\"[transform, sizeStyle, colorStyle]\"\n @dblclick.stop=\"edit\"\n >\n <svg\n v-if=\"kind === 'shape'\"\n class=\"dou-whiteboard-node__shape\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <rect\n v-if=\"shape === 'rect'\"\n :x=\"shapeInset\"\n :y=\"shapeInset\"\n :width=\"Math.max(0, shown.w - shapeInset * 2)\"\n :height=\"Math.max(0, shown.h - shapeInset * 2)\"\n rx=\"8\"\n />\n <ellipse\n v-else-if=\"shape === 'ellipse'\"\n :cx=\"shown.w / 2\"\n :cy=\"shown.h / 2\"\n :rx=\"Math.max(0, shown.w / 2 - shapeInset)\"\n :ry=\"Math.max(0, shown.h / 2 - shapeInset)\"\n />\n <polygon v-else :points=\"diamond\" />\n </svg>\n <svg\n v-else-if=\"kind === 'ink' && data.box\"\n class=\"dou-whiteboard-node__ink\"\n :viewBox=\"`0 0 ${shown.w} ${shown.h}`\"\n aria-hidden=\"true\"\n >\n <path class=\"dou-whiteboard-node__ink-hit\" :d=\"ink\" />\n <path :d=\"ink\" />\n </svg>\n <div\n v-else-if=\"kind === 'image' && broken\"\n class=\"dou-whiteboard-node__image is-broken\"\n role=\"img\"\n :aria-label=\"data.alt || undefined\"\n >\n <ImageOffIcon />\n </div>\n <img\n v-else-if=\"kind === 'image'\"\n class=\"dou-whiteboard-node__image\"\n :src=\"data.src\"\n :alt=\"data.alt ?? ''\"\n draggable=\"false\"\n @error=\"broken = true\"\n />\n <textarea\n v-if=\"editing\"\n ref=\"field\"\n v-model=\"draft\"\n class=\"dou-whiteboard-node__text dou-whiteboard-node__field\"\n :aria-label=\"ctx.messages.value.board.editText\"\n @keydown=\"onKeydown\"\n @blur=\"finish\"\n @pointerdown.stop\n />\n <div\n v-else-if=\"writable\"\n ref=\"textEl\"\n class=\"dou-whiteboard-node__text\"\n :style=\"textStyle\"\n v-text=\"data.text\"\n />\n <div v-if=\"kind !== 'ink'\" class=\"dou-whiteboard-node__anchors\">\n <template v-for=\"side in anchorSides\" :key=\"side\">\n <DouFlowPort :id=\"`${side}-in`\" class=\"dou-whiteboard-node__anchor\" />\n <DouFlowPort :id=\"side\" class=\"dou-whiteboard-node__anchor\" />\n </template>\n </div>\n <template v-if=\"handles\">\n <!-- the sides stay on the node, under its anchors; the turn and the\n corners go above every node, so a neighbour never covers them -->\n <span\n v-for=\"handle in sideHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"['dou-whiteboard-node__side', handle.x ? 'is-x' : 'is-y']\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-dou-nodrag\n aria-hidden=\"true\"\n @pointerdown=\"onResize($event, handle)\"\n />\n <Teleport :to=\"state.handles.value\" :disabled=\"!state.handles.value\">\n <div class=\"dou-whiteboard-node__frame\" :style=\"frameStyle\" aria-hidden=\"true\">\n <!-- data-flow-overlay on its target: the selection's toolbar keeps\n clear of where a finger can take it, when it floats below the\n node or the node is turned upside down -->\n <span\n class=\"dou-whiteboard-node__turn\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"startTurn\"\n >\n <span class=\"dou-whiteboard-node__target\" data-flow-overlay />\n </span>\n <span\n v-for=\"handle in cornerHandles\"\n :key=\"`${handle.x},${handle.y}`\"\n :class=\"[\n 'dou-whiteboard-node__corner',\n handle.x < 0 ? 'is-left' : 'is-right',\n handle.y < 0 ? 'is-top' : 'is-bottom',\n ]\"\n :style=\"{ left: place(handle.x), top: place(handle.y), cursor: cursorOf(handle) }\"\n :data-handle=\"`${handle.x},${handle.y}`\"\n data-flow-handle\n data-dou-nodrag\n @pointerdown=\"onResize($event, handle)\"\n />\n </div>\n </Teleport>\n </template>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCA,MAAM,QAAQ;EACd,MAAM,MAAM,cAAc;EAC1B,MAAM,QAAQ,WAAW,GAAG;EAE5B,MAAM,QAAyB;GAAC;GAAU;GAAQ;GAAO;EAAO;;EAEhE,MAAM,OAAO,eAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,KAAK,OAAO;EACrF,MAAM,QAAQ,eAAgC,MAAM,KAAK,SAAS,MAAM;EACxE,MAAM,OAAO,eACL,MAAM,KAAK,SAAS,KAAK,UAAU,WAAW,YAAY,UAClE;EACA,MAAM,aAAa,eAAe,KAAK,UAAU,WAAW,YAAY,MAAM,KAAK,MAAM,CAAC;EAC1F,MAAM,oBAAoB,eAAe,KAAK,UAAU,YAAY,YAAY,MAAM,KAAK,IAAI,CAAC;EAChG,MAAM,aAAa,eAAe;GAChC,MAAM,OAA+B,CAAC;GACtC,IAAI,KAAK,UAAU,SAAS;IAC1B,MAAM,OAAO,iBAAiB,MAAM,KAAK,MAAM,OAAO;IACtD,IAAI,MAAM,KAAK,iCAAiC;IAChD,IAAI,CAAC,WAAW,OAAO;KACrB,MAAM,SAAS,mBAAmB,MAAM,KAAK,MAAM;KACnD,IAAI,UAAU,WAAW,QAAQ,KAAK,mCAAmC;IAC3E;IACA,MAAM,YAAY,iBAAiB,MAAM,KAAK,SAAS;IACvD,IAAI,WAAW,KAAK,iCAAiC;GACvD,OAAO,IAAI,KAAK,UAAU,UAAU;IAClC,MAAM,OAAO,iBAAiB,MAAM,KAAK,MAAM,QAAQ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AO;MAC3B,OAAKC,eAAA;;OAA+D,OAAO,IAAC,IAAA,YAAA;OAA6C,OAAO,IAAC,IAAA,WAAA;;MAKjI,OAAKE,eAAA;OAAA,MAAU,MAAM,OAAO,CAAC;OAAA,KAAQ,MAAM,OAAO,CAAC;OAAA,QAAW,SAAS,MAAM;MAAA,CAAA;MAC7E,eAAW,GAAK,OAAO,EAAC,GAAI,OAAO;MACpC,oBAAA;MACA,mBAAA;MACC,gBAAW,WAAE,SAAS,QAAQ,MAAM"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isSafeCssColor } from "../export/color.js";
|
|
2
|
+
// src/whiteboard/colors.ts
|
|
3
|
+
/**
|
|
4
|
+
* The built-in whiteboard palette names; their values follow the light or dark
|
|
5
|
+
* color mode for readable contrast on the board.
|
|
6
|
+
*/
|
|
7
|
+
var whiteboardColors = [
|
|
8
|
+
"gray",
|
|
9
|
+
"red",
|
|
10
|
+
"orange",
|
|
11
|
+
"yellow",
|
|
12
|
+
"green",
|
|
13
|
+
"blue",
|
|
14
|
+
"purple",
|
|
15
|
+
"pink"
|
|
16
|
+
];
|
|
17
|
+
var TONES = [
|
|
18
|
+
"neutral",
|
|
19
|
+
"primary",
|
|
20
|
+
"success",
|
|
21
|
+
"warning",
|
|
22
|
+
"danger"
|
|
23
|
+
];
|
|
24
|
+
var isWhiteboardColor = (value) => typeof value === "string" && whiteboardColors.includes(value);
|
|
25
|
+
var isToneColor = (value) => typeof value === "string" && TONES.includes(value);
|
|
26
|
+
/** Whether a color value explicitly disables painting (`'none'` or `'transparent'`). */
|
|
27
|
+
var isNoneColor = (value) => typeof value === "string" && /^(none|transparent)$/i.test(value.trim());
|
|
28
|
+
/** Trims a color value; maps `'none'` / `'transparent'` to `'none'`, empty strings to `undefined`. */
|
|
29
|
+
function normalizeColorValue(value) {
|
|
30
|
+
if (typeof value !== "string") return void 0;
|
|
31
|
+
const trimmed = value.trim();
|
|
32
|
+
if (!trimmed) return void 0;
|
|
33
|
+
return isNoneColor(trimmed) ? "none" : trimmed;
|
|
34
|
+
}
|
|
35
|
+
/** Like `normalizeColorValue`, dropping `'none'`/`'transparent'` for channels that stay painted. */
|
|
36
|
+
function normalizeOpaqueColor(value) {
|
|
37
|
+
const normalized = normalizeColorValue(value);
|
|
38
|
+
return normalized === "none" ? void 0 : normalized;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Turns a fill color into a CSS / SVG paint value.
|
|
42
|
+
* Returns `'none'` for transparent fills (use `'transparent'` for CSS `background-color`).
|
|
43
|
+
*/
|
|
44
|
+
function resolveFillColor(value, kind = "shape") {
|
|
45
|
+
const color = normalizeColorValue(value);
|
|
46
|
+
if (!color) return void 0;
|
|
47
|
+
if (color === "none") return "none";
|
|
48
|
+
if (isWhiteboardColor(color)) return `var(--dou-whiteboard-fill-${color})`;
|
|
49
|
+
if (isToneColor(color)) {
|
|
50
|
+
if (kind === "sticky") return `color-mix(in oklab, var(--dou-color-${color}) 20%, var(--dou-color-bg-surface))`;
|
|
51
|
+
if (color === "neutral") return "var(--dou-color-bg-surface)";
|
|
52
|
+
return `color-mix(in oklab, var(--dou-color-${color}) 10%, var(--dou-color-bg-surface))`;
|
|
53
|
+
}
|
|
54
|
+
return isSafeCssColor(color) ? color : void 0;
|
|
55
|
+
}
|
|
56
|
+
/** Turns a border, connector or ink color into a CSS / SVG stroke/fill paint value. */
|
|
57
|
+
function resolveStrokeColor(value) {
|
|
58
|
+
const color = normalizeColorValue(value);
|
|
59
|
+
if (!color) return void 0;
|
|
60
|
+
if (color === "none") return "none";
|
|
61
|
+
if (isWhiteboardColor(color)) return `var(--dou-whiteboard-color-${color})`;
|
|
62
|
+
if (isToneColor(color)) return color === "neutral" ? "var(--dou-flow-whiteboard-ink)" : `var(--dou-color-${color})`;
|
|
63
|
+
return isSafeCssColor(color) ? color : void 0;
|
|
64
|
+
}
|
|
65
|
+
/** Turns a text color into a CSS / SVG color value. */
|
|
66
|
+
function resolveTextColor(value) {
|
|
67
|
+
const color = normalizeOpaqueColor(value);
|
|
68
|
+
if (!color) return void 0;
|
|
69
|
+
if (isWhiteboardColor(color)) return `var(--dou-whiteboard-color-${color})`;
|
|
70
|
+
if (isToneColor(color)) return color === "neutral" ? "var(--dou-color-text)" : `var(--dou-color-${color}-text)`;
|
|
71
|
+
return isSafeCssColor(color) ? color : void 0;
|
|
72
|
+
}
|
|
73
|
+
/** Human-readable name for a color value in tooltips and screen-reader announcements. */
|
|
74
|
+
function colorDisplayName(value, t, noneLabel) {
|
|
75
|
+
if (value === null) return t.mixed;
|
|
76
|
+
if (value === void 0) return t.colorDefault;
|
|
77
|
+
if (value === "none") return noneLabel ?? t.borderNone;
|
|
78
|
+
if (isWhiteboardColor(value)) return t.colors[value];
|
|
79
|
+
if (isToneColor(value)) return t.tones[value];
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
export { colorDisplayName, isNoneColor, isToneColor, isWhiteboardColor, normalizeColorValue, normalizeOpaqueColor, resolveFillColor, resolveStrokeColor, resolveTextColor, whiteboardColors };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","names":[],"sources":["../../src/whiteboard/colors.ts"],"sourcesContent":["import type { Tone } from 'dou-ui'\nimport { isSafeCssColor } from '../export/color'\nimport type { FlowMessages } from '../locale'\n\n/**\n * The built-in whiteboard palette names; their values follow the light or dark\n * color mode for readable contrast on the board.\n */\nexport const whiteboardColors = [\n 'gray',\n 'red',\n 'orange',\n 'yellow',\n 'green',\n 'blue',\n 'purple',\n 'pink',\n] as const\n\nexport type WhiteboardPaletteColor = (typeof whiteboardColors)[number]\n\n/**\n * A color on the whiteboard: a palette name (adapts to light and dark mode),\n * a DouUI `Tone`, or any CSS color string (such as `#3b6ea8` or `rgba(...)`).\n */\nexport type WhiteboardColor = WhiteboardPaletteColor | Tone | (string & {})\n\n/** A background fill color, or `'none'` / `'transparent'` for a transparent fill. */\nexport type WhiteboardFill = WhiteboardColor | 'none' | 'transparent'\n\n/** A border color, or `'none'` (or `'transparent'`) for a borderless shape. */\nexport type WhiteboardStroke = WhiteboardColor | 'none'\n\nconst TONES: readonly Tone[] = ['neutral', 'primary', 'success', 'warning', 'danger']\n\nexport const isWhiteboardColor = (value: unknown): value is WhiteboardPaletteColor =>\n typeof value === 'string' && (whiteboardColors as readonly string[]).includes(value)\n\nexport const isToneColor = (value: unknown): value is Tone =>\n typeof value === 'string' && (TONES as readonly string[]).includes(value)\n\n/** Whether a color value explicitly disables painting (`'none'` or `'transparent'`). */\nexport const isNoneColor = (value: unknown): boolean =>\n typeof value === 'string' && /^(none|transparent)$/i.test(value.trim())\n\n/** Trims a color value; maps `'none'` / `'transparent'` to `'none'`, empty strings to `undefined`. */\nexport function normalizeColorValue(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const trimmed = value.trim()\n if (!trimmed) return undefined\n return isNoneColor(trimmed) ? 'none' : trimmed\n}\n\n/** Like `normalizeColorValue`, dropping `'none'`/`'transparent'` for channels that stay painted. */\nexport function normalizeOpaqueColor(value: unknown): string | undefined {\n const normalized = normalizeColorValue(value)\n return normalized === 'none' ? undefined : normalized\n}\n\n/**\n * Turns a fill color into a CSS / SVG paint value.\n * Returns `'none'` for transparent fills (use `'transparent'` for CSS `background-color`).\n */\nexport function resolveFillColor(\n value: WhiteboardFill | undefined,\n kind: 'shape' | 'sticky' = 'shape',\n): string | undefined {\n const color = normalizeColorValue(value)\n if (!color) return undefined\n if (color === 'none') return 'none'\n if (isWhiteboardColor(color)) return `var(--dou-whiteboard-fill-${color})`\n if (isToneColor(color)) {\n if (kind === 'sticky')\n return `color-mix(in oklab, var(--dou-color-${color}) 20%, var(--dou-color-bg-surface))`\n if (color === 'neutral') return 'var(--dou-color-bg-surface)'\n return `color-mix(in oklab, var(--dou-color-${color}) 10%, var(--dou-color-bg-surface))`\n }\n return isSafeCssColor(color) ? color : undefined\n}\n\n/** Turns a border, connector or ink color into a CSS / SVG stroke/fill paint value. */\nexport function resolveStrokeColor(value: WhiteboardStroke | undefined): string | undefined {\n const color = normalizeColorValue(value)\n if (!color) return undefined\n if (color === 'none') return 'none'\n if (isWhiteboardColor(color)) return `var(--dou-whiteboard-color-${color})`\n if (isToneColor(color))\n return color === 'neutral' ? 'var(--dou-flow-whiteboard-ink)' : `var(--dou-color-${color})`\n return isSafeCssColor(color) ? color : undefined\n}\n\n/** Turns a text color into a CSS / SVG color value. */\nexport function resolveTextColor(value: WhiteboardColor | undefined): string | undefined {\n const color = normalizeOpaqueColor(value)\n if (!color) return undefined\n if (isWhiteboardColor(color)) return `var(--dou-whiteboard-color-${color})`\n if (isToneColor(color))\n return color === 'neutral' ? 'var(--dou-color-text)' : `var(--dou-color-${color}-text)`\n return isSafeCssColor(color) ? color : undefined\n}\n\n/** Human-readable name for a color value in tooltips and screen-reader announcements. */\nexport function colorDisplayName(\n value: string | null | undefined,\n t: FlowMessages['board'],\n noneLabel?: string,\n): string {\n if (value === null) return t.mixed\n if (value === undefined) return t.colorDefault\n if (value === 'none') return noneLabel ?? t.borderNone\n if (isWhiteboardColor(value)) return t.colors[value]\n if (isToneColor(value)) return t.tones[value]\n return value\n}\n"],"mappings":";;;;;;AAQA,IAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAgBA,IAAM,QAAyB;CAAC;CAAW;CAAW;CAAW;CAAW;AAAQ;AAEpF,IAAa,qBAAqB,UAChC,OAAO,UAAU,YAAa,iBAAuC,SAAS,KAAK;AAErF,IAAa,eAAe,UAC1B,OAAO,UAAU,YAAa,MAA4B,SAAS,KAAK;;AAG1E,IAAa,eAAe,UAC1B,OAAO,UAAU,YAAY,wBAAwB,KAAK,MAAM,KAAK,CAAC;;AAGxE,SAAgB,oBAAoB,OAAoC;CACtE,IAAI,OAAO,UAAU,UAAU,OAAO,KAAA;CACtC,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,CAAC,SAAS,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AAE;CAClC,IAAI,UAAU,QAAQ,OAAO,aAAa,EAAE;CAC5C,IAAI,kBAAkB,KAAK,GAAG,OAAO,EAAE,OAAO;CAC9C,IAAI,YAAY,KAAK,GAAG,OAAO,EAAE,MAAM;CACvC,OAAO;AACT"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { bezierEdge, defineEdgeType, stepEdge } from "../core/edge-types.js";
|
|
2
1
|
import { format } from "../locale.js";
|
|
3
|
-
import {
|
|
2
|
+
import { bezierEdge, defineEdgeType, stepEdge, straightEdge } from "../core/edge-types.js";
|
|
3
|
+
import { normalizeOpaqueColor, resolveStrokeColor } from "./colors.js";
|
|
4
|
+
import { cleanData, colorToolbarItem, sameData, sharedValue } from "./toolbar.js";
|
|
5
|
+
import { ArrowEndsIcon, ArrowLeftRightIcon, ArrowRightIcon, ConnectorCurveIcon, ConnectorElbowIcon, ConnectorStraightIcon, LineDashDotIcon, LineDashedIcon, LineDottedIcon, LineSolidIcon, LineStyleIcon, MinusIcon, PaletteIcon, RouteIcon } from "@dou-ui/icons";
|
|
4
6
|
// src/whiteboard/connector.ts
|
|
5
7
|
var ARROW = {
|
|
6
8
|
length: 10,
|
|
@@ -59,17 +61,12 @@ var connectorEdge = defineEdgeType({
|
|
|
59
61
|
const data = edge?.data ?? {};
|
|
60
62
|
const route = data.route ?? "straight";
|
|
61
63
|
const straight = route === "straight";
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
label: {
|
|
65
|
-
x: (source.x + target.x) / 2,
|
|
66
|
-
y: (source.y + target.y) / 2
|
|
67
|
-
}
|
|
68
|
-
} : (route === "elbow" ? stepEdge : bezierEdge).route(source, target, edge);
|
|
64
|
+
const points = edge?.points ?? [];
|
|
65
|
+
const base = straight ? straightEdge.route(source, target, edge) : (route === "elbow" ? stepEdge : bezierEdge).route(source, target, edge);
|
|
69
66
|
const arrow = data.arrow ?? "end";
|
|
70
67
|
let marks = "";
|
|
71
|
-
if (arrow !== "none") marks += arrowhead(target, arrival(target, source, straight));
|
|
72
|
-
if (arrow === "both") marks += arrowhead(source, arrival(source, target, straight));
|
|
68
|
+
if (arrow !== "none") marks += arrowhead(target, arrival(target, points.at(-1) ?? source, straight));
|
|
69
|
+
if (arrow === "both") marks += arrowhead(source, arrival(source, points[0] ?? target, straight));
|
|
73
70
|
return {
|
|
74
71
|
...base,
|
|
75
72
|
marks: marks || void 0
|
|
@@ -77,7 +74,13 @@ var connectorEdge = defineEdgeType({
|
|
|
77
74
|
},
|
|
78
75
|
style(edge) {
|
|
79
76
|
const dash = DASHES[edge.data?.dash ?? "solid"];
|
|
80
|
-
|
|
77
|
+
const color = resolveStrokeColor(edge.data?.color);
|
|
78
|
+
const stroke = color && color !== "none" ? color : void 0;
|
|
79
|
+
if (!dash && !stroke) return void 0;
|
|
80
|
+
const out = {};
|
|
81
|
+
if (dash) out.strokeDasharray = dash;
|
|
82
|
+
if (stroke) out["--dou-flow-connector-color"] = stroke;
|
|
83
|
+
return out;
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
86
|
var ROUTES = [
|
|
@@ -128,6 +131,10 @@ var ARROWS = [
|
|
|
128
131
|
];
|
|
129
132
|
var data = (edge) => edge.data ?? {};
|
|
130
133
|
var isConnector = (edge) => (edge.type ?? "connector") === "connector";
|
|
134
|
+
var effectiveConnectorColor = (edge) => {
|
|
135
|
+
const raw = normalizeOpaqueColor(data(edge).color);
|
|
136
|
+
return raw && resolveStrokeColor(raw) ? raw : void 0;
|
|
137
|
+
};
|
|
131
138
|
/** Route, dash and arrow choices over the selected connectors. */
|
|
132
139
|
function connectorToolbar(ctx, edges) {
|
|
133
140
|
if (!edges.every(isConnector)) return [];
|
|
@@ -160,6 +167,32 @@ function connectorToolbar(ctx, edges) {
|
|
|
160
167
|
}))
|
|
161
168
|
};
|
|
162
169
|
}
|
|
170
|
+
const colorValue = sharedValue(edges.map(effectiveConnectorColor));
|
|
171
|
+
const colorSwatch = colorValue ? resolveStrokeColor(colorValue) : void 0;
|
|
172
|
+
const targetKey = edges.map((edge) => edge.id).sort().join(",");
|
|
173
|
+
const colorItem = colorToolbarItem({
|
|
174
|
+
ctx,
|
|
175
|
+
key: "connector-color",
|
|
176
|
+
scope: `connector-color:e:${targetKey}`,
|
|
177
|
+
kind: "stroke",
|
|
178
|
+
icon: PaletteIcon,
|
|
179
|
+
value: colorValue,
|
|
180
|
+
swatch: colorSwatch === "none" ? void 0 : colorSwatch,
|
|
181
|
+
labelOf: t.lineColorOf,
|
|
182
|
+
announceSet: t.lineColorSet,
|
|
183
|
+
apply(next, meta) {
|
|
184
|
+
const color = next === "none" ? void 0 : next;
|
|
185
|
+
ctx.transact((tr) => {
|
|
186
|
+
for (const edge of edges) {
|
|
187
|
+
const current = tr.getEdge(edge.id);
|
|
188
|
+
if (!current || effectiveConnectorColor(current) === color) continue;
|
|
189
|
+
const patched = cleanData(current.data, { color });
|
|
190
|
+
const nextData = Object.keys(patched).length ? patched : void 0;
|
|
191
|
+
if (!sameData(current.data, nextData)) tr.updateEdge(current.id, { data: nextData });
|
|
192
|
+
}
|
|
193
|
+
}, meta);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
163
196
|
return [
|
|
164
197
|
choice("route", "straight", ROUTES, t.routes, {
|
|
165
198
|
of: t.routeOf,
|
|
@@ -172,7 +205,8 @@ function connectorToolbar(ctx, edges) {
|
|
|
172
205
|
choice("arrow", "end", ARROWS, t.arrows, {
|
|
173
206
|
of: t.arrowOf,
|
|
174
207
|
set: t.arrowSet
|
|
175
|
-
}, ArrowEndsIcon)
|
|
208
|
+
}, ArrowEndsIcon),
|
|
209
|
+
colorItem
|
|
176
210
|
];
|
|
177
211
|
}
|
|
178
212
|
export { connectorEdge, connectorToolbar };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.js","names":[],"sources":["../../src/whiteboard/connector.ts"],"sourcesContent":["import {\n ArrowEndsIcon,\n ArrowLeftRightIcon,\n ArrowRightIcon,\n ConnectorCurveIcon,\n ConnectorElbowIcon,\n ConnectorStraightIcon,\n LineDashDotIcon,\n LineDashedIcon,\n LineDottedIcon,\n LineSolidIcon,\n LineStyleIcon,\n MinusIcon,\n RouteIcon,\n} from '@dou-ui/icons'\nimport type { Component } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport { bezierEdge, defineEdgeType, stepEdge, type EdgeAnchor } from '../core/edge-types'\nimport type { FlowToolbarItem } from '../core/menu'\nimport type { FlowEdge, Point, PortSide } from '../core/model'\nimport { format } from '../locale'\nimport type {\n WhiteboardArrow,\n WhiteboardConnectorData,\n WhiteboardDash,\n WhiteboardRoute,\n} from './model'\n\nconst ARROW = { length: 10, spread: 0.45 }\nconst r2 = (v: number) => Math.round(v * 100) / 100\nconst p = (pt: Point) => `${r2(pt.x)} ${r2(pt.y)}`\n\n/** Out of a side, away from the node. */\nconst outward: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\n/** An open arrowhead with its tip at `tip`, pointing along `angle`. */\nfunction arrowhead(tip: Point, angle: number) {\n const wing = (spread: number) => ({\n x: tip.x - ARROW.length * Math.cos(angle + spread),\n y: tip.y - ARROW.length * Math.sin(angle + spread),\n })\n return `M${p(wing(ARROW.spread))}L${p(tip)}L${p(wing(-ARROW.spread))}`\n}\n\n/** The way a run arrives at `end`: straight from `from`, or into the side it faces. */\nfunction arrival(end: EdgeAnchor, from: Point, straight: boolean) {\n if (straight) return Math.atan2(end.y - from.y, end.x - from.x)\n const out = outward[end.side]\n return Math.atan2(-out.y, -out.x)\n}\n\n/** Dash patterns, in px of a 1.5px stroke with round ends: a 0 dash is a dot. */\nconst DASHES: Record<WhiteboardDash, string | undefined> = {\n solid: undefined,\n dashed: '6 5',\n dotted: '0 4',\n 'dash-dot': '8 4 0 4',\n}\n\n/**\n * The whiteboard's line: straight, with right-angled turns or curved\n * (`data.route`), solid or dashed (`data.dash`), with arrowheads at the end,\n * both ends or neither (`data.arrow`).\n */\nexport const connectorEdge = defineEdgeType<WhiteboardConnectorData>({\n type: 'connector',\n route(source, target, edge) {\n const data = edge?.data ?? {}\n const route = data.route ?? 'straight'\n const straight = route === 'straight'\n const base = straight\n ? {\n path: `M${p(source)}L${p(target)}`,\n label: { x: (source.x + target.x) / 2, y: (source.y + target.y) / 2 },\n }\n : (route === 'elbow' ? stepEdge : bezierEdge).route(source, target, edge as FlowEdge)\n const arrow = data.arrow ?? 'end'\n let marks = ''\n if (arrow !== 'none') marks += arrowhead(target, arrival(target, source, straight))\n if (arrow === 'both') marks += arrowhead(source, arrival(source, target, straight))\n return { ...base, marks: marks || undefined }\n },\n style(edge) {\n const dash = DASHES[edge.data?.dash ?? 'solid']\n return dash ? { strokeDasharray: dash } : undefined\n },\n})\n\nconst ROUTES: { value: WhiteboardRoute; icon: Component }[] = [\n { value: 'straight', icon: ConnectorStraightIcon },\n { value: 'elbow', icon: ConnectorElbowIcon },\n { value: 'curve', icon: ConnectorCurveIcon },\n]\nconst DASH_CHOICES: { value: WhiteboardDash; icon: Component }[] = [\n { value: 'solid', icon: LineSolidIcon },\n { value: 'dashed', icon: LineDashedIcon },\n { value: 'dotted', icon: LineDottedIcon },\n { value: 'dash-dot', icon: LineDashDotIcon },\n]\nconst ARROWS: { value: WhiteboardArrow; icon: Component }[] = [\n { value: 'none', icon: MinusIcon },\n { value: 'end', icon: ArrowRightIcon },\n { value: 'both', icon: ArrowLeftRightIcon },\n]\n\nconst data = (edge: FlowEdge) => (edge.data ?? {}) as WhiteboardConnectorData\nconst isConnector = (edge: FlowEdge) => (edge.type ?? 'connector') === 'connector'\n\n/** Route, dash and arrow choices over the selected connectors. */\nexport function connectorToolbar(ctx: FlowEditorContext, edges: FlowEdge[]): FlowToolbarItem[] {\n if (!edges.every(isConnector)) return []\n const t = ctx.messages.value.board\n\n /**\n * One button: its label and icon say the value in use, or that the\n * selected connectors differ; its menu sets one value on all of them.\n */\n function choice<V extends string>(\n key: 'route' | 'dash' | 'arrow',\n fallback: V,\n options: { value: V; icon: Component }[],\n names: Record<V, string>,\n text: { of: string; set: string },\n mixedIcon: Component,\n ): FlowToolbarItem {\n const values = new Set(edges.map((edge) => (data(edge)[key] as V | undefined) ?? fallback))\n const only = values.size === 1 ? [...values][0]! : null\n return {\n key,\n label: format(text.of, { value: only ? names[only] : t.mixed }),\n icon: only ? options.find((item) => item.value === only)!.icon : mixedIcon,\n children: options.map((item) => ({\n key: `${key}-${item.value}`,\n label: names[item.value],\n icon: item.icon,\n checked: item.value === only,\n run() {\n ctx.transact((tr) => {\n for (const edge of edges)\n tr.updateEdge(edge.id, { data: { ...edge.data, [key]: item.value } })\n })\n ctx.announce(format(text.set, { value: names[item.value] }))\n },\n })),\n }\n }\n\n return [\n choice('route', 'straight', ROUTES, t.routes, { of: t.routeOf, set: t.routeSet }, RouteIcon),\n choice(\n 'dash',\n 'solid',\n DASH_CHOICES,\n t.dashes,\n { of: t.dashOf, set: t.dashSet },\n LineStyleIcon,\n ),\n choice('arrow', 'end', ARROWS, t.arrows, { of: t.arrowOf, set: t.arrowSet }, ArrowEndsIcon),\n ]\n}\n"],"mappings":";;;;AA4BA,IAAM,QAAQ;CAAE,QAAQ;CAAI,QAAQ;AAAK;AACzC,IAAM,MAAM,MAAc,KAAK,MAAM,IAAI,GAAG,IAAI;AAChD,IAAM,KAAK,OAAc,GAAG,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;;AAG/C,IAAM,UAAmC;CACvC,MAAM;EAAE,GAAG;EAAI,GAAG;CAAE;CACpB,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;CACnB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;AACvB;;AAGA,SAAS,UAAU,KAAY,OAAe;CAC5C,MAAM,QAAQ,YAAoB;EAChC,GAAG,IAAI,IAAI,MAAM,SAAS,KAAK,IAAI,QAAQ,MAAM;EACjD,GAAG,IA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,SAAS,KAAK,UAAU;IACxB,MAAM;KACJ,IAAI,UAAU,OAAO;MACnB,KAAK,MAAM,QAAQ,OACjB,GAAG,WAAW,KAAK,IAAI,EAAE,MAAM;OAAE,GAAG,KAAK;QAAO,MAAM,KAAK;MAAM,EAAE,CAAC;KACxE,CAAC;KACD,IAAI,SAAS,OAAO,KAAK,KAAK,EAAE,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC;IAC7D;GACF,EAAE;EACJ;CACF;CAEA,OAAO;EACL,OAAO,SAAS,YAAY,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,SAAS;EAC3F,OACE,QACA,SACA,cACA,EAAE,QACF;GAAE,IAAI,EAAE;GAAQ,KAAK,EAAE;EAAQ,GAC/B,aACF;EACA,OAAO,SAAS,OAAO,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,aAAa;CAC5F;AACF"}
|
|
1
|
+
{"version":3,"file":"connector.js","names":[],"sources":["../../src/whiteboard/connector.ts"],"sourcesContent":["import {\n ArrowEndsIcon,\n ArrowLeftRightIcon,\n ArrowRightIcon,\n ConnectorCurveIcon,\n ConnectorElbowIcon,\n ConnectorStraightIcon,\n LineDashDotIcon,\n LineDashedIcon,\n LineDottedIcon,\n LineSolidIcon,\n LineStyleIcon,\n MinusIcon,\n PaletteIcon,\n RouteIcon,\n} from '@dou-ui/icons'\nimport type { Component, CSSProperties } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport {\n bezierEdge,\n defineEdgeType,\n stepEdge,\n straightEdge,\n type EdgeAnchor,\n} from '../core/edge-types'\nimport type { FlowToolbarItem } from '../core/menu'\nimport type { FlowEdge, Point, PortSide } from '../core/model'\nimport { format } from '../locale'\nimport { normalizeOpaqueColor, resolveStrokeColor } from './colors'\nimport type {\n WhiteboardArrow,\n WhiteboardConnectorData,\n WhiteboardDash,\n WhiteboardRoute,\n} from './model'\nimport { cleanData, colorToolbarItem, sameData, sharedValue } from './toolbar'\n\nconst ARROW = { length: 10, spread: 0.45 }\nconst r2 = (v: number) => Math.round(v * 100) / 100\nconst p = (pt: Point) => `${r2(pt.x)} ${r2(pt.y)}`\n\n/** Out of a side, away from the node. */\nconst outward: Record<PortSide, Point> = {\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n bottom: { x: 0, y: 1 },\n}\n\n/** An open arrowhead with its tip at `tip`, pointing along `angle`. */\nfunction arrowhead(tip: Point, angle: number) {\n const wing = (spread: number) => ({\n x: tip.x - ARROW.length * Math.cos(angle + spread),\n y: tip.y - ARROW.length * Math.sin(angle + spread),\n })\n return `M${p(wing(ARROW.spread))}L${p(tip)}L${p(wing(-ARROW.spread))}`\n}\n\n/** The way a run arrives at `end`: straight from `from`, or into the side it faces. */\nfunction arrival(end: EdgeAnchor, from: Point, straight: boolean) {\n if (straight) return Math.atan2(end.y - from.y, end.x - from.x)\n const out = outward[end.side]\n return Math.atan2(-out.y, -out.x)\n}\n\n/** Dash patterns, in px of a 1.5px stroke with round ends: a 0 dash is a dot. */\nconst DASHES: Record<WhiteboardDash, string | undefined> = {\n solid: undefined,\n dashed: '6 5',\n dotted: '0 4',\n 'dash-dot': '8 4 0 4',\n}\n\n/**\n * The whiteboard's line: straight, with right-angled turns or curved\n * (`data.route`), solid or dashed (`data.dash`), with arrowheads at the end,\n * both ends or neither (`data.arrow`).\n */\nexport const connectorEdge = defineEdgeType<WhiteboardConnectorData>({\n type: 'connector',\n route(source, target, edge) {\n const data = edge?.data ?? {}\n const route = data.route ?? 'straight'\n const straight = route === 'straight'\n // Tidying lays points between the nodes in the way of a long connector.\n const points = edge?.points ?? []\n const base = straight\n ? straightEdge.route(source, target, edge as FlowEdge)\n : (route === 'elbow' ? stepEdge : bezierEdge).route(source, target, edge as FlowEdge)\n const arrow = data.arrow ?? 'end'\n let marks = ''\n if (arrow !== 'none')\n marks += arrowhead(target, arrival(target, points.at(-1) ?? source, straight))\n if (arrow === 'both') marks += arrowhead(source, arrival(source, points[0] ?? target, straight))\n return { ...base, marks: marks || undefined }\n },\n style(edge) {\n const dash = DASHES[edge.data?.dash ?? 'solid']\n const color = resolveStrokeColor(edge.data?.color)\n const stroke = color && color !== 'none' ? color : undefined\n if (!dash && !stroke) return undefined\n const out: Record<string, string> = {}\n if (dash) out.strokeDasharray = dash\n if (stroke) out['--dou-flow-connector-color'] = stroke\n return out as CSSProperties\n },\n})\n\nconst ROUTES: { value: WhiteboardRoute; icon: Component }[] = [\n { value: 'straight', icon: ConnectorStraightIcon },\n { value: 'elbow', icon: ConnectorElbowIcon },\n { value: 'curve', icon: ConnectorCurveIcon },\n]\nconst DASH_CHOICES: { value: WhiteboardDash; icon: Component }[] = [\n { value: 'solid', icon: LineSolidIcon },\n { value: 'dashed', icon: LineDashedIcon },\n { value: 'dotted', icon: LineDottedIcon },\n { value: 'dash-dot', icon: LineDashDotIcon },\n]\nconst ARROWS: { value: WhiteboardArrow; icon: Component }[] = [\n { value: 'none', icon: MinusIcon },\n { value: 'end', icon: ArrowRightIcon },\n { value: 'both', icon: ArrowLeftRightIcon },\n]\n\nconst data = (edge: FlowEdge) => (edge.data ?? {}) as WhiteboardConnectorData\nconst isConnector = (edge: FlowEdge) => (edge.type ?? 'connector') === 'connector'\nconst effectiveConnectorColor = (edge: FlowEdge) => {\n const raw = normalizeOpaqueColor(data(edge).color)\n return raw && resolveStrokeColor(raw) ? raw : undefined\n}\n\n/** Route, dash and arrow choices over the selected connectors. */\nexport function connectorToolbar(ctx: FlowEditorContext, edges: FlowEdge[]): FlowToolbarItem[] {\n if (!edges.every(isConnector)) return []\n const t = ctx.messages.value.board\n\n /**\n * One button: its label and icon say the value in use, or that the\n * selected connectors differ; its menu sets one value on all of them.\n */\n function choice<V extends string>(\n key: 'route' | 'dash' | 'arrow',\n fallback: V,\n options: { value: V; icon: Component }[],\n names: Record<V, string>,\n text: { of: string; set: string },\n mixedIcon: Component,\n ): FlowToolbarItem {\n const values = new Set(edges.map((edge) => (data(edge)[key] as V | undefined) ?? fallback))\n const only = values.size === 1 ? [...values][0]! : null\n return {\n key,\n label: format(text.of, { value: only ? names[only] : t.mixed }),\n icon: only ? options.find((item) => item.value === only)!.icon : mixedIcon,\n children: options.map((item) => ({\n key: `${key}-${item.value}`,\n label: names[item.value],\n icon: item.icon,\n checked: item.value === only,\n run() {\n ctx.transact((tr) => {\n for (const edge of edges)\n tr.updateEdge(edge.id, { data: { ...edge.data, [key]: item.value } })\n })\n ctx.announce(format(text.set, { value: names[item.value] }))\n },\n })),\n }\n }\n\n const colorValue = sharedValue(edges.map(effectiveConnectorColor))\n const colorSwatch = colorValue ? resolveStrokeColor(colorValue) : undefined\n const targetKey = edges\n .map((edge) => edge.id)\n // oxlint-disable-next-line unicorn/no-array-sort -- sorts a fresh array\n .sort()\n .join(',')\n const colorItem = colorToolbarItem({\n ctx,\n key: 'connector-color',\n scope: `connector-color:e:${targetKey}`,\n kind: 'stroke',\n icon: PaletteIcon,\n value: colorValue,\n swatch: colorSwatch === 'none' ? undefined : colorSwatch,\n labelOf: t.lineColorOf,\n announceSet: t.lineColorSet,\n apply(next, meta) {\n const color = next === 'none' ? undefined : next\n ctx.transact((tr) => {\n for (const edge of edges) {\n const current = tr.getEdge(edge.id)\n if (!current || effectiveConnectorColor(current) === color) continue\n const patched = cleanData(current.data, { color })\n const nextData = Object.keys(patched).length ? patched : undefined\n if (!sameData(current.data, nextData)) tr.updateEdge(current.id, { data: nextData })\n }\n }, meta)\n },\n })\n\n return [\n choice('route', 'straight', ROUTES, t.routes, { of: t.routeOf, set: t.routeSet }, RouteIcon),\n choice(\n 'dash',\n 'solid',\n DASH_CHOICES,\n t.dashes,\n { of: t.dashOf, set: t.dashSet },\n LineStyleIcon,\n ),\n choice('arrow', 'end', ARROWS, t.arrows, { of: t.arrowOf, set: t.arrowSet }, ArrowEndsIcon),\n colorItem,\n ]\n}\n"],"mappings":";;;;;;AAqCA,IAAM,QA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,EAAE,CAAC,CAEtB,KAAK,CAAC,CACN,KAAK,GAAG;CACX,MAAM,YAAY,iBAAiB;EACjC;EACA,KAAK;EACL,OAAO,qBAAqB;EAC5B,MAAM;EACN,MAAM;EACN,OAAO;EACP,QAAQ,gBAAgB,SAAS,KAAA,IAAY;EAC7C,SAAS,EAAE;EACX,aAAa,EAAE;EACf,MAAM,MAAM,MAAM;GAChB,MAAM,QAAQ,SAAS,SAAS,KAAA,IAAY;GAC5C,IAAI,UAAU,OAAO;IACnB,KAAK,MAAM,QAAQ,OAAO;KACxB,MAAM,UAAU,GAAG,QAAQ,KAAK,EAAE;KAClC,IAAI,CAAC,WAAW,wBAAwB,OAAO,MAAM,OAAO;KAC5D,MAAM,UAAU,UAAU,QAAQ,MAAM,EAAE,MAAM,CAAC;KACjD,MAAM,WAAW,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU,KAAA;KACzD,IAAI,CAAC,SAAS,QAAQ,MAAM,QAAQ,GAAG,GAAG,WAAW,QAAQ,IAAI,EAAE,MAAM,SAAS,CAAC;IACrF;GACF,GAAG,IAAI;EACT;CACF,CAAC;CAED,OAAO;EACL,OAAO,SAAS,YAAY,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,SAAS;EAC3F,OACE,QACA,SACA,cACA,EAAE,QACF;GAAE,IAAI,EAAE;GAAQ,KAAK,EAAE;EAAQ,GAC/B,aACF;EACA,OAAO,SAAS,OAAO,QAAQ,EAAE,QAAQ;GAAE,IAAI,EAAE;GAAS,KAAK,EAAE;EAAS,GAAG,aAAa;EAC1F;CACF;AACF"}
|
package/dist/whiteboard/draw.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNoneColor, resolveFillColor, resolveStrokeColor, resolveTextColor } from "./colors.js";
|
|
1
2
|
import { fitInk, inkOutline, unpack } from "./ink.js";
|
|
2
3
|
// src/whiteboard/draw.ts
|
|
3
4
|
var px = (value, fallback) => {
|
|
@@ -16,20 +17,34 @@ function drawBoardNode(node, draw) {
|
|
|
16
17
|
const parts = [];
|
|
17
18
|
if (kind === "shape") {
|
|
18
19
|
const s = draw.style(nodeClass, "dou-whiteboard-node__shape");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const borderless = isNoneColor(data.stroke);
|
|
21
|
+
const customFill = resolveFillColor(data.fill, "shape");
|
|
22
|
+
const fill = customFill === "none" ? "none" : customFill && draw.color(customFill) || draw.color(s.fill);
|
|
23
|
+
const strokeWidth = borderless ? 0 : px(s.strokeWidth, 1.5);
|
|
24
|
+
const i = strokeWidth / 2;
|
|
25
|
+
const diamondInset = borderless ? 0 : 1;
|
|
26
|
+
if (!borderless || fill !== "none") {
|
|
27
|
+
const customStroke = borderless ? void 0 : resolveStrokeColor(data.stroke);
|
|
28
|
+
const stroke = customStroke && draw.color(customStroke) || draw.color(s.stroke);
|
|
29
|
+
const paint = borderless ? `fill="${draw.escape(fill)}" stroke="none"` : `fill="${draw.escape(fill)}" stroke="${draw.escape(stroke)}" stroke-width="${strokeWidth}" stroke-linejoin="round"`;
|
|
30
|
+
if (shape === "ellipse") parts.push(`<ellipse cx="${r(w / 2)}" cy="${r(h / 2)}" rx="${r(Math.max(0, w / 2 - i))}" ry="${r(Math.max(0, h / 2 - i))}" ${paint}/>`);
|
|
31
|
+
else if (shape === "diamond") parts.push(`<polygon points="${r(w / 2)},${diamondInset} ${r(w - diamondInset)},${r(h / 2)} ${r(w / 2)},${r(h - diamondInset)} ${diamondInset},${r(h / 2)}" ${paint}/>`);
|
|
32
|
+
else parts.push(`<rect x="${i}" y="${i}" width="${r(Math.max(0, w - strokeWidth))}" height="${r(Math.max(0, h - strokeWidth))}" rx="8" ${paint}/>`);
|
|
33
|
+
}
|
|
25
34
|
} else if (kind === "sticky") {
|
|
26
35
|
const s = draw.style(nodeClass);
|
|
27
|
-
|
|
36
|
+
const customFill = resolveFillColor(data.fill, "sticky");
|
|
37
|
+
if (customFill !== "none") {
|
|
38
|
+
const fill = customFill && draw.color(customFill) || draw.color(s.backgroundColor);
|
|
39
|
+
parts.push(`<rect width="${r(w)}" height="${r(h)}" rx="${px(s.borderTopLeftRadius, 4)}" fill="${draw.escape(fill)}"/>`);
|
|
40
|
+
}
|
|
28
41
|
} else if (kind === "ink" && data.points && data.box) {
|
|
29
42
|
const s = draw.style(nodeClass, "dou-whiteboard-node__ink");
|
|
30
43
|
const size = data.size ?? 4;
|
|
31
44
|
const d = inkOutline(fitInk(unpack(data.points), data.box, w, h, size), size);
|
|
32
|
-
|
|
45
|
+
const customStroke = resolveStrokeColor(data.color);
|
|
46
|
+
const fill = customStroke && customStroke !== "none" && draw.color(customStroke) || draw.color(s.fill);
|
|
47
|
+
parts.push(`<path d="${d}" fill="${draw.escape(fill)}"/>`);
|
|
33
48
|
} else if (kind === "image" && data.src) {
|
|
34
49
|
const s = draw.style(nodeClass, "dou-whiteboard-node__image");
|
|
35
50
|
parts.push(draw.image(data.src, {
|
|
@@ -46,6 +61,8 @@ function drawBoardNode(node, draw) {
|
|
|
46
61
|
const side = px(s.paddingLeft, 16);
|
|
47
62
|
const lineHeight = px(s.lineHeight, size * 1.5);
|
|
48
63
|
const centred = kind !== "text";
|
|
64
|
+
const customText = resolveTextColor(kind === "text" ? data.color : data.textColor);
|
|
65
|
+
const color = customText && draw.color(customText) || draw.color(draw.style(nodeClass).color);
|
|
49
66
|
parts.push(draw.text(data.text, {
|
|
50
67
|
x: side,
|
|
51
68
|
y: top,
|
|
@@ -54,7 +71,7 @@ function drawBoardNode(node, draw) {
|
|
|
54
71
|
}, {
|
|
55
72
|
size,
|
|
56
73
|
lineHeight,
|
|
57
|
-
color
|
|
74
|
+
color,
|
|
58
75
|
align: centred ? "center" : "start",
|
|
59
76
|
valign: centred ? "middle" : "top"
|
|
60
77
|
}));
|