canvu-react 0.3.39 → 0.4.0

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 (45) hide show
  1. package/dist/{asset-hydration-DowNdaOJ.d.cts → asset-hydration-B7yMDQE-.d.cts} +2 -2
  2. package/dist/{asset-hydration-DdFLdlqX.d.ts → asset-hydration-CbwQVAwh.d.ts} +2 -2
  3. package/dist/{camera-Di5R_Rwl.d.cts → camera-CVVG7z56.d.cts} +1 -1
  4. package/dist/{camera-AoTwBSoE.d.ts → camera-CoRYN_IV.d.ts} +1 -1
  5. package/dist/chatbot.d.cts +4 -4
  6. package/dist/chatbot.d.ts +4 -4
  7. package/dist/index.cjs +59 -15
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +6 -6
  10. package/dist/index.d.ts +6 -6
  11. package/dist/index.js +59 -15
  12. package/dist/index.js.map +1 -1
  13. package/dist/native.cjs +57 -14
  14. package/dist/native.cjs.map +1 -1
  15. package/dist/native.d.cts +2 -2
  16. package/dist/native.d.ts +2 -2
  17. package/dist/native.js +57 -14
  18. package/dist/native.js.map +1 -1
  19. package/dist/react.cjs +699 -255
  20. package/dist/react.cjs.map +1 -1
  21. package/dist/react.d.cts +10 -10
  22. package/dist/react.d.ts +10 -10
  23. package/dist/react.js +699 -255
  24. package/dist/react.js.map +1 -1
  25. package/dist/realtime.cjs +498 -129
  26. package/dist/realtime.cjs.map +1 -1
  27. package/dist/realtime.d.cts +6 -6
  28. package/dist/realtime.d.ts +6 -6
  29. package/dist/realtime.js +479 -129
  30. package/dist/realtime.js.map +1 -1
  31. package/dist/{shape-builders-Dedcl6tw.d.cts → shape-builders-BAWu-PxX.d.cts} +7 -3
  32. package/dist/{shape-builders-C7bxJBGR.d.ts → shape-builders-ClKv9tz9.d.ts} +7 -3
  33. package/dist/tldraw.cjs +56 -14
  34. package/dist/tldraw.cjs.map +1 -1
  35. package/dist/tldraw.d.cts +1 -1
  36. package/dist/tldraw.d.ts +1 -1
  37. package/dist/tldraw.js +56 -14
  38. package/dist/tldraw.js.map +1 -1
  39. package/dist/{types-DUW61Tjy.d.cts → types-BC9Xgfu6.d.cts} +11 -6
  40. package/dist/{types-Bnq2HtHQ.d.cts → types-BCCvY6ie.d.cts} +2 -0
  41. package/dist/{types-Bnq2HtHQ.d.ts → types-BCCvY6ie.d.ts} +2 -0
  42. package/dist/{types-B2Na677H.d.cts → types-BUPc2Zgw.d.cts} +1 -1
  43. package/dist/{types-zmUah-vP.d.ts → types-CYtq9Pr9.d.ts} +1 -1
  44. package/dist/{types-BBb8KoyW.d.ts → types-DlSVGX0w.d.ts} +11 -6
  45. package/package.json +3 -2
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as Camera2D } from './camera-Di5R_Rwl.cjs';
2
- export { a as Camera2DOptions } from './camera-Di5R_Rwl.cjs';
3
- import { V as VectorSceneItem, A as ArrowEndpointBinding, R as Rect } from './types-Bnq2HtHQ.cjs';
4
- export { a as ArrowBindings, b as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-Bnq2HtHQ.cjs';
5
- export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-DowNdaOJ.cjs';
6
- export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, a as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, L as LINK_PLUGIN_KEY, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildLinkCardSvg, k as buildRectSvg, l as computeFreehandSvgPayload, m as createArchitecturalCloudItem, n as createDrawDotItem, o as createEllipseItem, p as createFreehandStrokeItem, q as createImageFromVectorTrace, r as createImageItem, s as createLineItem, t as createLinkItem, u as createRectangleItem, v as createShapeId, w as createTextItem, x as getLinkData, y as isLinkItem, z as lineEndpointsToLocal, A as rebuildItemSvg, B as resolveStrokeStyle } from './shape-builders-Dedcl6tw.cjs';
1
+ import { C as Camera2D } from './camera-CVVG7z56.cjs';
2
+ export { a as Camera2DOptions } from './camera-CVVG7z56.cjs';
3
+ import { V as VectorSceneItem, A as ArrowEndpointBinding, R as Rect } from './types-BCCvY6ie.cjs';
4
+ export { a as ArrowBindings, b as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-BCCvY6ie.cjs';
5
+ export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-B7yMDQE-.cjs';
6
+ export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, a as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, L as LINK_PLUGIN_KEY, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildLinkCardSvg, k as buildRectSvg, l as computeFreehandSvgPayload, m as createArchitecturalCloudItem, n as createDrawDotItem, o as createEllipseItem, p as createFreehandStrokeItem, q as createImageFromVectorTrace, r as createImageItem, s as createLineItem, t as createLinkItem, u as createRectangleItem, v as createShapeId, w as createTextItem, x as getLinkData, y as isLinkItem, z as lineEndpointsToLocal, A as rebuildItemSvg, B as resolveStrokeStyle } from './shape-builders-BAWu-PxX.cjs';
7
7
 
