@haklex/rich-ext-whiteboard 0.69.1 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{InteractiveScene-BqL3hsuU.js → InteractiveScene-Lz3yM1UW.js} +1 -1
- package/dist/{WhiteboardEditor-BVIGm8z0.js → WhiteboardEditor-BuF9_kou.js} +467 -128
- package/dist/{WhiteboardExpandShell-B9cCX4Yt.js → WhiteboardExpandShell-C0O3sSSt.js} +2 -2
- package/dist/editor/RichTextEditor.d.ts.map +1 -1
- package/dist/editor/StyleSheet.d.ts +0 -1
- package/dist/editor/StyleSheet.d.ts.map +1 -1
- package/dist/editor/WhiteboardCanvas.d.ts.map +1 -1
- package/dist/editor/binding-actions.d.ts +0 -1
- package/dist/editor/binding-actions.d.ts.map +1 -1
- package/dist/editor/layout.d.ts +4 -1
- package/dist/editor/layout.d.ts.map +1 -1
- package/dist/editor/linear-editor.d.ts +1 -3
- package/dist/editor/linear-editor.d.ts.map +1 -1
- package/dist/editor/overlay/SelectionOverlay.d.ts +0 -1
- package/dist/editor/overlay/SelectionOverlay.d.ts.map +1 -1
- package/dist/editor/selection-utils.d.ts +1 -3
- package/dist/editor/selection-utils.d.ts.map +1 -1
- package/dist/editor/shortcuts.d.ts +0 -2
- package/dist/editor/shortcuts.d.ts.map +1 -1
- package/dist/editor/text-actions.d.ts +0 -1
- package/dist/editor/text-actions.d.ts.map +1 -1
- package/dist/editor/tools/eraser.d.ts.map +1 -1
- package/dist/editor/tools/linear.d.ts +0 -2
- package/dist/editor/tools/linear.d.ts.map +1 -1
- package/dist/editor/tools/selection.d.ts +0 -2
- package/dist/editor/tools/selection.d.ts.map +1 -1
- package/dist/editor/tools/shape.d.ts +0 -7
- package/dist/editor/tools/shape.d.ts.map +1 -1
- package/dist/editor/tools/transform-gesture.d.ts +0 -2
- package/dist/editor/tools/transform-gesture.d.ts.map +1 -1
- package/dist/editor/transform.d.ts +0 -3
- package/dist/editor/transform.d.ts.map +1 -1
- package/dist/editor.mjs +32 -10
- package/dist/export/png.d.ts +0 -1
- package/dist/export/png.d.ts.map +1 -1
- package/dist/{export-CVvB15w6.js → export-D8KZqnab.js} +1 -1
- package/dist/index.mjs +3 -3
- package/dist/model/binding.d.ts +0 -2
- package/dist/model/binding.d.ts.map +1 -1
- package/dist/model/bounds.d.ts.map +1 -1
- package/dist/model/clipboard.d.ts +0 -1
- package/dist/model/clipboard.d.ts.map +1 -1
- package/dist/model/elbow.d.ts +0 -1
- package/dist/model/elbow.d.ts.map +1 -1
- package/dist/model/reconcile.d.ts.map +1 -1
- package/dist/model/richtext.d.ts +0 -2
- package/dist/model/richtext.d.ts.map +1 -1
- package/dist/model/shadow.d.ts +0 -1
- package/dist/model/shadow.d.ts.map +1 -1
- package/dist/model/skeleton.d.ts.map +1 -1
- package/dist/model/text-layout.d.ts +0 -1
- package/dist/model/text-layout.d.ts.map +1 -1
- package/dist/{reconcile-VoMFWmyk.js → reconcile-r3gVDm8B.js} +9 -2
- package/dist/scene/Scene.d.ts.map +1 -1
- package/dist/scene/elements.d.ts.map +1 -1
- package/dist/scene/freedraw.d.ts.map +1 -1
- package/dist/scene/rough.d.ts +4 -6
- package/dist/scene/rough.d.ts.map +1 -1
- package/dist/scene/scene-utils.d.ts +5 -0
- package/dist/scene/scene-utils.d.ts.map +1 -1
- package/dist/scene.mjs +4 -4
- package/dist/static.mjs +1 -1
- package/dist/{viewport-fit-CKwXs0RK.js → viewport-fit-C7OBkUJh.js} +174 -74
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as sameContent, n as reconcileElements, r as remoteWins, t as orderByIndex } from "./reconcile-
|
|
1
|
+
import { $ as boundsOfPoints, A as contentRoot, B as isHandFontFamily, C as newFrameElement, D as newRichTextElement, E as newLinearElement, G as getElementCenter, H as getCommonBounds, J as isLinear, K as getLinearAbsolutePoints, M as randomId, N as randomInteger, O as newSvgElement, P as DEFAULT_STYLE, Q as boundsIntersect, S as newElement, T as newImageElement, U as getElementAbsoluteCorners, W as getElementBounds, X as angleOf$1, Y as toLocalPoint, Z as boundsContain, _ as parseSvgSize, b as syncIndices, c as SceneHandFontContext, d as normalizeElement, et as distanceToSegment, g as isSvgSource, h as refreshTextDimensions, i as DARK_SCENE_FILTER, j as richTextPlainText, k as newTextElement, l as resolveRichTextHeights, m as layoutBoundText, nt as rotatePoint, o as RICHTEXT_BASE_STYLE, p as _defineProperty, q as hitTestElement, r as SceneContent, tt as normalizeBox, v as bumpVersion, w as newFreedrawElement, x as getLineHeight, z as fontFamilyToCss } from "./viewport-fit-C7OBkUJh.js";
|
|
2
|
+
import { i as sameContent, n as reconcileElements, r as remoteWins, t as orderByIndex } from "./reconcile-r3gVDm8B.js";
|
|
3
3
|
import { $createParagraphNode, $getSelection, $isRangeSelection, FORMAT_TEXT_COMMAND } from "lexical";
|
|
4
4
|
import { use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -309,7 +309,7 @@ function createWhiteboardStore(input, options = {}) {
|
|
|
309
309
|
const known = new Set(doc.elements.map((el) => el.id));
|
|
310
310
|
return {
|
|
311
311
|
...doc,
|
|
312
|
-
elements: [...doc.elements.map((el) => taken.get(el.id) ?? el), ...accepted.filter((el) => !known.has(el.id))]
|
|
312
|
+
elements: orderByIndex([...doc.elements.map((el) => taken.get(el.id) ?? el), ...accepted.filter((el) => !known.has(el.id))])
|
|
313
313
|
};
|
|
314
314
|
};
|
|
315
315
|
history.rewrite(rewrite);
|
|
@@ -372,7 +372,7 @@ function createWhiteboardStore(input, options = {}) {
|
|
|
372
372
|
};
|
|
373
373
|
};
|
|
374
374
|
const restore = (doc) => {
|
|
375
|
-
const elements = sync ? supersede(state.elements, doc.elements) : doc.elements;
|
|
375
|
+
const elements = sync ? orderByIndex(supersede(state.elements, doc.elements)) : doc.elements;
|
|
376
376
|
const alive = new Set(elements.filter((el) => !el.isDeleted).map((el) => el.id));
|
|
377
377
|
set({
|
|
378
378
|
elements,
|
|
@@ -487,8 +487,20 @@ function createWhiteboardStore(input, options = {}) {
|
|
|
487
487
|
function useStore(store, selector) {
|
|
488
488
|
return useSyncExternalStore(store.subscribe, () => selector(store.getState()), () => selector(store.getState()));
|
|
489
489
|
}
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/editor/layout.ts
|
|
492
|
+
var NARROW_WIDTH = 640;
|
|
490
493
|
function useNarrowLayout(store) {
|
|
491
|
-
return useStore(store, (s) => s.canvasSize.width > 0 && s.canvasSize.width <
|
|
494
|
+
return useStore(store, (s) => s.canvasSize.width > 0 && s.canvasSize.width < NARROW_WIDTH);
|
|
495
|
+
}
|
|
496
|
+
var BAR_WIDTH = 440;
|
|
497
|
+
var BAR_MARGIN = 8;
|
|
498
|
+
var clamp$1 = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
499
|
+
function formatBarPosition(left, top, canvas) {
|
|
500
|
+
const maxLeft = Math.max(BAR_MARGIN, canvas.width - BAR_WIDTH - BAR_MARGIN);
|
|
501
|
+
const minTop = 44;
|
|
502
|
+
const maxTop = Math.max(minTop, canvas.height - BAR_MARGIN);
|
|
503
|
+
return [clamp$1(left, BAR_MARGIN, maxLeft), clamp$1(top - BAR_MARGIN, minTop, maxTop)];
|
|
492
504
|
}
|
|
493
505
|
//#endregion
|
|
494
506
|
//#region src/editor/chrome.css.ts
|
|
@@ -706,7 +718,7 @@ function parseClipboard(raw) {
|
|
|
706
718
|
if (!text) return null;
|
|
707
719
|
if (text.startsWith("{")) try {
|
|
708
720
|
const json = JSON.parse(text);
|
|
709
|
-
if ((json.type ===
|
|
721
|
+
if ((json.type === CLIPBOARD_TYPE || json.type === "excalidraw") && Array.isArray(json.elements)) return {
|
|
710
722
|
elements: json.elements.filter((el) => !el.isDeleted),
|
|
711
723
|
files: json.files ?? {}
|
|
712
724
|
};
|
|
@@ -826,23 +838,26 @@ function getContainerId(el) {
|
|
|
826
838
|
function groupMembers(elements, groupId) {
|
|
827
839
|
return elements.filter((el) => isAlive(el) && el.groupIds?.includes(groupId)).map((el) => el.id);
|
|
828
840
|
}
|
|
829
|
-
function
|
|
841
|
+
function targetGroupFor(el, editingGroupId) {
|
|
830
842
|
const groups = el.groupIds ?? [];
|
|
831
|
-
if (groups.length === 0) return
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
843
|
+
if (groups.length === 0) return null;
|
|
844
|
+
const depth = editingGroupId ? groups.indexOf(editingGroupId) : -1;
|
|
845
|
+
if (depth === 0) return null;
|
|
846
|
+
return depth > 0 ? groups[depth - 1] : groups.at(-1);
|
|
847
|
+
}
|
|
848
|
+
function selectionForElement(state, el) {
|
|
849
|
+
const target = targetGroupFor(el, state.editingGroupId);
|
|
850
|
+
if (!target) return [el.id];
|
|
836
851
|
return groupMembers(state.elements, target);
|
|
837
852
|
}
|
|
838
|
-
function getHitElement(elements, p, tolerance) {
|
|
839
|
-
const byId = new Map(elements.map((el) => [el.id, el]));
|
|
853
|
+
function getHitElement(elements, p, tolerance, byId) {
|
|
840
854
|
for (let i = elements.length - 1; i >= 0; i--) {
|
|
841
855
|
const el = elements[i];
|
|
842
856
|
if (!isSelectable(el)) continue;
|
|
843
857
|
if (!hitTestElement(el, p, tolerance)) continue;
|
|
844
858
|
const containerId = getContainerId(el);
|
|
845
|
-
|
|
859
|
+
if (!containerId) return el;
|
|
860
|
+
const container = byId ? byId.get(containerId) : elements.find((candidate) => candidate.id === containerId);
|
|
846
861
|
if (container && isSelectable(container)) return container;
|
|
847
862
|
return el;
|
|
848
863
|
}
|
|
@@ -865,12 +880,49 @@ function withBoundText(elements, ids) {
|
|
|
865
880
|
return out;
|
|
866
881
|
}
|
|
867
882
|
function selectInBox(state, box) {
|
|
868
|
-
const
|
|
869
|
-
const inside = new Set(
|
|
883
|
+
const insideElements = [];
|
|
884
|
+
const inside = /* @__PURE__ */ new Set();
|
|
885
|
+
for (const el of state.elements) {
|
|
886
|
+
if (!isSelectable(el) || getContainerId(el)) continue;
|
|
887
|
+
if (boundsContain(box, getElementBounds(el))) {
|
|
888
|
+
insideElements.push(el);
|
|
889
|
+
inside.add(el.id);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
if (inside.size === 0) return /* @__PURE__ */ new Set();
|
|
893
|
+
const neededGroups = /* @__PURE__ */ new Set();
|
|
894
|
+
for (const el of insideElements) {
|
|
895
|
+
const group = targetGroupFor(el, state.editingGroupId);
|
|
896
|
+
if (group) neededGroups.add(group);
|
|
897
|
+
}
|
|
898
|
+
let membersByGroup = null;
|
|
899
|
+
if (neededGroups.size > 0) {
|
|
900
|
+
membersByGroup = /* @__PURE__ */ new Map();
|
|
901
|
+
for (const el of state.elements) {
|
|
902
|
+
if (!isAlive(el) || !el.groupIds || el.groupIds.length === 0) continue;
|
|
903
|
+
for (const gid of el.groupIds) {
|
|
904
|
+
if (!neededGroups.has(gid)) continue;
|
|
905
|
+
let list = membersByGroup.get(gid);
|
|
906
|
+
if (!list) {
|
|
907
|
+
list = [];
|
|
908
|
+
membersByGroup.set(gid, list);
|
|
909
|
+
}
|
|
910
|
+
list.push(el.id);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
870
914
|
const result = /* @__PURE__ */ new Set();
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
915
|
+
const checkedGroups = /* @__PURE__ */ new Set();
|
|
916
|
+
for (const el of insideElements) {
|
|
917
|
+
const group = targetGroupFor(el, state.editingGroupId);
|
|
918
|
+
if (!group) {
|
|
919
|
+
result.add(el.id);
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (checkedGroups.has(group)) continue;
|
|
923
|
+
checkedGroups.add(group);
|
|
924
|
+
const members = membersByGroup.get(group) ?? [el.id];
|
|
925
|
+
if (members.every((member) => inside.has(member))) for (const member of members) result.add(member);
|
|
874
926
|
}
|
|
875
927
|
return result;
|
|
876
928
|
}
|
|
@@ -1187,6 +1239,9 @@ function isBindable(el) {
|
|
|
1187
1239
|
if (el.isDeleted || !BINDABLE.has(el.type)) return false;
|
|
1188
1240
|
return !(el.type === "text" && el.containerId);
|
|
1189
1241
|
}
|
|
1242
|
+
//#endregion
|
|
1243
|
+
//#region src/model/elbow.ts
|
|
1244
|
+
var ELBOW_PADDING = 20;
|
|
1190
1245
|
var BEND_PENALTY = 60;
|
|
1191
1246
|
var DIRS = [
|
|
1192
1247
|
[1, 0],
|
|
@@ -1227,129 +1282,345 @@ function crosses(a, b, [minX, minY, maxX, maxY]) {
|
|
|
1227
1282
|
}
|
|
1228
1283
|
function exitPoint(p, heading, target) {
|
|
1229
1284
|
if (!target) return p;
|
|
1230
|
-
const [minX, minY, maxX, maxY] = expand(getElementBounds(target),
|
|
1285
|
+
const [minX, minY, maxX, maxY] = expand(getElementBounds(target), ELBOW_PADDING);
|
|
1231
1286
|
if (heading[0] > 0) return [Math.max(maxX, p[0]), p[1]];
|
|
1232
1287
|
if (heading[0] < 0) return [Math.min(minX, p[0]), p[1]];
|
|
1233
1288
|
if (heading[1] > 0) return [p[0], Math.max(maxY, p[1])];
|
|
1234
1289
|
return [p[0], Math.min(minY, p[1])];
|
|
1235
1290
|
}
|
|
1291
|
+
var CORRIDOR_MARGIN = 80;
|
|
1236
1292
|
var MinHeap = class {
|
|
1237
1293
|
constructor() {
|
|
1238
|
-
_defineProperty(this, "
|
|
1294
|
+
_defineProperty(this, "keys", /* @__PURE__ */ new Int32Array(256));
|
|
1295
|
+
_defineProperty(this, "fs", /* @__PURE__ */ new Float64Array(256));
|
|
1296
|
+
_defineProperty(this, "hs", /* @__PURE__ */ new Float64Array(256));
|
|
1297
|
+
_defineProperty(this, "seqs", /* @__PURE__ */ new Int32Array(256));
|
|
1298
|
+
_defineProperty(this, "len", 0);
|
|
1239
1299
|
_defineProperty(this, "seq", 0);
|
|
1240
1300
|
}
|
|
1241
1301
|
get size() {
|
|
1242
|
-
return this.
|
|
1302
|
+
return this.len;
|
|
1243
1303
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1252
|
-
|
|
1304
|
+
peekF() {
|
|
1305
|
+
return this.fs[0];
|
|
1306
|
+
}
|
|
1307
|
+
push(key, f, h) {
|
|
1308
|
+
if (this.len === this.keys.length) this.grow();
|
|
1309
|
+
let i = this.len++;
|
|
1310
|
+
const s = this.seq++;
|
|
1311
|
+
const { keys, fs, hs, seqs } = this;
|
|
1312
|
+
keys[i] = key;
|
|
1313
|
+
fs[i] = f;
|
|
1314
|
+
hs[i] = h;
|
|
1315
|
+
seqs[i] = s;
|
|
1253
1316
|
while (i > 0) {
|
|
1254
1317
|
const parent = i - 1 >> 1;
|
|
1255
|
-
if (!this.less(
|
|
1256
|
-
|
|
1318
|
+
if (!this.less(i, parent)) break;
|
|
1319
|
+
this.swap(i, parent);
|
|
1257
1320
|
i = parent;
|
|
1258
1321
|
}
|
|
1259
1322
|
}
|
|
1260
1323
|
pop() {
|
|
1261
|
-
const
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1324
|
+
const top = this.keys[0];
|
|
1325
|
+
const last = --this.len;
|
|
1326
|
+
if (last > 0) {
|
|
1327
|
+
this.keys[0] = this.keys[last];
|
|
1328
|
+
this.fs[0] = this.fs[last];
|
|
1329
|
+
this.hs[0] = this.hs[last];
|
|
1330
|
+
this.seqs[0] = this.seqs[last];
|
|
1266
1331
|
let i = 0;
|
|
1267
1332
|
for (;;) {
|
|
1268
1333
|
const l = i * 2 + 1;
|
|
1269
1334
|
const r = l + 1;
|
|
1270
1335
|
let m = i;
|
|
1271
|
-
if (l <
|
|
1272
|
-
if (r <
|
|
1336
|
+
if (l < last && this.less(l, m)) m = l;
|
|
1337
|
+
if (r < last && this.less(r, m)) m = r;
|
|
1273
1338
|
if (m === i) break;
|
|
1274
|
-
|
|
1339
|
+
this.swap(i, m);
|
|
1275
1340
|
i = m;
|
|
1276
1341
|
}
|
|
1277
1342
|
}
|
|
1278
|
-
return top
|
|
1343
|
+
return top;
|
|
1344
|
+
}
|
|
1345
|
+
grow() {
|
|
1346
|
+
const nextCap = this.keys.length * 2;
|
|
1347
|
+
const nextKeys = new Int32Array(nextCap);
|
|
1348
|
+
const nextFs = new Float64Array(nextCap);
|
|
1349
|
+
const nextHs = new Float64Array(nextCap);
|
|
1350
|
+
const nextSeqs = new Int32Array(nextCap);
|
|
1351
|
+
nextKeys.set(this.keys);
|
|
1352
|
+
nextFs.set(this.fs);
|
|
1353
|
+
nextHs.set(this.hs);
|
|
1354
|
+
nextSeqs.set(this.seqs);
|
|
1355
|
+
this.keys = nextKeys;
|
|
1356
|
+
this.fs = nextFs;
|
|
1357
|
+
this.hs = nextHs;
|
|
1358
|
+
this.seqs = nextSeqs;
|
|
1279
1359
|
}
|
|
1280
1360
|
less(a, b) {
|
|
1281
|
-
|
|
1361
|
+
const fa = this.fs[a];
|
|
1362
|
+
const fb = this.fs[b];
|
|
1363
|
+
if (fa !== fb) return fa < fb;
|
|
1364
|
+
const ha = this.hs[a];
|
|
1365
|
+
const hb = this.hs[b];
|
|
1366
|
+
if (ha !== hb) return ha < hb;
|
|
1367
|
+
return this.seqs[a] < this.seqs[b];
|
|
1368
|
+
}
|
|
1369
|
+
swap(a, b) {
|
|
1370
|
+
const tk = this.keys[a];
|
|
1371
|
+
this.keys[a] = this.keys[b];
|
|
1372
|
+
this.keys[b] = tk;
|
|
1373
|
+
const tf = this.fs[a];
|
|
1374
|
+
this.fs[a] = this.fs[b];
|
|
1375
|
+
this.fs[b] = tf;
|
|
1376
|
+
const th = this.hs[a];
|
|
1377
|
+
this.hs[a] = this.hs[b];
|
|
1378
|
+
this.hs[b] = th;
|
|
1379
|
+
const ts = this.seqs[a];
|
|
1380
|
+
this.seqs[a] = this.seqs[b];
|
|
1381
|
+
this.seqs[b] = ts;
|
|
1282
1382
|
}
|
|
1283
1383
|
};
|
|
1284
|
-
|
|
1384
|
+
function sortedUnique(values) {
|
|
1385
|
+
values.sort();
|
|
1386
|
+
let write = 0;
|
|
1387
|
+
for (let i = 0; i < values.length; i++) {
|
|
1388
|
+
const v = values[i];
|
|
1389
|
+
if (write === 0 || values[write - 1] !== v) values[write++] = v;
|
|
1390
|
+
}
|
|
1391
|
+
return values.subarray(0, write);
|
|
1392
|
+
}
|
|
1393
|
+
function lowerBound(arr, value) {
|
|
1394
|
+
let lo = 0;
|
|
1395
|
+
let hi = arr.length;
|
|
1396
|
+
while (lo < hi) {
|
|
1397
|
+
const mid = lo + hi >>> 1;
|
|
1398
|
+
if (arr[mid] < value) lo = mid + 1;
|
|
1399
|
+
else hi = mid;
|
|
1400
|
+
}
|
|
1401
|
+
return lo;
|
|
1402
|
+
}
|
|
1403
|
+
function edgeBlockedExact(a, b, boxes) {
|
|
1404
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1405
|
+
const box = boxes[i];
|
|
1406
|
+
if (!strictlyInside(a, box) && !strictlyInside(b, box) && crosses(a, b, box)) return true;
|
|
1407
|
+
}
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
function rasterizeDiff(diff, rows, cols, out) {
|
|
1411
|
+
const diffW = cols + 1;
|
|
1412
|
+
for (let r = 0; r < rows; r++) {
|
|
1413
|
+
let rowSum = 0;
|
|
1414
|
+
const rowOff = r * diffW;
|
|
1415
|
+
const prevOff = (r - 1) * diffW;
|
|
1416
|
+
const outOff = r * cols;
|
|
1417
|
+
for (let c = 0; c < cols; c++) {
|
|
1418
|
+
rowSum += diff[rowOff + c];
|
|
1419
|
+
const val = r > 0 ? rowSum + diff[prevOff + c] : rowSum;
|
|
1420
|
+
diff[rowOff + c] = val;
|
|
1421
|
+
out[outOff + c] = val > 0 ? 1 : 0;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
function addDiffRect(diff, diffW, r0, r1, c0, c1) {
|
|
1426
|
+
if (r0 >= r1 || c0 >= c1) return;
|
|
1427
|
+
diff[r0 * diffW + c0] += 1;
|
|
1428
|
+
diff[r0 * diffW + c1] -= 1;
|
|
1429
|
+
diff[r1 * diffW + c0] -= 1;
|
|
1430
|
+
diff[r1 * diffW + c1] += 1;
|
|
1431
|
+
}
|
|
1285
1432
|
function searchGrid(from, to, startDir, endDir, boxes) {
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
]
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1433
|
+
const xRaw = new Float64Array(boxes.length * 2 + 3);
|
|
1434
|
+
const yRaw = new Float64Array(boxes.length * 2 + 3);
|
|
1435
|
+
xRaw[0] = from[0];
|
|
1436
|
+
xRaw[1] = to[0];
|
|
1437
|
+
xRaw[2] = (from[0] + to[0]) / 2;
|
|
1438
|
+
yRaw[0] = from[1];
|
|
1439
|
+
yRaw[1] = to[1];
|
|
1440
|
+
yRaw[2] = (from[1] + to[1]) / 2;
|
|
1441
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1442
|
+
const b = boxes[i];
|
|
1443
|
+
const base = 3 + i * 2;
|
|
1444
|
+
xRaw[base] = b[0];
|
|
1445
|
+
xRaw[base + 1] = b[2];
|
|
1446
|
+
yRaw[base] = b[1];
|
|
1447
|
+
yRaw[base + 1] = b[3];
|
|
1448
|
+
}
|
|
1449
|
+
const xs = sortedUnique(xRaw);
|
|
1450
|
+
const ys = sortedUnique(yRaw);
|
|
1298
1451
|
const cols = xs.length;
|
|
1299
|
-
const
|
|
1300
|
-
const
|
|
1301
|
-
const
|
|
1302
|
-
const
|
|
1303
|
-
const
|
|
1304
|
-
const
|
|
1305
|
-
const
|
|
1306
|
-
const
|
|
1452
|
+
const rows = ys.length;
|
|
1453
|
+
const totalNodes = rows * cols;
|
|
1454
|
+
const startXi = lowerBound(xs, from[0]);
|
|
1455
|
+
const startYi = lowerBound(ys, from[1]);
|
|
1456
|
+
const goalXi = lowerBound(xs, to[0]);
|
|
1457
|
+
const goalYi = lowerBound(ys, to[1]);
|
|
1458
|
+
const startNode = startYi * cols + startXi;
|
|
1459
|
+
const goalNode = goalYi * cols + goalXi;
|
|
1460
|
+
const vertexBlocked = new Uint8Array(totalNodes);
|
|
1461
|
+
const hBlocked = new Uint8Array(totalNodes);
|
|
1462
|
+
const vBlocked = new Uint8Array(totalNodes);
|
|
1463
|
+
if (boxes.length > 0) {
|
|
1464
|
+
const boxIdx = new Int32Array(boxes.length * 4);
|
|
1465
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1466
|
+
const b = boxes[i];
|
|
1467
|
+
const off = i * 4;
|
|
1468
|
+
boxIdx[off] = lowerBound(xs, b[0]);
|
|
1469
|
+
boxIdx[off + 1] = lowerBound(xs, b[2]);
|
|
1470
|
+
boxIdx[off + 2] = lowerBound(ys, b[1]);
|
|
1471
|
+
boxIdx[off + 3] = lowerBound(ys, b[3]);
|
|
1472
|
+
}
|
|
1473
|
+
const diffW = cols + 1;
|
|
1474
|
+
const diff = new Int32Array((rows + 1) * diffW);
|
|
1475
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1476
|
+
const off = i * 4;
|
|
1477
|
+
addDiffRect(diff, diffW, boxIdx[off + 2] + 1, boxIdx[off + 3], boxIdx[off] + 1, boxIdx[off + 1]);
|
|
1478
|
+
}
|
|
1479
|
+
rasterizeDiff(diff, rows, cols, vertexBlocked);
|
|
1480
|
+
vertexBlocked[startNode] = 0;
|
|
1481
|
+
vertexBlocked[goalNode] = 0;
|
|
1482
|
+
diff.fill(0);
|
|
1483
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1484
|
+
const off = i * 4;
|
|
1485
|
+
addDiffRect(diff, diffW, boxIdx[off + 2] + 1, boxIdx[off + 3], boxIdx[off], boxIdx[off + 1]);
|
|
1486
|
+
}
|
|
1487
|
+
rasterizeDiff(diff, rows, cols, hBlocked);
|
|
1488
|
+
diff.fill(0);
|
|
1489
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1490
|
+
const off = i * 4;
|
|
1491
|
+
addDiffRect(diff, diffW, boxIdx[off + 2], boxIdx[off + 3], boxIdx[off] + 1, boxIdx[off + 1]);
|
|
1492
|
+
}
|
|
1493
|
+
rasterizeDiff(diff, rows, cols, vBlocked);
|
|
1494
|
+
const specials = [[
|
|
1495
|
+
startXi,
|
|
1496
|
+
startYi,
|
|
1497
|
+
from
|
|
1498
|
+
], [
|
|
1499
|
+
goalXi,
|
|
1500
|
+
goalYi,
|
|
1501
|
+
to
|
|
1502
|
+
]];
|
|
1503
|
+
for (const [sx, sy, sp] of specials) {
|
|
1504
|
+
if (sx + 1 < cols) hBlocked[sy * cols + sx] = edgeBlockedExact(sp, [xs[sx + 1], ys[sy]], boxes) ? 1 : 0;
|
|
1505
|
+
if (sx > 0) hBlocked[sy * cols + sx - 1] = edgeBlockedExact([xs[sx - 1], ys[sy]], sp, boxes) ? 1 : 0;
|
|
1506
|
+
if (sy + 1 < rows) vBlocked[sy * cols + sx] = edgeBlockedExact(sp, [xs[sx], ys[sy + 1]], boxes) ? 1 : 0;
|
|
1507
|
+
if (sy > 0) vBlocked[(sy - 1) * cols + sx] = edgeBlockedExact([xs[sx], ys[sy - 1]], sp, boxes) ? 1 : 0;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
const totalStates = totalNodes * 4;
|
|
1511
|
+
const g = new Float64Array(totalStates);
|
|
1512
|
+
g.fill(Infinity);
|
|
1513
|
+
const parent = new Int32Array(totalStates);
|
|
1514
|
+
parent.fill(-1);
|
|
1515
|
+
const closed = new Uint8Array(totalStates);
|
|
1307
1516
|
const heap = new MinHeap();
|
|
1308
|
-
const
|
|
1517
|
+
const toX = to[0];
|
|
1518
|
+
const toY = to[1];
|
|
1519
|
+
const startH = Math.abs(from[0] - toX) + Math.abs(from[1] - toY);
|
|
1309
1520
|
const startKey = startNode * 4 + startDir;
|
|
1310
|
-
g
|
|
1311
|
-
heap.push(startKey,
|
|
1312
|
-
let
|
|
1521
|
+
g[startKey] = 0;
|
|
1522
|
+
heap.push(startKey, startH, startH);
|
|
1523
|
+
let bestCost = Infinity;
|
|
1524
|
+
let bestKey = -1;
|
|
1313
1525
|
while (heap.size > 0) {
|
|
1526
|
+
if (heap.peekF() >= bestCost) break;
|
|
1314
1527
|
const key = heap.pop();
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
const
|
|
1318
|
-
|
|
1319
|
-
const
|
|
1528
|
+
if (closed[key]) continue;
|
|
1529
|
+
closed[key] = 1;
|
|
1530
|
+
const cost = g[key];
|
|
1531
|
+
if (cost >= bestCost) break;
|
|
1532
|
+
const node = key >> 2;
|
|
1533
|
+
const dir = key & 3;
|
|
1320
1534
|
if (node === goalNode) {
|
|
1321
1535
|
const total = cost + (dir === endDir ? 0 : BEND_PENALTY * 1.5);
|
|
1322
|
-
if (
|
|
1323
|
-
|
|
1324
|
-
key
|
|
1325
|
-
}
|
|
1536
|
+
if (total < bestCost) {
|
|
1537
|
+
bestCost = total;
|
|
1538
|
+
bestKey = key;
|
|
1539
|
+
}
|
|
1326
1540
|
continue;
|
|
1327
1541
|
}
|
|
1328
1542
|
const xi = node % cols;
|
|
1329
|
-
const yi =
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1334
|
-
if (
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1543
|
+
const yi = (node - xi) / cols;
|
|
1544
|
+
const px = xs[xi];
|
|
1545
|
+
const py = ys[yi];
|
|
1546
|
+
if (dir !== 2 && xi + 1 < cols) {
|
|
1547
|
+
const next = node + 1;
|
|
1548
|
+
if (!vertexBlocked[next] && !hBlocked[node]) {
|
|
1549
|
+
const nextKey = next << 2 | 0;
|
|
1550
|
+
const qx = xs[xi + 1];
|
|
1551
|
+
const ng = cost + (qx - px) + (dir === 0 ? 0 : BEND_PENALTY);
|
|
1552
|
+
if (ng < g[nextKey]) {
|
|
1553
|
+
const nh = Math.abs(qx - toX) + Math.abs(py - toY);
|
|
1554
|
+
if (ng + nh < bestCost) {
|
|
1555
|
+
g[nextKey] = ng;
|
|
1556
|
+
parent[nextKey] = key;
|
|
1557
|
+
heap.push(nextKey, ng + nh, nh);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
if (dir !== 3 && yi + 1 < rows) {
|
|
1563
|
+
const next = node + cols;
|
|
1564
|
+
if (!vertexBlocked[next] && !vBlocked[node]) {
|
|
1565
|
+
const nextKey = next << 2 | 1;
|
|
1566
|
+
const qy = ys[yi + 1];
|
|
1567
|
+
const ng = cost + (qy - py) + (dir === 1 ? 0 : BEND_PENALTY);
|
|
1568
|
+
if (ng < g[nextKey]) {
|
|
1569
|
+
const nh = Math.abs(px - toX) + Math.abs(qy - toY);
|
|
1570
|
+
if (ng + nh < bestCost) {
|
|
1571
|
+
g[nextKey] = ng;
|
|
1572
|
+
parent[nextKey] = key;
|
|
1573
|
+
heap.push(nextKey, ng + nh, nh);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
if (dir !== 0 && xi > 0) {
|
|
1579
|
+
const next = node - 1;
|
|
1580
|
+
if (!vertexBlocked[next] && !hBlocked[next]) {
|
|
1581
|
+
const nextKey = next << 2 | 2;
|
|
1582
|
+
const qx = xs[xi - 1];
|
|
1583
|
+
const ng = cost + (px - qx) + (dir === 2 ? 0 : BEND_PENALTY);
|
|
1584
|
+
if (ng < g[nextKey]) {
|
|
1585
|
+
const nh = Math.abs(qx - toX) + Math.abs(py - toY);
|
|
1586
|
+
if (ng + nh < bestCost) {
|
|
1587
|
+
g[nextKey] = ng;
|
|
1588
|
+
parent[nextKey] = key;
|
|
1589
|
+
heap.push(nextKey, ng + nh, nh);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (dir !== 1 && yi > 0) {
|
|
1595
|
+
const next = node - cols;
|
|
1596
|
+
if (!vertexBlocked[next] && !vBlocked[next]) {
|
|
1597
|
+
const nextKey = next << 2 | 3;
|
|
1598
|
+
const qy = ys[yi - 1];
|
|
1599
|
+
const ng = cost + (py - qy) + (dir === 3 ? 0 : BEND_PENALTY);
|
|
1600
|
+
if (ng < g[nextKey]) {
|
|
1601
|
+
const nh = Math.abs(px - toX) + Math.abs(qy - toY);
|
|
1602
|
+
if (ng + nh < bestCost) {
|
|
1603
|
+
g[nextKey] = ng;
|
|
1604
|
+
parent[nextKey] = key;
|
|
1605
|
+
heap.push(nextKey, ng + nh, nh);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1344
1609
|
}
|
|
1345
1610
|
}
|
|
1346
|
-
if (
|
|
1611
|
+
if (bestKey < 0) return null;
|
|
1347
1612
|
const path = [];
|
|
1348
|
-
let key =
|
|
1349
|
-
while (key
|
|
1350
|
-
const node =
|
|
1351
|
-
|
|
1352
|
-
|
|
1613
|
+
let key = bestKey;
|
|
1614
|
+
while (key >= 0) {
|
|
1615
|
+
const node = key >> 2;
|
|
1616
|
+
if (node === startNode) path.push(from);
|
|
1617
|
+
else if (node === goalNode) path.push(to);
|
|
1618
|
+
else {
|
|
1619
|
+
const xi = node % cols;
|
|
1620
|
+
const yi = (node - xi) / cols;
|
|
1621
|
+
path.push([xs[xi], ys[yi]]);
|
|
1622
|
+
}
|
|
1623
|
+
key = parent[key];
|
|
1353
1624
|
}
|
|
1354
1625
|
return path.reverse();
|
|
1355
1626
|
}
|
|
@@ -1367,16 +1638,48 @@ function simplify(points, keep = /* @__PURE__ */ new Set()) {
|
|
|
1367
1638
|
];
|
|
1368
1639
|
if ((a[0] === b[0] && b[0] === c[0] || a[1] === b[1] && b[1] === c[1]) && !keep.has(`${b[0]},${b[1]}`)) out.splice(i, 1);
|
|
1369
1640
|
}
|
|
1641
|
+
if (out.length === 1 && points.length >= 2) out.push([out[0][0], out[0][1]]);
|
|
1370
1642
|
return out;
|
|
1371
1643
|
}
|
|
1644
|
+
function pathHitsAny(path, boxes) {
|
|
1645
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
1646
|
+
const a = path[i];
|
|
1647
|
+
const b = path[i + 1];
|
|
1648
|
+
for (let j = 0; j < boxes.length; j++) {
|
|
1649
|
+
const box = boxes[j];
|
|
1650
|
+
if (!strictlyInside(a, box) && !strictlyInside(b, box) && crosses(a, b, box)) return true;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1372
1655
|
function routeElbowArrow(start, end, opts) {
|
|
1373
1656
|
const startHeading = opts.startHeading ?? (opts.startTarget ? headingForPoint(opts.startTarget, end) : towards(start, end));
|
|
1374
1657
|
const endHeading = opts.endHeading ?? (opts.endTarget ? headingForPoint(opts.endTarget, start) : towards(end, start));
|
|
1375
1658
|
const from = exitPoint(start, startHeading, opts.startTarget);
|
|
1376
1659
|
const to = exitPoint(end, endHeading, opts.endTarget);
|
|
1377
1660
|
const targets = [opts.startTarget, opts.endTarget].filter((el) => !!el).map((el) => getElementBounds(el));
|
|
1378
|
-
const boxes = [...opts.obstacles, ...targets].map((b) => expand(b,
|
|
1379
|
-
const
|
|
1661
|
+
const boxes = [...opts.obstacles, ...targets].map((b) => expand(b, ELBOW_PADDING));
|
|
1662
|
+
const startDir = dirIndex(startHeading);
|
|
1663
|
+
const endDir = (dirIndex(endHeading) + 2) % 4;
|
|
1664
|
+
let middle = null;
|
|
1665
|
+
if (boxes.length > 0) {
|
|
1666
|
+
const cMinX = Math.min(from[0], to[0]) - CORRIDOR_MARGIN;
|
|
1667
|
+
const cMinY = Math.min(from[1], to[1]) - CORRIDOR_MARGIN;
|
|
1668
|
+
const cMaxX = Math.max(from[0], to[0]) + CORRIDOR_MARGIN;
|
|
1669
|
+
const cMaxY = Math.max(from[1], to[1]) + CORRIDOR_MARGIN;
|
|
1670
|
+
const culled = [];
|
|
1671
|
+
const outside = [];
|
|
1672
|
+
for (let i = 0; i < boxes.length; i++) {
|
|
1673
|
+
const b = boxes[i];
|
|
1674
|
+
if (b[0] <= cMaxX && b[2] >= cMinX && b[1] <= cMaxY && b[3] >= cMinY) culled.push(b);
|
|
1675
|
+
else outside.push(b);
|
|
1676
|
+
}
|
|
1677
|
+
if (outside.length > 0) {
|
|
1678
|
+
const candidate = searchGrid(from, to, startDir, endDir, culled);
|
|
1679
|
+
if (candidate && !pathHitsAny(candidate, outside)) middle = candidate;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
middle ?? (middle = searchGrid(from, to, startDir, endDir, boxes));
|
|
1380
1683
|
if (!middle) {
|
|
1381
1684
|
const mx = (from[0] + to[0]) / 2;
|
|
1382
1685
|
return simplify([
|
|
@@ -1514,6 +1817,9 @@ function movePoint(el, index, p) {
|
|
|
1514
1817
|
abs[index] = p;
|
|
1515
1818
|
return bumpVersion(el, fromAbsolutePoints(el, abs));
|
|
1516
1819
|
}
|
|
1820
|
+
//#endregion
|
|
1821
|
+
//#region src/model/binding.ts
|
|
1822
|
+
var BINDING_DISTANCE = 15;
|
|
1517
1823
|
var bindingKey = (end) => end === "start" ? "startBinding" : "endBinding";
|
|
1518
1824
|
function fromLocal(el, [lx, ly]) {
|
|
1519
1825
|
return rotatePoint([el.x + lx, el.y + ly], getElementCenter(el), angleOf$1(el));
|
|
@@ -1550,7 +1856,7 @@ function distanceToOutline(el, p) {
|
|
|
1550
1856
|
return Math.hypot(Math.max(-lx, 0, lx - w), Math.max(-ly, 0, ly - h));
|
|
1551
1857
|
}
|
|
1552
1858
|
function getHoveredBindable(elements, p, zoom, excludeIds = /* @__PURE__ */ new Set()) {
|
|
1553
|
-
const threshold =
|
|
1859
|
+
const threshold = BINDING_DISTANCE / zoom;
|
|
1554
1860
|
for (let i = elements.length - 1; i >= 0; i--) {
|
|
1555
1861
|
const el = elements[i];
|
|
1556
1862
|
if (excludeIds.has(el.id) || !isBindable(el)) continue;
|
|
@@ -1608,7 +1914,7 @@ function frameFor(target, from) {
|
|
|
1608
1914
|
half: extentAlong(target, n)
|
|
1609
1915
|
};
|
|
1610
1916
|
}
|
|
1611
|
-
var clamp
|
|
1917
|
+
var clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
1612
1918
|
function computeFocus(target, from, to) {
|
|
1613
1919
|
const f = frameFor(target, from);
|
|
1614
1920
|
if (!f || f.half === 0) return 0;
|
|
@@ -1616,12 +1922,12 @@ function computeFocus(target, from, to) {
|
|
|
1616
1922
|
const v = [p[0] - f.o[0], p[1] - f.o[1]];
|
|
1617
1923
|
const along = v[0] * f.u[0] + v[1] * f.u[1];
|
|
1618
1924
|
if (along < 1e-9) return 0;
|
|
1619
|
-
return clamp
|
|
1925
|
+
return clamp(f.len / along * (v[0] * f.n[0] + v[1] * f.n[1]) / f.half, -1, 1);
|
|
1620
1926
|
}
|
|
1621
1927
|
function getBindingPoint(target, focus, gap, otherPoint) {
|
|
1622
1928
|
const f = frameFor(target, otherPoint);
|
|
1623
1929
|
if (!f) return getElementCenter(target);
|
|
1624
|
-
const offset = clamp
|
|
1930
|
+
const offset = clamp(focus, -1, 1) * f.half;
|
|
1625
1931
|
const aim = [f.c[0] + f.n[0] * offset, f.c[1] + f.n[1] * offset];
|
|
1626
1932
|
const dist = Math.hypot(aim[0] - f.o[0], aim[1] - f.o[1]);
|
|
1627
1933
|
if (dist < 1e-9) return fromLocal(target, aim);
|
|
@@ -1680,6 +1986,11 @@ function bindLinearEnd(elements, linearId, end, targetId) {
|
|
|
1680
1986
|
return current;
|
|
1681
1987
|
}
|
|
1682
1988
|
var finiteOr = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
1989
|
+
function anchorPoint(target, binding) {
|
|
1990
|
+
const fixed = binding.fixedPoint;
|
|
1991
|
+
if (Array.isArray(fixed) && fixed.length === 2 && fixed.every(Number.isFinite)) return fromLocal(target, [fixed[0] * target.width, fixed[1] * target.height]);
|
|
1992
|
+
return getElementCenter(target);
|
|
1993
|
+
}
|
|
1683
1994
|
function attachmentPoint(target, binding, other) {
|
|
1684
1995
|
const fixed = binding.fixedPoint;
|
|
1685
1996
|
if (Array.isArray(fixed) && fixed.length === 2 && fixed.every(Number.isFinite)) return fromLocal(target, [fixed[0] * target.width, fixed[1] * target.height]);
|
|
@@ -1687,18 +1998,25 @@ function attachmentPoint(target, binding, other) {
|
|
|
1687
1998
|
}
|
|
1688
1999
|
function recomputeEnds(linear, byId, ends) {
|
|
1689
2000
|
const abs = getLinearAbsolutePoints(linear);
|
|
2001
|
+
const nextAbs = [...abs];
|
|
1690
2002
|
let changed = false;
|
|
1691
2003
|
for (const end of ends) {
|
|
1692
2004
|
const binding = linear[bindingKey(end)];
|
|
1693
2005
|
const target = binding && byId.get(binding.elementId);
|
|
1694
2006
|
if (!binding || !target || target.isDeleted) continue;
|
|
1695
2007
|
const [index, adjacentIndex] = endIndices(linear, end);
|
|
1696
|
-
|
|
2008
|
+
let other = abs[adjacentIndex];
|
|
2009
|
+
if (abs.length === 2) {
|
|
2010
|
+
const oppositeBinding = linear[bindingKey(end === "start" ? "end" : "start")];
|
|
2011
|
+
const oppositeTarget = oppositeBinding && byId.get(oppositeBinding.elementId);
|
|
2012
|
+
if (oppositeBinding && oppositeTarget && !oppositeTarget.isDeleted) other = anchorPoint(oppositeTarget, oppositeBinding);
|
|
2013
|
+
}
|
|
2014
|
+
const next = attachmentPoint(target, binding, other);
|
|
1697
2015
|
if (!next.every(Number.isFinite)) continue;
|
|
1698
|
-
|
|
2016
|
+
nextAbs[index] = next;
|
|
1699
2017
|
changed = true;
|
|
1700
2018
|
}
|
|
1701
|
-
return changed ? bumpVersion(linear, fromAbsolutePoints(linear,
|
|
2019
|
+
return changed ? bumpVersion(linear, fromAbsolutePoints(linear, nextAbs)) : linear;
|
|
1702
2020
|
}
|
|
1703
2021
|
function updateBoundArrows(elements, changedIds) {
|
|
1704
2022
|
const byId = new Map(elements.map((el) => [el.id, el]));
|
|
@@ -1899,10 +2217,26 @@ function collect(ctx, from, to) {
|
|
|
1899
2217
|
const state = ctx.store.getState();
|
|
1900
2218
|
const tol = 6 / state.viewport.zoom;
|
|
1901
2219
|
const erasing = new Set(state.erasingIds);
|
|
2220
|
+
const segMinX = Math.min(from[0], to[0]);
|
|
2221
|
+
const segMinY = Math.min(from[1], to[1]);
|
|
2222
|
+
const segMaxX = Math.max(from[0], to[0]);
|
|
2223
|
+
const segMaxY = Math.max(from[1], to[1]);
|
|
2224
|
+
const candidates = [];
|
|
2225
|
+
let needsById = false;
|
|
2226
|
+
for (const el of state.elements) {
|
|
2227
|
+
if (erasing.has(el.id) || !isSelectable(el)) continue;
|
|
2228
|
+
const [minX, minY, maxX, maxY] = getElementBounds(el);
|
|
2229
|
+
const pad = tol + (Number.isFinite(el.strokeWidth) ? el.strokeWidth : 0) / 2;
|
|
2230
|
+
const frameExtra = el.type === "frame" || el.type === "magicframe" ? 20 : 0;
|
|
2231
|
+
if (maxX + pad < segMinX || minX - pad > segMaxX || maxY + pad < segMinY || minY - pad - frameExtra > segMaxY) continue;
|
|
2232
|
+
candidates.push(el);
|
|
2233
|
+
if (getContainerId(el)) needsById = true;
|
|
2234
|
+
}
|
|
2235
|
+
if (candidates.length === 0) return;
|
|
2236
|
+
const byId = needsById ? new Map(state.elements.filter((el) => !erasing.has(el.id)).map((el) => [el.id, el])) : void 0;
|
|
1902
2237
|
const steps = Math.max(1, Math.ceil(Math.hypot(to[0] - from[0], to[1] - from[1]) / SAMPLE_STEP));
|
|
1903
|
-
const alive = state.elements.filter((el) => !erasing.has(el.id));
|
|
1904
2238
|
for (let i = 0; i <= steps; i++) {
|
|
1905
|
-
const hit = getHitElement(
|
|
2239
|
+
const hit = getHitElement(candidates, [from[0] + (to[0] - from[0]) * i / steps, from[1] + (to[1] - from[1]) * i / steps], tol, byId);
|
|
1906
2240
|
if (hit) erasing.add(hit.id);
|
|
1907
2241
|
}
|
|
1908
2242
|
if (erasing.size !== state.erasingIds.size) ctx.store.setState({ erasingIds: erasing });
|
|
@@ -2168,6 +2502,9 @@ function createLinearTool(type, options = {}) {
|
|
|
2168
2502
|
}
|
|
2169
2503
|
};
|
|
2170
2504
|
}
|
|
2505
|
+
//#endregion
|
|
2506
|
+
//#region src/editor/linear-editor.ts
|
|
2507
|
+
var POINT_HIT_RADIUS = 8;
|
|
2171
2508
|
function isEditableLinear(el) {
|
|
2172
2509
|
return !!el && (el.type === "line" || el.type === "arrow") && !el.locked;
|
|
2173
2510
|
}
|
|
@@ -2220,7 +2557,7 @@ function moveElbowSegment(el, index, p) {
|
|
|
2220
2557
|
});
|
|
2221
2558
|
}
|
|
2222
2559
|
function hitPointHandle(el, p, zoom) {
|
|
2223
|
-
const radius =
|
|
2560
|
+
const radius = POINT_HIT_RADIUS / zoom;
|
|
2224
2561
|
const near = ([x, y]) => Math.hypot(p[0] - x, p[1] - y) <= radius;
|
|
2225
2562
|
const abs = getLinearAbsolutePoints(el);
|
|
2226
2563
|
for (let i = abs.length - 1; i >= 0; i--) if ((i === 0 || i === abs.length - 1 || !el.elbowed) && near(abs[i])) return {
|
|
@@ -2308,6 +2645,11 @@ function startPointGesture(ctx, e, onMove) {
|
|
|
2308
2645
|
}
|
|
2309
2646
|
};
|
|
2310
2647
|
}
|
|
2648
|
+
//#endregion
|
|
2649
|
+
//#region src/editor/transform.ts
|
|
2650
|
+
var HANDLE_PADDING = 8;
|
|
2651
|
+
var ROTATION_OFFSET = 24;
|
|
2652
|
+
var HANDLE_HIT_RADIUS = 8;
|
|
2311
2653
|
var MIN_SIZE = 1;
|
|
2312
2654
|
var SNAP_ANGLE = Math.PI / 12;
|
|
2313
2655
|
function unrotatedBox(el) {
|
|
@@ -2344,7 +2686,7 @@ function getTransformFrame(elements) {
|
|
|
2344
2686
|
};
|
|
2345
2687
|
}
|
|
2346
2688
|
function getTransformHandles(box, zoom, angle = 0) {
|
|
2347
|
-
const pad =
|
|
2689
|
+
const pad = HANDLE_PADDING / zoom;
|
|
2348
2690
|
const [x1, y1, x2, y2] = [
|
|
2349
2691
|
box[0] - pad,
|
|
2350
2692
|
box[1] - pad,
|
|
@@ -2362,7 +2704,7 @@ function getTransformHandles(box, zoom, angle = 0) {
|
|
|
2362
2704
|
s: [cx, y2],
|
|
2363
2705
|
sw: [x1, y2],
|
|
2364
2706
|
w: [x1, cy],
|
|
2365
|
-
rotation: [cx, y1 -
|
|
2707
|
+
rotation: [cx, y1 - ROTATION_OFFSET / zoom]
|
|
2366
2708
|
};
|
|
2367
2709
|
if (!angle) return raw;
|
|
2368
2710
|
const out = {};
|
|
@@ -2370,7 +2712,7 @@ function getTransformHandles(box, zoom, angle = 0) {
|
|
|
2370
2712
|
return out;
|
|
2371
2713
|
}
|
|
2372
2714
|
function hitTransformHandle(handles, p, zoom) {
|
|
2373
|
-
const radius =
|
|
2715
|
+
const radius = HANDLE_HIT_RADIUS / zoom;
|
|
2374
2716
|
for (const [k, [hx, hy]] of Object.entries(handles)) if (Math.hypot(p[0] - hx, p[1] - hy) <= radius) return k;
|
|
2375
2717
|
return null;
|
|
2376
2718
|
}
|
|
@@ -2841,6 +3183,9 @@ function isChromeTarget(target) {
|
|
|
2841
3183
|
return target instanceof Element && !!target.closest(`[data-whiteboard-chrome]`);
|
|
2842
3184
|
}
|
|
2843
3185
|
var WHEEL_ZOOM_FACTOR = .01;
|
|
3186
|
+
var EDITING_CARD_PROPS = { className: editingCard };
|
|
3187
|
+
var ERASING_PROPS = { opacity: .25 };
|
|
3188
|
+
var PENDING_IMAGE_PROPS = { opacity: .5 };
|
|
2844
3189
|
var WhiteboardCanvas = ({ children, context, handlers, onContextMenu, store, theme }) => {
|
|
2845
3190
|
const ref = useRef(null);
|
|
2846
3191
|
const activeRef = useRef(null);
|
|
@@ -2876,9 +3221,9 @@ var WhiteboardCanvas = ({ children, context, handlers, onContextMenu, store, the
|
|
|
2876
3221
|
}), [elements, files]);
|
|
2877
3222
|
const hiddenIds = useMemo(() => editingTextId ? /* @__PURE__ */ new Set([editingTextId]) : void 0, [editingTextId]);
|
|
2878
3223
|
const elementProps = useCallback((el) => {
|
|
2879
|
-
if (el.id === editingRichTextId) return
|
|
2880
|
-
if (erasingIds.has(el.id)) return
|
|
2881
|
-
if (el.type === "image" && el.status === "pending") return
|
|
3224
|
+
if (el.id === editingRichTextId) return EDITING_CARD_PROPS;
|
|
3225
|
+
if (erasingIds.has(el.id)) return ERASING_PROPS;
|
|
3226
|
+
if (el.type === "image" && el.status === "pending") return PENDING_IMAGE_PROPS;
|
|
2882
3227
|
}, [erasingIds, editingRichTextId]);
|
|
2883
3228
|
const toPointer = useCallback((e) => {
|
|
2884
3229
|
const rect = ref.current.getBoundingClientRect();
|
|
@@ -3520,15 +3865,6 @@ var THEME = {
|
|
|
3520
3865
|
underlineStrikethrough
|
|
3521
3866
|
}
|
|
3522
3867
|
};
|
|
3523
|
-
var BAR_WIDTH = 440;
|
|
3524
|
-
var BAR_MARGIN = 8;
|
|
3525
|
-
var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
3526
|
-
function formatBarPosition(left, top, canvas) {
|
|
3527
|
-
const maxLeft = Math.max(BAR_MARGIN, canvas.width - BAR_WIDTH - BAR_MARGIN);
|
|
3528
|
-
const minTop = 44;
|
|
3529
|
-
const maxTop = Math.max(minTop, canvas.height - BAR_MARGIN);
|
|
3530
|
-
return [clamp(left, BAR_MARGIN, maxLeft), clamp(top - BAR_MARGIN, minTop, maxTop)];
|
|
3531
|
-
}
|
|
3532
3868
|
var NODES = [
|
|
3533
3869
|
HeadingNode,
|
|
3534
3870
|
QuoteNode,
|
|
@@ -4347,12 +4683,15 @@ var StylePanel = ({ store }) => {
|
|
|
4347
4683
|
children: rows
|
|
4348
4684
|
});
|
|
4349
4685
|
};
|
|
4686
|
+
//#endregion
|
|
4687
|
+
//#region src/editor/StyleSheet.tsx
|
|
4688
|
+
var SHEET_ROWS = 4;
|
|
4350
4689
|
var StyleSheet = ({ store }) => {
|
|
4351
4690
|
const rows = useStyleRows(store);
|
|
4352
4691
|
const hasSelection = useStore(store, (s) => s.selectedIds.size > 0);
|
|
4353
4692
|
const [expanded, setExpanded] = useState(false);
|
|
4354
4693
|
if (!rows || !hasSelection) return null;
|
|
4355
|
-
const visible = expanded ? rows : rows.slice(0,
|
|
4694
|
+
const visible = expanded ? rows : rows.slice(0, SHEET_ROWS);
|
|
4356
4695
|
return /* @__PURE__ */ jsxs("div", {
|
|
4357
4696
|
"data-style-sheet": true,
|
|
4358
4697
|
"data-whiteboard-chrome": true,
|
|
@@ -4360,7 +4699,7 @@ var StyleSheet = ({ store }) => {
|
|
|
4360
4699
|
children: [
|
|
4361
4700
|
/* @__PURE__ */ jsx("div", { className: grabber }),
|
|
4362
4701
|
visible,
|
|
4363
|
-
rows.length >
|
|
4702
|
+
rows.length > SHEET_ROWS && /* @__PURE__ */ jsx("button", {
|
|
4364
4703
|
"data-style-more": true,
|
|
4365
4704
|
className: "_14kbw0vm",
|
|
4366
4705
|
type: "button",
|