@rocketium/auto-adapt 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -182,6 +182,9 @@ var isGroupJSON = (object) => {
182
182
  var isCreativeBoxJSON = (object) => {
183
183
  return object?.dataType === "CREATIVE_BOX";
184
184
  };
185
+ var isVideoJSON = (object) => {
186
+ return object?.dataType === "VIDEO";
187
+ };
185
188
  var isAudioJSON = (object) => {
186
189
  return object?.dataType === "AUDIO";
187
190
  };
@@ -453,6 +456,7 @@ var adaptTextSkew = (object, widthRatio, heightRatio, scalingRatio, closestHeigh
453
456
  height: object.height * heightRatio,
454
457
  autoFitSizes: scaleAutoFitSizes(object.autoFitSizes, scalingRatio, closestHeight),
455
458
  cornerRadius: scaleCornerRadius(object.cornerRadius, scalingRatio),
459
+ ...getScaledBorderJSON({ object, scalingRatio }),
456
460
  fontSize: object.fontSize * scalingRatio,
457
461
  wordStyle: adaptWordStyleFontSizes({ wordStyle: object.wordStyle || [], scalingRatio })
458
462
  };
@@ -467,7 +471,8 @@ var adaptImageSkew = (object, widthRatio, heightRatio, scalingRatio) => {
467
471
  imageScale: (object.imageScale ?? 1) * scalingRatio,
468
472
  imageLeft: (object.imageLeft ?? 0) * widthRatio,
469
473
  imageTop: (object.imageTop ?? 0) * heightRatio,
470
- cornerRadius: scaleCornerRadius(object.cornerRadius, scalingRatio)
474
+ cornerRadius: scaleCornerRadius(object.cornerRadius, scalingRatio),
475
+ ...getScaledBorderJSON({ object, scalingRatio })
471
476
  };
472
477
  };
473
478
  var adaptSvgSkew = (object, widthRatio, heightRatio, scalingRatio) => {
@@ -504,7 +509,7 @@ var adaptShapeSkew = (object, widthRatio, heightRatio, scalingRatio) => {
504
509
  ...getScaledBorderJSON({ object, scalingRatio })
505
510
  };
506
511
  };
