Quellcode durchsuchen

moves svg utils into its own package

main
Steve Ruiz vor 4 Jahren
Ursprung
Commit
b94c97aafe

+ 3
- 2
package.json Datei anzeigen

@@ -13,9 +13,10 @@
13 13
     "packages/core",
14 14
     "packages/tldraw",
15 15
     "packages/dev",
16
-    "packages/www",
17 16
     "packages/vec",
18
-    "packages/intersect"
17
+    "packages/svg",
18
+    "packages/intersect",
19
+    "packages/www"
19 20
   ],
20 21
   "scripts": {
21 22
     "test": "jest",

+ 0
- 1
packages/core/src/utils/index.d.ts.map Datei anzeigen

@@ -1 +0,0 @@
1
-{"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"}

+ 0
- 1
packages/core/src/utils/index.ts Datei anzeigen

@@ -1,5 +1,4 @@
1 1
 import { Utils } from './utils'
2 2
 export { Utils } from './utils'
3
-export { Svg } from './svg'
4 3
 
5 4
 export default Utils

+ 0
- 1
packages/core/src/utils/polyfills.d.ts Datei anzeigen

@@ -1 +0,0 @@
1
-//# sourceMappingURL=polyfills.d.ts.map

+ 0
- 1
packages/core/src/utils/polyfills.d.ts.map Datei anzeigen

@@ -1 +0,0 @@
1
-{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["polyfills.ts"],"names":[],"mappings":""}

+ 0
- 15
packages/core/src/utils/svg.d.ts Datei anzeigen

@@ -1,15 +0,0 @@
1
-export declare class Svg {
2
-    static ellipse: (A: number[], r: number) => string;
3
-    static moveTo: (v: number[]) => string;
4
-    static lineTo: (v: number[]) => string;
5
-    static line: (a: number[], ...pts: number[][]) => string;
6
-    static hLineTo: (v: number[]) => string;
7
-    static vLineTo: (v: number[]) => string;
8
-    static bezierTo: (A: number[], B: number[], C: number[]) => string;
9
-    static arcTo: (C: number[], r: number, A: number[], B: number[]) => string;
10
-    static closePath: () => string;
11
-    static rectTo: (A: number[]) => string;
12
-    static getPointAtLength: (path: SVGPathElement, length: number) => number[];
13
-}
14
-export default Svg;
15
-//# sourceMappingURL=svg.d.ts.map

+ 0
- 1
packages/core/src/utils/svg.d.ts.map Datei anzeigen

@@ -1 +0,0 @@
1
-{"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"}

+ 0
- 64
packages/core/src/utils/svg.ts Datei anzeigen

@@ -1,64 +0,0 @@
1
-import { Utils } from './utils'
2
-
3
-// General
4
-
5
-export class Svg {
6
-  static ellipse = (A: number[], r: number): string => {
7
-    return `M ${A[0] - r},${A[1]}
8
-      a ${r},${r} 0 1,0 ${r * 2},0
9
-      a ${r},${r} 0 1,0 -${r * 2},0 `
10
-  }
11
-
12
-  static moveTo = (v: number[]): string => {
13
-    return `M ${v[0]},${v[1]} `
14
-  }
15
-
16
-  static lineTo = (v: number[]): string => {
17
-    return `L ${v[0]},${v[1]} `
18
-  }
19
-
20
-  static line = (a: number[], ...pts: number[][]): string => {
21
-    return Svg.moveTo(a) + pts.map((p): string => Svg.lineTo(p)).join()
22
-  }
23
-
24
-  static hLineTo = (v: number[]): string => {
25
-    return `H ${v[0]},${v[1]} `
26
-  }
27
-
28
-  static vLineTo = (v: number[]): string => {
29
-    return `V ${v[0]},${v[1]} `
30
-  }
31
-
32
-  static bezierTo = (A: number[], B: number[], C: number[]): string => {
33
-    return `C ${A[0]},${A[1]} ${B[0]},${B[1]} ${C[0]},${C[1]} `
34
-  }
35
-
36
-  static arcTo = (C: number[], r: number, A: number[], B: number[]): string => {
37
-    return [
38
-      Svg.moveTo(A),
39
-      'A',
40
-      r,
41
-      r,
42
-      0,
43
-      0,
44
-      Utils.getArcLength(C, r, A, B) > 0 ? '1' : '0',
45
-      B[0],
46
-      B[1],
47
-    ].join(' ')
48
-  }
49
-
50
-  static closePath = (): string => {
51
-    return 'Z'
52
-  }
53
-
54
-  static rectTo = (A: number[]): string => {
55
-    return ['R', A[0], A[1]].join(' ')
56
-  }
57
-
58
-  static getPointAtLength = (path: SVGPathElement, length: number): number[] => {
59
-    const point = path.getPointAtLength(length)
60
-    return [point.x, point.y]
61
-  }
62
-}
63
-
64
-export default Svg

+ 0
- 497
packages/core/src/utils/utils.d.ts Datei anzeigen

@@ -1,497 +0,0 @@
1
-import type React from 'react';
2
-import { TLBezierCurveSegment, TLBounds, TLBoundsCorner, TLBoundsEdge } from '../types';
3
-import './polyfills';
4
-import type { TLBoundsWithCenter } from '+index';
5
-export declare class Utils {
6
-    static filterObject<T extends object>(obj: T, fn: (entry: Entry<T>, i?: number, arr?: Entry<T>[]) => boolean): Partial<T>;
7
-    static deepMerge: <T>(target: T, patch: any) => T;
8
-    /**
9
-     * Linear interpolation betwen two numbers.
10
-     * @param y1
11
-     * @param y2
12
-     * @param mu
13
-     */
14
-    static lerp(y1: number, y2: number, mu: number): number;
15
-    /**
16
-     * Linear interpolation between two colors.
17
-     *
18
-     * ### Example
19
-     *
20
-     *```ts
21
-     * lerpColor("#000000", "#0099FF", .25)
22
-     *```
23
-     */
24
-    static lerpColor(color1: string, color2: string, factor?: number): string;
25
-    /**
26
-     * Modulate a value between two ranges.
27
-     * @param value
28
-     * @param rangeA from [low, high]
29
-     * @param rangeB to [low, high]
30
-     * @param clamp
31
-     */
32
-    static modulate(value: number, rangeA: number[], rangeB: number[], clamp?: boolean): number;
33
-    /**
34
-     * Clamp a value into a range.
35
-     * @param n
36
-     * @param min
37
-     */
38
-    static clamp(n: number, min: number): number;
39
-    static clamp(n: number, min: number, max: number): number;
40
-    static compress(s: string): string;
41
-    static decompress(s: string): string;
42
-    /**
43
-     * Recursively clone an object or array.
44
-     * @param obj
45
-     */
46
-    static deepClone<T extends unknown>(obj: T): T;
47
-    /**
48
-     * Seeded random number generator, using [xorshift](https://en.wikipedia.org/wiki/Xorshift).
49
-     * The result will always be betweeen -1 and 1.
50
-     *
51
-     * Adapted from [seedrandom](https://github.com/davidbau/seedrandom).
52
-     */
53
-    static rng(seed?: string): () => number;
54
-    static getRectangleSides(point: number[], size: number[], rotation?: number): [string, number[][]][];
55
-    static getBoundsSides(bounds: TLBounds): [string, number[][]][];
56
-    static shallowEqual<T extends Record<string, unknown>>(objA: T, objB: T): boolean;
57
-    /**
58
-     * Get the outer of between a circle and a point.
59
-     * @param C The circle's center.
60
-     * @param r The circle's radius.
61
-     * @param P The point.
62
-     * @param side
63
-     */
64
-    static getCircleTangentToPoint(C: number[], r: number, P: number[], side: number): number[] | null;
65
-    /**
66
-     * Get outer tangents of two circles.
67
-     * @param x0
68
-     * @param y0
69
-     * @param r0
70
-     * @param x1
71
-     * @param y1
72
-     * @param r1
73
-     * @returns [lx0, ly0, lx1, ly1, rx0, ry0, rx1, ry1]
74
-     */
75
-    static getOuterTangentsOfCircles(C0: number[], r0: number, C1: number[], r1: number): number[][] | null;
76
-    /**
77
-     * Get the closest point on the perimeter of a circle to a given point.
78
-     * @param C The circle's center.
79
-     * @param r The circle's radius.
80
-     * @param P The point.
81
-     */
82
-    static getClosestPointOnCircle(C: number[], r: number, P: number[]): number[];
83
-    /**
84
-     * Get a circle from three points.
85
-     * @param A
86
-     * @param B
87
-     * @param C
88
-     * @returns [x, y, r]
89
-     */
90
-    static circleFromThreePoints(A: number[], B: number[], C: number[]): number[];
91
-    /**
92
-     * Find the approximate perimeter of an ellipse.
93
-     * @param rx
94
-     * @param ry
95
-     */
96
-    static perimeterOfEllipse(rx: number, ry: number): number;
97
-    /**
98
-     * Get the short angle distance between two angles.
99
-     * @param a0
100
-     * @param a1
101
-     */
102
-    static shortAngleDist(a0: number, a1: number): number;
103
-    /**
104
-     * Get the long angle distance between two angles.
105
-     * @param a0
106
-     * @param a1
107
-     */
108
-    static longAngleDist(a0: number, a1: number): number;
109
-    /**
110
-     * Interpolate an angle between two angles.
111
-     * @param a0
112
-     * @param a1
113
-     * @param t
114
-     */
115
-    static lerpAngles(a0: number, a1: number, t: number): number;
116
-    /**
117
-     * Get the short distance between two angles.
118
-     * @param a0
119
-     * @param a1
120
-     */
121
-    static angleDelta(a0: number, a1: number): number;
122
-    /**
123
-     * Get the "sweep" or short distance between two points on a circle's perimeter.
124
-     * @param C
125
-     * @param A
126
-     * @param B
127
-     */
128
-    static getSweep(C: number[], A: number[], B: number[]): number;
129
-    /**
130
-     * Rotate a point around a center.
131
-     * @param x The x-axis coordinate of the point.
132
-     * @param y The y-axis coordinate of the point.
133
-     * @param cx The x-axis coordinate of the point to rotate round.
134
-     * @param cy The y-axis coordinate of the point to rotate round.
135
-     * @param angle The distance (in radians) to rotate.
136
-     */
137
-    static rotatePoint(A: number[], B: number[], angle: number): number[];
138
-    /**
139
-     * Clamp radians within 0 and 2PI
140
-     * @param r
141
-     */
142
-    static clampRadians(r: number): number;
143
-    /**
144
-     * Clamp rotation to even segments.
145
-     * @param r
146
-     * @param segments
147
-     */
148
-    static snapAngleToSegments(r: number, segments: number): number;
149
-    /**
150
-     * Is angle c between angles a and b?
151
-     * @param a
152
-     * @param b
153
-     * @param c
154
-     */
155
-    static isAngleBetween(a: number, b: number, c: number): boolean;
156
-    /**
157
-     * Convert degrees to radians.
158
-     * @param d
159
-     */
160
-    static degreesToRadians(d: number): number;
161
-    /**
162
-     * Convert radians to degrees.
163
-     * @param r
164
-     */
165
-    static radiansToDegrees(r: number): number;
166
-    /**
167
-     * Get the length of an arc between two points on a circle's perimeter.
168
-     * @param C
169
-     * @param r
170
-     * @param A
171
-     * @param B
172
-     */
173
-    static getArcLength(C: number[], r: number, A: number[], B: number[]): number;
174
-    /**
175
-     * Get a dash offset for an arc, based on its length.
176
-     * @param C
177
-     * @param r
178
-     * @param A
179
-     * @param B
180
-     * @param step
181
-     */
182
-    static getArcDashOffset(C: number[], r: number, A: number[], B: number[], step: number): number;
183
-    /**
184
-     * Get a dash offset for an ellipse, based on its length.
185
-     * @param A
186
-     * @param step
187
-     */
188
-    static getEllipseDashOffset(A: number[], step: number): number;
189
-    /**
190
-     * Get bezier curve segments that pass through an array of points.
191
-     * @param points
192
-     * @param tension
193
-     */
194
-    static getTLBezierCurveSegments(points: number[][], tension?: number): TLBezierCurveSegment[];
195
-    /**
196
-     * Find a point along a curve segment, via pomax.
197
-     * @param t
198
-     * @param points [cpx1, cpy1, cpx2, cpy2, px, py][]
199
-     */
200
-    static computePointOnCurve(t: number, points: number[][]): number[];
201
-    /**
202
-     * Evaluate a 2d cubic bezier at a point t on the x axis.
203
-     * @param tx
204
-     * @param x1
205
-     * @param y1
206
-     * @param x2
207
-     * @param y2
208
-     */
209
-    static cubicBezier(tx: number, x1: number, y1: number, x2: number, y2: number): number;
210
-    /**
211
-     * Get a bezier curve data for a spline that fits an array of points.
212
-     * @param points An array of points formatted as [x, y]
213
-     * @param k Tension
214
-     */
215
-    static getSpline(pts: number[][], k?: number): {
216
-        cp1x: number;
217
-        cp1y: number;
218
-        cp2x: number;
219
-        cp2y: number;
220
-        px: number;
221
-        py: number;
222
-    }[];
223
-    /**
224
-     * Get a bezier curve data for a spline that fits an array of points.
225
-     * @param pts
226
-     * @param tension
227
-     * @param isClosed
228
-     * @param numOfSegments
229
-     */
230
-    static getCurvePoints(pts: number[][], tension?: number, isClosed?: boolean, numOfSegments?: number): number[][];
231
-    /**
232
-     * Simplify a line (using Ramer-Douglas-Peucker algorithm).
233
-     * @param points An array of points as [x, y, ...][]
234
-     * @param tolerance The minimum line distance (also called epsilon).
235
-     * @returns Simplified array as [x, y, ...][]
236
-     */
237
-    static simplify(points: number[][], tolerance?: number): number[][];
238
-    /**
239
-     * Get whether a point is inside of a circle.
240
-     * @param A
241
-     * @param b
242
-     * @returns
243
-     */
244
-    static pointInCircle(A: number[], C: number[], r: number): boolean;
245
-    /**
246
-     * Get whether a point is inside of an ellipse.
247
-     * @param point
248
-     * @param center
249
-     * @param rx
250
-     * @param ry
251
-     * @param rotation
252
-     * @returns
253
-     */
254
-    static pointInEllipse(A: number[], C: number[], rx: number, ry: number, rotation?: number): boolean;
255
-    /**
256
-     * Get whether a point is inside of a rectangle.
257
-     * @param point
258
-     * @param size
259
-     */
260
-    static pointInRect(point: number[], size: number[]): boolean;
261
-    static pointInPolygon(p: number[], points: number[][]): boolean;
262
-    /**
263
-     * Expand a bounding box by a delta.
264
-     *
265
-     * ### Example
266
-     *
267
-     *```ts
268
-     * expandBounds(myBounds, [100, 100])
269
-     *```
270
-     */
271
-    static expandBounds(bounds: TLBounds, delta: number): TLBounds;
272
-    /**
273
-     * Get whether a point is inside of a bounds.
274
-     * @param A
275
-     * @param b
276
-     * @returns
277
-     */
278
-    static pointInBounds(A: number[], b: TLBounds): boolean;
279
-    /**
280
-     * Get whether two bounds collide.
281
-     * @param a Bounds
282
-     * @param b Bounds
283
-     * @returns
284
-     */
285
-    static boundsCollide(a: TLBounds, b: TLBounds): boolean;
286
-    /**
287
-     * Get whether the bounds of A contain the bounds of B. A perfect match will return true.
288
-     * @param a Bounds
289
-     * @param b Bounds
290
-     * @returns
291
-     */
292
-    static boundsContain(a: TLBounds, b: TLBounds): boolean;
293
-    /**
294
-     * Get whether the bounds of A are contained by the bounds of B.
295
-     * @param a Bounds
296
-     * @param b Bounds
297
-     * @returns
298
-     */
299
-    static boundsContained(a: TLBounds, b: TLBounds): boolean;
300
-    /**
301
-     * Get whether two bounds are identical.
302
-     * @param a Bounds
303
-     * @param b Bounds
304
-     * @returns
305
-     */
306
-    static boundsAreEqual(a: TLBounds, b: TLBounds): boolean;
307
-    /**
308
-     * Find a bounding box from an array of points.
309
-     * @param points
310
-     * @param rotation (optional) The bounding box's rotation.
311
-     */
312
-    static getBoundsFromPoints(points: number[][], rotation?: number): TLBounds;
313
-    /**
314
-     * Center a bounding box around a given point.
315
-     * @param bounds
316
-     * @param center
317
-     */
318
-    static centerBounds(bounds: TLBounds, point: number[]): TLBounds;
319
-    /**
320
-     * Move a bounding box without recalculating it.
321
-     * @param bounds
322
-     * @param delta
323
-     * @returns
324
-     */
325
-    static translateBounds(bounds: TLBounds, delta: number[]): TLBounds;
326
-    /**
327
-     * Rotate a bounding box.
328
-     * @param bounds
329
-     * @param center
330
-     * @param rotation
331
-     */
332
-    static rotateBounds(bounds: TLBounds, center: number[], rotation: number): TLBounds;
333
-    /**
334
-     * Get the rotated bounds of an ellipse.
335
-     * @param x
336
-     * @param y
337
-     * @param rx
338
-     * @param ry
339
-     * @param rotation
340
-     */
341
-    static getRotatedEllipseBounds(x: number, y: number, rx: number, ry: number, rotation?: number): TLBounds;
342
-    /**
343
-     * Get a bounding box that includes two bounding boxes.
344
-     * @param a Bounding box
345
-     * @param b Bounding box
346
-     * @returns
347
-     */
348
-    static getExpandedBounds(a: TLBounds, b: TLBounds): TLBounds;
349
-    /**
350
-     * Get the common bounds of a group of bounds.
351
-     * @returns
352
-     */
353
-    static getCommonBounds(bounds: TLBounds[]): TLBounds;
354
-    static getRotatedCorners(b: TLBounds, rotation?: number): number[][];
355
-    static getTransformedBoundingBox(bounds: TLBounds, handle: TLBoundsCorner | TLBoundsEdge | 'center', delta: number[], rotation?: number, isAspectRatioLocked?: boolean): TLBounds & {
356
-        scaleX: number;
357
-        scaleY: number;
358
-    };
359
-    static getTransformAnchor(type: TLBoundsEdge | TLBoundsCorner, isFlippedX: boolean, isFlippedY: boolean): TLBoundsCorner | TLBoundsEdge;
360
-    /**
361
-     * Get the relative bounds (usually a child) within a transformed bounding box.
362
-     * @param bounds
363
-     * @param initialBounds
364
-     * @param initialShapeBounds
365
-     * @param isFlippedX
366
-     * @param isFlippedY
367
-     */
368
-    static getRelativeTransformedBoundingBox(bounds: TLBounds, initialBounds: TLBounds, initialShapeBounds: TLBounds, isFlippedX: boolean, isFlippedY: boolean): TLBounds;
369
-    /**
370
-     * Get the size of a rotated box.
371
-     * @param size : ;
372
-     * @param rotation
373
-     */
374
-    static getRotatedSize(size: number[], rotation: number): number[];
375
-    /**
376
-     * Get the center of a bounding box.
377
-     * @param bounds
378
-     */
379
-    static getBoundsCenter(bounds: TLBounds): number[];
380
-    /**
381
-     * Get a bounding box with a midX and midY.
382
-     * @param bounds
383
-     */
384
-    static getBoundsWithCenter(bounds: TLBounds): TLBounds & {
385
-        midX: number;
386
-        midY: number;
387
-    };
388
-    static getSnapPoints: (bounds: any, others: TLBoundsWithCenter[], snapDistance: number) => {
389
-        offset: number[];
390
-        snapLines: number[][][];
391
-    };
392
-    /**
393
-     *
394
-     *
395
-     * ### Example
396
-     *
397
-     *```ts
398
-     * example
399
-     *```
400
-     */
401
-    static removeDuplicatePoints(points: number[][]): number[][];
402
-    /**
403
-    // points =
404
-  
405
-  
406
-  /**
407
-   * Get a value from a cache (a WeakMap), filling the value if it is not present.
408
-   *
409
-   * ### Example
410
-   *
411
-   *```ts
412
-   * getFromCache(boundsCache, shape, (cache) => cache.set(shape, "value"))
413
-   *```
414
-   */
415
-    static getFromCache<V, I extends object>(cache: WeakMap<I, V>, item: I, getNext: () => V): V;
416
-    /**
417
-     * Get a unique string id.
418
-     */
419
-    static uniqueId(a?: string): string;
420
-    /**
421
-     * Shuffle the contents of an array.
422
-     * @param arr
423
-     * @param offset
424
-     */
425
-    static rotateArray<T>(arr: T[], offset: number): T[];
426
-    /**
427
-     * Deep compare two arrays.
428
-     * @param a
429
-     * @param b
430
-     */
431
-    static deepCompareArrays<T>(a: T[], b: T[]): boolean;
432
-    /**
433
-     * Deep compare any values.
434
-     * @param a
435
-     * @param b
436
-     */
437
-    static deepCompare<T>(a: T, b: T): boolean;
438
-    /**
439
-     * Find whether two arrays intersect.
440
-     * @param a
441
-     * @param b
442
-     * @param fn An optional function to apply to the items of a; will check if b includes the result.
443
-     */
444
-    static arrsIntersect<T, K>(a: T[], b: K[], fn?: (item: K) => T): boolean;
445
-    static arrsIntersect<T>(a: T[], b: T[]): boolean;
446
-    /**
447
-     * Get the unique values from an array of strings or numbers.
448
-     * @param items
449
-     */
450
-    static uniqueArray<T extends string | number>(...items: T[]): T[];
451
-    /**
452
-     * Convert a set to an array.
453
-     * @param set
454
-     */
455
-    static setToArray<T>(set: Set<T>): T[];
456
-    /**
457
-     * Debounce a function.
458
-     */
459
-    static debounce<T extends (...args: any[]) => void>(fn: T, ms?: number): (...args: Parameters<T>) => void;
460
-    static TRIM_NUMBERS: RegExp;
461
-    /**
462
-     * Turn an array of points into a path of quadradic curves.
463
-     * @param stroke ;
464
-     */
465
-    static getSvgPathFromStroke(points: number[][], closed?: boolean): string;
466
-    /**
467
-     * Get balanced dash-strokearray and dash-strokeoffset properties for a path of a given length.
468
-     * @param length The length of the path.
469
-     * @param strokeWidth The shape's stroke-width property.
470
-     * @param style The stroke's style: "dashed" or "dotted" (default "dashed").
471
-     * @param snap An interval for dashes (e.g. 4 will produce arrays with 4, 8, 16, etc dashes).
472
-     */
473
-    static getPerfectDashProps(length: number, strokeWidth: number, style: 'dashed' | 'dotted' | string, snap?: number, outset?: boolean): {
474
-        strokeDasharray: string;
475
-        strokeDashoffset: string;
476
-    };
477
-    static isMobileSize(): boolean;
478
-    static isMobileSafari(): boolean;
479
-    static throttle<T extends (...args: any) => any>(func: T, limit: number): (...args: Parameters<T>) => ReturnType<T>;
480
-    /**
481
-     * Find whether the current display is a touch display.
482
-     */
483
-    /**
484
-     * Find whether the current device is a Mac / iOS / iPadOS.
485
-     */
486
-    static isDarwin(): boolean;
487
-    /**
488
-     * Get whether an event is command (mac) or control (pc).
489
-     * @param e
490
-     */
491
-    static metaKey(e: KeyboardEvent | React.KeyboardEvent): boolean;
492
-}
493
-export default Utils;
494
-declare type Entry<T> = {
495
-    [K in keyof T]: [K, T[K]];
496
-}[keyof T];
497
-//# sourceMappingURL=utils.d.ts.map

+ 0
- 1
packages/core/src/utils/utils.d.ts.map
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 1
- 1
packages/dev/package.json Datei anzeigen

@@ -40,4 +40,4 @@
40 40
     "typescript": "4.2.3"
41 41
   },
