canvu-react 0.4.25 → 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,16 +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 = [];
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
- result.push({ translateX: x }, { translateY: y });
1311
- return result;
1309
+ return [];
1310
+ }
1311
+ function skiaItemRotationOrigin(x, y, cx, cy) {
1312
+ return { x: x + cx, y: y + cy };
1312
1313
  }
1313
1314
  function rgbaFromHexAndOpacity(hex, opacity) {
1314
1315
  if (!hex) return hex;
@@ -2158,8 +2159,10 @@ function NativeInteractionOverlay({
2158
2159
  const b = normalizeRect(it.bounds);
2159
2160
  const cx = b.width / 2;
2160
2161
  const cy = b.height / 2;
2161
- const t = skiaItemPlacementTransform(it.x, it.y, cx, cy, it.rotation ?? 0);
2162
- 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(
2163
2166
  Rect,
2164
2167
  {
2165
2168
  x: 0,
@@ -2171,7 +2174,11 @@ function NativeInteractionOverlay({
2171
2174
  strokeWidth: overlayStrokeWorld,
2172
2175
  antiAlias: true
2173
2176
  }
2174
- ) }, 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);
2175
2182
  }),
2176
2183
  showResizeHandles && bSingle && single && /* @__PURE__ */ jsxs(Fragment, { children: [
2177
2184
  HANDLE_ORDER.map((hid) => {
@@ -2432,16 +2439,28 @@ function NativeInteractionOverlay({
2432
2439
  const b = normalizeRect(it.bounds);
2433
2440
  const cx = b.width / 2;
2434
2441
  const cy = b.height / 2;
2435
- const t = skiaItemPlacementTransform(it.x, it.y, cx, cy, it.rotation ?? 0);
2436
- 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(
2437
2446
  Group,
2438
2447
  {
2439
- transform: t,
2448
+ transform: translationTransform,
2440
2449
  opacity: ERASER_PREVIEW_OPACITY,
2441
2450
  children: /* @__PURE__ */ jsx(NativeShapeRenderer, { item: it })
2442
2451
  },
2443
2452
  `erase-${it.id}`
2444
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
+ );
2445
2464
  }) });
2446
2465
  }, [eraserPreviewItems]);
2447
2466
  const eraserTrailElements = useMemo(() => {
@@ -2633,14 +2652,12 @@ var MemoShape = memo(function MemoShape2({
2633
2652
  const b = normalizeRect(item.bounds);
2634
2653
  const cx = b.width / 2;
2635
2654
  const cy = b.height / 2;
2636
- const itemTransform = skiaItemPlacementTransform(
2637
- item.x,
2638
- item.y,
2639
- cx,
2640
- cy,
2641
- item.rotation ?? 0
2642
- );
2643
- 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 });
2644
2661
  });
2645
2662
  function NativeSceneRenderer({
2646
2663
  items,