canvu-react 0.3.39 → 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-DowNdaOJ.d.cts → asset-hydration-B7yMDQE-.d.cts} +2 -2
- package/dist/{asset-hydration-DdFLdlqX.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 +59 -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 +59 -15
- 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 +699 -255
- 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 +699 -255
- 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-Dedcl6tw.d.cts → shape-builders-BAWu-PxX.d.cts} +7 -3
- package/dist/{shape-builders-C7bxJBGR.d.ts → shape-builders-ClKv9tz9.d.ts} +7 -3
- package/dist/tldraw.cjs +56 -14
- 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 +56 -14
- package/dist/tldraw.js.map +1 -1
- package/dist/{types-DUW61Tjy.d.cts → types-BC9Xgfu6.d.cts} +11 -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-BBb8KoyW.d.ts → types-DlSVGX0w.d.ts} +11 -6
- package/package.json +1 -1
package/dist/tldraw.d.cts
CHANGED
package/dist/tldraw.d.ts
CHANGED
package/dist/tldraw.js
CHANGED
|
@@ -117,11 +117,14 @@ function escapeHtmlText2(s) {
|
|
|
117
117
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
118
118
|
}
|
|
119
119
|
var DEFAULT_TEXT_FONT_SIZE = 18;
|
|
120
|
+
var TEXT_FONT_FAMILY = "Inter, -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif";
|
|
120
121
|
var LINE_HEIGHT_RATIO = 22 / 18;
|
|
121
|
-
var FIRST_LINE_BASELINE_RATIO =
|
|
122
|
+
var FIRST_LINE_BASELINE_RATIO = 20 / 18;
|
|
123
|
+
var EDIT_TOP_PAD_RATIO = 4 / 18;
|
|
124
|
+
var BOTTOM_PAD_RATIO = 4 / 18;
|
|
122
125
|
var PLACEHOLDER = "Tap to type";
|
|
123
126
|
var MIN_TEXT_BOX_W = 40;
|
|
124
|
-
var MIN_TEXT_BOX_H =
|
|
127
|
+
var MIN_TEXT_BOX_H = 26;
|
|
125
128
|
var TEXT_PAD_X = 4;
|
|
126
129
|
var MAX_TEXT_MEASURE_CACHE_ENTRIES = 2e3;
|
|
127
130
|
var sharedMeasureContext;
|
|
@@ -167,7 +170,7 @@ function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
|
167
170
|
let maxInnerW = 0;
|
|
168
171
|
const ctx = getSharedMeasureContext();
|
|
169
172
|
if (ctx) {
|
|
170
|
-
ctx.font = `${fontSize}px
|
|
173
|
+
ctx.font = `${fontSize}px ${TEXT_FONT_FAMILY}`;
|
|
171
174
|
for (const line of lines) {
|
|
172
175
|
const toMeasure = trimmed.length === 0 ? PLACEHOLDER : line.length === 0 ? " " : line;
|
|
173
176
|
maxInnerW = Math.max(maxInnerW, ctx.measureText(toMeasure).width);
|
|
@@ -183,22 +186,22 @@ function measureTextBoundsLocal(content, fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
|
183
186
|
const width = Math.max(minW, TEXT_PAD_X * 2 + maxInnerW);
|
|
184
187
|
const height = Math.max(
|
|
185
188
|
MIN_TEXT_BOX_H,
|
|
186
|
-
baselineY + (lines.length - 1) * lh + Math.max(
|
|
189
|
+
baselineY + (lines.length - 1) * lh + Math.max(4, fontSize * BOTTOM_PAD_RATIO)
|
|
187
190
|
);
|
|
188
191
|
const measured = { width, height };
|
|
189
192
|
cacheMeasuredBounds(cacheKey, measured);
|
|
190
193
|
return measured;
|
|
191
194
|
}
|
|
192
|
-
function buildTextSvg(content, _width, _height, fillColor = "#
|
|
195
|
+
function buildTextSvg(content, _width, _height, fillColor = "#1d1d1d", fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
193
196
|
const lh = lineHeightFor(fontSize);
|
|
194
197
|
const y0 = firstLineBaselineY(fontSize);
|
|
195
198
|
const trimmed = content.trim();
|
|
196
199
|
if (trimmed.length === 0) {
|
|
197
|
-
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="
|
|
200
|
+
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="#94a3b8" font-style="italic">${escapeSvgTextContent(PLACEHOLDER)}</text>`;
|
|
198
201
|
}
|
|
199
202
|
const lines = content.split("\n");
|
|
200
203
|
if (lines.length === 1) {
|
|
201
|
-
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="
|
|
204
|
+
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="${fillColor}">${escapeSvgTextContent(lines[0] ?? "")}</text>`;
|
|
202
205
|
}
|
|
203
206
|
const parts = [];
|
|
204
207
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -209,23 +212,24 @@ function buildTextSvg(content, _width, _height, fillColor = "#2563eb", fontSize
|
|
|
209
212
|
parts.push(`<tspan x="4" dy="${lh}">${escapeSvgTextContent(line)}</tspan>`);
|
|
210
213
|
}
|
|
211
214
|
}
|
|
212
|
-
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="
|
|
215
|
+
return `<text x="4" y="${y0}" font-size="${fontSize}" font-family="${TEXT_FONT_FAMILY}" fill="${fillColor}">${parts.join("")}</text>`;
|
|
213
216
|
}
|
|
214
|
-
function buildTextFixedBoundsSvg(content, width, height, fillColor = "#
|
|
217
|
+
function buildTextFixedBoundsSvg(content, width, height, fillColor = "#1d1d1d", fontSize = DEFAULT_TEXT_FONT_SIZE) {
|
|
215
218
|
const w = Math.max(1, width);
|
|
216
219
|
const h = Math.max(1, height);
|
|
217
220
|
const lh = lineHeightFor(fontSize);
|
|
218
221
|
const trimmed = content.trim();
|
|
222
|
+
const padTop = EDIT_TOP_PAD_RATIO * fontSize;
|
|
219
223
|
if (trimmed.length === 0) {
|
|
220
|
-
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
|
|
224
|
+
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">${escapeHtmlText2(PLACEHOLDER)}</div></foreignObject>`;
|
|
221
225
|
}
|
|
222
226
|
const body = escapeHtmlText2(content);
|
|
223
|
-
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
|
|
227
|
+
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>`;
|
|
224
228
|
}
|
|
225
229
|
|
|
226
230
|
// src/scene/shape-builders.ts
|
|
227
231
|
var DEFAULT_STROKE_STYLE = {
|
|
228
|
-
stroke: "#
|
|
232
|
+
stroke: "#1d1d1d",
|
|
229
233
|
strokeWidth: 2
|
|
230
234
|
};
|
|
231
235
|
function perfectFreehandOptions(toolKind, style, strokeComplete, pressureAware = false) {
|
|
@@ -276,7 +280,8 @@ function resolveStrokeStyle(item) {
|
|
|
276
280
|
return {
|
|
277
281
|
stroke: item.stroke ?? DEFAULT_STROKE_STYLE.stroke,
|
|
278
282
|
strokeWidth: item.strokeWidth ?? DEFAULT_STROKE_STYLE.strokeWidth,
|
|
279
|
-
strokeOpacity: item.strokeOpacity
|
|
283
|
+
strokeOpacity: item.strokeOpacity,
|
|
284
|
+
strokeDash: item.strokeDash
|
|
280
285
|
};
|
|
281
286
|
}
|
|
282
287
|
function strokeOpacityAttr(style) {
|
|
@@ -605,6 +610,30 @@ function buildDrawDotSvg(r, style = DEFAULT_STROKE_STYLE) {
|
|
|
605
610
|
const op = style.strokeOpacity != null ? ` fill-opacity="${style.strokeOpacity}"` : "";
|
|
606
611
|
return `<circle cx="${r}" cy="${r}" r="${r}" fill="${style.stroke}" shape-rendering="geometricPrecision"${op} />`;
|
|
607
612
|
}
|
|
613
|
+
function dashArrayForDrawStroke(strokeWidth) {
|
|
614
|
+
const dash = Math.max(strokeWidth * 1.8, 4);
|
|
615
|
+
const gap = Math.max(strokeWidth * 1.4, 3);
|
|
616
|
+
return `${dash} ${gap}`;
|
|
617
|
+
}
|
|
618
|
+
function buildSmoothedCenterlinePath(points) {
|
|
619
|
+
if (points.length < 2) return null;
|
|
620
|
+
const first = points[0];
|
|
621
|
+
if (!first) return null;
|
|
622
|
+
let d = `M ${first.x} ${first.y}`;
|
|
623
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
624
|
+
const a = points[i];
|
|
625
|
+
const b = points[i + 1];
|
|
626
|
+
if (!a || !b) continue;
|
|
627
|
+
const midX = (a.x + b.x) / 2;
|
|
628
|
+
const midY = (a.y + b.y) / 2;
|
|
629
|
+
d += ` Q ${a.x} ${a.y} ${midX} ${midY}`;
|
|
630
|
+
}
|
|
631
|
+
const last = points[points.length - 1];
|
|
632
|
+
if (last) {
|
|
633
|
+
d += ` L ${last.x} ${last.y}`;
|
|
634
|
+
}
|
|
635
|
+
return d;
|
|
636
|
+
}
|
|
608
637
|
function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeComplete = true) {
|
|
609
638
|
if (pathPointsLocal.length === 0) return null;
|
|
610
639
|
if (pathPointsLocal.length === 1) {
|
|
@@ -619,6 +648,18 @@ function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeCompl
|
|
|
619
648
|
fillOpacity: style.strokeOpacity
|
|
620
649
|
};
|
|
621
650
|
}
|
|
651
|
+
if (style.strokeDash === "dashed" && (toolKind === "draw" || toolKind === "pencil")) {
|
|
652
|
+
const d2 = buildSmoothedCenterlinePath(pathPointsLocal);
|
|
653
|
+
if (!d2) return null;
|
|
654
|
+
return {
|
|
655
|
+
kind: "strokePath",
|
|
656
|
+
d: d2,
|
|
657
|
+
stroke: style.stroke,
|
|
658
|
+
strokeWidth: style.strokeWidth,
|
|
659
|
+
strokeOpacity: style.strokeOpacity,
|
|
660
|
+
strokeDasharray: dashArrayForDrawStroke(style.strokeWidth)
|
|
661
|
+
};
|
|
662
|
+
}
|
|
622
663
|
const hasPressure = pathPointsLocal.some(
|
|
623
664
|
(p) => p.pressure != null && Number.isFinite(p.pressure)
|
|
624
665
|
);
|
|
@@ -661,7 +702,8 @@ function freehandPayloadToSvgString(payload) {
|
|
|
661
702
|
strokeWidth: payload.strokeWidth,
|
|
662
703
|
strokeOpacity: payload.strokeOpacity
|
|
663
704
|
});
|
|
664
|
-
|
|
705
|
+
const dash = payload.strokeDasharray ? ` stroke-dasharray="${payload.strokeDasharray}"` : "";
|
|
706
|
+
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} />`;
|
|
665
707
|
}
|
|
666
708
|
function buildFreehandPathSvg(pathPointsLocal, style, toolKind, strokeComplete = true) {
|
|
667
709
|
const payload = computeFreehandSvgPayload(
|