modern-text 1.11.1 → 2.0.0

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.
Files changed (30) hide show
  1. package/README.md +283 -22
  2. package/dist/deformations/index.cjs +566 -0
  3. package/dist/deformations/index.d.cts +11 -0
  4. package/dist/deformations/index.d.mts +11 -0
  5. package/dist/deformations/index.d.ts +11 -0
  6. package/dist/deformations/index.mjs +563 -0
  7. package/dist/index.cjs +15 -3
  8. package/dist/index.d.cts +186 -6
  9. package/dist/index.d.mts +186 -6
  10. package/dist/index.d.ts +186 -6
  11. package/dist/index.js +6 -5
  12. package/dist/index.mjs +4 -2
  13. package/dist/shared/modern-text.B2xfrqDc.cjs +556 -0
  14. package/dist/shared/modern-text.BD7PBYt7.d.cts +100 -0
  15. package/dist/shared/modern-text.BxijkspX.d.ts +100 -0
  16. package/dist/shared/{modern-text.BKZQdmgG.cjs → modern-text.CBgc-cQ1.cjs} +288 -18
  17. package/dist/shared/modern-text.CYa4lfoG.d.mts +100 -0
  18. package/dist/shared/{modern-text.Dqw5Z6MV.mjs → modern-text.ChzjFjsk.mjs} +283 -13
  19. package/dist/shared/{modern-text.Db7Uoht6.d.cts → modern-text.D4WopQCu.d.cts} +56 -22
  20. package/dist/shared/{modern-text.Db7Uoht6.d.mts → modern-text.D4WopQCu.d.mts} +56 -22
  21. package/dist/shared/{modern-text.Db7Uoht6.d.ts → modern-text.D4WopQCu.d.ts} +56 -22
  22. package/dist/shared/modern-text.JF1ny7A-.mjs +550 -0
  23. package/dist/shared/modern-text.MC5bIC9E.cjs +316 -0
  24. package/dist/shared/modern-text.fT17R5HY.mjs +310 -0
  25. package/dist/web-components/index.cjs +2 -1
  26. package/dist/web-components/index.d.cts +1 -1
  27. package/dist/web-components/index.d.mts +1 -1
  28. package/dist/web-components/index.d.ts +1 -1
  29. package/dist/web-components/index.mjs +2 -1
  30. package/package.json +12 -7