42 42
   "gitHead": "a7dac0f83ad998e205c2aab58182cb4ba4e099a6"
43
-}
43
+}

+ 3
- 6
packages/intersect/package.json Datei anzeigen

@@ -2,7 +2,7 @@
2 2
   "name": "@tldraw/intersect",
3 3
   "version": "0.0.126",
4 4
   "private": false,
5
-  "description": "A tiny little drawing app (intersect)",
5
+  "description": "Intersection utilities for tldraw.",
6 6
   "author": "@steveruizok",
7 7
   "repository": {
8 8
     "type": "git",
@@ -21,7 +21,7 @@
21 21
   "typings": "./dist/types/index.d.ts",
22 22
   "scripts": {
23 23
     "start:pre": "node scripts/pre-dev && yarn types:pre",
24
-    "start": "node scripts/dev & yarn types:dev",
24
+    "start:utils": "node scripts/dev & yarn types:dev",
25 25
     "build": "node scripts/build && yarn types:build",
26 26
     "types:pre": "tsc",
27 27
     "types:dev": "tsc --watch",
@@ -33,8 +33,6 @@
33 33
     "docs:watch": "typedoc --watch"
34 34
   },
35 35
   "devDependencies": {
36
-    "@babel/core": "^7.15.5",
37
-    "@babel/preset-env": "^7.15.4",
38 36
     "@types/jest": "^27.0.1",
39 37
     "@types/node": "^16.7.10",
40 38
     "@typescript-eslint/eslint-plugin": "^4.30.0",
@@ -42,7 +40,6 @@
42 40
     "esbuild": "^0.13.8",
43 41
     "eslint": "^7.32.0",
44 42
     "lerna": "^4.0.0",
45
-    "ts-node": "^10.2.1",
46 43
     "tslib": "^2.3.1",
47 44
     "typedoc": "^0.22.3",
48 45
     "typescript": "^4.4.2"
@@ -51,4 +48,4 @@
51 48
     "@tldraw/vec": "^0.0.126"
52 49
   },
53 50
   "gitHead": "5cb031ddc264846ec6732d7179511cddea8ef034"
54
-}
51
+}

