@excalidraw/math 0.18.0-a9ca16e → 0.18.0-ab0255f

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 (175) hide show
  1. package/dist/dev/index.js +297 -99
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +1 -1
  4. package/dist/types/common/src/colors.d.ts +17 -1
  5. package/dist/types/common/src/constants.d.ts +12 -7
  6. package/dist/types/common/src/keys.d.ts +2 -0
  7. package/dist/types/common/src/points.d.ts +1 -1
  8. package/dist/types/common/src/utils.d.ts +1 -43
  9. package/dist/types/element/src/Scene.d.ts +6 -4
  10. package/dist/types/element/src/align.d.ts +2 -2
  11. package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
  12. package/dist/types/element/src/arrows/focus.d.ts +5 -2
  13. package/dist/types/element/src/binding.d.ts +17 -8
  14. package/dist/types/element/src/bounds.d.ts +22 -7
  15. package/dist/types/element/src/bucketFill.d.ts +110 -0
  16. package/dist/types/element/src/collision.d.ts +1 -1
  17. package/dist/types/element/src/comparisons.d.ts +5 -4
  18. package/dist/types/element/src/convertToShape.d.ts +23 -0
  19. package/dist/types/element/src/distribute.d.ts +2 -2
  20. package/dist/types/element/src/dragElements.d.ts +27 -0
  21. package/dist/types/element/src/duplicate.d.ts +4 -3
  22. package/dist/types/element/src/embeddable.d.ts +2 -2
  23. package/dist/types/element/src/flowchart.d.ts +7 -7
  24. package/dist/types/element/src/fractionalIndex.d.ts +2 -2
  25. package/dist/types/element/src/frame.d.ts +9 -8
  26. package/dist/types/element/src/groups.d.ts +9 -9
  27. package/dist/types/element/src/index.d.ts +4 -1
  28. package/dist/types/element/src/linearElementEditor.d.ts +17 -10
  29. package/dist/types/element/src/newElement.d.ts +14 -0
  30. package/dist/types/element/src/renderElement.d.ts +0 -3
  31. package/dist/types/element/src/resizeElements.d.ts +2 -2
  32. package/dist/types/element/src/selection.d.ts +6 -6
  33. package/dist/types/element/src/shape.d.ts +13 -1
  34. package/dist/types/element/src/textElement.d.ts +12 -9
  35. package/dist/types/element/src/transform.d.ts +2 -2
  36. package/dist/types/element/src/typeChecks.d.ts +26 -25
  37. package/dist/types/element/src/types.d.ts +8 -1
  38. package/dist/types/element/src/utils.d.ts +1 -1
  39. package/dist/types/element/src/zindex.d.ts +2 -2
  40. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +30 -12
  41. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  42. package/dist/types/excalidraw/actions/actionBoundText.d.ts +20 -8
  43. package/dist/types/excalidraw/actions/actionCanvas.d.ts +132 -926
  44. package/dist/types/excalidraw/actions/actionClipboard.d.ts +20 -8
  45. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +10 -4
  46. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +32 -13
  47. package/dist/types/excalidraw/actions/{actionEmbeddable.d.ts → actionDeselect.d.ts} +24 -33
  48. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
  49. package/dist/types/excalidraw/actions/actionElementLink.d.ts +10 -4
  50. package/dist/types/excalidraw/actions/actionElementLock.d.ts +21 -9
  51. package/dist/types/excalidraw/actions/actionExport.d.ts +22 -10
  52. package/dist/types/excalidraw/actions/actionFrame.d.ts +42 -196
  53. package/dist/types/excalidraw/actions/actionGroup.d.ts +35 -23
  54. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +14 -6
  55. package/dist/types/excalidraw/actions/actionLink.d.ts +11 -5
  56. package/dist/types/excalidraw/actions/actionMenu.d.ts +10 -4
  57. package/dist/types/excalidraw/actions/actionProperties.d.ts +50 -26
  58. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +15 -9
  59. package/dist/types/excalidraw/actions/actionStyles.d.ts +10 -4
  60. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
  61. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +11 -5
  62. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +14 -9
  63. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +11 -5
  64. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +11 -5
  65. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +14 -9
  66. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
  67. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +11 -5
  68. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +12 -6
  69. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +11 -5
  70. package/dist/types/excalidraw/actions/index.d.ts +2 -2
  71. package/dist/types/excalidraw/actions/manager.d.ts +1 -0
  72. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  73. package/dist/types/excalidraw/actions/types.d.ts +8 -4
  74. package/dist/types/excalidraw/{animated-trail.d.ts → animatedTrail.d.ts} +4 -3
  75. package/dist/types/excalidraw/appState.d.ts +7 -5
  76. package/dist/types/excalidraw/components/Actions.d.ts +17 -12
  77. package/dist/types/excalidraw/components/ActiveConfirmDialog.d.ts +1 -1
  78. package/dist/types/excalidraw/components/App.arrowText.d.ts +72 -0
  79. package/dist/types/excalidraw/components/App.bucketFill.d.ts +34 -0
  80. package/dist/types/excalidraw/components/App.cursor.d.ts +31 -0
  81. package/dist/types/excalidraw/components/App.d.ts +355 -65
  82. package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
  83. package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
  84. package/dist/types/excalidraw/components/App.viewport.d.ts +73 -0
  85. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +5 -3
  86. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +1 -0
  87. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +6 -1
  88. package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +1 -1
  89. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +2 -1
  90. package/dist/types/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -2
  91. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
  92. package/dist/types/excalidraw/components/CursorHint.d.ts +46 -0
  93. package/dist/types/excalidraw/components/EyeDropper.d.ts +1 -1
  94. package/dist/types/excalidraw/components/{ToolButton.d.ts → IconButton.d.ts} +16 -19
  95. package/dist/types/excalidraw/components/Island.d.ts +7 -0
  96. package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
  97. package/dist/types/excalidraw/components/LayerUI.d.ts +4 -2
  98. package/dist/types/excalidraw/components/LibraryMenu.d.ts +1 -1
  99. package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
  100. package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
  101. package/dist/types/excalidraw/components/MobileMenu.d.ts +4 -4
  102. package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
  103. package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirmState.d.ts +1 -1
  104. package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
  105. package/dist/types/excalidraw/components/Popover.d.ts +1 -3
  106. package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
  107. package/dist/types/excalidraw/components/SVGLayer.d.ts +1 -1
  108. package/dist/types/excalidraw/components/SearchMenu.d.ts +1 -1
  109. package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +1 -1
  110. package/dist/types/excalidraw/components/Stats/Angle.d.ts +2 -2
  111. package/dist/types/excalidraw/components/Stats/Dimension.d.ts +2 -2
  112. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +2 -2
  113. package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +2 -2
  114. package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +2 -2
  115. package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +2 -2
  116. package/dist/types/excalidraw/components/Stats/Position.d.ts +3 -3
  117. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
  118. package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +4 -4
  119. package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +3 -3
  120. package/dist/types/excalidraw/components/ToolPopover.d.ts +3 -6
  121. package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
  122. package/dist/types/excalidraw/components/Tools.d.ts +146 -0
  123. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +3 -1
  124. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +1 -0
  125. package/dist/types/excalidraw/components/canvases/StaticCanvas.d.ts +1 -1
  126. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -1
  127. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  128. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +2 -2
  129. package/dist/types/excalidraw/components/icons.d.ts +3 -1
  130. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +8 -4
  131. package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
  132. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
  133. package/dist/types/excalidraw/data/blob.d.ts +24 -12
  134. package/dist/types/excalidraw/data/index.d.ts +4 -4
  135. package/dist/types/excalidraw/data/json.d.ts +18 -12
  136. package/dist/types/excalidraw/data/library.d.ts +1 -1
  137. package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
  138. package/dist/types/excalidraw/eraser/index.d.ts +2 -3
  139. package/dist/types/excalidraw/hooks/useAppStateValue.d.ts +29 -0
  140. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  141. package/dist/types/excalidraw/{laser-trails.d.ts → laserTrails.d.ts} +5 -7
  142. package/dist/types/excalidraw/lasso/index.d.ts +2 -3
  143. package/dist/types/excalidraw/renderer/animation.d.ts +5 -1
  144. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -3
  145. package/dist/types/excalidraw/scene/Renderer.d.ts +426 -19
  146. package/dist/types/excalidraw/scene/export.d.ts +3 -3
  147. package/dist/types/excalidraw/scene/index.d.ts +2 -2
  148. package/dist/types/excalidraw/scene/types.d.ts +4 -3
  149. package/dist/types/excalidraw/snapping.d.ts +7 -7
  150. package/dist/types/excalidraw/types.d.ts +368 -19
  151. package/dist/types/excalidraw/viewport.d.ts +272 -0
  152. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +2 -3
  153. package/dist/types/fractional-indexing/src/index.d.ts +29 -0
  154. package/dist/types/laser-pointer/src/index.d.ts +2 -0
  155. package/dist/types/laser-pointer/src/math.d.ts +16 -0
  156. package/dist/types/laser-pointer/src/simplify.d.ts +2 -0
  157. package/dist/types/laser-pointer/src/state.d.ts +36 -0
  158. package/dist/types/math/src/constants.d.ts +0 -1
  159. package/dist/types/math/src/curve.d.ts +4 -1
  160. package/dist/types/math/src/index.d.ts +1 -0
  161. package/dist/types/math/src/pca.d.ts +79 -0
  162. package/dist/types/math/src/point.d.ts +1 -0
  163. package/dist/types/math/src/polygon.d.ts +25 -1
  164. package/dist/types/utils/src/export.d.ts +3 -3
  165. package/dist/types/utils/src/index.d.ts +1 -2
  166. package/package.json +2 -2
  167. package/dist/types/excalidraw/animation-frame-handler.d.ts +0 -16
  168. package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
  169. package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -10
  170. package/dist/types/excalidraw/components/shapes.d.ts +0 -263
  171. package/dist/types/excalidraw/cursor.d.ts +0 -5
  172. package/dist/types/excalidraw/scene/scroll.d.ts +0 -18
  173. package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
  174. package/dist/types/utils/src/bbox.d.ts +0 -9
  175. package/dist/types/utils/src/withinBounds.d.ts +0 -19