@@ -0,0 +1,316 @@
1
+ 'use strict';
2
+
3
+ const modernPath2d = require('modern-path2d');
4
+
5
+ class ShapeCurve {
6
+ arcLengthDivisions = 200;
7
+ _cacheArcLengths;
8
+ _needsUpdate = false;
9
+ getPointAt(u, output = new modernPath2d.Vector2()) {
10
+ return this.getPoint(this.getUToTMapping(u), output);
11
+ }
12
+ getLength() {
13
+ const lengths = this.getLengths();
14
+ return lengths[lengths.length - 1];
15
+ }
16
+ getLengths(divisions = this.arcLengthDivisions) {
17
+ if (this._cacheArcLengths && this._cacheArcLengths.length === divisions + 1 && !this._needsUpdate) {
18
+ return this._cacheArcLengths;
19
+ }
20
+ this._needsUpdate = false;
21
+ const cache = [0];
22
+ let last = this.getPoint(0);
23
+ let sum = 0;
24
+ for (let i = 1; i <= divisions; i++) {
25
+ const current = this.getPoint(i / divisions);
26
+ sum += current.distanceTo(last);
27
+ cache.push(sum);
28
+ last = current;
29
+ }
30
+ this._cacheArcLengths = cache;
31
+ return cache;
32
+ }
33
+ getUToTMapping(u, distance) {
34
+ const lengths = this.getLengths();
35
+ const lengthsLen = lengths.length;
36
+ const targetLength = distance === void 0 ? u * lengths[lengthsLen - 1] : distance;
37
+ let low = 0;
38
+ let high = lengthsLen - 1;
39
+ let i = 0;
40
+ while (low <= high) {
41
+ i = Math.floor(low + (high - low) / 2);
42
+ const comparison = lengths[i] - targetLength;
43
+ if (comparison < 0) {
44
+ low = i + 1;
45
+ } else if (comparison > 0) {
46
+ high = i - 1;
47
+ } else {
48
+ high = i;
49
+ break;
50
+ }
51
+ }
52
+ i = high;
53
+ if (lengths[i] === targetLength) {
54
+ return i / (lengthsLen - 1);
55
+ }
56
+ const lengthBefore = lengths[i];
57
+ const lengthAfter = lengths[i + 1];
58
+ const segmentLength = lengthAfter - lengthBefore;
59
+ const segmentFraction = (targetLength - lengthBefore) / segmentLength;
60
+ return (i + segmentFraction) / (lengthsLen - 1);
61
+ }
62
+ getTangent(t, output = new modernPath2d.Vector2()) {
63
+ const delta = 1e-4;
64
+ const t1 = Math.max(0, t - delta);
65
+ const t2 = Math.min(1, t + delta);
66
+ return output.copyFrom(this.getPoint(t2).sub(this.getPoint(t1)).normalize());
67
+ }
68
+ getNormal(t, output = new modernPath2d.Vector2()) {
69
+ this.getTangent(t, output);
70
+ return output.set(-output.y, output.x).normalize();
71
+ }
72
+ }
73
+ class SegmentedCurve extends ShapeCurve {
74
+ curveT = 0;
75
+ getPoint(t, output = new modernPath2d.Vector2()) {
76
+ return this.getCurve(t).getPoint(this.curveT, output);
77
+ }
78
+ getPointAt(u, output = new modernPath2d.Vector2()) {
79
+ return this.getPoint(u, output);
80
+ }
81
+ getTangent(t, output = new modernPath2d.Vector2()) {
82
+ return this.getCurve(t).getTangent(this.curveT, output);
83
+ }
84
+ getNormal(t, output = new modernPath2d.Vector2()) {
85
+ return this.getCurve(t).getNormal(this.curveT, output);
86
+ }
87
+ }
88
+ class LineShapeCurve extends ShapeCurve {
89
+ constructor(start, end) {
90
+ super();
91
+ this.start = start;
92
+ this.end = end;
93
+ }
94
+ getPoint(t, output = new modernPath2d.Vector2()) {
95
+ if (t === 1) {
96
+ output.copyFrom(this.end);
97
+ } else {
98
+ output.copyFrom(this.end).sub(this.start).scale(t).add(this.start);
99
+ }
100
+ return output;
101
+ }
102
+ getPointAt(u, output = new modernPath2d.Vector2()) {
103
+ return this.getPoint(u, output);
104
+ }
105
+ getTangent(_t, output = new modernPath2d.Vector2()) {
106
+ return output.subVectors(this.end, this.start).normalize();
107
+ }
108
+ }
109
+ class CircleCurve extends ShapeCurve {
110
+ constructor(center, radius, start = 0, end = Math.PI * 2) {
111
+ super();
112
+ this.center = center;
113
+ this.radius = radius;
114
+ this.start = start;
115
+ this.end = end;
116
+ }
117
+ getPoint(t, output = new modernPath2d.Vector2()) {
118
+ return output.copyFrom(this.center).add(this.getNormal(t).scale(this.radius));
119
+ }
120
+ getTangent(t, output = new modernPath2d.Vector2()) {
121
+ const { x, y } = this.getNormal(t);
122
+ return output.set(-y, x);
123
+ }
124
+ getNormal(t, output = new modernPath2d.Vector2()) {
125
+ const { start, end } = this;
126
+ const _t = t * (end - start) + start - 0.5 * Math.PI;
127
+ return output.set(Math.cos(_t), Math.sin(_t));
128
+ }
129
+ }
130
+ class EllipseCurve extends ShapeCurve {
131
+ constructor(center = new modernPath2d.Vector2(), radiusX = 1, radiusY = 1, rotation = 0, startAngle = 0, endAngle = Math.PI * 2, clockwise = false) {
132
+ super();
133
+ this.center = center;
134
+ this.radiusX = radiusX;
135
+ this.radiusY = radiusY;
136
+ this.rotation = rotation;
137
+ this.startAngle = startAngle;
138
+ this.endAngle = endAngle;
139
+ this.clockwise = clockwise;
140
+ }
141
+ getPoint(t, output = new modernPath2d.Vector2()) {
142
+ const twoPi = Math.PI * 2;
143
+ let deltaAngle = this.endAngle - this.startAngle;
144
+ const samePoints = Math.abs(deltaAngle) < Number.EPSILON;
145
+ while (deltaAngle < 0) {
146
+ deltaAngle += twoPi;
147
+ }
148
+ while (deltaAngle > twoPi) {
149
+ deltaAngle -= twoPi;
150
+ }
151
+ if (deltaAngle < Number.EPSILON) {
152
+ deltaAngle = samePoints ? 0 : twoPi;
153
+ }
154
+ if (this.clockwise && !samePoints) {
155
+ deltaAngle = deltaAngle === twoPi ? -twoPi : deltaAngle - twoPi;
156
+ }
157
+ const angle = this.startAngle + t * deltaAngle;
158
+ let x = this.center.x + this.radiusX * Math.cos(angle);
159
+ let y = this.center.y + this.radiusY * Math.sin(angle);
160
+ if (this.rotation !== 0) {
161
+ const cos = Math.cos(this.rotation);
162
+ const sin = Math.sin(this.rotation);
163
+ const tx = x - this.center.x;
164
+ const ty = y - this.center.y;
165
+ x = tx * cos - ty * sin + this.center.x;
166
+ y = tx * sin + ty * cos + this.center.y;
167
+ }
168
+ return output.set(x, y);
169
+ }
170
+ }
171
+ class HeartCurve extends SegmentedCurve {
172
+ constructor(center, size, start = 0, end = 1) {
173
+ super();
174
+ this.center = center;
175
+ this.size = size;
176
+ this.start = start;
177
+ this.end = end;
178
+ this.update();
179
+ }
180
+ curves = [];
181
+ update() {
182
+ const { x, y } = this.center;
183
+ const c1Center = new modernPath2d.Vector2(x + 0.5 * this.size, y - 0.5 * this.size);
184
+ const c5Center = new modernPath2d.Vector2(x - 0.5 * this.size, y - 0.5 * this.size);
185
+ const c3Center = new modernPath2d.Vector2(x, y + 0.5 * this.size);
186
+ const curve1 = new CircleCurve(c1Center, Math.SQRT1_2 * this.size, -0.25 * Math.PI, 0.75 * Math.PI);
187
+ const curve5 = new CircleCurve(c5Center, Math.SQRT1_2 * this.size, -0.75 * Math.PI, 0.25 * Math.PI);
188
+ const curve3 = new CircleCurve(c3Center, 0.5 * Math.SQRT1_2 * this.size, 0.75 * Math.PI, 1.25 * Math.PI);
189
+ const bottom = new modernPath2d.Vector2(x, y + this.size);
190
+ const right = new modernPath2d.Vector2(x + this.size, y);
191
+ const rightInner = modernPath2d.Vector2.lerp(right, bottom, 0.75);
192
+ const left = new modernPath2d.Vector2(x - this.size, y);
193
+ const leftInner = modernPath2d.Vector2.lerp(left, bottom, 0.75);
194
+ const curve2 = new LineShapeCurve(right, rightInner);
195
+ const curve4 = new LineShapeCurve(leftInner, left);
196
+ this.curves = [curve1, curve2, curve3, curve4, curve5];
197
+ return this;
198
+ }
199
+ getCurve(t) {
200
+ let val = (t * (this.end - this.start) + this.start) % 1;
201
+ if (val < 0) {
202
+ val += 1;
203
+ }
204
+ val *= 9 * Math.PI / 8 + 1.5;
205
+ const PI_1_2 = 0.5 * Math.PI;
206
+ let index;
207
+ if (val < PI_1_2) {
208
+ index = 0;
209
+ this.curveT = val / PI_1_2;
210
+ } else if (val < PI_1_2 + 0.75) {
211
+ index = 1;
212
+ this.curveT = (val - PI_1_2) / 0.75;
213
+ } else if (val < 5 * Math.PI / 8 + 0.75) {
214
+ index = 2;
215
+ this.curveT = (val - PI_1_2 - 0.75) / (Math.PI / 8);
216
+ } else if (val < 5 * Math.PI / 8 + 1.5) {
217
+ index = 3;
218
+ this.curveT = (val - 5 * Math.PI / 8 - 0.75) / 0.75;
219
+ } else {
220
+ index = 4;
221
+ this.curveT = (val - 5 * Math.PI / 8 - 1.5) / PI_1_2;
222
+ }
223
+ return this.curves[index];
224
+ }
225
+ }
226
+ class PolygonCurve extends SegmentedCurve {
227
+ constructor(center, radius = 0, number = 0, start = 0, end = 1) {
228
+ super();
229
+ this.center = center;
230
+ this.radius = radius;
231
+ this.number = number;
232
+ this.start = start;
233
+ this.end = end;
234
+ this.update();
235
+ }
236
+ curves = [];
237
+ points = [];
238
+ update() {
239
+ for (let i = 0; i < this.number; i++) {
240
+ let radian = i * 2 * Math.PI / this.number;
241
+ radian -= 0.5 * Math.PI;
242
+ this.points.push(
243
+ new modernPath2d.Vector2(this.radius * Math.cos(radian), this.radius * Math.sin(radian)).add(this.center)
244
+ );
245
+ }
246
+ for (let i = 0; i < this.number; i++) {
247
+ this.curves.push(new LineShapeCurve(this.points[i], this.points[(i + 1) % this.number]));
248
+ }
249
+ return this;
250
+ }
251
+ getCurve(t) {
252
+ let pos = (t * (this.end - this.start) + this.start) % 1;
253
+ if (pos < 0) {
254
+ pos += 1;
255
+ }
256
+ const v = pos * this.number;
257
+ const index = Math.floor(v);
258
+ this.curveT = v - index;
259
+ return this.curves[index];
260
+ }
261
+ }
262
+ class RectangularCurve extends SegmentedCurve {
263
+ constructor(center, rx, aspectRatio = 1, start = 0, end = 1) {
264
+ super();
265
+ this.center = center;
266
+ this.rx = rx;
267
+ this.aspectRatio = aspectRatio;
268
+ this.start = start;
269
+ this.end = end;
270
+ this.update();
271
+ }
272
+ curves = [];
273
+ update() {
274
+ const { x, y } = this.center;
275
+ const offsetX = this.rx;
276
+ const offsetY = this.rx / this.aspectRatio;
277
+ const points = [
278
+ new modernPath2d.Vector2(x - offsetX, y - offsetY),
279
+ new modernPath2d.Vector2(x + offsetX, y - offsetY),
280
+ new modernPath2d.Vector2(x + offsetX, y + offsetY),
281
+ new modernPath2d.Vector2(x - offsetX, y + offsetY)
282
+ ];
283
+ for (let i = 0; i < 4; i++) {
284
+ this.curves.push(new LineShapeCurve(points[i].clone(), points[(i + 1) % 4].clone()));
285
+ }
286
+ return this;
287
+ }
288
+ getCurve(t) {
289
+ let current = (t * (this.end - this.start) + this.start) % 1;
290
+ if (current < 0) {
291
+ current += 1;
292
+ }
293
+ current *= (1 + this.aspectRatio) * 2;
294
+ let i;
295
+ if (current < this.aspectRatio) {
296
+ i = 0;
297
+ this.curveT = current / this.aspectRatio;
298
+ } else if (current < this.aspectRatio + 1) {
299
+ i = 1;
300
+ this.curveT = current - this.aspectRatio;
301
+ } else if (current < 2 * this.aspectRatio + 1) {
302
+ i = 2;
303
+ this.curveT = (current - this.aspectRatio - 1) / this.aspectRatio;
304
+ } else {
305
+ i = 3;
306
+ this.curveT = current - 2 * this.aspectRatio - 1;
307
+ }
308
+ return this.curves[i];
309
+ }
310
+ }
311
+
312
+ exports.CircleCurve = CircleCurve;
313
+ exports.EllipseCurve = EllipseCurve;
314
+ exports.HeartCurve = HeartCurve;
315
+ exports.PolygonCurve = PolygonCurve;
316
+ exports.RectangularCurve = RectangularCurve;
@@ -0,0 +1,310 @@
1
+ import { Vector2 } from 'modern-path2d';
2
+
3
+ class ShapeCurve {
4
+ arcLengthDivisions = 200;
5
+ _cacheArcLengths;
6
+ _needsUpdate = false;
7
+ getPointAt(u, output = new Vector2()) {
8
+ return this.getPoint(this.getUToTMapping(u), output);
9
+ }
10
+ getLength() {
11
+ const lengths = this.getLengths();
12
+ return lengths[lengths.length - 1];
13
+ }
14
+ getLengths(divisions = this.arcLengthDivisions) {
15
+ if (this._cacheArcLengths && this._cacheArcLengths.length === divisions + 1 && !this._needsUpdate) {
16
+ return this._cacheArcLengths;
17
+ }
18
+ this._needsUpdate = false;
19
+ const cache = [0];
20
+ let last = this.getPoint(0);
21
+ let sum = 0;
22
+ for (let i = 1; i <= divisions; i++) {
23
+ const current = this.getPoint(i / divisions);
24
+ sum += current.distanceTo(last);
25
+ cache.push(sum);
26
+ last = current;
27
+ }
28
+ this._cacheArcLengths = cache;
29
+ return cache;
30
+ }
31
+ getUToTMapping(u, distance) {
32
+ const lengths = this.getLengths();
33
+ const lengthsLen = lengths.length;
34
+ const targetLength = distance === void 0 ? u * lengths[lengthsLen - 1] : distance;
35
+ let low = 0;
36
+ let high = lengthsLen - 1;
37
+ let i = 0;
38
+ while (low <= high) {
39
+ i = Math.floor(low + (high - low) / 2);
40
+ const comparison = lengths[i] - targetLength;
41
+ if (comparison < 0) {
42
+ low = i + 1;
43
+ } else if (comparison > 0) {
44
+ high = i - 1;
45
+ } else {
46
+ high = i;
47
+ break;
48
+ }
49
+ }
50
+ i = high;
51
+ if (lengths[i] === targetLength) {
52
+ return i / (lengthsLen - 1);
53
+ }
54
+ const lengthBefore = lengths[i];
55
+ const lengthAfter = lengths[i + 1];
56
+ const segmentLength = lengthAfter - lengthBefore;
57
+ const segmentFraction = (targetLength - lengthBefore) / segmentLength;
58
+ return (i + segmentFraction) / (lengthsLen - 1);
59
+ }
60
+ getTangent(t, output = new Vector2()) {
61
+ const delta = 1e-4;
62
+ const t1 = Math.max(0, t - delta);
63
+ const t2 = Math.min(1, t + delta);
64
+ return output.copyFrom(this.getPoint(t2).sub(this.getPoint(t1)).normalize());
65
+ }
66
+ getNormal(t, output = new Vector2()) {
67
+ this.getTangent(t, output);
68
+ return output.set(-output.y, output.x).normalize();
69
+ }
70
+ }
71
+ class SegmentedCurve extends ShapeCurve {
72
+ curveT = 0;
73
+ getPoint(t, output = new Vector2()) {
74
+ return this.getCurve(t).getPoint(this.curveT, output);
75
+ }
76
+ getPointAt(u, output = new Vector2()) {
77
+ return this.getPoint(u, output);
78
+ }
79
+ getTangent(t, output = new Vector2()) {
80
+ return this.getCurve(t).getTangent(this.curveT, output);
81
+ }
82
+ getNormal(t, output = new Vector2()) {
83
+ return this.getCurve(t).getNormal(this.curveT, output);
84
+ }
85
+ }
86
+ class LineShapeCurve extends ShapeCurve {
87
+ constructor(start, end) {
88
+ super();
89
+ this.start = start;
90
+ this.end = end;
91
+ }
92
+ getPoint(t, output = new Vector2()) {
93
+ if (t === 1) {
94
+ output.copyFrom(this.end);
95
+ } else {
96
+ output.copyFrom(this.end).sub(this.start).scale(t).add(this.start);
97
+ }
98
+ return output;
99
+ }
100
+ getPointAt(u, output = new Vector2()) {
101
+ return this.getPoint(u, output);
102
+ }
103
+ getTangent(_t, output = new Vector2()) {
104
+ return output.subVectors(this.end, this.start).normalize();
105
+ }
106
+ }
107
+ class CircleCurve extends ShapeCurve {
108
+ constructor(center, radius, start = 0, end = Math.PI * 2) {
109
+ super();
110
+ this.center = center;
111
+ this.radius = radius;
112
+ this.start = start;
113
+ this.end = end;
114
+ }
115
+ getPoint(t, output = new Vector2()) {
116
+ return output.copyFrom(this.center).add(this.getNormal(t).scale(this.radius));
117
+ }
118
+ getTangent(t, output = new Vector2()) {
119
+ const { x, y } = this.getNormal(t);
120
+ return output.set(-y, x);
121
+ }
122
+ getNormal(t, output = new Vector2()) {
123
+ const { start, end } = this;
124
+ const _t = t * (end - start) + start - 0.5 * Math.PI;
125
+ return output.set(Math.cos(_t), Math.sin(_t));
126
+ }
127
+ }
128
+ class EllipseCurve extends ShapeCurve {
129
+ constructor(center = new Vector2(), radiusX = 1, radiusY = 1, rotation = 0, startAngle = 0, endAngle = Math.PI * 2, clockwise = false) {
130
+ super();
131
+ this.center = center;
132
+ this.radiusX = radiusX;
133
+ this.radiusY = radiusY;
134
+ this.rotation = rotation;
135
+ this.startAngle = startAngle;
136
+ this.endAngle = endAngle;
137
+ this.clockwise = clockwise;
138
+ }
139
+ getPoint(t, output = new Vector2()) {
140
+ const twoPi = Math.PI * 2;
141
+ let deltaAngle = this.endAngle - this.startAngle;
142
+ const samePoints = Math.abs(deltaAngle) < Number.EPSILON;
143
+ while (deltaAngle < 0) {
144
+ deltaAngle += twoPi;
145
+ }
146
+ while (deltaAngle > twoPi) {
147
+ deltaAngle -= twoPi;
148
+ }
149
+ if (deltaAngle < Number.EPSILON) {
150
+ deltaAngle = samePoints ? 0 : twoPi;
151
+ }
152
+ if (this.clockwise && !samePoints) {
153
+ deltaAngle = deltaAngle === twoPi ? -twoPi : deltaAngle - twoPi;
154
+ }
155
+ const angle = this.startAngle + t * deltaAngle;
156
+ let x = this.center.x + this.radiusX * Math.cos(angle);
157
+ let y = this.center.y + this.radiusY * Math.sin(angle);
158
+ if (this.rotation !== 0) {
159
+ const cos = Math.cos(this.rotation);
160
+ const sin = Math.sin(this.rotation);
161
+ const tx = x - this.center.x;
162
+ const ty = y - this.center.y;
163
+ x = tx * cos - ty * sin + this.center.x;
164
+ y = tx * sin + ty * cos + this.center.y;
165
+ }
166
+ return output.set(x, y);
167
+ }
168
+ }
169
+ class HeartCurve extends SegmentedCurve {
170
+ constructor(center, size, start = 0, end = 1) {
171
+ super();
172
+ this.center = center;
173
+ this.size = size;
174
+ this.start = start;
175
+ this.end = end;
176
+ this.update();
177
+ }
178
+ curves = [];
179
+ update() {
180
+ const { x, y } = this.center;
181
+ const c1Center = new Vector2(x + 0.5 * this.size, y - 0.5 * this.size);
182
+ const c5Center = new Vector2(x - 0.5 * this.size, y - 0.5 * this.size);
183
+ const c3Center = new Vector2(x, y + 0.5 * this.size);
184
+ const curve1 = new CircleCurve(c1Center, Math.SQRT1_2 * this.size, -0.25 * Math.PI, 0.75 * Math.PI);
185
+ const curve5 = new CircleCurve(c5Center, Math.SQRT1_2 * this.size, -0.75 * Math.PI, 0.25 * Math.PI);
186
+ const curve3 = new CircleCurve(c3Center, 0.5 * Math.SQRT1_2 * this.size, 0.75 * Math.PI, 1.25 * Math.PI);
187
+ const bottom = new Vector2(x, y + this.size);
188
+ const right = new Vector2(x + this.size, y);
189
+ const rightInner = Vector2.lerp(right, bottom, 0.75);
190
+ const left = new Vector2(x - this.size, y);
191
+ const leftInner = Vector2.lerp(left, bottom, 0.75);
192
+ const curve2 = new LineShapeCurve(right, rightInner);
193
+ const curve4 = new LineShapeCurve(leftInner, left);
194
+ this.curves = [curve1, curve2, curve3, curve4, curve5];
195
+ return this;
196
+ }
197
+ getCurve(t) {
198
+ let val = (t * (this.end - this.start) + this.start) % 1;
199
+ if (val < 0) {
200
+ val += 1;
201
+ }
202
+ val *= 9 * Math.PI / 8 + 1.5;
203
+ const PI_1_2 = 0.5 * Math.PI;
204
+ let index;
205
+ if (val < PI_1_2) {
206
+ index = 0;
207
+ this.curveT = val / PI_1_2;
208
+ } else if (val < PI_1_2 + 0.75) {
209
+ index = 1;
210
+ this.curveT = (val - PI_1_2) / 0.75;
211
+ } else if (val < 5 * Math.PI / 8 + 0.75) {
212
+ index = 2;
213
+ this.curveT = (val - PI_1_2 - 0.75) / (Math.PI / 8);
214
+ } else if (val < 5 * Math.PI / 8 + 1.5) {
215
+ index = 3;
216
+ this.curveT = (val - 5 * Math.PI / 8 - 0.75) / 0.75;
217
+ } else {
218
+ index = 4;
219
+ this.curveT = (val - 5 * Math.PI / 8 - 1.5) / PI_1_2;
220
+ }
221
+ return this.curves[index];
222
+ }
223
+ }
224
+ class PolygonCurve extends SegmentedCurve {
225
+ constructor(center, radius = 0, number = 0, start = 0, end = 1) {
226
+ super();
227
+ this.center = center;
228
+ this.radius = radius;
229
+ this.number = number;
230
+ this.start = start;
231
+ this.end = end;
232
+ this.update();
233
+ }
234
+ curves = [];
235
+ points = [];
236
+ update() {
237
+ for (let i = 0; i < this.number; i++) {
238
+ let radian = i * 2 * Math.PI / this.number;
239
+ radian -= 0.5 * Math.PI;
240
+ this.points.push(
241
+ new Vector2(this.radius * Math.cos(radian), this.radius * Math.sin(radian)).add(this.center)
242
+ );
243
+ }
244
+ for (let i = 0; i < this.number; i++) {
245
+ this.curves.push(new LineShapeCurve(this.points[i], this.points[(i + 1) % this.number]));
246
+ }
247
+ return this;
248
+ }
249
+ getCurve(t) {
250
+ let pos = (t * (this.end - this.start) + this.start) % 1;
251
+ if (pos < 0) {
252
+ pos += 1;
253
+ }
254
+ const v = pos * this.number;
255
+ const index = Math.floor(v);
256
+ this.curveT = v - index;
257
+ return this.curves[index];
258
+ }
259
+ }
260
+ class RectangularCurve extends SegmentedCurve {
261
+ constructor(center, rx, aspectRatio = 1, start = 0, end = 1) {
262
+ super();
263
+ this.center = center;
264
+ this.rx = rx;
265
+ this.aspectRatio = aspectRatio;
266
+ this.start = start;
267
+ this.end = end;
268
+ this.update();
269
+ }
270
+ curves = [];
271
+ update() {
272
+ const { x, y } = this.center;
273
+ const offsetX = this.rx;
274
+ const offsetY = this.rx / this.aspectRatio;
275
+ const points = [
276
+ new Vector2(x - offsetX, y - offsetY),
277
+ new Vector2(x + offsetX, y - offsetY),
278
+ new Vector2(x + offsetX, y + offsetY),
279
+ new Vector2(x - offsetX, y + offsetY)
280
+ ];
281
+ for (let i = 0; i < 4; i++) {
282
+ this.curves.push(new LineShapeCurve(points[i].clone(), points[(i + 1) % 4].clone()));
283
+ }
284
+ return this;
285
+ }
286
+ getCurve(t) {
287
+ let current = (t * (this.end - this.start) + this.start) % 1;
288
+ if (current < 0) {
289
+ current += 1;
290
+ }
291
+ current *= (1 + this.aspectRatio) * 2;
292
+ let i;
293
+ if (current < this.aspectRatio) {
294
+ i = 0;
295
+ this.curveT = current / this.aspectRatio;
296
+ } else if (current < this.aspectRatio + 1) {
297
+ i = 1;
298
+ this.curveT = current - this.aspectRatio;
299
+ } else if (current < 2 * this.aspectRatio + 1) {
300
+ i = 2;
301
+ this.curveT = (current - this.aspectRatio - 1) / this.aspectRatio;
302
+ } else {
303
+ i = 3;
304
+ this.curveT = current - 2 * this.aspectRatio - 1;
305
+ }
306
+ return this.curves[i];
307
+ }
308
+ }
309
+
310
+ export { CircleCurve as C, EllipseCurve as E, HeartCurve as H, PolygonCurve as P, RectangularCurve as R };
@@ -2,9 +2,10 @@
2
2
 
