canvu-react 0.3.38 → 0.3.40
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/{asset-hydration-EtEuBwb7.d.cts → asset-hydration-B7yMDQE-.d.cts} +2 -2
- package/dist/{asset-hydration-DrTOgDdd.d.ts → asset-hydration-CbwQVAwh.d.ts} +2 -2
- package/dist/{camera-Di5R_Rwl.d.cts → camera-CVVG7z56.d.cts} +1 -1
- package/dist/{camera-AoTwBSoE.d.ts → camera-CoRYN_IV.d.ts} +1 -1
- package/dist/chatbot.d.cts +4 -4
- package/dist/chatbot.d.ts +4 -4
- package/dist/index.cjs +164 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +159 -16
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +57 -14
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.cts +2 -2
- package/dist/native.d.ts +2 -2
- package/dist/native.js +57 -14
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +731 -258
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +10 -10
- package/dist/react.d.ts +10 -10
- package/dist/react.js +731 -258
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +36 -0
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +6 -6
- package/dist/realtime.d.ts +6 -6
- package/dist/realtime.js +36 -0
- package/dist/realtime.js.map +1 -1
- package/dist/{shape-builders-CsbSRZnQ.d.cts → shape-builders-BAWu-PxX.d.cts} +46 -4
- package/dist/{shape-builders-CsSXKCcs.d.ts → shape-builders-ClKv9tz9.d.ts} +46 -4
- package/dist/tldraw.cjs +189 -78
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.d.cts +1 -1
- package/dist/tldraw.d.ts +1 -1
- package/dist/tldraw.js +189 -78
- package/dist/tldraw.js.map +1 -1
- package/dist/{types-DWGk2_GZ.d.cts → types-BC9Xgfu6.d.cts} +20 -6
- package/dist/{types-Bnq2HtHQ.d.cts → types-BCCvY6ie.d.cts} +2 -0
- package/dist/{types-Bnq2HtHQ.d.ts → types-BCCvY6ie.d.ts} +2 -0
- package/dist/{types-B2Na677H.d.cts → types-BUPc2Zgw.d.cts} +1 -1
- package/dist/{types-zmUah-vP.d.ts → types-CYtq9Pr9.d.ts} +1 -1
- package/dist/{types-B6PAYKzx.d.ts → types-DlSVGX0w.d.ts} +20 -6
- package/package.json +1 -1
package/dist/native.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { C as Camera2D } from './camera-
|
|
3
|
-
import { V as VectorSceneItem, R as Rect } from './types-
|
|
2
|
+
import { C as Camera2D } from './camera-CVVG7z56.cjs';
|
|
3
|
+
import { V as VectorSceneItem, R as Rect } from './types-BCCvY6ie.cjs';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
|
|
6
6
|
type PlacementPreview = {
|
package/dist/native.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { C as Camera2D } from './camera-
|
|
3
|
-
import { V as VectorSceneItem, R as Rect } from './types-
|
|
2
|
+
import { C as Camera2D } from './camera-CoRYN_IV.js';
|
|
3
|
+
import { V as VectorSceneItem, R as Rect } from './types-BCCvY6ie.js';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
|
|
6
6
|
type PlacementPreview = {
|
package/dist/native.js
CHANGED
|
@@ -172,11 +172,14 @@ function escapeHtmlText(s) {
|
|
|
172
172
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
173
173
|
}
|
|
174
174
|
var DEFAULT_TEXT_FONT_SIZE = 18;
|
|
175
|
+
var TEXT_FONT_FAMILY = "Inter, -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif";
|
|
175
176
|
var LINE_HEIGHT_RATIO = 22 / 18;
|
|
176
|
-
var FIRST_LINE_BASELINE_RATIO =
|
|
177
|
+
var FIRST_LINE_BASELINE_RATIO = 20 / 18;
|
|
178
|
+
var EDIT_TOP_PAD_RATIO = 4 / 18;
|
|
179
|
+
var BOTTOM_PAD_RATIO = 4 / 18;
|
|
177
180
|
var PLACEHOLDER = "Tap to type";
|
|
178
181
|
var MIN_TEXT_BOX_W = 40;
|
|
179
|
-
var MIN_TEXT_BOX_H =
|
|
182
|
+
var MIN_TEXT_BOX_H = 26;
|
|
180
183
|
var TEXT_PAD_X = 4;
|
|
181
184
|
var MAX_TEXT_MEASURE_CACHE_ENTRIES = 2e3;
|
|
182
185
|
var sharedMeasureContext;
|
|
@@ -222,7 +225,7 @@ function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
|
222
225
|
let maxInnerW = 0;
|
|
223
226
|
const ctx = getSharedMeasureContext();
|
|
224
227
|
if (ctx) {
|
|
225
|
-
ctx.font = `${fontSize}px
|
|
228
|
+
ctx.font = `${fontSize}px ${TEXT_FONT_FAMILY}`;
|
|
226
229
|
for (const line of lines) {
|
|
227
230
|
const toMeasure = trimmed.length === 0 ? PLACEHOLDER : line.length === 0 ? " " : line;
|
|
228
231
|
maxInnerW = Math.max(maxInnerW, ctx.measureText(toMeasure).width);
|
|
@@ -238,22 +241,22 @@ function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
|
238
241
|
const width = Math.max(minW, TEXT_PAD_X * 2 + maxInnerW);
|
|
239
242
|
const height = Math.max(
|
|
240
243
|
MIN_TEXT_BOX_H,
|
|
241
|
-
baselineY + (lines.length - 1) * lh + Math.max(
|
|
244
|
+
baselineY + (lines.length - 1) * lh + Math.max(4, fontSize * BOTTOM_PAD_RATIO)
|
|
242
245
|
);
|
|
243
246
|
const measured = { width, height };
|
|
244
247
|
cacheMeasuredBounds(cacheKey, measured);
|
|
245
248
|
return measured;
|
|
246
249
|
}
|
|
247
|
-
function buildTextSvg(content, _width, _height, fillColor = "#
|
|
250
|
+
function buildTextSvg(content, _width, _height, fillColor = "#1d1d1d", fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
248
251
|
const lh = lineHeightFor(fontSize);
|
|
249
252
|
const y0 = firstLineBaselineY(fontSize);
|
|
250
253
|
const trimmed = content.trim();
|
|
251
254
|
if (trimmed.length === 0) {
|
|
252
|
-
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="
|
|
255
|
+
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="#94a3b8" font-style="italic">${escapeSvgTextContent(PLACEHOLDER)}</text>`;
|
|
253
256
|
}
|
|
254
257
|
const lines = content.split("\n");
|
|
255
258
|
if (lines.length === 1) {
|
|
256
|
-
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="
|
|
259
|
+
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="${fillColor}">${escapeSvgTextContent(lines[0] ?? "")}</text>`;
|
|
257
260
|
}
|
|
258
261
|
const parts = [];
|
|
259
262
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -264,23 +267,24 @@ function buildTextSvg(content, _width, _height, fillColor = "#2563eb", fontSize
|
|
|
264
267
|
parts.push(`<tspan x="4" dy="${lh}">${escapeSvgTextContent(line)}</tspan>`);
|
|
265
268
|
}
|
|
266
269
|
}
|
|
267
|
-
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="
|
|
270
|
+
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="${fillColor}">${parts.join("")}</text>`;
|
|
268
271
|
}
|
|
269
|
-
function buildTextFixedBoundsSvg(content, width, height, fillColor = "#
|
|
272
|
+
function buildTextFixedBoundsSvg(content, width, height, fillColor = "#1d1d1d", fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
270
273
|
const w = Math.max(1, width);
|
|
271
274
|
const h = Math.max(1, height);
|
|
272
275
|
const lh = lineHeightFor(fontSize);
|
|
273
276
|
const trimmed = content.trim();
|
|
277
|
+
const padTop = EDIT_TOP_PAD_RATIO * fontSize;
|
|
274
278
|
if (trimmed.length === 0) {
|
|
275
|
-
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
|
|
279
|
+
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>`;
|
|
276
280
|
}
|
|
277
281
|
const body = escapeHtmlText(content);
|
|
278
|
-
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
|
|
282
|
+
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>`;
|
|
279
283
|
}
|
|
280
284
|
|
|
281
285
|
// src/scene/shape-builders.ts
|
|
282
286
|
var DEFAULT_STROKE_STYLE = {
|
|
283
|
-
stroke: "#
|
|
287
|
+
stroke: "#1d1d1d",
|
|
284
288
|
strokeWidth: 2
|
|
285
289
|
};
|
|
286
290
|
var TOOL_FREEHAND_DEFAULTS = {
|
|
@@ -337,7 +341,8 @@ function resolveStrokeStyle(item) {
|
|
|
337
341
|
return {
|
|
338
342
|
stroke: item.stroke ?? DEFAULT_STROKE_STYLE.stroke,
|
|
339
343
|
strokeWidth: item.strokeWidth ?? DEFAULT_STROKE_STYLE.strokeWidth,
|
|
340
|
-
strokeOpacity: item.strokeOpacity
|
|
344
|
+
strokeOpacity: item.strokeOpacity,
|
|
345
|
+
strokeDash: item.strokeDash
|
|
341
346
|
};
|
|
342
347
|
}
|
|
343
348
|
function strokeOpacityAttr(style) {
|
|
@@ -666,6 +671,30 @@ function buildDrawDotSvg(r, style = DEFAULT_STROKE_STYLE) {
|
|
|
666
671
|
const op = style.strokeOpacity != null ? ` fill-opacity="${style.strokeOpacity}"` : "";
|
|
667
672
|
return `<circle cx="${r}" cy="${r}" r="${r}" fill="${style.stroke}" shape-rendering="geometricPrecision"${op} />`;
|
|
668
673
|
}
|
|
674
|
+
function dashArrayForDrawStroke(strokeWidth) {
|
|
675
|
+
const dash = Math.max(strokeWidth * 1.8, 4);
|
|
676
|
+
const gap = Math.max(strokeWidth * 1.4, 3);
|
|
677
|
+
return `${dash} ${gap}`;
|
|
678
|
+
}
|
|
679
|
+
function buildSmoothedCenterlinePath(points) {
|
|
680
|
+
if (points.length < 2) return null;
|
|
681
|
+
const first = points[0];
|
|
682
|
+
if (!first) return null;
|
|
683
|
+
let d = `M ${first.x} ${first.y}`;
|
|
684
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
685
|
+
const a = points[i];
|
|
686
|
+
const b = points[i + 1];
|
|
687
|
+
if (!a || !b) continue;
|
|
688
|
+
const midX = (a.x + b.x) / 2;
|
|
689
|
+
const midY = (a.y + b.y) / 2;
|
|
690
|
+
d += ` Q ${a.x} ${a.y} ${midX} ${midY}`;
|
|
691
|
+
}
|
|
692
|
+
const last = points[points.length - 1];
|
|
693
|
+
if (last) {
|
|
694
|
+
d += ` L ${last.x} ${last.y}`;
|
|
695
|
+
}
|
|
696
|
+
return d;
|
|
697
|
+
}
|
|
669
698
|
function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeComplete = true) {
|
|
670
699
|
if (pathPointsLocal.length === 0) return null;
|
|
671
700
|
if (pathPointsLocal.length === 1) {
|
|
@@ -680,6 +709,18 @@ function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeCompl
|
|
|
680
709
|
fillOpacity: style.strokeOpacity
|
|
681
710
|
};
|
|
682
711
|
}
|
|
712
|
+
if (style.strokeDash === "dashed" && (toolKind === "draw" || toolKind === "pencil")) {
|
|
713
|
+
const d2 = buildSmoothedCenterlinePath(pathPointsLocal);
|
|
714
|
+
if (!d2) return null;
|
|
715
|
+
return {
|
|
716
|
+
kind: "strokePath",
|
|
717
|
+
d: d2,
|
|
718
|
+
stroke: style.stroke,
|
|
719
|
+
strokeWidth: style.strokeWidth,
|
|
720
|
+
strokeOpacity: style.strokeOpacity,
|
|
721
|
+
strokeDasharray: dashArrayForDrawStroke(style.strokeWidth)
|
|
722
|
+
};
|
|
723
|
+
}
|
|
683
724
|
const hasPressure = pathPointsLocal.some(
|
|
684
725
|
(p) => p.pressure != null && Number.isFinite(p.pressure)
|
|
685
726
|
);
|
|
@@ -722,7 +763,8 @@ function freehandPayloadToSvgString(payload) {
|
|
|
722
763
|
strokeWidth: payload.strokeWidth,
|
|
723
764
|
strokeOpacity: payload.strokeOpacity
|
|
724
765
|
});
|
|
725
|
-
|
|
766
|
+
const dash = payload.strokeDasharray ? ` stroke-dasharray="${payload.strokeDasharray}"` : "";
|
|
767
|
+
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} />`;
|
|
726
768
|
}
|
|
727
769
|
function buildFreehandPathSvg(pathPointsLocal, style, toolKind, strokeComplete = true) {
|
|
728
770
|
const payload = computeFreehandSvgPayload(
|
|
@@ -874,6 +916,7 @@ function createFreehandStrokeItem(id, pointsWorld, toolKind, style) {
|
|
|
874
916
|
stroke: merged.stroke,
|
|
875
917
|
strokeWidth: merged.strokeWidth,
|
|
876
918
|
...merged.strokeOpacity != null ? { strokeOpacity: merged.strokeOpacity } : {},
|
|
919
|
+
...merged.strokeDash != null ? { strokeDash: merged.strokeDash } : {},
|
|
877
920
|
pathPointsLocal,
|
|
878
921
|
childrenSvg: ""
|
|
879
922
|
});
|