canvu-react 0.4.35 → 0.4.37

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,10 +1,8 @@
1
1
  import getStroke from 'perfect-freehand';
2
- import { Group, Canvas, Rect, Circle, Path, RoundedRect, Oval, DashPathEffect, Line, vec, matchFont, Text, Image } from '@shopify/react-native-skia';
2
+ import { Group, Canvas, Rect, Circle, Path, RoundedRect, Oval, DashPathEffect, Line, vec, matchFont, Text as Text$1, Image } from '@shopify/react-native-skia';
3
3
  import { memo, forwardRef, useState, useRef, useCallback, useEffect, useMemo, useImperativeHandle } from 'react';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { StyleSheet, PanResponder, View, Pressable, Text as Text$1, ScrollView } from 'react-native';
6
-
7
- // src/scene/shape-builders.ts
5
+ import { StyleSheet, PanResponder, View, Modal, Text, TextInput, Pressable, ScrollView } from 'react-native';
8
6
 
9
7
  // src/math/rect.ts
10
8
  function rectsIntersect(a, b) {
@@ -22,12 +20,36 @@ function normalizeRect(r) {
22
20
  }
23
21
 
24
22
  // src/scene/custom-shape.ts
23
+ function expandCustomShapeTemplate(template, width, height) {
24
+ return template.replace(/\{\{w\}\}/g, String(width)).replace(/\{\{h\}\}/g, String(height)).replace(/\{\{width\}\}/g, String(width)).replace(/\{\{height\}\}/g, String(height));
25
+ }
26
+ function resolveCustomInner(content, size) {
27
+ if ("render" in content) {
28
+ return content.render(size);
29
+ }
30
+ return expandCustomShapeTemplate(content.svg, size.width, size.height);
31
+ }
25
32
  function buildCustomShapeChildrenSvg(inner, intrinsic, bounds) {
26
33
  const b = normalizeRect(bounds);
27
34
  const sx = b.width / intrinsic.width;
28
35
  const sy = b.height / intrinsic.height;
29
36
  return `<g transform="scale(${sx},${sy})">${inner}</g>`;
30
37
  }
38
+ function createCustomShapeItem(id, bounds, content) {
39
+ const r = normalizeRect(bounds);
40
+ const intrinsic = { width: r.width, height: r.height };
41
+ const inner = resolveCustomInner(content, intrinsic);
42
+ return {
43
+ id,
44
+ x: r.x,
45
+ y: r.y,
46
+ bounds: { ...r },
47
+ toolKind: "custom",
48
+ customIntrinsicSize: intrinsic,
49
+ customInnerSvg: inner,
50
+ childrenSvg: buildCustomShapeChildrenSvg(inner, intrinsic, r)
51
+ };
52
+ }
31
53
 
32
54
  // src/scene/link-item.ts
33
55
  var LINK_PLUGIN_KEY = "canvuLink";
@@ -140,6 +162,9 @@ function getLinkData(item) {
140
162
  const entry = item.pluginData?.[LINK_PLUGIN_KEY];
141
163
  return isCanvuLinkData(entry) ? entry : null;
142
164
  }
165
+ function isLinkItem(item) {
166
+ return getLinkData(item) != null;
167
+ }
143
168
  function rebuildLinkItemSvg(item) {
144
169
  const link = getLinkData(item);
145
170
  if (!link) return item;
@@ -173,6 +198,26 @@ function rebuildLinkItemSvg(item) {
173
198
  childrenSvg: buildLinkCardSvg(width, height, link)
174
199
  };
175
200
  }
201
+ function createLinkItem(id, bounds, link) {
202
+ const width = bounds.width || DEFAULT_LINK_CARD_WIDTH;
203
+ const height = bounds.height || DEFAULT_LINK_CARD_HEIGHT;
204
+ const item = createCustomShapeItem(
205
+ id,
206
+ { ...bounds, width, height },
207
+ { render: (size) => buildLinkCardSvg(size.width, size.height, link) }
208
+ );
209
+ return rebuildLinkItemSvg({
210
+ ...item,
211
+ pluginData: {
212
+ ...item.pluginData ?? {},
213
+ [LINK_PLUGIN_KEY]: link
214
+ }
215
+ });
216
+ }
217
+ var DEFAULT_LINK_CARD_SIZE = {
218
+ width: DEFAULT_LINK_CARD_WIDTH,
219
+ height: DEFAULT_LINK_CARD_HEIGHT
220
+ };
176
221
 
177
222
  // src/scene/text-svg.ts
178
223
  function escapeSvgTextContent(s) {
@@ -1398,6 +1443,50 @@ function smoothFreehandPointsToPathD(points) {
1398
1443
  d += ` Q ${pLast.x} ${pLast.y} ${pEnd.x} ${pEnd.y}`;
1399
1444
  return d;
1400
1445
  }
1446
+
1447
+ // src/native/native-link-card.ts
1448
+ function linkHostname(href) {
1449
+ try {
1450
+ return new URL(href).hostname.replace(/^www\./, "");
1451
+ } catch {
1452
+ return href;
1453
+ }
1454
+ }
1455
+ function linkProtocol(href) {
1456
+ try {
1457
+ return new URL(href).protocol;
1458
+ } catch {
1459
+ return "";
1460
+ }
1461
+ }
1462
+ function linkInitial(value) {
1463
+ const first = value.trim().charAt(0).toUpperCase();
1464
+ return first || "L";
1465
+ }
1466
+ function normalizeNativeLinkHref(value) {
1467
+ const trimmed = value.trim();
1468
+ if (!trimmed) return null;
1469
+ if (/^[a-z][a-z0-9+.-]*:/i.test(trimmed)) return trimmed;
1470
+ return `https://${trimmed}`;
1471
+ }
1472
+ function buildNativeLinkCardDisplay(link) {
1473
+ const hostname = linkHostname(link.href);
1474
+ const title = link.title?.trim() || hostname || "Link";
1475
+ return {
1476
+ title,
1477
+ subtitle: hostname || link.href,
1478
+ initial: linkInitial(hostname || title),
1479
+ secure: linkProtocol(link.href) === "https:"
1480
+ };
1481
+ }
1482
+ function createNativeLinkCardBoundsAtPoint(point) {
1483
+ return {
1484
+ x: point.x - DEFAULT_LINK_CARD_SIZE.width / 2,
1485
+ y: point.y - DEFAULT_LINK_CARD_SIZE.height / 2,
1486
+ width: DEFAULT_LINK_CARD_SIZE.width,
1487
+ height: DEFAULT_LINK_CARD_SIZE.height
1488
+ };
1489
+ }
1401
1490
  var DEFAULT_NATIVE_IMAGE_CACHE_MAX_ENTRIES = 96;
1402
1491
  function disposeCachedImage(image) {
1403
1492
  try {
@@ -1757,7 +1846,7 @@ function SvgNodeItem({ node }) {
1757
1846
  const fs = node.fontSize != null ? toNum(node.fontSize) : 16;
1758
1847
  const font = matchFont({ fontSize: fs });
1759
1848
  return /* @__PURE__ */ jsx(Fragment, { children: node.children.map((tspan, i) => /* @__PURE__ */ jsx(
1760
- Text,
1849
+ Text$1,
1761
1850
  {
1762
1851
  x: tspan.x != null ? toNum(tspan.x) : node.x != null ? toNum(node.x) : 0,
1763
1852
  y: tspan.dy != null ? (node.y != null ? toNum(node.y) : fs) + toNum(tspan.dy) : (node.y != null ? toNum(node.y) : fs) + i * fs * 1.2,
@@ -2087,7 +2176,119 @@ function localBounds(bounds) {
2087
2176
  const b = normalizeRect(bounds);
2088
2177
  return { w: Math.max(0, b.width), h: Math.max(0, b.height) };
2089
2178
  }
2179
+ function truncateText(value, maxChars) {
2180
+ if (value.length <= maxChars) return value;
2181
+ return `${value.slice(0, Math.max(0, maxChars - 3)).trimEnd()}...`;
2182
+ }
2183
+ function NativeLinkCardRenderer({
2184
+ item,
2185
+ link
2186
+ }) {
2187
+ const bounds = normalizeRect(item.bounds);
2188
+ const scaleX = Math.max(0.01, bounds.width / DEFAULT_LINK_CARD_SIZE.width);
2189
+ const scaleY = Math.max(0.01, bounds.height / DEFAULT_LINK_CARD_SIZE.height);
2190
+ const display = buildNativeLinkCardDisplay(link);
2191
+ const titleFont = matchFont({ fontSize: 14.5, fontWeight: "700" });
2192
+ const subtitleFont = matchFont({ fontSize: 12.5 });
2193
+ const initialFont = matchFont({ fontSize: 17, fontWeight: "700" });
2194
+ const title = truncateText(display.title, 28);
2195
+ const subtitle = truncateText(display.subtitle, display.secure ? 28 : 31);
2196
+ const subtitleX = display.secure ? 82 : 69;
2197
+ const subtitleWidth = display.secure ? 188 : 201;
2198
+ return /* @__PURE__ */ jsxs(Group, { transform: [{ scaleX }, { scaleY }], children: [
2199
+ /* @__PURE__ */ jsx(
2200
+ RoundedRect,
2201
+ {
2202
+ x: 0,
2203
+ y: 0,
2204
+ width: DEFAULT_LINK_CARD_SIZE.width,
2205
+ height: DEFAULT_LINK_CARD_SIZE.height,
2206
+ r: 16,
2207
+ color: "#ffffff",
2208
+ style: "fill",
2209
+ antiAlias: true
2210
+ }
2211
+ ),
2212
+ /* @__PURE__ */ jsx(
2213
+ RoundedRect,
2214
+ {
2215
+ x: 0.5,
2216
+ y: 0.5,
2217
+ width: DEFAULT_LINK_CARD_SIZE.width - 1,
2218
+ height: DEFAULT_LINK_CARD_SIZE.height - 1,
2219
+ r: 15.5,
2220
+ color: "#dfe4ea",
2221
+ style: "stroke",
2222
+ strokeWidth: 1,
2223
+ antiAlias: true
2224
+ }
2225
+ ),
2226
+ /* @__PURE__ */ jsx(
2227
+ RoundedRect,
2228
+ {
2229
+ x: 14,
2230
+ y: 14,
2231
+ width: 42,
2232
+ height: 42,
2233
+ r: 11,
2234
+ color: "#315bd6",
2235
+ style: "fill",
2236
+ antiAlias: true
2237
+ }
2238
+ ),
2239
+ /* @__PURE__ */ jsx(
2240
+ Text$1,
2241
+ {
2242
+ x: 29.5,
2243
+ y: 41,
2244
+ text: display.initial,
2245
+ color: "#ffffff",
2246
+ font: initialFont
2247
+ }
2248
+ ),
2249
+ /* @__PURE__ */ jsx(Group, { clip: { x: 69, y: 13, width: 215, height: 24 }, children: /* @__PURE__ */ jsx(Text$1, { x: 69, y: 32, text: title, color: "#1f2937", font: titleFont }) }),
2250
+ display.secure ? /* @__PURE__ */ jsxs(Group, { transform: [{ translateX: 69 }, { translateY: 41 }], children: [
2251
+ /* @__PURE__ */ jsx(
2252
+ Rect,
2253
+ {
2254
+ x: 1.5,
2255
+ y: 4.5,
2256
+ width: 7,
2257
+ height: 6,
2258
+ color: "#6b7280",
2259
+ style: "stroke",
2260
+ strokeWidth: 1.3
2261
+ }
2262
+ ),
2263
+ /* @__PURE__ */ jsx(
2264
+ Path,
2265
+ {
2266
+ path: "M3 4.5 V3 a2 2 0 0 1 4 0 v1.5",
2267
+ color: "#6b7280",
2268
+ style: "stroke",
2269
+ strokeWidth: 1.3,
2270
+ strokeCap: "round",
2271
+ strokeJoin: "round"
2272
+ }
2273
+ )
2274
+ ] }) : null,
2275
+ /* @__PURE__ */ jsx(Group, { clip: { x: subtitleX, y: 34, width: subtitleWidth, height: 22 }, children: /* @__PURE__ */ jsx(
2276
+ Text$1,
2277
+ {
2278
+ x: subtitleX,
2279
+ y: 51,
2280
+ text: subtitle,
2281
+ color: "#6b7280",
2282
+ font: subtitleFont
2283
+ }
2284
+ ) })
2285
+ ] });
2286
+ }
2090
2287
  function NativeShapeRenderer({ item }) {
2288
+ const link = getLinkData(item);
2289
+ if (link) {
2290
+ return /* @__PURE__ */ jsx(NativeLinkCardRenderer, { item, link });
2291
+ }
2091
2292
  const style = resolveStrokeStyle(item);
2092
2293
  const k = item.toolKind;
2093
2294
  if (k === "rect") {
@@ -2220,7 +2421,7 @@ function NativeShapeRenderer({ item }) {
2220
2421
  const lines = item.text.split("\n");
2221
2422
  const font = matchFont({ fontSize: fs });
2222
2423
  return /* @__PURE__ */ jsx(Fragment, { children: lines.map((line, i) => /* @__PURE__ */ jsx(
2223
- Text,
2424
+ Text$1,
2224
2425
  {
2225
2426
  x: 0,
2226
2427
  y: fs + i * fs * 1.2,
@@ -2966,7 +3167,7 @@ function NativeInteractionOverlay({
2966
3167
  }
2967
3168
  ),
2968
3169
  peer.displayName ? /* @__PURE__ */ jsx(
2969
- Text,
3170
+ Text$1,
2970
3171
  {
2971
3172
  x: cursor.x + labelOffsetX,
2972
3173
  y: cursor.y + labelOffsetY,
@@ -3240,7 +3441,7 @@ function RangeControl({
3240
3441
  ]
3241
3442
  }
3242
3443
  ),
3243
- valueLabel ? /* @__PURE__ */ jsx(Text$1, { style: styles.rangeValue, children: valueLabel }) : null
3444
+ valueLabel ? /* @__PURE__ */ jsx(Text, { style: styles.rangeValue, children: valueLabel }) : null
3244
3445
  ] });
3245
3446
  }
3246
3447
  function InspectorSection({
@@ -3248,7 +3449,7 @@ function InspectorSection({
3248
3449
  children
3249
3450
  }) {
3250
3451
  return /* @__PURE__ */ jsxs(View, { style: styles.section, children: [
3251
- /* @__PURE__ */ jsx(Text$1, { style: styles.sectionLabel, children: label }),
3452
+ /* @__PURE__ */ jsx(Text, { style: styles.sectionLabel, children: label }),
3252
3453
  children
3253
3454
  ] });
3254
3455
  }
@@ -3270,7 +3471,7 @@ function SegmentControl({
3270
3471
  children: [
3271
3472
  segment.preview,
3272
3473
  /* @__PURE__ */ jsx(
3273
- Text$1,
3474
+ Text,
3274
3475
  {
3275
3476
  style: [
3276
3477
  styles.segmentLabel,
@@ -3510,9 +3711,14 @@ var DEFAULT_NATIVE_OVERFLOW_TOOL_IDS = [
3510
3711
  "line",
3511
3712
  "marker",
3512
3713
  "laser",
3513
- "image"
3714
+ "image",
3715
+ "link"
3514
3716
  ];
3515
3717
  var CLOUD_TOOL_ICON_PATH = "M17.5 19H8.5a6.5 6.5 0 1 1 6.17-8.55A4.75 4.75 0 0 1 17.5 9.5a4.75 4.75 0 0 1 0 9.5Z";
3718
+ var LINK_TOOL_ICON_PATHS = [
3719
+ "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",
3720
+ "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
3721
+ ];
3516
3722
  function NativeCloudToolIcon({
3517
3723
  color,
3518
3724
  size = 19,
@@ -3531,6 +3737,25 @@ function NativeCloudToolIcon({
3531
3737
  }
3532
3738
  ) }) });
3533
3739
  }
3740
+ function NativeLinkToolIcon({
3741
+ color,
3742
+ size = 20,
3743
+ strokeWidth = 2.4
3744
+ }) {
3745
+ const scale = size / 24;
3746
+ return /* @__PURE__ */ jsx(Canvas, { style: { width: size, height: size }, children: /* @__PURE__ */ jsx(Group, { transform: [{ scale }], children: LINK_TOOL_ICON_PATHS.map((path) => /* @__PURE__ */ jsx(
3747
+ Path,
3748
+ {
3749
+ path,
3750
+ color,
3751
+ style: "stroke",
3752
+ strokeWidth,
3753
+ strokeCap: "round",
3754
+ strokeJoin: "round"
3755
+ },
3756
+ path
3757
+ )) }) });
3758
+ }
3534
3759
  var DEFAULT_NATIVE_VECTOR_TOOLS = [
3535
3760
  { id: "hand", label: "Hand", shortcutHint: "H", shortLabel: "H" },
3536
3761
  { id: "select", label: "Select", shortcutHint: "V", shortLabel: "V" },
@@ -3568,7 +3793,8 @@ var DEFAULT_NATIVE_VECTOR_TOOLS = [
3568
3793
  shortLabel: "E"
3569
3794
  },
3570
3795
  { id: "text", label: "Text", shortcutHint: "T", shortLabel: "T" },
3571
- { id: "image", label: "File", shortcutHint: "I", shortLabel: "I" }
3796
+ { id: "image", label: "File", shortcutHint: "I", shortLabel: "I" },
3797
+ { id: "link", label: "Link", shortcutHint: "N", shortLabel: "L" }
3572
3798
  ];
3573
3799
  function splitToolbarTools(tools, overflowToolIds) {
3574
3800
  const overflowIds = new Set(overflowToolIds);
@@ -3691,7 +3917,7 @@ function NativeVectorToolbar({
3691
3917
  disabled: toolLockDisabled,
3692
3918
  foregroundColor: "#18181b",
3693
3919
  onToggle: toggleToolLock
3694
- }) ?? /* @__PURE__ */ jsx(Text$1, { style: styles2.lockGlyph, children: toolLocked ? "L" : "U" })
3920
+ }) ?? /* @__PURE__ */ jsx(Text, { style: styles2.lockGlyph, children: toolLocked ? "L" : "U" })
3695
3921
  }
3696
3922
  ),
3697
3923
  /* @__PURE__ */ jsx(View, { style: styles2.toolLockDivider })
@@ -3738,8 +3964,8 @@ function NativeVectorToolbar({
3738
3964
  disabled,
3739
3965
  foregroundColor: "#18181b",
3740
3966
  onSelect: () => onChange(activeOverflowTool.id)
3741
- }) ?? renderNativeToolFallback(activeOverflowTool, "#18181b") : renderOverflowIcon?.(overflowRenderInput) ?? /* @__PURE__ */ jsx(Text$1, { style: styles2.shapesGlyph, children: "S" }) }),
3742
- renderOverflowChevronIcon?.(overflowRenderInput) ?? /* @__PURE__ */ jsx(Text$1, { style: styles2.chevronGlyph, children: overflowOpen ? "^" : "v" })
3967
+ }) ?? renderNativeToolFallback(activeOverflowTool, "#18181b") : renderOverflowIcon?.(overflowRenderInput) ?? /* @__PURE__ */ jsx(Text, { style: styles2.shapesGlyph, children: "S" }) }),
3968
+ renderOverflowChevronIcon?.(overflowRenderInput) ?? /* @__PURE__ */ jsx(Text, { style: styles2.chevronGlyph, children: overflowOpen ? "^" : "v" })
3743
3969
  ]
3744
3970
  }
3745
3971
  ) : null
@@ -3809,7 +4035,7 @@ function renderNativeToolButton(input) {
3809
4035
  children: [
3810
4036
  /* @__PURE__ */ jsx(View, { style: styles2.iconSlot, children: icon }),
3811
4037
  input.density === "comfortable" ? /* @__PURE__ */ jsx(
3812
- Text$1,
4038
+ Text,
3813
4039
  {
3814
4040
  numberOfLines: 1,
3815
4041
  style: [
@@ -3830,7 +4056,10 @@ function renderNativeToolFallback(tool, foregroundColor, toolLabelStyle) {
3830
4056
  if (tool.id === "architectural-cloud") {
3831
4057
  return /* @__PURE__ */ jsx(NativeCloudToolIcon, { color: foregroundColor });
3832
4058
  }
3833
- return /* @__PURE__ */ jsx(Text$1, { style: [styles2.shortLabel, { color: foregroundColor }, toolLabelStyle], children: tool.shortLabel ?? tool.label.slice(0, 1).toUpperCase() });
4059
+ if (tool.id === "link") {
4060
+ return /* @__PURE__ */ jsx(NativeLinkToolIcon, { color: foregroundColor });
4061
+ }
4062
+ return /* @__PURE__ */ jsx(Text, { style: [styles2.shortLabel, { color: foregroundColor }, toolLabelStyle], children: tool.shortLabel ?? tool.label.slice(0, 1).toUpperCase() });
3834
4063
  }
3835
4064
  var styles2 = StyleSheet.create({
3836
4065
  shell: {
@@ -4428,6 +4657,13 @@ function resizeItemByHandle(item, start, handle, currentWorld) {
4428
4657
  }
4429
4658
  return { ...item, x: nb.x, y: nb.y, bounds: nb };
4430
4659
  }
4660
+ var DEFAULT_NATIVE_LINK_TOOL_DIALOG_LABELS = {
4661
+ title: "Add link",
4662
+ description: "Paste the link you want to add to the board.",
4663
+ inputPlaceholder: "https://example.com",
4664
+ cancelLabel: "Cancel",
4665
+ addLabel: "Add"
4666
+ };
4431
4667
  var MIN_PLACE_SIZE = 8;
4432
4668
  var MIN_ARROW_DRAG_PX = 8;
4433
4669
  var TAP_PX = 20;
@@ -4510,6 +4746,8 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4510
4746
  onSelectionChange,
4511
4747
  onItemsChange,
4512
4748
  onToolChangeRequest,
4749
+ onLinkToolRequest,
4750
+ linkToolDialogLabels,
4513
4751
  onWorldPointerDown,
4514
4752
  onWorldPointerMove,
4515
4753
  onWorldPointerLeave,
@@ -4529,6 +4767,8 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4529
4767
  toolLockedRef.current = toolLocked;
4530
4768
  const onToolChangeRequestRef = useRef(onToolChangeRequest);
4531
4769
  onToolChangeRequestRef.current = onToolChangeRequest;
4770
+ const onLinkToolRequestRef = useRef(onLinkToolRequest);
4771
+ onLinkToolRequestRef.current = onLinkToolRequest;
4532
4772
  const onWorldPointerDownRef = useRef(onWorldPointerDown);
4533
4773
  onWorldPointerDownRef.current = onWorldPointerDown;
4534
4774
  const onWorldPointerMoveRef = useRef(onWorldPointerMove);
@@ -4562,6 +4802,8 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4562
4802
  );
4563
4803
  const [eraserTrail, setEraserTrail] = useState([]);
4564
4804
  const [laserTrail, setLaserTrail] = useState([]);
4805
+ const [pendingNativeLinkRequest, setPendingNativeLinkRequest] = useState(null);
4806
+ const [nativeLinkInputValue, setNativeLinkInputValue] = useState("");
4565
4807
  const laserClearTimerRef = useRef(null);
4566
4808
  const strokeStyleRef = useRef({ ...DEFAULT_STROKE_STYLE });
4567
4809
  const markerStrokeStyleRef = useRef({ ...MARKER_TOOL_STYLE });
@@ -4639,6 +4881,21 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4639
4881
  onToolChangeRequestRef.current?.("select");
4640
4882
  }
4641
4883
  }, []);
4884
+ const requestSelectToolAfterNativeLinkUse = useCallback(() => {
4885
+ onToolChangeRequestRef.current?.("select");
4886
+ }, []);
4887
+ const closeNativeLinkDialog = useCallback(() => {
4888
+ setPendingNativeLinkRequest(null);
4889
+ setNativeLinkInputValue("");
4890
+ }, []);
4891
+ const submitNativeLinkDialog = useCallback(() => {
4892
+ const href = normalizeNativeLinkHref(nativeLinkInputValue);
4893
+ if (!href || !pendingNativeLinkRequest) return;
4894
+ const inserted = pendingNativeLinkRequest.insertLink({ href });
4895
+ if (inserted) {
4896
+ closeNativeLinkDialog();
4897
+ }
4898
+ }, [closeNativeLinkDialog, nativeLinkInputValue, pendingNativeLinkRequest]);
4642
4899
  if (!cameraRef.current) {
4643
4900
  cameraRef.current = new Camera2D({ minZoom: 0.05, maxZoom: 32 });
4644
4901
  }
@@ -4871,7 +5128,7 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
4871
5128
  });
4872
5129
  return;
4873
5130
  }
4874
- if (tool === "note" || tool === "text") {
5131
+ if (tool === "link" || tool === "note" || tool === "text") {
4875
5132
  dragStateRef.current = {
4876
5133
  kind: "tap",
4877
5134
  tool,
@@ -5207,6 +5464,43 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5207
5464
  const screenDy = point.y - st.startScreen.y;
5208
5465
  if (Math.hypot(screenDx, screenDy) > TAP_PX) return;
5209
5466
  const change = onItemsChangeRef.current;
5467
+ if (st.tool === "link") {
5468
+ const suggestedBounds = createNativeLinkCardBoundsAtPoint(st.startWorld);
5469
+ const insertLink = (link, options = {}) => {
5470
+ const currentChange = onItemsChangeRef.current;
5471
+ if (!currentChange) return null;
5472
+ const id = options.id ?? createShapeId();
5473
+ const item = createLinkItem(id, options.bounds ?? suggestedBounds, link);
5474
+ currentChange([...itemsRef.current, item]);
5475
+ onSelectionChangeRef.current?.([id]);
5476
+ requestSelectToolAfterNativeLinkUse();
5477
+ return item;
5478
+ };
5479
+ const requestLink = onLinkToolRequestRef.current;
5480
+ if (requestLink) {
5481
+ requestLink({
5482
+ toolId: "link",
5483
+ worldX: st.startWorld.x,
5484
+ worldY: st.startWorld.y,
5485
+ screenX: st.startScreen.x,
5486
+ screenY: st.startScreen.y,
5487
+ suggestedBounds,
5488
+ insertLink
5489
+ });
5490
+ return;
5491
+ }
5492
+ setNativeLinkInputValue("");
5493
+ setPendingNativeLinkRequest({
5494
+ toolId: "link",
5495
+ worldX: st.startWorld.x,
5496
+ worldY: st.startWorld.y,
5497
+ screenX: st.startScreen.x,
5498
+ screenY: st.startScreen.y,
5499
+ suggestedBounds,
5500
+ insertLink
5501
+ });
5502
+ return;
5503
+ }
5210
5504
  if (!change) return;
5211
5505
  if (st.tool === "text") {
5212
5506
  const id = createShapeId();
@@ -5254,6 +5548,7 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5254
5548
  dragStateRef.current = { kind: "idle" };
5255
5549
  },
5256
5550
  [
5551
+ requestSelectToolAfterNativeLinkUse,
5257
5552
  requestSelectToolAfterUse,
5258
5553
  screenToWorld,
5259
5554
  setRealtimePlacementPreview,
@@ -5385,7 +5680,13 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5385
5680
  [requestRender, size]
5386
5681
  );
5387
5682
  const activeStyleToolId = toolId === "draw" || toolId === "marker" ? toolId : null;
5388
- return /* @__PURE__ */ jsx(
5683
+ const nativeLinkDialogLabels = {
5684
+ ...DEFAULT_NATIVE_LINK_TOOL_DIALOG_LABELS,
5685
+ ...linkToolDialogLabels ?? {}
5686
+ };
5687
+ const normalizedNativeLinkHref = normalizeNativeLinkHref(nativeLinkInputValue);
5688
+ const nativeLinkCanSubmit = pendingNativeLinkRequest !== null && normalizedNativeLinkHref !== null && onItemsChange != null;
5689
+ return /* @__PURE__ */ jsxs(
5389
5690
  View,
5390
5691
  {
5391
5692
  style: { flex: 1, overflow: "hidden" },
@@ -5399,81 +5700,226 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5399
5700
  notifyWorldPointerLeave();
5400
5701
  },
5401
5702
  ...panResponder.panHandlers,
5402
- children: size.width > 0 && size.height > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
5703
+ children: [
5704
+ size.width > 0 && size.height > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
5705
+ /* @__PURE__ */ jsx(
5706
+ NativeSceneRenderer,
5707
+ {
5708
+ items: sceneItems,
5709
+ camera,
5710
+ width: size.width,
5711
+ height: size.height
5712
+ }
5713
+ ),
5714
+ interactive && /* @__PURE__ */ jsx(
5715
+ NativeInteractionOverlay,
5716
+ {
5717
+ camera,
5718
+ width: size.width,
5719
+ height: size.height,
5720
+ selectedItems,
5721
+ showResizeHandles,
5722
+ placementPreview,
5723
+ laserTrail,
5724
+ eraserTrail,
5725
+ eraserPreviewItems: items.filter(
5726
+ (it) => eraserPreviewIds.includes(it.id)
5727
+ ),
5728
+ previewStrokeStyle: strokeStyleState,
5729
+ remotePresence
5730
+ }
5731
+ ),
5732
+ interactive && showStyleInspector && activeStyleToolId ? /* @__PURE__ */ jsx(
5733
+ View,
5734
+ {
5735
+ pointerEvents: "box-none",
5736
+ style: styleInspectorPlacement === "top-left" ? {
5737
+ position: "absolute",
5738
+ left: 16,
5739
+ top: 104,
5740
+ alignItems: "flex-start"
5741
+ } : {
5742
+ position: "absolute",
5743
+ left: 16,
5744
+ right: 16,
5745
+ bottom: 84,
5746
+ alignItems: "center"
5747
+ },
5748
+ children: /* @__PURE__ */ jsx(
5749
+ NativeVectorStyleInspector,
5750
+ {
5751
+ toolId: activeStyleToolId,
5752
+ value: strokeStyleState,
5753
+ onChange: patchCurrentStrokeStyle
5754
+ }
5755
+ )
5756
+ }
5757
+ ) : null,
5758
+ toolbar && /* @__PURE__ */ jsx(
5759
+ View,
5760
+ {
5761
+ style: {
5762
+ position: "absolute",
5763
+ bottom: 16,
5764
+ left: 16,
5765
+ right: 16,
5766
+ flexDirection: "row",
5767
+ justifyContent: "center",
5768
+ alignItems: "center"
5769
+ },
5770
+ pointerEvents: "box-none",
5771
+ children: toolbar
5772
+ }
5773
+ )
5774
+ ] }),
5403
5775
  /* @__PURE__ */ jsx(
5404
- NativeSceneRenderer,
5405
- {
5406
- items: sceneItems,
5407
- camera,
5408
- width: size.width,
5409
- height: size.height
5410
- }
5411
- ),
5412
- interactive && /* @__PURE__ */ jsx(
5413
- NativeInteractionOverlay,
5414
- {
5415
- camera,
5416
- width: size.width,
5417
- height: size.height,
5418
- selectedItems,
5419
- showResizeHandles,
5420
- placementPreview,
5421
- laserTrail,
5422
- eraserTrail,
5423
- eraserPreviewItems: items.filter(
5424
- (it) => eraserPreviewIds.includes(it.id)
5425
- ),
5426
- previewStrokeStyle: strokeStyleState,
5427
- remotePresence
5428
- }
5429
- ),
5430
- interactive && showStyleInspector && activeStyleToolId ? /* @__PURE__ */ jsx(
5431
- View,
5776
+ Modal,
5432
5777
  {
5433
- pointerEvents: "box-none",
5434
- style: styleInspectorPlacement === "top-left" ? {
5435
- position: "absolute",
5436
- left: 16,
5437
- top: 104,
5438
- alignItems: "flex-start"
5439
- } : {
5440
- position: "absolute",
5441
- left: 16,
5442
- right: 16,
5443
- bottom: 84,
5444
- alignItems: "center"
5445
- },
5446
- children: /* @__PURE__ */ jsx(
5447
- NativeVectorStyleInspector,
5448
- {
5449
- toolId: activeStyleToolId,
5450
- value: strokeStyleState,
5451
- onChange: patchCurrentStrokeStyle
5452
- }
5453
- )
5454
- }
5455
- ) : null,
5456
- toolbar && /* @__PURE__ */ jsx(
5457
- View,
5458
- {
5459
- style: {
5460
- position: "absolute",
5461
- bottom: 16,
5462
- left: 16,
5463
- right: 16,
5464
- flexDirection: "row",
5465
- justifyContent: "center",
5466
- alignItems: "center"
5467
- },
5468
- pointerEvents: "box-none",
5469
- children: toolbar
5778
+ animationType: "fade",
5779
+ transparent: true,
5780
+ visible: pendingNativeLinkRequest !== null,
5781
+ onRequestClose: closeNativeLinkDialog,
5782
+ children: /* @__PURE__ */ jsx(View, { style: styles3.nativeLinkDialogBackdrop, children: /* @__PURE__ */ jsxs(View, { style: styles3.nativeLinkDialogCard, children: [
5783
+ /* @__PURE__ */ jsx(Text, { style: styles3.nativeLinkDialogTitle, children: nativeLinkDialogLabels.title }),
5784
+ /* @__PURE__ */ jsx(Text, { style: styles3.nativeLinkDialogDescription, children: nativeLinkDialogLabels.description }),
5785
+ /* @__PURE__ */ jsx(
5786
+ TextInput,
5787
+ {
5788
+ accessibilityLabel: nativeLinkDialogLabels.title,
5789
+ autoCapitalize: "none",
5790
+ autoCorrect: false,
5791
+ keyboardType: "url",
5792
+ onChangeText: setNativeLinkInputValue,
5793
+ onSubmitEditing: submitNativeLinkDialog,
5794
+ placeholder: nativeLinkDialogLabels.inputPlaceholder,
5795
+ returnKeyType: "done",
5796
+ style: styles3.nativeLinkDialogInput,
5797
+ value: nativeLinkInputValue
5798
+ }
5799
+ ),
5800
+ /* @__PURE__ */ jsxs(View, { style: styles3.nativeLinkDialogActions, children: [
5801
+ /* @__PURE__ */ jsx(
5802
+ Pressable,
5803
+ {
5804
+ accessibilityRole: "button",
5805
+ onPress: closeNativeLinkDialog,
5806
+ style: ({ pressed }) => [
5807
+ styles3.nativeLinkDialogButton,
5808
+ pressed ? styles3.nativeLinkDialogButtonPressed : void 0
5809
+ ],
5810
+ children: /* @__PURE__ */ jsx(Text, { style: styles3.nativeLinkDialogButtonText, children: nativeLinkDialogLabels.cancelLabel })
5811
+ }
5812
+ ),
5813
+ /* @__PURE__ */ jsx(
5814
+ Pressable,
5815
+ {
5816
+ accessibilityRole: "button",
5817
+ accessibilityState: { disabled: !nativeLinkCanSubmit },
5818
+ disabled: !nativeLinkCanSubmit,
5819
+ onPress: submitNativeLinkDialog,
5820
+ style: ({ pressed }) => [
5821
+ styles3.nativeLinkDialogButton,
5822
+ styles3.nativeLinkDialogPrimaryButton,
5823
+ pressed && nativeLinkCanSubmit ? styles3.nativeLinkDialogPrimaryButtonPressed : void 0,
5824
+ !nativeLinkCanSubmit ? styles3.nativeLinkDialogDisabledButton : void 0
5825
+ ],
5826
+ children: /* @__PURE__ */ jsx(Text, { style: styles3.nativeLinkDialogPrimaryButtonText, children: nativeLinkDialogLabels.addLabel })
5827
+ }
5828
+ )
5829
+ ] })
5830
+ ] }) })
5470
5831
  }
5471
5832
  )
5472
- ] })
5833
+ ]
5473
5834
  }
5474
5835
  );
5475
5836
  });
5837
+ var styles3 = StyleSheet.create({
5838
+ nativeLinkDialogBackdrop: {
5839
+ flex: 1,
5840
+ alignItems: "center",
5841
+ justifyContent: "center",
5842
+ paddingHorizontal: 24,
5843
+ backgroundColor: "rgba(0, 0, 0, 0.45)"
5844
+ },
5845
+ nativeLinkDialogCard: {
5846
+ width: "100%",
5847
+ maxWidth: 480,
5848
+ padding: 24,
5849
+ borderRadius: 16,
5850
+ backgroundColor: "#ffffff",
5851
+ shadowColor: "#000000",
5852
+ shadowOpacity: 0.18,
5853
+ shadowRadius: 24,
5854
+ shadowOffset: { width: 0, height: 8 },
5855
+ elevation: 12
5856
+ },
5857
+ nativeLinkDialogTitle: {
5858
+ color: "#111827",
5859
+ fontSize: 24,
5860
+ fontWeight: "700",
5861
+ lineHeight: 30
5862
+ },
5863
+ nativeLinkDialogDescription: {
5864
+ marginTop: 12,
5865
+ color: "#6b7280",
5866
+ fontSize: 16,
5867
+ lineHeight: 22
5868
+ },
5869
+ nativeLinkDialogInput: {
5870
+ marginTop: 24,
5871
+ height: 52,
5872
+ paddingHorizontal: 14,
5873
+ borderRadius: 10,
5874
+ borderWidth: StyleSheet.hairlineWidth,
5875
+ borderColor: "#d1d5db",
5876
+ color: "#111827",
5877
+ fontSize: 18,
5878
+ backgroundColor: "#ffffff"
5879
+ },
5880
+ nativeLinkDialogActions: {
5881
+ marginTop: 24,
5882
+ flexDirection: "row",
5883
+ justifyContent: "flex-end",
5884
+ gap: 12
5885
+ },
5886
+ nativeLinkDialogButton: {
5887
+ minWidth: 92,
5888
+ height: 48,
5889
+ alignItems: "center",
5890
+ justifyContent: "center",
5891
+ borderRadius: 10,
5892
+ borderWidth: StyleSheet.hairlineWidth,
5893
+ borderColor: "#d1d5db",
5894
+ backgroundColor: "#ffffff",
5895
+ paddingHorizontal: 18
5896
+ },
5897
+ nativeLinkDialogButtonPressed: {
5898
+ backgroundColor: "#f3f4f6"
5899
+ },
5900
+ nativeLinkDialogButtonText: {
5901
+ color: "#111827",
5902
+ fontSize: 17,
5903
+ fontWeight: "600"
5904
+ },
5905
+ nativeLinkDialogPrimaryButton: {
5906
+ borderColor: "#18181b",
5907
+ backgroundColor: "#18181b"
5908
+ },
5909
+ nativeLinkDialogPrimaryButtonPressed: {
5910
+ backgroundColor: "#27272a"
5911
+ },
5912
+ nativeLinkDialogDisabledButton: {
5913
+ borderColor: "#9ca3af",
5914
+ backgroundColor: "#9ca3af"
5915
+ },
5916
+ nativeLinkDialogPrimaryButtonText: {
5917
+ color: "#ffffff",
5918
+ fontSize: 17,
5919
+ fontWeight: "700"
5920
+ }
5921
+ });
5476
5922
 
5477
- export { DEFAULT_NATIVE_OVERFLOW_TOOL_IDS, DEFAULT_NATIVE_VECTOR_TOOLS, NATIVE_STYLE_PALETTE, NativeInteractionOverlay, NativeSceneRenderer, NativeShapeRenderer, NativeVectorStyleInspector, NativeVectorToolbar, NativeVectorViewport, createFreehandStrokeItem, createImageItem, createShapeId, nativeStyleColorWithOpacity, normalizeNativeStyleHex, parseSvgFragment };
5923
+ export { DEFAULT_LINK_CARD_SIZE, DEFAULT_NATIVE_OVERFLOW_TOOL_IDS, DEFAULT_NATIVE_VECTOR_TOOLS, NATIVE_STYLE_PALETTE, NativeInteractionOverlay, NativeSceneRenderer, NativeShapeRenderer, NativeVectorStyleInspector, NativeVectorToolbar, NativeVectorViewport, createFreehandStrokeItem, createImageItem, createLinkItem, createShapeId, getLinkData, isLinkItem, nativeStyleColorWithOpacity, normalizeNativeStyleHex, parseSvgFragment };
5478
5924
  //# sourceMappingURL=native.js.map
5479
5925
  //# sourceMappingURL=native.js.map