@haklex/rich-ext-whiteboard 0.69.2 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/{InteractiveScene-BqL3hsuU.js → InteractiveScene-Lz3yM1UW.js} +1 -1
  2. package/dist/{WhiteboardEditor-BVIGm8z0.js → WhiteboardEditor-BuF9_kou.js} +467 -128
  3. package/dist/{WhiteboardExpandShell-B9cCX4Yt.js → WhiteboardExpandShell-C0O3sSSt.js} +2 -2
  4. package/dist/editor/RichTextEditor.d.ts.map +1 -1
  5. package/dist/editor/StyleSheet.d.ts +0 -1
  6. package/dist/editor/StyleSheet.d.ts.map +1 -1
  7. package/dist/editor/WhiteboardCanvas.d.ts.map +1 -1
  8. package/dist/editor/binding-actions.d.ts +0 -1
  9. package/dist/editor/binding-actions.d.ts.map +1 -1
  10. package/dist/editor/layout.d.ts +4 -1
  11. package/dist/editor/layout.d.ts.map +1 -1
  12. package/dist/editor/linear-editor.d.ts +1 -3
  13. package/dist/editor/linear-editor.d.ts.map +1 -1
  14. package/dist/editor/overlay/SelectionOverlay.d.ts +0 -1
  15. package/dist/editor/overlay/SelectionOverlay.d.ts.map +1 -1
  16. package/dist/editor/selection-utils.d.ts +1 -3
  17. package/dist/editor/selection-utils.d.ts.map +1 -1
  18. package/dist/editor/shortcuts.d.ts +0 -2
  19. package/dist/editor/shortcuts.d.ts.map +1 -1
  20. package/dist/editor/text-actions.d.ts +0 -1
  21. package/dist/editor/text-actions.d.ts.map +1 -1
  22. package/dist/editor/tools/eraser.d.ts.map +1 -1
  23. package/dist/editor/tools/linear.d.ts +0 -2
  24. package/dist/editor/tools/linear.d.ts.map +1 -1
  25. package/dist/editor/tools/selection.d.ts +0 -2
  26. package/dist/editor/tools/selection.d.ts.map +1 -1
  27. package/dist/editor/tools/shape.d.ts +0 -7
  28. package/dist/editor/tools/shape.d.ts.map +1 -1
  29. package/dist/editor/tools/transform-gesture.d.ts +0 -2
  30. package/dist/editor/tools/transform-gesture.d.ts.map +1 -1
  31. package/dist/editor/transform.d.ts +0 -3
  32. package/dist/editor/transform.d.ts.map +1 -1
  33. package/dist/editor.mjs +32 -10
  34. package/dist/export/png.d.ts +0 -1
  35. package/dist/export/png.d.ts.map +1 -1
  36. package/dist/{export-CVvB15w6.js → export-D8KZqnab.js} +1 -1
  37. package/dist/index.mjs +3 -3
  38. package/dist/model/binding.d.ts +0 -2
  39. package/dist/model/binding.d.ts.map +1 -1
  40. package/dist/model/bounds.d.ts.map +1 -1
  41. package/dist/model/clipboard.d.ts +0 -1
  42. package/dist/model/clipboard.d.ts.map +1 -1
  43. package/dist/model/elbow.d.ts +0 -1
  44. package/dist/model/elbow.d.ts.map +1 -1
  45. package/dist/model/reconcile.d.ts.map +1 -1
  46. package/dist/model/richtext.d.ts +0 -2
  47. package/dist/model/richtext.d.ts.map +1 -1
  48. package/dist/model/shadow.d.ts +0 -1
  49. package/dist/model/shadow.d.ts.map +1 -1
  50. package/dist/model/skeleton.d.ts.map +1 -1
  51. package/dist/model/text-layout.d.ts +0 -1
  52. package/dist/model/text-layout.d.ts.map +1 -1
  53. package/dist/{reconcile-VoMFWmyk.js → reconcile-r3gVDm8B.js} +9 -2
  54. package/dist/scene/Scene.d.ts.map +1 -1
  55. package/dist/scene/elements.d.ts.map +1 -1
  56. package/dist/scene/freedraw.d.ts.map +1 -1
  57. package/dist/scene/rough.d.ts +4 -6
  58. package/dist/scene/rough.d.ts.map +1 -1
  59. package/dist/scene/scene-utils.d.ts +5 -0
  60. package/dist/scene/scene-utils.d.ts.map +1 -1
  61. package/dist/scene.mjs +4 -4
  62. package/dist/static.mjs +1 -1
  63. package/dist/{viewport-fit-CKwXs0RK.js → viewport-fit-C7OBkUJh.js} +174 -74
  64. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"rough.d.ts","sources":["../../src/scene/rough.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,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AE,YAAY,GAAG,QAAQ,CAEtF;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,QAAQ,CAExF;AAuBD,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACrB;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,aAAa,EAAE,CAMpE;AAqBD,wBAAgB,eAAe,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAOvD"}
