@remotion/rough-notation 4.0.490

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.
@@ -0,0 +1,3060 @@
1
+ // src/Annotation.tsx
2
+ import React2, { useMemo as useMemo3 } from "react";
3
+ import {
4
+ Interactive,
5
+ Sequence
6
+ } from "remotion";
7
+
8
+ // src/create-annotation.tsx
9
+ import {
10
+ createContext,
11
+ createRef,
12
+ useEffect as useEffect2,
13
+ useMemo as useMemo2,
14
+ useState as useState2
15
+ } from "react";
16
+ import { continueRender, delayRender } from "remotion";
17
+
18
+ // src/element-size.ts
19
+ import { useCallback, useEffect, useMemo, useState } from "react";
20
+ var useElementSize = (ref) => {
21
+ const [size, setSize] = useState(() => {
22
+ if (!ref.current) {
23
+ return null;
24
+ }
25
+ const rect = ref.current.getClientRects();
26
+ if (!rect[0]) {
27
+ return null;
28
+ }
29
+ return {
30
+ width: rect[0].width,
31
+ height: rect[0].height,
32
+ left: rect[0].x,
33
+ top: rect[0].y
34
+ };
35
+ });
36
+ const observer = useMemo(() => {
37
+ if (typeof ResizeObserver === "undefined") {
38
+ return null;
39
+ }
40
+ return new ResizeObserver((entries) => {
41
+ const { target } = entries[0];
42
+ const newSize = target.getClientRects();
43
+ if (!newSize?.[0]) {
44
+ setSize(null);
45
+ return;
46
+ }
47
+ const { width, height } = newSize[0];
48
+ setSize({
49
+ width,
50
+ height,
51
+ left: newSize[0].x,
52
+ top: newSize[0].y
53
+ });
54
+ });
55
+ }, []);
56
+ const updateSize = useCallback(() => {
57
+ if (!ref.current) {
58
+ return;
59
+ }
60
+ const rect = ref.current.getClientRects();
61
+ if (!rect[0]) {
62
+ setSize(null);
63
+ return;
64
+ }
65
+ setSize((prevState) => {
66
+ const isSame = prevState && prevState.width === rect[0].width && prevState.height === rect[0].height && prevState.left === rect[0].x && prevState.top === rect[0].y;
67
+ if (isSame) {
68
+ return prevState;
69
+ }
70
+ return {
71
+ width: rect[0].width,
72
+ height: rect[0].height,
73
+ left: rect[0].x,
74
+ top: rect[0].y
75
+ };
76
+ });
77
+ }, [ref]);
78
+ useEffect(() => {
79
+ if (!observer) {
80
+ return;
81
+ }
82
+ const { current } = ref;
83
+ if (current) {
84
+ observer.observe(current);
85
+ }
86
+ return () => {
87
+ if (current) {
88
+ observer.unobserve(current);
89
+ }
90
+ };
91
+ }, [observer, ref, updateSize]);
92
+ return useMemo(() => {
93
+ if (!size) {
94
+ return null;
95
+ }
96
+ return { ...size, refresh: updateSize };
97
+ }, [size, updateSize]);
98
+ };
99
+
100
+ // ../paths/dist/esm/index.mjs
101
+ var tValues = [
102
+ [],
103
+ [],
104
+ [
105
+ -0.5773502691896257,
106
+ 0.5773502691896257
107
+ ],
108
+ [
109
+ 0,
110
+ -0.7745966692414834,
111
+ 0.7745966692414834
112
+ ],
113
+ [
114
+ -0.33998104358485626,
115
+ 0.33998104358485626,
116
+ -0.8611363115940526,
117
+ 0.8611363115940526
118
+ ],
119
+ [
120
+ 0,
121
+ -0.5384693101056831,
122
+ 0.5384693101056831,
123
+ -0.906179845938664,
124
+ 0.906179845938664
125
+ ],
126
+ [
127
+ 0.6612093864662645,
128
+ -0.6612093864662645,
129
+ -0.2386191860831969,
130
+ 0.2386191860831969,
131
+ -0.932469514203152,
132
+ 0.932469514203152
133
+ ],
134
+ [
135
+ 0,
136
+ 0.4058451513773972,
137
+ -0.4058451513773972,
138
+ -0.7415311855993945,
139
+ 0.7415311855993945,
140
+ -0.9491079123427585,
141
+ 0.9491079123427585
142
+ ],
143
+ [
144
+ -0.1834346424956498,
145
+ 0.1834346424956498,
146
+ -0.525532409916329,
147
+ 0.525532409916329,
148
+ -0.7966664774136267,
149
+ 0.7966664774136267,
150
+ -0.9602898564975363,
151
+ 0.9602898564975363
152
+ ],
153
+ [
154
+ 0,
155
+ -0.8360311073266358,
156
+ 0.8360311073266358,
157
+ -0.9681602395076261,
158
+ 0.9681602395076261,
159
+ -0.3242534234038089,
160
+ 0.3242534234038089,
161
+ -0.6133714327005904,
162
+ 0.6133714327005904
163
+ ],
164
+ [
165
+ -0.14887433898163122,
166
+ 0.14887433898163122,
167
+ -0.4333953941292472,
168
+ 0.4333953941292472,
169
+ -0.6794095682990244,
170
+ 0.6794095682990244,
171
+ -0.8650633666889845,
172
+ 0.8650633666889845,
173
+ -0.9739065285171717,
174
+ 0.9739065285171717
175
+ ],
176
+ [
177
+ 0,
178
+ -0.26954315595234496,
179
+ 0.26954315595234496,
180
+ -0.5190961292068118,
181
+ 0.5190961292068118,
182
+ -0.7301520055740494,
183
+ 0.7301520055740494,
184
+ -0.8870625997680953,
185
+ 0.8870625997680953,
186
+ -0.978228658146057,
187
+ 0.978228658146057
188
+ ],
189
+ [
190
+ -0.1252334085114689,
191
+ 0.1252334085114689,
192
+ -0.3678314989981802,
193
+ 0.3678314989981802,
194
+ -0.5873179542866175,
195
+ 0.5873179542866175,
196
+ -0.7699026741943047,
197
+ 0.7699026741943047,
198
+ -0.9041172563704749,
199
+ 0.9041172563704749,
200
+ -0.9815606342467192,
201
+ 0.9815606342467192
202
+ ],
203
+ [
204
+ 0,
205
+ -0.2304583159551348,
206
+ 0.2304583159551348,
207
+ -0.44849275103644687,
208
+ 0.44849275103644687,
209
+ -0.6423493394403402,
210
+ 0.6423493394403402,
211
+ -0.8015780907333099,
212
+ 0.8015780907333099,
213
+ -0.9175983992229779,
214
+ 0.9175983992229779,
215
+ -0.9841830547185881,
216
+ 0.9841830547185881
217
+ ],
218
+ [
219
+ -0.10805494870734367,
220
+ 0.10805494870734367,
221
+ -0.31911236892788974,
222
+ 0.31911236892788974,
223
+ -0.5152486363581541,
224
+ 0.5152486363581541,
225
+ -0.6872929048116855,
226
+ 0.6872929048116855,
227
+ -0.827201315069765,
228
+ 0.827201315069765,
229
+ -0.9284348836635735,
230
+ 0.9284348836635735,
231
+ -0.9862838086968123,
232
+ 0.9862838086968123
233
+ ],
234
+ [
235
+ 0,
236
+ -0.20119409399743451,
237
+ 0.20119409399743451,
238
+ -0.3941513470775634,
239
+ 0.3941513470775634,
240
+ -0.5709721726085388,
241
+ 0.5709721726085388,
242
+ -0.7244177313601701,
243
+ 0.7244177313601701,
244
+ -0.8482065834104272,
245
+ 0.8482065834104272,
246
+ -0.937273392400706,
247
+ 0.937273392400706,
248
+ -0.9879925180204854,
249
+ 0.9879925180204854
250
+ ],
251
+ [
252
+ -0.09501250983763744,
253
+ 0.09501250983763744,
254
+ -0.2816035507792589,
255
+ 0.2816035507792589,
256
+ -0.45801677765722737,
257
+ 0.45801677765722737,
258
+ -0.6178762444026438,
259
+ 0.6178762444026438,
260
+ -0.755404408355003,
261
+ 0.755404408355003,
262
+ -0.8656312023878318,
263
+ 0.8656312023878318,
264
+ -0.9445750230732326,
265
+ 0.9445750230732326,
266
+ -0.9894009349916499,
267
+ 0.9894009349916499
268
+ ],
269
+ [
270
+ 0,
271
+ -0.17848418149584785,
272
+ 0.17848418149584785,
273
+ -0.3512317634538763,
274
+ 0.3512317634538763,
275
+ -0.5126905370864769,
276
+ 0.5126905370864769,
277
+ -0.6576711592166907,
278
+ 0.6576711592166907,
279
+ -0.7815140038968014,
280
+ 0.7815140038968014,
281
+ -0.8802391537269859,
282
+ 0.8802391537269859,
283
+ -0.9506755217687678,
284
+ 0.9506755217687678,
285
+ -0.9905754753144174,
286
+ 0.9905754753144174
287
+ ],
288
+ [
289
+ -0.0847750130417353,
290
+ 0.0847750130417353,
291
+ -0.2518862256915055,
292
+ 0.2518862256915055,
293
+ -0.41175116146284263,
294
+ 0.41175116146284263,
295
+ -0.5597708310739475,
296
+ 0.5597708310739475,
297
+ -0.6916870430603532,
298
+ 0.6916870430603532,
299
+ -0.8037049589725231,
300
+ 0.8037049589725231,
301
+ -0.8926024664975557,
302
+ 0.8926024664975557,
303
+ -0.9558239495713977,
304
+ 0.9558239495713977,
305
+ -0.9915651684209309,
306
+ 0.9915651684209309
307
+ ],
308
+ [
309
+ 0,
310
+ -0.16035864564022537,
311
+ 0.16035864564022537,
312
+ -0.31656409996362983,
313
+ 0.31656409996362983,
314
+ -0.46457074137596094,
315
+ 0.46457074137596094,
316
+ -0.600545304661681,
317
+ 0.600545304661681,
318
+ -0.7209661773352294,
319
+ 0.7209661773352294,
320
+ -0.8227146565371428,
321
+ 0.8227146565371428,
322
+ -0.9031559036148179,
323
+ 0.9031559036148179,
324
+ -0.96020815213483,
325
+ 0.96020815213483,
326
+ -0.9924068438435844,
327
+ 0.9924068438435844
328
+ ],
329
+ [
330
+ -0.07652652113349734,
331
+ 0.07652652113349734,
332
+ -0.22778585114164507,
333
+ 0.22778585114164507,
334
+ -0.37370608871541955,
335
+ 0.37370608871541955,
336
+ -0.5108670019508271,
337
+ 0.5108670019508271,
338
+ -0.636053680726515,
339
+ 0.636053680726515,
340
+ -0.7463319064601508,
341
+ 0.7463319064601508,
342
+ -0.8391169718222188,
343
+ 0.8391169718222188,
344
+ -0.912234428251326,
345
+ 0.912234428251326,
346
+ -0.9639719272779138,
347
+ 0.9639719272779138,
348
+ -0.9931285991850949,
349
+ 0.9931285991850949
350
+ ],
351
+ [
352
+ 0,
353
+ -0.1455618541608951,
354
+ 0.1455618541608951,
355
+ -0.2880213168024011,
356
+ 0.2880213168024011,
357
+ -0.4243421202074388,
358
+ 0.4243421202074388,
359
+ -0.5516188358872198,
360
+ 0.5516188358872198,
361
+ -0.6671388041974123,
362
+ 0.6671388041974123,
363
+ -0.7684399634756779,
364
+ 0.7684399634756779,
365
+ -0.8533633645833173,
366
+ 0.8533633645833173,
367
+ -0.9200993341504008,
368
+ 0.9200993341504008,
369
+ -0.9672268385663063,
370
+ 0.9672268385663063,
371
+ -0.9937521706203895,
372
+ 0.9937521706203895
373
+ ],
374
+ [
375
+ -0.06973927331972223,
376
+ 0.06973927331972223,
377
+ -0.20786042668822127,
378
+ 0.20786042668822127,
379
+ -0.34193582089208424,
380
+ 0.34193582089208424,
381
+ -0.469355837986757,
382
+ 0.469355837986757,
383
+ -0.5876404035069116,
384
+ 0.5876404035069116,
385
+ -0.6944872631866827,
386
+ 0.6944872631866827,
387
+ -0.7878168059792081,
388
+ 0.7878168059792081,
389
+ -0.8658125777203002,
390
+ 0.8658125777203002,
391
+ -0.926956772187174,
392
+ 0.926956772187174,
393
+ -0.9700604978354287,
394
+ 0.9700604978354287,
395
+ -0.9942945854823992,
396
+ 0.9942945854823992
397
+ ],
398
+ [
399
+ 0,
400
+ -0.1332568242984661,
401
+ 0.1332568242984661,
402
+ -0.26413568097034495,
403
+ 0.26413568097034495,
404
+ -0.3903010380302908,
405
+ 0.3903010380302908,
406
+ -0.5095014778460075,
407
+ 0.5095014778460075,
408
+ -0.6196098757636461,
409
+ 0.6196098757636461,
410
+ -0.7186613631319502,
411
+ 0.7186613631319502,
412
+ -0.8048884016188399,
413
+ 0.8048884016188399,
414
+ -0.8767523582704416,
415
+ 0.8767523582704416,
416
+ -0.9329710868260161,
417
+ 0.9329710868260161,
418
+ -0.9725424712181152,
419
+ 0.9725424712181152,
420
+ -0.9947693349975522,
421
+ 0.9947693349975522
422
+ ],
423
+ [
424
+ -0.06405689286260563,
425
+ 0.06405689286260563,
426
+ -0.1911188674736163,
427
+ 0.1911188674736163,
428
+ -0.3150426796961634,
429
+ 0.3150426796961634,
430
+ -0.4337935076260451,
431
+ 0.4337935076260451,
432
+ -0.5454214713888396,
433
+ 0.5454214713888396,
434
+ -0.6480936519369755,
435
+ 0.6480936519369755,
436
+ -0.7401241915785544,
437
+ 0.7401241915785544,
438
+ -0.820001985973903,
439
+ 0.820001985973903,
440
+ -0.8864155270044011,
441
+ 0.8864155270044011,
442
+ -0.9382745520027328,
443
+ 0.9382745520027328,
444
+ -0.9747285559713095,
445
+ 0.9747285559713095,
446
+ -0.9951872199970213,
447
+ 0.9951872199970213
448
+ ]
449
+ ];
450
+ var cValues = [
451
+ [],
452
+ [],
453
+ [1, 1],
454
+ [
455
+ 0.8888888888888888,
456
+ 0.5555555555555556,
457
+ 0.5555555555555556
458
+ ],
459
+ [
460
+ 0.6521451548625461,
461
+ 0.6521451548625461,
462
+ 0.34785484513745385,
463
+ 0.34785484513745385
464
+ ],
465
+ [
466
+ 0.5688888888888889,
467
+ 0.47862867049936647,
468
+ 0.47862867049936647,
469
+ 0.23692688505618908,
470
+ 0.23692688505618908
471
+ ],
472
+ [
473
+ 0.3607615730481386,
474
+ 0.3607615730481386,
475
+ 0.46791393457269104,
476
+ 0.46791393457269104,
477
+ 0.17132449237917036,
478
+ 0.17132449237917036
479
+ ],
480
+ [
481
+ 0.4179591836734694,
482
+ 0.3818300505051189,
483
+ 0.3818300505051189,
484
+ 0.27970539148927664,
485
+ 0.27970539148927664,
486
+ 0.1294849661688697,
487
+ 0.1294849661688697
488
+ ],
489
+ [
490
+ 0.362683783378362,
491
+ 0.362683783378362,
492
+ 0.31370664587788727,
493
+ 0.31370664587788727,
494
+ 0.22238103445337448,
495
+ 0.22238103445337448,
496
+ 0.10122853629037626,
497
+ 0.10122853629037626
498
+ ],
499
+ [
500
+ 0.3302393550012598,
501
+ 0.1806481606948574,
502
+ 0.1806481606948574,
503
+ 0.08127438836157441,
504
+ 0.08127438836157441,
505
+ 0.31234707704000286,
506
+ 0.31234707704000286,
507
+ 0.26061069640293544,
508
+ 0.26061069640293544
509
+ ],
510
+ [
511
+ 0.29552422471475287,
512
+ 0.29552422471475287,
513
+ 0.26926671930999635,
514
+ 0.26926671930999635,
515
+ 0.21908636251598204,
516
+ 0.21908636251598204,
517
+ 0.1494513491505806,
518
+ 0.1494513491505806,
519
+ 0.06667134430868814,
520
+ 0.06667134430868814
521
+ ],
522
+ [
523
+ 0.2729250867779006,
524
+ 0.26280454451024665,
525
+ 0.26280454451024665,
526
+ 0.23319376459199048,
527
+ 0.23319376459199048,
528
+ 0.18629021092773426,
529
+ 0.18629021092773426,
530
+ 0.1255803694649046,
531
+ 0.1255803694649046,
532
+ 0.05566856711617366,
533
+ 0.05566856711617366
534
+ ],
535
+ [
536
+ 0.24914704581340277,
537
+ 0.24914704581340277,
538
+ 0.2334925365383548,
539
+ 0.2334925365383548,
540
+ 0.20316742672306592,
541
+ 0.20316742672306592,
542
+ 0.16007832854334622,
543
+ 0.16007832854334622,
544
+ 0.10693932599531843,
545
+ 0.10693932599531843,
546
+ 0.04717533638651183,
547
+ 0.04717533638651183
548
+ ],
549
+ [
550
+ 0.2325515532308739,
551
+ 0.22628318026289723,
552
+ 0.22628318026289723,
553
+ 0.2078160475368885,
554
+ 0.2078160475368885,
555
+ 0.17814598076194574,
556
+ 0.17814598076194574,
557
+ 0.13887351021978725,
558
+ 0.13887351021978725,
559
+ 0.09212149983772845,
560
+ 0.09212149983772845,
561
+ 0.04048400476531588,
562
+ 0.04048400476531588
563
+ ],
564
+ [
565
+ 0.2152638534631578,
566
+ 0.2152638534631578,
567
+ 0.2051984637212956,
568
+ 0.2051984637212956,
569
+ 0.18553839747793782,
570
+ 0.18553839747793782,
571
+ 0.15720316715819355,
572
+ 0.15720316715819355,
573
+ 0.12151857068790319,
574
+ 0.12151857068790319,
575
+ 0.08015808715976021,
576
+ 0.08015808715976021,
577
+ 0.03511946033175186,
578
+ 0.03511946033175186
579
+ ],
580
+ [
581
+ 0.2025782419255613,
582
+ 0.19843148532711158,
583
+ 0.19843148532711158,
584
+ 0.1861610000155622,
585
+ 0.1861610000155622,
586
+ 0.16626920581699392,
587
+ 0.16626920581699392,
588
+ 0.13957067792615432,
589
+ 0.13957067792615432,
590
+ 0.10715922046717194,
591
+ 0.10715922046717194,
592
+ 0.07036604748810812,
593
+ 0.07036604748810812,
594
+ 0.03075324199611727,
595
+ 0.03075324199611727
596
+ ],
597
+ [
598
+ 0.1894506104550685,
599
+ 0.1894506104550685,
600
+ 0.18260341504492358,
601
+ 0.18260341504492358,
602
+ 0.16915651939500254,
603
+ 0.16915651939500254,
604
+ 0.14959598881657674,
605
+ 0.14959598881657674,
606
+ 0.12462897125553388,
607
+ 0.12462897125553388,
608
+ 0.09515851168249279,
609
+ 0.09515851168249279,
610
+ 0.062253523938647894,
611
+ 0.062253523938647894,
612
+ 0.027152459411754096,
613
+ 0.027152459411754096
614
+ ],
615
+ [
616
+ 0.17944647035620653,
617
+ 0.17656270536699264,
618
+ 0.17656270536699264,
619
+ 0.16800410215645004,
620
+ 0.16800410215645004,
621
+ 0.15404576107681028,
622
+ 0.15404576107681028,
623
+ 0.13513636846852548,
624
+ 0.13513636846852548,
625
+ 0.11188384719340397,
626
+ 0.11188384719340397,
627
+ 0.08503614831717918,
628
+ 0.08503614831717918,
629
+ 0.0554595293739872,
630
+ 0.0554595293739872,
631
+ 0.02414830286854793,
632
+ 0.02414830286854793
633
+ ],
634
+ [
635
+ 0.1691423829631436,
636
+ 0.1691423829631436,
637
+ 0.16427648374583273,
638
+ 0.16427648374583273,
639
+ 0.15468467512626524,
640
+ 0.15468467512626524,
641
+ 0.14064291467065065,
642
+ 0.14064291467065065,
643
+ 0.12255520671147846,
644
+ 0.12255520671147846,
645
+ 0.10094204410628717,
646
+ 0.10094204410628717,
647
+ 0.07642573025488905,
648
+ 0.07642573025488905,
649
+ 0.0497145488949698,
650
+ 0.0497145488949698,
651
+ 0.02161601352648331,
652
+ 0.02161601352648331
653
+ ],
654
+ [
655
+ 0.1610544498487837,
656
+ 0.15896884339395434,
657
+ 0.15896884339395434,
658
+ 0.15276604206585967,
659
+ 0.15276604206585967,
660
+ 0.1426067021736066,
661
+ 0.1426067021736066,
662
+ 0.12875396253933621,
663
+ 0.12875396253933621,
664
+ 0.11156664554733399,
665
+ 0.11156664554733399,
666
+ 0.09149002162245,
667
+ 0.09149002162245,
668
+ 0.06904454273764123,
669
+ 0.06904454273764123,
670
+ 0.0448142267656996,
671
+ 0.0448142267656996,
672
+ 0.019461788229726478,
673
+ 0.019461788229726478
674
+ ],
675
+ [
676
+ 0.15275338713072584,
677
+ 0.15275338713072584,
678
+ 0.14917298647260374,
679
+ 0.14917298647260374,
680
+ 0.14209610931838204,
681
+ 0.14209610931838204,
682
+ 0.13168863844917664,
683
+ 0.13168863844917664,
684
+ 0.11819453196151841,
685
+ 0.11819453196151841,
686
+ 0.10193011981724044,
687
+ 0.10193011981724044,
688
+ 0.08327674157670475,
689
+ 0.08327674157670475,
690
+ 0.06267204833410907,
691
+ 0.06267204833410907,
692
+ 0.04060142980038694,
693
+ 0.04060142980038694,
694
+ 0.017614007139152118,
695
+ 0.017614007139152118
696
+ ],
697
+ [
698
+ 0.14608113364969041,
699
+ 0.14452440398997005,
700
+ 0.14452440398997005,
701
+ 0.13988739479107315,
702
+ 0.13988739479107315,
703
+ 0.13226893863333747,
704
+ 0.13226893863333747,
705
+ 0.12183141605372853,
706
+ 0.12183141605372853,
707
+ 0.10879729916714838,
708
+ 0.10879729916714838,
709
+ 0.09344442345603386,
710
+ 0.09344442345603386,
711
+ 0.0761001136283793,
712
+ 0.0761001136283793,
713
+ 0.057134425426857205,
714
+ 0.057134425426857205,
715
+ 0.036953789770852494,
716
+ 0.036953789770852494,
717
+ 0.016017228257774335,
718
+ 0.016017228257774335
719
+ ],
720
+ [
721
+ 0.13925187285563198,
722
+ 0.13925187285563198,
723
+ 0.13654149834601517,
724
+ 0.13654149834601517,
725
+ 0.13117350478706238,
726
+ 0.13117350478706238,
727
+ 0.12325237681051242,
728
+ 0.12325237681051242,
729
+ 0.11293229608053922,
730
+ 0.11293229608053922,
731
+ 0.10041414444288096,
732
+ 0.10041414444288096,
733
+ 0.08594160621706773,
734
+ 0.08594160621706773,
735
+ 0.06979646842452049,
736
+ 0.06979646842452049,
737
+ 0.052293335152683286,
738
+ 0.052293335152683286,
739
+ 0.03377490158481415,
740
+ 0.03377490158481415,
741
+ 0.0146279952982722,
742
+ 0.0146279952982722
743
+ ],
744
+ [
745
+ 0.13365457218610619,
746
+ 0.1324620394046966,
747
+ 0.1324620394046966,
748
+ 0.12890572218808216,
749
+ 0.12890572218808216,
750
+ 0.12304908430672953,
751
+ 0.12304908430672953,
752
+ 0.11499664022241136,
753
+ 0.11499664022241136,
754
+ 0.10489209146454141,
755
+ 0.10489209146454141,
756
+ 0.09291576606003515,
757
+ 0.09291576606003515,
758
+ 0.07928141177671895,
759
+ 0.07928141177671895,
760
+ 0.06423242140852585,
761
+ 0.06423242140852585,
762
+ 0.04803767173108467,
763
+ 0.04803767173108467,
764
+ 0.030988005856979445,
765
+ 0.030988005856979445,
766
+ 0.013411859487141771,
767
+ 0.013411859487141771
768
+ ],
769
+ [
770
+ 0.12793819534675216,
771
+ 0.12793819534675216,
772
+ 0.1258374563468283,
773
+ 0.1258374563468283,
774
+ 0.12167047292780339,
775
+ 0.12167047292780339,
776
+ 0.1155056680537256,
777
+ 0.1155056680537256,
778
+ 0.10744427011596563,
779
+ 0.10744427011596563,
780
+ 0.09761865210411388,
781
+ 0.09761865210411388,
782
+ 0.08619016153195327,
783
+ 0.08619016153195327,
784
+ 0.0733464814110803,
785
+ 0.0733464814110803,
786
+ 0.05929858491543678,
787
+ 0.05929858491543678,
788
+ 0.04427743881741981,
789
+ 0.04427743881741981,
790
+ 0.028531388628933663,
791
+ 0.028531388628933663,
792
+ 0.0123412297999872,
793
+ 0.0123412297999872
794
+ ]
795
+ ];
796
+ var binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
797
+ var cubicPoint = (xs, ys, t) => {
798
+ const x = (1 - t) * (1 - t) * (1 - t) * xs[0] + 3 * (1 - t) * (1 - t) * t * xs[1] + 3 * (1 - t) * t * t * xs[2] + t * t * t * xs[3];
799
+ const y = (1 - t) * (1 - t) * (1 - t) * ys[0] + 3 * (1 - t) * (1 - t) * t * ys[1] + 3 * (1 - t) * t * t * ys[2] + t * t * t * ys[3];
800
+ return { x, y };
801
+ };
802
+ var getDerivative = (derivative, t, vs) => {
803
+ const n = vs.length - 1;
804
+ let value;
805
+ if (n === 0) {
806
+ return 0;
807
+ }
808
+ if (derivative === 0) {
809
+ value = 0;
810
+ for (let k = 0;k <= n; k++) {
811
+ value += binomialCoefficients[n][k] * (1 - t) ** (n - k) * t ** k * vs[k];
812
+ }
813
+ return value;
814
+ }
815
+ const _vs = new Array(n);
816
+ for (let k = 0;k < n; k++) {
817
+ _vs[k] = n * (vs[k + 1] - vs[k]);
818
+ }
819
+ return getDerivative(derivative - 1, t, _vs);
820
+ };
821
+ function bFunc(xs, ys, t) {
822
+ const xbase = getDerivative(1, t, xs);
823
+ const ybase = getDerivative(1, t, ys);
824
+ const combined = xbase * xbase + ybase * ybase;
825
+ return Math.sqrt(combined);
826
+ }
827
+ var getCubicArcLength = ({
828
+ sx,
829
+ sy,
830
+ t
831
+ }) => {
832
+ let correctedT;
833
+ const n = 20;
834
+ const z = t / 2;
835
+ let sum = 0;
836
+ for (let i = 0;i < n; i++) {
837
+ correctedT = z * tValues[n][i] + z;
838
+ sum += cValues[n][i] * bFunc(sx, sy, correctedT);
839
+ }
840
+ return z * sum;
841
+ };
842
+ var quadraticPoint = (xs, ys, t) => {
843
+ const x = (1 - t) * (1 - t) * xs[0] + 2 * (1 - t) * t * xs[1] + t * t * xs[2];
844
+ const y = (1 - t) * (1 - t) * ys[0] + 2 * (1 - t) * t * ys[1] + t * t * ys[2];
845
+ return { x, y };
846
+ };
847
+ var cubicDerivative = (xs, ys, t) => {
848
+ const derivative = quadraticPoint([3 * (xs[1] - xs[0]), 3 * (xs[2] - xs[1]), 3 * (xs[3] - xs[2])], [3 * (ys[1] - ys[0]), 3 * (ys[2] - ys[1]), 3 * (ys[3] - ys[2])], t);
849
+ return derivative;
850
+ };
851
+ var getQuadraticArcLength = (xs, ys, t) => {
852
+ if (t === undefined) {
853
+ t = 1;
854
+ }
855
+ const ax = xs[0] - 2 * xs[1] + xs[2];
856
+ const ay = ys[0] - 2 * ys[1] + ys[2];
857
+ const bx = 2 * xs[1] - 2 * xs[0];
858
+ const by = 2 * ys[1] - 2 * ys[0];
859
+ const A = 4 * (ax * ax + ay * ay);
860
+ const B = 4 * (ax * bx + ay * by);
861
+ const C = bx * bx + by * by;
862
+ if (A === 0) {
863
+ return t * Math.sqrt((xs[2] - xs[0]) ** 2 + (ys[2] - ys[0]) ** 2);
864
+ }
865
+ const b = B / (2 * A);
866
+ const c = C / A;
867
+ const u = t + b;
868
+ const k = c - b * b;
869
+ const uuk = u * u + k > 0 ? Math.sqrt(u * u + k) : 0;
870
+ const bbk = b * b + k > 0 ? Math.sqrt(b * b + k) : 0;
871
+ const term = b + Math.sqrt(b * b + k) === 0 ? 0 : k * Math.log(Math.abs((u + uuk) / (b + bbk)));
872
+ return Math.sqrt(A) / 2 * (u * uuk - b * bbk + term);
873
+ };
874
+ var quadraticDerivative = (xs, ys, t) => {
875
+ return {
876
+ x: (1 - t) * 2 * (xs[1] - xs[0]) + t * 2 * (xs[2] - xs[1]),
877
+ y: (1 - t) * 2 * (ys[1] - ys[0]) + t * 2 * (ys[2] - ys[1])
878
+ };
879
+ };
880
+ var t2length = ({
881
+ length,
882
+ totalLength,
883
+ func
884
+ }) => {
885
+ let error = 1;
886
+ let t = length / totalLength;
887
+ let step = (length - func(t)) / totalLength;
888
+ let numIterations = 0;
889
+ while (error > 0.001) {
890
+ const increasedTLength = func(t + step);
891
+ const increasedTError = Math.abs(length - increasedTLength) / totalLength;
892
+ if (increasedTError < error) {
893
+ error = increasedTError;
894
+ t += step;
895
+ } else {
896
+ const decreasedTLength = func(t - step);
897
+ const decreasedTError = Math.abs(length - decreasedTLength) / totalLength;
898
+ if (decreasedTError < error) {
899
+ error = decreasedTError;
900
+ t -= step;
901
+ } else {
902
+ step /= 2;
903
+ }
904
+ }
905
+ numIterations++;
906
+ if (numIterations > 500) {
907
+ break;
908
+ }
909
+ }
910
+ return t;
911
+ };
912
+ var makeQuadratic = ({
913
+ startX,
914
+ startY,
915
+ cpx,
916
+ cpy,
917
+ x,
918
+ y
919
+ }) => {
920
+ const a = { x: startX, y: startY };
921
+ const b = { x: cpx, y: cpy };
922
+ const c = { x, y };
923
+ const length = getQuadraticArcLength([a.x, b.x, c.x, 0], [a.y, b.y, c.y, 0], 1);
924
+ const getTotalLength = () => {
925
+ return length;
926
+ };
927
+ const getPointAtLength = (len) => {
928
+ const xs = [a.x, b.x, c.x, 0];
929
+ const xy = [a.y, b.y, c.y, 0];
930
+ const t = t2length({
931
+ length: len,
932
+ totalLength: length,
933
+ func: (i) => getQuadraticArcLength(xs, xy, i)
934
+ });
935
+ return quadraticPoint(xs, xy, t);
936
+ };
937
+ const getTangentAtLength = (len) => {
938
+ const xs = [a.x, b.x, c.x, 0];
939
+ const xy = [a.y, b.y, c.y, 0];
940
+ const t = t2length({
941
+ length: len,
942
+ totalLength: length,
943
+ func: (i) => getQuadraticArcLength(xs, xy, i)
944
+ });
945
+ const derivative = quadraticDerivative(xs, xy, t);
946
+ const mdl = Math.sqrt(derivative.x * derivative.x + derivative.y * derivative.y);
947
+ let tangent;
948
+ if (mdl > 0) {
949
+ tangent = { x: derivative.x / mdl, y: derivative.y / mdl };
950
+ } else {
951
+ tangent = { x: 0, y: 0 };
952
+ }
953
+ return tangent;
954
+ };
955
+ const getC = () => {
956
+ return c;
957
+ };
958
+ return {
959
+ getPointAtLength,
960
+ getTangentAtLength,
961
+ getTotalLength,
962
+ getC,
963
+ type: "quadratic-bezier",
964
+ getD: () => ({ x: 0, y: 0 })
965
+ };
966
+ };
967
+ var makeCubic = ({
968
+ startX,
969
+ startY,
970
+ cp1x,
971
+ cp1y,
972
+ cp2x,
973
+ cp2y,
974
+ x,
975
+ y
976
+ }) => {
977
+ const a = { x: startX, y: startY };
978
+ const b = { x: cp1x, y: cp1y };
979
+ const c = { x: cp2x, y: cp2y };
980
+ const d = { x, y };
981
+ const length = getCubicArcLength({
982
+ sx: [a.x, b.x, c.x, d.x],
983
+ sy: [a.y, b.y, c.y, d.y],
984
+ t: 1
985
+ });
986
+ const getTotalLength = () => {
987
+ return length;
988
+ };
989
+ const getPointAtLength = (len) => {
990
+ const sx = [a.x, b.x, c.x, d.x];
991
+ const sy = [a.y, b.y, c.y, d.y];
992
+ const t = t2length({
993
+ length: len,
994
+ totalLength: length,
995
+ func: (i) => {
996
+ return getCubicArcLength({ sx, sy, t: i });
997
+ }
998
+ });
999
+ return cubicPoint(sx, sy, t);
1000
+ };
1001
+ const getTangentAtLength = (len) => {
1002
+ const xs = [a.x, b.x, c.x, d.x];
1003
+ const xy = [a.y, b.y, c.y, d.y];
1004
+ const t = t2length({
1005
+ length: len,
1006
+ totalLength: length,
1007
+ func: (i) => getCubicArcLength({ sx: xs, sy: xy, t: i })
1008
+ });
1009
+ const derivative = cubicDerivative(xs, xy, t);
1010
+ const mdl = Math.sqrt(derivative.x * derivative.x + derivative.y * derivative.y);
1011
+ let tangent;
1012
+ if (mdl > 0) {
1013
+ tangent = { x: derivative.x / mdl, y: derivative.y / mdl };
1014
+ } else {
1015
+ tangent = { x: 0, y: 0 };
1016
+ }
1017
+ return tangent;
1018
+ };
1019
+ const getC = () => {
1020
+ return c;
1021
+ };
1022
+ const getD = () => {
1023
+ return d;
1024
+ };
1025
+ return {
1026
+ getPointAtLength,
1027
+ getTangentAtLength,
1028
+ getTotalLength,
1029
+ getC,
1030
+ getD,
1031
+ type: "cubic-bezier"
1032
+ };
1033
+ };
1034
+ var makeLinearPosition = ({
1035
+ x0,
1036
+ x1,
1037
+ y0,
1038
+ y1
1039
+ }) => {
1040
+ return {
1041
+ getTotalLength: () => {
1042
+ return Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
1043
+ },
1044
+ getPointAtLength: (pos) => {
1045
+ let fraction = pos / Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
1046
+ fraction = Number.isNaN(fraction) ? 1 : fraction;
1047
+ const newDeltaX = (x1 - x0) * fraction;
1048
+ const newDeltaY = (y1 - y0) * fraction;
1049
+ return { x: x0 + newDeltaX, y: y0 + newDeltaY };
1050
+ },
1051
+ getTangentAtLength: () => {
1052
+ const module = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
1053
+ return { x: (x1 - x0) / module, y: (y1 - y0) / module };
1054
+ },
1055
+ type: "linear"
1056
+ };
1057
+ };
1058
+ var length = {
1059
+ a: 7,
1060
+ A: 7,
1061
+ C: 6,
1062
+ c: 6,
1063
+ H: 1,
1064
+ h: 1,
1065
+ L: 2,
1066
+ l: 2,
1067
+ M: 2,
1068
+ m: 2,
1069
+ Q: 4,
1070
+ q: 4,
1071
+ S: 4,
1072
+ s: 4,
1073
+ T: 2,
1074
+ t: 2,
1075
+ V: 1,
1076
+ v: 1,
1077
+ Z: 0,
1078
+ z: 0
1079
+ };
1080
+ var chunkExact = (array, instruction) => {
1081
+ const chunks = [];
1082
+ const expectedSize = length[instruction];
1083
+ if (array.length % expectedSize !== 0) {
1084
+ throw new Error(`Expected number of arguments of SVG instruction "${instruction} ${array.join(" ")}" to be a multiple of ${expectedSize}`);
1085
+ }
1086
+ for (let i = 0;i < array.length; i += expectedSize) {
1087
+ chunks.push(array.slice(i, i + expectedSize));
1088
+ }
1089
+ return chunks;
1090
+ };
1091
+ var makeInstructions = (arr, instruction, cb) => {
1092
+ return chunkExact(arr, instruction).map((args) => {
1093
+ return cb(args);
1094
+ });
1095
+ };
1096
+ var segmentRegExp = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
1097
+ var numberRegExp = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
1098
+ var parseValues = (args, instructionType) => {
1099
+ const numbers = args.match(numberRegExp);
1100
+ if (!numbers) {
1101
+ if (instructionType === "Z" || instructionType === "z") {
1102
+ return [];
1103
+ }
1104
+ throw new Error(`Malformed path data: ${instructionType} was expected to have numbers afterwards`);
1105
+ }
1106
+ const expectedArguments = length[instructionType];
1107
+ if (numbers.length % expectedArguments !== 0) {
1108
+ throw new Error(`Malformed path data: ${instructionType} was expected to have a multiple of ${expectedArguments} numbers, but got "${instructionType} ${numbers.join(" ")} instead"`);
1109
+ }
1110
+ return numbers.map(Number);
1111
+ };
1112
+ var parsePath = (path) => {
1113
+ if (!path) {
1114
+ throw new Error("No path provided");
1115
+ }
1116
+ const segments = path.match(segmentRegExp);
1117
+ if (!segments) {
1118
+ throw new Error(`No path elements found in string ${path}`);
1119
+ }
1120
+ return segments.map((segmentString) => {
1121
+ const command = segmentString.charAt(0);
1122
+ const args = parseValues(segmentString.substring(1), command);
1123
+ if (command === "M" && args.length > 2) {
1124
+ const segmentsArray = [];
1125
+ segmentsArray.push({
1126
+ type: command,
1127
+ x: args[0],
1128
+ y: args[1]
1129
+ });
1130
+ segmentsArray.push(...makeInstructions(args.slice(2), "L", (numbers) => ({
1131
+ type: "L",
1132
+ x: numbers[0],
1133
+ y: numbers[1]
1134
+ })));
1135
+ return segmentsArray;
1136
+ }
1137
+ if (command === "m" && args.length > 2) {
1138
+ const segmentsArray = [];
1139
+ segmentsArray.push({
1140
+ type: command,
1141
+ dx: args[0],
1142
+ dy: args[1]
1143
+ });
1144
+ segmentsArray.push(...makeInstructions(args.slice(2), "l", (numbers) => ({
1145
+ type: "l",
1146
+ dx: numbers[0],
1147
+ dy: numbers[1]
1148
+ })));
1149
+ return segmentsArray;
1150
+ }
1151
+ if (command === "Z" || command === "z") {
1152
+ return [
1153
+ {
1154
+ type: "Z"
1155
+ }
1156
+ ];
1157
+ }
1158
+ if (command === "A") {
1159
+ return makeInstructions(args, command, (numbers) => ({
1160
+ type: command,
1161
+ rx: numbers[0],
1162
+ ry: numbers[1],
1163
+ xAxisRotation: numbers[2],
1164
+ largeArcFlag: numbers[3] === 1,
1165
+ sweepFlag: numbers[4] === 1,
1166
+ x: numbers[5],
1167
+ y: numbers[6]
1168
+ }));
1169
+ }
1170
+ if (command === "a") {
1171
+ return makeInstructions(args, command, (numbers) => ({
1172
+ type: command,
1173
+ rx: numbers[0],
1174
+ ry: numbers[1],
1175
+ xAxisRotation: numbers[2],
1176
+ largeArcFlag: numbers[3] === 1,
1177
+ sweepFlag: numbers[4] === 1,
1178
+ dx: numbers[5],
1179
+ dy: numbers[6]
1180
+ }));
1181
+ }
1182
+ if (command === "C") {
1183
+ return makeInstructions(args, command, (numbers) => ({
1184
+ type: command,
1185
+ cp1x: numbers[0],
1186
+ cp1y: numbers[1],
1187
+ cp2x: numbers[2],
1188
+ cp2y: numbers[3],
1189
+ x: numbers[4],
1190
+ y: numbers[5]
1191
+ }));
1192
+ }
1193
+ if (command === "c") {
1194
+ return makeInstructions(args, command, (numbers) => ({
1195
+ type: command,
1196
+ cp1dx: numbers[0],
1197
+ cp1dy: numbers[1],
1198
+ cp2dx: numbers[2],
1199
+ cp2dy: numbers[3],
1200
+ dx: numbers[4],
1201
+ dy: numbers[5]
1202
+ }));
1203
+ }
1204
+ if (command === "S") {
1205
+ return makeInstructions(args, command, (numbers) => ({
1206
+ type: command,
1207
+ cpx: numbers[0],
1208
+ cpy: numbers[1],
1209
+ x: numbers[2],
1210
+ y: numbers[3]
1211
+ }));
1212
+ }
1213
+ if (command === "s") {
1214
+ return makeInstructions(args, command, (numbers) => ({
1215
+ type: command,
1216
+ cpdx: numbers[0],
1217
+ cpdy: numbers[1],
1218
+ dx: numbers[2],
1219
+ dy: numbers[3]
1220
+ }));
1221
+ }
1222
+ if (command === "H") {
1223
+ return makeInstructions(args, command, (numbers) => ({
1224
+ type: command,
1225
+ x: numbers[0]
1226
+ }));
1227
+ }
1228
+ if (command === "h") {
1229
+ return makeInstructions(args, command, (numbers) => ({
1230
+ type: command,
1231
+ dx: numbers[0]
1232
+ }));
1233
+ }
1234
+ if (command === "V") {
1235
+ return makeInstructions(args, command, (numbers) => ({
1236
+ type: command,
1237
+ y: numbers[0]
1238
+ }));
1239
+ }
1240
+ if (command === "v") {
1241
+ return makeInstructions(args, command, (numbers) => ({
1242
+ type: command,
1243
+ dy: numbers[0]
1244
+ }));
1245
+ }
1246
+ if (command === "L") {
1247
+ return makeInstructions(args, command, (numbers) => ({
1248
+ type: command,
1249
+ x: numbers[0],
1250
+ y: numbers[1]
1251
+ }));
1252
+ }
1253
+ if (command === "M") {
1254
+ return makeInstructions(args, command, (numbers) => ({
1255
+ type: command,
1256
+ x: numbers[0],
1257
+ y: numbers[1]
1258
+ }));
1259
+ }
1260
+ if (command === "m") {
1261
+ return makeInstructions(args, command, (numbers) => ({
1262
+ type: command,
1263
+ dx: numbers[0],
1264
+ dy: numbers[1]
1265
+ }));
1266
+ }
1267
+ if (command === "l") {
1268
+ return makeInstructions(args, command, (numbers) => ({
1269
+ type: command,
1270
+ dx: numbers[0],
1271
+ dy: numbers[1]
1272
+ }));
1273
+ }
1274
+ if (command === "Q") {
1275
+ return makeInstructions(args, command, (numbers) => ({
1276
+ type: command,
1277
+ cpx: numbers[0],
1278
+ cpy: numbers[1],
1279
+ x: numbers[2],
1280
+ y: numbers[3]
1281
+ }));
1282
+ }
1283
+ if (command === "q") {
1284
+ return makeInstructions(args, command, (numbers) => ({
1285
+ type: command,
1286
+ cpdx: numbers[0],
1287
+ cpdy: numbers[1],
1288
+ dx: numbers[2],
1289
+ dy: numbers[3]
1290
+ }));
1291
+ }
1292
+ if (command === "T") {
1293
+ return makeInstructions(args, command, (numbers) => ({
1294
+ type: command,
1295
+ x: numbers[0],
1296
+ y: numbers[1]
1297
+ }));
1298
+ }
1299
+ if (command === "t") {
1300
+ return makeInstructions(args, command, (numbers) => ({
1301
+ type: command,
1302
+ dx: numbers[0],
1303
+ dy: numbers[1]
1304
+ }));
1305
+ }
1306
+ throw new Error(`Invalid path element ${segmentString}`);
1307
+ }, []).flat(1);
1308
+ };
1309
+ var TAU = Math.PI * 2;
1310
+ var mod = (x, m) => {
1311
+ return (x % m + m) % m;
1312
+ };
1313
+ var toRadians = (angle) => {
1314
+ return angle * (Math.PI / 180);
1315
+ };
1316
+ var distance = (p0, p1) => {
1317
+ return Math.sqrt((p1.x - p0.x) ** 2 + (p1.y - p0.y) ** 2);
1318
+ };
1319
+ var clamp = (val, min, max) => {
1320
+ return Math.min(Math.max(val, min), max);
1321
+ };
1322
+ var angleBetween = (v0, v1) => {
1323
+ const p = v0.x * v1.x + v0.y * v1.y;
1324
+ const n = Math.sqrt((v0.x ** 2 + v0.y ** 2) * (v1.x ** 2 + v1.y ** 2));
1325
+ const sign = v0.x * v1.y - v0.y * v1.x < 0 ? -1 : 1;
1326
+ const angle = sign * Math.acos(p / n);
1327
+ return angle;
1328
+ };
1329
+ var pointOnEllipticalArc = ({
1330
+ p0,
1331
+ rx,
1332
+ ry,
1333
+ xAxisRotation,
1334
+ largeArcFlag,
1335
+ sweepFlag,
1336
+ p1,
1337
+ t
1338
+ }) => {
1339
+ rx = Math.abs(rx);
1340
+ ry = Math.abs(ry);
1341
+ xAxisRotation = mod(xAxisRotation, 360);
1342
+ const xAxisRotationRadians = toRadians(xAxisRotation);
1343
+ if (p0.x === p1.x && p0.y === p1.y) {
1344
+ return { x: p0.x, y: p0.y, ellipticalArcAngle: 0 };
1345
+ }
1346
+ if (rx === 0 || ry === 0) {
1347
+ return { x: 0, y: 0, ellipticalArcAngle: 0 };
1348
+ }
1349
+ const dx = (p0.x - p1.x) / 2;
1350
+ const dy = (p0.y - p1.y) / 2;
1351
+ const transformedPoint = {
1352
+ x: Math.cos(xAxisRotationRadians) * dx + Math.sin(xAxisRotationRadians) * dy,
1353
+ y: -Math.sin(xAxisRotationRadians) * dx + Math.cos(xAxisRotationRadians) * dy
1354
+ };
1355
+ const radiiCheck = transformedPoint.x ** 2 / rx ** 2 + transformedPoint.y ** 2 / ry ** 2;
1356
+ if (radiiCheck > 1) {
1357
+ rx *= Math.sqrt(radiiCheck);
1358
+ ry *= Math.sqrt(radiiCheck);
1359
+ }
1360
+ const cSquareNumerator = rx ** 2 * ry ** 2 - rx ** 2 * transformedPoint.y ** 2 - ry ** 2 * transformedPoint.x ** 2;
1361
+ const cSquareRootDenom = rx ** 2 * transformedPoint.y ** 2 + ry ** 2 * transformedPoint.x ** 2;
1362
+ let cRadicand = cSquareNumerator / cSquareRootDenom;
1363
+ cRadicand = cRadicand < 0 ? 0 : cRadicand;
1364
+ const cCoef = (largeArcFlag === sweepFlag ? -1 : 1) * Math.sqrt(cRadicand);
1365
+ const transformedCenter = {
1366
+ x: cCoef * (rx * transformedPoint.y / ry),
1367
+ y: cCoef * (-(ry * transformedPoint.x) / rx)
1368
+ };
1369
+ const center = {
1370
+ x: Math.cos(xAxisRotationRadians) * transformedCenter.x - Math.sin(xAxisRotationRadians) * transformedCenter.y + (p0.x + p1.x) / 2,
1371
+ y: Math.sin(xAxisRotationRadians) * transformedCenter.x + Math.cos(xAxisRotationRadians) * transformedCenter.y + (p0.y + p1.y) / 2
1372
+ };
1373
+ const startVector = {
1374
+ x: (transformedPoint.x - transformedCenter.x) / rx,
1375
+ y: (transformedPoint.y - transformedCenter.y) / ry
1376
+ };
1377
+ const startAngle = angleBetween({
1378
+ x: 1,
1379
+ y: 0
1380
+ }, startVector);
1381
+ const endVector = {
1382
+ x: (-transformedPoint.x - transformedCenter.x) / rx,
1383
+ y: (-transformedPoint.y - transformedCenter.y) / ry
1384
+ };
1385
+ let sweepAngle = angleBetween(startVector, endVector);
1386
+ if (!sweepFlag && sweepAngle > 0) {
1387
+ sweepAngle -= 2 * Math.PI;
1388
+ } else if (sweepFlag && sweepAngle < 0) {
1389
+ sweepAngle += 2 * Math.PI;
1390
+ }
1391
+ sweepAngle %= 2 * Math.PI;
1392
+ const angle = startAngle + sweepAngle * t;
1393
+ const ellipseComponentX = rx * Math.cos(angle);
1394
+ const ellipseComponentY = ry * Math.sin(angle);
1395
+ const point = {
1396
+ x: Math.cos(xAxisRotationRadians) * ellipseComponentX - Math.sin(xAxisRotationRadians) * ellipseComponentY + center.x,
1397
+ y: Math.sin(xAxisRotationRadians) * ellipseComponentX + Math.cos(xAxisRotationRadians) * ellipseComponentY + center.y,
1398
+ ellipticalArcStartAngle: startAngle,
1399
+ ellipticalArcEndAngle: startAngle + sweepAngle,
1400
+ ellipticalArcAngle: angle,
1401
+ ellipticalArcCenter: center,
1402
+ resultantRx: rx,
1403
+ resultantRy: ry
1404
+ };
1405
+ return point;
1406
+ };
1407
+ var approximateArcLengthOfCurve = (resolution, pointOnCurveFunc) => {
1408
+ resolution = resolution ? resolution : 500;
1409
+ let resultantArcLength = 0;
1410
+ const arcLengthMap = [];
1411
+ const approximationLines = [];
1412
+ let prevPoint = pointOnCurveFunc(0);
1413
+ let nextPoint;
1414
+ for (let i = 0;i < resolution; i++) {
1415
+ const t = clamp(i * (1 / resolution), 0, 1);
1416
+ nextPoint = pointOnCurveFunc(t);
1417
+ resultantArcLength += distance(prevPoint, nextPoint);
1418
+ approximationLines.push([prevPoint, nextPoint]);
1419
+ arcLengthMap.push({
1420
+ t,
1421
+ arcLength: resultantArcLength
1422
+ });
1423
+ prevPoint = nextPoint;
1424
+ }
1425
+ nextPoint = pointOnCurveFunc(1);
1426
+ approximationLines.push([prevPoint, nextPoint]);
1427
+ resultantArcLength += distance(prevPoint, nextPoint);
1428
+ arcLengthMap.push({
1429
+ t: 1,
1430
+ arcLength: resultantArcLength
1431
+ });
1432
+ return {
1433
+ arcLength: resultantArcLength,
1434
+ arcLengthMap,
1435
+ approximationLines
1436
+ };
1437
+ };
1438
+ var makeArc = ({
1439
+ x0,
1440
+ y0,
1441
+ rx,
1442
+ ry,
1443
+ xAxisRotate,
1444
+ LargeArcFlag,
1445
+ SweepFlag,
1446
+ x1,
1447
+ y1
1448
+ }) => {
1449
+ const lengthProperties = approximateArcLengthOfCurve(300, (t) => {
1450
+ return pointOnEllipticalArc({
1451
+ p0: { x: x0, y: y0 },
1452
+ rx,
1453
+ ry,
1454
+ xAxisRotation: xAxisRotate,
1455
+ largeArcFlag: LargeArcFlag,
1456
+ sweepFlag: SweepFlag,
1457
+ p1: { x: x1, y: y1 },
1458
+ t
1459
+ });
1460
+ });
1461
+ const length2 = lengthProperties.arcLength;
1462
+ const getPointAtLength = (fractionLength) => {
1463
+ if (fractionLength < 0) {
1464
+ fractionLength = 0;
1465
+ } else if (fractionLength > length2) {
1466
+ fractionLength = length2;
1467
+ }
1468
+ const position = pointOnEllipticalArc({
1469
+ p0: { x: x0, y: y0 },
1470
+ rx,
1471
+ ry,
1472
+ xAxisRotation: xAxisRotate,
1473
+ largeArcFlag: LargeArcFlag,
1474
+ sweepFlag: SweepFlag,
1475
+ p1: { x: x1, y: y1 },
1476
+ t: fractionLength / length2
1477
+ });
1478
+ return { x: position.x, y: position.y };
1479
+ };
1480
+ return {
1481
+ getPointAtLength,
1482
+ getTangentAtLength: (fractionLength) => {
1483
+ if (fractionLength < 0) {
1484
+ fractionLength = 0;
1485
+ } else if (fractionLength > length2) {
1486
+ fractionLength = length2;
1487
+ }
1488
+ const point_dist = 0.05;
1489
+ const p1 = getPointAtLength(fractionLength);
1490
+ let p2;
1491
+ if (fractionLength < 0) {
1492
+ fractionLength = 0;
1493
+ } else if (fractionLength > length2) {
1494
+ fractionLength = length2;
1495
+ }
1496
+ if (fractionLength < length2 - point_dist) {
1497
+ p2 = getPointAtLength(fractionLength + point_dist);
1498
+ } else {
1499
+ p2 = getPointAtLength(fractionLength - point_dist);
1500
+ }
1501
+ const xDist = p2.x - p1.x;
1502
+ const yDist = p2.y - p1.y;
1503
+ const dist = Math.sqrt(xDist * xDist + yDist * yDist);
1504
+ if (fractionLength < length2 - point_dist) {
1505
+ return { x: -xDist / dist, y: -yDist / dist };
1506
+ }
1507
+ return { x: xDist / dist, y: yDist / dist };
1508
+ },
1509
+ getTotalLength: () => {
1510
+ return length2;
1511
+ },
1512
+ type: "arc"
1513
+ };
1514
+ };
1515
+ var constructFromInstructions = (instructions) => {
1516
+ let totalLength = 0;
1517
+ const partialLengths = [];
1518
+ const functions = [];
1519
+ let initialPoint = null;
1520
+ let cur = [0, 0];
1521
+ let prev_point = [0, 0];
1522
+ let curve;
1523
+ let ringStart = [0, 0];
1524
+ const segments = [];
1525
+ for (let i = 0;i < instructions.length; i++) {
1526
+ const instruction = instructions[i];
1527
+ if (instruction.type !== "m" && instruction.type !== "M" && segments.length > 0) {
1528
+ segments[segments.length - 1].push(instruction);
1529
+ }
1530
+ if (instruction.type === "M") {
1531
+ cur = [instruction.x, instruction.y];
1532
+ ringStart = [cur[0], cur[1]];
1533
+ segments.push([instruction]);
1534
+ functions.push(null);
1535
+ if (i === 0) {
1536
+ initialPoint = { x: instruction.x, y: instruction.y };
1537
+ }
1538
+ }
1539
+ if (instruction.type === "m") {
1540
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
1541
+ ringStart = [cur[0], cur[1]];
1542
+ segments.push([{ type: "M", x: cur[0], y: cur[1] }]);
1543
+ functions.push(null);
1544
+ }
1545
+ if (instruction.type === "L") {
1546
+ totalLength += Math.sqrt((cur[0] - instruction.x) ** 2 + (cur[1] - instruction.y) ** 2);
1547
+ functions.push(makeLinearPosition({
1548
+ x0: cur[0],
1549
+ x1: instruction.x,
1550
+ y0: cur[1],
1551
+ y1: instruction.y
1552
+ }));
1553
+ cur = [instruction.x, instruction.y];
1554
+ }
1555
+ if (instruction.type === "l") {
1556
+ totalLength += Math.sqrt(instruction.dx ** 2 + instruction.dy ** 2);
1557
+ functions.push(makeLinearPosition({
1558
+ x0: cur[0],
1559
+ x1: instruction.dx + cur[0],
1560
+ y0: cur[1],
1561
+ y1: instruction.dy + cur[1]
1562
+ }));
1563
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
1564
+ }
1565
+ if (instruction.type === "H") {
1566
+ totalLength += Math.abs(cur[0] - instruction.x);
1567
+ functions.push(makeLinearPosition({
1568
+ x0: cur[0],
1569
+ x1: instruction.x,
1570
+ y0: cur[1],
1571
+ y1: cur[1]
1572
+ }));
1573
+ cur[0] = instruction.x;
1574
+ }
1575
+ if (instruction.type === "h") {
1576
+ totalLength += Math.abs(instruction.dx);
1577
+ functions.push(makeLinearPosition({
1578
+ x0: cur[0],
1579
+ x1: cur[0] + instruction.dx,
1580
+ y0: cur[1],
1581
+ y1: cur[1]
1582
+ }));
1583
+ cur[0] = instruction.dx + cur[0];
1584
+ } else if (instruction.type === "V") {
1585
+ totalLength += Math.abs(cur[1] - instruction.y);
1586
+ functions.push(makeLinearPosition({
1587
+ x0: cur[0],
1588
+ x1: cur[0],
1589
+ y0: cur[1],
1590
+ y1: instruction.y
1591
+ }));
1592
+ cur[1] = instruction.y;
1593
+ }
1594
+ if (instruction.type === "v") {
1595
+ totalLength += Math.abs(instruction.dy);
1596
+ functions.push(makeLinearPosition({
1597
+ x0: cur[0],
1598
+ x1: cur[0],
1599
+ y0: cur[1],
1600
+ y1: cur[1] + instruction.dy
1601
+ }));
1602
+ cur[1] = instruction.dy + cur[1];
1603
+ } else if (instruction.type === "Z") {
1604
+ totalLength += Math.sqrt((ringStart[0] - cur[0]) ** 2 + (ringStart[1] - cur[1]) ** 2);
1605
+ functions.push(makeLinearPosition({
1606
+ x0: cur[0],
1607
+ x1: ringStart[0],
1608
+ y0: cur[1],
1609
+ y1: ringStart[1]
1610
+ }));
1611
+ cur = [ringStart[0], ringStart[1]];
1612
+ }
1613
+ if (instruction.type === "C") {
1614
+ curve = makeCubic({
1615
+ startX: cur[0],
1616
+ startY: cur[1],
1617
+ cp1x: instruction.cp1x,
1618
+ cp1y: instruction.cp1y,
1619
+ cp2x: instruction.cp2x,
1620
+ cp2y: instruction.cp2y,
1621
+ x: instruction.x,
1622
+ y: instruction.y
1623
+ });
1624
+ totalLength += curve.getTotalLength();
1625
+ cur = [instruction.x, instruction.y];
1626
+ functions.push(curve);
1627
+ } else if (instruction.type === "c") {
1628
+ curve = makeCubic({
1629
+ startX: cur[0],
1630
+ startY: cur[1],
1631
+ cp1x: cur[0] + instruction.cp1dx,
1632
+ cp1y: cur[1] + instruction.cp1dy,
1633
+ cp2x: cur[0] + instruction.cp2dx,
1634
+ cp2y: cur[1] + instruction.cp2dy,
1635
+ x: cur[0] + instruction.dx,
1636
+ y: cur[1] + instruction.dy
1637
+ });
1638
+ if (curve.getTotalLength() > 0) {
1639
+ totalLength += curve.getTotalLength();
1640
+ functions.push(curve);
1641
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
1642
+ } else {
1643
+ functions.push(makeLinearPosition({ x0: cur[0], x1: cur[0], y0: cur[1], y1: cur[1] }));
1644
+ }
1645
+ }
1646
+ if (instruction.type === "S") {
1647
+ const prev = instructions[i - 1];
1648
+ const prevWasCurve = prev.type === "C" || prev.type === "c" || prev.type === "S" || prev.type === "s";
1649
+ if (i > 0 && prevWasCurve) {
1650
+ if (curve) {
1651
+ const c = curve.getC();
1652
+ curve = makeCubic({
1653
+ startX: cur[0],
1654
+ startY: cur[1],
1655
+ cp1x: 2 * cur[0] - c.x,
1656
+ cp1y: 2 * cur[1] - c.y,
1657
+ cp2x: instruction.cpx,
1658
+ cp2y: instruction.cpy,
1659
+ x: instruction.x,
1660
+ y: instruction.y
1661
+ });
1662
+ }
1663
+ } else {
1664
+ curve = makeCubic({
1665
+ startX: cur[0],
1666
+ startY: cur[1],
1667
+ cp1x: cur[0],
1668
+ cp1y: cur[1],
1669
+ cp2x: instruction.cpx,
1670
+ cp2y: instruction.cpy,
1671
+ x: instruction.x,
1672
+ y: instruction.y
1673
+ });
1674
+ }
1675
+ if (curve) {
1676
+ totalLength += curve.getTotalLength();
1677
+ cur = [instruction.x, instruction.y];
1678
+ functions.push(curve);
1679
+ }
1680
+ }
1681
+ if (instruction.type === "s") {
1682
+ const prev = instructions[i - 1];
1683
+ const prevWasCurve = prev.type === "C" || prev.type === "c" || prev.type === "S" || prev.type === "s";
1684
+ if (i > 0 && prevWasCurve) {
1685
+ if (curve) {
1686
+ const c = curve.getC();
1687
+ const d = curve.getD();
1688
+ curve = makeCubic({
1689
+ startX: cur[0],
1690
+ startY: cur[1],
1691
+ cp1x: cur[0] + d.x - c.x,
1692
+ cp1y: cur[1] + d.y - c.y,
1693
+ cp2x: cur[0] + instruction.cpdx,
1694
+ cp2y: cur[1] + instruction.cpdy,
1695
+ x: cur[0] + instruction.dx,
1696
+ y: cur[1] + instruction.dy
1697
+ });
1698
+ }
1699
+ } else {
1700
+ curve = makeCubic({
1701
+ startX: cur[0],
1702
+ startY: cur[1],
1703
+ cp1x: cur[0],
1704
+ cp1y: cur[1],
1705
+ cp2x: cur[0] + instruction.cpdx,
1706
+ cp2y: cur[1] + instruction.cpdy,
1707
+ x: cur[0] + instruction.dx,
1708
+ y: cur[1] + instruction.dy
1709
+ });
1710
+ }
1711
+ if (curve) {
1712
+ totalLength += curve.getTotalLength();
1713
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
1714
+ functions.push(curve);
1715
+ }
1716
+ }
1717
+ if (instruction.type === "Q") {
1718
+ if (cur[0] === instruction.cpx && cur[1] === instruction.cpy) {
1719
+ const linearCurve = makeLinearPosition({
1720
+ x0: instruction.cpx,
1721
+ x1: instruction.x,
1722
+ y0: instruction.cpy,
1723
+ y1: instruction.y
1724
+ });
1725
+ totalLength += linearCurve.getTotalLength();
1726
+ functions.push(linearCurve);
1727
+ } else {
1728
+ curve = makeQuadratic({
1729
+ startX: cur[0],
1730
+ startY: cur[1],
1731
+ cpx: instruction.cpx,
1732
+ cpy: instruction.cpy,
1733
+ x: instruction.x,
1734
+ y: instruction.y
1735
+ });
1736
+ totalLength += curve.getTotalLength();
1737
+ functions.push(curve);
1738
+ }
1739
+ cur = [instruction.x, instruction.y];
1740
+ prev_point = [instruction.cpx, instruction.cpy];
1741
+ }
1742
+ if (instruction.type === "q") {
1743
+ if (instruction.cpdx === 0 && instruction.cpdy === 0) {
1744
+ const linearCurve = makeLinearPosition({
1745
+ x0: cur[0] + instruction.cpdx,
1746
+ x1: cur[0] + instruction.cpdy,
1747
+ y0: cur[1] + instruction.dx,
1748
+ y1: cur[1] + instruction.dy
1749
+ });
1750
+ totalLength += linearCurve.getTotalLength();
1751
+ functions.push(linearCurve);
1752
+ } else {
1753
+ curve = makeQuadratic({
1754
+ startX: cur[0],
1755
+ startY: cur[1],
1756
+ cpx: cur[0] + instruction.cpdx,
1757
+ cpy: cur[1] + instruction.cpdy,
1758
+ x: cur[0] + instruction.dx,
1759
+ y: cur[1] + instruction.dy
1760
+ });
1761
+ totalLength += curve.getTotalLength();
1762
+ functions.push(curve);
1763
+ }
1764
+ prev_point = [cur[0] + instruction.cpdx, cur[1] + instruction.cpdy];
1765
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
1766
+ }
1767
+ if (instruction.type === "T") {
1768
+ const prev = instructions[i - 1];
1769
+ const prevWasQ = prev.type === "Q" || prev.type === "q" || prev.type === "T" || prev.type === "t";
1770
+ if (i > 0 && prevWasQ) {
1771
+ curve = makeQuadratic({
1772
+ startX: cur[0],
1773
+ startY: cur[1],
1774
+ cpx: 2 * cur[0] - prev_point[0],
1775
+ cpy: 2 * cur[1] - prev_point[1],
1776
+ x: instruction.x,
1777
+ y: instruction.y
1778
+ });
1779
+ functions.push(curve);
1780
+ totalLength += curve.getTotalLength();
1781
+ } else {
1782
+ const linearCurve = makeLinearPosition({
1783
+ x0: cur[0],
1784
+ x1: instruction.x,
1785
+ y0: cur[1],
1786
+ y1: instruction.y
1787
+ });
1788
+ functions.push(linearCurve);
1789
+ totalLength += linearCurve.getTotalLength();
1790
+ }
1791
+ prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
1792
+ cur = [instruction.x, instruction.y];
1793
+ }
1794
+ if (instruction.type === "t") {
1795
+ const prev = instructions[i - 1];
1796
+ const prevWasQ = prev.type === "Q" || prev.type === "q" || prev.type === "T" || prev.type === "t";
1797
+ if (i > 0 && prevWasQ) {
1798
+ curve = makeQuadratic({
1799
+ startX: cur[0],
1800
+ startY: cur[1],
1801
+ cpx: 2 * cur[0] - prev_point[0],
1802
+ cpy: 2 * cur[1] - prev_point[1],
1803
+ x: cur[0] + instruction.dx,
1804
+ y: cur[1] + instruction.dy
1805
+ });
1806
+ totalLength += curve.getTotalLength();
1807
+ functions.push(curve);
1808
+ } else {
1809
+ const linearCurve = makeLinearPosition({
1810
+ x0: cur[0],
1811
+ x1: cur[0] + instruction.dx,
1812
+ y0: cur[1],
1813
+ y1: cur[1] + instruction.dy
1814
+ });
1815
+ totalLength += linearCurve.getTotalLength();
1816
+ functions.push(linearCurve);
1817
+ }
1818
+ prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
1819
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
1820
+ }
1821
+ if (instruction.type === "A") {
1822
+ const arcCurve = makeArc({
1823
+ x0: cur[0],
1824
+ y0: cur[1],
1825
+ rx: instruction.rx,
1826
+ ry: instruction.ry,
1827
+ xAxisRotate: instruction.xAxisRotation,
1828
+ LargeArcFlag: instruction.largeArcFlag,
1829
+ SweepFlag: instruction.sweepFlag,
1830
+ x1: instruction.x,
1831
+ y1: instruction.y
1832
+ });
1833
+ totalLength += arcCurve.getTotalLength();
1834
+ cur = [instruction.x, instruction.y];
1835
+ functions.push(arcCurve);
1836
+ }
1837
+ if (instruction.type === "a") {
1838
+ const arcCurve = makeArc({
1839
+ x0: cur[0],
1840
+ y0: cur[1],
1841
+ rx: instruction.rx,
1842
+ ry: instruction.ry,
1843
+ xAxisRotate: instruction.xAxisRotation,
1844
+ LargeArcFlag: instruction.largeArcFlag,
1845
+ SweepFlag: instruction.sweepFlag,
1846
+ x1: cur[0] + instruction.dx,
1847
+ y1: cur[1] + instruction.dy
1848
+ });
1849
+ totalLength += arcCurve.getTotalLength();
1850
+ cur = [cur[0] + instruction.dx, cur[1] + instruction.dy];
1851
+ functions.push(arcCurve);
1852
+ }
1853
+ partialLengths.push(totalLength);
1854
+ }
1855
+ return {
1856
+ segments,
1857
+ initialPoint,
1858
+ totalLength,
1859
+ partialLengths,
1860
+ functions
1861
+ };
1862
+ };
1863
+ var construct = (string) => {
1864
+ const parsed = parsePath(string);
1865
+ return constructFromInstructions(parsed);
1866
+ };
1867
+ var getLength = (path) => {
1868
+ const constructucted = construct(path);
1869
+ return constructucted.totalLength;
1870
+ };
1871
+ var evolvePath = (progress, path) => {
1872
+ const length2 = getLength(path);
1873
+ if (progress === 0) {
1874
+ const extendedLength = length2 * 1.5;
1875
+ return {
1876
+ strokeDasharray: `${extendedLength} ${extendedLength}`,
1877
+ strokeDashoffset: extendedLength
1878
+ };
1879
+ }
1880
+ const strokeDasharray = `${length2} ${length2}`;
1881
+ const strokeDashoffset = length2 - progress * length2;
1882
+ return { strokeDasharray, strokeDashoffset };
1883
+ };
1884
+
1885
+ // ../../node_modules/.bun/roughjs@4.6.6/node_modules/roughjs/bin/math.js
1886
+ class Random {
1887
+ constructor(seed) {
1888
+ this.seed = seed;
1889
+ }
1890
+ next() {
1891
+ if (this.seed) {
1892
+ return (2 ** 31 - 1 & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31;
1893
+ } else {
1894
+ return Math.random();
1895
+ }
1896
+ }
1897
+ }
1898
+ // ../../node_modules/.bun/roughjs@4.6.6/node_modules/roughjs/bin/renderer.js
1899
+ function line(x1, y1, x2, y2, o) {
1900
+ return { type: "path", ops: _doubleLine(x1, y1, x2, y2, o) };
1901
+ }
1902
+ function linearPath(points, close, o) {
1903
+ const len = (points || []).length;
1904
+ if (len > 2) {
1905
+ const ops = [];
1906
+ for (let i = 0;i < len - 1; i++) {
1907
+ ops.push(..._doubleLine(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1], o));
1908
+ }
1909
+ if (close) {
1910
+ ops.push(..._doubleLine(points[len - 1][0], points[len - 1][1], points[0][0], points[0][1], o));
1911
+ }
1912
+ return { type: "path", ops };
1913
+ } else if (len === 2) {
1914
+ return line(points[0][0], points[0][1], points[1][0], points[1][1], o);
1915
+ }
1916
+ return { type: "path", ops: [] };
1917
+ }
1918
+ function polygon(points, o) {
1919
+ return linearPath(points, true, o);
1920
+ }
1921
+ function rectangle(x, y, width, height, o) {
1922
+ const points = [
1923
+ [x, y],
1924
+ [x + width, y],
1925
+ [x + width, y + height],
1926
+ [x, y + height]
1927
+ ];
1928
+ return polygon(points, o);
1929
+ }
1930
+ function ellipse(x, y, width, height, o) {
1931
+ const params = generateEllipseParams(width, height, o);
1932
+ return ellipseWithParams(x, y, o, params).opset;
1933
+ }
1934
+ function generateEllipseParams(width, height, o) {
1935
+ const psq = Math.sqrt(Math.PI * 2 * Math.sqrt((Math.pow(width / 2, 2) + Math.pow(height / 2, 2)) / 2));
1936
+ const stepCount = Math.ceil(Math.max(o.curveStepCount, o.curveStepCount / Math.sqrt(200) * psq));
1937
+ const increment = Math.PI * 2 / stepCount;
1938
+ let rx = Math.abs(width / 2);
1939
+ let ry = Math.abs(height / 2);
1940
+ const curveFitRandomness = 1 - o.curveFitting;
1941
+ rx += _offsetOpt(rx * curveFitRandomness, o);
1942
+ ry += _offsetOpt(ry * curveFitRandomness, o);
1943
+ return { increment, rx, ry };
1944
+ }
1945
+ function ellipseWithParams(x, y, o, ellipseParams) {
1946
+ const [ap1, cp1] = _computeEllipsePoints(ellipseParams.increment, x, y, ellipseParams.rx, ellipseParams.ry, 1, ellipseParams.increment * _offset(0.1, _offset(0.4, 1, o), o), o);
1947
+ let o1 = _curve(ap1, null, o);
1948
+ if (!o.disableMultiStroke && o.roughness !== 0) {
1949
+ const [ap2] = _computeEllipsePoints(ellipseParams.increment, x, y, ellipseParams.rx, ellipseParams.ry, 1.5, 0, o);
1950
+ const o2 = _curve(ap2, null, o);
1951
+ o1 = o1.concat(o2);
1952
+ }
1953
+ return {
1954
+ estimatedPoints: cp1,
1955
+ opset: { type: "path", ops: o1 }
1956
+ };
1957
+ }
1958
+ function random(ops) {
1959
+ if (!ops.randomizer) {
1960
+ ops.randomizer = new Random(ops.seed || 0);
1961
+ }
1962
+ return ops.randomizer.next();
1963
+ }
1964
+ function _offset(min, max, ops, roughnessGain = 1) {
1965
+ return ops.roughness * roughnessGain * (random(ops) * (max - min) + min);
1966
+ }
1967
+ function _offsetOpt(x, ops, roughnessGain = 1) {
1968
+ return _offset(-x, x, ops, roughnessGain);
1969
+ }
1970
+ function _doubleLine(x1, y1, x2, y2, o, filling = false) {
1971
+ const singleStroke = filling ? o.disableMultiStrokeFill : o.disableMultiStroke;
1972
+ const o1 = _line(x1, y1, x2, y2, o, true, false);
1973
+ if (singleStroke) {
1974
+ return o1;
1975
+ }
1976
+ const o2 = _line(x1, y1, x2, y2, o, true, true);
1977
+ return o1.concat(o2);
1978
+ }
1979
+ function _line(x1, y1, x2, y2, o, move, overlay) {
1980
+ const lengthSq = Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2);
1981
+ const length2 = Math.sqrt(lengthSq);
1982
+ let roughnessGain = 1;
1983
+ if (length2 < 200) {
1984
+ roughnessGain = 1;
1985
+ } else if (length2 > 500) {
1986
+ roughnessGain = 0.4;
1987
+ } else {
1988
+ roughnessGain = -0.0016668 * length2 + 1.233334;
1989
+ }
1990
+ let offset = o.maxRandomnessOffset || 0;
1991
+ if (offset * offset * 100 > lengthSq) {
1992
+ offset = length2 / 10;
1993
+ }
1994
+ const halfOffset = offset / 2;
1995
+ const divergePoint = 0.2 + random(o) * 0.2;
1996
+ let midDispX = o.bowing * o.maxRandomnessOffset * (y2 - y1) / 200;
1997
+ let midDispY = o.bowing * o.maxRandomnessOffset * (x1 - x2) / 200;
1998
+ midDispX = _offsetOpt(midDispX, o, roughnessGain);
1999
+ midDispY = _offsetOpt(midDispY, o, roughnessGain);
2000
+ const ops = [];
2001
+ const randomHalf = () => _offsetOpt(halfOffset, o, roughnessGain);
2002
+ const randomFull = () => _offsetOpt(offset, o, roughnessGain);
2003
+ const preserveVertices = o.preserveVertices;
2004
+ if (move) {
2005
+ if (overlay) {
2006
+ ops.push({
2007
+ op: "move",
2008
+ data: [
2009
+ x1 + (preserveVertices ? 0 : randomHalf()),
2010
+ y1 + (preserveVertices ? 0 : randomHalf())
2011
+ ]
2012
+ });
2013
+ } else {
2014
+ ops.push({
2015
+ op: "move",
2016
+ data: [
2017
+ x1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain)),
2018
+ y1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain))
2019
+ ]
2020
+ });
2021
+ }
2022
+ }
2023
+ if (overlay) {
2024
+ ops.push({
2025
+ op: "bcurveTo",
2026
+ data: [
2027
+ midDispX + x1 + (x2 - x1) * divergePoint + randomHalf(),
2028
+ midDispY + y1 + (y2 - y1) * divergePoint + randomHalf(),
2029
+ midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomHalf(),
2030
+ midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomHalf(),
2031
+ x2 + (preserveVertices ? 0 : randomHalf()),
2032
+ y2 + (preserveVertices ? 0 : randomHalf())
2033
+ ]
2034
+ });
2035
+ } else {
2036
+ ops.push({
2037
+ op: "bcurveTo",
2038
+ data: [
2039
+ midDispX + x1 + (x2 - x1) * divergePoint + randomFull(),
2040
+ midDispY + y1 + (y2 - y1) * divergePoint + randomFull(),
2041
+ midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomFull(),
2042
+ midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomFull(),
2043
+ x2 + (preserveVertices ? 0 : randomFull()),
2044
+ y2 + (preserveVertices ? 0 : randomFull())
2045
+ ]
2046
+ });
2047
+ }
2048
+ return ops;
2049
+ }
2050
+ function _curve(points, closePoint, o) {
2051
+ const len = points.length;
2052
+ const ops = [];
2053
+ if (len > 3) {
2054
+ const b = [];
2055
+ const s = 1 - o.curveTightness;
2056
+ ops.push({ op: "move", data: [points[1][0], points[1][1]] });
2057
+ for (let i = 1;i + 2 < len; i++) {
2058
+ const cachedVertArray = points[i];
2059
+ b[0] = [cachedVertArray[0], cachedVertArray[1]];
2060
+ b[1] = [cachedVertArray[0] + (s * points[i + 1][0] - s * points[i - 1][0]) / 6, cachedVertArray[1] + (s * points[i + 1][1] - s * points[i - 1][1]) / 6];
2061
+ b[2] = [points[i + 1][0] + (s * points[i][0] - s * points[i + 2][0]) / 6, points[i + 1][1] + (s * points[i][1] - s * points[i + 2][1]) / 6];
2062
+ b[3] = [points[i + 1][0], points[i + 1][1]];
2063
+ ops.push({ op: "bcurveTo", data: [b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1]] });
2064
+ }
2065
+ if (closePoint && closePoint.length === 2) {
2066
+ const ro = o.maxRandomnessOffset;
2067
+ ops.push({ op: "lineTo", data: [closePoint[0] + _offsetOpt(ro, o), closePoint[1] + _offsetOpt(ro, o)] });
2068
+ }
2069
+ } else if (len === 3) {
2070
+ ops.push({ op: "move", data: [points[1][0], points[1][1]] });
2071
+ ops.push({
2072
+ op: "bcurveTo",
2073
+ data: [
2074
+ points[1][0],
2075
+ points[1][1],
2076
+ points[2][0],
2077
+ points[2][1],
2078
+ points[2][0],
2079
+ points[2][1]
2080
+ ]
2081
+ });
2082
+ } else if (len === 2) {
2083
+ ops.push(..._line(points[0][0], points[0][1], points[1][0], points[1][1], o, true, true));
2084
+ }
2085
+ return ops;
2086
+ }
2087
+ function _computeEllipsePoints(increment, cx, cy, rx, ry, offset, overlap, o) {
2088
+ const coreOnly = o.roughness === 0;
2089
+ const corePoints = [];
2090
+ const allPoints = [];
2091
+ if (coreOnly) {
2092
+ increment = increment / 4;
2093
+ allPoints.push([
2094
+ cx + rx * Math.cos(-increment),
2095
+ cy + ry * Math.sin(-increment)
2096
+ ]);
2097
+ for (let angle = 0;angle <= Math.PI * 2; angle = angle + increment) {
2098
+ const p = [
2099
+ cx + rx * Math.cos(angle),
2100
+ cy + ry * Math.sin(angle)
2101
+ ];
2102
+ corePoints.push(p);
2103
+ allPoints.push(p);
2104
+ }
2105
+ allPoints.push([
2106
+ cx + rx * Math.cos(0),
2107
+ cy + ry * Math.sin(0)
2108
+ ]);
2109
+ allPoints.push([
2110
+ cx + rx * Math.cos(increment),
2111
+ cy + ry * Math.sin(increment)
2112
+ ]);
2113
+ } else {
2114
+ const radOffset = _offsetOpt(0.5, o) - Math.PI / 2;
2115
+ allPoints.push([
2116
+ _offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),
2117
+ _offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment)
2118
+ ]);
2119
+ const endAngle = Math.PI * 2 + radOffset - 0.01;
2120
+ for (let angle = radOffset;angle < endAngle; angle = angle + increment) {
2121
+ const p = [
2122
+ _offsetOpt(offset, o) + cx + rx * Math.cos(angle),
2123
+ _offsetOpt(offset, o) + cy + ry * Math.sin(angle)
2124
+ ];
2125
+ corePoints.push(p);
2126
+ allPoints.push(p);
2127
+ }
2128
+ allPoints.push([
2129
+ _offsetOpt(offset, o) + cx + rx * Math.cos(radOffset + Math.PI * 2 + overlap * 0.5),
2130
+ _offsetOpt(offset, o) + cy + ry * Math.sin(radOffset + Math.PI * 2 + overlap * 0.5)
2131
+ ]);
2132
+ allPoints.push([
2133
+ _offsetOpt(offset, o) + cx + 0.98 * rx * Math.cos(radOffset + overlap),
2134
+ _offsetOpt(offset, o) + cy + 0.98 * ry * Math.sin(radOffset + overlap)
2135
+ ]);
2136
+ allPoints.push([
2137
+ _offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset + overlap * 0.5),
2138
+ _offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset + overlap * 0.5)
2139
+ ]);
2140
+ }
2141
+ return [allPoints, corePoints];
2142
+ }
2143
+
2144
+ // src/render-annotation.tsx
2145
+ import { jsx } from "react/jsx-runtime";
2146
+ var opsToPath = (opList) => {
2147
+ const paths = [];
2148
+ for (const drawing of opList) {
2149
+ let path = "";
2150
+ for (const item of drawing.ops) {
2151
+ const { data } = item;
2152
+ if (item.op === "move") {
2153
+ if (path.trim()) {
2154
+ paths.push(path.trim());
2155
+ }
2156
+ path = `M${data[0]} ${data[1]} `;
2157
+ } else if (item.op === "bcurveTo") {
2158
+ path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
2159
+ } else if (item.op === "lineTo") {
2160
+ path += `L${data[0]} ${data[1]} `;
2161
+ }
2162
+ }
2163
+ if (path.trim()) {
2164
+ paths.push(path.trim());
2165
+ }
2166
+ }
2167
+ return paths;
2168
+ };
2169
+ var addKeysToPaths = (paths) => {
2170
+ const occurrences = new Map;
2171
+ return paths.map((d) => {
2172
+ const occurrence = occurrences.get(d) ?? 0;
2173
+ occurrences.set(d, occurrence + 1);
2174
+ return { d, key: `${d}-${occurrence}` };
2175
+ });
2176
+ };
2177
+ var getOptions = (type, seed, overrides) => {
2178
+ return {
2179
+ maxRandomnessOffset: 5,
2180
+ roughness: type === "highlight" ? 3 : 1.5,
2181
+ bowing: 1,
2182
+ stroke: "#000",
2183
+ strokeWidth: 1.5,
2184
+ curveTightness: 0,
2185
+ curveFitting: 0.95,
2186
+ curveStepCount: 9,
2187
+ fillStyle: "hachure",
2188
+ fillWeight: -1,
2189
+ hachureAngle: -41,
2190
+ hachureGap: -1,
2191
+ dashOffset: -1,
2192
+ dashGap: -1,
2193
+ zigzagOffset: -1,
2194
+ disableMultiStroke: type !== "double",
2195
+ disableMultiStrokeFill: false,
2196
+ fillShapeRoughnessGain: 1.5,
2197
+ preserveVertices: false,
2198
+ ...overrides,
2199
+ seed
2200
+ };
2201
+ };
2202
+ var getCircleItems = (rect, config) => {
2203
+ if (config.type !== "circle") {
2204
+ throw new Error("Not a circle");
2205
+ }
2206
+ if (config.box === "inside") {
2207
+ const paddedWidth = rect.w + (config.padding.left + config.padding.right);
2208
+ const paddedHeight = rect.h + (config.padding.top + config.padding.bottom);
2209
+ const x = rect.x - config.padding.left + paddedWidth / 2;
2210
+ const y = rect.y - config.padding.top + paddedHeight / 2;
2211
+ return { width: paddedWidth, height: paddedHeight, x, y };
2212
+ }
2213
+ const cx = rect.x + rect.w / 2 - config.padding.left / 2 + config.padding.right / 2;
2214
+ const cy = rect.y + rect.h / 2 - config.padding.top / 2 + config.padding.bottom / 2;
2215
+ const width = rect.w + config.padding.left + config.padding.right;
2216
+ const height = rect.h + config.padding.top + config.padding.bottom;
2217
+ return {
2218
+ width: width / Math.sqrt(2) * 2,
2219
+ height: height / Math.sqrt(2) * 2,
2220
+ x: cx,
2221
+ y: cy
2222
+ };
2223
+ };
2224
+ function getInstructions({
2225
+ rect,
2226
+ config,
2227
+ seed,
2228
+ options
2229
+ }) {
2230
+ if (config.type === "none") {
2231
+ return { opList: [], strokeWidth: 0 };
2232
+ }
2233
+ if (config.type === "underline") {
2234
+ const o = getOptions("single", seed, options);
2235
+ const { iterations } = config;
2236
+ const rtl = config.rtl ? 1 : 0;
2237
+ const opList = [];
2238
+ const y = rect.y + rect.h + config.padding.top;
2239
+ for (let i = rtl;i < iterations + rtl; i++) {
2240
+ if (i % 2) {
2241
+ opList.push(line(rect.x + rect.w, y, rect.x, y, o));
2242
+ } else {
2243
+ opList.push(line(rect.x, y, rect.x + rect.w, y, o));
2244
+ }
2245
+ }
2246
+ return { opList, strokeWidth: config.strokeWidth };
2247
+ }
2248
+ if (config.type === "strike-through") {
2249
+ const o = getOptions("single", seed, options);
2250
+ const { iterations } = config;
2251
+ const rtl = config.rtl ? 1 : 0;
2252
+ const opList = [];
2253
+ const y = rect.y + rect.h / 2;
2254
+ for (let i = rtl;i < iterations + rtl; i++) {
2255
+ if (i % 2) {
2256
+ opList.push(line(rect.x + rect.w, y, rect.x, y, o));
2257
+ } else {
2258
+ opList.push(line(rect.x, y, rect.x + rect.w, y, o));
2259
+ }
2260
+ }
2261
+ return { opList, strokeWidth: config.strokeWidth };
2262
+ }
2263
+ if (config.type === "box") {
2264
+ const o = getOptions("single", seed, options);
2265
+ const { iterations } = config;
2266
+ const opList = [];
2267
+ const x = rect.x - config.padding.left;
2268
+ const y = rect.y - config.padding.top;
2269
+ const width = rect.w + (config.padding.left + config.padding.right);
2270
+ const height = rect.h + (config.padding.top + config.padding.bottom);
2271
+ for (let i = 0;i < iterations; i++) {
2272
+ opList.push(rectangle(x, y, width, height, o));
2273
+ }
2274
+ return { opList, strokeWidth: config.strokeWidth };
2275
+ }
2276
+ if (config.type === "bracket") {
2277
+ const o = getOptions("single", seed, options);
2278
+ const opList = [];
2279
+ const lx = rect.x - config.padding.left;
2280
+ const rx = rect.x + rect.w + config.padding.right;
2281
+ const ty = rect.y - config.padding.top;
2282
+ const by = rect.y + rect.h + config.padding.bottom;
2283
+ const sides = [
2284
+ {
2285
+ enabled: config.bracketBottom,
2286
+ points: [
2287
+ [lx, by],
2288
+ [rx, by]
2289
+ ]
2290
+ },
2291
+ {
2292
+ enabled: config.bracketTop,
2293
+ points: [
2294
+ [lx, ty],
2295
+ [rx, ty]
2296
+ ]
2297
+ },
2298
+ {
2299
+ enabled: config.bracketLeft,
2300
+ points: [
2301
+ [lx, ty],
2302
+ [lx, by]
2303
+ ]
2304
+ },
2305
+ {
2306
+ enabled: config.bracketRight,
2307
+ points: [
2308
+ [rx, ty],
2309
+ [rx, by]
2310
+ ]
2311
+ }
2312
+ ];
2313
+ for (const side of sides) {
2314
+ if (side.enabled) {
2315
+ opList.push(linearPath(side.points, false, o));
2316
+ }
2317
+ }
2318
+ return { opList, strokeWidth: config.strokeWidth };
2319
+ }
2320
+ if (config.type === "crossed-off") {
2321
+ const o = getOptions("single", seed, options);
2322
+ const { iterations } = config;
2323
+ const rtl = config.rtl ? 1 : 0;
2324
+ const opList = [];
2325
+ const { x } = rect;
2326
+ const { y } = rect;
2327
+ const x2 = x + rect.w;
2328
+ const y2 = y + rect.h;
2329
+ for (let i = rtl;i < iterations + rtl; i++) {
2330
+ if (i % 2) {
2331
+ opList.push(line(x2, y2, x, y, o));
2332
+ } else {
2333
+ opList.push(line(x, y, x2, y2, o));
2334
+ }
2335
+ }
2336
+ for (let i = rtl;i < iterations + rtl; i++) {
2337
+ if (i % 2) {
2338
+ opList.push(line(x, y2, x2, y, o));
2339
+ } else {
2340
+ opList.push(line(x2, y, x, y2, o));
2341
+ }
2342
+ }
2343
+ return { opList, strokeWidth: config.strokeWidth };
2344
+ }
2345
+ if (config.type === "circle") {
2346
+ const { iterations } = config;
2347
+ const opList = [];
2348
+ const { width, height, x, y } = getCircleItems(rect, config);
2349
+ for (let i = 0;i < iterations; i++) {
2350
+ const o = getOptions("single", seed + i, options);
2351
+ opList.push(ellipse(x, y, width, height, o));
2352
+ }
2353
+ return { opList, strokeWidth: config.strokeWidth };
2354
+ }
2355
+ if (config.type === "highlight") {
2356
+ const { iterations } = config;
2357
+ const rtl = config.rtl ? 1 : 0;
2358
+ const opList = [];
2359
+ const y = rect.y + rect.h / 2 + (config.padding.bottom - config.padding.top) / 2;
2360
+ for (let i = rtl;i < iterations + rtl; i++) {
2361
+ const o = getOptions("highlight", seed + i, options);
2362
+ if (i % 2) {
2363
+ opList.push(line(rect.x + rect.w + config.padding.right, y, rect.x - config.padding.left, y, o));
2364
+ } else {
2365
+ opList.push(line(rect.x - config.padding.left, y, rect.x + rect.w + config.padding.right, y, o));
2366
+ }
2367
+ }
2368
+ return {
2369
+ opList,
2370
+ strokeWidth: rect.h + config.padding.top + config.padding.bottom
2371
+ };
2372
+ }
2373
+ throw new Error(`Unrecognized annotation type: ${config}`);
2374
+ }
2375
+ var renderAnnotation = ({
2376
+ rect,
2377
+ config,
2378
+ seed,
2379
+ progress,
2380
+ options
2381
+ }) => {
2382
+ if (config.type === "none") {
2383
+ return [];
2384
+ }
2385
+ const { opList, strokeWidth } = getInstructions({
2386
+ config,
2387
+ rect,
2388
+ seed,
2389
+ options
2390
+ });
2391
+ const pathsWithKeys = addKeysToPaths(opsToPath(opList));
2392
+ return pathsWithKeys.map(({ d, key }, i) => {
2393
+ const isLast = i === pathsWithKeys.length - 1;
2394
+ const progressForIteration = Math.max(0, Math.min(isLast ? Infinity : 1, progress * pathsWithKeys.length - i));
2395
+ const { strokeDasharray, strokeDashoffset } = evolvePath(progressForIteration, d);
2396
+ return /* @__PURE__ */ jsx("path", {
2397
+ d,
2398
+ fill: "none",
2399
+ stroke: config.color,
2400
+ strokeWidth,
2401
+ strokeDasharray,
2402
+ strokeDashoffset
2403
+ }, key);
2404
+ });
2405
+ };
2406
+
2407
+ // src/rough.ts
2408
+ var svgRect = ({
2409
+ svg,
2410
+ element,
2411
+ scale
2412
+ }) => {
2413
+ const rect1 = svg.getBoundingClientRect();
2414
+ const rect2 = element.getBoundingClientRect();
2415
+ const inverseScale = 1 / scale;
2416
+ return {
2417
+ x: (rect2.x - rect1.x) * inverseScale,
2418
+ y: (rect2.y - rect1.y) * inverseScale,
2419
+ w: rect2.width * inverseScale,
2420
+ h: rect2.height * inverseScale
2421
+ };
2422
+ };
2423
+ var render = ({
2424
+ svg,
2425
+ seed,
2426
+ element,
2427
+ config,
2428
+ scale,
2429
+ progress,
2430
+ options
2431
+ }) => {
2432
+ if (scale === 0) {
2433
+ return [];
2434
+ }
2435
+ const rect = svgRect({ svg, element, scale });
2436
+ if (rect.w === 0 || rect.h === 0) {
2437
+ return [];
2438
+ }
2439
+ return renderAnnotation({
2440
+ config,
2441
+ seed,
2442
+ rect,
2443
+ progress,
2444
+ options
2445
+ });
2446
+ };
2447
+
2448
+ // src/types.ts
2449
+ var defaultPadding = {
2450
+ bottom: 0,
2451
+ left: 0,
2452
+ right: 0,
2453
+ top: 0
2454
+ };
2455
+ var resolvePadding = (padding) => {
2456
+ return {
2457
+ ...defaultPadding,
2458
+ ...padding
2459
+ };
2460
+ };
2461
+ var resolveIterations = (iterations, defaultIterations) => {
2462
+ if (iterations === undefined) {
2463
+ return defaultIterations;
2464
+ }
2465
+ if (!Number.isInteger(iterations) || iterations < 1) {
2466
+ throw new TypeError("iterations must be an integer of at least 1");
2467
+ }
2468
+ return iterations;
2469
+ };
2470
+ var shared = ({
2471
+ color,
2472
+ strokeWidth,
2473
+ defaultStrokeWidth
2474
+ }) => {
2475
+ return {
2476
+ color: color ?? "currentColor",
2477
+ strokeWidth: strokeWidth ?? defaultStrokeWidth
2478
+ };
2479
+ };
2480
+ var resolveRoughOptions = (options) => {
2481
+ return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
2482
+ };
2483
+ var resolveAnnotationConfig = (config) => {
2484
+ if (config.type === "none") {
2485
+ return config;
2486
+ }
2487
+ if (config.type === "underline") {
2488
+ return {
2489
+ type: "underline",
2490
+ ...shared({ ...config, defaultStrokeWidth: 20 }),
2491
+ padding: resolvePadding(config.padding),
2492
+ iterations: resolveIterations(config.iterations, 2),
2493
+ rtl: config.rtl ?? false
2494
+ };
2495
+ }
2496
+ if (config.type === "strike-through") {
2497
+ return {
2498
+ type: "strike-through",
2499
+ ...shared({ ...config, defaultStrokeWidth: 20 }),
2500
+ iterations: resolveIterations(config.iterations, 1),
2501
+ rtl: config.rtl ?? false
2502
+ };
2503
+ }
2504
+ if (config.type === "box") {
2505
+ return {
2506
+ type: "box",
2507
+ ...shared({ ...config, defaultStrokeWidth: 7 }),
2508
+ padding: resolvePadding(config.padding),
2509
+ iterations: resolveIterations(config.iterations, 2)
2510
+ };
2511
+ }
2512
+ if (config.type === "bracket") {
2513
+ return {
2514
+ type: "bracket",
2515
+ ...shared({ ...config, defaultStrokeWidth: 20 }),
2516
+ padding: resolvePadding(config.padding),
2517
+ bracketLeft: config.bracketLeft ?? false,
2518
+ bracketRight: config.bracketRight ?? true,
2519
+ bracketTop: config.bracketTop ?? false,
2520
+ bracketBottom: config.bracketBottom ?? false
2521
+ };
2522
+ }
2523
+ if (config.type === "crossed-off") {
2524
+ return {
2525
+ type: "crossed-off",
2526
+ ...shared({ ...config, defaultStrokeWidth: 20 }),
2527
+ iterations: resolveIterations(config.iterations, 1),
2528
+ rtl: config.rtl ?? false
2529
+ };
2530
+ }
2531
+ if (config.type === "circle") {
2532
+ return {
2533
+ type: "circle",
2534
+ ...shared({ ...config, defaultStrokeWidth: 20 }),
2535
+ padding: resolvePadding(config.padding),
2536
+ iterations: resolveIterations(config.iterations, 2),
2537
+ box: config.box ?? "around"
2538
+ };
2539
+ }
2540
+ if (config.type === "highlight") {
2541
+ return {
2542
+ type: "highlight",
2543
+ color: config.color ?? "currentColor",
2544
+ padding: resolvePadding(config.padding),
2545
+ iterations: resolveIterations(config.iterations, 2),
2546
+ rtl: config.rtl ?? false
2547
+ };
2548
+ }
2549
+ const invalidConfig = config;
2550
+ throw new TypeError(`Unsupported annotation type: ${String(invalidConfig.type)}`);
2551
+ };
2552
+
2553
+ // src/create-annotation.tsx
2554
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2555
+ var AnnotationContext = createContext({
2556
+ setSvgChildren: () => {
2557
+ return;
2558
+ },
2559
+ svgChildren: []
2560
+ });
2561
+ var MEASURER_SIZE = 100;
2562
+ var measurerSize = {
2563
+ height: MEASURER_SIZE,
2564
+ width: MEASURER_SIZE,
2565
+ position: "fixed",
2566
+ opacity: 0,
2567
+ top: -1e4
2568
+ };
2569
+ var createAnnotation = () => {
2570
+ const ref = createRef();
2571
+ const svgRef = createRef();
2572
+ const measurer = createRef();
2573
+ const Container = (props) => {
2574
+ const [svgChildren, setSvgChildren] = useState2([]);
2575
+ const value = useMemo2(() => {
2576
+ return { setSvgChildren, svgChildren };
2577
+ }, [svgChildren]);
2578
+ return /* @__PURE__ */ jsxs(AnnotationContext.Provider, {
2579
+ value,
2580
+ children: [
2581
+ props.children,
2582
+ /* @__PURE__ */ jsx2("div", {
2583
+ ref: measurer,
2584
+ style: measurerSize
2585
+ })
2586
+ ]
2587
+ });
2588
+ };
2589
+ const Tracker = ({ children, style }) => {
2590
+ return /* @__PURE__ */ jsx2("span", {
2591
+ ref,
2592
+ style: {
2593
+ ...style,
2594
+ display: "inline-block",
2595
+ position: "relative",
2596
+ whiteSpace: "pre"
2597
+ },
2598
+ children
2599
+ });
2600
+ };
2601
+ const Annotation = ({
2602
+ roughness,
2603
+ maxRandomnessOffset,
2604
+ bowing,
2605
+ curveFitting,
2606
+ curveTightness,
2607
+ curveStepCount,
2608
+ disableMultiStroke,
2609
+ preserveVertices,
2610
+ seed,
2611
+ progress,
2612
+ ...config
2613
+ }) => {
2614
+ const parsed = useMemo2(() => {
2615
+ return resolveAnnotationConfig(config);
2616
+ }, [config]);
2617
+ const roughJsOptions = useMemo2(() => {
2618
+ return resolveRoughOptions({
2619
+ roughness,
2620
+ maxRandomnessOffset,
2621
+ bowing,
2622
+ curveFitting,
2623
+ curveTightness,
2624
+ curveStepCount,
2625
+ disableMultiStroke,
2626
+ preserveVertices
2627
+ });
2628
+ }, [
2629
+ bowing,
2630
+ curveFitting,
2631
+ curveStepCount,
2632
+ curveTightness,
2633
+ disableMultiStroke,
2634
+ maxRandomnessOffset,
2635
+ preserveVertices,
2636
+ roughness
2637
+ ]);
2638
+ const [initial] = useState2(() => delayRender());
2639
+ const size = useElementSize(ref);
2640
+ useEffect2(() => {
2641
+ if (size === null) {
2642
+ return;
2643
+ }
2644
+ continueRender(initial);
2645
+ }, [initial, size]);
2646
+ const scale = measurer.current ? measurer.current.getBoundingClientRect().width / MEASURER_SIZE : null;
2647
+ const svgChildren = ref.current && scale ? render({
2648
+ config: parsed,
2649
+ svg: svgRef.current,
2650
+ element: ref.current,
2651
+ seed: seed ?? 1,
2652
+ scale,
2653
+ progress,
2654
+ options: roughJsOptions
2655
+ }) : [];
2656
+ return /* @__PURE__ */ jsx2("svg", {
2657
+ ref: svgRef,
2658
+ style: {
2659
+ position: "absolute",
2660
+ top: 0,
2661
+ left: 0,
2662
+ overflow: "visible",
2663
+ width: 100,
2664
+ height: 100
2665
+ },
2666
+ children: svgChildren
2667
+ });
2668
+ };
2669
+ return { Container, Tracker, Annotation };
2670
+ };
2671
+
2672
+ // src/Annotation.tsx
2673
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2674
+ var colorSchema = {
2675
+ color: {
2676
+ type: "color",
2677
+ default: "currentColor",
2678
+ description: "Color"
2679
+ }
2680
+ };
2681
+ var strokeWidthSchema = (defaultValue) => ({
2682
+ strokeWidth: {
2683
+ type: "number",
2684
+ min: 0,
2685
+ step: 1,
2686
+ default: defaultValue,
2687
+ description: "Stroke Width",
2688
+ hiddenFromList: false
2689
+ }
2690
+ });
2691
+ var iterationsSchema = (defaultValue) => ({
2692
+ iterations: {
2693
+ type: "number",
2694
+ min: 1,
2695
+ step: 1,
2696
+ default: defaultValue,
2697
+ description: "Iterations",
2698
+ hiddenFromList: false
2699
+ }
2700
+ });
2701
+ var rtlSchema = {
2702
+ rtl: {
2703
+ type: "boolean",
2704
+ default: false,
2705
+ description: "Right-to-left"
2706
+ }
2707
+ };
2708
+ var roughJsControlsSchema = (defaultRoughness) => ({
2709
+ roughness: {
2710
+ type: "number",
2711
+ min: 0,
2712
+ step: 0.1,
2713
+ default: defaultRoughness,
2714
+ description: "Roughness",
2715
+ hiddenFromList: false
2716
+ },
2717
+ maxRandomnessOffset: {
2718
+ type: "number",
2719
+ min: 0,
2720
+ step: 0.1,
2721
+ default: 5,
2722
+ description: "Max Randomness Offset",
2723
+ hiddenFromList: false
2724
+ },
2725
+ bowing: {
2726
+ type: "number",
2727
+ min: 0,
2728
+ step: 0.1,
2729
+ default: 1,
2730
+ description: "Bowing",
2731
+ hiddenFromList: false
2732
+ },
2733
+ disableMultiStroke: {
2734
+ type: "boolean",
2735
+ default: false,
2736
+ description: "Disable Multi Stroke"
2737
+ },
2738
+ preserveVertices: {
2739
+ type: "boolean",
2740
+ default: false,
2741
+ description: "Preserve Vertices"
2742
+ }
2743
+ });
2744
+ var curveControlsSchema = {
2745
+ curveFitting: {
2746
+ type: "number",
2747
+ min: 0,
2748
+ step: 0.01,
2749
+ default: 0.95,
2750
+ description: "Curve Fitting",
2751
+ hiddenFromList: false
2752
+ },
2753
+ curveTightness: {
2754
+ type: "number",
2755
+ step: 0.1,
2756
+ default: 0,
2757
+ description: "Curve Tightness",
2758
+ hiddenFromList: false
2759
+ },
2760
+ curveStepCount: {
2761
+ type: "number",
2762
+ min: 1,
2763
+ step: 1,
2764
+ default: 9,
2765
+ description: "Curve Step Count",
2766
+ hiddenFromList: false
2767
+ }
2768
+ };
2769
+ var paddingSchema = {
2770
+ "padding.left": {
2771
+ type: "number",
2772
+ step: 1,
2773
+ default: 0,
2774
+ description: "Left Padding",
2775
+ hiddenFromList: false
2776
+ },
2777
+ "padding.right": {
2778
+ type: "number",
2779
+ step: 1,
2780
+ default: 0,
2781
+ description: "Right Padding",
2782
+ hiddenFromList: false
2783
+ },
2784
+ "padding.top": {
2785
+ type: "number",
2786
+ step: 1,
2787
+ default: 0,
2788
+ description: "Top Padding",
2789
+ hiddenFromList: false
2790
+ },
2791
+ "padding.bottom": {
2792
+ type: "number",
2793
+ step: 1,
2794
+ default: 0,
2795
+ description: "Bottom Padding",
2796
+ hiddenFromList: false
2797
+ }
2798
+ };
2799
+ var underlinePaddingSchema = {
2800
+ "padding.top": paddingSchema["padding.top"]
2801
+ };
2802
+ var textContentSchema = {
2803
+ children: {
2804
+ type: "text-content",
2805
+ default: "",
2806
+ description: "Text",
2807
+ keyframable: false
2808
+ }
2809
+ };
2810
+ var sharedSchema = (defaultRoughness) => ({
2811
+ ...Interactive.baseSchema,
2812
+ progress: {
2813
+ type: "number",
2814
+ min: 0,
2815
+ max: 1,
2816
+ step: 0.01,
2817
+ default: 1,
2818
+ description: "Progress",
2819
+ hiddenFromList: false
2820
+ },
2821
+ disabled: {
2822
+ type: "boolean",
2823
+ default: false,
2824
+ description: "Disabled"
2825
+ },
2826
+ seed: {
2827
+ type: "number",
2828
+ step: 1,
2829
+ default: 1,
2830
+ description: "Seed",
2831
+ hiddenFromList: false
2832
+ },
2833
+ ...roughJsControlsSchema(defaultRoughness),
2834
+ ...colorSchema,
2835
+ ...Interactive.textSchema,
2836
+ ...textContentSchema
2837
+ });
2838
+ var highlightSchema = {
2839
+ ...sharedSchema(3),
2840
+ ...iterationsSchema(2),
2841
+ ...rtlSchema,
2842
+ ...paddingSchema
2843
+ };
2844
+ var underlineSchema = {
2845
+ ...sharedSchema(1.5),
2846
+ ...strokeWidthSchema(20),
2847
+ ...iterationsSchema(2),
2848
+ ...rtlSchema,
2849
+ ...underlinePaddingSchema
2850
+ };
2851
+ var strikeThroughSchema = {
2852
+ ...sharedSchema(1.5),
2853
+ ...strokeWidthSchema(20),
2854
+ ...iterationsSchema(1),
2855
+ ...rtlSchema
2856
+ };
2857
+ var crossedOffSchema = {
2858
+ ...sharedSchema(1.5),
2859
+ ...strokeWidthSchema(20),
2860
+ ...iterationsSchema(1),
2861
+ ...rtlSchema
2862
+ };
2863
+ var boxSchema = {
2864
+ ...sharedSchema(1.5),
2865
+ ...strokeWidthSchema(7),
2866
+ ...iterationsSchema(2),
2867
+ ...paddingSchema
2868
+ };
2869
+ var bracketSchema = {
2870
+ ...sharedSchema(1.5),
2871
+ ...strokeWidthSchema(20),
2872
+ ...paddingSchema,
2873
+ bracketLeft: {
2874
+ type: "boolean",
2875
+ default: false,
2876
+ description: "Left Bracket"
2877
+ },
2878
+ bracketRight: {
2879
+ type: "boolean",
2880
+ default: true,
2881
+ description: "Right Bracket"
2882
+ },
2883
+ bracketTop: {
2884
+ type: "boolean",
2885
+ default: false,
2886
+ description: "Top Bracket"
2887
+ },
2888
+ bracketBottom: {
2889
+ type: "boolean",
2890
+ default: false,
2891
+ description: "Bottom Bracket"
2892
+ }
2893
+ };
2894
+ var circleSchema = {
2895
+ ...sharedSchema(1.5),
2896
+ ...strokeWidthSchema(20),
2897
+ ...iterationsSchema(2),
2898
+ ...paddingSchema,
2899
+ ...curveControlsSchema,
2900
+ box: {
2901
+ type: "enum",
2902
+ default: "around",
2903
+ description: "Box",
2904
+ keyframable: false,
2905
+ variants: {
2906
+ inside: {},
2907
+ around: {}
2908
+ }
2909
+ }
2910
+ };
2911
+ var makeAnnotationComponent = ({
2912
+ type,
2913
+ componentName,
2914
+ documentationSlug,
2915
+ layer,
2916
+ schema
2917
+ }) => {
2918
+ const AnnotationInner = ({
2919
+ children,
2920
+ durationInFrames,
2921
+ from,
2922
+ trimBefore,
2923
+ freeze,
2924
+ hidden,
2925
+ name,
2926
+ showInTimeline,
2927
+ controls,
2928
+ stack,
2929
+ style,
2930
+ progress,
2931
+ seed,
2932
+ disabled,
2933
+ roughness,
2934
+ maxRandomnessOffset,
2935
+ bowing,
2936
+ curveFitting,
2937
+ curveTightness,
2938
+ curveStepCount,
2939
+ disableMultiStroke,
2940
+ preserveVertices,
2941
+ ...configProps
2942
+ }) => {
2943
+ const annotation = useMemo3(() => {
2944
+ return createAnnotation();
2945
+ }, []);
2946
+ const outlineRef = React2.useRef(null);
2947
+ const config = disabled ? { type: "none" } : { ...configProps, type };
2948
+ const annotationElement = /* @__PURE__ */ jsx3(annotation.Annotation, {
2949
+ ...config,
2950
+ progress,
2951
+ seed,
2952
+ roughness,
2953
+ maxRandomnessOffset,
2954
+ bowing,
2955
+ curveFitting,
2956
+ curveTightness,
2957
+ curveStepCount,
2958
+ disableMultiStroke,
2959
+ preserveVertices
2960
+ });
2961
+ return /* @__PURE__ */ jsx3(Sequence, {
2962
+ layout: "none",
2963
+ from: from ?? 0,
2964
+ trimBefore,
2965
+ durationInFrames: durationInFrames ?? Infinity,
2966
+ freeze,
2967
+ hidden,
2968
+ name: name ?? `<${componentName}>`,
2969
+ showInTimeline: showInTimeline ?? true,
2970
+ controls,
2971
+ _remotionInternalStack: stack,
2972
+ _remotionInternalDocumentationLink: `https://www.remotion.dev/docs/rough-notation/${documentationSlug}`,
2973
+ outlineRef,
2974
+ children: /* @__PURE__ */ jsx3("span", {
2975
+ ref: outlineRef,
2976
+ style: { display: "inline-block" },
2977
+ children: /* @__PURE__ */ jsxs2(annotation.Container, {
2978
+ children: [
2979
+ layer === "behind" ? annotationElement : null,
2980
+ /* @__PURE__ */ jsx3(annotation.Tracker, {
2981
+ style,
2982
+ children
2983
+ }),
2984
+ layer === "on-top" ? annotationElement : null
2985
+ ]
2986
+ })
2987
+ })
2988
+ });
2989
+ };
2990
+ const Component = Interactive.withSchema({
2991
+ Component: AnnotationInner,
2992
+ componentName: `<${componentName}>`,
2993
+ componentIdentity: Interactive._internalMakeRemotionComponentIdentity({
2994
+ packageName: "@remotion/rough-notation",
2995
+ componentName
2996
+ }),
2997
+ schema,
2998
+ supportsEffects: false
2999
+ });
3000
+ Component.displayName = componentName;
3001
+ return Component;
3002
+ };
3003
+ var Highlight = makeAnnotationComponent({
3004
+ type: "highlight",
3005
+ componentName: "Highlight",
3006
+ documentationSlug: "highlight",
3007
+ layer: "behind",
3008
+ schema: highlightSchema
3009
+ });
3010
+ var Underline = makeAnnotationComponent({
3011
+ type: "underline",
3012
+ componentName: "Underline",
3013
+ documentationSlug: "underline",
3014
+ layer: "on-top",
3015
+ schema: underlineSchema
3016
+ });
3017
+ var StrikeThrough = makeAnnotationComponent({
3018
+ type: "strike-through",
3019
+ componentName: "StrikeThrough",
3020
+ documentationSlug: "strike-through",
3021
+ layer: "on-top",
3022
+ schema: strikeThroughSchema
3023
+ });
3024
+ var CrossedOff = makeAnnotationComponent({
3025
+ type: "crossed-off",
3026
+ componentName: "CrossedOff",
3027
+ documentationSlug: "crossed-off",
3028
+ layer: "on-top",
3029
+ schema: crossedOffSchema
3030
+ });
3031
+ var Box = makeAnnotationComponent({
3032
+ type: "box",
3033
+ componentName: "Box",
3034
+ documentationSlug: "box",
3035
+ layer: "on-top",
3036
+ schema: boxSchema
3037
+ });
3038
+ var Bracket = makeAnnotationComponent({
3039
+ type: "bracket",
3040
+ componentName: "Bracket",
3041
+ documentationSlug: "bracket",
3042
+ layer: "on-top",
3043
+ schema: bracketSchema
3044
+ });
3045
+ var Circle = makeAnnotationComponent({
3046
+ type: "circle",
3047
+ componentName: "Circle",
3048
+ documentationSlug: "circle",
3049
+ layer: "on-top",
3050
+ schema: circleSchema
3051
+ });
3052
+ export {
3053
+ Underline,
3054
+ StrikeThrough,
3055
+ Highlight,
3056
+ CrossedOff,
3057
+ Circle,
3058
+ Bracket,
3059
+ Box
3060
+ };