@ngstarter-ui/components 22.3.2 → 22.3.3
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/ai/component-registry.json +161 -1
- package/fesm2022/ngstarter-ui-components-color-switcher.mjs +2 -2
- package/fesm2022/ngstarter-ui-components-color-switcher.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-tiles.mjs +117 -106
- package/fesm2022/ngstarter-ui-components-tiles.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-timepicker.mjs +3 -2
- package/fesm2022/ngstarter-ui-components-timepicker.mjs.map +1 -1
- package/fesm2022/ngstarter-ui-components-whiteboard.mjs +1868 -0
- package/fesm2022/ngstarter-ui-components-whiteboard.mjs.map +1 -0
- package/package.json +5 -1
- package/types/ngstarter-ui-components-tiles.d.ts +5 -7
- package/types/ngstarter-ui-components-whiteboard.d.ts +350 -0
|
@@ -0,0 +1,1868 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { model, input, booleanAttribute, output, signal, computed, viewChild, inject, NgZone, DestroyRef, effect, afterRenderEffect, afterEveryRender, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { DOCUMENT } from '@angular/common';
|
|
4
|
+
import * as i1 from '@angular/forms';
|
|
5
|
+
import { FormsModule } from '@angular/forms';
|
|
6
|
+
import { Alert } from '@ngstarter-ui/components/alert';
|
|
7
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
|
+
import { Button } from '@ngstarter-ui/components/button';
|
|
9
|
+
import { ButtonToggle, ButtonToggleGroup } from '@ngstarter-ui/components/button-toggle';
|
|
10
|
+
import { Card, CardAside, CardContent, CardHeader } from '@ngstarter-ui/components/card';
|
|
11
|
+
import { ColorPicker, ColorPickerThumbnail, ColorPickerTriggerForDirective } from '@ngstarter-ui/components/color-picker';
|
|
12
|
+
import { ColorSwitcher } from '@ngstarter-ui/components/color-switcher';
|
|
13
|
+
import { ConfirmManager } from '@ngstarter-ui/components/confirm';
|
|
14
|
+
import { Divider } from '@ngstarter-ui/components/divider';
|
|
15
|
+
import { Icon } from '@ngstarter-ui/components/icon';
|
|
16
|
+
import { Input } from '@ngstarter-ui/components/input';
|
|
17
|
+
import { Menu, MenuDivider, MenuItem, MenuTrigger } from '@ngstarter-ui/components/menu';
|
|
18
|
+
import { ScrollbarArea } from '@ngstarter-ui/components/scrollbar-area';
|
|
19
|
+
import { Segmented, SegmentedButton, SegmentedIconDirective } from '@ngstarter-ui/components/segmented';
|
|
20
|
+
import { Slider, SliderThumb } from '@ngstarter-ui/components/slider';
|
|
21
|
+
import { Toolbar } from '@ngstarter-ui/components/toolbar';
|
|
22
|
+
import { Tooltip } from '@ngstarter-ui/components/tooltip';
|
|
23
|
+
import Konva from 'konva';
|
|
24
|
+
import { v7 } from 'uuid';
|
|
25
|
+
|
|
26
|
+
const connectorEnds = ['start', 'end'];
|
|
27
|
+
const bindingKey = { start: 'startBinding', end: 'endBinding' };
|
|
28
|
+
function isConnector(element) {
|
|
29
|
+
return element.type === 'line' || element.type === 'arrow';
|
|
30
|
+
}
|
|
31
|
+
function isBlock(element) {
|
|
32
|
+
return element.width > 0 && element.height > 0 &&
|
|
33
|
+
(element.type === 'rectangle' || element.type === 'ellipse' || element.type === 'diamond' || element.type === 'note');
|
|
34
|
+
}
|
|
35
|
+
function toWorld(element, point) {
|
|
36
|
+
const angle = (element.rotation ?? 0) * Math.PI / 180;
|
|
37
|
+
const cos = Math.cos(angle), sin = Math.sin(angle);
|
|
38
|
+
const x = point.x * (element.scaleX ?? 1), y = point.y * (element.scaleY ?? 1);
|
|
39
|
+
return { x: element.x + x * cos - y * sin, y: element.y + x * sin + y * cos };
|
|
40
|
+
}
|
|
41
|
+
function toLocal(element, point) {
|
|
42
|
+
const angle = (element.rotation ?? 0) * Math.PI / 180;
|
|
43
|
+
const cos = Math.cos(angle), sin = Math.sin(angle);
|
|
44
|
+
const x = point.x - element.x, y = point.y - element.y;
|
|
45
|
+
return { x: (x * cos + y * sin) / (element.scaleX ?? 1), y: (y * cos - x * sin) / (element.scaleY ?? 1) };
|
|
46
|
+
}
|
|
47
|
+
function anchorPoint(block, binding) {
|
|
48
|
+
return toWorld(block, { x: binding.anchor[0] * block.width, y: binding.anchor[1] * block.height });
|
|
49
|
+
}
|
|
50
|
+
function outlineDistance(block, x, y) {
|
|
51
|
+
if (block.type === 'ellipse')
|
|
52
|
+
return Math.hypot(x, y);
|
|
53
|
+
if (block.type === 'diamond')
|
|
54
|
+
return Math.abs(x) + Math.abs(y);
|
|
55
|
+
return Math.max(Math.abs(x), Math.abs(y));
|
|
56
|
+
}
|
|
57
|
+
function cornerRadius(block) {
|
|
58
|
+
return Math.min(block.type === 'note' ? 4 : 8, block.width / 2, block.height / 2);
|
|
59
|
+
}
|
|
60
|
+
function outlineAnchor(block, x, y) {
|
|
61
|
+
if (x === 0 && y === 0)
|
|
62
|
+
x = 1;
|
|
63
|
+
const distance = outlineDistance(block, x, y);
|
|
64
|
+
let u = (1 + x / distance) / 2, v = (1 + y / distance) / 2;
|
|
65
|
+
if (block.type === 'rectangle' || block.type === 'note') {
|
|
66
|
+
const radius = cornerRadius(block);
|
|
67
|
+
const dx = (u - 0.5) * block.width, dy = (v - 0.5) * block.height;
|
|
68
|
+
const cx = Math.sign(dx) * (block.width / 2 - radius);
|
|
69
|
+
const cy = Math.sign(dy) * (block.height / 2 - radius);
|
|
70
|
+
if (Math.abs(dx) > Math.abs(cx) && Math.abs(dy) > Math.abs(cy)) {
|
|
71
|
+
// Where the center ray meets the rounded corner, before it reaches the bounding box.
|
|
72
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
73
|
+
const projection = dx * cx + dy * cy;
|
|
74
|
+
const offset = cx * cx + cy * cy - radius * radius;
|
|
75
|
+
const t = (projection + Math.sqrt(Math.max(0, projection * projection - lengthSquared * offset))) / lengthSquared;
|
|
76
|
+
u = 0.5 + (u - 0.5) * t;
|
|
77
|
+
v = 0.5 + (v - 0.5) * t;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { elementId: block.id, anchor: [Math.max(0, Math.min(1, u)), Math.max(0, Math.min(1, v))] };
|
|
81
|
+
}
|
|
82
|
+
function facingAnchor(block, other) {
|
|
83
|
+
const local = toLocal(block, other);
|
|
84
|
+
return outlineAnchor(block, 2 * local.x / block.width - 1, 2 * local.y / block.height - 1);
|
|
85
|
+
}
|
|
86
|
+
/** A segment starting on a convex outline stays outside if it leaves along the tangent or outward. */
|
|
87
|
+
function canReach(block, binding, other) {
|
|
88
|
+
const tolerance = 1e-7;
|
|
89
|
+
const local = toLocal(block, other);
|
|
90
|
+
const [u, v] = binding.anchor;
|
|
91
|
+
if (block.type === 'rectangle' || block.type === 'note') {
|
|
92
|
+
const radius = cornerRadius(block);
|
|
93
|
+
const x = u * block.width, y = v * block.height;
|
|
94
|
+
const nx = x - Math.max(radius, Math.min(block.width - radius, x));
|
|
95
|
+
const ny = y - Math.max(radius, Math.min(block.height - radius, y));
|
|
96
|
+
return Math.hypot(nx, ny) >= radius - tolerance && nx * (local.x - x) + ny * (local.y - y) >= -tolerance;
|
|
97
|
+
}
|
|
98
|
+
const x = 2 * u - 1, y = 2 * v - 1;
|
|
99
|
+
if (outlineDistance(block, x, y) < 1 - tolerance)
|
|
100
|
+
return false;
|
|
101
|
+
const dx = 2 * local.x / block.width - 1 - x, dy = 2 * local.y / block.height - 1 - y;
|
|
102
|
+
if (block.type === 'ellipse')
|
|
103
|
+
return x * dx + y * dy >= -tolerance;
|
|
104
|
+
// At a diamond vertex, either adjoining edge can be the outward side.
|
|
105
|
+
const alongX = Math.abs(x) < tolerance ? Math.abs(dx) : Math.sign(x) * dx;
|
|
106
|
+
const alongY = Math.abs(y) < tolerance ? Math.abs(dy) : Math.sign(y) * dy;
|
|
107
|
+
return alongX + alongY >= -tolerance;
|
|
108
|
+
}
|
|
109
|
+
function findBinding(elements, point, other, tolerance, exclude) {
|
|
110
|
+
let best;
|
|
111
|
+
for (let i = elements.length - 1; i >= 0; i--) {
|
|
112
|
+
const block = elements[i];
|
|
113
|
+
if (block.id === exclude || block.opacity === 0 || !isBlock(block))
|
|
114
|
+
continue;
|
|
115
|
+
const local = toLocal(block, point);
|
|
116
|
+
const x = 2 * local.x / block.width - 1, y = 2 * local.y / block.height - 1;
|
|
117
|
+
const inside = outlineDistance(block, x, y) <= 1;
|
|
118
|
+
let binding = outlineAnchor(block, x, y);
|
|
119
|
+
let snap = anchorPoint(block, binding);
|
|
120
|
+
const distance = Math.hypot(snap.x - point.x, snap.y - point.y);
|
|
121
|
+
if (inside) {
|
|
122
|
+
if (distance > tolerance || (x === 0 && y === 0)) {
|
|
123
|
+
binding = facingAnchor(block, other);
|
|
124
|
+
snap = anchorPoint(block, binding);
|
|
125
|
+
}
|
|
126
|
+
return { binding, point: snap };
|
|
127
|
+
}
|
|
128
|
+
if (distance <= tolerance && (!best || distance < best.distance))
|
|
129
|
+
best = { binding, point: snap, distance };
|
|
130
|
+
}
|
|
131
|
+
return best;
|
|
132
|
+
}
|
|
133
|
+
function connectorEndPoint(element, end) {
|
|
134
|
+
const points = element.points;
|
|
135
|
+
const index = end === 'start' ? 0 : points.length - 2;
|
|
136
|
+
return toWorld(element, { x: points[index], y: points[index + 1] });
|
|
137
|
+
}
|
|
138
|
+
function connectorBendPoint(element) {
|
|
139
|
+
const [x1, y1, x2, y2] = element.points;
|
|
140
|
+
const [x, y] = element.bend ?? [(x1 + x2) / 2, (y1 + y2) / 2];
|
|
141
|
+
return toWorld(element, { x, y });
|
|
142
|
+
}
|
|
143
|
+
/** A quadratic through the bend at t=0.5, expressed as a cubic for Konva. */
|
|
144
|
+
function curveControl(start, bend, end) {
|
|
145
|
+
return { x: 2 * bend.x - (start.x + end.x) / 2, y: 2 * bend.y - (start.y + end.y) / 2 };
|
|
146
|
+
}
|
|
147
|
+
function connectorPath(element) {
|
|
148
|
+
const points = [...element.points ?? []];
|
|
149
|
+
if (!element.bend || points.length !== 4)
|
|
150
|
+
return { points, bezier: false };
|
|
151
|
+
const [x1, y1, x2, y2] = points, [x, y] = element.bend;
|
|
152
|
+
const control = curveControl({ x: x1, y: y1 }, { x, y }, { x: x2, y: y2 });
|
|
153
|
+
return { points: [
|
|
154
|
+
x1, y1, (x1 + 2 * control.x) / 3, (y1 + 2 * control.y) / 3,
|
|
155
|
+
(x2 + 2 * control.x) / 3, (y2 + 2 * control.y) / 3, x2, y2,
|
|
156
|
+
], bezier: true };
|
|
157
|
+
}
|
|
158
|
+
function setConnectorBend(element, point) {
|
|
159
|
+
if (!point && !element.bend)
|
|
160
|
+
return element;
|
|
161
|
+
const local = point && toLocal(element, point);
|
|
162
|
+
return withConnectorSize({ ...element, bend: local && [local.x, local.y] }, element.points);
|
|
163
|
+
}
|
|
164
|
+
function setConnectorEnds(element, start, end) {
|
|
165
|
+
if (!start && !end)
|
|
166
|
+
return element;
|
|
167
|
+
const points = [...element.points];
|
|
168
|
+
if (start) {
|
|
169
|
+
const local = toLocal(element, start);
|
|
170
|
+
points[0] = local.x;
|
|
171
|
+
points[1] = local.y;
|
|
172
|
+
}
|
|
173
|
+
if (end) {
|
|
174
|
+
const local = toLocal(element, end);
|
|
175
|
+
points[points.length - 2] = local.x;
|
|
176
|
+
points[points.length - 1] = local.y;
|
|
177
|
+
}
|
|
178
|
+
return withConnectorSize(element, points);
|
|
179
|
+
}
|
|
180
|
+
function withConnectorSize(element, points) {
|
|
181
|
+
let minX = element.bend?.[0] ?? points[0], maxX = minX, minY = element.bend?.[1] ?? points[1], maxY = minY;
|
|
182
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
183
|
+
minX = Math.min(minX, points[i]);
|
|
184
|
+
maxX = Math.max(maxX, points[i]);
|
|
185
|
+
minY = Math.min(minY, points[i + 1]);
|
|
186
|
+
maxY = Math.max(maxY, points[i + 1]);
|
|
187
|
+
}
|
|
188
|
+
return { ...element, points, width: maxX - minX, height: maxY - minY };
|
|
189
|
+
}
|
|
190
|
+
function resolveConnector(element, getBlock) {
|
|
191
|
+
if (!isConnector(element) || !element.points || (!element.startBinding && !element.endBinding))
|
|
192
|
+
return element;
|
|
193
|
+
const start = element.startBinding && getBlock(element.startBinding.elementId);
|
|
194
|
+
const end = element.endBinding && getBlock(element.endBinding.elementId);
|
|
195
|
+
let startBinding = start && isBlock(start) ? element.startBinding : undefined;
|
|
196
|
+
let endBinding = end && isBlock(end) ? element.endBinding : undefined;
|
|
197
|
+
let startPoint = start && startBinding ? anchorPoint(start, startBinding) : connectorEndPoint(element, 'start');
|
|
198
|
+
let endPoint = end && endBinding ? anchorPoint(end, endBinding) : connectorEndPoint(element, 'end');
|
|
199
|
+
const bend = element.bend && connectorBendPoint(element);
|
|
200
|
+
const control = bend && curveControl(startPoint, bend, endPoint);
|
|
201
|
+
if (element.points.length === 4 &&
|
|
202
|
+
((start && startBinding && !canReach(start, startBinding, control ?? endPoint)) ||
|
|
203
|
+
(end && endBinding && !canReach(end, endBinding, control ?? startPoint)))) {
|
|
204
|
+
// Use a guide independent of the current anchors so resolving again keeps the same sides.
|
|
205
|
+
const startCenter = start && startBinding ? toWorld(start, { x: start.width / 2, y: start.height / 2 }) : startPoint;
|
|
206
|
+
const endCenter = end && endBinding ? toWorld(end, { x: end.width / 2, y: end.height / 2 }) : endPoint;
|
|
207
|
+
const guide = bend && curveControl(startCenter, bend, endCenter);
|
|
208
|
+
if (start && startBinding) {
|
|
209
|
+
startBinding = facingAnchor(start, guide ?? endCenter);
|
|
210
|
+
startPoint = anchorPoint(start, startBinding);
|
|
211
|
+
}
|
|
212
|
+
if (end && endBinding) {
|
|
213
|
+
endBinding = facingAnchor(end, guide ?? startCenter);
|
|
214
|
+
endPoint = anchorPoint(end, endBinding);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return setConnectorEnds({ ...element, startBinding, endBinding }, startBinding ? startPoint : undefined, endBinding ? endPoint : undefined);
|
|
218
|
+
}
|
|
219
|
+
/** When the blocks overlap along the connector, there may be no visible path. */
|
|
220
|
+
function isConnectorObscured(element, getBlock) {
|
|
221
|
+
if (!isConnector(element) || element.points?.length !== 4 || (!element.startBinding && !element.endBinding))
|
|
222
|
+
return false;
|
|
223
|
+
const startPoint = connectorEndPoint(element, 'start'), endPoint = connectorEndPoint(element, 'end');
|
|
224
|
+
if (!element.bend && Math.hypot(endPoint.x - startPoint.x, endPoint.y - startPoint.y) < 1e-7)
|
|
225
|
+
return true;
|
|
226
|
+
const start = element.startBinding && getBlock(element.startBinding.elementId);
|
|
227
|
+
const end = element.endBinding && getBlock(element.endBinding.elementId);
|
|
228
|
+
const control = element.bend && curveControl(startPoint, connectorBendPoint(element), endPoint);
|
|
229
|
+
return !!((start && element.startBinding && !canReach(start, element.startBinding, control ?? endPoint)) ||
|
|
230
|
+
(end && element.endBinding && !canReach(end, element.endBinding, control ?? startPoint)));
|
|
231
|
+
}
|
|
232
|
+
function resolveBindings(elements) {
|
|
233
|
+
if (!elements.some(element => element.startBinding || element.endBinding))
|
|
234
|
+
return elements;
|
|
235
|
+
const byId = new Map(elements.map(element => [element.id, element]));
|
|
236
|
+
return elements.map(element => resolveConnector(element, id => byId.get(id)));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const elementTypes = new Set(['pencil', 'rectangle', 'diamond', 'ellipse', 'arrow', 'line', 'text', 'note']);
|
|
240
|
+
function parseBinding(value) {
|
|
241
|
+
if (value === undefined)
|
|
242
|
+
return undefined;
|
|
243
|
+
if (!value || typeof value !== 'object' || !('elementId' in value) || typeof value.elementId !== 'string' || !value.elementId ||
|
|
244
|
+
!('anchor' in value) || !Array.isArray(value.anchor) || value.anchor.length !== 2 ||
|
|
245
|
+
!value.anchor.every(point => typeof point === 'number' && Number.isFinite(point) && point >= 0 && point <= 1)) {
|
|
246
|
+
throw new Error('Invalid whiteboard connector binding.');
|
|
247
|
+
}
|
|
248
|
+
return { elementId: value.elementId, anchor: [value.anchor[0], value.anchor[1]] };
|
|
249
|
+
}
|
|
250
|
+
/** Parses the portable data format, never Konva's executable scene graph. */
|
|
251
|
+
function parseWhiteboardDocument(json) {
|
|
252
|
+
const value = JSON.parse(json);
|
|
253
|
+
if (!value || typeof value !== 'object' || !('version' in value) || value.version !== 1 ||
|
|
254
|
+
!('elements' in value) || !Array.isArray(value.elements) || value.elements.length > 10000) {
|
|
255
|
+
throw new Error('Invalid whiteboard document.');
|
|
256
|
+
}
|
|
257
|
+
const ids = new Set();
|
|
258
|
+
const elements = value.elements.map((item) => {
|
|
259
|
+
if (!item || typeof item !== 'object')
|
|
260
|
+
throw new Error('Invalid whiteboard element.');
|
|
261
|
+
const e = item;
|
|
262
|
+
const finite = (key) => typeof e[key] === 'number' && Number.isFinite(e[key]);
|
|
263
|
+
if (typeof e['id'] !== 'string' || !e['id'] || ids.has(e['id']) ||
|
|
264
|
+
typeof e['type'] !== 'string' || !elementTypes.has(e['type']) ||
|
|
265
|
+
!['x', 'y', 'width', 'height', 'strokeWidth', 'opacity', 'fontSize'].every(finite) ||
|
|
266
|
+
e['width'] < 0 || e['height'] < 0 ||
|
|
267
|
+
e['strokeWidth'] <= 0 || e['fontSize'] <= 0 ||
|
|
268
|
+
e['opacity'] < 0 || e['opacity'] > 1 ||
|
|
269
|
+
typeof e['stroke'] !== 'string' || typeof e['fill'] !== 'string' ||
|
|
270
|
+
!['solid', 'dashed', 'dotted'].includes(e['lineStyle']) ||
|
|
271
|
+
['rotation', 'scaleX', 'scaleY'].some(key => e[key] !== undefined && !finite(key)) ||
|
|
272
|
+
['scaleX', 'scaleY'].some(key => e[key] !== undefined && e[key] <= 0) ||
|
|
273
|
+
(e['text'] !== undefined && typeof e['text'] !== 'string') ||
|
|
274
|
+
(e['fontFamily'] !== undefined && typeof e['fontFamily'] !== 'string') ||
|
|
275
|
+
(e['textAlign'] !== undefined && !['left', 'center', 'right'].includes(e['textAlign']))) {
|
|
276
|
+
throw new Error('Invalid whiteboard element.');
|
|
277
|
+
}
|
|
278
|
+
const path = ['pencil', 'line', 'arrow'].includes(e['type']);
|
|
279
|
+
if (path && (!Array.isArray(e['points']) || e['points'].length < 4 ||
|
|
280
|
+
e['points'].length % 2 !== 0 || e['points'].length > 200000 ||
|
|
281
|
+
!e['points'].every((n) => typeof n === 'number' && Number.isFinite(n)))) {
|
|
282
|
+
throw new Error('Invalid whiteboard path.');
|
|
283
|
+
}
|
|
284
|
+
if (e['pressures'] !== undefined && (e['type'] !== 'pencil' || !Array.isArray(e['pressures']) ||
|
|
285
|
+
!Array.isArray(e['points']) || e['pressures'].length !== e['points'].length / 2 ||
|
|
286
|
+
!e['pressures'].every((p) => typeof p === 'number' && Number.isFinite(p) && p >= 0 && p <= 1))) {
|
|
287
|
+
throw new Error('Invalid whiteboard pen pressure.');
|
|
288
|
+
}
|
|
289
|
+
const connector = e['type'] === 'line' || e['type'] === 'arrow';
|
|
290
|
+
const bend = e['bend'];
|
|
291
|
+
if (bend !== undefined && (!connector || e['points'].length !== 4 ||
|
|
292
|
+
!Array.isArray(bend) || bend.length !== 2 ||
|
|
293
|
+
!bend.every(point => typeof point === 'number' && Number.isFinite(point)))) {
|
|
294
|
+
throw new Error('Invalid whiteboard connector bend.');
|
|
295
|
+
}
|
|
296
|
+
const startBinding = connector ? parseBinding(e['startBinding']) : undefined;
|
|
297
|
+
const endBinding = connector ? parseBinding(e['endBinding']) : undefined;
|
|
298
|
+
ids.add(e['id']);
|
|
299
|
+
// Pick known fields so imported metadata cannot become Konva attributes or event handlers.
|
|
300
|
+
return {
|
|
301
|
+
id: e['id'], type: e['type'],
|
|
302
|
+
x: e['x'], y: e['y'],
|
|
303
|
+
width: e['width'], height: e['height'],
|
|
304
|
+
stroke: e['stroke'], fill: e['fill'], strokeWidth: e['strokeWidth'],
|
|
305
|
+
opacity: e['opacity'], lineStyle: e['lineStyle'],
|
|
306
|
+
fontSize: e['fontSize'],
|
|
307
|
+
rotation: e['rotation'],
|
|
308
|
+
scaleX: e['scaleX'], scaleY: e['scaleY'],
|
|
309
|
+
...(path ? { points: [...e['points']] } : {}),
|
|
310
|
+
...(Array.isArray(bend) ? { bend: [bend[0], bend[1]] } : {}),
|
|
311
|
+
...(startBinding ? { startBinding } : {}),
|
|
312
|
+
...(endBinding ? { endBinding } : {}),
|
|
313
|
+
...(e['text'] === undefined ? {} : { text: e['text'] }),
|
|
314
|
+
...(e['pressures'] === undefined ? {} : { pressures: [...e['pressures']] }),
|
|
315
|
+
...(e['fontFamily'] === undefined ? {} : { fontFamily: e['fontFamily'] }),
|
|
316
|
+
...(e['textAlign'] === undefined ? {} : { textAlign: e['textAlign'] }),
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
return { version: 1, elements: resolveBindings(elements) };
|
|
320
|
+
}
|
|
321
|
+
/** Keep the canvas point under the pointer stationary while changing scale. */
|
|
322
|
+
function zoomWhiteboardAt(view, point, zoom) {
|
|
323
|
+
const next = Math.max(0.1, Math.min(5, zoom));
|
|
324
|
+
return {
|
|
325
|
+
x: point.x - (point.x - view.x) / view.zoom * next,
|
|
326
|
+
y: point.y - (point.y - view.y) / view.zoom * next,
|
|
327
|
+
zoom: next,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/** Bounded document history; viewport changes deliberately do not create undo entries. */
|
|
331
|
+
class WhiteboardHistory {
|
|
332
|
+
current;
|
|
333
|
+
limit;
|
|
334
|
+
past = [];
|
|
335
|
+
future = [];
|
|
336
|
+
constructor(current, limit = 100) {
|
|
337
|
+
this.current = current;
|
|
338
|
+
this.limit = limit;
|
|
339
|
+
}
|
|
340
|
+
get canUndo() { return this.past.length > 0; }
|
|
341
|
+
get canRedo() { return this.future.length > 0; }
|
|
342
|
+
reset(document) {
|
|
343
|
+
this.current = document;
|
|
344
|
+
this.past = [];
|
|
345
|
+
this.future = [];
|
|
346
|
+
}
|
|
347
|
+
commit(elements) {
|
|
348
|
+
this.past.push(this.current);
|
|
349
|
+
if (this.past.length > this.limit)
|
|
350
|
+
this.past.shift();
|
|
351
|
+
this.current = { version: 1, elements };
|
|
352
|
+
this.future = [];
|
|
353
|
+
}
|
|
354
|
+
undo() {
|
|
355
|
+
const previous = this.past.pop();
|
|
356
|
+
if (!previous)
|
|
357
|
+
return;
|
|
358
|
+
this.future.push(this.current);
|
|
359
|
+
this.current = previous;
|
|
360
|
+
}
|
|
361
|
+
redo() {
|
|
362
|
+
const next = this.future.pop();
|
|
363
|
+
if (!next)
|
|
364
|
+
return;
|
|
365
|
+
this.past.push(this.current);
|
|
366
|
+
this.current = next;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const bindingSnapDistance = 14;
|
|
371
|
+
const selectionHandleSize = 9;
|
|
372
|
+
const selectionPadding = 5;
|
|
373
|
+
const eraserTrailDuration = 160;
|
|
374
|
+
const eraserTrailRadius = 5;
|
|
375
|
+
const noteTextPadding = 16;
|
|
376
|
+
const textLineHeight = 1.4;
|
|
377
|
+
const textCaretSpace = 2;
|
|
378
|
+
const whiteboardFontFamily = 'DM Sans, sans-serif';
|
|
379
|
+
function hasWhiteboardText(element) {
|
|
380
|
+
return element.type === 'text' || element.type === 'note' ||
|
|
381
|
+
(element.type === 'rectangle' && !!element.text?.trim());
|
|
382
|
+
}
|
|
383
|
+
function canEditText(element) {
|
|
384
|
+
return element.type === 'rectangle' || hasWhiteboardText(element);
|
|
385
|
+
}
|
|
386
|
+
function arrowHead(element) {
|
|
387
|
+
const points = element.points;
|
|
388
|
+
const [x, y] = element.bend ?? points ?? [];
|
|
389
|
+
const length = points?.length === 4 && (element.startBinding || element.endBinding)
|
|
390
|
+
? Math.min(12, Math.hypot(points[2] - x, points[3] - y))
|
|
391
|
+
: 12;
|
|
392
|
+
return { pointerLength: length, pointerWidth: length * 10 / 12 };
|
|
393
|
+
}
|
|
394
|
+
/** Browser-only canvas mechanics, kept separate from Angular controls and portable data. */
|
|
395
|
+
class WhiteboardEngine {
|
|
396
|
+
callbacks;
|
|
397
|
+
stage;
|
|
398
|
+
layer = new Konva.Layer();
|
|
399
|
+
ui = new Konva.Layer();
|
|
400
|
+
eraserTrail = new Konva.Line({
|
|
401
|
+
name: 'eraser-trail', visible: false, listening: false, closed: true, tension: 0.4, opacity: 0.24,
|
|
402
|
+
});
|
|
403
|
+
eraserTrailAnimation = new Konva.Animation(() => this.drawEraserTrail(), this.ui);
|
|
404
|
+
transformer;
|
|
405
|
+
marquee = new Konva.Rect({ visible: false, listening: false, fill: '#245bff18', stroke: '#245bff', strokeWidth: 1 });
|
|
406
|
+
connectorHandles = {
|
|
407
|
+
start: new Konva.Circle({ name: 'connector-start', visible: false, fill: '#ffffff', stroke: '#245bff' }),
|
|
408
|
+
end: new Konva.Circle({ name: 'connector-end', visible: false, fill: '#ffffff', stroke: '#245bff' }),
|
|
409
|
+
bend: new Konva.Circle({ name: 'connector-bend', visible: false, fill: '#245bff', stroke: '#245bff' }),
|
|
410
|
+
};
|
|
411
|
+
bindingHints = {
|
|
412
|
+
start: new Konva.Circle({ visible: false, listening: false, stroke: '#245bff', fill: '#245bff22' }),
|
|
413
|
+
end: new Konva.Circle({ visible: false, listening: false, stroke: '#245bff', fill: '#245bff22' }),
|
|
414
|
+
};
|
|
415
|
+
history;
|
|
416
|
+
nodes = new Map();
|
|
417
|
+
elements = new Map();
|
|
418
|
+
connected = [];
|
|
419
|
+
selection = new Set();
|
|
420
|
+
tool = 'select';
|
|
421
|
+
readonlyMode = false;
|
|
422
|
+
space = false;
|
|
423
|
+
draft;
|
|
424
|
+
draftNode;
|
|
425
|
+
textEdit;
|
|
426
|
+
notePreview;
|
|
427
|
+
start;
|
|
428
|
+
pan;
|
|
429
|
+
erased = new Set();
|
|
430
|
+
lastErasePoint;
|
|
431
|
+
eraserTrailPoints = [];
|
|
432
|
+
move;
|
|
433
|
+
connectorEdit;
|
|
434
|
+
pointerId;
|
|
435
|
+
lastMoveEnd = -Infinity;
|
|
436
|
+
toolLocked = true;
|
|
437
|
+
pressureSensitive = false;
|
|
438
|
+
cancelPointer = (event) => {
|
|
439
|
+
if (event.type === 'lostpointercapture' && event.target !== this.stage.content)
|
|
440
|
+
return;
|
|
441
|
+
if (event.pointerId === this.pointerId)
|
|
442
|
+
this.cancelGesture();
|
|
443
|
+
};
|
|
444
|
+
style = { stroke: '#245bff', fill: 'transparent', strokeWidth: 2, opacity: 1, lineStyle: 'solid', fontSize: 24 };
|
|
445
|
+
constructor(container, document, callbacks) {
|
|
446
|
+
this.callbacks = callbacks;
|
|
447
|
+
this.history = new WhiteboardHistory({ ...document, elements: resolveBindings(document.elements) });
|
|
448
|
+
this.stage = new Konva.Stage({ container, width: Math.max(container.clientWidth, 1), height: Math.max(container.clientHeight, 1) });
|
|
449
|
+
this.stage.add(this.layer, this.ui);
|
|
450
|
+
// Konva keeps Transformer controls in screen coordinates, independent of stage zoom.
|
|
451
|
+
this.transformer = new Konva.Transformer({
|
|
452
|
+
flipEnabled: false, rotateEnabled: true, rotateLineVisible: false, borderStroke: '#245bff', anchorStroke: '#245bff',
|
|
453
|
+
anchorFill: '#ffffff', anchorSize: selectionHandleSize, anchorCornerRadius: selectionHandleSize / 2, padding: selectionPadding,
|
|
454
|
+
enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right'],
|
|
455
|
+
rotateAnchorOffset: 24 + 2 * selectionPadding,
|
|
456
|
+
anchorStyleFunc: anchor => anchor.hitStrokeWidth(10),
|
|
457
|
+
boundBoxFunc: (oldBox, box) => box.width < Math.min(8, oldBox.width) || box.height < Math.min(8, oldBox.height) ? oldBox : box,
|
|
458
|
+
});
|
|
459
|
+
// Draw behind the rotation handle and end at the padded selection border.
|
|
460
|
+
const transformer = this.transformer;
|
|
461
|
+
const rotationStem = new Konva.Shape({
|
|
462
|
+
listening: false, stroke: transformer.borderStroke(), strokeWidth: transformer.borderStrokeWidth(),
|
|
463
|
+
sceneFunc: (context, shape) => {
|
|
464
|
+
if (!transformer.nodes().length)
|
|
465
|
+
return;
|
|
466
|
+
const [a, b, c, d, x, y] = shape.getAbsoluteTransform().copy().invert()
|
|
467
|
+
.multiply(transformer.getAbsoluteTransform()).getMatrix();
|
|
468
|
+
context.transform(a, b, c, d, x, y);
|
|
469
|
+
const center = transformer.width() / 2;
|
|
470
|
+
const padding = transformer.padding();
|
|
471
|
+
context.beginPath();
|
|
472
|
+
context.moveTo(center, padding - transformer.rotateAnchorOffset());
|
|
473
|
+
context.lineTo(center, -padding);
|
|
474
|
+
context.strokeShape(shape);
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
this.ui.add(this.marquee, rotationStem, transformer, ...Object.values(this.bindingHints), ...Object.values(this.connectorHandles), this.eraserTrail);
|
|
478
|
+
// Konva translates native pointercancel into pointerup on hit shapes. Cancel first,
|
|
479
|
+
// including when the pointer is over empty canvas, so interrupted strokes are never saved.
|
|
480
|
+
this.stage.content.addEventListener('pointercancel', this.cancelPointer, true);
|
|
481
|
+
this.stage.content.addEventListener('lostpointercapture', this.cancelPointer);
|
|
482
|
+
this.transformer.on('transform', () => this.refreshConnections());
|
|
483
|
+
this.transformer.on('transformend', () => this.commitTransforms());
|
|
484
|
+
this.stage.on('pointerdown', (e) => this.pointerDown(e));
|
|
485
|
+
this.stage.on('pointermove', (e) => this.pointerMove(e.evt));
|
|
486
|
+
this.stage.on('pointerup', (e) => this.pointerUp(e.evt));
|
|
487
|
+
this.stage.on('wheel', (e) => {
|
|
488
|
+
e.evt.preventDefault();
|
|
489
|
+
const p = this.stage.getPointerPosition();
|
|
490
|
+
if (!p || this.pointerId !== undefined || this.transformer.isTransforming())
|
|
491
|
+
return;
|
|
492
|
+
if (e.evt.ctrlKey || e.evt.metaKey) {
|
|
493
|
+
this.setViewport(zoomWhiteboardAt(this.viewport, p, this.viewport.zoom * Math.exp(-e.evt.deltaY * 0.01)));
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
this.setViewport({ ...this.viewport, x: this.stage.x() - e.evt.deltaX, y: this.stage.y() - e.evt.deltaY });
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
this.stage.on('pointerdblclick dblclick dbltap', e => {
|
|
500
|
+
if (this.readonlyMode || this.tool !== 'select' || e.evt.timeStamp - this.lastMoveEnd < Konva.dblClickWindow)
|
|
501
|
+
return;
|
|
502
|
+
const element = this.elementFromNode(e.target);
|
|
503
|
+
if (element && canEditText(element)) {
|
|
504
|
+
this.callbacks.editText({ point: { x: element.x, y: element.y }, type: element.type === 'note' ? 'note' : 'text', element });
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
this.render();
|
|
508
|
+
}
|
|
509
|
+
get document() { return this.history.current; }
|
|
510
|
+
get viewport() { return { x: this.stage.x(), y: this.stage.y(), zoom: this.stage.scaleX() }; }
|
|
511
|
+
setDocument(document) {
|
|
512
|
+
this.finishTextEdit();
|
|
513
|
+
this.cancelGesture();
|
|
514
|
+
this.history.reset({ ...document, elements: resolveBindings(document.elements) });
|
|
515
|
+
this.selection.clear();
|
|
516
|
+
this.render();
|
|
517
|
+
this.emitSelection();
|
|
518
|
+
}
|
|
519
|
+
resize(width, height) { this.stage.size({ width: Math.max(1, width), height: Math.max(1, height) }); }
|
|
520
|
+
redraw() { this.layer.draw(); this.ui.draw(); }
|
|
521
|
+
setTool(tool) {
|
|
522
|
+
if (tool === this.tool)
|
|
523
|
+
return;
|
|
524
|
+
this.cancelGesture();
|
|
525
|
+
this.tool = tool;
|
|
526
|
+
if (tool !== 'select')
|
|
527
|
+
this.selection.clear();
|
|
528
|
+
this.updateInteraction();
|
|
529
|
+
this.emitSelection();
|
|
530
|
+
}
|
|
531
|
+
setReadonly(value) {
|
|
532
|
+
if (value)
|
|
533
|
+
this.finishTextEdit();
|
|
534
|
+
this.cancelGesture();
|
|
535
|
+
this.readonlyMode = value;
|
|
536
|
+
this.updateInteraction();
|
|
537
|
+
}
|
|
538
|
+
setSpace(value) {
|
|
539
|
+
if (value === this.space)
|
|
540
|
+
return;
|
|
541
|
+
if (value && !this.pan)
|
|
542
|
+
this.cancelGesture();
|
|
543
|
+
this.space = value;
|
|
544
|
+
this.updateInteraction();
|
|
545
|
+
}
|
|
546
|
+
setViewport(view) {
|
|
547
|
+
if (this.start || this.move || this.connectorEdit)
|
|
548
|
+
this.cancelGesture();
|
|
549
|
+
const current = this.viewport;
|
|
550
|
+
if (view.x === current.x && view.y === current.y && view.zoom === current.zoom)
|
|
551
|
+
return;
|
|
552
|
+
this.stage.position({ x: view.x, y: view.y });
|
|
553
|
+
this.stage.scale({ x: view.zoom, y: view.zoom });
|
|
554
|
+
// The trail follows screen coordinates independently of the document viewport.
|
|
555
|
+
this.eraserTrail.setAttrs({
|
|
556
|
+
x: -view.x / view.zoom, y: -view.y / view.zoom, scaleX: 1 / view.zoom, scaleY: 1 / view.zoom,
|
|
557
|
+
});
|
|
558
|
+
this.marquee.strokeWidth(1 / view.zoom);
|
|
559
|
+
this.updateConnectorHandles();
|
|
560
|
+
this.callbacks.viewport(this.viewport);
|
|
561
|
+
}
|
|
562
|
+
zoom(factor) {
|
|
563
|
+
this.setViewport(zoomWhiteboardAt(this.viewport, { x: this.stage.width() / 2, y: this.stage.height() / 2 }, this.viewport.zoom * factor));
|
|
564
|
+
}
|
|
565
|
+
fitToContent() {
|
|
566
|
+
if (!this.document.elements.length) {
|
|
567
|
+
this.setViewport({ x: 0, y: 0, zoom: 1 });
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const bounds = this.layer.getClientRect({ relativeTo: this.stage });
|
|
571
|
+
const zoom = Math.max(0.1, Math.min(2, (this.stage.width() - 96) / Math.max(bounds.width, 1), (this.stage.height() - 144) / Math.max(bounds.height, 1)));
|
|
572
|
+
this.setViewport({ x: this.stage.width() / 2 - (bounds.x + bounds.width / 2) * zoom, y: this.stage.height() / 2 - (bounds.y + bounds.height / 2) * zoom, zoom });
|
|
573
|
+
}
|
|
574
|
+
undo() { if (!this.readonlyMode && this.history.canUndo) {
|
|
575
|
+
this.cancelGesture();
|
|
576
|
+
this.history.undo();
|
|
577
|
+
this.changed();
|
|
578
|
+
} }
|
|
579
|
+
redo() { if (!this.readonlyMode && this.history.canRedo) {
|
|
580
|
+
this.cancelGesture();
|
|
581
|
+
this.history.redo();
|
|
582
|
+
this.changed();
|
|
583
|
+
} }
|
|
584
|
+
clear() { if (!this.readonlyMode && this.document.elements.length)
|
|
585
|
+
this.commit([]); }
|
|
586
|
+
deleteSelection() {
|
|
587
|
+
if (this.selection.size)
|
|
588
|
+
this.commit(this.document.elements.filter(e => !this.selection.has(e.id)));
|
|
589
|
+
}
|
|
590
|
+
duplicateSelection() {
|
|
591
|
+
if (this.readonlyMode || !this.selection.size)
|
|
592
|
+
return;
|
|
593
|
+
const originals = this.document.elements.filter(e => this.selection.has(e.id));
|
|
594
|
+
const ids = new Map(originals.map(element => [element.id, v7()]));
|
|
595
|
+
const copies = originals.map(element => {
|
|
596
|
+
const copy = { ...element, id: ids.get(element.id), x: element.x + 24, y: element.y + 24 };
|
|
597
|
+
for (const end of connectorEnds) {
|
|
598
|
+
const key = bindingKey[end], binding = copy[key];
|
|
599
|
+
if (!binding)
|
|
600
|
+
continue;
|
|
601
|
+
const elementId = ids.get(binding.elementId);
|
|
602
|
+
copy[key] = elementId ? { ...binding, elementId } : undefined;
|
|
603
|
+
}
|
|
604
|
+
return copy;
|
|
605
|
+
});
|
|
606
|
+
this.selection = new Set(copies.map(e => e.id));
|
|
607
|
+
this.commit([...this.document.elements, ...copies]);
|
|
608
|
+
}
|
|
609
|
+
selectAll() { this.selection = new Set(this.document.elements.map(e => e.id)); this.updateInteraction(); this.emitSelection(); }
|
|
610
|
+
deselect() { this.cancelGesture(); this.selection.clear(); this.updateInteraction(); this.emitSelection(); }
|
|
611
|
+
nudgeSelection(x, y) {
|
|
612
|
+
if (this.readonlyMode || this.tool !== 'select' || !this.selection.size || this.pointerId !== undefined || this.transformer.isTransforming())
|
|
613
|
+
return false;
|
|
614
|
+
this.commit(this.document.elements.map(element => this.selection.has(element.id)
|
|
615
|
+
? { ...element, x: element.x + x, y: element.y + y }
|
|
616
|
+
: element));
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
applyStyle(style) {
|
|
620
|
+
this.style = { ...this.style, ...style };
|
|
621
|
+
if (this.selection.size)
|
|
622
|
+
this.commit(this.document.elements.map(e => this.selection.has(e.id) ? { ...e, ...style } : e));
|
|
623
|
+
}
|
|
624
|
+
applyTypography(style) {
|
|
625
|
+
if (this.readonlyMode)
|
|
626
|
+
return undefined;
|
|
627
|
+
this.style = { ...this.style, ...style };
|
|
628
|
+
if (this.textEdit) {
|
|
629
|
+
this.textEdit.element = { ...this.textEdit.element, ...style };
|
|
630
|
+
return this.textEdit.element;
|
|
631
|
+
}
|
|
632
|
+
if (this.document.elements.some(e => this.selection.has(e.id) && hasWhiteboardText(e))) {
|
|
633
|
+
this.commit(this.document.elements.map(e => this.selection.has(e.id) && hasWhiteboardText(e)
|
|
634
|
+
? this.withText({ ...e, ...style }, e.text ?? '')
|
|
635
|
+
: e));
|
|
636
|
+
}
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
beginTextEdit(request) {
|
|
640
|
+
if (this.readonlyMode || this.textEdit)
|
|
641
|
+
return undefined;
|
|
642
|
+
const element = request.element
|
|
643
|
+
? this.elements.get(request.element.id)
|
|
644
|
+
: request.type === 'note' ? this.createNote(request.point) : this.createElement('text', request.point);
|
|
645
|
+
if (!element || !canEditText(element))
|
|
646
|
+
return undefined;
|
|
647
|
+
this.textEdit = { element, existing: !!request.element };
|
|
648
|
+
this.renderTextEdit();
|
|
649
|
+
this.updateInteraction();
|
|
650
|
+
return element;
|
|
651
|
+
}
|
|
652
|
+
finishTextEdit(text) {
|
|
653
|
+
const edit = this.textEdit;
|
|
654
|
+
if (!edit)
|
|
655
|
+
return;
|
|
656
|
+
this.textEdit = undefined;
|
|
657
|
+
this.notePreview?.destroy();
|
|
658
|
+
this.notePreview = undefined;
|
|
659
|
+
const { element, existing } = edit;
|
|
660
|
+
this.nodes.get(element.id)?.findOne('Text')?.show();
|
|
661
|
+
this.updateInteraction();
|
|
662
|
+
if (text === undefined || this.readonlyMode || (!text.trim() && (!existing || element.type === 'text')))
|
|
663
|
+
return;
|
|
664
|
+
if (element.type === 'rectangle' && !text.trim())
|
|
665
|
+
text = '';
|
|
666
|
+
if (existing) {
|
|
667
|
+
const current = this.elements.get(element.id);
|
|
668
|
+
if (current && (current !== element || (current.text ?? '') !== text)) {
|
|
669
|
+
this.commit(this.document.elements.map(e => e.id === current.id ? this.withText(element, text) : e));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
this.completeDrawing(this.withText(element, text));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
textEditorLayout(element, text) {
|
|
677
|
+
const { width, height, fontSize, type } = element;
|
|
678
|
+
if (type === 'note')
|
|
679
|
+
return { width, height, padding: noteTextPadding, paddingTop: noteTextPadding, lineHeight: textLineHeight };
|
|
680
|
+
if (type === 'rectangle') {
|
|
681
|
+
const label = this.createTextLabel({ ...element, text });
|
|
682
|
+
const paddingTop = Math.max(0, (height - label.height()) / 2);
|
|
683
|
+
label.destroy();
|
|
684
|
+
return { width, height: Math.max(height, fontSize), padding: 0, paddingTop, lineHeight: 1 };
|
|
685
|
+
}
|
|
686
|
+
const layout = this.withText(element, text);
|
|
687
|
+
return { width: layout.width, height: Math.max(layout.height, fontSize * textLineHeight), padding: 0, paddingTop: 0, lineHeight: textLineHeight };
|
|
688
|
+
}
|
|
689
|
+
exportPng(options = {}) {
|
|
690
|
+
// An independent stage exports world-space content without selection handles or viewport clipping.
|
|
691
|
+
const container = this.stage.container().ownerDocument.createElement('div');
|
|
692
|
+
const stage = new Konva.Stage({ container, width: 1, height: 1 });
|
|
693
|
+
try {
|
|
694
|
+
const layer = new Konva.Layer();
|
|
695
|
+
stage.add(layer);
|
|
696
|
+
for (const e of this.document.elements)
|
|
697
|
+
layer.add(this.createNode(e));
|
|
698
|
+
const bounds = this.document.elements.length ? layer.getClientRect() : { x: 0, y: 0, width: 800, height: 600 };
|
|
699
|
+
const padding = Math.max(0, options.padding ?? 32);
|
|
700
|
+
const x = bounds.x - padding, y = bounds.y - padding;
|
|
701
|
+
const width = Math.max(1, bounds.width + padding * 2), height = Math.max(1, bounds.height + padding * 2);
|
|
702
|
+
const background = new Konva.Rect({ x, y, width, height, fill: options.backgroundColor ?? '#ffffff', listening: false });
|
|
703
|
+
layer.add(background);
|
|
704
|
+
background.moveToBottom();
|
|
705
|
+
const pixelRatio = Math.min(Math.max(0.1, options.pixelRatio ?? 2), 4, 16384 / width, 16384 / height, Math.sqrt(16777216 / (width * height)));
|
|
706
|
+
return stage.toDataURL({ x, y, width, height, pixelRatio });
|
|
707
|
+
}
|
|
708
|
+
finally {
|
|
709
|
+
stage.destroy();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
destroy() {
|
|
713
|
+
this.eraserTrailAnimation.stop();
|
|
714
|
+
this.releasePointer();
|
|
715
|
+
this.stage.content.removeEventListener('pointercancel', this.cancelPointer, true);
|
|
716
|
+
this.stage.content.removeEventListener('lostpointercapture', this.cancelPointer);
|
|
717
|
+
this.stage.destroy();
|
|
718
|
+
}
|
|
719
|
+
createElement(type, point) {
|
|
720
|
+
const { fontFamily, textAlign, ...style } = this.style;
|
|
721
|
+
return { id: v7(), type, ...point, width: 0, height: 0, ...style,
|
|
722
|
+
...(type === 'text' || type === 'note' ? { fontFamily, textAlign } : {}) };
|
|
723
|
+
}
|
|
724
|
+
createNote(point) {
|
|
725
|
+
const note = this.createElement('note', point);
|
|
726
|
+
return { ...note, width: 220, height: 180, fill: note.fill === 'transparent' ? '#fff1b8' : note.fill };
|
|
727
|
+
}
|
|
728
|
+
createNoteText(note) {
|
|
729
|
+
return new Konva.Text({
|
|
730
|
+
x: noteTextPadding, y: noteTextPadding, width: Math.max(1, note.width - 2 * noteTextPadding),
|
|
731
|
+
text: note.text ?? '', fontSize: note.fontSize, fontFamily: note.fontFamily ?? whiteboardFontFamily,
|
|
732
|
+
align: note.textAlign ?? 'left', fill: note.stroke, lineHeight: textLineHeight, wrap: 'word',
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
createTextLabel(element) {
|
|
736
|
+
const rectangle = element.type === 'rectangle';
|
|
737
|
+
return new Konva.Text({
|
|
738
|
+
width: element.width || undefined, text: element.text ?? '', fontSize: element.fontSize,
|
|
739
|
+
fontFamily: element.fontFamily ?? whiteboardFontFamily, align: element.textAlign ?? (rectangle ? 'center' : 'left'),
|
|
740
|
+
fill: element.stroke, lineHeight: rectangle ? 1 : textLineHeight,
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
withText(element, text) {
|
|
744
|
+
const updated = { ...element, text };
|
|
745
|
+
if (updated.type === 'note') {
|
|
746
|
+
const label = this.createNoteText(updated);
|
|
747
|
+
updated.height = Math.max(updated.height, label.height() + 2 * noteTextPadding);
|
|
748
|
+
label.destroy();
|
|
749
|
+
}
|
|
750
|
+
else if (updated.type === 'text') {
|
|
751
|
+
const label = this.createTextLabel({ ...updated, width: 0 });
|
|
752
|
+
// The native editor needs space for its caret after the last glyph.
|
|
753
|
+
updated.width = Math.max(updated.width, 80, Math.min(480, Math.ceil(label.width() + textCaretSpace)));
|
|
754
|
+
label.width(updated.width);
|
|
755
|
+
updated.height = label.height();
|
|
756
|
+
label.destroy();
|
|
757
|
+
}
|
|
758
|
+
return updated;
|
|
759
|
+
}
|
|
760
|
+
createNode(e) {
|
|
761
|
+
const group = new Konva.Group({
|
|
762
|
+
id: e.id, x: e.x, y: e.y, rotation: e.rotation ?? 0, scaleX: e.scaleX ?? 1, scaleY: e.scaleY ?? 1,
|
|
763
|
+
opacity: e.opacity, visible: !isConnectorObscured(e, id => this.elements.get(id)),
|
|
764
|
+
});
|
|
765
|
+
const attrs = { stroke: e.stroke, strokeWidth: e.strokeWidth, fill: e.fill,
|
|
766
|
+
dash: e.lineStyle === 'dashed' ? [e.strokeWidth * 5, e.strokeWidth * 3] : e.lineStyle === 'dotted' ? [e.strokeWidth, e.strokeWidth * 3] : [],
|
|
767
|
+
lineCap: 'round', lineJoin: 'round', hitStrokeWidth: Math.max(12, e.strokeWidth) };
|
|
768
|
+
switch (e.type) {
|
|
769
|
+
case 'rectangle':
|
|
770
|
+
group.add(new Konva.Rect({ ...attrs, width: e.width, height: e.height, cornerRadius: 8 }));
|
|
771
|
+
if (e.text)
|
|
772
|
+
group.add(this.createTextLabel(e).height(e.height).verticalAlign('middle'));
|
|
773
|
+
break;
|
|
774
|
+
case 'diamond':
|
|
775
|
+
group.add(new Konva.Line({ ...attrs, points: [e.width / 2, 0, e.width, e.height / 2, e.width / 2, e.height, 0, e.height / 2], closed: true }));
|
|
776
|
+
break;
|
|
777
|
+
case 'ellipse':
|
|
778
|
+
group.add(new Konva.Ellipse({ ...attrs, x: e.width / 2, y: e.height / 2, radiusX: e.width / 2, radiusY: e.height / 2 }));
|
|
779
|
+
break;
|
|
780
|
+
case 'arrow':
|
|
781
|
+
group.add(new Konva.Arrow({ ...attrs, ...arrowHead(e), ...connectorPath(e), fill: e.fill === 'transparent' ? e.stroke : e.fill }));
|
|
782
|
+
break;
|
|
783
|
+
case 'line':
|
|
784
|
+
group.add(new Konva.Line({ ...attrs, fill: undefined, ...connectorPath(e) }));
|
|
785
|
+
break;
|
|
786
|
+
case 'pencil':
|
|
787
|
+
if (e.pressures)
|
|
788
|
+
group.add(this.pressureStroke(e));
|
|
789
|
+
else
|
|
790
|
+
group.add(new Konva.Line({ ...attrs, fill: undefined, points: [...e.points ?? []], tension: 0.3 }));
|
|
791
|
+
break;
|
|
792
|
+
case 'note':
|
|
793
|
+
group.add(new Konva.Rect({ fill: e.fill, width: e.width, height: e.height, cornerRadius: 4 }));
|
|
794
|
+
group.add(this.createNoteText(e).height(Math.max(0, e.height - 2 * noteTextPadding)));
|
|
795
|
+
break;
|
|
796
|
+
case 'text':
|
|
797
|
+
group.add(this.createTextLabel(e));
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
800
|
+
return group;
|
|
801
|
+
}
|
|
802
|
+
pressureStroke(element) {
|
|
803
|
+
const points = element.points, pressures = element.pressures;
|
|
804
|
+
let x = Infinity, y = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
805
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
806
|
+
x = Math.min(x, points[i]);
|
|
807
|
+
y = Math.min(y, points[i + 1]);
|
|
808
|
+
maxX = Math.max(maxX, points[i]);
|
|
809
|
+
maxY = Math.max(maxY, points[i + 1]);
|
|
810
|
+
}
|
|
811
|
+
return new Konva.Shape({
|
|
812
|
+
x, y, width: maxX - x, height: maxY - y,
|
|
813
|
+
stroke: element.stroke, strokeWidth: element.strokeWidth, hitStrokeWidth: Math.max(12, element.strokeWidth),
|
|
814
|
+
sceneFunc: context => {
|
|
815
|
+
context.setAttr('strokeStyle', element.stroke);
|
|
816
|
+
context.setAttr('lineCap', 'round');
|
|
817
|
+
for (let i = 2; i < points.length; i += 2) {
|
|
818
|
+
context.beginPath();
|
|
819
|
+
context.moveTo(points[i - 2] - x, points[i - 1] - y);
|
|
820
|
+
context.lineTo(points[i] - x, points[i + 1] - y);
|
|
821
|
+
context.setAttr('lineWidth', element.strokeWidth * (0.2 + 0.8 * (pressures[i / 2 - 1] + pressures[i / 2]) / 2));
|
|
822
|
+
context.stroke();
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
hitFunc: (context, shape) => {
|
|
826
|
+
context.beginPath();
|
|
827
|
+
context.moveTo(points[0] - x, points[1] - y);
|
|
828
|
+
for (let i = 2; i < points.length; i += 2)
|
|
829
|
+
context.lineTo(points[i] - x, points[i + 1] - y);
|
|
830
|
+
context.strokeShape(shape);
|
|
831
|
+
},
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
render() {
|
|
835
|
+
this.transformer.nodes([]);
|
|
836
|
+
this.layer.destroyChildren();
|
|
837
|
+
this.notePreview = undefined;
|
|
838
|
+
this.nodes.clear();
|
|
839
|
+
this.elements = new Map(this.document.elements.map(element => [element.id, element]));
|
|
840
|
+
this.connected = this.document.elements.filter(element => element.startBinding || element.endBinding);
|
|
841
|
+
for (const element of this.document.elements) {
|
|
842
|
+
const node = this.createNode(element);
|
|
843
|
+
this.nodes.set(element.id, node);
|
|
844
|
+
this.layer.add(node);
|
|
845
|
+
}
|
|
846
|
+
this.selection = new Set([...this.selection].filter(id => this.nodes.has(id)));
|
|
847
|
+
this.renderTextEdit();
|
|
848
|
+
this.updateInteraction();
|
|
849
|
+
}
|
|
850
|
+
renderTextEdit() {
|
|
851
|
+
if (!this.textEdit)
|
|
852
|
+
return;
|
|
853
|
+
const { element, existing } = this.textEdit;
|
|
854
|
+
if (existing)
|
|
855
|
+
this.nodes.get(element.id)?.findOne('Text')?.hide();
|
|
856
|
+
else if (element.type === 'note') {
|
|
857
|
+
this.notePreview = this.createNode(element);
|
|
858
|
+
this.layer.add(this.notePreview);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
updateInteraction() {
|
|
862
|
+
const showTransformer = this.canEditCanvas() && this.tool !== 'hand' && this.tool !== 'eraser' && !this.selectedConnector();
|
|
863
|
+
this.transformer.nodes(showTransformer ? [...this.selection].flatMap(id => this.nodes.get(id) ?? []) : []);
|
|
864
|
+
this.updateConnectorHandles();
|
|
865
|
+
this.stage.container().dataset['tool'] = this.pan || this.space || this.readonlyMode ? 'hand' : this.tool;
|
|
866
|
+
}
|
|
867
|
+
canEditCanvas() {
|
|
868
|
+
return !this.space && !this.pan && !this.readonlyMode && !this.textEdit;
|
|
869
|
+
}
|
|
870
|
+
selectedConnector() {
|
|
871
|
+
if (!this.canEditCanvas() || this.selection.size !== 1 ||
|
|
872
|
+
(this.tool !== 'select' && this.tool !== 'line' && this.tool !== 'arrow'))
|
|
873
|
+
return undefined;
|
|
874
|
+
const element = this.elements.get(this.selection.values().next().value);
|
|
875
|
+
return element && isConnector(element) && element.points?.length === 4 ? element : undefined;
|
|
876
|
+
}
|
|
877
|
+
updateConnectorHandles() {
|
|
878
|
+
const element = this.connectorEdit?.draft ?? this.selectedConnector();
|
|
879
|
+
const group = element && this.nodes.get(element.id);
|
|
880
|
+
const line = group?.getChildren()[0];
|
|
881
|
+
if (!element || !group || !(line instanceof Konva.Line)) {
|
|
882
|
+
for (const handle of Object.values(this.connectorHandles))
|
|
883
|
+
handle.hide();
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const points = line.points(), end = points.length - 2;
|
|
887
|
+
const [x, y] = element.bend ?? [(points[0] + points[end]) / 2, (points[1] + points[end + 1]) / 2];
|
|
888
|
+
const positions = { start: { x: points[0], y: points[1] }, end: { x: points[end], y: points[end + 1] }, bend: { x, y } };
|
|
889
|
+
const zoom = this.viewport.zoom;
|
|
890
|
+
this.connectorHandles.bend.fill(element.bend ? '#ffffff' : '#245bff');
|
|
891
|
+
for (const handle of [...connectorEnds, 'bend']) {
|
|
892
|
+
const point = group.getTransform().point(positions[handle]);
|
|
893
|
+
this.connectorHandles[handle].setAttrs({
|
|
894
|
+
...point, radius: selectionHandleSize / (2 * zoom), strokeWidth: 1 / zoom, hitStrokeWidth: 10 / zoom, visible: true,
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
showBindingHint(end, point) {
|
|
899
|
+
const hint = this.bindingHints[end];
|
|
900
|
+
if (!point) {
|
|
901
|
+
hint.hide();
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const zoom = this.viewport.zoom;
|
|
905
|
+
hint.setAttrs({ ...point, radius: 9 / zoom, strokeWidth: 1.5 / zoom, visible: true });
|
|
906
|
+
}
|
|
907
|
+
liveTransform(element) {
|
|
908
|
+
const node = this.nodes.get(element.id);
|
|
909
|
+
return node ? { ...element, ...node.position(), rotation: node.rotation(), scaleX: node.scaleX(), scaleY: node.scaleY() } : element;
|
|
910
|
+
}
|
|
911
|
+
liveElement = (id) => {
|
|
912
|
+
const element = this.elements.get(id);
|
|
913
|
+
return element && this.liveTransform(element);
|
|
914
|
+
};
|
|
915
|
+
updateConnectorPath(element) {
|
|
916
|
+
const group = this.nodes.get(element.id);
|
|
917
|
+
const line = group?.getChildren()[0];
|
|
918
|
+
if (!group || !(line instanceof Konva.Line) || !element.points)
|
|
919
|
+
return;
|
|
920
|
+
group.visible(!isConnectorObscured(element, this.liveElement));
|
|
921
|
+
const path = connectorPath(element);
|
|
922
|
+
if (line instanceof Konva.Arrow)
|
|
923
|
+
line.setAttrs({ ...arrowHead(element), ...path });
|
|
924
|
+
else
|
|
925
|
+
line.setAttrs(path);
|
|
926
|
+
}
|
|
927
|
+
refreshConnections() {
|
|
928
|
+
for (const element of this.connected) {
|
|
929
|
+
this.updateConnectorPath(resolveConnector(this.liveTransform(element), this.liveElement));
|
|
930
|
+
}
|
|
931
|
+
this.updateConnectorHandles();
|
|
932
|
+
}
|
|
933
|
+
elementFromNode(node) {
|
|
934
|
+
let current = node;
|
|
935
|
+
while (current && current !== this.stage) {
|
|
936
|
+
const element = this.elements.get(current.id());
|
|
937
|
+
if (element)
|
|
938
|
+
return element;
|
|
939
|
+
current = current.getParent();
|
|
940
|
+
}
|
|
941
|
+
return undefined;
|
|
942
|
+
}
|
|
943
|
+
capturePointer(e) {
|
|
944
|
+
this.pointerId = e.pointerId;
|
|
945
|
+
if (e.isTrusted)
|
|
946
|
+
this.stage.content.setPointerCapture(e.pointerId);
|
|
947
|
+
}
|
|
948
|
+
releasePointer() {
|
|
949
|
+
const pointerId = this.pointerId;
|
|
950
|
+
this.pointerId = undefined;
|
|
951
|
+
if (pointerId !== undefined && this.stage.content.hasPointerCapture(pointerId))
|
|
952
|
+
this.stage.content.releasePointerCapture(pointerId);
|
|
953
|
+
}
|
|
954
|
+
pointerDown(event) {
|
|
955
|
+
const e = event.evt;
|
|
956
|
+
if ((e.button !== 0 && e.button !== 1) || this.pointerId !== undefined || this.transformer.isTransforming())
|
|
957
|
+
return;
|
|
958
|
+
if (this.textEdit) {
|
|
959
|
+
// Let the inline editor finish on blur before starting another canvas gesture.
|
|
960
|
+
this.stage.container().focus({ preventScroll: true });
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const screen = this.stage.getPointerPosition(), point = this.stage.getRelativePointerPosition();
|
|
964
|
+
if (!screen || !point)
|
|
965
|
+
return;
|
|
966
|
+
this.stage.container().focus({ preventScroll: true });
|
|
967
|
+
if (this.tool === 'hand' || this.space || e.button === 1 || this.readonlyMode) {
|
|
968
|
+
e.preventDefault();
|
|
969
|
+
this.pan = { pointer: screen, position: this.stage.position() };
|
|
970
|
+
this.capturePointer(e);
|
|
971
|
+
this.updateInteraction();
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (event.target.getParent() === this.transformer)
|
|
975
|
+
return;
|
|
976
|
+
const connector = this.selectedConnector();
|
|
977
|
+
const handle = ['start', 'end', 'bend'].find(key => event.target === this.connectorHandles[key]);
|
|
978
|
+
if (connector && handle) {
|
|
979
|
+
this.connectorEdit = { element: connector, handle, start: point };
|
|
980
|
+
this.capturePointer(e);
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (this.tool === 'select') {
|
|
984
|
+
const element = this.elementFromNode(event.target);
|
|
985
|
+
if (element) {
|
|
986
|
+
if (e.shiftKey || e.metaKey || e.ctrlKey) {
|
|
987
|
+
if (this.selection.has(element.id))
|
|
988
|
+
this.selection.delete(element.id);
|
|
989
|
+
else
|
|
990
|
+
this.selection.add(element.id);
|
|
991
|
+
}
|
|
992
|
+
else if (!this.selection.has(element.id))
|
|
993
|
+
this.selection = new Set([element.id]);
|
|
994
|
+
this.updateInteraction();
|
|
995
|
+
this.emitSelection();
|
|
996
|
+
if (this.selection.has(element.id)) {
|
|
997
|
+
this.move = {
|
|
998
|
+
start: point,
|
|
999
|
+
origins: new Map([...this.selection].map(id => [id, this.nodes.get(id).position()])),
|
|
1000
|
+
started: false,
|
|
1001
|
+
};
|
|
1002
|
+
this.capturePointer(e);
|
|
1003
|
+
}
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (!e.shiftKey)
|
|
1007
|
+
this.selection.clear();
|
|
1008
|
+
this.start = point;
|
|
1009
|
+
this.marquee.setAttrs({ x: point.x, y: point.y, width: 0, height: 0, visible: true });
|
|
1010
|
+
this.updateInteraction();
|
|
1011
|
+
this.emitSelection();
|
|
1012
|
+
this.capturePointer(e);
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
if (this.selection.size) {
|
|
1016
|
+
this.selection.clear();
|
|
1017
|
+
this.updateInteraction();
|
|
1018
|
+
this.emitSelection();
|
|
1019
|
+
}
|
|
1020
|
+
this.start = point;
|
|
1021
|
+
this.capturePointer(e);
|
|
1022
|
+
if (this.tool === 'text' || this.tool === 'note')
|
|
1023
|
+
return;
|
|
1024
|
+
if (this.tool === 'eraser') {
|
|
1025
|
+
this.clearEraserTrail();
|
|
1026
|
+
this.eraserTrail.fill(getComputedStyle(this.stage.container()).color);
|
|
1027
|
+
this.eraseTo(screen);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
this.draft = this.createElement(this.tool, point);
|
|
1031
|
+
if (['pencil', 'line', 'arrow'].includes(this.tool))
|
|
1032
|
+
this.draft.points = [0, 0, 0.01, 0.01];
|
|
1033
|
+
if (this.tool === 'pencil' && this.pressureSensitive && e.pointerType === 'pen')
|
|
1034
|
+
this.draft.pressures = [e.pressure, e.pressure];
|
|
1035
|
+
this.draftNode = this.createNode(this.draft);
|
|
1036
|
+
this.layer.add(this.draftNode);
|
|
1037
|
+
}
|
|
1038
|
+
pointerMove(event) {
|
|
1039
|
+
if (event.pointerId !== this.pointerId)
|
|
1040
|
+
return;
|
|
1041
|
+
const screen = this.stage.getPointerPosition(), point = this.stage.getRelativePointerPosition();
|
|
1042
|
+
if (!screen || !point)
|
|
1043
|
+
return;
|
|
1044
|
+
if (this.pan) {
|
|
1045
|
+
this.setViewport({ ...this.viewport, x: this.pan.position.x + screen.x - this.pan.pointer.x, y: this.pan.position.y + screen.y - this.pan.pointer.y });
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
if (this.connectorEdit) {
|
|
1049
|
+
this.moveConnectorHandle(point, event);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (this.move) {
|
|
1053
|
+
const { start, origins } = this.move;
|
|
1054
|
+
const x = point.x - start.x, y = point.y - start.y;
|
|
1055
|
+
if (!this.move.started && Math.hypot(x, y) * this.viewport.zoom < 3)
|
|
1056
|
+
return;
|
|
1057
|
+
this.move.started = true;
|
|
1058
|
+
for (const [id, origin] of origins)
|
|
1059
|
+
this.nodes.get(id)?.position({ x: origin.x + x, y: origin.y + y });
|
|
1060
|
+
this.refreshConnections();
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
if (!this.start)
|
|
1064
|
+
return;
|
|
1065
|
+
if (this.tool === 'eraser') {
|
|
1066
|
+
this.eraseTo(screen);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const width = Math.abs(point.x - this.start.x), height = Math.abs(point.y - this.start.y);
|
|
1070
|
+
if (this.tool === 'select') {
|
|
1071
|
+
this.marquee.setAttrs({ x: Math.min(point.x, this.start.x), y: Math.min(point.y, this.start.y), width, height });
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
if (!this.draft)
|
|
1075
|
+
return;
|
|
1076
|
+
if (this.tool === 'pencil') {
|
|
1077
|
+
const points = this.draft.points;
|
|
1078
|
+
const x = point.x - this.start.x, y = point.y - this.start.y;
|
|
1079
|
+
if (Math.hypot(x - points[points.length - 2], y - points[points.length - 1]) < 1 / this.viewport.zoom)
|
|
1080
|
+
return;
|
|
1081
|
+
this.draft.points = [...points, x, y];
|
|
1082
|
+
if (this.draft.pressures) {
|
|
1083
|
+
const pressure = event.type === 'pointerup' ? this.draft.pressures.at(-1) : event.pressure;
|
|
1084
|
+
this.draft.pressures = [...this.draft.pressures, Math.max(0, Math.min(1, pressure))];
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
else if (this.tool === 'line' || this.tool === 'arrow') {
|
|
1088
|
+
let x = point.x - this.start.x, y = point.y - this.start.y;
|
|
1089
|
+
if (event.shiftKey) {
|
|
1090
|
+
const step = Math.PI / 12;
|
|
1091
|
+
const angle = Math.round(Math.atan2(y, x) / step) * step;
|
|
1092
|
+
const length = Math.hypot(x, y);
|
|
1093
|
+
x = Math.cos(angle) * length;
|
|
1094
|
+
y = Math.sin(angle) * length;
|
|
1095
|
+
}
|
|
1096
|
+
const end = { x: this.start.x + x, y: this.start.y + y };
|
|
1097
|
+
const bind = !event.ctrlKey && !event.metaKey;
|
|
1098
|
+
const tolerance = bindingSnapDistance / this.viewport.zoom;
|
|
1099
|
+
const startSnap = bind ? findBinding(this.document.elements, this.start, end, tolerance) : undefined;
|
|
1100
|
+
const endSnap = bind ? findBinding(this.document.elements, end, startSnap?.point ?? this.start, tolerance, startSnap?.binding.elementId) : undefined;
|
|
1101
|
+
this.draft = resolveConnector(setConnectorEnds({
|
|
1102
|
+
...this.draft, points: [0, 0, x, y], width: Math.abs(x), height: Math.abs(y),
|
|
1103
|
+
startBinding: startSnap?.binding, endBinding: endSnap?.binding,
|
|
1104
|
+
}, startSnap?.point, endSnap?.point), this.liveElement);
|
|
1105
|
+
this.showBindingHint('start', this.draft.startBinding ? connectorEndPoint(this.draft, 'start') : undefined);
|
|
1106
|
+
this.showBindingHint('end', this.draft.endBinding ? connectorEndPoint(this.draft, 'end') : undefined);
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
const size = Math.max(width, height);
|
|
1110
|
+
this.draft.width = event.shiftKey ? size : width;
|
|
1111
|
+
this.draft.height = event.shiftKey ? size : height;
|
|
1112
|
+
this.draft.x = point.x < this.start.x ? this.start.x - this.draft.width : this.start.x;
|
|
1113
|
+
this.draft.y = point.y < this.start.y ? this.start.y - this.draft.height : this.start.y;
|
|
1114
|
+
}
|
|
1115
|
+
if (this.tool === 'pencil') {
|
|
1116
|
+
this.draft.width = width;
|
|
1117
|
+
this.draft.height = height;
|
|
1118
|
+
}
|
|
1119
|
+
this.draftNode?.destroy();
|
|
1120
|
+
this.draftNode = this.createNode(this.draft);
|
|
1121
|
+
this.layer.add(this.draftNode);
|
|
1122
|
+
}
|
|
1123
|
+
moveConnectorHandle(point, event) {
|
|
1124
|
+
const edit = this.connectorEdit;
|
|
1125
|
+
const { element, handle, start } = edit;
|
|
1126
|
+
const x = point.x - start.x, y = point.y - start.y;
|
|
1127
|
+
const zoom = this.viewport.zoom;
|
|
1128
|
+
if (!edit.draft && Math.hypot(x, y) * zoom < 3)
|
|
1129
|
+
return;
|
|
1130
|
+
const original = handle === 'bend' ? connectorBendPoint(element) : connectorEndPoint(element, handle);
|
|
1131
|
+
const destination = { x: original.x + x, y: original.y + y };
|
|
1132
|
+
if (handle === 'bend') {
|
|
1133
|
+
const midpoint = connectorBendPoint({ ...element, bend: undefined });
|
|
1134
|
+
const straight = Math.hypot(destination.x - midpoint.x, destination.y - midpoint.y) * zoom < 3;
|
|
1135
|
+
const bent = setConnectorBend(element, straight ? undefined : destination);
|
|
1136
|
+
edit.draft = bent === element ? element : resolveConnector(bent, this.liveElement);
|
|
1137
|
+
this.updateConnectorPath(edit.draft);
|
|
1138
|
+
this.updateConnectorHandles();
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
const end = handle;
|
|
1142
|
+
const opposite = end === 'start' ? 'end' : 'start';
|
|
1143
|
+
const other = element.bend ? connectorBendPoint(element) : connectorEndPoint(element, opposite);
|
|
1144
|
+
const snap = event.ctrlKey || event.metaKey ? undefined :
|
|
1145
|
+
findBinding(this.document.elements, destination, other, bindingSnapDistance / zoom, element[bindingKey[opposite]]?.elementId);
|
|
1146
|
+
const target = snap?.point ?? destination;
|
|
1147
|
+
edit.draft = resolveConnector(setConnectorEnds({ ...element, [bindingKey[end]]: snap?.binding }, end === 'start' ? target : undefined, end === 'end' ? target : undefined), this.liveElement);
|
|
1148
|
+
this.updateConnectorPath(edit.draft);
|
|
1149
|
+
this.updateConnectorHandles();
|
|
1150
|
+
this.showBindingHint(end, edit.draft[bindingKey[end]] ? connectorEndPoint(edit.draft, end) : undefined);
|
|
1151
|
+
}
|
|
1152
|
+
pointerUp(event) {
|
|
1153
|
+
if (event.pointerId !== this.pointerId)
|
|
1154
|
+
return;
|
|
1155
|
+
this.pointerMove(event);
|
|
1156
|
+
this.releasePointer();
|
|
1157
|
+
for (const end of connectorEnds)
|
|
1158
|
+
this.showBindingHint(end);
|
|
1159
|
+
if (this.pan) {
|
|
1160
|
+
this.pan = undefined;
|
|
1161
|
+
this.updateInteraction();
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (this.connectorEdit) {
|
|
1165
|
+
const { draft, element } = this.connectorEdit;
|
|
1166
|
+
this.connectorEdit = undefined;
|
|
1167
|
+
if (draft && draft !== element)
|
|
1168
|
+
this.commit(this.document.elements.map(element => element.id === draft.id ? draft : element));
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
if (this.move) {
|
|
1172
|
+
const { started } = this.move;
|
|
1173
|
+
this.move = undefined;
|
|
1174
|
+
if (started) {
|
|
1175
|
+
this.lastMoveEnd = event.timeStamp;
|
|
1176
|
+
this.commitTransforms();
|
|
1177
|
+
}
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
if (!this.start)
|
|
1181
|
+
return;
|
|
1182
|
+
if (this.tool === 'select') {
|
|
1183
|
+
const bounds = this.marquee.getClientRect({ skipStroke: true });
|
|
1184
|
+
if (bounds.width > 3 && bounds.height > 3) {
|
|
1185
|
+
for (const [id, node] of this.nodes) {
|
|
1186
|
+
const rect = node.getClientRect({ skipStroke: true });
|
|
1187
|
+
if (rect.x >= bounds.x && rect.y >= bounds.y &&
|
|
1188
|
+
rect.x + rect.width <= bounds.x + bounds.width && rect.y + rect.height <= bounds.y + bounds.height) {
|
|
1189
|
+
this.selection.add(id);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
this.marquee.hide();
|
|
1194
|
+
this.start = undefined;
|
|
1195
|
+
this.updateInteraction();
|
|
1196
|
+
this.emitSelection();
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
const start = this.start;
|
|
1200
|
+
this.start = undefined;
|
|
1201
|
+
if (this.tool === 'text' || this.tool === 'note') {
|
|
1202
|
+
const point = this.stage.getRelativePointerPosition();
|
|
1203
|
+
if (point && Math.hypot(point.x - start.x, point.y - start.y) * this.viewport.zoom < 3) {
|
|
1204
|
+
this.callbacks.editText({ point: start, type: this.tool });
|
|
1205
|
+
}
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
if (this.tool === 'eraser') {
|
|
1209
|
+
if (this.erased.size)
|
|
1210
|
+
this.commit(this.document.elements.filter(e => !this.erased.has(e.id)));
|
|
1211
|
+
this.erased.clear();
|
|
1212
|
+
this.lastErasePoint = undefined;
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
const draft = this.draft;
|
|
1216
|
+
this.draft = undefined;
|
|
1217
|
+
this.draftNode?.destroy();
|
|
1218
|
+
this.draftNode = undefined;
|
|
1219
|
+
if (draft) {
|
|
1220
|
+
const { width, height, type } = draft;
|
|
1221
|
+
const minSize = 3 / this.viewport.zoom;
|
|
1222
|
+
const end = this.stage.getRelativePointerPosition();
|
|
1223
|
+
const largeEnough = isConnector(draft)
|
|
1224
|
+
? !!end && Math.hypot(end.x - start.x, end.y - start.y) >= minSize && Math.hypot(width, height) >= minSize
|
|
1225
|
+
: Math.min(width, height) >= minSize;
|
|
1226
|
+
if (type === 'pencil' || largeEnough)
|
|
1227
|
+
this.completeDrawing(draft);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
completeDrawing(element) {
|
|
1231
|
+
const returnToSelection = !this.toolLocked && element.type !== 'pencil';
|
|
1232
|
+
if (returnToSelection)
|
|
1233
|
+
this.tool = 'select';
|
|
1234
|
+
this.selection = new Set([element.id]);
|
|
1235
|
+
this.commit([...this.document.elements, element]);
|
|
1236
|
+
if (returnToSelection)
|
|
1237
|
+
this.callbacks.drawComplete?.();
|
|
1238
|
+
}
|
|
1239
|
+
eraseTo(point) {
|
|
1240
|
+
const previous = this.eraserTrailPoints.at(-1)?.point;
|
|
1241
|
+
if (!previous || Math.hypot(point.x - previous.x, point.y - previous.y) >= 1) {
|
|
1242
|
+
this.eraserTrailPoints.push({ point, time: performance.now() });
|
|
1243
|
+
if (this.eraserTrailPoints.length > 1 && !this.eraserTrailAnimation.isRunning())
|
|
1244
|
+
this.eraserTrailAnimation.start();
|
|
1245
|
+
}
|
|
1246
|
+
const start = this.lastErasePoint ?? point;
|
|
1247
|
+
this.lastErasePoint = point;
|
|
1248
|
+
const x = point.x - start.x, y = point.y - start.y;
|
|
1249
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(x, y) / 2));
|
|
1250
|
+
for (let i = 1; i <= steps; i++) {
|
|
1251
|
+
const hit = this.layer.getIntersection({ x: start.x + x * i / steps, y: start.y + y * i / steps });
|
|
1252
|
+
const element = hit && this.elementFromNode(hit);
|
|
1253
|
+
if (!element || this.erased.has(element.id))
|
|
1254
|
+
continue;
|
|
1255
|
+
this.erased.add(element.id);
|
|
1256
|
+
this.nodes.get(element.id)?.opacity(0.15);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
drawEraserTrail() {
|
|
1260
|
+
const now = performance.now();
|
|
1261
|
+
while (this.eraserTrailPoints.length && now - this.eraserTrailPoints[0].time >= eraserTrailDuration) {
|
|
1262
|
+
this.eraserTrailPoints.shift();
|
|
1263
|
+
}
|
|
1264
|
+
if (this.eraserTrailPoints.length < 2) {
|
|
1265
|
+
this.eraserTrail.hide();
|
|
1266
|
+
if (!this.eraserTrailPoints.length)
|
|
1267
|
+
this.eraserTrailAnimation.stop();
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
// Build both sides of a smooth ribbon. Older segments narrow as they expire.
|
|
1271
|
+
const first = this.eraserTrailPoints[0].point;
|
|
1272
|
+
const last = this.eraserTrailPoints.at(-1).point;
|
|
1273
|
+
const outline = [first.x, first.y];
|
|
1274
|
+
const farSide = [];
|
|
1275
|
+
for (let i = 1; i < this.eraserTrailPoints.length; i++) {
|
|
1276
|
+
const { point: a, time: start } = this.eraserTrailPoints[i - 1];
|
|
1277
|
+
const { point: b, time: end } = this.eraserTrailPoints[i];
|
|
1278
|
+
const radius = eraserTrailRadius * (1 - (now - (start + end) / 2) / eraserTrailDuration);
|
|
1279
|
+
const length = Math.hypot(b.x - a.x, b.y - a.y);
|
|
1280
|
+
const dx = (b.y - a.y) / length * radius, dy = (b.x - a.x) / length * radius;
|
|
1281
|
+
const x = (a.x + b.x) / 2, y = (a.y + b.y) / 2;
|
|
1282
|
+
outline.push(x - dx, y + dy);
|
|
1283
|
+
farSide.push({ x: x + dx, y: y - dy });
|
|
1284
|
+
}
|
|
1285
|
+
outline.push(last.x, last.y);
|
|
1286
|
+
for (const { x, y } of farSide.reverse())
|
|
1287
|
+
outline.push(x, y);
|
|
1288
|
+
this.eraserTrail.points(outline).show();
|
|
1289
|
+
}
|
|
1290
|
+
clearEraserTrail() {
|
|
1291
|
+
this.eraserTrailAnimation.stop();
|
|
1292
|
+
this.eraserTrailPoints = [];
|
|
1293
|
+
this.eraserTrail.hide();
|
|
1294
|
+
}
|
|
1295
|
+
cancelGesture() {
|
|
1296
|
+
this.clearEraserTrail();
|
|
1297
|
+
this.releasePointer();
|
|
1298
|
+
this.pan = undefined;
|
|
1299
|
+
this.start = undefined;
|
|
1300
|
+
if (this.move) {
|
|
1301
|
+
for (const [id, origin] of this.move.origins)
|
|
1302
|
+
this.nodes.get(id)?.position(origin);
|
|
1303
|
+
this.move = undefined;
|
|
1304
|
+
this.refreshConnections();
|
|
1305
|
+
}
|
|
1306
|
+
if (this.connectorEdit) {
|
|
1307
|
+
this.updateConnectorPath(this.connectorEdit.element);
|
|
1308
|
+
this.connectorEdit = undefined;
|
|
1309
|
+
}
|
|
1310
|
+
for (const end of connectorEnds)
|
|
1311
|
+
this.showBindingHint(end);
|
|
1312
|
+
this.draft = undefined;
|
|
1313
|
+
this.draftNode?.destroy();
|
|
1314
|
+
this.draftNode = undefined;
|
|
1315
|
+
this.marquee.hide();
|
|
1316
|
+
this.lastErasePoint = undefined;
|
|
1317
|
+
if (this.erased.size) {
|
|
1318
|
+
this.erased.clear();
|
|
1319
|
+
for (const e of this.document.elements)
|
|
1320
|
+
this.nodes.get(e.id)?.opacity(e.opacity);
|
|
1321
|
+
}
|
|
1322
|
+
this.updateInteraction();
|
|
1323
|
+
}
|
|
1324
|
+
commitTransforms() {
|
|
1325
|
+
let changed = false;
|
|
1326
|
+
const elements = this.document.elements.map(element => {
|
|
1327
|
+
const node = this.selection.has(element.id) ? this.nodes.get(element.id) : undefined;
|
|
1328
|
+
if (!node)
|
|
1329
|
+
return element;
|
|
1330
|
+
const { x, y } = node.position();
|
|
1331
|
+
const rotation = node.rotation(), scaleX = node.scaleX(), scaleY = node.scaleY();
|
|
1332
|
+
if (x === element.x && y === element.y && rotation === (element.rotation ?? 0) &&
|
|
1333
|
+
scaleX === (element.scaleX ?? 1) && scaleY === (element.scaleY ?? 1))
|
|
1334
|
+
return element;
|
|
1335
|
+
changed = true;
|
|
1336
|
+
return { ...element, x, y, rotation, scaleX, scaleY };
|
|
1337
|
+
});
|
|
1338
|
+
if (changed)
|
|
1339
|
+
this.commit(elements);
|
|
1340
|
+
}
|
|
1341
|
+
commit(elements) {
|
|
1342
|
+
if (this.readonlyMode)
|
|
1343
|
+
return;
|
|
1344
|
+
this.history.commit(resolveBindings(elements));
|
|
1345
|
+
this.changed();
|
|
1346
|
+
}
|
|
1347
|
+
changed() {
|
|
1348
|
+
this.render();
|
|
1349
|
+
this.emitSelection();
|
|
1350
|
+
this.callbacks.change(this.document, this.history.canUndo, this.history.canRedo);
|
|
1351
|
+
}
|
|
1352
|
+
emitSelection() { this.callbacks.selection(this.document.elements.filter(e => this.selection.has(e.id))); }
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
const WHITEBOARD_LABELS = {
|
|
1356
|
+
en: {
|
|
1357
|
+
tools: { hand: 'Hand', select: 'Select', rectangle: 'Rectangle', diamond: 'Diamond', ellipse: 'Ellipse', arrow: 'Arrow', line: 'Line', pencil: 'Pencil', text: 'Text', note: 'Note', eraser: 'Eraser' },
|
|
1358
|
+
properties: 'Properties', closeProperties: 'Close properties', color: 'Color', stroke: 'Stroke color', customColor: 'Custom color',
|
|
1359
|
+
fill: 'Fill', noFill: 'No fill', width: 'Stroke width', lineStyle: 'Line style', solid: 'Solid', dashed: 'Dashed', dotted: 'Dotted',
|
|
1360
|
+
arrowheadColor: 'Arrowhead color', useStrokeColor: 'Use stroke color',
|
|
1361
|
+
opacity: 'Opacity',
|
|
1362
|
+
lockTool: 'Keep drawing tool active', export: 'Export', more: 'More actions', exportPng: 'Export PNG', saveJson: 'Save JSON', openJson: 'Open JSON', clear: 'Clear whiteboard',
|
|
1363
|
+
clearTitle: 'Clear whiteboard?', clearDescription: 'All objects will be removed. You can restore them with Undo.',
|
|
1364
|
+
duplicate: 'Duplicate selection', delete: 'Delete selection', zoomOut: 'Zoom out', zoomIn: 'Zoom in', resetZoom: 'Reset zoom to 100%', fit: 'Fit to content',
|
|
1365
|
+
undo: 'Undo', redo: 'Redo', grid: 'Toggle grid', canvasHint: 'Space to pan · Ctrl + wheel to zoom', canvasHelp: 'Drawing canvas. Use the toolbar to draw. Space to pan, Control plus wheel to zoom.',
|
|
1366
|
+
text: 'Text', textColor: 'Text color', noteText: 'Note text', notePlaceholder: 'Type a note…',
|
|
1367
|
+
fontFamily: 'Font family', fontSize: 'Font size', textAlign: 'Text alignment',
|
|
1368
|
+
fonts: { handwritten: 'Handwritten', sans: 'Sans serif', mono: 'Monospace', serif: 'Serif' },
|
|
1369
|
+
fontSizes: { S: 'Small', M: 'Medium', L: 'Large', XL: 'Extra large' },
|
|
1370
|
+
alignments: { left: 'Align left', center: 'Align center', right: 'Align right' },
|
|
1371
|
+
dismiss: 'Dismiss import error', objects: 'objects',
|
|
1372
|
+
},
|
|
1373
|
+
ru: {
|
|
1374
|
+
tools: { hand: 'Перемещение', select: 'Выделение', rectangle: 'Прямоугольник', diamond: 'Ромб', ellipse: 'Эллипс', arrow: 'Стрелка', line: 'Линия', pencil: 'Карандаш', text: 'Текст', note: 'Заметка', eraser: 'Ластик' },
|
|
1375
|
+
properties: 'Свойства', closeProperties: 'Закрыть свойства', color: 'Цвет', stroke: 'Цвет обводки', customColor: 'Другой цвет',
|
|
1376
|
+
fill: 'Фон', noFill: 'Без заливки', width: 'Толщина', lineStyle: 'Стиль линии', solid: 'Сплошная', dashed: 'Штриховая', dotted: 'Пунктирная',
|
|
1377
|
+
arrowheadColor: 'Цвет наконечника', useStrokeColor: 'Использовать цвет обводки',
|
|
1378
|
+
opacity: 'Непрозрачность',
|
|
1379
|
+
lockTool: 'Закрепить инструмент', export: 'Экспорт', more: 'Другие действия', exportPng: 'Экспорт PNG', saveJson: 'Сохранить JSON', openJson: 'Открыть JSON', clear: 'Очистить доску',
|
|
1380
|
+
clearTitle: 'Очистить доску?', clearDescription: 'Все объекты будут удалены. Их можно восстановить действием «Отменить».',
|
|
1381
|
+
duplicate: 'Дублировать', delete: 'Удалить', zoomOut: 'Уменьшить', zoomIn: 'Увеличить', resetZoom: 'Масштаб 100%', fit: 'Показать всю доску',
|
|
1382
|
+
undo: 'Отменить', redo: 'Повторить', grid: 'Показать сетку', canvasHint: 'Пробел — перемещение · Ctrl + колесо — масштаб', canvasHelp: 'Холст для рисования. Пробел — перемещение, Ctrl + колесо — масштаб.',
|
|
1383
|
+
text: 'Текст', textColor: 'Цвет текста', noteText: 'Текст заметки', notePlaceholder: 'Введите заметку…',
|
|
1384
|
+
fontFamily: 'Семейство шрифтов', fontSize: 'Размер шрифта', textAlign: 'Выравнивание текста',
|
|
1385
|
+
fonts: { handwritten: 'Рукописный', sans: 'Без засечек', mono: 'Моноширинный', serif: 'С засечками' },
|
|
1386
|
+
fontSizes: { S: 'Маленький', M: 'Средний', L: 'Большой', XL: 'Очень большой' },
|
|
1387
|
+
alignments: { left: 'По левому краю', center: 'По центру', right: 'По правому краю' },
|
|
1388
|
+
dismiss: 'Закрыть сообщение', objects: 'объектов',
|
|
1389
|
+
},
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
class Whiteboard {
|
|
1393
|
+
/** Portable canvas data. Replace this value to load a document and reset undo history. */
|
|
1394
|
+
value = model({ version: 1, elements: [] }, /* @ts-ignore */
|
|
1395
|
+
...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
1396
|
+
tool = model('pencil', /* @ts-ignore */
|
|
1397
|
+
...(ngDevMode ? [{ debugName: "tool" }] : /* istanbul ignore next */ []));
|
|
1398
|
+
title = input('Whiteboard', /* @ts-ignore */
|
|
1399
|
+
...(ngDevMode ? [{ debugName: "title" }] : /* istanbul ignore next */ []));
|
|
1400
|
+
subtitle = input('', /* @ts-ignore */
|
|
1401
|
+
...(ngDevMode ? [{ debugName: "subtitle" }] : /* istanbul ignore next */ []));
|
|
1402
|
+
locale = input('en', /* @ts-ignore */
|
|
1403
|
+
...(ngDevMode ? [{ debugName: "locale" }] : /* istanbul ignore next */ []));
|
|
1404
|
+
toolLocked = model(true, /* @ts-ignore */
|
|
1405
|
+
...(ngDevMode ? [{ debugName: "toolLocked" }] : /* istanbul ignore next */ []));
|
|
1406
|
+
pressureSensitive = model(false, /* @ts-ignore */
|
|
1407
|
+
...(ngDevMode ? [{ debugName: "pressureSensitive" }] : /* istanbul ignore next */ []));
|
|
1408
|
+
drawingStyle = model({ stroke: '#245bff', fill: 'transparent', strokeWidth: 2, opacity: 1, lineStyle: 'solid', fontSize: 24 }, /* @ts-ignore */
|
|
1409
|
+
...(ngDevMode ? [{ debugName: "drawingStyle" }] : /* istanbul ignore next */ []));
|
|
1410
|
+
readOnly = input(false, { ...(ngDevMode ? { debugName: "readOnly" } : /* istanbul ignore next */ {}), alias: 'readonly', transform: booleanAttribute });
|
|
1411
|
+
showToolbar = input(true, { ...(ngDevMode ? { debugName: "showToolbar" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
1412
|
+
showGrid = model(true, /* @ts-ignore */
|
|
1413
|
+
...(ngDevMode ? [{ debugName: "showGrid" }] : /* istanbul ignore next */ []));
|
|
1414
|
+
showProperties = model(true, /* @ts-ignore */
|
|
1415
|
+
...(ngDevMode ? [{ debugName: "showProperties" }] : /* istanbul ignore next */ []));
|
|
1416
|
+
colors = input(['#12203b', '#e7333f', '#29a34a', '#245bff', '#e9aa16'], /* @ts-ignore */
|
|
1417
|
+
...(ngDevMode ? [{ debugName: "colors" }] : /* istanbul ignore next */ []));
|
|
1418
|
+
selectionChange = output();
|
|
1419
|
+
viewportChange = output();
|
|
1420
|
+
exported = output();
|
|
1421
|
+
importError = output();
|
|
1422
|
+
canUndo = signal(false, /* @ts-ignore */
|
|
1423
|
+
...(ngDevMode ? [{ debugName: "canUndo" }] : /* istanbul ignore next */ []));
|
|
1424
|
+
canRedo = signal(false, /* @ts-ignore */
|
|
1425
|
+
...(ngDevMode ? [{ debugName: "canRedo" }] : /* istanbul ignore next */ []));
|
|
1426
|
+
selectedElements = signal([], /* @ts-ignore */
|
|
1427
|
+
...(ngDevMode ? [{ debugName: "selectedElements" }] : /* istanbul ignore next */ []));
|
|
1428
|
+
viewport = signal({ x: 0, y: 0, zoom: 1 }, /* @ts-ignore */
|
|
1429
|
+
...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
|
|
1430
|
+
zoomLabel = computed(() => `${Math.round(this.viewport().zoom * 100)}%`, /* @ts-ignore */
|
|
1431
|
+
...(ngDevMode ? [{ debugName: "zoomLabel" }] : /* istanbul ignore next */ []));
|
|
1432
|
+
style = this.drawingStyle;
|
|
1433
|
+
labels = computed(() => WHITEBOARD_LABELS[this.locale()], /* @ts-ignore */
|
|
1434
|
+
...(ngDevMode ? [{ debugName: "labels" }] : /* istanbul ignore next */ []));
|
|
1435
|
+
fills = ['#ffccd2', '#b4efc3', '#bde3ff', '#ffedaa'];
|
|
1436
|
+
textDraft = signal('', /* @ts-ignore */
|
|
1437
|
+
...(ngDevMode ? [{ debugName: "textDraft" }] : /* istanbul ignore next */ []));
|
|
1438
|
+
textEdit = signal(undefined, /* @ts-ignore */
|
|
1439
|
+
...(ngDevMode ? [{ debugName: "textEdit" }] : /* istanbul ignore next */ []));
|
|
1440
|
+
textEditorLayout = computed(() => {
|
|
1441
|
+
const element = this.textEdit();
|
|
1442
|
+
return element && this.engine?.textEditorLayout(element, this.textDraft());
|
|
1443
|
+
}, /* @ts-ignore */
|
|
1444
|
+
...(ngDevMode ? [{ debugName: "textEditorLayout" }] : /* istanbul ignore next */ []));
|
|
1445
|
+
textEditorTransform = computed(() => {
|
|
1446
|
+
const element = this.textEdit();
|
|
1447
|
+
if (!element)
|
|
1448
|
+
return undefined;
|
|
1449
|
+
const { x, y, zoom } = this.viewport();
|
|
1450
|
+
const left = x + element.x * zoom, top = y + element.y * zoom;
|
|
1451
|
+
return `translate(${left}px, ${top}px) rotate(${element.rotation ?? 0}deg) scale(${zoom * (element.scaleX ?? 1)}, ${zoom * (element.scaleY ?? 1)})`;
|
|
1452
|
+
}, /* @ts-ignore */
|
|
1453
|
+
...(ngDevMode ? [{ debugName: "textEditorTransform" }] : /* istanbul ignore next */ []));
|
|
1454
|
+
selectedText = computed(() => this.selectedElements().find(hasWhiteboardText), /* @ts-ignore */
|
|
1455
|
+
...(ngDevMode ? [{ debugName: "selectedText" }] : /* istanbul ignore next */ []));
|
|
1456
|
+
propertyControls = computed(() => {
|
|
1457
|
+
const tool = this.tool();
|
|
1458
|
+
const editing = this.textEdit();
|
|
1459
|
+
const targets = editing ? [editing] : this.selectedElements();
|
|
1460
|
+
if (tool === 'hand' || tool === 'eraser' || (tool === 'select' && !targets.length))
|
|
1461
|
+
return undefined;
|
|
1462
|
+
const types = targets.length ? targets.map(element => element.type) : [tool];
|
|
1463
|
+
const hasOutline = (type) => type !== 'text' && type !== 'note';
|
|
1464
|
+
const strokeWidth = types.every(hasOutline);
|
|
1465
|
+
const fill = types.every(type => type === 'rectangle' || type === 'diamond' || type === 'ellipse' || type === 'note');
|
|
1466
|
+
const arrowhead = types.every(type => type === 'arrow');
|
|
1467
|
+
const labels = this.labels();
|
|
1468
|
+
return {
|
|
1469
|
+
colorLabel: strokeWidth ? labels.stroke : types.some(hasOutline) ? labels.color : labels.textColor,
|
|
1470
|
+
fillLabel: arrowhead ? labels.arrowheadColor : fill ? labels.fill : undefined,
|
|
1471
|
+
arrowhead,
|
|
1472
|
+
strokeWidth,
|
|
1473
|
+
lineStyle: strokeWidth && targets.every(element => element.type !== 'pencil' || !element.pressures),
|
|
1474
|
+
typography: !!editing || (targets.length ? targets.every(hasWhiteboardText) : tool === 'text' || tool === 'note'),
|
|
1475
|
+
};
|
|
1476
|
+
}, /* @ts-ignore */
|
|
1477
|
+
...(ngDevMode ? [{ debugName: "propertyControls" }] : /* istanbul ignore next */ []));
|
|
1478
|
+
typography = computed(() => {
|
|
1479
|
+
const element = this.textEdit() ?? this.selectedText();
|
|
1480
|
+
const { fontFamily, fontSize, textAlign } = element ?? this.style();
|
|
1481
|
+
return {
|
|
1482
|
+
fontFamily: fontFamily ?? whiteboardFontFamily,
|
|
1483
|
+
fontSize,
|
|
1484
|
+
textAlign: textAlign ?? (element?.type === 'rectangle' ? 'center' : 'left'),
|
|
1485
|
+
};
|
|
1486
|
+
}, /* @ts-ignore */
|
|
1487
|
+
...(ngDevMode ? [{ debugName: "typography" }] : /* istanbul ignore next */ []));
|
|
1488
|
+
fontOptions = [
|
|
1489
|
+
{ key: 'handwritten', value: 'Caveat, cursive', icon: 'fluent:edit-24-regular' },
|
|
1490
|
+
{ key: 'sans', value: whiteboardFontFamily, icon: 'fluent:text-font-24-regular' },
|
|
1491
|
+
{ key: 'mono', value: 'monospace', icon: 'fluent:code-24-regular' },
|
|
1492
|
+
{ key: 'serif', value: 'Georgia, serif' },
|
|
1493
|
+
];
|
|
1494
|
+
fontSizes = [
|
|
1495
|
+
{ label: 'S', value: 16 }, { label: 'M', value: 24 },
|
|
1496
|
+
{ label: 'L', value: 32 }, { label: 'XL', value: 48 },
|
|
1497
|
+
];
|
|
1498
|
+
textAlignments = ['left', 'center', 'right'];
|
|
1499
|
+
errorMessage = signal('', /* @ts-ignore */
|
|
1500
|
+
...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
|
|
1501
|
+
toolLabel = computed(() => {
|
|
1502
|
+
const selected = this.selectedElements();
|
|
1503
|
+
return selected.length > 1 ? `${selected.length} ${this.labels().objects}` : this.labels().tools[selected[0]?.type ?? this.tool()];
|
|
1504
|
+
}, /* @ts-ignore */
|
|
1505
|
+
...(ngDevMode ? [{ debugName: "toolLabel" }] : /* istanbul ignore next */ []));
|
|
1506
|
+
tools = [
|
|
1507
|
+
{ value: 'hand', label: 'Hand', icon: 'fluent:hand-left-24-regular', shortcut: 'H' },
|
|
1508
|
+
{ value: 'select', label: 'Select', icon: 'fluent:cursor-24-regular', shortcut: 'V' },
|
|
1509
|
+
{ value: 'rectangle', label: 'Rectangle', icon: 'fluent:square-24-regular', shortcut: 'R' },
|
|
1510
|
+
{ value: 'diamond', label: 'Diamond', icon: 'fluent:diamond-24-regular', shortcut: 'D' },
|
|
1511
|
+
{ value: 'ellipse', label: 'Ellipse', icon: 'fluent:circle-24-regular', shortcut: 'O' },
|
|
1512
|
+
{ value: 'arrow', label: 'Arrow', icon: 'fluent:arrow-right-24-regular', shortcut: 'A' },
|
|
1513
|
+
{ value: 'line', label: 'Line', icon: 'fluent:line-horizontal-1-24-regular', shortcut: 'L' },
|
|
1514
|
+
{ value: 'pencil', label: 'Pencil', icon: 'fluent:edit-24-regular', shortcut: 'P' },
|
|
1515
|
+
{ value: 'text', label: 'Text', icon: 'fluent:text-t-24-regular', shortcut: 'T' },
|
|
1516
|
+
{ value: 'note', label: 'Note', icon: 'fluent:note-24-regular', shortcut: 'N' },
|
|
1517
|
+
{ value: 'eraser', label: 'Eraser', icon: 'fluent:eraser-24-regular', shortcut: 'E' },
|
|
1518
|
+
];
|
|
1519
|
+
canvas = viewChild.required('canvas', /* @ts-ignore */
|
|
1520
|
+
...(ngDevMode ? [{ debugName: "canvas" }] : /* istanbul ignore next */ []));
|
|
1521
|
+
textEditor = viewChild('textEditor', /* @ts-ignore */
|
|
1522
|
+
...(ngDevMode ? [{ debugName: "textEditor" }] : /* istanbul ignore next */ []));
|
|
1523
|
+
document = inject(DOCUMENT);
|
|
1524
|
+
zone = inject(NgZone);
|
|
1525
|
+
destroyRef = inject(DestroyRef);
|
|
1526
|
+
confirm = inject(ConfirmManager);
|
|
1527
|
+
engine;
|
|
1528
|
+
resizeObserver;
|
|
1529
|
+
lastDocument;
|
|
1530
|
+
previousTool = 'select';
|
|
1531
|
+
focusedTextEditor;
|
|
1532
|
+
constructor() {
|
|
1533
|
+
effect(() => {
|
|
1534
|
+
const document = this.value();
|
|
1535
|
+
if (this.engine && document !== this.lastDocument) {
|
|
1536
|
+
this.textEdit.set(undefined);
|
|
1537
|
+
this.engine.setDocument(document);
|
|
1538
|
+
this.lastDocument = document;
|
|
1539
|
+
this.canUndo.set(false);
|
|
1540
|
+
this.canRedo.set(false);
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
1543
|
+
effect(() => { const tool = this.tool(); this.engine?.setTool(tool); });
|
|
1544
|
+
effect(() => {
|
|
1545
|
+
const readonly = this.readOnly();
|
|
1546
|
+
if (readonly)
|
|
1547
|
+
this.textEdit.set(undefined);
|
|
1548
|
+
this.engine?.setReadonly(readonly);
|
|
1549
|
+
});
|
|
1550
|
+
effect(() => { const locked = this.toolLocked(); if (this.engine)
|
|
1551
|
+
this.engine.toolLocked = locked; });
|
|
1552
|
+
effect(() => { const pressure = this.pressureSensitive(); if (this.engine)
|
|
1553
|
+
this.engine.pressureSensitive = pressure; });
|
|
1554
|
+
effect(() => { const style = this.style(); if (this.engine)
|
|
1555
|
+
this.engine.style = style; });
|
|
1556
|
+
afterRenderEffect(() => {
|
|
1557
|
+
const editor = this.textEditor()?.nativeElement;
|
|
1558
|
+
if (!editor || this.textEdit()?.type !== 'text')
|
|
1559
|
+
return;
|
|
1560
|
+
const layout = this.textEditorLayout();
|
|
1561
|
+
if (!layout)
|
|
1562
|
+
return;
|
|
1563
|
+
// Native wrapping can differ from canvas metrics, especially at a word boundary.
|
|
1564
|
+
editor.style.height = `${Math.ceil(layout.height)}px`;
|
|
1565
|
+
editor.style.height = `${editor.scrollHeight}px`;
|
|
1566
|
+
editor.scrollTop = 0;
|
|
1567
|
+
});
|
|
1568
|
+
afterEveryRender(() => {
|
|
1569
|
+
const container = this.canvas().nativeElement;
|
|
1570
|
+
const editor = this.textEditor()?.nativeElement;
|
|
1571
|
+
if (editor !== this.focusedTextEditor) {
|
|
1572
|
+
this.focusedTextEditor = editor;
|
|
1573
|
+
if (editor) {
|
|
1574
|
+
editor.focus({ preventScroll: true });
|
|
1575
|
+
editor.setSelectionRange(editor.value.length, editor.value.length);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
if (this.engine) {
|
|
1579
|
+
// Angular can replace the reserved host during template hot reload. Keep the
|
|
1580
|
+
// existing stage and history, and restore its imperative canvas DOM afterwards.
|
|
1581
|
+
if (!container.contains(this.engine.stage.content)) {
|
|
1582
|
+
this.resizeObserver?.unobserve(this.engine.stage.container());
|
|
1583
|
+
this.engine.stage.container(container);
|
|
1584
|
+
this.resizeObserver?.observe(container);
|
|
1585
|
+
this.engine.resize(container.clientWidth, container.clientHeight);
|
|
1586
|
+
}
|
|
1587
|
+
return;
|
|
1588
|
+
}
|
|
1589
|
+
this.zone.runOutsideAngular(() => {
|
|
1590
|
+
this.lastDocument = this.value();
|
|
1591
|
+
this.engine = new WhiteboardEngine(this.canvas().nativeElement, this.value(), {
|
|
1592
|
+
change: (value, undo, redo) => this.zone.run(() => {
|
|
1593
|
+
this.lastDocument = value;
|
|
1594
|
+
this.value.set(value);
|
|
1595
|
+
this.canUndo.set(undo);
|
|
1596
|
+
this.canRedo.set(redo);
|
|
1597
|
+
}),
|
|
1598
|
+
selection: elements => this.zone.run(() => {
|
|
1599
|
+
this.selectedElements.set(elements);
|
|
1600
|
+
if (elements[0]) {
|
|
1601
|
+
const { stroke, fill, strokeWidth, opacity, lineStyle } = elements[0];
|
|
1602
|
+
const { fontSize, fontFamily, textAlign } = this.selectedText() ?? this.style();
|
|
1603
|
+
const style = { stroke, fill, strokeWidth, opacity, lineStyle, fontSize, fontFamily, textAlign };
|
|
1604
|
+
this.style.set(style);
|
|
1605
|
+
if (this.engine)
|
|
1606
|
+
this.engine.style = style;
|
|
1607
|
+
}
|
|
1608
|
+
this.selectionChange.emit(elements);
|
|
1609
|
+
}),
|
|
1610
|
+
viewport: view => this.zone.run(() => { this.viewport.set(view); this.viewportChange.emit(view); }),
|
|
1611
|
+
editText: request => this.zone.run(() => this.editText(request)),
|
|
1612
|
+
drawComplete: () => this.zone.run(() => this.tool.set('select')),
|
|
1613
|
+
});
|
|
1614
|
+
this.engine.style = this.style();
|
|
1615
|
+
this.engine.toolLocked = this.toolLocked();
|
|
1616
|
+
this.engine.pressureSensitive = this.pressureSensitive();
|
|
1617
|
+
this.engine.setTool(this.tool());
|
|
1618
|
+
this.engine.setReadonly(this.readOnly());
|
|
1619
|
+
this.resizeObserver = new ResizeObserver(entries => {
|
|
1620
|
+
const size = entries[0]?.contentRect;
|
|
1621
|
+
if (size)
|
|
1622
|
+
this.engine?.resize(size.width, size.height);
|
|
1623
|
+
});
|
|
1624
|
+
this.resizeObserver.observe(container);
|
|
1625
|
+
this.destroyRef.onDestroy(() => { this.resizeObserver?.disconnect(); this.engine?.destroy(); });
|
|
1626
|
+
});
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
undo() { this.engine?.undo(); }
|
|
1630
|
+
redo() { this.engine?.redo(); }
|
|
1631
|
+
clear() { this.engine?.clear(); }
|
|
1632
|
+
deleteSelection() { this.engine?.deleteSelection(); }
|
|
1633
|
+
duplicateSelection() { this.engine?.duplicateSelection(); }
|
|
1634
|
+
zoomIn() { this.engine?.zoom(1.2); }
|
|
1635
|
+
zoomOut() { this.engine?.zoom(1 / 1.2); }
|
|
1636
|
+
resetView() { this.engine?.setViewport({ x: 0, y: 0, zoom: 1 }); }
|
|
1637
|
+
fitToContent() { this.engine?.fitToContent(); }
|
|
1638
|
+
/** Repaint after the consuming application finishes loading a custom canvas font. */
|
|
1639
|
+
redraw() { this.engine?.redraw(); }
|
|
1640
|
+
exportJson() { return JSON.stringify(this.value(), null, 2); }
|
|
1641
|
+
exportPng(options) {
|
|
1642
|
+
const result = this.engine?.exportPng(options) ?? null;
|
|
1643
|
+
if (result)
|
|
1644
|
+
this.exported.emit(result);
|
|
1645
|
+
return result;
|
|
1646
|
+
}
|
|
1647
|
+
importJson(json) {
|
|
1648
|
+
if (this.readOnly())
|
|
1649
|
+
return;
|
|
1650
|
+
const value = parseWhiteboardDocument(json);
|
|
1651
|
+
this.textEdit.set(undefined);
|
|
1652
|
+
this.value.set(value);
|
|
1653
|
+
this.engine?.setDocument(value);
|
|
1654
|
+
this.lastDocument = value;
|
|
1655
|
+
this.canUndo.set(false);
|
|
1656
|
+
this.canRedo.set(false);
|
|
1657
|
+
this.errorMessage.set('');
|
|
1658
|
+
this.fitToContent();
|
|
1659
|
+
}
|
|
1660
|
+
updateStyle(style) {
|
|
1661
|
+
if (this.readOnly())
|
|
1662
|
+
return;
|
|
1663
|
+
this.style.update(current => ({ ...current, ...style }));
|
|
1664
|
+
this.engine?.applyStyle(style);
|
|
1665
|
+
}
|
|
1666
|
+
updateTypography(style) {
|
|
1667
|
+
if (this.readOnly())
|
|
1668
|
+
return;
|
|
1669
|
+
this.style.update(current => ({ ...current, ...style }));
|
|
1670
|
+
const element = this.engine?.applyTypography(style);
|
|
1671
|
+
if (element)
|
|
1672
|
+
this.textEdit.set(element);
|
|
1673
|
+
}
|
|
1674
|
+
keepTextFocus(event) {
|
|
1675
|
+
if (this.textEdit())
|
|
1676
|
+
event.preventDefault();
|
|
1677
|
+
}
|
|
1678
|
+
confirmClear() {
|
|
1679
|
+
this.confirm.open({ title: this.labels().clearTitle, description: this.labels().clearDescription })
|
|
1680
|
+
.confirmed.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => this.clear());
|
|
1681
|
+
}
|
|
1682
|
+
async importFile(event) {
|
|
1683
|
+
const input = event.target;
|
|
1684
|
+
const file = input.files?.[0];
|
|
1685
|
+
if (!file)
|
|
1686
|
+
return;
|
|
1687
|
+
try {
|
|
1688
|
+
if (file.size > 10 * 1024 * 1024)
|
|
1689
|
+
throw new Error('Choose a whiteboard JSON file smaller than 10 MB.');
|
|
1690
|
+
this.importJson(await file.text());
|
|
1691
|
+
}
|
|
1692
|
+
catch (error) {
|
|
1693
|
+
const message = error instanceof Error ? error : new Error('Unable to import whiteboard.');
|
|
1694
|
+
this.errorMessage.set(message.message);
|
|
1695
|
+
this.importError.emit(message);
|
|
1696
|
+
}
|
|
1697
|
+
finally {
|
|
1698
|
+
input.value = '';
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
downloadPng() {
|
|
1702
|
+
const data = this.exportPng();
|
|
1703
|
+
if (data)
|
|
1704
|
+
this.download(data, 'whiteboard.png');
|
|
1705
|
+
}
|
|
1706
|
+
downloadJson() {
|
|
1707
|
+
const url = URL.createObjectURL(new Blob([this.exportJson()], { type: 'application/json' }));
|
|
1708
|
+
this.download(url, 'whiteboard.json');
|
|
1709
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
1710
|
+
}
|
|
1711
|
+
download(url, filename) {
|
|
1712
|
+
const link = this.document.createElement('a');
|
|
1713
|
+
link.href = url;
|
|
1714
|
+
link.download = filename;
|
|
1715
|
+
link.click();
|
|
1716
|
+
}
|
|
1717
|
+
editText(request) {
|
|
1718
|
+
if (this.textEdit())
|
|
1719
|
+
return;
|
|
1720
|
+
this.releasePan();
|
|
1721
|
+
const element = this.engine?.beginTextEdit(request);
|
|
1722
|
+
if (!element)
|
|
1723
|
+
return;
|
|
1724
|
+
this.textDraft.set(element.text ?? '');
|
|
1725
|
+
this.textEdit.set(element);
|
|
1726
|
+
}
|
|
1727
|
+
finishTextEditing(text) {
|
|
1728
|
+
if (!this.textEdit() || this.destroyRef.destroyed)
|
|
1729
|
+
return;
|
|
1730
|
+
this.textEdit.set(undefined);
|
|
1731
|
+
this.engine?.finishTextEdit(this.readOnly() ? undefined : text);
|
|
1732
|
+
}
|
|
1733
|
+
onTextKeydown(event, text) {
|
|
1734
|
+
if (event.isComposing)
|
|
1735
|
+
return;
|
|
1736
|
+
const cancel = event.key === 'Escape';
|
|
1737
|
+
const save = event.key === 'Enter' && (event.ctrlKey || event.metaKey);
|
|
1738
|
+
if (!cancel && !save)
|
|
1739
|
+
return;
|
|
1740
|
+
event.preventDefault();
|
|
1741
|
+
this.finishTextEditing(save ? text : undefined);
|
|
1742
|
+
this.canvas().nativeElement.focus({ preventScroll: true });
|
|
1743
|
+
}
|
|
1744
|
+
focusCanvasFromPointer(event) {
|
|
1745
|
+
if (event.detail > 0)
|
|
1746
|
+
this.canvas().nativeElement.focus({ preventScroll: true });
|
|
1747
|
+
}
|
|
1748
|
+
selectTool(tool, toggle = false) {
|
|
1749
|
+
const active = this.tool();
|
|
1750
|
+
if (tool === 'hand' || tool === 'eraser') {
|
|
1751
|
+
if (tool === active && toggle)
|
|
1752
|
+
tool = this.previousTool;
|
|
1753
|
+
else if (active !== 'hand' && active !== 'eraser')
|
|
1754
|
+
this.previousTool = active;
|
|
1755
|
+
}
|
|
1756
|
+
this.tool.set(tool);
|
|
1757
|
+
this.engine?.setTool(tool);
|
|
1758
|
+
}
|
|
1759
|
+
releasePan() { this.engine?.setSpace(false); }
|
|
1760
|
+
onKeyup(event) { if (event.code === 'Space')
|
|
1761
|
+
this.releasePan(); }
|
|
1762
|
+
onKeydown(event) {
|
|
1763
|
+
// The tool strip stays keyboard-accessible without sending shortcuts from editors or other boards.
|
|
1764
|
+
const onCanvas = event.target === this.canvas().nativeElement;
|
|
1765
|
+
const onToolStrip = event.target instanceof HTMLElement && !!event.target.closest('.drawing-tools');
|
|
1766
|
+
if ((!onCanvas && !onToolStrip) || this.textEdit() || event.defaultPrevented || event.isComposing)
|
|
1767
|
+
return;
|
|
1768
|
+
const key = event.key.toLowerCase(), modifier = event.ctrlKey || event.metaKey;
|
|
1769
|
+
if (onCanvas && event.code === 'Space' && !modifier && !event.altKey) {
|
|
1770
|
+
event.preventDefault();
|
|
1771
|
+
this.engine?.setSpace(true);
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
if (key === 'escape') {
|
|
1775
|
+
const active = this.tool();
|
|
1776
|
+
this.engine?.deselect();
|
|
1777
|
+
this.selectTool(active === 'hand' || active === 'eraser' ? this.previousTool : 'select');
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1780
|
+
if (key === '+' || key === '=') {
|
|
1781
|
+
event.preventDefault();
|
|
1782
|
+
this.zoomIn();
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
if (key === '-') {
|
|
1786
|
+
event.preventDefault();
|
|
1787
|
+
this.zoomOut();
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
if (key === '0') {
|
|
1791
|
+
event.preventDefault();
|
|
1792
|
+
this.fitToContent();
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
if (this.readOnly())
|
|
1796
|
+
return;
|
|
1797
|
+
if (modifier && key === 'a') {
|
|
1798
|
+
event.preventDefault();
|
|
1799
|
+
this.selectTool('select');
|
|
1800
|
+
this.engine?.selectAll();
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
if (modifier && key === 'z') {
|
|
1804
|
+
event.preventDefault();
|
|
1805
|
+
event.shiftKey ? this.redo() : this.undo();
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
if (modifier && key === 'y') {
|
|
1809
|
+
event.preventDefault();
|
|
1810
|
+
this.redo();
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
if (modifier && key === 'd') {
|
|
1814
|
+
event.preventDefault();
|
|
1815
|
+
this.duplicateSelection();
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
if (key === 'delete' || key === 'backspace') {
|
|
1819
|
+
event.preventDefault();
|
|
1820
|
+
this.deleteSelection();
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
if (onCanvas && !modifier && !event.altKey) {
|
|
1824
|
+
const step = event.shiftKey ? 10 : 1;
|
|
1825
|
+
const x = key === 'arrowleft' ? -step : key === 'arrowright' ? step : 0;
|
|
1826
|
+
const y = key === 'arrowup' ? -step : key === 'arrowdown' ? step : 0;
|
|
1827
|
+
if ((x || y) && this.engine?.nudgeSelection(x, y)) {
|
|
1828
|
+
event.preventDefault();
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
if (!modifier && !event.altKey && !event.shiftKey && !event.repeat) {
|
|
1833
|
+
if (key === 'q') {
|
|
1834
|
+
event.preventDefault();
|
|
1835
|
+
this.toolLocked.update(locked => !locked);
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
const tool = this.tools.find(tool => tool.shortcut.toLowerCase() === key);
|
|
1839
|
+
if (tool) {
|
|
1840
|
+
event.preventDefault();
|
|
1841
|
+
this.selectTool(tool.value, true);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: Whiteboard, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1846
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: Whiteboard, isStandalone: true, selector: "ngs-whiteboard", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, tool: { classPropertyName: "tool", publicName: "tool", isSignal: true, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: true, isRequired: false, transformFunction: null }, subtitle: { classPropertyName: "subtitle", publicName: "subtitle", isSignal: true, isRequired: false, transformFunction: null }, locale: { classPropertyName: "locale", publicName: "locale", isSignal: true, isRequired: false, transformFunction: null }, toolLocked: { classPropertyName: "toolLocked", publicName: "toolLocked", isSignal: true, isRequired: false, transformFunction: null }, pressureSensitive: { classPropertyName: "pressureSensitive", publicName: "pressureSensitive", isSignal: true, isRequired: false, transformFunction: null }, drawingStyle: { classPropertyName: "drawingStyle", publicName: "drawingStyle", isSignal: true, isRequired: false, transformFunction: null }, readOnly: { classPropertyName: "readOnly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, showToolbar: { classPropertyName: "showToolbar", publicName: "showToolbar", isSignal: true, isRequired: false, transformFunction: null }, showGrid: { classPropertyName: "showGrid", publicName: "showGrid", isSignal: true, isRequired: false, transformFunction: null }, showProperties: { classPropertyName: "showProperties", publicName: "showProperties", isSignal: true, isRequired: false, transformFunction: null }, colors: { classPropertyName: "colors", publicName: "colors", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { value: "valueChange", tool: "toolChange", toolLocked: "toolLockedChange", pressureSensitive: "pressureSensitiveChange", drawingStyle: "drawingStyleChange", showGrid: "showGridChange", showProperties: "showPropertiesChange", selectionChange: "selectionChange", viewportChange: "viewportChange", exported: "exported", importError: "importError" }, host: { listeners: { "keydown": "onKeydown($event)", "window:keyup": "onKeyup($event)", "window:blur": "releasePan()" }, properties: { "class.ngs-whiteboard-grid": "showGrid()", "class.ngs-whiteboard-readonly": "readOnly()" }, classAttribute: "ngs-whiteboard @container/whiteboard" }, viewQueries: [{ propertyName: "canvas", first: true, predicate: ["canvas"], descendants: true, isSignal: true }, { propertyName: "textEditor", first: true, predicate: ["textEditor"], descendants: true, isSignal: true }], exportAs: ["ngsWhiteboard"], ngImport: i0, template: "<div #canvas class=\"canvas absolute inset-0\" tabindex=\"0\" role=\"region\"\n [attr.aria-label]=\"title() + '. ' + labels().canvasHelp\"></div>\n\n@if (textEdit(); as element) {\n @if (textEditorLayout(); as layout) {\n <textarea #textEditor ngsInput class=\"text-editor\" [attr.aria-label]=\"element.type === 'note' ? labels().noteText : labels().text\"\n [class.auto-height]=\"element.type === 'text'\"\n [attr.placeholder]=\"element.type === 'note' ? labels().notePlaceholder : null\" [value]=\"textDraft()\"\n [style.transform]=\"textEditorTransform()\" [style.width.px]=\"layout.width\"\n [style.height.px]=\"element.type === 'text' ? null : layout.height\"\n [style.padding.px]=\"layout.padding\" [style.padding-top.px]=\"layout.paddingTop\" [style.font-size.px]=\"element.fontSize\"\n [style.font-family]=\"typography().fontFamily\" [style.line-height]=\"layout.lineHeight\"\n [style.text-align]=\"typography().textAlign\" [style.color]=\"element.stroke\" [style.opacity]=\"element.opacity\"\n (input)=\"textDraft.set(textEditor.value)\" (blur)=\"finishTextEditing(textEditor.value)\"\n (keydown)=\"onTextKeydown($event, textEditor.value)\"></textarea>\n }\n}\n\n@if (showToolbar()) {\n @let controls = propertyControls();\n @let toolbarTooltipDelay = 1000;\n <div class=\"pointer-events-none absolute inset-x-6 top-4 z-10 flex items-start justify-between gap-4\">\n <div class=\"flex min-w-0 items-center gap-2 @3xl/whiteboard:gap-4\">\n <button ngsIconButton type=\"button\" class=\"board-mark pointer-events-auto shrink-0 rounded-2xl!\" [attr.aria-label]=\"labels().properties\"\n [attr.aria-pressed]=\"!!controls && !readOnly() && showProperties()\" [disabled]=\"!controls || readOnly()\"\n (click)=\"showProperties.set(!showProperties())\">\n <ngs-icon name=\"fluent:whiteboard-24-regular\"/>\n </button>\n <div class=\"flex min-w-0 flex-col gap-1\">\n <span class=\"board-title truncate leading-6 font-bold\">{{ title() }}</span>\n @if (subtitle()) { <span class=\"board-subtitle truncate text-sm\">{{ subtitle() }}</span> }\n </div>\n </div>\n <div class=\"pointer-events-auto flex shrink-0 items-center gap-3 pt-1\">\n <button ngsButton=\"outlined\" type=\"button\" class=\"export-action\" (click)=\"downloadPng()\" [attr.aria-label]=\"labels().exportPng\">\n <ngs-icon name=\"fluent:arrow-export-up-24-regular\"/>{{ labels().export }}\n </button>\n <button ngsIconButton type=\"button\" class=\"more-action rounded-xl!\" [ngsMenuTriggerFor]=\"fileMenu\" [attr.aria-label]=\"labels().more\">\n <ngs-icon name=\"fluent:more-vertical-24-regular\"/>\n </button>\n </div>\n </div>\n <div class=\"drawing-tools pointer-events-auto absolute inset-x-6 top-24 z-10 mx-auto h-16 w-max max-w-[calc(100%-3rem)] rounded-2xl @7xl/whiteboard:top-4 @7xl/whiteboard:h-[4.5rem]\">\n <ngs-scrollbar-area [absolute]=\"false\" class=\"relative! h-full\">\n <ngs-toolbar class=\"h-full w-max! px-2\" [attr.aria-label]=\"labels().properties\">\n <button ngsIconButton type=\"button\" class=\"tool-lock\" [attr.aria-label]=\"labels().lockTool\"\n [ngsTooltip]=\"labels().lockTool\" [ngsTooltipShowDelay]=\"toolbarTooltipDelay\"\n [attr.aria-pressed]=\"toolLocked()\" (click)=\"toolLocked.set(!toolLocked())\" [disabled]=\"readOnly()\">\n <ngs-icon [name]=\"toolLocked() ? 'fluent:lock-closed-24-regular' : 'fluent:lock-open-24-regular'\"/>\n </button>\n <ngs-button-toggle-group onlyIcon hideSelectionIndicator [value]=\"tool()\" (valueChange)=\"selectTool($event)\" (click)=\"focusCanvasFromPointer($event)\">\n @for (item of tools; track item.value) {\n <ngs-button-toggle class=\"w-14\" [value]=\"item.value\" [disabled]=\"readOnly() && item.value !== 'hand' && item.value !== 'select'\"\n [ngsTooltip]=\"labels().tools[item.value] + ' (' + item.shortcut + ')'\" [ngsTooltipShowDelay]=\"toolbarTooltipDelay\">\n <span class=\"flex flex-col items-center gap-1.5\" [attr.aria-label]=\"labels().tools[item.value]\">\n <ngs-icon [name]=\"item.icon\" [class.tool-cursor-icon]=\"item.value === 'select'\"/>\n @if (item.value !== 'hand') { <span class=\"tool-shortcut text-[9px] leading-none\" aria-hidden=\"true\">{{ item.shortcut }}</span> }\n </span>\n </ngs-button-toggle>\n @if (item.value === 'hand') { <ngs-divider vertical fixedHeight class=\"mx-2 h-9!\"/> }\n }\n </ngs-button-toggle-group>\n </ngs-toolbar>\n </ngs-scrollbar-area>\n </div>\n\n @if (controls && showProperties() && !readOnly()) {\n <ngs-card class=\"properties-panel absolute left-6 top-44 z-10 flex w-70 flex-col @7xl/whiteboard:top-28\" appearance=\"outlined\">\n <ngs-card-header class=\"flex h-12.5 shrink-0 items-center justify-between px-4! py-0!\">\n <span class=\"text-lg font-semibold\">{{ toolLabel() }}</span>\n <ngs-card-aside>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().closeProperties\" (click)=\"showProperties.set(false)\">\n <ngs-icon name=\"fluent:dismiss-24-regular\"/>\n </button>\n </ngs-card-aside>\n </ngs-card-header>\n <ngs-divider/>\n <ngs-card-content class=\"grid! min-h-0 p-0!\">\n <ngs-scrollbar-area [absolute]=\"false\" class=\"relative! grid! min-h-0\">\n <div class=\"flex flex-col gap-4 p-4\">\n <div class=\"flex flex-col gap-2.5\">\n <span class=\"property-label text-sm\">{{ controls.colorLabel }}</span>\n <div class=\"flex items-center gap-3\">\n <ngs-color-switcher [colors]=\"colors()\" [selectedColor]=\"style().stroke\" (colorChange)=\"updateStyle({stroke: $event})\"/>\n <button ngs-color-picker-thumbnail class=\"custom-color\" [ngsColorPickerTriggerFor]=\"customColor\"\n [attr.aria-label]=\"labels().customColor\" [ngsTooltip]=\"labels().customColor\"></button>\n </div>\n </div>\n @if (controls.fillLabel) {\n <div class=\"flex flex-col gap-2.5\">\n <span class=\"property-label text-sm\">{{ controls.fillLabel }}</span>\n <div class=\"flex items-center gap-3\">\n <button ngs-color-picker-thumbnail [color]=\"controls.arrowhead ? style().stroke : 'transparent'\" [class.is-selected]=\"style().fill === 'transparent'\"\n [attr.aria-label]=\"controls.arrowhead ? labels().useStrokeColor : labels().noFill\"\n [attr.aria-pressed]=\"style().fill === 'transparent'\" (click)=\"updateStyle({fill: 'transparent'})\"></button>\n <ngs-color-switcher [colors]=\"fills\" [selectedColor]=\"style().fill\" (colorChange)=\"updateStyle({fill: $event})\"/>\n </div>\n </div>\n }\n @if (controls.strokeWidth) {\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().width }}</span>\n <ngs-segmented class=\"stroke-options\" [value]=\"style().strokeWidth\" (valueChange)=\"updateStyle({strokeWidth: $event})\" [attr.aria-label]=\"labels().width\">\n @for (width of [1, 2, 4]; track width) {\n <button ngs-segmented-button iconOnly [value]=\"width\" [attr.aria-label]=\"width + ' px'\">\n <ngs-icon ngsSegmentedIcon name=\"fluent:line-horizontal-1-24-regular\" [class.medium-stroke]=\"width === 2\" [class.heavy-stroke]=\"width === 4\"/>\n </button>\n }\n </ngs-segmented>\n </div>\n }\n @if (controls.lineStyle) {\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().lineStyle }}</span>\n <ngs-segmented class=\"stroke-options\" [value]=\"style().lineStyle\" (valueChange)=\"updateStyle({lineStyle: $event})\" [attr.aria-label]=\"labels().lineStyle\">\n <button ngs-segmented-button iconOnly value=\"solid\" [attr.aria-label]=\"labels().solid\"><ngs-icon ngsSegmentedIcon name=\"fluent:line-horizontal-1-24-regular\"/></button>\n <button ngs-segmented-button iconOnly value=\"dashed\" [attr.aria-label]=\"labels().dashed\"><ngs-icon ngsSegmentedIcon name=\"fluent:line-dashes-24-regular\" class=\"rotate-45\"/></button>\n <button ngs-segmented-button iconOnly value=\"dotted\" [attr.aria-label]=\"labels().dotted\"><ngs-icon ngsSegmentedIcon name=\"fluent:more-horizontal-24-regular\"/></button>\n </ngs-segmented>\n </div>\n }\n @if (controls.typography) {\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().fontFamily }}</span>\n <ngs-segmented class=\"typography-options\" role=\"group\" [attr.aria-label]=\"labels().fontFamily\"\n [value]=\"typography().fontFamily\" (valueChange)=\"updateTypography({fontFamily: $event})\"\n (mousedown)=\"keepTextFocus($event)\">\n @for (option of fontOptions; track option.key) {\n <button ngs-segmented-button iconOnly type=\"button\" [value]=\"option.value\"\n [attr.aria-label]=\"labels().fonts[option.key]\" [attr.aria-pressed]=\"typography().fontFamily === option.value\"\n [ngsTooltip]=\"labels().fonts[option.key]\">\n @if ('icon' in option) {\n <ngs-icon ngsSegmentedIcon [name]=\"option.icon\"/>\n } @else {\n <span ngsSegmentedIcon class=\"serif-sample\" aria-hidden=\"true\">A</span>\n }\n </button>\n }\n </ngs-segmented>\n </div>\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().fontSize }}</span>\n <ngs-segmented class=\"typography-options\" role=\"group\" [attr.aria-label]=\"labels().fontSize\"\n [value]=\"typography().fontSize\" (valueChange)=\"updateTypography({fontSize: $event})\"\n (mousedown)=\"keepTextFocus($event)\">\n @for (size of fontSizes; track size.value) {\n <button ngs-segmented-button type=\"button\" [value]=\"size.value\"\n [attr.aria-label]=\"labels().fontSizes[size.label]\" [attr.aria-pressed]=\"typography().fontSize === size.value\">\n {{ size.label }}\n </button>\n }\n </ngs-segmented>\n </div>\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().textAlign }}</span>\n <ngs-segmented class=\"typography-options\" role=\"group\" [attr.aria-label]=\"labels().textAlign\"\n [value]=\"typography().textAlign\" (valueChange)=\"updateTypography({textAlign: $event})\"\n (mousedown)=\"keepTextFocus($event)\">\n @for (align of textAlignments; track align) {\n <button ngs-segmented-button iconOnly type=\"button\" [value]=\"align\"\n [attr.aria-label]=\"labels().alignments[align]\" [attr.aria-pressed]=\"typography().textAlign === align\"\n [ngsTooltip]=\"labels().alignments[align]\">\n <ngs-icon ngsSegmentedIcon [name]=\"'fluent:text-align-' + align + '-24-regular'\"/>\n </button>\n }\n </ngs-segmented>\n </div>\n }\n <div class=\"flex flex-col gap-2\">\n <div class=\"flex items-center justify-between text-sm\"><span class=\"property-label\">{{ labels().opacity }}</span><span>{{ (style().opacity * 100).toFixed(0) }}%</span></div>\n <ngs-slider [min]=\"0\" [max]=\"100\" [step]=\"1\" class=\"w-full!\">\n <input ngsSliderThumb [value]=\"style().opacity * 100\" (valueChange)=\"updateStyle({opacity: $event / 100})\" [attr.aria-label]=\"labels().opacity\">\n </ngs-slider>\n </div>\n @if (selectedElements().length) {\n <ngs-divider/>\n <div class=\"flex items-center gap-2\">\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().duplicate\" ngsTooltip=\"Duplicate (Ctrl+D)\" (click)=\"duplicateSelection()\"><ngs-icon name=\"fluent:copy-24-regular\"/></button>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().delete\" ngsTooltip=\"Delete\" (click)=\"deleteSelection()\"><ngs-icon name=\"fluent:delete-24-regular\"/></button>\n </div>\n }\n </div>\n </ngs-scrollbar-area>\n </ngs-card-content>\n </ngs-card>\n }\n\n <div class=\"pointer-events-none absolute inset-x-6 bottom-6 z-10 flex items-end gap-4\">\n <div class=\"pointer-events-auto flex flex-wrap gap-4\">\n <ngs-toolbar class=\"zoom-toolbar w-auto! gap-0! rounded-xl p-1\" [attr.aria-label]=\"labels().resetZoom\">\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().zoomOut\" [ngsTooltip]=\"labels().zoomOut\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" (click)=\"zoomOut()\"><ngs-icon name=\"fluent:subtract-24-regular\"/></button>\n <button ngsButton type=\"button\" class=\"zoom-value\" [ngsMenuTriggerFor]=\"zoomMenu\" [attr.aria-label]=\"labels().resetZoom\" reverse>\n <ngs-icon name=\"fluent:chevron-down-16-regular\"/>{{ zoomLabel() }}\n </button>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().zoomIn\" [ngsTooltip]=\"labels().zoomIn\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" (click)=\"zoomIn()\"><ngs-icon name=\"fluent:add-24-regular\"/></button>\n <ngs-divider vertical fixedHeight class=\"mx-1\"/>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().fit\" [ngsTooltip]=\"labels().fit\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" (click)=\"fitToContent()\"><ngs-icon name=\"fluent:arrow-expand-24-regular\"/></button>\n </ngs-toolbar>\n @if (!readOnly()) {\n <ngs-toolbar class=\"history-toolbar w-auto! gap-0! rounded-xl p-1\" [attr.aria-label]=\"labels().undo\">\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().undo\" [ngsTooltip]=\"labels().undo\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" [disabled]=\"!canUndo()\" (click)=\"undo()\"><ngs-icon name=\"fluent:arrow-undo-24-regular\"/></button>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().redo\" [ngsTooltip]=\"labels().redo\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" [disabled]=\"!canRedo()\" (click)=\"redo()\"><ngs-icon name=\"fluent:arrow-redo-24-regular\"/></button>\n </ngs-toolbar>\n }\n </div>\n <span class=\"canvas-hint absolute bottom-1 left-1/2 hidden -translate-x-1/2 whitespace-nowrap rounded-full px-4 py-2 text-sm @7xl/whiteboard:block\">{{ labels().canvasHint }}</span>\n </div>\n}\n\n@if (errorMessage()) {\n <ngs-alert variant=\"negative\" class=\"absolute inset-x-4 bottom-20 z-20 text-sm\" role=\"alert\">\n {{ errorMessage() }}\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().dismiss\" (click)=\"errorMessage.set('')\"><ngs-icon name=\"fluent:dismiss-24-regular\"/></button>\n </ngs-alert>\n}\n\n<input #fileInput type=\"file\" accept=\"application/json,.json\" hidden (change)=\"importFile($event)\">\n<ngs-menu #fileMenu=\"ngsMenu\">\n <button ngs-menu-item (click)=\"downloadPng()\">{{ labels().exportPng }}</button>\n <button ngs-menu-item (click)=\"downloadJson()\">{{ labels().saveJson }}</button>\n @if (!readOnly()) {\n <button ngs-menu-item (click)=\"fileInput.click()\">{{ labels().openJson }}</button>\n <ngs-menu-divider/>\n <button ngs-menu-item [disabled]=\"!value().elements.length\" (click)=\"confirmClear()\">{{ labels().clear }}</button>\n }\n <ngs-menu-divider/>\n <button ngs-menu-item [selected]=\"showGrid()\" (click)=\"showGrid.set(!showGrid())\">{{ labels().grid }}</button>\n</ngs-menu>\n<ngs-menu #zoomMenu=\"ngsMenu\">\n <button ngs-menu-item (click)=\"resetView()\">100%</button>\n <button ngs-menu-item (click)=\"fitToContent()\">{{ labels().fit }}</button>\n</ngs-menu>\n<ng-template #customColor><ngs-color-picker [ngModel]=\"style().stroke\" (ngModelChange)=\"updateStyle({stroke: $event})\"/></ng-template>\n", styles: [":host{--ngs-whiteboard-bg: var(--ngs-color-surface, #ffffff);--ngs-whiteboard-grid-color: var(--ngs-color-primary);--ngs-whiteboard-panel-bg: var(--ngs-color-surface, #ffffff);--ngs-whiteboard-panel-shadow: 0 2px 5px var(--ngs-color-on-surface), 0 6px 18px var(--ngs-color-on-surface);display:block;position:relative;isolation:isolate;height:var(--ngs-whiteboard-height, 40rem);min-height:calc(var(--spacing, .25rem) * 96);overflow:hidden;background:var(--ngs-whiteboard-bg);color:var(--ngs-color-on-surface);font-family:var(--ngs-font-family-base);border:1px solid var(--ngs-color-border);border-radius:var(--ngs-radius-lg)}@supports (color: color-mix(in lab,red,red)){:host{--ngs-whiteboard-grid-color: color-mix(in srgb, var(--ngs-color-primary) 16%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host{--ngs-whiteboard-panel-shadow: 0 2px 5px color-mix(in srgb, var(--ngs-color-on-surface) 4%, transparent), 0 6px 18px color-mix(in srgb, var(--ngs-color-on-surface) 4%, transparent)}}:host .canvas{outline:none;touch-action:none;-webkit-user-select:none;user-select:none}:host .canvas[data-tool=pencil],:host .canvas[data-tool=rectangle],:host .canvas[data-tool=diamond],:host .canvas[data-tool=ellipse],:host .canvas[data-tool=line],:host .canvas[data-tool=arrow]{cursor:crosshair}:host .canvas[data-tool=hand]{cursor:grab}:host .canvas[data-tool=hand]:active{cursor:grabbing}:host .canvas[data-tool=text],:host .canvas[data-tool=note]{cursor:text}:host .canvas[data-tool=eraser]{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='8' cy='8' r='5' fill='none' stroke='white' stroke-width='3'/%3E%3Ccircle cx='8' cy='8' r='5' fill='none' stroke='%234b4b4b'/%3E%3C/svg%3E\") 8 8,cell}:host .canvas:focus-visible{outline:2px solid var(--ngs-state-focus-ring);outline-offset:-2px}:host textarea.text-editor{position:absolute;inset:0 auto auto 0;z-index:1;box-sizing:border-box;margin:0;border:0;outline:0;background:transparent;resize:none;overflow:auto;overflow-wrap:break-word;transform-origin:top left}:host textarea.text-editor.auto-height{overflow:hidden}:host textarea.text-editor::placeholder{color:currentColor;opacity:.65}:host.ngs-whiteboard-grid .canvas{background-image:radial-gradient(circle,var(--ngs-whiteboard-grid-color) .65px,transparent .85px);background-size:calc(var(--spacing, .25rem) * 6) calc(var(--spacing, .25rem) * 6)}:host .drawing-tools,:host ngs-toolbar.zoom-toolbar,:host ngs-toolbar.history-toolbar{background:var(--ngs-whiteboard-panel-bg);box-shadow:var(--ngs-whiteboard-panel-shadow);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host .drawing-tools,:host ngs-toolbar.zoom-toolbar,:host ngs-toolbar.history-toolbar{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 70%,transparent)}}:host ngs-toolbar{--ngs-toolbar-gap: 0}:host ngs-button-toggle-group{--ngs-button-toggle-button-height: calc(var(--spacing, .25rem) * 14);--ngs-button-toggle-button-border-radius: calc(var(--spacing, .25rem) * 2.5);--ngs-button-toggle-group-bg: transparent;--ngs-button-toggle-group-border-width: 0;--ngs-button-toggle-group-padding: 0;--ngs-button-toggle-group-gap: 0;--ngs-button-toggle-checked-bg-color: var(--ngs-color-primary-container);--ngs-button-toggle-checked-text-color: var(--ngs-color-primary);--ngs-icon-size: calc(var(--spacing, .25rem) * 5.5)}:host ngs-card.properties-panel{--ngs-card-radius: calc(var(--spacing, .25rem) * 3.5);--ngs-card-shadow: var(--ngs-whiteboard-panel-shadow);--ngs-card-bg: var(--ngs-whiteboard-panel-bg);--ngs-card-border-color: var(--ngs-color-border);max-height:calc(100% - calc(var(--spacing, .25rem) * 64))}@supports (color: color-mix(in lab,red,red)){:host ngs-card.properties-panel{--ngs-card-border-color: color-mix(in srgb, var(--ngs-color-border) 70%, transparent)}}:host ngs-color-switcher{--ngs-brand-colors-color-size: calc(var(--spacing, .25rem) * 7);--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 3);--ngs-brand-colors-color-shadow: none;--ngs-brand-colors-selected-outline: 1.5px solid var(--ngs-color-primary);--ngs-brand-colors-selected-outline-offset: 3px;--ngs-brand-colors-selected-dot-size: calc(var(--spacing, .25rem) * 2)}:host button[ngs-color-picker-thumbnail]{--ngs-color-picker-thumbnail-size: calc(var(--spacing, .25rem) * 7)}:host button[ngs-color-picker-thumbnail].is-selected{outline:1.5px solid var(--ngs-color-primary);outline-offset:2px}:host button[ngs-color-picker-thumbnail].custom-color{--ngs-color-picker-thumbnail-bg: conic-gradient(#ed6278, #f6c84a, #87d68c, #55c9db, #6578e6, #bc7ada, #ed6278);outline:1px solid var(--ngs-color-border);outline-offset:1px}:host button[ngs-color-picker-thumbnail].custom-color:after{box-shadow:inset 0 0 0 4px var(--ngs-color-surface)}:host ngs-segmented.stroke-options,:host ngs-segmented.typography-options{--ngs-segmented-bg: transparent;--ngs-segmented-padding: 0;--ngs-segmented-gap: calc(var(--spacing, .25rem) * 1.5);--ngs-segmented-radius: calc(var(--spacing, .25rem) * 2.5);--ngs-segmented-button-height: calc(var(--spacing, .25rem) * 9.5);--ngs-segmented-button-radius: calc(var(--spacing, .25rem) * 2.5);--ngs-segmented-button-selected-bg: var(--ngs-color-primary-container);--ngs-segmented-button-selected-color: var(--ngs-color-primary);--ngs-segmented-button-selected-shadow: none;--ngs-icon-size: calc(var(--spacing, .25rem) * 6)}:host ngs-segmented.stroke-options button[ngs-segmented-button],:host ngs-segmented.typography-options button[ngs-segmented-button]{--ngs-segmented-button-min-width: calc(var(--spacing, .25rem) * 13);background:var(--ngs-color-surface-container-low);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host ngs-segmented.stroke-options button[ngs-segmented-button],:host ngs-segmented.typography-options button[ngs-segmented-button]{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 50%,transparent)}}:host ngs-segmented.stroke-options button[ngs-segmented-button].is-selected,:host ngs-segmented.typography-options button[ngs-segmented-button].is-selected{background:transparent}:host ngs-segmented.typography-options{--ngs-segmented-button-height: calc(var(--spacing, .25rem) * 8.5);--ngs-icon-size: calc(var(--spacing, .25rem) * 4.5)}:host ngs-segmented.typography-options button[ngs-segmented-button]{--ngs-segmented-button-min-width: calc(var(--spacing, .25rem) * 9)}:host ngs-segmented.typography-options .serif-sample{font:1rem/1 Georgia,serif}:host ngs-slider{--ngs-slider-track-active-height: var(--spacing, .25rem);--ngs-slider-track-height: var(--spacing, .25rem);--ngs-slider-track-color: var(--ngs-color-surface-container-highest);--ngs-slider-thumb-size: calc(var(--spacing, .25rem) * 5);height:calc(var(--spacing, .25rem) * 8);padding:var(--spacing, .25rem) 0}:host button[ngsIconButton],:host button[ngsButton]{--ngs-button-height: calc(var(--spacing, .25rem) * 9);--ngs-button-font-size: var(--ngs-font-size-sm);--ngs-icon-size: calc(var(--spacing, .25rem) * 5)}:host button[ngsIconButton].board-mark{--ngs-button-height: calc(var(--spacing, .25rem) * 14);--ngs-icon-size: calc(var(--spacing, .25rem) * 7);--ngs-button-bg: var(--ngs-color-primary-container);--ngs-button-color: var(--ngs-color-primary);--ngs-button-radius: calc(var(--spacing, .25rem) * 3.5);box-shadow:var(--ngs-whiteboard-panel-shadow);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].board-mark{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 60%,transparent)}}:host .board-title{font-size:calc(var(--spacing, .25rem) * 4.5)}:host button[ngsButton].export-action,:host button[ngsIconButton].more-action{--ngs-button-height: calc(var(--spacing, .25rem) * 10);--ngs-button-font-size: calc(var(--spacing, .25rem) * 4);--ngs-button-radius: calc(var(--spacing, .25rem) * 3);--ngs-button-outlined-border: var(--ngs-color-border);--ngs-button-bg: var(--ngs-whiteboard-panel-bg);box-shadow:var(--ngs-whiteboard-panel-shadow)}@supports (color: color-mix(in lab,red,red)){:host button[ngsButton].export-action,:host button[ngsIconButton].more-action{--ngs-button-outlined-border: color-mix(in srgb, var(--ngs-color-border) 70%, transparent)}}:host button[ngsIconButton].more-action{outline:1px solid var(--ngs-button-outlined-border)}:host button[ngsIconButton].tool-lock{--ngs-button-height: calc(var(--spacing, .25rem) * 9)}:host button[ngsButton].zoom-value{--ngs-button-padding: 0 calc(var(--spacing, .25rem) * 2);--ngs-button-content-gap: var(--spacing, .25rem);--ngs-icon-size: calc(var(--spacing, .25rem) * 3)}:host .board-subtitle{color:var(--ngs-color-on-surface-variant)}:host .tool-shortcut{color:var(--ngs-color-on-surface-variant);color:oklch(from var(--ngs-color-on-surface-variant) l 0 0)}:host ngs-icon.tool-cursor-icon{translate:-1.5px}:host .property-label{color:var(--ngs-color-on-surface)}:host .canvas-hint{background:var(--ngs-whiteboard-panel-bg);color:var(--ngs-color-on-surface-variant);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host .canvas-hint{background:color-mix(in srgb,var(--ngs-whiteboard-panel-bg) 92%,transparent)}}@supports (color: color-mix(in lab,red,red)){:host .canvas-hint{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 70%,transparent)}}:host ngs-icon.medium-stroke{filter:drop-shadow(0 .4px currentColor)}:host ngs-icon.heavy-stroke{filter:drop-shadow(0 1px currentColor) drop-shadow(0 -1px currentColor)}@container whiteboard (width >= 80rem){:host ngs-card.properties-panel{max-height:calc(100% - calc(var(--spacing, .25rem) * 48))}}@container whiteboard (width < 40rem){:host ngs-card.properties-panel{width:calc(var(--spacing, .25rem) * 64)}:host ngs-color-switcher{--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 2)}:host button[ngsIconButton].board-mark{--ngs-button-height: calc(var(--spacing, .25rem) * 10);--ngs-icon-size: calc(var(--spacing, .25rem) * 5)}:host .board-title{font-size:calc(var(--spacing, .25rem) * 4)}:host button[ngsButton].export-action{--ngs-button-padding: 0 calc(var(--spacing, .25rem) * 3);--ngs-button-font-size: var(--ngs-font-size-sm)}}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: Alert, selector: "ngs-alert", inputs: ["autoClose", "bordered", "variant"], outputs: ["closed"], exportAs: ["ngsAlert"] }, { kind: "component", type: Button, selector: " button[ngsButton], button[ngsIconButton], a[ngsButton], a[ngsIconButton] ", inputs: ["ngsButton", "ngsIconButton", "loading", "disabled", "disabledInteractive", "disableRipple", "reverse", "fullWidth", "hideTextOnMobile"], exportAs: ["ngsButton"] }, { kind: "component", type: ButtonToggle, selector: "ngs-button-toggle", inputs: ["id", "value", "name", "checked", "disabled", "onlyIcon"], outputs: ["change"], exportAs: ["ngsButtonToggle"] }, { kind: "component", type: ButtonToggleGroup, selector: "ngs-button-toggle-group", inputs: ["appearance", "disabled", "multiple", "hideSelectionIndicator", "vertical", "value", "onlyIcon"], outputs: ["valueChange", "change"], exportAs: ["ngsButtonToggleGroup"] }, { kind: "component", type: Card, selector: "ngs-card", inputs: ["appearance"], exportAs: ["ngsCard"] }, { kind: "component", type: CardAside, selector: "ngs-card-aside, [ngs-card-aside], ngsCardAside" }, { kind: "component", type: CardContent, selector: "ngs-card-content, [ngs-card-content], [ngsCardContent]", inputs: ["withoutPadding"], exportAs: ["ngsCardContent"] }, { kind: "component", type: CardHeader, selector: "ngs-card-header", exportAs: ["ngsCardHeader"] }, { kind: "component", type: ColorPicker, selector: "ngs-color-picker", inputs: ["color", "disabled", "asDropdown", "showOpacity", "resultFormat"], outputs: ["colorChange", "rawColorChange"], exportAs: ["ngsColorPicker"] }, { kind: "component", type: ColorPickerThumbnail, selector: "ngs-color-picker-thumbnail,[ngs-color-picker-thumbnail]", inputs: ["color"], exportAs: ["ngsColorPickerThumbnail"] }, { kind: "directive", type: ColorPickerTriggerForDirective, selector: "[ngsColorPickerTriggerFor]", inputs: ["ngsColorPickerTriggerFor", "position"], outputs: ["opened", "closed"], exportAs: ["ngsColorPickerTriggerFor"] }, { kind: "component", type: ColorSwitcher, selector: "ngs-color-switcher", inputs: ["colors", "selectedColor", "disabled"], outputs: ["colorChange"], exportAs: ["ngsColorSwitcher"] }, { kind: "component", type: Divider, selector: "ngs-divider", inputs: ["vertical", "inset", "fixedHeight"], exportAs: ["ngsDivider"] }, { kind: "component", type: Icon, selector: "ngs-icon", inputs: ["name"], exportAs: ["ngsIcon"] }, { kind: "directive", type: Input, selector: "input[ngsInput], textarea[ngsInput]", inputs: ["id", "placeholder", "required", "disabled", "readonly", "errorStateMatcher"], exportAs: ["ngsInput"] }, { kind: "component", type: Menu, selector: "ngs-menu", inputs: ["themeSource", "role", "classList", "xPosition", "yPosition", "pushIntoViewport"], outputs: ["closed"], exportAs: ["ngsMenu"] }, { kind: "component", type: MenuDivider, selector: "ngs-menu-divider" }, { kind: "component", type: MenuItem, selector: "ngs-menu-item, [ngs-menu-item]", inputs: ["disabled", "role", "selected"], outputs: ["_triggered"], exportAs: ["ngsMenuItem"] }, { kind: "directive", type: MenuTrigger, selector: "[ngsMenuTriggerFor]", inputs: ["ngsMenuTriggerFor", "ngsMenuTriggerData", "ngsMenuDisabled", "xPosition", "yPosition", "ngsMenuTriggerRestoreFocus"], outputs: ["menuOpened", "menuClosed"], exportAs: ["ngsMenuTrigger"] }, { kind: "component", type: ScrollbarArea, selector: "ngs-scrollbar-area", inputs: ["scrollbarWidth", "autoHide", "absolute"], outputs: ["scrolled"], exportAs: ["ngsScrollbarArea"] }, { kind: "component", type: Segmented, selector: "ngs-segmented", inputs: ["value", "disabled", "size"], outputs: ["valueChange"], exportAs: ["ngsSegmented"] }, { kind: "component", type: SegmentedButton, selector: "ngs-segmented-button,[ngs-segmented-button]", inputs: ["value", "disabled", "iconOnly"], exportAs: ["ngsSegmentedButton"] }, { kind: "directive", type: SegmentedIconDirective, selector: "[ngsSegmentedIcon]", exportAs: ["ngsSegmentedIcon"] }, { kind: "component", type: Slider, selector: "ngs-slider", inputs: ["disabled", "discrete", "showTickMarks", "min", "max", "step", "displayWith"], exportAs: ["ngsSlider"] }, { kind: "directive", type: SliderThumb, selector: "input[ngsSliderThumb]", inputs: ["value"], outputs: ["valueChange"], exportAs: ["ngsSliderThumb"] }, { kind: "component", type: Toolbar, selector: "ngs-toolbar", exportAs: ["ngsToolbar"] }, { kind: "directive", type: Tooltip, selector: "[ngsTooltip]", inputs: ["ngsTooltip", "ngsTooltipPosition", "ngsTooltipClass", "ngsTooltipShowDelay", "ngsTooltipHideDelay", "ngsTooltipOffset", "ngsTooltipPositionAtOrigin", "ngsTooltipDisabled"], exportAs: ["ngsTooltip"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1847
|
+
}
|
|
1848
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: Whiteboard, decorators: [{
|
|
1849
|
+
type: Component,
|
|
1850
|
+
args: [{ selector: 'ngs-whiteboard', exportAs: 'ngsWhiteboard', imports: [FormsModule, Alert, Button, ButtonToggle, ButtonToggleGroup, Card, CardAside, CardContent, CardHeader,
|
|
1851
|
+
ColorPicker, ColorPickerThumbnail, ColorPickerTriggerForDirective, ColorSwitcher, Divider,
|
|
1852
|
+
Icon, Input, Menu, MenuDivider,
|
|
1853
|
+
MenuItem, MenuTrigger, ScrollbarArea, Segmented, SegmentedButton, SegmentedIconDirective, Slider, SliderThumb, Toolbar, Tooltip], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
1854
|
+
class: 'ngs-whiteboard @container/whiteboard',
|
|
1855
|
+
'[class.ngs-whiteboard-grid]': 'showGrid()',
|
|
1856
|
+
'[class.ngs-whiteboard-readonly]': 'readOnly()',
|
|
1857
|
+
'(keydown)': 'onKeydown($event)',
|
|
1858
|
+
'(window:keyup)': 'onKeyup($event)',
|
|
1859
|
+
'(window:blur)': 'releasePan()',
|
|
1860
|
+
}, template: "<div #canvas class=\"canvas absolute inset-0\" tabindex=\"0\" role=\"region\"\n [attr.aria-label]=\"title() + '. ' + labels().canvasHelp\"></div>\n\n@if (textEdit(); as element) {\n @if (textEditorLayout(); as layout) {\n <textarea #textEditor ngsInput class=\"text-editor\" [attr.aria-label]=\"element.type === 'note' ? labels().noteText : labels().text\"\n [class.auto-height]=\"element.type === 'text'\"\n [attr.placeholder]=\"element.type === 'note' ? labels().notePlaceholder : null\" [value]=\"textDraft()\"\n [style.transform]=\"textEditorTransform()\" [style.width.px]=\"layout.width\"\n [style.height.px]=\"element.type === 'text' ? null : layout.height\"\n [style.padding.px]=\"layout.padding\" [style.padding-top.px]=\"layout.paddingTop\" [style.font-size.px]=\"element.fontSize\"\n [style.font-family]=\"typography().fontFamily\" [style.line-height]=\"layout.lineHeight\"\n [style.text-align]=\"typography().textAlign\" [style.color]=\"element.stroke\" [style.opacity]=\"element.opacity\"\n (input)=\"textDraft.set(textEditor.value)\" (blur)=\"finishTextEditing(textEditor.value)\"\n (keydown)=\"onTextKeydown($event, textEditor.value)\"></textarea>\n }\n}\n\n@if (showToolbar()) {\n @let controls = propertyControls();\n @let toolbarTooltipDelay = 1000;\n <div class=\"pointer-events-none absolute inset-x-6 top-4 z-10 flex items-start justify-between gap-4\">\n <div class=\"flex min-w-0 items-center gap-2 @3xl/whiteboard:gap-4\">\n <button ngsIconButton type=\"button\" class=\"board-mark pointer-events-auto shrink-0 rounded-2xl!\" [attr.aria-label]=\"labels().properties\"\n [attr.aria-pressed]=\"!!controls && !readOnly() && showProperties()\" [disabled]=\"!controls || readOnly()\"\n (click)=\"showProperties.set(!showProperties())\">\n <ngs-icon name=\"fluent:whiteboard-24-regular\"/>\n </button>\n <div class=\"flex min-w-0 flex-col gap-1\">\n <span class=\"board-title truncate leading-6 font-bold\">{{ title() }}</span>\n @if (subtitle()) { <span class=\"board-subtitle truncate text-sm\">{{ subtitle() }}</span> }\n </div>\n </div>\n <div class=\"pointer-events-auto flex shrink-0 items-center gap-3 pt-1\">\n <button ngsButton=\"outlined\" type=\"button\" class=\"export-action\" (click)=\"downloadPng()\" [attr.aria-label]=\"labels().exportPng\">\n <ngs-icon name=\"fluent:arrow-export-up-24-regular\"/>{{ labels().export }}\n </button>\n <button ngsIconButton type=\"button\" class=\"more-action rounded-xl!\" [ngsMenuTriggerFor]=\"fileMenu\" [attr.aria-label]=\"labels().more\">\n <ngs-icon name=\"fluent:more-vertical-24-regular\"/>\n </button>\n </div>\n </div>\n <div class=\"drawing-tools pointer-events-auto absolute inset-x-6 top-24 z-10 mx-auto h-16 w-max max-w-[calc(100%-3rem)] rounded-2xl @7xl/whiteboard:top-4 @7xl/whiteboard:h-[4.5rem]\">\n <ngs-scrollbar-area [absolute]=\"false\" class=\"relative! h-full\">\n <ngs-toolbar class=\"h-full w-max! px-2\" [attr.aria-label]=\"labels().properties\">\n <button ngsIconButton type=\"button\" class=\"tool-lock\" [attr.aria-label]=\"labels().lockTool\"\n [ngsTooltip]=\"labels().lockTool\" [ngsTooltipShowDelay]=\"toolbarTooltipDelay\"\n [attr.aria-pressed]=\"toolLocked()\" (click)=\"toolLocked.set(!toolLocked())\" [disabled]=\"readOnly()\">\n <ngs-icon [name]=\"toolLocked() ? 'fluent:lock-closed-24-regular' : 'fluent:lock-open-24-regular'\"/>\n </button>\n <ngs-button-toggle-group onlyIcon hideSelectionIndicator [value]=\"tool()\" (valueChange)=\"selectTool($event)\" (click)=\"focusCanvasFromPointer($event)\">\n @for (item of tools; track item.value) {\n <ngs-button-toggle class=\"w-14\" [value]=\"item.value\" [disabled]=\"readOnly() && item.value !== 'hand' && item.value !== 'select'\"\n [ngsTooltip]=\"labels().tools[item.value] + ' (' + item.shortcut + ')'\" [ngsTooltipShowDelay]=\"toolbarTooltipDelay\">\n <span class=\"flex flex-col items-center gap-1.5\" [attr.aria-label]=\"labels().tools[item.value]\">\n <ngs-icon [name]=\"item.icon\" [class.tool-cursor-icon]=\"item.value === 'select'\"/>\n @if (item.value !== 'hand') { <span class=\"tool-shortcut text-[9px] leading-none\" aria-hidden=\"true\">{{ item.shortcut }}</span> }\n </span>\n </ngs-button-toggle>\n @if (item.value === 'hand') { <ngs-divider vertical fixedHeight class=\"mx-2 h-9!\"/> }\n }\n </ngs-button-toggle-group>\n </ngs-toolbar>\n </ngs-scrollbar-area>\n </div>\n\n @if (controls && showProperties() && !readOnly()) {\n <ngs-card class=\"properties-panel absolute left-6 top-44 z-10 flex w-70 flex-col @7xl/whiteboard:top-28\" appearance=\"outlined\">\n <ngs-card-header class=\"flex h-12.5 shrink-0 items-center justify-between px-4! py-0!\">\n <span class=\"text-lg font-semibold\">{{ toolLabel() }}</span>\n <ngs-card-aside>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().closeProperties\" (click)=\"showProperties.set(false)\">\n <ngs-icon name=\"fluent:dismiss-24-regular\"/>\n </button>\n </ngs-card-aside>\n </ngs-card-header>\n <ngs-divider/>\n <ngs-card-content class=\"grid! min-h-0 p-0!\">\n <ngs-scrollbar-area [absolute]=\"false\" class=\"relative! grid! min-h-0\">\n <div class=\"flex flex-col gap-4 p-4\">\n <div class=\"flex flex-col gap-2.5\">\n <span class=\"property-label text-sm\">{{ controls.colorLabel }}</span>\n <div class=\"flex items-center gap-3\">\n <ngs-color-switcher [colors]=\"colors()\" [selectedColor]=\"style().stroke\" (colorChange)=\"updateStyle({stroke: $event})\"/>\n <button ngs-color-picker-thumbnail class=\"custom-color\" [ngsColorPickerTriggerFor]=\"customColor\"\n [attr.aria-label]=\"labels().customColor\" [ngsTooltip]=\"labels().customColor\"></button>\n </div>\n </div>\n @if (controls.fillLabel) {\n <div class=\"flex flex-col gap-2.5\">\n <span class=\"property-label text-sm\">{{ controls.fillLabel }}</span>\n <div class=\"flex items-center gap-3\">\n <button ngs-color-picker-thumbnail [color]=\"controls.arrowhead ? style().stroke : 'transparent'\" [class.is-selected]=\"style().fill === 'transparent'\"\n [attr.aria-label]=\"controls.arrowhead ? labels().useStrokeColor : labels().noFill\"\n [attr.aria-pressed]=\"style().fill === 'transparent'\" (click)=\"updateStyle({fill: 'transparent'})\"></button>\n <ngs-color-switcher [colors]=\"fills\" [selectedColor]=\"style().fill\" (colorChange)=\"updateStyle({fill: $event})\"/>\n </div>\n </div>\n }\n @if (controls.strokeWidth) {\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().width }}</span>\n <ngs-segmented class=\"stroke-options\" [value]=\"style().strokeWidth\" (valueChange)=\"updateStyle({strokeWidth: $event})\" [attr.aria-label]=\"labels().width\">\n @for (width of [1, 2, 4]; track width) {\n <button ngs-segmented-button iconOnly [value]=\"width\" [attr.aria-label]=\"width + ' px'\">\n <ngs-icon ngsSegmentedIcon name=\"fluent:line-horizontal-1-24-regular\" [class.medium-stroke]=\"width === 2\" [class.heavy-stroke]=\"width === 4\"/>\n </button>\n }\n </ngs-segmented>\n </div>\n }\n @if (controls.lineStyle) {\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().lineStyle }}</span>\n <ngs-segmented class=\"stroke-options\" [value]=\"style().lineStyle\" (valueChange)=\"updateStyle({lineStyle: $event})\" [attr.aria-label]=\"labels().lineStyle\">\n <button ngs-segmented-button iconOnly value=\"solid\" [attr.aria-label]=\"labels().solid\"><ngs-icon ngsSegmentedIcon name=\"fluent:line-horizontal-1-24-regular\"/></button>\n <button ngs-segmented-button iconOnly value=\"dashed\" [attr.aria-label]=\"labels().dashed\"><ngs-icon ngsSegmentedIcon name=\"fluent:line-dashes-24-regular\" class=\"rotate-45\"/></button>\n <button ngs-segmented-button iconOnly value=\"dotted\" [attr.aria-label]=\"labels().dotted\"><ngs-icon ngsSegmentedIcon name=\"fluent:more-horizontal-24-regular\"/></button>\n </ngs-segmented>\n </div>\n }\n @if (controls.typography) {\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().fontFamily }}</span>\n <ngs-segmented class=\"typography-options\" role=\"group\" [attr.aria-label]=\"labels().fontFamily\"\n [value]=\"typography().fontFamily\" (valueChange)=\"updateTypography({fontFamily: $event})\"\n (mousedown)=\"keepTextFocus($event)\">\n @for (option of fontOptions; track option.key) {\n <button ngs-segmented-button iconOnly type=\"button\" [value]=\"option.value\"\n [attr.aria-label]=\"labels().fonts[option.key]\" [attr.aria-pressed]=\"typography().fontFamily === option.value\"\n [ngsTooltip]=\"labels().fonts[option.key]\">\n @if ('icon' in option) {\n <ngs-icon ngsSegmentedIcon [name]=\"option.icon\"/>\n } @else {\n <span ngsSegmentedIcon class=\"serif-sample\" aria-hidden=\"true\">A</span>\n }\n </button>\n }\n </ngs-segmented>\n </div>\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().fontSize }}</span>\n <ngs-segmented class=\"typography-options\" role=\"group\" [attr.aria-label]=\"labels().fontSize\"\n [value]=\"typography().fontSize\" (valueChange)=\"updateTypography({fontSize: $event})\"\n (mousedown)=\"keepTextFocus($event)\">\n @for (size of fontSizes; track size.value) {\n <button ngs-segmented-button type=\"button\" [value]=\"size.value\"\n [attr.aria-label]=\"labels().fontSizes[size.label]\" [attr.aria-pressed]=\"typography().fontSize === size.value\">\n {{ size.label }}\n </button>\n }\n </ngs-segmented>\n </div>\n <div class=\"flex flex-col gap-2\">\n <span class=\"property-label text-sm\">{{ labels().textAlign }}</span>\n <ngs-segmented class=\"typography-options\" role=\"group\" [attr.aria-label]=\"labels().textAlign\"\n [value]=\"typography().textAlign\" (valueChange)=\"updateTypography({textAlign: $event})\"\n (mousedown)=\"keepTextFocus($event)\">\n @for (align of textAlignments; track align) {\n <button ngs-segmented-button iconOnly type=\"button\" [value]=\"align\"\n [attr.aria-label]=\"labels().alignments[align]\" [attr.aria-pressed]=\"typography().textAlign === align\"\n [ngsTooltip]=\"labels().alignments[align]\">\n <ngs-icon ngsSegmentedIcon [name]=\"'fluent:text-align-' + align + '-24-regular'\"/>\n </button>\n }\n </ngs-segmented>\n </div>\n }\n <div class=\"flex flex-col gap-2\">\n <div class=\"flex items-center justify-between text-sm\"><span class=\"property-label\">{{ labels().opacity }}</span><span>{{ (style().opacity * 100).toFixed(0) }}%</span></div>\n <ngs-slider [min]=\"0\" [max]=\"100\" [step]=\"1\" class=\"w-full!\">\n <input ngsSliderThumb [value]=\"style().opacity * 100\" (valueChange)=\"updateStyle({opacity: $event / 100})\" [attr.aria-label]=\"labels().opacity\">\n </ngs-slider>\n </div>\n @if (selectedElements().length) {\n <ngs-divider/>\n <div class=\"flex items-center gap-2\">\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().duplicate\" ngsTooltip=\"Duplicate (Ctrl+D)\" (click)=\"duplicateSelection()\"><ngs-icon name=\"fluent:copy-24-regular\"/></button>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().delete\" ngsTooltip=\"Delete\" (click)=\"deleteSelection()\"><ngs-icon name=\"fluent:delete-24-regular\"/></button>\n </div>\n }\n </div>\n </ngs-scrollbar-area>\n </ngs-card-content>\n </ngs-card>\n }\n\n <div class=\"pointer-events-none absolute inset-x-6 bottom-6 z-10 flex items-end gap-4\">\n <div class=\"pointer-events-auto flex flex-wrap gap-4\">\n <ngs-toolbar class=\"zoom-toolbar w-auto! gap-0! rounded-xl p-1\" [attr.aria-label]=\"labels().resetZoom\">\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().zoomOut\" [ngsTooltip]=\"labels().zoomOut\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" (click)=\"zoomOut()\"><ngs-icon name=\"fluent:subtract-24-regular\"/></button>\n <button ngsButton type=\"button\" class=\"zoom-value\" [ngsMenuTriggerFor]=\"zoomMenu\" [attr.aria-label]=\"labels().resetZoom\" reverse>\n <ngs-icon name=\"fluent:chevron-down-16-regular\"/>{{ zoomLabel() }}\n </button>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().zoomIn\" [ngsTooltip]=\"labels().zoomIn\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" (click)=\"zoomIn()\"><ngs-icon name=\"fluent:add-24-regular\"/></button>\n <ngs-divider vertical fixedHeight class=\"mx-1\"/>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().fit\" [ngsTooltip]=\"labels().fit\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" (click)=\"fitToContent()\"><ngs-icon name=\"fluent:arrow-expand-24-regular\"/></button>\n </ngs-toolbar>\n @if (!readOnly()) {\n <ngs-toolbar class=\"history-toolbar w-auto! gap-0! rounded-xl p-1\" [attr.aria-label]=\"labels().undo\">\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().undo\" [ngsTooltip]=\"labels().undo\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" [disabled]=\"!canUndo()\" (click)=\"undo()\"><ngs-icon name=\"fluent:arrow-undo-24-regular\"/></button>\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().redo\" [ngsTooltip]=\"labels().redo\"\n [ngsTooltipShowDelay]=\"toolbarTooltipDelay\" [disabled]=\"!canRedo()\" (click)=\"redo()\"><ngs-icon name=\"fluent:arrow-redo-24-regular\"/></button>\n </ngs-toolbar>\n }\n </div>\n <span class=\"canvas-hint absolute bottom-1 left-1/2 hidden -translate-x-1/2 whitespace-nowrap rounded-full px-4 py-2 text-sm @7xl/whiteboard:block\">{{ labels().canvasHint }}</span>\n </div>\n}\n\n@if (errorMessage()) {\n <ngs-alert variant=\"negative\" class=\"absolute inset-x-4 bottom-20 z-20 text-sm\" role=\"alert\">\n {{ errorMessage() }}\n <button ngsIconButton type=\"button\" [attr.aria-label]=\"labels().dismiss\" (click)=\"errorMessage.set('')\"><ngs-icon name=\"fluent:dismiss-24-regular\"/></button>\n </ngs-alert>\n}\n\n<input #fileInput type=\"file\" accept=\"application/json,.json\" hidden (change)=\"importFile($event)\">\n<ngs-menu #fileMenu=\"ngsMenu\">\n <button ngs-menu-item (click)=\"downloadPng()\">{{ labels().exportPng }}</button>\n <button ngs-menu-item (click)=\"downloadJson()\">{{ labels().saveJson }}</button>\n @if (!readOnly()) {\n <button ngs-menu-item (click)=\"fileInput.click()\">{{ labels().openJson }}</button>\n <ngs-menu-divider/>\n <button ngs-menu-item [disabled]=\"!value().elements.length\" (click)=\"confirmClear()\">{{ labels().clear }}</button>\n }\n <ngs-menu-divider/>\n <button ngs-menu-item [selected]=\"showGrid()\" (click)=\"showGrid.set(!showGrid())\">{{ labels().grid }}</button>\n</ngs-menu>\n<ngs-menu #zoomMenu=\"ngsMenu\">\n <button ngs-menu-item (click)=\"resetView()\">100%</button>\n <button ngs-menu-item (click)=\"fitToContent()\">{{ labels().fit }}</button>\n</ngs-menu>\n<ng-template #customColor><ngs-color-picker [ngModel]=\"style().stroke\" (ngModelChange)=\"updateStyle({stroke: $event})\"/></ng-template>\n", styles: [":host{--ngs-whiteboard-bg: var(--ngs-color-surface, #ffffff);--ngs-whiteboard-grid-color: var(--ngs-color-primary);--ngs-whiteboard-panel-bg: var(--ngs-color-surface, #ffffff);--ngs-whiteboard-panel-shadow: 0 2px 5px var(--ngs-color-on-surface), 0 6px 18px var(--ngs-color-on-surface);display:block;position:relative;isolation:isolate;height:var(--ngs-whiteboard-height, 40rem);min-height:calc(var(--spacing, .25rem) * 96);overflow:hidden;background:var(--ngs-whiteboard-bg);color:var(--ngs-color-on-surface);font-family:var(--ngs-font-family-base);border:1px solid var(--ngs-color-border);border-radius:var(--ngs-radius-lg)}@supports (color: color-mix(in lab,red,red)){:host{--ngs-whiteboard-grid-color: color-mix(in srgb, var(--ngs-color-primary) 16%, transparent)}}@supports (color: color-mix(in lab,red,red)){:host{--ngs-whiteboard-panel-shadow: 0 2px 5px color-mix(in srgb, var(--ngs-color-on-surface) 4%, transparent), 0 6px 18px color-mix(in srgb, var(--ngs-color-on-surface) 4%, transparent)}}:host .canvas{outline:none;touch-action:none;-webkit-user-select:none;user-select:none}:host .canvas[data-tool=pencil],:host .canvas[data-tool=rectangle],:host .canvas[data-tool=diamond],:host .canvas[data-tool=ellipse],:host .canvas[data-tool=line],:host .canvas[data-tool=arrow]{cursor:crosshair}:host .canvas[data-tool=hand]{cursor:grab}:host .canvas[data-tool=hand]:active{cursor:grabbing}:host .canvas[data-tool=text],:host .canvas[data-tool=note]{cursor:text}:host .canvas[data-tool=eraser]{cursor:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='8' cy='8' r='5' fill='none' stroke='white' stroke-width='3'/%3E%3Ccircle cx='8' cy='8' r='5' fill='none' stroke='%234b4b4b'/%3E%3C/svg%3E\") 8 8,cell}:host .canvas:focus-visible{outline:2px solid var(--ngs-state-focus-ring);outline-offset:-2px}:host textarea.text-editor{position:absolute;inset:0 auto auto 0;z-index:1;box-sizing:border-box;margin:0;border:0;outline:0;background:transparent;resize:none;overflow:auto;overflow-wrap:break-word;transform-origin:top left}:host textarea.text-editor.auto-height{overflow:hidden}:host textarea.text-editor::placeholder{color:currentColor;opacity:.65}:host.ngs-whiteboard-grid .canvas{background-image:radial-gradient(circle,var(--ngs-whiteboard-grid-color) .65px,transparent .85px);background-size:calc(var(--spacing, .25rem) * 6) calc(var(--spacing, .25rem) * 6)}:host .drawing-tools,:host ngs-toolbar.zoom-toolbar,:host ngs-toolbar.history-toolbar{background:var(--ngs-whiteboard-panel-bg);box-shadow:var(--ngs-whiteboard-panel-shadow);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host .drawing-tools,:host ngs-toolbar.zoom-toolbar,:host ngs-toolbar.history-toolbar{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 70%,transparent)}}:host ngs-toolbar{--ngs-toolbar-gap: 0}:host ngs-button-toggle-group{--ngs-button-toggle-button-height: calc(var(--spacing, .25rem) * 14);--ngs-button-toggle-button-border-radius: calc(var(--spacing, .25rem) * 2.5);--ngs-button-toggle-group-bg: transparent;--ngs-button-toggle-group-border-width: 0;--ngs-button-toggle-group-padding: 0;--ngs-button-toggle-group-gap: 0;--ngs-button-toggle-checked-bg-color: var(--ngs-color-primary-container);--ngs-button-toggle-checked-text-color: var(--ngs-color-primary);--ngs-icon-size: calc(var(--spacing, .25rem) * 5.5)}:host ngs-card.properties-panel{--ngs-card-radius: calc(var(--spacing, .25rem) * 3.5);--ngs-card-shadow: var(--ngs-whiteboard-panel-shadow);--ngs-card-bg: var(--ngs-whiteboard-panel-bg);--ngs-card-border-color: var(--ngs-color-border);max-height:calc(100% - calc(var(--spacing, .25rem) * 64))}@supports (color: color-mix(in lab,red,red)){:host ngs-card.properties-panel{--ngs-card-border-color: color-mix(in srgb, var(--ngs-color-border) 70%, transparent)}}:host ngs-color-switcher{--ngs-brand-colors-color-size: calc(var(--spacing, .25rem) * 7);--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 3);--ngs-brand-colors-color-shadow: none;--ngs-brand-colors-selected-outline: 1.5px solid var(--ngs-color-primary);--ngs-brand-colors-selected-outline-offset: 3px;--ngs-brand-colors-selected-dot-size: calc(var(--spacing, .25rem) * 2)}:host button[ngs-color-picker-thumbnail]{--ngs-color-picker-thumbnail-size: calc(var(--spacing, .25rem) * 7)}:host button[ngs-color-picker-thumbnail].is-selected{outline:1.5px solid var(--ngs-color-primary);outline-offset:2px}:host button[ngs-color-picker-thumbnail].custom-color{--ngs-color-picker-thumbnail-bg: conic-gradient(#ed6278, #f6c84a, #87d68c, #55c9db, #6578e6, #bc7ada, #ed6278);outline:1px solid var(--ngs-color-border);outline-offset:1px}:host button[ngs-color-picker-thumbnail].custom-color:after{box-shadow:inset 0 0 0 4px var(--ngs-color-surface)}:host ngs-segmented.stroke-options,:host ngs-segmented.typography-options{--ngs-segmented-bg: transparent;--ngs-segmented-padding: 0;--ngs-segmented-gap: calc(var(--spacing, .25rem) * 1.5);--ngs-segmented-radius: calc(var(--spacing, .25rem) * 2.5);--ngs-segmented-button-height: calc(var(--spacing, .25rem) * 9.5);--ngs-segmented-button-radius: calc(var(--spacing, .25rem) * 2.5);--ngs-segmented-button-selected-bg: var(--ngs-color-primary-container);--ngs-segmented-button-selected-color: var(--ngs-color-primary);--ngs-segmented-button-selected-shadow: none;--ngs-icon-size: calc(var(--spacing, .25rem) * 6)}:host ngs-segmented.stroke-options button[ngs-segmented-button],:host ngs-segmented.typography-options button[ngs-segmented-button]{--ngs-segmented-button-min-width: calc(var(--spacing, .25rem) * 13);background:var(--ngs-color-surface-container-low);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host ngs-segmented.stroke-options button[ngs-segmented-button],:host ngs-segmented.typography-options button[ngs-segmented-button]{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 50%,transparent)}}:host ngs-segmented.stroke-options button[ngs-segmented-button].is-selected,:host ngs-segmented.typography-options button[ngs-segmented-button].is-selected{background:transparent}:host ngs-segmented.typography-options{--ngs-segmented-button-height: calc(var(--spacing, .25rem) * 8.5);--ngs-icon-size: calc(var(--spacing, .25rem) * 4.5)}:host ngs-segmented.typography-options button[ngs-segmented-button]{--ngs-segmented-button-min-width: calc(var(--spacing, .25rem) * 9)}:host ngs-segmented.typography-options .serif-sample{font:1rem/1 Georgia,serif}:host ngs-slider{--ngs-slider-track-active-height: var(--spacing, .25rem);--ngs-slider-track-height: var(--spacing, .25rem);--ngs-slider-track-color: var(--ngs-color-surface-container-highest);--ngs-slider-thumb-size: calc(var(--spacing, .25rem) * 5);height:calc(var(--spacing, .25rem) * 8);padding:var(--spacing, .25rem) 0}:host button[ngsIconButton],:host button[ngsButton]{--ngs-button-height: calc(var(--spacing, .25rem) * 9);--ngs-button-font-size: var(--ngs-font-size-sm);--ngs-icon-size: calc(var(--spacing, .25rem) * 5)}:host button[ngsIconButton].board-mark{--ngs-button-height: calc(var(--spacing, .25rem) * 14);--ngs-icon-size: calc(var(--spacing, .25rem) * 7);--ngs-button-bg: var(--ngs-color-primary-container);--ngs-button-color: var(--ngs-color-primary);--ngs-button-radius: calc(var(--spacing, .25rem) * 3.5);box-shadow:var(--ngs-whiteboard-panel-shadow);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host button[ngsIconButton].board-mark{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 60%,transparent)}}:host .board-title{font-size:calc(var(--spacing, .25rem) * 4.5)}:host button[ngsButton].export-action,:host button[ngsIconButton].more-action{--ngs-button-height: calc(var(--spacing, .25rem) * 10);--ngs-button-font-size: calc(var(--spacing, .25rem) * 4);--ngs-button-radius: calc(var(--spacing, .25rem) * 3);--ngs-button-outlined-border: var(--ngs-color-border);--ngs-button-bg: var(--ngs-whiteboard-panel-bg);box-shadow:var(--ngs-whiteboard-panel-shadow)}@supports (color: color-mix(in lab,red,red)){:host button[ngsButton].export-action,:host button[ngsIconButton].more-action{--ngs-button-outlined-border: color-mix(in srgb, var(--ngs-color-border) 70%, transparent)}}:host button[ngsIconButton].more-action{outline:1px solid var(--ngs-button-outlined-border)}:host button[ngsIconButton].tool-lock{--ngs-button-height: calc(var(--spacing, .25rem) * 9)}:host button[ngsButton].zoom-value{--ngs-button-padding: 0 calc(var(--spacing, .25rem) * 2);--ngs-button-content-gap: var(--spacing, .25rem);--ngs-icon-size: calc(var(--spacing, .25rem) * 3)}:host .board-subtitle{color:var(--ngs-color-on-surface-variant)}:host .tool-shortcut{color:var(--ngs-color-on-surface-variant);color:oklch(from var(--ngs-color-on-surface-variant) l 0 0)}:host ngs-icon.tool-cursor-icon{translate:-1.5px}:host .property-label{color:var(--ngs-color-on-surface)}:host .canvas-hint{background:var(--ngs-whiteboard-panel-bg);color:var(--ngs-color-on-surface-variant);outline:1px solid var(--ngs-color-border)}@supports (color: color-mix(in lab,red,red)){:host .canvas-hint{background:color-mix(in srgb,var(--ngs-whiteboard-panel-bg) 92%,transparent)}}@supports (color: color-mix(in lab,red,red)){:host .canvas-hint{outline:1px solid color-mix(in srgb,var(--ngs-color-border) 70%,transparent)}}:host ngs-icon.medium-stroke{filter:drop-shadow(0 .4px currentColor)}:host ngs-icon.heavy-stroke{filter:drop-shadow(0 1px currentColor) drop-shadow(0 -1px currentColor)}@container whiteboard (width >= 80rem){:host ngs-card.properties-panel{max-height:calc(100% - calc(var(--spacing, .25rem) * 48))}}@container whiteboard (width < 40rem){:host ngs-card.properties-panel{width:calc(var(--spacing, .25rem) * 64)}:host ngs-color-switcher{--ngs-brand-colors-gap: calc(var(--spacing, .25rem) * 2)}:host button[ngsIconButton].board-mark{--ngs-button-height: calc(var(--spacing, .25rem) * 10);--ngs-icon-size: calc(var(--spacing, .25rem) * 5)}:host .board-title{font-size:calc(var(--spacing, .25rem) * 4)}:host button[ngsButton].export-action{--ngs-button-padding: 0 calc(var(--spacing, .25rem) * 3);--ngs-button-font-size: var(--ngs-font-size-sm)}}\n/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */\n"] }]
|
|
1861
|
+
}], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }], tool: [{ type: i0.Input, args: [{ isSignal: true, alias: "tool", required: false }] }, { type: i0.Output, args: ["toolChange"] }], title: [{ type: i0.Input, args: [{ isSignal: true, alias: "title", required: false }] }], subtitle: [{ type: i0.Input, args: [{ isSignal: true, alias: "subtitle", required: false }] }], locale: [{ type: i0.Input, args: [{ isSignal: true, alias: "locale", required: false }] }], toolLocked: [{ type: i0.Input, args: [{ isSignal: true, alias: "toolLocked", required: false }] }, { type: i0.Output, args: ["toolLockedChange"] }], pressureSensitive: [{ type: i0.Input, args: [{ isSignal: true, alias: "pressureSensitive", required: false }] }, { type: i0.Output, args: ["pressureSensitiveChange"] }], drawingStyle: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawingStyle", required: false }] }, { type: i0.Output, args: ["drawingStyleChange"] }], readOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], showToolbar: [{ type: i0.Input, args: [{ isSignal: true, alias: "showToolbar", required: false }] }], showGrid: [{ type: i0.Input, args: [{ isSignal: true, alias: "showGrid", required: false }] }, { type: i0.Output, args: ["showGridChange"] }], showProperties: [{ type: i0.Input, args: [{ isSignal: true, alias: "showProperties", required: false }] }, { type: i0.Output, args: ["showPropertiesChange"] }], colors: [{ type: i0.Input, args: [{ isSignal: true, alias: "colors", required: false }] }], selectionChange: [{ type: i0.Output, args: ["selectionChange"] }], viewportChange: [{ type: i0.Output, args: ["viewportChange"] }], exported: [{ type: i0.Output, args: ["exported"] }], importError: [{ type: i0.Output, args: ["importError"] }], canvas: [{ type: i0.ViewChild, args: ['canvas', { isSignal: true }] }], textEditor: [{ type: i0.ViewChild, args: ['textEditor', { isSignal: true }] }] } });
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* Generated bundle index. Do not edit.
|
|
1865
|
+
*/
|
|
1866
|
+
|
|
1867
|
+
export { Whiteboard, parseWhiteboardDocument };
|
|
1868
|
+
//# sourceMappingURL=ngstarter-ui-components-whiteboard.mjs.map
|