+ 21
- 0
packages/svg/LICENSE Datei anzeigen

@@ -0,0 +1,21 @@
1
+MIT License
2
+
3
+Copyright (c) 2021 Stephen Ruiz Ltd
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 3
- 0
packages/svg/README.md Datei anzeigen

@@ -0,0 +1,3 @@
1
+# @tldraw/svg
2
+
3
+SVG utilities.

+ 48
- 0
packages/svg/package.json Datei anzeigen

@@ -0,0 +1,48 @@
1
+{
2
+  "name": "@tldraw/svg",
3
+  "version": "0.0.126",
4
+  "private": false,
5
+  "description": "SVG utilities for tldraw.",
6
+  "author": "@steveruizok",
7
+  "repository": {
8
+    "type": "git",
9
+    "url": "git+https://github.com/tldraw/tldraw.git",
10
+    "directory": "packages/vec"
11
+  },
12
+  "license": "MIT",
13
+  "keywords": [],
14
+  "files": [
15
+    "dist/**/*"
16
+  ],
17
+  "sideEffects": false,
18
+  "main": "./dist/cjs/index.js",
19
+  "module": "./dist/esm/index.js",
20
+  "types": "./dist/types/index.d.ts",
21
+  "typings": "./dist/types/index.d.ts",
22
+  "scripts": {
23
+    "start:pre": "node scripts/pre-dev && yarn types:pre",
24
+    "start:utils": "node scripts/dev & yarn types:dev",
25
+    "build": "node scripts/build && yarn types:build",
26
+    "types:pre": "tsc",
27
+    "types:dev": "tsc --watch",
28
+    "types:build": "tsc --project tsconfig.build.json",
29
+    "lint": "eslint src/ --ext .ts,.tsx",
30
+    "clean": "rm -rf dist",
31
+    "ts-node": "ts-node",
32
+    "docs": "typedoc",
33
+    "docs:watch": "typedoc --watch"
34
+  },
35
+  "devDependencies": {
36
+    "@types/jest": "^27.0.1",
37
+    "@types/node": "^16.7.10",
38
+    "@typescript-eslint/eslint-plugin": "^4.30.0",
39
+    "@typescript-eslint/parser": "^4.30.0",
40
+    "esbuild": "^0.13.8",
41
+    "eslint": "^7.32.0",
42
+    "lerna": "^4.0.0",
43
+    "tslib": "^2.3.1",
44
+    "typedoc": "^0.22.3",
45
+    "typescript": "^4.4.2"
46
+  },
47
+  "gitHead": "5cb031ddc264846ec6732d7179511cddea8ef034"
48
+}