3
3
  const diff = require('diff');
4
4
  const modernIdoc = require('modern-idoc');
5
- const Text = require('../shared/modern-text.BKZQdmgG.cjs');
5
+ const Text = require('../shared/modern-text.CBgc-cQ1.cjs');
6
6
  require('modern-path2d');
7
7
  require('modern-font');
8
+ require('../shared/modern-text.B2xfrqDc.cjs');
8
9
 
9
10
  var __defProp = Object.defineProperty;
10
11
  var __decorateClass = (decorators, target, key, kind) => {
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.Db7Uoht6.cjs';
2
+ import { T as Text } from '../shared/modern-text.D4WopQCu.cjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.Db7Uoht6.mjs';
2
+ import { T as Text } from '../shared/modern-text.D4WopQCu.mjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.Db7Uoht6.js';
2
+ import { T as Text } from '../shared/modern-text.D4WopQCu.js';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,8 +1,9 @@
1
1
  import { diffChars } from 'diff';
2
2
  import { isCRLF, textContentToString, normalizeCRLF, normalizeTextContent, property } from 'modern-idoc';
3
- import { T as Text } from '../shared/modern-text.Dqw5Z6MV.mjs';
3
+ import { T as Text } from '../shared/modern-text.ChzjFjsk.mjs';
4
4
  import 'modern-path2d';
5
5
  import 'modern-font';
6
+ import '../shared/modern-text.JF1ny7A-.mjs';
6
7
 
7
8
  var __defProp = Object.defineProperty;
8
9
  var __decorateClass = (decorators, target, key, kind) => {