@zsviczian/excalidraw 0.17.1-obsidian-47 → 0.17.1-obsidian-48

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 (73) hide show
  1. package/dist/excalidraw.development.js +248 -127
  2. package/dist/excalidraw.production.min.js +1 -1
  3. package/package.json +1 -1
  4. package/types/excalidraw/actions/actionAddToLibrary.d.ts +3 -3
  5. package/types/excalidraw/actions/actionBoundText.d.ts +2 -2
  6. package/types/excalidraw/actions/actionCanvas.d.ts +18 -18
  7. package/types/excalidraw/actions/actionClipboard.d.ts +10 -10
  8. package/types/excalidraw/actions/actionDeleteSelected.d.ts +6 -6
  9. package/types/excalidraw/actions/actionDuplicateSelection.d.ts +1 -1
  10. package/types/excalidraw/actions/actionElementLock.d.ts +2 -2
  11. package/types/excalidraw/actions/actionExport.d.ts +15 -15
  12. package/types/excalidraw/actions/actionFinalize.d.ts +2 -2
  13. package/types/excalidraw/actions/actionFrame.d.ts +4 -4
  14. package/types/excalidraw/actions/actionGroup.d.ts +2 -2
  15. package/types/excalidraw/actions/actionLinearEditor.d.ts +1 -1
  16. package/types/excalidraw/actions/actionLink.d.ts +1 -1
  17. package/types/excalidraw/actions/actionMenu.d.ts +3 -3
  18. package/types/excalidraw/actions/actionNavigate.d.ts +2 -2
  19. package/types/excalidraw/actions/actionProperties.d.ts +14 -14
  20. package/types/excalidraw/actions/actionSelectAll.d.ts +1 -1
  21. package/types/excalidraw/actions/actionStyles.d.ts +1 -1
  22. package/types/excalidraw/actions/actionToggleGridMode.d.ts +1 -1
  23. package/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +1 -1
  24. package/types/excalidraw/actions/actionToggleStats.d.ts +1 -1
  25. package/types/excalidraw/actions/actionToggleViewMode.d.ts +1 -1
  26. package/types/excalidraw/actions/actionToggleZenMode.d.ts +1 -1
  27. package/types/excalidraw/actions/actionZindex.d.ts +2 -2
  28. package/types/excalidraw/appState.d.ts +8 -8
  29. package/types/excalidraw/clipboard.d.ts +2 -2
  30. package/types/excalidraw/components/App.d.ts +2 -2
  31. package/types/excalidraw/components/hyperlink/helpers.d.ts +4 -3
  32. package/types/excalidraw/element/binding.d.ts +12 -10
  33. package/types/excalidraw/element/bounds.d.ts +6 -4
  34. package/types/excalidraw/element/collision.d.ts +6 -5
  35. package/types/excalidraw/element/embeddable.d.ts +1 -1
  36. package/types/excalidraw/element/heading.d.ts +5 -4
  37. package/types/excalidraw/element/linearElementEditor.d.ts +20 -237
  38. package/types/excalidraw/element/resizeElements.d.ts +1 -2
  39. package/types/excalidraw/element/resizeTest.d.ts +3 -2
  40. package/types/excalidraw/element/routing.d.ts +2 -2
  41. package/types/excalidraw/element/textElement.d.ts +1 -1
  42. package/types/excalidraw/element/transformHandles.d.ts +4 -3
  43. package/types/excalidraw/element/typeChecks.d.ts +0 -3
  44. package/types/excalidraw/element/types.d.ts +7 -6
  45. package/types/excalidraw/obsidianUtils.d.ts +1 -0
  46. package/types/excalidraw/points.d.ts +3 -3
  47. package/types/excalidraw/shapes.d.ts +19 -4
  48. package/types/excalidraw/snapping.d.ts +13 -10
  49. package/types/excalidraw/types.d.ts +0 -2
  50. package/types/excalidraw/utils.d.ts +3 -4
  51. package/types/excalidraw/visualdebug.d.ts +4 -3
  52. package/types/excalidraw/zindex.d.ts +2 -2
  53. package/types/math/angle.d.ts +17 -0
  54. package/types/math/arc.d.ts +6 -0
  55. package/types/math/curve.d.ts +32 -0
  56. package/types/math/ga/ga.d.ts +63 -0
  57. package/types/math/ga/gadirections.d.ts +8 -0
  58. package/types/math/ga/galines.d.ts +22 -0
  59. package/types/math/ga/gapoints.d.ts +7 -0
  60. package/types/math/ga/gatransforms.d.ts +10 -0
  61. package/types/math/index.d.ts +12 -0
  62. package/types/math/line.d.ts +26 -0
  63. package/types/math/point.d.ts +140 -0
  64. package/types/math/polygon.d.ts +5 -0
  65. package/types/math/range.d.ts +44 -0
  66. package/types/math/segment.d.ts +32 -0
  67. package/types/math/triangle.d.ts +11 -0
  68. package/types/math/types.d.ts +96 -0
  69. package/types/math/utils.d.ts +5 -0
  70. package/types/math/vector.d.ts +88 -0
  71. package/types/utils/bbox.d.ts +7 -9
  72. package/types/utils/collision.d.ts +9 -4
  73. package/types/utils/geometry/shape.d.ts +38 -23
