canvu-react 0.4.22 → 0.4.24

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