canvu-react 0.4.46 → 0.4.48

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.
Files changed (51) hide show
  1. package/dist/{asset-hydration-Dc7fsnTG.d.ts → asset-hydration-BSjiek7Q.d.ts} +2 -2
  2. package/dist/{asset-hydration-Cy_2FyV5.d.cts → asset-hydration-F6aM5C7x.d.cts} +2 -2
  3. package/dist/{asset-store-TzOPvlgn.d.cts → asset-store-35ysK28r.d.cts} +1 -1
  4. package/dist/{asset-store-DQPRZEcy.d.ts → asset-store-D_FjW_CN.d.ts} +1 -1
  5. package/dist/chatbot.d.cts +6 -6
  6. package/dist/chatbot.d.ts +6 -6
  7. package/dist/index.cjs +49 -1
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +53 -9
  10. package/dist/index.d.ts +53 -9
  11. package/dist/index.js +49 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/{link-item-DwzXOwU5.d.cts → link-item-BMV3VUCr.d.cts} +1 -1
  14. package/dist/{link-item-IW4GTnxl.d.ts → link-item-COoNNvCu.d.ts} +1 -1
  15. package/dist/native.cjs +104 -51
  16. package/dist/native.cjs.map +1 -1
  17. package/dist/native.d.cts +6 -6
  18. package/dist/native.d.ts +6 -6
  19. package/dist/native.js +104 -51
  20. package/dist/native.js.map +1 -1
  21. package/dist/react.cjs +259 -18
  22. package/dist/react.cjs.map +1 -1
  23. package/dist/react.d.cts +29 -13
  24. package/dist/react.d.ts +29 -13
  25. package/dist/react.js +259 -18
  26. package/dist/react.js.map +1 -1
  27. package/dist/realtime.cjs +3 -1
  28. package/dist/realtime.cjs.map +1 -1
  29. package/dist/realtime.d.cts +8 -8
  30. package/dist/realtime.d.ts +8 -8
  31. package/dist/realtime.js +3 -1
  32. package/dist/realtime.js.map +1 -1
  33. package/dist/realtimeNative.d.cts +4 -4
  34. package/dist/realtimeNative.d.ts +4 -4
  35. package/dist/{shape-builders-Cyh8zvDG.d.ts → shape-builders-BCOAG0pS.d.ts} +1 -1
  36. package/dist/{shape-builders-CKEMjivV.d.cts → shape-builders-BmLS8CNh.d.cts} +1 -1
  37. package/dist/tldraw.cjs +3 -1
  38. package/dist/tldraw.cjs.map +1 -1
  39. package/dist/tldraw.d.cts +1 -1
  40. package/dist/tldraw.d.ts +1 -1
  41. package/dist/tldraw.js +3 -1
  42. package/dist/tldraw.js.map +1 -1
  43. package/dist/{types-BUPc2Zgw.d.cts → types-6HszqSa5.d.cts} +1 -1
  44. package/dist/{types-B7xZAKVJ.d.ts → types-BAEHaIYO.d.ts} +43 -6
  45. package/dist/{types-B82WiQQh.d.ts → types-BMMPUak7.d.ts} +1 -1
  46. package/dist/{types-BQUbxMgz.d.cts → types-BOQLWyCw.d.cts} +1 -1
  47. package/dist/{types-CYtq9Pr9.d.ts → types-BtWbGOqh.d.ts} +1 -1
  48. package/dist/{types-BCCvY6ie.d.cts → types-fJNwEnHf.d.cts} +35 -1
  49. package/dist/{types-BCCvY6ie.d.ts → types-fJNwEnHf.d.ts} +35 -1
  50. package/dist/{types-C4wI3Jyc.d.cts → types-uzeExFkd.d.cts} +43 -6
  51. package/package.json +1 -1
