canvu-react 0.4.24 → 0.4.26

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
@@ -1,5 +1,5 @@
1
1
  import getStroke from 'perfect-freehand';
2
- import { Group, RoundedRect, Circle, Line, vec, Path, matchFont, Text, Canvas, Rect, Oval, DashPathEffect, useImage, Image } from '@shopify/react-native-skia';
2
+ import { Group, Canvas, Rect, Circle, Path, RoundedRect, Oval, DashPathEffect, Line, vec, matchFont, Text, useImage, Image } from '@shopify/react-native-skia';
3
3
  import { memo, forwardRef, useState, useRef, useEffect, useCallback, useMemo, useImperativeHandle } from 'react';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { StyleSheet, PanResponder, View, Pressable, Text as Text$1, ScrollView } from 'react-native';
@@ -1299,15 +1299,17 @@ function parseSvgTransform(s) {
1299
1299
  function skiaCameraTransform(zoom, panX, panY) {
1300
1300
  return [{ translateX: panX }, { translateY: panY }, { scale: zoom }];
1301
1301
  }
1302
- function skiaItemPlacementTransform(x, y, cx, cy, rotationRad) {
1303
- const result = [{ translateX: x }, { translateY: y }];
1302
+ function skiaItemTranslationTransform(x, y) {
1303
+ return [{ translateX: x }, { translateY: y }];
1304
+ }
1305
+ function skiaItemRotationTransform(rotationRad) {
1304
1306
  if (Math.abs(rotationRad) > 1e-12) {
1305
- result.push({
1306
- rotate: rotationRad,
1307
- origin: { x: cx, y: cy }
1308
- });
1307
+ return [{ rotate: rotationRad }];
1309
1308
  }
1310
- return result;
1309
+ return [];
1310
+ }
1311
+ function skiaItemRotationOrigin(x, y, cx, cy) {
1312
+ return { x: x + cx, y: y + cy };
1311
1313
  }
1312
1314
  function rgbaFromHexAndOpacity(hex, opacity) {
1313
1315
  if (!hex) return hex;
@@ -2157,8 +2159,10 @@ function NativeInteractionOverlay({
2157
2159
  const b = normalizeRect(it.bounds);
2158
2160
  const cx = b.width / 2;
2159
2161
  const cy = b.height / 2;
2160
- const t = skiaItemPlacementTransform(it.x, it.y, cx, cy, it.rotation ?? 0);
2161
- return /* @__PURE__ */ jsx(Group, { transform: t, children: /* @__PURE__ */ jsx(
2162
+ const rotationTransform = skiaItemRotationTransform(it.rotation ?? 0);
2163
+ const rotationOrigin = skiaItemRotationOrigin(it.x, it.y, cx, cy);
2164
+ const translationTransform = skiaItemTranslationTransform(it.x, it.y);
2165
+ const selectionRect = /* @__PURE__ */ jsx(Group, { transform: translationTransform, children: /* @__PURE__ */ jsx(
2162
2166
  Rect,
2163
2167
  {
2164
2168
  x: 0,
@@ -2170,7 +2174,11 @@ function NativeInteractionOverlay({
2170
2174
  strokeWidth: overlayStrokeWorld,
2171
2175
  antiAlias: true
2172
2176
  }
2173
- ) }, it.id);
2177
+ ) });
2178
+ if (rotationTransform.length === 0) {
2179
+ return /* @__PURE__ */ jsx(Group, { children: selectionRect }, it.id);
2180
+ }
2181
+ return /* @__PURE__ */ jsx(Group, { transform: rotationTransform, origin: rotationOrigin, children: selectionRect }, it.id);
2174
2182
  }),
2175
2183
  showResizeHandles && bSingle && single && /* @__PURE__ */ jsxs(Fragment, { children: [
2176
2184
  HANDLE_ORDER.map((hid) => {
@@ -2431,16 +2439,28 @@ function NativeInteractionOverlay({
2431
2439
  const b = normalizeRect(it.bounds);
2432
2440
  const cx = b.width / 2;
2433
2441
  const cy = b.height / 2;
2434
- const t = skiaItemPlacementTransform(it.x, it.y, cx, cy, it.rotation ?? 0);
2435
- return /* @__PURE__ */ jsx(
2442
+ const rotationTransform = skiaItemRotationTransform(it.rotation ?? 0);
2443
+ const rotationOrigin = skiaItemRotationOrigin(it.x, it.y, cx, cy);
2444
+ const translationTransform = skiaItemTranslationTransform(it.x, it.y);
2445
+ const preview = /* @__PURE__ */ jsx(
2436
2446
  Group,
2437
2447
  {
2438
- transform: t,
2448
+ transform: translationTransform,
2439
2449
  opacity: ERASER_PREVIEW_OPACITY,
2440
2450
  children: /* @__PURE__ */ jsx(NativeShapeRenderer, { item: it })
2441
2451
  },
2442
2452
  `erase-${it.id}`
2443
2453
  );
2454
+ if (rotationTransform.length === 0) return preview;
2455
+ return /* @__PURE__ */ jsx(
2456
+ Group,
2457
+ {
2458
+ transform: rotationTransform,
2459
+ origin: rotationOrigin,
2460
+ children: preview
2461
+ },
2462
+ `erase-rot-${it.id}`
2463
+ );
2444
2464
  }) });
2445
2465
  }, [eraserPreviewItems]);
2446
2466
  const eraserTrailElements = useMemo(() => {
@@ -2632,14 +2652,12 @@ var MemoShape = memo(function MemoShape2({
2632
2652
  const b = normalizeRect(item.bounds);
2633
2653
  const cx = b.width / 2;
2634
2654
  const cy = b.height / 2;
2635
- const itemTransform = skiaItemPlacementTransform(
2636
- item.x,
2637
- item.y,
2638
- cx,
2639
- cy,
2640
- item.rotation ?? 0
2641
- );
2642
- return /* @__PURE__ */ jsx(Group, { transform: itemTransform, children: /* @__PURE__ */ jsx(NativeShapeRenderer, { item }) });
2655
+ const rotationTransform = skiaItemRotationTransform(item.rotation ?? 0);
2656
+ const rotationOrigin = skiaItemRotationOrigin(item.x, item.y, cx, cy);
2657
+ const translationTransform = skiaItemTranslationTransform(item.x, item.y);
2658
+ const shape = /* @__PURE__ */ jsx(Group, { transform: translationTransform, children: /* @__PURE__ */ jsx(NativeShapeRenderer, { item }) });
2659
+ if (rotationTransform.length === 0) return shape;
2660
+ return /* @__PURE__ */ jsx(Group, { transform: rotationTransform, origin: rotationOrigin, children: shape });
2643
2661
  });
2644
2662
  function NativeSceneRenderer({
2645
2663
  items,