@@ -0,0 +1,88 @@
1
+ import type { GlobalPoint, LocalPoint, Vector } from "./types";
2
+ /**
3
+ * Create a vector from the x and y coordiante elements.
4
+ *
5
+ * @param x The X aspect of the vector
6
+ * @param y T Y aspect of the vector
7
+ * @returns The constructed vector with X and Y as the coordinates
8
+ */
9
+ export declare function vector(x: number, y: number, originX?: number, originY?: number): Vector;
10
+ /**
11
+ * Turn a point into a vector with the origin point.
12
+ *
13
+ * @param p The point to turn into a vector
14
+ * @param origin The origin point in a given coordiante system
15
+ * @returns The created vector from the point and the origin
16
+ */
17
+ export declare function vectorFromPoint<Point extends GlobalPoint | LocalPoint>(p: Point, origin?: Point): Vector;
18
+ /**
19
+ * Cross product is a binary operation on two vectors in 2D space.
20
+ * It results in a vector that is perpendicular to both vectors.
21
+ *
22
+ * @param a One of the vectors to use for the directed area calculation
23
+ * @param b The other vector to use for the directed area calculation
24
+ * @returns The directed area value for the two vectos
25
+ */
26
+ export declare function vectorCross(a: Vector, b: Vector): number;
27
+ /**
28
+ * Dot product is defined as the sum of the products of the
29
+ * two vectors.
30
+ *
31
+ * @param a One of the vectors for which the sum of products is calculated
32
+ * @param b The other vector for which the sum of products is calculated
33
+ * @returns The sum of products of the two vectors
34
+ */
35
+ export declare function vectorDot(a: Vector, b: Vector): number;
36
+ /**
37
+ * Determines if the value has the shape of a Vector.
38
+ *
39
+ * @param v The value to test
40
+ * @returns TRUE if the value has the shape and components of a Vectors
41
+ */
42
+ export declare function isVector(v: unknown): v is Vector;
43
+ /**
44
+ * Add two vectors by adding their coordinates.
45
+ *
46
+ * @param a One of the vectors to add
47
+ * @param b The other vector to add
48
+ * @returns The sum vector of the two provided vectors
49
+ */
50
+ export declare function vectorAdd(a: Readonly<Vector>, b: Readonly<Vector>): Vector;
51
+ /**
52
+ * Add two vectors by adding their coordinates.
53
+ *
54
+ * @param start One of the vectors to add
55
+ * @param end The other vector to add
56
+ * @returns The sum vector of the two provided vectors
57
+ */
58
+ export declare function vectorSubtract(start: Readonly<Vector>, end: Readonly<Vector>): Vector;
59
+ /**
60
+ * Scale vector by a scalar.
61
+ *
62
+ * @param v The vector to scale
63
+ * @param scalar The scalar to multiply the vector components with
64
+ * @returns The new scaled vector
65
+ */
66
+ export declare function vectorScale(v: Vector, scalar: number): Vector;
67
+ /**
68
+ * Calculates the sqare magnitude of a vector. Use this if you compare
69
+ * magnitudes as it saves you an SQRT.
70
+ *
71
+ * @param v The vector to measure
72
+ * @returns The scalar squared magnitude of the vector
73
+ */
74
+ export declare function vectorMagnitudeSq(v: Vector): number;
75
+ /**
76
+ * Calculates the magnitude of a vector.
77
+ *
78
+ * @param v The vector to measure
79
+ * @returns The scalar magnitude of the vector
80
+ */
81
+ export declare function vectorMagnitude(v: Vector): number;
82
+ /**
83
+ * Normalize the vector (i.e. make the vector magnitue equal 1).
84
+ *
85
+ * @param v The vector to normalize
86
+ * @returns The new normalized vector
87
+ */
88
+ export declare const vectorNormalize: (v: Vector) => Vector;
@@ -1,11 +1,9 @@
1
+ import { type GlobalPoint, type LocalPoint } from "../math";
1
2
  import type { Bounds } from "../excalidraw/element/bounds";
