@tldraw/editor 3.14.0-canary.ee1f3f027485 → 3.14.0-canary.f6a0206007b3
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 +59 -46
- package/dist-cjs/index.js +3 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +2 -2
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +16 -20
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +3 -3
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +8 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +6 -0
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +6 -0
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +13 -8
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +41 -21
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +11 -11
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js +13 -16
- package/dist-cjs/lib/primitives/geometry/CubicBezier2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js +4 -4
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Edge2d.js +14 -17
- package/dist-cjs/lib/primitives/geometry/Edge2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +10 -10
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Point2d.js +6 -6
- package/dist-cjs/lib/primitives/geometry/Point2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polygon2d.js +3 -0
- package/dist-cjs/lib/primitives/geometry/Polygon2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js +8 -5
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Rectangle2d.js +22 -11
- package/dist-cjs/lib/primitives/geometry/Rectangle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +22 -22
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
- package/dist-cjs/lib/utils/areShapesContentEqual.js +1 -1
- package/dist-cjs/lib/utils/areShapesContentEqual.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +59 -46
- package/dist-esm/index.mjs +3 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +2 -2
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +16 -20
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +3 -3
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +8 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +6 -0
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +6 -0
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +13 -8
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +41 -21
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +11 -11
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs +13 -16
- package/dist-esm/lib/primitives/geometry/CubicBezier2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs +4 -4
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs +14 -17
- package/dist-esm/lib/primitives/geometry/Edge2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +11 -11
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Point2d.mjs +6 -6
- package/dist-esm/lib/primitives/geometry/Point2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polygon2d.mjs +3 -0
- package/dist-esm/lib/primitives/geometry/Polygon2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +8 -5
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Rectangle2d.mjs +22 -11
- package/dist-esm/lib/primitives/geometry/Rectangle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +22 -22
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
- package/dist-esm/lib/utils/areShapesContentEqual.mjs +1 -1
- package/dist-esm/lib/utils/areShapesContentEqual.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +1 -0
- package/src/lib/editor/Editor.ts +3 -2
- package/src/lib/editor/derivations/notVisibleShapes.ts +24 -25
- package/src/lib/editor/shapes/ShapeUtil.ts +9 -0
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +8 -0
- package/src/lib/primitives/Box.ts +8 -0
- package/src/lib/primitives/Vec.test.ts +2 -2
- package/src/lib/primitives/Vec.ts +13 -8
- package/src/lib/primitives/geometry/Arc2d.ts +42 -23
- package/src/lib/primitives/geometry/Circle2d.ts +12 -12
- package/src/lib/primitives/geometry/CubicBezier2d.test.ts +5 -0
- package/src/lib/primitives/geometry/CubicBezier2d.ts +13 -17
- package/src/lib/primitives/geometry/CubicSpline2d.ts +5 -5
- package/src/lib/primitives/geometry/Edge2d.ts +14 -18
- package/src/lib/primitives/geometry/Ellipse2d.ts +12 -13
- package/src/lib/primitives/geometry/Point2d.ts +6 -6
- package/src/lib/primitives/geometry/Polygon2d.ts +4 -0
- package/src/lib/primitives/geometry/Polyline2d.ts +10 -7
- package/src/lib/primitives/geometry/Rectangle2d.ts +24 -11
- package/src/lib/primitives/geometry/Stadium2d.ts +22 -23
- package/src/lib/utils/areShapesContentEqual.ts +2 -1
- package/src/version.ts +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box } from "../Box.mjs";
|
|
2
2
|
import { Vec } from "../Vec.mjs";
|
|
3
|
-
import { PI, PI2, perimeterOfEllipse } from "../utils.mjs";
|
|
3
|
+
import { PI, PI2, clamp, perimeterOfEllipse } from "../utils.mjs";
|
|
4
4
|
import { Edge2d } from "./Edge2d.mjs";
|
|
5
5
|
import { Geometry2d } from "./Geometry2d.mjs";
|
|
6
6
|
import { getVerticesCountForLength } from "./geometry-constants.mjs";
|
|
@@ -9,11 +9,11 @@ class Ellipse2d extends Geometry2d {
|
|
|
9
9
|
super({ ...config, isClosed: true });
|
|
10
10
|
this.config = config;
|
|
11
11
|
const { width, height } = config;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this._w = width;
|
|
13
|
+
this._h = height;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
_w;
|
|
16
|
+
_h;
|
|
17
17
|
_edges;
|
|
18
18
|
// eslint-disable-next-line no-restricted-syntax
|
|
19
19
|
get edges() {
|
|
@@ -29,8 +29,8 @@ class Ellipse2d extends Geometry2d {
|
|
|
29
29
|
return this._edges;
|
|
30
30
|
}
|
|
31
31
|
getVertices() {
|
|
32
|
-
const w = Math.max(1, this.
|
|
33
|
-
const h = Math.max(1, this.
|
|
32
|
+
const w = Math.max(1, this._w);
|
|
33
|
+
const h = Math.max(1, this._h);
|
|
34
34
|
const cx = w / 2;
|
|
35
35
|
const cy = h / 2;
|
|
36
36
|
const q = Math.pow(cx - cy, 2) / Math.pow(cx + cy, 2);
|
|
@@ -45,7 +45,7 @@ class Ellipse2d extends Geometry2d {
|
|
|
45
45
|
let tc = 1;
|
|
46
46
|
const vertices = Array(len);
|
|
47
47
|
for (let i = 0; i < len; i++) {
|
|
48
|
-
vertices[i] = new Vec(cx + cx * cos, cy + cy * sin);
|
|
48
|
+
vertices[i] = new Vec(clamp(cx + cx * cos, 0, w), clamp(cy + cy * sin, 0, h));
|
|
49
49
|
ts = b * cos + a * sin;
|
|
50
50
|
tc = a * cos - b * sin;
|
|
51
51
|
sin = ts;
|
|
@@ -73,10 +73,10 @@ class Ellipse2d extends Geometry2d {
|
|
|
73
73
|
return this.edges.some((edge) => edge.hitTestLineSegment(A, B));
|
|
74
74
|
}
|
|
75
75
|
getBounds() {
|
|
76
|
-
return new Box(0, 0, this.
|
|
76
|
+
return new Box(0, 0, this._w, this._h);
|
|
77
77
|
}
|
|
78
78
|
getLength() {
|
|
79
|
-
const { w, h } = this;
|
|
79
|
+
const { _w: w, _h: h } = this;
|
|
80
80
|
const cx = w / 2;
|
|
81
81
|
const cy = h / 2;
|
|
82
82
|
const rx = Math.max(0, cx);
|
|
@@ -84,7 +84,7 @@ class Ellipse2d extends Geometry2d {
|
|
|
84
84
|
return perimeterOfEllipse(rx, ry);
|
|
85
85
|
}
|
|
86
86
|
getSvgPathData(first = false) {
|
|
87
|
-
const { w, h } = this;
|
|
87
|
+
const { _w: w, _h: h } = this;
|
|
88
88
|
const cx = w / 2;
|
|
89
89
|
const cy = h / 2;
|
|
90
90
|
const rx = Math.max(0, cx);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Ellipse2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { PI, PI2, perimeterOfEllipse } from '../utils'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Ellipse2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,IAAI,KAAK,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { PI, PI2, clamp, perimeterOfEllipse } from '../utils'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\nimport { getVerticesCountForLength } from './geometry-constants'\n\n/** @public */\nexport class Ellipse2d extends Geometry2d {\n\tprivate _w: number\n\tprivate _h: number\n\tprivate _edges?: Edge2d[]\n\n\tconstructor(\n\t\tpublic config: Omit<Geometry2dOptions, 'isClosed'> & {\n\t\t\twidth: number\n\t\t\theight: number\n\t\t}\n\t) {\n\t\tsuper({ ...config, isClosed: true })\n\t\tconst { width, height } = config\n\t\tthis._w = width\n\t\tthis._h = height\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tget edges() {\n\t\tif (!this._edges) {\n\t\t\tconst { vertices } = this\n\t\t\tthis._edges = []\n\t\t\tfor (let i = 0, n = vertices.length; i < n; i++) {\n\t\t\t\tconst start = vertices[i]\n\t\t\t\tconst end = vertices[(i + 1) % n]\n\t\t\t\tthis._edges.push(new Edge2d({ start, end }))\n\t\t\t}\n\t\t}\n\n\t\treturn this._edges\n\t}\n\n\tgetVertices() {\n\t\t// Perimeter of the ellipse\n\t\tconst w = Math.max(1, this._w)\n\t\tconst h = Math.max(1, this._h)\n\t\tconst cx = w / 2\n\t\tconst cy = h / 2\n\t\tconst q = Math.pow(cx - cy, 2) / Math.pow(cx + cy, 2)\n\t\tconst p = PI * (cx + cy) * (1 + (3 * q) / (10 + Math.sqrt(4 - 3 * q)))\n\t\t// Number of points\n\t\tconst len = getVerticesCountForLength(p)\n\t\t// Size of step\n\t\tconst step = PI2 / len\n\n\t\tconst a = Math.cos(step)\n\t\tconst b = Math.sin(step)\n\n\t\tlet sin = 0\n\t\tlet cos = 1\n\t\tlet ts = 0\n\t\tlet tc = 1\n\n\t\tconst vertices = Array(len)\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tvertices[i] = new Vec(clamp(cx + cx * cos, 0, w), clamp(cy + cy * sin, 0, h))\n\t\t\tts = b * cos + a * sin\n\t\t\ttc = a * cos - b * sin\n\t\t\tsin = ts\n\t\t\tcos = tc\n\t\t}\n\n\t\treturn vertices\n\t}\n\n\tnearestPoint(A: VecLike): Vec {\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet d: number\n\t\tlet p: Vec\n\t\tfor (const edge of this.edges) {\n\t\t\tp = edge.nearestPoint(A)\n\t\t\td = Vec.Dist2(p, A)\n\t\t\tif (d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = d\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike): boolean {\n\t\treturn this.edges.some((edge) => edge.hitTestLineSegment(A, B))\n\t}\n\n\tgetBounds() {\n\t\treturn new Box(0, 0, this._w, this._h)\n\t}\n\n\tgetLength(): number {\n\t\tconst { _w: w, _h: h } = this\n\t\tconst cx = w / 2\n\t\tconst cy = h / 2\n\t\tconst rx = Math.max(0, cx)\n\t\tconst ry = Math.max(0, cy)\n\t\treturn perimeterOfEllipse(rx, ry)\n\t}\n\n\tgetSvgPathData(first = false) {\n\t\tconst { _w: w, _h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,IAAI,GAAG,EAAE;AACzB,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,WAAO,mBAAmB,IAAI,EAAE;AAAA,EACjC;AAAA,EAEA,eAAe,QAAQ,OAAO;AAC7B,UAAM,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI;AACzB,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,IAAI;AACf,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,UAAM,KAAK,KAAK,IAAI,GAAG,EAAE;AACzB,WAAO,GAAG,QAAQ,IAAI,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,CAAC;AAAA,EACvG;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { Vec } from "../Vec.mjs";
|
|
2
2
|
import { Geometry2d } from "./Geometry2d.mjs";
|
|
3
3
|
class Point2d extends Geometry2d {
|
|
4
|
-
|
|
4
|
+
_point;
|
|
5
5
|
constructor(config) {
|
|
6
6
|
super({ ...config, isClosed: true, isFilled: true });
|
|
7
7
|
const { point } = config;
|
|
8
|
-
this.
|
|
8
|
+
this._point = point;
|
|
9
9
|
}
|
|
10
10
|
getVertices() {
|
|
11
|
-
return [this.
|
|
11
|
+
return [this._point];
|
|
12
12
|
}
|
|
13
13
|
nearestPoint() {
|
|
14
|
-
return this.
|
|
14
|
+
return this._point;
|
|
15
15
|
}
|
|
16
16
|
hitTestLineSegment(A, B, margin) {
|
|
17
|
-
return Vec.DistanceToLineSegment(A, B, this.
|
|
17
|
+
return Vec.DistanceToLineSegment(A, B, this._point) < margin;
|
|
18
18
|
}
|
|
19
19
|
getSvgPathData() {
|
|
20
|
-
const { point } = this;
|
|
20
|
+
const { _point: point } = this;
|
|
21
21
|
return `M${point.toFixed()}`;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Point2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Point2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kBAAqC;AAGvC,MAAM,gBAAgB,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Point2d extends Geometry2d {\n\tprivate _point: Vec\n\n\tconstructor(\n\t\tconfig: Omit<Geometry2dOptions, 'isClosed' | 'isFilled'> & { margin: number; point: Vec }\n\t) {\n\t\tsuper({ ...config, isClosed: true, isFilled: true })\n\t\tconst { point } = config\n\n\t\tthis._point = point\n\t}\n\n\tgetVertices() {\n\t\treturn [this._point]\n\t}\n\n\tnearestPoint(): Vec {\n\t\treturn this._point\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike, margin: number): boolean {\n\t\treturn Vec.DistanceToLineSegment(A, B, this._point) < margin\n\t}\n\n\tgetSvgPathData() {\n\t\tconst { _point: point } = this\n\t\treturn `M${point.toFixed()}`\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,kBAAqC;AAGvC,MAAM,gBAAgB,WAAW;AAAA,EAC/B;AAAA,EAER,YACC,QACC;AACD,UAAM,EAAE,GAAG,QAAQ,UAAU,MAAM,UAAU,KAAK,CAAC;AACnD,UAAM,EAAE,MAAM,IAAI;AAElB,SAAK,SAAS;AAAA,EACf;AAAA,EAEA,cAAc;AACb,WAAO,CAAC,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,eAAoB;AACnB,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,mBAAmB,GAAY,GAAY,QAAyB;AACnE,WAAO,IAAI,sBAAsB,GAAG,GAAG,KAAK,MAAM,IAAI;AAAA,EACvD;AAAA,EAEA,iBAAiB;AAChB,UAAM,EAAE,QAAQ,MAAM,IAAI;AAC1B,WAAO,IAAI,MAAM,QAAQ,CAAC;AAAA,EAC3B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Polygon2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec } from '../Vec'\nimport { Geometry2dOptions } from './Geometry2d'\nimport { Polyline2d } from './Polyline2d'\n\n/** @public */\nexport class Polygon2d extends Polyline2d {\n\tconstructor(config: Omit<Geometry2dOptions, 'isClosed'> & { points: Vec[] }) {\n\t\tsuper({ ...config })\n\t\tthis.isClosed = true\n\t}\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,kBAAkB;AAGpB,MAAM,kBAAkB,WAAW;AAAA,EACzC,YAAY,QAAiE;AAC5E,UAAM,EAAE,GAAG,OAAO,CAAC;AACnB,SAAK,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec } from '../Vec'\nimport { Geometry2dOptions } from './Geometry2d'\nimport { Polyline2d } from './Polyline2d'\n\n/** @public */\nexport class Polygon2d extends Polyline2d {\n\tconstructor(config: Omit<Geometry2dOptions, 'isClosed'> & { points: Vec[] }) {\n\t\tsuper({ ...config })\n\t\tthis.isClosed = true\n\n\t\tif (config.points.length < 3) {\n\t\t\tthrow new Error('Polygon2d: points must be an array of at least 3 points')\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,kBAAkB;AAGpB,MAAM,kBAAkB,WAAW;AAAA,EACzC,YAAY,QAAiE;AAC5E,UAAM,EAAE,GAAG,OAAO,CAAC;AACnB,SAAK,WAAW;AAEhB,QAAI,OAAO,OAAO,SAAS,GAAG;AAC7B,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC1E;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,13 +2,16 @@ import { Vec } from "../Vec.mjs";
|
|
|
2
2
|
import { Edge2d } from "./Edge2d.mjs";
|
|
3
3
|
import { Geometry2d } from "./Geometry2d.mjs";
|
|
4
4
|
class Polyline2d extends Geometry2d {
|
|
5
|
-
|
|
5
|
+
_points;
|
|
6
|
+
_segments;
|
|
6
7
|
constructor(config) {
|
|
7
8
|
super({ isClosed: false, isFilled: false, ...config });
|
|
8
9
|
const { points } = config;
|
|
9
|
-
this.
|
|
10
|
+
this._points = points;
|
|
11
|
+
if (points.length < 2) {
|
|
12
|
+
throw new Error("Polyline2d: points must be an array of at least 2 points");
|
|
13
|
+
}
|
|
10
14
|
}
|
|
11
|
-
_segments;
|
|
12
15
|
// eslint-disable-next-line no-restricted-syntax
|
|
13
16
|
get segments() {
|
|
14
17
|
if (!this._segments) {
|
|
@@ -29,11 +32,11 @@ class Polyline2d extends Geometry2d {
|
|
|
29
32
|
return this.segments.reduce((acc, segment) => acc + segment.length, 0);
|
|
30
33
|
}
|
|
31
34
|
getVertices() {
|
|
32
|
-
return this.
|
|
35
|
+
return this._points;
|
|
33
36
|
}
|
|
34
37
|
nearestPoint(A) {
|
|
35
38
|
const { segments } = this;
|
|
36
|
-
let nearest = this.
|
|
39
|
+
let nearest = this._points[0];
|
|
37
40
|
let dist = Infinity;
|
|
38
41
|
let p;
|
|
39
42
|
let d;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Polyline2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Polyline2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,kBAAqC;AAGvC,MAAM,mBAAmB,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Vec, VecLike } from '../Vec'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Polyline2d extends Geometry2d {\n\tprivate _points: Vec[]\n\tprivate _segments?: Edge2d[]\n\n\tconstructor(config: Omit<Geometry2dOptions, 'isFilled' | 'isClosed'> & { points: Vec[] }) {\n\t\tsuper({ isClosed: false, isFilled: false, ...config })\n\t\tconst { points } = config\n\t\tthis._points = points\n\n\t\tif (points.length < 2) {\n\t\t\tthrow new Error('Polyline2d: points must be an array of at least 2 points')\n\t\t}\n\t}\n\n\t// eslint-disable-next-line no-restricted-syntax\n\tprotected get segments() {\n\t\tif (!this._segments) {\n\t\t\tthis._segments = []\n\t\t\tconst { vertices } = this\n\t\t\tfor (let i = 0, n = vertices.length - 1; i < n; i++) {\n\t\t\t\tconst start = vertices[i]\n\t\t\t\tconst end = vertices[i + 1]\n\t\t\t\tthis._segments.push(new Edge2d({ start, end }))\n\t\t\t}\n\n\t\t\tif (this.isClosed) {\n\t\t\t\tthis._segments.push(new Edge2d({ start: vertices[vertices.length - 1], end: vertices[0] }))\n\t\t\t}\n\t\t}\n\n\t\treturn this._segments\n\t}\n\n\toverride getLength() {\n\t\treturn this.segments.reduce((acc, segment) => acc + segment.length, 0)\n\t}\n\n\tgetVertices() {\n\t\treturn this._points\n\t}\n\n\tnearestPoint(A: VecLike): Vec {\n\t\tconst { segments } = this\n\t\tlet nearest = this._points[0]\n\t\tlet dist = Infinity\n\t\tlet p: Vec // current point on segment\n\t\tlet d: number // distance from A to p\n\t\tfor (let i = 0; i < segments.length; i++) {\n\t\t\tp = segments[i].nearestPoint(A)\n\t\t\td = Vec.Dist2(p, A)\n\t\t\tif (d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = d\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike, distance = 0): boolean {\n\t\tconst { segments } = this\n\t\tfor (let i = 0, n = segments.length; i < n; i++) {\n\t\t\tif (segments[i].hitTestLineSegment(A, B, distance)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tgetSvgPathData(): string {\n\t\tconst { vertices } = this\n\t\tif (vertices.length < 2) return ''\n\t\treturn vertices.reduce((acc, vertex, i) => {\n\t\t\tif (i === 0) return `M ${vertex.x} ${vertex.y}`\n\t\t\treturn `${acc} L ${vertex.x} ${vertex.y}`\n\t\t}, '')\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,kBAAqC;AAGvC,MAAM,mBAAmB,WAAW;AAAA,EAClC;AAAA,EACA;AAAA,EAER,YAAY,QAA8E;AACzF,UAAM,EAAE,UAAU,OAAO,UAAU,OAAO,GAAG,OAAO,CAAC;AACrD,UAAM,EAAE,OAAO,IAAI;AACnB,SAAK,UAAU;AAEf,QAAI,OAAO,SAAS,GAAG;AACtB,YAAM,IAAI,MAAM,0DAA0D;AAAA,IAC3E;AAAA,EACD;AAAA;AAAA,EAGA,IAAc,WAAW;AACxB,QAAI,CAAC,KAAK,WAAW;AACpB,WAAK,YAAY,CAAC;AAClB,YAAM,EAAE,SAAS,IAAI;AACrB,eAAS,IAAI,GAAG,IAAI,SAAS,SAAS,GAAG,IAAI,GAAG,KAAK;AACpD,cAAM,QAAQ,SAAS,CAAC;AACxB,cAAM,MAAM,SAAS,IAAI,CAAC;AAC1B,aAAK,UAAU,KAAK,IAAI,OAAO,EAAE,OAAO,IAAI,CAAC,CAAC;AAAA,MAC/C;AAEA,UAAI,KAAK,UAAU;AAClB,aAAK,UAAU,KAAK,IAAI,OAAO,EAAE,OAAO,SAAS,SAAS,SAAS,CA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7
7
|
}
|
|
@@ -2,10 +2,10 @@ import { Box } from "../Box.mjs";
|
|
|
2
2
|
import { Vec } from "../Vec.mjs";
|
|
3
3
|
import { Polygon2d } from "./Polygon2d.mjs";
|
|
4
4
|
class Rectangle2d extends Polygon2d {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
_x;
|
|
6
|
+
_y;
|
|
7
|
+
_w;
|
|
8
|
+
_h;
|
|
9
9
|
constructor(config) {
|
|
10
10
|
const { x = 0, y = 0, width, height } = config;
|
|
11
11
|
super({
|
|
@@ -17,18 +17,29 @@ class Rectangle2d extends Polygon2d {
|
|
|
17
17
|
new Vec(x, y + height)
|
|
18
18
|
]
|
|
19
19
|
});
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
20
|
+
this._x = x;
|
|
21
|
+
this._y = y;
|
|
22
|
+
this._w = width;
|
|
23
|
+
this._h = height;
|
|
24
24
|
}
|
|
25
25
|
getBounds() {
|
|
26
|
-
return new Box(this.
|
|
26
|
+
return new Box(this._x, this._y, this._w, this._h);
|
|
27
27
|
}
|
|
28
28
|
getSvgPathData() {
|
|
29
|
-
const { x, y, w, h } = this;
|
|
30
|
-
|
|
29
|
+
const { _x: x, _y: y, _w: w, _h: h } = this;
|
|
30
|
+
this.negativeZeroFix();
|
|
31
|
+
return `M${x},${y} h${w} v${h} h${-w}z`;
|
|
31
32
|
}
|
|
33
|
+
negativeZeroFix() {
|
|
34
|
+
this._x = zeroFix(this._x);
|
|
35
|
+
this._y = zeroFix(this._y);
|
|
36
|
+
this._w = zeroFix(this._w);
|
|
37
|
+
this._h = zeroFix(this._h);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function zeroFix(value) {
|
|
41
|
+
if (Object.is(value, -0)) return 0;
|
|
42
|
+
return value;
|
|
32
43
|
}
|
|
33
44
|
export {
|
|
34
45
|
Rectangle2d
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Rectangle2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec } from '../Vec'\nimport { Geometry2dOptions } from './Geometry2d'\nimport { Polygon2d } from './Polygon2d'\n\n/** @public */\nexport class Rectangle2d extends Polygon2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAW;AAEpB,SAAS,iBAAiB;AAGnB,MAAM,oBAAoB,UAAU;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec } from '../Vec'\nimport { Geometry2dOptions } from './Geometry2d'\nimport { Polygon2d } from './Polygon2d'\n\n/** @public */\nexport class Rectangle2d extends Polygon2d {\n\tprivate _x: number\n\tprivate _y: number\n\tprivate _w: number\n\tprivate _h: number\n\n\tconstructor(\n\t\tconfig: Omit<Geometry2dOptions, 'isClosed'> & {\n\t\t\tx?: number\n\t\t\ty?: number\n\t\t\twidth: number\n\t\t\theight: number\n\t\t}\n\t) {\n\t\tconst { x = 0, y = 0, width, height } = config\n\t\tsuper({\n\t\t\t...config,\n\t\t\tpoints: [\n\t\t\t\tnew Vec(x, y),\n\t\t\t\tnew Vec(x + width, y),\n\t\t\t\tnew Vec(x + width, y + height),\n\t\t\t\tnew Vec(x, y + height),\n\t\t\t],\n\t\t})\n\t\tthis._x = x\n\t\tthis._y = y\n\t\tthis._w = width\n\t\tthis._h = height\n\t}\n\n\tgetBounds() {\n\t\treturn new Box(this._x, this._y, this._w, this._h)\n\t}\n\n\tgetSvgPathData(): string {\n\t\tconst { _x: x, _y: y, _w: w, _h: h } = this\n\t\tthis.negativeZeroFix()\n\t\treturn `M${x},${y} h${w} v${h} h${-w}z`\n\t}\n\n\tprivate negativeZeroFix() {\n\t\tthis._x = zeroFix(this._x)\n\t\tthis._y = zeroFix(this._y)\n\t\tthis._w = zeroFix(this._w)\n\t\tthis._h = ze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|
"names": []
|
|
7
7
|
}
|
|
@@ -9,58 +9,58 @@ class Stadium2d extends Geometry2d {
|
|
|
9
9
|
super({ ...config, isClosed: true });
|
|
10
10
|
this.config = config;
|
|
11
11
|
const { width: w, height: h } = config;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this._w = w;
|
|
13
|
+
this._h = h;
|
|
14
14
|
if (h > w) {
|
|
15
15
|
const r = w / 2;
|
|
16
|
-
this.
|
|
16
|
+
this._a = new Arc2d({
|
|
17
17
|
start: new Vec(0, r),
|
|
18
18
|
end: new Vec(w, r),
|
|
19
19
|
center: new Vec(w / 2, r),
|
|
20
20
|
sweepFlag: 1,
|
|
21
21
|
largeArcFlag: 1
|
|
22
22
|
});
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
23
|
+
this._b = new Edge2d({ start: new Vec(w, r), end: new Vec(w, h - r) });
|
|
24
|
+
this._c = new Arc2d({
|
|
25
25
|
start: new Vec(w, h - r),
|
|
26
26
|
end: new Vec(0, h - r),
|
|
27
27
|
center: new Vec(w / 2, h - r),
|
|
28
28
|
sweepFlag: 1,
|
|
29
29
|
largeArcFlag: 1
|
|
30
30
|
});
|
|
31
|
-
this.
|
|
31
|
+
this._d = new Edge2d({ start: new Vec(0, h - r), end: new Vec(0, r) });
|
|
32
32
|
} else {
|
|
33
33
|
const r = h / 2;
|
|
34
|
-
this.
|
|
34
|
+
this._a = new Arc2d({
|
|
35
35
|
start: new Vec(r, h),
|
|
36
36
|
end: new Vec(r, 0),
|
|
37
37
|
center: new Vec(r, r),
|
|
38
38
|
sweepFlag: 1,
|
|
39
39
|
largeArcFlag: 1
|
|
40
40
|
});
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
41
|
+
this._b = new Edge2d({ start: new Vec(r, 0), end: new Vec(w - r, 0) });
|
|
42
|
+
this._c = new Arc2d({
|
|
43
43
|
start: new Vec(w - r, 0),
|
|
44
44
|
end: new Vec(w - r, h),
|
|
45
45
|
center: new Vec(w - r, r),
|
|
46
46
|
sweepFlag: 1,
|
|
47
47
|
largeArcFlag: 1
|
|
48
48
|
});
|
|
49
|
-
this.
|
|
49
|
+
this._d = new Edge2d({ start: new Vec(w - r, h), end: new Vec(r, h) });
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
_w;
|
|
53
|
+
_h;
|
|
54
|
+
_a;
|
|
55
|
+
_b;
|
|
56
|
+
_c;
|
|
57
|
+
_d;
|
|
58
58
|
nearestPoint(A) {
|
|
59
59
|
let nearest;
|
|
60
60
|
let dist = Infinity;
|
|
61
61
|
let _d;
|
|
62
62
|
let p;
|
|
63
|
-
const { a, b, c, d } = this;
|
|
63
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
64
64
|
for (const part of [a, b, c, d]) {
|
|
65
65
|
p = part.nearestPoint(A);
|
|
66
66
|
_d = Vec.Dist2(p, A);
|
|
@@ -73,26 +73,26 @@ class Stadium2d extends Geometry2d {
|
|
|
73
73
|
return nearest;
|
|
74
74
|
}
|
|
75
75
|
hitTestLineSegment(A, B) {
|
|
76
|
-
const { a, b, c, d } = this;
|
|
76
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
77
77
|
return [a, b, c, d].some((edge) => edge.hitTestLineSegment(A, B));
|
|
78
78
|
}
|
|
79
79
|
getVertices() {
|
|
80
|
-
const { a, b, c, d } = this;
|
|
80
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
81
81
|
return [a, b, c, d].reduce((a2, p) => {
|
|
82
82
|
a2.push(...p.vertices);
|
|
83
83
|
return a2;
|
|
84
84
|
}, []);
|
|
85
85
|
}
|
|
86
86
|
getBounds() {
|
|
87
|
-
return new Box(0, 0, this.
|
|
87
|
+
return new Box(0, 0, this._w, this._h);
|
|
88
88
|
}
|
|
89
89
|
getLength() {
|
|
90
|
-
const { h, w } = this;
|
|
90
|
+
const { _h: h, _w: w } = this;
|
|
91
91
|
if (h > w) return (PI * (w / 2) + (h - w)) * 2;
|
|
92
92
|
else return (PI * (h / 2) + (w - h)) * 2;
|
|
93
93
|
}
|
|
94
94
|
getSvgPathData() {
|
|
95
|
-
const { a, b, c, d } = this;
|
|
95
|
+
const { _a: a, _b: b, _c: c, _d: d } = this;
|
|
96
96
|
return [a, b, c, d].map((p, i) => p.getSvgPathData(i === 0)).join(" ") + " Z";
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/primitives/geometry/Stadium2d.ts"],
|
|
4
|
-
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { PI } from '../utils'\nimport { Arc2d } from './Arc2d'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Stadium2d extends Geometry2d {\n\
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,kBAAqC;AAGvC,MAAM,kBAAkB,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Box } from '../Box'\nimport { Vec, VecLike } from '../Vec'\nimport { PI } from '../utils'\nimport { Arc2d } from './Arc2d'\nimport { Edge2d } from './Edge2d'\nimport { Geometry2d, Geometry2dOptions } from './Geometry2d'\n\n/** @public */\nexport class Stadium2d extends Geometry2d {\n\tprivate _w: number\n\tprivate _h: number\n\tprivate _a: Arc2d\n\tprivate _b: Edge2d\n\tprivate _c: Arc2d\n\tprivate _d: Edge2d\n\n\tconstructor(\n\t\tpublic config: Omit<Geometry2dOptions, 'isClosed'> & {\n\t\t\twidth: number\n\t\t\theight: number\n\t\t}\n\t) {\n\t\tsuper({ ...config, isClosed: true })\n\t\tconst { width: w, height: h } = config\n\t\tthis._w = w\n\t\tthis._h = h\n\n\t\tif (h > w) {\n\t\t\tconst r = w / 2\n\t\t\tthis._a = new Arc2d({\n\t\t\t\tstart: new Vec(0, r),\n\t\t\t\tend: new Vec(w, r),\n\t\t\t\tcenter: new Vec(w / 2, r),\n\t\t\t\tsweepFlag: 1,\n\t\t\t\tlargeArcFlag: 1,\n\t\t\t})\n\t\t\tthis._b = new Edge2d({ start: new Vec(w, r), end: new Vec(w, h - r) })\n\t\t\tthis._c = new Arc2d({\n\t\t\t\tstart: new Vec(w, h - r),\n\t\t\t\tend: new Vec(0, h - r),\n\t\t\t\tcenter: new Vec(w / 2, h - r),\n\t\t\t\tsweepFlag: 1,\n\t\t\t\tlargeArcFlag: 1,\n\t\t\t})\n\t\t\tthis._d = new Edge2d({ start: new Vec(0, h - r), end: new Vec(0, r) })\n\t\t} else {\n\t\t\tconst r = h / 2\n\t\t\tthis._a = new Arc2d({\n\t\t\t\tstart: new Vec(r, h),\n\t\t\t\tend: new Vec(r, 0),\n\t\t\t\tcenter: new Vec(r, r),\n\t\t\t\tsweepFlag: 1,\n\t\t\t\tlargeArcFlag: 1,\n\t\t\t})\n\t\t\tthis._b = new Edge2d({ start: new Vec(r, 0), end: new Vec(w - r, 0) })\n\t\t\tthis._c = new Arc2d({\n\t\t\t\tstart: new Vec(w - r, 0),\n\t\t\t\tend: new Vec(w - r, h),\n\t\t\t\tcenter: new Vec(w - r, r),\n\t\t\t\tsweepFlag: 1,\n\t\t\t\tlargeArcFlag: 1,\n\t\t\t})\n\t\t\tthis._d = new Edge2d({ start: new Vec(w - r, h), end: new Vec(r, h) })\n\t\t}\n\t}\n\n\tnearestPoint(A: VecLike): Vec {\n\t\tlet nearest: Vec | undefined\n\t\tlet dist = Infinity\n\t\tlet _d: number\n\t\tlet p: Vec\n\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = this\n\t\tfor (const part of [a, b, c, d]) {\n\t\t\tp = part.nearestPoint(A)\n\t\t\t_d = Vec.Dist2(p, A)\n\t\t\tif (_d < dist) {\n\t\t\t\tnearest = p\n\t\t\t\tdist = _d\n\t\t\t}\n\t\t}\n\t\tif (!nearest) throw Error('nearest point not found')\n\t\treturn nearest\n\t}\n\n\thitTestLineSegment(A: VecLike, B: VecLike): boolean {\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = this\n\t\treturn [a, b, c, d].some((edge) => edge.hitTestLineSegment(A, B))\n\t}\n\n\tgetVertices() {\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = this\n\t\treturn [a, b, c, d].reduce<Vec[]>((a, p) => {\n\t\t\ta.push(...p.vertices)\n\t\t\treturn a\n\t\t}, [])\n\t}\n\n\tgetBounds() {\n\t\treturn new Box(0, 0, this._w, this._h)\n\t}\n\n\tgetLength() {\n\t\tconst { _h: h, _w: w } = this\n\t\tif (h > w) return (PI * (w / 2) + (h - w)) * 2\n\t\telse return (PI * (h / 2) + (w - h)) * 2\n\t}\n\n\tgetSvgPathData() {\n\t\tconst { _a: a, _b: b, _c: c, _d: d } = this\n\t\treturn [a, b, c, d].map((p, i) => p.getSvgPathData(i === 0)).join(' ') + ' Z'\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW;AACpB,SAAS,WAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,kBAAqC;AAGvC,MAAM,kBAAkB,WAAW;AAAA,EAQzC,YACQ,QAIN;AACD,UAAM,EAAE,GAAG,QAAQ,UAAU,KAAK,CAAC;AAL5B;AAMP,UAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,IAAI;AAChC,SAAK,KAAK;AACV,SAAK,KAAK;AAEV,QAAI,IAAI,GAAG;AACV,YAAM,IAAI,IAAI;AACd,WAAK,KAAK,IAAI,MAAM;AAAA,QACnB,OAAO,IAAI,IAAI,GAAG,CAAC;AAAA,QACnB,KAAK,IAAI,IAAI,GAAG,CAAC;AAAA,QACjB,QAAQ,IAAI,IAAI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SAAQ,MAAM,IAAI,MAAM,IAAI,MAAM;AAAA,EACxC;AAAA,EAEA,iBAAiB;AAChB,UAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,IAAI;AACvC,WAAO,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,MAAM,EAAE,eAAe,MAAM,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI;AAAA,EAC1E;AACD;",
|
|
6
6
|
"names": ["a"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/utils/areShapesContentEqual.ts"],
|
|
4
|
-
"sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\n\nexport const areShapesContentEqual = (a: TLShape, b: TLShape) =>\n\ta.props === b.props && a.meta === b.meta\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { TLShape } from '@tldraw/tlschema'\n\n/** @public */\nexport const areShapesContentEqual = (a: TLShape, b: TLShape) =>\n\ta.parentId === b.parentId && a.props === b.props && a.meta === b.meta\n"],
|
|
5
|
+
"mappings": "AAGO,MAAM,wBAAwB,CAAC,GAAY,MACjD,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist-esm/version.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const version = "3.14.0-canary.
|
|
1
|
+
const version = "3.14.0-canary.f6a0206007b3";
|
|
2
2
|
const publishDates = {
|
|
3
3
|
major: "2024-09-13T14:36:29.063Z",
|
|
4
|
-
minor: "2025-
|
|
5
|
-
patch: "2025-
|
|
4
|
+
minor: "2025-06-03T09:18:36.909Z",
|
|
5
|
+
patch: "2025-06-03T09:18:36.909Z"
|
|
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 = '3.14.0-canary.
|
|
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 = '3.14.0-canary.f6a0206007b3'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-06-03T09:18:36.909Z',\n\tpatch: '2025-06-03T09:18:36.909Z',\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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "A tiny little drawing app (editor).",
|
|
4
|
-
"version": "3.14.0-canary.
|
|
4
|
+
"version": "3.14.0-canary.f6a0206007b3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"@tiptap/core": "^2.9.1",
|
|
49
49
|
"@tiptap/pm": "^2.9.1",
|
|
50
50
|
"@tiptap/react": "^2.9.1",
|
|
51
|
-
"@tldraw/state": "3.14.0-canary.
|
|
52
|
-
"@tldraw/state-react": "3.14.0-canary.
|
|
53
|
-
"@tldraw/store": "3.14.0-canary.
|
|
54
|
-
"@tldraw/tlschema": "3.14.0-canary.
|
|
55
|
-
"@tldraw/utils": "3.14.0-canary.
|
|
56
|
-
"@tldraw/validate": "3.14.0-canary.
|
|
51
|
+
"@tldraw/state": "3.14.0-canary.f6a0206007b3",
|
|
52
|
+
"@tldraw/state-react": "3.14.0-canary.f6a0206007b3",
|
|
53
|
+
"@tldraw/store": "3.14.0-canary.f6a0206007b3",
|
|
54
|
+
"@tldraw/tlschema": "3.14.0-canary.f6a0206007b3",
|
|
55
|
+
"@tldraw/utils": "3.14.0-canary.f6a0206007b3",
|
|
56
|
+
"@tldraw/validate": "3.14.0-canary.f6a0206007b3",
|
|
57
57
|
"@types/core-js": "^2.5.8",
|
|
58
58
|
"@use-gesture/react": "^10.3.1",
|
|
59
59
|
"classnames": "^2.5.1",
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import 'core-js/stable/array/flat-map.js'
|
|
|
4
4
|
import 'core-js/stable/array/flat.js'
|
|
5
5
|
import 'core-js/stable/string/at.js'
|
|
6
6
|
import 'core-js/stable/string/replace-all.js'
|
|
7
|
+
export { areShapesContentEqual } from './lib/utils/areShapesContentEqual'
|
|
7
8
|
|
|
8
9
|
// eslint-disable-next-line local/no-export-star
|
|
9
10
|
export * from '@tldraw/state'
|
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -506,6 +506,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
506
506
|
shape: {
|
|
507
507
|
afterChange: (shapeBefore, shapeAfter) => {
|
|
508
508
|
for (const binding of this.getBindingsInvolvingShape(shapeAfter)) {
|
|
509
|
+
if (areShapesContentEqual(shapeBefore, shapeAfter)) continue
|
|
510
|
+
|
|
509
511
|
invalidBindingTypes.add(binding.type)
|
|
510
512
|
if (binding.fromId === shapeAfter.id) {
|
|
511
513
|
this.getBindingUtil(binding).onAfterChangeFromShape?.({
|
|
@@ -5796,8 +5798,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5796
5798
|
parent: TLParentId | TLPage | TLShape,
|
|
5797
5799
|
visitor: (id: TLShapeId) => void | false
|
|
5798
5800
|
): this {
|
|
5799
|
-
const
|
|
5800
|
-
const children = this.getSortedChildIdsForParent(parentId)
|
|
5801
|
+
const children = this.getSortedChildIdsForParent(parent)
|
|
5801
5802
|
for (const id of children) {
|
|
5802
5803
|
if (visitor(id) === false) continue
|
|
5803
5804
|
this.visitDescendants(id, visitor)
|
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
import { computed, isUninitialized } from '@tldraw/state'
|
|
2
2
|
import { TLShapeId } from '@tldraw/tlschema'
|
|
3
|
-
import { Box } from '../../primitives/Box'
|
|
4
3
|
import { Editor } from '../Editor'
|
|
5
4
|
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
function fromScratch(editor: Editor): Set<TLShapeId> {
|
|
6
|
+
const shapesIds = editor.getCurrentPageShapeIds()
|
|
7
|
+
const viewportPageBounds = editor.getViewportPageBounds()
|
|
8
|
+
const notVisibleShapes = new Set<TLShapeId>()
|
|
9
|
+
shapesIds.forEach((id) => {
|
|
10
|
+
// If the shape is fully outside of the viewport page bounds, add it to the set.
|
|
11
|
+
// We'll ignore masks here, since they're more expensive to compute and the overhead is not worth it.
|
|
12
|
+
const pageBounds = editor.getShapePageBounds(id)
|
|
13
|
+
if (pageBounds === undefined || !viewportPageBounds.includes(pageBounds)) {
|
|
14
|
+
notVisibleShapes.add(id)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
return notVisibleShapes
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Incremental derivation of not visible shapes.
|
|
17
|
-
* Non visible shapes are shapes outside of the viewport page bounds
|
|
22
|
+
* Non visible shapes are shapes outside of the viewport page bounds.
|
|
18
23
|
*
|
|
19
24
|
* @param editor - Instance of the tldraw Editor.
|
|
20
25
|
* @returns Incremental derivation of non visible shapes.
|
|
21
26
|
*/
|
|
22
|
-
export
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const notVisibleShapes = new Set<TLShapeId>()
|
|
27
|
-
shapes.forEach((id) => {
|
|
28
|
-
if (isShapeNotVisible(editor, id, viewportPageBounds)) {
|
|
29
|
-
notVisibleShapes.add(id)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
return notVisibleShapes
|
|
33
|
-
}
|
|
34
|
-
return computed<Set<TLShapeId>>('notVisibleShapes', (prevValue) => {
|
|
27
|
+
export function notVisibleShapes(editor: Editor) {
|
|
28
|
+
return computed<Set<TLShapeId>>('notVisibleShapes', function updateNotVisibleShapes(prevValue) {
|
|
29
|
+
const nextValue = fromScratch(editor)
|
|
30
|
+
|
|
35
31
|
if (isUninitialized(prevValue)) {
|
|
36
|
-
return
|
|
32
|
+
return nextValue
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
// If there are more or less shapes, we know there's a change
|
|
41
36
|
if (prevValue.size !== nextValue.size) return nextValue
|
|
37
|
+
|
|
38
|
+
// If any of the old shapes are not in the new set, we know there's a change
|
|
42
39
|
for (const prev of prevValue) {
|
|
43
40
|
if (!nextValue.has(prev)) {
|
|
44
41
|
return nextValue
|
|
45
42
|
}
|
|
46
43
|
}
|
|
44
|
+
|
|
45
|
+
// If we've made it here, we know that the set is the same
|
|
47
46
|
return prevValue
|
|
48
47
|
})
|
|
49
48
|
}
|