+ 65
- 0
packages/svg/scripts/build.js Datei anzeigen

@@ -0,0 +1,65 @@
1
+/* eslint-disable */
2
+const fs = require('fs')
3
+const esbuild = require('esbuild')
4
+const { gzip } = require('zlib')
5
+
6
+const name = process.env.npm_package_name || ''
7
+
8
+async function main() {
9
+  if (fs.existsSync('./dist')) {
10
+    fs.rmSync('./dist', { recursive: true }, (e) => {
11
+      if (e) {
12
+        throw e
13
+      }
14
+    })
15
+  }
16
+
17
+  try {
18
+    esbuild.buildSync({
19
+      entryPoints: ['./src/index.ts'],
20
+      outdir: 'dist/cjs',
21
+      minify: true,
22
+      bundle: true,
23
+      format: 'cjs',
24
+      target: 'es6',
25
+      jsxFactory: 'React.createElement',
26
+      jsxFragment: 'React.Fragment',
27
+      tsconfig: './tsconfig.build.json',
28
+      external: ['react', 'react-dom'],
29
+    })
30
+
31
+    const esmResult = esbuild.buildSync({
32
+      entryPoints: ['./src/index.ts'],
33
+      outdir: 'dist/esm',
34
+      minify: true,
35
+      bundle: true,
36
+      format: 'esm',
37
+      target: 'es6',
38
+      tsconfig: './tsconfig.build.json',
39
+      jsxFactory: 'React.createElement',
40
+      jsxFragment: 'React.Fragment',
41
+      external: ['react', 'react-dom'],
42
+      metafile: true,
43
+    })
44
+
45
+    let esmSize = 0
46
+    Object.values(esmResult.metafile.outputs).forEach((output) => {
47
+      esmSize += output.bytes
48
+    })
49
+
50
+    fs.readFile('./dist/esm/index.js', (_err, data) => {
51
+      gzip(data, (_err, result) => {
52
+        console.log(
53
+          `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
54
+            result.length / 1000
55
+          ).toFixed(2)}kb minified)`
56
+        )
57
+      })
58
+    })
59
+  } catch (e) {
60
+    console.log(`× ${name}: Build failed due to an error.`)
61
+    console.log(e)
62
+  }
63
+}
64
+
65
+main()