2
- import type { Point } from "../excalidraw/types";
3
- export type LineSegment = [Point, Point];
4
- export declare function getBBox(line: LineSegment): Bounds;
5
- export declare function crossProduct(a: Point, b: Point): number;
3
+ export type LineSegment<P extends LocalPoint | GlobalPoint> = [P, P];
4
+ export declare function getBBox<P extends LocalPoint | GlobalPoint>(line: LineSegment<P>): Bounds;
6
5
  export declare function doBBoxesIntersect(a: Bounds, b: Bounds): boolean;
7
- export declare function translate(a: Point, b: Point): Point;
8
- export declare function isPointOnLine(l: LineSegment, p: Point): boolean;
9
- export declare function isPointRightOfLine(l: LineSegment, p: Point): boolean;
10
- export declare function isLineSegmentTouchingOrCrossingLine(a: LineSegment, b: LineSegment): boolean;
11
- export declare function doLineSegmentsIntersect(a: LineSegment, b: LineSegment): boolean;
6
+ export declare function isPointOnLine<P extends GlobalPoint | LocalPoint>(l: LineSegment<P>, p: P): boolean;
7
+ export declare function isPointRightOfLine<P extends GlobalPoint | LocalPoint>(l: LineSegment<P>, p: P): boolean;
8
+ export declare function isLineSegmentTouchingOrCrossingLine<P extends GlobalPoint | LocalPoint>(a: LineSegment<P>, b: LineSegment<P>): boolean;
9
+ export declare function doLineSegmentsIntersect<P extends GlobalPoint | LocalPoint>(a: LineSegment<P>, b: LineSegment<P>): boolean;
@@ -1,4 +1,9 @@
1
- import type { Point, Polygon, GeometricShape } from "./geometry/shape";
2
- export declare const isPointOnShape: (point: Point, shape: GeometricShape, tolerance?: number) => boolean;
3
- export declare const isPointInShape: (point: Point, shape: GeometricShape) => boolean;
4
- export declare const isPointInBounds: (point: Point, bounds: Polygon) => boolean;
1
+ import type { Polyline } from "./geometry/shape";
2
+ import { type GeometricShape } from "./geometry/shape";
3
+ import type { Curve } from "../math";
4
+ import { type GlobalPoint, type LocalPoint, type Polygon } from "../math";
5
+ export declare const isPointOnShape: <Point extends GlobalPoint | LocalPoint>(point: Point, shape: GeometricShape<Point>, tolerance?: number) => boolean;
6
+ export declare const isPointInShape: <Point extends GlobalPoint | LocalPoint>(point: Point, shape: GeometricShape<Point>) => boolean;
7
+ export declare const isPointInBounds: <Point extends GlobalPoint | LocalPoint>(point: Point, bounds: Polygon<Point>) => boolean;
8
+ export declare const pointOnCurve: <Point extends GlobalPoint | LocalPoint>(point: Point, curve: Curve<Point>, threshold: number) => boolean;
9
+ export declare const pointOnPolyline: <Point extends GlobalPoint | LocalPoint>(point: Point, polyline: Polyline<Point>, threshold?: number) => boolean;
@@ -11,46 +11,61 @@
11
11
  * also included in this file are methods for converting an Excalidraw element or a Drawable from roughjs
12
12
  * to pure shapes
13
13
  */
14
- import type { ElementsMap, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawTextElement } from "../../excalidraw/element/types";
14
+ import type { Curve, LineSegment, Polygon, Radians } from "../../math";
15
+ import { type GlobalPoint, type LocalPoint } from "../../math";
16
+ import type { ElementsMap, ExcalidrawBindableElement, ExcalidrawDiamondElement, ExcalidrawElement, ExcalidrawEllipseElement, ExcalidrawEmbeddableElement, ExcalidrawFrameLikeElement, ExcalidrawFreeDrawElement, ExcalidrawIframeElement, ExcalidrawImageElement, ExcalidrawLinearElement, ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawTextElement } from "../../excalidraw/element/types";
15
17
  import type { Drawable, Op } from "roughjs/bin/core";
