microboard-temp 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/node.js CHANGED
@@ -4,43 +4,25 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- function __accessProp(key) {
8
- return this[key];
9
- }
10
- var __toESMCache_node;
11
- var __toESMCache_esm;
12
7
  var __toESM = (mod, isNodeMode, target) => {
13
- var canCache = mod != null && typeof mod === "object";
14
- if (canCache) {
15
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
- var cached = cache.get(mod);
17
- if (cached)
18
- return cached;
19
- }
20
8
  target = mod != null ? __create(__getProtoOf(mod)) : {};
21
9
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
10
  for (let key of __getOwnPropNames(mod))
23
11
  if (!__hasOwnProp.call(to, key))
24
12
  __defProp(to, key, {
25
- get: __accessProp.bind(mod, key),
13
+ get: () => mod[key],
26
14
  enumerable: true
27
15
  });
28
- if (canCache)
29
- cache.set(mod, to);
30
16
  return to;
31
17
  };
32
18
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
- var __returnValue = (v) => v;
34
- function __exportSetter(name, newValue) {
35
- this[name] = __returnValue.bind(null, newValue);
36
- }
37
19
  var __export = (target, all) => {
38
20
  for (var name in all)
39
21
  __defProp(target, name, {
40
22
  get: all[name],
41
23
  enumerable: true,
42
24
  configurable: true,
43
- set: __exportSetter.bind(all, name)
25
+ set: (newValue) => all[name] = () => newValue
44
26
  });
45
27
  };