+ 31
- 0
packages/svg/scripts/dev.js Datei anzeigen

@@ -0,0 +1,31 @@
1
+/* eslint-disable */
2
+const esbuild = require('esbuild')
3
+
4
+const name = process.env.npm_package_name || ''
5
+
6
+async function main() {
7
+  esbuild.build({
8
+    entryPoints: ['./src/index.ts'],
9
+    outdir: 'dist/cjs',
10
+    minify: false,
11
+    bundle: true,
12
+    format: 'cjs',
13
+    target: 'es6',
14
+    jsxFactory: 'React.createElement',
15
+    jsxFragment: 'React.Fragment',
16
+    tsconfig: './tsconfig.json',
17
+    external: ['react', 'react-dom'],
18
+    incremental: true,
19
+    watch: {
20
+      onRebuild(error) {
21
+        if (error) {
22
+          console.log(`× ${name}: An error in prevented the rebuild.`)
23
+          return
24
+        }
25
+        console.log(`✔ ${name}: Rebuilt.`)
26
+      },
27
+    },
28
+  })
29
+}
30
+
31
+main()

+ 28
- 0
packages/svg/scripts/pre-dev.js Datei anzeigen

@@ -0,0 +1,28 @@
1
+/* eslint-disable */
2
+const fs = require('fs')
3
+const esbuild = require('esbuild')
4
+
5
+async function main() {
6
+  if (fs.existsSync('./dist')) {
7
+    fs.rmSync('./dist', { recursive: true }, (e) => {
8
+      if (e) {
9
+        throw e
10
+      }
11
+    })
12
+  }
13
+
14
+  esbuild.build({
15
+    entryPoints: ['./src/index.ts'],
16
+    outdir: 'dist/cjs',
17
+    minify: false,
18
+    bundle: true,
19
+    format: 'cjs',
20
+    target: 'es6',
21
+    jsxFactory: 'React.createElement',
22
+    jsxFragment: 'React.Fragment',
23
+    tsconfig: './tsconfig.json',
24
+    external: ['react', 'react-dom'],
25
+  })
26
+}
27
+
28
+main()

