canvu-react 0.4.5 → 0.4.6

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.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Camera2D } from './camera-CVVG7z56.cjs';
1
+ import { C as Camera2D } from './shape-builders-CKEMjivV.cjs';
2
+ export { o as createFreehandStrokeItem, t as createShapeId } from './shape-builders-CKEMjivV.cjs';
3
3
  import { V as VectorSceneItem, R as Rect } from './types-BCCvY6ie.cjs';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
  import * as react from 'react';
5
6
  import { ReactNode } from 'react';
6
7
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
@@ -291,4 +292,4 @@ type SvgNode = SvgRectNode | SvgEllipseNode | SvgCircleNode | SvgLineNode | SvgP
291
292
  */
292
293
  declare function parseSvgFragment(xml: string): SvgNode[];
293
294
 
294
- export { DEFAULT_NATIVE_VECTOR_TOOLS, NativeInteractionOverlay, type NativeInteractionOverlayProps, NativeSceneRenderer, type NativeSceneRendererProps, NativeShapeRenderer, type NativeShapeRendererProps, type NativeVectorToolDefinition, NativeVectorToolbar, type NativeVectorToolbarProps, type NativeVectorToolbarRenderToolInput, NativeVectorViewport, type NativeVectorViewportHandle, type NativeVectorViewportProps, type PlacementPreview, type SvgNode, parseSvgFragment };
295
+ export { DEFAULT_NATIVE_VECTOR_TOOLS, NativeInteractionOverlay, type NativeInteractionOverlayProps, NativeSceneRenderer, type NativeSceneRendererProps, NativeShapeRenderer, type NativeShapeRendererProps, type NativeVectorToolDefinition, NativeVectorToolbar, type NativeVectorToolbarProps, type NativeVectorToolbarRenderToolInput, NativeVectorViewport, type NativeVectorViewportHandle, type NativeVectorViewportProps, type PlacementPreview, type SvgNode, VectorSceneItem, parseSvgFragment };
package/dist/native.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Camera2D } from './camera-CoRYN_IV.js';
1
+ import { C as Camera2D } from './shape-builders-Cyh8zvDG.js';
2
+ export { o as createFreehandStrokeItem, t as createShapeId } from './shape-builders-Cyh8zvDG.js';
3
3
  import { V as VectorSceneItem, R as Rect } from './types-BCCvY6ie.js';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
  import * as react from 'react';
5
6
  import { ReactNode } from 'react';
6
7
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
@@ -291,4 +292,4 @@ type SvgNode = SvgRectNode | SvgEllipseNode | SvgCircleNode | SvgLineNode | SvgP
291
292
  */
292
293
  declare function parseSvgFragment(xml: string): SvgNode[];
293
294
 
294
- export { DEFAULT_NATIVE_VECTOR_TOOLS, NativeInteractionOverlay, type NativeInteractionOverlayProps, NativeSceneRenderer, type NativeSceneRendererProps, NativeShapeRenderer, type NativeShapeRendererProps, type NativeVectorToolDefinition, NativeVectorToolbar, type NativeVectorToolbarProps, type NativeVectorToolbarRenderToolInput, NativeVectorViewport, type NativeVectorViewportHandle, type NativeVectorViewportProps, type PlacementPreview, type SvgNode, parseSvgFragment };
295
+ export { DEFAULT_NATIVE_VECTOR_TOOLS, NativeInteractionOverlay, type NativeInteractionOverlayProps, NativeSceneRenderer, type NativeSceneRendererProps, NativeShapeRenderer, type NativeShapeRendererProps, type NativeVectorToolDefinition, NativeVectorToolbar, type NativeVectorToolbarProps, type NativeVectorToolbarRenderToolInput, NativeVectorViewport, type NativeVectorViewportHandle, type NativeVectorViewportProps, type PlacementPreview, type SvgNode, VectorSceneItem, parseSvgFragment };
package/dist/native.js CHANGED
@@ -1,10 +1,10 @@
1
+ import getStroke from 'perfect-freehand';
1
2
  import { Group, RoundedRect, Circle, Line, vec, Path, matchFont, Text, Canvas, Rect, Oval } from '@shopify/react-native-skia';
2
3
  import { memo, forwardRef, useState, useRef, useCallback, useMemo, useImperativeHandle } from 'react';
3
- import getStroke from 'perfect-freehand';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { StyleSheet, PanResponder, View, ScrollView, Text as Text$1, Pressable } from 'react-native';
6
6
 