46
28
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -81,13 +63,13 @@ var require_extend = __commonJS((exports, module) => {
81
63
  var toStr = Object.prototype.toString;
82
64
  var defineProperty = Object.defineProperty;
83
65
  var gOPD = Object.getOwnPropertyDescriptor;
84
- var isArray = function isArray2(arr2) {
66
+ var isArray = function isArray(arr2) {
85
67
  if (typeof Array.isArray === "function") {
86
68
  return Array.isArray(arr2);
87
69
  }
88
70
  return toStr.call(arr2) === "[object Array]";
89
71
  };
90
- var isPlainObject2 = function isPlainObject3(obj) {
72
+ var isPlainObject2 = function isPlainObject(obj) {
91
73
  if (!obj || toStr.call(obj) !== "[object Object]") {
92
74
  return false;
93
75
  }
@@ -100,7 +82,7 @@ var require_extend = __commonJS((exports, module) => {
100
82
  for (key in obj) {}
101
83
  return typeof key === "undefined" || hasOwn.call(obj, key);
102
84
  };
103
- var setProperty = function setProperty2(target, options) {
85
+ var setProperty = function setProperty(target, options) {
104
86
  if (defineProperty && options.name === "__proto__") {
105
87
  defineProperty(target, options.name, {
106
88
  enumerable: true,
@@ -112,7 +94,7 @@ var require_extend = __commonJS((exports, module) => {
112
94
  target[options.name] = options.newValue;
113
95
  }
114
96
  };
115
- var getProperty = function getProperty2(obj, name) {
97
+ var getProperty = function getProperty(obj, name) {
116
98
  if (name === "__proto__") {
117
99
  if (!hasOwn.call(obj, name)) {
118
100
  return;
@@ -1094,7 +1076,7 @@ var require_remark_slate_cjs_development = __commonJS((exports) => {
1094
1076
  };
1095
1077
  }
1096
1078
  }
1097
- var forceLeafNode = function forceLeafNode2(children) {
1079
+ var forceLeafNode = function forceLeafNode(children) {
1098
1080
  return {
1099
1081
  text: children.map(function(k) {
1100
1082
  return k === null || k === undefined ? undefined : k.text;
@@ -1111,7 +1093,7 @@ var require_remark_slate_cjs_development = __commonJS((exports) => {
1111
1093
  return acc;
1112
1094
  }, {});
1113
1095
  }
1114
- var isLeafNode = function isLeafNode2(node2) {
1096
+ var isLeafNode = function isLeafNode(node2) {
1115
1097
  return typeof node2.text === "string";
1116
1098
  };
1117
1099
  var VOID_ELEMENTS = ["thematic_break", "image"];
@@ -1246,11 +1228,11 @@ var require_remark_slate_cjs_development = __commonJS((exports) => {
1246
1228
  var formattedString = format + children + reverseStr(format);
1247
1229
  return string3.replace(frozenString, formattedString);
1248
1230
  }
1249
- var reverseStr = function reverseStr2(string3) {
1231
+ var reverseStr = function reverseStr(string3) {
1250
1232
  return string3.split("").reverse().join("");
1251
1233
  };
1252
1234
  function plugin(opts) {
1253
- var compiler2 = function compiler3(node2) {
1235
+ var compiler2 = function compiler(node2) {
1254
1236
  return node2.children.map(function(c) {
1255
1237
  return deserialize(c, opts);
1256
1238
  });
@@ -1275,7 +1257,7 @@ var require_tinyqueue = __commonJS((exports, module) => {
1275
1257
  (function(global2, factory) {
1276
1258
  typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global2 = global2 || self, global2.TinyQueue = factory());
1277
1259
  })(exports, function() {
1278
- var TinyQueue = function TinyQueue2(data, compare) {
1260
+ var TinyQueue = function TinyQueue(data, compare) {
1279
1261
  if (data === undefined)
1280
1262
  data = [];
1281
1263
  if (compare === undefined)
@@ -1289,7 +1271,7 @@ var require_tinyqueue = __commonJS((exports, module) => {
1289
1271
  }
1290
1272
  }
1291
1273
  };
1292
- TinyQueue.prototype.push = function push2(item) {
1274
+ TinyQueue.prototype.push = function push(item) {
1293
1275
  this.data.push(item);
1294
1276
  this.length++;
1295
1277
  this._up(this.length - 1);
@@ -1569,7 +1551,7 @@ function safeRequestAnimationFrame(callback) {
1569
1551
  if (typeof requestAnimationFrame === "function") {
1570
1552
  return requestAnimationFrame(callback);
1571
1553
  } else {
1572
- callback();
1554
+ setTimeout(callback, 0);
1573
1555
  }
1574
1556
  }
1575
1557
 
@@ -2015,206 +1997,6 @@ class Mbr {
2015
1997
  }
2016
1998
  }
2017
1999
  }
2018
- // src/Items/Mbr/updateRects.ts
2019
- function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
2020
- const { selection, camera } = board;
2021
- const panel = ref.current;
2022
- const selectionMbr = mbr ?? selection.getMbr();
2023
- const selectionItems = selection.items;
2024
- const richTextSelection = selectionItems.getSingle() instanceof RichText ? selectionItems.list()[0] : undefined;
2025
- if (panel && selectionMbr) {
2026
- if (fit === "contextPanel") {
2027
- const panelRect = getContextPanelRect(selectionMbr, camera, panel, !!richTextSelection, horizontalOffset, verticalOffset);
2028
- return panelRect;
2029
- }
2030
- if (fit === "linkToBtn") {
2031
- if (!mbr) {
2032
- return null;
2033
- }
2034
- const panelRect = fitLinkToBtn(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
2035
- return panelRect;
2036
- }
2037
- if (fit === "comment") {
2038
- if (!mbr) {
2039
- return null;
2040
- }
2041
- const panelRect = fitComment(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
2042
- return panelRect;
2043
- }
2044
- if (fit === "threadPanel") {
2045
- if (!mbr) {
2046
- return null;
2047
- }
2048
- const panelRect = fitThreadPanel(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
2049
- return panelRect;
2050
- }
2051
- if (fit === "boardMenu") {
2052
- if (!mbr) {
2053
- return null;
2054
- }
2055
- const panelRect = fitBoardMenu(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
2056
- return panelRect;
2057
- }
2058
- if (fit === "hyperLink") {
2059
- if (!mbr) {
2060
- return null;
2061
- }
2062
- const panelRect = fitHyperLink(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), camera.window.getMbr(), verticalOffset);
2063
- return panelRect;
2064
- }
2065
- }
2066
- return null;
2067
- }
2068
- function getContextPanelRect(selectionMbr, camera, panel, toLeft, horizontalOffset, verticalOffset) {
2069
- const transformedMbr = selectionMbr.getTransformed(camera.getMatrix());
2070
- const windowMbr = camera.window.getMbr();
2071
- const panelRectFromDom = Mbr.fromDomRect(panel.getBoundingClientRect());
2072
- const panelRect = toLeft ? fitContextPanelToLeft(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset) : fitContextPanelToCenter(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset);
2073
- return panelRect;
2074
- }
2075
- function fitContextPanelToLeft(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
2076
- const panelHeight = panel.getHeight();
2077
- const panelWidth = panel.getWidth();
2078
- const newPanel = new Mbr;
2079
- const topSpace = selectionMbr.top - view.top;
2080
- const hasEnoughTopSpace = topSpace >= panelHeight + verticalOffset;
2081
- if (hasEnoughTopSpace) {
2082
- newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
2083
- if (newPanel.top < view.top) {
2084
- newPanel.top = view.top + verticalOffset;
2085
- }
2086
- } else {
2087
- const usePanelTop = panel.top > 1 && panel.top > selectionMbr.top + verticalOffset;
2088
- newPanel.top = usePanelTop ? panel.top : selectionMbr.bottom + verticalOffset;
2089
- const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
2090
- const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
2091
- if (isOverflowingBottom || isLargeOffsetForRichText) {
2092
- newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
2093
- }
2094
- }
2095
- newPanel.bottom = newPanel.top + panelHeight;
2096
- fitContextPanelInViewRect(newPanel, view, verticalOffset);
2097
- const itemMbr = selectionMbr.getMbr();
2098
- newPanel.left = itemMbr.left;
2099
- adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
2100
- return newPanel;
2101
- }
2102
- function fitContextPanelToCenter(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
2103
- const panelHeight = panel.getHeight();
2104
- const panelWidth = panel.getWidth();
2105
- const newPanel = new Mbr;
2106
- const topSpace = selectionMbr.top - view.top;
2107
- const bottomSpace = view.bottom - selectionMbr.bottom;
2108
- const shouldPlaceAbove = topSpace > bottomSpace - panelHeight;
2109
- if (shouldPlaceAbove) {
2110
- newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
2111
- if (newPanel.top < view.top) {
2112
- newPanel.top = view.top + verticalOffset;
2113
- }
2114
- } else {
2115
- newPanel.top = selectionMbr.bottom + verticalOffset;
2116
- const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
2117
- const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
2118
- if (isOverflowingBottom || isLargeOffsetForRichText) {
2119
- newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
2120
- }
2121
- }
2122
- newPanel.bottom = newPanel.top + panelHeight;
2123
- fitContextPanelInViewRect(newPanel, view, verticalOffset);
2124
- const itemCenter = selectionMbr.getCenter();
2125
- newPanel.left = itemCenter.x - panelWidth / 2;
2126
- adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
2127
- return newPanel;
2128
- }
2129
- function adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset) {
2130
- newPanel.right = newPanel.left + panelWidth;
2131
- if (newPanel.left < view.left + horizontalOffset) {
2132
- newPanel.left = view.left + horizontalOffset;
2133
- } else if (newPanel.right + horizontalOffset > view.right) {
2134
- newPanel.left = view.right - (panelWidth + horizontalOffset);
2135
- }
2136
- newPanel.right = newPanel.left + panelWidth;
2137
- }
2138
- function fitContextPanelInViewRect(panel, view, verticalOffset) {
2139
- const panelHeight = panel.getHeight();
2140
- if (panel.top <= view.top + verticalOffset) {
2141
- panel.top = view.top + 2 * verticalOffset;
2142
- panel.bottom = panel.top + panelHeight;
2143
- }
2144
- if (panel.bottom >= view.bottom - verticalOffset) {
2145
- panel.bottom = view.bottom - 2 * verticalOffset;
2146
- panel.top = panel.bottom - panelHeight;
2147
- }
2148
- }
2149
- function fitLinkToBtn(itemMbr, view, panel, verticalOffset = -2, horizontalOffset = -2) {
2150
- const panelHeight = panel.getHeight();
2151
- const newPanel = new Mbr;
2152
- newPanel.top = itemMbr.top - panelHeight - verticalOffset;
2153
- newPanel.top = newPanel.top + panelHeight;
2154
- newPanel.bottom = newPanel.top + panelHeight * 2;
2155
- const panelWidth = panel.getWidth();
2156
- newPanel.left = itemMbr.right - panelWidth + horizontalOffset;
2157
- return newPanel;
2158
- }
2159
- function fitHyperLink(linkMbr, panel, view, offset = 20) {
2160
- const panelHeight = panel.getHeight();
2161
- const newPanel = new Mbr;
2162
- newPanel.top = linkMbr.bottom;
2163
- newPanel.bottom = panelHeight + newPanel.top;
2164
- const panelWidth = panel.getWidth();
2165
- newPanel.left = linkMbr.left;
2166
- newPanel.right = newPanel.left + panelWidth;
2167
- return newPanel;
2168
- }
2169
- function fitComment(anchor, panel, verticalOffset = 0, horizontalOffset = 0) {
2170
- const panelHeight = panel.getHeight();
2171
- const newPanel = new Mbr;
2172
- newPanel.top = anchor.top - panelHeight - verticalOffset;
2173
- newPanel.bottom = newPanel.top + panelHeight;
2174
- const panelWidth = panel.getWidth();
2175
- newPanel.left = anchor.left - panelWidth / 2 - horizontalOffset;
2176
- newPanel.right = newPanel.left + panelWidth;
2177
- return newPanel;
2178
- }
2179
- function fitBoardMenu(anchor, view, panel, verticalOffset = 20, horizontalOffset = 20) {
2180
- const panelHeight = panel.getHeight();
2181
- const panelWidth = panel.getWidth();
2182
- const newPanel = new Mbr;
2183
- newPanel.top = anchor.top;
2184
- newPanel.bottom = newPanel.top + panelHeight;
2185
- if (newPanel.bottom > view.bottom - verticalOffset) {
2186
- newPanel.bottom = view.bottom - verticalOffset;
2187
- newPanel.top = newPanel.bottom - panelHeight;
2188
- }
2189
- newPanel.left = anchor.left;
2190
- newPanel.right = newPanel.left + panelWidth;
2191
- if (newPanel.right > view.right - horizontalOffset) {
2192
- newPanel.right = view.right - horizontalOffset;
2193
- newPanel.left = newPanel.right - panelWidth;
2194
- }
2195
- return newPanel;
2196
- }
2197
- function fitThreadPanel(anchor, view, panel, verticalOffset = 50, horizontalOffset = 50) {
2198
- const panelHeight = panel.getHeight();
2199
- const panelWidth = panel.getWidth();
2200
- const newPanel = new Mbr;
2201
- newPanel.top = anchor.top - panelHeight / 2;
2202
- if (newPanel.top < view.top + verticalOffset) {
2203
- newPanel.top = view.top + verticalOffset;
2204
- }
2205
- newPanel.bottom = newPanel.top + panelHeight;
2206
- if (newPanel.bottom > view.bottom - verticalOffset) {
2207
- newPanel.bottom = view.bottom - verticalOffset;
2208
- newPanel.top = newPanel.bottom - panelHeight;
2209
- }
2210
- newPanel.left = anchor.left;
2211
- newPanel.right = newPanel.left + panelWidth;
2212
- if (newPanel.right > view.right - horizontalOffset) {
2213
- newPanel.right = anchor.right;
2214
- newPanel.left = newPanel.right - panelWidth;
2215
- }
2216
- return newPanel;
2217
- }
2218
2000
  // src/Items/Line/Line.ts
2219
2001
  function getLinesRelationType(lineA, lineB) {
2220
2002
  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);
@@ -4137,6 +3919,232 @@ class Arc {
4137
3919
  return new Arc(this.center.copy(), this.radiusX, this.radiusY, this.startAngle, this.endAngle, this.clockwise);
4138
3920
  }
4139
3921
  }
3922
+ // src/SessionStorage.ts
3923
+ var _sessionStorage;
3924
+ if (typeof window !== "undefined" && window.sessionStorage) {
3925
+ _sessionStorage = window.sessionStorage;
3926
+ } else {
3927
+
3928
+ class NodeStoragePolyfill {
3929
+ _store = {};
3930
+ clear() {
3931
+ this._store = {};
3932
+ }
3933
+ getItem(key) {
3934
+ return Object.prototype.hasOwnProperty.call(this._store, key) ? this._store[key] : null;
3935
+ }
3936
+ key(index) {
3937
+ const keys = Object.keys(this._store);
3938
+ return keys[index] ?? null;
3939
+ }
3940
+ removeItem(key) {
3941
+ delete this._store[key];
3942
+ }
3943
+ setItem(key, value) {
3944
+ this._store[key] = value;
3945
+ }
3946
+ get length() {
3947
+ return Object.keys(this._store).length;
3948
+ }
3949
+ }
3950
+ _sessionStorage = new NodeStoragePolyfill;
3951
+ }
3952
+
3953
+ class SessionStorage {
3954
+ set(key, value) {
3955
+ const boardId = this.getBoardId() || "";
3956
+ _sessionStorage.setItem(boardId + "_" + key, JSON.stringify(value));
3957
+ }
3958
+ get(key) {
3959
+ const boardId = this.getBoardId() || "";
3960
+ const item = _sessionStorage.getItem(boardId + "_" + key);
3961
+ if (!item || item === "undefined") {
3962
+ return;
3963
+ }
3964
+ return JSON.parse(item);
3965
+ }
3966
+ remove(key) {
3967
+ const boardId = this.getBoardId() || "";
3968
+ _sessionStorage.removeItem(boardId + "_" + key);
3969
+ }
3970
+ setConnectorStrokeStyle(color) {
3971
+ this.set(`connectorStrokeStyle`, color);
3972
+ }
3973
+ getConnectorStrokeStyle() {
3974
+ return this.get("connectorStrokeStyle");
3975
+ }
3976
+ setConnectorLineWidth(width) {
3977
+ this.set(`connectorLineWidth`, width);
3978
+ }
3979
+ getConnectorLineWidth() {
3980
+ return this.get("connectorLineWidth");
3981
+ }
3982
+ setConnectorFillColor(color) {
3983
+ this.set(`connectorFillColor`, color);
3984
+ }
3985
+ getConnectorFillColor() {
3986
+ return this.get("connectorFillColor");
3987
+ }
3988
+ setConnectorPointer(type, edge) {
3989
+ this.set(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`, type);
3990
+ }
3991
+ getConnectorPointer(edge) {
3992
+ return this.get(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`);
3993
+ }
3994
+ setConnectorLineStyle(type) {
3995
+ this.set("connectorLineStyle", type);
3996
+ }
3997
+ getConnectorLineStyle() {
3998
+ return this.get("connectorLineStyle");
3999
+ }
4000
+ setShapeData(data) {
4001
+ this.set("lastShapeData", data);
4002
+ }
4003
+ getShapeData() {
4004
+ return this.get("lastShapeData");
4005
+ }
4006
+ setStickerData(data) {
4007
+ this.set("lastSticker", data);
4008
+ }
4009
+ getStickerData() {
4010
+ return this.get("lastSticker");
4011
+ }
4012
+ setShapeWidth(width) {
4013
+ this.set("shapeWidth", width);
4014
+ }
4015
+ getShapeWidth() {
4016
+ return this.get("shapeWidth");
4017
+ }
4018
+ setShapeHeight(height) {
4019
+ this.set("shapeHeight", height);
4020
+ }
4021
+ getShapeHeight() {
4022
+ return this.get("shapeHeight");
4023
+ }
4024
+ setImageDimensions(dimension) {
4025
+ this.set("imageDimensions", dimension);
4026
+ }
4027
+ getImageDimensions() {
4028
+ return this.get("imageDimensions");
4029
+ }
4030
+ setFontSize(itemType, size) {
4031
+ this.set(`fontSize_${itemType}`, size);
4032
+ }
4033
+ getFontSize(itemType) {
4034
+ return this.get(`fontSize_${itemType}`);
4035
+ }
4036
+ setFontStyles(itemType, styles) {
4037
+ this.set(`fontStyles_${itemType}`, styles);
4038
+ }
4039
+ getFontStyles(itemType) {
4040
+ return this.get(`fontStyles_${itemType}`);
4041
+ }
4042
+ setFontColor(itemType, color) {
4043
+ this.set(`fontColor_${itemType}`, color);
4044
+ }
4045
+ getFontColor(itemType) {
4046
+ return this.get(`fontColor_${itemType}`);
4047
+ }
4048
+ setFontHighlight(itemType, highlightColor) {
4049
+ this.set(`fontHighlightColor_${itemType}`, highlightColor);
4050
+ }
4051
+ getFontHighlight(itemType) {
4052
+ return this.get(`fontHighlightColor_${itemType}`);
4053
+ }
4054
+ setHorizontalAlignment(itemType, horizontalAlignment) {
4055
+ this.set(`fontHorizontalAlignment_${itemType}`, horizontalAlignment);
4056
+ }
4057
+ getHorizontalAlignment(itemType) {
4058
+ return this.get(`fontHorizontalAlignment_${itemType}`);
4059
+ }
4060
+ setVerticalAlignment(itemType, verticalAlignment) {
4061
+ this.set(`fontVerticalAlignment_${itemType}`, verticalAlignment);
4062
+ }
4063
+ getVerticalAlignment(itemType) {
4064
+ return this.get(`fontVerticalAlignment_${itemType}`);
4065
+ }
4066
+ setLastAIRequest(request) {
4067
+ _sessionStorage.setItem("lastAIRequest", request);
4068
+ }
4069
+ getLastAIRequest() {
4070
+ return _sessionStorage.getItem("lastAIRequest");
4071
+ }
4072
+ removeLastAIRequest() {
4073
+ _sessionStorage.removeItem("lastAIRequest");
4074
+ }
4075
+ clear() {
4076
+ _sessionStorage.clear();
4077
+ }
4078
+ getBoardId() {
4079
+ if (typeof window === "undefined") {
4080
+ return;
4081
+ }
4082
+ return window.location.href.split("/").pop()?.split("?")[0];
4083
+ }
4084
+ }
4085
+ var tempStorage = new SessionStorage;
4086
+
4087
+ // src/HTMLRender/HTMLRender.ts
4088
+ function getTranslationFromHTML(el) {
4089
+ const transform = el.style.transform;
4090
+ const translateMatch = transform.match(/translate\(([^)]+)\)/);
4091
+ const [translateX, translateY] = translateMatch ? translateMatch[1].split(",").map((value) => parseFloat(value)) : [0, 0];
4092
+ return [translateX, translateY];
4093
+ }
4094
+ function getScaleFromHTML(el) {
4095
+ const transform = el.style.transform;
4096
+ const scaleMatch = transform.match(/scale\(([^)]+)\)/);
4097
+ const [scaleX, scaleY] = scaleMatch ? scaleMatch[1].split(",").map((value) => parseFloat(value)) : [1, 1];
4098
+ return [scaleX, scaleY];
4099
+ }
4100
+ function translateElementBy(el, x, y) {
4101
+ const [exX, exY] = getTranslationFromHTML(el);
4102
+ const [newX, newY] = [exX + x, exY + y];
4103
+ const [scaleX, scaleY] = getScaleFromHTML(el);
4104
+ el.style.transform = `translate(${newX}px, ${newY}px) scale(${scaleX}, ${scaleY})`;
4105
+ return el;
4106
+ }
4107
+ function scaleElementBy(el, scaleX, scaleY) {
4108
+ const [currentScaleX, currentScaleY] = getScaleFromHTML(el);
4109
+ const [newScaleX, newScaleY] = [
4110
+ currentScaleX * scaleX,
4111
+ currentScaleY * scaleY
4112
+ ];
4113
+ const [translateX, translateY] = getTranslationFromHTML(el);
4114
+ el.style.transform = `translate(${translateX}px, ${translateY}px) scale(${newScaleX}, ${newScaleY})`;
4115
+ return el;
4116
+ }
4117
+ function resetElementScale(el) {
4118
+ const [x, y] = getTranslationFromHTML(el);
4119
+ el.style.transform = `translate(${x}px, ${y}px) scale(1, 1)`;
4120
+ return el;
4121
+ }
4122
+ function positionRelatively(toPosition, positionBy, padding = 0) {
4123
+ const [translateX, translateY] = getTranslationFromHTML(toPosition);
4124
+ const [frameX, frameY] = getTranslationFromHTML(positionBy);
4125
+ const [dx, dy] = [translateX - frameX, translateY - frameY];
4126
+ const verticalAlignment = toPosition.getAttribute("data-vertical-alignment");
4127
+ const horizontalAlignment = toPosition.getAttribute("data-vertical-alignment");
4128
+ let paddingX = padding;
4129
+ let paddingY = padding;
4130
+ if (verticalAlignment && verticalAlignment === "bottom") {
4131
+ paddingY = -padding;
4132
+ }
4133
+ if (horizontalAlignment && horizontalAlignment === "right") {
4134
+ paddingX = -padding;
4135
+ }
4136
+ const [scaleX, scaleY] = getScaleFromHTML(toPosition);
4137
+ toPosition.style.transform = `translate(${dx + paddingX}px, ${dy + paddingY}px) scale(${scaleX}, ${scaleY})`;
4138
+ return toPosition;
4139
+ }
4140
+ function positionAbsolutely(toPosition, positionBy) {
4141
+ const [translateX, translateY] = getTranslationFromHTML(toPosition);
4142
+ const [frameX, frameY] = getTranslationFromHTML(positionBy);
4143
+ const [dx, dy] = [translateX + frameX, translateY + frameY];
4144
+ const [scaleX, scaleY] = getScaleFromHTML(toPosition);
4145
+ toPosition.style.transform = `translate(${dx}px, ${dy}px) scale(${scaleX}, ${scaleY})`;
4146
+ return toPosition;
4147
+ }
4140
4148
  // src/api/BrowserDocumentFactory.ts
4141
4149
  class BrowserDocumentFactory {
4142
4150
  createElement(tagName) {
@@ -4315,6 +4323,152 @@ class MockPath2D {
4315
4323
  }
4316
4324
  }
4317
4325
 
4326
+ // src/Items/Transformation/Matrix.ts
4327
+ class Matrix2 {
4328
+ translateX;
4329
+ translateY;
4330
+ scaleX;
4331
+ scaleY;
4332
+ shearX;
4333
+ shearY;
4334
+ constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, shearX = 0, shearY = 0) {
4335
+ this.translateX = translateX;
4336
+ this.translateY = translateY;
4337
+ this.scaleX = scaleX;
4338
+ this.scaleY = scaleY;
4339
+ this.shearX = shearX;
4340
+ this.shearY = shearY;
4341
+ this.translateX = toFiniteNumber(translateX);
4342
+ this.translateY = toFiniteNumber(translateY);
4343
+ this.scaleX = toFiniteNumber(scaleX, 1);
4344
+ this.scaleY = toFiniteNumber(scaleY, 1);
4345
+ this.shearX = toFiniteNumber(shearX);
4346
+ this.shearY = toFiniteNumber(shearY);
4347
+ }
4348
+ translate(x, y) {
4349
+ this.translateX += x;
4350
+ this.translateY += y;
4351
+ }
4352
+ scale(x, y) {
4353
+ this.scaleX = this.scaleX * x;
4354
+ this.scaleY = this.scaleY * y;
4355
+ }
4356
+ multiplyByMatrix(matrix) {
4357
+ const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this;
4358
+ this.translateX = scaleX * matrix.translateX + shearX * matrix.translateY + translateX;
4359
+ this.translateY = shearY * matrix.translateX + scaleY * matrix.translateY + translateY;
4360
+ this.scaleX = scaleX * matrix.scaleX + shearX * matrix.shearY;
4361
+ this.scaleY = shearY * matrix.shearX + scaleY * matrix.scaleY;
4362
+ this.shearX = scaleX * matrix.shearX + shearX * matrix.scaleY;
4363
+ this.shearY = shearY * matrix.scaleX + scaleY * matrix.shearY;
4364
+ return this;
4365
+ }
4366
+ multiplyByMatrixies(matrixies) {
4367
+ for (const matrix of matrixies) {
4368
+ this.multiplyByMatrix(matrix);
4369
+ }
4370
+ return this;
4371
+ }
4372
+ multiply(value) {
4373
+ if (Array.isArray(value)) {
4374
+ this.multiplyByMatrixies(value);
4375
+ } else {
4376
+ this.multiplyByMatrix(value);
4377
+ }
4378
+ return this;
4379
+ }
4380
+ copy() {
4381
+ return new Matrix2(this.translateX, this.translateY, this.scaleX, this.scaleY, this.shearX, this.shearY);
4382
+ }
4383
+ invert() {
4384
+ const { scaleX, shearY, shearX, scaleY, translateX, translateY } = this;
4385
+ const denom = scaleX * scaleY - shearX * shearY;
4386
+ this.scaleX = scaleY / denom;
4387
+ this.shearY = shearY / -denom;
4388
+ this.shearX = shearX / -denom;
4389
+ this.scaleY = scaleX / denom;
4390
+ this.translateX = (scaleY * translateX - shearX * translateY) / -denom;
4391
+ this.translateY = (shearY * translateX - scaleX * translateY) / denom;
4392
+ }
4393
+ getInverse() {
4394
+ const inverse = this.copy();
4395
+ inverse.invert();
4396
+ return inverse;
4397
+ }
4398
+ rotateByRadian(radian) {
4399
+ const cosAngle = Math.cos(radian);
4400
+ const sinAngle = Math.sin(radian);
4401
+ const rotationMatrix = new Matrix2(0, 0, cosAngle, cosAngle, -sinAngle, sinAngle);
4402
+ return this.multiply(rotationMatrix);
4403
+ }
4404
+ rotateBy(degree) {
4405
+ const radian = degree * Math.PI / 180;
4406
+ this.rotateByRadian(radian);
4407
+ }
4408
+ rotateByObjectCenter(degree, size, scale) {
4409
+ const angle = degree * (Math.PI / 180);
4410
+ const width = size.width * scale.x;
4411
+ const height = size.height * scale.y;
4412
+ const centerX = width / 2;
4413
+ const centerY = height / 2;
4414
+ const x = centerX - (centerX * Math.cos(angle) - centerY * Math.sin(angle));
4415
+ const y = centerY - (centerX * Math.sin(angle) + centerY * Math.cos(angle));
4416
+ this.rotateBy(degree);
4417
+ this.translate(x, y);
4418
+ }
4419
+ rotateByRelativeTo(degree, x, y) {
4420
+ this.translateX += x;
4421
+ this.translateY += y;
4422
+ this.rotateBy(degree);
4423
+ this.translateX -= x;
4424
+ this.translateY -= y;
4425
+ }
4426
+ rotateByRadianRelativeTo(radian, x, y) {
4427
+ this.translateX += x;
4428
+ this.translateY += y;
4429
+ this.rotateByRadian(radian);
4430
+ this.translateX -= x;
4431
+ this.translateY -= y;
4432
+ }
4433
+ apply(point) {
4434
+ const { x, y } = point;
4435
+ point.x = this.scaleX * x + this.shearX * y + this.translateX;
4436
+ point.y = this.shearY * x + this.scaleY * y + this.translateY;
4437
+ }
4438
+ applyToContext(ctx) {
4439
+ ctx.transform(this.scaleX, this.shearY, this.shearX, this.scaleY, this.translateX, this.translateY);
4440
+ }
4441
+ getAffineMatrix() {
4442
+ return {
4443
+ a: this.scaleX,
4444
+ b: this.shearY,
4445
+ c: this.shearX,
4446
+ d: this.scaleY,
4447
+ e: this.translateX,
4448
+ f: this.translateY
4449
+ };
4450
+ }
4451
+ getCssString() {
4452
+ return `matrix(${this.scaleX},${this.shearY},${this.shearX},${this.scaleY},${this.translateX},${this.translateY})`;
4453
+ }
4454
+ identity() {
4455
+ return new Matrix2;
4456
+ }
4457
+ mirrorOrigin() {
4458
+ return new Matrix2(0, 0, -1, -1);
4459
+ }
4460
+ mirrorX() {
4461
+ return new Matrix2(0, 0, 1, -1);
4462
+ }
4463
+ mirrorY() {
4464
+ return new Matrix2(0, 0, -1, 1);
4465
+ }
4466
+ compare(matrix) {
4467
+ const { translateX, translateY, scaleX, scaleY, shearX, shearY } = matrix;
4468
+ return this.translateX === translateX && this.translateY === translateY && this.scaleX === scaleX && this.scaleY === scaleY && this.shearX === shearX && this.shearY === shearY;
4469
+ }
4470
+ }
4471
+
4318
4472
  // src/Subject.ts
4319
4473
  class Subject {
4320
4474
  observers = [];
@@ -7255,7 +7409,7 @@ var Browser = /* @__PURE__ */ function() {
7255
7409
  }
7256
7410
  _createClass(Browser2, [{
7257
7411
  key: "init",
7258
- value: function init2(services) {
7412
+ value: function init(services) {
7259
7413
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7260
7414
  var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7261
7415
  this.services = services || {
@@ -7310,7 +7464,7 @@ var Browser = /* @__PURE__ */ function() {
7310
7464
  }
7311
7465
  }, {
7312
7466
  key: "cacheUserLanguage",
7313
- value: function cacheUserLanguage4(lng, caches) {
7467
+ value: function cacheUserLanguage(lng, caches) {
7314
7468
  var _this2 = this;
7315
7469
  if (!caches)
7316
7470
  caches = this.options.caches;
@@ -7709,1044 +7863,237 @@ var conf = {
7709
7863
  };
7710
7864
  initDefaultI18N();
7711
7865
 
7712
- // src/Items/Transformation/Matrix.ts
7713
- class Matrix2 {
7714
- translateX;
7715
- translateY;
7716
- scaleX;
7717
- scaleY;
7718
- shearX;
7719
- shearY;
7720
- constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, shearX = 0, shearY = 0) {
7721
- this.translateX = translateX;
7722
- this.translateY = translateY;
7723
- this.scaleX = scaleX;
7724
- this.scaleY = scaleY;
7725
- this.shearX = shearX;
7726
- this.shearY = shearY;
7727
- this.translateX = toFiniteNumber(translateX);
7728
- this.translateY = toFiniteNumber(translateY);
7729
- this.scaleX = toFiniteNumber(scaleX, 1);
7730
- this.scaleY = toFiniteNumber(scaleY, 1);
7731
- this.shearX = toFiniteNumber(shearX);
7732
- this.shearY = toFiniteNumber(shearY);
7866
+ // src/Items/Path/Path.ts
7867
+ var LinePatterns = {
7868
+ solid: [],
7869
+ dot: [1, 2],
7870
+ dash: [10, 10],
7871
+ longDash: [20, 5],
7872
+ dotDash: [15, 3, 3, 3],
7873
+ tripleDotDash: [20, 3, 3, 3, 3, 3, 3, 3],
7874
+ looseDoubleDotDash: [12, 3, 3]
7875
+ };
7876
+ var LineStyles = [
7877
+ "solid",
7878
+ "dot",
7879
+ "dash",
7880
+ "longDash",
7881
+ "dotDash",
7882
+ "tripleDotDash",
7883
+ "looseDoubleDotDash"
7884
+ ];
7885
+ var scaledPatterns = {};
7886
+ function scalePatterns(scale) {
7887
+ function scaleLinePattern(pattern) {
7888
+ const scaledPattern = [];
7889
+ for (const number of LinePatterns[pattern]) {
7890
+ scaledPattern.push(number * scale);
7891
+ }
7892
+ return scaledPattern;
7733
7893
  }
7734
- translate(x, y) {
7735
- this.translateX += x;
7736
- this.translateY += y;
7894
+ const slp = scaleLinePattern;
7895
+ if (!scaledPatterns[scale]) {
7896
+ scaledPatterns[scale] = {
7897
+ solid: slp("solid"),
7898
+ dot: slp("dot"),
7899
+ dash: slp("dash"),
7900
+ longDash: slp("longDash"),
7901
+ dotDash: slp("dotDash"),
7902
+ tripleDotDash: slp("tripleDotDash"),
7903
+ looseDoubleDotDash: slp("looseDoubleDotDash")
7904
+ };
7737
7905
  }
7738
- scale(x, y) {
7739
- this.scaleX = this.scaleX * x;
7740
- this.scaleY = this.scaleY * y;
7906
+ return scaledPatterns[scale];
7907
+ }
7908
+ var borderWidths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
7909
+
7910
+ class Path {
7911
+ segments;
7912
+ isClosedValue;
7913
+ backgroundColor;
7914
+ borderColor;
7915
+ borderStyle;
7916
+ borderWidth;
7917
+ backgroundOpacity;
7918
+ borderOpacity;
7919
+ shadowColor;
7920
+ shadowBlur;
7921
+ shadowOffsetX;
7922
+ shadowOffsetY;
7923
+ paddingTop;
7924
+ paddingRight;
7925
+ paddingBottom;
7926
+ paddingLeft;
7927
+ path2d;
7928
+ x;
7929
+ y;
7930
+ width;
7931
+ height;
7932
+ maxDimension;
7933
+ linePattern;
7934
+ connectedItemType = "";
7935
+ 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) {
7936
+ this.segments = segments;
7937
+ this.isClosedValue = isClosedValue;
7938
+ this.backgroundColor = backgroundColor;
7939
+ this.borderColor = borderColor;
7940
+ this.borderStyle = borderStyle;
7941
+ this.borderWidth = borderWidth;
7942
+ this.backgroundOpacity = backgroundOpacity;
7943
+ this.borderOpacity = borderOpacity;
7944
+ this.shadowColor = shadowColor;
7945
+ this.shadowBlur = shadowBlur;
7946
+ this.shadowOffsetX = shadowOffsetX;
7947
+ this.shadowOffsetY = shadowOffsetY;
7948
+ this.paddingTop = paddingTop;
7949
+ this.paddingRight = paddingRight;
7950
+ this.paddingBottom = paddingBottom;
7951
+ this.paddingLeft = paddingLeft;
7952
+ this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7953
+ const mbr = this.getMbr();
7954
+ this.x = mbr.left;
7955
+ this.y = mbr.top;
7956
+ this.width = this.getMbr().getWidth();
7957
+ this.height = this.getMbr().getHeight();
7958
+ this.maxDimension = Math.max(mbr.getWidth(), mbr.getHeight());
7959
+ this.path2d = new conf.path2DFactory;
7960
+ this.updateCache();
7741
7961
  }
7742
- multiplyByMatrix(matrix) {
7743
- const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this;
7744
- this.translateX = scaleX * matrix.translateX + shearX * matrix.translateY + translateX;
7745
- this.translateY = shearY * matrix.translateX + scaleY * matrix.translateY + translateY;
7746
- this.scaleX = scaleX * matrix.scaleX + shearX * matrix.shearY;
7747
- this.scaleY = shearY * matrix.shearX + scaleY * matrix.scaleY;
7748
- this.shearX = scaleX * matrix.shearX + shearX * matrix.scaleY;
7749
- this.shearY = shearY * matrix.scaleX + scaleY * matrix.shearY;
7750
- return this;
7962
+ getBackgroundColor() {
7963
+ return this.backgroundColor;
7751
7964
  }
7752
- multiplyByMatrixies(matrixies) {
7753
- for (const matrix of matrixies) {
7754
- this.multiplyByMatrix(matrix);
7755
- }
7756
- return this;
7965
+ getBorderColor() {
7966
+ return this.borderColor;
7757
7967
  }
7758
- multiply(value) {
7759
- if (Array.isArray(value)) {
7760
- this.multiplyByMatrixies(value);
7761
- } else {
7762
- this.multiplyByMatrix(value);
7763
- }
7764
- return this;
7968
+ getBorderStyle() {
7969
+ return this.borderStyle;
7765
7970
  }
7766
- copy() {
7767
- return new Matrix2(this.translateX, this.translateY, this.scaleX, this.scaleY, this.shearX, this.shearY);
7971
+ getBorderWidth() {
7972
+ return this.borderWidth;
7768
7973
  }
7769
- invert() {
7770
- const { scaleX, shearY, shearX, scaleY, translateX, translateY } = this;
7771
- const denom = scaleX * scaleY - shearX * shearY;
7772
- this.scaleX = scaleY / denom;
7773
- this.shearY = shearY / -denom;
7774
- this.shearX = shearX / -denom;
7775
- this.scaleY = scaleX / denom;
7776
- this.translateX = (scaleY * translateX - shearX * translateY) / -denom;
7777
- this.translateY = (shearY * translateX - scaleX * translateY) / denom;
7974
+ setBackgroundColor(color) {
7975
+ this.backgroundColor = color;
7778
7976
  }
7779
- getInverse() {
7780
- const inverse = this.copy();
7781
- inverse.invert();
7782
- return inverse;
7977
+ setBorderColor(color) {
7978
+ this.borderColor = color;
7783
7979
  }
7784
- rotateByRadian(radian) {
7785
- const cosAngle = Math.cos(radian);
7786
- const sinAngle = Math.sin(radian);
7787
- const rotationMatrix = new Matrix2(0, 0, cosAngle, cosAngle, -sinAngle, sinAngle);
7788
- return this.multiply(rotationMatrix);
7980
+ setBorderStyle(style) {
7981
+ this.borderStyle = style;
7982
+ this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7789
7983
  }
7790
- rotateBy(degree) {
7791
- const radian = degree * Math.PI / 180;
7792
- this.rotateByRadian(radian);
7984
+ setBorderWidth(width) {
7985
+ this.borderWidth = width;
7986
+ this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
7793
7987
  }
7794
- rotateByObjectCenter(degree, size, scale) {
7795
- const angle = degree * (Math.PI / 180);
7796
- const width = size.width * scale.x;
7797
- const height = size.height * scale.y;
7798
- const centerX = width / 2;
7799
- const centerY = height / 2;
7800
- const x = centerX - (centerX * Math.cos(angle) - centerY * Math.sin(angle));
7801
- const y = centerY - (centerX * Math.sin(angle) + centerY * Math.cos(angle));
7802
- this.rotateBy(degree);
7803
- this.translate(x, y);
7988
+ getShadowColor() {
7989
+ return this.shadowColor;
7804
7990
  }
7805
- rotateByRelativeTo(degree, x, y) {
7806
- this.translateX += x;
7807
- this.translateY += y;
7808
- this.rotateBy(degree);
7809
- this.translateX -= x;
7810
- this.translateY -= y;
7991
+ setShadowColor(color) {
7992
+ this.shadowColor = color;
7811
7993
  }
7812
- rotateByRadianRelativeTo(radian, x, y) {
7813
- this.translateX += x;
7814
- this.translateY += y;
7815
- this.rotateByRadian(radian);
7816
- this.translateX -= x;
7817
- this.translateY -= y;
7994
+ getShadowBlur() {
7995
+ return this.shadowBlur;
7818
7996
  }
7819
- apply(point) {
7820
- const { x, y } = point;
7821
- point.x = this.scaleX * x + this.shearX * y + this.translateX;
7822
- point.y = this.shearY * x + this.scaleY * y + this.translateY;
7997
+ setShadowBlur(blur) {
7998
+ this.shadowBlur = blur;
7823
7999
  }
7824
- applyToContext(ctx) {
7825
- ctx.transform(this.scaleX, this.shearY, this.shearX, this.scaleY, this.translateX, this.translateY);
8000
+ getShadowOffsetX() {
8001
+ return this.shadowOffsetX;
7826
8002
  }
7827
- getAffineMatrix() {
7828
- return {
7829
- a: this.scaleX,
7830
- b: this.shearY,
7831
- c: this.shearX,
7832
- d: this.scaleY,
7833
- e: this.translateX,
7834
- f: this.translateY
7835
- };
8003
+ setShadowOffsetX(offsetX) {
8004
+ this.shadowOffsetX = offsetX;
7836
8005
  }
7837
- getCssString() {
7838
- return `matrix(${this.scaleX},${this.shearY},${this.shearX},${this.scaleY},${this.translateX},${this.translateY})`;
8006
+ getShadowOffsetY() {
8007
+ return this.shadowOffsetY;
7839
8008
  }
7840
- identity() {
7841
- return new Matrix2;
8009
+ setShadowOffsetY(offsetY) {
8010
+ this.shadowOffsetY = offsetY;
7842
8011
  }
7843
- mirrorOrigin() {
7844
- return new Matrix2(0, 0, -1, -1);
8012
+ getBackgroundOpacity() {
8013
+ return this.backgroundOpacity;
7845
8014
  }
7846
- mirrorX() {
7847
- return new Matrix2(0, 0, 1, -1);
8015
+ setBackgroundOpacity(opacity) {
8016
+ this.backgroundOpacity = opacity;
7848
8017
  }
7849
- mirrorY() {
7850
- return new Matrix2(0, 0, -1, 1);
8018
+ getBorderOpacity() {
8019
+ return this.borderOpacity;
7851
8020
  }
7852
- compare(matrix) {
7853
- const { translateX, translateY, scaleX, scaleY, shearX, shearY } = matrix;
7854
- return this.translateX === translateX && this.translateY === translateY && this.scaleX === scaleX && this.scaleY === scaleY && this.shearX === shearX && this.shearY === shearY;
8021
+ getWidth() {
8022
+ return this.width;
7855
8023
  }
7856
- }
7857
- // src/SubjectOperation.ts
7858
- class SubjectOperation {
7859
- observers = [];
7860
- subscribe(observer) {
7861
- const index = this.observers.indexOf(observer);
7862
- if (index === -1) {
7863
- this.observers.push(observer);
8024
+ getHeight() {
8025
+ return this.height;
8026
+ }
8027
+ setBorderOpacity(opacity) {
8028
+ this.borderOpacity = opacity;
8029
+ }
8030
+ updateCache() {
8031
+ const { left, top, right, bottom } = this.getMbr();
8032
+ this.x = left - this.paddingLeft;
8033
+ this.y = top - this.paddingTop;
8034
+ this.width = right - left + this.paddingLeft + this.paddingRight;
8035
+ this.height = bottom - top + this.paddingTop + this.paddingBottom;
8036
+ const path2d = new conf.path2DFactory;
8037
+ if (this.segments.length === 0) {
8038
+ return;
8039
+ }
8040
+ this.segments[0].moveToStart(path2d);
8041
+ for (const segment of this.segments) {
8042
+ segment.render(path2d);
8043
+ }
8044
+ if (this.isClosedValue) {
8045
+ path2d.closePath();
7864
8046
  }
8047
+ this.path2d = path2d;
7865
8048
  }
7866
- unsubscribe(observer) {
7867
- const index = this.observers.indexOf(observer);
7868
- if (index !== -1) {
7869
- this.observers.splice(index, 1);
8049
+ getIntersectionPoints(segment) {
8050
+ let intersections = [];
8051
+ for (const item of this.segments) {
8052
+ intersections = intersections.concat(item.getIntersectionPoints(segment));
7870
8053
  }
8054
+ return intersections;
7871
8055
  }
7872
- publish(subject, op) {
7873
- for (const observer of this.observers) {
7874
- observer(subject, op);
8056
+ getNearestEdgePointTo(point) {
8057
+ return this.getNearestEdgeAndPointTo(point).point;
8058
+ }
8059
+ getNearestEdgeAndPointTo(point) {
8060
+ const candidates = [];
8061
+ for (let index = 0;index < this.segments.length; index++) {
8062
+ const segment = this.segments[index];
8063
+ const pointOnSegment = segment.getNearestEdgePointTo(point);
8064
+ candidates.push({
8065
+ index,
8066
+ segment,
8067
+ point: pointOnSegment,
8068
+ distance: point.getDistance(pointOnSegment)
8069
+ });
8070
+ }
8071
+ let nearest = candidates[0];
8072
+ for (const candidate of candidates) {
8073
+ if (candidate.distance < nearest.distance) {
8074
+ nearest = candidate;
8075
+ }
7875
8076
  }
8077
+ return nearest;
7876
8078
  }
7877
- }
7878
-
7879
- // src/Items/ItemsCommandUtils.ts
7880
- function mapItemsByOperation(item, getCallback) {
7881
- const items = Array.isArray(item) ? item : [item];
7882
- return items.map((item2) => {
7883
- const operation = getCallback(item2);
7884
- return { item: item2, operation };
7885
- });
7886
- }
7887
-
7888
- // src/Items/Transformation/TransformationCommand.ts
7889
- class TransformationCommand {
7890
- transformation;
7891
- operation;
7892
- reverse;
7893
- constructor(transformation, operation) {
7894
- this.transformation = transformation;
7895
- this.operation = operation;
7896
- this.reverse = this.getReverse();
8079
+ getDistanceToPoint(point) {
8080
+ const nearest = this.getNearestEdgePointTo(point);
8081
+ return point.getDistance(nearest);
7897
8082
  }
7898
- merge(op) {
7899
- this.operation = op;
7900
- this.reverse = this.getReverse();
7901
- return this;
8083
+ isUnderPoint(point) {
8084
+ return this.isEnclosedOrCrossedBy(new Mbr(point.x, point.y, point.x, point.y));
7902
8085
  }
7903
- apply() {
7904
- for (const transformation of this.transformation) {
7905
- transformation.apply(this.operation);
8086
+ isPointOverEdges(point, tolerance = 5) {
8087
+ for (const segment of this.segments) {
8088
+ const distance = segment.getDistance(point);
8089
+ if (distance <= tolerance) {
8090
+ return true;
8091
+ }
7906
8092
  }
8093
+ return false;
7907
8094
  }
7908
- revert() {
7909
- this.reverse.forEach(({ item, operation }) => {
7910
- item.apply(operation);
7911
- });
7912
- }
7913
- getReverse() {
7914
- const op = this.operation;
7915
- switch (this.operation.method) {
7916
- case "applyMatrix": {
7917
- const op2 = this.operation;
7918
- return this.transformation.map((t3) => {
7919
- const itemOp = op2.items.find((i) => i.id === t3.getId());
7920
- if (!itemOp)
7921
- return { item: t3, operation: op2 };
7922
- return {
7923
- item: t3,
7924
- operation: {
7925
- class: "Transformation",
7926
- method: "applyMatrix",
7927
- items: [{
7928
- id: t3.getId(),
7929
- matrix: {
7930
- translateX: -itemOp.matrix.translateX,
7931
- translateY: -itemOp.matrix.translateY,
7932
- scaleX: 1 / itemOp.matrix.scaleX,
7933
- scaleY: 1 / itemOp.matrix.scaleY,
7934
- shearX: 0,
7935
- shearY: 0
7936
- }
7937
- }]
7938
- }
7939
- };
7940
- });
7941
- }
7942
- case "translateTo":
7943
- return mapItemsByOperation(this.transformation, (transformation) => {
7944
- return {
7945
- ...this.operation,
7946
- x: transformation.getTranslation().x,
7947
- y: transformation.getTranslation().y
7948
- };
7949
- });
7950
- case "translateBy": {
7951
- const op2 = this.operation;
7952
- return mapItemsByOperation(this.transformation, () => {
7953
- return {
7954
- ...this.operation,
7955
- x: -op2.x,
7956
- y: -op2.y
7957
- };
7958
- });
7959
- }
7960
- case "scaleTo":
7961
- case "scaleToRelativeTo": {
7962
- return mapItemsByOperation(this.transformation, (transformation) => {
7963
- return {
7964
- ...op,
7965
- x: transformation.getScale().x,
7966
- y: transformation.getScale().y
7967
- };
7968
- });
7969
- }
7970
- case "scaleBy":
7971
- case "scaleByRelativeTo": {
7972
- const op2 = this.operation;
7973
- return mapItemsByOperation(this.transformation, () => {
7974
- return {
7975
- ...op2,
7976
- x: 1 / op2.x,
7977
- y: 1 / op2.y
7978
- };
7979
- });
7980
- }
7981
- case "scaleByTranslateBy": {
7982
- const op2 = this.operation;
7983
- const scaleTransformation = mapItemsByOperation(this.transformation, () => {
7984
- const scaleX = 1 / op2.scale.x;
7985
- const scaleY = 1 / op2.scale.y;
7986
- const translateX = -op2.translate.x;
7987
- const translateY = -op2.translate.y;
7988
- return {
7989
- ...op2,
7990
- scale: {
7991
- x: scaleX,
7992
- y: scaleY
7993
- },
7994
- translate: {
7995
- x: translateX,
7996
- y: translateY
7997
- }
7998
- };
7999
- });
8000
- return scaleTransformation;
8001
- }
8002
- case "rotateTo":
8003
- return mapItemsByOperation(this.transformation, (transformation) => {
8004
- return {
8005
- ...this.operation,
8006
- degree: transformation.getRotation()
8007
- };
8008
- });
8009
- case "rotateBy": {
8010
- const op2 = this.operation;
8011
- return mapItemsByOperation(this.transformation, () => {
8012
- return {
8013
- ...this.operation,
8014
- degree: -op2.degree
8015
- };
8016
- });
8017
- }
8018
- case "transformMany": {
8019
- const { operation, transformation } = this;
8020
- return transformation.map((currTrans) => {
8021
- const op2 = operation.items[currTrans.getId()];
8022
- 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 };
8023
- return {
8024
- item: currTrans,
8025
- operation: {
8026
- class: "Transformation",
8027
- method: "applyMatrix",
8028
- items: [{
8029
- id: currTrans.getId(),
8030
- matrix: {
8031
- translateX: op2.method === "applyMatrix" ? -m.translateX : m.translateX,
8032
- translateY: op2.method === "applyMatrix" ? -m.translateY : m.translateY,
8033
- scaleX: op2.method === "applyMatrix" ? 1 / m.scaleX : m.scaleX,
8034
- scaleY: op2.method === "applyMatrix" ? 1 / m.scaleY : m.scaleY,
8035
- shearX: 0,
8036
- shearY: 0
8037
- }
8038
- }]
8039
- }
8040
- };
8041
- });
8042
- }
8043
- case "locked": {
8044
- const op2 = this.operation;
8045
- return mapItemsByOperation(this.transformation, () => {
8046
- return {
8047
- ...op2,
8048
- item: [...op2.item],
8049
- method: "unlocked",
8050
- locked: false
8051
- };
8052
- });
8053
- }
8054
- case "unlocked": {
8055
- const op2 = this.operation;
8056
- return mapItemsByOperation(this.transformation, () => {
8057
- return {
8058
- ...op2,
8059
- item: [...op2.item],
8060
- method: "locked",
8061
- locked: true
8062
- };
8063
- });
8064
- }
8065
- default:
8066
- return [
8067
- { item: this.transformation[0], operation: this.operation }
8068
- ];
8069
- }
8070
- }
8071
- }
8072
-
8073
- // src/Items/Transformation/TransformationData.ts
8074
- class DefaultTransformationData {
8075
- translateX;
8076
- translateY;
8077
- scaleX;
8078
- scaleY;
8079
- rotate;
8080
- isLocked;
8081
- constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, rotate = 0, isLocked = false) {
8082
- this.translateX = translateX;
8083
- this.translateY = translateY;
8084
- this.scaleX = scaleX;
8085
- this.scaleY = scaleY;
8086
- this.rotate = rotate;
8087
- this.isLocked = isLocked;
8088
- }
8089
- }
8090
-
8091
- // src/Items/Transformation/Transformation.ts
8092
- var defaultData = new DefaultTransformationData;
8093
-
8094
- class Transformation {
8095
- id;
8096
- events;
8097
- subject = new SubjectOperation;
8098
- _matrix = new Matrix2;
8099
- previous = new Matrix2;
8100
- rotate = defaultData.rotate;
8101
- isLocked = false;
8102
- constructor(id = "", events) {
8103
- this.id = id;
8104
- this.events = events;
8105
- }
8106
- getMatrixData() {
8107
- const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this._matrix;
8108
- return { translateX, translateY, scaleX, scaleY, shearX, shearY };
8109
- }
8110
- toMatrix() {
8111
- return this._matrix.copy();
8112
- }
8113
- applyToContext(ctx) {
8114
- this._matrix.applyToContext(ctx);
8115
- }
8116
- getTranslation() {
8117
- return { x: this._matrix.translateX, y: this._matrix.translateY };
8118
- }
8119
- getScale() {
8120
- return { x: this._matrix.scaleX, y: this._matrix.scaleY };
8121
- }
8122
- getRotation() {
8123
- return this.rotate;
8124
- }
8125
- setLocal(xOrData, y, scaleX, scaleY) {
8126
- this.previous = this._matrix.copy();
8127
- if (typeof xOrData === "object") {
8128
- if (xOrData.translateX !== undefined)
8129
- this._matrix.translateX = xOrData.translateX;
8130
- if (xOrData.translateY !== undefined)
8131
- this._matrix.translateY = xOrData.translateY;
8132
- if (xOrData.scaleX !== undefined)
8133
- this._matrix.scaleX = xOrData.scaleX;
8134
- if (xOrData.scaleY !== undefined)
8135
- this._matrix.scaleY = xOrData.scaleY;
8136
- } else {
8137
- this._matrix.translateX = xOrData;
8138
- this._matrix.translateY = y;
8139
- if (scaleX !== undefined)
8140
- this._matrix.scaleX = scaleX;
8141
- if (scaleY !== undefined)
8142
- this._matrix.scaleY = scaleY;
8143
- }
8144
- this.subject.publish(this, {
8145
- class: "Transformation",
8146
- method: "applyMatrix",
8147
- items: [{ id: this.id, matrix: this.getMatrixData() }]
8148
- });
8149
- }
8150
- serialize() {
8151
- return {
8152
- translateX: this._matrix.translateX,
8153
- translateY: this._matrix.translateY,
8154
- scaleX: this._matrix.scaleX,
8155
- scaleY: this._matrix.scaleY,
8156
- rotate: this.rotate,
8157
- isLocked: this.isLocked
8158
- };
8159
- }
8160
- deserialize(data) {
8161
- this.previous = this._matrix.copy();
8162
- if (data.translateX) {
8163
- this._matrix.translateX = data.translateX;
8164
- }
8165
- if (data.translateY) {
8166
- this._matrix.translateY = data.translateY;
8167
- }
8168
- if (data.scaleX) {
8169
- this._matrix.scaleX = data.scaleX;
8170
- }
8171
- if (data.scaleY) {
8172
- this._matrix.scaleY = data.scaleY;
8173
- }
8174
- if (data.isLocked) {
8175
- this.isLocked = data.isLocked;
8176
- }
8177
- if (data.rotate) {
8178
- this.rotate = data.rotate;
8179
- }
8180
- this.subject.publish(this, {
8181
- class: "Transformation",
8182
- method: "deserialize",
8183
- item: [this.id],
8184
- data
8185
- });
8186
- return this;
8187
- }
8188
- copy(id) {
8189
- const { translateX, translateY, scaleX, scaleY } = this._matrix;
8190
- const { rotate } = this;
8191
- return new Transformation(id || "", this.events).deserialize({
8192
- translateX,
8193
- translateY,
8194
- scaleX,
8195
- scaleY,
8196
- rotate,
8197
- isLocked: false
8198
- });
8199
- }
8200
- getInverse() {
8201
- const copy2 = this.copy();
8202
- copy2._matrix.invert();
8203
- return copy2;
8204
- }
8205
- getId() {
8206
- return this.id;
8207
- }
8208
- setId(id) {
8209
- this.id = id;
8210
- }
8211
- emit(operation) {
8212
- if (this.events) {
8213
- const command = new TransformationCommand([this], operation);
8214
- command.apply();
8215
- this.events.emit(operation, command);
8216
- } else {
8217
- this.apply(operation);
8218
- }
8219
- }
8220
- emitMatrix(matrix, timeStamp) {
8221
- this.emit({
8222
- class: "Transformation",
8223
- method: "applyMatrix",
8224
- items: [{ id: this.id, matrix }],
8225
- timeStamp
8226
- });
8227
- }
8228
- translateTo(x, y, timeStamp) {
8229
- if (!this.id) {}
8230
- this.emitMatrix({
8231
- translateX: x - this._matrix.translateX,
8232
- translateY: y - this._matrix.translateY,
8233
- scaleX: 1,
8234
- scaleY: 1,
8235
- shearX: 0,
8236
- shearY: 0
8237
- }, timeStamp);
8238
- }
8239
- translateBy(x, y, timeStamp) {
8240
- if (!this.id) {}
8241
- if (x === 0 && y === 0) {
8242
- return;
8243
- }
8244
- this.emitMatrix({
8245
- translateX: x,
8246
- translateY: y,
8247
- scaleX: 1,
8248
- scaleY: 1,
8249
- shearX: 0,
8250
- shearY: 0
8251
- }, timeStamp);
8252
- }
8253
- scaleTo(x, y, timeStamp) {
8254
- this.emitMatrix({
8255
- translateX: 0,
8256
- translateY: 0,
8257
- scaleX: x / this._matrix.scaleX,
8258
- scaleY: y / this._matrix.scaleY,
8259
- shearX: 0,
8260
- shearY: 0
8261
- }, timeStamp);
8262
- }
8263
- scaleBy(x, y, timeStamp) {
8264
- if (x === 0 && y === 0) {
8265
- return;
8266
- }
8267
- this.emitMatrix({
8268
- translateX: 0,
8269
- translateY: 0,
8270
- scaleX: x,
8271
- scaleY: y,
8272
- shearX: 0,
8273
- shearY: 0
8274
- }, timeStamp);
8275
- }
8276
- scaleByTranslateBy(scale, translate, timeStamp) {
8277
- if (scale.x === 0 && scale.y === 0 && translate.x === 0 && translate.y === 0) {
8278
- return;
8279
- }
8280
- this.emitMatrix({
8281
- translateX: translate.x,
8282
- translateY: translate.y,
8283
- scaleX: scale.x,
8284
- scaleY: scale.y,
8285
- shearX: 0,
8286
- shearY: 0
8287
- }, timeStamp);
8288
- }
8289
- rotateTo(degree, timeStamp) {
8290
- this.emit({
8291
- class: "Transformation",
8292
- method: "rotateTo",
8293
- item: [this.id],
8294
- degree,
8295
- timeStamp
8296
- });
8297
- }
8298
- rotateBy(degree, timeStamp) {
8299
- this.emit({
8300
- class: "Transformation",
8301
- method: "rotateBy",
8302
- item: [this.id],
8303
- degree,
8304
- timeStamp
8305
- });
8306
- }
8307
- scaleToRelativeTo(x, y, _point, timeStamp) {
8308
- this.emitMatrix({
8309
- translateX: 0,
8310
- translateY: 0,
8311
- scaleX: x / this._matrix.scaleX,
8312
- scaleY: y / this._matrix.scaleY,
8313
- shearX: 0,
8314
- shearY: 0
8315
- }, timeStamp);
8316
- }
8317
- scaleByRelativeTo(x, y, point, timeStamp) {
8318
- const { scaleX: sx0, scaleY: sy0, translateX: tx0, translateY: ty0 } = this._matrix;
8319
- const newSx = sx0 * x;
8320
- const newSy = sy0 * y;
8321
- this.emitMatrix({
8322
- translateX: -point.x * newSx + point.x - tx0,
8323
- translateY: -point.y * newSy + point.y - ty0,
8324
- scaleX: x,
8325
- scaleY: y,
8326
- shearX: 0,
8327
- shearY: 0
8328
- }, timeStamp);
8329
- }
8330
- setIsLocked(isLocked, timestamp) {
8331
- if (isLocked) {
8332
- this.emit({
8333
- class: "Transformation",
8334
- method: "locked",
8335
- item: [this.id],
8336
- locked: true,
8337
- timestamp
8338
- });
8339
- } else {
8340
- this.emit({
8341
- class: "Transformation",
8342
- method: "unlocked",
8343
- item: [this.id],
8344
- locked: false,
8345
- timestamp
8346
- });
8347
- }
8348
- }
8349
- apply(op) {
8350
- this.previous = this._matrix.copy();
8351
- switch (op.method) {
8352
- case "applyMatrix": {
8353
- const itemOp = op.items.find((i) => i.id === this.id);
8354
- if (itemOp) {
8355
- this._matrix.scale(itemOp.matrix.scaleX, itemOp.matrix.scaleY);
8356
- this._matrix.translate(itemOp.matrix.translateX, itemOp.matrix.translateY);
8357
- }
8358
- break;
8359
- }
8360
- case "translateTo":
8361
- this.applyTranslateTo(op.x, op.y);
8362
- break;
8363
- case "translateBy":
8364
- this.applyTranslateBy(op.x, op.y);
8365
- break;
8366
- case "scaleTo":
8367
- this.applyScaleTo(op.x, op.y);
8368
- break;
8369
- case "scaleBy":
8370
- this.applyScaleBy(op.x, op.y);
8371
- break;
8372
- case "scaleToRelativeTo":
8373
- this.applyScaleToRelativeTo(op.x, op.y, op.point);
8374
- break;
8375
- case "scaleByRelativeTo":
8376
- this.applyScaleByRelativeTo(op.x, op.y, op.point);
8377
- break;
8378
- case "scaleByTranslateBy":
8379
- this.applyScaleByTranslateBy(op.scale, op.translate);
8380
- break;
8381
- case "rotateTo":
8382
- this.applyRotateTo(op.degree);
8383
- break;
8384
- case "rotateBy":
8385
- this.applyRotateBy(op.degree);
8386
- break;
8387
- case "transformMany":
8388
- this.applyTransformMany(op.items[this.id]);
8389
- break;
8390
- case "locked":
8391
- this.applyLocked(op.locked);
8392
- break;
8393
- case "unlocked":
8394
- this.applyUnlocked(op.locked);
8395
- break;
8396
- default:
8397
- return;
8398
- }
8399
- this.subject.publish(this, op);
8400
- }
8401
- applyTranslateTo(x, y) {
8402
- this._matrix.translateX = x;
8403
- this._matrix.translateY = y;
8404
- }
8405
- applyTranslateBy(x, y) {
8406
- this._matrix.translate(x, y);
8407
- }
8408
- applyScaleTo(x, y) {
8409
- this._matrix.scaleX = x;
8410
- this._matrix.scaleY = y;
8411
- }
8412
- applyScaleBy(x, y) {
8413
- this._matrix.scale(x, y);
8414
- }
8415
- applyScaleByTranslateBy(scale, translate) {
8416
- this._matrix.scale(scale.x, scale.y);
8417
- this._matrix.translate(translate.x, translate.y);
8418
- }
8419
- applyTransformMany(op) {
8420
- if (op.method === "applyMatrix") {
8421
- this._matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
8422
- this._matrix.translate(op.matrix.translateX, op.matrix.translateY);
8423
- } else if (op.method === "scaleByTranslateBy") {
8424
- this.applyScaleByTranslateBy(op.scale, op.translate);
8425
- } else if (op.method === "scaleBy") {
8426
- this.applyScaleBy(op.x, op.y);
8427
- } else if (op.method === "translateBy") {
8428
- this.applyTranslateBy(op.x, op.y);
8429
- } else if (op.method === "translateTo") {
8430
- this.applyTranslateTo(op.x, op.y);
8431
- }
8432
- }
8433
- applyScaleByRelativeTo(x, y, point) {
8434
- const scaleX = this._matrix.scaleX * x;
8435
- const scaleY = this._matrix.scaleY * y;
8436
- this._matrix.translateX = -point.x * scaleX + point.x;
8437
- this._matrix.translateY = -point.y * scaleY + point.y;
8438
- this._matrix.scaleX = scaleX;
8439
- this._matrix.scaleY = scaleY;
8440
- }
8441
- applyScaleToRelativeTo(x, y, point) {
8442
- this.applyTranslateBy(-point.x, -point.y);
8443
- this.applyScaleTo(x, y);
8444
- this.applyTranslateBy(point.x, point.y);
8445
- }
8446
- applyRotateTo(degree) {
8447
- if (degree > 0) {
8448
- while (degree > 360) {
8449
- degree -= 360;
8450
- }
8451
- if (degree === 360) {
8452
- degree = 0;
8453
- }
8454
- } else {
8455
- while (degree < -360) {
8456
- degree += 360;
8457
- }
8458
- if (degree === -360) {
8459
- degree = 0;
8460
- }
8461
- }
8462
- this.rotate = degree;
8463
- }
8464
- applyRotateBy(degree) {
8465
- this.applyRotateTo(this.rotate + degree);
8466
- }
8467
- applyLocked(locked) {
8468
- this.isLocked = locked;
8469
- }
8470
- applyUnlocked(locked) {
8471
- this.isLocked = locked;
8472
- }
8473
- }
8474
- // src/Items/DrawingContext.ts
8475
- class DrawingContext {
8476
- camera;
8477
- ctx;
8478
- cursorCtx;
8479
- matrix;
8480
- isBorderInvisible = false;
8481
- shapeVisibilityTreshold = 3;
8482
- rectangleVisibilyTreshold = 2;
8483
- constructor(camera, ctx, cursorCtx, matrix = new Matrix2) {
8484
- this.camera = camera;
8485
- this.ctx = ctx;
8486
- this.cursorCtx = cursorCtx;
8487
- this.matrix = matrix;
8488
- this.setCamera(camera);
8489
- }
8490
- dpi() {
8491
- return conf.getDPI();
8492
- }
8493
- setCamera(camera) {
8494
- this.camera = camera;
8495
- this.matrix = camera.getMatrix();
8496
- const scale = this.matrix.scaleX;
8497
- this.isBorderInvisible = 4 * scale < 0.1;
8498
- }
8499
- clear() {
8500
- this.ctx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
8501
- this.ctx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
8502
- this.matrix.applyToContext(this.ctx);
8503
- }
8504
- clearCursor() {
8505
- if (!this.cursorCtx) {
8506
- return;
8507
- }
8508
- this.cursorCtx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
8509
- this.cursorCtx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
8510
- this.matrix.applyToContext(this.cursorCtx);
8511
- }
8512
- applyChanges() {
8513
- this.matrix.applyToContext(this.ctx);
8514
- }
8515
- getCameraScale() {
8516
- return this.camera.getScale();
8517
- }
8518
- }
8519
- // src/Items/Path/Path.ts
8520
- var LinePatterns = {
8521
- solid: [],
8522
- dot: [1, 2],
8523
- dash: [10, 10],
8524
- longDash: [20, 5],
8525
- dotDash: [15, 3, 3, 3],
8526
- tripleDotDash: [20, 3, 3, 3, 3, 3, 3, 3],
8527
- looseDoubleDotDash: [12, 3, 3]
8528
- };
8529
- var LineStyles = [
8530
- "solid",
8531
- "dot",
8532
- "dash",
8533
- "longDash",
8534
- "dotDash",
8535
- "tripleDotDash",
8536
- "looseDoubleDotDash"
8537
- ];
8538
- var scaledPatterns = {};
8539
- function scalePatterns(scale) {
8540
- function scaleLinePattern(pattern) {
8541
- const scaledPattern = [];
8542
- for (const number of LinePatterns[pattern]) {
8543
- scaledPattern.push(number * scale);
8544
- }
8545
- return scaledPattern;
8546
- }
8547
- const slp = scaleLinePattern;
8548
- if (!scaledPatterns[scale]) {
8549
- scaledPatterns[scale] = {
8550
- solid: slp("solid"),
8551
- dot: slp("dot"),
8552
- dash: slp("dash"),
8553
- longDash: slp("longDash"),
8554
- dotDash: slp("dotDash"),
8555
- tripleDotDash: slp("tripleDotDash"),
8556
- looseDoubleDotDash: slp("looseDoubleDotDash")
8557
- };
8558
- }
8559
- return scaledPatterns[scale];
8560
- }
8561
- var borderWidths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
8562
-
8563
- class Path {
8564
- segments;
8565
- isClosedValue;
8566
- backgroundColor;
8567
- borderColor;
8568
- borderStyle;
8569
- borderWidth;
8570
- backgroundOpacity;
8571
- borderOpacity;
8572
- shadowColor;
8573
- shadowBlur;
8574
- shadowOffsetX;
8575
- shadowOffsetY;
8576
- paddingTop;
8577
- paddingRight;
8578
- paddingBottom;
8579
- paddingLeft;
8580
- path2d;
8581
- x;
8582
- y;
8583
- width;
8584
- height;
8585
- maxDimension;
8586
- linePattern;
8587
- connectedItemType = "";
8588
- 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) {
8589
- this.segments = segments;
8590
- this.isClosedValue = isClosedValue;
8591
- this.backgroundColor = backgroundColor;
8592
- this.borderColor = borderColor;
8593
- this.borderStyle = borderStyle;
8594
- this.borderWidth = borderWidth;
8595
- this.backgroundOpacity = backgroundOpacity;
8596
- this.borderOpacity = borderOpacity;
8597
- this.shadowColor = shadowColor;
8598
- this.shadowBlur = shadowBlur;
8599
- this.shadowOffsetX = shadowOffsetX;
8600
- this.shadowOffsetY = shadowOffsetY;
8601
- this.paddingTop = paddingTop;
8602
- this.paddingRight = paddingRight;
8603
- this.paddingBottom = paddingBottom;
8604
- this.paddingLeft = paddingLeft;
8605
- this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
8606
- const mbr = this.getMbr();
8607
- this.x = mbr.left;
8608
- this.y = mbr.top;
8609
- this.width = this.getMbr().getWidth();
8610
- this.height = this.getMbr().getHeight();
8611
- this.maxDimension = Math.max(mbr.getWidth(), mbr.getHeight());
8612
- this.path2d = new conf.path2DFactory;
8613
- this.updateCache();
8614
- }
8615
- getBackgroundColor() {
8616
- return this.backgroundColor;
8617
- }
8618
- getBorderColor() {
8619
- return this.borderColor;
8620
- }
8621
- getBorderStyle() {
8622
- return this.borderStyle;
8623
- }
8624
- getBorderWidth() {
8625
- return this.borderWidth;
8626
- }
8627
- setBackgroundColor(color) {
8628
- this.backgroundColor = color;
8629
- }
8630
- setBorderColor(color) {
8631
- this.borderColor = color;
8632
- }
8633
- setBorderStyle(style) {
8634
- this.borderStyle = style;
8635
- this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
8636
- }
8637
- setBorderWidth(width) {
8638
- this.borderWidth = width;
8639
- this.linePattern = scalePatterns(this.borderWidth)[this.borderStyle];
8640
- }
8641
- getShadowColor() {
8642
- return this.shadowColor;
8643
- }
8644
- setShadowColor(color) {
8645
- this.shadowColor = color;
8646
- }
8647
- getShadowBlur() {
8648
- return this.shadowBlur;
8649
- }
8650
- setShadowBlur(blur) {
8651
- this.shadowBlur = blur;
8652
- }
8653
- getShadowOffsetX() {
8654
- return this.shadowOffsetX;
8655
- }
8656
- setShadowOffsetX(offsetX) {
8657
- this.shadowOffsetX = offsetX;
8658
- }
8659
- getShadowOffsetY() {
8660
- return this.shadowOffsetY;
8661
- }
8662
- setShadowOffsetY(offsetY) {
8663
- this.shadowOffsetY = offsetY;
8664
- }
8665
- getBackgroundOpacity() {
8666
- return this.backgroundOpacity;
8667
- }
8668
- setBackgroundOpacity(opacity) {
8669
- this.backgroundOpacity = opacity;
8670
- }
8671
- getBorderOpacity() {
8672
- return this.borderOpacity;
8673
- }
8674
- getWidth() {
8675
- return this.width;
8676
- }
8677
- getHeight() {
8678
- return this.height;
8679
- }
8680
- setBorderOpacity(opacity) {
8681
- this.borderOpacity = opacity;
8682
- }
8683
- updateCache() {
8684
- const { left, top, right, bottom } = this.getMbr();
8685
- this.x = left - this.paddingLeft;
8686
- this.y = top - this.paddingTop;
8687
- this.width = right - left + this.paddingLeft + this.paddingRight;
8688
- this.height = bottom - top + this.paddingTop + this.paddingBottom;
8689
- const path2d = new conf.path2DFactory;
8690
- if (this.segments.length === 0) {
8691
- return;
8692
- }
8693
- this.segments[0].moveToStart(path2d);
8694
- for (const segment of this.segments) {
8695
- segment.render(path2d);
8696
- }
8697
- if (this.isClosedValue) {
8698
- path2d.closePath();
8699
- }
8700
- this.path2d = path2d;
8701
- }
8702
- getIntersectionPoints(segment) {
8703
- let intersections = [];
8704
- for (const item of this.segments) {
8705
- intersections = intersections.concat(item.getIntersectionPoints(segment));
8706
- }
8707
- return intersections;
8708
- }
8709
- getNearestEdgePointTo(point) {
8710
- return this.getNearestEdgeAndPointTo(point).point;
8711
- }
8712
- getNearestEdgeAndPointTo(point) {
8713
- const candidates = [];
8714
- for (let index = 0;index < this.segments.length; index++) {
8715
- const segment = this.segments[index];
8716
- const pointOnSegment = segment.getNearestEdgePointTo(point);
8717
- candidates.push({
8718
- index,
8719
- segment,
8720
- point: pointOnSegment,
8721
- distance: point.getDistance(pointOnSegment)
8722
- });
8723
- }
8724
- let nearest = candidates[0];
8725
- for (const candidate of candidates) {
8726
- if (candidate.distance < nearest.distance) {
8727
- nearest = candidate;
8728
- }
8729
- }
8730
- return nearest;
8731
- }
8732
- getDistanceToPoint(point) {
8733
- const nearest = this.getNearestEdgePointTo(point);
8734
- return point.getDistance(nearest);
8735
- }
8736
- isUnderPoint(point) {
8737
- return this.isEnclosedOrCrossedBy(new Mbr(point.x, point.y, point.x, point.y));
8738
- }
8739
- isPointOverEdges(point, tolerance = 5) {
8740
- for (const segment of this.segments) {
8741
- const distance = segment.getDistance(point);
8742
- if (distance <= tolerance) {
8743
- return true;
8744
- }
8745
- }
8746
- return false;
8747
- }
8748
- isNearPoint(point, distance) {
8749
- return distance > this.getDistanceToPoint(point);
8095
+ isNearPoint(point, distance) {
8096
+ return distance > this.getDistanceToPoint(point);
8750
8097
  }
8751
8098
  getMbr() {
8752
8099
  if (this.segments.length === 0) {
@@ -9161,382 +8508,18 @@ class Paths {
9161
8508
  return !isAllPathsOpened;
9162
8509
  }
9163
8510
  }
9164
- // src/Items/Connector/ConnectorCommand.ts
9165
- class ConnectorCommand {
9166
- connector;
9167
- operation;
9168
- reverse;
9169
- constructor(connector, operation) {
9170
- this.connector = connector;
9171
- this.operation = operation;
9172
- this.reverse = this.getReverse();
9173
- }
9174
- merge(op) {
9175
- this.operation = op;
9176
- return this;
9177
- }
9178
- apply() {
9179
- for (const connector of this.connector) {
9180
- connector.apply(this.operation);
9181
- }
9182
- }
9183
- revert() {
9184
- for (const { item, operation } of this.reverse) {
9185
- item.apply(operation);
9186
- }
9187
- }
9188
- getReverse() {
9189
- const reverse = [];
9190
- switch (this.operation.method) {
9191
- case "setStartPoint":
9192
- for (const connector of this.connector) {
9193
- reverse.push({
9194
- item: connector,
9195
- operation: {
9196
- ...this.operation,
9197
- startPointData: connector.getStartPoint().serialize()
9198
- }
9199
- });
9200
- }
9201
- break;
9202
- case "setEndPoint":
9203
- for (const connector of this.connector) {
9204
- reverse.push({
9205
- item: connector,
9206
- operation: {
9207
- ...this.operation,
9208
- endPointData: connector.getEndPoint().serialize()
9209
- }
9210
- });
9211
- }
9212
- break;
9213
- case "setMiddlePoint":
9214
- for (const connector of this.connector) {
9215
- const middlePoint = connector.getMiddlePoint();
9216
- reverse.push({
9217
- item: connector,
9218
- operation: {
9219
- ...this.operation,
9220
- middlePointData: middlePoint ? middlePoint.serialize() : null
9221
- }
9222
- });
9223
- }
9224
- break;
9225
- case "setStartPointerStyle":
9226
- for (const connector of this.connector) {
9227
- reverse.push({
9228
- item: connector,
9229
- operation: {
9230
- ...this.operation,
9231
- startPointerStyle: connector.getStartPointerStyle()
9232
- }
9233
- });
9234
- }
9235
- break;
9236
- case "setEndPointerStyle":
9237
- for (const connector of this.connector) {
9238
- reverse.push({
9239
- item: connector,
9240
- operation: {
9241
- ...this.operation,
9242
- endPointerStyle: connector.getEndPointerStyle()
9243
- }
9244
- });
9245
- }
9246
- break;
9247
- case "setLineStyle":
9248
- for (const connector of this.connector) {
9249
- reverse.push({
9250
- item: connector,
9251
- operation: {
9252
- ...this.operation,
9253
- lineStyle: connector.getLineStyle()
9254
- }
9255
- });
9256
- }
9257
- break;
9258
- case "setBorderStyle":
9259
- for (const connector of this.connector) {
9260
- reverse.push({
9261
- item: connector,
9262
- operation: {
9263
- ...this.operation,
9264
- borderStyle: connector.getBorderStyle()
9265
- }
9266
- });
9267
- }
9268
- break;
9269
- case "setLineWidth":
9270
- for (const connector of this.connector) {
9271
- reverse.push({
9272
- item: connector,
9273
- operation: {
9274
- ...this.operation,
9275
- lineWidth: connector.getLineWidth()
9276
- }
9277
- });
9278
- }
9279
- break;
9280
- case "setLineColor":
9281
- for (const connector of this.connector) {
9282
- reverse.push({
9283
- item: connector,
9284
- operation: {
9285
- ...this.operation,
9286
- lineColor: connector.getLineColor()
9287
- }
9288
- });
9289
- }
9290
- break;
9291
- case "switchPointers":
9292
- for (const connector of this.connector) {
9293
- reverse.push({
9294
- item: connector,
9295
- operation: this.operation
9296
- });
9297
- }
9298
- break;
9299
- }
9300
- return reverse;
9301
- }
9302
- }
9303
-
9304
- // src/SessionStorage.ts
9305
- var _sessionStorage;
9306
- if (typeof window !== "undefined" && window.sessionStorage) {
9307
- _sessionStorage = window.sessionStorage;
9308
- } else {
9309
-
9310
- class NodeStoragePolyfill {
9311
- _store = {};
9312
- clear() {
9313
- this._store = {};
9314
- }
9315
- getItem(key) {
9316
- return Object.prototype.hasOwnProperty.call(this._store, key) ? this._store[key] : null;
9317
- }
9318
- key(index) {
9319
- const keys = Object.keys(this._store);
9320
- return keys[index] ?? null;
9321
- }
9322
- removeItem(key) {
9323
- delete this._store[key];
9324
- }
9325
- setItem(key, value) {
9326
- this._store[key] = value;
9327
- }
9328
- get length() {
9329
- return Object.keys(this._store).length;
9330
- }
9331
- }
9332
- _sessionStorage = new NodeStoragePolyfill;
9333
- }
9334
-
9335
- class SessionStorage {
9336
- set(key, value) {
9337
- const boardId = this.getBoardId() || "";
9338
- _sessionStorage.setItem(boardId + "_" + key, JSON.stringify(value));
9339
- }
9340
- get(key) {
9341
- const boardId = this.getBoardId() || "";
9342
- const item = _sessionStorage.getItem(boardId + "_" + key);
9343
- if (!item || item === "undefined") {
9344
- return;
9345
- }
9346
- return JSON.parse(item);
9347
- }
9348
- remove(key) {
9349
- const boardId = this.getBoardId() || "";
9350
- _sessionStorage.removeItem(boardId + "_" + key);
9351
- }
9352
- setConnectorStrokeStyle(color) {
9353
- this.set(`connectorStrokeStyle`, color);
9354
- }
9355
- getConnectorStrokeStyle() {
9356
- return this.get("connectorStrokeStyle");
9357
- }
9358
- setConnectorLineWidth(width) {
9359
- this.set(`connectorLineWidth`, width);
9360
- }
9361
- getConnectorLineWidth() {
9362
- return this.get("connectorLineWidth");
9363
- }
9364
- setConnectorFillColor(color) {
9365
- this.set(`connectorFillColor`, color);
9366
- }
9367
- getConnectorFillColor() {
9368
- return this.get("connectorFillColor");
9369
- }
9370
- setConnectorPointer(type, edge) {
9371
- this.set(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`, type);
9372
- }
9373
- getConnectorPointer(edge) {
9374
- return this.get(`connector${edge.charAt(0).toUpperCase() + edge.slice(1)}Pointer`);
9375
- }
9376
- setConnectorLineStyle(type) {
9377
- this.set("connectorLineStyle", type);
9378
- }
9379
- getConnectorLineStyle() {
9380
- return this.get("connectorLineStyle");
9381
- }
9382
- setShapeData(data) {
9383
- this.set("lastShapeData", data);
9384
- }
9385
- getShapeData() {
9386
- return this.get("lastShapeData");
9387
- }
9388
- setStickerData(data) {
9389
- this.set("lastSticker", data);
9390
- }
9391
- getStickerData() {
9392
- return this.get("lastSticker");
9393
- }
9394
- setShapeWidth(width) {
9395
- this.set("shapeWidth", width);
9396
- }
9397
- getShapeWidth() {
9398
- return this.get("shapeWidth");
9399
- }
9400
- setShapeHeight(height) {
9401
- this.set("shapeHeight", height);
9402
- }
9403
- getShapeHeight() {
9404
- return this.get("shapeHeight");
9405
- }
9406
- setImageDimensions(dimension) {
9407
- this.set("imageDimensions", dimension);
9408
- }
9409
- getImageDimensions() {
9410
- return this.get("imageDimensions");
9411
- }
9412
- setFontSize(itemType, size) {
9413
- this.set(`fontSize_${itemType}`, size);
9414
- }
9415
- getFontSize(itemType) {
9416
- return this.get(`fontSize_${itemType}`);
9417
- }
9418
- setFontStyles(itemType, styles) {
9419
- this.set(`fontStyles_${itemType}`, styles);
9420
- }
9421
- getFontStyles(itemType) {
9422
- return this.get(`fontStyles_${itemType}`);
9423
- }
9424
- setFontColor(itemType, color) {
9425
- this.set(`fontColor_${itemType}`, color);
9426
- }
9427
- getFontColor(itemType) {
9428
- return this.get(`fontColor_${itemType}`);
9429
- }
9430
- setFontHighlight(itemType, highlightColor) {
9431
- this.set(`fontHighlightColor_${itemType}`, highlightColor);
9432
- }
9433
- getFontHighlight(itemType) {
9434
- return this.get(`fontHighlightColor_${itemType}`);
9435
- }
9436
- setHorizontalAlignment(itemType, horizontalAlignment) {
9437
- this.set(`fontHorizontalAlignment_${itemType}`, horizontalAlignment);
9438
- }
9439
- getHorizontalAlignment(itemType) {
9440
- return this.get(`fontHorizontalAlignment_${itemType}`);
9441
- }
9442
- setVerticalAlignment(itemType, verticalAlignment) {
9443
- this.set(`fontVerticalAlignment_${itemType}`, verticalAlignment);
9444
- }
9445
- getVerticalAlignment(itemType) {
9446
- return this.get(`fontVerticalAlignment_${itemType}`);
9447
- }
9448
- setLastAIRequest(request) {
9449
- _sessionStorage.setItem("lastAIRequest", request);
9450
- }
9451
- getLastAIRequest() {
9452
- return _sessionStorage.getItem("lastAIRequest");
9453
- }
9454
- removeLastAIRequest() {
9455
- _sessionStorage.removeItem("lastAIRequest");
9456
- }
9457
- clear() {
9458
- _sessionStorage.clear();
9459
- }
9460
- getBoardId() {
9461
- if (typeof window === "undefined") {
9462
- return;
9463
- }
9464
- return window.location.href.split("/").pop()?.split("?")[0];
9465
- }
9466
- }
9467
- var tempStorage = new SessionStorage;
9468
-
9469
- // src/HTMLRender/HTMLRender.ts
9470
- function getTranslationFromHTML(el) {
9471
- const transform = el.style.transform;
9472
- const translateMatch = transform.match(/translate\(([^)]+)\)/);
9473
- const [translateX, translateY] = translateMatch ? translateMatch[1].split(",").map((value) => parseFloat(value)) : [0, 0];
9474
- return [translateX, translateY];
9475
- }
9476
- function getScaleFromHTML(el) {
9477
- const transform = el.style.transform;
9478
- const scaleMatch = transform.match(/scale\(([^)]+)\)/);
9479
- const [scaleX, scaleY] = scaleMatch ? scaleMatch[1].split(",").map((value) => parseFloat(value)) : [1, 1];
9480
- return [scaleX, scaleY];
9481
- }
9482
- function translateElementBy(el, x, y) {
9483
- const [exX, exY] = getTranslationFromHTML(el);
9484
- const [newX, newY] = [exX + x, exY + y];
9485
- const [scaleX, scaleY] = getScaleFromHTML(el);
9486
- el.style.transform = `translate(${newX}px, ${newY}px) scale(${scaleX}, ${scaleY})`;
9487
- return el;
9488
- }
9489
- function scaleElementBy(el, scaleX, scaleY) {
9490
- const [currentScaleX, currentScaleY] = getScaleFromHTML(el);
9491
- const [newScaleX, newScaleY] = [
9492
- currentScaleX * scaleX,
9493
- currentScaleY * scaleY
9494
- ];
9495
- const [translateX, translateY] = getTranslationFromHTML(el);
9496
- el.style.transform = `translate(${translateX}px, ${translateY}px) scale(${newScaleX}, ${newScaleY})`;
9497
- return el;
9498
- }
9499
- function resetElementScale(el) {
9500
- const [x, y] = getTranslationFromHTML(el);
9501
- el.style.transform = `translate(${x}px, ${y}px) scale(1, 1)`;
9502
- return el;
9503
- }
9504
- function positionRelatively(toPosition, positionBy, padding = 0) {
9505
- const [translateX, translateY] = getTranslationFromHTML(toPosition);
9506
- const [frameX, frameY] = getTranslationFromHTML(positionBy);
9507
- const [dx, dy] = [translateX - frameX, translateY - frameY];
9508
- const verticalAlignment = toPosition.getAttribute("data-vertical-alignment");
9509
- const horizontalAlignment = toPosition.getAttribute("data-vertical-alignment");
9510
- let paddingX = padding;
9511
- let paddingY = padding;
9512
- if (verticalAlignment && verticalAlignment === "bottom") {
9513
- paddingY = -padding;
9514
- }
9515
- if (horizontalAlignment && horizontalAlignment === "right") {
9516
- paddingX = -padding;
9517
- }
9518
- const [scaleX, scaleY] = getScaleFromHTML(toPosition);
9519
- toPosition.style.transform = `translate(${dx + paddingX}px, ${dy + paddingY}px) scale(${scaleX}, ${scaleY})`;
9520
- return toPosition;
9521
- }
9522
- function positionAbsolutely(toPosition, positionBy) {
9523
- const [translateX, translateY] = getTranslationFromHTML(toPosition);
9524
- const [frameX, frameY] = getTranslationFromHTML(positionBy);
9525
- const [dx, dy] = [translateX + frameX, translateY + frameY];
9526
- const [scaleX, scaleY] = getScaleFromHTML(toPosition);
9527
- toPosition.style.transform = `translate(${dx}px, ${dy}px) scale(${scaleX}, ${scaleY})`;
9528
- return toPosition;
9529
- }
9530
8511
  // src/Items/Frame/Basic/Custom/index.ts
9531
8512
  var Custom = {
9532
8513
  name: "Custom",
9533
8514
  textBounds: new Mbr(0, -10, 100, -1),
9534
- path: new Path([
9535
- new Line(new Point(0, 0), new Point(100, 0)),
9536
- new Line(new Point(100, 0), new Point(100, 100)),
9537
- new Line(new Point(100, 100), new Point(0, 100)),
9538
- new Line(new Point(0, 100), new Point(0, 0))
9539
- ], true),
8515
+ get path() {
8516
+ return new Path([
8517
+ new Line(new Point(0, 0), new Point(100, 0)),
8518
+ new Line(new Point(100, 0), new Point(100, 100)),
8519
+ new Line(new Point(100, 100), new Point(0, 100)),
8520
+ new Line(new Point(0, 100), new Point(0, 0))
8521
+ ], true);
8522
+ },
9540
8523
  anchorPoints: [new Point(0, 50), new Point(100, 50), new Point(50, 0), new Point(50, 100)]
9541
8524
  };
9542
8525
 
@@ -9544,12 +8527,14 @@ var Custom = {
9544
8527
  var Frame16x9 = {
9545
8528
  name: "16:9",
9546
8529
  textBounds: new Mbr(0, -10, 200, -1),
9547
- path: new Path([
9548
- new Line(new Point(0, 0), new Point(200, 0)),
9549
- new Line(new Point(200, 0), new Point(200, 200 * (739 / 1314))),
9550
- new Line(new Point(200, 200 * (739 / 1314)), new Point(0, 200 * (739 / 1314))),
9551
- new Line(new Point(0, 200 * (739 / 1314)), new Point(0, 0))
9552
- ], true),
8530
+ get path() {
8531
+ return new Path([
8532
+ new Line(new Point(0, 0), new Point(200, 0)),
8533
+ new Line(new Point(200, 0), new Point(200, 200 * (739 / 1314))),
8534
+ new Line(new Point(200, 200 * (739 / 1314)), new Point(0, 200 * (739 / 1314))),
8535
+ new Line(new Point(0, 200 * (739 / 1314)), new Point(0, 0))
8536
+ ], true);
8537
+ },
9553
8538
  anchorPoints: [
9554
8539
  new Point(0, 100 * (739 / 1314)),
9555
8540
  new Point(200, 100 * (739 / 1314)),
@@ -9562,12 +8547,14 @@ var Frame16x9 = {
9562
8547
  var Frame4x3 = {
9563
8548
  name: "4:3",
9564
8549
  textBounds: new Mbr(0, -10, 200, -1),
9565
- path: new Path([
9566
- new Line(new Point(0, 0), new Point(200, 0)),
9567
- new Line(new Point(200, 0), new Point(200, 200 * (853 / 1138))),
9568
- new Line(new Point(200, 200 * (853 / 1138)), new Point(0, 200 * (853 / 1138))),
9569
- new Line(new Point(0, 200 * (853 / 1138)), new Point(0, 0))
9570
- ], true),
8550
+ get path() {
8551
+ return new Path([
8552
+ new Line(new Point(0, 0), new Point(200, 0)),
8553
+ new Line(new Point(200, 0), new Point(200, 200 * (853 / 1138))),
8554
+ new Line(new Point(200, 200 * (853 / 1138)), new Point(0, 200 * (853 / 1138))),
8555
+ new Line(new Point(0, 200 * (853 / 1138)), new Point(0, 0))
8556
+ ], true);
8557
+ },
9571
8558
  anchorPoints: [
9572
8559
  new Point(0, 100 * (853 / 1138)),
9573
8560
  new Point(200, 100 * (853 / 1138)),
@@ -9580,12 +8567,14 @@ var Frame4x3 = {
9580
8567
  var A4 = {
9581
8568
  name: "A4",
9582
8569
  textBounds: new Mbr(0, -15, 100, -1),
9583
- path: new Path([
9584
- new Line(new Point(0, 0), new Point(100, 0)),
9585
- new Line(new Point(100, 0), new Point(100, 100 * (1172 / 828))),
9586
- new Line(new Point(100, 100 * (1172 / 828)), new Point(0, 100 * (1172 / 828))),
9587
- new Line(new Point(0, 100 * (1172 / 828)), new Point(0, 0))
9588
- ], true),
8570
+ get path() {
8571
+ return new Path([
8572
+ new Line(new Point(0, 0), new Point(100, 0)),
8573
+ new Line(new Point(100, 0), new Point(100, 100 * (1172 / 828))),
8574
+ new Line(new Point(100, 100 * (1172 / 828)), new Point(0, 100 * (1172 / 828))),
8575
+ new Line(new Point(0, 100 * (1172 / 828)), new Point(0, 0))
8576
+ ], true);
8577
+ },
9589
8578
  anchorPoints: [
9590
8579
  new Point(0, 50 * (1172 / 828)),
9591
8580
  new Point(100, 50 * (1172 / 828)),
@@ -9598,12 +8587,14 @@ var A4 = {
9598
8587
  var Letter = {
9599
8588
  name: "Letter",
9600
8589
  textBounds: new Mbr(0, -10, 100, -1),
9601
- path: new Path([
9602
- new Line(new Point(0, 0), new Point(100, 0)),
9603
- new Line(new Point(100, 0), new Point(100, 100 * (1120 / 867))),
9604
- new Line(new Point(100, 100 * (1120 / 867)), new Point(0, 100 * (1120 / 867))),
9605
- new Line(new Point(0, 100 * (1120 / 867)), new Point(0, 0))
9606
- ], true),
8590
+ get path() {
8591
+ return new Path([
8592
+ new Line(new Point(0, 0), new Point(100, 0)),
8593
+ new Line(new Point(100, 0), new Point(100, 100 * (1120 / 867))),
8594
+ new Line(new Point(100, 100 * (1120 / 867)), new Point(0, 100 * (1120 / 867))),
8595
+ new Line(new Point(0, 100 * (1120 / 867)), new Point(0, 0))
8596
+ ], true);
8597
+ },
9607
8598
  anchorPoints: [
9608
8599
  new Point(0, 50 * (1120 / 867)),
9609
8600
  new Point(100, 50 * (1120 / 867)),
@@ -9616,12 +8607,14 @@ var Letter = {
9616
8607
  var Frame1x1 = {
9617
8608
  name: "1:1",
9618
8609
  textBounds: new Mbr(0, -10, 100, -1),
9619
- path: new Path([
9620
- new Line(new Point(0, 0), new Point(100, 0)),
9621
- new Line(new Point(100, 0), new Point(100, 100)),
9622
- new Line(new Point(100, 100), new Point(0, 100)),
9623
- new Line(new Point(0, 100), new Point(0, 0))
9624
- ], true),
8610
+ get path() {
8611
+ return new Path([
8612
+ new Line(new Point(0, 0), new Point(100, 0)),
8613
+ new Line(new Point(100, 0), new Point(100, 100)),
8614
+ new Line(new Point(100, 100), new Point(0, 100)),
8615
+ new Line(new Point(0, 100), new Point(0, 0))
8616
+ ], true);
8617
+ },
9625
8618
  anchorPoints: [new Point(0, 50), new Point(100, 50), new Point(50, 0), new Point(50, 100)]
9626
8619
  };
9627
8620
 
@@ -9629,12 +8622,14 @@ var Frame1x1 = {
9629
8622
  var Frame3x2 = {
9630
8623
  name: "3:2",
9631
8624
  textBounds: new Mbr(0, -10, 200, -1),
9632
- path: new Path([
9633
- new Line(new Point(0, 0), new Point(200, 0)),
9634
- new Line(new Point(200, 0), new Point(200, 200 * (200 / 300))),
9635
- new Line(new Point(200, 200 * (200 / 300)), new Point(0, 200 * (200 / 300))),
9636
- new Line(new Point(0, 200 * (200 / 300)), new Point(0, 0))
9637
- ], true),
8625
+ get path() {
8626
+ return new Path([
8627
+ new Line(new Point(0, 0), new Point(200, 0)),
8628
+ new Line(new Point(200, 0), new Point(200, 200 * (200 / 300))),
8629
+ new Line(new Point(200, 200 * (200 / 300)), new Point(0, 200 * (200 / 300))),
8630
+ new Line(new Point(0, 200 * (200 / 300)), new Point(0, 0))
8631
+ ], true);
8632
+ },
9638
8633
  anchorPoints: [
9639
8634
  new Point(0, 100 * (200 / 300)),
9640
8635
  new Point(200, 100 * (200 / 300)),
@@ -9647,12 +8642,14 @@ var Frame3x2 = {
9647
8642
  var Frame9x18 = {
9648
8643
  name: "9:18",
9649
8644
  textBounds: new Mbr(0, -10, 200, -1),
9650
- path: new Path([
9651
- new Line(new Point(0, 0), new Point(200, 0)),
9652
- new Line(new Point(200, 0), new Point(200, 200 * (1230 / 612))),
9653
- new Line(new Point(200, 200 * (1230 / 612)), new Point(0, 200 * (1230 / 612))),
9654
- new Line(new Point(0, 200 * (1230 / 612)), new Point(0, 0))
9655
- ], true),
8645
+ get path() {
8646
+ return new Path([
8647
+ new Line(new Point(0, 0), new Point(200, 0)),
8648
+ new Line(new Point(200, 0), new Point(200, 200 * (1230 / 612))),
8649
+ new Line(new Point(200, 200 * (1230 / 612)), new Point(0, 200 * (1230 / 612))),
8650
+ new Line(new Point(0, 200 * (1230 / 612)), new Point(0, 0))
8651
+ ], true);
8652
+ },
9656
8653
  anchorPoints: [
9657
8654
  new Point(0, 100 * (1230 / 612)),
9658
8655
  new Point(200, 100 * (1230 / 612)),
@@ -10126,9 +9123,40 @@ import {
10126
9123
  Editor as Editor30,
10127
9124
  Element as Element6,
10128
9125
  Text,
10129
- Transforms as Transforms19
9126
+ Transforms as Transforms20
10130
9127
  } from "slate";
10131
9128
 
9129
+ // src/SubjectOperation.ts
9130
+ class SubjectOperation {
9131
+ observers = [];
9132
+ subscribe(observer) {
9133
+ const index = this.observers.indexOf(observer);
9134
+ if (index === -1) {
9135
+ this.observers.push(observer);
9136
+ }
9137
+ }
9138
+ unsubscribe(observer) {
9139
+ const index = this.observers.indexOf(observer);
9140
+ if (index !== -1) {
9141
+ this.observers.splice(index, 1);
9142
+ }
9143
+ }
9144
+ publish(subject, op) {
9145
+ for (const observer of this.observers) {
9146
+ observer(subject, op);
9147
+ }
9148
+ }
9149
+ }
9150
+
9151
+ // src/Items/ItemsCommandUtils.ts
9152
+ function mapItemsByOperation(item, getCallback) {
9153
+ const items = Array.isArray(item) ? item : [item];
9154
+ return items.map((item2) => {
9155
+ const operation = getCallback(item2);
9156
+ return { item: item2, operation };
9157
+ });
9158
+ }
9159
+
10132
9160
  // src/Items/LinkTo/LinkToCommand.ts
10133
9161
  class LinkToCommand {
10134
9162
  linkTo;
@@ -11014,7 +10042,7 @@ function fillText(ctx, textBlock) {
11014
10042
  import {
11015
10043
  createEditor,
11016
10044
  Editor as Editor26,
11017
- Transforms as Transforms17
10045
+ Transforms as Transforms18
11018
10046
  } from "slate";
11019
10047
 
11020
10048
  // node_modules/slate-history/dist/index.js
@@ -11088,7 +10116,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
11088
10116
  if (it)
11089
10117
  o = it;
11090
10118
  var i = 0;
11091
- var F = function F2() {};
10119
+ var F = function F() {};
11092
10120
  return { s: F, n: function n() {
11093
10121
  if (i >= o.length)
11094
10122
  return { done: true };
@@ -11870,7 +10898,10 @@ var setLink = (editor, link, selection) => {
11870
10898
  return;
11871
10899
  }
11872
10900
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
11873
- Editor11.addMark(editor, "fontColor", format);
10901
+ Transforms10.setNodes(editor, { fontColor: format }, {
10902
+ match: (n) => !Editor11.isEditor(n) && n.type === "text",
10903
+ split: true
10904
+ });
11874
10905
  for (const [node, path2] of Editor11.nodes(editor, {
11875
10906
  match: (n) => !Editor11.isEditor(n) && n.type === "text"
11876
10907
  })) {
@@ -19796,6 +18827,7 @@ class MarkdownProcessor {
19796
18827
  isProcessingChunk = false;
19797
18828
  stopProcessingMarkDownCb = null;
19798
18829
  currentNode = "";
18830
+ doneResolvers = [];
19799
18831
  editor;
19800
18832
  subject = new Subject;
19801
18833
  constructor(editor) {
@@ -19807,6 +18839,19 @@ class MarkdownProcessor {
19807
18839
  getStopProcessingMarkDownCb() {
19808
18840
  return this.stopProcessingMarkDownCb;
19809
18841
  }
18842
+ waitForDone() {
18843
+ if (!this.isProcessingChunk && this.chunksQueue.length === 0) {
18844
+ return Promise.resolve();
18845
+ }
18846
+ return new Promise((resolve) => {
18847
+ this.doneResolvers.push(resolve);
18848
+ });
18849
+ }
18850
+ notifyDone() {
18851
+ const resolvers = this.doneResolvers;
18852
+ this.doneResolvers = [];
18853
+ resolvers.forEach((r) => r());
18854
+ }
19810
18855
  deserializeMarkdown(isNewParagraphNeeded) {
19811
18856
  const lastNode = this.getText()[this.getText().length - 1];
19812
18857
  if (lastNode.type !== "paragraph") {
@@ -19863,6 +18908,7 @@ class MarkdownProcessor {
19863
18908
  async processNextChunk() {
19864
18909
  if (this.chunksQueue.length === 0) {
19865
18910
  this.isProcessingChunk = false;
18911
+ this.notifyDone();
19866
18912
  return;
19867
18913
  }
19868
18914
  this.isProcessingChunk = true;
@@ -19870,6 +18916,7 @@ class MarkdownProcessor {
19870
18916
  if (chunk === "StopProcessingMarkdown") {
19871
18917
  await this.deserializeMarkdownAsync(false);
19872
18918
  this.isProcessingChunk = false;
18919
+ this.notifyDone();
19873
18920
  this.currentNode = "";
19874
18921
  if (this.stopProcessingMarkDownCb) {
19875
18922
  selectWholeText(this.editor);
@@ -20138,7 +19185,7 @@ function setSelectionFontSize(editor, isAutosize, fontSize, selectionContext) {
20138
19185
  }
20139
19186
 
20140
19187
  // src/Items/RichText/editorHelpers/selectionOps/setSelectionFontStyle.ts
20141
- import { Editor as Editor24 } from "slate";
19188
+ import { Editor as Editor24, Range as Range8, Transforms as Transforms17 } from "slate";
20142
19189
 
20143
19190
  // src/Items/RichText/editorHelpers/common/getEachNodeInSelectionStyles.ts
20144
19191
  function getEachNodeInSelectionStyles(editor) {
@@ -20168,10 +19215,22 @@ function setSelectionFontStyle(editor, style) {
20168
19215
  const isAllNodesContainStyle = selectionStyles.every((styleArr) => styleArr.includes(style2));
20169
19216
  const isSomeNodeContainStyle = selectionStyles.some((styleArr) => styleArr.includes(style2));
20170
19217
  const isAllNodesNotContainStyle = selectionStyles.every((styleArr) => !styleArr.includes(style2));
19218
+ let value;
20171
19219
  if (isAllNodesContainStyle) {
20172
- Editor24.addMark(editor, style2, false);
19220
+ value = false;
20173
19221
  } else if (isSomeNodeContainStyle || isAllNodesNotContainStyle) {
20174
- Editor24.addMark(editor, style2, true);
19222
+ value = true;
19223
+ } else {
19224
+ continue;
19225
+ }
19226
+ const { selection } = editor;
19227
+ if (selection && Range8.isExpanded(selection)) {
19228
+ Transforms17.setNodes(editor, { [style2]: value }, {
19229
+ match: (n) => !Editor24.isEditor(n) && n.type === "text",
19230
+ split: true
19231
+ });
19232
+ } else {
19233
+ Editor24.addMark(editor, style2, value);
20175
19234
  }
20176
19235
  }
20177
19236
  }
@@ -20429,373 +19488,960 @@ class EditorContainer {
20429
19488
  }
20430
19489
  console.error("Error applying this type operation: ", operations2);
20431
19490
  }
20432
- }
20433
- applySelectionEdit(op) {
20434
- this.shouldEmit = false;
20435
- for (const operation of op.ops) {
20436
- this.decorated.apply(operation);
19491
+ }
19492
+ applySelectionEdit(op) {
19493
+ this.shouldEmit = false;
19494
+ for (const operation of op.ops) {
19495
+ this.decorated.apply(operation);
19496
+ }
19497
+ this.shouldEmit = true;
19498
+ }
19499
+ applySelectionOp(op) {
19500
+ this.shouldEmit = false;
19501
+ Editor26.withoutNormalizing(this.editor, () => {
19502
+ for (const operation of op.ops) {
19503
+ this.decorated.apply(operation);
19504
+ }
19505
+ });
19506
+ this.shouldEmit = true;
19507
+ }
19508
+ applyWholeTextOp(op) {
19509
+ const selection = this.editor.selection;
19510
+ selectWholeText(this.editor);
19511
+ switch (op.method) {
19512
+ case "setFontStyle":
19513
+ this.setSelectionFontStyle(op.fontStyleList);
19514
+ break;
19515
+ case "setFontColor":
19516
+ this.setSelectionFontColor(op.fontColor);
19517
+ break;
19518
+ case "setFontFamily":
19519
+ break;
19520
+ case "setFontSize":
19521
+ this.textScale = Number(op.fontSize) / this.getScale() / this.initialTextStyles.fontSize;
19522
+ break;
19523
+ case "setFontHighlight":
19524
+ this.setSelectionFontHighlight(op.fontHighlight);
19525
+ break;
19526
+ case "setHorisontalAlignment":
19527
+ this.setSelectionHorisontalAlignment(op.horisontalAlignment);
19528
+ break;
19529
+ case "setMaxWidth":
19530
+ this.applyMaxWidth(op.maxWidth ?? 0);
19531
+ break;
19532
+ }
19533
+ if (selection) {
19534
+ Transforms18.select(this.editor, selection);
19535
+ }
19536
+ }
19537
+ applyMaxWidth(maxWidth) {
19538
+ this.maxWidth = maxWidth;
19539
+ }
19540
+ setMaxWidth(maxWidth) {
19541
+ this.emit({
19542
+ class: "RichText",
19543
+ method: "setMaxWidth",
19544
+ item: [this.id],
19545
+ maxWidth
19546
+ });
19547
+ }
19548
+ setSelectionFontColor(format, selectionContext) {
19549
+ this.startOpRecording();
19550
+ setSelectionFontColor(this.editor, format, selectionContext);
19551
+ return this.stopOpRecordingAndGetOps();
19552
+ }
19553
+ setSelectionLink(link, selection) {
19554
+ this.startOpRecording();
19555
+ setLink(this.editor, link, selection);
19556
+ return this.stopOpRecordingAndGetOps();
19557
+ }
19558
+ setSelectionFontStyle(style) {
19559
+ this.startOpRecording();
19560
+ setSelectionFontStyle(this.editor, style);
19561
+ return this.stopOpRecordingAndGetOps();
19562
+ }
19563
+ setSelectionFontSize(fontSize, selectionContext) {
19564
+ this.startOpRecording();
19565
+ const shouldUpdateElement = setSelectionFontSize(this.editor, this.getAutosize(), fontSize, selectionContext);
19566
+ if (shouldUpdateElement) {
19567
+ this.updateElement();
19568
+ }
19569
+ return this.stopOpRecordingAndGetOps();
19570
+ }
19571
+ setSelectionFontHighlight(format, selectionContext) {
19572
+ this.startOpRecording();
19573
+ setSelectionFontHighlight(this.editor, format, selectionContext);
19574
+ return this.stopOpRecordingAndGetOps();
19575
+ }
19576
+ setSelectionHorisontalAlignment(horisontalAlignment, selectionContext) {
19577
+ this.startOpRecording();
19578
+ setSelectionHorisontalAlignment(this.editor, horisontalAlignment, selectionContext);
19579
+ return this.stopOpRecordingAndGetOps();
19580
+ }
19581
+ getSelectionMarks() {
19582
+ return getSelectionMarks(this.editor);
19583
+ }
19584
+ handleListMerge() {
19585
+ return handleListMerge(this.editor);
19586
+ }
19587
+ getListTypeAtSelectionStart() {
19588
+ return getListTypeAtSelectionStart(this.editor);
19589
+ }
19590
+ handleSplitListItem() {
19591
+ return handleSplitListItem(this.editor);
19592
+ }
19593
+ includesListNode() {
19594
+ return this.getText().some((node2) => node2.type === "ol_list" || node2.type === "ul_list");
19595
+ }
19596
+ toggleListType(targetListType, shouldWrap = true) {
19597
+ const result = toggleListType(this.editor, targetListType, shouldWrap);
19598
+ this.subject.publish(this);
19599
+ return result;
19600
+ }
19601
+ withAutoList() {
19602
+ return withAutoList(this.editor);
19603
+ }
19604
+ handleWrapIntoNestedList() {
19605
+ const result = handleWrapIntoNestedList(this.editor);
19606
+ this.subject.publish(this);
19607
+ return result;
19608
+ }
19609
+ getFirstSelectionLink(selection) {
19610
+ return getFirstSelectionLink(this.editor, selection);
19611
+ }
19612
+ getText() {
19613
+ return this.editor.children;
19614
+ }
19615
+ getTextParagraphs(lines) {
19616
+ const newlines = [];
19617
+ lines.forEach((line) => {
19618
+ if (!this.getAutosize()) {
19619
+ newlines.push(this.createParagraphNode(line));
19620
+ return;
19621
+ }
19622
+ const validText = this.getValidText(line, newlines);
19623
+ if (validText.length > 0) {
19624
+ newlines.push(this.createParagraphNode(validText));
19625
+ } else {
19626
+ this.getOnLimitReached()();
19627
+ }
19628
+ });
19629
+ return newlines;
19630
+ }
19631
+ getValidText(line, newlines) {
19632
+ let left = 0;
19633
+ let right = line.length;
19634
+ let validText = "";
19635
+ while (left <= right) {
19636
+ const mid = Math.floor((left + right) / 2);
19637
+ const currentText = line.slice(0, mid);
19638
+ const testLine = this.createParagraphNode(currentText);
19639
+ const nodes = [...newlines, testLine];
19640
+ this.applyAutoSizeScale(this.calcAutoSize(nodes), nodes);
19641
+ const relativeFontSize = this.getFontSize() / this.getMatrixScale();
19642
+ if (relativeFontSize >= 10) {
19643
+ validText = currentText;
19644
+ left = mid + 1;
19645
+ } else {
19646
+ right = mid - 1;
19647
+ }
19648
+ }
19649
+ return validText;
19650
+ }
19651
+ createParagraphNode(text3) {
19652
+ return createParagraphNode(text3, this.editor, this.horisontalAlignment);
19653
+ }
19654
+ insertCopiedText(text3) {
19655
+ const lines = this.getTextParagraphs(text3.split(/\r\n|\r|\n/));
19656
+ if (this.isLimitReached(lines)) {
19657
+ return true;
19658
+ }
19659
+ insertCopiedNodes(this.editor, lines);
19660
+ this.subject.publish(this);
19661
+ return true;
19662
+ }
19663
+ checkIsAutoSizeTextScaleAllowed(nodes) {
19664
+ const existingNodes = this.getBlockNodes();
19665
+ const textScale = this.calcAutoSize([...existingNodes, ...nodes]);
19666
+ const marks = this.getSelectionMarks();
19667
+ const fontSize = marks?.fontSize ?? this.initialTextStyles.fontSize;
19668
+ return Math.ceil(textScale * (fontSize === "auto" ? 14 : fontSize)) / this.getMatrixScale() > 4;
19669
+ }
19670
+ isLimitReached(nodes) {
19671
+ if (this.getAutosize()) {
19672
+ if (!this.checkIsAutoSizeTextScaleAllowed(nodes)) {
19673
+ this.getOnLimitReached()();
19674
+ return true;
19675
+ }
19676
+ }
19677
+ return false;
19678
+ }
19679
+ insertCopiedNodes(nodes) {
19680
+ if (this.isLimitReached(nodes)) {
19681
+ return true;
19682
+ }
19683
+ insertCopiedNodes(this.editor, nodes);
19684
+ this.subject.publish(this);
19685
+ return true;
19686
+ }
19687
+ hasTextInSelection() {
19688
+ return hasTextInSelection(this.editor);
19689
+ }
19690
+ getSelection() {
19691
+ return JSON.parse(JSON.stringify(this.editor.selection));
19692
+ }
19693
+ splitNode() {
19694
+ Transforms18.splitNodes(this.editor, { always: true });
19695
+ }
19696
+ getBlockNodes() {
19697
+ return this.editor.children;
19698
+ }
19699
+ isEmpty() {
19700
+ return isTextEmpty(this.editor.children);
19701
+ }
19702
+ clearText() {
19703
+ clearText(this.editor);
19704
+ }
19705
+ addText(text3) {
19706
+ this.editor.apply({
19707
+ type: "insert_text",
19708
+ text: text3,
19709
+ path: [0, 0],
19710
+ offset: 0
19711
+ });
19712
+ }
19713
+ selectWholeText() {
19714
+ selectWholeText(this.editor);
19715
+ }
19716
+ moveCursorToEndOfTheText(delay = 10) {
19717
+ moveCursorToEndOfTheText(this.editor, delay);
19718
+ }
19719
+ }
19720
+
19721
+ // src/Items/RichText/findOptimalMaxWidthForTextAutoSize.ts
19722
+ function findOptimalMaxWidthForTextAutoSize(text3, containerWidth, containerHeight, initialMaxWidth, tolerance = 0.05) {
19723
+ const targetRatio = containerWidth / containerHeight;
19724
+ let low = 0;
19725
+ let high = initialMaxWidth * 3;
19726
+ let closestRatioDifference = Infinity;
19727
+ let closestWidth = initialMaxWidth;
19728
+ let closestHeight = initialMaxWidth / targetRatio;
19729
+ const iterations = Math.min(Math.max(3, containerWidth / 80), 15);
19730
+ for (let i = 0;i < iterations && low < high; i += 1) {
19731
+ const mid = (low + high) / 2;
19732
+ const { width: calcWidth, height: calcHeight } = getBlockNodes(text3, mid);
19733
+ const currentRatio = calcWidth / calcHeight;
19734
+ const ratioDifference = Math.abs(currentRatio - targetRatio);
19735
+ if (ratioDifference < closestRatioDifference) {
19736
+ closestRatioDifference = ratioDifference;
19737
+ closestWidth = calcWidth;
19738
+ closestHeight = calcHeight;
19739
+ }
19740
+ if (ratioDifference <= tolerance) {
19741
+ break;
19742
+ }
19743
+ if (currentRatio < targetRatio) {
19744
+ low = mid + 1;
19745
+ } else {
19746
+ high = mid - 1;
19747
+ }
19748
+ }
19749
+ const scale = Math.min(containerWidth / closestWidth, containerHeight / closestHeight);
19750
+ return {
19751
+ bestMaxWidth: initialMaxWidth / scale,
19752
+ bestMaxHeight: initialMaxWidth / targetRatio / scale
19753
+ };
19754
+ }
19755
+
19756
+ // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontColor.ts
19757
+ import { Editor as Editor27 } from "slate";
19758
+ function applySelectionFontColor(editor, fontColor) {
19759
+ if (!editor) {
19760
+ throw new Error("Editor is not initialized");
19761
+ }
19762
+ const marks = getSelectionMarks(editor);
19763
+ if (!marks) {
19764
+ return;
19765
+ }
19766
+ Editor27.addMark(editor, "fontColor", fontColor);
19767
+ }
19768
+
19769
+ // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontSize.ts
19770
+ import { Editor as Editor28, Transforms as Transforms19 } from "slate";
19771
+ function applySelectionFontSize(editor, fontSize, selectionContext) {
19772
+ const size = fontSize;
19773
+ if (typeof size !== "number") {
19774
+ return;
19775
+ }
19776
+ if (!editor) {
19777
+ throw new Error("Editor is not initialized");
19778
+ }
19779
+ const selection = editor.selection;
19780
+ const marks = getSelectionMarks(editor);
19781
+ if (!marks) {
19782
+ return;
19783
+ }
19784
+ if (JSON.stringify(selection?.anchor) === JSON.stringify(selection?.focus)) {
19785
+ Transforms19.select(editor, {
19786
+ anchor: Editor28.start(editor, []),
19787
+ focus: Editor28.end(editor, [])
19788
+ });
19789
+ }
19790
+ Editor28.addMark(editor, "fontSize", size);
19791
+ if (selectionContext === "EditTextUnderPointer") {}
19792
+ }
19793
+
19794
+ // src/Items/RichText/editorHelpers/common/getSelectedBlockNode.ts
19795
+ import { Editor as Editor29, Element as Element5 } from "slate";
19796
+ function getSelectedBlockNode(editor) {
19797
+ const { selection } = editor;
19798
+ if (!selection) {
19799
+ return null;
19800
+ }
19801
+ const [node2] = Editor29.node(editor, selection);
19802
+ if (Editor29.isEditor(node2) || !Element5.isElement(node2)) {
19803
+ return null;
19804
+ }
19805
+ return node2;
19806
+ }
19807
+
19808
+ // src/Items/RichText/utils.ts
19809
+ function findCommonStrings(arrays) {
19810
+ if (arrays.length === 0) {
19811
+ return [];
19812
+ }
19813
+ let commonStrings = arrays[0];
19814
+ for (let i = 1;i < arrays.length; i++) {
19815
+ commonStrings = commonStrings.filter((str) => arrays[i].includes(str));
19816
+ }
19817
+ return commonStrings;
19818
+ }
19819
+
19820
+ // src/Items/RichText/editorHelpers/common/getSelectionStyles.ts
19821
+ function getSelectionStyles(editor) {
19822
+ const { selection } = editor;
19823
+ if (!selection) {
19824
+ return;
19825
+ }
19826
+ const nodes = getAllTextNodesInSelection(editor);
19827
+ const styles = nodes.reduce((acc, node2) => {
19828
+ const styles2 = [];
19829
+ if (node2.text === "") {
19830
+ return acc;
19831
+ }
19832
+ if (node2.bold) {
19833
+ styles2.push("bold");
19834
+ }
19835
+ if (node2.italic) {
19836
+ styles2.push("italic");
20437
19837
  }
20438
- this.shouldEmit = true;
20439
- }
20440
- applySelectionOp(op) {
20441
- this.shouldEmit = false;
20442
- Editor26.withoutNormalizing(this.editor, () => {
20443
- for (const operation of op.ops) {
20444
- this.decorated.apply(operation);
20445
- }
20446
- });
20447
- this.shouldEmit = true;
20448
- }
20449
- applyWholeTextOp(op) {
20450
- const selection = this.editor.selection;
20451
- selectWholeText(this.editor);
20452
- switch (op.method) {
20453
- case "setFontStyle":
20454
- this.setSelectionFontStyle(op.fontStyleList);
20455
- break;
20456
- case "setFontColor":
20457
- this.setSelectionFontColor(op.fontColor);
20458
- break;
20459
- case "setFontFamily":
20460
- break;
20461
- case "setFontSize":
20462
- this.textScale = Number(op.fontSize) / this.getScale() / this.initialTextStyles.fontSize;
20463
- break;
20464
- case "setFontHighlight":
20465
- this.setSelectionFontHighlight(op.fontHighlight);
20466
- break;
20467
- case "setHorisontalAlignment":
20468
- this.setSelectionHorisontalAlignment(op.horisontalAlignment);
20469
- break;
20470
- case "setMaxWidth":
20471
- this.applyMaxWidth(op.maxWidth ?? 0);
20472
- break;
19838
+ if (node2.underline) {
19839
+ styles2.push("underline");
20473
19840
  }
20474
- if (selection) {
20475
- Transforms17.select(this.editor, selection);
19841
+ if (node2["line-through"]) {
19842
+ styles2.push("line-through");
20476
19843
  }
19844
+ acc.push(styles2);
19845
+ return acc;
19846
+ }, []);
19847
+ return findCommonStrings(styles);
19848
+ }
19849
+
19850
+ // src/Items/RichText/editorHelpers/common/setEditorFocus.ts
19851
+ import { ReactEditor as ReactEditor6 } from "slate-react";
19852
+ function setEditorFocus(editor, selectionContext) {
19853
+ if (!editor) {
19854
+ throw new Error("Editor is not initialized");
20477
19855
  }
20478
- applyMaxWidth(maxWidth) {
20479
- this.maxWidth = maxWidth;
20480
- }
20481
- setMaxWidth(maxWidth) {
20482
- this.emit({
20483
- class: "RichText",
20484
- method: "setMaxWidth",
20485
- item: [this.id],
20486
- maxWidth
20487
- });
20488
- }
20489
- setSelectionFontColor(format, selectionContext) {
20490
- this.startOpRecording();
20491
- setSelectionFontColor(this.editor, format, selectionContext);
20492
- return this.stopOpRecordingAndGetOps();
19856
+ if (selectionContext === "EditTextUnderPointer") {
19857
+ ReactEditor6.focus(editor);
20493
19858
  }
20494
- setSelectionLink(link, selection) {
20495
- this.startOpRecording();
20496
- setLink(this.editor, link, selection);
20497
- return this.stopOpRecordingAndGetOps();
19859
+ }
19860
+
19861
+ // src/Items/Transformation/TransformationCommand.ts
19862
+ class TransformationCommand {
19863
+ transformation;
19864
+ operation;
19865
+ reverse;
19866
+ constructor(transformation, operation) {
19867
+ this.transformation = transformation;
19868
+ this.operation = operation;
19869
+ this.reverse = this.getReverse();
20498
19870
  }
20499
- setSelectionFontStyle(style) {
20500
- this.startOpRecording();
20501
- setSelectionFontStyle(this.editor, style);
20502
- return this.stopOpRecordingAndGetOps();
19871
+ merge(op) {
19872
+ this.operation = op;
19873
+ this.reverse = this.getReverse();
19874
+ return this;
20503
19875
  }
20504
- setSelectionFontSize(fontSize, selectionContext) {
20505
- this.startOpRecording();
20506
- const shouldUpdateElement = setSelectionFontSize(this.editor, this.getAutosize(), fontSize, selectionContext);
20507
- if (shouldUpdateElement) {
20508
- this.updateElement();
19876
+ apply() {
19877
+ for (const transformation of this.transformation) {
19878
+ transformation.apply(this.operation);
20509
19879
  }
20510
- return this.stopOpRecordingAndGetOps();
20511
19880
  }
20512
- setSelectionFontHighlight(format, selectionContext) {
20513
- this.startOpRecording();
20514
- setSelectionFontHighlight(this.editor, format, selectionContext);
20515
- return this.stopOpRecordingAndGetOps();
19881
+ revert() {
19882
+ this.reverse.forEach(({ item, operation }) => {
19883
+ item.apply(operation);
19884
+ });
20516
19885
  }
20517
- setSelectionHorisontalAlignment(horisontalAlignment, selectionContext) {
20518
- this.startOpRecording();
20519
- setSelectionHorisontalAlignment(this.editor, horisontalAlignment, selectionContext);
20520
- return this.stopOpRecordingAndGetOps();
19886
+ getReverse() {
19887
+ const op = this.operation;
19888
+ switch (this.operation.method) {
19889
+ case "applyMatrix": {
19890
+ const op2 = this.operation;
19891
+ return this.transformation.map((t3) => {
19892
+ const itemOp = op2.items.find((i) => i.id === t3.getId());
19893
+ if (!itemOp)
19894
+ return { item: t3, operation: op2 };
19895
+ return {
19896
+ item: t3,
19897
+ operation: {
19898
+ class: "Transformation",
19899
+ method: "applyMatrix",
19900
+ items: [{
19901
+ id: t3.getId(),
19902
+ matrix: {
19903
+ translateX: -itemOp.matrix.translateX,
19904
+ translateY: -itemOp.matrix.translateY,
19905
+ scaleX: 1 / itemOp.matrix.scaleX,
19906
+ scaleY: 1 / itemOp.matrix.scaleY,
19907
+ shearX: 0,
19908
+ shearY: 0
19909
+ }
19910
+ }]
19911
+ }
19912
+ };
19913
+ });
19914
+ }
19915
+ case "translateTo":
19916
+ return mapItemsByOperation(this.transformation, (transformation) => {
19917
+ return {
19918
+ ...this.operation,
19919
+ x: transformation.getTranslation().x,
19920
+ y: transformation.getTranslation().y
19921
+ };
19922
+ });
19923
+ case "translateBy": {
19924
+ const op2 = this.operation;
19925
+ return mapItemsByOperation(this.transformation, () => {
19926
+ return {
19927
+ ...this.operation,
19928
+ x: -op2.x,
19929
+ y: -op2.y
19930
+ };
19931
+ });
19932
+ }
19933
+ case "scaleTo":
19934
+ case "scaleToRelativeTo": {
19935
+ return mapItemsByOperation(this.transformation, (transformation) => {
19936
+ return {
19937
+ ...op,
19938
+ x: transformation.getScale().x,
19939
+ y: transformation.getScale().y
19940
+ };
19941
+ });
19942
+ }
19943
+ case "scaleBy":
19944
+ case "scaleByRelativeTo": {
19945
+ const op2 = this.operation;
19946
+ return mapItemsByOperation(this.transformation, () => {
19947
+ return {
19948
+ ...op2,
19949
+ x: 1 / op2.x,
19950
+ y: 1 / op2.y
19951
+ };
19952
+ });
19953
+ }
19954
+ case "scaleByTranslateBy": {
19955
+ const op2 = this.operation;
19956
+ const scaleTransformation = mapItemsByOperation(this.transformation, () => {
19957
+ const scaleX = 1 / op2.scale.x;
19958
+ const scaleY = 1 / op2.scale.y;
19959
+ const translateX = -op2.translate.x;
19960
+ const translateY = -op2.translate.y;
19961
+ return {
19962
+ ...op2,
19963
+ scale: {
19964
+ x: scaleX,
19965
+ y: scaleY
19966
+ },
19967
+ translate: {
19968
+ x: translateX,
19969
+ y: translateY
19970
+ }
19971
+ };
19972
+ });
19973
+ return scaleTransformation;
19974
+ }
19975
+ case "rotateTo":
19976
+ return mapItemsByOperation(this.transformation, (transformation) => {
19977
+ return {
19978
+ ...this.operation,
19979
+ degree: transformation.getRotation()
19980
+ };
19981
+ });
19982
+ case "rotateBy": {
19983
+ const op2 = this.operation;
19984
+ return mapItemsByOperation(this.transformation, () => {
19985
+ return {
19986
+ ...this.operation,
19987
+ degree: -op2.degree
19988
+ };
19989
+ });
19990
+ }
19991
+ case "transformMany": {
19992
+ const { operation, transformation } = this;
19993
+ return transformation.map((currTrans) => {
19994
+ const op2 = operation.items[currTrans.getId()];
19995
+ 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 };
19996
+ return {
19997
+ item: currTrans,
19998
+ operation: {
19999
+ class: "Transformation",
20000
+ method: "applyMatrix",
20001
+ items: [{
20002
+ id: currTrans.getId(),
20003
+ matrix: {
20004
+ translateX: op2.method === "applyMatrix" ? -m.translateX : m.translateX,
20005
+ translateY: op2.method === "applyMatrix" ? -m.translateY : m.translateY,
20006
+ scaleX: op2.method === "applyMatrix" ? 1 / m.scaleX : m.scaleX,
20007
+ scaleY: op2.method === "applyMatrix" ? 1 / m.scaleY : m.scaleY,
20008
+ shearX: 0,
20009
+ shearY: 0
20010
+ }
20011
+ }]
20012
+ }
20013
+ };
20014
+ });
20015
+ }
20016
+ case "locked": {
20017
+ const op2 = this.operation;
20018
+ return mapItemsByOperation(this.transformation, () => {
20019
+ return {
20020
+ ...op2,
20021
+ item: [...op2.item],
20022
+ method: "unlocked",
20023
+ locked: false
20024
+ };
20025
+ });
20026
+ }
20027
+ case "unlocked": {
20028
+ const op2 = this.operation;
20029
+ return mapItemsByOperation(this.transformation, () => {
20030
+ return {
20031
+ ...op2,
20032
+ item: [...op2.item],
20033
+ method: "locked",
20034
+ locked: true
20035
+ };
20036
+ });
20037
+ }
20038
+ default:
20039
+ return [
20040
+ { item: this.transformation[0], operation: this.operation }
20041
+ ];
20042
+ }
20521
20043
  }
20522
- getSelectionMarks() {
20523
- return getSelectionMarks(this.editor);
20044
+ }
20045
+
20046
+ // src/Items/Transformation/TransformationData.ts
20047
+ class DefaultTransformationData {
20048
+ translateX;
20049
+ translateY;
20050
+ scaleX;
20051
+ scaleY;
20052
+ rotate;
20053
+ isLocked;
20054
+ constructor(translateX = 0, translateY = 0, scaleX = 1, scaleY = 1, rotate = 0, isLocked = false) {
20055
+ this.translateX = translateX;
20056
+ this.translateY = translateY;
20057
+ this.scaleX = scaleX;
20058
+ this.scaleY = scaleY;
20059
+ this.rotate = rotate;
20060
+ this.isLocked = isLocked;
20524
20061
  }
20525
- handleListMerge() {
20526
- return handleListMerge(this.editor);
20062
+ }
20063
+
20064
+ // src/Items/Transformation/Transformation.ts
20065
+ var defaultData = new DefaultTransformationData;
20066
+
20067
+ class Transformation {
20068
+ id;
20069
+ events;
20070
+ subject = new SubjectOperation;
20071
+ _matrix = new Matrix2;
20072
+ previous = new Matrix2;
20073
+ rotate = defaultData.rotate;
20074
+ isLocked = false;
20075
+ constructor(id = "", events) {
20076
+ this.id = id;
20077
+ this.events = events;
20527
20078
  }
20528
- getListTypeAtSelectionStart() {
20529
- return getListTypeAtSelectionStart(this.editor);
20079
+ getMatrixData() {
20080
+ const { translateX, translateY, scaleX, scaleY, shearX, shearY } = this._matrix;
20081
+ return { translateX, translateY, scaleX, scaleY, shearX, shearY };
20530
20082
  }
20531
- handleSplitListItem() {
20532
- return handleSplitListItem(this.editor);
20083
+ toMatrix() {
20084
+ return this._matrix.copy();
20533
20085
  }
20534
- includesListNode() {
20535
- return this.getText().some((node2) => node2.type === "ol_list" || node2.type === "ul_list");
20086
+ applyToContext(ctx) {
20087
+ this._matrix.applyToContext(ctx);
20536
20088
  }
20537
- toggleListType(targetListType, shouldWrap = true) {
20538
- const result = toggleListType(this.editor, targetListType, shouldWrap);
20539
- this.subject.publish(this);
20540
- return result;
20089
+ getTranslation() {
20090
+ return { x: this._matrix.translateX, y: this._matrix.translateY };
20541
20091
  }
20542
- withAutoList() {
20543
- return withAutoList(this.editor);
20092
+ getScale() {
20093
+ return { x: this._matrix.scaleX, y: this._matrix.scaleY };
20544
20094
  }
20545
- handleWrapIntoNestedList() {
20546
- const result = handleWrapIntoNestedList(this.editor);
20547
- this.subject.publish(this);
20548
- return result;
20095
+ getRotation() {
20096
+ return this.rotate;
20549
20097
  }
20550
- getFirstSelectionLink(selection) {
20551
- return getFirstSelectionLink(this.editor, selection);
20098
+ setLocal(xOrData, y, scaleX, scaleY) {
20099
+ this.previous = this._matrix.copy();
20100
+ if (typeof xOrData === "object") {
20101
+ if (xOrData.translateX !== undefined)
20102
+ this._matrix.translateX = xOrData.translateX;
20103
+ if (xOrData.translateY !== undefined)
20104
+ this._matrix.translateY = xOrData.translateY;
20105
+ if (xOrData.scaleX !== undefined)
20106
+ this._matrix.scaleX = xOrData.scaleX;
20107
+ if (xOrData.scaleY !== undefined)
20108
+ this._matrix.scaleY = xOrData.scaleY;
20109
+ } else {
20110
+ this._matrix.translateX = xOrData;
20111
+ this._matrix.translateY = y;
20112
+ if (scaleX !== undefined)
20113
+ this._matrix.scaleX = scaleX;
20114
+ if (scaleY !== undefined)
20115
+ this._matrix.scaleY = scaleY;
20116
+ }
20117
+ this.subject.publish(this, {
20118
+ class: "Transformation",
20119
+ method: "applyMatrix",
20120
+ items: [{ id: this.id, matrix: this.getMatrixData() }]
20121
+ });
20552
20122
  }
20553
- getText() {
20554
- return this.editor.children;
20123
+ serialize() {
20124
+ return {
20125
+ translateX: this._matrix.translateX,
20126
+ translateY: this._matrix.translateY,
20127
+ scaleX: this._matrix.scaleX,
20128
+ scaleY: this._matrix.scaleY,
20129
+ rotate: this.rotate,
20130
+ isLocked: this.isLocked
20131
+ };
20555
20132
  }
20556
- getTextParagraphs(lines) {
20557
- const newlines = [];
20558
- lines.forEach((line) => {
20559
- if (!this.getAutosize()) {
20560
- newlines.push(this.createParagraphNode(line));
20561
- return;
20562
- }
20563
- const validText = this.getValidText(line, newlines);
20564
- if (validText.length > 0) {
20565
- newlines.push(this.createParagraphNode(validText));
20566
- } else {
20567
- this.getOnLimitReached()();
20568
- }
20133
+ deserialize(data) {
20134
+ this.previous = this._matrix.copy();
20135
+ if (data.translateX) {
20136
+ this._matrix.translateX = data.translateX;
20137
+ }
20138
+ if (data.translateY) {
20139
+ this._matrix.translateY = data.translateY;
20140
+ }
20141
+ if (data.scaleX) {
20142
+ this._matrix.scaleX = data.scaleX;
20143
+ }
20144
+ if (data.scaleY) {
20145
+ this._matrix.scaleY = data.scaleY;
20146
+ }
20147
+ if (data.isLocked) {
20148
+ this.isLocked = data.isLocked;
20149
+ }
20150
+ if (data.rotate) {
20151
+ this.rotate = data.rotate;
20152
+ }
20153
+ this.subject.publish(this, {
20154
+ class: "Transformation",
20155
+ method: "deserialize",
20156
+ item: [this.id],
20157
+ data
20569
20158
  });
20570
- return newlines;
20159
+ return this;
20571
20160
  }
20572
- getValidText(line, newlines) {
20573
- let left = 0;
20574
- let right = line.length;
20575
- let validText = "";
20576
- while (left <= right) {
20577
- const mid = Math.floor((left + right) / 2);
20578
- const currentText = line.slice(0, mid);
20579
- const testLine = this.createParagraphNode(currentText);
20580
- const nodes = [...newlines, testLine];
20581
- this.applyAutoSizeScale(this.calcAutoSize(nodes), nodes);
20582
- const relativeFontSize = this.getFontSize() / this.getMatrixScale();
20583
- if (relativeFontSize >= 10) {
20584
- validText = currentText;
20585
- left = mid + 1;
20586
- } else {
20587
- right = mid - 1;
20588
- }
20589
- }
20590
- return validText;
20161
+ copy(id) {
20162
+ const { translateX, translateY, scaleX, scaleY } = this._matrix;
20163
+ const { rotate } = this;
20164
+ return new Transformation(id || "", this.events).deserialize({
20165
+ translateX,
20166
+ translateY,
20167
+ scaleX,
20168
+ scaleY,
20169
+ rotate,
20170
+ isLocked: false
20171
+ });
20591
20172
  }
20592
- createParagraphNode(text3) {
20593
- return createParagraphNode(text3, this.editor, this.horisontalAlignment);
20173
+ getInverse() {
20174
+ const copy2 = this.copy();
20175
+ copy2._matrix.invert();
20176
+ return copy2;
20594
20177
  }
20595
- insertCopiedText(text3) {
20596
- const lines = this.getTextParagraphs(text3.split(/\r\n|\r|\n/));
20597
- if (this.isLimitReached(lines)) {
20598
- return true;
20599
- }
20600
- insertCopiedNodes(this.editor, lines);
20601
- this.subject.publish(this);
20602
- return true;
20178
+ getId() {
20179
+ return this.id;
20603
20180
  }
20604
- checkIsAutoSizeTextScaleAllowed(nodes) {
20605
- const existingNodes = this.getBlockNodes();
20606
- const textScale = this.calcAutoSize([...existingNodes, ...nodes]);
20607
- const marks = this.getSelectionMarks();
20608
- const fontSize = marks?.fontSize ?? this.initialTextStyles.fontSize;
20609
- return Math.ceil(textScale * (fontSize === "auto" ? 14 : fontSize)) / this.getMatrixScale() > 4;
20181
+ setId(id) {
20182
+ this.id = id;
20610
20183
  }
20611
- isLimitReached(nodes) {
20612
- if (this.getAutosize()) {
20613
- if (!this.checkIsAutoSizeTextScaleAllowed(nodes)) {
20614
- this.getOnLimitReached()();
20615
- return true;
20616
- }
20184
+ emit(operation) {
20185
+ if (this.events) {
20186
+ const command = new TransformationCommand([this], operation);
20187
+ command.apply();
20188
+ this.events.emit(operation, command);
20189
+ } else {
20190
+ this.apply(operation);
20617
20191
  }
20618
- return false;
20619
20192
  }
20620
- insertCopiedNodes(nodes) {
20621
- if (this.isLimitReached(nodes)) {
20622
- return true;
20623
- }
20624
- insertCopiedNodes(this.editor, nodes);
20625
- this.subject.publish(this);
20626
- return true;
20193
+ emitMatrix(matrix, timeStamp) {
20194
+ this.emit({
20195
+ class: "Transformation",
20196
+ method: "applyMatrix",
20197
+ items: [{ id: this.id, matrix }],
20198
+ timeStamp
20199
+ });
20627
20200
  }
20628
- hasTextInSelection() {
20629
- return hasTextInSelection(this.editor);
20201
+ translateTo(x, y, timeStamp) {
20202
+ if (!this.id) {}
20203
+ this.emitMatrix({
20204
+ translateX: x - this._matrix.translateX,
20205
+ translateY: y - this._matrix.translateY,
20206
+ scaleX: 1,
20207
+ scaleY: 1,
20208
+ shearX: 0,
20209
+ shearY: 0
20210
+ }, timeStamp);
20630
20211
  }
20631
- getSelection() {
20632
- return JSON.parse(JSON.stringify(this.editor.selection));
20212
+ translateBy(x, y, timeStamp) {
20213
+ if (!this.id) {}
20214
+ if (x === 0 && y === 0) {
20215
+ return;
20216
+ }
20217
+ this.emitMatrix({
20218
+ translateX: x,
20219
+ translateY: y,
20220
+ scaleX: 1,
20221
+ scaleY: 1,
20222
+ shearX: 0,
20223
+ shearY: 0
20224
+ }, timeStamp);
20633
20225
  }
20634
- splitNode() {
20635
- Transforms17.splitNodes(this.editor, { always: true });
20226
+ scaleTo(x, y, timeStamp) {
20227
+ this.emitMatrix({
20228
+ translateX: 0,
20229
+ translateY: 0,
20230
+ scaleX: x / this._matrix.scaleX,
20231
+ scaleY: y / this._matrix.scaleY,
20232
+ shearX: 0,
20233
+ shearY: 0
20234
+ }, timeStamp);
20636
20235
  }
20637
- getBlockNodes() {
20638
- return this.editor.children;
20236
+ scaleBy(x, y, timeStamp) {
20237
+ if (x === 0 && y === 0) {
20238
+ return;
20239
+ }
20240
+ this.emitMatrix({
20241
+ translateX: 0,
20242
+ translateY: 0,
20243
+ scaleX: x,
20244
+ scaleY: y,
20245
+ shearX: 0,
20246
+ shearY: 0
20247
+ }, timeStamp);
20639
20248
  }
20640
- isEmpty() {
20641
- return isTextEmpty(this.editor.children);
20249
+ scaleByTranslateBy(scale, translate, timeStamp) {
20250
+ if (scale.x === 0 && scale.y === 0 && translate.x === 0 && translate.y === 0) {
20251
+ return;
20252
+ }
20253
+ this.emitMatrix({
20254
+ translateX: translate.x,
20255
+ translateY: translate.y,
20256
+ scaleX: scale.x,
20257
+ scaleY: scale.y,
20258
+ shearX: 0,
20259
+ shearY: 0
20260
+ }, timeStamp);
20642
20261
  }
20643
- clearText() {
20644
- clearText(this.editor);
20262
+ rotateTo(degree, timeStamp) {
20263
+ this.emit({
20264
+ class: "Transformation",
20265
+ method: "rotateTo",
20266
+ item: [this.id],
20267
+ degree,
20268
+ timeStamp
20269
+ });
20645
20270
  }
20646
- addText(text3) {
20647
- this.editor.apply({
20648
- type: "insert_text",
20649
- text: text3,
20650
- path: [0, 0],
20651
- offset: 0
20271
+ rotateBy(degree, timeStamp) {
20272
+ this.emit({
20273
+ class: "Transformation",
20274
+ method: "rotateBy",
20275
+ item: [this.id],
20276
+ degree,
20277
+ timeStamp
20652
20278
  });
20653
20279
  }
20654
- selectWholeText() {
20655
- selectWholeText(this.editor);
20280
+ scaleToRelativeTo(x, y, _point, timeStamp) {
20281
+ this.emitMatrix({
20282
+ translateX: 0,
20283
+ translateY: 0,
20284
+ scaleX: x / this._matrix.scaleX,
20285
+ scaleY: y / this._matrix.scaleY,
20286
+ shearX: 0,
20287
+ shearY: 0
20288
+ }, timeStamp);
20656
20289
  }
20657
- moveCursorToEndOfTheText(delay = 10) {
20658
- moveCursorToEndOfTheText(this.editor, delay);
20290
+ scaleByRelativeTo(x, y, point3, timeStamp) {
20291
+ const { scaleX: sx0, scaleY: sy0, translateX: tx0, translateY: ty0 } = this._matrix;
20292
+ const newSx = sx0 * x;
20293
+ const newSy = sy0 * y;
20294
+ this.emitMatrix({
20295
+ translateX: -point3.x * newSx + point3.x - tx0,
20296
+ translateY: -point3.y * newSy + point3.y - ty0,
20297
+ scaleX: x,
20298
+ scaleY: y,
20299
+ shearX: 0,
20300
+ shearY: 0
20301
+ }, timeStamp);
20659
20302
  }
20660
- }
20661
-
20662
- // src/Items/RichText/findOptimalMaxWidthForTextAutoSize.ts
20663
- function findOptimalMaxWidthForTextAutoSize(text3, containerWidth, containerHeight, initialMaxWidth, tolerance = 0.05) {
20664
- const targetRatio = containerWidth / containerHeight;
20665
- let low = 0;
20666
- let high = initialMaxWidth * 3;
20667
- let closestRatioDifference = Infinity;
20668
- let closestWidth = initialMaxWidth;
20669
- let closestHeight = initialMaxWidth / targetRatio;
20670
- const iterations = Math.min(Math.max(3, containerWidth / 80), 15);
20671
- for (let i = 0;i < iterations && low < high; i += 1) {
20672
- const mid = (low + high) / 2;
20673
- const { width: calcWidth, height: calcHeight } = getBlockNodes(text3, mid);
20674
- const currentRatio = calcWidth / calcHeight;
20675
- const ratioDifference = Math.abs(currentRatio - targetRatio);
20676
- if (ratioDifference < closestRatioDifference) {
20677
- closestRatioDifference = ratioDifference;
20678
- closestWidth = calcWidth;
20679
- closestHeight = calcHeight;
20680
- }
20681
- if (ratioDifference <= tolerance) {
20682
- break;
20683
- }
20684
- if (currentRatio < targetRatio) {
20685
- low = mid + 1;
20303
+ setIsLocked(isLocked, timestamp) {
20304
+ if (isLocked) {
20305
+ this.emit({
20306
+ class: "Transformation",
20307
+ method: "locked",
20308
+ item: [this.id],
20309
+ locked: true,
20310
+ timestamp
20311
+ });
20686
20312
  } else {
20687
- high = mid - 1;
20313
+ this.emit({
20314
+ class: "Transformation",
20315
+ method: "unlocked",
20316
+ item: [this.id],
20317
+ locked: false,
20318
+ timestamp
20319
+ });
20688
20320
  }
20689
20321
  }
20690
- const scale = Math.min(containerWidth / closestWidth, containerHeight / closestHeight);
20691
- return {
20692
- bestMaxWidth: initialMaxWidth / scale,
20693
- bestMaxHeight: initialMaxWidth / targetRatio / scale
20694
- };
20695
- }
20696
-
20697
- // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontColor.ts
20698
- import { Editor as Editor27 } from "slate";
20699
- function applySelectionFontColor(editor, fontColor) {
20700
- if (!editor) {
20701
- throw new Error("Editor is not initialized");
20322
+ apply(op) {
20323
+ this.previous = this._matrix.copy();
20324
+ switch (op.method) {
20325
+ case "applyMatrix": {
20326
+ const itemOp = op.items.find((i) => i.id === this.id);
20327
+ if (itemOp) {
20328
+ this._matrix.scale(itemOp.matrix.scaleX, itemOp.matrix.scaleY);
20329
+ this._matrix.translate(itemOp.matrix.translateX, itemOp.matrix.translateY);
20330
+ }
20331
+ break;
20332
+ }
20333
+ case "translateTo":
20334
+ this.applyTranslateTo(op.x, op.y);
20335
+ break;
20336
+ case "translateBy":
20337
+ this.applyTranslateBy(op.x, op.y);
20338
+ break;
20339
+ case "scaleTo":
20340
+ this.applyScaleTo(op.x, op.y);
20341
+ break;
20342
+ case "scaleBy":
20343
+ this.applyScaleBy(op.x, op.y);
20344
+ break;
20345
+ case "scaleToRelativeTo":
20346
+ this.applyScaleToRelativeTo(op.x, op.y, op.point);
20347
+ break;
20348
+ case "scaleByRelativeTo":
20349
+ this.applyScaleByRelativeTo(op.x, op.y, op.point);
20350
+ break;
20351
+ case "scaleByTranslateBy":
20352
+ this.applyScaleByTranslateBy(op.scale, op.translate);
20353
+ break;
20354
+ case "rotateTo":
20355
+ this.applyRotateTo(op.degree);
20356
+ break;
20357
+ case "rotateBy":
20358
+ this.applyRotateBy(op.degree);
20359
+ break;
20360
+ case "transformMany":
20361
+ this.applyTransformMany(op.items[this.id]);
20362
+ break;
20363
+ case "locked":
20364
+ this.applyLocked(op.locked);
20365
+ break;
20366
+ case "unlocked":
20367
+ this.applyUnlocked(op.locked);
20368
+ break;
20369
+ default:
20370
+ return;
20371
+ }
20372
+ this.subject.publish(this, op);
20702
20373
  }
20703
- const marks = getSelectionMarks(editor);
20704
- if (!marks) {
20705
- return;
20374
+ applyTranslateTo(x, y) {
20375
+ this._matrix.translateX = x;
20376
+ this._matrix.translateY = y;
20706
20377
  }
20707
- Editor27.addMark(editor, "fontColor", fontColor);
20708
- }
20709
-
20710
- // src/Items/RichText/editorHelpers/selectionOps/applySelectionFontSize.ts
20711
- import { Editor as Editor28, Transforms as Transforms18 } from "slate";
20712
- function applySelectionFontSize(editor, fontSize, selectionContext) {
20713
- const size = fontSize;
20714
- if (typeof size !== "number") {
20715
- return;
20378
+ applyTranslateBy(x, y) {
20379
+ this._matrix.translate(x, y);
20716
20380
  }
20717
- if (!editor) {
20718
- throw new Error("Editor is not initialized");
20381
+ applyScaleTo(x, y) {
20382
+ this._matrix.scaleX = x;
20383
+ this._matrix.scaleY = y;
20719
20384
  }
20720
- const selection = editor.selection;
20721
- const marks = getSelectionMarks(editor);
20722
- if (!marks) {
20723
- return;
20385
+ applyScaleBy(x, y) {
20386
+ this._matrix.scale(x, y);
20724
20387
  }
20725
- if (JSON.stringify(selection?.anchor) === JSON.stringify(selection?.focus)) {
20726
- Transforms18.select(editor, {
20727
- anchor: Editor28.start(editor, []),
20728
- focus: Editor28.end(editor, [])
20729
- });
20388
+ applyScaleByTranslateBy(scale, translate) {
20389
+ this._matrix.scale(scale.x, scale.y);
20390
+ this._matrix.translate(translate.x, translate.y);
20730
20391
  }
20731
- Editor28.addMark(editor, "fontSize", size);
20732
- if (selectionContext === "EditTextUnderPointer") {}
20733
- }
20734
-
20735
- // src/Items/RichText/editorHelpers/common/getSelectedBlockNode.ts
20736
- import { Editor as Editor29, Element as Element5 } from "slate";
20737
- function getSelectedBlockNode(editor) {
20738
- const { selection } = editor;
20739
- if (!selection) {
20740
- return null;
20392
+ applyTransformMany(op) {
20393
+ if (op.method === "applyMatrix") {
20394
+ this._matrix.scale(op.matrix.scaleX, op.matrix.scaleY);
20395
+ this._matrix.translate(op.matrix.translateX, op.matrix.translateY);
20396
+ } else if (op.method === "scaleByTranslateBy") {
20397
+ this.applyScaleByTranslateBy(op.scale, op.translate);
20398
+ } else if (op.method === "scaleBy") {
20399
+ this.applyScaleBy(op.x, op.y);
20400
+ } else if (op.method === "translateBy") {
20401
+ this.applyTranslateBy(op.x, op.y);
20402
+ } else if (op.method === "translateTo") {
20403
+ this.applyTranslateTo(op.x, op.y);
20404
+ }
20741
20405
  }
20742
- const [node2] = Editor29.node(editor, selection);
20743
- if (Editor29.isEditor(node2) || !Element5.isElement(node2)) {
20744
- return null;
20406
+ applyScaleByRelativeTo(x, y, point3) {
20407
+ const scaleX = this._matrix.scaleX * x;
20408
+ const scaleY = this._matrix.scaleY * y;
20409
+ this._matrix.translateX = -point3.x * scaleX + point3.x;
20410
+ this._matrix.translateY = -point3.y * scaleY + point3.y;
20411
+ this._matrix.scaleX = scaleX;
20412
+ this._matrix.scaleY = scaleY;
20745
20413
  }
20746
- return node2;
20747
- }
20748
-
20749
- // src/Items/RichText/utils.ts
20750
- function findCommonStrings(arrays) {
20751
- if (arrays.length === 0) {
20752
- return [];
20414
+ applyScaleToRelativeTo(x, y, point3) {
20415
+ this.applyTranslateBy(-point3.x, -point3.y);
20416
+ this.applyScaleTo(x, y);
20417
+ this.applyTranslateBy(point3.x, point3.y);
20753
20418
  }
20754
- let commonStrings = arrays[0];
20755
- for (let i = 1;i < arrays.length; i++) {
20756
- commonStrings = commonStrings.filter((str) => arrays[i].includes(str));
20419
+ applyRotateTo(degree) {
20420
+ if (degree > 0) {
20421
+ while (degree > 360) {
20422
+ degree -= 360;
20423
+ }
20424
+ if (degree === 360) {
20425
+ degree = 0;
20426
+ }
20427
+ } else {
20428
+ while (degree < -360) {
20429
+ degree += 360;
20430
+ }
20431
+ if (degree === -360) {
20432
+ degree = 0;
20433
+ }
20434
+ }
20435
+ this.rotate = degree;
20757
20436
  }
20758
- return commonStrings;
20759
- }
20760
-
20761
- // src/Items/RichText/editorHelpers/common/getSelectionStyles.ts
20762
- function getSelectionStyles(editor) {
20763
- const { selection } = editor;
20764
- if (!selection) {
20765
- return;
20437
+ applyRotateBy(degree) {
20438
+ this.applyRotateTo(this.rotate + degree);
20766
20439
  }
20767
- const nodes = getAllTextNodesInSelection(editor);
20768
- const styles = nodes.reduce((acc, node2) => {
20769
- const styles2 = [];
20770
- if (node2.text === "") {
20771
- return acc;
20772
- }
20773
- if (node2.bold) {
20774
- styles2.push("bold");
20775
- }
20776
- if (node2.italic) {
20777
- styles2.push("italic");
20778
- }
20779
- if (node2.underline) {
20780
- styles2.push("underline");
20781
- }
20782
- if (node2["line-through"]) {
20783
- styles2.push("line-through");
20784
- }
20785
- acc.push(styles2);
20786
- return acc;
20787
- }, []);
20788
- return findCommonStrings(styles);
20789
- }
20790
-
20791
- // src/Items/RichText/editorHelpers/common/setEditorFocus.ts
20792
- import { ReactEditor as ReactEditor6 } from "slate-react";
20793
- function setEditorFocus(editor, selectionContext) {
20794
- if (!editor) {
20795
- throw new Error("Editor is not initialized");
20440
+ applyLocked(locked) {
20441
+ this.isLocked = locked;
20796
20442
  }
20797
- if (selectionContext === "EditTextUnderPointer") {
20798
- ReactEditor6.focus(editor);
20443
+ applyUnlocked(locked) {
20444
+ this.isLocked = locked;
20799
20445
  }
20800
20446
  }
20801
20447
 
@@ -21135,6 +20781,146 @@ function applyRedo(board, operation) {
21135
20781
  addOperationHandler("undo", applyUndo);
21136
20782
  addOperationHandler("redo", applyRedo);
21137
20783
 
20784
+ // src/Items/Connector/ConnectorCommand.ts
20785
+ class ConnectorCommand {
20786
+ connector;
20787
+ operation;
20788
+ reverse;
20789
+ constructor(connector, operation) {
20790
+ this.connector = connector;
20791
+ this.operation = operation;
20792
+ this.reverse = this.getReverse();
20793
+ }
20794
+ merge(op) {
20795
+ this.operation = op;
20796
+ return this;
20797
+ }
20798
+ apply() {
20799
+ for (const connector of this.connector) {
20800
+ connector.apply(this.operation);
20801
+ }
20802
+ }
20803
+ revert() {
20804
+ for (const { item, operation } of this.reverse) {
20805
+ item.apply(operation);
20806
+ }
20807
+ }
20808
+ getReverse() {
20809
+ const reverse = [];
20810
+ switch (this.operation.method) {
20811
+ case "setStartPoint":
20812
+ for (const connector of this.connector) {
20813
+ reverse.push({
20814
+ item: connector,
20815
+ operation: {
20816
+ ...this.operation,
20817
+ startPointData: connector.getStartPoint().serialize()
20818
+ }
20819
+ });
20820
+ }
20821
+ break;
20822
+ case "setEndPoint":
20823
+ for (const connector of this.connector) {
20824
+ reverse.push({
20825
+ item: connector,
20826
+ operation: {
20827
+ ...this.operation,
20828
+ endPointData: connector.getEndPoint().serialize()
20829
+ }
20830
+ });
20831
+ }
20832
+ break;
20833
+ case "setMiddlePoint":
20834
+ for (const connector of this.connector) {
20835
+ const middlePoint = connector.getMiddlePoint();
20836
+ reverse.push({
20837
+ item: connector,
20838
+ operation: {
20839
+ ...this.operation,
20840
+ middlePointData: middlePoint ? middlePoint.serialize() : null
20841
+ }
20842
+ });
20843
+ }
20844
+ break;
20845
+ case "setStartPointerStyle":
20846
+ for (const connector of this.connector) {
20847
+ reverse.push({
20848
+ item: connector,
20849
+ operation: {
20850
+ ...this.operation,
20851
+ startPointerStyle: connector.getStartPointerStyle()
20852
+ }
20853
+ });
20854
+ }
20855
+ break;
20856
+ case "setEndPointerStyle":
20857
+ for (const connector of this.connector) {
20858
+ reverse.push({
20859
+ item: connector,
20860
+ operation: {
20861
+ ...this.operation,
20862
+ endPointerStyle: connector.getEndPointerStyle()
20863
+ }
20864
+ });
20865
+ }
20866
+ break;
20867
+ case "setLineStyle":
20868
+ for (const connector of this.connector) {
20869
+ reverse.push({
20870
+ item: connector,
20871
+ operation: {
20872
+ ...this.operation,
20873
+ lineStyle: connector.getLineStyle()
20874
+ }
20875
+ });
20876
+ }
20877
+ break;
20878
+ case "setBorderStyle":
20879
+ for (const connector of this.connector) {
20880
+ reverse.push({
20881
+ item: connector,
20882
+ operation: {
20883
+ ...this.operation,
20884
+ borderStyle: connector.getBorderStyle()
20885
+ }
20886
+ });
20887
+ }
20888
+ break;
20889
+ case "setLineWidth":
20890
+ for (const connector of this.connector) {
20891
+ reverse.push({
20892
+ item: connector,
20893
+ operation: {
20894
+ ...this.operation,
20895
+ lineWidth: connector.getLineWidth()
20896
+ }
20897
+ });
20898
+ }
20899
+ break;
20900
+ case "setLineColor":
20901
+ for (const connector of this.connector) {
20902
+ reverse.push({
20903
+ item: connector,
20904
+ operation: {
20905
+ ...this.operation,
20906
+ lineColor: connector.getLineColor()
20907
+ }
20908
+ });
20909
+ }
20910
+ break;
20911
+ case "switchPointers":
20912
+ for (const connector of this.connector) {
20913
+ reverse.push({
20914
+ item: connector,
20915
+ operation: this.operation
20916
+ });
20917
+ }
20918
+ break;
20919
+ }
20920
+ return reverse;
20921
+ }
20922
+ }
20923
+
21138
20924
  // src/Items/Drawing/DrawingCommand.ts
21139
20925
  class DrawingCommand {
21140
20926
  item;
@@ -21302,7 +21088,6 @@ class FrameCommand {
21302
21088
  }
21303
21089
  }
21304
21090
  }
21305
-
21306
21091
  // src/Items/Comment/CommentCommand.ts
21307
21092
  class CommentCommand {
21308
21093
  comment;
@@ -21380,9 +21165,15 @@ class CommentCommand {
21380
21165
  }
21381
21166
  }
21382
21167
  }
21383
- // node_modules/uuid/dist/esm/native.js
21384
- import { randomUUID } from "crypto";
21385
- var native_default = { randomUUID };
21168
+
21169
+ // node_modules/uuid/dist/esm/stringify.js
21170
+ var byteToHex = [];
21171
+ for (let i = 0;i < 256; ++i) {
21172
+ byteToHex.push((i + 256).toString(16).slice(1));
21173
+ }
21174
+ function unsafeStringify(arr2, offset = 0) {
21175
+ 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();
21176
+ }
21386
21177
 
21387
21178
  // node_modules/uuid/dist/esm/rng.js
21388
21179
  import { randomFillSync } from "crypto";
@@ -21396,14 +21187,9 @@ function rng() {
21396
21187
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
21397
21188
  }
21398
21189
 
21399
- // node_modules/uuid/dist/esm/stringify.js
21400
- var byteToHex = [];
21401
- for (let i = 0;i < 256; ++i) {
21402
- byteToHex.push((i + 256).toString(16).slice(1));
21403
- }
21404
- function unsafeStringify(arr2, offset = 0) {
21405
- 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();
21406
- }
21190
+ // node_modules/uuid/dist/esm/native.js
21191
+ import { randomUUID } from "crypto";
21192
+ var native_default = { randomUUID };
21407
21193
 
21408
21194
  // node_modules/uuid/dist/esm/v4.js
21409
21195
  function v4(options, buf, offset) {
@@ -22868,18 +22654,25 @@ class RTreeIndex {
22868
22654
  }
22869
22655
 
22870
22656
  // src/SpatialIndex/LayeredIndex/index.ts
22871
- class Container extends Mbr {
22657
+ class Container {
22872
22658
  id;
22873
22659
  item;
22874
22660
  layer;
22875
22661
  zIndex;
22662
+ left;
22663
+ top;
22664
+ right;
22665
+ bottom;
22876
22666
  constructor(id, item, layer, zIndex) {
22877
- const rect = item.getMbrWithChildren();
22878
- super(rect.left, rect.top, rect.right, rect.bottom);
22879
22667
  this.id = id;
22880
22668
  this.item = item;
22881
22669
  this.layer = layer;
22882
22670
  this.zIndex = zIndex;
22671
+ const rect = item.getMbrWithChildren();
22672
+ this.left = rect.left;
22673
+ this.top = rect.top;
22674
+ this.right = rect.right;
22675
+ this.bottom = rect.bottom;
22883
22676
  }
22884
22677
  }
22885
22678
 
@@ -24258,7 +24051,7 @@ class RichText extends BaseItem {
24258
24051
  parent = "Board";
24259
24052
  subject = new Subject;
24260
24053
  editor;
24261
- editorTransforms = Transforms19;
24054
+ editorTransforms = Transforms20;
24262
24055
  editorEditor = Editor30;
24263
24056
  isContainerSet = false;
24264
24057
  isRenderEnabled = true;
@@ -24881,9 +24674,9 @@ class RichText extends BaseItem {
24881
24674
  }
24882
24675
  restoreSelection(selection) {
24883
24676
  if (selection) {
24884
- Transforms19.select(this.editor.editor, selection);
24677
+ Transforms20.select(this.editor.editor, selection);
24885
24678
  } else {
24886
- Transforms19.deselect(this.editor.editor);
24679
+ Transforms20.deselect(this.editor.editor);
24887
24680
  }
24888
24681
  }
24889
24682
  deserialize(data) {
@@ -25166,6 +24959,252 @@ class RichText extends BaseItem {
25166
24959
  return this.prevMbr;
25167
24960
  }
25168
24961
  }
24962
+
24963
+ // src/Items/Mbr/updateRects.ts
24964
+ function updateRects(board, ref, mbr, verticalOffset, horizontalOffset, fit = "contextPanel") {
24965
+ const { selection, camera } = board;
24966
+ const panel = ref.current;
24967
+ const selectionMbr = mbr ?? selection.getMbr();
24968
+ const selectionItems = selection.items;
24969
+ const richTextSelection = selectionItems.getSingle() instanceof RichText ? selectionItems.list()[0] : undefined;
24970
+ if (panel && selectionMbr) {
24971
+ if (fit === "contextPanel") {
24972
+ const panelRect = getContextPanelRect(selectionMbr, camera, panel, !!richTextSelection, horizontalOffset, verticalOffset);
24973
+ return panelRect;
24974
+ }
24975
+ if (fit === "linkToBtn") {
24976
+ if (!mbr) {
24977
+ return null;
24978
+ }
24979
+ const panelRect = fitLinkToBtn(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
24980
+ return panelRect;
24981
+ }
24982
+ if (fit === "comment") {
24983
+ if (!mbr) {
24984
+ return null;
24985
+ }
24986
+ const panelRect = fitComment(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
24987
+ return panelRect;
24988
+ }
24989
+ if (fit === "threadPanel") {
24990
+ if (!mbr) {
24991
+ return null;
24992
+ }
24993
+ const panelRect = fitThreadPanel(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
24994
+ return panelRect;
24995
+ }
24996
+ if (fit === "boardMenu") {
24997
+ if (!mbr) {
24998
+ return null;
24999
+ }
25000
+ const panelRect = fitBoardMenu(selectionMbr.getTransformed(camera.getMatrix()), camera.window.getMbr(), Mbr.fromDomRect(panel.getBoundingClientRect()), verticalOffset, horizontalOffset);
25001
+ return panelRect;
25002
+ }
25003
+ if (fit === "hyperLink") {
25004
+ if (!mbr) {
25005
+ return null;
25006
+ }
25007
+ const panelRect = fitHyperLink(selectionMbr.getTransformed(camera.getMatrix()), Mbr.fromDomRect(panel.getBoundingClientRect()), camera.window.getMbr(), verticalOffset);
25008
+ return panelRect;
25009
+ }
25010
+ }
25011
+ return null;
25012
+ }
25013
+ function getContextPanelRect(selectionMbr, camera, panel, toLeft, horizontalOffset, verticalOffset) {
25014
+ const transformedMbr = selectionMbr.getTransformed(camera.getMatrix());
25015
+ const windowMbr = camera.window.getMbr();
25016
+ const panelRectFromDom = Mbr.fromDomRect(panel.getBoundingClientRect());
25017
+ const panelRect = toLeft ? fitContextPanelToLeft(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset) : fitContextPanelToCenter(transformedMbr, windowMbr, panelRectFromDom, verticalOffset, horizontalOffset);
25018
+ return panelRect;
25019
+ }
25020
+ function fitContextPanelToLeft(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
25021
+ const panelHeight = panel.getHeight();
25022
+ const panelWidth = panel.getWidth();
25023
+ const newPanel = new Mbr;
25024
+ const topSpace = selectionMbr.top - view.top;
25025
+ const hasEnoughTopSpace = topSpace >= panelHeight + verticalOffset;
25026
+ if (hasEnoughTopSpace) {
25027
+ newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
25028
+ if (newPanel.top < view.top) {
25029
+ newPanel.top = view.top + verticalOffset;
25030
+ }
25031
+ } else {
25032
+ const usePanelTop = panel.top > 1 && panel.top > selectionMbr.top + verticalOffset;
25033
+ newPanel.top = usePanelTop ? panel.top : selectionMbr.bottom + verticalOffset;
25034
+ const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
25035
+ const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
25036
+ if (isOverflowingBottom || isLargeOffsetForRichText) {
25037
+ newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
25038
+ }
25039
+ }
25040
+ newPanel.bottom = newPanel.top + panelHeight;
25041
+ fitContextPanelInViewRect(newPanel, view, verticalOffset);
25042
+ const itemMbr = selectionMbr.getMbr();
25043
+ newPanel.left = itemMbr.left;
25044
+ adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
25045
+ return newPanel;
25046
+ }
25047
+ function fitContextPanelToCenter(selectionMbr, view, panel, verticalOffset = 40, horizontalOffset = 80) {
25048
+ const panelHeight = panel.getHeight();
25049
+ const panelWidth = panel.getWidth();
25050
+ const newPanel = new Mbr;
25051
+ const topSpace = selectionMbr.top - view.top;
25052
+ const bottomSpace = view.bottom - selectionMbr.bottom;
25053
+ const shouldPlaceAbove = topSpace > bottomSpace - panelHeight;
25054
+ if (shouldPlaceAbove) {
25055
+ newPanel.top = selectionMbr.top - panelHeight - verticalOffset;
25056
+ if (newPanel.top < view.top) {
25057
+ newPanel.top = view.top + verticalOffset;
25058
+ }
25059
+ } else {
25060
+ newPanel.top = selectionMbr.bottom + verticalOffset;
25061
+ const isOverflowingBottom = newPanel.top + panelHeight > view.bottom;
25062
+ const isLargeOffsetForRichText = newPanel.top >= selectionMbr.bottom + verticalOffset * 2;
25063
+ if (isOverflowingBottom || isLargeOffsetForRichText) {
25064
+ newPanel.top = selectionMbr.bottom - (panelHeight + verticalOffset);
25065
+ }
25066
+ }
25067
+ newPanel.bottom = newPanel.top + panelHeight;
25068
+ fitContextPanelInViewRect(newPanel, view, verticalOffset);
25069
+ const itemCenter = selectionMbr.getCenter();
25070
+ newPanel.left = itemCenter.x - panelWidth / 2;
25071
+ adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset);
25072
+ return newPanel;
25073
+ }
25074
+ function adjustPanelHorizontal(newPanel, panelWidth, view, horizontalOffset) {
25075
+ newPanel.right = newPanel.left + panelWidth;
25076
+ if (newPanel.left < view.left + horizontalOffset) {
25077
+ newPanel.left = view.left + horizontalOffset;
25078
+ } else if (newPanel.right + horizontalOffset > view.right) {
25079
+ newPanel.left = view.right - (panelWidth + horizontalOffset);
25080
+ }
25081
+ newPanel.right = newPanel.left + panelWidth;
25082
+ }
25083
+ function fitContextPanelInViewRect(panel, view, verticalOffset) {
25084
+ const panelHeight = panel.getHeight();
25085
+ if (panel.top <= view.top + verticalOffset) {
25086
+ panel.top = view.top + 2 * verticalOffset;
25087
+ panel.bottom = panel.top + panelHeight;
25088
+ }
25089
+ if (panel.bottom >= view.bottom - verticalOffset) {
25090
+ panel.bottom = view.bottom - 2 * verticalOffset;
25091
+ panel.top = panel.bottom - panelHeight;
25092
+ }
25093
+ }
25094
+ function fitLinkToBtn(itemMbr, view, panel, verticalOffset = -2, horizontalOffset = -2) {
25095
+ const panelHeight = panel.getHeight();
25096
+ const newPanel = new Mbr;
25097
+ newPanel.top = itemMbr.top - panelHeight - verticalOffset;
25098
+ newPanel.top = newPanel.top + panelHeight;
25099
+ newPanel.bottom = newPanel.top + panelHeight * 2;
25100
+ const panelWidth = panel.getWidth();
25101
+ newPanel.left = itemMbr.right - panelWidth + horizontalOffset;
25102
+ return newPanel;
25103
+ }
25104
+ function fitHyperLink(linkMbr, panel, view, offset = 20) {
25105
+ const panelHeight = panel.getHeight();
25106
+ const newPanel = new Mbr;
25107
+ newPanel.top = linkMbr.bottom;
25108
+ newPanel.bottom = panelHeight + newPanel.top;
25109
+ const panelWidth = panel.getWidth();
25110
+ newPanel.left = linkMbr.left;
25111
+ newPanel.right = newPanel.left + panelWidth;
25112
+ return newPanel;
25113
+ }
25114
+ function fitComment(anchor, panel, verticalOffset = 0, horizontalOffset = 0) {
25115
+ const panelHeight = panel.getHeight();
25116
+ const newPanel = new Mbr;
25117
+ newPanel.top = anchor.top - panelHeight - verticalOffset;
25118
+ newPanel.bottom = newPanel.top + panelHeight;
25119
+ const panelWidth = panel.getWidth();
25120
+ newPanel.left = anchor.left - panelWidth / 2 - horizontalOffset;
25121
+ newPanel.right = newPanel.left + panelWidth;
25122
+ return newPanel;
25123
+ }
25124
+ function fitBoardMenu(anchor, view, panel, verticalOffset = 20, horizontalOffset = 20) {
25125
+ const panelHeight = panel.getHeight();
25126
+ const panelWidth = panel.getWidth();
25127
+ const newPanel = new Mbr;
25128
+ newPanel.top = anchor.top;
25129
+ newPanel.bottom = newPanel.top + panelHeight;
25130
+ if (newPanel.bottom > view.bottom - verticalOffset) {
25131
+ newPanel.bottom = view.bottom - verticalOffset;
25132
+ newPanel.top = newPanel.bottom - panelHeight;
25133
+ }
25134
+ newPanel.left = anchor.left;
25135
+ newPanel.right = newPanel.left + panelWidth;
25136
+ if (newPanel.right > view.right - horizontalOffset) {
25137
+ newPanel.right = view.right - horizontalOffset;
25138
+ newPanel.left = newPanel.right - panelWidth;
25139
+ }
25140
+ return newPanel;
25141
+ }
25142
+ function fitThreadPanel(anchor, view, panel, verticalOffset = 50, horizontalOffset = 50) {
25143
+ const panelHeight = panel.getHeight();
25144
+ const panelWidth = panel.getWidth();
25145
+ const newPanel = new Mbr;
25146
+ newPanel.top = anchor.top - panelHeight / 2;
25147
+ if (newPanel.top < view.top + verticalOffset) {
25148
+ newPanel.top = view.top + verticalOffset;
25149
+ }
25150
+ newPanel.bottom = newPanel.top + panelHeight;
25151
+ if (newPanel.bottom > view.bottom - verticalOffset) {
25152
+ newPanel.bottom = view.bottom - verticalOffset;
25153
+ newPanel.top = newPanel.bottom - panelHeight;
25154
+ }
25155
+ newPanel.left = anchor.left;
25156
+ newPanel.right = newPanel.left + panelWidth;
25157
+ if (newPanel.right > view.right - horizontalOffset) {
25158
+ newPanel.right = anchor.right;
25159
+ newPanel.left = newPanel.right - panelWidth;
25160
+ }
25161
+ return newPanel;
25162
+ }
25163
+ // src/Items/DrawingContext.ts
25164
+ class DrawingContext2 {
25165
+ camera;
25166
+ ctx;
25167
+ cursorCtx;
25168
+ matrix;
25169
+ isBorderInvisible = false;
25170
+ shapeVisibilityTreshold = 3;
25171
+ rectangleVisibilyTreshold = 2;
25172
+ constructor(camera, ctx, cursorCtx, matrix = new Matrix2) {
25173
+ this.camera = camera;
25174
+ this.ctx = ctx;
25175
+ this.cursorCtx = cursorCtx;
25176
+ this.matrix = matrix;
25177
+ this.setCamera(camera);
25178
+ }
25179
+ dpi() {
25180
+ return conf.getDPI();
25181
+ }
25182
+ setCamera(camera) {
25183
+ this.camera = camera;
25184
+ this.matrix = camera.getMatrix();
25185
+ const scale = this.matrix.scaleX;
25186
+ this.isBorderInvisible = 4 * scale < 0.1;
25187
+ }
25188
+ clear() {
25189
+ this.ctx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
25190
+ this.ctx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
25191
+ this.matrix.applyToContext(this.ctx);
25192
+ }
25193
+ clearCursor() {
25194
+ if (!this.cursorCtx) {
25195
+ return;
25196
+ }
25197
+ this.cursorCtx.setTransform(1 * this.dpi(), 0, 0, 1 * this.dpi(), 0, 0);
25198
+ this.cursorCtx.clearRect(0, 0, conf.getDocumentWidth(), conf.getDocumentHeight());
25199
+ this.matrix.applyToContext(this.cursorCtx);
25200
+ }
25201
+ applyChanges() {
25202
+ this.matrix.applyToContext(this.ctx);
25203
+ }
25204
+ getCameraScale() {
25205
+ return this.camera.getScale();
25206
+ }
25207
+ }
25169
25208
  // node_modules/property-information/lib/util/schema.js
25170
25209
  class Schema {
25171
25210
  constructor(property, normal, space) {
@@ -36844,10 +36883,10 @@ function zwitch(key, options) {
36844
36883
  const settings = options || {};
36845
36884
  function one4(value, ...parameters) {
36846
36885
  let fn = one4.invalid;
36847
- const handlers3 = one4.handlers;
36886
+ const handlers2 = one4.handlers;
36848
36887
  if (value && own7.call(value, key)) {
36849
36888
  const id = String(value[key]);
36850
- fn = own7.call(handlers3, id) ? handlers3[id] : one4.unknown;
36889
+ fn = own7.call(handlers2, id) ? handlers2[id] : one4.unknown;
36851
36890
  }
36852
36891
  if (fn) {
36853
36892
  return fn.call(this, value, ...parameters);
@@ -38717,14 +38756,13 @@ function getControlPoint(data, findItem2) {
38717
38756
  }
38718
38757
  }
38719
38758
  function toRelativePoint(point5, item) {
38720
- const matrix = item.transformation?.matrix || new Matrix2;
38721
- const inverse = matrix.getInverse();
38759
+ const inverse = item.transformation ? item.transformation.getInverse().toMatrix() : new Matrix2;
38722
38760
  point5 = point5.copy();
38723
38761
  point5.transform(inverse);
38724
38762
  return point5;
38725
38763
  }
38726
38764
  function fromRelativePoint(relativePoint, item, edge) {
38727
- const matrix = item.transformation?.matrix.copy() || new Matrix2;
38765
+ const matrix = item.transformation?.toMatrix() ?? new Matrix2;
38728
38766
  const point5 = relativePoint.copy();
38729
38767
  point5.transform(matrix);
38730
38768
  if (item instanceof RichText || item instanceof AINode) {
@@ -42677,7 +42715,7 @@ async function exportBoardSnapshot({
42677
42715
  const selectionMatrix = new Matrix2(translationX, translationY, scaleX, scaleY);
42678
42716
  camera.matrix = selectionMatrix;
42679
42717
  }
42680
- const context = new DrawingContext(camera, ctx);
42718
+ const context = new DrawingContext2(camera, ctx);
42681
42719
  context.setCamera(camera);
42682
42720
  context.ctx.setTransform(upscaleFactor, 0, 0, upscaleFactor, 0, 0);
42683
42721
  context.matrix.applyToContext(context.ctx);
@@ -44525,7 +44563,7 @@ class Placeholder extends BaseItem {
44525
44563
  function getPlaceholderImage(board, imageDimension) {
44526
44564
  const placeholderCanvas = conf.documentFactory.createElement("canvas");
44527
44565
  const placeholderContext = placeholderCanvas.getContext("2d");
44528
- const context = new DrawingContext(board.camera, placeholderContext);
44566
+ const context = new DrawingContext2(board.camera, placeholderContext);
44529
44567
  const placeholder = new Placeholder(board);
44530
44568
  if (imageDimension) {
44531
44569
  placeholderCanvas.width = imageDimension.width;
@@ -47169,7 +47207,7 @@ class ExportSnapshot extends Tool {
47169
47207
  const cameraCenter = this.board.camera.getMbr().getCenter();
47170
47208
  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);
47171
47209
  this.board.selection.disable();
47172
- this.tempDrawingContext = new DrawingContext(board.camera, this.tempCtx);
47210
+ this.tempDrawingContext = new DrawingContext2(board.camera, this.tempCtx);
47173
47211
  }
47174
47212
  rectMoveTo(x, y) {
47175
47213
  this.transformation.translateTo(x, y);
@@ -47457,7 +47495,7 @@ function createCanvasDrawer(board) {
47457
47495
  const camera = new Camera;
47458
47496
  const newCameraMatix = new Matrix2(-mbr.left, -mbr.top, 1, 1);
47459
47497
  camera.matrix = newCameraMatix;
47460
- const context = new DrawingContext(camera, ctx);
47498
+ const context = new DrawingContext2(camera, ctx);
47461
47499
  context.setCamera(camera);
47462
47500
  context.ctx.setTransform(board2.camera.getMatrix().scaleX, 0, 0, board2.camera.getMatrix().scaleY, 0, 0);
47463
47501
  context.matrix.applyToContext(context.ctx);
@@ -51634,8 +51672,11 @@ class Camera {
51634
51672
  boardId = "";
51635
51673
  observableItem = null;
51636
51674
  throttledZoom;
51637
- isAnimating = false;
51638
51675
  isTrackingAnimation = false;
51676
+ localAnimationTarget = null;
51677
+ localAnimationId = null;
51678
+ localLastTime = null;
51679
+ localSpringVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0 };
51639
51680
  trackingAnimationId = null;
51640
51681
  trackingTarget = null;
51641
51682
  lastTrackingTime = null;
@@ -51715,7 +51756,7 @@ class Camera {
51715
51756
  }
51716
51757
  view(_left, _top, _scale) {}
51717
51758
  zoomRelativeToPointerBy(scale) {
51718
- this.zoomRelativeToPointBy(scale, this.pointer.x, this.pointer.y, 0);
51759
+ this.zoomRelativeToPointBy(scale, this.pointer.x, this.pointer.y);
51719
51760
  }
51720
51761
  zoomRelativeToPointBy(scale, x, y, duration = 400) {
51721
51762
  const startScaleX = this.matrix.scaleX;
@@ -51741,23 +51782,12 @@ class Camera {
51741
51782
  this.subject.publish(this);
51742
51783
  return;
51743
51784
  }
51744
- const startTime = performance.now();
51745
- const animate = (currentTime) => {
51746
- if (!currentTime) {
51747
- currentTime = performance.now();
51748
- }
51749
- const progress = Math.min((currentTime - startTime) / duration, 1);
51750
- const easedProgress = this.easeOutQuad(progress);
51751
- this.matrix.translateX = this.lerp(startTranslateX, targetTranslateX, easedProgress);
51752
- this.matrix.translateY = this.lerp(startTranslateY, targetTranslateY, easedProgress);
51753
- this.matrix.scaleX = this.lerp(startScaleX, finalScaleX, easedProgress);
51754
- this.matrix.scaleY = this.lerp(startScaleY, finalScaleY, easedProgress);
51755
- this.subject.publish(this);
51756
- if (progress < 1) {
51757
- safeRequestAnimationFrame(animate);
51758
- }
51759
- };
51760
- safeRequestAnimationFrame(animate);
51785
+ this.animateLocalToTarget({
51786
+ translateX: targetTranslateX,
51787
+ translateY: targetTranslateY,
51788
+ scaleX: finalScaleX,
51789
+ scaleY: finalScaleY
51790
+ });
51761
51791
  }
51762
51792
  saveDownEvent(event) {
51763
51793
  this.touchEvents.set(event.pointerId, event);
@@ -51987,13 +52017,6 @@ class Camera {
51987
52017
  }
51988
52018
  }
51989
52019
  viewRectangle(mbr, offsetInPercent = 10, duration = 500) {
51990
- if (duration <= 0) {
51991
- duration = 1;
51992
- }
51993
- if (this.isAnimating) {
51994
- return;
51995
- }
51996
- this.isAnimating = true;
51997
52020
  if (mbr.left === mbr.right && mbr.bottom === mbr.top) {
51998
52021
  mbr.left -= 100;
51999
52022
  mbr.right += 100;
@@ -52016,9 +52039,6 @@ class Camera {
52016
52039
  targetScale = Math.min(targetScale, this.maxScale);
52017
52040
  const translationX = this.window.width / 2 - (mbrWithOffset.left + mbrWidth / 2) * targetScale;
52018
52041
  const translationY = this.window.height / 2 - (mbrWithOffset.top + mbrHeight / 2) * targetScale;
52019
- const startTranslationX = this.matrix.translateX;
52020
- const startTranslationY = this.matrix.translateY;
52021
- const startScale = this.matrix.scaleX;
52022
52042
  if (duration === 0) {
52023
52043
  this.matrix.translateX = translationX;
52024
52044
  this.matrix.translateY = translationY;
@@ -52027,29 +52047,76 @@ class Camera {
52027
52047
  this.subject.publish(this);
52028
52048
  return;
52029
52049
  }
52030
- const startTime = performance.now();
52031
- const animate = () => {
52032
- const currentTime = performance.now();
52033
- const progress = Math.min((currentTime - startTime) / duration, 1);
52034
- const easedProgress = this.easeOutQuad(progress);
52035
- this.matrix.translateX = this.lerp(startTranslationX, translationX, easedProgress);
52036
- this.matrix.translateY = this.lerp(startTranslationY, translationY, easedProgress);
52037
- this.matrix.scaleX = this.lerp(startScale, targetScale, easedProgress);
52038
- this.matrix.scaleY = this.matrix.scaleX;
52050
+ this.animateLocalToTarget({
52051
+ translateX: translationX,
52052
+ translateY: translationY,
52053
+ scaleX: targetScale,
52054
+ scaleY: targetScale
52055
+ });
52056
+ }
52057
+ cancelLocalAnimation() {
52058
+ if (this.localAnimationId !== null) {
52059
+ cancelAnimationFrame(this.localAnimationId);
52060
+ this.localAnimationId = null;
52061
+ }
52062
+ this.localAnimationTarget = null;
52063
+ this.localLastTime = null;
52064
+ this.localSpringVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0 };
52065
+ }
52066
+ animateLocalToTarget(target) {
52067
+ this.localAnimationTarget = target;
52068
+ if (this.localAnimationId !== null) {
52069
+ return;
52070
+ }
52071
+ this.localLastTime = null;
52072
+ const STIFFNESS = 150;
52073
+ const DAMPING = 28;
52074
+ const SNAP_PX = 0.5;
52075
+ const SNAP_SCALE = 0.0005;
52076
+ const SNAP_VEL = 1;
52077
+ const springStep = (pos, tgt, vel, dt) => {
52078
+ const acc = STIFFNESS * (tgt - pos) - DAMPING * vel;
52079
+ const newVel = vel + acc * dt;
52080
+ return [pos + newVel * dt, newVel];
52081
+ };
52082
+ const loop = () => {
52083
+ const tgt = this.localAnimationTarget;
52084
+ if (!tgt) {
52085
+ this.localAnimationId = null;
52086
+ return;
52087
+ }
52088
+ const now = performance.now();
52089
+ const dt = Math.min(this.localLastTime !== null ? now - this.localLastTime : 16, 50) / 1000;
52090
+ this.localLastTime = now;
52091
+ const v = this.localSpringVelocity;
52092
+ const [tx, vtx] = springStep(this.matrix.translateX, tgt.translateX, v.translateX, dt);
52093
+ const [ty, vty] = springStep(this.matrix.translateY, tgt.translateY, v.translateY, dt);
52094
+ const [sx, vsx] = springStep(this.matrix.scaleX, tgt.scaleX, v.scaleX, dt);
52095
+ const [sy, vsy] = springStep(this.matrix.scaleY, tgt.scaleY, v.scaleY, dt);
52096
+ this.matrix.translateX = tx;
52097
+ this.matrix.translateY = ty;
52098
+ this.matrix.scaleX = sx;
52099
+ this.matrix.scaleY = sy;
52100
+ this.localSpringVelocity = { translateX: vtx, translateY: vty, scaleX: vsx, scaleY: vsy };
52101
+ this.updateBoardPointer();
52039
52102
  this.subject.publish(this);
52040
- if (progress < 1) {
52041
- safeRequestAnimationFrame(animate);
52042
- } else {
52043
- this.isAnimating = false;
52103
+ 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;
52104
+ if (settled) {
52105
+ this.matrix.translateX = tgt.translateX;
52106
+ this.matrix.translateY = tgt.translateY;
52107
+ this.matrix.scaleX = tgt.scaleX;
52108
+ this.matrix.scaleY = tgt.scaleY;
52109
+ this.localSpringVelocity = { translateX: 0, translateY: 0, scaleX: 0, scaleY: 0 };
52110
+ this.localAnimationTarget = null;
52111
+ this.localAnimationId = null;
52112
+ this.localLastTime = null;
52113
+ this.updateBoardPointer();
52114
+ this.subject.publish(this);
52115
+ return;
52044
52116
  }
52117
+ this.localAnimationId = safeRequestAnimationFrame(loop) || null;
52045
52118
  };
52046
- safeRequestAnimationFrame(animate);
52047
- }
52048
- lerp(a2, b, time) {
52049
- return a2 + (b - a2) * time;
52050
- }
52051
- easeOutQuad(time) {
52052
- return time * (2 - time);
52119
+ this.localAnimationId = safeRequestAnimationFrame(loop) || null;
52053
52120
  }
52054
52121
  zoomToFit(rect, offsetInPercent = 10, duration = 480) {
52055
52122
  this.viewRectangle(rect, offsetInPercent, duration);
@@ -52058,11 +52125,13 @@ class Camera {
52058
52125
  return { x: 0, y: 0 };
52059
52126
  }
52060
52127
  translateTo(x, y) {
52128
+ this.cancelLocalAnimation();
52061
52129
  this.matrix.translate(x, y);
52062
52130
  this.updateBoardPointer();
52063
52131
  this.subject.publish(this);
52064
52132
  }
52065
52133
  translateBy(x, y) {
52134
+ this.cancelLocalAnimation();
52066
52135
  this.matrix.translate(x * this.matrix.scaleX, y * this.matrix.scaleY);
52067
52136
  this.updateBoardPointer();
52068
52137
  this.subject.publish(this);
@@ -58643,6 +58712,21 @@ function insertEventsFromOtherConnectionsIntoList(value, list6, board) {
58643
58712
  }
58644
58713
  const events = expandEvents(eventArray);
58645
58714
  board.selection.memoize();
58715
+ const focusedTextId = board.selection.memorySnapshot?.focus?.textToEdit;
58716
+ let localOpOriginalSelection = null;
58717
+ if (focusedTextId) {
58718
+ const allUnconfirmed = [...list6.getRecordsToSend(), ...list6.getNewRecords()];
58719
+ for (const rec of allUnconfirmed) {
58720
+ const op = rec.event.body.operation;
58721
+ if (op.class === "RichText" && op.method === "edit") {
58722
+ const items = Array.isArray(op.item) ? op.item : [op.item];
58723
+ if (items.includes(focusedTextId)) {
58724
+ localOpOriginalSelection = op.selection;
58725
+ break;
58726
+ }
58727
+ }
58728
+ }
58729
+ }
58646
58730
  const createdItems = [];
58647
58731
  const updatedText = [];
58648
58732
  const filter = (rec) => {
@@ -58652,6 +58736,10 @@ function insertEventsFromOtherConnectionsIntoList(value, list6, board) {
58652
58736
  createdItems.push(...creating);
58653
58737
  return false;
58654
58738
  }
58739
+ if (op.class === "RichText" && op.method === "edit") {
58740
+ const items = Array.isArray(op.item) ? op.item : [op.item];
58741
+ updatedText.push(...items);
58742
+ }
58655
58743
  return true;
58656
58744
  };
58657
58745
  list6.revertUnconfirmed(filter);
@@ -58670,7 +58758,28 @@ function insertEventsFromOtherConnectionsIntoList(value, list6, board) {
58670
58758
  return arr2.some((item) => lookup9.has(item));
58671
58759
  };
58672
58760
  const currSelection = board.selection.list().map((item) => item.getId());
58673
- if (hasAnyOverlap(currSelection, createdItems) || hasAnyOverlap(currSelection, updatedText)) {
58761
+ const memoizedCursor = board.selection.memorySnapshot?.focus?.selection;
58762
+ if (focusedTextId && localOpOriginalSelection && memoizedCursor && hasAnyOverlap(currSelection, updatedText)) {
58763
+ const rt = board.items.getById(focusedTextId)?.getRichText();
58764
+ if (rt) {
58765
+ const otAdjustedCursor = rt.editor.getSelection();
58766
+ if (otAdjustedCursor && memoizedCursor.anchor.path.length > 0 && memoizedCursor.focus.path.length > 0) {
58767
+ const deltaAnchor = otAdjustedCursor.anchor.offset - (localOpOriginalSelection?.anchor?.offset ?? 0);
58768
+ const deltaFocus = otAdjustedCursor.focus.offset - (localOpOriginalSelection?.focus?.offset ?? 0);
58769
+ const adjustedSelection = {
58770
+ anchor: {
58771
+ path: memoizedCursor.anchor.path,
58772
+ offset: memoizedCursor.anchor.offset + deltaAnchor
58773
+ },
58774
+ focus: {
58775
+ path: memoizedCursor.focus.path,
58776
+ offset: memoizedCursor.focus.offset + deltaFocus
58777
+ }
58778
+ };
58779
+ rt.editorTransforms.select(rt.editor.editor, adjustedSelection);
58780
+ }
58781
+ }
58782
+ } else if (hasAnyOverlap(currSelection, createdItems) || hasAnyOverlap(currSelection, updatedText)) {
58674
58783
  board.selection.applyMemoizedCaretOrRange();
58675
58784
  }
58676
58785
  }
@@ -58953,16 +59062,16 @@ function createEvents(board, connection, lastIndex) {
58953
59062
  }
58954
59063
  // src/Events/MessageRouter/createMessageRouter.ts
58955
59064
  function createMessageRouter() {
58956
- const handlers3 = new Map;
59065
+ const handlers2 = new Map;
58957
59066
  function addHandler(type, handler) {
58958
- handlers3.set(type, (message, board) => {
59067
+ handlers2.set(type, (message, board) => {
58959
59068
  if (message.type === type) {
58960
59069
  handler(message, board);
58961
59070
  }
58962
59071
  });
58963
59072
  }
58964
59073
  function handleMessage(message, board) {
58965
- const handler = handlers3.get(message.type);
59074
+ const handler = handlers2.get(message.type);
58966
59075
  if (handler) {
58967
59076
  handler(message, board);
58968
59077
  } else {
@@ -59741,7 +59850,7 @@ export {
59741
59850
  ExportQuality,
59742
59851
  Events2 as Events,
59743
59852
  EditorContainer,
59744
- DrawingContext,
59853
+ DrawingContext2 as DrawingContext,
59745
59854
  Drawing,
59746
59855
  Dice,
59747
59856
  DefaultTransformationData,