+ 63
- 0
packages/svg/src/index.ts Datei anzeigen

@@ -0,0 +1,63 @@
1
+// General
2
+function angle(A: number[], B: number[]): number {
3
+  return Math.atan2(B[1] - A[1], B[0] - A[0])
4
+}
5
+
6
+function shortAngleDist(A: number, B: number) {
7
+  const max = Math.PI * 2
8
+  const da = (B - A) % max
9
+  return ((2 * da) % max) - da
10
+}
11
+
12
+function getArcLength(C: number[], r: number, A: number[], B: number[]): number {
13
+  return r * (2 * Math.PI) * (shortAngleDist(angle(C, A), angle(C, B)) / (2 * Math.PI))
14
+}
15
+
16
+export const moveTo = (v: number[]): string => {
17
+  return `M ${v} `
18
+}
19
+
20
+export const lineTo = (...v: number[][]): string => {
21
+  return `L ${v.join(' ')} `
22
+}
23
+
24
+export const hLineTo = (v: number[]): string => {
25
+  return `H ${v} `
26
+}
27
+
28
+export const vLineTo = (v: number[]): string => {
29
+  return `V ${v} `
30
+}
31
+
32
+export const bezierTo = (A: number[], B: number[], C: number[]): string => {
33
+  return `C ${A} ${B} ${C} `
34
+}
35
+
36
+export const arcTo = (C: number[], r: number, A: number[], B: number[]): string => {
37
+  return [moveTo(A), 'A', r, r, 0, 0, getArcLength(C, r, A, B) > 0 ? '1' : '0', B[0], B[1]].join(
38
+    ' '
39
+  )
40
+}
41
+
42
+export const rectTo = (A: number[]): string => {
43
+  return `R ${A}`
44
+}
45
+
46
+export const ellipse = (A: number[], r: number): string => {
47
+  return `M ${A[0] - r},${A[1]}
48
+      a ${r},${r} 0 1,0 ${r * 2},0
49
+      a ${r},${r} 0 1,0 -${r * 2},0 `
50
+}
51
+
52
+export const line = (a: number[], ...pts: number[][]): string => {
53
+  return moveTo(a) + lineTo(...pts)
54
+}
55
+
56
+export const closePath = (): string => {
57
+  return 'Z'
58
+}
59
+
60
+export const getPointAtLength = (path: SVGPathElement, length: number): number[] => {
61
+  const point = path.getPointAtLength(length)
62
+  return [point.x, point.y]
63
+}

