Merge remote-tracking branch 'upstream/master' into snap-to-shape

This commit is contained in:
Mathias Krafft 2025-03-28 11:22:44 +01:00
commit ae65fbd570
No known key found for this signature in database
GPG key ID: D99E394FA2319429
490 changed files with 7224 additions and 5197 deletions

View file

@ -2,18 +2,18 @@
"name": "@excalidraw/utils",
"version": "0.1.2",
"type": "module",
"types": "./dist/types/utils/index.d.ts",
"types": "./dist/types/utils/src/index.d.ts",
"main": "./dist/prod/index.js",
"module": "./dist/prod/index.js",
"exports": {
".": {
"types": "./dist/types/utils/index.d.ts",
"types": "./dist/types/utils/src/index.d.ts",
"development": "./dist/dev/index.js",
"production": "./dist/prod/index.js",
"default": "./dist/prod/index.js"
},
"./*": {
"types": "./../utils/dist/types/utils/*"
"types": "./../utils/dist/types/utils/src/*.d.ts"
}
},
"files": [

View file

@ -4,7 +4,8 @@ import {
type GlobalPoint,
type LocalPoint,
} from "@excalidraw/math";
import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
import type { Bounds } from "@excalidraw/element/bounds";
export type LineSegment<P extends LocalPoint | GlobalPoint> = [P, P];

View file

@ -1,10 +1,3 @@
import type { Polycurve, Polyline } from "./geometry/shape";
import {
pointInEllipse,
pointOnEllipse,
type GeometricShape,
} from "./geometry/shape";
import type { Curve } from "@excalidraw/math";
import {
lineSegment,
pointFrom,
@ -17,6 +10,12 @@ import {
type Polygon,
} from "@excalidraw/math";
import type { Curve } from "@excalidraw/math";
import { pointInEllipse, pointOnEllipse } from "./shape";
import type { Polycurve, Polyline, GeometricShape } from "./shape";
// check if the given point is considered on the given shape's border
export const isPointOnShape = <Point extends GlobalPoint | LocalPoint>(
point: Point,

View file

@ -1,23 +1,24 @@
import {
exportToCanvas as _exportToCanvas,
exportToSvg as _exportToSvg,
} from "@excalidraw/excalidraw/scene/export";
import { MIME_TYPES } from "@excalidraw/common";
import { getDefaultAppState } from "@excalidraw/excalidraw/appState";
import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
import type {
ExcalidrawElement,
ExcalidrawFrameLikeElement,
NonDeleted,
} from "@excalidraw/excalidraw/element/types";
import { restore } from "@excalidraw/excalidraw/data/restore";
import { MIME_TYPES } from "@excalidraw/excalidraw/constants";
import { encodePngMetadata } from "@excalidraw/excalidraw/data/image";
import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
import {
copyBlobToClipboardAsPng,
copyTextToSystemClipboard,
copyToClipboard,
} from "@excalidraw/excalidraw/clipboard";
import { encodePngMetadata } from "@excalidraw/excalidraw/data/image";
import { serializeAsJSON } from "@excalidraw/excalidraw/data/json";
import { restore } from "@excalidraw/excalidraw/data/restore";
import {
exportToCanvas as _exportToCanvas,
exportToSvg as _exportToSvg,
} from "@excalidraw/excalidraw/scene/export";
import type {
ExcalidrawElement,
ExcalidrawFrameLikeElement,
NonDeleted,
} from "@excalidraw/element/types";
import type { AppState, BinaryFiles } from "@excalidraw/excalidraw/types";
export { MIME_TYPES };

View file

@ -1,4 +1,4 @@
export * from "./export";
export * from "./withinBounds";
export * from "./bbox";
export { getCommonBounds } from "@excalidraw/excalidraw/element/bounds";
export { getCommonBounds } from "@excalidraw/element/bounds";

View file

@ -11,8 +11,9 @@
* also included in this file are methods for converting an Excalidraw element or a Drawable from roughjs
* to pure shapes
*/
import { pointsOnBezierCurves } from "points-on-curve";
import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
import { invariant } from "@excalidraw/common";
import {
curve,
lineSegment,
@ -32,7 +33,9 @@ import {
type GlobalPoint,
type LocalPoint,
} from "@excalidraw/math";
import { getElementAbsoluteCoords } from "@excalidraw/excalidraw/element";
import { getElementAbsoluteCoords } from "@excalidraw/element/bounds";
import type {
ElementsMap,
ExcalidrawBindableElement,
@ -48,10 +51,10 @@ import type {
ExcalidrawRectangleElement,
ExcalidrawSelectionElement,
ExcalidrawTextElement,
} from "@excalidraw/excalidraw/element/types";
import { pointsOnBezierCurves } from "points-on-curve";
} from "@excalidraw/element/types";
import type { Curve, LineSegment, Polygon, Radians } from "@excalidraw/math";
import type { Drawable, Op } from "roughjs/bin/core";
import { invariant } from "@excalidraw/excalidraw/utils";
// a polyline (made up term here) is a line consisting of other line segments
// this corresponds to a straight line element in the editor but it could also

View file

@ -6,12 +6,12 @@ import type {
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
ExcalidrawRectangleElement,
} from "../excalidraw/element/types";
import type { BoundingBox, Bounds } from "../excalidraw/element/bounds";
import { getCenterForBounds, getCommonBoundingBox } from "../excalidraw/element/bounds";
import { newArrowElement, newElement, newLinearElement } from "../excalidraw/element";
} from "@excalidraw/element/types";
import type { BoundingBox, Bounds } from "@excalidraw/element/bounds";
import { getCenterForBounds, getCommonBoundingBox } from "@excalidraw/element/bounds";
import { newArrowElement, newElement, newLinearElement } from "@excalidraw/element/newElement";
import { angleBetween, GlobalPoint, LocalPoint, perpendicularDistance, pointDistance } from "@excalidraw/math";
import { ROUNDNESS } from "@excalidraw/excalidraw/constants";
import { ROUNDNESS } from "@excalidraw/common";
type Shape =
| ExcalidrawRectangleElement["type"]

View file

@ -1,20 +1,12 @@
import type {
ExcalidrawElement,
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
NonDeletedExcalidrawElement,
} from "@excalidraw/excalidraw/element/types";
import { arrayToMap } from "@excalidraw/common";
import { getElementBounds } from "@excalidraw/element/bounds";
import {
isArrowElement,
isExcalidrawElement,
isFreeDrawElement,
isLinearElement,
isTextElement,
} from "@excalidraw/excalidraw/element/typeChecks";
import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
import { getElementBounds } from "@excalidraw/excalidraw/element/bounds";
import { arrayToMap } from "@excalidraw/excalidraw/utils";
import type { LocalPoint } from "@excalidraw/math";
} from "@excalidraw/element/typeChecks";
import {
rangeIncludesValue,
pointFrom,
@ -22,6 +14,15 @@ import {
rangeInclusive,
} from "@excalidraw/math";
import type { Bounds } from "@excalidraw/element/bounds";
import type {
ExcalidrawElement,
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
import type { LocalPoint } from "@excalidraw/math";
type Element = NonDeletedExcalidrawElement;
type Elements = readonly NonDeletedExcalidrawElement[];

View file

@ -1,4 +1,3 @@
import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math";
import {
curve,
degreesToRadians,
@ -7,8 +6,12 @@ import {
pointFrom,
pointRotateDegs,
} from "@excalidraw/math";
import { pointOnCurve, pointOnPolyline } from "./collision";
import type { Polyline } from "./geometry/shape";
import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math";
import { pointOnCurve, pointOnPolyline } from "../src/collision";
import type { Polyline } from "../src/shape";
describe("point and curve", () => {
const c: Curve<GlobalPoint> = curve(

View file

@ -1,9 +1,9 @@
import * as utils from ".";
import { MIME_TYPES } from "@excalidraw/common";
import * as mockedSceneExportUtils from "@excalidraw/excalidraw/scene/export";
import { diagramFactory } from "@excalidraw/excalidraw/tests/fixtures/diagramFixture";
import { vi } from "vitest";
import * as mockedSceneExportUtils from "@excalidraw/excalidraw/scene/export";
import { MIME_TYPES } from "@excalidraw/excalidraw/constants";
import * as utils from "../src";
const exportToSvgSpy = vi.spyOn(mockedSceneExportUtils, "exportToSvg");

View file

@ -1,9 +1,3 @@
import type {
GlobalPoint,
LineSegment,
Polygon,
Radians,
} from "@excalidraw/math";
import {
pointFrom,
lineSegment,
@ -13,7 +7,15 @@ import {
polygonIncludesPoint,
segmentsIntersectAt,
} from "@excalidraw/math";
import { pointInEllipse, pointOnEllipse, type Ellipse } from "./shape";
import type {
GlobalPoint,
LineSegment,
Polygon,
Radians,
} from "@excalidraw/math";
import { pointInEllipse, pointOnEllipse, type Ellipse } from "../src/shape";
describe("point and line", () => {
// const l: Line<GlobalPoint> = line(point(1, 0), point(1, 2));

View file

@ -1,8 +1,10 @@
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
import * as utils from "./index";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { decodeSvgBase64Payload } from "@excalidraw/excalidraw/scene/export";
import { decodePngMetadata } from "@excalidraw/excalidraw/data/image";
import { decodeSvgBase64Payload } from "@excalidraw/excalidraw/scene/export";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
import * as utils from "../src";
// NOTE this test file is using the actual API, unmocked. Hence splitting it
// from the other test file, because I couldn't figure out how to test

View file

@ -1,10 +1,12 @@
import type { Bounds } from "@excalidraw/excalidraw/element/bounds";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import type { Bounds } from "@excalidraw/element/bounds";
import {
elementPartiallyOverlapsWithOrContainsBBox,
elementsOverlappingBBox,
isElementInsideBBox,
} from "./withinBounds";
} from "../src/withinBounds";
const makeElement = (x: number, y: number, width: number, height: number) =>
API.createElement({

View file

@ -1,24 +1,8 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist/types",
"target": "ESNext",
"strict": true,
"skipLibCheck": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"jsx": "react-jsx",
"emitDeclarationOnly": true,
"paths": {
"@excalidraw/excalidraw": ["../excalidraw/index.tsx"],
"@excalidraw/utils": ["../utils/index.ts"],
"@excalidraw/math": ["../math/index.ts"],
"@excalidraw/excalidraw/*": ["../excalidraw/*"],
"@excalidraw/utils/*": ["../utils/*"],
"@excalidraw/math/*": ["../math/*"]
}
"outDir": "./dist/types"
},
"include": ["src/**/*", "global.d.ts"],
"exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
}