@@ -7,4 +7,9 @@ export interface SceneBounds {
7
7
  }
8
8
  export declare function computeSceneBounds(input: ExcalidrawElement[]): SceneBounds;
9
9
  export declare const DARK_SCENE_FILTER = "invert(93%) hue-rotate(180deg)";
10
+ export interface LabelCut {
11
+ area: [number, number, number, number];
12
+ hole: [number, number, number, number];
13
+ }
14
+ export declare function labelCuts(elements: readonly ExcalidrawElement[]): Map<string, LabelCut>;
10
15
  //# sourceMappingURL=scene-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scene-utils.d.ts","sources":["../../src/scene/scene-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIjD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,WAAW,CAoB1E;AAED,eAAO,MAAM,iBAAiB,mCAAmC,CAAC"}
1
+ {"version":3,"file":"scene-utils.d.ts","sources":["../../src/scene/scene-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIjD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,WAAW,CAoB1E;AAED,eAAO,MAAM,iBAAiB,mCAAmC,CAAC;AAKlE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CA8BvF"}
package/dist/scene.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { B as isHandFontFamily, F as HAND_FONT_STACK, G as getElementBounds, I as MONO_FONT_STACK, L as SANS_FONT_STACK, R as WHITEBOARD_FONT_STACK, U as getCommonBounds, V as setFontFamilyStack, a as computeSceneBounds, f as restoreElements, i as DARK_SCENE_FILTER, l as resolveRichTextHeights, n as Scene, r as SceneContent, t as viewportFor, u as FontLoadError, z as fontFamilyToCss } from "./viewport-fit-CKwXs0RK.js";
2
- import { t as InteractiveScene } from "./InteractiveScene-BqL3hsuU.js";
3
- import { t as orderByIndex } from "./reconcile-VoMFWmyk.js";
4
- import { n as exportToSvg, r as collectFontFaces, t as exportToBlob } from "./export-CVvB15w6.js";
1
+ import { B as isHandFontFamily, F as HAND_FONT_STACK, H as getCommonBounds, I as MONO_FONT_STACK, L as SANS_FONT_STACK, R as WHITEBOARD_FONT_STACK, V as setFontFamilyStack, W as getElementBounds, a as computeSceneBounds, f as restoreElements, i as DARK_SCENE_FILTER, l as resolveRichTextHeights, n as Scene, r as SceneContent, t as viewportFor, u as FontLoadError, z as fontFamilyToCss } from "./viewport-fit-C7OBkUJh.js";
2
+ import { t as InteractiveScene } from "./InteractiveScene-Lz3yM1UW.js";
3
+ import { t as orderByIndex } from "./reconcile-r3gVDm8B.js";
4
+ import { n as exportToSvg, r as collectFontFaces, t as exportToBlob } from "./export-D8KZqnab.js";
5
5
  export { DARK_SCENE_FILTER, FontLoadError, HAND_FONT_STACK, InteractiveScene, MONO_FONT_STACK, SANS_FONT_STACK, Scene, SceneContent, WHITEBOARD_FONT_STACK, collectFontFaces, computeSceneBounds, exportToBlob, exportToSvg, fontFamilyToCss, getCommonBounds, getElementBounds, isHandFontFamily, orderByIndex, resolveRichTextHeights, restoreElements, setFontFamilyStack, viewportFor };
package/dist/static.mjs CHANGED
@@ -1 +1 @@
1
- export { n as $createWhiteboardNode, r as $isWhiteboardNode, b as EXCALIDRAW_BLOCK_TRANSFORMER, P as WHITEBOARD_NODE_KEY, h as WhiteboardConfigProvider, o as WhiteboardDisplayRenderer, o as WhiteboardRenderer, o as WhiteboardStaticRenderer, t as WhiteboardExpandShell, i as WhiteboardNode, a as WhiteboardSSRRenderer, g as useWhiteboardConfig, E as whiteboardFullscreenPopup } from "./WhiteboardExpandShell-B9cCX4Yt.js";
1
+ export { n as $createWhiteboardNode, r as $isWhiteboardNode, b as EXCALIDRAW_BLOCK_TRANSFORMER, P as WHITEBOARD_NODE_KEY, h as WhiteboardConfigProvider, o as WhiteboardDisplayRenderer, o as WhiteboardRenderer, o as WhiteboardStaticRenderer, t as WhiteboardExpandShell, i as WhiteboardNode, a as WhiteboardSSRRenderer, g as useWhiteboardConfig, E as whiteboardFullscreenPopup } from "./WhiteboardExpandShell-C0O3sSSt.js";
@@ -1,4 +1,4 @@
1
- import { createContext, memo, use, useId } from "react";
1
+ import { createContext, memo, use, useId, useMemo } from "react";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import { getStroke } from "perfect-freehand";
4
4
  import { RoughGenerator } from "roughjs/bin/generator";
@@ -68,16 +68,26 @@ function isLinear(el) {
68
68
  function pointsOf(el) {
69
69
  return el.points && el.points.length > 0 ? el.points : [[0, 0]];
70
70
  }
71
+ var linearLocalBoundsCache = /* @__PURE__ */ new WeakMap();
72
+ function localPointBounds(el) {
73
+ const cached = linearLocalBoundsCache.get(el);
74
+ if (cached) return cached;
75
+ const bounds = boundsOfPoints(pointsOf(el));
76
+ linearLocalBoundsCache.set(el, bounds);
77
+ return bounds;
78
+ }
71
79
  function getElementCenter(el) {
72
80
  if (isLinear(el)) {
73
- const [minX, minY, maxX, maxY] = boundsOfPoints(pointsOf(el));
81
+ const [minX, minY, maxX, maxY] = localPointBounds(el);
74
82
  return [el.x + (minX + maxX) / 2, el.y + (minY + maxY) / 2];
75
83
  }
76
84
  return [el.x + el.width / 2, el.y + el.height / 2];
77
85
  }
78
86
  function getLinearAbsolutePoints(el) {
87
+ const angle = angleOf(el);
88
+ if (!angle) return pointsOf(el).map(([px, py]) => [el.x + px, el.y + py]);
79
89
  const center = getElementCenter(el);
80
- return pointsOf(el).map(([px, py]) => rotatePoint([el.x + px, el.y + py], center, angleOf(el)));
90
+ return pointsOf(el).map(([px, py]) => rotatePoint([el.x + px, el.y + py], center, angle));
81
91
  }
82
92
  function getElementAbsoluteCorners(el) {
83
93
  if (isLinear(el)) return getLinearAbsolutePoints(el);
@@ -91,6 +101,25 @@ function getElementAbsoluteCorners(el) {
91
101
  ].map((p) => rotatePoint(p, center, angleOf(el)));
92
102
  }
93
103
  function getElementBounds(el) {
104
+ if (!angleOf(el)) {
105
+ if (isLinear(el)) {
106
+ const [minX, minY, maxX, maxY] = localPointBounds(el);
107
+ return [
108
+ el.x + minX,
109
+ el.y + minY,
110
+ el.x + maxX,
111
+ el.y + maxY
112
+ ];
113
+ }
114
+ const x1 = el.x + el.width;
115
+ const y1 = el.y + el.height;
116
+ return [
117
+ Math.min(el.x, x1),
118
+ Math.min(el.y, y1),
119
+ Math.max(el.x, x1),
120
+ Math.max(el.y, y1)
121
+ ];
122
+ }
94
123
  return boundsOfPoints(getElementAbsoluteCorners(el));
95
124
  }
96
125
  function getCommonBounds(elements) {
@@ -103,7 +132,9 @@ function getCommonBounds(elements) {
103
132
  return boundsOfPoints(elements.flatMap((el) => getElementAbsoluteCorners(el)));
104
133
  }
105
134
  function toLocalPoint(el, p) {
106
- const [x, y] = rotatePoint(p, getElementCenter(el), -angleOf(el));
135
+ const angle = angleOf(el);
136
+ if (!angle) return [p[0] - el.x, p[1] - el.y];
137
+ const [x, y] = rotatePoint(p, getElementCenter(el), -angle);
107
138
  return [x - el.x, y - el.y];
108
139
  }
109
140
  var isFilled = (el) => !!el.backgroundColor && el.backgroundColor !== "transparent";
@@ -113,6 +144,7 @@ function hitRectangle(w, h, [lx, ly], tol, filled) {
113
144
  return lx <= tol || lx >= w - tol || ly <= tol || ly >= h - tol;
114
145
  }
115
146
  function hitEllipse(w, h, [lx, ly], tol, filled) {
147
+ if (lx < -tol || lx > w + tol || ly < -tol || ly > h + tol) return false;
116
148
  const rx = w / 2;
117
149
  const ry = h / 2;
118
150
  if (rx <= 0 || ry <= 0) return false;
@@ -124,19 +156,15 @@ function hitEllipse(w, h, [lx, ly], tol, filled) {
124
156
  return edgeDistance <= tol;
125
157
  }
126
158
  function hitDiamond(w, h, p, tol, filled) {
159
+ if (p[0] < -tol || p[0] > w + tol || p[1] < -tol || p[1] > h + tol) return false;
160
+ if (filled && w > 0 && h > 0) {
161
+ if (Math.abs(p[0] - w / 2) / (w / 2) + Math.abs(p[1] - h / 2) / (h / 2) <= 1) return true;
162
+ }
127
163
  const top = [w / 2, 0];
128
164
  const right = [w, h / 2];
129
165
  const bottom = [w / 2, h];
130
166
  const left = [0, h / 2];
131
- if (filled && w > 0 && h > 0) {
132
- if (Math.abs(p[0] - w / 2) / (w / 2) + Math.abs(p[1] - h / 2) / (h / 2) <= 1) return true;
133
- }
134
- return [
135
- [top, right],
136
- [right, bottom],
137
- [bottom, left],
138
- [left, top]
139
- ].some(([a, b]) => distanceToSegment(p, a, b) <= tol);
167
+ return distanceToSegment(p, top, right) <= tol || distanceToSegment(p, right, bottom) <= tol || distanceToSegment(p, bottom, left) <= tol || distanceToSegment(p, left, top) <= tol;
140
168
  }
141
169
  function hitPolyline(points, p, tol) {
142
170
  if (points.length === 1) return distanceToSegment(p, points[0], points[0]) <= tol;
@@ -146,7 +174,22 @@ function hitPolyline(points, p, tol) {
146
174
  function hitTestElement(el, p, tolerance) {
147
175
  if (el.isDeleted) return false;
148
176
  const tol = tolerance + (Number.isFinite(el.strokeWidth) ? el.strokeWidth : 0) / 2;
149
- if (isLinear(el)) return hitPolyline(getLinearAbsolutePoints(el), p, tol);
177
+ if (isLinear(el)) {
178
+ const [minX, minY, maxX, maxY] = localPointBounds(el);
179
+ const angle = angleOf(el);
180
+ let lx;
181
+ let ly;
182
+ if (!angle) {
183
+ lx = p[0] - el.x;
184
+ ly = p[1] - el.y;
185
+ } else {
186
+ const [rx, ry] = rotatePoint(p, [el.x + (minX + maxX) / 2, el.y + (minY + maxY) / 2], -angle);
187
+ lx = rx - el.x;
188
+ ly = ry - el.y;
189
+ }
190
+ if (lx < minX - tol || lx > maxX + tol || ly < minY - tol || ly > maxY + tol) return false;
191
+ return hitPolyline(pointsOf(el), [lx, ly], tol);
192
+ }
150
193
  const local = toLocalPoint(el, p);
151
194
  const { width: w, height: h } = el;
152
195
  switch (el.type) {
@@ -163,9 +206,6 @@ function hitTestElement(el, p, tolerance) {
163
206
  default: return hitRectangle(w, h, local, tol, true);
164
207
  }
165
208
  }
166
- function elementsInBox(elements, box) {
167
- return elements.filter((el) => !el.isDeleted && boundsContain(box, getElementBounds(el)));
168
- }
169
209
  //#endregion
170
210
  //#region src/scene/fonts.ts
171
211
  var HAND_FONT_STACK = "\"LXGW WenKai Screen\", \"LXGW WenKai\", \"Excalifont\", \"Virgil\", \"Comic Sans MS\", \"Segoe Print\", \"Bradley Hand\", cursive";
@@ -1130,7 +1170,10 @@ function outlineToPath(points) {
1130
1170
  }
1131
1171
  return `${d}Z`;
1132
1172
  }
1173
+ var outlineCache = /* @__PURE__ */ new WeakMap();
1133
1174
  function freedrawOutline(el) {
1175
+ const cached = outlineCache.get(el);
1176
+ if (cached !== void 0) return cached;
1134
1177
  const pressures = el.pressures ?? [];
1135
1178
  const simulate = el.simulatePressure ?? pressures.length === 0;
1136
1179
  const input = el.points.map(([x, y], i) => [
@@ -1138,7 +1181,7 @@ function freedrawOutline(el) {
1138
1181
  y,
1139
1182
  simulate ? .5 : pressures[i] ?? .5
1140
1183
  ]);
1141
- return outlineToPath(getStroke(input, {
1184
+ const d = outlineToPath(getStroke(input, {
1142
1185
  simulatePressure: simulate,
1143
1186
  size: el.strokeWidth * 4.25,
1144
1187
  thinning: .6,
@@ -1147,6 +1190,8 @@ function freedrawOutline(el) {
1147
1190
  easing: (t) => Math.sin(t * Math.PI / 2),
1148
1191
  last: true
1149
1192
  }));
1193
+ outlineCache.set(el, d);
1194
+ return d;
1150
1195
  }
1151
1196
  //#endregion
1152
1197
  //#region src/scene/keys.ts
@@ -1406,6 +1451,12 @@ function gen() {
1406
1451
  if (!_gen) _gen = new RoughGenerator();
1407
1452
  return _gen;
1408
1453
  }
1454
+ var rectCache = /* @__PURE__ */ new WeakMap();
1455
+ var roundedRectCache = /* @__PURE__ */ new WeakMap();
1456
+ var ellipseCache = /* @__PURE__ */ new WeakMap();
1457
+ var diamondCache = /* @__PURE__ */ new WeakMap();
1458
+ var linearCache = /* @__PURE__ */ new WeakMap();
1459
+ var opSetsCache = /* @__PURE__ */ new WeakMap();
1409
1460
  function roughOptionsForElement(el, override) {
1410
1461
  const dashes = strokeDash(el.strokeStyle, el.strokeWidth);
1411
1462
  const opts = {
@@ -1432,23 +1483,57 @@ function strokeDash(style, w) {
1432
1483
  if (style === "dotted") return [1.5, 6 + w];
1433
1484
  }
1434
1485
  function rectangle(el, override) {
1435
- return gen().rectangle(0, 0, el.width, el.height, roughOptionsForElement(el, override));
1486
+ if (!override) {
1487
+ const cached = rectCache.get(el);
1488
+ if (cached) return cached;
1489
+ }
1490
+ const drawable = gen().rectangle(0, 0, el.width, el.height, roughOptionsForElement(el, override));
1491
+ if (!override) rectCache.set(el, drawable);
1492
+ return drawable;
1493
+ }
1494
+ function roundedRectangle(el, radius) {
1495
+ const cached = roundedRectCache.get(el);
1496
+ if (cached) return cached;
1497
+ const drawable = gen().path(roundedRectPath(el.width, el.height, radius), roughOptionsForElement(el));
1498
+ roundedRectCache.set(el, drawable);
1499
+ return drawable;
1436
1500
  }
1437
1501
  function ellipse(el, override) {
1438
- return gen().ellipse(el.width / 2, el.height / 2, el.width, el.height, roughOptionsForElement(el, override));
1502
+ if (!override) {
1503
+ const cached = ellipseCache.get(el);
1504
+ if (cached) return cached;
1505
+ }
1506
+ const drawable = gen().ellipse(el.width / 2, el.height / 2, el.width, el.height, roughOptionsForElement(el, override));
1507
+ if (!override) ellipseCache.set(el, drawable);
1508
+ return drawable;
1439
1509
  }
1440
1510
  function diamond(el, override) {
1511
+ if (!override) {
1512
+ const cached = diamondCache.get(el);
1513
+ if (cached) return cached;
1514
+ }
1441
1515
  const hw = el.width / 2;
1442
1516
  const hh = el.height / 2;
1443
- return gen().polygon([
1517
+ const drawable = gen().polygon([
1444
1518
  [hw, 0],
1445
1519
  [el.width, hh],
1446
1520
  [hw, el.height],
1447
1521
  [0, hh]
1448
1522
  ], roughOptionsForElement(el, override));
1523
+ if (!override) diamondCache.set(el, drawable);
1524
+ return drawable;
1449
1525
  }
1450
- function path(d, options) {
1451
- return gen().path(d, options);
1526
+ function linearDrawable(el, points) {
1527
+ const cached = linearCache.get(el);
1528
+ if (cached) return cached;
1529
+ const isCurved = el.roundness?.type === 2;
1530
+ const opts = roughOptionsForElement(el, {
1531
+ fill: void 0,
1532
+ fillStyle: void 0
1533
+ });
1534
+ const drawable = isCurved && points.length > 2 ? curve(points, opts) : linearPath(points, opts);
1535
+ linearCache.set(el, drawable);
1536
+ return drawable;
1452
1537
  }
1453
1538
  function linearPath(points, options) {
1454
1539
  return gen().linearPath(points, options);
@@ -1470,10 +1555,14 @@ function opsToPath(ops) {
1470
1555
  return d.trim();
1471
1556
  }
1472
1557
  function drawableToOpSets(drawable) {
1473
- return drawable.sets.map((set) => ({
1558
+ const cached = opSetsCache.get(drawable);
1559
+ if (cached) return cached;
1560
+ const sets = drawable.sets.map((set) => ({
1474
1561
  type: set.type,
1475
1562
  d: opsToPath(set.ops)
1476
1563
  }));
1564
+ opSetsCache.set(drawable, sets);
1565
+ return sets;
1477
1566
  }
1478
1567
  function roundedRectPath(width, height, radius) {
1479
1568
  const r = Math.max(0, Math.min(radius, width / 2, height / 2));
@@ -1522,7 +1611,7 @@ var SvgRender = ({ el }) => {
1522
1611
  };
1523
1612
  //#endregion
1524
1613
  //#region src/scene/elements.tsx
1525
- var ElementContent = ({ el, files }) => {
1614
+ var ElementContent = memo(({ el, files }) => {
1526
1615
  switch (el.type) {
1527
1616
  case "rectangle": return /* @__PURE__ */ jsx(RectangleRender, { el });
1528
1617
  case "ellipse": return /* @__PURE__ */ jsx(EllipseRender, { el });
@@ -1543,7 +1632,8 @@ var ElementContent = ({ el, files }) => {
1543
1632
  case "iframe": return /* @__PURE__ */ jsx(EmbedPlaceholder, { el });
1544
1633
  default: return null;
1545
1634
  }
1546
- };
1635
+ });
1636
+ ElementContent.displayName = "ElementContent";
1547
1637
  var EVENODD_SHAPES = /* @__PURE__ */ new Set(["curve", "polygon"]);
1548
1638
  var PathSet = ({ drawable, fillColor, strokeColor, strokeWidth }) => {
1549
1639
  const opSets = drawableToOpSets(drawable);
@@ -1575,8 +1665,7 @@ var PathSet = ({ drawable, fillColor, strokeColor, strokeWidth }) => {
1575
1665
  };
1576
1666
  var RectangleRender = ({ el }) => {
1577
1667
  const radius = getCornerRadius(el);
1578
- const opts = roughOptionsForElement(el);
1579
- const drawable = radius > 0 ? path(roundedRectPath(el.width, el.height, radius), opts) : rectangle(el);
1668
+ const drawable = radius > 0 ? roundedRectangle(el, radius) : rectangle(el);
1580
1669
  return /* @__PURE__ */ jsx(PathSet, {
1581
1670
  drawable,
1582
1671
  fillColor: el.backgroundColor !== "transparent" ? el.backgroundColor : void 0,
@@ -1679,12 +1768,7 @@ var Arrowhead = ({ angle, color, shape, strokeWidth, x, y }) => {
1679
1768
  };
1680
1769
  var LinearRender = ({ el }) => {
1681
1770
  const points = el.points && el.points.length > 0 ? el.points : [[0, 0], [el.width, el.height]];
1682
- const isCurved = el.roundness?.type === 2;
1683
- const opts = roughOptionsForElement(el, {
1684
- fill: void 0,
1685
- fillStyle: void 0
1686
- });
1687
- const drawable = isCurved && points.length > 2 ? curve(points, opts) : linearPath(points, opts);
1771
+ const drawable = linearDrawable(el, points);
1688
1772
  const startHead = el.startArrowhead;
1689
1773
  const endHead = el.type === "arrow" ? el.endArrowhead ?? "arrow" : el.endArrowhead;
1690
1774
  const startInfo = startHead ? arrowheadAngle(points, "start") : null;
@@ -1877,36 +1961,6 @@ function computeSceneBounds(input) {
1877
1961
  };
1878
1962
  }
1879
1963
  var DARK_SCENE_FILTER = "invert(93%) hue-rotate(180deg)";
1880
- //#endregion
1881
- //#region src/scene/shadow.tsx
1882
- var ShadowFilter = ({ dark, id }) => /* @__PURE__ */ jsx("filter", {
1883
- height: "160%",
1884
- id,
1885
- width: "140%",
1886
- x: "-20%",
1887
- y: "-20%",
1888
- children: /* @__PURE__ */ jsx("feDropShadow", {
1889
- dx: "0",
1890
- dy: "3",
1891
- floodColor: dark ? "#fff" : "#000",
1892
- floodOpacity: "0.14",
1893
- stdDeviation: "4"
1894
- })
1895
- });
1896
- //#endregion
1897
- //#region src/scene/Scene.tsx
1898
- var CounterInvertFilter = ({ id }) => /* @__PURE__ */ jsxs("filter", {
1899
- colorInterpolationFilters: "sRGB",
1900
- id,
1901
- children: [/* @__PURE__ */ jsx("feColorMatrix", {
1902
- type: "hueRotate",
1903
- values: "180"
1904
- }), /* @__PURE__ */ jsx("feColorMatrix", {
1905
- type: "matrix",
1906
- values: "-1.16279 0 0 0 1.081395 0 -1.16279 0 0 1.081395 0 0 -1.16279 0 1.081395 0 0 0 1 0"
1907
- })]
1908
- });
1909
- var isFrame = (el) => el.type === "frame" || el.type === "magicframe";
1910
1964
  var LABEL_PAD = 4;
1911
1965
  var LINE_PAD = 64;
1912
1966
  function labelCuts(elements) {
@@ -1946,22 +2000,58 @@ function labelCuts(elements) {
1946
2000
  }
1947
2001
  return cuts;
1948
2002
  }
2003
+ //#endregion
2004
+ //#region src/scene/shadow.tsx
2005
+ var ShadowFilter = ({ dark, id }) => /* @__PURE__ */ jsx("filter", {
2006
+ height: "160%",
2007
+ id,
2008
+ width: "140%",
2009
+ x: "-20%",
2010
+ y: "-20%",
2011
+ children: /* @__PURE__ */ jsx("feDropShadow", {
2012
+ dx: "0",
2013
+ dy: "3",
2014
+ floodColor: dark ? "#fff" : "#000",
2015
+ floodOpacity: "0.14",
2016
+ stdDeviation: "4"
2017
+ })
2018
+ });
2019
+ //#endregion
2020
+ //#region src/scene/Scene.tsx
2021
+ var CounterInvertFilter = ({ id }) => /* @__PURE__ */ jsxs("filter", {
2022
+ colorInterpolationFilters: "sRGB",
2023
+ id,
2024
+ children: [/* @__PURE__ */ jsx("feColorMatrix", {
2025
+ type: "hueRotate",
2026
+ values: "180"
2027
+ }), /* @__PURE__ */ jsx("feColorMatrix", {
2028
+ type: "matrix",
2029
+ values: "-1.16279 0 0 0 1.081395 0 -1.16279 0 0 1.081395 0 0 -1.16279 0 1.081395 0 0 0 1 0"
2030
+ })]
2031
+ });
2032
+ var isFrame = (el) => el.type === "frame" || el.type === "magicframe";
1949
2033
  var SceneContent = memo(({ dark = false, elementProps, files, handFontOverride, hiddenIds, scene }) => {
1950
- const elements = resolveRichTextHeights(scene.elements.filter((el) => !el.isDeleted));
2034
+ const elements = useMemo(() => resolveRichTextHeights(scene.elements.filter((el) => !el.isDeleted)), [scene.elements]);
1951
2035
  const inheritedHandFont = use(SceneHandFontContext);
1952
2036
  const handFont = handFontOverride ?? inheritedHandFont;
1953
2037
  const uid = useId().replaceAll(/[^\w-]/g, "");
1954
2038
  const filterId = `rich-excalidraw-counter-invert-${uid}`;
1955
- const frames = new Map(elements.filter(isFrame).map((f) => [f.id, f]));
1956
- const usedFrames = new Set(elements.map((el) => el.frameId).filter((id) => !!id && frames.has(id)));
2039
+ const darkContextValue = useMemo(() => dark ? { filterId } : null, [dark, filterId]);
2040
+ const { anyShadow, cuts, frames, usedFrames } = useMemo(() => {
2041
+ const nextFrames = new Map(elements.filter(isFrame).map((f) => [f.id, f]));
2042
+ return {
2043
+ frames: nextFrames,
2044
+ usedFrames: new Set(elements.map((el) => el.frameId).filter((id) => !!id && nextFrames.has(id))),
2045
+ anyShadow: elements.some(hasShadow),
2046
+ cuts: labelCuts(elements)
2047
+ };
2048
+ }, [elements]);
1957
2049
  const clipId = (frameId) => `rich-excalidraw-frame-${uid}-${frameId.replaceAll(/[^\w-]/g, "")}`;
1958
2050
  const shadowId = `rich-excalidraw-shadow-${uid}`;
1959
- const anyShadow = elements.some(hasShadow);
1960
- const cuts = labelCuts(elements);
1961
2051
  const cutId = (id) => `rich-excalidraw-label-${uid}-${id.replaceAll(/[^\w-]/g, "")}`;
1962
2052
  const hasDefs = dark || usedFrames.size > 0 || anyShadow || cuts.size > 0;
1963
2053
  return /* @__PURE__ */ jsx(SceneDarkContext, {
1964
- value: dark ? { filterId } : null,
2054
+ value: darkContextValue,
1965
2055
  children: /* @__PURE__ */ jsxs(SceneHandFontContext, {
1966
2056
  value: handFont,
1967
2057
  children: [hasDefs && /* @__PURE__ */ jsxs("defs", { children: [
@@ -2008,7 +2098,7 @@ var SceneContent = memo(({ dark = false, elementProps, files, handFontOverride,
2008
2098
  const drawn = /* @__PURE__ */ jsx(ElementGroup, {
2009
2099
  el,
2010
2100
  extra: elementProps?.(el),
2011
- files
2101
+ files: el.type === "image" ? files : void 0
2012
2102
  }, el.id);
2013
2103
  const element = cuts.has(el.id) ? /* @__PURE__ */ jsx("g", {
2014
2104
  mask: `url(#${cutId(el.id)})`,
@@ -2052,7 +2142,16 @@ var Scene = ({ className, files, handFontOverride, scene, style, theme = "light"
2052
2142
  })
2053
2143
  });
2054
2144
  };
2055
- var ElementGroup = ({ el, extra, files }) => {
2145
+ function shallowEqualRecord(a, b) {
2146
+ if (a === b) return true;
2147
+ if (!a || !b) return false;
2148
+ const keysA = Object.keys(a);
2149
+ const keysB = Object.keys(b);
2150
+ if (keysA.length !== keysB.length) return false;
2151
+ for (const k of keysA) if (!Object.is(a[k], b[k])) return false;
2152
+ return true;
2153
+ }
2154
+ var ElementGroup = memo(({ el, extra, files }) => {
2056
2155
  const angleDeg = angleOf(el) * 180 / Math.PI;
2057
2156
  const [cx, cy] = getElementCenter(el);
2058
2157
  const transform = `translate(${el.x} ${el.y}) rotate(${angleDeg} ${cx - el.x} ${cy - el.y})`;
@@ -2069,7 +2168,8 @@ var ElementGroup = ({ el, extra, files }) => {
2069
2168
  files
2070
2169
  })
2071
2170
  });
2072
- };
2171
+ }, (prev, next) => prev.el === next.el && prev.files === next.files && shallowEqualRecord(prev.extra, next.extra));
2172
+ ElementGroup.displayName = "ElementGroup";
2073
2173
  //#endregion
2074
2174
  //#region src/model/viewport-fit.ts
2075
2175
  function viewportFor(bounds, size, { insets = {}, maxZoom = 30, minZoom = .1, padding = 0, zoomFactor = 1 } = {}) {
@@ -2089,4 +2189,4 @@ function viewportFor(bounds, size, { insets = {}, maxZoom = 30, minZoom = .1, pa
2089
2189
  };
2090
2190
  }
2091
2191
  //#endregion
2092
- export { boundsIntersect as $, contentRoot as A, isHandFontFamily as B, newFrameElement as C, newRichTextElement as D, newLinearElement as E, HAND_FONT_STACK as F, getElementBounds as G, elementsInBox as H, MONO_FONT_STACK as I, hitTestElement as J, getElementCenter as K, SANS_FONT_STACK as L, randomId as M, randomInteger as N, newSvgElement as O, DEFAULT_STYLE as P, boundsContain as Q, WHITEBOARD_FONT_STACK as R, newElement as S, newImageElement as T, getCommonBounds as U, setFontFamilyStack as V, getElementAbsoluteCorners as W, toLocalPoint as X, isLinear as Y, angleOf as Z, parseSvgSize as _, computeSceneBounds as a, syncIndices as b, SceneHandFontContext as c, normalizeElement as d, boundsOfPoints as et, restoreElements as f, isSvgSource as g, refreshTextDimensions as h, DARK_SCENE_FILTER as i, richTextPlainText as j, newTextElement as k, resolveRichTextHeights as l, layoutBoundText as m, Scene as n, normalizeBox as nt, RICHTEXT_BASE_STYLE as o, _defineProperty as p, getLinearAbsolutePoints as q, SceneContent as r, rotatePoint as rt, SceneExportContext as s, viewportFor as t, distanceToSegment as tt, FontLoadError as u, bumpVersion as v, newFreedrawElement as w, getLineHeight as x, isValidIndex as y, fontFamilyToCss as z };
2192
+ export { boundsOfPoints as $, contentRoot as A, isHandFontFamily as B, newFrameElement as C, newRichTextElement as D, newLinearElement as E, HAND_FONT_STACK as F, getElementCenter as G, getCommonBounds as H, MONO_FONT_STACK as I, isLinear as J, getLinearAbsolutePoints as K, SANS_FONT_STACK as L, randomId as M, randomInteger as N, newSvgElement as O, DEFAULT_STYLE as P, boundsIntersect as Q, WHITEBOARD_FONT_STACK as R, newElement as S, newImageElement as T, getElementAbsoluteCorners as U, setFontFamilyStack as V, getElementBounds as W, angleOf as X, toLocalPoint as Y, boundsContain as Z, parseSvgSize as _, computeSceneBounds as a, syncIndices as b, SceneHandFontContext as c, normalizeElement as d, distanceToSegment as et, restoreElements as f, isSvgSource as g, refreshTextDimensions as h, DARK_SCENE_FILTER as i, richTextPlainText as j, newTextElement as k, resolveRichTextHeights as l, layoutBoundText as m, Scene as n, rotatePoint as nt, RICHTEXT_BASE_STYLE as o, _defineProperty as p, hitTestElement as q, SceneContent as r, SceneExportContext as s, viewportFor as t, normalizeBox as tt, FontLoadError as u, bumpVersion as v, newFreedrawElement as w, getLineHeight as x, isValidIndex as y, fontFamilyToCss as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-ext-whiteboard",
3
- "version": "0.69.2",
3
+ "version": "0.70.0",
4
4
  "description": "Hand-drawn whiteboard extension for Excalidraw-format scenes",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@haklex/rich-headless": "0.69.2",
36
+ "@haklex/rich-headless": "0.70.0",
37
37
  "jsondiffpatch": "^0.7.6",
38
38
  "perfect-freehand": "^1.2.3",
39
39
  "roughjs": "^4.6.6"
@@ -55,9 +55,9 @@
55
55
  "vite": "^8.3.5"
56
56
  },
57
57
  "peerDependencies": {
58
- "@haklex/rich-editor": "^0.69.2",
59
- "@haklex/rich-editor-ui": "^0.69.2",
60
- "@haklex/rich-style-token": "^0.69.2",
58
+ "@haklex/rich-editor": "^0.70.0",
59
+ "@haklex/rich-editor-ui": "^0.70.0",
60
+ "@haklex/rich-style-token": "^0.70.0",
61
61
  "@lexical/link": "^0.53.0",
62
62
  "@lexical/list": "^0.53.0",
63
63
  "@lexical/react": "^0.53.0",