package/dist/dev/index.js CHANGED
@@ -152,6 +152,9 @@ var pointScaleFromOrigin = (p, mid, multiplier) => pointTranslate(mid, vectorSca
152
152
  var isPointWithinBounds = (p, q, r) => {
153
153
  return q[0] <= Math.max(p[0], r[0]) && q[0] >= Math.min(p[0], r[0]) && q[1] <= Math.max(p[1], r[1]) && q[1] >= Math.min(p[1], r[1]);
154
154
  };
155
+ var isValidPoint = (point) => {
156
+ return Array.isArray(point) && point.length === 2 && isFiniteNumber(point[0]) && isFiniteNumber(point[1]);
157
+ };
155
158
 
156
159
  // src/constants.ts
157
160
  var LegendreGaussN24TValues = [
@@ -259,8 +262,15 @@ var initial_guesses = [
259
262
  [0.2, 0],
260
263
  [0.8, 0]
261
264
  ];
262
- var calculate = ([t0, s0], l, c) => {
263
- const solution = solveWithAnalyticalJacobian(c, l, t0, s0, 0.01, 4);
265
+ var calculate = ([t0, s0], l, c, tolerance = 0.01, iterLimit = 4) => {
266
+ const solution = solveWithAnalyticalJacobian(
267
+ c,
268
+ l,
269
+ t0,
270
+ s0,
271
+ tolerance,
272
+ iterLimit
273
+ );
264
274
  if (!solution) {
265
275
  return null;
266
276
  }
@@ -270,16 +280,34 @@ var calculate = ([t0, s0], l, c) => {
270
280
  }
271
281
  return bezierEquation(c, t);
272
282
  };
273
- function curveIntersectLineSegment(c, l) {
274
- let solution = calculate(initial_guesses[0], l, c);
283
+ function curveIntersectLineSegment(c, l, opts) {
284
+ let solution = calculate(
285
+ initial_guesses[0],
286
+ l,
287
+ c,
288
+ opts?.tolerance,
289
+ opts?.iterLimit
290
+ );
275
291
  if (solution) {
276
292
  return [solution];
277
293
  }
278
- solution = calculate(initial_guesses[1], l, c);
294
+ solution = calculate(
295
+ initial_guesses[1],
296
+ l,
297
+ c,
298
+ opts?.tolerance,
299
+ opts?.iterLimit
300
+ );
279
301
  if (solution) {
280
302
  return [solution];
281
303
  }
282
- solution = calculate(initial_guesses[2], l, c);
304
+ solution = calculate(
305
+ initial_guesses[2],
306
+ l,
307
+ c,
308
+ opts?.tolerance,
309
+ opts?.iterLimit
310
+ );
283
311
  if (solution) {
284
312
  return [solution];
285
313
  }
@@ -316,7 +344,7 @@ function curveClosestPoint(c, p, tolerance = 1e-3) {
316
344
  t1,
317
345
  (t) => pointDistance(p, bezierEquation(c, t))
318
346
  );
319
- if (!solution) {
347
+ if (solution == null) {
320
348
  return null;
321
349
  }
322
350
  return bezierEquation(c, solution);
@@ -324,7 +352,7 @@ function curveClosestPoint(c, p, tolerance = 1e-3) {
324
352
  function curvePointDistance(c, p) {
325
353
  const closest = curveClosestPoint(c, p);
326
354
  if (!closest) {
327
- return 0;
355
+ return Infinity;
328
356
  }
329
357
  return pointDistance(p, closest);
330
358
  }
@@ -610,11 +638,257 @@ function linesIntersectAt(a, b) {
610
638
  return null;
611
639
  }
612
640
 
641
+ // src/pca.ts
642
+ function centroid(points) {
643
+ let cx = 0;
644
+ let cy = 0;
645
+ for (const [x, y] of points) {
646
+ cx += x;
647
+ cy += y;
648
+ }
649
+ return pointFrom(cx / points.length, cy / points.length);
650
+ }
651
+ function principalAxes(points) {
652
+ if (points.length < 2) {
653
+ console.error("Degenerate point set: at least two points are required");
654
+ }
655
+ const c = centroid(points);
656
+ let m20 = 0;
657
+ let m02 = 0;
658
+ let m11 = 0;
659
+ for (const [x, y] of points) {
660
+ const dx = x - c[0];
661
+ const dy = y - c[1];
662
+ m20 += dx * dx;
663
+ m02 += dy * dy;
664
+ m11 += dx * dy;
665
+ }
666
+ m20 /= points.length;
667
+ m02 /= points.length;
668
+ m11 /= points.length;
669
+ const trace = m20 + m02;
670
+ const diff = Math.hypot(m20 - m02, 2 * m11);
671
+ const majorVariance = (trace + diff) / 2;
672
+ const minorVariance = (trace - diff) / 2;
673
+ let major;
674
+ if (Math.abs(m11) > Number.EPSILON) {
675
+ major = vectorNormalize(vector(majorVariance - m02, m11));
676
+ } else {
677
+ major = m20 >= m02 ? vector(1, 0) : vector(0, 1);
678
+ }
679
+ return {
680
+ centroid: c,
681
+ major,
682
+ minor: vectorNormal(major),
683
+ majorVariance,
684
+ minorVariance
685
+ };
686
+ }
687
+ function principalCoords(points, axes, scale = 1) {
688
+ const { centroid: c, major, minor } = axes;
689
+ return points.map(([x, y]) => {
690
+ const dx = x - c[0];
691
+ const dy = y - c[1];
692
+ return [
693
+ (dx * major[0] + dy * major[1]) * scale,
694
+ (dx * minor[0] + dy * minor[1]) * scale
695
+ ];
696
+ });
697
+ }
698
+ function orientPrincipalAxes(points, axes) {
699
+ const u = principalCoords(points, axes).map(([uu]) => uu);
700
+ if (skewness(u) <= 0) {
701
+ return axes;
702
+ }
703
+ const major = vectorScale(axes.major, -1);
704
+ return { ...axes, major, minor: vectorNormal(major) };
705
+ }
706
+ function elongation(axes) {
707
+ return axes.majorVariance > 0 ? axes.minorVariance / axes.majorVariance : 1;
708
+ }
709
+ function standardizedMoment(values, order) {
710
+ const n = values.length;
711
+ let mean = 0;
712
+ for (const v of values) {
713
+ mean += v;
714
+ }
715
+ mean /= n;
716
+ let variance = 0;
717
+ let moment = 0;
718
+ for (const v of values) {
719
+ const d = v - mean;
720
+ variance += d * d;
721
+ moment += d ** order;
722
+ }
723
+ variance /= n;
724
+ moment /= n;
725
+ const sigma = Math.sqrt(variance);
726
+ return sigma > Number.EPSILON ? moment / sigma ** order : 0;
727
+ }
728
+ function skewness(values) {
729
+ return standardizedMoment(values, 3);
730
+ }
731
+ function kurtosis(values) {
732
+ return standardizedMoment(values, 4);
733
+ }
734
+
735
+ // src/polygon.ts
736
+ function polygon(...points) {
737
+ return polygonClose(points);
738
+ }
739
+ function polygonFromPoints(points) {
740
+ return polygonClose(points);
741
+ }
742
+ var polygonIncludesPoint = (point, polygon2) => {
743
+ const x = point[0];
744
+ const y = point[1];
745
+ let inside = false;
746
+ for (let i = 0, j = polygon2.length - 1; i < polygon2.length; j = i++) {
747
+ const xi = polygon2[i][0];
748
+ const yi = polygon2[i][1];
749
+ const xj = polygon2[j][0];
750
+ const yj = polygon2[j][1];
751
+ if ((yi > y && yj <= y || yi <= y && yj > y) && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
752
+ inside = !inside;
753
+ }
754
+ }
755
+ return inside;
756
+ };
757
+ var polygonIncludesPointNonZero = (point, polygon2) => {
758
+ const [x, y] = point;
759
+ let windingNumber = 0;
760
+ for (let i = 0; i < polygon2.length; i++) {
761
+ const j = (i + 1) % polygon2.length;
762
+ const [xi, yi] = polygon2[i];
763
+ const [xj, yj] = polygon2[j];
764
+ if (yi <= y) {
765
+ if (yj > y) {
766
+ if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) > 0) {
767
+ windingNumber++;
768
+ }
769
+ }
770
+ } else if (yj <= y) {
771
+ if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) < 0) {
772
+ windingNumber--;
773
+ }
774
+ }
775
+ }
776
+ return windingNumber !== 0;
777
+ };
778
+ function polygonClose(polygon2) {
779
+ return polygonIsClosed(polygon2) ? polygon2 : [...polygon2, polygon2[0]];
780
+ }
781
+ function polygonIsClosed(polygon2, tolerance = PRECISION) {
782
+ return pointsEqual(polygon2[0], polygon2[polygon2.length - 1], tolerance);
783
+ }
784
+ function polygonSignedArea(polygon2, tolerance = PRECISION) {
785
+ const pts = polygonIsClosed(polygon2, tolerance) ? polygon2.slice(0, -1) : polygon2;
786
+ let sum = 0;
787
+ for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) {
788
+ sum += pts[j][0] * pts[i][1] - pts[i][0] * pts[j][1];
789
+ }
790
+ return sum / 2;
791
+ }
792
+ function polygonArea(polygon2, tolerance = PRECISION) {
793
+ return Math.abs(polygonSignedArea(polygon2, tolerance));
794
+ }
795
+ function convexHull(points) {
796
+ if (points.length < 3) {
797
+ return [...points];
798
+ }
799
+ const sorted = [...points].sort(
800
+ (a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]
801
+ );
802
+ const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
803
+ const half = (pts) => {
804
+ const chain = [];
805
+ for (const p of pts) {
806
+ while (chain.length >= 2 && cross(chain[chain.length - 2], chain[chain.length - 1], p) <= 0) {
807
+ chain.pop();
808
+ }
809
+ chain.push(p);
810
+ }
811
+ chain.pop();
812
+ return chain;
813
+ };
814
+ const hull = [...half(sorted), ...half([...sorted].reverse())];
815
+ return hull.length >= 3 ? hull : [...points];
816
+ }
817
+ function simplifyConvexPolygon(polygon2, angleThreshold) {
818
+ if (polygon2.length < 3) {
819
+ return [...polygon2];
820
+ }
821
+ const turnAt = (i) => {
822
+ const prev = polygon2[(i - 1 + polygon2.length) % polygon2.length];
823
+ const curr = polygon2[i];
824
+ const next = polygon2[(i + 1) % polygon2.length];
825
+ const inAngle = Math.atan2(curr[1] - prev[1], curr[0] - prev[0]);
826
+ const outAngle = Math.atan2(next[1] - curr[1], next[0] - curr[0]);
827
+ return Math.abs(normalizeTurn(outAngle - inAngle));
828
+ };
829
+ let start = 0;
830
+ for (let i = 1; i < polygon2.length; i++) {
831
+ if (turnAt(i) > turnAt(start)) {
832
+ start = i;
833
+ }
834
+ }
835
+ const simplified = [];
836
+ let accumulated = 0;
837
+ for (let k = 0; k < polygon2.length; k++) {
838
+ const i = (start + k) % polygon2.length;
839
+ accumulated += turnAt(i);
840
+ if (accumulated >= angleThreshold) {
841
+ simplified.push(polygon2[i]);
842
+ accumulated = 0;
843
+ }
844
+ }
845
+ return simplified.length >= 3 ? simplified : [...polygon2];
846
+ }
847
+ function normalizeTurn(angle) {
848
+ let a = angle;
849
+ while (a > Math.PI) {
850
+ a -= 2 * Math.PI;
851
+ }
852
+ while (a < -Math.PI) {
853
+ a += 2 * Math.PI;
854
+ }
855
+ return a;
856
+ }
857
+
858
+ // src/range.ts
859
+ import { toBrandedType } from "@excalidraw/common";
860
+ function rangeInclusive(start, end) {
861
+ return toBrandedType([start, end]);
862
+ }
863
+ function rangeInclusiveFromPair(pair) {
864
+ return toBrandedType(pair);
865
+ }
866
+ var rangesOverlap = ([a0, a1], [b0, b1]) => {
867
+ if (a0 <= b0) {
868
+ return a1 >= b0;
869
+ }
870
+ if (a0 >= b0) {
871
+ return b1 >= a0;
872
+ }
873
+ return false;
874
+ };
875
+ var rangeIntersection = ([a0, a1], [b0, b1]) => {
876
+ const rangeStart = Math.max(a0, b0);
877
+ const rangeEnd = Math.min(a1, b1);
878
+ if (rangeStart <= rangeEnd) {
879
+ return toBrandedType([rangeStart, rangeEnd]);
880
+ }
881
+ return null;
882
+ };
883
+ var rangeIncludesValue = (value, [min, max]) => {
884
+ return value >= min && value <= max;
885
+ };
886
+
613
887
  // src/segment.ts
614
888
  function lineSegment(a, b) {
615
889
  return [a, b];
616
890
  }
617
- var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[0]);
891
+ var isLineSegment = (segment) => Array.isArray(segment) && segment.length === 2 && isPoint(segment[0]) && isPoint(segment[1]);
618
892
  var lineSegmentRotate = (l, angle, origin) => {
619
893
  return lineSegment(
620
894
  pointRotateRads(l[0], origin || pointCenter(l[0], l[1]), angle),
@@ -699,95 +973,6 @@ function lineSegmentsDistance(s1, s2) {
699
973
  );
700
974
  }
701
975
 
702
- // src/polygon.ts
703
- function polygon(...points) {
704
- return polygonClose(points);
705
- }
706
- function polygonFromPoints(points) {
707
- return polygonClose(points);
708
- }
709
- var polygonIncludesPoint = (point, polygon2) => {
710
- const x = point[0];
711
- const y = point[1];
712
- let inside = false;
713
- for (let i = 0, j = polygon2.length - 1; i < polygon2.length; j = i++) {
714
- const xi = polygon2[i][0];
715
- const yi = polygon2[i][1];
716
- const xj = polygon2[j][0];
717
- const yj = polygon2[j][1];
718
- if ((yi > y && yj <= y || yi <= y && yj > y) && x < (xj - xi) * (y - yi) / (yj - yi) + xi) {
719
- inside = !inside;
720
- }
721
- }
722
- return inside;
723
- };
724
- var polygonIncludesPointNonZero = (point, polygon2) => {
725
- const [x, y] = point;
726
- let windingNumber = 0;
727
- for (let i = 0; i < polygon2.length; i++) {
728
- const j = (i + 1) % polygon2.length;
729
- const [xi, yi] = polygon2[i];
730
- const [xj, yj] = polygon2[j];
731
- if (yi <= y) {
732
- if (yj > y) {
733
- if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) > 0) {
734
- windingNumber++;
735
- }
736
- }
737
- } else if (yj <= y) {
738
- if ((xj - xi) * (y - yi) - (x - xi) * (yj - yi) < 0) {
739
- windingNumber--;
740
- }
741
- }
742
- }
743
- return windingNumber !== 0;
744
- };
745
- var pointOnPolygon = (p, poly, threshold = PRECISION) => {
746
- let on = false;
747
- for (let i = 0, l = poly.length - 1; i < l; i++) {
748
- if (pointOnLineSegment(p, lineSegment(poly[i], poly[i + 1]), threshold)) {
749
- on = true;
750
- break;
751
- }
752
- }
753
- return on;
754
- };
755
- function polygonClose(polygon2) {
756
- return polygonIsClosed(polygon2) ? polygon2 : [...polygon2, polygon2[0]];
757
- }
758
- function polygonIsClosed(polygon2) {
759
- return pointsEqual(polygon2[0], polygon2[polygon2.length - 1]);
760
- }
761
-
762
- // src/range.ts
763
- import { toBrandedType } from "@excalidraw/common";
764
- function rangeInclusive(start, end) {
765
- return toBrandedType([start, end]);
766
- }
767
- function rangeInclusiveFromPair(pair) {
768
- return toBrandedType(pair);
769
- }
770
- var rangesOverlap = ([a0, a1], [b0, b1]) => {
771
- if (a0 <= b0) {
772
- return a1 >= b0;
773
- }
774
- if (a0 >= b0) {
775
- return b1 >= a0;
776
- }
777
- return false;
778
- };
779
- var rangeIntersection = ([a0, a1], [b0, b1]) => {
780
- const rangeStart = Math.max(a0, b0);
781
- const rangeEnd = Math.min(a1, b1);
782
- if (rangeStart <= rangeEnd) {
783
- return toBrandedType([rangeStart, rangeEnd]);
784
- }
785
- return null;
786
- };
787
- var rangeIncludesValue = (value, [min, max]) => {
788
- return value >= min && value <= max;
789
- };
790
-
791
976
  // src/rectangle.ts
