@tldraw/editor 4.1.0-next.b6dfe9bccde9 → 4.1.0-next.b9999db71010
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.d.ts +16 -3
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +2 -2
- package/dist-cjs/lib/components/ErrorBoundary.js +1 -1
- package/dist-cjs/lib/components/HTMLContainer.js +1 -1
- package/dist-cjs/lib/components/SVGContainer.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCursor.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultHandle.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultSelectionBackground.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultSnapIndictor.js +2 -2
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js +1 -1
- package/dist-cjs/lib/editor/Editor.js +5 -3
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +67 -2
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/hooks/useDarkMode.js +1 -1
- package/dist-cjs/lib/hooks/useEditor.js +1 -1
- package/dist-cjs/lib/hooks/useGestureEvents.js +1 -1
- package/dist-cjs/lib/hooks/useHandleEvents.js +1 -1
- package/dist-cjs/lib/hooks/useZoomCss.js +1 -1
- package/dist-cjs/lib/license/LicenseManager.js +18 -12
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +4 -4
- package/dist-cjs/lib/license/Watermark.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +5 -0
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/version.js +4 -4
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +16 -3
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +5 -2
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +67 -2
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseManager.mjs +18 -12
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +4 -4
- package/dist-esm/lib/license/Watermark.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +5 -0
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/version.mjs +4 -4
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +7 -2
- package/package.json +7 -7
- package/src/index.ts +0 -1
- package/src/lib/editor/Editor.ts +5 -2
- package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +91 -4
- package/src/lib/editor/shapes/ShapeUtil.ts +10 -0
- package/src/lib/license/LicenseManager.test.ts +68 -4
- package/src/lib/license/LicenseManager.ts +19 -20
- package/src/lib/license/Watermark.tsx +4 -4
- package/src/lib/primitives/geometry/Geometry2d.ts +6 -0
- package/src/version.ts +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Geometry2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { assert, invLerp } from '@tldraw/utils'\nimport { Box } from '../Box'\nimport { Mat, MatModel } from '../Mat'\nimport { Vec, VecLike } from '../Vec'\nimport {\n\tintersectCirclePolygon,\n\tintersectCirclePolyline,\n\tintersectLineSegmentPolygon,\n\tintersectLineSegmentPolyline,\n\tintersectPolys,\n\tlinesIntersect,\n\tpolygonIntersectsPolyline,\n\tpolygonsIntersect,\n} from '../intersect'\nimport { approximately, pointInPolygon } from '../utils'\n\n/**\n * Filter geometry within a group.\n *\n * Filters are ignored when called directly on primitive geometries, but can be used to narrow down\n * the results of an operation on `Group2d` geometries.\n *\n * @public\n */\nexport interface Geometry2dFilters {\n\treadonly includeLabels?: boolean\n\treadonly includeInternal?: boolean\n}\n\n/** @public */\nexport const Geometry2dFilters: {\n\tEXCLUDE_NON_STANDARD: Geometry2dFilters\n\tINCLUDE_ALL: Geometry2dFilters\n\tEXCLUDE_LABELS: Geometry2dFilters\n\tEXCLUDE_INTERNAL: Geometry2dFilters\n} = {\n\tEXCLUDE_NON_STANDARD: {\n\t\tincludeLabels: false,\n\t\tincludeInternal: false,\n\t},\n\tINCLUDE_ALL: { includeLabels: true, includeInternal: true },\n\tEXCLUDE_LABELS: { includeLabels: false, includeInternal: true },\n\tEXCLUDE_INTERNAL: { includeLabels: true, includeInternal: false },\n}\n\n/** @public */\nexport interface TransformedGeometry2dOptions {\n\tisLabel?: boolean\n\tisEmptyLabel?: boolean\n\tisInternal?: boolean\n\tdebugColor?: string\n\tignore?: boolean\n\texcludeFromShapeBounds?: boolean\n}\n\n/** @public */\nexport interface Geometry2dOptions extends TransformedGeometry2dOptions {\n\tisFilled: boolean\n\tisClosed: boolean\n}\n\n/** @public */\nexport abstract class Geometry2d {\n\t// todo: consider making accessors for these too, so that they can be overridden in subclasses by geometries with more complex logic\n\tisFilled = false\n\tisClosed = true\n\tisLabel = false\n\tisEmptyLabel = false\n\tisInternal = false\n\texcludeFromShapeBounds = false\n\tdebugColor?: string\n\tignore?: boolean\n\n\tconstructor(opts: Geometry2dOptions) {\n\t\tconst {\n\t\t\tisLabel = false,\n\t\t\tisEmptyLabel = false,\n\t\t\tisInternal = false,\n\t\t\texcludeFromShapeBounds = false,\n\t\t} = opts\n\t\tthis.isFilled = opts.isFilled\n\t\tthis.isClosed = opts.isClosed\n\t\tthis.debugColor = opts.debugColor\n\t\tthis.ignore = opts.ignore\n\t\tthis.isLabel = isLabel\n\t\tthis.isEmptyLabel = isEmptyLabel\n\t\tthis.isInternal = isInternal\n\t\tthis.excludeFromShapeBounds = excludeFromShapeBounds\n\t}\n\n\tisExcludedByFilter(filters?: Geometry2dFilters) {\n\t\tif (!filters) return false\n\t\tif (this.isLabel && !filters.includeLabels) return true\n\t\tif (this.isInternal && !filters.includeInternal) return true\n\t\treturn false\n\t}\n\n\tabstract getVertices(filters: Geometry2dFilters): Vec[]\n\n\tabstract nearestPoint(point: VecLike, _filters?: Geometry2dFilters): Vec\n\n\thitTestPoint(point: VecLike, margin = 0, hitInside = false, _filters?: Geometry2dFilters) {\n\t\t// First check whether the point is inside\n\t\tif (this.isClosed && (this.isFilled || hitInside) && pointInPolygon(point, this.vertices)) {\n\t\t\treturn true\n\t\t}\n\t\t// Then check whether the distance is within the margin\n\t\treturn Vec.Dist2(point, this.nearestPoint(point)) <= margin * margin\n\t}\n\n\tdistanceToPoint(point: VecLike, hitInside = false, filters?: Geometry2dFilters) {\n\t\treturn (\n\t\t\tVec.Dist(point, this.nearestPoint(point, filters)) *\n\t\t\t(this.isClosed && (this.isFilled || hitInside) && pointInPolygon(point, this.vertices)\n\t\t\t\t? -1\n\t\t\t\t: 1)\n\t\t)\n\t}\n\n\tdistanceToLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {\n\t\tif (Vec.Equals(A, B)) return this.distanceToPoint(A, false, filters)\n\t\tconst { vertices } = this\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number, p: Vec, q: Vec\n\t\tconst nextLimit = this.isClosed ? vertices.length : vertices.length - 1\n\t\tfor (let i = 0; i < vertices.length; i++) {\n\t\t\tp = vertices[i]\n\t\t\tif (i < nextLimit) {\n\t\t\t\tconst next = vertices[(i + 1) % vertices.length]\n\t\t\t\tif (linesIntersect(A, B, p, next)) return 0\n\t\t\t}\n\t\t\tq = Vec.NearestPointOnLineSegment(A, B, p, true)\n\t\t\td = Vec.Dist2(p, q)\n\t\t\tif (d < dist) {\n\t\t\t\tdist = d\n\t\t\t\tnearest = q\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn this.isClosed && this.isFilled && pointInPolygon(nearest, this.vertices) ? -dist : dist\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike, distance = 0, filters?: Geometry2dFilters): boolean {\n\t\treturn this.distanceToLineSegment(A, B, filters) <= distance\n\t}\n\n\tintersectLineSegment(A: VecLike, B: VecLike, _filters?: Geometry2dFilters): VecLike[] {\n\t\tconst intersections = this.isClosed\n\t\t\t? intersectLineSegmentPolygon(A, B, this.vertices)\n\t\t\t: intersectLineSegmentPolyline(A, B, this.vertices)\n\n\t\treturn intersections ?? []\n\t}\n\n\tintersectCircle(center: VecLike, radius: number, _filters?: Geometry2dFilters): VecLike[] {\n\t\tconst intersections = this.isClosed\n\t\t\t? intersectCirclePolygon(center, radius, this.vertices)\n\t\t\t: intersectCirclePolyline(center, radius, this.vertices)\n\n\t\treturn intersections ?? []\n\t}\n\n\tintersectPolygon(polygon: VecLike[], _filters?: Geometry2dFilters): VecLike[] {\n\t\treturn intersectPolys(polygon, this.vertices, true, this.isClosed)\n\t}\n\n\tintersectPolyline(polyline: VecLike[], _filters?: Geometry2dFilters): VecLike[] {\n\t\treturn intersectPolys(polyline, this.vertices, false, this.isClosed)\n\t}\n\n\t/**\n\t * Find a point along the edge of the geometry that is a fraction `t` along the entire way round.\n\t */\n\tinterpolateAlongEdge(t: number, _filters?: Geometry2dFilters): Vec {\n\t\tconst { vertices } = this\n\n\t\tif (t <= 0) return vertices[0]\n\n\t\tconst distanceToTravel = t * this.length\n\t\tlet distanceTraveled = 0\n\n\t\tfor (let i = 0; i < (this.isClosed ? vertices.length : vertices.length - 1); i++) {\n\t\t\tconst curr = vertices[i]\n\t\t\tconst next = vertices[(i + 1) % vertices.length]\n\t\t\tconst dist = Vec.Dist(curr, next)\n\t\t\tconst newDistanceTraveled = distanceTraveled + dist\n\t\t\tif (newDistanceTraveled >= distanceToTravel) {\n\t\t\t\tconst p = Vec.Lrp(\n\t\t\t\t\tcurr,\n\t\t\t\t\tnext,\n\t\t\t\t\tinvLerp(distanceTraveled, newDistanceTraveled, distanceToTravel)\n\t\t\t\t)\n\t\t\t\treturn p\n\t\t\t}\n\t\t\tdistanceTraveled = newDistanceTraveled\n\t\t}\n\n\t\treturn this.isClosed ? vertices[0] : vertices[vertices.length - 1]\n\t}\n\n\t/**\n\t * Take `point`, find the closest point to it on the edge of the geometry, and return how far\n\t * along the edge it is as a fraction of the total length.\n\t */\n\tuninterpolateAlongEdge(point: VecLike, _filters?: Geometry2dFilters): number {\n\t\tconst { vertices, length } = this\n\t\tlet closestSegment = null\n\t\tlet closestDistance = Infinity\n\t\tlet distanceTraveled = 0\n\n\t\tfor (let i = 0; i < (this.isClosed ? vertices.length : vertices.length - 1); i++) {\n\t\t\tconst curr = vertices[i]\n\t\t\tconst next = vertices[(i + 1) % vertices.length]\n\n\t\t\tconst nearestPoint = Vec.NearestPointOnLineSegment(curr, next, point, true)\n\t\t\tconst distance = Vec.Dist(nearestPoint, point)\n\n\t\t\tif (distance < closestDistance) {\n\t\t\t\tclosestDistance = distance\n\t\t\t\tclosestSegment = {\n\t\t\t\t\tstart: curr,\n\t\t\t\t\tend: next,\n\t\t\t\t\tnearestPoint,\n\t\t\t\t\tdistanceToStart: distanceTraveled,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdistanceTraveled += Vec.Dist(curr, next)\n\t\t}\n\n\t\tassert(closestSegment)\n\n\t\tconst distanceAlongRoute =\n\t\t\tclosestSegment.distanceToStart + Vec.Dist(closestSegment.start, closestSegment.nearestPoint)\n\n\t\treturn distanceAlongRoute / length\n\t}\n\n\tisPointInBounds(point: VecLike, margin = 0) {\n\t\tconst { bounds } = this\n\t\treturn !(\n\t\t\tpoint.x < bounds.minX - margin ||\n\t\t\tpoint.y < bounds.minY - margin ||\n\t\t\tpoint.x > bounds.maxX + margin ||\n\t\t\tpoint.y > bounds.maxY + margin\n\t\t)\n\t}\n\n\toverlapsPolygon(_polygon: VecLike[]): boolean {\n\t\tconst polygon = _polygon.map((v) => Vec.From(v))\n\n\t\t// Otherwise, check if the geometry itself overlaps the polygon\n\t\tconst { vertices, center, isFilled, isEmptyLabel, isClosed } = this\n\n\t\t// We'll do things in order of cheapest to most expensive checks\n\n\t\t// Skip empty labels\n\t\tif (isEmptyLabel) return false\n\n\t\t// If any of the geometry's vertices are inside the polygon, it's inside\n\t\tif (vertices.some((v) => pointInPolygon(v, polygon))) {\n\t\t\treturn true\n\t\t}\n\n\t\t// If the geometry is filled and closed and its center is inside the polygon, it's inside\n\t\tif (isClosed) {\n\t\t\tif (isFilled) {\n\t\t\t\t// If closed and filled, check if the center is inside the polygon\n\t\t\t\tif (pointInPolygon(center, polygon)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\n\t\t\t\t// ..then, slightly more expensive check, see the geometry covers the entire polygon but not its center\n\t\t\t\tif (polygon.every((v) => pointInPolygon(v, vertices))) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If any the geometry's vertices intersect the edge of the polygon, it's inside.\n\t\t\t// for example when a rotated rectangle is moved over the corner of a parent rectangle\n\t\t\t// If the geometry is closed, intersect as a polygon\n\t\t\tif (polygonsIntersect(polygon, vertices)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t} else {\n\t\t\t// If the geometry is not closed, intersect as a polyline\n\t\t\tif (polygonIntersectsPolyline(polygon, vertices)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\t// If none of the above checks passed, the geometry is outside the polygon\n\t\treturn false\n\t}\n\n\ttransform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2d {\n\t\treturn new TransformedGeometry2d(this, transform, opts)\n\t}\n\n\tprivate _vertices: Vec[] | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget vertices(): Vec[] {\n\t\tif (!this._vertices) {\n\t\t\tthis._vertices = this.getVertices(Geometry2dFilters.EXCLUDE_LABELS)\n\t\t}\n\n\t\treturn this._vertices\n\t}\n\n\tgetBoundsVertices(): Vec[] {\n\t\tif (this.excludeFromShapeBounds) return []\n\t\treturn this.vertices\n\t}\n\n\tprivate _boundsVertices: Vec[] | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget boundsVertices(): Vec[] {\n\t\tif (!this._boundsVertices) {\n\t\t\tthis._boundsVertices = this.getBoundsVertices()\n\t\t}\n\t\treturn this._boundsVertices\n\t}\n\n\tgetBounds() {\n\t\treturn Box.FromPoints(this.boundsVertices)\n\t}\n\n\tprivate _bounds: Box | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bounds(): Box {\n\t\tif (!this._bounds) {\n\t\t\tthis._bounds = this.getBounds()\n\t\t}\n\t\treturn this._bounds\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn this.bounds.center\n\t}\n\n\tprivate _area: number | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget area() {\n\t\tif (!this._area) {\n\t\t\tthis._area = this.getArea()\n\t\t}\n\t\treturn this._area\n\t}\n\n\tgetArea() {\n\t\tif (!this.isClosed) {\n\t\t\treturn 0\n\t\t}\n\t\tconst { vertices } = this\n\t\tlet area = 0\n\t\tfor (let i = 0, n = vertices.length; i < n; i++) {\n\t\t\tconst curr = vertices[i]\n\t\t\tconst next = vertices[(i + 1) % n]\n\t\t\tarea += curr.x * next.y - next.x * curr.y\n\t\t}\n\t\treturn area / 2\n\t}\n\n\ttoSimpleSvgPath() {\n\t\tlet path = ''\n\n\t\tconst { vertices } = this\n\t\tconst n = vertices.length\n\n\t\tif (n === 0) return path\n\n\t\tpath += `M${vertices[0].x},${vertices[0].y}`\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tpath += `L${vertices[i].x},${vertices[i].y}`\n\t\t}\n\n\t\tif (this.isClosed) {\n\t\t\tpath += 'Z'\n\t\t}\n\n\t\treturn path\n\t}\n\n\tprivate _length?: number\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget length() {\n\t\tif (this._length) return this._length\n\t\tthis._length = this.getLength(Geometry2dFilters.EXCLUDE_LABELS)\n\t\treturn this._length\n\t}\n\n\tgetLength(_filters?: Geometry2dFilters) {\n\t\tconst vertices = this.getVertices(_filters ?? Geometry2dFilters.EXCLUDE_LABELS)\n\t\tif (vertices.length === 0) return 0\n\t\tlet prev = vertices[0]\n\t\tlet length = 0\n\t\tfor (let i = 1; i < vertices.length; i++) {\n\t\t\tconst next = vertices[i]\n\t\t\tlength += Vec.Dist(prev, next)\n\t\t\tprev = next\n\t\t}\n\t\tif (this.isClosed) {\n\t\t\tlength += Vec.Dist(vertices[vertices.length - 1], vertices[0])\n\t\t}\n\t\treturn length\n\t}\n\n\tabstract getSvgPathData(first: boolean): string\n}\n\n// =================================================================================================\n// Because Geometry2d.transform depends on TransformedGeometry2d, we need to define it here instead\n// of in its own files. This prevents a circular import error.\n// =================================================================================================\n\n/** @public */\nexport class TransformedGeometry2d extends Geometry2d {\n\tprivate readonly inverse: MatModel\n\tprivate readonly decomposed\n\n\tconstructor(\n\t\tprivate readonly geometry: Geometry2d,\n\t\tprivate readonly matrix: MatModel,\n\t\topts?: TransformedGeometry2dOptions\n\t) {\n\t\tsuper(geometry)\n\t\tthis.inverse = Mat.Inverse(matrix)\n\t\tthis.decomposed = Mat.Decompose(matrix)\n\n\t\tif (opts) {\n\t\t\tif (opts.isLabel != null) this.isLabel = opts.isLabel\n\t\t\tif (opts.isInternal != null) this.isInternal = opts.isInternal\n\t\t\tif (opts.debugColor != null) this.debugColor = opts.debugColor\n\t\t\tif (opts.ignore != null) this.ignore = opts.ignore\n\t\t}\n\n\t\tassert(\n\t\t\tapproximately(this.decomposed.scaleX, this.decomposed.scaleY),\n\t\t\t'non-uniform scaling is not yet supported'\n\t\t)\n\t}\n\n\tgetVertices(filters: Geometry2dFilters): Vec[] {\n\t\treturn this.geometry.getVertices(filters).map((v) => Mat.applyToPoint(this.matrix, v))\n\t}\n\n\tgetBoundsVertices(): Vec[] {\n\t\treturn this.geometry.getBoundsVertices().map((v) => Mat.applyToPoint(this.matrix, v))\n\t}\n\n\tnearestPoint(point: VecLike, filters?: Geometry2dFilters): Vec {\n\t\treturn Mat.applyToPoint(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.nearestPoint(Mat.applyToPoint(this.inverse, point), filters)\n\t\t)\n\t}\n\n\toverride hitTestPoint(\n\t\tpoint: VecLike,\n\t\tmargin = 0,\n\t\thitInside?: boolean,\n\t\tfilters?: Geometry2dFilters\n\t): boolean {\n\t\treturn this.geometry.hitTestPoint(\n\t\t\tMat.applyToPoint(this.inverse, point),\n\t\t\tmargin / this.decomposed.scaleX,\n\t\t\thitInside,\n\t\t\tfilters\n\t\t)\n\t}\n\n\toverride distanceToPoint(point: VecLike, hitInside = false, filters?: Geometry2dFilters) {\n\t\treturn (\n\t\t\tthis.geometry.distanceToPoint(Mat.applyToPoint(this.inverse, point), hitInside, filters) *\n\t\t\tthis.decomposed.scaleX\n\t\t)\n\t}\n\n\toverride distanceToLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {\n\t\treturn (\n\t\t\tthis.geometry.distanceToLineSegment(\n\t\t\t\tMat.applyToPoint(this.inverse, A),\n\t\t\t\tMat.applyToPoint(this.inverse, B),\n\t\t\t\tfilters\n\t\t\t) * this.decomposed.scaleX\n\t\t)\n\t}\n\n\toverride hitTestLineSegment(\n\t\tA: VecLike,\n\t\tB: VecLike,\n\t\tdistance = 0,\n\t\tfilters?: Geometry2dFilters\n\t): boolean {\n\t\treturn this.geometry.hitTestLineSegment(\n\t\t\tMat.applyToPoint(this.inverse, A),\n\t\t\tMat.applyToPoint(this.inverse, B),\n\t\t\tdistance / this.decomposed.scaleX,\n\t\t\tfilters\n\t\t)\n\t}\n\n\toverride intersectLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectLineSegment(\n\t\t\t\tMat.applyToPoint(this.inverse, A),\n\t\t\t\tMat.applyToPoint(this.inverse, B),\n\t\t\t\tfilters\n\t\t\t)\n\t\t)\n\t}\n\n\toverride intersectCircle(center: VecLike, radius: number, filters?: Geometry2dFilters) {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectCircle(\n\t\t\t\tMat.applyToPoint(this.inverse, center),\n\t\t\t\tradius / this.decomposed.scaleX,\n\t\t\t\tfilters\n\t\t\t)\n\t\t)\n\t}\n\n\toverride intersectPolygon(polygon: VecLike[], filters?: Geometry2dFilters): VecLike[] {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectPolygon(Mat.applyToPoints(this.inverse, polygon), filters)\n\t\t)\n\t}\n\n\toverride intersectPolyline(polyline: VecLike[], filters?: Geometry2dFilters): VecLike[] {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectPolyline(Mat.applyToPoints(this.inverse, polyline), filters)\n\t\t)\n\t}\n\n\toverride transform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2d {\n\t\treturn new TransformedGeometry2d(this.geometry, Mat.Multiply(transform, this.matrix), {\n\t\t\tisLabel: opts?.isLabel ?? this.isLabel,\n\t\t\tisInternal: opts?.isInternal ?? this.isInternal,\n\t\t\tdebugColor: opts?.debugColor ?? this.debugColor,\n\t\t\tignore: opts?.ignore ?? this.ignore,\n\t\t})\n\t}\n\n\tgetSvgPathData(): string {\n\t\tthrow new Error('Cannot get SVG path data for transformed geometry.')\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,QAAQ,eAAe;AAChC,SAAS,WAAW;AACpB,SAAS,WAAqB;AAC9B,SAAS,WAAoB;AAC7B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,eAAe,sBAAsB;AAgBvC,MAAM,oBAKT;AAAA,EACH,sBAAsB;AAAA,IACrB,eAAe;AAAA,IACf,iBAAiB;AAAA,EAClB;AAAA,EACA,aAAa,EAAE,eAAe,MAAM,iBAAiB,KAAK;AAAA,EAC1D,gBAAgB,EAAE,eAAe,OAAO,iBAAiB,KAAK;AAAA,EAC9D,kBAAkB,EAAE,eAAe,MAAM,iBAAiB,MAAM;AACjE;AAmBO,MAAe,WAAW;AAAA;AAAA,EAEhC,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA,EACf,aAAa;AAAA,EACb,yBAAyB;AAAA,EACzB;AAAA,EACA;AAAA,EAEA,YAAY,MAAyB;AACpC,UAAM;AAAA,MACL,UAAU;AAAA,MACV,eAAe;AAAA,MACf,aAAa;AAAA,MACb,yBAAyB;AAAA,IAC1B,IAAI;AACJ,SAAK,WAAW,KAAK;AACrB,SAAK,WAAW,KAAK;AACrB,SAAK,aAAa,KAAK;AACvB,SAAK,SAAS,KAAK;AACnB,SAAK,UAAU;AACf,SAAK,eAAe;AACpB,SAAK,aAAa;AAClB,SAAK,yBAAyB;AAAA,EAC/B;AAAA,EAEA,mBAAmB,SAA6B;AAC/C,QAAI,CAAC,QAAS,QAAO;AACrB,QAAI,KAAK,WAAW,CAAC,QAAQ,cAAe,QAAO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iB,SAAoB,SAAwC;AACrF,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK,SAAS,iBAAiB,IAAI,cAAc,KAAK,SAAS,OAAO,GAAG,OAAO;AAAA,IACjF;AAAA,EACD;AAAA,EAES,kBAAkB,UAAqB,SAAwC;AACvF,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK,SAAS,kBAAkB,IAAI,cAAc,KAAK,SAAS,QAAQ,GAAG,OAAO;AAAA,IACnF;AAAA,EACD;AAAA,EAES,UAAU,WAAqB,MAAiD;AACxF,WAAO,IAAI,sBAAsB,KAAK,UAAU,IAAI,SAAS,WAAW,KAAK,MAAM,GAAG;AAAA,MACrF,SAAS,MAAM,WAAW,KAAK;AAAA,MAC/B,YAAY,MAAM,cAAc,KAAK;AAAA,MACrC,YAAY,MAAM,cAAc,KAAK;AAAA,MACrC,QAAQ,MAAM,UAAU,KAAK;AAAA,IAC9B,CAAC;AAAA,EACF;AAAA,EAEA,iBAAyB;AACxB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACrE;AACD;",
|
|
4
|
+
"sourcesContent": ["import { assert, invLerp } from '@tldraw/utils'\nimport { Box } from '../Box'\nimport { Mat, MatModel } from '../Mat'\nimport { Vec, VecLike } from '../Vec'\nimport {\n\tintersectCirclePolygon,\n\tintersectCirclePolyline,\n\tintersectLineSegmentPolygon,\n\tintersectLineSegmentPolyline,\n\tintersectPolys,\n\tlinesIntersect,\n\tpolygonIntersectsPolyline,\n\tpolygonsIntersect,\n} from '../intersect'\nimport { approximately, pointInPolygon } from '../utils'\n\n/**\n * Filter geometry within a group.\n *\n * Filters are ignored when called directly on primitive geometries, but can be used to narrow down\n * the results of an operation on `Group2d` geometries.\n *\n * @public\n */\nexport interface Geometry2dFilters {\n\treadonly includeLabels?: boolean\n\treadonly includeInternal?: boolean\n}\n\n/** @public */\nexport const Geometry2dFilters: {\n\tEXCLUDE_NON_STANDARD: Geometry2dFilters\n\tINCLUDE_ALL: Geometry2dFilters\n\tEXCLUDE_LABELS: Geometry2dFilters\n\tEXCLUDE_INTERNAL: Geometry2dFilters\n} = {\n\tEXCLUDE_NON_STANDARD: {\n\t\tincludeLabels: false,\n\t\tincludeInternal: false,\n\t},\n\tINCLUDE_ALL: { includeLabels: true, includeInternal: true },\n\tEXCLUDE_LABELS: { includeLabels: false, includeInternal: true },\n\tEXCLUDE_INTERNAL: { includeLabels: true, includeInternal: false },\n}\n\n/** @public */\nexport interface TransformedGeometry2dOptions {\n\tisLabel?: boolean\n\tisEmptyLabel?: boolean\n\tisInternal?: boolean\n\tdebugColor?: string\n\tignore?: boolean\n\texcludeFromShapeBounds?: boolean\n}\n\n/** @public */\nexport interface Geometry2dOptions extends TransformedGeometry2dOptions {\n\tisFilled: boolean\n\tisClosed: boolean\n}\n\n/** @public */\nexport abstract class Geometry2d {\n\t// todo: consider making accessors for these too, so that they can be overridden in subclasses by geometries with more complex logic\n\tisFilled = false\n\tisClosed = true\n\tisLabel = false\n\tisEmptyLabel = false\n\tisInternal = false\n\texcludeFromShapeBounds = false\n\tdebugColor?: string\n\tignore?: boolean\n\n\tconstructor(opts: Geometry2dOptions) {\n\t\tconst {\n\t\t\tisLabel = false,\n\t\t\tisEmptyLabel = false,\n\t\t\tisInternal = false,\n\t\t\texcludeFromShapeBounds = false,\n\t\t} = opts\n\t\tthis.isFilled = opts.isFilled\n\t\tthis.isClosed = opts.isClosed\n\t\tthis.debugColor = opts.debugColor\n\t\tthis.ignore = opts.ignore\n\t\tthis.isLabel = isLabel\n\t\tthis.isEmptyLabel = isEmptyLabel\n\t\tthis.isInternal = isInternal\n\t\tthis.excludeFromShapeBounds = excludeFromShapeBounds\n\t}\n\n\tisExcludedByFilter(filters?: Geometry2dFilters) {\n\t\tif (!filters) return false\n\t\tif (this.isLabel && !filters.includeLabels) return true\n\t\tif (this.isInternal && !filters.includeInternal) return true\n\t\treturn false\n\t}\n\n\tabstract getVertices(filters: Geometry2dFilters): Vec[]\n\n\tabstract nearestPoint(point: VecLike, _filters?: Geometry2dFilters): Vec\n\n\thitTestPoint(point: VecLike, margin = 0, hitInside = false, _filters?: Geometry2dFilters) {\n\t\t// First check whether the point is inside\n\t\tif (this.isClosed && (this.isFilled || hitInside) && pointInPolygon(point, this.vertices)) {\n\t\t\treturn true\n\t\t}\n\t\t// Then check whether the distance is within the margin\n\t\treturn Vec.Dist2(point, this.nearestPoint(point)) <= margin * margin\n\t}\n\n\tdistanceToPoint(point: VecLike, hitInside = false, filters?: Geometry2dFilters) {\n\t\treturn (\n\t\t\tVec.Dist(point, this.nearestPoint(point, filters)) *\n\t\t\t(this.isClosed && (this.isFilled || hitInside) && pointInPolygon(point, this.vertices)\n\t\t\t\t? -1\n\t\t\t\t: 1)\n\t\t)\n\t}\n\n\tdistanceToLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {\n\t\tif (Vec.Equals(A, B)) return this.distanceToPoint(A, false, filters)\n\t\tconst { vertices } = this\n\t\tif (vertices.length === 0) throw Error('nearest point not found')\n\t\tif (vertices.length === 1) return Vec.Dist(A, vertices[0])\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number, p: Vec, q: Vec\n\t\tconst nextLimit = this.isClosed ? vertices.length : vertices.length - 1\n\t\tfor (let i = 0; i < vertices.length; i++) {\n\t\t\tp = vertices[i]\n\t\t\tif (i < nextLimit) {\n\t\t\t\tconst next = vertices[(i + 1) % vertices.length]\n\t\t\t\tif (linesIntersect(A, B, p, next)) return 0\n\t\t\t}\n\t\t\tq = Vec.NearestPointOnLineSegment(A, B, p, true)\n\t\t\td = Vec.Dist2(p, q)\n\t\t\tif (d < dist) {\n\t\t\t\tdist = d\n\t\t\t\tnearest = q\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn this.isClosed && this.isFilled && pointInPolygon(nearest, this.vertices) ? -dist : dist\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike, distance = 0, filters?: Geometry2dFilters): boolean {\n\t\treturn this.distanceToLineSegment(A, B, filters) <= distance\n\t}\n\n\tintersectLineSegment(A: VecLike, B: VecLike, _filters?: Geometry2dFilters): VecLike[] {\n\t\tconst intersections = this.isClosed\n\t\t\t? intersectLineSegmentPolygon(A, B, this.vertices)\n\t\t\t: intersectLineSegmentPolyline(A, B, this.vertices)\n\n\t\treturn intersections ?? []\n\t}\n\n\tintersectCircle(center: VecLike, radius: number, _filters?: Geometry2dFilters): VecLike[] {\n\t\tconst intersections = this.isClosed\n\t\t\t? intersectCirclePolygon(center, radius, this.vertices)\n\t\t\t: intersectCirclePolyline(center, radius, this.vertices)\n\n\t\treturn intersections ?? []\n\t}\n\n\tintersectPolygon(polygon: VecLike[], _filters?: Geometry2dFilters): VecLike[] {\n\t\treturn intersectPolys(polygon, this.vertices, true, this.isClosed)\n\t}\n\n\tintersectPolyline(polyline: VecLike[], _filters?: Geometry2dFilters): VecLike[] {\n\t\treturn intersectPolys(polyline, this.vertices, false, this.isClosed)\n\t}\n\n\t/**\n\t * Find a point along the edge of the geometry that is a fraction `t` along the entire way round.\n\t */\n\tinterpolateAlongEdge(t: number, _filters?: Geometry2dFilters): Vec {\n\t\tconst { vertices } = this\n\n\t\tif (vertices.length === 0) return new Vec(0, 0)\n\t\tif (vertices.length === 1) return vertices[0]\n\t\tif (t <= 0) return vertices[0]\n\n\t\tconst distanceToTravel = t * this.length\n\t\tlet distanceTraveled = 0\n\n\t\tfor (let i = 0; i < (this.isClosed ? vertices.length : vertices.length - 1); i++) {\n\t\t\tconst curr = vertices[i]\n\t\t\tconst next = vertices[(i + 1) % vertices.length]\n\t\t\tconst dist = Vec.Dist(curr, next)\n\t\t\tconst newDistanceTraveled = distanceTraveled + dist\n\t\t\tif (newDistanceTraveled >= distanceToTravel) {\n\t\t\t\tconst p = Vec.Lrp(\n\t\t\t\t\tcurr,\n\t\t\t\t\tnext,\n\t\t\t\t\tinvLerp(distanceTraveled, newDistanceTraveled, distanceToTravel)\n\t\t\t\t)\n\t\t\t\treturn p\n\t\t\t}\n\t\t\tdistanceTraveled = newDistanceTraveled\n\t\t}\n\n\t\treturn this.isClosed ? vertices[0] : vertices[vertices.length - 1]\n\t}\n\n\t/**\n\t * Take `point`, find the closest point to it on the edge of the geometry, and return how far\n\t * along the edge it is as a fraction of the total length.\n\t */\n\tuninterpolateAlongEdge(point: VecLike, _filters?: Geometry2dFilters): number {\n\t\tconst { vertices, length } = this\n\t\tlet closestSegment = null\n\t\tlet closestDistance = Infinity\n\t\tlet distanceTraveled = 0\n\n\t\tif (vertices.length === 0 || vertices.length === 1) return 0\n\n\t\tfor (let i = 0; i < (this.isClosed ? vertices.length : vertices.length - 1); i++) {\n\t\t\tconst curr = vertices[i]\n\t\t\tconst next = vertices[(i + 1) % vertices.length]\n\n\t\t\tconst nearestPoint = Vec.NearestPointOnLineSegment(curr, next, point, true)\n\t\t\tconst distance = Vec.Dist(nearestPoint, point)\n\n\t\t\tif (distance < closestDistance) {\n\t\t\t\tclosestDistance = distance\n\t\t\t\tclosestSegment = {\n\t\t\t\t\tstart: curr,\n\t\t\t\t\tend: next,\n\t\t\t\t\tnearestPoint,\n\t\t\t\t\tdistanceToStart: distanceTraveled,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdistanceTraveled += Vec.Dist(curr, next)\n\t\t}\n\n\t\tassert(closestSegment)\n\n\t\tconst distanceAlongRoute =\n\t\t\tclosestSegment.distanceToStart + Vec.Dist(closestSegment.start, closestSegment.nearestPoint)\n\n\t\treturn distanceAlongRoute / length\n\t}\n\n\tisPointInBounds(point: VecLike, margin = 0) {\n\t\tconst { bounds } = this\n\t\treturn !(\n\t\t\tpoint.x < bounds.minX - margin ||\n\t\t\tpoint.y < bounds.minY - margin ||\n\t\t\tpoint.x > bounds.maxX + margin ||\n\t\t\tpoint.y > bounds.maxY + margin\n\t\t)\n\t}\n\n\toverlapsPolygon(_polygon: VecLike[]): boolean {\n\t\tconst polygon = _polygon.map((v) => Vec.From(v))\n\n\t\t// Otherwise, check if the geometry itself overlaps the polygon\n\t\tconst { vertices, center, isFilled, isEmptyLabel, isClosed } = this\n\n\t\t// We'll do things in order of cheapest to most expensive checks\n\n\t\t// Skip empty labels\n\t\tif (isEmptyLabel) return false\n\n\t\t// If any of the geometry's vertices are inside the polygon, it's inside\n\t\tif (vertices.some((v) => pointInPolygon(v, polygon))) {\n\t\t\treturn true\n\t\t}\n\n\t\t// If the geometry is filled and closed and its center is inside the polygon, it's inside\n\t\tif (isClosed) {\n\t\t\tif (isFilled) {\n\t\t\t\t// If closed and filled, check if the center is inside the polygon\n\t\t\t\tif (pointInPolygon(center, polygon)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\n\t\t\t\t// ..then, slightly more expensive check, see the geometry covers the entire polygon but not its center\n\t\t\t\tif (polygon.every((v) => pointInPolygon(v, vertices))) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If any the geometry's vertices intersect the edge of the polygon, it's inside.\n\t\t\t// for example when a rotated rectangle is moved over the corner of a parent rectangle\n\t\t\t// If the geometry is closed, intersect as a polygon\n\t\t\tif (polygonsIntersect(polygon, vertices)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t} else {\n\t\t\t// If the geometry is not closed, intersect as a polyline\n\t\t\tif (polygonIntersectsPolyline(polygon, vertices)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\n\t\t// If none of the above checks passed, the geometry is outside the polygon\n\t\treturn false\n\t}\n\n\ttransform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2d {\n\t\treturn new TransformedGeometry2d(this, transform, opts)\n\t}\n\n\tprivate _vertices: Vec[] | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget vertices(): Vec[] {\n\t\tif (!this._vertices) {\n\t\t\tthis._vertices = this.getVertices(Geometry2dFilters.EXCLUDE_LABELS)\n\t\t}\n\n\t\treturn this._vertices\n\t}\n\n\tgetBoundsVertices(): Vec[] {\n\t\tif (this.excludeFromShapeBounds) return []\n\t\treturn this.vertices\n\t}\n\n\tprivate _boundsVertices: Vec[] | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget boundsVertices(): Vec[] {\n\t\tif (!this._boundsVertices) {\n\t\t\tthis._boundsVertices = this.getBoundsVertices()\n\t\t}\n\t\treturn this._boundsVertices\n\t}\n\n\tgetBounds() {\n\t\treturn Box.FromPoints(this.boundsVertices)\n\t}\n\n\tprivate _bounds: Box | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget bounds(): Box {\n\t\tif (!this._bounds) {\n\t\t\tthis._bounds = this.getBounds()\n\t\t}\n\t\treturn this._bounds\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget center() {\n\t\treturn this.bounds.center\n\t}\n\n\tprivate _area: number | undefined\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget area() {\n\t\tif (!this._area) {\n\t\t\tthis._area = this.getArea()\n\t\t}\n\t\treturn this._area\n\t}\n\n\tgetArea() {\n\t\tif (!this.isClosed) {\n\t\t\treturn 0\n\t\t}\n\t\tconst { vertices } = this\n\t\tlet area = 0\n\t\tfor (let i = 0, n = vertices.length; i < n; i++) {\n\t\t\tconst curr = vertices[i]\n\t\t\tconst next = vertices[(i + 1) % n]\n\t\t\tarea += curr.x * next.y - next.x * curr.y\n\t\t}\n\t\treturn area / 2\n\t}\n\n\ttoSimpleSvgPath() {\n\t\tlet path = ''\n\n\t\tconst { vertices } = this\n\t\tconst n = vertices.length\n\n\t\tif (n === 0) return path\n\n\t\tpath += `M${vertices[0].x},${vertices[0].y}`\n\n\t\tfor (let i = 1; i < n; i++) {\n\t\t\tpath += `L${vertices[i].x},${vertices[i].y}`\n\t\t}\n\n\t\tif (this.isClosed) {\n\t\t\tpath += 'Z'\n\t\t}\n\n\t\treturn path\n\t}\n\n\tprivate _length?: number\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget length() {\n\t\tif (this._length) return this._length\n\t\tthis._length = this.getLength(Geometry2dFilters.EXCLUDE_LABELS)\n\t\treturn this._length\n\t}\n\n\tgetLength(_filters?: Geometry2dFilters) {\n\t\tconst vertices = this.getVertices(_filters ?? Geometry2dFilters.EXCLUDE_LABELS)\n\t\tif (vertices.length === 0) return 0\n\t\tlet prev = vertices[0]\n\t\tlet length = 0\n\t\tfor (let i = 1; i < vertices.length; i++) {\n\t\t\tconst next = vertices[i]\n\t\t\tlength += Vec.Dist(prev, next)\n\t\t\tprev = next\n\t\t}\n\t\tif (this.isClosed) {\n\t\t\tlength += Vec.Dist(vertices[vertices.length - 1], vertices[0])\n\t\t}\n\t\treturn length\n\t}\n\n\tabstract getSvgPathData(first: boolean): string\n}\n\n// =================================================================================================\n// Because Geometry2d.transform depends on TransformedGeometry2d, we need to define it here instead\n// of in its own files. This prevents a circular import error.\n// =================================================================================================\n\n/** @public */\nexport class TransformedGeometry2d extends Geometry2d {\n\tprivate readonly inverse: MatModel\n\tprivate readonly decomposed\n\n\tconstructor(\n\t\tprivate readonly geometry: Geometry2d,\n\t\tprivate readonly matrix: MatModel,\n\t\topts?: TransformedGeometry2dOptions\n\t) {\n\t\tsuper(geometry)\n\t\tthis.inverse = Mat.Inverse(matrix)\n\t\tthis.decomposed = Mat.Decompose(matrix)\n\n\t\tif (opts) {\n\t\t\tif (opts.isLabel != null) this.isLabel = opts.isLabel\n\t\t\tif (opts.isInternal != null) this.isInternal = opts.isInternal\n\t\t\tif (opts.debugColor != null) this.debugColor = opts.debugColor\n\t\t\tif (opts.ignore != null) this.ignore = opts.ignore\n\t\t}\n\n\t\tassert(\n\t\t\tapproximately(this.decomposed.scaleX, this.decomposed.scaleY),\n\t\t\t'non-uniform scaling is not yet supported'\n\t\t)\n\t}\n\n\tgetVertices(filters: Geometry2dFilters): Vec[] {\n\t\treturn this.geometry.getVertices(filters).map((v) => Mat.applyToPoint(this.matrix, v))\n\t}\n\n\tgetBoundsVertices(): Vec[] {\n\t\treturn this.geometry.getBoundsVertices().map((v) => Mat.applyToPoint(this.matrix, v))\n\t}\n\n\tnearestPoint(point: VecLike, filters?: Geometry2dFilters): Vec {\n\t\treturn Mat.applyToPoint(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.nearestPoint(Mat.applyToPoint(this.inverse, point), filters)\n\t\t)\n\t}\n\n\toverride hitTestPoint(\n\t\tpoint: VecLike,\n\t\tmargin = 0,\n\t\thitInside?: boolean,\n\t\tfilters?: Geometry2dFilters\n\t): boolean {\n\t\treturn this.geometry.hitTestPoint(\n\t\t\tMat.applyToPoint(this.inverse, point),\n\t\t\tmargin / this.decomposed.scaleX,\n\t\t\thitInside,\n\t\t\tfilters\n\t\t)\n\t}\n\n\toverride distanceToPoint(point: VecLike, hitInside = false, filters?: Geometry2dFilters) {\n\t\treturn (\n\t\t\tthis.geometry.distanceToPoint(Mat.applyToPoint(this.inverse, point), hitInside, filters) *\n\t\t\tthis.decomposed.scaleX\n\t\t)\n\t}\n\n\toverride distanceToLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {\n\t\treturn (\n\t\t\tthis.geometry.distanceToLineSegment(\n\t\t\t\tMat.applyToPoint(this.inverse, A),\n\t\t\t\tMat.applyToPoint(this.inverse, B),\n\t\t\t\tfilters\n\t\t\t) * this.decomposed.scaleX\n\t\t)\n\t}\n\n\toverride hitTestLineSegment(\n\t\tA: VecLike,\n\t\tB: VecLike,\n\t\tdistance = 0,\n\t\tfilters?: Geometry2dFilters\n\t): boolean {\n\t\treturn this.geometry.hitTestLineSegment(\n\t\t\tMat.applyToPoint(this.inverse, A),\n\t\t\tMat.applyToPoint(this.inverse, B),\n\t\t\tdistance / this.decomposed.scaleX,\n\t\t\tfilters\n\t\t)\n\t}\n\n\toverride intersectLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters) {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectLineSegment(\n\t\t\t\tMat.applyToPoint(this.inverse, A),\n\t\t\t\tMat.applyToPoint(this.inverse, B),\n\t\t\t\tfilters\n\t\t\t)\n\t\t)\n\t}\n\n\toverride intersectCircle(center: VecLike, radius: number, filters?: Geometry2dFilters) {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectCircle(\n\t\t\t\tMat.applyToPoint(this.inverse, center),\n\t\t\t\tradius / this.decomposed.scaleX,\n\t\t\t\tfilters\n\t\t\t)\n\t\t)\n\t}\n\n\toverride intersectPolygon(polygon: VecLike[], filters?: Geometry2dFilters): VecLike[] {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectPolygon(Mat.applyToPoints(this.inverse, polygon), filters)\n\t\t)\n\t}\n\n\toverride intersectPolyline(polyline: VecLike[], filters?: Geometry2dFilters): VecLike[] {\n\t\treturn Mat.applyToPoints(\n\t\t\tthis.matrix,\n\t\t\tthis.geometry.intersectPolyline(Mat.applyToPoints(this.inverse, polyline), filters)\n\t\t)\n\t}\n\n\toverride transform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2d {\n\t\treturn new TransformedGeometry2d(this.geometry, Mat.Multiply(transform, this.matrix), {\n\t\t\tisLabel: opts?.isLabel ?? this.isLabel,\n\t\t\tisInternal: opts?.isInternal ?? this.isInternal,\n\t\t\tdebugColor: opts?.debugColor ?? this.debugColor,\n\t\t\tignore: opts?.ignore ?? this.ignore,\n\t\t})\n\t}\n\n\tgetSvgPathData(): string {\n\t\tthrow new Error('Cannot get SVG path data for transformed geometry.')\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,QAAQ,eAAe;AAChC,SAAS,WAAW;AACpB,SAAS,WAAqB;AAC9B,SAAS,WAAoB;AAC7B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,eAAe,sBAAsB;AAgBvC,MAAM,oBAKT;AAAA,EACH,sBAAsB;AAAA,IACrB,eAAe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AAwC;AACvF,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK,SAAS,kBAAkB,IAAI,cAAc,KAAK,SAAS,QAAQ,GAAG,OAAO;AAAA,IACnF;AAAA,EACD;AAAA,EAES,UAAU,WAAqB,MAAiD;AACxF,WAAO,IAAI,sBAAsB,KAAK,UAAU,IAAI,SAAS,WAAW,KAAK,MAAM,GAAG;AAAA,MACrF,SAAS,MAAM,WAAW,KAAK;AAAA,MAC/B,YAAY,MAAM,cAAc,KAAK;AAAA,MACrC,YAAY,MAAM,cAAc,KAAK;AAAA,MACrC,QAAQ,MAAM,UAAU,KAAK;AAAA,IAC9B,CAAC;AAAA,EACF;AAAA,EAEA,iBAAyB;AACxB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACrE;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/version.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const version = "4.1.0-next.
|
|
1
|
+
const version = "4.1.0-next.b9999db71010";
|
|
2
2
|
const publishDates = {
|
|
3
|
-
major: "2025-09-
|
|
4
|
-
minor: "2025-
|
|
5
|
-
patch: "2025-
|
|
3
|
+
major: "2025-09-18T14:39:22.803Z",
|
|
4
|
+
minor: "2025-10-15T09:19:04.044Z",
|
|
5
|
+
patch: "2025-10-15T09:19:04.044Z"
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
8
|
publishDates,
|
package/dist-esm/version.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.1.0-next.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '4.1.0-next.b9999db71010'\nexport const publishDates = {\n\tmajor: '2025-09-18T14:39:22.803Z',\n\tminor: '2025-10-15T09:19:04.044Z',\n\tpatch: '2025-10-15T09:19:04.044Z',\n}\n"],
|
|
5
5
|
"mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/editor.css
CHANGED
|
@@ -1321,6 +1321,10 @@ input,
|
|
|
1321
1321
|
flex: 1;
|
|
1322
1322
|
}
|
|
1323
1323
|
|
|
1324
|
+
.tl-bookmark__copy_container:has(.tl-bookmark__link:only-child) {
|
|
1325
|
+
justify-content: center;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1324
1328
|
.tl-bookmark__heading,
|
|
1325
1329
|
.tl-bookmark__description,
|
|
1326
1330
|
.tl-bookmark__link {
|
|
@@ -1353,7 +1357,7 @@ input,
|
|
|
1353
1357
|
line-clamp: 3;
|
|
1354
1358
|
text-overflow: ellipsis;
|
|
1355
1359
|
display: -webkit-box;
|
|
1356
|
-
color: var(--tl-color-text-
|
|
1360
|
+
color: var(--tl-color-text-1);
|
|
1357
1361
|
margin: var(--tl-space-2) 0px;
|
|
1358
1362
|
}
|
|
1359
1363
|
|
|
@@ -1365,11 +1369,12 @@ input,
|
|
|
1365
1369
|
font-size: 12px;
|
|
1366
1370
|
pointer-events: all;
|
|
1367
1371
|
display: flex;
|
|
1368
|
-
color: var(--tl-color-text-
|
|
1372
|
+
color: var(--tl-color-text-1);
|
|
1369
1373
|
align-items: center;
|
|
1370
1374
|
cursor: var(--tl-cursor-pointer);
|
|
1371
1375
|
width: fit-content;
|
|
1372
1376
|
max-width: 100%;
|
|
1377
|
+
text-decoration: none;
|
|
1373
1378
|
}
|
|
1374
1379
|
|
|
1375
1380
|
.tl-bookmark__link > span {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "tldraw infinite canvas SDK (editor).",
|
|
4
|
-
"version": "4.1.0-next.
|
|
4
|
+
"version": "4.1.0-next.b9999db71010",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@tiptap/core": "^2.9.1",
|
|
51
51
|
"@tiptap/pm": "^2.9.1",
|
|
52
52
|
"@tiptap/react": "^2.9.1",
|
|
53
|
-
"@tldraw/state": "4.1.0-next.
|
|
54
|
-
"@tldraw/state-react": "4.1.0-next.
|
|
55
|
-
"@tldraw/store": "4.1.0-next.
|
|
56
|
-
"@tldraw/tlschema": "4.1.0-next.
|
|
57
|
-
"@tldraw/utils": "4.1.0-next.
|
|
58
|
-
"@tldraw/validate": "4.1.0-next.
|
|
53
|
+
"@tldraw/state": "4.1.0-next.b9999db71010",
|
|
54
|
+
"@tldraw/state-react": "4.1.0-next.b9999db71010",
|
|
55
|
+
"@tldraw/store": "4.1.0-next.b9999db71010",
|
|
56
|
+
"@tldraw/tlschema": "4.1.0-next.b9999db71010",
|
|
57
|
+
"@tldraw/utils": "4.1.0-next.b9999db71010",
|
|
58
|
+
"@tldraw/validate": "4.1.0-next.b9999db71010",
|
|
59
59
|
"@types/core-js": "^2.5.8",
|
|
60
60
|
"@use-gesture/react": "^10.3.1",
|
|
61
61
|
"classnames": "^2.5.1",
|
package/src/index.ts
CHANGED
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
JsonObject,
|
|
70
70
|
PerformanceTracker,
|
|
71
71
|
Result,
|
|
72
|
+
ZERO_INDEX_KEY,
|
|
72
73
|
annotateError,
|
|
73
74
|
assert,
|
|
74
75
|
assertExists,
|
|
@@ -2019,7 +2020,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2019
2020
|
}
|
|
2020
2021
|
|
|
2021
2022
|
/**
|
|
2022
|
-
*
|
|
2023
|
+
* Get the page bounds of all the provided shapes.
|
|
2024
|
+
*
|
|
2025
|
+
* @public
|
|
2023
2026
|
*/
|
|
2024
2027
|
getShapesPageBounds(shapeIds: TLShapeId[]): Box | null {
|
|
2025
2028
|
const bounds = compact(shapeIds.map((id) => this.getShapePageBounds(id)))
|
|
@@ -5661,7 +5664,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5661
5664
|
const children = this._parentIdsToChildIds.get()[parentId]
|
|
5662
5665
|
|
|
5663
5666
|
if (!children || children.length === 0) {
|
|
5664
|
-
return
|
|
5667
|
+
return getIndexAbove(ZERO_INDEX_KEY)
|
|
5665
5668
|
}
|
|
5666
5669
|
const shape = this.getShape(children[children.length - 1])!
|
|
5667
5670
|
return getIndexAbove(shape.index)
|
|
@@ -4,7 +4,7 @@ import { assertExists, uniqueId } from '@tldraw/utils'
|
|
|
4
4
|
import { Vec } from '../../../primitives/Vec'
|
|
5
5
|
import { Geometry2d } from '../../../primitives/geometry/Geometry2d'
|
|
6
6
|
import { Editor } from '../../Editor'
|
|
7
|
-
import { SnapData, SnapManager } from './SnapManager'
|
|
7
|
+
import { PointsSnapIndicator, SnapData, SnapManager } from './SnapManager'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* When dragging a handle, users can snap the handle to key geometry on other nearby shapes.
|
|
@@ -43,6 +43,11 @@ export interface HandleSnapGeometry {
|
|
|
43
43
|
getSelfSnapPoints?(handle: TLHandle): VecModel[]
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
interface AlignPointsSnap {
|
|
47
|
+
snaps: PointsSnapIndicator[]
|
|
48
|
+
nudge: Vec
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
const defaultGetSelfSnapOutline = () => null
|
|
47
52
|
const defaultGetSelfSnapPoints = () => []
|
|
48
53
|
/** @public */
|
|
@@ -171,6 +176,67 @@ export class HandleSnaps {
|
|
|
171
176
|
return null
|
|
172
177
|
}
|
|
173
178
|
|
|
179
|
+
private getHandleSnapData({
|
|
180
|
+
handle,
|
|
181
|
+
currentShapeId,
|
|
182
|
+
}: {
|
|
183
|
+
handle: TLHandle
|
|
184
|
+
currentShapeId: TLShapeId
|
|
185
|
+
}): AlignPointsSnap | null {
|
|
186
|
+
const snapThreshold = this.manager.getSnapThreshold()
|
|
187
|
+
const currentShapeTransform = assertExists(this.editor.getShapePageTransform(currentShapeId))
|
|
188
|
+
const handleInPageSpace = currentShapeTransform.applyToPoint(handle)
|
|
189
|
+
|
|
190
|
+
let nearestXSnap: Vec | null = null
|
|
191
|
+
let nearestYSnap: Vec | null = null
|
|
192
|
+
let minOffsetX = snapThreshold
|
|
193
|
+
let minOffsetY = snapThreshold
|
|
194
|
+
|
|
195
|
+
for (const snapPoint of this.iterateSnapPointsInPageSpace(currentShapeId, handle)) {
|
|
196
|
+
const offsetX = Math.abs(handleInPageSpace.x - snapPoint.x)
|
|
197
|
+
const offsetY = Math.abs(handleInPageSpace.y - snapPoint.y)
|
|
198
|
+
if (offsetX < minOffsetX) {
|
|
199
|
+
minOffsetX = offsetX
|
|
200
|
+
nearestXSnap = snapPoint
|
|
201
|
+
}
|
|
202
|
+
if (offsetY < minOffsetY) {
|
|
203
|
+
minOffsetY = offsetY
|
|
204
|
+
nearestYSnap = snapPoint
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (!nearestXSnap && !nearestYSnap) {
|
|
209
|
+
return null
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const nudge = new Vec(
|
|
213
|
+
nearestXSnap ? nearestXSnap.x - handleInPageSpace.x : 0,
|
|
214
|
+
nearestYSnap ? nearestYSnap.y - handleInPageSpace.y : 0
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
const snappedHandle = Vec.Add(handleInPageSpace, nudge)
|
|
218
|
+
const snaps: PointsSnapIndicator[] = []
|
|
219
|
+
|
|
220
|
+
if (nearestXSnap) {
|
|
221
|
+
const snappedHandleOnX = new Vec(nearestXSnap.x, snappedHandle.y)
|
|
222
|
+
snaps.push({
|
|
223
|
+
id: uniqueId(),
|
|
224
|
+
type: 'points',
|
|
225
|
+
points: [nearestXSnap, snappedHandleOnX],
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
if (nearestYSnap) {
|
|
229
|
+
const snappedHandleOnY = new Vec(snappedHandle.x, nearestYSnap.y)
|
|
230
|
+
snaps.push({
|
|
231
|
+
id: uniqueId(),
|
|
232
|
+
type: 'points',
|
|
233
|
+
points: [nearestYSnap, snappedHandleOnY],
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return { snaps, nudge }
|
|
238
|
+
}
|
|
239
|
+
|
|
174
240
|
snapHandle({
|
|
175
241
|
currentShapeId,
|
|
176
242
|
handle,
|
|
@@ -180,10 +246,16 @@ export class HandleSnaps {
|
|
|
180
246
|
}): SnapData | null {
|
|
181
247
|
const currentShapeTransform = assertExists(this.editor.getShapePageTransform(currentShapeId))
|
|
182
248
|
const handleInPageSpace = currentShapeTransform.applyToPoint(handle)
|
|
183
|
-
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
250
|
+
const snapType = handle.canSnap ? 'point' : handle.snapType
|
|
251
|
+
|
|
252
|
+
if (snapType === 'point') {
|
|
253
|
+
const snapPosition = this.getHandleSnapPosition({ currentShapeId, handle, handleInPageSpace })
|
|
254
|
+
|
|
255
|
+
if (!snapPosition) {
|
|
256
|
+
return null
|
|
257
|
+
}
|
|
184
258
|
|
|
185
|
-
// If we found a point, display snap lines, and return the nudge
|
|
186
|
-
if (snapPosition) {
|
|
187
259
|
this.manager.setIndicators([
|
|
188
260
|
{
|
|
189
261
|
id: uniqueId(),
|
|
@@ -195,6 +267,21 @@ export class HandleSnaps {
|
|
|
195
267
|
return { nudge: Vec.Sub(snapPosition, handleInPageSpace) }
|
|
196
268
|
}
|
|
197
269
|
|
|
270
|
+
if (snapType === 'align') {
|
|
271
|
+
const snapData = this.getHandleSnapData({
|
|
272
|
+
handle,
|
|
273
|
+
currentShapeId,
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
if (!snapData) {
|
|
277
|
+
return null
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.manager.setIndicators(snapData.snaps)
|
|
281
|
+
|
|
282
|
+
return { nudge: snapData.nudge }
|
|
283
|
+
}
|
|
284
|
+
|
|
198
285
|
return null
|
|
199
286
|
}
|
|
200
287
|
}
|
|
@@ -328,6 +328,16 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
328
328
|
*/
|
|
329
329
|
shouldClipChild?(child: TLShape): boolean
|
|
330
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Whether a specific shape should hide in the minimap.
|
|
333
|
+
*
|
|
334
|
+
* If not defined, the default behavior is to show all shapes in the minimap.
|
|
335
|
+
*
|
|
336
|
+
* @returns boolean indicating if this shape should hide in the minimap
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
hideInMinimap?(_shape: Shape): boolean
|
|
340
|
+
|
|
331
341
|
/**
|
|
332
342
|
* Whether the shape should hide its resize handles when selected.
|
|
333
343
|
*
|
|
@@ -36,13 +36,15 @@ describe('LicenseManager', () => {
|
|
|
36
36
|
let licenseManager: LicenseManager
|
|
37
37
|
|
|
38
38
|
beforeAll(() => {
|
|
39
|
+
process.env.NODE_ENV = 'production'
|
|
39
40
|
return new Promise((resolve) => {
|
|
40
41
|
generateKeyPair().then((kp) => {
|
|
41
42
|
keyPair = kp
|
|
42
|
-
licenseManager = new LicenseManager('', keyPair.publicKey
|
|
43
|
+
licenseManager = new LicenseManager('', keyPair.publicKey)
|
|
43
44
|
resolve(void 0)
|
|
44
45
|
})
|
|
45
46
|
})
|
|
47
|
+
process.env.NODE_ENV = 'test'
|
|
46
48
|
})
|
|
47
49
|
|
|
48
50
|
beforeEach(() => {
|
|
@@ -58,7 +60,7 @@ describe('LicenseManager', () => {
|
|
|
58
60
|
expect(result).toMatchObject({ isLicenseParseable: false, reason: 'no-key-provided' })
|
|
59
61
|
})
|
|
60
62
|
|
|
61
|
-
it('Signals that it is development mode when
|
|
63
|
+
it('Signals that it is development mode when localhost', async () => {
|
|
62
64
|
const schemes = ['http', 'https']
|
|
63
65
|
for (const scheme of schemes) {
|
|
64
66
|
// @ts-ignore
|
|
@@ -66,7 +68,7 @@ describe('LicenseManager', () => {
|
|
|
66
68
|
// @ts-ignore
|
|
67
69
|
window.location = new URL(`${scheme}://localhost:3000`)
|
|
68
70
|
|
|
69
|
-
const testEnvLicenseManager = new LicenseManager('', keyPair.publicKey
|
|
71
|
+
const testEnvLicenseManager = new LicenseManager('', keyPair.publicKey)
|
|
70
72
|
const licenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
71
73
|
const result = await testEnvLicenseManager.getLicenseFromKey(licenseKey)
|
|
72
74
|
expect(result).toMatchObject({
|
|
@@ -77,6 +79,66 @@ describe('LicenseManager', () => {
|
|
|
77
79
|
}
|
|
78
80
|
})
|
|
79
81
|
|
|
82
|
+
it('Signals that it is development mode when NODE_ENV is not production', async () => {
|
|
83
|
+
process.env.NODE_ENV = 'development'
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
delete window.location
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
window.location = new URL(`https://www.example.com`)
|
|
88
|
+
|
|
89
|
+
const testEnvLicenseManager = new LicenseManager('', keyPair.publicKey)
|
|
90
|
+
const licenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
91
|
+
const result = await testEnvLicenseManager.getLicenseFromKey(licenseKey)
|
|
92
|
+
expect(result).toMatchObject({
|
|
93
|
+
isLicenseParseable: true,
|
|
94
|
+
isDomainValid: true,
|
|
95
|
+
isDevelopment: true,
|
|
96
|
+
})
|
|
97
|
+
const licenseState = testEnvLicenseManager.state.get()
|
|
98
|
+
expect(licenseState).toBe('unlicensed')
|
|
99
|
+
process.env.NODE_ENV = 'test'
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('Signals that it is development mode when NODE_ENV is "test"', async () => {
|
|
103
|
+
process.env.NODE_ENV = 'test'
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
delete window.location
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
window.location = new URL(`https://www.example.com`)
|
|
108
|
+
|
|
109
|
+
const testEnvLicenseManager = new LicenseManager('', keyPair.publicKey)
|
|
110
|
+
const licenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
111
|
+
const result = await testEnvLicenseManager.getLicenseFromKey(licenseKey)
|
|
112
|
+
expect(result).toMatchObject({
|
|
113
|
+
isLicenseParseable: true,
|
|
114
|
+
isDomainValid: true,
|
|
115
|
+
isDevelopment: true,
|
|
116
|
+
})
|
|
117
|
+
const licenseState = testEnvLicenseManager.state.get()
|
|
118
|
+
expect(licenseState).toBe('unlicensed')
|
|
119
|
+
process.env.NODE_ENV = 'test'
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('Signals that it is not development mode when NODE_ENV is production', async () => {
|
|
123
|
+
process.env.NODE_ENV = 'production'
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
delete window.location
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
window.location = new URL(`https://www.example.com`)
|
|
128
|
+
|
|
129
|
+
const testEnvLicenseManager = new LicenseManager('', keyPair.publicKey)
|
|
130
|
+
const licenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
131
|
+
const result = await testEnvLicenseManager.getLicenseFromKey(licenseKey)
|
|
132
|
+
expect(result).toMatchObject({
|
|
133
|
+
isLicenseParseable: true,
|
|
134
|
+
isDomainValid: true,
|
|
135
|
+
isDevelopment: false,
|
|
136
|
+
})
|
|
137
|
+
const licenseState = testEnvLicenseManager.state.get()
|
|
138
|
+
expect(licenseState).toBe('unlicensed-production')
|
|
139
|
+
process.env.NODE_ENV = 'test'
|
|
140
|
+
})
|
|
141
|
+
|
|
80
142
|
it('Cleanses out valid keys that accidentally have zero-width characters or newlines', async () => {
|
|
81
143
|
const cleanLicenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
82
144
|
const dirtyLicenseKey = cleanLicenseKey + '\u200B\u200D\uFEFF\n\r'
|
|
@@ -85,10 +147,12 @@ describe('LicenseManager', () => {
|
|
|
85
147
|
})
|
|
86
148
|
|
|
87
149
|
it('Fails if garbage key provided', async () => {
|
|
88
|
-
|
|
150
|
+
process.env.NODE_ENV = 'production'
|
|
151
|
+
const badPublicKeyLicenseManager = new LicenseManager('', 'badpublickey')
|
|
89
152
|
const invalidLicenseKey = await generateLicenseKey(STANDARD_LICENSE_INFO, keyPair)
|
|
90
153
|
const result = await badPublicKeyLicenseManager.getLicenseFromKey(invalidLicenseKey)
|
|
91
154
|
expect(result).toMatchObject({ isLicenseParseable: false, reason: 'invalid-license-key' })
|
|
155
|
+
process.env.NODE_ENV = 'test'
|
|
92
156
|
})
|
|
93
157
|
|
|
94
158
|
it('Fails if non-JSON parseable message is provided', async () => {
|
|
@@ -87,9 +87,6 @@ export interface ValidLicenseKeyResult {
|
|
|
87
87
|
daysSinceExpiry: number
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
/** @internal */
|
|
91
|
-
export type TestEnvironment = 'development' | 'production'
|
|
92
|
-
|
|
93
90
|
/** @internal */
|
|
94
91
|
export type TrackType = 'unlicensed' | 'with_watermark' | 'evaluation' | null
|
|
95
92
|
|
|
@@ -103,13 +100,9 @@ export class LicenseManager {
|
|
|
103
100
|
state = atom<LicenseState>('license state', 'pending')
|
|
104
101
|
public verbose = true
|
|
105
102
|
|
|
106
|
-
constructor(
|
|
107
|
-
licenseKey: string | undefined,
|
|
108
|
-
testPublicKey?: string,
|
|
109
|
-
testEnvironment?: TestEnvironment
|
|
110
|
-
) {
|
|
103
|
+
constructor(licenseKey: string | undefined, testPublicKey?: string) {
|
|
111
104
|
this.isTest = process.env.NODE_ENV === 'test'
|
|
112
|
-
this.isDevelopment = this.getIsDevelopment(
|
|
105
|
+
this.isDevelopment = this.getIsDevelopment()
|
|
113
106
|
this.publicKey = testPublicKey || this.publicKey
|
|
114
107
|
this.isCryptoAvailable = !!crypto.subtle
|
|
115
108
|
|
|
@@ -131,14 +124,12 @@ export class LicenseManager {
|
|
|
131
124
|
})
|
|
132
125
|
}
|
|
133
126
|
|
|
134
|
-
private getIsDevelopment(
|
|
135
|
-
if (testEnvironment === 'development') return true
|
|
136
|
-
if (testEnvironment === 'production') return false
|
|
137
|
-
|
|
127
|
+
private getIsDevelopment() {
|
|
138
128
|
// If we are using https on a non-localhost domain we assume it's a production env and a development one otherwise
|
|
139
129
|
return (
|
|
140
130
|
!['https:', 'vscode-webview:'].includes(window.location.protocol) ||
|
|
141
|
-
window.location.hostname === 'localhost'
|
|
131
|
+
window.location.hostname === 'localhost' ||
|
|
132
|
+
process.env.NODE_ENV !== 'production'
|
|
142
133
|
)
|
|
143
134
|
}
|
|
144
135
|
|
|
@@ -181,6 +172,9 @@ export class LicenseManager {
|
|
|
181
172
|
if ('license' in result) {
|
|
182
173
|
url.searchParams.set('license_id', result.license.id)
|
|
183
174
|
}
|
|
175
|
+
if (process.env.NODE_ENV) {
|
|
176
|
+
url.searchParams.set('environment', process.env.NODE_ENV)
|
|
177
|
+
}
|
|
184
178
|
|
|
185
179
|
// eslint-disable-next-line no-restricted-globals
|
|
186
180
|
fetch(url.toString())
|
|
@@ -415,22 +409,27 @@ export class LicenseManager {
|
|
|
415
409
|
// If we added a new flag it will be twice the value of the currently highest flag.
|
|
416
410
|
// And if all the current flags are on we would get the `HIGHEST_FLAG * 2 - 1`, so anything higher than that means there are new flags.
|
|
417
411
|
if (result.license.flags >= HIGHEST_FLAG * 2) {
|
|
418
|
-
this.outputMessages(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
412
|
+
this.outputMessages(
|
|
413
|
+
[
|
|
414
|
+
'Warning: This tldraw license contains some unknown flags.',
|
|
415
|
+
'This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality.',
|
|
416
|
+
],
|
|
417
|
+
'warning'
|
|
418
|
+
)
|
|
422
419
|
}
|
|
423
420
|
}
|
|
424
421
|
|
|
425
|
-
private outputMessages(messages: string[]) {
|
|
422
|
+
private outputMessages(messages: string[], type: 'warning' | 'error' = 'error') {
|
|
426
423
|
if (this.isTest) return
|
|
427
424
|
if (this.verbose) {
|
|
428
425
|
this.outputDelimiter()
|
|
429
426
|
for (const message of messages) {
|
|
427
|
+
const color = type === 'warning' ? 'orange' : 'crimson'
|
|
428
|
+
const bgColor = type === 'warning' ? 'orange' : 'crimson'
|
|
430
429
|
// eslint-disable-next-line no-console
|
|
431
430
|
console.log(
|
|
432
431
|
`%c${message}`,
|
|
433
|
-
`color:
|
|
432
|
+
`color: ${color}; background: ${bgColor}; padding: 2px; border-radius: 3px;`
|
|
434
433
|
)
|
|
435
434
|
}
|
|
436
435
|
this.outputDelimiter()
|
|
@@ -208,22 +208,22 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
@media (hover: hover) {
|
|
211
|
-
.${className}
|
|
211
|
+
.${className} > button {
|
|
212
212
|
pointer-events: none;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
.${className}
|
|
215
|
+
.${className}:hover {
|
|
216
216
|
background-color: var(--tl-color-background);
|
|
217
217
|
transition: background-color 0.2s ease-in-out;
|
|
218
218
|
transition-delay: 0.32s;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
.${className}
|
|
221
|
+
.${className}:hover > button {
|
|
222
222
|
animation: ${className}_delayed_link 0.2s forwards ease-in-out;
|
|
223
223
|
animation-delay: 0.32s;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
.${className}
|
|
226
|
+
.${className} > button:focus-visible {
|
|
227
227
|
opacity: 1;
|
|
228
228
|
}
|
|
229
229
|
}
|