From b94c97aafeaf427a42424ccce177768b872ce529 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Fri, 22 Oct 2021 20:03:22 +0100 Subject: [PATCH] moves svg utils into its own package --- package.json | 5 +- packages/core/src/utils/index.d.ts.map | 1 - packages/core/src/utils/index.ts | 1 - packages/core/src/utils/polyfills.d.ts | 1 - packages/core/src/utils/polyfills.d.ts.map | 1 - packages/core/src/utils/svg.d.ts | 15 - packages/core/src/utils/svg.d.ts.map | 1 - packages/core/src/utils/svg.ts | 64 --- packages/core/src/utils/utils.d.ts | 497 --------------------- packages/core/src/utils/utils.d.ts.map | 1 - packages/dev/package.json | 2 +- packages/intersect/package.json | 9 +- packages/svg/LICENSE | 21 + packages/svg/README.md | 3 + packages/svg/package.json | 48 ++ packages/svg/scripts/build.js | 65 +++ packages/svg/scripts/dev.js | 31 ++ packages/svg/scripts/pre-dev.js | 28 ++ packages/svg/src/index.ts | 63 +++ packages/svg/tsconfig.build.json | 24 + packages/svg/tsconfig.json | 18 + packages/vec/package.json | 9 +- 22 files changed, 311 insertions(+), 597 deletions(-) delete mode 100644 packages/core/src/utils/index.d.ts.map delete mode 100644 packages/core/src/utils/polyfills.d.ts delete mode 100644 packages/core/src/utils/polyfills.d.ts.map delete mode 100644 packages/core/src/utils/svg.d.ts delete mode 100644 packages/core/src/utils/svg.d.ts.map delete mode 100644 packages/core/src/utils/svg.ts delete mode 100644 packages/core/src/utils/utils.d.ts delete mode 100644 packages/core/src/utils/utils.d.ts.map create mode 100644 packages/svg/LICENSE create mode 100644 packages/svg/README.md create mode 100644 packages/svg/package.json create mode 100644 packages/svg/scripts/build.js create mode 100644 packages/svg/scripts/dev.js create mode 100644 packages/svg/scripts/pre-dev.js create mode 100644 packages/svg/src/index.ts create mode 100644 packages/svg/tsconfig.build.json create mode 100644 packages/svg/tsconfig.json diff --git a/package.json b/package.json index 8306f2941..7752b1fd1 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,10 @@ "packages/core", "packages/tldraw", "packages/dev", - "packages/www", "packages/vec", - "packages/intersect" + "packages/svg", + "packages/intersect", + "packages/www" ], "scripts": { "test": "jest", diff --git a/packages/core/src/utils/index.d.ts.map b/packages/core/src/utils/index.d.ts.map deleted file mode 100644 index bffadbbed..000000000 --- a/packages/core/src/utils/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,eAAe,KAAK,CAAA"} \ No newline at end of file diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index c29ab98a1..cdb565ef1 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -1,5 +1,4 @@ import { Utils } from './utils' export { Utils } from './utils' -export { Svg } from './svg' export default Utils diff --git a/packages/core/src/utils/polyfills.d.ts b/packages/core/src/utils/polyfills.d.ts deleted file mode 100644 index 4cadf2004..000000000 --- a/packages/core/src/utils/polyfills.d.ts +++ /dev/null @@ -1 +0,0 @@ -//# sourceMappingURL=polyfills.d.ts.map \ No newline at end of file diff --git a/packages/core/src/utils/polyfills.d.ts.map b/packages/core/src/utils/polyfills.d.ts.map deleted file mode 100644 index 3f87e72ea..000000000 --- a/packages/core/src/utils/polyfills.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["polyfills.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/core/src/utils/svg.d.ts b/packages/core/src/utils/svg.d.ts deleted file mode 100644 index 5f4b3948f..000000000 --- a/packages/core/src/utils/svg.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -export declare class Svg { - static ellipse: (A: number[], r: number) => string; - static moveTo: (v: number[]) => string; - static lineTo: (v: number[]) => string; - static line: (a: number[], ...pts: number[][]) => string; - static hLineTo: (v: number[]) => string; - static vLineTo: (v: number[]) => string; - static bezierTo: (A: number[], B: number[], C: number[]) => string; - static arcTo: (C: number[], r: number, A: number[], B: number[]) => string; - static closePath: () => string; - static rectTo: (A: number[]) => string; - static getPointAtLength: (path: SVGPathElement, length: number) => number[]; -} -export default Svg; -//# sourceMappingURL=svg.d.ts.map \ No newline at end of file diff --git a/packages/core/src/utils/svg.d.ts.map b/packages/core/src/utils/svg.d.ts.map deleted file mode 100644 index 8fa1dfadb..000000000 --- a/packages/core/src/utils/svg.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["svg.ts"],"names":[],"mappings":"AAIA,qBAAa,GAAG;IACd,MAAM,CAAC,OAAO,MAAO,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,CAIhD;IAED,MAAM,CAAC,MAAM,MAAO,MAAM,EAAE,KAAG,MAAM,CAEpC;IAED,MAAM,CAAC,MAAM,MAAO,MAAM,EAAE,KAAG,MAAM,CAEpC;IAED,MAAM,CAAC,IAAI,MAAO,MAAM,EAAE,UAAU,MAAM,EAAE,EAAE,KAAG,MAAM,CAEtD;IAED,MAAM,CAAC,OAAO,MAAO,MAAM,EAAE,KAAG,MAAM,CAErC;IAED,MAAM,CAAC,OAAO,MAAO,MAAM,EAAE,KAAG,MAAM,CAErC;IAED,MAAM,CAAC,QAAQ,MAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,KAAG,MAAM,CAEhE;IAED,MAAM,CAAC,KAAK,MAAO,MAAM,EAAE,KAAK,MAAM,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,KAAG,MAAM,CAYxE;IAED,MAAM,CAAC,SAAS,QAAO,MAAM,CAE5B;IAED,MAAM,CAAC,MAAM,MAAO,MAAM,EAAE,KAAG,MAAM,CAEpC;IAED,MAAM,CAAC,gBAAgB,SAAU,cAAc,UAAU,MAAM,KAAG,MAAM,EAAE,CAGzE;CACF;AAED,eAAe,GAAG,CAAA"} \ No newline at end of file diff --git a/packages/core/src/utils/svg.ts b/packages/core/src/utils/svg.ts deleted file mode 100644 index b8e6aefb2..000000000 --- a/packages/core/src/utils/svg.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Utils } from './utils' - -// General - -export class Svg { - static ellipse = (A: number[], r: number): string => { - return `M ${A[0] - r},${A[1]} - a ${r},${r} 0 1,0 ${r * 2},0 - a ${r},${r} 0 1,0 -${r * 2},0 ` - } - - static moveTo = (v: number[]): string => { - return `M ${v[0]},${v[1]} ` - } - - static lineTo = (v: number[]): string => { - return `L ${v[0]},${v[1]} ` - } - - static line = (a: number[], ...pts: number[][]): string => { - return Svg.moveTo(a) + pts.map((p): string => Svg.lineTo(p)).join() - } - - static hLineTo = (v: number[]): string => { - return `H ${v[0]},${v[1]} ` - } - - static vLineTo = (v: number[]): string => { - return `V ${v[0]},${v[1]} ` - } - - static bezierTo = (A: number[], B: number[], C: number[]): string => { - return `C ${A[0]},${A[1]} ${B[0]},${B[1]} ${C[0]},${C[1]} ` - } - - static arcTo = (C: number[], r: number, A: number[], B: number[]): string => { - return [ - Svg.moveTo(A), - 'A', - r, - r, - 0, - 0, - Utils.getArcLength(C, r, A, B) > 0 ? '1' : '0', - B[0], - B[1], - ].join(' ') - } - - static closePath = (): string => { - return 'Z' - } - - static rectTo = (A: number[]): string => { - return ['R', A[0], A[1]].join(' ') - } - - static getPointAtLength = (path: SVGPathElement, length: number): number[] => { - const point = path.getPointAtLength(length) - return [point.x, point.y] - } -} - -export default Svg diff --git a/packages/core/src/utils/utils.d.ts b/packages/core/src/utils/utils.d.ts deleted file mode 100644 index 601f8e7dc..000000000 --- a/packages/core/src/utils/utils.d.ts +++ /dev/null @@ -1,497 +0,0 @@ -import type React from 'react'; -import { TLBezierCurveSegment, TLBounds, TLBoundsCorner, TLBoundsEdge } from '../types'; -import './polyfills'; -import type { TLBoundsWithCenter } from '+index'; -export declare class Utils { - static filterObject(obj: T, fn: (entry: Entry, i?: number, arr?: Entry[]) => boolean): Partial; - static deepMerge: (target: T, patch: any) => T; - /** - * Linear interpolation betwen two numbers. - * @param y1 - * @param y2 - * @param mu - */ - static lerp(y1: number, y2: number, mu: number): number; - /** - * Linear interpolation between two colors. - * - * ### Example - * - *```ts - * lerpColor("#000000", "#0099FF", .25) - *``` - */ - static lerpColor(color1: string, color2: string, factor?: number): string; - /** - * Modulate a value between two ranges. - * @param value - * @param rangeA from [low, high] - * @param rangeB to [low, high] - * @param clamp - */ - static modulate(value: number, rangeA: number[], rangeB: number[], clamp?: boolean): number; - /** - * Clamp a value into a range. - * @param n - * @param min - */ - static clamp(n: number, min: number): number; - static clamp(n: number, min: number, max: number): number; - static compress(s: string): string; - static decompress(s: string): string; - /** - * Recursively clone an object or array. - * @param obj - */ - static deepClone(obj: T): T; - /** - * Seeded random number generator, using [xorshift](https://en.wikipedia.org/wiki/Xorshift). - * The result will always be betweeen -1 and 1. - * - * Adapted from [seedrandom](https://github.com/davidbau/seedrandom). - */ - static rng(seed?: string): () => number; - static getRectangleSides(point: number[], size: number[], rotation?: number): [string, number[][]][]; - static getBoundsSides(bounds: TLBounds): [string, number[][]][]; - static shallowEqual>(objA: T, objB: T): boolean; - /** - * Get the outer of between a circle and a point. - * @param C The circle's center. - * @param r The circle's radius. - * @param P The point. - * @param side - */ - static getCircleTangentToPoint(C: number[], r: number, P: number[], side: number): number[] | null; - /** - * Get outer tangents of two circles. - * @param x0 - * @param y0 - * @param r0 - * @param x1 - * @param y1 - * @param r1 - * @returns [lx0, ly0, lx1, ly1, rx0, ry0, rx1, ry1] - */ - static getOuterTangentsOfCircles(C0: number[], r0: number, C1: number[], r1: number): number[][] | null; - /** - * Get the closest point on the perimeter of a circle to a given point. - * @param C The circle's center. - * @param r The circle's radius. - * @param P The point. - */ - static getClosestPointOnCircle(C: number[], r: number, P: number[]): number[]; - /** - * Get a circle from three points. - * @param A - * @param B - * @param C - * @returns [x, y, r] - */ - static circleFromThreePoints(A: number[], B: number[], C: number[]): number[]; - /** - * Find the approximate perimeter of an ellipse. - * @param rx - * @param ry - */ - static perimeterOfEllipse(rx: number, ry: number): number; - /** - * Get the short angle distance between two angles. - * @param a0 - * @param a1 - */ - static shortAngleDist(a0: number, a1: number): number; - /** - * Get the long angle distance between two angles. - * @param a0 - * @param a1 - */ - static longAngleDist(a0: number, a1: number): number; - /** - * Interpolate an angle between two angles. - * @param a0 - * @param a1 - * @param t - */ - static lerpAngles(a0: number, a1: number, t: number): number; - /** - * Get the short distance between two angles. - * @param a0 - * @param a1 - */ - static angleDelta(a0: number, a1: number): number; - /** - * Get the "sweep" or short distance between two points on a circle's perimeter. - * @param C - * @param A - * @param B - */ - static getSweep(C: number[], A: number[], B: number[]): number; - /** - * Rotate a point around a center. - * @param x The x-axis coordinate of the point. - * @param y The y-axis coordinate of the point. - * @param cx The x-axis coordinate of the point to rotate round. - * @param cy The y-axis coordinate of the point to rotate round. - * @param angle The distance (in radians) to rotate. - */ - static rotatePoint(A: number[], B: number[], angle: number): number[]; - /** - * Clamp radians within 0 and 2PI - * @param r - */ - static clampRadians(r: number): number; - /** - * Clamp rotation to even segments. - * @param r - * @param segments - */ - static snapAngleToSegments(r: number, segments: number): number; - /** - * Is angle c between angles a and b? - * @param a - * @param b - * @param c - */ - static isAngleBetween(a: number, b: number, c: number): boolean; - /** - * Convert degrees to radians. - * @param d - */ - static degreesToRadians(d: number): number; - /** - * Convert radians to degrees. - * @param r - */ - static radiansToDegrees(r: number): number; - /** - * Get the length of an arc between two points on a circle's perimeter. - * @param C - * @param r - * @param A - * @param B - */ - static getArcLength(C: number[], r: number, A: number[], B: number[]): number; - /** - * Get a dash offset for an arc, based on its length. - * @param C - * @param r - * @param A - * @param B - * @param step - */ - static getArcDashOffset(C: number[], r: number, A: number[], B: number[], step: number): number; - /** - * Get a dash offset for an ellipse, based on its length. - * @param A - * @param step - */ - static getEllipseDashOffset(A: number[], step: number): number; - /** - * Get bezier curve segments that pass through an array of points. - * @param points - * @param tension - */ - static getTLBezierCurveSegments(points: number[][], tension?: number): TLBezierCurveSegment[]; - /** - * Find a point along a curve segment, via pomax. - * @param t - * @param points [cpx1, cpy1, cpx2, cpy2, px, py][] - */ - static computePointOnCurve(t: number, points: number[][]): number[]; - /** - * Evaluate a 2d cubic bezier at a point t on the x axis. - * @param tx - * @param x1 - * @param y1 - * @param x2 - * @param y2 - */ - static cubicBezier(tx: number, x1: number, y1: number, x2: number, y2: number): number; - /** - * Get a bezier curve data for a spline that fits an array of points. - * @param points An array of points formatted as [x, y] - * @param k Tension - */ - static getSpline(pts: number[][], k?: number): { - cp1x: number; - cp1y: number; - cp2x: number; - cp2y: number; - px: number; - py: number; - }[]; - /** - * Get a bezier curve data for a spline that fits an array of points. - * @param pts - * @param tension - * @param isClosed - * @param numOfSegments - */ - static getCurvePoints(pts: number[][], tension?: number, isClosed?: boolean, numOfSegments?: number): number[][]; - /** - * Simplify a line (using Ramer-Douglas-Peucker algorithm). - * @param points An array of points as [x, y, ...][] - * @param tolerance The minimum line distance (also called epsilon). - * @returns Simplified array as [x, y, ...][] - */ - static simplify(points: number[][], tolerance?: number): number[][]; - /** - * Get whether a point is inside of a circle. - * @param A - * @param b - * @returns - */ - static pointInCircle(A: number[], C: number[], r: number): boolean; - /** - * Get whether a point is inside of an ellipse. - * @param point - * @param center - * @param rx - * @param ry - * @param rotation - * @returns - */ - static pointInEllipse(A: number[], C: number[], rx: number, ry: number, rotation?: number): boolean; - /** - * Get whether a point is inside of a rectangle. - * @param point - * @param size - */ - static pointInRect(point: number[], size: number[]): boolean; - static pointInPolygon(p: number[], points: number[][]): boolean; - /** - * Expand a bounding box by a delta. - * - * ### Example - * - *```ts - * expandBounds(myBounds, [100, 100]) - *``` - */ - static expandBounds(bounds: TLBounds, delta: number): TLBounds; - /** - * Get whether a point is inside of a bounds. - * @param A - * @param b - * @returns - */ - static pointInBounds(A: number[], b: TLBounds): boolean; - /** - * Get whether two bounds collide. - * @param a Bounds - * @param b Bounds - * @returns - */ - static boundsCollide(a: TLBounds, b: TLBounds): boolean; - /** - * Get whether the bounds of A contain the bounds of B. A perfect match will return true. - * @param a Bounds - * @param b Bounds - * @returns - */ - static boundsContain(a: TLBounds, b: TLBounds): boolean; - /** - * Get whether the bounds of A are contained by the bounds of B. - * @param a Bounds - * @param b Bounds - * @returns - */ - static boundsContained(a: TLBounds, b: TLBounds): boolean; - /** - * Get whether two bounds are identical. - * @param a Bounds - * @param b Bounds - * @returns - */ - static boundsAreEqual(a: TLBounds, b: TLBounds): boolean; - /** - * Find a bounding box from an array of points. - * @param points - * @param rotation (optional) The bounding box's rotation. - */ - static getBoundsFromPoints(points: number[][], rotation?: number): TLBounds; - /** - * Center a bounding box around a given point. - * @param bounds - * @param center - */ - static centerBounds(bounds: TLBounds, point: number[]): TLBounds; - /** - * Move a bounding box without recalculating it. - * @param bounds - * @param delta - * @returns - */ - static translateBounds(bounds: TLBounds, delta: number[]): TLBounds; - /** - * Rotate a bounding box. - * @param bounds - * @param center - * @param rotation - */ - static rotateBounds(bounds: TLBounds, center: number[], rotation: number): TLBounds; - /** - * Get the rotated bounds of an ellipse. - * @param x - * @param y - * @param rx - * @param ry - * @param rotation - */ - static getRotatedEllipseBounds(x: number, y: number, rx: number, ry: number, rotation?: number): TLBounds; - /** - * Get a bounding box that includes two bounding boxes. - * @param a Bounding box - * @param b Bounding box - * @returns - */ - static getExpandedBounds(a: TLBounds, b: TLBounds): TLBounds; - /** - * Get the common bounds of a group of bounds. - * @returns - */ - static getCommonBounds(bounds: TLBounds[]): TLBounds; - static getRotatedCorners(b: TLBounds, rotation?: number): number[][]; - static getTransformedBoundingBox(bounds: TLBounds, handle: TLBoundsCorner | TLBoundsEdge | 'center', delta: number[], rotation?: number, isAspectRatioLocked?: boolean): TLBounds & { - scaleX: number; - scaleY: number; - }; - static getTransformAnchor(type: TLBoundsEdge | TLBoundsCorner, isFlippedX: boolean, isFlippedY: boolean): TLBoundsCorner | TLBoundsEdge; - /** - * Get the relative bounds (usually a child) within a transformed bounding box. - * @param bounds - * @param initialBounds - * @param initialShapeBounds - * @param isFlippedX - * @param isFlippedY - */ - static getRelativeTransformedBoundingBox(bounds: TLBounds, initialBounds: TLBounds, initialShapeBounds: TLBounds, isFlippedX: boolean, isFlippedY: boolean): TLBounds; - /** - * Get the size of a rotated box. - * @param size : ; - * @param rotation - */ - static getRotatedSize(size: number[], rotation: number): number[]; - /** - * Get the center of a bounding box. - * @param bounds - */ - static getBoundsCenter(bounds: TLBounds): number[]; - /** - * Get a bounding box with a midX and midY. - * @param bounds - */ - static getBoundsWithCenter(bounds: TLBounds): TLBounds & { - midX: number; - midY: number; - }; - static getSnapPoints: (bounds: any, others: TLBoundsWithCenter[], snapDistance: number) => { - offset: number[]; - snapLines: number[][][]; - }; - /** - * - * - * ### Example - * - *```ts - * example - *``` - */ - static removeDuplicatePoints(points: number[][]): number[][]; - /** - // points = - - - /** - * Get a value from a cache (a WeakMap), filling the value if it is not present. - * - * ### Example - * - *```ts - * getFromCache(boundsCache, shape, (cache) => cache.set(shape, "value")) - *``` - */ - static getFromCache(cache: WeakMap, item: I, getNext: () => V): V; - /** - * Get a unique string id. - */ - static uniqueId(a?: string): string; - /** - * Shuffle the contents of an array. - * @param arr - * @param offset - */ - static rotateArray(arr: T[], offset: number): T[]; - /** - * Deep compare two arrays. - * @param a - * @param b - */ - static deepCompareArrays(a: T[], b: T[]): boolean; - /** - * Deep compare any values. - * @param a - * @param b - */ - static deepCompare(a: T, b: T): boolean; - /** - * Find whether two arrays intersect. - * @param a - * @param b - * @param fn An optional function to apply to the items of a; will check if b includes the result. - */ - static arrsIntersect(a: T[], b: K[], fn?: (item: K) => T): boolean; - static arrsIntersect(a: T[], b: T[]): boolean; - /** - * Get the unique values from an array of strings or numbers. - * @param items - */ - static uniqueArray(...items: T[]): T[]; - /** - * Convert a set to an array. - * @param set - */ - static setToArray(set: Set): T[]; - /** - * Debounce a function. - */ - static debounce void>(fn: T, ms?: number): (...args: Parameters) => void; - static TRIM_NUMBERS: RegExp; - /** - * Turn an array of points into a path of quadradic curves. - * @param stroke ; - */ - static getSvgPathFromStroke(points: number[][], closed?: boolean): string; - /** - * Get balanced dash-strokearray and dash-strokeoffset properties for a path of a given length. - * @param length The length of the path. - * @param strokeWidth The shape's stroke-width property. - * @param style The stroke's style: "dashed" or "dotted" (default "dashed"). - * @param snap An interval for dashes (e.g. 4 will produce arrays with 4, 8, 16, etc dashes). - */ - static getPerfectDashProps(length: number, strokeWidth: number, style: 'dashed' | 'dotted' | string, snap?: number, outset?: boolean): { - strokeDasharray: string; - strokeDashoffset: string; - }; - static isMobileSize(): boolean; - static isMobileSafari(): boolean; - static throttle any>(func: T, limit: number): (...args: Parameters) => ReturnType; - /** - * Find whether the current display is a touch display. - */ - /** - * Find whether the current device is a Mac / iOS / iPadOS. - */ - static isDarwin(): boolean; - /** - * Get whether an event is command (mac) or control (pc). - * @param e - */ - static metaKey(e: KeyboardEvent | React.KeyboardEvent): boolean; -} -export default Utils; -declare type Entry = { - [K in keyof T]: [K, T[K]]; -}[keyof T]; -//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/packages/core/src/utils/utils.d.ts.map b/packages/core/src/utils/utils.d.ts.map deleted file mode 100644 index f3495b844..000000000 --- a/packages/core/src/utils/utils.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACR,cAAc,EAGd,YAAY,EACb,MAAM,UAAU,CAAA;AAEjB,OAAO,aAAa,CAAA;AACpB,OAAO,KAAK,EAAS,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAEvD,qBAAa,KAAK;IAKhB,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,MAAM,EAClC,GAAG,EAAE,CAAC,EACN,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CAAC,cAAc;IASrB,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EAC7C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC;IAmB5C;;OAEG;IAOH;;OAEG;IACH,MAAM,CAAC,QAAQ,IAAI,OAAO;IAI1B;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,GAAG,KAAK,CAAC,aAAa,GAAG,OAAO;CAGhE;AAED,eAAe,KAAK,CAAA;AAIpB,aAAK,KAAK,CAAC,CAAC,IAAI;KACb,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1B,CAAC,MAAM,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/packages/dev/package.json b/packages/dev/package.json index e11e79504..327c85f48 100644 --- a/packages/dev/package.json +++ b/packages/dev/package.json @@ -40,4 +40,4 @@ "typescript": "4.2.3" }, "gitHead": "a7dac0f83ad998e205c2aab58182cb4ba4e099a6" -} +} \ No newline at end of file diff --git a/packages/intersect/package.json b/packages/intersect/package.json index 5fc736743..9018feb79 100644 --- a/packages/intersect/package.json +++ b/packages/intersect/package.json @@ -2,7 +2,7 @@ "name": "@tldraw/intersect", "version": "0.0.126", "private": false, - "description": "A tiny little drawing app (intersect)", + "description": "Intersection utilities for tldraw.", "author": "@steveruizok", "repository": { "type": "git", @@ -21,7 +21,7 @@ "typings": "./dist/types/index.d.ts", "scripts": { "start:pre": "node scripts/pre-dev && yarn types:pre", - "start": "node scripts/dev & yarn types:dev", + "start:utils": "node scripts/dev & yarn types:dev", "build": "node scripts/build && yarn types:build", "types:pre": "tsc", "types:dev": "tsc --watch", @@ -33,8 +33,6 @@ "docs:watch": "typedoc --watch" }, "devDependencies": { - "@babel/core": "^7.15.5", - "@babel/preset-env": "^7.15.4", "@types/jest": "^27.0.1", "@types/node": "^16.7.10", "@typescript-eslint/eslint-plugin": "^4.30.0", @@ -42,7 +40,6 @@ "esbuild": "^0.13.8", "eslint": "^7.32.0", "lerna": "^4.0.0", - "ts-node": "^10.2.1", "tslib": "^2.3.1", "typedoc": "^0.22.3", "typescript": "^4.4.2" @@ -51,4 +48,4 @@ "@tldraw/vec": "^0.0.126" }, "gitHead": "5cb031ddc264846ec6732d7179511cddea8ef034" -} +} \ No newline at end of file diff --git a/packages/svg/LICENSE b/packages/svg/LICENSE new file mode 100644 index 000000000..bdcc8b850 --- /dev/null +++ b/packages/svg/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Stephen Ruiz Ltd + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/svg/README.md b/packages/svg/README.md new file mode 100644 index 000000000..9ff03c9d1 --- /dev/null +++ b/packages/svg/README.md @@ -0,0 +1,3 @@ +# @tldraw/svg + +SVG utilities. diff --git a/packages/svg/package.json b/packages/svg/package.json new file mode 100644 index 000000000..522f3c852 --- /dev/null +++ b/packages/svg/package.json @@ -0,0 +1,48 @@ +{ + "name": "@tldraw/svg", + "version": "0.0.126", + "private": false, + "description": "SVG utilities for tldraw.", + "author": "@steveruizok", + "repository": { + "type": "git", + "url": "git+https://github.com/tldraw/tldraw.git", + "directory": "packages/vec" + }, + "license": "MIT", + "keywords": [], + "files": [ + "dist/**/*" + ], + "sideEffects": false, + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", + "typings": "./dist/types/index.d.ts", + "scripts": { + "start:pre": "node scripts/pre-dev && yarn types:pre", + "start:utils": "node scripts/dev & yarn types:dev", + "build": "node scripts/build && yarn types:build", + "types:pre": "tsc", + "types:dev": "tsc --watch", + "types:build": "tsc --project tsconfig.build.json", + "lint": "eslint src/ --ext .ts,.tsx", + "clean": "rm -rf dist", + "ts-node": "ts-node", + "docs": "typedoc", + "docs:watch": "typedoc --watch" + }, + "devDependencies": { + "@types/jest": "^27.0.1", + "@types/node": "^16.7.10", + "@typescript-eslint/eslint-plugin": "^4.30.0", + "@typescript-eslint/parser": "^4.30.0", + "esbuild": "^0.13.8", + "eslint": "^7.32.0", + "lerna": "^4.0.0", + "tslib": "^2.3.1", + "typedoc": "^0.22.3", + "typescript": "^4.4.2" + }, + "gitHead": "5cb031ddc264846ec6732d7179511cddea8ef034" +} \ No newline at end of file diff --git a/packages/svg/scripts/build.js b/packages/svg/scripts/build.js new file mode 100644 index 000000000..4fbe922f6 --- /dev/null +++ b/packages/svg/scripts/build.js @@ -0,0 +1,65 @@ +/* eslint-disable */ +const fs = require('fs') +const esbuild = require('esbuild') +const { gzip } = require('zlib') + +const name = process.env.npm_package_name || '' + +async function main() { + if (fs.existsSync('./dist')) { + fs.rmSync('./dist', { recursive: true }, (e) => { + if (e) { + throw e + } + }) + } + + try { + esbuild.buildSync({ + entryPoints: ['./src/index.ts'], + outdir: 'dist/cjs', + minify: true, + bundle: true, + format: 'cjs', + target: 'es6', + jsxFactory: 'React.createElement', + jsxFragment: 'React.Fragment', + tsconfig: './tsconfig.build.json', + external: ['react', 'react-dom'], + }) + + const esmResult = esbuild.buildSync({ + entryPoints: ['./src/index.ts'], + outdir: 'dist/esm', + minify: true, + bundle: true, + format: 'esm', + target: 'es6', + tsconfig: './tsconfig.build.json', + jsxFactory: 'React.createElement', + jsxFragment: 'React.Fragment', + external: ['react', 'react-dom'], + metafile: true, + }) + + let esmSize = 0 + Object.values(esmResult.metafile.outputs).forEach((output) => { + esmSize += output.bytes + }) + + fs.readFile('./dist/esm/index.js', (_err, data) => { + gzip(data, (_err, result) => { + console.log( + `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${( + result.length / 1000 + ).toFixed(2)}kb minified)` + ) + }) + }) + } catch (e) { + console.log(`× ${name}: Build failed due to an error.`) + console.log(e) + } +} + +main() diff --git a/packages/svg/scripts/dev.js b/packages/svg/scripts/dev.js new file mode 100644 index 000000000..050de844d --- /dev/null +++ b/packages/svg/scripts/dev.js @@ -0,0 +1,31 @@ +/* eslint-disable */ +const esbuild = require('esbuild') + +const name = process.env.npm_package_name || '' + +async function main() { + esbuild.build({ + entryPoints: ['./src/index.ts'], + outdir: 'dist/cjs', + minify: false, + bundle: true, + format: 'cjs', + target: 'es6', + jsxFactory: 'React.createElement', + jsxFragment: 'React.Fragment', + tsconfig: './tsconfig.json', + external: ['react', 'react-dom'], + incremental: true, + watch: { + onRebuild(error) { + if (error) { + console.log(`× ${name}: An error in prevented the rebuild.`) + return + } + console.log(`✔ ${name}: Rebuilt.`) + }, + }, + }) +} + +main() diff --git a/packages/svg/scripts/pre-dev.js b/packages/svg/scripts/pre-dev.js new file mode 100644 index 000000000..531792366 --- /dev/null +++ b/packages/svg/scripts/pre-dev.js @@ -0,0 +1,28 @@ +/* eslint-disable */ +const fs = require('fs') +const esbuild = require('esbuild') + +async function main() { + if (fs.existsSync('./dist')) { + fs.rmSync('./dist', { recursive: true }, (e) => { + if (e) { + throw e + } + }) + } + + esbuild.build({ + entryPoints: ['./src/index.ts'], + outdir: 'dist/cjs', + minify: false, + bundle: true, + format: 'cjs', + target: 'es6', + jsxFactory: 'React.createElement', + jsxFragment: 'React.Fragment', + tsconfig: './tsconfig.json', + external: ['react', 'react-dom'], + }) +} + +main() diff --git a/packages/svg/src/index.ts b/packages/svg/src/index.ts new file mode 100644 index 000000000..cbb41eb9a --- /dev/null +++ b/packages/svg/src/index.ts @@ -0,0 +1,63 @@ +// General +function angle(A: number[], B: number[]): number { + return Math.atan2(B[1] - A[1], B[0] - A[0]) +} + +function shortAngleDist(A: number, B: number) { + const max = Math.PI * 2 + const da = (B - A) % max + return ((2 * da) % max) - da +} + +function getArcLength(C: number[], r: number, A: number[], B: number[]): number { + return r * (2 * Math.PI) * (shortAngleDist(angle(C, A), angle(C, B)) / (2 * Math.PI)) +} + +export const moveTo = (v: number[]): string => { + return `M ${v} ` +} + +export const lineTo = (...v: number[][]): string => { + return `L ${v.join(' ')} ` +} + +export const hLineTo = (v: number[]): string => { + return `H ${v} ` +} + +export const vLineTo = (v: number[]): string => { + return `V ${v} ` +} + +export const bezierTo = (A: number[], B: number[], C: number[]): string => { + return `C ${A} ${B} ${C} ` +} + +export const arcTo = (C: number[], r: number, A: number[], B: number[]): string => { + return [moveTo(A), 'A', r, r, 0, 0, getArcLength(C, r, A, B) > 0 ? '1' : '0', B[0], B[1]].join( + ' ' + ) +} + +export const rectTo = (A: number[]): string => { + return `R ${A}` +} + +export const ellipse = (A: number[], r: number): string => { + return `M ${A[0] - r},${A[1]} + a ${r},${r} 0 1,0 ${r * 2},0 + a ${r},${r} 0 1,0 -${r * 2},0 ` +} + +export const line = (a: number[], ...pts: number[][]): string => { + return moveTo(a) + lineTo(...pts) +} + +export const closePath = (): string => { + return 'Z' +} + +export const getPointAtLength = (path: SVGPathElement, length: number): number[] => { + const point = path.getPointAtLength(length) + return [point.x, point.y] +} diff --git a/packages/svg/tsconfig.build.json b/packages/svg/tsconfig.build.json new file mode 100644 index 000000000..83bed1073 --- /dev/null +++ b/packages/svg/tsconfig.build.json @@ -0,0 +1,24 @@ +{ + "extends": "./tsconfig.json", + "exclude": [ + "node_modules", + "**/*.test.tsx", + "**/*.test.ts", + "**/*.spec.tsx", + "**/*.spec.ts", + "src/test", + "dist", + "docs" + ], + "compilerOptions": { + "composite": false, + "incremental": false, + "declarationMap": false, + "sourceMap": false, + "emitDeclarationOnly": true, + "paths": { + "@tldraw/vec": ["../vec"] + } + }, + "references": [{ "path": "../vec" }] +} diff --git a/packages/svg/tsconfig.json b/packages/svg/tsconfig.json new file mode 100644 index 000000000..3b9ffa9a3 --- /dev/null +++ b/packages/svg/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["src"], + "exclude": ["node_modules", "dist", "docs"], + "compilerOptions": { + "outDir": "./dist/types", + "rootDir": "src", + "baseUrl": "src", + "paths": { + "@tldraw/vec": ["../vec"] + } + }, + "references": [{ "path": "../vec" }], + "typedocOptions": { + "entryPoints": ["src/index.ts"], + "out": "docs" + } +} diff --git a/packages/vec/package.json b/packages/vec/package.json index f14fb97b9..75845d05e 100644 --- a/packages/vec/package.json +++ b/packages/vec/package.json @@ -2,7 +2,7 @@ "name": "@tldraw/vec", "version": "0.0.126", "private": false, - "description": "A tiny little drawing app (vec)", + "description": "Vector utilities for tldraw.", "author": "@steveruizok", "repository": { "type": "git", @@ -21,7 +21,7 @@ "typings": "./dist/types/index.d.ts", "scripts": { "start:pre": "node scripts/pre-dev && yarn types:pre", - "start": "node scripts/dev & yarn types:dev", + "start:utils": "node scripts/dev & yarn types:dev", "build": "node scripts/build && yarn types:build", "types:pre": "tsc", "types:dev": "tsc --watch", @@ -33,8 +33,6 @@ "docs:watch": "typedoc --watch" }, "devDependencies": { - "@babel/core": "^7.15.5", - "@babel/preset-env": "^7.15.4", "@types/jest": "^27.0.1", "@types/node": "^16.7.10", "@typescript-eslint/eslint-plugin": "^4.30.0", @@ -42,10 +40,9 @@ "esbuild": "^0.13.8", "eslint": "^7.32.0", "lerna": "^4.0.0", - "ts-node": "^10.2.1", "tslib": "^2.3.1", "typedoc": "^0.22.3", "typescript": "^4.4.2" }, "gitHead": "5cb031ddc264846ec6732d7179511cddea8ef034" -} +} \ No newline at end of file