792
977
  function rectangle(topLeft, bottomRight) {
793
978
  return [topLeft, bottomRight];
@@ -824,7 +1009,9 @@ export {
824
1009
  average,
825
1010
  bezierEquation,
826
1011
  cartesian2Polar,
1012
+ centroid,
827
1013
  clamp,
1014
+ convexHull,
828
1015
  curve,
829
1016
  curveCatmullRomCubicApproxPoints,
830
1017
  curveCatmullRomQuadraticApproxPoints,
@@ -844,6 +1031,7 @@ export {
844
1031
  ellipseLineIntersectionPoints,
845
1032
  ellipseSegmentInterceptPoints,
846
1033
  ellipseTouchesPoint,
1034
+ elongation,
847
1035
  isCloseTo,
848
1036
  isCurve,
849
1037
  isFiniteNumber,
@@ -851,7 +1039,9 @@ export {
851
1039
  isPoint,
852
1040
  isPointWithinBounds,
853
1041
  isRightAngleRads,
1042
+ isValidPoint,
854
1043
  isVector,
1044
+ kurtosis,
855
1045
  line,
856
1046
  lineSegment,
857
1047
  lineSegmentIntersectionPoints,
@@ -860,6 +1050,7 @@ export {
860
1050
  linesIntersectAt,
861
1051
  normalizeRadians,
862
1052
  offsetPointsForQuadraticBezier,
1053
+ orientPrincipalAxes,
863
1054
  pointCenter,
864
1055
  pointDistance,
865
1056
  pointDistanceSq,
@@ -868,16 +1059,20 @@ export {
868
1059
  pointFromPair,
869
1060
  pointFromVector,
870
1061
  pointOnLineSegment,
871
- pointOnPolygon,
872
1062
  pointRotateDegs,
873
1063
  pointRotateRads,
874
1064
  pointScaleFromOrigin,
875
1065
  pointTranslate,
876
1066
  pointsEqual,
877
1067
  polygon,
1068
+ polygonArea,
878
1069
  polygonFromPoints,
879
1070
  polygonIncludesPoint,
880
1071
  polygonIncludesPointNonZero,
1072
+ polygonIsClosed,
1073
+ polygonSignedArea,
1074
+ principalAxes,
1075
+ principalCoords,
881
1076
  radiansBetweenAngles,
882
1077
  radiansDifference,
883
1078
  radiansToDegrees,
@@ -893,6 +1088,9 @@ export {
893
1088
  round,
894
1089
  roundToStep,
895
1090
  segmentsIntersectAt,
1091
+ simplifyConvexPolygon,
1092
+ skewness,
1093
+ standardizedMoment,
896
1094
  triangleIncludesPoint,
897
1095
  vector,
898
1096
  vectorAdd,