8
8
  type EncodeCanvasToBlobOptions = {
9
9
  mimeType?: string;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { C as Camera2D } from './camera-AoTwBSoE.js';
2
- export { a as Camera2DOptions } from './camera-AoTwBSoE.js';
3
- import { V as VectorSceneItem, A as ArrowEndpointBinding, R as Rect } from './types-Bnq2HtHQ.js';
4
- export { a as ArrowBindings, b as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-Bnq2HtHQ.js';
5
- export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-DdFLdlqX.js';
6
- export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, a as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, L as LINK_PLUGIN_KEY, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildLinkCardSvg, k as buildRectSvg, l as computeFreehandSvgPayload, m as createArchitecturalCloudItem, n as createDrawDotItem, o as createEllipseItem, p as createFreehandStrokeItem, q as createImageFromVectorTrace, r as createImageItem, s as createLineItem, t as createLinkItem, u as createRectangleItem, v as createShapeId, w as createTextItem, x as getLinkData, y as isLinkItem, z as lineEndpointsToLocal, A as rebuildItemSvg, B as resolveStrokeStyle } from './shape-builders-C7bxJBGR.js';
1
+ import { C as Camera2D } from './camera-CoRYN_IV.js';
2
+ export { a as Camera2DOptions } from './camera-CoRYN_IV.js';
3
+ import { V as VectorSceneItem, A as ArrowEndpointBinding, R as Rect } from './types-BCCvY6ie.js';
4
+ export { a as ArrowBindings, b as VectorPathPoint, n as normalizeRect, r as rectsIntersect } from './types-BCCvY6ie.js';
5
+ export { H as HydratedSceneItemsWithAssetsResult, h as hydrateSceneItemsWithAssets } from './asset-hydration-CbwQVAwh.js';
6
+ export { C as CanvuLinkData, D as DEFAULT_LINK_CARD_SIZE, a as DEFAULT_STROKE_STYLE, F as FreehandSvgPayload, L as LINK_PLUGIN_KEY, S as StrokeStyle, b as applyStrokeToItem, c as buildArchitecturalCloudPathD, d as buildArchitecturalCloudSvg, e as buildArrowSvg, f as buildDrawDotSvg, g as buildEllipseSvg, h as buildFreehandPathSvg, i as buildLineSvg, j as buildLinkCardSvg, k as buildRectSvg, l as computeFreehandSvgPayload, m as createArchitecturalCloudItem, n as createDrawDotItem, o as createEllipseItem, p as createFreehandStrokeItem, q as createImageFromVectorTrace, r as createImageItem, s as createLineItem, t as createLinkItem, u as createRectangleItem, v as createShapeId, w as createTextItem, x as getLinkData, y as isLinkItem, z as lineEndpointsToLocal, A as rebuildItemSvg, B as resolveStrokeStyle } from './shape-builders-ClKv9tz9.js';
7
7
 
8
8
  type EncodeCanvasToBlobOptions = {
9
9
  mimeType?: string;
package/dist/index.js CHANGED
@@ -991,11 +991,14 @@ function escapeHtmlText(s) {
991
991
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
992
992
  }
993
993
  var DEFAULT_TEXT_FONT_SIZE = 18;
994
+ var TEXT_FONT_FAMILY = "Inter, -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif";
994
995
  var LINE_HEIGHT_RATIO = 22 / 18;
995
- var FIRST_LINE_BASELINE_RATIO = 24 / 18;
996
+ var FIRST_LINE_BASELINE_RATIO = 20 / 18;
997
+ var EDIT_TOP_PAD_RATIO = 4 / 18;
998
+ var BOTTOM_PAD_RATIO = 4 / 18;
996
999
  var PLACEHOLDER = "Tap to type";
997
1000
  var MIN_TEXT_BOX_W = 40;
998
- var MIN_TEXT_BOX_H = 36;
1001
+ var MIN_TEXT_BOX_H = 26;
999
1002
  var TEXT_PAD_X = 4;
1000
1003
  var MAX_TEXT_MEASURE_CACHE_ENTRIES = 2e3;
1001
1004
  var sharedMeasureContext;
@@ -1041,7 +1044,7 @@ function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
1041
1044
  let maxInnerW = 0;
1042
1045
  const ctx = getSharedMeasureContext();
1043
1046
  if (ctx) {
1044
- ctx.font = `${fontSize}px system-ui, sans-serif`;
1047
+ ctx.font = `${fontSize}px ${TEXT_FONT_FAMILY}`;
1045
1048
  for (const line of lines) {
1046
1049
  const toMeasure = trimmed.length === 0 ? PLACEHOLDER : line.length === 0 ? " " : line;
1047
1050
  maxInnerW = Math.max(maxInnerW, ctx.measureText(toMeasure).width);
@@ -1057,22 +1060,22 @@ function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
1057
1060
  const width = Math.max(minW, TEXT_PAD_X * 2 + maxInnerW);
1058
1061
  const height = Math.max(
1059
1062
  MIN_TEXT_BOX_H,
1060
- baselineY + (lines.length - 1) * lh + Math.max(8, fontSize * 0.35)
1063
+ baselineY + (lines.length - 1) * lh + Math.max(4, fontSize * BOTTOM_PAD_RATIO)
1061
1064
  );
1062
1065
  const measured = { width, height };
1063
1066
  cacheMeasuredBounds(cacheKey, measured);
1064
1067
  return measured;
1065
1068
  }
1066
- function buildTextSvg(content, _width, _height, fillColor = "#2563eb", fontSize = DEFAULT_TEXT_FONT_SIZE) {
1069
+ function buildTextSvg(content, _width, _height, fillColor = "#1d1d1d", fontSize = DEFAULT_TEXT_FONT_SIZE) {
1067
1070
  const lh = lineHeightFor(fontSize);
1068
1071
  const y0 = firstLineBaselineY(fontSize);
1069
1072
  const trimmed = content.trim();
1070
1073
  if (trimmed.length === 0) {
1071
- return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="system-ui,sans-serif" fill="#94a3b8" font-style="italic">${escapeSvgTextContent(PLACEHOLDER)}</text>`;
1074
+ return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="#94a3b8" font-style="italic">${escapeSvgTextContent(PLACEHOLDER)}</text>`;
1072
1075
  }
1073
1076
  const lines = content.split("\n");
1074
1077
  if (lines.length === 1) {
1075
- return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="system-ui,sans-serif" fill="${fillColor}">${escapeSvgTextContent(lines[0] ?? "")}</text>`;
1078
+ return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="${fillColor}">${escapeSvgTextContent(lines[0] ?? "")}</text>`;
1076
1079
  }
1077
1080
  const parts = [];
1078
1081
  for (let i = 0; i < lines.length; i++) {
@@ -1083,23 +1086,24 @@ function buildTextSvg(content, _width, _height, fillColor = "#2563eb", fontSize
1083
1086
  parts.push(`<tspan x="4" dy="${lh}">${escapeSvgTextContent(line)}</tspan>`);
1084
1087
  }
1085
1088
  }
1086
- return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="system-ui,sans-serif" fill="${fillColor}">${parts.join("")}</text>`;
1089
+ return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="${fillColor}">${parts.join("")}</text>`;
1087
1090
  }
1088
- function buildTextFixedBoundsSvg(content, width, height, fillColor = "#2563eb", fontSize = DEFAULT_TEXT_FONT_SIZE) {
1091
+ function buildTextFixedBoundsSvg(content, width, height, fillColor = "#1d1d1d", fontSize = DEFAULT_TEXT_FONT_SIZE) {
1089
1092
  const w = Math.max(1, width);
1090
1093
  const h = Math.max(1, height);
1091
1094
  const lh = lineHeightFor(fontSize);
1092
1095
  const trimmed = content.trim();
1096
+ const padTop = EDIT_TOP_PAD_RATIO * fontSize;
1093
1097
  if (trimmed.length === 0) {
1094
- return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:2px 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:system-ui,sans-serif;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:#94a3b8;font-style:italic">${escapeHtmlText(PLACEHOLDER)}</div></foreignObject>`;
1098
+ return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:${padTop}px 4px 0 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:${TEXT_FONT_FAMILY};white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:#94a3b8;font-style:italic">${escapeHtmlText(PLACEHOLDER)}</div></foreignObject>`;
1095
1099
  }
1096
1100
  const body = escapeHtmlText(content);
1097
- return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:2px 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:system-ui,sans-serif;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:${fillColor}">${body}</div></foreignObject>`;
1101
+ return `<foreignObject width="${w}" height="${h}"><div xmlns="http://www.w3.org/1999/xhtml" style="box-sizing:border-box;width:100%;height:100%;margin:0;padding:${padTop}px 4px 0 4px;font-size:${fontSize}px;line-height:${lh}px;font-family:${TEXT_FONT_FAMILY};white-space:pre-wrap;word-wrap:break-word;overflow:hidden;color:${fillColor}">${body}</div></foreignObject>`;
1098
1102
  }
1099
1103
 
1100
1104
  // src/scene/shape-builders.ts
1101
1105
  var DEFAULT_STROKE_STYLE = {
1102
- stroke: "#2563eb",
1106
+ stroke: "#1d1d1d",
1103
1107
  strokeWidth: 2
1104
1108
  };
1105
1109
  var TOOL_FREEHAND_DEFAULTS = {
@@ -1156,7 +1160,8 @@ function resolveStrokeStyle(item) {
1156
1160
  return {
1157
1161
  stroke: item.stroke ?? DEFAULT_STROKE_STYLE.stroke,
1158
1162
  strokeWidth: item.strokeWidth ?? DEFAULT_STROKE_STYLE.strokeWidth,
1159
- strokeOpacity: item.strokeOpacity
1163
+ strokeOpacity: item.strokeOpacity,
1164
+ strokeDash: item.strokeDash
1160
1165
  };
1161
1166
  }
1162
1167
  function strokeOpacityAttr(style) {
@@ -1485,6 +1490,30 @@ function buildDrawDotSvg(r, style = DEFAULT_STROKE_STYLE) {
1485
1490
  const op = style.strokeOpacity != null ? ` fill-opacity="${style.strokeOpacity}"` : "";
1486
1491
  return `<circle cx="${r}" cy="${r}" r="${r}" fill="${style.stroke}" shape-rendering="geometricPrecision"${op} />`;
1487
1492
  }
1493
+ function dashArrayForDrawStroke(strokeWidth) {
1494
+ const dash = Math.max(strokeWidth * 1.8, 4);
1495
+ const gap = Math.max(strokeWidth * 1.4, 3);
1496
+ return `${dash} ${gap}`;
1497
+ }
1498
+ function buildSmoothedCenterlinePath(points) {
1499
+ if (points.length < 2) return null;
1500
+ const first = points[0];
1501
+ if (!first) return null;
1502
+ let d = `M ${first.x} ${first.y}`;
1503
+ for (let i = 1; i < points.length - 1; i++) {
1504
+ const a = points[i];
1505
+ const b = points[i + 1];
1506
+ if (!a || !b) continue;
1507
+ const midX = (a.x + b.x) / 2;
1508
+ const midY = (a.y + b.y) / 2;
1509
+ d += ` Q ${a.x} ${a.y} ${midX} ${midY}`;
1510
+ }
1511
+ const last = points[points.length - 1];
1512
+ if (last) {
1513
+ d += ` L ${last.x} ${last.y}`;
1514
+ }
1515
+ return d;
1516
+ }
1488
1517
  function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeComplete = true) {
1489
1518
  if (pathPointsLocal.length === 0) return null;
1490
1519
  if (pathPointsLocal.length === 1) {
@@ -1499,6 +1528,18 @@ function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeCompl
1499
1528
  fillOpacity: style.strokeOpacity
1500
1529
  };
1501
1530
  }
1531
+ if (style.strokeDash === "dashed" && (toolKind === "draw" || toolKind === "pencil")) {
1532
+ const d2 = buildSmoothedCenterlinePath(pathPointsLocal);
1533
+ if (!d2) return null;
1534
+ return {
1535
+ kind: "strokePath",
1536
+ d: d2,
1537
+ stroke: style.stroke,
1538
+ strokeWidth: style.strokeWidth,
1539
+ strokeOpacity: style.strokeOpacity,
1540
+ strokeDasharray: dashArrayForDrawStroke(style.strokeWidth)
1541
+ };
1542
+ }
1502
1543
  const hasPressure = pathPointsLocal.some(
1503
1544
  (p) => p.pressure != null && Number.isFinite(p.pressure)
1504
1545
  );
@@ -1541,7 +1582,8 @@ function freehandPayloadToSvgString(payload) {
1541
1582
  strokeWidth: payload.strokeWidth,
1542
1583
  strokeOpacity: payload.strokeOpacity
1543
1584
  });
1544
- return `<path d="${payload.d}" fill="none" stroke="${payload.stroke}" stroke-width="${payload.strokeWidth}" stroke-linecap="round" stroke-linejoin="round" shape-rendering="geometricPrecision"${op} />`;
1585
+ const dash = payload.strokeDasharray ? ` stroke-dasharray="${payload.strokeDasharray}"` : "";
1586
+ return `<path d="${payload.d}" fill="none" stroke="${payload.stroke}" stroke-width="${payload.strokeWidth}" stroke-linecap="round" stroke-linejoin="round" shape-rendering="geometricPrecision"${op}${dash} />`;
1545
1587
  }
1546
1588
  function buildFreehandPathSvg(pathPointsLocal, style, toolKind, strokeComplete = true) {
1547
1589
  const payload = computeFreehandSvgPayload(
@@ -1753,7 +1795,7 @@ function createDrawDotItem(id, worldX, worldY, radius, style) {
1753
1795
  childrenSvg: ""
1754
1796
  });
1755
1797
  }
1756
- function createTextItem(id, bounds, text = "", style) {
1798
+ function createTextItem(id, bounds, text = "", style, textFontSize) {
1757
1799
  const r = normalizeRect(bounds);
1758
1800
  const s = { ...DEFAULT_STROKE_STYLE, ...style };
1759
1801
  return rebuildItemSvg({
@@ -1766,6 +1808,7 @@ function createTextItem(id, bounds, text = "", style) {
1766
1808
  stroke: s.stroke,
1767
1809
  strokeWidth: s.strokeWidth,
1768
1810
  ...s.strokeOpacity != null ? { strokeOpacity: s.strokeOpacity } : {},
1811
+ ...textFontSize != null ? { textFontSize } : {},
1769
1812
  childrenSvg: ""
1770
1813
  });
1771
1814
  }
@@ -1802,6 +1845,7 @@ function createFreehandStrokeItem(id, pointsWorld, toolKind, style) {
1802
1845
  stroke: merged.stroke,
1803
1846
  strokeWidth: merged.strokeWidth,
1804
1847
  ...merged.strokeOpacity != null ? { strokeOpacity: merged.strokeOpacity } : {},
1848
+ ...merged.strokeDash != null ? { strokeDash: merged.strokeDash } : {},
1805
1849
  pathPointsLocal,
1806
1850
  childrenSvg: ""
1807
1851
  });