canvu-react 0.4.25 → 0.4.27

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';
@@ -37,6 +37,7 @@ function escapeHtmlText(s) {
37
37
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
38
38
  }
39
39
  var DEFAULT_TEXT_FONT_SIZE = 18;
40
+ var DEFAULT_TEXT_TOOL_FONT_SIZE = 28;
40
41
  var TEXT_FONT_FAMILY = "Inter, -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif";
41
42
  var LINE_HEIGHT_RATIO = 22 / 18;
42
43
  var FIRST_LINE_BASELINE_RATIO = 20 / 18;
@@ -77,6 +78,12 @@ function lineHeightFor(fontSize) {
77
78
  function firstLineBaselineY(fontSize) {
78
79
  return fontSize * FIRST_LINE_BASELINE_RATIO;
79
80
  }
81
+ function textBaselineYFor(fontSize) {
82
+ return firstLineBaselineY(fontSize);
83
+ }
84
+ function textLineHeightFor(fontSize) {
85
+ return lineHeightFor(fontSize);
86
+ }
80
87
  function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
81
88
  const cacheKey = textMeasureCacheKey(content, fontSize);
82
89
  const cached = textMeasureCache.get(cacheKey);
@@ -1299,16 +1306,17 @@ function parseSvgTransform(s) {
1299
1306
  function skiaCameraTransform(zoom, panX, panY) {
1300
1307
  return [{ translateX: panX }, { translateY: panY }, { scale: zoom }];
1301
1308
  }
1302
- function skiaItemPlacementTransform(x, y, cx, cy, rotationRad) {
1303
- const result = [];
1309
+ function skiaItemTranslationTransform(x, y) {
1310
+ return [{ translateX: x }, { translateY: y }];
1311
+ }
1312
+ function skiaItemRotationTransform(rotationRad) {
1304
1313
  if (Math.abs(rotationRad) > 1e-12) {
1305
- result.push({
1306
- rotate: rotationRad,
1307
- origin: { x: cx, y: cy }
1308
- });
1314
+ return [{ rotate: rotationRad }];
1309
1315
  }
1310
- result.push({ translateX: x }, { translateY: y });
1311
- return result;
1316
+ return [];
1317
+ }
1318
+ function skiaItemRotationOrigin(x, y, cx, cy) {
1319
+ return { x: x + cx, y: y + cy };
1312
1320
  }
1313
1321
  function rgbaFromHexAndOpacity(hex, opacity) {
1314
1322
  if (!hex) return hex;
@@ -2158,8 +2166,10 @@ function NativeInteractionOverlay({
2158
2166
  const b = normalizeRect(it.bounds);
2159
2167
  const cx = b.width / 2;
2160
2168
  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(
2169
+ const rotationTransform = skiaItemRotationTransform(it.rotation ?? 0);
2170
+ const rotationOrigin = skiaItemRotationOrigin(it.x, it.y, cx, cy);
2171
+ const translationTransform = skiaItemTranslationTransform(it.x, it.y);
2172
+ const selectionRect = /* @__PURE__ */ jsx(Group, { transform: translationTransform, children: /* @__PURE__ */ jsx(
2163
2173
  Rect,
2164
2174
  {
2165
2175
  x: 0,
@@ -2171,7 +2181,11 @@ function NativeInteractionOverlay({
2171
2181
  strokeWidth: overlayStrokeWorld,
2172
2182
  antiAlias: true
2173
2183
  }
2174
- ) }, it.id);
2184
+ ) });
2185
+ if (rotationTransform.length === 0) {
2186
+ return /* @__PURE__ */ jsx(Group, { children: selectionRect }, it.id);
2187
+ }
2188
+ return /* @__PURE__ */ jsx(Group, { transform: rotationTransform, origin: rotationOrigin, children: selectionRect }, it.id);
2175
2189
  }),
2176
2190
  showResizeHandles && bSingle && single && /* @__PURE__ */ jsxs(Fragment, { children: [
2177
2191
  HANDLE_ORDER.map((hid) => {
@@ -2432,16 +2446,28 @@ function NativeInteractionOverlay({
2432
2446
  const b = normalizeRect(it.bounds);
2433
2447
  const cx = b.width / 2;
2434
2448
  const cy = b.height / 2;
2435
- const t = skiaItemPlacementTransform(it.x, it.y, cx, cy, it.rotation ?? 0);
2436
- return /* @__PURE__ */ jsx(
2449
+ const rotationTransform = skiaItemRotationTransform(it.rotation ?? 0);
2450
+ const rotationOrigin = skiaItemRotationOrigin(it.x, it.y, cx, cy);
2451
+ const translationTransform = skiaItemTranslationTransform(it.x, it.y);
2452
+ const preview = /* @__PURE__ */ jsx(
2437
2453
  Group,
2438
2454
  {
2439
- transform: t,
2455
+ transform: translationTransform,
2440
2456
  opacity: ERASER_PREVIEW_OPACITY,
2441
2457
  children: /* @__PURE__ */ jsx(NativeShapeRenderer, { item: it })
2442
2458
  },
2443
2459
  `erase-${it.id}`
2444
2460
  );
2461
+ if (rotationTransform.length === 0) return preview;
2462
+ return /* @__PURE__ */ jsx(
2463
+ Group,
2464
+ {
2465
+ transform: rotationTransform,
2466
+ origin: rotationOrigin,
2467
+ children: preview
2468
+ },
2469
+ `erase-rot-${it.id}`
2470
+ );
2445
2471
  }) });
2446
2472
  }, [eraserPreviewItems]);
2447
2473
  const eraserTrailElements = useMemo(() => {
@@ -2633,14 +2659,12 @@ var MemoShape = memo(function MemoShape2({
2633
2659
  const b = normalizeRect(item.bounds);
2634
2660
  const cx = b.width / 2;
2635
2661
  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 }) });
2662
+ const rotationTransform = skiaItemRotationTransform(item.rotation ?? 0);
2663
+ const rotationOrigin = skiaItemRotationOrigin(item.x, item.y, cx, cy);
2664
+ const translationTransform = skiaItemTranslationTransform(item.x, item.y);
2665
+ const shape = /* @__PURE__ */ jsx(Group, { transform: translationTransform, children: /* @__PURE__ */ jsx(NativeShapeRenderer, { item }) });
2666
+ if (rotationTransform.length === 0) return shape;
2667
+ return /* @__PURE__ */ jsx(Group, { transform: rotationTransform, origin: rotationOrigin, children: shape });
2644
2668
  });
2645
2669
  function NativeSceneRenderer({
2646
2670
  items,
@@ -4611,17 +4635,21 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4611
4635
  if (!change) return;
4612
4636
  if (st.tool === "text") {
4613
4637
  const id = createShapeId();
4638
+ const fs = DEFAULT_TEXT_TOOL_FONT_SIZE;
4639
+ const baseline = textBaselineYFor(fs);
4640
+ const lh = textLineHeightFor(fs);
4641
+ const minH = Math.max(26, baseline + Math.max(4, lh * 0.2));
4614
4642
  const item = createTextItem(
4615
4643
  id,
4616
4644
  {
4617
4645
  x: st.startWorld.x - 4,
4618
- y: st.startWorld.y - 18,
4646
+ y: st.startWorld.y - baseline,
4619
4647
  width: 160,
4620
- height: 26
4648
+ height: minH
4621
4649
  },
4622
4650
  "Text",
4623
4651
  strokeStyleRef.current,
4624
- 18
4652
+ fs
4625
4653
  );
4626
4654
  change([...itemsRef.current, item]);
4627
4655
  onSelectionChangeRef.current?.([id]);