canvu-react 0.4.69 → 0.4.70

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
@@ -8390,6 +8390,47 @@ function shallowEqualStringArray(a, b) {
8390
8390
  return true;
8391
8391
  }
8392
8392
 
8393
+ // src/react/stroke-input.ts
8394
+ function getPointerEventSamples(event) {
8395
+ if (typeof event.getCoalescedEvents !== "function") {
8396
+ return [event];
8397
+ }
8398
+ const samples = event.getCoalescedEvents();
8399
+ return samples.length > 0 ? samples : [event];
8400
+ }
8401
+ var resolveInterpolatedPressure = (lastPoint, nextPoint, ratio) => {
8402
+ if (lastPoint.pressure != null && nextPoint.pressure != null) {
8403
+ return lastPoint.pressure + (nextPoint.pressure - lastPoint.pressure) * ratio;
8404
+ }
8405
+ return ratio === 1 ? nextPoint.pressure : void 0;
8406
+ };
8407
+ var resolveMaxStepWorld = (maxStepWorld) => Number.isFinite(maxStepWorld) && maxStepWorld > 0 ? maxStepWorld : Number.POSITIVE_INFINITY;
8408
+ function appendInterpolatedStrokePoint(points, nextPoint, maxStepWorld) {
8409
+ if (points.length === 0) return [nextPoint];
8410
+ const lastPoint = points[points.length - 1];
8411
+ if (!lastPoint) return [...points, nextPoint];
8412
+ const deltaX = nextPoint.x - lastPoint.x;
8413
+ const deltaY = nextPoint.y - lastPoint.y;
8414
+ const distanceSquared = deltaX * deltaX + deltaY * deltaY;
8415
+ if (distanceSquared < 1e-12) return points;
8416
+ const distance = Math.sqrt(distanceSquared);
8417
+ const stepCount = Math.max(
8418
+ 1,
8419
+ Math.ceil(distance / resolveMaxStepWorld(maxStepWorld))
8420
+ );
8421
+ if (stepCount === 1) return [...points, nextPoint];
8422
+ const interpolatedPoints = Array.from({ length: stepCount }, (_, index) => {
8423
+ const ratio = (index + 1) / stepCount;
8424
+ const pressure = resolveInterpolatedPressure(lastPoint, nextPoint, ratio);
8425
+ return {
8426
+ x: lastPoint.x + deltaX * ratio,
8427
+ y: lastPoint.y + deltaY * ratio,
8428
+ ...pressure != null ? { pressure } : {}
8429
+ };
8430
+ });
8431
+ return [...points, ...interpolatedPoints];
8432
+ }
8433
+
8393
8434
  // src/react/TextEditOverlay.tsx
8394
8435
  init_rect();
8395
8436
  init_text_svg();
@@ -8649,13 +8690,6 @@ function pointInSelectedItemBounds(item, worldX, worldY) {
8649
8690
  );
8650
8691
  return local.x >= 0 && local.x <= bounds.width && local.y >= 0 && local.y <= bounds.height;
8651
8692
  }
8652
- function pointerEventSamples(ev) {
8653
- if (ev.pointerType !== "pen" || typeof ev.getCoalescedEvents !== "function") {
8654
- return [ev];
8655
- }
8656
- const samples = ev.getCoalescedEvents();
8657
- return samples.length > 0 ? samples : [ev];
8658
- }
8659
8693
  var CANVU_PEN_ACTIVE_UI_BLOCK_CSS = `
8660
8694
  [data-canvu-pen-active="true"] [data-slot="vector-canvas-toolbar"],
8661
8695
  [data-canvu-pen-active="true"] [data-slot="vector-canvas-toolbar"] *,
@@ -8757,15 +8791,6 @@ function VectorViewportPluginInstances({
8757
8791
  ] }, plugin.id);
8758
8792
  }) });
8759
8793
  }
8760
- function appendInterpolatedPoints(points, next, maxStepWorld) {
8761
- if (points.length === 0) return [next];
8762
- const last = points[points.length - 1];
8763
- if (!last) return [...points, next];
8764
- const dx = next.x - last.x;
8765
- const dy = next.y - last.y;
8766
- if (dx * dx + dy * dy < 1e-12) return points;
8767
- return [...points, next];
8768
- }
8769
8794
  function pointerSampleToWorldPoint(screenToWorldFn, clientX, clientY, pressure) {
8770
8795
  const { worldX, worldY } = screenToWorldFn(clientX, clientY);
8771
8796
  const safePressure = pressure != null && Number.isFinite(pressure) ? Math.min(1, Math.max(0, pressure)) : void 0;
@@ -8796,15 +8821,19 @@ function isLikelyStylusTouch(touch) {
8796
8821
  }
8797
8822
  function appendPointerEventSamplesToStrokePoints(points, ev, zoom, screenToWorldFn) {
8798
8823
  let interpolated = points;
8799
- ev.pointerType === "pen" ? 0.35 / zoom : 1 / zoom;
8800
- for (const sample of pointerEventSamples(ev)) {
8824
+ const maxStepWorld = ev.pointerType === "pen" ? 0.35 / zoom : 1 / zoom;
8825
+ for (const sample of getPointerEventSamples(ev)) {
8801
8826
  const nextPoint = pointerSampleToWorldPoint(
8802
8827
  screenToWorldFn,
8803
8828
  sample.clientX,
8804
8829
  sample.clientY,
8805
8830
  sample.pointerType === "pen" ? sample.pressure : void 0
8806
8831
  );
8807
- interpolated = appendInterpolatedPoints(interpolated, nextPoint);
8832
+ interpolated = appendInterpolatedStrokePoint(
8833
+ interpolated,
8834
+ nextPoint,
8835
+ maxStepWorld
8836
+ );
8808
8837
  }
8809
8838
  return interpolated;
8810
8839
  }
@@ -8815,7 +8844,7 @@ function appendTouchToStrokePoints(points, touch, zoom, screenToWorldFn) {
8815
8844
  touch.clientY,
8816
8845
  touchPressure(touch)
8817
8846
  );
8818
- return appendInterpolatedPoints(points, nextPoint);
8847
+ return appendInterpolatedStrokePoint(points, nextPoint, 0.35 / zoom);
8819
8848
  }
8820
8849
  function createStraightStrokeState(anchorPoint, clientX, clientY) {
8821
8850
  return {