canvu-react 0.4.76 → 0.4.77

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/react.cjs CHANGED
@@ -8551,6 +8551,42 @@ function didReadOnlyActivationMovePastTap(session, pointer, tapPx) {
8551
8551
  return Math.hypot(dx, dy) > tapPx;
8552
8552
  }
8553
8553
 
8554
+ // src/react/render-scheduler.ts
8555
+ var getDefaultAnimationFrameRuntime = () => typeof window === "undefined" ? {} : window;
8556
+ function createAnimationFrameRenderScheduler({
8557
+ render,
8558
+ runtime = getDefaultAnimationFrameRuntime()
8559
+ }) {
8560
+ let frameId = null;
8561
+ const canceledFrameIds = /* @__PURE__ */ new Set();
8562
+ const request = () => {
8563
+ if (frameId != null) return;
8564
+ if (typeof runtime.requestAnimationFrame !== "function") {
8565
+ render();
8566
+ return;
8567
+ }
8568
+ const scheduledFrameId = runtime.requestAnimationFrame(() => {
8569
+ const currentFrameId = scheduledFrameId;
8570
+ if (canceledFrameIds.has(currentFrameId)) {
8571
+ canceledFrameIds.delete(currentFrameId);
8572
+ return;
8573
+ }
8574
+ if (frameId === currentFrameId) {
8575
+ frameId = null;
8576
+ }
8577
+ render();
8578
+ });
8579
+ frameId = scheduledFrameId;
8580
+ };
8581
+ const cancel = () => {
8582
+ if (frameId == null) return;
8583
+ canceledFrameIds.add(frameId);
8584
+ runtime.cancelAnimationFrame?.(frameId);
8585
+ frameId = null;
8586
+ };
8587
+ return { request, cancel };
8588
+ }
8589
+
8554
8590
  // src/react/stable-selection.ts
8555
8591
  function shallowEqualStringArray(a, b) {
8556
8592
  if (a === b) return true;
@@ -9563,6 +9599,9 @@ var VectorViewport = react.forwardRef(
9563
9599
  reducedMotionRef.current = reducedMotion;
9564
9600
  const [zoomPercent, setZoomPercent] = react.useState(100);
9565
9601
  const [cameraTick, setCameraTick] = react.useState(0);
9602
+ const renderFrameSchedulerRef = react.useRef(
9603
+ null
9604
+ );
9566
9605
  const [placementPreview, setPlacementPreview] = react.useState(null);
9567
9606
  const [eraserTrail, setEraserTrail] = react.useState([]);
9568
9607
  const [laserTrail, setLaserTrail] = react.useState([]);
@@ -9943,7 +9982,7 @@ var VectorViewport = react.forwardRef(
9943
9982
  renderSceneWithLivePenStroke
9944
9983
  ]
9945
9984
  );
9946
- const renderFrame = react.useCallback(() => {
9985
+ const renderFrameNow = react.useCallback(() => {
9947
9986
  const renderer = rendererRef.current;
9948
9987
  const cam = cameraRef.current;
9949
9988
  if (!renderer || !cam) return;
@@ -9956,6 +9995,14 @@ var VectorViewport = react.forwardRef(
9956
9995
  }
9957
9996
  onCameraChangeRef.current?.();
9958
9997
  }, []);
9998
+ const renderFrame = react.useCallback(() => {
9999
+ const scheduler = renderFrameSchedulerRef.current;
10000
+ if (!scheduler) {
10001
+ renderFrameNow();
10002
+ return;
10003
+ }
10004
+ scheduler.request();
10005
+ }, [renderFrameNow]);
9959
10006
  react.useEffect(() => {
9960
10007
  const el = sceneContainerRef.current;
9961
10008
  const interactionEl = interactionRootRef.current;
@@ -9974,6 +10021,9 @@ var VectorViewport = react.forwardRef(
9974
10021
  rasterImageCanvas: imageCanvasRenderingRef.current
9975
10022
  });
9976
10023
  rendererRef.current = renderer;
10024
+ renderFrameSchedulerRef.current = createAnimationFrameRenderScheduler({
10025
+ render: renderFrameNow
10026
+ });
9977
10027
  renderer.setInteractionState({
9978
10028
  selectedIds: effectiveSelectedIdsRef.current,
9979
10029
  hoveredItemId: hoveredItemIdRef.current
@@ -10008,6 +10058,8 @@ var VectorViewport = react.forwardRef(
10008
10058
  });
10009
10059
  }
10010
10060
  return () => {
10061
+ renderFrameSchedulerRef.current?.cancel();
10062
+ renderFrameSchedulerRef.current = null;
10011
10063
  detachInput();
10012
10064
  detachPencil?.();
10013
10065
  renderer.destroy();
@@ -10016,7 +10068,7 @@ var VectorViewport = react.forwardRef(
10016
10068
  cameraRef.current = null;
10017
10069
  setCameraForOverlay(null);
10018
10070
  };
10019
- }, [applePencilNav, renderFrame, resolveReadOnlyActivation]);
10071
+ }, [applePencilNav, renderFrame, renderFrameNow, resolveReadOnlyActivation]);
10020
10072
  react.useEffect(() => {
10021
10073
  rendererRef.current?.setInteractionState({
10022
10074
  selectedIds: effectiveSelectedIds,
@@ -10144,10 +10196,10 @@ var VectorViewport = react.forwardRef(
10144
10196
  livePenStrokeItemRef.current = null;
10145
10197
  }
10146
10198
  scene.setItems(resolvedSceneItems);
10147
- renderFrame();
10199
+ renderFrameNow();
10148
10200
  renderer?.renderLiveItem(livePenStrokeItemRef.current);
10149
10201
  }
10150
- }, [resolvedSceneItems, renderFrame]);
10202
+ }, [resolvedSceneItems, renderFrameNow]);
10151
10203
  react.useEffect(() => {
10152
10204
  const ids = effectiveSelectedIds;
10153
10205
  const valid = ids.filter((id) => items.some((i) => i.id === id));