package/dist/native.d.cts CHANGED
@@ -1,13 +1,13 @@
1
- import { C as CanvuLinkData } from './link-item-DwzXOwU5.cjs';
2
- export { D as DEFAULT_LINK_CARD_SIZE, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-DwzXOwU5.cjs';
3
- import { C as Camera2D, S as StrokeStyle } from './shape-builders-CKEMjivV.cjs';
4
- export { o as createFreehandStrokeItem, q as createImageItem, t as createShapeId } from './shape-builders-CKEMjivV.cjs';
5
- import { V as VectorSceneItem, R as Rect } from './types-BCCvY6ie.cjs';
1
+ import { C as CanvuLinkData } from './link-item-BMV3VUCr.cjs';
2
+ export { D as DEFAULT_LINK_CARD_SIZE, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-BMV3VUCr.cjs';
3
+ import { C as Camera2D, S as StrokeStyle } from './shape-builders-BmLS8CNh.cjs';
4
+ export { o as createFreehandStrokeItem, q as createImageItem, t as createShapeId } from './shape-builders-BmLS8CNh.cjs';
5
+ import { V as VectorSceneItem, R as Rect } from './types-fJNwEnHf.cjs';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
7
  import * as react from 'react';
8
8
  import { ReactNode } from 'react';
9
9
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
10
- import { R as RemotePresencePeer } from './types-BQUbxMgz.cjs';
10
+ import { R as RemotePresencePeer } from './types-BOQLWyCw.cjs';
11
11
 
12
12
  type NativeImagesMenuLabels = {
13
13
  title?: string;
package/dist/native.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { C as CanvuLinkData } from './link-item-IW4GTnxl.js';
2
- export { D as DEFAULT_LINK_CARD_SIZE, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-IW4GTnxl.js';
3
- import { C as Camera2D, S as StrokeStyle } from './shape-builders-Cyh8zvDG.js';
4
- export { o as createFreehandStrokeItem, q as createImageItem, t as createShapeId } from './shape-builders-Cyh8zvDG.js';
5
- import { V as VectorSceneItem, R as Rect } from './types-BCCvY6ie.js';
1
+ import { C as CanvuLinkData } from './link-item-COoNNvCu.js';
2
+ export { D as DEFAULT_LINK_CARD_SIZE, c as createLinkItem, g as getLinkData, i as isLinkItem } from './link-item-COoNNvCu.js';
3
+ import { C as Camera2D, S as StrokeStyle } from './shape-builders-BCOAG0pS.js';
4
+ export { o as createFreehandStrokeItem, q as createImageItem, t as createShapeId } from './shape-builders-BCOAG0pS.js';
5
+ import { V as VectorSceneItem, R as Rect } from './types-fJNwEnHf.js';
6
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
7
  import * as react from 'react';
8
8
  import { ReactNode } from 'react';
9
9
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
10
- import { R as RemotePresencePeer } from './types-B82WiQQh.js';
10
+ import { R as RemotePresencePeer } from './types-BMMPUak7.js';
11
11
 
12
12
  type NativeImagesMenuLabels = {
13
13
  title?: string;
package/dist/native.js CHANGED
@@ -35,7 +35,7 @@ function buildCustomShapeChildrenSvg(inner, intrinsic, bounds) {
35
35
  const sy = b.height / intrinsic.height;
36
36
  return `<g transform="scale(${sx},${sy})">${inner}</g>`;
37
37
  }
38
- function createCustomShapeItem(id, bounds, content) {
38
+ function createCustomShapeItem(id, bounds, content, options = {}) {
39
39
  const r = normalizeRect(bounds);
40
40
  const intrinsic = { width: r.width, height: r.height };
41
41
  const inner = resolveCustomInner(content, intrinsic);
@@ -47,6 +47,8 @@ function createCustomShapeItem(id, bounds, content) {
47
47
  toolKind: "custom",
48
48
  customIntrinsicSize: intrinsic,
49
49
  customInnerSvg: inner,
50
+ ...options.resizeHandles !== void 0 ? { customResizeHandles: options.resizeHandles } : {},
51
+ ...options.svgClassName ? { svgClassName: options.svgClassName } : {},
50
52
  childrenSvg: buildCustomShapeChildrenSvg(inner, intrinsic, r)
51
53
  };
52
54
  }
@@ -1589,7 +1591,42 @@ var styles = StyleSheet.create({
1589
1591
  });
1590
1592
 
1591
1593
  // src/interaction/resize-handles.ts
1592
- var HANDLE_IDS = ["nw", "n", "ne", "e", "se", "s", "sw", "w"];
1594
+ var ALL_RESIZE_HANDLES = [
1595
+ "nw",
1596
+ "n",
1597
+ "ne",
1598
+ "e",
1599
+ "se",
1600
+ "s",
1601
+ "sw",
1602
+ "w"
1603
+ ];
1604
+ var CORNER_RESIZE_HANDLES = [
1605
+ "nw",
1606
+ "ne",
1607
+ "se",
1608
+ "sw"
1609
+ ];
1610
+ function dedupeHandles(handles) {
1611
+ const allowed = new Set(handles);
1612
+ return ALL_RESIZE_HANDLES.filter((handle) => allowed.has(handle));
1613
+ }
1614
+ function resolveCustomResizeHandles(handles) {
1615
+ if (handles === "corners") return CORNER_RESIZE_HANDLES;
1616
+ if (handles === "all" || handles === void 0) return ALL_RESIZE_HANDLES;
1617
+ return dedupeHandles(handles);
1618
+ }
1619
+ function resolveResizeHandlesForItem(item) {
1620
+ if (!item) return ALL_RESIZE_HANDLES;
1621
+ if (getLinkData(item)) return CORNER_RESIZE_HANDLES;
1622
+ if (item.toolKind === "custom") {
1623
+ return resolveCustomResizeHandles(item.customResizeHandles);
1624
+ }
1625
+ return ALL_RESIZE_HANDLES;
1626
+ }
1627
+ function itemAllowsResizeHandle(item, handle) {
1628
+ return resolveResizeHandlesForItem(item).includes(handle);
1629
+ }
1593
1630
  function getHandleWorldPosition(bounds, id) {
1594
1631
  const r = normalizeRect(bounds);
1595
1632
  const cx = r.x + r.width / 2;
@@ -1613,7 +1650,7 @@ function getHandleWorldPosition(bounds, id) {
1613
1650
  return { x: r.x, y: cy };
1614
1651
  }
1615
1652
  }
1616
- function hitTestResizeHandle(bounds, worldX, worldY, radiusWorld, rotationRad = 0) {
1653
+ function hitTestResizeHandle(bounds, worldX, worldY, radiusWorld, rotationRad = 0, handles = ALL_RESIZE_HANDLES) {
1617
1654
  const r = normalizeRect(bounds);
1618
1655
  const pl = worldToItemLocal(
1619
1656
  worldX,
@@ -1627,7 +1664,7 @@ function hitTestResizeHandle(bounds, worldX, worldY, radiusWorld, rotationRad =
1627
1664
  const localBounds2 = { x: 0, y: 0, width: r.width, height: r.height };
1628
1665
  let best = null;
1629
1666
  let bestD = radiusWorld;
1630
- for (const id of HANDLE_IDS) {
1667
+ for (const id of handles) {
1631
1668
  const p = getHandleWorldPosition(localBounds2, id);
1632
1669
  const d = Math.hypot(pl.x - p.x, pl.y - p.y);
1633
1670
  if (d <= bestD) {
@@ -3026,6 +3063,35 @@ function resolveNativeStrokePreviewStyle(tool, previewStrokeStyle) {
3026
3063
  };
3027
3064
  }
3028
3065
 
3066
+ // src/native/native-stroke-preview.ts
3067
+ var NATIVE_STROKE_PREVIEW_MAX_POINTS = 160;
3068
+ function sampleNativeStrokePreviewPoints(points, maxPoints = NATIVE_STROKE_PREVIEW_MAX_POINTS) {
3069
+ if (points.length <= maxPoints) return points.map((point) => ({ ...point }));
3070
+ if (maxPoints <= 1) {
3071
+ const last2 = points[points.length - 1];
3072
+ return last2 ? [{ ...last2 }] : [];
3073
+ }
3074
+ const lastIndex = points.length - 1;
3075
+ const last = points[lastIndex];
3076
+ if (!last) return [];
3077
+ const step = lastIndex / (maxPoints - 1);
3078
+ return Array.from({ length: maxPoints }, (_, index) => {
3079
+ const point = points[Math.round(index * step)] ?? last;
3080
+ return { x: point.x, y: point.y };
3081
+ });
3082
+ }
3083
+ function buildNativeStrokePreviewPath(points) {
3084
+ if (points.length < 2) return null;
3085
+ const d = smoothFreehandPointsToPathD(points);
3086
+ return d || null;
3087
+ }
3088
+ function nativeStrokePreviewDashArray(style, tool) {
3089
+ if (style.strokeDash !== "dashed" || tool !== "draw") return void 0;
3090
+ const dash = Math.max(style.strokeWidth * 1.8, 4);
3091
+ const gap = Math.max(style.strokeWidth * 1.4, 3);
3092
+ return `${dash} ${gap}`;
3093
+ }
3094
+
3029
3095
  // src/native/native-vector-interactions.ts
3030
3096
  var NATIVE_SELECTION_HANDLE_HIT_RADIUS_PX = 24;
3031
3097
  function nativeItemPlacementBounds(item) {
@@ -3075,7 +3141,8 @@ function hitTestNativeSelectionHandle({
3075
3141
  worldPoint.x,
3076
3142
  worldPoint.y,
3077
3143
  handleRadiusWorld,
3078
- rotation
3144
+ rotation,
3145
+ resolveResizeHandlesForItem(selectedItem)
3079
3146
  );
3080
3147
  return handle ? { kind: "resize", handle } : null;
3081
3148
  }
@@ -3111,7 +3178,6 @@ function nativeRotationDragStart(input) {
3111
3178
  startRotation: input.item.rotation ?? 0
3112
3179
  };
3113
3180
  }
3114
- var HANDLE_ORDER = ["nw", "n", "ne", "e", "se", "s", "sw", "w"];
3115
3181
  var ERASER_PREVIEW_OPACITY = 0.3;
3116
3182
  var OVERLAY_STROKE_PX = 1.25;
3117
3183
  var MARQUEE_DASH_PX = 4;
@@ -3200,7 +3266,7 @@ function NativeInteractionOverlay({
3200
3266
  return /* @__PURE__ */ jsx(Group, { transform: rotationTransform, origin: rotationOrigin, children: selectionRect }, it.id);
3201
3267
  }),
3202
3268
  showResizeHandles && bSingle && single && /* @__PURE__ */ jsxs(Fragment, { children: [
3203
- HANDLE_ORDER.map((hid) => {
3269
+ resolveResizeHandlesForItem(single).map((hid) => {
3204
3270
  const p = getHandleWorldPositionRotated(bSingle, hid, rotSingle);
3205
3271
  return /* @__PURE__ */ jsxs(Group, { children: [
3206
3272
  /* @__PURE__ */ jsx(
@@ -3397,58 +3463,42 @@ function NativeInteractionOverlay({
3397
3463
  p.tool,
3398
3464
  p.style ?? previewStrokeStyle
3399
3465
  );
3400
- const payload = computeFreehandSvgPayload(
3401
- p.points,
3402
- style,
3403
- isLaser ? "draw" : p.tool,
3404
- p.points.length === 2
3466
+ const strokeColor = colorWithOpacity(
3467
+ style.stroke,
3468
+ isLaser ? 0.85 : style.strokeOpacity
3405
3469
  );
3406
- if (!payload) return null;
3407
- if (payload.kind === "circle") {
3470
+ if (p.points.length === 1) {
3471
+ const point = p.points[0];
3472
+ if (!point) return null;
3408
3473
  return /* @__PURE__ */ jsx(
3409
3474
  Circle,
3410
3475
  {
3411
- cx: payload.cx,
3412
- cy: payload.cy,
3413
- r: payload.r,
3414
- color: colorWithOpacity(payload.fill, payload.fillOpacity),
3415
- style: "fill",
3416
- antiAlias: true
3417
- }
3418
- );
3419
- }
3420
- if (payload.kind === "fillPath") {
3421
- return /* @__PURE__ */ jsx(
3422
- Path,
3423
- {
3424
- path: payload.d,
3425
- color: colorWithOpacity(payload.fill, payload.fillOpacity),
3476
+ cx: point.x,
3477
+ cy: point.y,
3478
+ r: Math.max(0.5, style.strokeWidth / 2),
3479
+ color: strokeColor,
3426
3480
  style: "fill",
3427
- fillType: "winding",
3428
3481
  antiAlias: true
3429
3482
  }
3430
3483
  );
3431
3484
  }
3432
- if (payload.kind === "strokePath") {
3433
- const intervals = dashIntervalsFromStrokeDasharray3(payload.strokeDasharray);
3434
- return /* @__PURE__ */ jsx(
3435
- Path,
3436
- {
3437
- path: payload.d,
3438
- color: colorWithOpacity(
3439
- payload.stroke,
3440
- isLaser ? 0.85 : payload.strokeOpacity
3441
- ),
3442
- style: "stroke",
3443
- strokeWidth: payload.strokeWidth,
3444
- strokeCap: "round",
3445
- strokeJoin: "round",
3446
- antiAlias: true,
3447
- children: intervals ? /* @__PURE__ */ jsx(DashPathEffect, { intervals }) : null
3448
- }
3449
- );
3450
- }
3451
- return null;
3485
+ const path = buildNativeStrokePreviewPath(p.points);
3486
+ if (!path) return null;
3487
+ const strokeDasharray = nativeStrokePreviewDashArray(style, p.tool);
3488
+ const intervals = dashIntervalsFromStrokeDasharray3(strokeDasharray);
3489
+ return /* @__PURE__ */ jsx(
3490
+ Path,
3491
+ {
3492
+ path,
3493
+ color: strokeColor,
3494
+ style: "stroke",
3495
+ strokeWidth: style.strokeWidth,
3496
+ strokeCap: "round",
3497
+ strokeJoin: "round",
3498
+ antiAlias: true,
3499
+ children: intervals ? /* @__PURE__ */ jsx(DashPathEffect, { intervals }) : null
3500
+ }
3501
+ );
3452
3502
  }
3453
3503
  return null;
3454
3504
  }, [placementPreview, previewStrokeStyle, overlayStrokeWorld, marqueeDashWorld]);
@@ -5013,6 +5063,9 @@ function applyRotationFromPointer(item, startRotation, startPointerAngleRad, poi
5013
5063
  }
5014
5064
  function resizeItemByHandle(item, start, handle, currentWorld) {
5015
5065
  const sb = normalizeRect(start.bounds);
5066
+ if (!itemAllowsResizeHandle(item, handle)) {
5067
+ return item;
5068
+ }
5016
5069
  const newBoundsRaw = computeNewBoundsForResize(item, sb, handle, currentWorld);
5017
5070
  const nb = normalizeRect(newBoundsRaw);
5018
5071
  const k = item.toolKind;
@@ -5890,7 +5943,7 @@ var NativeVectorViewport = forwardRef(function NativeVectorViewport2({
5890
5943
  setRealtimePlacementPreview({
5891
5944
  kind: "stroke",
5892
5945
  tool: st.tool,
5893
- points: [...pts],
5946
+ points: sampleNativeStrokePreviewPoints(pts),
5894
5947
  style: { ...strokeStyleRef.current }
5895
5948
  });
5896
5949
  return;