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