microboard-temp 0.6.2 → 0.6.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.
@@ -3,43 +3,25 @@ var __getProtoOf = Object.getPrototypeOf;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- function __accessProp(key) {
7
- return this[key];
8
- }
9
- var __toESMCache_node;
10
- var __toESMCache_esm;
11
6
  var __toESM = (mod, isNodeMode, target) => {
12
- var canCache = mod != null && typeof mod === "object";
13
- if (canCache) {
14
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
15
- var cached = cache.get(mod);
16
- if (cached)
17
- return cached;
18
- }
19
7
  target = mod != null ? __create(__getProtoOf(mod)) : {};
20
8
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
21
9
  for (let key of __getOwnPropNames(mod))
22
10
  if (!__hasOwnProp.call(to, key))
23
11
  __defProp(to, key, {
24
- get: __accessProp.bind(mod, key),
12
+ get: () => mod[key],
25
13
  enumerable: true
26
14
  });
27
- if (canCache)
28
- cache.set(mod, to);
29
15
  return to;
30
16
  };
31
17
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
32
- var __returnValue = (v) => v;
33
- function __exportSetter(name, newValue) {
34
- this[name] = __returnValue.bind(null, newValue);
35
- }
36
18
  var __export = (target, all) => {
37
19
  for (var name in all)
38
20
  __defProp(target, name, {
39
21
  get: all[name],
40
22
  enumerable: true,
41
23
  configurable: true,
42
- set: __exportSetter.bind(all, name)
24
+ set: (newValue) => all[name] = () => newValue
43
25
  });
44
26
  };
