@remotion/svg-3d-engine 4.0.527 → 4.0.529
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.mjs +3 -736
- package/package.json +3 -3
package/dist/esm/index.mjs
CHANGED
|
@@ -258,742 +258,8 @@ var serializeThreeDReducedInstruction = (instruction) => {
|
|
|
258
258
|
throw new Error("Unknown instruction type");
|
|
259
259
|
};
|
|
260
260
|
var threeDIntoSvgPath = (instructions) => instructions.map((instruction) => serializeThreeDReducedInstruction(instruction)).join(" ");
|
|
261
|
-
// ../paths/dist/esm/index.mjs
|
|
262
|
-
var length = {
|
|
263
|
-
a: 7,
|
|
264
|
-
A: 7,
|
|
265
|
-
C: 6,
|
|
266
|
-
c: 6,
|
|
267
|
-
H: 1,
|
|
268
|
-
h: 1,
|
|
269
|
-
L: 2,
|
|
270
|
-
l: 2,
|
|
271
|
-
M: 2,
|
|
272
|
-
m: 2,
|
|
273
|
-
Q: 4,
|
|
274
|
-
q: 4,
|
|
275
|
-
S: 4,
|
|
276
|
-
s: 4,
|
|
277
|
-
T: 2,
|
|
278
|
-
t: 2,
|
|
279
|
-
V: 1,
|
|
280
|
-
v: 1,
|
|
281
|
-
Z: 0,
|
|
282
|
-
z: 0
|
|
283
|
-
};
|
|
284
|
-
var chunkExact = (array, instruction) => {
|
|
285
|
-
const chunks = [];
|
|
286
|
-
const expectedSize = length[instruction];
|
|
287
|
-
if (array.length % expectedSize !== 0) {
|
|
288
|
-
throw new Error(`Expected number of arguments of SVG instruction "${instruction} ${array.join(" ")}" to be a multiple of ${expectedSize}`);
|
|
289
|
-
}
|
|
290
|
-
for (let i = 0;i < array.length; i += expectedSize) {
|
|
291
|
-
chunks.push(array.slice(i, i + expectedSize));
|
|
292
|
-
}
|
|
293
|
-
return chunks;
|
|
294
|
-
};
|
|
295
|
-
var makeInstructions = (arr, instruction, cb) => {
|
|
296
|
-
return chunkExact(arr, instruction).map((args) => {
|
|
297
|
-
return cb(args);
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
var segmentRegExp = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
|
|
301
|
-
var numberRegExp = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
|
|
302
|
-
var parseValues = (args, instructionType) => {
|
|
303
|
-
const numbers = args.match(numberRegExp);
|
|
304
|
-
if (!numbers) {
|
|
305
|
-
if (instructionType === "Z" || instructionType === "z") {
|
|
306
|
-
return [];
|
|
307
|
-
}
|
|
308
|
-
throw new Error(`Malformed path data: ${instructionType} was expected to have numbers afterwards`);
|
|
309
|
-
}
|
|
310
|
-
const expectedArguments = length[instructionType];
|
|
311
|
-
if (numbers.length % expectedArguments !== 0) {
|
|
312
|
-
throw new Error(`Malformed path data: ${instructionType} was expected to have a multiple of ${expectedArguments} numbers, but got "${instructionType} ${numbers.join(" ")} instead"`);
|
|
313
|
-
}
|
|
314
|
-
return numbers.map(Number);
|
|
315
|
-
};
|
|
316
|
-
var parsePath = (path) => {
|
|
317
|
-
if (!path) {
|
|
318
|
-
throw new Error("No path provided");
|
|
319
|
-
}
|
|
320
|
-
const segments = path.match(segmentRegExp);
|
|
321
|
-
if (!segments) {
|
|
322
|
-
throw new Error(`No path elements found in string ${path}`);
|
|
323
|
-
}
|
|
324
|
-
return segments.map((segmentString) => {
|
|
325
|
-
const command = segmentString.charAt(0);
|
|
326
|
-
const args = parseValues(segmentString.substring(1), command);
|
|
327
|
-
if (command === "M" && args.length > 2) {
|
|
328
|
-
const segmentsArray = [];
|
|
329
|
-
segmentsArray.push({
|
|
330
|
-
type: command,
|
|
331
|
-
x: args[0],
|
|
332
|
-
y: args[1]
|
|
333
|
-
});
|
|
334
|
-
segmentsArray.push(...makeInstructions(args.slice(2), "L", (numbers) => ({
|
|
335
|
-
type: "L",
|
|
336
|
-
x: numbers[0],
|
|
337
|
-
y: numbers[1]
|
|
338
|
-
})));
|
|
339
|
-
return segmentsArray;
|
|
340
|
-
}
|
|
341
|
-
if (command === "m" && args.length > 2) {
|
|
342
|
-
const segmentsArray = [];
|
|
343
|
-
segmentsArray.push({
|
|
344
|
-
type: command,
|
|
345
|
-
dx: args[0],
|
|
346
|
-
dy: args[1]
|
|
347
|
-
});
|
|
348
|
-
segmentsArray.push(...makeInstructions(args.slice(2), "l", (numbers) => ({
|
|
349
|
-
type: "l",
|
|
350
|
-
dx: numbers[0],
|
|
351
|
-
dy: numbers[1]
|
|
352
|
-
})));
|
|
353
|
-
return segmentsArray;
|
|
354
|
-
}
|
|
355
|
-
if (command === "Z" || command === "z") {
|
|
356
|
-
return [
|
|
357
|
-
{
|
|
358
|
-
type: "Z"
|
|
359
|
-
}
|
|
360
|
-
];
|
|
361
|
-
}
|
|
362
|
-
if (command === "A") {
|
|
363
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
364
|
-
type: command,
|
|
365
|
-
rx: numbers[0],
|
|
366
|
-
ry: numbers[1],
|
|
367
|
-
xAxisRotation: numbers[2],
|
|
368
|
-
largeArcFlag: numbers[3] === 1,
|
|
369
|
-
sweepFlag: numbers[4] === 1,
|
|
370
|
-
x: numbers[5],
|
|
371
|
-
y: numbers[6]
|
|
372
|
-
}));
|
|
373
|
-
}
|
|
374
|
-
if (command === "a") {
|
|
375
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
376
|
-
type: command,
|
|
377
|
-
rx: numbers[0],
|
|
378
|
-
ry: numbers[1],
|
|
379
|
-
xAxisRotation: numbers[2],
|
|
380
|
-
largeArcFlag: numbers[3] === 1,
|
|
381
|
-
sweepFlag: numbers[4] === 1,
|
|
382
|
-
dx: numbers[5],
|
|
383
|
-
dy: numbers[6]
|
|
384
|
-
}));
|
|
385
|
-
}
|
|
386
|
-
if (command === "C") {
|
|
387
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
388
|
-
type: command,
|
|
389
|
-
cp1x: numbers[0],
|
|
390
|
-
cp1y: numbers[1],
|
|
391
|
-
cp2x: numbers[2],
|
|
392
|
-
cp2y: numbers[3],
|
|
393
|
-
x: numbers[4],
|
|
394
|
-
y: numbers[5]
|
|
395
|
-
}));
|
|
396
|
-
}
|
|
397
|
-
if (command === "c") {
|
|
398
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
399
|
-
type: command,
|
|
400
|
-
cp1dx: numbers[0],
|
|
401
|
-
cp1dy: numbers[1],
|
|
402
|
-
cp2dx: numbers[2],
|
|
403
|
-
cp2dy: numbers[3],
|
|
404
|
-
dx: numbers[4],
|
|
405
|
-
dy: numbers[5]
|
|
406
|
-
}));
|
|
407
|
-
}
|
|
408
|
-
if (command === "S") {
|
|
409
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
410
|
-
type: command,
|
|
411
|
-
cpx: numbers[0],
|
|
412
|
-
cpy: numbers[1],
|
|
413
|
-
x: numbers[2],
|
|
414
|
-
y: numbers[3]
|
|
415
|
-
}));
|
|
416
|
-
}
|
|
417
|
-
if (command === "s") {
|
|
418
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
419
|
-
type: command,
|
|
420
|
-
cpdx: numbers[0],
|
|
421
|
-
cpdy: numbers[1],
|
|
422
|
-
dx: numbers[2],
|
|
423
|
-
dy: numbers[3]
|
|
424
|
-
}));
|
|
425
|
-
}
|
|
426
|
-
if (command === "H") {
|
|
427
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
428
|
-
type: command,
|
|
429
|
-
x: numbers[0]
|
|
430
|
-
}));
|
|
431
|
-
}
|
|
432
|
-
if (command === "h") {
|
|
433
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
434
|
-
type: command,
|
|
435
|
-
dx: numbers[0]
|
|
436
|
-
}));
|
|
437
|
-
}
|
|
438
|
-
if (command === "V") {
|
|
439
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
440
|
-
type: command,
|
|
441
|
-
y: numbers[0]
|
|
442
|
-
}));
|
|
443
|
-
}
|
|
444
|
-
if (command === "v") {
|
|
445
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
446
|
-
type: command,
|
|
447
|
-
dy: numbers[0]
|
|
448
|
-
}));
|
|
449
|
-
}
|
|
450
|
-
if (command === "L") {
|
|
451
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
452
|
-
type: command,
|
|
453
|
-
x: numbers[0],
|
|
454
|
-
y: numbers[1]
|
|
455
|
-
}));
|
|
456
|
-
}
|
|
457
|
-
if (command === "M") {
|
|
458
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
459
|
-
type: command,
|
|
460
|
-
x: numbers[0],
|
|
461
|
-
y: numbers[1]
|
|
462
|
-
}));
|
|
463
|
-
}
|
|
464
|
-
if (command === "m") {
|
|
465
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
466
|
-
type: command,
|
|
467
|
-
dx: numbers[0],
|
|
468
|
-
dy: numbers[1]
|
|
469
|
-
}));
|
|
470
|
-
}
|
|
471
|
-
if (command === "l") {
|
|
472
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
473
|
-
type: command,
|
|
474
|
-
dx: numbers[0],
|
|
475
|
-
dy: numbers[1]
|
|
476
|
-
}));
|
|
477
|
-
}
|
|
478
|
-
if (command === "Q") {
|
|
479
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
480
|
-
type: command,
|
|
481
|
-
cpx: numbers[0],
|
|
482
|
-
cpy: numbers[1],
|
|
483
|
-
x: numbers[2],
|
|
484
|
-
y: numbers[3]
|
|
485
|
-
}));
|
|
486
|
-
}
|
|
487
|
-
if (command === "q") {
|
|
488
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
489
|
-
type: command,
|
|
490
|
-
cpdx: numbers[0],
|
|
491
|
-
cpdy: numbers[1],
|
|
492
|
-
dx: numbers[2],
|
|
493
|
-
dy: numbers[3]
|
|
494
|
-
}));
|
|
495
|
-
}
|
|
496
|
-
if (command === "T") {
|
|
497
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
498
|
-
type: command,
|
|
499
|
-
x: numbers[0],
|
|
500
|
-
y: numbers[1]
|
|
501
|
-
}));
|
|
502
|
-
}
|
|
503
|
-
if (command === "t") {
|
|
504
|
-
return makeInstructions(args, command, (numbers) => ({
|
|
505
|
-
type: command,
|
|
506
|
-
dx: numbers[0],
|
|
507
|
-
dy: numbers[1]
|
|
508
|
-
}));
|
|
509
|
-
}
|
|
510
|
-
throw new Error(`Invalid path element ${segmentString}`);
|
|
511
|
-
}, []).flat(1);
|
|
512
|
-
};
|
|
513
|
-
var convertQToCInstruction = (instruction, startPoint) => {
|
|
514
|
-
const cp1x = startPoint.x + 2 / 3 * (instruction.cpx - startPoint.x);
|
|
515
|
-
const cp1y = startPoint.y + 2 / 3 * (instruction.cpy - startPoint.y);
|
|
516
|
-
const cp2x = instruction.x + 2 / 3 * (instruction.cpx - instruction.x);
|
|
517
|
-
const cp2y = instruction.y + 2 / 3 * (instruction.cpy - instruction.y);
|
|
518
|
-
return {
|
|
519
|
-
type: "C",
|
|
520
|
-
cp1x,
|
|
521
|
-
cp1y,
|
|
522
|
-
cp2x,
|
|
523
|
-
cp2y,
|
|
524
|
-
x: instruction.x,
|
|
525
|
-
y: instruction.y
|
|
526
|
-
};
|
|
527
|
-
};
|
|
528
|
-
var iterateOverSegments = ({
|
|
529
|
-
segments,
|
|
530
|
-
iterate
|
|
531
|
-
}) => {
|
|
532
|
-
let x = 0;
|
|
533
|
-
let y = 0;
|
|
534
|
-
let initialX = 0;
|
|
535
|
-
let initialY = 0;
|
|
536
|
-
let cpX = null;
|
|
537
|
-
let cpY = null;
|
|
538
|
-
const newSegments = segments.map((s, i) => {
|
|
539
|
-
const newSeg = iterate({
|
|
540
|
-
segment: s,
|
|
541
|
-
x,
|
|
542
|
-
y,
|
|
543
|
-
prevSegment: segments[i - 1] ?? null,
|
|
544
|
-
initialX,
|
|
545
|
-
initialY,
|
|
546
|
-
cpX,
|
|
547
|
-
cpY
|
|
548
|
-
});
|
|
549
|
-
switch (s.type) {
|
|
550
|
-
case "M":
|
|
551
|
-
initialX = s.x;
|
|
552
|
-
initialY = s.y;
|
|
553
|
-
x = s.x;
|
|
554
|
-
y = s.y;
|
|
555
|
-
cpX = null;
|
|
556
|
-
cpY = null;
|
|
557
|
-
break;
|
|
558
|
-
case "Q":
|
|
559
|
-
x = s.x;
|
|
560
|
-
y = s.y;
|
|
561
|
-
cpX = s.cpx;
|
|
562
|
-
cpY = s.cpy;
|
|
563
|
-
break;
|
|
564
|
-
case "A":
|
|
565
|
-
x = s.x;
|
|
566
|
-
y = s.y;
|
|
567
|
-
cpX = null;
|
|
568
|
-
cpY = null;
|
|
569
|
-
break;
|
|
570
|
-
case "C":
|
|
571
|
-
x = s.x;
|
|
572
|
-
y = s.y;
|
|
573
|
-
cpX = s.cp2x;
|
|
574
|
-
cpY = s.cp2y;
|
|
575
|
-
break;
|
|
576
|
-
case "S":
|
|
577
|
-
x = s.x;
|
|
578
|
-
y = s.y;
|
|
579
|
-
cpX = s.cpx;
|
|
580
|
-
cpY = s.cpy;
|
|
581
|
-
break;
|
|
582
|
-
case "T":
|
|
583
|
-
if (cpX !== null && cpY !== null) {
|
|
584
|
-
cpX = x - (cpX - x);
|
|
585
|
-
cpY = y - (cpY - y);
|
|
586
|
-
}
|
|
587
|
-
x = s.x;
|
|
588
|
-
y = s.y;
|
|
589
|
-
break;
|
|
590
|
-
case "L":
|
|
591
|
-
x = s.x;
|
|
592
|
-
y = s.y;
|
|
593
|
-
cpX = null;
|
|
594
|
-
cpY = null;
|
|
595
|
-
break;
|
|
596
|
-
case "V":
|
|
597
|
-
y = s.y;
|
|
598
|
-
cpX = null;
|
|
599
|
-
cpY = null;
|
|
600
|
-
break;
|
|
601
|
-
case "H":
|
|
602
|
-
x = s.x;
|
|
603
|
-
cpX = null;
|
|
604
|
-
cpY = null;
|
|
605
|
-
break;
|
|
606
|
-
case "Z":
|
|
607
|
-
x = initialX;
|
|
608
|
-
y = initialY;
|
|
609
|
-
cpX = null;
|
|
610
|
-
cpY = null;
|
|
611
|
-
break;
|
|
612
|
-
default:
|
|
613
|
-
throw new Error(`Unexpected instruction ${s.type}`);
|
|
614
|
-
}
|
|
615
|
-
return newSeg;
|
|
616
|
-
});
|
|
617
|
-
return newSegments.flat(1);
|
|
618
|
-
};
|
|
619
|
-
var TAU = Math.PI * 2;
|
|
620
|
-
function approximate_unit_arc(theta1, delta_theta) {
|
|
621
|
-
const alpha = 4 / 3 * Math.tan(delta_theta / 4);
|
|
622
|
-
const x1 = Math.cos(theta1);
|
|
623
|
-
const y1 = Math.sin(theta1);
|
|
624
|
-
const x2 = Math.cos(theta1 + delta_theta);
|
|
625
|
-
const y2 = Math.sin(theta1 + delta_theta);
|
|
626
|
-
return [
|
|
627
|
-
x1,
|
|
628
|
-
y1,
|
|
629
|
-
x1 - y1 * alpha,
|
|
630
|
-
y1 + x1 * alpha,
|
|
631
|
-
x2 + y2 * alpha,
|
|
632
|
-
y2 - x2 * alpha,
|
|
633
|
-
x2,
|
|
634
|
-
y2
|
|
635
|
-
];
|
|
636
|
-
}
|
|
637
|
-
function unit_vector_angle(ux, uy, vx, vy) {
|
|
638
|
-
const sign = ux * vy - uy * vx < 0 ? -1 : 1;
|
|
639
|
-
let dot2 = ux * vx + uy * vy;
|
|
640
|
-
if (dot2 > 1) {
|
|
641
|
-
dot2 = 1;
|
|
642
|
-
}
|
|
643
|
-
if (dot2 < -1) {
|
|
644
|
-
dot2 = -1;
|
|
645
|
-
}
|
|
646
|
-
return sign * Math.acos(dot2);
|
|
647
|
-
}
|
|
648
|
-
function get_arc_center({
|
|
649
|
-
x1,
|
|
650
|
-
y1,
|
|
651
|
-
x2,
|
|
652
|
-
y2,
|
|
653
|
-
largeArcFlag,
|
|
654
|
-
sweepFlag,
|
|
655
|
-
rx,
|
|
656
|
-
ry,
|
|
657
|
-
sin_phi,
|
|
658
|
-
cos_phi
|
|
659
|
-
}) {
|
|
660
|
-
const x1p = cos_phi * (x1 - x2) / 2 + sin_phi * (y1 - y2) / 2;
|
|
661
|
-
const y1p = -sin_phi * (x1 - x2) / 2 + cos_phi * (y1 - y2) / 2;
|
|
662
|
-
const rx_sq = rx * rx;
|
|
663
|
-
const ry_sq = ry * ry;
|
|
664
|
-
const x1p_sq = x1p * x1p;
|
|
665
|
-
const y1p_sq = y1p * y1p;
|
|
666
|
-
let radicant = rx_sq * ry_sq - rx_sq * y1p_sq - ry_sq * x1p_sq;
|
|
667
|
-
if (radicant < 0) {
|
|
668
|
-
radicant = 0;
|
|
669
|
-
}
|
|
670
|
-
radicant /= rx_sq * y1p_sq + ry_sq * x1p_sq;
|
|
671
|
-
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
|
|
672
|
-
const cxp = radicant * rx / ry * y1p;
|
|
673
|
-
const cyp = radicant * -ry / rx * x1p;
|
|
674
|
-
const cx = cos_phi * cxp - sin_phi * cyp + (x1 + x2) / 2;
|
|
675
|
-
const cy = sin_phi * cxp + cos_phi * cyp + (y1 + y2) / 2;
|
|
676
|
-
const v1x = (x1p - cxp) / rx;
|
|
677
|
-
const v1y = (y1p - cyp) / ry;
|
|
678
|
-
const v2x = (-x1p - cxp) / rx;
|
|
679
|
-
const v2y = (-y1p - cyp) / ry;
|
|
680
|
-
const theta1 = unit_vector_angle(1, 0, v1x, v1y);
|
|
681
|
-
let delta_theta = unit_vector_angle(v1x, v1y, v2x, v2y);
|
|
682
|
-
if (sweepFlag === false && delta_theta > 0) {
|
|
683
|
-
delta_theta -= TAU;
|
|
684
|
-
}
|
|
685
|
-
if (sweepFlag === true && delta_theta < 0) {
|
|
686
|
-
delta_theta += TAU;
|
|
687
|
-
}
|
|
688
|
-
return [cx, cy, theta1, delta_theta];
|
|
689
|
-
}
|
|
690
|
-
function arcToCircle({
|
|
691
|
-
x1,
|
|
692
|
-
y1,
|
|
693
|
-
x2,
|
|
694
|
-
y2,
|
|
695
|
-
largeArcFlag,
|
|
696
|
-
sweepFlag,
|
|
697
|
-
rx,
|
|
698
|
-
ry,
|
|
699
|
-
phi
|
|
700
|
-
}) {
|
|
701
|
-
const sin_phi = Math.sin(phi * TAU / 360);
|
|
702
|
-
const cos_phi = Math.cos(phi * TAU / 360);
|
|
703
|
-
const x1p = cos_phi * (x1 - x2) / 2 + sin_phi * (y1 - y2) / 2;
|
|
704
|
-
const y1p = -sin_phi * (x1 - x2) / 2 + cos_phi * (y1 - y2) / 2;
|
|
705
|
-
if (x1p === 0 && y1p === 0) {
|
|
706
|
-
return [];
|
|
707
|
-
}
|
|
708
|
-
if (rx === 0 || ry === 0) {
|
|
709
|
-
return [];
|
|
710
|
-
}
|
|
711
|
-
rx = Math.abs(rx);
|
|
712
|
-
ry = Math.abs(ry);
|
|
713
|
-
const lambda = x1p * x1p / (rx * rx) + y1p * y1p / (ry * ry);
|
|
714
|
-
if (lambda > 1) {
|
|
715
|
-
rx *= Math.sqrt(lambda);
|
|
716
|
-
ry *= Math.sqrt(lambda);
|
|
717
|
-
}
|
|
718
|
-
const cc = get_arc_center({
|
|
719
|
-
x1,
|
|
720
|
-
y1,
|
|
721
|
-
x2,
|
|
722
|
-
y2,
|
|
723
|
-
largeArcFlag,
|
|
724
|
-
sweepFlag,
|
|
725
|
-
rx,
|
|
726
|
-
ry,
|
|
727
|
-
sin_phi,
|
|
728
|
-
cos_phi
|
|
729
|
-
});
|
|
730
|
-
const result = [];
|
|
731
|
-
let theta1 = cc[2];
|
|
732
|
-
let delta_theta = cc[3];
|
|
733
|
-
const segments = Math.max(Math.ceil(Math.abs(delta_theta) / (TAU / 4)), 1);
|
|
734
|
-
delta_theta /= segments;
|
|
735
|
-
for (let i = 0;i < segments; i++) {
|
|
736
|
-
result.push(approximate_unit_arc(theta1, delta_theta));
|
|
737
|
-
theta1 += delta_theta;
|
|
738
|
-
}
|
|
739
|
-
return result.map((curve) => {
|
|
740
|
-
for (let i = 0;i < curve.length; i += 2) {
|
|
741
|
-
let x = curve[i + 0];
|
|
742
|
-
let y = curve[i + 1];
|
|
743
|
-
x *= rx;
|
|
744
|
-
y *= ry;
|
|
745
|
-
const xp = cos_phi * x - sin_phi * y;
|
|
746
|
-
const yp = sin_phi * x + cos_phi * y;
|
|
747
|
-
curve[i + 0] = xp + cc[0];
|
|
748
|
-
curve[i + 1] = yp + cc[1];
|
|
749
|
-
}
|
|
750
|
-
return curve;
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
var removeATSHVQInstructions = (segments) => {
|
|
754
|
-
return iterateOverSegments({
|
|
755
|
-
segments,
|
|
756
|
-
iterate: ({ segment, prevSegment, x, y, cpX, cpY }) => {
|
|
757
|
-
if (segment.type === "H") {
|
|
758
|
-
return [{ type: "L", x: segment.x, y }];
|
|
759
|
-
}
|
|
760
|
-
if (segment.type === "V") {
|
|
761
|
-
return [{ type: "L", x, y: segment.y }];
|
|
762
|
-
}
|
|
763
|
-
if (segment.type === "A") {
|
|
764
|
-
const nextX = segment.x;
|
|
765
|
-
const nextY = segment.y;
|
|
766
|
-
const new_segments = arcToCircle({
|
|
767
|
-
x1: x,
|
|
768
|
-
y1: y,
|
|
769
|
-
x2: nextX,
|
|
770
|
-
y2: nextY,
|
|
771
|
-
largeArcFlag: segment.largeArcFlag,
|
|
772
|
-
sweepFlag: segment.sweepFlag,
|
|
773
|
-
rx: segment.rx,
|
|
774
|
-
ry: segment.ry,
|
|
775
|
-
phi: segment.xAxisRotation
|
|
776
|
-
});
|
|
777
|
-
if (new_segments.length === 0) {
|
|
778
|
-
return [
|
|
779
|
-
{
|
|
780
|
-
type: "L",
|
|
781
|
-
x: segment.x,
|
|
782
|
-
y: segment.y
|
|
783
|
-
}
|
|
784
|
-
];
|
|
785
|
-
}
|
|
786
|
-
const result = new_segments.map((_s) => {
|
|
787
|
-
return {
|
|
788
|
-
type: "C",
|
|
789
|
-
cp1x: _s[2],
|
|
790
|
-
cp1y: _s[3],
|
|
791
|
-
cp2x: _s[4],
|
|
792
|
-
cp2y: _s[5],
|
|
793
|
-
x: _s[6],
|
|
794
|
-
y: _s[7]
|
|
795
|
-
};
|
|
796
|
-
});
|
|
797
|
-
return result;
|
|
798
|
-
}
|
|
799
|
-
if (segment.type === "T") {
|
|
800
|
-
let prevControlX = 0;
|
|
801
|
-
let prevControlY = 0;
|
|
802
|
-
if (prevSegment && (prevSegment.type === "Q" || prevSegment.type === "T")) {
|
|
803
|
-
prevControlX = cpX;
|
|
804
|
-
prevControlY = cpY;
|
|
805
|
-
} else {
|
|
806
|
-
prevControlX = x;
|
|
807
|
-
prevControlY = y;
|
|
808
|
-
}
|
|
809
|
-
const vectorX = prevControlX - x;
|
|
810
|
-
const vectorY = prevControlY - y;
|
|
811
|
-
const newControlX = x - vectorX;
|
|
812
|
-
const newControlY = y - vectorY;
|
|
813
|
-
return [
|
|
814
|
-
convertQToCInstruction({
|
|
815
|
-
type: "Q",
|
|
816
|
-
cpx: newControlX,
|
|
817
|
-
cpy: newControlY,
|
|
818
|
-
x: segment.x,
|
|
819
|
-
y: segment.y
|
|
820
|
-
}, { x, y })
|
|
821
|
-
];
|
|
822
|
-
}
|
|
823
|
-
if (segment.type === "S") {
|
|
824
|
-
let prevControlX = 0;
|
|
825
|
-
let prevControlY = 0;
|
|
826
|
-
if (prevSegment && prevSegment.type === "C") {
|
|
827
|
-
prevControlX = prevSegment.cp2x;
|
|
828
|
-
prevControlY = prevSegment.cp2y;
|
|
829
|
-
} else if (prevSegment && prevSegment.type === "S") {
|
|
830
|
-
prevControlX = prevSegment.cpx;
|
|
831
|
-
prevControlY = prevSegment.cpy;
|
|
832
|
-
} else {
|
|
833
|
-
prevControlX = x;
|
|
834
|
-
prevControlY = y;
|
|
835
|
-
}
|
|
836
|
-
const vectorX = prevControlX - x;
|
|
837
|
-
const vectorY = prevControlY - y;
|
|
838
|
-
const newControlX = x - vectorX;
|
|
839
|
-
const newControlY = y - vectorY;
|
|
840
|
-
return [
|
|
841
|
-
{
|
|
842
|
-
type: "C",
|
|
843
|
-
cp1x: newControlX,
|
|
844
|
-
cp1y: newControlY,
|
|
845
|
-
cp2x: segment.cpx,
|
|
846
|
-
cp2y: segment.cpy,
|
|
847
|
-
x: segment.x,
|
|
848
|
-
y: segment.y
|
|
849
|
-
}
|
|
850
|
-
];
|
|
851
|
-
}
|
|
852
|
-
if (segment.type === "Q") {
|
|
853
|
-
return [convertQToCInstruction(segment, { x, y })];
|
|
854
|
-
}
|
|
855
|
-
return [segment];
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
};
|
|
859
|
-
var normalizeInstructions = (instructions) => {
|
|
860
|
-
const normalized = [];
|
|
861
|
-
let x = 0;
|
|
862
|
-
let y = 0;
|
|
863
|
-
let moveX = 0;
|
|
864
|
-
let moveY = 0;
|
|
865
|
-
for (let i = 0;i < instructions.length; i++) {
|
|
866
|
-
const instruction = instructions[i];
|
|
867
|
-
if (instruction.type === "M") {
|
|
868
|
-
moveX = instruction.x;
|
|
869
|
-
moveY = instruction.y;
|
|
870
|
-
} else if (instruction.type === "m") {
|
|
871
|
-
moveX += instruction.dx;
|
|
872
|
-
moveY += instruction.dy;
|
|
873
|
-
}
|
|
874
|
-
if (instruction.type === "A" || instruction.type === "C" || instruction.type === "L" || instruction.type === "M" || instruction.type === "Q" || instruction.type === "S" || instruction.type === "T") {
|
|
875
|
-
normalized.push(instruction);
|
|
876
|
-
x = instruction.x;
|
|
877
|
-
y = instruction.y;
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
if (instruction.type === "a" || instruction.type === "c" || instruction.type === "l" || instruction.type === "m" || instruction.type === "q" || instruction.type === "s" || instruction.type === "t") {
|
|
881
|
-
const currentX = x;
|
|
882
|
-
const currentY = y;
|
|
883
|
-
x += instruction.dx;
|
|
884
|
-
y += instruction.dy;
|
|
885
|
-
if (instruction.type === "a") {
|
|
886
|
-
normalized.push({
|
|
887
|
-
type: "A",
|
|
888
|
-
largeArcFlag: instruction.largeArcFlag,
|
|
889
|
-
rx: instruction.rx,
|
|
890
|
-
ry: instruction.ry,
|
|
891
|
-
sweepFlag: instruction.sweepFlag,
|
|
892
|
-
xAxisRotation: instruction.xAxisRotation,
|
|
893
|
-
x,
|
|
894
|
-
y
|
|
895
|
-
});
|
|
896
|
-
continue;
|
|
897
|
-
}
|
|
898
|
-
if (instruction.type === "c") {
|
|
899
|
-
normalized.push({
|
|
900
|
-
type: "C",
|
|
901
|
-
cp1x: instruction.cp1dx + currentX,
|
|
902
|
-
cp1y: instruction.cp1dy + currentY,
|
|
903
|
-
cp2x: instruction.cp2dx + currentX,
|
|
904
|
-
cp2y: instruction.cp2dy + currentY,
|
|
905
|
-
x,
|
|
906
|
-
y
|
|
907
|
-
});
|
|
908
|
-
continue;
|
|
909
|
-
}
|
|
910
|
-
if (instruction.type === "l") {
|
|
911
|
-
normalized.push({
|
|
912
|
-
type: "L",
|
|
913
|
-
x,
|
|
914
|
-
y
|
|
915
|
-
});
|
|
916
|
-
continue;
|
|
917
|
-
}
|
|
918
|
-
if (instruction.type === "m") {
|
|
919
|
-
normalized.push({
|
|
920
|
-
type: "M",
|
|
921
|
-
x,
|
|
922
|
-
y
|
|
923
|
-
});
|
|
924
|
-
continue;
|
|
925
|
-
}
|
|
926
|
-
if (instruction.type === "q") {
|
|
927
|
-
normalized.push({
|
|
928
|
-
type: "Q",
|
|
929
|
-
cpx: instruction.cpdx + currentX,
|
|
930
|
-
cpy: instruction.cpdy + currentY,
|
|
931
|
-
x,
|
|
932
|
-
y
|
|
933
|
-
});
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
if (instruction.type === "s") {
|
|
937
|
-
normalized.push({
|
|
938
|
-
type: "S",
|
|
939
|
-
cpx: instruction.cpdx + currentX,
|
|
940
|
-
cpy: instruction.cpdy + currentY,
|
|
941
|
-
x,
|
|
942
|
-
y
|
|
943
|
-
});
|
|
944
|
-
continue;
|
|
945
|
-
}
|
|
946
|
-
if (instruction.type === "t") {
|
|
947
|
-
normalized.push({
|
|
948
|
-
type: "T",
|
|
949
|
-
x,
|
|
950
|
-
y
|
|
951
|
-
});
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
if (instruction.type === "H") {
|
|
956
|
-
normalized.push(instruction);
|
|
957
|
-
x = instruction.x;
|
|
958
|
-
continue;
|
|
959
|
-
}
|
|
960
|
-
if (instruction.type === "V") {
|
|
961
|
-
normalized.push(instruction);
|
|
962
|
-
y = instruction.y;
|
|
963
|
-
continue;
|
|
964
|
-
}
|
|
965
|
-
if (instruction.type === "Z") {
|
|
966
|
-
normalized.push(instruction);
|
|
967
|
-
x = moveX;
|
|
968
|
-
y = moveY;
|
|
969
|
-
continue;
|
|
970
|
-
}
|
|
971
|
-
if (instruction.type === "h") {
|
|
972
|
-
x += instruction.dx;
|
|
973
|
-
normalized.push({
|
|
974
|
-
type: "H",
|
|
975
|
-
x
|
|
976
|
-
});
|
|
977
|
-
continue;
|
|
978
|
-
}
|
|
979
|
-
if (instruction.type === "v") {
|
|
980
|
-
y += instruction.dy;
|
|
981
|
-
normalized.push({
|
|
982
|
-
type: "V",
|
|
983
|
-
y
|
|
984
|
-
});
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
987
|
-
throw new Error("Unknown instruction type: " + instruction.type);
|
|
988
|
-
}
|
|
989
|
-
return normalized;
|
|
990
|
-
};
|
|
991
|
-
var reduceInstructions = (instruction) => {
|
|
992
|
-
const simplified = normalizeInstructions(instruction);
|
|
993
|
-
return removeATSHVQInstructions(simplified);
|
|
994
|
-
};
|
|
995
|
-
|
|
996
261
|
// src/fix-z.ts
|
|
262
|
+
import { reduceInstructions } from "@remotion/paths";
|
|
997
263
|
var turnInto3D = (instructions) => {
|
|
998
264
|
let lastMove = [0, 0, 0, 1];
|
|
999
265
|
const newInstructions = [];
|
|
@@ -1031,6 +297,7 @@ var turnInto3D = (instructions) => {
|
|
|
1031
297
|
};
|
|
1032
298
|
|
|
1033
299
|
// src/map-face.ts
|
|
300
|
+
import { parsePath, reduceInstructions as reduceInstructions2 } from "@remotion/paths";
|
|
1034
301
|
var translateSvgInstruction = (instruction, x, y, z) => {
|
|
1035
302
|
if (instruction.type === "M") {
|
|
1036
303
|
return {
|
|
@@ -1112,7 +379,7 @@ var transformPath = ({
|
|
|
1112
379
|
transformation
|
|
1113
380
|
}) => {
|
|
1114
381
|
const parsed = parsePath(path);
|
|
1115
|
-
const reduced =
|
|
382
|
+
const reduced = reduceInstructions2(parsed);
|
|
1116
383
|
const threeD = turnInto3D(reduced);
|
|
1117
384
|
return threeDIntoSvgPath(threeD.map((p) => {
|
|
1118
385
|
return multiplyMatrixAndSvgInstruction(transformation, p);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/svg-3d-engine",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@remotion/paths": "4.0.
|
|
4
|
+
"@remotion/paths": "4.0.529"
|
|
5
5
|
},
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
7
|
+
"@remotion/eslint-config-internal": "4.0.529",
|
|
8
8
|
"eslint": "9.19.0",
|
|
9
9
|
"@typescript/native-preview": "7.0.0-dev.20260217.1"
|
|
10
10
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"require": "./dist/cjs/index.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
-
"version": "4.0.
|
|
27
|
+
"version": "4.0.529",
|
|
28
28
|
"repository": {
|
|
29
29
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/svg-3d-engine"
|
|
30
30
|
},
|