507
- var adaptGroupChildText = (groupObject, scalingRatio, closestHeight, parentObject) => {
512
+ var adaptGroupChildText = (groupObject, scalingRatio, closestHeight) => {
508
513
  return {
509
514
  ...groupObject,
510
515
  left: groupObject.left * scalingRatio,
@@ -514,13 +519,13 @@ var adaptGroupChildText = (groupObject, scalingRatio, closestHeight, parentObjec
514
519
  wordSpacing: groupObject.wordSpacing ? groupObject.wordSpacing * scalingRatio : 0,
515
520
  padding: scalePadding(groupObject.padding, scalingRatio),
516
521
  cornerRadius: scaleCornerRadius(groupObject.cornerRadius, scalingRatio),
517
- ...getScaledBorderJSON({ object: parentObject, scalingRatio }),
522
+ ...getScaledBorderJSON({ object: groupObject, scalingRatio }),
518
523
  autoFitSizes: scaleAutoFitSizes(groupObject.autoFitSizes, scalingRatio, closestHeight),
519
524
  fontSize: groupObject.fontSize * scalingRatio,
520
525
  wordStyle: adaptWordStyleFontSizes({ wordStyle: groupObject.wordStyle || [], scalingRatio })
521
526
  };
522
527
  };
523
- var adaptGroupChildImage = (groupObject, scalingRatio, parentObject) => {
528
+ var adaptGroupChildImage = (groupObject, scalingRatio) => {
524
529
  return {
525
530
  ...groupObject,
526
531
  left: groupObject.left * scalingRatio,
@@ -531,10 +536,10 @@ var adaptGroupChildImage = (groupObject, scalingRatio, parentObject) => {
531
536
  imageLeft: (groupObject.imageLeft ?? 0) * scalingRatio,
532
537
  imageTop: (groupObject.imageTop ?? 0) * scalingRatio,
533
538
  cornerRadius: scaleCornerRadius(groupObject.cornerRadius, scalingRatio),
534
- ...getScaledBorderJSON({ object: parentObject, scalingRatio })
539
+ ...getScaledBorderJSON({ object: groupObject, scalingRatio })
535
540
  };
536
541
  };
537
- var adaptGroupChildSvg = (svgContainer, scalingRatio, parentObject) => {
542
+ var adaptGroupChildSvg = (svgContainer, scalingRatio) => {
538
543
  return {
539
544
  ...svgContainer,
540
545
  left: svgContainer.left * scalingRatio,
@@ -544,10 +549,10 @@ var adaptGroupChildSvg = (svgContainer, scalingRatio, parentObject) => {
544
549
  imageScale: (svgContainer.imageScale ?? 1) * scalingRatio,
545
550
  imageLeft: (svgContainer.imageLeft ?? 0) * scalingRatio,
546
551
  imageTop: (svgContainer.imageTop ?? 0) * scalingRatio,
547
- ...getScaledBorderJSON({ object: parentObject, scalingRatio })
552
+ ...getScaledBorderJSON({ object: svgContainer, scalingRatio })
548
553
  };
549
554
  };
550
- var adaptGroupChildRoundedRect = (roundedRectObject, scalingRatio, parentObject) => {
555
+ var adaptGroupChildRoundedRect = (roundedRectObject, scalingRatio) => {
551
556
  return {
552
557
  ...roundedRectObject,
553
558
  left: roundedRectObject.left * scalingRatio,
@@ -555,17 +560,17 @@ var adaptGroupChildRoundedRect = (roundedRectObject, scalingRatio, parentObject)
555
560
  width: roundedRectObject.width * scalingRatio,
556
561
  height: roundedRectObject.height * scalingRatio,
557
562
  cornerRadius: scaleCornerRadius(roundedRectObject.cornerRadius, scalingRatio),
558
- ...getScaledBorderJSON({ object: parentObject, scalingRatio })
563
+ ...getScaledBorderJSON({ object: roundedRectObject, scalingRatio })
559
564
  };
560
565
  };
561
- var adaptGroupChildShape = (groupObject, scalingRatio, parentObject) => {
566
+ var adaptGroupChildShape = (groupObject, scalingRatio) => {
562
567
  return {
563
568
  ...groupObject,
564
569
  left: num(groupObject, "left") * scalingRatio,
565
570
  top: num(groupObject, "top") * scalingRatio,
566
571
  scaleX: num(groupObject, "scaleX", 1) * scalingRatio,
567
572
  scaleY: num(groupObject, "scaleY", 1) * scalingRatio,
568
- ...getScaledBorderJSON({ object: parentObject, scalingRatio })
573
+ ...getScaledBorderJSON({ object: groupObject, scalingRatio })
569
574
  };
570
575
  };
571
576
 
@@ -658,29 +663,27 @@ var getAdaptedObjectsJSON = ({
658
663
  newObjects[groupObjectId] = adaptGroupChildText(
659
664
  groupObject,
660
665
  scalingRatio,
661
- closestHeight,
662
- object
666
+ closestHeight
663
667
  );
664
668
  continue;
665
669
  }
666
670
  if (isImageJSON(groupObject)) {
667
- newObjects[groupObjectId] = adaptGroupChildImage(groupObject, scalingRatio, object);
671
+ newObjects[groupObjectId] = adaptGroupChildImage(groupObject, scalingRatio);
668
672
  continue;
669
673
  }
670
674
  if (isShapeJSON(groupObject)) {
671
675
  if (isSVGContainerJSON(groupObject)) {
672
- newObjects[groupObjectId] = adaptGroupChildSvg(groupObject, scalingRatio, object);
676
+ newObjects[groupObjectId] = adaptGroupChildSvg(groupObject, scalingRatio);
673
677
  continue;
674
678
  }
675
679
  if (isRoundedRectJSON(groupObject)) {
676
680
  newObjects[groupObjectId] = adaptGroupChildRoundedRect(
677
681
  groupObject,
678
- scalingRatio,
679
- object
682
+ scalingRatio
680
683
  );
681
684
  continue;
682
685
  }
683
- newObjects[groupObjectId] = adaptGroupChildShape(groupObject, scalingRatio, object);
686
+ newObjects[groupObjectId] = adaptGroupChildShape(groupObject, scalingRatio);
684
687
  continue;
685
688
  }
686
689
  }
@@ -742,6 +745,60 @@ var applyAdaptedAsOverrides = (originalObjects, adaptedObjects, newSizeId) => {
742
745
  }
743
746
  return result;
744
747
  };
748
+ var LAYOUT_KEYS_COMMON = ["left", "top", "width", "height", "angle", "visible"];
749
+ var LAYOUT_KEYS_TEXT_EXTRA = ["fontSize", "autoFitSizes", "padding", "wordSpacing"];
750
+ var LAYOUT_KEYS_IMAGE_VIDEO_EXTRA = ["imageScale", "imageLeft", "imageTop", "objectFit", "imageOriginX", "imageOriginY"];
751
+ var LAYOUT_KEYS_SVG_EXTRA = ["imageScale", "imageLeft", "imageTop", "scaleX", "scaleY", "objectFit", "imageOriginX", "imageOriginY"];
752
+ var LAYOUT_KEYS_PATH = ["left", "top", "angle", "visible", "scaleX", "scaleY"];
753
+ var getLayoutKeysForElement = (element) => {
754
+ if (isCreativeBoxJSON(element) || isAudioJSON(element)) {
755
+ return [];
756
+ }
757
+ if (isTextJSON(element)) {
758
+ return [...LAYOUT_KEYS_COMMON, ...LAYOUT_KEYS_TEXT_EXTRA];
759
+ }
760
+ if (isImageJSON(element) || isVideoJSON(element)) {
761
+ return [...LAYOUT_KEYS_COMMON, ...LAYOUT_KEYS_IMAGE_VIDEO_EXTRA];
762
+ }
763
+ if (isShapeJSON(element)) {
764
+ if (isSVGContainerJSON(element)) {
765
+ return [...LAYOUT_KEYS_COMMON, ...LAYOUT_KEYS_SVG_EXTRA];
766
+ }
767
+ if (isRoundedRectJSON(element)) {
768
+ return LAYOUT_KEYS_COMMON;
769
+ }
770
+ return LAYOUT_KEYS_PATH;
771
+ }
772
+ if (isGroupJSON(element)) {
773
+ return LAYOUT_KEYS_COMMON;
774
+ }
775
+ return LAYOUT_KEYS_COMMON;
776
+ };
777
+ var mergeLayoutFromReference = (base, layoutReference) => {
778
+ if (isCreativeBoxJSON(base) || isAudioJSON(base)) {
779
+ return base;
780
+ }
781
+ const layoutKeys = getLayoutKeysForElement(base);
782
+ const merged = { ...base };
783
+ const ref = layoutReference;
784
+ for (const key of layoutKeys) {
785
+ if (ref[key] !== void 0) {
786
+ merged[key] = ref[key];
787
+ }
788
+ }
789
+ return merged;
790
+ };
791
+ var mergeLayoutFromReferenceObjects = (baseObjects, referenceObjects) => {
792
+ const merged = {};
793
+ for (const [layerId, baseObj] of Object.entries(baseObjects)) {
794
+ if (referenceObjects[layerId]) {
795
+ merged[layerId] = mergeLayoutFromReference(baseObj, referenceObjects[layerId]);
796
+ } else {
797
+ merged[layerId] = baseObj;
798
+ }
799
+ }
800
+ return merged;
801
+ };
745
802
  var buildNewCapsule = ({
746
803
  originalCapsule,
747
804
  updatedObjects,
@@ -892,6 +949,6 @@ var RULER_AXIS = {
892
949
  Y: "y"
893
950
  };
894
951
 
895
- export { AnimationSpecialCase, CANVAS_EDITOR_ELEMENT, CreativeElementCategory, RULER_AXIS, TextAnimationType, WORD_STYLE_TYPE, adaptWordStyleFontSizes, applyAdaptedAsOverrides, buildNewCapsule, checkIfElementShouldBeSkewed, findBestReferenceSize, findClosestSizeObjectsWithMatches, findClosestSizeWithMatches, generateBaseLayoutForSize, getAdaptedObjectsJSON, getAreaPercentageOfElementOnCanvasJSON, getEuclideanDistanceBetweenSizes, getNormalizedSizeValue, getScaledBorderJSON, getValuesWithoutSkewingJSON, isAudioJSON, isCreativeBoxJSON, isGroupJSON, isImageJSON, isRoundedRectJSON, isSVGContainerJSON, isShapeJSON, isTextJSON, resolveObjectsForSize, scaleAutoFitSizes, scaleCornerRadius, scalePadding };
952
+ export { AnimationSpecialCase, CANVAS_EDITOR_ELEMENT, CreativeElementCategory, RULER_AXIS, TextAnimationType, WORD_STYLE_TYPE, adaptWordStyleFontSizes, applyAdaptedAsOverrides, buildNewCapsule, checkIfElementShouldBeSkewed, findBestReferenceSize, findClosestSizeObjectsWithMatches, findClosestSizeWithMatches, generateBaseLayoutForSize, getAdaptedObjectsJSON, getAreaPercentageOfElementOnCanvasJSON, getEuclideanDistanceBetweenSizes, getNormalizedSizeValue, getScaledBorderJSON, getValuesWithoutSkewingJSON, isAudioJSON, isCreativeBoxJSON, isGroupJSON, isImageJSON, isRoundedRectJSON, isSVGContainerJSON, isShapeJSON, isTextJSON, isVideoJSON, mergeLayoutFromReference, mergeLayoutFromReferenceObjects, resolveObjectsForSize, scaleAutoFitSizes, scaleCornerRadius, scalePadding };
896
953
  //# sourceMappingURL=index.mjs.map
897
954
  //# sourceMappingURL=index.mjs.map