+ 24
- 0
packages/svg/tsconfig.build.json Datei anzeigen

@@ -0,0 +1,24 @@
1
+{
2
+  "extends": "./tsconfig.json",
3
+  "exclude": [
4
+    "node_modules",
5
+    "**/*.test.tsx",
6
+    "**/*.test.ts",
7
+    "**/*.spec.tsx",
8
+    "**/*.spec.ts",
9
+    "src/test",
10
+    "dist",
11
+    "docs"
12
+  ],
13
+  "compilerOptions": {
14
+    "composite": false,
15
+    "incremental": false,
16
+    "declarationMap": false,
17
+    "sourceMap": false,
18
+    "emitDeclarationOnly": true,
19
+    "paths": {
20
+      "@tldraw/vec": ["../vec"]
21
+    }
22
+  },
23
+  "references": [{ "path": "../vec" }]
24
+}

+ 18
- 0
packages/svg/tsconfig.json Datei anzeigen

@@ -0,0 +1,18 @@
1
+{
2
+  "extends": "../../tsconfig.base.json",
3
+  "include": ["src"],
4
+  "exclude": ["node_modules", "dist", "docs"],
5
+  "compilerOptions": {
6
+    "outDir": "./dist/types",
7
+    "rootDir": "src",
8
+    "baseUrl": "src",
9
+    "paths": {
10
+      "@tldraw/vec": ["../vec"]
11
+    }
12
+  },
13
+  "references": [{ "path": "../vec" }],
14
+  "typedocOptions": {
15
+    "entryPoints": ["src/index.ts"],
16
+    "out": "docs"
17
+  }
18
+}