45
27
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -56,13 +38,13 @@ var require_extend = __commonJS((exports, module) => {
56
38
  var toStr = Object.prototype.toString;
57
39
  var defineProperty = Object.defineProperty;
58
40
  var gOPD = Object.getOwnPropertyDescriptor;
59
- var isArray = function isArray2(arr2) {
41
+ var isArray = function isArray(arr2) {
60
42
  if (typeof Array.isArray === "function") {
61
43
  return Array.isArray(arr2);
62
44
  }
63
45
  return toStr.call(arr2) === "[object Array]";
64
46
  };
65
- var isPlainObject2 = function isPlainObject3(obj) {
47
+ var isPlainObject2 = function isPlainObject(obj) {
66
48
  if (!obj || toStr.call(obj) !== "[object Object]") {
67
49
  return false;
68
50
  }
@@ -75,7 +57,7 @@ var require_extend = __commonJS((exports, module) => {
75
57
  for (key in obj) {}
76
58
  return typeof key === "undefined" || hasOwn.call(obj, key);
77
59
  };
78
- var setProperty = function setProperty2(target, options) {
60
+ var setProperty = function setProperty(target, options) {
79
61
  if (defineProperty && options.name === "__proto__") {
80
62
  defineProperty(target, options.name, {
81
63
  enumerable: true,
@@ -87,7 +69,7 @@ var require_extend = __commonJS((exports, module) => {
87
69
  target[options.name] = options.newValue;
88
70
  }
89
71
  };
90
- var getProperty = function getProperty2(obj, name) {
72
+ var getProperty = function getProperty(obj, name) {
91
73
  if (name === "__proto__") {
92
74
  if (!hasOwn.call(obj, name)) {
93
75
  return;
@@ -792,7 +774,7 @@ function safeRequestAnimationFrame(callback) {
792
774
  if (typeof requestAnimationFrame === "function") {
793
775
  return requestAnimationFrame(callback);
794
776
  } else {
795
- callback();
777
+ setTimeout(callback, 0);
796
778
  }
797
779
  }
798
780
 
@@ -1238,206 +1220,6 @@ class Mbr {
1238
1220
  }
1239
1221
  }
1240
1222
  }
1241
- // src/Items/Mbr/updateRects.ts
1242
- function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
1243
- const { selection, camera } = board;
1244
- const panel = ref.current;
1245
- const selectionMbr = mbr ?? selection.getMbr();
1246
- const selectionItems = selection.items;
1247
- const richTextSelection = selectionItems.getSingle() instanceof RichText ? selectionItems.list()[0] : undefined;
1248
- if (panel && selectionMbr) {
1249
- if (fit === "contextPanel") {
1250
- const panelRect = getContextPanelRect(selectionMbr, camera, panel, !!richTextSelection, horizontalOffset, verticalOffset);
1251
- return panelRect;
1252
- }
1253
- if (fit === "linkToBtn") {
1254
- if (!mbr) {
1255
- return null;
1256
- }
1257
- const panelRect = fitLinkToBtn(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
1258
- return panelRect;
1259
- }
1260
- if (fit === "comment") {
1261
- if (!mbr) {
1262
- return null;
1263
- }
1264
- const panelRect = fitComment(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
1265
- return panelRect;
1266
- }
1267
- if (fit === "threadPanel") {
1268
- if (!mbr) {
1269
- return null;
1270
- }
1271
- const panelRect = fitThreadPanel(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
1272
- return panelRect;
1273
- }
1274
- if (fit === "boardMenu") {
1275
- if (!mbr) {
1276
- return null;
1277
- }
1278
- const panelRect = fitBoardMenu(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
1279
- return panelRect;
1280
- }
1281
- if (fit === "hyperLink") {
1282
- if (!mbr) {
1283
- return null;
1284
- }
1285
- const panelRect = fitHyperLink(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), camera.window.getMbr(), verticalOffset);
1286
- return panelRect;
1287
- }
1288
- }
1289
- return null;
1290
- }
1291
- function getContextPanelRect(selectionMbr, camera, panel, toLeft, horizontalOffset, verticalOffset) {
1292
- const transformedMbr = selectionMbr.getTransformed(camera.getMatrix());
1293
- const windowMbr = camera.window.getMbr();
1294
- const panelRectFromDom = Mbr.fromDomRect(panel.getBoundingClientRect());
1295
- const panelRect = toLeft ? fitContextPanelToLeft(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset) : fitContextPanelToCenter(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset);
1296
- return panelRect;
1297
- }
1298
- function fitContextPanelToLeft(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
1299
- const panelHeight = panel.getHeight();
1300
- const panelWidth = panel.getWidth();
1301
- const newPanel = new Mbr;
1302
- const topSpace = selectionMbr.top - view.top;
1303
- const hasEnoughTopSpace = topSpace >= panelHeight + verticalOffset;
1304
- if (hasEnoughTopSpace) {
1305
- newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
1306
- if (newPanel.top < view.top) {
1307
- newPanel.top = view.top + verticalOffset;
1308
- }
1309
- } else {
1310
- const usePanelTop = panel.top > 1 && panel.top > selectionMbr.top + verticalOffset;
1311
- newPanel.top = usePanelTop ? panel.top : selectionMbr.bottom + verticalOffset;
1312
- const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
1313
- const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
1314
- if (isOverflowingBottom || isLargeOffsetForRichText) {
1315
- newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
1316
- }
1317
- }
1318
- newPanel.bottom = newPanel.top + panelHeight;
1319
- fitContextPanelInViewRect(newPanel, view, verticalOffset);
1320
- const itemMbr = selectionMbr.getMbr();
1321
- newPanel.left = itemMbr.left;
1322
- adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
1323
- return newPanel;
1324
- }
1325
- function fitContextPanelToCenter(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
1326
- const panelHeight = panel.getHeight();
1327
- const panelWidth = panel.getWidth();
1328
- const newPanel = new Mbr;
1329
- const topSpace = selectionMbr.top - view.top;
1330
- const bottomSpace = view.bottom - selectionMbr.bottom;
1331
- const shouldPlaceAbove = topSpace > bottomSpace - panelHeight;
1332
- if (shouldPlaceAbove) {
1333
- newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
1334
- if (newPanel.top < view.top) {
1335
- newPanel.top = view.top + verticalOffset;
1336
- }
1337
- } else {
1338
- newPanel.top = selectionMbr.bottom + verticalOffset;
1339
- const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
1340
- const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
1341
- if (isOverflowingBottom || isLargeOffsetForRichText) {
1342
- newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
1343
- }
1344
- }
1345
- newPanel.bottom = newPanel.top + panelHeight;
1346
- fitContextPanelInViewRect(newPanel, view, verticalOffset);
1347
- const itemCenter = selectionMbr.getCenter();
1348
- newPanel.left = itemCenter.x - panelWidth / 2;
1349
- adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
1350
- return newPanel;
1351
- }
1352
- function adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset) {
1353
- newPanel.right = newPanel.left + panelWidth;
1354
- if (newPanel.left < view.left + horizontalOffset) {
1355
- newPanel.left = view.left + horizontalOffset;
1356
- } else if (newPanel.right + horizontalOffset > view.right) {
1357
- newPanel.left = view.right - (panelWidth + horizontalOffset);
1358
- }
1359
- newPanel.right = newPanel.left + panelWidth;
1360
- }
1361
- function fitContextPanelInViewRect(panel, view, verticalOffset) {
1362
- const panelHeight = panel.getHeight();
1363
- if (panel.top <= view.top + verticalOffset) {
1364
- panel.top = view.top + 2 * verticalOffset;
1365
- panel.bottom = panel.top + panelHeight;
1366
- }
1367
- if (panel.bottom >= view.bottom - verticalOffset) {
1368
- panel.bottom = view.bottom - 2 * verticalOffset;
1369
- panel.top = panel.bottom - panelHeight;
1370
- }
1371
- }
1372
- function fitLinkToBtn(itemMbr, view, panel, verticalOffset = -2, horizontalOffset = -2) {
1373
- const panelHeight = panel.getHeight();
1374
- const newPanel = new Mbr;
1375
- newPanel.top = itemMbr.top - panelHeight - verticalOffset;
1376
- newPanel.top = newPanel.top + panelHeight;
1377
- newPanel.bottom = newPanel.top + panelHeight * 2;
1378
- const panelWidth = panel.getWidth();
1379
- newPanel.left = itemMbr.right - panelWidth + horizontalOffset;
1380
- return newPanel;
1381
- }
1382
- function fitHyperLink(linkMbr, panel, view, offset = 20) {
1383
- const panelHeight = panel.getHeight();
1384
- const newPanel = new Mbr;
1385
- newPanel.top = linkMbr.bottom;
1386
- newPanel.bottom = panelHeight + newPanel.top;
1387
- const panelWidth = panel.getWidth();
1388
- newPanel.left = linkMbr.left;
1389
- newPanel.right = newPanel.left + panelWidth;
1390
- return newPanel;
1391
- }
1392
- function fitComment(anchor, panel, verticalOffset = 0, horizontalOffset = 0) {
1393
- const panelHeight = panel.getHeight();
1394
- const newPanel = new Mbr;
1395
- newPanel.top = anchor.top - panelHeight - verticalOffset;
1396
- newPanel.bottom = newPanel.top + panelHeight;
1397
- const panelWidth = panel.getWidth();
1398
- newPanel.left = anchor.left - panelWidth / 2 - horizontalOffset;
1399
- newPanel.right = newPanel.left + panelWidth;
1400
- return newPanel;
1401
- }
1402
- function fitBoardMenu(anchor, view, panel, verticalOffset = 20, horizontalOffset = 20) {
1403
- const panelHeight = panel.getHeight();
1404
- const panelWidth = panel.getWidth();
1405
- const newPanel = new Mbr;
1406
- newPanel.top = anchor.top;
1407
- newPanel.bottom = newPanel.top + panelHeight;
1408
- if (newPanel.bottom > view.bottom - verticalOffset) {
1409
- newPanel.bottom = view.bottom - verticalOffset;
1410
- newPanel.top = newPanel.bottom - panelHeight;
1411
- }
1412
- newPanel.left = anchor.left;
1413
- newPanel.right = newPanel.left + panelWidth;
1414
- if (newPanel.right > view.right - horizontalOffset) {
1415
- newPanel.right = view.right - horizontalOffset;
1416
- newPanel.left = newPanel.right - panelWidth;
1417
- }
1418
- return newPanel;
1419
- }
1420
- function fitThreadPanel(anchor, view, panel, verticalOffset = 50, horizontalOffset = 50) {
1421
- const panelHeight = panel.getHeight();
1422
- const panelWidth = panel.getWidth();
1423
- const newPanel = new Mbr;
1424
- newPanel.top = anchor.top - panelHeight / 2;
1425
- if (newPanel.top < view.top + verticalOffset) {
1426
- newPanel.top = view.top + verticalOffset;
1427
- }
1428
- newPanel.bottom = newPanel.top + panelHeight;
1429
- if (newPanel.bottom > view.bottom - verticalOffset) {
1430
- newPanel.bottom = view.bottom - verticalOffset;
1431
- newPanel.top = newPanel.bottom - panelHeight;
1432
- }
1433
- newPanel.left = anchor.left;
1434
- newPanel.right = newPanel.left + panelWidth;
1435
- if (newPanel.right > view.right - horizontalOffset) {
1436
- newPanel.right = anchor.right;
1437
- newPanel.left = newPanel.right - panelWidth;
1438
- }
1439
- return newPanel;
1440
- }
1441
1223
  // src/Items/Line/Line.ts
1442
1224
  function getLinesRelationType(lineA, lineB) {
1443
1225
  let denominator = (lineB.end.y - lineB.start.y) * (lineA.end.x - lineA.start.x) - (lineB.end.x - lineB.start.x) * (lineA.end.y - lineA.start.y);
@@ -3360,6 +3142,232 @@ class Arc {
3360
3142
  return new Arc(this.center.copy(), this.radiusX, this.radiusY, this.startAngle, this.endAngle, this.clockwise);
3361
3143
  }
3362
3144
  }
3145
+ // src/SessionStorage.ts
3146
+ var _sessionStorage;
3147
+ if (typeof window !== "undefined" && window.sessionStorage) {
3148
+ _sessionStorage = window.sessionStorage;
3149
+ } else {
3150
+
3151
+ class NodeStoragePolyfill {
3152
+ _store = {};
3153
+ clear() {
3154
+ this._store = {};
3155
+ }
3156
+ getItem(key) {
3157
+ return Object.prototype.hasOwnProperty.call(this._store, key) ? this._store[key] : null;
3158
+ }
3159
+ key(index) {
3160
+ const keys = Object.keys(this._store);
3161
+ return keys[index] ?? null;
3162
+ }
3163
+ removeItem(key) {
3164
+ delete this._store[key];
3165
+ }
3166
+ setItem(key, value) {
3167
+ this._store[key] = value;
3168
+ }
3169
+ get length() {
3170
+ return Object.keys(this._store).length;
3171
+ }
3172
+ }
3173
+ _sessionStorage = new NodeStoragePolyfill;
3174
+ }
3175
+
3176
+ class SessionStorage {
3177
+ set(key, value) {
3178
+ const boardId = this.getBoardId() || "";
3179
+ _sessionStorage.setItem(boardId + "_" + key, JSON.stringify(value));
3180
+ }
3181
+ get(key) {
3182
+ const boardId = this.getBoardId() || "";
3183
+ const item = _sessionStorage.getItem(boardId + "_" + key);
3184
+ if (!item || item === "undefined") {
3185
+ return;
3186
+ }
3187
+ return JSON.parse(item);
3188
+ }
3189
+ remove(key) {
3190
+ const boardId = this.getBoardId() || "";
3191
+ _sessionStorage.removeItem(boardId + "_" + key);
3192
+ }
3193
+ setConnectorStrokeStyle(color) {
3194
+ this.set(`connectorStrokeStyle`, color);
3195
+ }
3196
+ getConnectorStrokeStyle() {
3197
+ return this.get("connectorStrokeStyle");
3198
+ }
3199
+ setConnectorLineWidth(width) {
3200
+ this.set(`connectorLineWidth`, width);
3201
+ }
3202
+ getConnectorLineWidth() {
3203
+ return this.get("connectorLineWidth");
3204
+ }
3205
+ setConnectorFillColor(color) {
3206
+ this.set(`connectorFillColor`, color);
3207
+ }
3208
+ getConnectorFillColor() {
3209
+ return this.get("connectorFillColor");
3210
+ }
3211
+ setConnectorPointer(type, edge) {
3212
+ this.set(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`, type);
3213
+ }
3214
+ getConnectorPointer(edge) {
3215
+ return this.get(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`);
3216
+ }
3217
+ setConnectorLineStyle(type) {
3218
+ this.set("connectorLineStyle", type);
3219
+ }
3220
+ getConnectorLineStyle() {
3221
+ return this.get("connectorLineStyle");
3222
+ }
3223
+ setShapeData(data) {
3224
+ this.set("lastShapeData", data);
3225
+ }
3226
+ getShapeData() {
3227
+ return this.get("lastShapeData");
3228
+ }
3229
+ setStickerData(data) {
3230
+ this.set("lastSticker", data);
3231
+ }
3232
+ getStickerData() {
3233
+ return this.get("lastSticker");
3234
+ }
3235
+ setShapeWidth(width) {
3236
+ this.set("shapeWidth", width);
3237
+ }
3238
+ getShapeWidth() {
3239
+ return this.get("shapeWidth");
3240
+ }
3241
+ setShapeHeight(height) {
3242
+ this.set("shapeHeight", height);
3243
+ }
3244
+ getShapeHeight() {
3245
+ return this.get("shapeHeight");
3246
+ }
3247
+ setImageDimensions(dimension) {
3248
+ this.set("imageDimensions", dimension);
3249
+ }
3250
+ getImageDimensions() {
3251
+ return this.get("imageDimensions");
3252
+ }
3253
+ setFontSize(itemType, size) {
3254
+ this.set(`fontSize_${itemType}`, size);
3255
+ }
3256
+ getFontSize(itemType) {
3257
+ return this.get(`fontSize_${itemType}`);
3258
+ }
3259
+ setFontStyles(itemType, styles) {
3260
+ this.set(`fontStyles_${itemType}`, styles);
3261
+ }
3262
+ getFontStyles(itemType) {
3263
+ return this.get(`fontStyles_${itemType}`);
3264
+ }
3265
+ setFontColor(itemType, color) {
3266
+ this.set(`fontColor_${itemType}`, color);
3267
+ }
3268
+ getFontColor(itemType) {
3269
+ return this.get(`fontColor_${itemType}`);
3270
+ }
3271
+ setFontHighlight(itemType, highlightColor) {
3272
+ this.set(`fontHighlightColor_${itemType}`, highlightColor);
3273
+ }
3274
+ getFontHighlight(itemType) {
3275
+ return this.get(`fontHighlightColor_${itemType}`);
3276
+ }
3277
+ setHorizontalAlignment(itemType, horizontalAlignment) {
3278
+ this.set(`fontHorizontalAlignment_${itemType}`, horizontalAlignment);
3279
+ }
3280
+ getHorizontalAlignment(itemType) {
3281
+ return this.get(`fontHorizontalAlignment_${itemType}`);
3282
+ }
3283
+ setVerticalAlignment(itemType, verticalAlignment) {
3284
+ this.set(`fontVerticalAlignment_${itemType}`, verticalAlignment);
3285
+ }
3286
+ getVerticalAlignment(itemType) {
3287
+ return this.get(`fontVerticalAlignment_${itemType}`);
3288
+ }
3289
+ setLastAIRequest(request) {
3290
+ _sessionStorage.setItem("lastAIRequest", request);
3291
+ }
3292
+ getLastAIRequest() {
3293
+ return _sessionStorage.getItem("lastAIRequest");
3294
+ }
3295
+ removeLastAIRequest() {
3296
+ _sessionStorage.removeItem("lastAIRequest");
3297
+ }
3298
+ clear() {
3299
+ _sessionStorage.clear();
3300
+ }
3301
+ getBoardId() {
3302
+ if (typeof window === "undefined") {
3303
+ return;
3304
+ }
3305
+ return window.location.href.split("/").pop()?.split("?")[0];
3306
+ }
3307
+ }
3308
+ var tempStorage = new SessionStorage;
3309
+
3310
+ // src/HTMLRender/HTMLRender.ts
3311
+ function getTranslationFromHTML(el) {
3312
+ const transform = el.style.transform;
3313
+ const translateMatch = transform.match(/translate\(([^)]+)\)/);
3314
+ const [translateX, translateY] = translateMatch ? translateMatch[1].split(",").map((value) => parseFloat(value)) : [0, 0];
3315
+ return [translateX, translateY];
3316
+ }
3317
+ function getScaleFromHTML(el) {
3318
+ const transform = el.style.transform;
3319
+ const scaleMatch = transform.match(/scale\(([^)]+)\)/);
3320
+ const [scaleX, scaleY] = scaleMatch ? scaleMatch[1].split(",").map((value) => parseFloat(value)) : [1, 1];
3321
+ return [scaleX, scaleY];
3322
+ }
3323
+ function translateElementBy(el, x, y) {
3324
+ const [exX, exY] = getTranslationFromHTML(el);
3325
+ const [newX, newY] = [exX + x, exY + y];
3326
+ const [scaleX, scaleY] = getScaleFromHTML(el);
3327
+ el.style.transform = `translate(${newX}px, ${newY}px) scale(${scaleX}, ${scaleY})`;
3328
+ return el;
3329
+ }
3330
+ function scaleElementBy(el, scaleX, scaleY) {
3331
+ const [currentScaleX, currentScaleY] = getScaleFromHTML(el);
3332
+ const [newScaleX, newScaleY] = [
3333
+ currentScaleX * scaleX,
3334
+ currentScaleY * scaleY
3335
+ ];
3336
+ const [translateX, translateY] = getTranslationFromHTML(el);
3337
+ el.style.transform = `translate(${translateX}px, ${translateY}px) scale(${newScaleX}, ${newScaleY})`;
3338
+ return el;
3339
+ }
3340
+ function resetElementScale(el) {
3341
+ const [x, y] = getTranslationFromHTML(el);
3342
+ el.style.transform = `translate(${x}px, ${y}px) scale(1, 1)`;
3343
+ return el;
3344
+ }
3345
+ function positionRelatively(toPosition, positionBy, padding = 0) {
3346
+ const [translateX, translateY] = getTranslationFromHTML(toPosition);
3347
+ const [frameX, frameY] = getTranslationFromHTML(positionBy);
3348
+ const [dx, dy] = [translateX - frameX, translateY - frameY];
3349
+ const verticalAlignment = toPosition.getAttribute("data-vertical-alignment");
3350
+ const horizontalAlignment = toPosition.getAttribute("data-vertical-alignment");
3351
+ let paddingX = padding;
3352
+ let paddingY = padding;
3353
+ if (verticalAlignment && verticalAlignment === "bottom") {
3354
+ paddingY = -padding;
3355
+ }
3356
+ if (horizontalAlignment && horizontalAlignment === "right") {
3357
+ paddingX = -padding;
3358
+ }
3359
+ const [scaleX, scaleY] = getScaleFromHTML(toPosition);
3360
+ toPosition.style.transform = `translate(${dx + paddingX}px, ${dy + paddingY}px) scale(${scaleX}, ${scaleY})`;
3361
+ return toPosition;
3362
+ }
3363
+ function positionAbsolutely(toPosition, positionBy) {
3364
+ const [translateX, translateY] = getTranslationFromHTML(toPosition);
3365
+ const [frameX, frameY] = getTranslationFromHTML(positionBy);
3366
+ const [dx, dy] = [translateX + frameX, translateY + frameY];
3367
+ const [scaleX, scaleY] = getScaleFromHTML(toPosition);
3368
+ toPosition.style.transform = `translate(${dx}px, ${dy}px) scale(${scaleX}, ${scaleY})`;
3369
+ return toPosition;
3370
+ }
3363
3371
  // src/api/BrowserDocumentFactory.ts
3364
3372
  class BrowserDocumentFactory {
3365
3373
  createElement(tagName) {
@@ -3538,6 +3546,152 @@ class MockPath2D {
3538
3546
  }
3539
3547
  }
3540
3548
 
3549
+ // src/Items/Transformation/Matrix.ts
3550
+ class Matrix2 {
3551
+ translateX;
3552
+ translateY;
3553
+ scaleX;
3554
+ scaleY;
3555
+ shearX;
3556
+ shearY;
3557
+ constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, shearX = 0, shearY = 0) {
3558
+ this.translateX = translateX;
3559
+ this.translateY = translateY;
3560
+ this.scaleX = scaleX;
3561
+ this.scaleY = scaleY;
3562
+ this.shearX = shearX;
3563
+ this.shearY = shearY;
3564
+ this.translateX = toFiniteNumber(translateX);
3565
+ this.translateY = toFiniteNumber(translateY);
3566
+ this.scaleX = toFiniteNumber(scaleX, 1);
3567
+ this.scaleY = toFiniteNumber(scaleY, 1);
3568
+ this.shearX = toFiniteNumber(shearX);
3569
+ this.shearY = toFiniteNumber(shearY);
3570
+ }
3571
+ translate(x, y) {
3572
+ this.translateX += x;
3573
+ this.translateY += y;
3574
+ }
3575
+ scale(x, y) {
3576
+ this.scaleX = this.scaleX * x;
3577
+ this.scaleY = this.scaleY * y;
3578
+ }
3579
+ multiplyByMatrix(matrix) {
3580
+ const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this;
3581
+ this.translateX = scaleX * matrix.translateX + shearX * matrix.translateY + translateX;
3582
+ this.translateY = shearY * matrix.translateX + scaleY * matrix.translateY + translateY;
3583
+ this.scaleX = scaleX * matrix.scaleX + shearX * matrix.shearY;
3584
+ this.scaleY = shearY * matrix.shearX + scaleY * matrix.scaleY;
3585
+ this.shearX = scaleX * matrix.shearX + shearX * matrix.scaleY;
3586
+ this.shearY = shearY * matrix.scaleX + scaleY * matrix.shearY;
3587
+ return this;
3588
+ }
3589
+ multiplyByMatrixies(matrixies) {
3590
+ for (const matrix of matrixies) {
3591
+ this.multiplyByMatrix(matrix);
3592
+ }
3593
+ return this;
3594
+ }
3595
+ multiply(value) {
3596
+ if (Array.isArray(value)) {
3597
+ this.multiplyByMatrixies(value);
3598
+ } else {
3599
+ this.multiplyByMatrix(value);
3600
+ }
3601
+ return this;
3602
+ }
3603
+ copy() {
3604
+ return new Matrix2(this.translateX, this.translateY, this.scaleX, this.scaleY, this.shearX, this.shearY);
3605
+ }
3606
+ invert() {
3607
+ const { scaleX, shearY, shearX, scaleY, translateX, translateY } = this;
3608
+ const denom = scaleX * scaleY - shearX * shearY;
3609
+ this.scaleX = scaleY / denom;
3610
+ this.shearY = shearY / -denom;
3611
+ this.shearX = shearX / -denom;
3612
+ this.scaleY = scaleX / denom;
3613
+ this.translateX = (scaleY * translateX - shearX * translateY) / -denom;
3614
+ this.translateY = (shearY * translateX - scaleX * translateY) / denom;
3615
+ }
3616
+ getInverse() {
3617
+ const inverse = this.copy();
3618
+ inverse.invert();
3619
+ return inverse;
3620
+ }
3621
+ rotateByRadian(radian) {
3622
+ const cosAngle = Math.cos(radian);
3623
+ const sinAngle = Math.sin(radian);
3624
+ const rotationMatrix = new Matrix2(0, 0, cosAngle, cosAngle, -sinAngle, sinAngle);
3625
+ return this.multiply(rotationMatrix);
3626
+ }
3627
+ rotateBy(degree) {
3628
+ const radian = degree * Math.PI / 180;
3629
+ this.rotateByRadian(radian);
3630
+ }
3631
+ rotateByObjectCenter(degree, size, scale) {
3632
+ const angle = degree * (Math.PI / 180);
3633
+ const width = size.width * scale.x;
3634
+ const height = size.height * scale.y;
3635
+ const centerX = width / 2;
3636
+ const centerY = height / 2;
3637
+ const x = centerX - (centerX * Math.cos(angle) - centerY * Math.sin(angle));
3638
+ const y = centerY - (centerX * Math.sin(angle) + centerY * Math.cos(angle));
3639
+ this.rotateBy(degree);
3640
+ this.translate(x, y);
3641
+ }
3642
+ rotateByRelativeTo(degree, x, y) {
3643
+ this.translateX += x;
3644
+ this.translateY += y;
3645
+ this.rotateBy(degree);
3646
+ this.translateX -= x;
3647
+ this.translateY -= y;
3648
+ }
3649
+ rotateByRadianRelativeTo(radian, x, y) {
3650
+ this.translateX += x;
3651
+ this.translateY += y;
3652
+ this.rotateByRadian(radian);
3653
+ this.translateX -= x;
3654
+ this.translateY -= y;
3655
+ }
3656
+ apply(point) {
3657
+ const { x, y } = point;
3658
+ point.x = this.scaleX * x + this.shearX * y + this.translateX;
3659
+ point.y = this.shearY * x + this.scaleY * y + this.translateY;
3660
+ }
3661
+ applyToContext(ctx) {
3662
+ ctx.transform(this.scaleX, this.shearY, this.shearX, this.scaleY, this.translateX, this.translateY);
3663
+ }
3664
+ getAffineMatrix() {
3665
+ return {
3666
+ a: this.scaleX,
3667
+ b: this.shearY,
3668
+ c: this.shearX,
3669
+ d: this.scaleY,
3670
+ e: this.translateX,
3671
+ f: this.translateY
3672
+ };
3673
+ }
3674
+ getCssString() {
3675
+ return `matrix(${this.scaleX},${this.shearY},${this.shearX},${this.scaleY},${this.translateX},${this.translateY})`;
3676
+ }
3677
+ identity() {
3678
+ return new Matrix2;
3679
+ }
3680
+ mirrorOrigin() {
3681
+ return new Matrix2(0, 0, -1, -1);
3682
+ }
3683
+ mirrorX() {
3684
+ return new Matrix2(0, 0, 1, -1);
3685
+ }
3686
+ mirrorY() {
3687
+ return new Matrix2(0, 0, -1, 1);
3688
+ }
3689
+ compare(matrix) {
3690
+ const { translateX, translateY, scaleX, scaleY, shearX, shearY } = matrix;
3691
+ return this.translateX === translateX && this.translateY === translateY && this.scaleX === scaleX && this.scaleY === scaleY && this.shearX === shearX && this.shearY === shearY;
3692
+ }
3693
+ }
3694
+
3541
3695
  // src/Subject.ts
3542
3696
  class Subject {
3543
3697
  observers = [];
@@ -6478,7 +6632,7 @@ var Browser = /* @__PURE__ */ function() {
6478
6632
  }
6479
6633
  _createClass(Browser2, [{
6480
6634
  key: "init",
6481
- value: function init2(services) {
6635
+ value: function init(services) {
6482
6636
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6483
6637
  var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6484
6638
  this.services = services || {
@@ -6533,7 +6687,7 @@ var Browser = /* @__PURE__ */ function() {
6533
6687
  }
6534
6688
  }, {
6535
6689
  key: "cacheUserLanguage",
6536
- value: function cacheUserLanguage4(lng, caches) {
6690
+ value: function cacheUserLanguage(lng, caches) {
6537
6691
  var _this2 = this;
6538
6692
  if (!caches)
6539
6693
  caches = this.options.caches;
@@ -6932,1044 +7086,237 @@ var conf = {
6932
7086
  };
6933
7087
  initDefaultI18N();
6934
7088
 
6935
- // src/Items/Transformation/Matrix.ts
6936
- class Matrix2 {
6937
- translateX;
6938
- translateY;
6939
- scaleX;
6940
- scaleY;
6941
- shearX;
6942
- shearY;
6943
- constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, shearX = 0, shearY = 0) {
6944
- this.translateX = translateX;
6945
- this.translateY = translateY;
6946
- this.scaleX = scaleX;
6947
- this.scaleY = scaleY;
6948
- this.shearX = shearX;
6949
- this.shearY = shearY;
6950
- this.translateX = toFiniteNumber(translateX);
6951
- this.translateY = toFiniteNumber(translateY);
6952
- this.scaleX = toFiniteNumber(scaleX, 1);
6953
- this.scaleY = toFiniteNumber(scaleY, 1);
6954
- this.shearX = toFiniteNumber(shearX);
6955
- this.shearY = toFiniteNumber(shearY);
7089
+ // src/Items/Path/Path.ts
7090
+ var LinePatterns = {
7091
+ solid: [],
7092
+ dot: [1, 2],
7093
+ dash: [10, 10],
7094
+ longDash: [20, 5],
7095
+ dotDash: [15, 3, 3, 3],
7096
+ tripleDotDash: [20, 3, 3, 3, 3, 3, 3, 3],
7097
+ looseDoubleDotDash: [12, 3, 3]
7098
+ };
7099
+ var LineStyles = [
7100
+ "solid",
7101
+ "dot",
7102
+ "dash",
7103
+ "longDash",
7104
+ "dotDash",
7105
+ "tripleDotDash",
7106
+ "looseDoubleDotDash"
7107
+ ];
7108
+ var scaledPatterns = {};
7109
+ function scalePatterns(scale) {
7110
+ function scaleLinePattern(pattern) {
7111
+ const scaledPattern = [];
7112
+ for (const number of LinePatterns[pattern]) {
7113
+ scaledPattern.push(number * scale);
7114
+ }
7115
+ return scaledPattern;
6956
7116
  }
6957
- translate(x, y) {
6958
- this.translateX += x;
6959
- this.translateY += y;
7117
+ const slp = scaleLinePattern;
7118
+ if (!scaledPatterns[scale]) {
7119
+ scaledPatterns[scale] = {
7120
+ solid: slp("solid"),
7121
+ dot: slp("dot"),
7122
+ dash: slp("dash"),
7123
+ longDash: slp("longDash"),
7124
+ dotDash: slp("dotDash"),
7125
+ tripleDotDash: slp("tripleDotDash"),
7126
+ looseDoubleDotDash: slp("looseDoubleDotDash")
7127
+ };
6960
7128
  }
6961
- scale(x, y) {
6962
- this.scaleX = this.scaleX * x;
6963
- this.scaleY = this.scaleY * y;
7129
+ return scaledPatterns[scale];
7130
+ }
7131
+ var borderWidths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
7132
+
7133
+ class Path {
7134
+ segments;
7135
+ isClosedValue;
7136
+ backgroundColor;
7137
+ borderColor;
7138
+ borderStyle;
7139
+ borderWidth;
7140
+ backgroundOpacity;
7141
+ borderOpacity;
7142
+ shadowColor;
7143
+ shadowBlur;
7144
+ shadowOffsetX;
7145
+ shadowOffsetY;
7146
+ paddingTop;
7147
+ paddingRight;
7148
+ paddingBottom;
7149
+ paddingLeft;
7150
+ path2d;
7151
+ x;
7152
+ y;
7153
+ width;
7154
+ height;
7155
+ maxDimension;
7156
+ linePattern;
7157
+ connectedItemType = "";
7158
+ constructor(segments = [], isClosedValue = false, backgroundColor = "none", borderColor = "black", borderStyle = "solid", borderWidth = 1, backgroundOpacity = 1, borderOpacity = 1, shadowColor = "transparent", shadowBlur = 0, shadowOffsetX = 0, shadowOffsetY = 0, paddingTop = 0, paddingRight = 0, paddingBottom = 0, paddingLeft = 0) {
7159
+ this.segments = segments;
7160
+ this.isClosedValue = isClosedValue;
7161
+ this.backgroundColor = backgroundColor;
7162
+ this.borderColor = borderColor;
7163
+ this.borderStyle = borderStyle;
7164
+ this.borderWidth = borderWidth;
7165
+ this.backgroundOpacity = backgroundOpacity;
7166
+ this.borderOpacity = borderOpacity;
7167
+ this.shadowColor = shadowColor;
7168
+ this.shadowBlur = shadowBlur;
7169
+ this.shadowOffsetX = shadowOffsetX;
7170
+ this.shadowOffsetY = shadowOffsetY;
7171
+ this.paddingTop = paddingTop;
7172
+ this.paddingRight = paddingRight;
7173
+ this.paddingBottom = paddingBottom;
7174
+ this.paddingLeft = paddingLeft;
7175
+ this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7176
+ const mbr = this.getMbr();
7177
+ this.x = mbr.left;
7178
+ this.y = mbr.top;
7179
+ this.width = this.getMbr().getWidth();
7180
+ this.height = this.getMbr().getHeight();
7181
+ this.maxDimension = Math.max(mbr.getWidth(), mbr.getHeight());
7182
+ this.path2d = new conf.path2DFactory;
7183
+ this.updateCache();
6964
7184
  }
6965
- multiplyByMatrix(matrix) {
6966
- const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this;
6967
- this.translateX = scaleX * matrix.translateX + shearX * matrix.translateY + translateX;
6968
- this.translateY = shearY * matrix.translateX + scaleY * matrix.translateY + translateY;
6969
- this.scaleX = scaleX * matrix.scaleX + shearX * matrix.shearY;
6970
- this.scaleY = shearY * matrix.shearX + scaleY * matrix.scaleY;
6971
- this.shearX = scaleX * matrix.shearX + shearX * matrix.scaleY;
6972
- this.shearY = shearY * matrix.scaleX + scaleY * matrix.shearY;
6973
- return this;
7185
+ getBackgroundColor() {
7186
+ return this.backgroundColor;
6974
7187
  }
6975
- multiplyByMatrixies(matrixies) {
6976
- for (const matrix of matrixies) {
6977
- this.multiplyByMatrix(matrix);
6978
- }
6979
- return this;
7188
+ getBorderColor() {
7189
+ return this.borderColor;
6980
7190
  }
6981
- multiply(value) {
6982
- if (Array.isArray(value)) {
6983
- this.multiplyByMatrixies(value);
6984
- } else {
6985
- this.multiplyByMatrix(value);
6986
- }
6987
- return this;
7191
+ getBorderStyle() {
7192
+ return this.borderStyle;
6988
7193
  }
6989
- copy() {
6990
- return new Matrix2(this.translateX, this.translateY, this.scaleX, this.scaleY, this.shearX, this.shearY);
7194
+ getBorderWidth() {
7195
+ return this.borderWidth;
6991
7196
  }
6992
- invert() {
6993
- const { scaleX, shearY, shearX, scaleY, translateX, translateY } = this;
6994
- const denom = scaleX * scaleY - shearX * shearY;
6995
- this.scaleX = scaleY / denom;
6996
- this.shearY = shearY / -denom;
6997
- this.shearX = shearX / -denom;
6998
- this.scaleY = scaleX / denom;
6999
- this.translateX = (scaleY * translateX - shearX * translateY) / -denom;
7000
- this.translateY = (shearY * translateX - scaleX * translateY) / denom;
7197
+ setBackgroundColor(color) {
7198
+ this.backgroundColor = color;
7001
7199
  }
7002
- getInverse() {
7003
- const inverse = this.copy();
7004
- inverse.invert();
7005
- return inverse;
7200
+ setBorderColor(color) {
7201
+ this.borderColor = color;
7006
7202
  }
7007
- rotateByRadian(radian) {
7008
- const cosAngle = Math.cos(radian);
7009
- const sinAngle = Math.sin(radian);
7010
- const rotationMatrix = new Matrix2(0, 0, cosAngle, cosAngle, -sinAngle, sinAngle);
7011
- return this.multiply(rotationMatrix);
7203
+ setBorderStyle(style) {
7204
+ this.borderStyle = style;
7205
+ this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7012
7206
  }
7013
- rotateBy(degree) {
7014
- const radian = degree * Math.PI / 180;
7015
- this.rotateByRadian(radian);
7207
+ setBorderWidth(width) {
7208
+ this.borderWidth = width;
7209
+ this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7016
7210
  }
7017
- rotateByObjectCenter(degree, size, scale) {
7018
- const angle = degree * (Math.PI / 180);
7019
- const width = size.width * scale.x;
7020
- const height = size.height * scale.y;
7021
- const centerX = width / 2;
7022
- const centerY = height / 2;
7023
- const x = centerX - (centerX * Math.cos(angle) - centerY * Math.sin(angle));
7024
- const y = centerY - (centerX * Math.sin(angle) + centerY * Math.cos(angle));
7025
- this.rotateBy(degree);
7026
- this.translate(x, y);
7211
+ getShadowColor() {
7212
+ return this.shadowColor;
7027
7213
  }
7028
- rotateByRelativeTo(degree, x, y) {
7029
- this.translateX += x;
7030
- this.translateY += y;
7031
- this.rotateBy(degree);
7032
- this.translateX -= x;
7033
- this.translateY -= y;
7214
+ setShadowColor(color) {
7215
+ this.shadowColor = color;
7034
7216
  }
7035
- rotateByRadianRelativeTo(radian, x, y) {
7036
- this.translateX += x;
7037
- this.translateY += y;
7038
- this.rotateByRadian(radian);
7039
- this.translateX -= x;
7040
- this.translateY -= y;
7217
+ getShadowBlur() {
7218
+ return this.shadowBlur;
7041
7219
  }
7042
- apply(point) {
7043
- const { x, y } = point;
7044
- point.x = this.scaleX * x + this.shearX * y + this.translateX;
7045
- point.y = this.shearY * x + this.scaleY * y + this.translateY;
7220
+ setShadowBlur(blur) {
7221
+ this.shadowBlur = blur;
7046
7222
  }
7047
- applyToContext(ctx) {
7048
- ctx.transform(this.scaleX, this.shearY, this.shearX, this.scaleY, this.translateX, this.translateY);
7223
+ getShadowOffsetX() {
7224
+ return this.shadowOffsetX;
7049
7225
  }
7050
- getAffineMatrix() {
7051
- return {
7052
- a: this.scaleX,
7053
- b: this.shearY,
7054
- c: this.shearX,
7055
- d: this.scaleY,
7056
- e: this.translateX,
7057
- f: this.translateY
7058
- };
7226
+ setShadowOffsetX(offsetX) {
7227
+ this.shadowOffsetX = offsetX;
7059
7228
  }
7060
- getCssString() {
7061
- return `matrix(${this.scaleX},${this.shearY},${this.shearX},${this.scaleY},${this.translateX},${this.translateY})`;
7229
+ getShadowOffsetY() {
7230
+ return this.shadowOffsetY;
7062
7231
  }
7063
- identity() {
7064
- return new Matrix2;
7232
+ setShadowOffsetY(offsetY) {
7233
+ this.shadowOffsetY = offsetY;
7065
7234
  }
7066
- mirrorOrigin() {
7067
- return new Matrix2(0, 0, -1, -1);
7235
+ getBackgroundOpacity() {
7236
+ return this.backgroundOpacity;
7068
7237
  }
7069
- mirrorX() {
7070
- return new Matrix2(0, 0, 1, -1);
7238
+ setBackgroundOpacity(opacity) {
7239
+ this.backgroundOpacity = opacity;
7071
7240
  }
7072
- mirrorY() {
7073
- return new Matrix2(0, 0, -1, 1);
7241
+ getBorderOpacity() {
7242
+ return this.borderOpacity;
7074
7243
  }
7075
- compare(matrix) {
7076
- const { translateX, translateY, scaleX, scaleY, shearX, shearY } = matrix;
7077
- return this.translateX === translateX && this.translateY === translateY && this.scaleX === scaleX && this.scaleY === scaleY && this.shearX === shearX && this.shearY === shearY;
7244
+ getWidth() {
7245
+ return this.width;
7078
7246
  }
7079
- }
7080
- // src/SubjectOperation.ts
7081
- class SubjectOperation {
7082
- observers = [];
7083
- subscribe(observer) {
7084
- const index = this.observers.indexOf(observer);
7085
- if (index === -1) {
7086
- this.observers.push(observer);
7247
+ getHeight() {
7248
+ return this.height;
7249
+ }
7250
+ setBorderOpacity(opacity) {
7251
+ this.borderOpacity = opacity;
7252
+ }
7253
+ updateCache() {
7254
+ const { left, top, right, bottom } = this.getMbr();
7255
+ this.x = left - this.paddingLeft;
7256
+ this.y = top - this.paddingTop;
7257
+ this.width = right - left + this.paddingLeft + this.paddingRight;
7258
+ this.height = bottom - top + this.paddingTop + this.paddingBottom;
7259
+ const path2d = new conf.path2DFactory;
7260
+ if (this.segments.length === 0) {
7261
+ return;
7262
+ }
7263
+ this.segments[0].moveToStart(path2d);
7264
+ for (const segment of this.segments) {
7265
+ segment.render(path2d);
7266
+ }
7267
+ if (this.isClosedValue) {
7268
+ path2d.closePath();
7087
7269
  }
7270
+ this.path2d = path2d;
7088
7271
  }
7089
- unsubscribe(observer) {
7090
- const index = this.observers.indexOf(observer);
7091
- if (index !== -1) {
7092
- this.observers.splice(index, 1);
7272
+ getIntersectionPoints(segment) {
7273
+ let intersections = [];
7274
+ for (const item of this.segments) {
7275
+ intersections = intersections.concat(item.getIntersectionPoints(segment));
7093
7276
  }
7277
+ return intersections;
7094
7278
  }
7095
- publish(subject, op) {
7096
- for (const observer of this.observers) {
7097
- observer(subject, op);
7279
+ getNearestEdgePointTo(point) {
7280
+ return this.getNearestEdgeAndPointTo(point).point;
7281
+ }
7282
+ getNearestEdgeAndPointTo(point) {
7283
+ const candidates = [];
7284
+ for (let index = 0;index < this.segments.length; index++) {
7285
+ const segment = this.segments[index];
7286
+ const pointOnSegment = segment.getNearestEdgePointTo(point);
7287
+ candidates.push({
7288
+ index,
7289
+ segment,
7290
+ point: pointOnSegment,
7291
+ distance: point.getDistance(pointOnSegment)
7292
+ });
7293
+ }
7294
+ let nearest = candidates[0];
7295
+ for (const candidate of candidates) {
7296
+ if (candidate.distance < nearest.distance) {
7297
+ nearest = candidate;
7298
+ }
7098
7299
  }
7300
+ return nearest;
7099
7301
  }
7100
- }
7101
-
7102
- // src/Items/ItemsCommandUtils.ts
7103
- function mapItemsByOperation(item, getCallback) {
7104
- const items = Array.isArray(item) ? item : [item];
7105
- return items.map((item2) => {
7106
- const operation = getCallback(item2);
7107
- return { item: item2, operation };
7108
- });
7109
- }
7110
-
7111
- // src/Items/Transformation/TransformationCommand.ts
7112
- class TransformationCommand {
7113
- transformation;
7114
- operation;
7115
- reverse;
7116
- constructor(transformation, operation) {
7117
- this.transformation = transformation;
7118
- this.operation = operation;
7119
- this.reverse = this.getReverse();
7302
+ getDistanceToPoint(point) {
7303
+ const nearest = this.getNearestEdgePointTo(point);
7304
+ return point.getDistance(nearest);
7120
7305
  }
7121
- merge(op) {
7122
- this.operation = op;
7123
- this.reverse = this.getReverse();
7124
- return this;
7306
+ isUnderPoint(point) {
7307
+ return this.isEnclosedOrCrossedBy(new Mbr(point.x, point.y, point.x, point.y));
7125
7308
  }
7126
- apply() {
7127
- for (const transformation of this.transformation) {
7128
- transformation.apply(this.operation);
7309
+ isPointOverEdges(point, tolerance = 5) {
7310
+ for (const segment of this.segments) {
7311
+ const distance = segment.getDistance(point);
7312
+ if (distance <= tolerance) {
7313
+ return true;
7314
+ }
7129
7315
  }
7316
+ return false;
7130
7317
  }
7131
- revert() {
7132
- this.reverse.forEach(({ item, operation }) => {
7133
- item.apply(operation);
7134
- });
7135
- }
7136
- getReverse() {
7137
- const op = this.operation;
7138
- switch (this.operation.method) {
7139
- case "applyMatrix": {
7140
- const op2 = this.operation;
7141
- return this.transformation.map((t3) => {
7142
- const itemOp = op2.items.find((i) => i.id === t3.getId());
7143
- if (!itemOp)
7144
- return { item: t3, operation: op2 };
7145
- return {
7146
- item: t3,
7147
- operation: {
7148
- class: "Transformation",
7149
- method: "applyMatrix",
7150
- items: [{
7151
- id: t3.getId(),
7152
- matrix: {
7153
- translateX: -itemOp.matrix.translateX,
7154
- translateY: -itemOp.matrix.translateY,
7155
- scaleX: 1 / itemOp.matrix.scaleX,
7156
- scaleY: 1 / itemOp.matrix.scaleY,
7157
- shearX: 0,
7158
- shearY: 0
7159
- }
7160
- }]
7161
- }
7162
- };
7163
- });
7164
- }
7165
- case "translateTo":
7166
- return mapItemsByOperation(this.transformation, (transformation) => {
7167
- return {
7168
- ...this.operation,
7169
- x: transformation.getTranslation().x,
7170
- y: transformation.getTranslation().y
7171
- };
7172
- });
7173
- case "translateBy": {
7174
- const op2 = this.operation;
7175
- return mapItemsByOperation(this.transformation, () => {
7176
- return {
7177
- ...this.operation,
7178
- x: -op2.x,
7179
- y: -op2.y
7180
- };
7181
- });
7182
- }
7183
- case "scaleTo":
7184
- case "scaleToRelativeTo": {
7185
- return mapItemsByOperation(this.transformation, (transformation) => {
7186
- return {
7187
- ...op,
7188
- x: transformation.getScale().x,
7189
- y: transformation.getScale().y
7190
- };
7191
- });
7192
- }
7193
- case "scaleBy":
7194
- case "scaleByRelativeTo": {
7195
- const op2 = this.operation;
7196
- return mapItemsByOperation(this.transformation, () => {
7197
- return {
7198
- ...op2,
7199
- x: 1 / op2.x,
7200
- y: 1 / op2.y
7201
- };
7202
- });
7203
- }
7204
- case "scaleByTranslateBy": {
7205
- const op2 = this.operation;
7206
- const scaleTransformation = mapItemsByOperation(this.transformation, () => {
7207
- const scaleX = 1 / op2.scale.x;
7208
- const scaleY = 1 / op2.scale.y;
7209
- const translateX = -op2.translate.x;
7210
- const translateY = -op2.translate.y;
7211
- return {
7212
- ...op2,
7213
- scale: {
7214
- x: scaleX,
7215
- y: scaleY
7216
- },
7217
- translate: {
7218
- x: translateX,
7219
- y: translateY
7220
- }
7221
- };
7222
- });
7223
- return scaleTransformation;
7224
- }
7225
- case "rotateTo":
7226
- return mapItemsByOperation(this.transformation, (transformation) => {
7227
- return {
7228
- ...this.operation,
7229
- degree: transformation.getRotation()
7230
- };
7231
- });
7232
- case "rotateBy": {
7233
- const op2 = this.operation;
7234
- return mapItemsByOperation(this.transformation, () => {
7235
- return {
7236
- ...this.operation,
7237
- degree: -op2.degree
7238
- };
7239
- });
7240
- }
7241
- case "transformMany": {
7242
- const { operation, transformation } = this;
7243
- return transformation.map((currTrans) => {
7244
- const op2 = operation.items[currTrans.getId()];
7245
- const m = op2.method === "applyMatrix" ? op2.matrix : op2.method === "scaleByTranslateBy" ? { translateX: -op2.translate.x, translateY: -op2.translate.y, scaleX: 1 / op2.scale.x, scaleY: 1 / op2.scale.y, shearX: 0, shearY: 0 } : { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 };
7246
- return {
7247
- item: currTrans,
7248
- operation: {
7249
- class: "Transformation",
7250
- method: "applyMatrix",
7251
- items: [{
7252
- id: currTrans.getId(),
7253
- matrix: {
7254
- translateX: op2.method === "applyMatrix" ? -m.translateX : m.translateX,
7255
- translateY: op2.method === "applyMatrix" ? -m.translateY : m.translateY,
7256
- scaleX: op2.method === "applyMatrix" ? 1 / m.scaleX : m.scaleX,
7257
- scaleY: op2.method === "applyMatrix" ? 1 / m.scaleY : m.scaleY,
7258
- shearX: 0,
7259
- shearY: 0
7260
- }
7261
- }]
7262
- }
7263
- };
7264
- });
7265
- }
7266
- case "locked": {
7267
- const op2 = this.operation;
7268
- return mapItemsByOperation(this.transformation, () => {
7269
- return {
7270
- ...op2,
7271
- item: [...op2.item],
7272
- method: "unlocked",
7273
- locked: false
7274
- };
7275
- });
7276
- }
7277
- case "unlocked": {
7278
- const op2 = this.operation;
7279
- return mapItemsByOperation(this.transformation, () => {
7280
- return {
7281
- ...op2,
7282
- item: [...op2.item],
7283
- method: "locked",
7284
- locked: true
7285
- };
7286
- });
7287
- }
7288
- default:
7289
- return [
7290
- { item: this.transformation[0], operation: this.operation }
7291
- ];
7292
- }
7293
- }
7294
- }
7295
-
7296
- // src/Items/Transformation/TransformationData.ts
7297
- class DefaultTransformationData {
7298
- translateX;
7299
- translateY;
7300
- scaleX;
7301
- scaleY;
7302
- rotate;
7303
- isLocked;
7304
- constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, rotate = 0, isLocked = false) {
7305
- this.translateX = translateX;
7306
- this.translateY = translateY;
7307
- this.scaleX = scaleX;
7308
- this.scaleY = scaleY;
7309
- this.rotate = rotate;
7310
- this.isLocked = isLocked;
7311
- }
7312
- }
7313
-
7314
- // src/Items/Transformation/Transformation.ts
7315
- var defaultData = new DefaultTransformationData;
7316
-
7317
- class Transformation {
7318
- id;
7319
- events;
7320
- subject = new SubjectOperation;
7321
- _matrix = new Matrix2;
7322
- previous = new Matrix2;
7323
- rotate = defaultData.rotate;
7324
- isLocked = false;
7325
- constructor(id = "", events) {
7326
- this.id = id;
7327
- this.events = events;
7328
- }
7329
- getMatrixData() {
7330
- const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this._matrix;
7331
- return { translateX, translateY, scaleX, scaleY, shearX, shearY };
7332
- }
7333
- toMatrix() {
7334
- return this._matrix.copy();
7335
- }
7336
- applyToContext(ctx) {
7337
- this._matrix.applyToContext(ctx);
7338
- }
7339
- getTranslation() {
7340
- return { x: this._matrix.translateX, y: this._matrix.translateY };
7341
- }
7342
- getScale() {
7343
- return { x: this._matrix.scaleX, y: this._matrix.scaleY };
7344
- }
7345
- getRotation() {
7346
- return this.rotate;
7347
- }
7348
- setLocal(xOrData, y, scaleX, scaleY) {
7349
- this.previous = this._matrix.copy();
7350
- if (typeof xOrData === "object") {
7351
- if (xOrData.translateX !== undefined)
7352
- this._matrix.translateX = xOrData.translateX;
7353
- if (xOrData.translateY !== undefined)
7354
- this._matrix.translateY = xOrData.translateY;
7355
- if (xOrData.scaleX !== undefined)
7356
- this._matrix.scaleX = xOrData.scaleX;
7357
- if (xOrData.scaleY !== undefined)
7358
- this._matrix.scaleY = xOrData.scaleY;
7359
- } else {
7360
- this._matrix.translateX = xOrData;
7361
- this._matrix.translateY = y;
7362
- if (scaleX !== undefined)
7363
- this._matrix.scaleX = scaleX;
7364
- if (scaleY !== undefined)
7365
- this._matrix.scaleY = scaleY;
7366
- }
7367
- this.subject.publish(this, {
7368
- class: "Transformation",
7369
- method: "applyMatrix",
7370
- items: [{ id: this.id, matrix: this.getMatrixData() }]
7371
- });
7372
- }
7373
- serialize() {
7374
- return {
7375
- translateX: this._matrix.translateX,
7376
- translateY: this._matrix.translateY,
7377
- scaleX: this._matrix.scaleX,
7378
- scaleY: this._matrix.scaleY,
7379
- rotate: this.rotate,
7380
- isLocked: this.isLocked
7381
- };
7382
- }
7383
- deserialize(data) {
7384
- this.previous = this._matrix.copy();
7385
- if (data.translateX) {
7386
- this._matrix.translateX = data.translateX;
7387
- }
7388
- if (data.translateY) {
7389
- this._matrix.translateY = data.translateY;
7390
- }
7391
- if (data.scaleX) {
7392
- this._matrix.scaleX = data.scaleX;
7393
- }
7394
- if (data.scaleY) {
7395
- this._matrix.scaleY = data.scaleY;
7396
- }
7397
- if (data.isLocked) {
7398
- this.isLocked = data.isLocked;
7399
- }
7400
- if (data.rotate) {
7401
- this.rotate = data.rotate;
7402
- }
7403
- this.subject.publish(this, {
7404
- class: "Transformation",
7405
- method: "deserialize",
7406
- item: [this.id],
7407
- data
7408
- });
7409
- return this;
7410
- }
7411
- copy(id) {
7412
- const { translateX, translateY, scaleX, scaleY } = this._matrix;
7413
- const { rotate } = this;
7414
- return new Transformation(id || "", this.events).deserialize({
7415
- translateX,
7416
- translateY,
7417
- scaleX,
7418
- scaleY,
7419
- rotate,
7420
- isLocked: false
7421
- });
7422
- }
7423
- getInverse() {
7424
- const copy2 = this.copy();
7425
- copy2._matrix.invert();
7426
- return copy2;
7427
- }
7428
- getId() {
7429
- return this.id;
7430
- }
7431
- setId(id) {
7432
- this.id = id;
7433
- }
7434
- emit(operation) {
7435
- if (this.events) {
7436
- const command = new TransformationCommand([this], operation);
7437
- command.apply();
7438
- this.events.emit(operation, command);
7439
- } else {
7440
- this.apply(operation);
7441
- }
7442
- }
7443
- emitMatrix(matrix, timeStamp) {
7444
- this.emit({
7445
- class: "Transformation",
7446
- method: "applyMatrix",
7447
- items: [{ id: this.id, matrix }],
7448
- timeStamp
7449
- });
7450
- }
7451
- translateTo(x, y, timeStamp) {
7452
- if (!this.id) {}
7453
- this.emitMatrix({
7454
- translateX: x - this._matrix.translateX,
7455
- translateY: y - this._matrix.translateY,
7456
- scaleX: 1,
7457
- scaleY: 1,
7458
- shearX: 0,
7459
- shearY: 0
7460
- }, timeStamp);
7461
- }
7462
- translateBy(x, y, timeStamp) {
7463
- if (!this.id) {}
7464
- if (x === 0 && y === 0) {
7465
- return;
7466
- }
7467
- this.emitMatrix({
7468
- translateX: x,
7469
- translateY: y,
7470
- scaleX: 1,
7471
- scaleY: 1,
7472
- shearX: 0,
7473
- shearY: 0
7474
- }, timeStamp);
7475
- }
7476
- scaleTo(x, y, timeStamp) {
7477
- this.emitMatrix({
7478
- translateX: 0,
7479
- translateY: 0,
7480
- scaleX: x / this._matrix.scaleX,
7481
- scaleY: y / this._matrix.scaleY,
7482
- shearX: 0,
7483
- shearY: 0
7484
- }, timeStamp);
7485
- }
7486
- scaleBy(x, y, timeStamp) {
7487
- if (x === 0 && y === 0) {
7488
- return;
7489
- }
7490
- this.emitMatrix({
7491
- translateX: 0,
7492
- translateY: 0,
7493
- scaleX: x,
7494
- scaleY: y,
7495
- shearX: 0,
7496
- shearY: 0
7497
- }, timeStamp);
7498
- }
7499
- scaleByTranslateBy(scale, translate, timeStamp) {
7500
- if (scale.x === 0 && scale.y === 0 && translate.x === 0 && translate.y === 0) {
7501
- return;
7502
- }
7503
- this.emitMatrix({
7504
- translateX: translate.x,
7505
- translateY: translate.y,
7506
- scaleX: scale.x,
7507
- scaleY: scale.y,
7508
- shearX: 0,
7509
- shearY: 0
7510
- }, timeStamp);
7511
- }
7512
- rotateTo(degree, timeStamp) {
7513
- this.emit({
7514
- class: "Transformation",
7515
- method: "rotateTo",
7516
- item: [this.id],
7517
- degree,
7518
- timeStamp
7519
- });
7520
- }
7521
- rotateBy(degree, timeStamp) {
7522
- this.emit({
7523
- class: "Transformation",
7524
- method: "rotateBy",
7525
- item: [this.id],
7526
- degree,
7527
- timeStamp
7528
- });
7529
- }
7530
- scaleToRelativeTo(x, y, _point, timeStamp) {
7531
- this.emitMatrix({
7532
- translateX: 0,
7533
- translateY: 0,
7534
- scaleX: x / this._matrix.scaleX,
7535
- scaleY: y / this._matrix.scaleY,
7536
- shearX: 0,
7537
- shearY: 0
7538
- }, timeStamp);
7539
- }
7540
- scaleByRelativeTo(x, y, point, timeStamp) {
7541
- const { scaleX: sx0, scaleY: sy0, translateX: tx0, translateY: ty0 } = this._matrix;
7542
- const newSx = sx0 * x;
7543
- const newSy = sy0 * y;
7544
- this.emitMatrix({
7545
- translateX: -point.x * newSx + point.x - tx0,
7546
- translateY: -point.y * newSy + point.y - ty0,
7547
- scaleX: x,
7548
- scaleY: y,
7549
- shearX: 0,
7550
- shearY: 0
7551
- }, timeStamp);
7552
- }
7553
- setIsLocked(isLocked, timestamp) {
7554
- if (isLocked) {
7555
- this.emit({
7556
- class: "Transformation",
7557
- method: "locked",
7558
- item: [this.id],
7559
- locked: true,
7560
- timestamp
7561
- });
7562
- } else {
7563
- this.emit({
7564
- class: "Transformation",
7565
- method: "unlocked",
7566
- item: [this.id],
7567
- locked: false,
7568
- timestamp
7569
- });
7570
- }
7571
- }
7572
- apply(op) {
7573
- this.previous = this._matrix.copy();
7574
- switch (op.method) {
7575
- case "applyMatrix": {
7576
- const itemOp = op.items.find((i) => i.id === this.id);
7577
- if (itemOp) {
7578
- this._matrix.scale(itemOp.matrix.scaleX, itemOp.matrix.scaleY);
7579
- this._matrix.translate(itemOp.matrix.translateX, itemOp.matrix.translateY);
7580
- }
7581
- break;
7582
- }
7583
- case "translateTo":
7584
- this.applyTranslateTo(op.x, op.y);
7585
- break;
7586
- case "translateBy":
7587
- this.applyTranslateBy(op.x, op.y);
7588
- break;
7589
- case "scaleTo":
7590
- this.applyScaleTo(op.x, op.y);
7591
- break;
7592
- case "scaleBy":
7593
- this.applyScaleBy(op.x, op.y);
7594
- break;
7595
- case "scaleToRelativeTo":
7596
- this.applyScaleToRelativeTo(op.x, op.y, op.point);
7597
- break;
7598
- case "scaleByRelativeTo":
7599
- this.applyScaleByRelativeTo(op.x, op.y, op.point);
7600
- break;
7601
- case "scaleByTranslateBy":
7602
- this.applyScaleByTranslateBy(op.scale, op.translate);
7603
- break;
7604
- case "rotateTo":
7605
- this.applyRotateTo(op.degree);
7606
- break;
7607
- case "rotateBy":
7608
- this.applyRotateBy(op.degree);
7609
- break;
7610
- case "transformMany":
7611
- this.applyTransformMany(op.items[this.id]);
7612
- break;
7613
- case "locked":
7614
- this.applyLocked(op.locked);
7615
- break;
7616
- case "unlocked":
7617
- this.applyUnlocked(op.locked);
7618
- break;
7619
- default:
7620
- return;
7621
- }
7622
- this.subject.publish(this, op);
7623
- }
7624
- applyTranslateTo(x, y) {
7625
- this._matrix.translateX = x;
7626
- this._matrix.translateY = y;
7627
- }
7628
- applyTranslateBy(x, y) {
7629
- this._matrix.translate(x, y);
7630
- }
7631
- applyScaleTo(x, y) {
7632
- this._matrix.scaleX = x;
7633
- this._matrix.scaleY = y;
7634
- }
7635
- applyScaleBy(x, y) {
7636
- this._matrix.scale(x, y);
7637
- }
7638
- applyScaleByTranslateBy(scale, translate) {
7639
- this._matrix.scale(scale.x, scale.y);
7640
- this._matrix.translate(translate.x, translate.y);
7641
- }
7642
- applyTransformMany(op) {
7643
- if (op.method === "applyMatrix") {
7644
- this._matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
7645
- this._matrix.translate(op.matrix.translateX, op.matrix.translateY);
7646
- } else if (op.method === "scaleByTranslateBy") {
7647
- this.applyScaleByTranslateBy(op.scale, op.translate);
7648
- } else if (op.method === "scaleBy") {
7649
- this.applyScaleBy(op.x, op.y);
7650
- } else if (op.method === "translateBy") {
7651
- this.applyTranslateBy(op.x, op.y);
7652
- } else if (op.method === "translateTo") {
7653
- this.applyTranslateTo(op.x, op.y);
7654
- }
7655
- }
7656
- applyScaleByRelativeTo(x, y, point) {
7657
- const scaleX = this._matrix.scaleX * x;
7658
- const scaleY = this._matrix.scaleY * y;
7659
- this._matrix.translateX = -point.x * scaleX + point.x;
7660
- this._matrix.translateY = -point.y * scaleY + point.y;
7661
- this._matrix.scaleX = scaleX;
7662
- this._matrix.scaleY = scaleY;
7663
- }
7664
- applyScaleToRelativeTo(x, y, point) {
7665
- this.applyTranslateBy(-point.x, -point.y);
7666
- this.applyScaleTo(x, y);
7667
- this.applyTranslateBy(point.x, point.y);
7668
- }
7669
- applyRotateTo(degree) {
7670
- if (degree > 0) {
7671
- while (degree > 360) {
7672
- degree -= 360;
7673
- }
7674
- if (degree === 360) {
7675
- degree = 0;
7676
- }
7677
- } else {
7678
- while (degree < -360) {
7679
- degree += 360;
7680
- }
7681
- if (degree === -360) {
7682
- degree = 0;
7683
- }
7684
- }
7685
- this.rotate = degree;
7686
- }
7687
- applyRotateBy(degree) {
7688
- this.applyRotateTo(this.rotate + degree);
7689
- }
7690
- applyLocked(locked) {
7691
- this.isLocked = locked;
7692
- }
7693
- applyUnlocked(locked) {
7694
- this.isLocked = locked;
7695
- }
7696
- }
7697
- // src/Items/DrawingContext.ts
7698
- class DrawingContext {
7699
- camera;
7700
- ctx;
7701
- cursorCtx;
7702
- matrix;
7703
- isBorderInvisible = false;
7704
- shapeVisibilityTreshold = 3;
7705
- rectangleVisibilyTreshold = 2;
7706
- constructor(camera, ctx, cursorCtx, matrix = new Matrix2) {
7707
- this.camera = camera;
7708
- this.ctx = ctx;
7709
- this.cursorCtx = cursorCtx;
7710
- this.matrix = matrix;
7711
- this.setCamera(camera);
7712
- }
7713
- dpi() {
7714
- return conf.getDPI();
7715
- }
7716
- setCamera(camera) {
7717
- this.camera = camera;
7718
- this.matrix = camera.getMatrix();
7719
- const scale = this.matrix.scaleX;
7720
- this.isBorderInvisible = 4 * scale < 0.1;
7721
- }
7722
- clear() {
7723
- this.ctx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
7724
- this.ctx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
7725
- this.matrix.applyToContext(this.ctx);
7726
- }
7727
- clearCursor() {
7728
- if (!this.cursorCtx) {
7729
- return;
7730
- }
7731
- this.cursorCtx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
7732
- this.cursorCtx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
7733
- this.matrix.applyToContext(this.cursorCtx);
7734
- }
7735
- applyChanges() {
7736
- this.matrix.applyToContext(this.ctx);
7737
- }
7738
- getCameraScale() {
7739
- return this.camera.getScale();
7740
- }
7741
- }
7742
- // src/Items/Path/Path.ts
7743
- var LinePatterns = {
7744
- solid: [],
7745
- dot: [1, 2],
7746
- dash: [10, 10],
7747
- longDash: [20, 5],
7748
- dotDash: [15, 3, 3, 3],
7749
- tripleDotDash: [20, 3, 3, 3, 3, 3, 3, 3],
7750
- looseDoubleDotDash: [12, 3, 3]
7751
- };
7752
- var LineStyles = [
7753
- "solid",
7754
- "dot",
7755
- "dash",
7756
- "longDash",
7757
- "dotDash",
7758
- "tripleDotDash",
7759
- "looseDoubleDotDash"
7760
- ];
7761
- var scaledPatterns = {};
7762
- function scalePatterns(scale) {
7763
- function scaleLinePattern(pattern) {
7764
- const scaledPattern = [];
7765
- for (const number of LinePatterns[pattern]) {
7766
- scaledPattern.push(number * scale);
7767
- }
7768
- return scaledPattern;
7769
- }
7770
- const slp = scaleLinePattern;
7771
- if (!scaledPatterns[scale]) {
7772
- scaledPatterns[scale] = {
7773
- solid: slp("solid"),
7774
- dot: slp("dot"),
7775
- dash: slp("dash"),
7776
- longDash: slp("longDash"),
7777
- dotDash: slp("dotDash"),
7778
- tripleDotDash: slp("tripleDotDash"),
7779
- looseDoubleDotDash: slp("looseDoubleDotDash")
7780
- };
7781
- }
7782
- return scaledPatterns[scale];
7783
- }
7784
- var borderWidths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
7785
-
7786
- class Path {
7787
- segments;
7788
- isClosedValue;
7789
- backgroundColor;
7790
- borderColor;
7791
- borderStyle;
7792
- borderWidth;
7793
- backgroundOpacity;
7794
- borderOpacity;
7795
- shadowColor;
7796
- shadowBlur;
7797
- shadowOffsetX;
7798
- shadowOffsetY;
7799
- paddingTop;
7800
- paddingRight;
7801
- paddingBottom;
7802
- paddingLeft;
7803
- path2d;
7804
- x;
7805
- y;
7806
- width;
7807
- height;
7808
- maxDimension;
7809
- linePattern;
7810
- connectedItemType = "";
7811
- constructor(segments = [], isClosedValue = false, backgroundColor = "none", borderColor = "black", borderStyle = "solid", borderWidth = 1, backgroundOpacity = 1, borderOpacity = 1, shadowColor = "transparent", shadowBlur = 0, shadowOffsetX = 0, shadowOffsetY = 0, paddingTop = 0, paddingRight = 0, paddingBottom = 0, paddingLeft = 0) {
7812
- this.segments = segments;
7813
- this.isClosedValue = isClosedValue;
7814
- this.backgroundColor = backgroundColor;
7815
- this.borderColor = borderColor;
7816
- this.borderStyle = borderStyle;
7817
- this.borderWidth = borderWidth;
7818
- this.backgroundOpacity = backgroundOpacity;
7819
- this.borderOpacity = borderOpacity;
7820
- this.shadowColor = shadowColor;
7821
- this.shadowBlur = shadowBlur;
7822
- this.shadowOffsetX = shadowOffsetX;
7823
- this.shadowOffsetY = shadowOffsetY;
7824
- this.paddingTop = paddingTop;
7825
- this.paddingRight = paddingRight;
7826
- this.paddingBottom = paddingBottom;
7827
- this.paddingLeft = paddingLeft;
7828
- this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7829
- const mbr = this.getMbr();
7830
- this.x = mbr.left;
7831
- this.y = mbr.top;
7832
- this.width = this.getMbr().getWidth();
7833
- this.height = this.getMbr().getHeight();
7834
- this.maxDimension = Math.max(mbr.getWidth(), mbr.getHeight());
7835
- this.path2d = new conf.path2DFactory;
7836
- this.updateCache();
7837
- }
7838
- getBackgroundColor() {
7839
- return this.backgroundColor;
7840
- }
7841
- getBorderColor() {
7842
- return this.borderColor;
7843
- }
7844
- getBorderStyle() {
7845
- return this.borderStyle;
7846
- }
7847
- getBorderWidth() {
7848
- return this.borderWidth;
7849
- }
7850
- setBackgroundColor(color) {
7851
- this.backgroundColor = color;
7852
- }
7853
- setBorderColor(color) {
7854
- this.borderColor = color;
7855
- }
7856
- setBorderStyle(style) {
7857
- this.borderStyle = style;
7858
- this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7859
- }
7860
- setBorderWidth(width) {
7861
- this.borderWidth = width;
7862
- this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7863
- }
7864
- getShadowColor() {
7865
- return this.shadowColor;
7866
- }
7867
- setShadowColor(color) {
7868
- this.shadowColor = color;
7869
- }
7870
- getShadowBlur() {
7871
- return this.shadowBlur;
7872
- }
7873
- setShadowBlur(blur) {
7874
- this.shadowBlur = blur;
7875
- }
7876
- getShadowOffsetX() {
7877
- return this.shadowOffsetX;
7878
- }
7879
- setShadowOffsetX(offsetX) {
7880
- this.shadowOffsetX = offsetX;
7881
- }
7882
- getShadowOffsetY() {
7883
- return this.shadowOffsetY;
7884
- }
7885
- setShadowOffsetY(offsetY) {
7886
- this.shadowOffsetY = offsetY;
7887
- }
7888
- getBackgroundOpacity() {
7889
- return this.backgroundOpacity;
7890
- }
7891
- setBackgroundOpacity(opacity) {
7892
- this.backgroundOpacity = opacity;
7893
- }
7894
- getBorderOpacity() {
7895
- return this.borderOpacity;
7896
- }
7897
- getWidth() {
7898
- return this.width;
7899
- }
7900
- getHeight() {
7901
- return this.height;
7902
- }
7903
- setBorderOpacity(opacity) {
7904
- this.borderOpacity = opacity;
7905
- }
7906
- updateCache() {
7907
- const { left, top, right, bottom } = this.getMbr();
7908
- this.x = left - this.paddingLeft;
7909
- this.y = top - this.paddingTop;
7910
- this.width = right - left + this.paddingLeft + this.paddingRight;
7911
- this.height = bottom - top + this.paddingTop + this.paddingBottom;
7912
- const path2d = new conf.path2DFactory;
7913
- if (this.segments.length === 0) {
7914
- return;
7915
- }
7916
- this.segments[0].moveToStart(path2d);
7917
- for (const segment of this.segments) {
7918
- segment.render(path2d);
7919
- }
7920
- if (this.isClosedValue) {
7921
- path2d.closePath();
7922
- }
7923
- this.path2d = path2d;
7924
- }
7925
- getIntersectionPoints(segment) {
7926
- let intersections = [];
7927
- for (const item of this.segments) {
7928
- intersections = intersections.concat(item.getIntersectionPoints(segment));
7929
- }
7930
- return intersections;
7931
- }
7932
- getNearestEdgePointTo(point) {
7933
- return this.getNearestEdgeAndPointTo(point).point;
7934
- }
7935
- getNearestEdgeAndPointTo(point) {
7936
- const candidates = [];
7937
- for (let index = 0;index < this.segments.length; index++) {
7938
- const segment = this.segments[index];
7939
- const pointOnSegment = segment.getNearestEdgePointTo(point);
7940
- candidates.push({
7941
- index,
7942
- segment,
7943
- point: pointOnSegment,
7944
- distance: point.getDistance(pointOnSegment)
7945
- });
7946
- }
7947
- let nearest = candidates[0];
7948
- for (const candidate of candidates) {
7949
- if (candidate.distance < nearest.distance) {
7950
- nearest = candidate;
7951
- }
7952
- }
7953
- return nearest;
7954
- }
7955
- getDistanceToPoint(point) {
7956
- const nearest = this.getNearestEdgePointTo(point);
7957
- return point.getDistance(nearest);
7958
- }
7959
- isUnderPoint(point) {
7960
- return this.isEnclosedOrCrossedBy(new Mbr(point.x, point.y, point.x, point.y));
7961
- }
7962
- isPointOverEdges(point, tolerance = 5) {
7963
- for (const segment of this.segments) {
7964
- const distance = segment.getDistance(point);
7965
- if (distance <= tolerance) {
7966
- return true;
7967
- }
7968
- }
7969
- return false;
7970
- }
7971
- isNearPoint(point, distance) {
7972
- return distance > this.getDistanceToPoint(point);
7318
+ isNearPoint(point, distance) {
7319
+ return distance > this.getDistanceToPoint(point);
7973
7320
  }
7974
7321
  getMbr() {
7975
7322
  if (this.segments.length === 0) {
@@ -8384,382 +7731,18 @@ class Paths {
8384
7731
  return !isAllPathsOpened;
8385
7732
  }
8386
7733
  }
8387
- // src/Items/Connector/ConnectorCommand.ts
8388
- class ConnectorCommand {
8389
- connector;
8390
- operation;
8391
- reverse;
8392
- constructor(connector, operation) {
8393
- this.connector = connector;
8394
- this.operation = operation;
8395
- this.reverse = this.getReverse();
8396
- }
8397
- merge(op) {
8398
- this.operation = op;
8399
- return this;
8400
- }
8401
- apply() {
8402
- for (const connector of this.connector) {
8403
- connector.apply(this.operation);
8404
- }
8405
- }
8406
- revert() {
8407
- for (const { item, operation } of this.reverse) {
8408
- item.apply(operation);
8409
- }
8410
- }
8411
- getReverse() {
8412
- const reverse = [];
8413
- switch (this.operation.method) {
8414
- case "setStartPoint":
8415
- for (const connector of this.connector) {
8416
- reverse.push({
8417
- item: connector,
8418
- operation: {
8419
- ...this.operation,
8420
- startPointData: connector.getStartPoint().serialize()
8421
- }
8422
- });
8423
- }
8424
- break;
8425
- case "setEndPoint":
8426
- for (const connector of this.connector) {
8427
- reverse.push({
8428
- item: connector,
8429
- operation: {
8430
- ...this.operation,
8431
- endPointData: connector.getEndPoint().serialize()
8432
- }
8433
- });
8434
- }
8435
- break;
8436
- case "setMiddlePoint":
8437
- for (const connector of this.connector) {
8438
- const middlePoint = connector.getMiddlePoint();
8439
- reverse.push({
8440
- item: connector,
8441
- operation: {
8442
- ...this.operation,
8443
- middlePointData: middlePoint ? middlePoint.serialize() : null
8444
- }
8445
- });
8446
- }
8447
- break;
8448
- case "setStartPointerStyle":
8449
- for (const connector of this.connector) {
8450
- reverse.push({
8451
- item: connector,
8452
- operation: {
8453
- ...this.operation,
8454
- startPointerStyle: connector.getStartPointerStyle()
8455
- }
8456
- });
8457
- }
8458
- break;
8459
- case "setEndPointerStyle":
8460
- for (const connector of this.connector) {
8461
- reverse.push({
8462
- item: connector,
8463
- operation: {
8464
- ...this.operation,
8465
- endPointerStyle: connector.getEndPointerStyle()
8466
- }
8467
- });
8468
- }
8469
- break;
8470
- case "setLineStyle":
8471
- for (const connector of this.connector) {
8472
- reverse.push({
8473
- item: connector,
8474
- operation: {
8475
- ...this.operation,
8476
- lineStyle: connector.getLineStyle()
8477
- }
8478
- });
8479
- }
8480
- break;
8481
- case "setBorderStyle":
8482
- for (const connector of this.connector) {
8483
- reverse.push({
8484
- item: connector,
8485
- operation: {
8486
- ...this.operation,
8487
- borderStyle: connector.getBorderStyle()
8488
- }
8489
- });
8490
- }
8491
- break;
8492
- case "setLineWidth":
8493
- for (const connector of this.connector) {
8494
- reverse.push({
8495
- item: connector,
8496
- operation: {
8497
- ...this.operation,
8498
- lineWidth: connector.getLineWidth()
8499
- }
8500
- });
8501
- }
8502
- break;
8503
- case "setLineColor":
8504
- for (const connector of this.connector) {
8505
- reverse.push({
8506
- item: connector,
8507
- operation: {
8508
- ...this.operation,
8509
- lineColor: connector.getLineColor()
8510
- }
8511
- });
8512
- }
8513
- break;
8514
- case "switchPointers":
8515
- for (const connector of this.connector) {
8516
- reverse.push({
8517
- item: connector,
8518
- operation: this.operation
8519
- });
8520
- }
8521
- break;
8522
- }
8523
- return reverse;
8524
- }
8525
- }
8526
-
8527
- // src/SessionStorage.ts
8528
- var _sessionStorage;
8529
- if (typeof window !== "undefined" && window.sessionStorage) {
8530
- _sessionStorage = window.sessionStorage;
8531
- } else {
8532
-
8533
- class NodeStoragePolyfill {
8534
- _store = {};
8535
- clear() {
8536
- this._store = {};
8537
- }
8538
- getItem(key) {
8539
- return Object.prototype.hasOwnProperty.call(this._store, key) ? this._store[key] : null;
8540
- }
8541
- key(index) {
8542
- const keys = Object.keys(this._store);
8543
- return keys[index] ?? null;
8544
- }
8545
- removeItem(key) {
8546
- delete this._store[key];
8547
- }
8548
- setItem(key, value) {
8549
- this._store[key] = value;
8550
- }
8551
- get length() {
8552
- return Object.keys(this._store).length;
8553
- }
8554
- }
8555
- _sessionStorage = new NodeStoragePolyfill;
8556
- }
8557
-
8558
- class SessionStorage {
8559
- set(key, value) {
8560
- const boardId = this.getBoardId() || "";
8561
- _sessionStorage.setItem(boardId + "_" + key, JSON.stringify(value));
8562
- }
8563
- get(key) {
8564
- const boardId = this.getBoardId() || "";
8565
- const item = _sessionStorage.getItem(boardId + "_" + key);
8566
- if (!item || item === "undefined") {
8567
- return;
8568
- }
8569
- return JSON.parse(item);
8570
- }
8571
- remove(key) {
8572
- const boardId = this.getBoardId() || "";
8573
- _sessionStorage.removeItem(boardId + "_" + key);
8574
- }
8575
- setConnectorStrokeStyle(color) {
8576
- this.set(`connectorStrokeStyle`, color);
8577
- }
8578
- getConnectorStrokeStyle() {
8579
- return this.get("connectorStrokeStyle");
8580
- }
8581
- setConnectorLineWidth(width) {
8582
- this.set(`connectorLineWidth`, width);
8583
- }
8584
- getConnectorLineWidth() {
8585
- return this.get("connectorLineWidth");
8586
- }
8587
- setConnectorFillColor(color) {
8588
- this.set(`connectorFillColor`, color);
8589
- }
8590
- getConnectorFillColor() {
8591
- return this.get("connectorFillColor");
8592
- }
8593
- setConnectorPointer(type, edge) {
8594
- this.set(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`, type);
8595
- }
8596
- getConnectorPointer(edge) {
8597
- return this.get(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`);
8598
- }
8599
- setConnectorLineStyle(type) {
8600
- this.set("connectorLineStyle", type);
8601
- }
8602
- getConnectorLineStyle() {
8603
- return this.get("connectorLineStyle");
8604
- }
8605
- setShapeData(data) {
8606
- this.set("lastShapeData", data);
8607
- }
8608
- getShapeData() {
8609
- return this.get("lastShapeData");
8610
- }
8611
- setStickerData(data) {
8612
- this.set("lastSticker", data);
8613
- }
8614
- getStickerData() {
8615
- return this.get("lastSticker");
8616
- }
8617
- setShapeWidth(width) {
8618
- this.set("shapeWidth", width);
8619
- }
8620
- getShapeWidth() {
8621
- return this.get("shapeWidth");
8622
- }
8623
- setShapeHeight(height) {
8624
- this.set("shapeHeight", height);
8625
- }
8626
- getShapeHeight() {
8627
- return this.get("shapeHeight");
8628
- }
8629
- setImageDimensions(dimension) {
8630
- this.set("imageDimensions", dimension);
8631
- }
8632
- getImageDimensions() {
8633
- return this.get("imageDimensions");
8634
- }
8635
- setFontSize(itemType, size) {
8636
- this.set(`fontSize_${itemType}`, size);
8637
- }
8638
- getFontSize(itemType) {
8639
- return this.get(`fontSize_${itemType}`);
8640
- }
8641
- setFontStyles(itemType, styles) {
8642
- this.set(`fontStyles_${itemType}`, styles);
8643
- }
8644
- getFontStyles(itemType) {
8645
- return this.get(`fontStyles_${itemType}`);
8646
- }
8647
- setFontColor(itemType, color) {
8648
- this.set(`fontColor_${itemType}`, color);
8649
- }
8650
- getFontColor(itemType) {
8651
- return this.get(`fontColor_${itemType}`);
8652
- }
8653
- setFontHighlight(itemType, highlightColor) {
8654
- this.set(`fontHighlightColor_${itemType}`, highlightColor);
8655
- }
8656
- getFontHighlight(itemType) {
8657
- return this.get(`fontHighlightColor_${itemType}`);
8658
- }
8659
- setHorizontalAlignment(itemType, horizontalAlignment) {
8660
- this.set(`fontHorizontalAlignment_${itemType}`, horizontalAlignment);
8661
- }
8662
- getHorizontalAlignment(itemType) {
8663
- return this.get(`fontHorizontalAlignment_${itemType}`);
8664
- }
8665
- setVerticalAlignment(itemType, verticalAlignment) {
8666
- this.set(`fontVerticalAlignment_${itemType}`, verticalAlignment);
8667
- }
8668
- getVerticalAlignment(itemType) {
8669
- return this.get(`fontVerticalAlignment_${itemType}`);
8670
- }
8671
- setLastAIRequest(request) {
8672
- _sessionStorage.setItem("lastAIRequest", request);
8673
- }
8674
- getLastAIRequest() {
8675
- return _sessionStorage.getItem("lastAIRequest");
8676
- }
8677
- removeLastAIRequest() {
8678
- _sessionStorage.removeItem("lastAIRequest");
8679
- }
8680
- clear() {
8681
- _sessionStorage.clear();
8682
- }
8683
- getBoardId() {
8684
- if (typeof window === "undefined") {
8685
- return;
8686
- }
8687
- return window.location.href.split("/").pop()?.split("?")[0];
8688
- }
8689
- }
8690
- var tempStorage = new SessionStorage;
8691
-
8692
- // src/HTMLRender/HTMLRender.ts
8693
- function getTranslationFromHTML(el) {
8694
- const transform = el.style.transform;
8695
- const translateMatch = transform.match(/translate\(([^)]+)\)/);
8696
- const [translateX, translateY] = translateMatch ? translateMatch[1].split(",").map((value) => parseFloat(value)) : [0, 0];
8697
- return [translateX, translateY];
8698
- }
8699
- function getScaleFromHTML(el) {
8700
- const transform = el.style.transform;
8701
- const scaleMatch = transform.match(/scale\(([^)]+)\)/);
8702
- const [scaleX, scaleY] = scaleMatch ? scaleMatch[1].split(",").map((value) => parseFloat(value)) : [1, 1];
8703
- return [scaleX, scaleY];
8704
- }
8705
- function translateElementBy(el, x, y) {
8706
- const [exX, exY] = getTranslationFromHTML(el);
8707
- const [newX, newY] = [exX + x, exY + y];
8708
- const [scaleX, scaleY] = getScaleFromHTML(el);
8709
- el.style.transform = `translate(${newX}px, ${newY}px) scale(${scaleX}, ${scaleY})`;
8710
- return el;
8711
- }
8712
- function scaleElementBy(el, scaleX, scaleY) {
8713
- const [currentScaleX, currentScaleY] = getScaleFromHTML(el);
8714
- const [newScaleX, newScaleY] = [
8715
- currentScaleX * scaleX,
8716
- currentScaleY * scaleY
8717
- ];
8718
- const [translateX, translateY] = getTranslationFromHTML(el);
8719
- el.style.transform = `translate(${translateX}px, ${translateY}px) scale(${newScaleX}, ${newScaleY})`;
8720
- return el;
8721
- }
8722
- function resetElementScale(el) {
8723
- const [x, y] = getTranslationFromHTML(el);
8724
- el.style.transform = `translate(${x}px, ${y}px) scale(1, 1)`;
8725
- return el;
8726
- }
8727
- function positionRelatively(toPosition, positionBy, padding = 0) {
8728
- const [translateX, translateY] = getTranslationFromHTML(toPosition);
8729
- const [frameX, frameY] = getTranslationFromHTML(positionBy);
8730
- const [dx, dy] = [translateX - frameX, translateY - frameY];
8731
- const verticalAlignment = toPosition.getAttribute("data-vertical-alignment");
8732
- const horizontalAlignment = toPosition.getAttribute("data-vertical-alignment");
8733
- let paddingX = padding;
8734
- let paddingY = padding;
8735
- if (verticalAlignment && verticalAlignment === "bottom") {
8736
- paddingY = -padding;
8737
- }
8738
- if (horizontalAlignment && horizontalAlignment === "right") {
8739
- paddingX = -padding;
8740
- }
8741
- const [scaleX, scaleY] = getScaleFromHTML(toPosition);
8742
- toPosition.style.transform = `translate(${dx + paddingX}px, ${dy + paddingY}px) scale(${scaleX}, ${scaleY})`;
8743
- return toPosition;
8744
- }
8745
- function positionAbsolutely(toPosition, positionBy) {
8746
- const [translateX, translateY] = getTranslationFromHTML(toPosition);
8747
- const [frameX, frameY] = getTranslationFromHTML(positionBy);
8748
- const [dx, dy] = [translateX + frameX, translateY + frameY];
8749
- const [scaleX, scaleY] = getScaleFromHTML(toPosition);
8750
- toPosition.style.transform = `translate(${dx}px, ${dy}px) scale(${scaleX}, ${scaleY})`;
8751
- return toPosition;
8752
- }
8753
7734
  // src/Items/Frame/Basic/Custom/index.ts
8754
7735
  var Custom = {
8755
7736
  name: "Custom",
8756
7737
  textBounds: new Mbr(0, -10, 100, -1),
8757
- path: new Path([
8758
- new Line(new Point(0, 0), new Point(100, 0)),
8759
- new Line(new Point(100, 0), new Point(100, 100)),
8760
- new Line(new Point(100, 100), new Point(0, 100)),
8761
- new Line(new Point(0, 100), new Point(0, 0))
8762
- ], true),
7738
+ get path() {
7739
+ return new Path([
7740
+ new Line(new Point(0, 0), new Point(100, 0)),
7741
+ new Line(new Point(100, 0), new Point(100, 100)),
7742
+ new Line(new Point(100, 100), new Point(0, 100)),
7743
+ new Line(new Point(0, 100), new Point(0, 0))
7744
+ ], true);
7745
+ },
8763
7746
  anchorPoints: [new Point(0, 50), new Point(100, 50), new Point(50, 0), new Point(50, 100)]
8764
7747
  };
8765
7748
 
@@ -8767,12 +7750,14 @@ var Custom = {
8767
7750
  var Frame16x9 = {
8768
7751
  name: "16:9",
8769
7752
  textBounds: new Mbr(0, -10, 200, -1),
8770
- path: new Path([
8771
- new Line(new Point(0, 0), new Point(200, 0)),
8772
- new Line(new Point(200, 0), new Point(200, 200 * (739 / 1314))),
8773
- new Line(new Point(200, 200 * (739 / 1314)), new Point(0, 200 * (739 / 1314))),
8774
- new Line(new Point(0, 200 * (739 / 1314)), new Point(0, 0))
8775
- ], true),
7753
+ get path() {
7754
+ return new Path([
7755
+ new Line(new Point(0, 0), new Point(200, 0)),
7756
+ new Line(new Point(200, 0), new Point(200, 200 * (739 / 1314))),
7757
+ new Line(new Point(200, 200 * (739 / 1314)), new Point(0, 200 * (739 / 1314))),
7758
+ new Line(new Point(0, 200 * (739 / 1314)), new Point(0, 0))
7759
+ ], true);
7760
+ },
8776
7761
  anchorPoints: [
8777
7762
  new Point(0, 100 * (739 / 1314)),
8778
7763
  new Point(200, 100 * (739 / 1314)),
@@ -8785,12 +7770,14 @@ var Frame16x9 = {
8785
7770
  var Frame4x3 = {
8786
7771
  name: "4:3",
8787
7772
  textBounds: new Mbr(0, -10, 200, -1),
8788
- path: new Path([
8789
- new Line(new Point(0, 0), new Point(200, 0)),
8790
- new Line(new Point(200, 0), new Point(200, 200 * (853 / 1138))),
8791
- new Line(new Point(200, 200 * (853 / 1138)), new Point(0, 200 * (853 / 1138))),
8792
- new Line(new Point(0, 200 * (853 / 1138)), new Point(0, 0))
8793
- ], true),
7773
+ get path() {
7774
+ return new Path([
7775
+ new Line(new Point(0, 0), new Point(200, 0)),
7776
+ new Line(new Point(200, 0), new Point(200, 200 * (853 / 1138))),
7777
+ new Line(new Point(200, 200 * (853 / 1138)), new Point(0, 200 * (853 / 1138))),
7778
+ new Line(new Point(0, 200 * (853 / 1138)), new Point(0, 0))
7779
+ ], true);
7780
+ },
8794
7781
  anchorPoints: [
8795
7782
  new Point(0, 100 * (853 / 1138)),
8796
7783
  new Point(200, 100 * (853 / 1138)),
@@ -8803,12 +7790,14 @@ var Frame4x3 = {
8803
7790
  var A4 = {
8804
7791
  name: "A4",
8805
7792
  textBounds: new Mbr(0, -15, 100, -1),
8806
- path: new Path([
8807
- new Line(new Point(0, 0), new Point(100, 0)),
8808
- new Line(new Point(100, 0), new Point(100, 100 * (1172 / 828))),
8809
- new Line(new Point(100, 100 * (1172 / 828)), new Point(0, 100 * (1172 / 828))),
8810
- new Line(new Point(0, 100 * (1172 / 828)), new Point(0, 0))
8811
- ], true),
7793
+ get path() {
7794
+ return new Path([
7795
+ new Line(new Point(0, 0), new Point(100, 0)),
7796
+ new Line(new Point(100, 0), new Point(100, 100 * (1172 / 828))),
7797
+ new Line(new Point(100, 100 * (1172 / 828)), new Point(0, 100 * (1172 / 828))),
7798
+ new Line(new Point(0, 100 * (1172 / 828)), new Point(0, 0))
7799
+ ], true);
7800
+ },
8812
7801
  anchorPoints: [
8813
7802
  new Point(0, 50 * (1172 / 828)),
8814
7803
  new Point(100, 50 * (1172 / 828)),
@@ -8821,12 +7810,14 @@ var A4 = {
8821
7810
  var Letter = {
8822
7811
  name: "Letter",
8823
7812
  textBounds: new Mbr(0, -10, 100, -1),
8824
- path: new Path([
8825
- new Line(new Point(0, 0), new Point(100, 0)),
8826
- new Line(new Point(100, 0), new Point(100, 100 * (1120 / 867))),
8827
- new Line(new Point(100, 100 * (1120 / 867)), new Point(0, 100 * (1120 / 867))),
8828
- new Line(new Point(0, 100 * (1120 / 867)), new Point(0, 0))
8829
- ], true),
7813
+ get path() {
7814
+ return new Path([
7815
+ new Line(new Point(0, 0), new Point(100, 0)),
7816
+ new Line(new Point(100, 0), new Point(100, 100 * (1120 / 867))),
7817
+ new Line(new Point(100, 100 * (1120 / 867)), new Point(0, 100 * (1120 / 867))),
7818
+ new Line(new Point(0, 100 * (1120 / 867)), new Point(0, 0))
7819
+ ], true);
7820
+ },
8830
7821
  anchorPoints: [
8831
7822
  new Point(0, 50 * (1120 / 867)),
8832
7823
  new Point(100, 50 * (1120 / 867)),
@@ -8839,12 +7830,14 @@ var Letter = {
8839
7830
  var Frame1x1 = {
8840
7831
  name: "1:1",
8841
7832
  textBounds: new Mbr(0, -10, 100, -1),
8842
- path: new Path([
8843
- new Line(new Point(0, 0), new Point(100, 0)),
8844
- new Line(new Point(100, 0), new Point(100, 100)),
8845
- new Line(new Point(100, 100), new Point(0, 100)),
8846
- new Line(new Point(0, 100), new Point(0, 0))
8847
- ], true),
7833
+ get path() {
7834
+ return new Path([
7835
+ new Line(new Point(0, 0), new Point(100, 0)),
7836
+ new Line(new Point(100, 0), new Point(100, 100)),
7837
+ new Line(new Point(100, 100), new Point(0, 100)),
7838
+ new Line(new Point(0, 100), new Point(0, 0))
7839
+ ], true);
7840
+ },
8848
7841
  anchorPoints: [new Point(0, 50), new Point(100, 50), new Point(50, 0), new Point(50, 100)]
8849
7842
  };
8850
7843
 
@@ -8852,12 +7845,14 @@ var Frame1x1 = {
8852
7845
  var Frame3x2 = {
8853
7846
  name: "3:2",
8854
7847
  textBounds: new Mbr(0, -10, 200, -1),
8855
- path: new Path([
8856
- new Line(new Point(0, 0), new Point(200, 0)),
8857
- new Line(new Point(200, 0), new Point(200, 200 * (200 / 300))),
8858
- new Line(new Point(200, 200 * (200 / 300)), new Point(0, 200 * (200 / 300))),
8859
- new Line(new Point(0, 200 * (200 / 300)), new Point(0, 0))
8860
- ], true),
7848
+ get path() {
7849
+ return new Path([
7850
+ new Line(new Point(0, 0), new Point(200, 0)),
7851
+ new Line(new Point(200, 0), new Point(200, 200 * (200 / 300))),
7852
+ new Line(new Point(200, 200 * (200 / 300)), new Point(0, 200 * (200 / 300))),
7853
+ new Line(new Point(0, 200 * (200 / 300)), new Point(0, 0))
7854
+ ], true);
7855
+ },
8861
7856
  anchorPoints: [
8862
7857
  new Point(0, 100 * (200 / 300)),
8863
7858
  new Point(200, 100 * (200 / 300)),
@@ -8870,12 +7865,14 @@ var Frame3x2 = {
8870
7865
  var Frame9x18 = {
8871
7866
  name: "9:18",
8872
7867
  textBounds: new Mbr(0, -10, 200, -1),
8873
- path: new Path([
8874
- new Line(new Point(0, 0), new Point(200, 0)),
8875
- new Line(new Point(200, 0), new Point(200, 200 * (1230 / 612))),
8876
- new Line(new Point(200, 200 * (1230 / 612)), new Point(0, 200 * (1230 / 612))),
8877
- new Line(new Point(0, 200 * (1230 / 612)), new Point(0, 0))
8878
- ], true),
7868
+ get path() {
7869
+ return new Path([
7870
+ new Line(new Point(0, 0), new Point(200, 0)),
7871
+ new Line(new Point(200, 0), new Point(200, 200 * (1230 / 612))),
7872
+ new Line(new Point(200, 200 * (1230 / 612)), new Point(0, 200 * (1230 / 612))),
7873
+ new Line(new Point(0, 200 * (1230 / 612)), new Point(0, 0))
7874
+ ], true);
7875
+ },
8879
7876
  anchorPoints: [
8880
7877
  new Point(0, 100 * (1230 / 612)),
8881
7878
  new Point(200, 100 * (1230 / 612)),
@@ -9349,9 +8346,40 @@ import {
9349
8346
  Editor as Editor31,
9350
8347
  Element as Element6,
9351
8348
  Text,
9352
- Transforms as Transforms20
8349
+ Transforms as Transforms21
9353
8350
  } from "slate";
9354
8351
 
8352
+ // src/SubjectOperation.ts
8353
+ class SubjectOperation {
8354
+ observers = [];
8355
+ subscribe(observer) {
8356
+ const index = this.observers.indexOf(observer);
8357
+ if (index === -1) {
8358
+ this.observers.push(observer);
8359
+ }
8360
+ }
8361
+ unsubscribe(observer) {
8362
+ const index = this.observers.indexOf(observer);
8363
+ if (index !== -1) {
8364
+ this.observers.splice(index, 1);
8365
+ }
8366
+ }
8367
+ publish(subject, op) {
8368
+ for (const observer of this.observers) {
8369
+ observer(subject, op);
8370
+ }
8371
+ }
8372
+ }
8373
+
8374
+ // src/Items/ItemsCommandUtils.ts
8375
+ function mapItemsByOperation(item, getCallback) {
8376
+ const items = Array.isArray(item) ? item : [item];
8377
+ return items.map((item2) => {
8378
+ const operation = getCallback(item2);
8379
+ return { item: item2, operation };
8380
+ });
8381
+ }
8382
+
9355
8383
  // src/Items/LinkTo/LinkToCommand.ts
9356
8384
  class LinkToCommand {
9357
8385
  linkTo;
@@ -10237,7 +9265,7 @@ function fillText(ctx, textBlock) {
10237
9265
  import {
10238
9266
  createEditor,
10239
9267
  Editor as Editor27,
10240
- Transforms as Transforms18
9268
+ Transforms as Transforms19
10241
9269
  } from "slate";
10242
9270
 
10243
9271
  // node_modules/is-plain-object/dist/is-plain-object.mjs
@@ -11057,7 +10085,10 @@ var setLink = (editor, link, selection) => {
11057
10085
  return;
11058
10086
  }
11059
10087
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
11060
- Editor12.addMark(editor, "fontColor", format);
10088
+ Transforms11.setNodes(editor, { fontColor: format }, {
10089
+ match: (n) => !Editor12.isEditor(n) && n.type === "text",
10090
+ split: true
10091
+ });
11061
10092
  for (const [node, path2] of Editor12.nodes(editor, {
11062
10093
  match: (n) => !Editor12.isEditor(n) && n.type === "text"
11063
10094
  })) {
@@ -17148,7 +16179,7 @@ function persistLeafFormats(children) {
17148
16179
  }, {});
17149
16180
  }
17150
16181
  function plugin(opts) {
17151
- var compiler2 = function compiler3(node2) {
16182
+ var compiler2 = function compiler(node2) {
17152
16183
  return node2.children.map(function(c) {
17153
16184
  return deserialize(c, opts);
17154
16185
  });
@@ -17268,6 +16299,7 @@ class MarkdownProcessor {
17268
16299
  isProcessingChunk = false;
17269
16300
  stopProcessingMarkDownCb = null;
17270
16301
  currentNode = "";
16302
+ doneResolvers = [];
17271
16303
  editor;
17272
16304
  subject = new Subject;
17273
16305
  constructor(editor) {
@@ -17279,6 +16311,19 @@ class MarkdownProcessor {
17279
16311
  getStopProcessingMarkDownCb() {
17280
16312
  return this.stopProcessingMarkDownCb;
17281
16313
  }
16314
+ waitForDone() {
16315
+ if (!this.isProcessingChunk && this.chunksQueue.length === 0) {
16316
+ return Promise.resolve();
16317
+ }
16318
+ return new Promise((resolve) => {
16319
+ this.doneResolvers.push(resolve);
16320
+ });
16321
+ }
16322
+ notifyDone() {
16323
+ const resolvers = this.doneResolvers;
16324
+ this.doneResolvers = [];
16325
+ resolvers.forEach((r) => r());
16326
+ }
17282
16327
  deserializeMarkdown(isNewParagraphNeeded) {
17283
16328
  const lastNode = this.getText()[this.getText().length - 1];
17284
16329
  if (lastNode.type !== "paragraph") {
@@ -17335,6 +16380,7 @@ class MarkdownProcessor {
17335
16380
  async processNextChunk() {
17336
16381
  if (this.chunksQueue.length === 0) {
17337
16382
  this.isProcessingChunk = false;
16383
+ this.notifyDone();
17338
16384
  return;
17339
16385
  }
17340
16386
  this.isProcessingChunk = true;
@@ -17342,6 +16388,7 @@ class MarkdownProcessor {
17342
16388
  if (chunk === "StopProcessingMarkdown") {
17343
16389
  await this.deserializeMarkdownAsync(false);
17344
16390
  this.isProcessingChunk = false;
16391
+ this.notifyDone();
17345
16392
  this.currentNode = "";
17346
16393
  if (this.stopProcessingMarkDownCb) {
17347
16394
  selectWholeText(this.editor);
@@ -17610,7 +16657,7 @@ function setSelectionFontSize(editor, isAutosize, fontSize, selectionContext) {
17610
16657
  }
17611
16658
 
17612
16659
  // src/Items/RichText/editorHelpers/selectionOps/setSelectionFontStyle.ts
17613
- import { Editor as Editor25 } from "slate";
16660
+ import { Editor as Editor25, Range as Range8, Transforms as Transforms18 } from "slate";
17614
16661
 
17615
16662
  // src/Items/RichText/editorHelpers/common/getEachNodeInSelectionStyles.ts
17616
16663
  function getEachNodeInSelectionStyles(editor) {
@@ -17640,10 +16687,22 @@ function setSelectionFontStyle(editor, style) {
17640
16687
  const isAllNodesContainStyle = selectionStyles.every((styleArr) => styleArr.includes(style2));
17641
16688
  const isSomeNodeContainStyle = selectionStyles.some((styleArr) => styleArr.includes(style2));
17642
16689
  const isAllNodesNotContainStyle = selectionStyles.every((styleArr) => !styleArr.includes(style2));
16690
+ let value;
17643
16691
  if (isAllNodesContainStyle) {
17644
- Editor25.addMark(editor, style2, false);
16692
+ value = false;
17645
16693
  } else if (isSomeNodeContainStyle || isAllNodesNotContainStyle) {
17646
- Editor25.addMark(editor, style2, true);
16694
+ value = true;
16695
+ } else {
16696
+ continue;
16697
+ }
16698
+ const { selection } = editor;
16699
+ if (selection && Range8.isExpanded(selection)) {
16700
+ Transforms18.setNodes(editor, { [style2]: value }, {
16701
+ match: (n) => !Editor25.isEditor(n) && n.type === "text",
16702
+ split: true
16703
+ });
16704
+ } else {
16705
+ Editor25.addMark(editor, style2, value);
17647
16706
  }
17648
16707
  }
17649
16708
  }
@@ -17901,373 +16960,960 @@ class EditorContainer {
17901
16960
  }
17902
16961
  console.error("Error applying this type operation: ", operations2);
17903
16962
  }
17904
- }
17905
- applySelectionEdit(op) {
17906
- this.shouldEmit = false;
17907
- for (const operation of op.ops) {
17908
- this.decorated.apply(operation);
16963
+ }
16964
+ applySelectionEdit(op) {
16965
+ this.shouldEmit = false;
16966
+ for (const operation of op.ops) {
16967
+ this.decorated.apply(operation);
16968
+ }
16969
+ this.shouldEmit = true;
16970
+ }
16971
+ applySelectionOp(op) {
16972
+ this.shouldEmit = false;
16973
+ Editor27.withoutNormalizing(this.editor, () => {
16974
+ for (const operation of op.ops) {
16975
+ this.decorated.apply(operation);
16976
+ }
16977
+ });
16978
+ this.shouldEmit = true;
16979
+ }
16980
+ applyWholeTextOp(op) {
16981
+ const selection = this.editor.selection;
16982
+ selectWholeText(this.editor);
16983
+ switch (op.method) {
16984
+ case "setFontStyle":
16985
+ this.setSelectionFontStyle(op.fontStyleList);
16986
+ break;
16987
+ case "setFontColor":
16988
+ this.setSelectionFontColor(op.fontColor);
16989
+ break;
16990
+ case "setFontFamily":
16991
+ break;
16992
+ case "setFontSize":
16993
+ this.textScale = Number(op.fontSize) / this.getScale() / this.initialTextStyles.fontSize;
16994
+ break;
16995
+ case "setFontHighlight":
16996
+ this.setSelectionFontHighlight(op.fontHighlight);
16997
+ break;
16998
+ case "setHorisontalAlignment":
16999
+ this.setSelectionHorisontalAlignment(op.horisontalAlignment);
17000
+ break;
17001
+ case "setMaxWidth":
17002
+ this.applyMaxWidth(op.maxWidth ?? 0);
17003
+ break;
17004
+ }
17005
+ if (selection) {
17006
+ Transforms19.select(this.editor, selection);
17007
+ }
17008
+ }
17009
+ applyMaxWidth(maxWidth) {
17010
+ this.maxWidth = maxWidth;
17011
+ }
17012
+ setMaxWidth(maxWidth) {
17013
+ this.emit({
17014
+ class: "RichText",
17015
+ method: "setMaxWidth",
17016
+ item: [this.id],
17017
+ maxWidth
17018
+ });
17019
+ }
17020
+ setSelectionFontColor(format, selectionContext) {
17021
+ this.startOpRecording();
17022
+ setSelectionFontColor(this.editor, format, selectionContext);
17023
+ return this.stopOpRecordingAndGetOps();
17024
+ }
17025
+ setSelectionLink(link, selection) {
17026
+ this.startOpRecording();
17027
+ setLink(this.editor, link, selection);
17028
+ return this.stopOpRecordingAndGetOps();
17029
+ }
17030
+ setSelectionFontStyle(style) {
17031
+ this.startOpRecording();
17032
+ setSelectionFontStyle(this.editor, style);
17033
+ return this.stopOpRecordingAndGetOps();
17034
+ }
17035
+ setSelectionFontSize(fontSize, selectionContext) {
17036
+ this.startOpRecording();
17037
+ const shouldUpdateElement = setSelectionFontSize(this.editor, this.getAutosize(), fontSize, selectionContext);
17038
+ if (shouldUpdateElement) {
17039
+ this.updateElement();
17040
+ }
17041
+ return this.stopOpRecordingAndGetOps();
17042
+ }
17043
+ setSelectionFontHighlight(format, selectionContext) {
17044
+ this.startOpRecording();
17045
+ setSelectionFontHighlight(this.editor, format, selectionContext);
17046
+ return this.stopOpRecordingAndGetOps();
17047
+ }
17048
+ setSelectionHorisontalAlignment(horisontalAlignment, selectionContext) {
17049
+ this.startOpRecording();
17050
+ setSelectionHorisontalAlignment(this.editor, horisontalAlignment, selectionContext);
17051
+ return this.stopOpRecordingAndGetOps();
17052
+ }
17053
+ getSelectionMarks() {
17054
+ return getSelectionMarks(this.editor);
17055
+ }
17056
+ handleListMerge() {
17057
+ return handleListMerge(this.editor);
17058
+ }
17059
+ getListTypeAtSelectionStart() {
17060
+ return getListTypeAtSelectionStart(this.editor);
17061
+ }
17062
+ handleSplitListItem() {
17063
+ return handleSplitListItem(this.editor);
17064
+ }
17065
+ includesListNode() {
17066
+ return this.getText().some((node2) => node2.type === "ol_list" || node2.type === "ul_list");
17067
+ }
17068
+ toggleListType(targetListType, shouldWrap = true) {
17069
+ const result = toggleListType(this.editor, targetListType, shouldWrap);
17070
+ this.subject.publish(this);
17071
+ return result;
17072
+ }
17073
+ withAutoList() {
17074
+ return withAutoList(this.editor);
17075
+ }
17076
+ handleWrapIntoNestedList() {
17077
+ const result = handleWrapIntoNestedList(this.editor);
17078
+ this.subject.publish(this);
17079
+ return result;
17080
+ }
17081
+ getFirstSelectionLink(selection) {
17082
+ return getFirstSelectionLink(this.editor, selection);
17083
+ }
17084
+ getText() {
17085
+ return this.editor.children;
17086
+ }
17087
+ getTextParagraphs(lines) {
17088
+ const newlines = [];
17089
+ lines.forEach((line) => {
17090
+ if (!this.getAutosize()) {
17091
+ newlines.push(this.createParagraphNode(line));
17092
+ return;
17093
+ }
17094
+ const validText = this.getValidText(line, newlines);
17095
+ if (validText.length > 0) {
17096
+ newlines.push(this.createParagraphNode(validText));
17097
+ } else {
17098
+ this.getOnLimitReached()();
17099
+ }
17100
+ });
17101
+ return newlines;
17102
+ }
17103
+ getValidText(line, newlines) {
17104
+ let left = 0;
17105
+ let right = line.length;
17106
+ let validText = "";
17107
+ while (left <= right) {
17108
+ const mid = Math.floor((left + right) / 2);
17109
+ const currentText = line.slice(0, mid);
17110
+ const testLine = this.createParagraphNode(currentText);
17111
+ const nodes = [...newlines, testLine];
17112
+ this.applyAutoSizeScale(this.calcAutoSize(nodes), nodes);
17113
+ const relativeFontSize = this.getFontSize() / this.getMatrixScale();
17114
+ if (relativeFontSize >= 10) {
17115
+ validText = currentText;
17116
+ left = mid + 1;
17117
+ } else {
17118
+ right = mid - 1;
17119
+ }
17120
+ }
17121
+ return validText;
17122
+ }
17123
+ createParagraphNode(text3) {
17124
+ return createParagraphNode(text3, this.editor, this.horisontalAlignment);
17125
+ }
17126
+ insertCopiedText(text3) {
17127
+ const lines = this.getTextParagraphs(text3.split(/\r\n|\r|\n/));
17128
+ if (this.isLimitReached(lines)) {
17129
+ return true;
17130
+ }
17131
+ insertCopiedNodes(this.editor, lines);
17132
+ this.subject.publish(this);
17133
+ return true;
17134
+ }
17135
+ checkIsAutoSizeTextScaleAllowed(nodes) {
17136
+ const existingNodes = this.getBlockNodes();
17137
+ const textScale = this.calcAutoSize([...existingNodes, ...nodes]);
17138
+ const marks = this.getSelectionMarks();
17139
+ const fontSize = marks?.fontSize ?? this.initialTextStyles.fontSize;
17140
+ return Math.ceil(textScale * (fontSize === "auto" ? 14 : fontSize)) / this.getMatrixScale() > 4;
17141
+ }
17142
+ isLimitReached(nodes) {
17143
+ if (this.getAutosize()) {
17144
+ if (!this.checkIsAutoSizeTextScaleAllowed(nodes)) {
17145
+ this.getOnLimitReached()();
17146
+ return true;
17147
+ }
17148
+ }
17149
+ return false;
17150
+ }
17151
+ insertCopiedNodes(nodes) {
17152
+ if (this.isLimitReached(nodes)) {
17153
+ return true;
17154
+ }
17155
+ insertCopiedNodes(this.editor, nodes);
17156
+ this.subject.publish(this);
17157
+ return true;
17158
+ }
17159
+ hasTextInSelection() {
17160
+ return hasTextInSelection(this.editor);
17161
+ }
17162
+ getSelection() {
17163
+ return JSON.parse(JSON.stringify(this.editor.selection));
17164
+ }
17165
+ splitNode() {
17166
+ Transforms19.splitNodes(this.editor, { always: true });
17167
+ }
17168
+ getBlockNodes() {
17169
+ return this.editor.children;
17170
+ }
17171
+ isEmpty() {
17172
+ return isTextEmpty(this.editor.children);
17173
+ }
17174
+ clearText() {
17175
+ clearText(this.editor);
17176
+ }
17177
+ addText(text3) {
17178
+ this.editor.apply({
17179
+ type: "insert_text",
17180
+ text: text3,
17181
+ path: [0, 0],
17182
+ offset: 0
17183
+ });
17184
+ }
17185
+ selectWholeText() {
17186
+ selectWholeText(this.editor);
17187
+ }
17188
+ moveCursorToEndOfTheText(delay = 10) {
17189
+ moveCursorToEndOfTheText(this.editor, delay);
17190
+ }
17191
+ }
17192
+
17193
+ // src/Items/RichText/findOptimalMaxWidthForTextAutoSize.ts
17194
+ function findOptimalMaxWidthForTextAutoSize(text3, containerWidth, containerHeight, initialMaxWidth, tolerance = 0.05) {
17195
+ const targetRatio = containerWidth / containerHeight;
17196
+ let low = 0;
17197
+ let high = initialMaxWidth * 3;
17198
+ let closestRatioDifference = Infinity;
17199
+ let closestWidth = initialMaxWidth;
17200
+ let closestHeight = initialMaxWidth / targetRatio;
17201
+ const iterations = Math.min(Math.max(3, containerWidth / 80), 15);
17202
+ for (let i = 0;i < iterations && low < high; i += 1) {
17203
+ const mid = (low + high) / 2;
17204
+ const { width: calcWidth, height: calcHeight } = getBlockNodes(text3, mid);
17205
+ const currentRatio = calcWidth / calcHeight;
17206
+ const ratioDifference = Math.abs(currentRatio - targetRatio);
17207
+ if (ratioDifference < closestRatioDifference) {
17208
+ closestRatioDifference = ratioDifference;
17209
+ closestWidth = calcWidth;
17210
+ closestHeight = calcHeight;
17211
+ }
17212
+ if (ratioDifference <= tolerance) {
17213
+ break;
17214
+ }
17215
+ if (currentRatio < targetRatio) {
17216
+ low = mid + 1;
17217
+ } else {
17218
+ high = mid - 1;
17219
+ }
17220
+ }
17221
+ const scale = Math.min(containerWidth / closestWidth, containerHeight / closestHeight);
17222
+ return {
17223
+ bestMaxWidth: initialMaxWidth / scale,
17224
+ bestMaxHeight: initialMaxWidth / targetRatio / scale
17225
+ };
17226
+ }
17227
+
17228
+ // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontColor.ts
17229
+ import { Editor as Editor28 } from "slate";
17230
+ function applySelectionFontColor(editor, fontColor) {
17231
+ if (!editor) {
17232
+ throw new Error("Editor is not initialized");
17233
+ }
17234
+ const marks = getSelectionMarks(editor);
17235
+ if (!marks) {
17236
+ return;
17237
+ }
17238
+ Editor28.addMark(editor, "fontColor", fontColor);
17239
+ }
17240
+
17241
+ // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontSize.ts
17242
+ import { Editor as Editor29, Transforms as Transforms20 } from "slate";
17243
+ function applySelectionFontSize(editor, fontSize, selectionContext) {
17244
+ const size = fontSize;
17245
+ if (typeof size !== "number") {
17246
+ return;
17247
+ }
17248
+ if (!editor) {
17249
+ throw new Error("Editor is not initialized");
17250
+ }
17251
+ const selection = editor.selection;
17252
+ const marks = getSelectionMarks(editor);
17253
+ if (!marks) {
17254
+ return;
17255
+ }
17256
+ if (JSON.stringify(selection?.anchor) === JSON.stringify(selection?.focus)) {
17257
+ Transforms20.select(editor, {
17258
+ anchor: Editor29.start(editor, []),
17259
+ focus: Editor29.end(editor, [])
17260
+ });
17261
+ }
17262
+ Editor29.addMark(editor, "fontSize", size);
17263
+ if (selectionContext === "EditTextUnderPointer") {}
17264
+ }
17265
+
17266
+ // src/Items/RichText/editorHelpers/common/getSelectedBlockNode.ts
17267
+ import { Editor as Editor30, Element as Element5 } from "slate";
17268
+ function getSelectedBlockNode(editor) {
17269
+ const { selection } = editor;
17270
+ if (!selection) {
17271
+ return null;
17272
+ }
17273
+ const [node2] = Editor30.node(editor, selection);
17274
+ if (Editor30.isEditor(node2) || !Element5.isElement(node2)) {
17275
+ return null;
17276
+ }
17277
+ return node2;
17278
+ }
17279
+
17280
+ // src/Items/RichText/utils.ts
17281
+ function findCommonStrings(arrays) {
17282
+ if (arrays.length === 0) {
17283
+ return [];
17284
+ }
17285
+ let commonStrings = arrays[0];
17286
+ for (let i = 1;i < arrays.length; i++) {
17287
+ commonStrings = commonStrings.filter((str) => arrays[i].includes(str));
17288
+ }
17289
+ return commonStrings;
17290
+ }
17291
+
17292
+ // src/Items/RichText/editorHelpers/common/getSelectionStyles.ts
17293
+ function getSelectionStyles(editor) {
17294
+ const { selection } = editor;
17295
+ if (!selection) {
17296
+ return;
17297
+ }
17298
+ const nodes = getAllTextNodesInSelection(editor);
17299
+ const styles = nodes.reduce((acc, node2) => {
17300
+ const styles2 = [];
17301
+ if (node2.text === "") {
17302
+ return acc;
17303
+ }
17304
+ if (node2.bold) {
17305
+ styles2.push("bold");
17306
+ }
17307
+ if (node2.italic) {
17308
+ styles2.push("italic");
17909
17309
  }
17910
- this.shouldEmit = true;
17911
- }
17912
- applySelectionOp(op) {
17913
- this.shouldEmit = false;
17914
- Editor27.withoutNormalizing(this.editor, () => {
17915
- for (const operation of op.ops) {
17916
- this.decorated.apply(operation);
17917
- }
17918
- });
17919
- this.shouldEmit = true;
17920
- }
17921
- applyWholeTextOp(op) {
17922
- const selection = this.editor.selection;
17923
- selectWholeText(this.editor);
17924
- switch (op.method) {
17925
- case "setFontStyle":
17926
- this.setSelectionFontStyle(op.fontStyleList);
17927
- break;
17928
- case "setFontColor":
17929
- this.setSelectionFontColor(op.fontColor);
17930
- break;
17931
- case "setFontFamily":
17932
- break;
17933
- case "setFontSize":
17934
- this.textScale = Number(op.fontSize) / this.getScale() / this.initialTextStyles.fontSize;
17935
- break;
17936
- case "setFontHighlight":
17937
- this.setSelectionFontHighlight(op.fontHighlight);
17938
- break;
17939
- case "setHorisontalAlignment":
17940
- this.setSelectionHorisontalAlignment(op.horisontalAlignment);
17941
- break;
17942
- case "setMaxWidth":
17943
- this.applyMaxWidth(op.maxWidth ?? 0);
17944
- break;
17310
+ if (node2.underline) {
17311
+ styles2.push("underline");
17945
17312
  }
17946
- if (selection) {
17947
- Transforms18.select(this.editor, selection);
17313
+ if (node2["line-through"]) {
17314
+ styles2.push("line-through");
17948
17315
  }
17316
+ acc.push(styles2);
17317
+ return acc;
17318
+ }, []);
17319
+ return findCommonStrings(styles);
17320
+ }
17321
+
17322
+ // src/Items/RichText/editorHelpers/common/setEditorFocus.ts
17323
+ import { ReactEditor as ReactEditor6 } from "slate-react";
17324
+ function setEditorFocus(editor, selectionContext) {
17325
+ if (!editor) {
17326
+ throw new Error("Editor is not initialized");
17949
17327
  }
17950
- applyMaxWidth(maxWidth) {
17951
- this.maxWidth = maxWidth;
17952
- }
17953
- setMaxWidth(maxWidth) {
17954
- this.emit({
17955
- class: "RichText",
17956
- method: "setMaxWidth",
17957
- item: [this.id],
17958
- maxWidth
17959
- });
17960
- }
17961
- setSelectionFontColor(format, selectionContext) {
17962
- this.startOpRecording();
17963
- setSelectionFontColor(this.editor, format, selectionContext);
17964
- return this.stopOpRecordingAndGetOps();
17328
+ if (selectionContext === "EditTextUnderPointer") {
17329
+ ReactEditor6.focus(editor);
17965
17330
  }
17966
- setSelectionLink(link, selection) {
17967
- this.startOpRecording();
17968
- setLink(this.editor, link, selection);
17969
- return this.stopOpRecordingAndGetOps();
17331
+ }
17332
+
17333
+ // src/Items/Transformation/TransformationCommand.ts
17334
+ class TransformationCommand {
17335
+ transformation;
17336
+ operation;
17337
+ reverse;
17338
+ constructor(transformation, operation) {
17339
+ this.transformation = transformation;
17340
+ this.operation = operation;
17341
+ this.reverse = this.getReverse();
17970
17342
  }
17971
- setSelectionFontStyle(style) {
17972
- this.startOpRecording();
17973
- setSelectionFontStyle(this.editor, style);
17974
- return this.stopOpRecordingAndGetOps();
17343
+ merge(op) {
17344
+ this.operation = op;
17345
+ this.reverse = this.getReverse();
17346
+ return this;
17975
17347
  }
17976
- setSelectionFontSize(fontSize, selectionContext) {
17977
- this.startOpRecording();
17978
- const shouldUpdateElement = setSelectionFontSize(this.editor, this.getAutosize(), fontSize, selectionContext);
17979
- if (shouldUpdateElement) {
17980
- this.updateElement();
17348
+ apply() {
17349
+ for (const transformation of this.transformation) {
17350
+ transformation.apply(this.operation);
17981
17351
  }
17982
- return this.stopOpRecordingAndGetOps();
17983
17352
  }
17984
- setSelectionFontHighlight(format, selectionContext) {
17985
- this.startOpRecording();
17986
- setSelectionFontHighlight(this.editor, format, selectionContext);
17987
- return this.stopOpRecordingAndGetOps();
17353
+ revert() {
17354
+ this.reverse.forEach(({ item, operation }) => {
17355
+ item.apply(operation);
17356
+ });
17988
17357
  }
17989
- setSelectionHorisontalAlignment(horisontalAlignment, selectionContext) {
17990
- this.startOpRecording();
17991
- setSelectionHorisontalAlignment(this.editor, horisontalAlignment, selectionContext);
17992
- return this.stopOpRecordingAndGetOps();
17358
+ getReverse() {
17359
+ const op = this.operation;
17360
+ switch (this.operation.method) {
17361
+ case "applyMatrix": {
17362
+ const op2 = this.operation;
17363
+ return this.transformation.map((t3) => {
17364
+ const itemOp = op2.items.find((i) => i.id === t3.getId());
17365
+ if (!itemOp)
17366
+ return { item: t3, operation: op2 };
17367
+ return {
17368
+ item: t3,
17369
+ operation: {
17370
+ class: "Transformation",
17371
+ method: "applyMatrix",
17372
+ items: [{
17373
+ id: t3.getId(),
17374
+ matrix: {
17375
+ translateX: -itemOp.matrix.translateX,
17376
+ translateY: -itemOp.matrix.translateY,
17377
+ scaleX: 1 / itemOp.matrix.scaleX,
17378
+ scaleY: 1 / itemOp.matrix.scaleY,
17379
+ shearX: 0,
17380
+ shearY: 0
17381
+ }
17382
+ }]
17383
+ }
17384
+ };
17385
+ });
17386
+ }
17387
+ case "translateTo":
17388
+ return mapItemsByOperation(this.transformation, (transformation) => {
17389
+ return {
17390
+ ...this.operation,
17391
+ x: transformation.getTranslation().x,
17392
+ y: transformation.getTranslation().y
17393
+ };
17394
+ });
17395
+ case "translateBy": {
17396
+ const op2 = this.operation;
17397
+ return mapItemsByOperation(this.transformation, () => {
17398
+ return {
17399
+ ...this.operation,
17400
+ x: -op2.x,
17401
+ y: -op2.y
17402
+ };
17403
+ });
17404
+ }
17405
+ case "scaleTo":
17406
+ case "scaleToRelativeTo": {
17407
+ return mapItemsByOperation(this.transformation, (transformation) => {
17408
+ return {
17409
+ ...op,
17410
+ x: transformation.getScale().x,
17411
+ y: transformation.getScale().y
17412
+ };
17413
+ });
17414
+ }
17415
+ case "scaleBy":
17416
+ case "scaleByRelativeTo": {
17417
+ const op2 = this.operation;
17418
+ return mapItemsByOperation(this.transformation, () => {
17419
+ return {
17420
+ ...op2,
17421
+ x: 1 / op2.x,
17422
+ y: 1 / op2.y
17423
+ };
17424
+ });
17425
+ }
17426
+ case "scaleByTranslateBy": {
17427
+ const op2 = this.operation;
17428
+ const scaleTransformation = mapItemsByOperation(this.transformation, () => {
17429
+ const scaleX = 1 / op2.scale.x;
17430
+ const scaleY = 1 / op2.scale.y;
17431
+ const translateX = -op2.translate.x;
17432
+ const translateY = -op2.translate.y;
17433
+ return {
17434
+ ...op2,
17435
+ scale: {
17436
+ x: scaleX,
17437
+ y: scaleY
17438
+ },
17439
+ translate: {
17440
+ x: translateX,
17441
+ y: translateY
17442
+ }
17443
+ };
17444
+ });
17445
+ return scaleTransformation;
17446
+ }
17447
+ case "rotateTo":
17448
+ return mapItemsByOperation(this.transformation, (transformation) => {
17449
+ return {
17450
+ ...this.operation,
17451
+ degree: transformation.getRotation()
17452
+ };
17453
+ });
17454
+ case "rotateBy": {
17455
+ const op2 = this.operation;
17456
+ return mapItemsByOperation(this.transformation, () => {
17457
+ return {
17458
+ ...this.operation,
17459
+ degree: -op2.degree
17460
+ };
17461
+ });
17462
+ }
17463
+ case "transformMany": {
17464
+ const { operation, transformation } = this;
17465
+ return transformation.map((currTrans) => {
17466
+ const op2 = operation.items[currTrans.getId()];
17467
+ const m = op2.method === "applyMatrix" ? op2.matrix : op2.method === "scaleByTranslateBy" ? { translateX: -op2.translate.x, translateY: -op2.translate.y, scaleX: 1 / op2.scale.x, scaleY: 1 / op2.scale.y, shearX: 0, shearY: 0 } : { translateX: 0, translateY: 0, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 };
17468
+ return {
17469
+ item: currTrans,
17470
+ operation: {
17471
+ class: "Transformation",
17472
+ method: "applyMatrix",
17473
+ items: [{
17474
+ id: currTrans.getId(),
17475
+ matrix: {
17476
+ translateX: op2.method === "applyMatrix" ? -m.translateX : m.translateX,
17477
+ translateY: op2.method === "applyMatrix" ? -m.translateY : m.translateY,
17478
+ scaleX: op2.method === "applyMatrix" ? 1 / m.scaleX : m.scaleX,
17479
+ scaleY: op2.method === "applyMatrix" ? 1 / m.scaleY : m.scaleY,
17480
+ shearX: 0,
17481
+ shearY: 0
17482
+ }
17483
+ }]
17484
+ }
17485
+ };
17486
+ });
17487
+ }
17488
+ case "locked": {
17489
+ const op2 = this.operation;
17490
+ return mapItemsByOperation(this.transformation, () => {
17491
+ return {
17492
+ ...op2,
17493
+ item: [...op2.item],
17494
+ method: "unlocked",
17495
+ locked: false
17496
+ };
17497
+ });
17498
+ }
17499
+ case "unlocked": {
17500
+ const op2 = this.operation;
17501
+ return mapItemsByOperation(this.transformation, () => {
17502
+ return {
17503
+ ...op2,
17504
+ item: [...op2.item],
17505
+ method: "locked",
17506
+ locked: true
17507
+ };
17508
+ });
17509
+ }
17510
+ default:
17511
+ return [
17512
+ { item: this.transformation[0], operation: this.operation }
17513
+ ];
17514
+ }
17993
17515
  }
17994
- getSelectionMarks() {
17995
- return getSelectionMarks(this.editor);
17516
+ }
17517
+
17518
+ // src/Items/Transformation/TransformationData.ts
17519
+ class DefaultTransformationData {
17520
+ translateX;
17521
+ translateY;
17522
+ scaleX;
17523
+ scaleY;
17524
+ rotate;
17525
+ isLocked;
17526
+ constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, rotate = 0, isLocked = false) {
17527
+ this.translateX = translateX;
17528
+ this.translateY = translateY;
17529
+ this.scaleX = scaleX;
17530
+ this.scaleY = scaleY;
17531
+ this.rotate = rotate;
17532
+ this.isLocked = isLocked;
17996
17533
  }
17997
- handleListMerge() {
17998
- return handleListMerge(this.editor);
17534
+ }
17535
+
17536
+ // src/Items/Transformation/Transformation.ts
17537
+ var defaultData = new DefaultTransformationData;
17538
+
17539
+ class Transformation {
17540
+ id;
17541
+ events;
17542
+ subject = new SubjectOperation;
17543
+ _matrix = new Matrix2;
17544
+ previous = new Matrix2;
17545
+ rotate = defaultData.rotate;
17546
+ isLocked = false;
17547
+ constructor(id = "", events) {
17548
+ this.id = id;
17549
+ this.events = events;
17999
17550
  }
18000
- getListTypeAtSelectionStart() {
18001
- return getListTypeAtSelectionStart(this.editor);
17551
+ getMatrixData() {
17552
+ const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this._matrix;
17553
+ return { translateX, translateY, scaleX, scaleY, shearX, shearY };
18002
17554
  }
18003
- handleSplitListItem() {
18004
- return handleSplitListItem(this.editor);
17555
+ toMatrix() {
17556
+ return this._matrix.copy();
18005
17557
  }
18006
- includesListNode() {
18007
- return this.getText().some((node2) => node2.type === "ol_list" || node2.type === "ul_list");
17558
+ applyToContext(ctx) {
17559
+ this._matrix.applyToContext(ctx);
18008
17560
  }
18009
- toggleListType(targetListType, shouldWrap = true) {
18010
- const result = toggleListType(this.editor, targetListType, shouldWrap);
18011
- this.subject.publish(this);
18012
- return result;
17561
+ getTranslation() {
17562
+ return { x: this._matrix.translateX, y: this._matrix.translateY };
18013
17563
  }
18014
- withAutoList() {
18015
- return withAutoList(this.editor);
17564
+ getScale() {
17565
+ return { x: this._matrix.scaleX, y: this._matrix.scaleY };
18016
17566
  }
18017
- handleWrapIntoNestedList() {
18018
- const result = handleWrapIntoNestedList(this.editor);
18019
- this.subject.publish(this);
18020
- return result;
17567
+ getRotation() {
17568
+ return this.rotate;
18021
17569
  }
18022
- getFirstSelectionLink(selection) {
18023
- return getFirstSelectionLink(this.editor, selection);
17570
+ setLocal(xOrData, y, scaleX, scaleY) {
17571
+ this.previous = this._matrix.copy();
17572
+ if (typeof xOrData === "object") {
17573
+ if (xOrData.translateX !== undefined)
17574
+ this._matrix.translateX = xOrData.translateX;
17575
+ if (xOrData.translateY !== undefined)
17576
+ this._matrix.translateY = xOrData.translateY;
17577
+ if (xOrData.scaleX !== undefined)
17578
+ this._matrix.scaleX = xOrData.scaleX;
17579
+ if (xOrData.scaleY !== undefined)
17580
+ this._matrix.scaleY = xOrData.scaleY;
17581
+ } else {
17582
+ this._matrix.translateX = xOrData;
17583
+ this._matrix.translateY = y;
17584
+ if (scaleX !== undefined)
17585
+ this._matrix.scaleX = scaleX;
17586
+ if (scaleY !== undefined)
17587
+ this._matrix.scaleY = scaleY;
17588
+ }
17589
+ this.subject.publish(this, {
17590
+ class: "Transformation",
17591
+ method: "applyMatrix",
17592
+ items: [{ id: this.id, matrix: this.getMatrixData() }]
17593
+ });
18024
17594
  }
18025
- getText() {
18026
- return this.editor.children;
17595
+ serialize() {
17596
+ return {
17597
+ translateX: this._matrix.translateX,
17598
+ translateY: this._matrix.translateY,
17599
+ scaleX: this._matrix.scaleX,
17600
+ scaleY: this._matrix.scaleY,
17601
+ rotate: this.rotate,
17602
+ isLocked: this.isLocked
17603
+ };
18027
17604
  }
18028
- getTextParagraphs(lines) {
18029
- const newlines = [];
18030
- lines.forEach((line) => {
18031
- if (!this.getAutosize()) {
18032
- newlines.push(this.createParagraphNode(line));
18033
- return;
18034
- }
18035
- const validText = this.getValidText(line, newlines);
18036
- if (validText.length > 0) {
18037
- newlines.push(this.createParagraphNode(validText));
18038
- } else {
18039
- this.getOnLimitReached()();
18040
- }
17605
+ deserialize(data) {
17606
+ this.previous = this._matrix.copy();
17607
+ if (data.translateX) {
17608
+ this._matrix.translateX = data.translateX;
17609
+ }
17610
+ if (data.translateY) {
17611
+ this._matrix.translateY = data.translateY;
17612
+ }
17613
+ if (data.scaleX) {
17614
+ this._matrix.scaleX = data.scaleX;
17615
+ }
17616
+ if (data.scaleY) {
17617
+ this._matrix.scaleY = data.scaleY;
17618
+ }
17619
+ if (data.isLocked) {
17620
+ this.isLocked = data.isLocked;
17621
+ }
17622
+ if (data.rotate) {
17623
+ this.rotate = data.rotate;
17624
+ }
17625
+ this.subject.publish(this, {
17626
+ class: "Transformation",
17627
+ method: "deserialize",
17628
+ item: [this.id],
17629
+ data
18041
17630
  });
18042
- return newlines;
17631
+ return this;
18043
17632
  }
18044
- getValidText(line, newlines) {
18045
- let left = 0;
18046
- let right = line.length;
18047
- let validText = "";
18048
- while (left <= right) {
18049
- const mid = Math.floor((left + right) / 2);
18050
- const currentText = line.slice(0, mid);
18051
- const testLine = this.createParagraphNode(currentText);
18052
- const nodes = [...newlines, testLine];
18053
- this.applyAutoSizeScale(this.calcAutoSize(nodes), nodes);
18054
- const relativeFontSize = this.getFontSize() / this.getMatrixScale();
18055
- if (relativeFontSize >= 10) {
18056
- validText = currentText;
18057
- left = mid + 1;
18058
- } else {
18059
- right = mid - 1;
18060
- }
18061
- }
18062
- return validText;
17633
+ copy(id) {
17634
+ const { translateX, translateY, scaleX, scaleY } = this._matrix;
17635
+ const { rotate } = this;
17636
+ return new Transformation(id || "", this.events).deserialize({
17637
+ translateX,
17638
+ translateY,
17639
+ scaleX,
17640
+ scaleY,
17641
+ rotate,
17642
+ isLocked: false
17643
+ });
18063
17644
  }
18064
- createParagraphNode(text3) {
18065
- return createParagraphNode(text3, this.editor, this.horisontalAlignment);
17645
+ getInverse() {
17646
+ const copy2 = this.copy();
17647
+ copy2._matrix.invert();
17648
+ return copy2;
18066
17649
  }
18067
- insertCopiedText(text3) {
18068
- const lines = this.getTextParagraphs(text3.split(/\r\n|\r|\n/));
18069
- if (this.isLimitReached(lines)) {
18070
- return true;
18071
- }
18072
- insertCopiedNodes(this.editor, lines);
18073
- this.subject.publish(this);
18074
- return true;
17650
+ getId() {
17651
+ return this.id;
18075
17652
  }
18076
- checkIsAutoSizeTextScaleAllowed(nodes) {
18077
- const existingNodes = this.getBlockNodes();
18078
- const textScale = this.calcAutoSize([...existingNodes, ...nodes]);
18079
- const marks = this.getSelectionMarks();
18080
- const fontSize = marks?.fontSize ?? this.initialTextStyles.fontSize;
18081
- return Math.ceil(textScale * (fontSize === "auto" ? 14 : fontSize)) / this.getMatrixScale() > 4;
17653
+ setId(id) {
17654
+ this.id = id;
18082
17655
  }
18083
- isLimitReached(nodes) {
18084
- if (this.getAutosize()) {
18085
- if (!this.checkIsAutoSizeTextScaleAllowed(nodes)) {
18086
- this.getOnLimitReached()();
18087
- return true;
18088
- }
17656
+ emit(operation) {
17657
+ if (this.events) {
17658
+ const command = new TransformationCommand([this], operation);
17659
+ command.apply();
17660
+ this.events.emit(operation, command);
17661
+ } else {
17662
+ this.apply(operation);
18089
17663
  }
18090
- return false;
18091
17664
  }
18092
- insertCopiedNodes(nodes) {
18093
- if (this.isLimitReached(nodes)) {
18094
- return true;
18095
- }
18096
- insertCopiedNodes(this.editor, nodes);
18097
- this.subject.publish(this);
18098
- return true;
17665
+ emitMatrix(matrix, timeStamp) {
17666
+ this.emit({
17667
+ class: "Transformation",
17668
+ method: "applyMatrix",
17669
+ items: [{ id: this.id, matrix }],
17670
+ timeStamp
17671
+ });
18099
17672
  }
18100
- hasTextInSelection() {
18101
- return hasTextInSelection(this.editor);
17673
+ translateTo(x, y, timeStamp) {
17674
+ if (!this.id) {}
17675
+ this.emitMatrix({
17676
+ translateX: x - this._matrix.translateX,
17677
+ translateY: y - this._matrix.translateY,
17678
+ scaleX: 1,
17679
+ scaleY: 1,
17680
+ shearX: 0,
17681
+ shearY: 0
17682
+ }, timeStamp);
18102
17683
  }
18103
- getSelection() {
18104
- return JSON.parse(JSON.stringify(this.editor.selection));
17684
+ translateBy(x, y, timeStamp) {
17685
+ if (!this.id) {}
17686
+ if (x === 0 && y === 0) {
17687
+ return;
17688
+ }
17689
+ this.emitMatrix({
17690
+ translateX: x,
17691
+ translateY: y,
17692
+ scaleX: 1,
17693
+ scaleY: 1,
17694
+ shearX: 0,
17695
+ shearY: 0
17696
+ }, timeStamp);
18105
17697
  }
18106
- splitNode() {
18107
- Transforms18.splitNodes(this.editor, { always: true });
17698
+ scaleTo(x, y, timeStamp) {
17699
+ this.emitMatrix({
17700
+ translateX: 0,
17701
+ translateY: 0,
17702
+ scaleX: x / this._matrix.scaleX,
17703
+ scaleY: y / this._matrix.scaleY,
17704
+ shearX: 0,
17705
+ shearY: 0
17706
+ }, timeStamp);
18108
17707
  }
18109
- getBlockNodes() {
18110
- return this.editor.children;
17708
+ scaleBy(x, y, timeStamp) {
17709
+ if (x === 0 && y === 0) {
17710
+ return;
17711
+ }
17712
+ this.emitMatrix({
17713
+ translateX: 0,
17714
+ translateY: 0,
17715
+ scaleX: x,
17716
+ scaleY: y,
17717
+ shearX: 0,
17718
+ shearY: 0
17719
+ }, timeStamp);
18111
17720
  }
18112
- isEmpty() {
18113
- return isTextEmpty(this.editor.children);
17721
+ scaleByTranslateBy(scale, translate, timeStamp) {
17722
+ if (scale.x === 0 && scale.y === 0 && translate.x === 0 && translate.y === 0) {
17723
+ return;
17724
+ }
17725
+ this.emitMatrix({
17726
+ translateX: translate.x,
17727
+ translateY: translate.y,
17728
+ scaleX: scale.x,
17729
+ scaleY: scale.y,
17730
+ shearX: 0,
17731
+ shearY: 0
17732
+ }, timeStamp);
18114
17733
  }
18115
- clearText() {
18116
- clearText(this.editor);
17734
+ rotateTo(degree, timeStamp) {
17735
+ this.emit({
17736
+ class: "Transformation",
17737
+ method: "rotateTo",
17738
+ item: [this.id],
17739
+ degree,
17740
+ timeStamp
17741
+ });
18117
17742
  }
18118
- addText(text3) {
18119
- this.editor.apply({
18120
- type: "insert_text",
18121
- text: text3,
18122
- path: [0, 0],
18123
- offset: 0
17743
+ rotateBy(degree, timeStamp) {
17744
+ this.emit({
17745
+ class: "Transformation",
17746
+ method: "rotateBy",
17747
+ item: [this.id],
17748
+ degree,
17749
+ timeStamp
18124
17750
  });
18125
17751
  }
18126
- selectWholeText() {
18127
- selectWholeText(this.editor);
17752
+ scaleToRelativeTo(x, y, _point, timeStamp) {
17753
+ this.emitMatrix({
17754
+ translateX: 0,
17755
+ translateY: 0,
17756
+ scaleX: x / this._matrix.scaleX,
17757
+ scaleY: y / this._matrix.scaleY,
17758
+ shearX: 0,
17759
+ shearY: 0
17760
+ }, timeStamp);
18128
17761
  }
18129
- moveCursorToEndOfTheText(delay = 10) {
18130
- moveCursorToEndOfTheText(this.editor, delay);
17762
+ scaleByRelativeTo(x, y, point3, timeStamp) {
17763
+ const { scaleX: sx0, scaleY: sy0, translateX: tx0, translateY: ty0 } = this._matrix;
17764
+ const newSx = sx0 * x;
17765
+ const newSy = sy0 * y;
17766
+ this.emitMatrix({
17767
+ translateX: -point3.x * newSx + point3.x - tx0,
17768
+ translateY: -point3.y * newSy + point3.y - ty0,
17769
+ scaleX: x,
17770
+ scaleY: y,
17771
+ shearX: 0,
17772
+ shearY: 0
17773
+ }, timeStamp);
18131
17774
  }
18132
- }
18133
-
18134
- // src/Items/RichText/findOptimalMaxWidthForTextAutoSize.ts
18135
- function findOptimalMaxWidthForTextAutoSize(text3, containerWidth, containerHeight, initialMaxWidth, tolerance = 0.05) {
18136
- const targetRatio = containerWidth / containerHeight;
18137
- let low = 0;
18138
- let high = initialMaxWidth * 3;
18139
- let closestRatioDifference = Infinity;
18140
- let closestWidth = initialMaxWidth;
18141
- let closestHeight = initialMaxWidth / targetRatio;
18142
- const iterations = Math.min(Math.max(3, containerWidth / 80), 15);
18143
- for (let i = 0;i < iterations && low < high; i += 1) {
18144
- const mid = (low + high) / 2;
18145
- const { width: calcWidth, height: calcHeight } = getBlockNodes(text3, mid);
18146
- const currentRatio = calcWidth / calcHeight;
18147
- const ratioDifference = Math.abs(currentRatio - targetRatio);
18148
- if (ratioDifference < closestRatioDifference) {
18149
- closestRatioDifference = ratioDifference;
18150
- closestWidth = calcWidth;
18151
- closestHeight = calcHeight;
18152
- }
18153
- if (ratioDifference <= tolerance) {
18154
- break;
18155
- }
18156
- if (currentRatio < targetRatio) {
18157
- low = mid + 1;
17775
+ setIsLocked(isLocked, timestamp) {
17776
+ if (isLocked) {
17777
+ this.emit({
17778
+ class: "Transformation",
17779
+ method: "locked",
17780
+ item: [this.id],
17781
+ locked: true,
17782
+ timestamp
17783
+ });
18158
17784
  } else {
18159
- high = mid - 1;
17785
+ this.emit({
17786
+ class: "Transformation",
17787
+ method: "unlocked",
17788
+ item: [this.id],
17789
+ locked: false,
17790
+ timestamp
17791
+ });
18160
17792
  }
18161
17793
  }
18162
- const scale = Math.min(containerWidth / closestWidth, containerHeight / closestHeight);
18163
- return {
18164
- bestMaxWidth: initialMaxWidth / scale,
18165
- bestMaxHeight: initialMaxWidth / targetRatio / scale
18166
- };
18167
- }
18168
-
18169
- // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontColor.ts
18170
- import { Editor as Editor28 } from "slate";
18171
- function applySelectionFontColor(editor, fontColor) {
18172
- if (!editor) {
18173
- throw new Error("Editor is not initialized");
17794
+ apply(op) {
17795
+ this.previous = this._matrix.copy();
17796
+ switch (op.method) {
17797
+ case "applyMatrix": {
17798
+ const itemOp = op.items.find((i) => i.id === this.id);
17799
+ if (itemOp) {
17800
+ this._matrix.scale(itemOp.matrix.scaleX, itemOp.matrix.scaleY);
17801
+ this._matrix.translate(itemOp.matrix.translateX, itemOp.matrix.translateY);
17802
+ }
17803
+ break;
17804
+ }
17805
+ case "translateTo":
17806
+ this.applyTranslateTo(op.x, op.y);
17807
+ break;
17808
+ case "translateBy":
17809
+ this.applyTranslateBy(op.x, op.y);
17810
+ break;
17811
+ case "scaleTo":
17812
+ this.applyScaleTo(op.x, op.y);
17813
+ break;
17814
+ case "scaleBy":
17815
+ this.applyScaleBy(op.x, op.y);
17816
+ break;
17817
+ case "scaleToRelativeTo":
17818
+ this.applyScaleToRelativeTo(op.x, op.y, op.point);
17819
+ break;
17820
+ case "scaleByRelativeTo":
17821
+ this.applyScaleByRelativeTo(op.x, op.y, op.point);
17822
+ break;
17823
+ case "scaleByTranslateBy":
17824
+ this.applyScaleByTranslateBy(op.scale, op.translate);
17825
+ break;
17826
+ case "rotateTo":
17827
+ this.applyRotateTo(op.degree);
17828
+ break;
17829
+ case "rotateBy":
17830
+ this.applyRotateBy(op.degree);
17831
+ break;
17832
+ case "transformMany":
17833
+ this.applyTransformMany(op.items[this.id]);
17834
+ break;
17835
+ case "locked":
17836
+ this.applyLocked(op.locked);
17837
+ break;
17838
+ case "unlocked":
17839
+ this.applyUnlocked(op.locked);
17840
+ break;
17841
+ default:
17842
+ return;
17843
+ }
17844
+ this.subject.publish(this, op);
18174
17845
  }
18175
- const marks = getSelectionMarks(editor);
18176
- if (!marks) {
18177
- return;
17846
+ applyTranslateTo(x, y) {
17847
+ this._matrix.translateX = x;
17848
+ this._matrix.translateY = y;
18178
17849
  }
18179
- Editor28.addMark(editor, "fontColor", fontColor);
18180
- }
18181
-
18182
- // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontSize.ts
18183
- import { Editor as Editor29, Transforms as Transforms19 } from "slate";
18184
- function applySelectionFontSize(editor, fontSize, selectionContext) {
18185
- const size = fontSize;
18186
- if (typeof size !== "number") {
18187
- return;
17850
+ applyTranslateBy(x, y) {
17851
+ this._matrix.translate(x, y);
18188
17852
  }
18189
- if (!editor) {
18190
- throw new Error("Editor is not initialized");
17853
+ applyScaleTo(x, y) {
17854
+ this._matrix.scaleX = x;
17855
+ this._matrix.scaleY = y;
18191
17856
  }
18192
- const selection = editor.selection;
18193
- const marks = getSelectionMarks(editor);
18194
- if (!marks) {
18195
- return;
17857
+ applyScaleBy(x, y) {
17858
+ this._matrix.scale(x, y);
18196
17859
  }
18197
- if (JSON.stringify(selection?.anchor) === JSON.stringify(selection?.focus)) {
18198
- Transforms19.select(editor, {
18199
- anchor: Editor29.start(editor, []),
18200
- focus: Editor29.end(editor, [])
18201
- });
17860
+ applyScaleByTranslateBy(scale, translate) {
17861
+ this._matrix.scale(scale.x, scale.y);
17862
+ this._matrix.translate(translate.x, translate.y);
18202
17863
  }
18203
- Editor29.addMark(editor, "fontSize", size);
18204
- if (selectionContext === "EditTextUnderPointer") {}
18205
- }
18206
-
18207
- // src/Items/RichText/editorHelpers/common/getSelectedBlockNode.ts
18208
- import { Editor as Editor30, Element as Element5 } from "slate";
18209
- function getSelectedBlockNode(editor) {
18210
- const { selection } = editor;
18211
- if (!selection) {
18212
- return null;
17864
+ applyTransformMany(op) {
17865
+ if (op.method === "applyMatrix") {
17866
+ this._matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
17867
+ this._matrix.translate(op.matrix.translateX, op.matrix.translateY);
17868
+ } else if (op.method === "scaleByTranslateBy") {
17869
+ this.applyScaleByTranslateBy(op.scale, op.translate);
17870
+ } else if (op.method === "scaleBy") {
17871
+ this.applyScaleBy(op.x, op.y);
17872
+ } else if (op.method === "translateBy") {
17873
+ this.applyTranslateBy(op.x, op.y);
17874
+ } else if (op.method === "translateTo") {
17875
+ this.applyTranslateTo(op.x, op.y);
17876
+ }
18213
17877
  }
18214
- const [node2] = Editor30.node(editor, selection);
18215
- if (Editor30.isEditor(node2) || !Element5.isElement(node2)) {
18216
- return null;
17878
+ applyScaleByRelativeTo(x, y, point3) {
17879
+ const scaleX = this._matrix.scaleX * x;
17880
+ const scaleY = this._matrix.scaleY * y;
17881
+ this._matrix.translateX = -point3.x * scaleX + point3.x;
17882
+ this._matrix.translateY = -point3.y * scaleY + point3.y;
17883
+ this._matrix.scaleX = scaleX;
17884
+ this._matrix.scaleY = scaleY;
18217
17885
  }
18218
- return node2;
18219
- }
18220
-
18221
- // src/Items/RichText/utils.ts
18222
- function findCommonStrings(arrays) {
18223
- if (arrays.length === 0) {
18224
- return [];
17886
+ applyScaleToRelativeTo(x, y, point3) {
17887
+ this.applyTranslateBy(-point3.x, -point3.y);
17888
+ this.applyScaleTo(x, y);
17889
+ this.applyTranslateBy(point3.x, point3.y);
18225
17890
  }
18226
- let commonStrings = arrays[0];
18227
- for (let i = 1;i < arrays.length; i++) {
18228
- commonStrings = commonStrings.filter((str) => arrays[i].includes(str));
17891
+ applyRotateTo(degree) {
17892
+ if (degree > 0) {
17893
+ while (degree > 360) {
17894
+ degree -= 360;
17895
+ }
17896
+ if (degree === 360) {
17897
+ degree = 0;
17898
+ }
17899
+ } else {
17900
+ while (degree < -360) {
17901
+ degree += 360;
17902
+ }
17903
+ if (degree === -360) {
17904
+ degree = 0;
17905
+ }
17906
+ }
17907
+ this.rotate = degree;
18229
17908
  }
18230
- return commonStrings;
18231
- }
18232
-
18233
- // src/Items/RichText/editorHelpers/common/getSelectionStyles.ts
18234
- function getSelectionStyles(editor) {
18235
- const { selection } = editor;
18236
- if (!selection) {
18237
- return;
17909
+ applyRotateBy(degree) {
17910
+ this.applyRotateTo(this.rotate + degree);
18238
17911
  }
18239
- const nodes = getAllTextNodesInSelection(editor);
18240
- const styles = nodes.reduce((acc, node2) => {
18241
- const styles2 = [];
18242
- if (node2.text === "") {
18243
- return acc;
18244
- }
18245
- if (node2.bold) {
18246
- styles2.push("bold");
18247
- }
18248
- if (node2.italic) {
18249
- styles2.push("italic");
18250
- }
18251
- if (node2.underline) {
18252
- styles2.push("underline");
18253
- }
18254
- if (node2["line-through"]) {
18255
- styles2.push("line-through");
18256
- }
18257
- acc.push(styles2);
18258
- return acc;
18259
- }, []);
18260
- return findCommonStrings(styles);
18261
- }
18262
-
18263
- // src/Items/RichText/editorHelpers/common/setEditorFocus.ts
18264
- import { ReactEditor as ReactEditor6 } from "slate-react";
18265
- function setEditorFocus(editor, selectionContext) {
18266
- if (!editor) {
18267
- throw new Error("Editor is not initialized");
17912
+ applyLocked(locked) {
17913
+ this.isLocked = locked;
18268
17914
  }
18269
- if (selectionContext === "EditTextUnderPointer") {
18270
- ReactEditor6.focus(editor);
17915
+ applyUnlocked(locked) {
17916
+ this.isLocked = locked;
18271
17917
  }
18272
17918
  }
18273
17919
 
@@ -18607,6 +18253,146 @@ function applyRedo(board, operation) {
18607
18253
  addOperationHandler("undo", applyUndo);
18608
18254
  addOperationHandler("redo", applyRedo);
18609
18255
 
18256
+ // src/Items/Connector/ConnectorCommand.ts
18257
+ class ConnectorCommand {
18258
+ connector;
18259
+ operation;
18260
+ reverse;
18261
+ constructor(connector, operation) {
18262
+ this.connector = connector;
18263
+ this.operation = operation;
18264
+ this.reverse = this.getReverse();
18265
+ }
18266
+ merge(op) {
18267
+ this.operation = op;
18268
+ return this;
18269
+ }
18270
+ apply() {
18271
+ for (const connector of this.connector) {
18272
+ connector.apply(this.operation);
18273
+ }
18274
+ }
18275
+ revert() {
18276
+ for (const { item, operation } of this.reverse) {
18277
+ item.apply(operation);
18278
+ }
18279
+ }
18280
+ getReverse() {
18281
+ const reverse = [];
18282
+ switch (this.operation.method) {
18283
+ case "setStartPoint":
18284
+ for (const connector of this.connector) {
18285
+ reverse.push({
18286
+ item: connector,
18287
+ operation: {
18288
+ ...this.operation,
18289
+ startPointData: connector.getStartPoint().serialize()
18290
+ }
18291
+ });
18292
+ }
18293
+ break;
18294
+ case "setEndPoint":
18295
+ for (const connector of this.connector) {
18296
+ reverse.push({
18297
+ item: connector,
18298
+ operation: {
18299
+ ...this.operation,
18300
+ endPointData: connector.getEndPoint().serialize()
18301
+ }
18302
+ });
18303
+ }
18304
+ break;
18305
+ case "setMiddlePoint":
18306
+ for (const connector of this.connector) {
18307
+ const middlePoint = connector.getMiddlePoint();
18308
+ reverse.push({
18309
+ item: connector,
18310
+ operation: {
18311
+ ...this.operation,
18312
+ middlePointData: middlePoint ? middlePoint.serialize() : null
18313
+ }
18314
+ });
18315
+ }
18316
+ break;
18317
+ case "setStartPointerStyle":
18318
+ for (const connector of this.connector) {
18319
+ reverse.push({
18320
+ item: connector,
18321
+ operation: {
18322
+ ...this.operation,
18323
+ startPointerStyle: connector.getStartPointerStyle()
18324
+ }
18325
+ });
18326
+ }
18327
+ break;
18328
+ case "setEndPointerStyle":
18329
+ for (const connector of this.connector) {
18330
+ reverse.push({
18331
+ item: connector,
18332
+ operation: {
18333
+ ...this.operation,
18334
+ endPointerStyle: connector.getEndPointerStyle()
18335
+ }
18336
+ });
18337
+ }
18338
+ break;
18339
+ case "setLineStyle":
18340
+ for (const connector of this.connector) {
18341
+ reverse.push({
18342
+ item: connector,
18343
+ operation: {
18344
+ ...this.operation,
18345
+ lineStyle: connector.getLineStyle()
18346
+ }
18347
+ });
18348
+ }
18349
+ break;
18350
+ case "setBorderStyle":
18351
+ for (const connector of this.connector) {
18352
+ reverse.push({
18353
+ item: connector,
18354
+ operation: {
18355
+ ...this.operation,
18356
+ borderStyle: connector.getBorderStyle()
18357
+ }
18358
+ });
18359
+ }
18360
+ break;
18361
+ case "setLineWidth":
18362
+ for (const connector of this.connector) {
18363
+ reverse.push({
18364
+ item: connector,
18365
+ operation: {
18366
+ ...this.operation,
18367
+ lineWidth: connector.getLineWidth()
18368
+ }
18369
+ });
18370
+ }
18371
+ break;
18372
+ case "setLineColor":
18373
+ for (const connector of this.connector) {
18374
+ reverse.push({
18375
+ item: connector,
18376
+ operation: {
18377
+ ...this.operation,
18378
+ lineColor: connector.getLineColor()
18379
+ }
18380
+ });
18381
+ }
18382
+ break;
18383
+ case "switchPointers":
18384
+ for (const connector of this.connector) {
18385
+ reverse.push({
18386
+ item: connector,
18387
+ operation: this.operation
18388
+ });
18389
+ }
18390
+ break;
18391
+ }
18392
+ return reverse;
18393
+ }
18394
+ }
18395
+
18610
18396
  // src/Items/Drawing/DrawingCommand.ts
18611
18397
  class DrawingCommand {
18612
18398
  item;
@@ -18774,7 +18560,6 @@ class FrameCommand {
18774
18560
  }
18775
18561
  }
18776
18562
  }
18777
-
18778
18563
  // src/Items/Comment/CommentCommand.ts
18779
18564
  class CommentCommand {
18780
18565
  comment;
@@ -18852,9 +18637,15 @@ class CommentCommand {
18852
18637
  }
18853
18638
  }
18854
18639
  }
18855
- // node_modules/uuid/dist/esm-browser/native.js
18856
- var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
18857
- var native_default = { randomUUID };
18640
+
18641
+ // node_modules/uuid/dist/esm-browser/stringify.js
18642
+ var byteToHex = [];
18643
+ for (let i = 0;i < 256; ++i) {
18644
+ byteToHex.push((i + 256).toString(16).slice(1));
18645
+ }
18646
+ function unsafeStringify(arr2, offset = 0) {
18647
+ return (byteToHex[arr2[offset + 0]] + byteToHex[arr2[offset + 1]] + byteToHex[arr2[offset + 2]] + byteToHex[arr2[offset + 3]] + "-" + byteToHex[arr2[offset + 4]] + byteToHex[arr2[offset + 5]] + "-" + byteToHex[arr2[offset + 6]] + byteToHex[arr2[offset + 7]] + "-" + byteToHex[arr2[offset + 8]] + byteToHex[arr2[offset + 9]] + "-" + byteToHex[arr2[offset + 10]] + byteToHex[arr2[offset + 11]] + byteToHex[arr2[offset + 12]] + byteToHex[arr2[offset + 13]] + byteToHex[arr2[offset + 14]] + byteToHex[arr2[offset + 15]]).toLowerCase();
18648
+ }
18858
18649
 
18859
18650
  // node_modules/uuid/dist/esm-browser/rng.js
18860
18651
  var getRandomValues;
@@ -18869,14 +18660,9 @@ function rng() {
18869
18660
  return getRandomValues(rnds8);
18870
18661
  }
18871
18662
 
18872
- // node_modules/uuid/dist/esm-browser/stringify.js
18873
- var byteToHex = [];
18874
- for (let i = 0;i < 256; ++i) {
18875
- byteToHex.push((i + 256).toString(16).slice(1));
18876
- }
18877
- function unsafeStringify(arr2, offset = 0) {
18878
- return (byteToHex[arr2[offset + 0]] + byteToHex[arr2[offset + 1]] + byteToHex[arr2[offset + 2]] + byteToHex[arr2[offset + 3]] + "-" + byteToHex[arr2[offset + 4]] + byteToHex[arr2[offset + 5]] + "-" + byteToHex[arr2[offset + 6]] + byteToHex[arr2[offset + 7]] + "-" + byteToHex[arr2[offset + 8]] + byteToHex[arr2[offset + 9]] + "-" + byteToHex[arr2[offset + 10]] + byteToHex[arr2[offset + 11]] + byteToHex[arr2[offset + 12]] + byteToHex[arr2[offset + 13]] + byteToHex[arr2[offset + 14]] + byteToHex[arr2[offset + 15]]).toLowerCase();
18879
- }
18663
+ // node_modules/uuid/dist/esm-browser/native.js
18664
+ var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
18665
+ var native_default = { randomUUID };
18880
18666
 
18881
18667
  // node_modules/uuid/dist/esm-browser/v4.js
18882
18668
  function v4(options, buf, offset) {
@@ -20408,18 +20194,25 @@ class RTreeIndex {
20408
20194
  }
20409
20195
 
20410
20196
  // src/SpatialIndex/LayeredIndex/index.ts
20411
- class Container extends Mbr {
20197
+ class Container {
20412
20198
  id;
20413
20199
  item;
20414
20200
  layer;
20415
20201
  zIndex;
20202
+ left;
20203
+ top;
20204
+ right;
20205
+ bottom;
20416
20206
  constructor(id, item, layer, zIndex) {
20417
- const rect = item.getMbrWithChildren();
20418
- super(rect.left, rect.top, rect.right, rect.bottom);
20419
20207
  this.id = id;
20420
20208
  this.item = item;
20421
20209
  this.layer = layer;
20422
20210
  this.zIndex = zIndex;
20211
+ const rect = item.getMbrWithChildren();
20212
+ this.left = rect.left;
20213
+ this.top = rect.top;
20214
+ this.right = rect.right;
20215
+ this.bottom = rect.bottom;
20423
20216
  }
20424
20217
  }
20425
20218
 
@@ -21798,7 +21591,7 @@ class RichText extends BaseItem {
21798
21591
  parent = "Board";
21799
21592
  subject = new Subject;
21800
21593
  editor;
21801
- editorTransforms = Transforms20;
21594
+ editorTransforms = Transforms21;
21802
21595
  editorEditor = Editor31;
21803
21596
  isContainerSet = false;
21804
21597
  isRenderEnabled = true;
@@ -22421,9 +22214,9 @@ class RichText extends BaseItem {
22421
22214
  }
22422
22215
  restoreSelection(selection) {
22423
22216
  if (selection) {
22424
- Transforms20.select(this.editor.editor, selection);
22217
+ Transforms21.select(this.editor.editor, selection);
22425
22218
  } else {
22426
- Transforms20.deselect(this.editor.editor);
22219
+ Transforms21.deselect(this.editor.editor);
22427
22220
  }
22428
22221
  }
22429
22222
  deserialize(data) {
@@ -22706,6 +22499,252 @@ class RichText extends BaseItem {
22706
22499
  return this.prevMbr;
22707
22500
  }
22708
22501
  }
22502
+
22503
+ // src/Items/Mbr/updateRects.ts
22504
+ function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
22505
+ const { selection, camera } = board;
22506
+ const panel = ref.current;
22507
+ const selectionMbr = mbr ?? selection.getMbr();
22508
+ const selectionItems = selection.items;
22509
+ const richTextSelection = selectionItems.getSingle() instanceof RichText ? selectionItems.list()[0] : undefined;
22510
+ if (panel && selectionMbr) {
22511
+ if (fit === "contextPanel") {
22512
+ const panelRect = getContextPanelRect(selectionMbr, camera, panel, !!richTextSelection, horizontalOffset, verticalOffset);
22513
+ return panelRect;
22514
+ }
22515
+ if (fit === "linkToBtn") {
22516
+ if (!mbr) {
22517
+ return null;
22518
+ }
22519
+ const panelRect = fitLinkToBtn(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
22520
+ return panelRect;
22521
+ }
22522
+ if (fit === "comment") {
22523
+ if (!mbr) {
22524
+ return null;
22525
+ }
22526
+ const panelRect = fitComment(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
22527
+ return panelRect;
22528
+ }
22529
+ if (fit === "threadPanel") {
22530
+ if (!mbr) {
22531
+ return null;
22532
+ }
22533
+ const panelRect = fitThreadPanel(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
22534
+ return panelRect;
22535
+ }
22536
+ if (fit === "boardMenu") {
22537
+ if (!mbr) {
22538
+ return null;
22539
+ }
22540
+ const panelRect = fitBoardMenu(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
22541
+ return panelRect;
22542
+ }
22543
+ if (fit === "hyperLink") {
22544
+ if (!mbr) {
22545
+ return null;
22546
+ }
22547
+ const panelRect = fitHyperLink(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), camera.window.getMbr(), verticalOffset);
22548
+ return panelRect;
22549
+ }
22550
+ }
22551
+ return null;
22552
+ }
22553
+ function getContextPanelRect(selectionMbr, camera, panel, toLeft, horizontalOffset, verticalOffset) {
22554
+ const transformedMbr = selectionMbr.getTransformed(camera.getMatrix());
22555
+ const windowMbr = camera.window.getMbr();
22556
+ const panelRectFromDom = Mbr.fromDomRect(panel.getBoundingClientRect());
22557
+ const panelRect = toLeft ? fitContextPanelToLeft(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset) : fitContextPanelToCenter(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset);
22558
+ return panelRect;
22559
+ }
22560
+ function fitContextPanelToLeft(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
22561
+ const panelHeight = panel.getHeight();
22562
+ const panelWidth = panel.getWidth();
22563
+ const newPanel = new Mbr;
22564
+ const topSpace = selectionMbr.top - view.top;
22565
+ const hasEnoughTopSpace = topSpace >= panelHeight + verticalOffset;
22566
+ if (hasEnoughTopSpace) {
22567
+ newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
22568
+ if (newPanel.top < view.top) {
22569
+ newPanel.top = view.top + verticalOffset;
22570
+ }
22571
+ } else {
22572
+ const usePanelTop = panel.top > 1 && panel.top > selectionMbr.top + verticalOffset;
22573
+ newPanel.top = usePanelTop ? panel.top : selectionMbr.bottom + verticalOffset;
22574
+ const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
22575
+ const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
22576
+ if (isOverflowingBottom || isLargeOffsetForRichText) {
22577
+ newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
22578
+ }
22579
+ }
22580
+ newPanel.bottom = newPanel.top + panelHeight;
22581
+ fitContextPanelInViewRect(newPanel, view, verticalOffset);
22582
+ const itemMbr = selectionMbr.getMbr();
22583
+ newPanel.left = itemMbr.left;
22584
+ adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
22585
+ return newPanel;
22586
+ }
22587
+ function fitContextPanelToCenter(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
22588
+ const panelHeight = panel.getHeight();
22589
+ const panelWidth = panel.getWidth();
22590
+ const newPanel = new Mbr;
22591
+ const topSpace = selectionMbr.top - view.top;
22592
+ const bottomSpace = view.bottom - selectionMbr.bottom;
22593
+ const shouldPlaceAbove = topSpace > bottomSpace - panelHeight;
22594
+ if (shouldPlaceAbove) {
22595
+ newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
22596
+ if (newPanel.top < view.top) {
22597
+ newPanel.top = view.top + verticalOffset;
22598
+ }
22599
+ } else {
22600
+ newPanel.top = selectionMbr.bottom + verticalOffset;
22601
+ const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
22602
+ const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
22603
+ if (isOverflowingBottom || isLargeOffsetForRichText) {
22604
+ newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
22605
+ }
22606
+ }
22607
+ newPanel.bottom = newPanel.top + panelHeight;
22608
+ fitContextPanelInViewRect(newPanel, view, verticalOffset);
22609
+ const itemCenter = selectionMbr.getCenter();
22610
+ newPanel.left = itemCenter.x - panelWidth / 2;
22611
+ adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
22612
+ return newPanel;
22613
+ }
22614
+ function adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset) {
22615
+ newPanel.right = newPanel.left + panelWidth;
22616
+ if (newPanel.left < view.left + horizontalOffset) {
22617
+ newPanel.left = view.left + horizontalOffset;
22618
+ } else if (newPanel.right + horizontalOffset > view.right) {
22619
+ newPanel.left = view.right - (panelWidth + horizontalOffset);
22620
+ }
22621
+ newPanel.right = newPanel.left + panelWidth;
22622
+ }
22623
+ function fitContextPanelInViewRect(panel, view, verticalOffset) {
22624
+ const panelHeight = panel.getHeight();
22625
+ if (panel.top <= view.top + verticalOffset) {
22626
+ panel.top = view.top + 2 * verticalOffset;
22627
+ panel.bottom = panel.top + panelHeight;
22628
+ }
22629
+ if (panel.bottom >= view.bottom - verticalOffset) {
22630
+ panel.bottom = view.bottom - 2 * verticalOffset;
22631
+ panel.top = panel.bottom - panelHeight;
22632
+ }
22633
+ }
22634
+ function fitLinkToBtn(itemMbr, view, panel, verticalOffset = -2, horizontalOffset = -2) {
22635
+ const panelHeight = panel.getHeight();
22636
+ const newPanel = new Mbr;
22637
+ newPanel.top = itemMbr.top - panelHeight - verticalOffset;
22638
+ newPanel.top = newPanel.top + panelHeight;
22639
+ newPanel.bottom = newPanel.top + panelHeight * 2;
22640
+ const panelWidth = panel.getWidth();
22641
+ newPanel.left = itemMbr.right - panelWidth + horizontalOffset;
22642
+ return newPanel;
22643
+ }
22644
+ function fitHyperLink(linkMbr, panel, view, offset = 20) {
22645
+ const panelHeight = panel.getHeight();
22646
+ const newPanel = new Mbr;
22647
+ newPanel.top = linkMbr.bottom;
22648
+ newPanel.bottom = panelHeight + newPanel.top;
22649
+ const panelWidth = panel.getWidth();
22650
+ newPanel.left = linkMbr.left;
22651
+ newPanel.right = newPanel.left + panelWidth;
22652
+ return newPanel;
22653
+ }
22654
+ function fitComment(anchor, panel, verticalOffset = 0, horizontalOffset = 0) {
22655
+ const panelHeight = panel.getHeight();
22656
+ const newPanel = new Mbr;
22657
+ newPanel.top = anchor.top - panelHeight - verticalOffset;
22658
+ newPanel.bottom = newPanel.top + panelHeight;
22659
+ const panelWidth = panel.getWidth();
22660
+ newPanel.left = anchor.left - panelWidth / 2 - horizontalOffset;
22661
+ newPanel.right = newPanel.left + panelWidth;
22662
+ return newPanel;
22663
+ }
22664
+ function fitBoardMenu(anchor, view, panel, verticalOffset = 20, horizontalOffset = 20) {
22665
+ const panelHeight = panel.getHeight();
22666
+ const panelWidth = panel.getWidth();
22667
+ const newPanel = new Mbr;
22668
+ newPanel.top = anchor.top;
22669
+ newPanel.bottom = newPanel.top + panelHeight;
22670
+ if (newPanel.bottom > view.bottom - verticalOffset) {
22671
+ newPanel.bottom = view.bottom - verticalOffset;
22672
+ newPanel.top = newPanel.bottom - panelHeight;
22673
+ }
22674
+ newPanel.left = anchor.left;
22675
+ newPanel.right = newPanel.left + panelWidth;
22676
+ if (newPanel.right > view.right - horizontalOffset) {
22677
+ newPanel.right = view.right - horizontalOffset;
22678
+ newPanel.left = newPanel.right - panelWidth;
22679
+ }
22680
+ return newPanel;
22681
+ }
22682
+ function fitThreadPanel(anchor, view, panel, verticalOffset = 50, horizontalOffset = 50) {
22683
+ const panelHeight = panel.getHeight();
22684
+ const panelWidth = panel.getWidth();
22685
+ const newPanel = new Mbr;
22686
+ newPanel.top = anchor.top - panelHeight / 2;
22687
+ if (newPanel.top < view.top + verticalOffset) {
22688
+ newPanel.top = view.top + verticalOffset;
22689
+ }
22690
+ newPanel.bottom = newPanel.top + panelHeight;
22691
+ if (newPanel.bottom > view.bottom - verticalOffset) {
22692
+ newPanel.bottom = view.bottom - verticalOffset;
22693
+ newPanel.top = newPanel.bottom - panelHeight;
22694
+ }
22695
+ newPanel.left = anchor.left;
22696
+ newPanel.right = newPanel.left + panelWidth;
22697
+ if (newPanel.right > view.right - horizontalOffset) {
22698
+ newPanel.right = anchor.right;
22699
+ newPanel.left = newPanel.right - panelWidth;
22700
+ }
22701
+ return newPanel;
22702
+ }
22703
+ // src/Items/DrawingContext.ts
22704
+ class DrawingContext2 {
22705
+ camera;
22706
+ ctx;
22707
+ cursorCtx;
22708
+ matrix;
22709
+ isBorderInvisible = false;
22710
+ shapeVisibilityTreshold = 3;
22711
+ rectangleVisibilyTreshold = 2;
22712
+ constructor(camera, ctx, cursorCtx, matrix = new Matrix2) {
22713
+ this.camera = camera;
22714
+ this.ctx = ctx;
22715
+ this.cursorCtx = cursorCtx;
22716
+ this.matrix = matrix;
22717
+ this.setCamera(camera);
22718
+ }
22719
+ dpi() {
22720
+ return conf.getDPI();
22721
+ }
22722
+ setCamera(camera) {
22723
+ this.camera = camera;
22724
+ this.matrix = camera.getMatrix();
22725
+ const scale = this.matrix.scaleX;
22726
+ this.isBorderInvisible = 4 * scale < 0.1;
22727
+ }
22728
+ clear() {
22729
+ this.ctx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
22730
+ this.ctx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
22731
+ this.matrix.applyToContext(this.ctx);
22732
+ }
22733
+ clearCursor() {
22734
+ if (!this.cursorCtx) {
22735
+ return;
22736
+ }
22737
+ this.cursorCtx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
22738
+ this.cursorCtx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
22739
+ this.matrix.applyToContext(this.cursorCtx);
22740
+ }
22741
+ applyChanges() {
22742
+ this.matrix.applyToContext(this.ctx);
22743
+ }
22744
+ getCameraScale() {
22745
+ return this.camera.getScale();
22746
+ }
22747
+ }
22709
22748
  // node_modules/property-information/lib/util/schema.js
22710
22749
  class Schema {
22711
22750
  constructor(property, normal, space) {
@@ -34384,10 +34423,10 @@ function zwitch(key, options) {
34384
34423
  const settings = options || {};
34385
34424
  function one4(value, ...parameters) {
34386
34425
  let fn = one4.invalid;
34387
- const handlers3 = one4.handlers;
34426
+ const handlers2 = one4.handlers;
34388
34427
  if (value && own6.call(value, key)) {
34389
34428
  const id = String(value[key]);
34390
- fn = own6.call(handlers3, id) ? handlers3[id] : one4.unknown;
34429
+ fn = own6.call(handlers2, id) ? handlers2[id] : one4.unknown;
34391
34430
  }
34392
34431
  if (fn) {
34393
34432
  return fn.call(this, value, ...parameters);
@@ -40216,7 +40255,7 @@ async function exportBoardSnapshot({
40216
40255
  const selectionMatrix = new Matrix2(translationX, translationY, scaleX, scaleY);
40217
40256
  camera.matrix = selectionMatrix;
40218
40257
  }
40219
- const context = new DrawingContext(camera, ctx);
40258
+ const context = new DrawingContext2(camera, ctx);
40220
40259
  context.setCamera(camera);
40221
40260
  context.ctx.setTransform(upscaleFactor, 0, 0, upscaleFactor, 0, 0);
40222
40261
  context.matrix.applyToContext(context.ctx);
@@ -42064,7 +42103,7 @@ class Placeholder extends BaseItem {
42064
42103
  function getPlaceholderImage(board, imageDimension) {
42065
42104
  const placeholderCanvas = conf.documentFactory.createElement("canvas");
42066
42105
  const placeholderContext = placeholderCanvas.getContext("2d");
42067
- const context = new DrawingContext(board.camera, placeholderContext);
42106
+ const context = new DrawingContext2(board.camera, placeholderContext);
42068
42107
  const placeholder = new Placeholder(board);
42069
42108
  if (imageDimension) {
42070
42109
  placeholderCanvas.width = imageDimension.width;
@@ -44708,7 +44747,7 @@ class ExportSnapshot extends Tool {
44708
44747
  const cameraCenter = this.board.camera.getMbr().getCenter();
44709
44748
  this.mbr = new Mbr(cameraCenter.x - conf.EXPORT_SELECTION_BOX_WIDTH / 2, cameraCenter.y - conf.EXPORT_SELECTION_BOX_HEIGHT / 2, cameraCenter.x + conf.EXPORT_SELECTION_BOX_WIDTH / 2, cameraCenter.y + conf.EXPORT_SELECTION_BOX_HEIGHT / 2, "transparent", "transparent", 1);
44710
44749
  this.board.selection.disable();
44711
- this.tempDrawingContext = new DrawingContext(board.camera, this.tempCtx);
44750
+ this.tempDrawingContext = new DrawingContext2(board.camera, this.tempCtx);
44712
44751
  }
44713
44752
  rectMoveTo(x, y) {
44714
44753
  this.transformation.translateTo(x, y);
@@ -44996,7 +45035,7 @@ function createCanvasDrawer(board) {
44996
45035
  const camera = new Camera;
44997
45036
  const newCameraMatix = new Matrix2(-mbr.left, -mbr.top, 1, 1);
44998
45037
  camera.matrix = newCameraMatix;
44999
- const context = new DrawingContext(camera, ctx);
45038
+ const context = new DrawingContext2(camera, ctx);
45000
45039
  context.setCamera(camera);
45001
45040
  context.ctx.setTransform(board2.camera.getMatrix().scaleX, 0, 0, board2.camera.getMatrix().scaleY, 0, 0);
45002
45041
  context.matrix.applyToContext(context.ctx);
@@ -49173,8 +49212,11 @@ class Camera {
49173
49212
  boardId = "";
49174
49213
  observableItem = null;
49175
49214
  throttledZoom;
49176
- isAnimating = false;
49177
49215
  isTrackingAnimation = false;
49216
+ localAnimationTarget = null;
49217
+ localAnimationId = null;
49218
+ localLastTime = null;
49219
+ localSpringVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0 };
49178
49220
  trackingAnimationId = null;
49179
49221
  trackingTarget = null;
49180
49222
  lastTrackingTime = null;
@@ -49254,7 +49296,7 @@ class Camera {
49254
49296
  }
49255
49297
  view(_left, _top, _scale) {}
49256
49298
  zoomRelativeToPointerBy(scale) {
49257
- this.zoomRelativeToPointBy(scale, this.pointer.x, this.pointer.y, 0);
49299
+ this.zoomRelativeToPointBy(scale, this.pointer.x, this.pointer.y);
49258
49300
  }
49259
49301
  zoomRelativeToPointBy(scale, x, y, duration = 400) {
49260
49302
  const startScaleX = this.matrix.scaleX;
@@ -49280,23 +49322,12 @@ class Camera {
49280
49322
  this.subject.publish(this);
49281
49323
  return;
49282
49324
  }
49283
- const startTime = performance.now();
49284
- const animate = (currentTime) => {
49285
- if (!currentTime) {
49286
- currentTime = performance.now();
49287
- }
49288
- const progress = Math.min((currentTime - startTime) / duration, 1);
49289
- const easedProgress = this.easeOutQuad(progress);
49290
- this.matrix.translateX = this.lerp(startTranslateX, targetTranslateX, easedProgress);
49291
- this.matrix.translateY = this.lerp(startTranslateY, targetTranslateY, easedProgress);
49292
- this.matrix.scaleX = this.lerp(startScaleX, finalScaleX, easedProgress);
49293
- this.matrix.scaleY = this.lerp(startScaleY, finalScaleY, easedProgress);
49294
- this.subject.publish(this);
49295
- if (progress < 1) {
49296
- safeRequestAnimationFrame(animate);
49297
- }
49298
- };
49299
- safeRequestAnimationFrame(animate);
49325
+ this.animateLocalToTarget({
49326
+ translateX: targetTranslateX,
49327
+ translateY: targetTranslateY,
49328
+ scaleX: finalScaleX,
49329
+ scaleY: finalScaleY
49330
+ });
49300
49331
  }
49301
49332
  saveDownEvent(event) {
49302
49333
  this.touchEvents.set(event.pointerId, event);
@@ -49526,13 +49557,6 @@ class Camera {
49526
49557
  }
49527
49558
  }
49528
49559
  viewRectangle(mbr, offsetInPercent = 10, duration = 500) {
49529
- if (duration <= 0) {
49530
- duration = 1;
49531
- }
49532
- if (this.isAnimating) {
49533
- return;
49534
- }
49535
- this.isAnimating = true;
49536
49560
  if (mbr.left === mbr.right && mbr.bottom === mbr.top) {
49537
49561
  mbr.left -= 100;
49538
49562
  mbr.right += 100;
@@ -49555,9 +49579,6 @@ class Camera {
49555
49579
  targetScale = Math.min(targetScale, this.maxScale);
49556
49580
  const translationX = this.window.width / 2 - (mbrWithOffset.left + mbrWidth / 2) * targetScale;
49557
49581
  const translationY = this.window.height / 2 - (mbrWithOffset.top + mbrHeight / 2) * targetScale;
49558
- const startTranslationX = this.matrix.translateX;
49559
- const startTranslationY = this.matrix.translateY;
49560
- const startScale = this.matrix.scaleX;
49561
49582
  if (duration === 0) {
49562
49583
  this.matrix.translateX = translationX;
49563
49584
  this.matrix.translateY = translationY;
@@ -49566,29 +49587,76 @@ class Camera {
49566
49587
  this.subject.publish(this);
49567
49588
  return;
49568
49589
  }
49569
- const startTime = performance.now();
49570
- const animate = () => {
49571
- const currentTime = performance.now();
49572
- const progress = Math.min((currentTime - startTime) / duration, 1);
49573
- const easedProgress = this.easeOutQuad(progress);
49574
- this.matrix.translateX = this.lerp(startTranslationX, translationX, easedProgress);
49575
- this.matrix.translateY = this.lerp(startTranslationY, translationY, easedProgress);
49576
- this.matrix.scaleX = this.lerp(startScale, targetScale, easedProgress);
49577
- this.matrix.scaleY = this.matrix.scaleX;
49590
+ this.animateLocalToTarget({
49591
+ translateX: translationX,
49592
+ translateY: translationY,
49593
+ scaleX: targetScale,
49594
+ scaleY: targetScale
49595
+ });
49596
+ }
49597
+ cancelLocalAnimation() {
49598
+ if (this.localAnimationId !== null) {
49599
+ cancelAnimationFrame(this.localAnimationId);
49600
+ this.localAnimationId = null;
49601
+ }
49602
+ this.localAnimationTarget = null;
49603
+ this.localLastTime = null;
49604
+ this.localSpringVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0 };
49605
+ }
49606
+ animateLocalToTarget(target) {
49607
+ this.localAnimationTarget = target;
49608
+ if (this.localAnimationId !== null) {
49609
+ return;
49610
+ }
49611
+ this.localLastTime = null;
49612
+ const STIFFNESS = 150;
49613
+ const DAMPING = 28;
49614
+ const SNAP_PX = 0.5;
49615
+ const SNAP_SCALE = 0.0005;
49616
+ const SNAP_VEL = 1;
49617
+ const springStep = (pos, tgt, vel, dt) => {
49618
+ const acc = STIFFNESS * (tgt - pos) - DAMPING * vel;
49619
+ const newVel = vel + acc * dt;
49620
+ return [pos + newVel * dt, newVel];
49621
+ };
49622
+ const loop = () => {
49623
+ const tgt = this.localAnimationTarget;
49624
+ if (!tgt) {
49625
+ this.localAnimationId = null;
49626
+ return;
49627
+ }
49628
+ const now = performance.now();
49629
+ const dt = Math.min(this.localLastTime !== null ? now - this.localLastTime : 16, 50) / 1000;
49630
+ this.localLastTime = now;
49631
+ const v = this.localSpringVelocity;
49632
+ const [tx, vtx] = springStep(this.matrix.translateX, tgt.translateX, v.translateX, dt);
49633
+ const [ty, vty] = springStep(this.matrix.translateY, tgt.translateY, v.translateY, dt);
49634
+ const [sx, vsx] = springStep(this.matrix.scaleX, tgt.scaleX, v.scaleX, dt);
49635
+ const [sy, vsy] = springStep(this.matrix.scaleY, tgt.scaleY, v.scaleY, dt);
49636
+ this.matrix.translateX = tx;
49637
+ this.matrix.translateY = ty;
49638
+ this.matrix.scaleX = sx;
49639
+ this.matrix.scaleY = sy;
49640
+ this.localSpringVelocity = { translateX: vtx, translateY: vty, scaleX: vsx, scaleY: vsy };
49641
+ this.updateBoardPointer();
49578
49642
  this.subject.publish(this);
49579
- if (progress < 1) {
49580
- safeRequestAnimationFrame(animate);
49581
- } else {
49582
- this.isAnimating = false;
49643
+ const settled = Math.abs(tgt.translateX - tx) < SNAP_PX && Math.abs(tgt.translateY - ty) < SNAP_PX && Math.abs(tgt.scaleX - sx) < SNAP_SCALE && Math.abs(vtx) < SNAP_VEL && Math.abs(vty) < SNAP_VEL;
49644
+ if (settled) {
49645
+ this.matrix.translateX = tgt.translateX;
49646
+ this.matrix.translateY = tgt.translateY;
49647
+ this.matrix.scaleX = tgt.scaleX;
49648
+ this.matrix.scaleY = tgt.scaleY;
49649
+ this.localSpringVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0 };
49650
+ this.localAnimationTarget = null;
49651
+ this.localAnimationId = null;
49652
+ this.localLastTime = null;
49653
+ this.updateBoardPointer();
49654
+ this.subject.publish(this);
49655
+ return;
49583
49656
  }
49657
+ this.localAnimationId = safeRequestAnimationFrame(loop) || null;
49584
49658
  };
49585
- safeRequestAnimationFrame(animate);
49586
- }
49587
- lerp(a2, b, time) {
49588
- return a2 + (b - a2) * time;
49589
- }
49590
- easeOutQuad(time) {
49591
- return time * (2 - time);
49659
+ this.localAnimationId = safeRequestAnimationFrame(loop) || null;
49592
49660
  }
49593
49661
  zoomToFit(rect, offsetInPercent = 10, duration = 480) {
49594
49662
  this.viewRectangle(rect, offsetInPercent, duration);
@@ -49597,11 +49665,13 @@ class Camera {
49597
49665
  return { x: 0, y: 0 };
49598
49666
  }
49599
49667
  translateTo(x, y) {
49668
+ this.cancelLocalAnimation();
49600
49669
  this.matrix.translate(x, y);
49601
49670
  this.updateBoardPointer();
49602
49671
  this.subject.publish(this);
49603
49672
  }
49604
49673
  translateBy(x, y) {
49674
+ this.cancelLocalAnimation();
49605
49675
  this.matrix.translate(x * this.matrix.scaleX, y * this.matrix.scaleY);
49606
49676
  this.updateBoardPointer();
49607
49677
  this.subject.publish(this);
@@ -56182,6 +56252,21 @@ function insertEventsFromOtherConnectionsIntoList(value, list6, board) {
56182
56252
  }
56183
56253
  const events = expandEvents(eventArray);
56184
56254
  board.selection.memoize();
56255
+ const focusedTextId = board.selection.memorySnapshot?.focus?.textToEdit;
56256
+ let localOpOriginalSelection = null;
56257
+ if (focusedTextId) {
56258
+ const allUnconfirmed = [...list6.getRecordsToSend(), ...list6.getNewRecords()];
56259
+ for (const rec of allUnconfirmed) {
56260
+ const op = rec.event.body.operation;
56261
+ if (op.class === "RichText" && op.method === "edit") {
56262
+ const items = Array.isArray(op.item) ? op.item : [op.item];
56263
+ if (items.includes(focusedTextId)) {
56264
+ localOpOriginalSelection = op.selection;
56265
+ break;
56266
+ }
56267
+ }
56268
+ }
56269
+ }
56185
56270
  const createdItems = [];
56186
56271
  const updatedText = [];
56187
56272
  const filter = (rec) => {
@@ -56191,6 +56276,10 @@ function insertEventsFromOtherConnectionsIntoList(value, list6, board) {
56191
56276
  createdItems.push(...creating);
56192
56277
  return false;
56193
56278
  }
56279
+ if (op.class === "RichText" && op.method === "edit") {
56280
+ const items = Array.isArray(op.item) ? op.item : [op.item];
56281
+ updatedText.push(...items);
56282
+ }
56194
56283
  return true;
56195
56284
  };
56196
56285
  list6.revertUnconfirmed(filter);
@@ -56209,7 +56298,28 @@ function insertEventsFromOtherConnectionsIntoList(value, list6, board) {
56209
56298
  return arr2.some((item) => lookup9.has(item));
56210
56299
  };
56211
56300
  const currSelection = board.selection.list().map((item) => item.getId());
56212
- if (hasAnyOverlap(currSelection, createdItems) || hasAnyOverlap(currSelection, updatedText)) {
56301
+ const memoizedCursor = board.selection.memorySnapshot?.focus?.selection;
56302
+ if (focusedTextId && localOpOriginalSelection && memoizedCursor && hasAnyOverlap(currSelection, updatedText)) {
56303
+ const rt = board.items.getById(focusedTextId)?.getRichText();
56304
+ if (rt) {
56305
+ const otAdjustedCursor = rt.editor.getSelection();
56306
+ if (otAdjustedCursor && memoizedCursor.anchor.path.length > 0 && memoizedCursor.focus.path.length > 0) {
56307
+ const deltaAnchor = otAdjustedCursor.anchor.offset - (localOpOriginalSelection?.anchor?.offset ?? 0);
56308
+ const deltaFocus = otAdjustedCursor.focus.offset - (localOpOriginalSelection?.focus?.offset ?? 0);
56309
+ const adjustedSelection = {
56310
+ anchor: {
56311
+ path: memoizedCursor.anchor.path,
56312
+ offset: memoizedCursor.anchor.offset + deltaAnchor
56313
+ },
56314
+ focus: {
56315
+ path: memoizedCursor.focus.path,
56316
+ offset: memoizedCursor.focus.offset + deltaFocus
56317
+ }
56318
+ };
56319
+ rt.editorTransforms.select(rt.editor.editor, adjustedSelection);
56320
+ }
56321
+ }
56322
+ } else if (hasAnyOverlap(currSelection, createdItems) || hasAnyOverlap(currSelection, updatedText)) {
56213
56323
  board.selection.applyMemoizedCaretOrRange();
56214
56324
  }
56215
56325
  }
@@ -56492,16 +56602,16 @@ function createEvents(board, connection, lastIndex) {
56492
56602
  }
56493
56603
  // src/Events/MessageRouter/createMessageRouter.ts
56494
56604
  function createMessageRouter() {
56495
- const handlers3 = new Map;
56605
+ const handlers2 = new Map;
56496
56606
  function addHandler(type, handler) {
56497
- handlers3.set(type, (message, board) => {
56607
+ handlers2.set(type, (message, board) => {
56498
56608
  if (message.type === type) {
56499
56609
  handler(message, board);
56500
56610
  }
56501
56611
  });
56502
56612
  }
56503
56613
  function handleMessage(message, board) {
56504
- const handler = handlers3.get(message.type);
56614
+ const handler = handlers2.get(message.type);
56505
56615
  if (handler) {
56506
56616
  handler(message, board);
56507
56617
  } else {
@@ -57208,7 +57318,7 @@ export {
57208
57318
  ExportQuality,
57209
57319
  Events2 as Events,
57210
57320
  EditorContainer,
57211
- DrawingContext,
57321
+ DrawingContext2 as DrawingContext,
57212
57322
  Drawing,
57213
57323
  Dice,
57214
57324
  DefaultTransformationData,