@bwp-web/canvas 1.1.0 → 1.1.2

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.js CHANGED
@@ -2756,14 +2756,17 @@ function useEditCanvas(options) {
2756
2756
  });
2757
2757
  setObjects(loaded);
2758
2758
  } finally {
2759
- isInitialLoadRef.current = false;
2760
2759
  setIsLoading(false);
2761
2760
  }
2762
2761
  }
2763
2762
  })();
2764
2763
  initPromise.then(async () => {
2765
- const onReadyResult = opts?.onReady?.(canvas);
2766
- await Promise.resolve(onReadyResult);
2764
+ try {
2765
+ const onReadyResult = opts?.onReady?.(canvas);
2766
+ await Promise.resolve(onReadyResult);
2767
+ } finally {
2768
+ isInitialLoadRef.current = false;
2769
+ }
2767
2770
  if (opts?.invertBackground !== void 0) {
2768
2771
  setBackgroundInverted(canvas, opts.invertBackground);
2769
2772
  }
@@ -3522,7 +3525,7 @@ function ObjectOverlay({
3522
3525
  const canvasRef = canvasRefProp ?? contextCanvasRef;
3523
3526
  const insideContainer = useIsInsideOverlayContainer();
3524
3527
  const stackRef = useRef8(null);
3525
- const prev = useRef8({ transform: "", w: "", h: "" });
3528
+ const prev = useRef8({ transform: "", w: "", h: "", z: "" });
3526
3529
  useEffect8(() => {
3527
3530
  const canvas = canvasRef?.current;
3528
3531
  if (!canvas || !object) return;
@@ -3553,6 +3556,11 @@ function ObjectOverlay({
3553
3556
  el.style.transform = transform;
3554
3557
  prev.current.transform = transform;
3555
3558
  }
3559
+ const z = String(zoom);
3560
+ if (prev.current.z !== z) {
3561
+ el.style.setProperty("--overlay-zoom", z);
3562
+ prev.current.z = z;
3563
+ }
3556
3564
  const w = `${screenWidth}px`;
3557
3565
  const h = `${screenHeight}px`;
3558
3566
  if (prev.current.w !== w || prev.current.h !== h) {
@@ -3572,7 +3580,7 @@ function ObjectOverlay({
3572
3580
  object.off("moving", update);
3573
3581
  object.off("scaling", update);
3574
3582
  object.off("rotating", update);
3575
- prev.current = { transform: "", w: "", h: "" };
3583
+ prev.current = { transform: "", w: "", h: "", z: "" };
3576
3584
  };
3577
3585
  }, [canvasRef, object, insideContainer]);
3578
3586
  if (!object) return null;
@@ -3798,10 +3806,10 @@ function ellipsePosition(angleDeg) {
3798
3806
  function toNum(v) {
3799
3807
  return typeof v === "number" ? v : 0;
3800
3808
  }
3801
- function readOverlayScale(el) {
3809
+ function readInlineProperty(el, prop) {
3802
3810
  let node = el.parentElement;
3803
3811
  while (node) {
3804
- const val = node.style.getPropertyValue("--overlay-scale");
3812
+ const val = node.style.getPropertyValue(prop);
3805
3813
  if (val) return parseFloat(val) || 1;
3806
3814
  node = node.parentElement;
3807
3815
  }
@@ -3820,7 +3828,6 @@ function OverlayBadge({
3820
3828
  ...rest
3821
3829
  }) {
3822
3830
  const ref = useRef11(null);
3823
- const baseSize = useRef11(null);
3824
3831
  useEffect11(() => {
3825
3832
  const el = ref.current;
3826
3833
  if (!el) return;
@@ -3829,21 +3836,13 @@ function OverlayBadge({
3829
3836
  let rafId = 0;
3830
3837
  function doUpdate() {
3831
3838
  if (!el || !ancestor) return;
3832
- const containerW = ancestor.clientWidth;
3833
- const containerH = ancestor.clientHeight;
3834
- if (containerW <= 0 || containerH <= 0) {
3839
+ if (ancestor.clientWidth <= 0 || ancestor.clientHeight <= 0) {
3835
3840
  el.style.transform = "";
3836
3841
  return;
3837
3842
  }
3838
- if (!baseSize.current) {
3839
- baseSize.current = { w: containerW, h: containerH };
3840
- }
3841
- const ratio = Math.min(
3842
- containerW / baseSize.current.w,
3843
- containerH / baseSize.current.h
3844
- );
3845
- const ownScale = Math.max(minScale, Math.min(ratio, maxScale));
3846
- const overlayScale = readOverlayScale(el);
3843
+ const zoom = readInlineProperty(el, "--overlay-zoom");
3844
+ const ownScale = Math.max(minScale, Math.min(zoom, maxScale));
3845
+ const overlayScale = readInlineProperty(el, "--overlay-scale");
3847
3846
  const scale = `scale(${ownScale / overlayScale})`;
3848
3847
  el.style.transform = circular ? `translate(-50%, -50%) ${scale}` : scale;
3849
3848
  }
@@ -3861,7 +3860,6 @@ function OverlayBadge({
3861
3860
  return () => {
3862
3861
  if (rafId) cancelAnimationFrame(rafId);
3863
3862
  observer.disconnect();
3864
- baseSize.current = null;
3865
3863
  };
3866
3864
  }, [maxScale, minScale, circular]);
3867
3865
  const positionSx = circular ? (() => {