Move utils source into src/

This commit is contained in:
Marcel Mraz 2025-03-24 12:15:37 +01:00
parent ba0a9e0cb4
commit 4a182f985b
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
31 changed files with 47 additions and 49 deletions

View file

@ -47,14 +47,6 @@ export default defineConfig(({ mode }) => {
find: /^@excalidraw\/excalidraw\/(.*?)/, find: /^@excalidraw\/excalidraw\/(.*?)/,
replacement: path.resolve(__dirname, "../packages/excalidraw/$1"), replacement: path.resolve(__dirname, "../packages/excalidraw/$1"),
}, },
{
find: /^@excalidraw\/utils$/,
replacement: path.resolve(__dirname, "../packages/utils/index.ts"),
},
{
find: /^@excalidraw\/utils\/(.*?)/,
replacement: path.resolve(__dirname, "../packages/utils/$1"),
},
{ {
find: /^@excalidraw\/math$/, find: /^@excalidraw\/math$/,
replacement: path.resolve(__dirname, "../packages/math/src/index.ts"), replacement: path.resolve(__dirname, "../packages/math/src/index.ts"),
@ -63,6 +55,14 @@ export default defineConfig(({ mode }) => {
find: /^@excalidraw\/math\/(.*?)/, find: /^@excalidraw\/math\/(.*?)/,
replacement: path.resolve(__dirname, "../packages/math/src/$1"), replacement: path.resolve(__dirname, "../packages/math/src/$1"),
}, },
{
find: /^@excalidraw\/utils$/,
replacement: path.resolve(__dirname, "../packages/utils/src/index.ts"),
},
{
find: /^@excalidraw\/utils\/(.*?)/,
replacement: path.resolve(__dirname, "../packages/utils/src/$1"),
},
], ],
}, },
build: { build: {

View file

@ -11,7 +11,7 @@ import {
pointRotateRads, pointRotateRads,
} from "@excalidraw/math"; } from "@excalidraw/math";
import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; import { getCurvePathOps } from "@excalidraw/utils/shape";
import type { import type {
Degrees, Degrees,

View file

@ -16,7 +16,7 @@ import {
} from "@excalidraw/math/ellipse"; } from "@excalidraw/math/ellipse";
import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision"; import { isPointInShape, isPointOnShape } from "@excalidraw/utils/collision";
import { getPolygonShape } from "@excalidraw/utils/geometry/shape"; import { getPolygonShape } from "@excalidraw/utils/shape";
import type { import type {
GlobalPoint, GlobalPoint,
@ -26,7 +26,7 @@ import type {
Radians, Radians,
} from "@excalidraw/math"; } from "@excalidraw/math";
import type { GeometricShape } from "@excalidraw/utils/geometry/shape"; import type { GeometricShape } from "@excalidraw/utils/shape";
import type { FrameNameBounds } from "@excalidraw/excalidraw/types"; import type { FrameNameBounds } from "@excalidraw/excalidraw/types";

View file

@ -9,7 +9,7 @@ import {
vectorFromPoint, vectorFromPoint,
} from "@excalidraw/math"; } from "@excalidraw/math";
import { getCurvePathOps } from "@excalidraw/utils/geometry/shape"; import { getCurvePathOps } from "@excalidraw/utils/shape";
import { import {
DRAGGING_THRESHOLD, DRAGGING_THRESHOLD,
@ -20,7 +20,7 @@ import {
tupleToCoors, tupleToCoors,
} from "@excalidraw/common"; } from "@excalidraw/common";
// TODO: remove the dependency on the scene // TODO: remove direct dependency on the scene, should be passed in or injected instead
import Scene from "@excalidraw/excalidraw/scene/Scene"; import Scene from "@excalidraw/excalidraw/scene/Scene";
import type { Store } from "@excalidraw/excalidraw/store"; import type { Store } from "@excalidraw/excalidraw/store";

View file

@ -5,7 +5,7 @@ import {
toBrandedType, toBrandedType,
} from "@excalidraw/common"; } from "@excalidraw/common";
// TODO_SEP: should be passed in or injected instead // TODO: remove direct dependency on the scene, should be passed in or injected instead
import Scene from "@excalidraw/excalidraw/scene/Scene"; import Scene from "@excalidraw/excalidraw/scene/Scene";
import type { Radians } from "@excalidraw/math"; import type { Radians } from "@excalidraw/math";

View file

@ -23,7 +23,7 @@ import {
getFreedrawShape, getFreedrawShape,
getPolygonShape, getPolygonShape,
type GeometricShape, type GeometricShape,
} from "@excalidraw/utils/geometry/shape"; } from "@excalidraw/utils/shape";
import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types"; import type { NormalizedZoomValue, Zoom } from "@excalidraw/excalidraw/types";

View file

@ -17,12 +17,12 @@ import {
render, render,
} from "@excalidraw/excalidraw/tests/test-utils"; } from "@excalidraw/excalidraw/tests/test-utils";
import "@excalidraw/utils/test-utils";
import type { LocalPoint } from "@excalidraw/math"; import type { LocalPoint } from "@excalidraw/math";
import { bindLinearElement } from "../src/binding"; import { bindLinearElement } from "../src/binding";
import "../../utils/test-utils";
import type { import type {
ExcalidrawArrowElement, ExcalidrawArrowElement,
ExcalidrawBindableElement, ExcalidrawBindableElement,

View file

@ -18,7 +18,7 @@ import {
vectorNormalize, vectorNormalize,
} from "@excalidraw/math"; } from "@excalidraw/math";
import { isPointInShape } from "@excalidraw/utils/collision"; import { isPointInShape } from "@excalidraw/utils/collision";
import { getSelectionBoxShape } from "@excalidraw/utils/geometry/shape"; import { getSelectionBoxShape } from "@excalidraw/utils/shape";
import { import {
COLOR_PALETTE, COLOR_PALETTE,

View file

@ -1,4 +1,4 @@
@import "../css/variables.module"; @import "../css/variables.module.scss";
.excalidraw { .excalidraw {
--avatar-size: 1.75rem; --avatar-size: 1.75rem;

View file

@ -21,6 +21,8 @@ import {
DEFAULT_ELEMENT_STROKE_COLOR_INDEX, DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
} from "@excalidraw/common"; } from "@excalidraw/common";
import "@excalidraw/utils/test-utils";
import type { LocalPoint, Radians } from "@excalidraw/math"; import type { LocalPoint, Radians } from "@excalidraw/math";
import type { import type {
@ -35,7 +37,6 @@ import type {
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import "../global.d.ts"; import "../global.d.ts";
import "../../utils/test-utils";
import { import {
actionSendBackward, actionSendBackward,

View file

@ -5,6 +5,8 @@ import { bindOrUnbindLinearElement } from "@excalidraw/element/binding";
import { KEYS, reseed } from "@excalidraw/common"; import { KEYS, reseed } from "@excalidraw/common";
import "@excalidraw/utils/test-utils";
import type { import type {
ExcalidrawLinearElement, ExcalidrawLinearElement,
NonDeleted, NonDeleted,
@ -17,7 +19,6 @@ import { Excalidraw } from "../index";
import * as InteractiveCanvas from "../renderer/interactiveScene"; import * as InteractiveCanvas from "../renderer/interactiveScene";
import * as StaticScene from "../renderer/staticScene"; import * as StaticScene from "../renderer/staticScene";
import "../../utils/test-utils";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "./helpers/ui";
import { render, fireEvent, act, unmountComponent } from "./test-utils"; import { render, fireEvent, act, unmountComponent } from "./test-utils";

View file

@ -1,4 +1,4 @@
import "../../utils/test-utils"; import "@excalidraw/utils/test-utils";
import { import {
curve, curve,

View file

@ -19,8 +19,8 @@
"@excalidraw/excalidraw/*": ["./excalidraw/*"], "@excalidraw/excalidraw/*": ["./excalidraw/*"],
"@excalidraw/math": ["./math/src/index.ts"], "@excalidraw/math": ["./math/src/index.ts"],
"@excalidraw/math/*": ["./math/src/*"], "@excalidraw/math/*": ["./math/src/*"],
"@excalidraw/utils": ["./utils/index.ts"], "@excalidraw/utils": ["./utils/src/index.ts"],
"@excalidraw/utils/*": ["./utils/*"] "@excalidraw/utils/*": ["./utils/src/*"]
} }
}, },
"exclude": ["**/*.test.*", "tests", "types", "examples", "dist"] "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]

View file

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

View file

@ -9,9 +9,9 @@ import {
import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math"; import type { Curve, Degrees, GlobalPoint } from "@excalidraw/math";
import { pointOnCurve, pointOnPolyline } from "./collision"; import { pointOnCurve, pointOnPolyline } from "../src/collision";
import type { Polyline } from "./geometry/shape"; import type { Polyline } from "../src/shape";
describe("point and curve", () => { describe("point and curve", () => {
const c: Curve<GlobalPoint> = curve( const c: Curve<GlobalPoint> = curve(

View file

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

View file

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

View file

@ -4,7 +4,7 @@ import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types"; import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
import * as utils from "./index"; import * as utils from "../src";
// NOTE this test file is using the actual API, unmocked. Hence splitting it // 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 // from the other test file, because I couldn't figure out how to test

View file

@ -6,7 +6,7 @@ import {
elementPartiallyOverlapsWithOrContainsBBox, elementPartiallyOverlapsWithOrContainsBBox,
elementsOverlappingBBox, elementsOverlappingBBox,
isElementInsideBBox, isElementInsideBBox,
} from "./withinBounds"; } from "../src/withinBounds";
const makeElement = (x: number, y: number, width: number, height: number) => const makeElement = (x: number, y: number, width: number, height: number) =>
API.createElement({ API.createElement({

View file

@ -32,7 +32,7 @@ const getConfig = (outdir) => ({
"@excalidraw/element": path.resolve(__dirname, "../packages/element/src"), "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
"@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"), "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
"@excalidraw/math": path.resolve(__dirname, "../packages/math/src"), "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"),
"@excalidraw/utils": path.resolve(__dirname, "../packages/utils"), "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"),
}, },
loader: { loader: {
".woff2": "file", ".woff2": "file",

View file

@ -10,7 +10,7 @@ const getConfig = (outdir) => ({
outdir, outdir,
bundle: true, bundle: true,
format: "esm", format: "esm",
entryPoints: ["index.ts"], entryPoints: ["src/index.ts"],
entryNames: "[name]", entryNames: "[name]",
assetNames: "[dir]/[name]", assetNames: "[dir]/[name]",
alias: { alias: {
@ -18,7 +18,7 @@ const getConfig = (outdir) => ({
"@excalidraw/element": path.resolve(__dirname, "../packages/element/src"), "@excalidraw/element": path.resolve(__dirname, "../packages/element/src"),
"@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"), "@excalidraw/excalidraw": path.resolve(__dirname, "../packages/excalidraw"),
"@excalidraw/math": path.resolve(__dirname, "../packages/math/src"), "@excalidraw/math": path.resolve(__dirname, "../packages/math/src"),
"@excalidraw/utils": path.resolve(__dirname, "../packages/utils"), "@excalidraw/utils": path.resolve(__dirname, "../packages/utils/src"),
}, },
}); });

View file

@ -27,8 +27,8 @@
"@excalidraw/element/*": ["./packages/element/src/*"], "@excalidraw/element/*": ["./packages/element/src/*"],
"@excalidraw/math": ["./packages/math/src/index.ts"], "@excalidraw/math": ["./packages/math/src/index.ts"],
"@excalidraw/math/*": ["./packages/math/src/*"], "@excalidraw/math/*": ["./packages/math/src/*"],
"@excalidraw/utils": ["./packages/utils/index.ts"], "@excalidraw/utils": ["./packages/utils/src/index.ts"],
"@excalidraw/utils/*": ["./packages/utils/*"] "@excalidraw/utils/*": ["./packages/utils/src/*"]
} }
}, },
"include": ["packages", "excalidraw-app"], "include": ["packages", "excalidraw-app"],

View file

@ -29,14 +29,6 @@ export default defineConfig({
find: /^@excalidraw\/excalidraw\/(.*?)/, find: /^@excalidraw\/excalidraw\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/excalidraw/$1"), replacement: path.resolve(__dirname, "./packages/excalidraw/$1"),
}, },
{
find: /^@excalidraw\/utils$/,
replacement: path.resolve(__dirname, "./packages/utils/index.ts"),
},
{
find: /^@excalidraw\/utils\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/utils/$1"),
},
{ {
find: /^@excalidraw\/math$/, find: /^@excalidraw\/math$/,
replacement: path.resolve(__dirname, "./packages/math/src/index.ts"), replacement: path.resolve(__dirname, "./packages/math/src/index.ts"),
@ -45,6 +37,14 @@ export default defineConfig({
find: /^@excalidraw\/math\/(.*?)/, find: /^@excalidraw\/math\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/math/src/$1"), replacement: path.resolve(__dirname, "./packages/math/src/$1"),
}, },
{
find: /^@excalidraw\/utils$/,
replacement: path.resolve(__dirname, "./packages/utils/src/index.ts"),
},
{
find: /^@excalidraw\/utils\/(.*?)/,
replacement: path.resolve(__dirname, "./packages/utils/src/$1"),
},
], ],
}, },
//@ts-ignore //@ts-ignore