move the files to src and tests folders under utils

This commit is contained in:
Aakansha Doshi 2024-05-09 13:30:26 +05:30
parent a76999e9a2
commit 58567dd2b6
13 changed files with 55 additions and 42 deletions

View File

@ -6,7 +6,7 @@ import {
rectangleWithLinkFixture, rectangleWithLinkFixture,
} from "../fixtures/elementFixture"; } from "../fixtures/elementFixture";
import { API } from "../helpers/api"; import { API } from "../helpers/api";
import { exportToCanvas, exportToSvg } from "../../../utils/export"; import { exportToCanvas, exportToSvg } from "../../../utils/src/export";
import { FRAME_STYLE } from "../../constants"; import { FRAME_STYLE } from "../../constants";
import { prepareElementsForExport } from "../../data"; import { prepareElementsForExport } from "../../data";

View File

@ -1,6 +1,6 @@
export * from "./export"; export * from "./src/export";
export * from "./withinBounds"; export * from "./src/withinBounds";
export * from "./bbox"; export * from "./src/bbox";
export * from "./collision"; export * from "./src/collision";
export * from "./geometry/shape"; export * from "./src/geometry/shape";
export * from "./geometry/geometry"; export * from "./src/geometry/geometry";

View File

@ -64,6 +64,7 @@
"@babel/preset-typescript": "7.18.6", "@babel/preset-typescript": "7.18.6",
"babel-loader": "8.2.5", "babel-loader": "8.2.5",
"babel-plugin-transform-class-properties": "6.24.1", "babel-plugin-transform-class-properties": "6.24.1",
"chokidar": "3.6.0",
"cross-env": "7.0.3", "cross-env": "7.0.3",
"css-loader": "6.7.1", "css-loader": "6.7.1",
"file-loader": "6.2.0", "file-loader": "6.2.0",
@ -79,6 +80,7 @@
"scripts": { "scripts": {
"gen:types": "rm -rf types && tsc", "gen:types": "rm -rf types && tsc",
"build:umd": "cross-env NODE_ENV=production webpack --config webpack.prod.config.js", "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: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", "build:umd:withAnalyzer": "cross-env NODE_ENV=production ANALYZER=true webpack --config webpack.prod.config.js",
"clear": "rm -rf dist", "clear": "rm -rf dist",

View File

@ -1,5 +1,5 @@
import type { Bounds } from "../excalidraw/element/bounds"; import type { Bounds } from "../../excalidraw/element/bounds";
import type { Point } from "../excalidraw/types"; import type { Point } from "../../excalidraw/types";
export type LineSegment = [Point, Point]; export type LineSegment = [Point, Point];
@ -17,6 +17,7 @@ export function crossProduct(a: Point, b: Point) {
} }
export function doBBoxesIntersect(a: Bounds, b: Bounds) { 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]; return a[0] <= b[2] && a[2] >= b[0] && a[1] <= b[3] && a[3] >= b[1];
} }

View File