+ 3
- 6
packages/vec/package.json Datei anzeigen

@@ -2,7 +2,7 @@
2 2
   "name": "@tldraw/vec",
3 3
   "version": "0.0.126",
4 4
   "private": false,
5
-  "description": "A tiny little drawing app (vec)",
5
+  "description": "Vector utilities for tldraw.",
6 6
   "author": "@steveruizok",
7 7
   "repository": {
8 8
     "type": "git",
@@ -21,7 +21,7 @@
21 21
   "typings": "./dist/types/index.d.ts",
22 22
   "scripts": {
23 23
     "start:pre": "node scripts/pre-dev && yarn types:pre",
24
-    "start": "node scripts/dev & yarn types:dev",
24
+    "start:utils": "node scripts/dev & yarn types:dev",
25 25
     "build": "node scripts/build && yarn types:build",
26 26
     "types:pre": "tsc",
27 27
     "types:dev": "tsc --watch",
@@ -33,8 +33,6 @@
33 33
     "docs:watch": "typedoc --watch"
34 34
   },
35 35
   "devDependencies": {
36
-    "@babel/core": "^7.15.5",
37
-    "@babel/preset-env": "^7.15.4",
38 36
     "@types/jest": "^27.0.1",
39 37
     "@types/node": "^16.7.10",
40 38
     "@typescript-eslint/eslint-plugin": "^4.30.0",
@@ -42,10 +40,9 @@
42 40
     "esbuild": "^0.13.8",
43 41
     "eslint": "^7.32.0",
44 42
     "lerna": "^4.0.0",
45
-    "ts-node": "^10.2.1",
46 43
     "tslib": "^2.3.1",
47 44
     "typedoc": "^0.22.3",
48 45
     "typescript": "^4.4.2"
49 46
   },
50 47
   "gitHead": "5cb031ddc264846ec6732d7179511cddea8ef034"
51
-}
48
+}

Laden…
Abbrechen
Speichern