canvu-react 0.4.23 → 0.4.25

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/native.js CHANGED
@@ -940,10 +940,6 @@ function worldToItemLocal(wx, wy, itemX, itemY, w, h, rotationRad) {
940
940
  const ly = sin * dx + cos * dy;
941
941
  return { x: c.x + lx, y: c.y + ly };
942
942
  }
943
- function itemPivotWorld(item) {
944
- const r = normalizeRect(item.bounds);
945
- return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
946
- }
947
943
  function boundsAabbForRotatedItem(item) {
948
944
  const rot = getItemRotationRad(item);
949
945
  if (Math.abs(rot) < 1e-12 && item.bounds.width >= 0 && item.bounds.height >= 0) {
@@ -1304,13 +1300,14 @@ function skiaCameraTransform(zoom, panX, panY) {
1304
1300
  return [{ translateX: panX }, { translateY: panY }, { scale: zoom }];
1305
1301
  }
1306
1302
  function skiaItemPlacementTransform(x, y, cx, cy, rotationRad) {
1307
- const result = [{ translateX: x }, { translateY: y }];
1303
+ const result = [];
1308
1304
  if (Math.abs(rotationRad) > 1e-12) {
1309
1305
  result.push({
1310
1306
  rotate: rotationRad,
1311
1307
  origin: { x: cx, y: cy }
1312
1308
  });
1313
1309
  }
1310
+ result.push({ translateX: x }, { translateY: y });
1314
1311
  return result;
1315
1312
  }
1316
1313
  function rgbaFromHexAndOpacity(hex, opacity) {
@@ -2029,6 +2026,92 @@ function resolveNativeStrokePreviewStyle(tool, previewStrokeStyle) {
2029
2026
  ...previewStrokeStyle?.strokeDash != null && !isLaser ? { strokeDash: previewStrokeStyle.strokeDash } : {}
2030
2027
  };
2031
2028
  }
2029
+
2030
+ // src/native/native-vector-interactions.ts
2031
+ var NATIVE_SELECTION_HANDLE_HIT_RADIUS_PX = 24;
2032
+ function nativeItemPlacementBounds(item) {
2033
+ const bounds = normalizeRect(item.bounds);
2034
+ return {
2035
+ x: item.x,
2036
+ y: item.y,
2037
+ width: bounds.width,
2038
+ height: bounds.height
2039
+ };
2040
+ }
2041
+ function supportsNativeResizeHandles(item) {
2042
+ const k = item?.toolKind;
2043
+ if (k === "rect" || k === "ellipse" || k === "architectural-cloud" || k === "line" || k === "arrow" || k === "image" || k === "text") {
2044
+ return true;
2045
+ }
2046
+ if ((k === "draw" || k === "pencil" || k === "brush" || k === "marker") && item?.pathPointsLocal && item.pathPointsLocal.length > 0) {
2047
+ return true;
2048
+ }
2049
+ return k === "custom" && !!item?.customIntrinsicSize && !!item?.customInnerSvg;
2050
+ }
2051
+ function hitTestNativeSelectionHandle({
2052
+ selectedItem,
2053
+ selectedCount,
2054
+ worldPoint,
2055
+ zoom
2056
+ }) {
2057
+ if (selectedCount !== 1) return null;
2058
+ if (!selectedItem || selectedItem.locked) return null;
2059
+ if (!supportsNativeResizeHandles(selectedItem)) return null;
2060
+ const bounds = nativeItemPlacementBounds(selectedItem);
2061
+ const rotation = selectedItem.rotation ?? 0;
2062
+ const handleRadiusWorld = NATIVE_SELECTION_HANDLE_HIT_RADIUS_PX / Math.max(zoom, 1e-9);
2063
+ const rotateOffsetWorld = 24 / Math.max(zoom, 1e-9);
2064
+ if (hitTestRotateHandle(
2065
+ bounds,
2066
+ rotation,
2067
+ worldPoint.x,
2068
+ worldPoint.y,
2069
+ handleRadiusWorld,
2070
+ rotateOffsetWorld
2071
+ )) {
2072
+ return { kind: "rotate" };
2073
+ }
2074
+ const handle = hitTestResizeHandle(
2075
+ bounds,
2076
+ worldPoint.x,
2077
+ worldPoint.y,
2078
+ handleRadiusWorld,
2079
+ rotation
2080
+ );
2081
+ return handle ? { kind: "resize", handle } : null;
2082
+ }
2083
+ function pointInNativeSelectedItemBounds(item, worldPoint) {
2084
+ const bounds = normalizeRect(item.bounds);
2085
+ const local = worldToItemLocal(
2086
+ worldPoint.x,
2087
+ worldPoint.y,
2088
+ item.x,
2089
+ item.y,
2090
+ bounds.width,
2091
+ bounds.height,
2092
+ item.rotation ?? 0
2093
+ );
2094
+ return local.x >= 0 && local.x <= bounds.width && local.y >= 0 && local.y <= bounds.height;
2095
+ }
2096
+ function resolveNativeCustomPlacement(toolId, customPlacement, customPlacements) {
2097
+ if (customPlacement?.toolId === toolId) return customPlacement;
2098
+ return customPlacements?.find((placement) => placement.toolId === toolId) ?? null;
2099
+ }
2100
+ function nativeRotationDragStart(input) {
2101
+ const bounds = nativeItemPlacementBounds(input.item);
2102
+ const pivotWorld = {
2103
+ x: bounds.x + bounds.width / 2,
2104
+ y: bounds.y + bounds.height / 2
2105
+ };
2106
+ return {
2107
+ pivotWorld,
2108
+ startPointerAngleRad: Math.atan2(
2109
+ input.worldPoint.y - pivotWorld.y,
2110
+ input.worldPoint.x - pivotWorld.x
2111
+ ),
2112
+ startRotation: input.item.rotation ?? 0
2113
+ };
2114
+ }
2032
2115
  var HANDLE_ORDER = ["nw", "n", "ne", "e", "se", "s", "sw", "w"];
2033
2116
  var ERASER_PREVIEW_OPACITY = 0.3;
2034
2117
  var OVERLAY_STROKE_PX = 1.25;
@@ -2067,7 +2150,7 @@ function NativeInteractionOverlay({
2067
2150
  const selectionElements = useMemo(() => {
2068
2151
  if (selectedItems.length === 0) return null;
2069
2152
  const single = selectedItems.length === 1 ? selectedItems[0] : void 0;
2070
- const bSingle = single ? normalizeRect(single.bounds) : null;
2153
+ const bSingle = single ? nativeItemPlacementBounds(single) : null;
2071
2154
  const rotSingle = single?.rotation ?? 0;
2072
2155
  const rotHandlePos = showResizeHandles && bSingle && single ? getRotationHandleWorldPosition(bSingle, rotSingle, rotateOffsetWorld) : null;
2073
2156
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -3784,79 +3867,6 @@ function resizeItemByHandle(item, start, handle, currentWorld) {
3784
3867
  }
3785
3868
  return { ...item, x: nb.x, y: nb.y, bounds: nb };
3786
3869
  }
3787
-
3788
- // src/native/native-vector-interactions.ts
3789
- var NATIVE_SELECTION_HANDLE_HIT_RADIUS_PX = 24;
3790
- function supportsNativeResizeHandles(item) {
3791
- const k = item?.toolKind;
3792
- if (k === "rect" || k === "ellipse" || k === "architectural-cloud" || k === "line" || k === "arrow" || k === "image" || k === "text") {
3793
- return true;
3794
- }
3795
- if ((k === "draw" || k === "pencil" || k === "brush" || k === "marker") && item?.pathPointsLocal && item.pathPointsLocal.length > 0) {
3796
- return true;
3797
- }
3798
- return k === "custom" && !!item?.customIntrinsicSize && !!item?.customInnerSvg;
3799
- }
3800
- function hitTestNativeSelectionHandle({
3801
- selectedItem,
3802
- selectedCount,
3803
- worldPoint,
3804
- zoom
3805
- }) {
3806
- if (selectedCount !== 1) return null;
3807
- if (!selectedItem || selectedItem.locked) return null;
3808
- if (!supportsNativeResizeHandles(selectedItem)) return null;
3809
- const bounds = normalizeRect(selectedItem.bounds);
3810
- const rotation = selectedItem.rotation ?? 0;
3811
- const handleRadiusWorld = NATIVE_SELECTION_HANDLE_HIT_RADIUS_PX / Math.max(zoom, 1e-9);
3812
- const rotateOffsetWorld = 24 / Math.max(zoom, 1e-9);
3813
- if (hitTestRotateHandle(
3814
- bounds,
3815
- rotation,
3816
- worldPoint.x,
3817
- worldPoint.y,
3818
- handleRadiusWorld,
3819
- rotateOffsetWorld
3820
- )) {
3821
- return { kind: "rotate" };
3822
- }
3823
- const handle = hitTestResizeHandle(
3824
- bounds,
3825
- worldPoint.x,
3826
- worldPoint.y,
3827
- handleRadiusWorld,
3828
- rotation
3829
- );
3830
- return handle ? { kind: "resize", handle } : null;
3831
- }
3832
- function pointInNativeSelectedItemBounds(item, worldPoint) {
3833
- const bounds = normalizeRect(item.bounds);
3834
- const local = worldToItemLocal(
3835
- worldPoint.x,
3836
- worldPoint.y,
3837
- item.x,
3838
- item.y,
3839
- bounds.width,
3840
- bounds.height,
3841
- item.rotation ?? 0
3842
- );
3843
- return local.x >= 0 && local.x <= bounds.width && local.y >= 0 && local.y <= bounds.height;
3844
- }
3845
- function resolveNativeCustomPlacement(toolId, customPlacement, customPlacements) {
3846
- if (customPlacement?.toolId === toolId) return customPlacement;
3847
- return customPlacements?.find((placement) => placement.toolId === toolId) ?? null;
3848
- }
3849
- function nativeRotationDragStart(input) {
3850
- const pivotWorld = itemPivotWorld(input.item);
3851
- return {
3852
- pivotWorld,
3853
- startPointerAngleRad: Math.atan2(
3854
- input.worldPoint.y - pivotWorld.y,
3855
- input.worldPoint.x - pivotWorld.x
3856
- ),
3857
- startRotation: input.item.rotation ?? 0
3858
- };
3859
- }
3860
3870
  var MIN_PLACE_SIZE = 8;
3861
3871
  var MIN_ARROW_DRAG_PX = 8;
3862
3872
  var TAP_PX = 20;
@@ -4138,7 +4148,7 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4138
4148
  handle: selectionHandle.handle,
4139
4149
  snapshot: selectedItem,
4140
4150
  start: {
4141
- bounds: selectedItem.bounds,
4151
+ bounds: nativeItemPlacementBounds(selectedItem),
4142
4152
  line: selectedItem.line
4143
4153
  }
4144
4154
  };