7
- // src/native/NativeInteractionOverlay.tsx
7
+ // src/scene/shape-builders.ts
8
8
 
9
9
  // src/math/rect.ts
10
10
  function rectsIntersect(a, b) {
@@ -21,148 +21,6 @@ function normalizeRect(r) {
21
21
  };
22
22
  }
23
23
 
24
- // src/math/item-transform.ts
25
- function getItemRotationRad(item) {
26
- return item.rotation ?? 0;
27
- }
28
- function itemLocalToWorld(lx, ly, itemX, itemY, w, h, rotationRad) {
29
- const c = { x: w / 2, y: h / 2 };
30
- const dlx = lx - c.x;
31
- const dly = ly - c.y;
32
- const cos = Math.cos(rotationRad);
33
- const sin = Math.sin(rotationRad);
34
- return {
35
- x: itemX + c.x + cos * dlx - sin * dly,
36
- y: itemY + c.y + sin * dlx + cos * dly
37
- };
38
- }
39
- function worldToItemLocal(wx, wy, itemX, itemY, w, h, rotationRad) {
40
- const c = { x: w / 2, y: h / 2 };
41
- const vx = wx - itemX;
42
- const vy = wy - itemY;
43
- const dx = vx - c.x;
44
- const dy = vy - c.y;
45
- const cos = Math.cos(-rotationRad);
46
- const sin = Math.sin(-rotationRad);
47
- const lx = cos * dx - sin * dy;
48
- const ly = sin * dx + cos * dy;
49
- return { x: c.x + lx, y: c.y + ly };
50
- }
51
- function boundsAabbForRotatedItem(item) {
52
- const rot = getItemRotationRad(item);
53
- if (Math.abs(rot) < 1e-12 && item.bounds.width >= 0 && item.bounds.height >= 0) {
54
- return item.bounds;
55
- }
56
- const r = normalizeRect(item.bounds);
57
- if (Math.abs(rot) < 1e-12) {
58
- return r;
59
- }
60
- const corners = [
61
- [0, 0],
62
- [r.width, 0],
63
- [r.width, r.height],
64
- [0, r.height]
65
- ];
66
- let minX = Infinity;
67
- let minY = Infinity;
68
- let maxX = -Infinity;
69
- let maxY = -Infinity;
70
- for (const [lx, ly] of corners) {
71
- const p = itemLocalToWorld(lx, ly, item.x, item.y, r.width, r.height, rot);
72
- minX = Math.min(minX, p.x);
73
- minY = Math.min(minY, p.y);
74
- maxX = Math.max(maxX, p.x);
75
- maxY = Math.max(maxY, p.y);
76
- }
77
- return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
78
- }
79
-
80
- // src/interaction/resize-handles.ts
81
- function getHandleWorldPosition(bounds, id) {
82
- const r = normalizeRect(bounds);
83
- const cx = r.x + r.width / 2;
84
- const cy = r.y + r.height / 2;
85
- switch (id) {
86
- case "nw":
87
- return { x: r.x, y: r.y };
88
- case "n":
89
- return { x: cx, y: r.y };
90
- case "ne":
91
- return { x: r.x + r.width, y: r.y };
92
- case "e":
93
- return { x: r.x + r.width, y: cy };
94
- case "se":
95
- return { x: r.x + r.width, y: r.y + r.height };
96
- case "s":
97
- return { x: cx, y: r.y + r.height };
98
- case "sw":
99
- return { x: r.x, y: r.y + r.height };
100
- case "w":
101
- return { x: r.x, y: cy };
102
- }
103
- }
104
- function getHandleWorldPositionRotated(bounds, handle, rotationRad) {
105
- const r = normalizeRect(bounds);
106
- const p = getHandleWorldPosition(
107
- { x: 0, y: 0, width: r.width, height: r.height },
108
- handle
109
- );
110
- return itemLocalToWorld(p.x, p.y, r.x, r.y, r.width, r.height, rotationRad);
111
- }
112
- function getRotationHandleWorldPosition(bounds, rotationRad, handleOffsetWorld) {
113
- const r = normalizeRect(bounds);
114
- return itemLocalToWorld(
115
- r.width / 2,
116
- -handleOffsetWorld,
117
- r.x,
118
- r.y,
119
- r.width,
120
- r.height,
121
- rotationRad
122
- );
123
- }
124
- function rectFromCorners(a, b) {
125
- const minX = Math.min(a.x, b.x);
126
- const maxX = Math.max(a.x, b.x);
127
- const minY = Math.min(a.y, b.y);
128
- const maxY = Math.max(a.y, b.y);
129
- return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
130
- }
131
-
132
- // src/scene/freehand-path.ts
133
- function smoothFreehandPointsToPathD(points) {
134
- const n = points.length;
135
- if (n === 0) return "";
136
- if (n === 1) {
137
- const p = points[0];
138
- if (!p) return "";
139
- return `M ${p.x} ${p.y}`;
140
- }
141
- if (n === 2) {
142
- const a = points[0];
143
- const b = points[1];
144
- if (!a || !b) return "";
145
- return `M ${a.x} ${a.y} L ${b.x} ${b.y}`;
146
- }
147
- const p0 = points[0];
148
- if (!p0) return "";
149
- let d = `M ${p0.x} ${p0.y}`;
150
- let i = 1;
151
- for (; i < n - 2; i++) {
152
- const pi = points[i];
153
- const pi1 = points[i + 1];
154
- if (!pi || !pi1) continue;
155
- const xc = (pi.x + pi1.x) / 2;
156
- const yc = (pi.y + pi1.y) / 2;
157
- d += ` Q ${pi.x} ${pi.y} ${xc} ${yc}`;
158
- }
159
- const pLast = points[i];
160
- const pEnd = points[i + 1];
161
- if (!pLast || !pEnd) return d;
162
- d += ` Q ${pLast.x} ${pLast.y} ${pEnd.x} ${pEnd.y}`;
163
- return d;
164
- }
165
-
166
24
  // src/scene/custom-shape.ts
