@dou-ui/flow 0.1.0-alpha.29 → 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/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/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/flow-editor.js.map +1 -1
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js +318 -87
- package/dist/flow-editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/locale.js +90 -3
- package/dist/locale.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/style.js +1 -0
- package/dist/types/core/menu.d.ts +55 -0
- package/dist/types/export/color.d.ts +6 -1
- package/dist/types/flow-editor.vue.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/locale.d.ts +19 -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 +22 -3
- 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 +50 -10
- 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 +42 -3
- 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 +2 -0
- package/dist/whiteboard/kit.js.map +1 -1
- package/dist/whiteboard/model.js +2 -1
- package/dist/whiteboard/model.js.map +1 -1
- package/dist/whiteboard/toolbar.js +296 -0
- package/dist/whiteboard/toolbar.js.map +1 -0
- package/package.json +3 -3
|
@@ -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,OAAO,KAAA;CACrB,OAAO,YAAY,OAAO,IAAI,SAAS;AACzC;;AAGA,SAAgB,qBAAqB,OAAoC;CACvE,MAAM,aAAa,oBAAoB,KAAK;CAC5C,OAAO,eAAe,S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EAAE,MAAM;CACvC,OAAO;AACT"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { format } from "../locale.js";
|
|
2
2
|
import { bezierEdge, defineEdgeType, stepEdge, straightEdge } from "../core/edge-types.js";
|
|
3
|
-
import {
|
|
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,
|
|
@@ -72,7 +74,13 @@ var connectorEdge = defineEdgeType({
|
|
|
72
74
|
},
|
|
73
75
|
style(edge) {
|
|
74
76
|
const dash = DASHES[edge.data?.dash ?? "solid"];
|
|
75
|
-
|
|
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;
|
|
76
84
|
}
|
|
77
85
|
});
|
|
78
86
|
var ROUTES = [
|
|
@@ -123,6 +131,10 @@ var ARROWS = [
|
|
|
123
131
|
];
|
|
124
132
|
var data = (edge) => edge.data ?? {};
|
|
125
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
|
+
};
|
|
126
138
|
/** Route, dash and arrow choices over the selected connectors. */
|
|
127
139
|
function connectorToolbar(ctx, edges) {
|
|
128
140
|
if (!edges.every(isConnector)) return [];
|
|
@@ -155,6 +167,32 @@ function connectorToolbar(ctx, edges) {
|
|
|
155
167
|
}))
|
|
156
168
|
};
|
|
157
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
|
+
});
|
|
158
196
|
return [
|
|
159
197
|
choice("route", "straight", ROUTES, t.routes, {
|
|
160
198
|
of: t.routeOf,
|
|
@@ -167,7 +205,8 @@ function connectorToolbar(ctx, edges) {
|
|
|
167
205
|
choice("arrow", "end", ARROWS, t.arrows, {
|
|
168
206
|
of: t.arrowOf,
|
|
169
207
|
set: t.arrowSet
|
|
170
|
-
}, ArrowEndsIcon)
|
|
208
|
+
}, ArrowEndsIcon),
|
|
209
|
+
colorItem
|
|
171
210
|
];
|
|
172
211
|
}
|
|
173
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 {\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 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 // 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 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":";;;;AAkCA,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,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CAAC,KAAM;EACnD,OAAO;GACL;GACA,OAAO,OAAO,KAAK,IAAI,EAAE,OAAO,OAAO,MAAM,QAAQ,EAAE,MAAM,CAAC;GAC9D,MAAM,OAAO,QAAQ,MAAM,SAAS,KAAK,UAAU,IAAI,CAAC,CAAE,OAAO;GACjE,UAAU,QAAQ,KAAK,UAAU;IAC/B,KAAK,GAAG,IAAI,GAAG,KAAK;IACpB,OAAO,MAAM,KAAK;IAClB,MAAM,KAAK;IACX,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,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,IAAI,IAAI,MAAM,SAAS,KAAK,IAAI,QAAQ,MAAM;CACnD;CACA,OAAO,IAAI,EAAE,KAAK,MAAM,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,MAAM,CAAC;AACrE;;AAGA,SAAS,QAAQ,KAAiB,MAAa,UAAmB;CAChE,IAAI,UAAU,OAAO,KAAK,MAAM,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,CAAC;CAC9D,MAAM,MAAM,QAAQ,IAAI;CACxB,OAAO,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC;AAClC;;AAGA,IAAM,SAAqD;CACzD,OAAO,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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
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draw.js","names":[],"sources":["../../src/whiteboard/draw.ts"],"sourcesContent":["import type { FlowNode } from '../core/model'\nimport type { FlowDrawContext } from '../export/context'\nimport { fitInk, inkOutline, INK_SIZE, unpack } from './ink'\nimport type { WhiteboardNodeData, WhiteboardShape } from './model'\n\nconst px = (value: string, fallback: number) => {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? n : fallback\n}\nconst r = (value: number) => Math.round(value * 100) / 100\n\n/** A board node as SVG, as `board-node.vue` draws it. */\nexport function drawBoardNode(node: FlowNode<WhiteboardNodeData>, draw: FlowDrawContext): string {\n const data = (node.data ?? {}) as WhiteboardNodeData & {\n shape?: WhiteboardShape\n text?: string\n tone?: string\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n }\n const kind = node.type === 'shape' || !node.type ? 'shape' : node.type\n const tone = data.tone ?? (kind === 'sticky' ? 'warning' : 'neutral')\n const shape = data.shape ?? 'rect'\n const nodeClass = `dou-whiteboard-node is-${kind}${kind === 'shape' ? ` is-${shape}` : ''} is-${tone}`\n const { width: w, height: h } = draw\n const parts: string[] = []\n\n if (kind === 'shape') {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__shape')\n const stroke = px(s.strokeWidth, 1.5)\n const i =
|
|
1
|
+
{"version":3,"file":"draw.js","names":[],"sources":["../../src/whiteboard/draw.ts"],"sourcesContent":["import type { FlowNode } from '../core/model'\nimport type { FlowDrawContext } from '../export/context'\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 type { WhiteboardNodeData, WhiteboardShape } from './model'\n\nconst px = (value: string, fallback: number) => {\n const n = Number.parseFloat(value)\n return Number.isFinite(n) ? n : fallback\n}\nconst r = (value: number) => Math.round(value * 100) / 100\n\n/** A board node as SVG, as `board-node.vue` draws it. */\nexport function drawBoardNode(node: FlowNode<WhiteboardNodeData>, draw: FlowDrawContext): string {\n const data = (node.data ?? {}) as WhiteboardNodeData & {\n shape?: WhiteboardShape\n text?: string\n tone?: string\n fill?: WhiteboardFill\n stroke?: WhiteboardStroke\n textColor?: WhiteboardColor\n color?: WhiteboardColor\n points?: number[]\n box?: [number, number]\n size?: number\n src?: string\n }\n const kind = node.type === 'shape' || !node.type ? 'shape' : node.type\n const tone = data.tone ?? (kind === 'sticky' ? 'warning' : 'neutral')\n const shape = data.shape ?? 'rect'\n const nodeClass = `dou-whiteboard-node is-${kind}${kind === 'shape' ? ` is-${shape}` : ''} is-${tone}`\n const { width: w, height: h } = draw\n const parts: string[] = []\n\n if (kind === 'shape') {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__shape')\n const borderless = isNoneColor(data.stroke)\n const customFill = resolveFillColor(data.fill, 'shape')\n const fill =\n customFill === 'none' ? 'none' : (customFill && draw.color(customFill)) || draw.color(s.fill)\n const strokeWidth = borderless ? 0 : px(s.strokeWidth, 1.5)\n const i = strokeWidth / 2\n const diamondInset = borderless ? 0 : 1\n if (!borderless || fill !== 'none') {\n const customStroke = borderless ? undefined : resolveStrokeColor(data.stroke)\n const stroke = (customStroke && draw.color(customStroke)) || draw.color(s.stroke)\n const paint = borderless\n ? `fill=\"${draw.escape(fill)}\" stroke=\"none\"`\n : `fill=\"${draw.escape(fill)}\" stroke=\"${draw.escape(stroke)}\" stroke-width=\"${strokeWidth}\" stroke-linejoin=\"round\"`\n if (shape === 'ellipse')\n parts.push(\n `<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}/>`,\n )\n else if (shape === 'diamond')\n parts.push(\n `<polygon points=\"${r(w / 2)},${diamondInset} ${r(w - diamondInset)},${r(h / 2)} ${r(w / 2)},${r(h - diamondInset)} ${diamondInset},${r(h / 2)}\" ${paint}/>`,\n )\n else\n parts.push(\n `<rect x=\"${i}\" y=\"${i}\" width=\"${r(Math.max(0, w - strokeWidth))}\" height=\"${r(Math.max(0, h - strokeWidth))}\" rx=\"8\" ${paint}/>`,\n )\n }\n } else if (kind === 'sticky') {\n const s = draw.style(nodeClass)\n const customFill = resolveFillColor(data.fill, 'sticky')\n if (customFill !== 'none') {\n const fill = (customFill && draw.color(customFill)) || draw.color(s.backgroundColor)\n parts.push(\n `<rect width=\"${r(w)}\" height=\"${r(h)}\" rx=\"${px(s.borderTopLeftRadius, 4)}\" fill=\"${draw.escape(fill)}\"/>`,\n )\n }\n } else if (kind === 'ink' && data.points && data.box) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__ink')\n const size = data.size ?? INK_SIZE\n const d = inkOutline(fitInk(unpack(data.points), data.box, w, h, size), size)\n const customStroke = resolveStrokeColor(data.color)\n const fill =\n (customStroke && customStroke !== 'none' && draw.color(customStroke)) || draw.color(s.fill)\n parts.push(`<path d=\"${d}\" fill=\"${draw.escape(fill)}\"/>`)\n } else if (kind === 'image' && data.src) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__image')\n parts.push(\n draw.image(\n data.src,\n { x: 0, y: 0, width: w, height: h },\n { radius: px(s.borderTopLeftRadius, 4) },\n ),\n )\n }\n\n if (data.text && (kind === 'shape' || kind === 'sticky' || kind === 'text')) {\n const s = draw.style(nodeClass, 'dou-whiteboard-node__text')\n const size = px(s.fontSize, 14)\n const top = px(s.paddingTop, 12)\n const side = px(s.paddingLeft, 16)\n const lineHeight = px(s.lineHeight, size * 1.5)\n const centred = kind !== 'text'\n const customText = resolveTextColor(kind === 'text' ? data.color : data.textColor)\n const color = (customText && draw.color(customText)) || draw.color(draw.style(nodeClass).color)\n parts.push(\n draw.text(\n data.text,\n { x: side, y: top, width: Math.max(0, w - side * 2), height: Math.max(0, h - top * 2) },\n {\n size,\n lineHeight,\n color,\n align: centred ? 'center' : 'start',\n valign: centred ? 'middle' : 'top',\n },\n ),\n )\n }\n\n const body = parts.join('')\n const rotation = data.rotation\n return rotation ? `<g transform=\"rotate(${rotation} ${r(w / 2)} ${r(h / 2)})\">${body}</g>` : body\n}\n"],"mappings":";;;AAcA,IAAM,MAAM,OAAe,aAAqB;CAC9C,MAAM,IAAI,OAAO,WAAW,KAAK;CACjC,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AACA,IAAM,KAAK,UAAkB,KAAK,MAAM,QAAQ,GAAG,IAAI;;AAGvD,SAAgB,cAAc,MAAoC,MAA+B;CAC/F,MAAM,OAAQ,KAAK,QAAQ,CAAC;CAa5B,MAAM,OAAO,KAAK,SAAS,WAAW,CAAC,KAAK,OAAO,UAAU,KAAK;CAClE,MAAM,OAAO,KAAK,SAAS,SAAS,WAAW,YAAY;CAC3D,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,YAAY,0BAA0B,OAAO,SAAS,UAAU,OAAO,UAAU,GAAG,MAAM;CAChG,MAAM,EAAE,OAAO,GAAG,QAAQ,MAAM;CAChC,MAAM,QAAkB,CAAC;CAEzB,IAAI,SAAS,SAAS;EACpB,MAAM,IAAI,KAAK,MAAM,WAAW,4BAA4B;EAC5D,MAAM,aAAa,YAAY,KAAK,MAAM;EAC1C,MAAM,aAAa,iBAAiB,KAAK,MAAM,OAAO;EACtD,MAAM,OACJ,eAAe,SAAS,SAAU,cAAc,KAAK,MAAM,UAAU,KAAM,KAAK,MAAM,EAAE,IAAI;EAC9F,MAAM,cAAc,aAAa,IAAI,GAAG,EAAE,aAAa,GAAG;EAC1D,MAAM,IAAI,cAAc;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AAM,KAAK,MAAM,KAAK,MAAM,SAAS,CAAC,CAAC,KAAK;EAC9F,MAAM,KACJ,KAAK,KACH,KAAK,MACL;GAAE,GAAG;GAAM,GAAG;GAAK,OAAO,KAAK,IAAI,GAAG,IAAI,OAAO,CAAC;GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI,MAAM,CAAC;EAAE,GACtF;GACE;GACA;GACA;GACA,OAAO,UAAU,WAAW;GAC5B,QAAQ,UAAU,WAAW;EAC/B,CACF,CACF;CACF;CAEA,MAAM,OAAO,MAAM,KAAK,EAAE;CAC1B,MAAM,WAAW,KAAK;CACtB,OAAO,WAAW,wBAAwB,SAAS,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,QAAQ;AAC/F"}
|
package/dist/whiteboard/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { isWhiteboardColor, whiteboardColors } from "./colors.js";
|
|
1
2
|
import { imageKey, whiteboardKeys } from "./model.js";
|
|
2
3
|
import { insertImages, pickImages } from "./image.js";
|
|
3
4
|
import { connectorEdge } from "./connector.js";
|
|
4
5
|
import { imageNode, inkNode, shapeNode, stickyNode, textNode, whiteboardKit } from "./kit.js";
|
|
5
|
-
export { connectorEdge, imageKey, imageNode, inkNode, insertImages, pickImages, shapeNode, stickyNode, textNode, whiteboardKeys, whiteboardKit };
|
|
6
|
+
export { connectorEdge, imageKey, imageNode, inkNode, insertImages, isWhiteboardColor, pickImages, shapeNode, stickyNode, textNode, whiteboardColors, whiteboardKeys, whiteboardKit };
|
package/dist/whiteboard/kit.js
CHANGED
|
@@ -9,6 +9,7 @@ import board_node_default from "./board-node.js";
|
|
|
9
9
|
import board_draft_default from "./board-draft.js";
|
|
10
10
|
import { imageFiles, insertImages, pickImages } from "./image.js";
|
|
11
11
|
import whiteboard_toolbar_default from "./whiteboard-toolbar.js";
|
|
12
|
+
import { boardNodeToolbar } from "./toolbar.js";
|
|
12
13
|
import { connectorEdge, connectorToolbar } from "./connector.js";
|
|
13
14
|
import { drawBoardNode } from "./draw.js";
|
|
14
15
|
import { drawInk, erase } from "./pen.js";
|
|
@@ -233,6 +234,7 @@ function whiteboardKit(options = {}) {
|
|
|
233
234
|
imageNode
|
|
234
235
|
],
|
|
235
236
|
edgeTypes: [connectorEdge],
|
|
237
|
+
toolbarItems: boardNodeToolbar,
|
|
236
238
|
edgeToolbarItems: connectorToolbar,
|
|
237
239
|
edgeType: "connector",
|
|
238
240
|
layers: { above: [board_draft_default] },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kit.js","names":["BoardNode","BoardDraft","WhiteboardToolbar"],"sources":["../../src/whiteboard/kit.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport { RotateCwIcon } from '@dou-ui/icons'\nimport { watch, type Ref } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport { defineFlowExtension, type FlowExtension, type FlowPressHandler } from '../core/extension'\nimport { turn } from '../core/geometry'\nimport { createId, type FlowData, type FlowNode, type Point, type Rect } from '../core/model'\nimport { defineNodeType } from '../core/node-types'\nimport { format, type FlowMessages } from '../locale'\nimport BoardNode from './board-node.vue'\nimport BoardDraft from './board-draft.vue'\nimport WhiteboardToolbar from './whiteboard-toolbar.vue'\nimport {\n imageKey,\n type WhiteboardImageData,\n type WhiteboardInkData,\n type WhiteboardNodeData,\n type WhiteboardShapeData,\n type WhiteboardShapeTool,\n type WhiteboardStickyData,\n type WhiteboardTextData,\n type WhiteboardTool,\n whiteboardKeys,\n} from './model'\nimport {\n imageFiles,\n insertImages,\n pickImages,\n type WhiteboardUpload,\n type WhiteboardUploadErrorHandler,\n} from './image'\nimport { connectorEdge, connectorToolbar } from './connector'\nimport { drawBoardNode } from './draw'\nimport { drawInk, erase } from './pen'\nimport { boardState, usable } from './state'\n\n/** The node types the whiteboard adds; only they turn. */\nconst BOARD_TYPES = new Set(['shape', 'sticky', 'text', 'ink', 'image'])\n\n/** \"Rectangle: text\", or just \"Rectangle\" while it has none. */\nconst nameOf = (kind: string, text: string | undefined, t: FlowMessages) =>\n text ? format(t.board.named, { kind, text }) : kind\n\n/** How far a board node is turned, from `data.rotation`. */\nconst turnedBy = (node: FlowNode<WhiteboardNodeData>) => node.data?.rotation ?? 0\n\n/** A rectangle, ellipse or diamond with centred text; `data.shape` says which. */\nexport const shapeNode = defineNodeType<WhiteboardShapeData>({\n type: 'shape',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 100 },\n defaults: () => ({ shape: 'rect' }),\n label: (node, t) => nameOf(t.board[node.data?.shape ?? 'rect'], node.data?.text, t),\n})\n\n/** A square note in a soft color. */\nexport const stickyNode = defineNodeType<WhiteboardStickyData>({\n type: 'sticky',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 64, minHeight: 64 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 160 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.sticky, node.data?.text, t),\n})\n\n/** Text on its own; it grows as it is typed. */\nexport const textNode = defineNodeType<WhiteboardTextData>({\n type: 'text',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 200, height: 40 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.text, node.data?.text, t),\n})\n\n/** A pen stroke; it stretches with its box. */\nexport const inkNode = defineNodeType<WhiteboardInkData>({\n type: 'ink',\n component: BoardNode,\n frame: false,\n resizable: { minWidth: 8, minHeight: 8 },\n rotation: turnedBy,\n draw: drawBoardNode,\n defaults: () => ({ points: [], box: [0, 0] }),\n label: (_, t) => t.board.ink,\n})\n\n/** An image; `data.src` is its address. */\nexport const imageNode = defineNodeType<WhiteboardImageData>({\n type: 'image',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 240, height: 180 },\n defaults: () => ({ src: '' }),\n label: (node, t) => nameOf(t.board.image, node.data?.alt, t),\n})\n\n/** The node type and data each drawing tool adds. */\nfunction kindOf(tool: WhiteboardShapeTool): { type: string; data: FlowData } {\n if (tool === 'sticky' || tool === 'text') return { type: tool, data: {} }\n return { type: 'shape', data: { shape: tool } }\n}\n\nfunction nodeFor(tool: WhiteboardShapeTool, rect: Rect): FlowNode {\n // text grows with what is typed: it keeps no height\n const height = tool === 'text' ? undefined : rect.height\n return { id: createId(), x: rect.x, y: rect.y, width: rect.width, height, ...kindOf(tool) }\n}\n\nconst SIZES: Record<WhiteboardShapeTool, { width: number; height: number }> = {\n rect: { width: 160, height: 100 },\n ellipse: { width: 140, height: 100 },\n diamond: { width: 140, height: 120 },\n sticky: { width: 160, height: 160 },\n text: { width: 200, height: 40 },\n}\n\n/**\n * The comment tool: a click on a node starts a thread pinned where it was\n * clicked, the point turned back with the node. A press on the empty canvas\n * does nothing; a mouse drag does nothing either, so a thread isn't started\n * by mistake, while a finger's drag moves the view, as it does elsewhere.\n */\nfunction pinComment(\n ctx: FlowEditorContext,\n node: string | null,\n start: Point,\n event: PointerEvent,\n): FlowPressHandler {\n const client = { x: event.clientX, y: event.clientY }\n const origin = { ...ctx.viewport.value }\n const finger = event.pointerType !== 'mouse'\n let moved = false\n return {\n move(_, move) {\n const dx = move.clientX - client.x\n const dy = move.clientY - client.y\n if (!moved && Math.hypot(dx, dy) <= 8) return\n moved = true\n if (finger) ctx.setViewport({ ...origin, x: origin.x + dx, y: origin.y + dy })\n },\n end() {\n const rect = node && !moved ? ctx.getNodeRect(node) : null\n if (!node || !rect || !rect.width || !rect.height) return\n const centre = { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }\n const local = turn(start, centre, -ctx.nodeRotation(node))\n const at = { x: (local.x - rect.x) / rect.width, y: (local.y - rect.y) / rect.height }\n // a tap: the card opens without the focus, so a phone's keyboard doesn't come up\n ctx.comment({ node, at }, { focus: !finger })\n },\n }\n}\n\n/** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */\nfunction added(ctx: FlowEditorContext, tool: WhiteboardShapeTool, id: string) {\n const state = boardState(ctx)\n if (!state.locked.value) state.tool.value = 'select'\n if (tool === 'sticky' || tool === 'text') state.editing.value = id\n}\n\nexport interface WhiteboardKitOptions {\n /**\n * The current tool, to share with your own toolbar. Made inside the kit\n * when left out.\n */\n tool?: Ref<WhiteboardTool>\n /** The built-in toolbar at the top of the editor. Defaults to `true`. */\n toolbar?: boolean\n /**\n * Turns an image file that is dropped, pasted or picked into the `src` it\n * is kept as, e.g. by uploading it and returning its address. Without it,\n * images are kept in the document as data URLs.\n */\n upload?: WhiteboardUpload\n /**\n * Called for each image whose `upload` failed, with the file and the\n * error; the app then tells the user, screen readers included. Without\n * it, a danger toast at the bottom says which images were not added.\n */\n onUploadError?: WhiteboardUploadErrorHandler\n}\n\n/**\n * The whiteboard: shape, sticky note and text nodes, the `connector` edge,\n * the drawing tools with their keys, and a toolbar. Add it after `flowKit()`.\n */\nexport function whiteboardKit(options: WhiteboardKitOptions = {}): FlowExtension {\n return defineFlowExtension({\n name: 'whiteboard',\n nodeTypes: [shapeNode, stickyNode, textNode, inkNode, imageNode],\n edgeTypes: [connectorEdge],\n edgeToolbarItems: connectorToolbar,\n edgeType: 'connector',\n layers: { above: [BoardDraft] },\n overlays: options.toolbar === false ? [] : [WhiteboardToolbar],\n\n setup(ctx) {\n const state = boardState(ctx)\n state.upload = options.upload\n state.onUploadError = options.onUploadError\n const stops: (() => void)[] = []\n if (options.tool) {\n const outer = options.tool\n state.tool.value = outer.value\n stops.push(\n watch(outer, (tool) => (state.tool.value = tool)),\n watch(state.tool, (tool) => (outer.value = tool)),\n )\n }\n // the comment tool goes once threads can't be started, every drawing tool once read-only\n stops.push(\n watch(\n () => usable(ctx, state.tool.value),\n (ok) => !ok && (state.tool.value = 'select'),\n { immediate: true },\n ),\n )\n // the cursor says what a press will do\n stops.push(\n watch(\n state.tool,\n (tool) => {\n const root = ctx.root.value\n if (root) root.dataset.boardTool = tool\n },\n { immediate: true },\n ),\n watch(state.panning, (panning) => {\n const root = ctx.root.value\n if (root) root.toggleAttribute('data-board-panning', panning)\n }),\n )\n // images dropped on the board or pasted into it\n const root = ctx.root.value\n const onDragOver = (event: DragEvent) => {\n if (ctx.readonly.value || !event.dataTransfer?.types.includes('Files')) return\n event.preventDefault()\n event.dataTransfer.dropEffect = 'copy'\n }\n const onDrop = (event: DragEvent) => {\n const files = imageFiles(event.dataTransfer?.files)\n if (ctx.readonly.value || !files.length) return\n event.preventDefault()\n const at = ctx.toCanvas({ x: event.clientX, y: event.clientY })\n void insertImages(ctx, files, { at })\n }\n const onPaste = (event: ClipboardEvent) => {\n const active = document.activeElement\n if (ctx.readonly.value || !root || !active || !root.contains(active)) return\n // pasting into a field is the field's\n if (active.closest('input, textarea, [contenteditable]')) return\n const files = imageFiles(event.clipboardData?.files)\n if (!files.length) return\n event.preventDefault()\n event.stopImmediatePropagation()\n void insertImages(ctx, files)\n }\n root?.addEventListener('dragover', onDragOver)\n root?.addEventListener('drop', onDrop)\n // before the editor's own paste, which reads nodes from text\n document.addEventListener('paste', onPaste, true)\n return () => {\n for (const stop of stops) stop()\n root?.removeEventListener('dragover', onDragOver)\n root?.removeEventListener('drop', onDrop)\n document.removeEventListener('paste', onPaste, true)\n delete ctx.root.value?.dataset.boardTool\n ctx.root.value?.removeAttribute('data-board-panning')\n }\n },\n\n press(ctx, press) {\n const state = boardState(ctx)\n const tool = state.tool.value\n if (tool === 'select') return\n // while read-only, only moving the view and commenting\n if (ctx.readonly.value && tool !== 'hand' && tool !== 'comment') return\n if (tool === 'comment')\n return pinComment(ctx, press.node?.id ?? null, press.point, press.event)\n // a press puts down whatever text was being typed\n state.editing.value = null\n if (tool === 'hand') {\n const start = { x: press.event.clientX, y: press.event.clientY }\n const origin = { ...ctx.viewport.value }\n state.panning.value = true\n const stop = () => (state.panning.value = false)\n return {\n end: stop,\n cancel: stop,\n move(_, event) {\n ctx.setViewport({\n ...origin,\n x: origin.x + event.clientX - start.x,\n y: origin.y + event.clientY - start.y,\n })\n },\n }\n }\n if (tool === 'pen') return drawInk(ctx, press.event)\n if (tool === 'eraser') return erase(ctx, press.point)\n const start = press.point\n const rectTo = (point: Point, square: boolean) => {\n let width = Math.abs(point.x - start.x)\n let height = Math.abs(point.y - start.y)\n if (square) width = height = Math.max(width, height)\n return {\n x: point.x < start.x ? start.x - width : start.x,\n y: point.y < start.y ? start.y - height : start.y,\n width,\n height,\n }\n }\n const done = (rect: Rect | null) => {\n state.draft.value = null\n if (!rect) return\n const node = nodeFor(tool, rect)\n ctx.transact((tr) => tr.addNode(node))\n ctx.selection.value = { nodes: [node.id], edges: [] }\n ctx.announce(format(ctx.messages.value.added, { node: ctx.messages.value.board[tool] }))\n added(ctx, tool, node.id)\n }\n return {\n move(point, event) {\n state.draft.value = { ...rectTo(point, event.shiftKey), tool }\n },\n end(point, event) {\n const rect = rectTo(point, event.shiftKey)\n const min = 8 / ctx.viewport.value.zoom\n if (rect.width < min && rect.height < min) {\n // a click: the default size, centred where it was clicked\n const size = SIZES[tool]\n done({ x: start.x - size.width / 2, y: start.y - size.height / 2, ...size })\n } else {\n done({\n ...rect,\n width: Math.max(rect.width, 24),\n height: tool === 'text' ? Math.max(rect.height, 40) : Math.max(rect.height, 24),\n })\n }\n },\n cancel: () => done(null),\n }\n },\n\n contextMenu(ctx, target) {\n if (target.kind !== 'node' || ctx.readonly.value) return []\n const t = ctx.messages.value.board\n const items: ContextMenuItem[] = []\n const node = target.node\n if (BOARD_TYPES.has(node.type ?? '') && ctx.selection.value.nodes.length <= 1) {\n const rotation = (node.data?.rotation as number | undefined) ?? 0\n const rotate = (to: number) => {\n ctx.transact((tr) => tr.updateData(node.id, { rotation: to || undefined }))\n ctx.announce(format(t.turned, { degrees: to }))\n }\n items.push(\n {\n key: 'rotate',\n label: t.rotate,\n icon: RotateCwIcon,\n divided: true,\n disabled: !!node.locked,\n run: () => rotate((rotation + 90) % 360),\n },\n {\n key: 'unrotate',\n label: t.unrotate,\n disabled: !rotation || !!node.locked,\n run: () => rotate(0),\n },\n )\n }\n return items\n },\n\n keymap(ctx) {\n const state = boardState(ctx)\n const pick = (tool: WhiteboardTool) => () => {\n if (!usable(ctx, tool)) return false\n state.tool.value = tool\n state.locked.value = false\n const t = ctx.messages.value.board\n ctx.announce(format(t.picked, { tool: t[tool] }))\n }\n const keys: Record<string, () => boolean | void> = {}\n for (const [tool, key] of Object.entries(whiteboardKeys))\n keys[key] = pick(tool as WhiteboardTool)\n return {\n ...keys,\n [imageKey]: () => {\n if (ctx.readonly.value) return false\n pickImages(ctx)\n },\n enter: () => {\n const tool = state.tool.value\n // with the comment tool, Enter starts a thread on the selected node, about all of it\n if (tool === 'comment') {\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length) return false\n return ctx.comment({ node: nodes[0]! }) || false\n }\n if (ctx.readonly.value) return false\n // with a drawing tool, Enter puts one down: after the selected node, or mid-view\n if (tool !== 'select' && tool !== 'hand' && tool !== 'pen' && tool !== 'eraser') {\n const { type, data } = kindOf(tool)\n // text keeps no height, as when drawn\n const size =\n tool === 'text' ? { width: SIZES.text.width, height: undefined } : SIZES[tool]\n // notes and text take focus in their own field\n const writes = tool === 'sticky' || tool === 'text'\n const id = ctx.insertNode(type, { data, size, focus: !writes })\n if (id) added(ctx, tool, id)\n return\n }\n // otherwise it writes in the selected note or shape\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length || ctx.readonly.value) return false\n const node = ctx.doc.value.nodes.find((n) => n.id === nodes[0])\n if (!node || !['shape', 'sticky', 'text'].includes(node.type ?? '')) return false\n state.editing.value = node.id\n },\n escape: () => {\n if (state.tool.value === 'select') return false\n state.tool.value = 'select'\n },\n }\n },\n })\n}\n\nexport { connectorEdge }\n"],"mappings":";;;;;;;;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M,MAAM,EAAE,OAAO,MAAM,EAAE;KAC9D,IAAI,CAAC,QAAQ,CAAC;MAAC;MAAS;MAAU;KAAM,CAAC,CAAC,SAAS,KAAK,QAAQ,EAAE,GAAG,OAAO;KAC5E,MAAM,QAAQ,QAAQ,KAAK;IAC7B;IACA,cAAc;KACZ,IAAI,MAAM,KAAK,UAAU,UAAU,OAAO;KAC1C,MAAM,KAAK,QAAQ;IACrB;GACF;EACF;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"kit.js","names":["BoardNode","BoardDraft","WhiteboardToolbar"],"sources":["../../src/whiteboard/kit.ts"],"sourcesContent":["import type { ContextMenuItem } from 'dou-ui'\nimport { RotateCwIcon } from '@dou-ui/icons'\nimport { watch, type Ref } from 'vue'\nimport type { FlowEditorContext } from '../context'\nimport { defineFlowExtension, type FlowExtension, type FlowPressHandler } from '../core/extension'\nimport { turn } from '../core/geometry'\nimport { createId, type FlowData, type FlowNode, type Point, type Rect } from '../core/model'\nimport { defineNodeType } from '../core/node-types'\nimport { format, type FlowMessages } from '../locale'\nimport BoardNode from './board-node.vue'\nimport BoardDraft from './board-draft.vue'\nimport WhiteboardToolbar from './whiteboard-toolbar.vue'\nimport {\n imageKey,\n type WhiteboardImageData,\n type WhiteboardInkData,\n type WhiteboardNodeData,\n type WhiteboardShapeData,\n type WhiteboardShapeTool,\n type WhiteboardStickyData,\n type WhiteboardTextData,\n type WhiteboardTool,\n whiteboardKeys,\n} from './model'\nimport {\n imageFiles,\n insertImages,\n pickImages,\n type WhiteboardUpload,\n type WhiteboardUploadErrorHandler,\n} from './image'\nimport { connectorEdge, connectorToolbar } from './connector'\nimport { drawBoardNode } from './draw'\nimport { drawInk, erase } from './pen'\nimport { boardState, usable } from './state'\nimport { boardNodeToolbar } from './toolbar'\n\n/** The node types the whiteboard adds; only they turn. */\nconst BOARD_TYPES = new Set(['shape', 'sticky', 'text', 'ink', 'image'])\n\n/** \"Rectangle: text\", or just \"Rectangle\" while it has none. */\nconst nameOf = (kind: string, text: string | undefined, t: FlowMessages) =>\n text ? format(t.board.named, { kind, text }) : kind\n\n/** How far a board node is turned, from `data.rotation`. */\nconst turnedBy = (node: FlowNode<WhiteboardNodeData>) => node.data?.rotation ?? 0\n\n/** A rectangle, ellipse or diamond with centred text; `data.shape` says which. */\nexport const shapeNode = defineNodeType<WhiteboardShapeData>({\n type: 'shape',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 100 },\n defaults: () => ({ shape: 'rect' }),\n label: (node, t) => nameOf(t.board[node.data?.shape ?? 'rect'], node.data?.text, t),\n})\n\n/** A square note in a soft color. */\nexport const stickyNode = defineNodeType<WhiteboardStickyData>({\n type: 'sticky',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 64, minHeight: 64 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 160, height: 160 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.sticky, node.data?.text, t),\n})\n\n/** Text on its own; it grows as it is typed. */\nexport const textNode = defineNodeType<WhiteboardTextData>({\n type: 'text',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 200, height: 40 },\n defaults: () => ({}),\n label: (node, t) => nameOf(t.board.text, node.data?.text, t),\n})\n\n/** A pen stroke; it stretches with its box. */\nexport const inkNode = defineNodeType<WhiteboardInkData>({\n type: 'ink',\n component: BoardNode,\n frame: false,\n resizable: { minWidth: 8, minHeight: 8 },\n rotation: turnedBy,\n draw: drawBoardNode,\n defaults: () => ({ points: [], box: [0, 0] }),\n label: (_, t) => t.board.ink,\n})\n\n/** An image; `data.src` is its address. */\nexport const imageNode = defineNodeType<WhiteboardImageData>({\n type: 'image',\n component: BoardNode,\n ports: 'sides',\n frame: false,\n resizable: { minWidth: 24, minHeight: 24 },\n rotation: turnedBy,\n draw: drawBoardNode,\n size: { width: 240, height: 180 },\n defaults: () => ({ src: '' }),\n label: (node, t) => nameOf(t.board.image, node.data?.alt, t),\n})\n\n/** The node type and data each drawing tool adds. */\nfunction kindOf(tool: WhiteboardShapeTool): { type: string; data: FlowData } {\n if (tool === 'sticky' || tool === 'text') return { type: tool, data: {} }\n return { type: 'shape', data: { shape: tool } }\n}\n\nfunction nodeFor(tool: WhiteboardShapeTool, rect: Rect): FlowNode {\n // text grows with what is typed: it keeps no height\n const height = tool === 'text' ? undefined : rect.height\n return { id: createId(), x: rect.x, y: rect.y, width: rect.width, height, ...kindOf(tool) }\n}\n\nconst SIZES: Record<WhiteboardShapeTool, { width: number; height: number }> = {\n rect: { width: 160, height: 100 },\n ellipse: { width: 140, height: 100 },\n diamond: { width: 140, height: 120 },\n sticky: { width: 160, height: 160 },\n text: { width: 200, height: 40 },\n}\n\n/**\n * The comment tool: a click on a node starts a thread pinned where it was\n * clicked, the point turned back with the node. A press on the empty canvas\n * does nothing; a mouse drag does nothing either, so a thread isn't started\n * by mistake, while a finger's drag moves the view, as it does elsewhere.\n */\nfunction pinComment(\n ctx: FlowEditorContext,\n node: string | null,\n start: Point,\n event: PointerEvent,\n): FlowPressHandler {\n const client = { x: event.clientX, y: event.clientY }\n const origin = { ...ctx.viewport.value }\n const finger = event.pointerType !== 'mouse'\n let moved = false\n return {\n move(_, move) {\n const dx = move.clientX - client.x\n const dy = move.clientY - client.y\n if (!moved && Math.hypot(dx, dy) <= 8) return\n moved = true\n if (finger) ctx.setViewport({ ...origin, x: origin.x + dx, y: origin.y + dy })\n },\n end() {\n const rect = node && !moved ? ctx.getNodeRect(node) : null\n if (!node || !rect || !rect.width || !rect.height) return\n const centre = { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }\n const local = turn(start, centre, -ctx.nodeRotation(node))\n const at = { x: (local.x - rect.x) / rect.width, y: (local.y - rect.y) / rect.height }\n // a tap: the card opens without the focus, so a phone's keyboard doesn't come up\n ctx.comment({ node, at }, { focus: !finger })\n },\n }\n}\n\n/** After a tool put down a node: back to select unless kept, and notes and text open to be written in. */\nfunction added(ctx: FlowEditorContext, tool: WhiteboardShapeTool, id: string) {\n const state = boardState(ctx)\n if (!state.locked.value) state.tool.value = 'select'\n if (tool === 'sticky' || tool === 'text') state.editing.value = id\n}\n\nexport interface WhiteboardKitOptions {\n /**\n * The current tool, to share with your own toolbar. Made inside the kit\n * when left out.\n */\n tool?: Ref<WhiteboardTool>\n /** The built-in toolbar at the top of the editor. Defaults to `true`. */\n toolbar?: boolean\n /**\n * Turns an image file that is dropped, pasted or picked into the `src` it\n * is kept as, e.g. by uploading it and returning its address. Without it,\n * images are kept in the document as data URLs.\n */\n upload?: WhiteboardUpload\n /**\n * Called for each image whose `upload` failed, with the file and the\n * error; the app then tells the user, screen readers included. Without\n * it, a danger toast at the bottom says which images were not added.\n */\n onUploadError?: WhiteboardUploadErrorHandler\n}\n\n/**\n * The whiteboard: shape, sticky note and text nodes, the `connector` edge,\n * the drawing tools with their keys, and a toolbar. Add it after `flowKit()`.\n */\nexport function whiteboardKit(options: WhiteboardKitOptions = {}): FlowExtension {\n return defineFlowExtension({\n name: 'whiteboard',\n nodeTypes: [shapeNode, stickyNode, textNode, inkNode, imageNode],\n edgeTypes: [connectorEdge],\n toolbarItems: boardNodeToolbar,\n edgeToolbarItems: connectorToolbar,\n edgeType: 'connector',\n layers: { above: [BoardDraft] },\n overlays: options.toolbar === false ? [] : [WhiteboardToolbar],\n\n setup(ctx) {\n const state = boardState(ctx)\n state.upload = options.upload\n state.onUploadError = options.onUploadError\n const stops: (() => void)[] = []\n if (options.tool) {\n const outer = options.tool\n state.tool.value = outer.value\n stops.push(\n watch(outer, (tool) => (state.tool.value = tool)),\n watch(state.tool, (tool) => (outer.value = tool)),\n )\n }\n // the comment tool goes once threads can't be started, every drawing tool once read-only\n stops.push(\n watch(\n () => usable(ctx, state.tool.value),\n (ok) => !ok && (state.tool.value = 'select'),\n { immediate: true },\n ),\n )\n // the cursor says what a press will do\n stops.push(\n watch(\n state.tool,\n (tool) => {\n const root = ctx.root.value\n if (root) root.dataset.boardTool = tool\n },\n { immediate: true },\n ),\n watch(state.panning, (panning) => {\n const root = ctx.root.value\n if (root) root.toggleAttribute('data-board-panning', panning)\n }),\n )\n // images dropped on the board or pasted into it\n const root = ctx.root.value\n const onDragOver = (event: DragEvent) => {\n if (ctx.readonly.value || !event.dataTransfer?.types.includes('Files')) return\n event.preventDefault()\n event.dataTransfer.dropEffect = 'copy'\n }\n const onDrop = (event: DragEvent) => {\n const files = imageFiles(event.dataTransfer?.files)\n if (ctx.readonly.value || !files.length) return\n event.preventDefault()\n const at = ctx.toCanvas({ x: event.clientX, y: event.clientY })\n void insertImages(ctx, files, { at })\n }\n const onPaste = (event: ClipboardEvent) => {\n const active = document.activeElement\n if (ctx.readonly.value || !root || !active || !root.contains(active)) return\n // pasting into a field is the field's\n if (active.closest('input, textarea, [contenteditable]')) return\n const files = imageFiles(event.clipboardData?.files)\n if (!files.length) return\n event.preventDefault()\n event.stopImmediatePropagation()\n void insertImages(ctx, files)\n }\n root?.addEventListener('dragover', onDragOver)\n root?.addEventListener('drop', onDrop)\n // before the editor's own paste, which reads nodes from text\n document.addEventListener('paste', onPaste, true)\n return () => {\n for (const stop of stops) stop()\n root?.removeEventListener('dragover', onDragOver)\n root?.removeEventListener('drop', onDrop)\n document.removeEventListener('paste', onPaste, true)\n delete ctx.root.value?.dataset.boardTool\n ctx.root.value?.removeAttribute('data-board-panning')\n }\n },\n\n press(ctx, press) {\n const state = boardState(ctx)\n const tool = state.tool.value\n if (tool === 'select') return\n // while read-only, only moving the view and commenting\n if (ctx.readonly.value && tool !== 'hand' && tool !== 'comment') return\n if (tool === 'comment')\n return pinComment(ctx, press.node?.id ?? null, press.point, press.event)\n // a press puts down whatever text was being typed\n state.editing.value = null\n if (tool === 'hand') {\n const start = { x: press.event.clientX, y: press.event.clientY }\n const origin = { ...ctx.viewport.value }\n state.panning.value = true\n const stop = () => (state.panning.value = false)\n return {\n end: stop,\n cancel: stop,\n move(_, event) {\n ctx.setViewport({\n ...origin,\n x: origin.x + event.clientX - start.x,\n y: origin.y + event.clientY - start.y,\n })\n },\n }\n }\n if (tool === 'pen') return drawInk(ctx, press.event)\n if (tool === 'eraser') return erase(ctx, press.point)\n const start = press.point\n const rectTo = (point: Point, square: boolean) => {\n let width = Math.abs(point.x - start.x)\n let height = Math.abs(point.y - start.y)\n if (square) width = height = Math.max(width, height)\n return {\n x: point.x < start.x ? start.x - width : start.x,\n y: point.y < start.y ? start.y - height : start.y,\n width,\n height,\n }\n }\n const done = (rect: Rect | null) => {\n state.draft.value = null\n if (!rect) return\n const node = nodeFor(tool, rect)\n ctx.transact((tr) => tr.addNode(node))\n ctx.selection.value = { nodes: [node.id], edges: [] }\n ctx.announce(format(ctx.messages.value.added, { node: ctx.messages.value.board[tool] }))\n added(ctx, tool, node.id)\n }\n return {\n move(point, event) {\n state.draft.value = { ...rectTo(point, event.shiftKey), tool }\n },\n end(point, event) {\n const rect = rectTo(point, event.shiftKey)\n const min = 8 / ctx.viewport.value.zoom\n if (rect.width < min && rect.height < min) {\n // a click: the default size, centred where it was clicked\n const size = SIZES[tool]\n done({ x: start.x - size.width / 2, y: start.y - size.height / 2, ...size })\n } else {\n done({\n ...rect,\n width: Math.max(rect.width, 24),\n height: tool === 'text' ? Math.max(rect.height, 40) : Math.max(rect.height, 24),\n })\n }\n },\n cancel: () => done(null),\n }\n },\n\n contextMenu(ctx, target) {\n if (target.kind !== 'node' || ctx.readonly.value) return []\n const t = ctx.messages.value.board\n const items: ContextMenuItem[] = []\n const node = target.node\n if (BOARD_TYPES.has(node.type ?? '') && ctx.selection.value.nodes.length <= 1) {\n const rotation = (node.data?.rotation as number | undefined) ?? 0\n const rotate = (to: number) => {\n ctx.transact((tr) => tr.updateData(node.id, { rotation: to || undefined }))\n ctx.announce(format(t.turned, { degrees: to }))\n }\n items.push(\n {\n key: 'rotate',\n label: t.rotate,\n icon: RotateCwIcon,\n divided: true,\n disabled: !!node.locked,\n run: () => rotate((rotation + 90) % 360),\n },\n {\n key: 'unrotate',\n label: t.unrotate,\n disabled: !rotation || !!node.locked,\n run: () => rotate(0),\n },\n )\n }\n return items\n },\n\n keymap(ctx) {\n const state = boardState(ctx)\n const pick = (tool: WhiteboardTool) => () => {\n if (!usable(ctx, tool)) return false\n state.tool.value = tool\n state.locked.value = false\n const t = ctx.messages.value.board\n ctx.announce(format(t.picked, { tool: t[tool] }))\n }\n const keys: Record<string, () => boolean | void> = {}\n for (const [tool, key] of Object.entries(whiteboardKeys))\n keys[key] = pick(tool as WhiteboardTool)\n return {\n ...keys,\n [imageKey]: () => {\n if (ctx.readonly.value) return false\n pickImages(ctx)\n },\n enter: () => {\n const tool = state.tool.value\n // with the comment tool, Enter starts a thread on the selected node, about all of it\n if (tool === 'comment') {\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length) return false\n return ctx.comment({ node: nodes[0]! }) || false\n }\n if (ctx.readonly.value) return false\n // with a drawing tool, Enter puts one down: after the selected node, or mid-view\n if (tool !== 'select' && tool !== 'hand' && tool !== 'pen' && tool !== 'eraser') {\n const { type, data } = kindOf(tool)\n // text keeps no height, as when drawn\n const size =\n tool === 'text' ? { width: SIZES.text.width, height: undefined } : SIZES[tool]\n // notes and text take focus in their own field\n const writes = tool === 'sticky' || tool === 'text'\n const id = ctx.insertNode(type, { data, size, focus: !writes })\n if (id) added(ctx, tool, id)\n return\n }\n // otherwise it writes in the selected note or shape\n const { nodes, edges } = ctx.selection.value\n if (nodes.length !== 1 || edges.length || ctx.readonly.value) return false\n const node = ctx.doc.value.nodes.find((n) => n.id === nodes[0])\n if (!node || !['shape', 'sticky', 'text'].includes(node.type ?? '')) return false\n state.editing.value = node.id\n },\n escape: () => {\n if (state.tool.value === 'select') return false\n state.tool.value = 'select'\n },\n }\n },\n })\n}\n\nexport { connectorEdge }\n"],"mappings":";;;;;;;;;;;;;;;;;;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M,MAAM,EAAE,OAAO,MAAM,EAAE;KAC9D,IAAI,CAAC,QAAQ,CAAC;MAAC;MAAS;MAAU;KAAM,CAAC,CAAC,SAAS,KAAK,QAAQ,EAAE,GAAG,OAAO;KAC5E,MAAM,QAAQ,QAAQ,KAAK;IAC7B;IACA,cAAc;KACZ,IAAI,MAAM,KAAK,UAAU,UAAU,OAAO;KAC1C,MAAM,KAAK,QAAQ;IACrB;GACF;EACF;CACF,CAAC;AACH"}
|
package/dist/whiteboard/model.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isWhiteboardColor, whiteboardColors } from "./colors.js";
|
|
1
2
|
// src/whiteboard/model.ts
|
|
2
3
|
/** Keys for the tools. */
|
|
3
4
|
var whiteboardKeys = {
|
|
@@ -20,6 +21,6 @@ var anchorSides = [
|
|
|
20
21
|
"bottom",
|
|
21
22
|
"left"
|
|
22
23
|
];
|
|
23
|
-
export { anchorSides, imageKey, whiteboardKeys };
|
|
24
|
+
export { anchorSides, imageKey, isWhiteboardColor, whiteboardColors, whiteboardKeys };
|
|
24
25
|
|
|
25
26
|
//# sourceMappingURL=model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/whiteboard/model.ts"],"sourcesContent":["import type { Tone } from 'dou-ui'\n\n/** What a press on the board does. */\nexport type WhiteboardTool =\n | 'select'\n | 'hand'\n | 'rect'\n | 'ellipse'\n | 'diamond'\n | 'sticky'\n | 'text'\n | 'pen'\n | 'eraser'\n | 'comment'\n\n/** The tools that put down a node with a box. */\nexport type WhiteboardShapeTool = Exclude<\n WhiteboardTool,\n 'select' | 'hand' | 'pen' | 'eraser' | 'comment'\n>\n\nexport type WhiteboardShape = 'rect' | 'ellipse' | 'diamond'\n\n/** What every board node can carry. */\nexport interface WhiteboardNodeData {\n [key: string]: unknown\n /** Degrees clockwise around the node's centre. */\n rotation?: number\n}\n\nexport interface WhiteboardShapeData extends WhiteboardNodeData {\n shape: WhiteboardShape\n text?: string\n /** `neutral` by default. */\n tone?: Tone\n}\n\nexport interface WhiteboardStickyData extends WhiteboardNodeData {\n text?: string\n /** `warning` (yellow) by default. */\n tone?: Tone\n}\n\nexport interface WhiteboardTextData extends WhiteboardNodeData {\n text?: string\n}\n\n/** A pen stroke. */\nexport interface WhiteboardInkData extends WhiteboardNodeData {\n /**\n * The points as `x, y, pressure` triples, flat, in the node's own units:\n * `0, 0` is its top left corner when it is `box` in size.\n */\n points: number[]\n /** The size the points were drawn at; the stroke stretches with the node. */\n box: [number, number]\n /**\n * The stroke's width drawn with a mouse or finger. `4` by default; a pen\n * makes it 0.4 to 1.6 times as wide as it presses lighter or harder.\n */\n size?: number\n /** The text color when left out. */\n tone?: Tone\n}\n\n/** How a connector runs: one straight line, right-angled turns, or a smooth curve. */\nexport type WhiteboardRoute = 'straight' | 'elbow' | 'curve'\nexport type WhiteboardDash = 'solid' | 'dashed' | 'dotted' | 'dash-dot'\n/** Which ends of a connector have an arrowhead. */\nexport type WhiteboardArrow = 'none' | 'end' | 'both'\n\n/** A `connector` edge's look. */\nexport interface WhiteboardConnectorData {\n [key: string]: unknown\n /** `straight` by default. */\n route?: WhiteboardRoute\n /** `solid` by default. */\n dash?: WhiteboardDash\n /** `end` by default. */\n arrow?: WhiteboardArrow\n /** Where an `elbow` connector's middle run sits, from 0 to 1; set by dragging it. */\n bend?: number\n}\n\nexport interface WhiteboardImageData extends WhiteboardNodeData {\n src: string\n /** Read by screen readers. */\n alt?: string\n}\n\n/** Keys for the tools. */\nexport const whiteboardKeys: Record<WhiteboardTool, string> = {\n select: 'v',\n hand: 'h',\n rect: 'r',\n ellipse: 'o',\n diamond: 'd',\n sticky: 's',\n text: 't',\n pen: 'p',\n eraser: 'x',\n comment: 'm',\n}\n\n/** The key that inserts an image. */\nexport const imageKey = 'i'\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n\nexport const anchorSides = SIDES\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/whiteboard/model.ts"],"sourcesContent":["import type { Tone } from 'dou-ui'\nimport type { WhiteboardColor, WhiteboardFill, WhiteboardStroke } from './colors'\n\nexport { whiteboardColors, isWhiteboardColor } from './colors'\nexport type {\n WhiteboardColor,\n WhiteboardFill,\n WhiteboardPaletteColor,\n WhiteboardStroke,\n} from './colors'\n\n/** What a press on the board does. */\nexport type WhiteboardTool =\n | 'select'\n | 'hand'\n | 'rect'\n | 'ellipse'\n | 'diamond'\n | 'sticky'\n | 'text'\n | 'pen'\n | 'eraser'\n | 'comment'\n\n/** The tools that put down a node with a box. */\nexport type WhiteboardShapeTool = Exclude<\n WhiteboardTool,\n 'select' | 'hand' | 'pen' | 'eraser' | 'comment'\n>\n\nexport type WhiteboardShape = 'rect' | 'ellipse' | 'diamond'\n\n/** What every board node can carry. */\nexport interface WhiteboardNodeData {\n [key: string]: unknown\n /** Degrees clockwise around the node's centre. */\n rotation?: number\n}\n\nexport interface WhiteboardShapeData extends WhiteboardNodeData {\n shape: WhiteboardShape\n text?: string\n /** `neutral` by default; kept for compatibility when `fill` / `stroke` are omitted. */\n tone?: Tone\n /** Background fill color, or `'none'` / `'transparent'` for no fill. */\n fill?: WhiteboardFill\n /** Border color, or `'none'` for a borderless shape. */\n stroke?: WhiteboardStroke\n /** Text color inside the shape. */\n textColor?: WhiteboardColor\n}\n\nexport interface WhiteboardStickyData extends WhiteboardNodeData {\n text?: string\n /** `warning` (yellow) by default; kept for compatibility when `fill` is omitted. */\n tone?: Tone\n /** Background color of the sticky note. */\n fill?: WhiteboardFill\n /** Text color inside the sticky note. */\n textColor?: WhiteboardColor\n}\n\nexport interface WhiteboardTextData extends WhiteboardNodeData {\n text?: string\n /** Text color. */\n color?: WhiteboardColor\n}\n\n/** A pen stroke. */\nexport interface WhiteboardInkData extends WhiteboardNodeData {\n /**\n * The points as `x, y, pressure` triples, flat, in the node's own units:\n * `0, 0` is its top left corner when it is `box` in size.\n */\n points: number[]\n /** The size the points were drawn at; the stroke stretches with the node. */\n box: [number, number]\n /**\n * The stroke's width drawn with a mouse or finger. `4` by default; a pen\n * makes it 0.4 to 1.6 times as wide as it presses lighter or harder.\n */\n size?: number\n /** The text color when left out; kept for compatibility when `color` is omitted. */\n tone?: Tone\n /** Stroke color. */\n color?: WhiteboardColor\n}\n\n/** How a connector runs: one straight line, right-angled turns, or a smooth curve. */\nexport type WhiteboardRoute = 'straight' | 'elbow' | 'curve'\nexport type WhiteboardDash = 'solid' | 'dashed' | 'dotted' | 'dash-dot'\n/** Which ends of a connector have an arrowhead. */\nexport type WhiteboardArrow = 'none' | 'end' | 'both'\n\n/** A `connector` edge's look. */\nexport interface WhiteboardConnectorData {\n [key: string]: unknown\n /** `straight` by default. */\n route?: WhiteboardRoute\n /** `solid` by default. */\n dash?: WhiteboardDash\n /** `end` by default. */\n arrow?: WhiteboardArrow\n /** Line and arrowhead color. */\n color?: WhiteboardColor\n /** Where an `elbow` connector's middle run sits, from 0 to 1; set by dragging it. */\n bend?: number\n}\n\nexport interface WhiteboardImageData extends WhiteboardNodeData {\n src: string\n /** Read by screen readers. */\n alt?: string\n}\n\n/** Keys for the tools. */\nexport const whiteboardKeys: Record<WhiteboardTool, string> = {\n select: 'v',\n hand: 'h',\n rect: 'r',\n ellipse: 'o',\n diamond: 'd',\n sticky: 's',\n text: 't',\n pen: 'p',\n eraser: 'x',\n comment: 'm',\n}\n\n/** The key that inserts an image. */\nexport const imageKey = 'i'\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n\nexport const anchorSides = SIDES\n"],"mappings":";;;AAoHA,IAAa,iBAAiD;CAC5D,QAAQ;CACR,MAAM;CACN,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,MAAM;CACN,KAAK;CACL,QAAQ;CACR,SAAS;AACX;;AAGA,IAAa,WAAW;AAIxB,IAAa,cAAc;CAFZ;CAAO;CAAS;CAAU;AAEd"}
|