16
- export type Point = [number, number];
17
- export type Vector = Point;
18
- export type Line = [Point, Point];
19
- export type Polyline = Line[];
20
- export type Curve = [Point, Point, Point, Point];
21
- export type Polycurve = Curve[];
22
- export type Polygon = Point[];
23
- export type Ellipse = {
18
+ export type Polyline<Point extends GlobalPoint | LocalPoint> = LineSegment<Point>[];
19
+ export type Polycurve<Point extends GlobalPoint | LocalPoint> = Curve<Point>[];
20
+ export type Ellipse<Point extends GlobalPoint | LocalPoint> = {
24
21
  center: Point;
25
- angle: number;
22
+ angle: Radians;
26
23
  halfWidth: number;
27
24
  halfHeight: number;
28
25
  };
29
- export type GeometricShape = {
26
+ export type GeometricShape<Point extends GlobalPoint | LocalPoint> = {
30
27
  type: "line";
31
- data: Line;
28
+ data: LineSegment<Point>;
32
29
  } | {
33
30
  type: "polygon";
34
- data: Polygon;
31
+ data: Polygon<Point>;
35
32
  } | {
36
33
  type: "curve";
37
- data: Curve;
34
+ data: Curve<Point>;
38
35
  } | {
39
36
  type: "ellipse";
40
- data: Ellipse;
37
+ data: Ellipse<Point>;
41
38
  } | {
42
39
  type: "polyline";
43
- data: Polyline;
40
+ data: Polyline<Point>;
44
41
  } | {
45
42
  type: "polycurve";
46
- data: Polycurve;
43
+ data: Polycurve<Point>;
47
44
  };
48
45
  type RectangularElement = ExcalidrawRectangleElement | ExcalidrawDiamondElement | ExcalidrawFrameLikeElement | ExcalidrawEmbeddableElement | ExcalidrawImageElement | ExcalidrawIframeElement | ExcalidrawTextElement | ExcalidrawSelectionElement;
49
- export declare const getPolygonShape: (element: RectangularElement) => GeometricShape;
50
- export declare const getSelectionBoxShape: (element: ExcalidrawElement, elementsMap: ElementsMap, padding?: number) => GeometricShape;
51
- export declare const getEllipseShape: (element: ExcalidrawEllipseElement) => GeometricShape;
46
+ export declare const getPolygonShape: <Point extends GlobalPoint | LocalPoint>(element: RectangularElement) => GeometricShape<Point>;
47
+ export declare const getSelectionBoxShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawElement, elementsMap: ElementsMap, padding?: number) => GeometricShape<Point>;
48
+ export declare const getEllipseShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawEllipseElement) => GeometricShape<Point>;
52
49
  export declare const getCurvePathOps: (shape: Drawable) => Op[];
53
- export declare const getCurveShape: (roughShape: Drawable, startingPoint: Point | undefined, angleInRadian: number, center: Point) => GeometricShape;
54
- export declare const getFreedrawShape: (element: ExcalidrawFreeDrawElement, center: Point, isClosed?: boolean) => GeometricShape;
55
- export declare const getClosedCurveShape: (element: ExcalidrawLinearElement, roughShape: Drawable, startingPoint: Point | undefined, angleInRadian: number, center: Point) => GeometricShape;
50
+ export declare const getCurveShape: <Point extends GlobalPoint | LocalPoint>(roughShape: Drawable, startingPoint: Point | undefined, angleInRadian: Radians, center: Point) => GeometricShape<Point>;
51
+ export declare const getFreedrawShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawFreeDrawElement, center: Point, isClosed?: boolean) => GeometricShape<Point>;
52
+ export declare const getClosedCurveShape: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawLinearElement, roughShape: Drawable, startingPoint: Point | undefined, angleInRadian: Radians, center: Point) => GeometricShape<Point>;
53
+ /**
54
+ * Determine intersection of a rectangular shaped element and a
55
+ * line segment.
56
+ *
57
+ * @param element The rectangular element to test against
58
+ * @param segment The segment intersecting the element
59
+ * @param gap Optional value to inflate the shape before testing
60
+ * @returns An array of intersections
61
+ */
62
+ export declare const segmentIntersectRectangleElement: <Point extends GlobalPoint | LocalPoint>(element: ExcalidrawBindableElement, segment: LineSegment<Point>, gap?: number) => Point[];
63
+ export declare const pointOnEllipse: <Point extends GlobalPoint | LocalPoint>(point: Point, ellipse: Ellipse<Point>, threshold?: number) => boolean;
64
+ export declare const pointInEllipse: <Point extends GlobalPoint | LocalPoint>(p: Point, ellipse: Ellipse<Point>) => boolean;
65
+ export declare const ellipseAxes: <Point extends GlobalPoint | LocalPoint>(ellipse: Ellipse<Point>) => {
66
+ majorAxis: number;
67
+ minorAxis: number;
68
+ };
69
+ export declare const ellipseFocusToCenter: <Point extends GlobalPoint | LocalPoint>(ellipse: Ellipse<Point>) => number;
70
+ export declare const ellipseExtremes: <Point extends GlobalPoint | LocalPoint>(ellipse: Ellipse<Point>) => import("../../math").Vector[];
56
71
  export {};