@ -1,23 +1,23 @@
import { import {
exportToCanvas as _exportToCanvas, exportToCanvas as _exportToCanvas,
exportToSvg as _exportToSvg, exportToSvg as _exportToSvg,
} from "../excalidraw/scene/export"; } from "../../excalidraw/scene/export";
import { getDefaultAppState } from "../excalidraw/appState"; import { getDefaultAppState } from "../../excalidraw/appState";
import type { AppState, BinaryFiles } from "../excalidraw/types"; import type { AppState, BinaryFiles } from "../../excalidraw/types";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawFrameLikeElement, ExcalidrawFrameLikeElement,
NonDeleted, NonDeleted,
} from "../excalidraw/element/types"; } from "../../excalidraw/element/types";
import { restore } from "../excalidraw/data/restore"; import { restore } from "../../excalidraw/data/restore";
import { MIME_TYPES } from "../excalidraw/constants"; import { MIME_TYPES } from "../../excalidraw/constants";
import { encodePngMetadata } from "../excalidraw/data/image"; import { encodePngMetadata } from "../../excalidraw/data/image";
import { serializeAsJSON } from "../excalidraw/data/json"; import { serializeAsJSON } from "../../excalidraw/data/json";
import { import {
copyBlobToClipboardAsPng, copyBlobToClipboardAsPng,
copyTextToSystemClipboard, copyTextToSystemClipboard,
copyToClipboard, copyToClipboard,
} from "../excalidraw/clipboard"; } from "../../excalidraw/clipboard";
export { MIME_TYPES }; export { MIME_TYPES };
@ -170,7 +170,7 @@ export const exportToSvg = async ({
exportPadding?: number; exportPadding?: number;
renderEmbeddables?: boolean; renderEmbeddables?: boolean;
}): Promise<SVGSVGElement> => { }): Promise<SVGSVGElement> => {
console.info("HIIII FROM UTILS WORKSPACE"); console.info("Watching exportToSVG :)");
const { elements: restoredElements, appState: restoredAppState } = restore( const { elements: restoredElements, appState: restoredAppState } = restore(
{ elements, appState }, { elements, appState },

View File

@ -1,4 +1,4 @@
import { distance2d } from "../../excalidraw/math"; import { distance2d } from "../../../excalidraw/math";
import type { import type {
Point, Point,
Line, Line,

View File

@ -12,7 +12,7 @@
* to pure shapes * to pure shapes
*/ */
import { getElementAbsoluteCoords } from "../../excalidraw/element"; import { getElementAbsoluteCoords } from "../../../excalidraw/element";
import type { import type {
ElementsMap, ElementsMap,
ExcalidrawDiamondElement, ExcalidrawDiamondElement,
@ -27,7 +27,7 @@ import type {
ExcalidrawRectangleElement, ExcalidrawRectangleElement,
ExcalidrawSelectionElement, ExcalidrawSelectionElement,
ExcalidrawTextElement, ExcalidrawTextElement,
} from "../../excalidraw/element/types"; } from "../../../excalidraw/element/types";
import { angleToDegrees, close, pointAdd, pointRotate } from "./geometry"; import { angleToDegrees, close, pointAdd, pointRotate } from "./geometry";
import { pointsOnBezierCurves } from "points-on-curve"; import { pointsOnBezierCurves } from "points-on-curve";
import type { Drawable, Op } from "roughjs/bin/core"; import type { Drawable, Op } from "roughjs/bin/core";

View File

@ -3,19 +3,19 @@ import type {
ExcalidrawFreeDrawElement, ExcalidrawFreeDrawElement,
ExcalidrawLinearElement, ExcalidrawLinearElement,
NonDeletedExcalidrawElement, NonDeletedExcalidrawElement,
} from "../excalidraw/element/types"; } from "../../excalidraw/element/types";
import { import {
isArrowElement, isArrowElement,
isExcalidrawElement, isExcalidrawElement,
isFreeDrawElement, isFreeDrawElement,
isLinearElement, isLinearElement,
isTextElement, isTextElement,
} from "../excalidraw/element/typeChecks"; } from "../../excalidraw/element/typeChecks";
import { isValueInRange, rotatePoint } from "../excalidraw/math"; import { isValueInRange, rotatePoint } from "../../excalidraw/math";
import type { Point } from "../excalidraw/types"; import type { Point } from "../../excalidraw/types";
import type { Bounds } from "../excalidraw/element/bounds"; import type { Bounds } from "../../excalidraw/element/bounds";
import { getElementBounds } from "../excalidraw/element/bounds"; import { getElementBounds } from "../../excalidraw/element/bounds";
import { arrayToMap } from "../excalidraw/utils"; import { arrayToMap } from "../../excalidraw/utils";
type Element = NonDeletedExcalidrawElement; type Element = NonDeletedExcalidrawElement;
type Elements = readonly NonDeletedExcalidrawElement[]; type Elements = readonly NonDeletedExcalidrawElement[];

View File

@ -1,9 +1,9 @@
import * as utils from "./export"; import * as utils from "../src/export";
import { diagramFactory } from "../excalidraw/tests/fixtures/diagramFixture"; import { diagramFactory } from "../../excalidraw/tests/fixtures/diagramFixture";
import { vi } from "vitest"; 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"); const exportToSvgSpy = vi.spyOn(mockedSceneExportUtils, "exportToSvg");

View File

@ -11,8 +11,15 @@ import {
pointOnPolyline, pointOnPolyline,
pointRightofLine, pointRightofLine,
pointRotate, pointRotate,
} from "./geometry"; } from "../src/geometry/geometry";
import type { Curve, Ellipse, Line, Point, Polygon, Polyline } from "./shape"; import type {
Curve,
Ellipse,
Line,
Point,
Polygon,
Polyline,
} from "../src/geometry/shape";
describe("point and line", () => { describe("point and line", () => {
const line: Line = [ const line: Line = [

View File

@ -1,7 +1,10 @@
import { decodePngMetadata, decodeSvgMetadata } from "../excalidraw/data/image"; import {
import type { ImportedDataState } from "../excalidraw/data/types"; decodePngMetadata,
import * as utils from "../utils"; decodeSvgMetadata,
import { API } from "../excalidraw/tests/helpers/api"; } 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 // 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

@ -1,10 +1,10 @@
import type { Bounds } from "../excalidraw/element/bounds"; import type { Bounds } from "../../excalidraw/element/bounds";
import { API } from "../excalidraw/tests/helpers/api"; import { API } from "../../excalidraw/tests/helpers/api";
import { 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({