167
25
  function buildCustomShapeChildrenSvg(inner, intrinsic, bounds) {
168
26
  const b = normalizeRect(bounds);
@@ -1036,6 +894,148 @@ function buildRasterImageChildrenSvg(dataUrl, intrinsic, bounds) {
1036
894
  return `<g transform="translate(${tx}, ${ty}) scale(${s})"><image href="${href}" x="0" y="0" width="${iw}" height="${ih}" /></g>`;
1037
895
  }
1038
896
 
897
+ // src/math/item-transform.ts
898
+ function getItemRotationRad(item) {
899
+ return item.rotation ?? 0;
900
+ }
901
+ function itemLocalToWorld(lx, ly, itemX, itemY, w, h, rotationRad) {
902
+ const c = { x: w / 2, y: h / 2 };
903
+ const dlx = lx - c.x;
904
+ const dly = ly - c.y;
905
+ const cos = Math.cos(rotationRad);
906
+ const sin = Math.sin(rotationRad);
907
+ return {
908
+ x: itemX + c.x + cos * dlx - sin * dly,
909
+ y: itemY + c.y + sin * dlx + cos * dly
910
+ };
911
+ }
912
+ function worldToItemLocal(wx, wy, itemX, itemY, w, h, rotationRad) {
913
+ const c = { x: w / 2, y: h / 2 };
914
+ const vx = wx - itemX;
915
+ const vy = wy - itemY;
916
+ const dx = vx - c.x;
917
+ const dy = vy - c.y;
918
+ const cos = Math.cos(-rotationRad);
919
+ const sin = Math.sin(-rotationRad);
920
+ const lx = cos * dx - sin * dy;
921
+ const ly = sin * dx + cos * dy;
922
+ return { x: c.x + lx, y: c.y + ly };
923
+ }
924
+ function boundsAabbForRotatedItem(item) {
925
+ const rot = getItemRotationRad(item);
926
+ if (Math.abs(rot) < 1e-12 && item.bounds.width >= 0 && item.bounds.height >= 0) {
927
+ return item.bounds;
928
+ }
929
+ const r = normalizeRect(item.bounds);
930
+ if (Math.abs(rot) < 1e-12) {
931
+ return r;
932
+ }
933
+ const corners = [
934
+ [0, 0],
935
+ [r.width, 0],
936
+ [r.width, r.height],
937
+ [0, r.height]
938
+ ];
939
+ let minX = Infinity;
940
+ let minY = Infinity;
941
+ let maxX = -Infinity;
942
+ let maxY = -Infinity;
943
+ for (const [lx, ly] of corners) {
944
+ const p = itemLocalToWorld(lx, ly, item.x, item.y, r.width, r.height, rot);
945
+ minX = Math.min(minX, p.x);
946
+ minY = Math.min(minY, p.y);
947
+ maxX = Math.max(maxX, p.x);
948
+ maxY = Math.max(maxY, p.y);
949
+ }
950
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
951
+ }
952
+
953
+ // src/interaction/resize-handles.ts
954
+ function getHandleWorldPosition(bounds, id) {
955
+ const r = normalizeRect(bounds);
956
+ const cx = r.x + r.width / 2;
957
+ const cy = r.y + r.height / 2;
958
+ switch (id) {
959
+ case "nw":
960
+ return { x: r.x, y: r.y };
961
+ case "n":
962
+ return { x: cx, y: r.y };
963
+ case "ne":
964
+ return { x: r.x + r.width, y: r.y };
965
+ case "e":
966
+ return { x: r.x + r.width, y: cy };
967
+ case "se":
968
+ return { x: r.x + r.width, y: r.y + r.height };
969
+ case "s":
970
+ return { x: cx, y: r.y + r.height };
971
+ case "sw":
972
+ return { x: r.x, y: r.y + r.height };
973
+ case "w":
974
+ return { x: r.x, y: cy };
975
+ }
976
+ }
977
+ function getHandleWorldPositionRotated(bounds, handle, rotationRad) {
978
+ const r = normalizeRect(bounds);
979
+ const p = getHandleWorldPosition(
980
+ { x: 0, y: 0, width: r.width, height: r.height },
981
+ handle
982
+ );
983
+ return itemLocalToWorld(p.x, p.y, r.x, r.y, r.width, r.height, rotationRad);
984
+ }
985
+ function getRotationHandleWorldPosition(bounds, rotationRad, handleOffsetWorld) {
986
+ const r = normalizeRect(bounds);
987
+ return itemLocalToWorld(
988
+ r.width / 2,
989
+ -handleOffsetWorld,
990
+ r.x,
991
+ r.y,
992
+ r.width,
993
+ r.height,
994
+ rotationRad
995
+ );
996
+ }
997
+ function rectFromCorners(a, b) {
998
+ const minX = Math.min(a.x, b.x);
999
+ const maxX = Math.max(a.x, b.x);
1000
+ const minY = Math.min(a.y, b.y);
1001
+ const maxY = Math.max(a.y, b.y);
1002
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
1003
+ }
1004
+
1005
+ // src/scene/freehand-path.ts
1006
+ function smoothFreehandPointsToPathD(points) {
1007
+ const n = points.length;
1008
+ if (n === 0) return "";
1009
+ if (n === 1) {
1010
+ const p = points[0];
1011
+ if (!p) return "";
1012
+ return `M ${p.x} ${p.y}`;
1013
+ }
1014
+ if (n === 2) {
1015
+ const a = points[0];
1016
+ const b = points[1];
1017
+ if (!a || !b) return "";
1018
+ return `M ${a.x} ${a.y} L ${b.x} ${b.y}`;
1019
+ }
1020
+ const p0 = points[0];
1021
+ if (!p0) return "";
1022
+ let d = `M ${p0.x} ${p0.y}`;
1023
+ let i = 1;
1024
+ for (; i < n - 2; i++) {
1025
+ const pi = points[i];
1026
+ const pi1 = points[i + 1];
1027
+ if (!pi || !pi1) continue;
1028
+ const xc = (pi.x + pi1.x) / 2;
1029
+ const yc = (pi.y + pi1.y) / 2;
1030
+ d += ` Q ${pi.x} ${pi.y} ${xc} ${yc}`;
1031
+ }
1032
+ const pLast = points[i];
1033
+ const pEnd = points[i + 1];
1034
+ if (!pLast || !pEnd) return d;
1035
+ d += ` Q ${pLast.x} ${pLast.y} ${pEnd.x} ${pEnd.y}`;
1036
+ return d;
1037
+ }
1038
+
1039
1039
  // src/native/skia-transform.ts
1040
1040
  function parseNum(s) {
1041
1041
  return Number(s);
@@ -3134,6 +3134,6 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
3134
3134
  );
3135
3135
  });
3136
3136
 
3137
- export { DEFAULT_NATIVE_VECTOR_TOOLS, NativeInteractionOverlay, NativeSceneRenderer, NativeShapeRenderer, NativeVectorToolbar, NativeVectorViewport, parseSvgFragment };
3137
+ export { DEFAULT_NATIVE_VECTOR_TOOLS, NativeInteractionOverlay, NativeSceneRenderer, NativeShapeRenderer, NativeVectorToolbar, NativeVectorViewport, createFreehandStrokeItem, createShapeId, parseSvgFragment };
3138
3138
  //# sourceMappingURL=native.js.map
3139
3139
  //# sourceMappingURL=native.js.map