From 58567dd2b6eb52247909b907190f569c190a6873 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 9 May 2024 13:30:26 +0530 Subject: [PATCH] move the files to src and tests folders under utils --- .../excalidraw/tests/scene/export.test.ts | 2 +- packages/utils/index.ts | 12 +++++------ packages/utils/package.json | 2 ++ packages/utils/{ => src}/bbox.ts | 5 +++-- packages/utils/{ => src}/collision.ts | 0 packages/utils/{ => src}/export.ts | 20 +++++++++---------- packages/utils/{ => src}/geometry/geometry.ts | 2 +- packages/utils/{ => src}/geometry/shape.ts | 4 ++-- packages/utils/{ => src}/withinBounds.ts | 14 ++++++------- packages/utils/{ => tests}/export.test.ts | 8 ++++---- .../{geometry => tests}/geometry.test.ts | 11 ++++++++-- .../utils/{ => tests}/utils.unmocked.test.ts | 11 ++++++---- .../utils/{ => tests}/withinBounds.test.ts | 6 +++--- 13 files changed, 55 insertions(+), 42 deletions(-) rename packages/utils/{ => src}/bbox.ts (91%) rename packages/utils/{ => src}/collision.ts (100%) rename packages/utils/{ => src}/export.ts (90%) rename packages/utils/{ => src}/geometry/geometry.ts (99%) rename packages/utils/{ => src}/geometry/shape.ts (98%) rename packages/utils/{ => src}/withinBounds.ts (92%) rename packages/utils/{ => tests}/export.test.ts (93%) rename packages/utils/{geometry => tests}/geometry.test.ts (97%) rename packages/utils/{ => tests}/utils.unmocked.test.ts (88%) rename packages/utils/{ => tests}/withinBounds.test.ts (97%) diff --git a/packages/excalidraw/tests/scene/export.test.ts b/packages/excalidraw/tests/scene/export.test.ts index a535035dc..d13ac7311 100644 --- a/packages/excalidraw/tests/scene/export.test.ts +++ b/packages/excalidraw/tests/scene/export.test.ts @@ -6,7 +6,7 @@ import { rectangleWithLinkFixture, } from "../fixtures/elementFixture"; import { API } from "../helpers/api"; -import { exportToCanvas, exportToSvg } from "../../../utils/export"; +import { exportToCanvas, exportToSvg } from "../../../utils/src/export"; import { FRAME_STYLE } from "../../constants"; import { prepareElementsForExport } from "../../data"; diff --git a/packages/utils/index.ts b/packages/utils/index.ts index 2abce2791..ec7c97af5 100644 --- a/packages/utils/index.ts +++ b/packages/utils/index.ts @@ -1,6 +1,6 @@ -export * from "./export"; -export * from "./withinBounds"; -export * from "./bbox"; -export * from "./collision"; -export * from "./geometry/shape"; -export * from "./geometry/geometry"; +export * from "./src/export"; +export * from "./src/withinBounds"; +export * from "./src/bbox"; +export * from "./src/collision"; +export * from "./src/geometry/shape"; +export * from "./src/geometry/geometry"; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1168c527..12bd8a2b5 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -64,6 +64,7 @@ "@babel/preset-typescript": "7.18.6", "babel-loader": "8.2.5", "babel-plugin-transform-class-properties": "6.24.1", + "chokidar": "3.6.0", "cross-env": "7.0.3", "css-loader": "6.7.1", "file-loader": "6.2.0", @@ -79,6 +80,7 @@ "scripts": { "gen:types": "rm -rf types && tsc", "build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js", + "build:src": "rm -rf dist && node ../../scripts/buildUtils.js", "build:esm": "rm -rf dist && node ../../scripts/buildUtils.js && yarn gen:types", "build:umd:withAnalyzer": "cross-env NODE_ENV=production ANALYZER=true webpack --config webpack.prod.config.js", "clear": "rm -rf dist", diff --git a/packages/utils/bbox.ts b/packages/utils/src/bbox.ts similarity index 91% rename from packages/utils/bbox.ts rename to packages/utils/src/bbox.ts index e662a5a8c..0b3df4681 100644 --- a/packages/utils/bbox.ts +++ b/packages/utils/src/bbox.ts @@ -1,5 +1,5 @@ -import type { Bounds } from "../excalidraw/element/bounds"; -import type { Point } from "../excalidraw/types"; +import type { Bounds } from "../../excalidraw/element/bounds"; +import type { Point } from "../../excalidraw/types"; export type LineSegment = [Point, Point]; @@ -17,6 +17,7 @@ export function crossProduct(a: Point, b: Point) { } export function doBBoxesIntersect(a: Bounds, b: Bounds) { + console.log("HI"); return a[0] <= b[2] && a[2] >= b[0] && a[1] <= b[3] && a[3] >= b[1]; } diff --git a/packages/utils/collision.ts b/packages/utils/src/collision.ts similarity index 100% rename from packages/utils/collision.ts rename to packages/utils/src/collision.ts diff --git a/packages/utils/export.ts b/packages/utils/src/export.ts similarity index 90% rename from packages/utils/export.ts rename to packages/utils/src/export.ts index d6a34da90..db33339cf 100644 --- a/packages/utils/export.ts +++ b/packages/utils/src/export.ts @@ -1,23 +1,23 @@ import { exportToCanvas as _exportToCanvas, exportToSvg as _exportToSvg, -} from "../excalidraw/scene/export"; -import { getDefaultAppState } from "../excalidraw/appState"; -import type { AppState, BinaryFiles } from "../excalidraw/types"; +} from "../../excalidraw/scene/export"; +import { getDefaultAppState } from "../../excalidraw/appState"; +import type { AppState, BinaryFiles } from "../../excalidraw/types"; import type { ExcalidrawElement, ExcalidrawFrameLikeElement, NonDeleted, -} from "../excalidraw/element/types"; -import { restore } from "../excalidraw/data/restore"; -import { MIME_TYPES } from "../excalidraw/constants"; -import { encodePngMetadata } from "../excalidraw/data/image"; -import { serializeAsJSON } from "../excalidraw/data/json"; +} from "../../excalidraw/element/types"; +import { restore } from "../../excalidraw/data/restore"; +import { MIME_TYPES } from "../../excalidraw/constants"; +import { encodePngMetadata } from "../../excalidraw/data/image"; +import { serializeAsJSON } from "../../excalidraw/data/json"; import { copyBlobToClipboardAsPng, copyTextToSystemClipboard, copyToClipboard, -} from "../excalidraw/clipboard"; +} from "../../excalidraw/clipboard"; export { MIME_TYPES }; @@ -170,7 +170,7 @@ export const exportToSvg = async ({ exportPadding?: number; renderEmbeddables?: boolean; }): Promise => { - console.info("HIIII FROM UTILS WORKSPACE"); + console.info("Watching exportToSVG :)"); const { elements: restoredElements, appState: restoredAppState } = restore( { elements, appState }, diff --git a/packages/utils/geometry/geometry.ts b/packages/utils/src/geometry/geometry.ts similarity index 99% rename from packages/utils/geometry/geometry.ts rename to packages/utils/src/geometry/geometry.ts index 4216fe0eb..fe0db6a41 100644 --- a/packages/utils/geometry/geometry.ts +++ b/packages/utils/src/geometry/geometry.ts @@ -1,4 +1,4 @@ -import { distance2d } from "../../excalidraw/math"; +import { distance2d } from "../../../excalidraw/math"; import type { Point, Line, diff --git a/packages/utils/geometry/shape.ts b/packages/utils/src/geometry/shape.ts similarity index 98% rename from packages/utils/geometry/shape.ts rename to packages/utils/src/geometry/shape.ts index d14456ea4..b000c153f 100644 --- a/packages/utils/geometry/shape.ts +++ b/packages/utils/src/geometry/shape.ts @@ -12,7 +12,7 @@ * to pure shapes */ -import { getElementAbsoluteCoords } from "../../excalidraw/element"; +import { getElementAbsoluteCoords } from "../../../excalidraw/element"; import type { ElementsMap, ExcalidrawDiamondElement, @@ -27,7 +27,7 @@ import type { ExcalidrawRectangleElement, ExcalidrawSelectionElement, ExcalidrawTextElement, -} from "../../excalidraw/element/types"; +} from "../../../excalidraw/element/types"; import { angleToDegrees, close, pointAdd, pointRotate } from "./geometry"; import { pointsOnBezierCurves } from "points-on-curve"; import type { Drawable, Op } from "roughjs/bin/core"; diff --git a/packages/utils/withinBounds.ts b/packages/utils/src/withinBounds.ts similarity index 92% rename from packages/utils/withinBounds.ts rename to packages/utils/src/withinBounds.ts index 02d316243..1ac91ae57 100644 --- a/packages/utils/withinBounds.ts +++ b/packages/utils/src/withinBounds.ts @@ -3,19 +3,19 @@ import type { ExcalidrawFreeDrawElement, ExcalidrawLinearElement, NonDeletedExcalidrawElement, -} from "../excalidraw/element/types"; +} from "../../excalidraw/element/types"; import { isArrowElement, isExcalidrawElement, isFreeDrawElement, isLinearElement, isTextElement, -} from "../excalidraw/element/typeChecks"; -import { isValueInRange, rotatePoint } from "../excalidraw/math"; -import type { Point } from "../excalidraw/types"; -import type { Bounds } from "../excalidraw/element/bounds"; -import { getElementBounds } from "../excalidraw/element/bounds"; -import { arrayToMap } from "../excalidraw/utils"; +} from "../../excalidraw/element/typeChecks"; +import { isValueInRange, rotatePoint } from "../../excalidraw/math"; +import type { Point } from "../../excalidraw/types"; +import type { Bounds } from "../../excalidraw/element/bounds"; +import { getElementBounds } from "../../excalidraw/element/bounds"; +import { arrayToMap } from "../../excalidraw/utils"; type Element = NonDeletedExcalidrawElement; type Elements = readonly NonDeletedExcalidrawElement[]; diff --git a/packages/utils/export.test.ts b/packages/utils/tests/export.test.ts similarity index 93% rename from packages/utils/export.test.ts rename to packages/utils/tests/export.test.ts index 433bbaec1..feb0a9d57 100644 --- a/packages/utils/export.test.ts +++ b/packages/utils/tests/export.test.ts @@ -1,9 +1,9 @@ -import * as utils from "./export"; -import { diagramFactory } from "../excalidraw/tests/fixtures/diagramFixture"; +import * as utils from "../src/export"; +import { diagramFactory } from "../../excalidraw/tests/fixtures/diagramFixture"; import { vi } from "vitest"; -import * as mockedSceneExportUtils from "../excalidraw/scene/export"; +import * as mockedSceneExportUtils from "../../excalidraw/scene/export"; -import { MIME_TYPES } from "../excalidraw/constants"; +import { MIME_TYPES } from "../../excalidraw/constants"; const exportToSvgSpy = vi.spyOn(mockedSceneExportUtils, "exportToSvg"); diff --git a/packages/utils/geometry/geometry.test.ts b/packages/utils/tests/geometry.test.ts similarity index 97% rename from packages/utils/geometry/geometry.test.ts rename to packages/utils/tests/geometry.test.ts index 0a75aae53..8b6c490de 100644 --- a/packages/utils/geometry/geometry.test.ts +++ b/packages/utils/tests/geometry.test.ts @@ -11,8 +11,15 @@ import { pointOnPolyline, pointRightofLine, pointRotate, -} from "./geometry"; -import type { Curve, Ellipse, Line, Point, Polygon, Polyline } from "./shape"; +} from "../src/geometry/geometry"; +import type { + Curve, + Ellipse, + Line, + Point, + Polygon, + Polyline, +} from "../src/geometry/shape"; describe("point and line", () => { const line: Line = [ diff --git a/packages/utils/utils.unmocked.test.ts b/packages/utils/tests/utils.unmocked.test.ts similarity index 88% rename from packages/utils/utils.unmocked.test.ts rename to packages/utils/tests/utils.unmocked.test.ts index ca4727855..832141110 100644 --- a/packages/utils/utils.unmocked.test.ts +++ b/packages/utils/tests/utils.unmocked.test.ts @@ -1,7 +1,10 @@ -import { decodePngMetadata, decodeSvgMetadata } from "../excalidraw/data/image"; -import type { ImportedDataState } from "../excalidraw/data/types"; -import * as utils from "../utils"; -import { API } from "../excalidraw/tests/helpers/api"; +import { + decodePngMetadata, + decodeSvgMetadata, +} from "../../excalidraw/data/image"; +import type { ImportedDataState } from "../../excalidraw/data/types"; +import * as utils from "../dist/prod"; +import { API } from "../../excalidraw/tests/helpers/api"; // 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 diff --git a/packages/utils/withinBounds.test.ts b/packages/utils/tests/withinBounds.test.ts similarity index 97% rename from packages/utils/withinBounds.test.ts rename to packages/utils/tests/withinBounds.test.ts index d0cc5e339..6d0da9d29 100644 --- a/packages/utils/withinBounds.test.ts +++ b/packages/utils/tests/withinBounds.test.ts @@ -1,10 +1,10 @@ -import type { Bounds } from "../excalidraw/element/bounds"; -import { API } from "../excalidraw/tests/helpers/api"; +import type { Bounds } from "../../excalidraw/element/bounds"; +import { API } from "../../excalidraw/tests/helpers/api"; import { elementPartiallyOverlapsWithOrContainsBBox, elementsOverlappingBBox, isElementInsideBBox, -} from "./withinBounds"; +} from "../src/withinBounds"; const makeElement = (x: number, y: number, width: number, height: number) => API.createElement({