canvu-react 0.3.7 → 0.3.9
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/README.md +192 -0
- package/dist/chatbot.d.cts +1 -1
- package/dist/chatbot.d.ts +1 -1
- package/dist/index.cjs +32 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -144
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +31 -109
- package/dist/native.cjs.map +1 -1
- package/dist/native.js +31 -109
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +1449 -1353
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +147 -4
- package/dist/react.d.ts +147 -4
- package/dist/react.js +1449 -1354
- package/dist/react.js.map +1 -1
- package/dist/realtime.cjs +244 -11
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +20 -7
- package/dist/realtime.d.ts +20 -7
- package/dist/realtime.js +244 -12
- package/dist/realtime.js.map +1 -1
- package/dist/tldraw.cjs +30 -142
- package/dist/tldraw.cjs.map +1 -1
- package/dist/tldraw.js +30 -142
- package/dist/tldraw.js.map +1 -1
- package/dist/{types-B_rv7p8b.d.cts → types-BtLGGw0r.d.cts} +126 -1
- package/dist/{types-BCtWx3zP.d.ts → types-ChnTSRSe.d.ts} +126 -1
- package/package.json +1 -1
package/dist/tldraw.cjs
CHANGED
|
@@ -50,89 +50,6 @@ function createCustomShapeItem(id, bounds, content) {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// src/scene/freehand-path.ts
|
|
54
|
-
function dedupeFreehandPoints(points, minDist) {
|
|
55
|
-
if (points.length <= 2) {
|
|
56
|
-
return points.map((p) => ({ ...p }));
|
|
57
|
-
}
|
|
58
|
-
const minSq = minDist * minDist;
|
|
59
|
-
const first = points[0];
|
|
60
|
-
if (!first) return [];
|
|
61
|
-
const out = [{ ...first }];
|
|
62
|
-
for (let i = 1; i < points.length - 1; i++) {
|
|
63
|
-
const p = points[i];
|
|
64
|
-
const last = out[out.length - 1];
|
|
65
|
-
if (!p || !last) continue;
|
|
66
|
-
const dx = p.x - last.x;
|
|
67
|
-
const dy = p.y - last.y;
|
|
68
|
-
if (dx * dx + dy * dy >= minSq) {
|
|
69
|
-
out.push({ ...p });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const end = points[points.length - 1];
|
|
73
|
-
const lastKept = out[out.length - 1];
|
|
74
|
-
if (!end || !lastKept) return out;
|
|
75
|
-
if ((end.x - lastKept.x) ** 2 + (end.y - lastKept.y) ** 2 > 1e-12) {
|
|
76
|
-
out.push({ ...end });
|
|
77
|
-
}
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
function smoothFreehandPointsToPathD(points) {
|
|
81
|
-
const n = points.length;
|
|
82
|
-
if (n === 0) return "";
|
|
83
|
-
if (n === 1) {
|
|
84
|
-
const p = points[0];
|
|
85
|
-
if (!p) return "";
|
|
86
|
-
return `M ${p.x} ${p.y}`;
|
|
87
|
-
}
|
|
88
|
-
if (n === 2) {
|
|
89
|
-
const a = points[0];
|
|
90
|
-
const b = points[1];
|
|
91
|
-
if (!a || !b) return "";
|
|
92
|
-
return `M ${a.x} ${a.y} L ${b.x} ${b.y}`;
|
|
93
|
-
}
|
|
94
|
-
const p0 = points[0];
|
|
95
|
-
if (!p0) return "";
|
|
96
|
-
let d = `M ${p0.x} ${p0.y}`;
|
|
97
|
-
let i = 1;
|
|
98
|
-
for (; i < n - 2; i++) {
|
|
99
|
-
const pi = points[i];
|
|
100
|
-
const pi1 = points[i + 1];
|
|
101
|
-
if (!pi || !pi1) continue;
|
|
102
|
-
const xc = (pi.x + pi1.x) / 2;
|
|
103
|
-
const yc = (pi.y + pi1.y) / 2;
|
|
104
|
-
d += ` Q ${pi.x} ${pi.y} ${xc} ${yc}`;
|
|
105
|
-
}
|
|
106
|
-
const pLast = points[i];
|
|
107
|
-
const pEnd = points[i + 1];
|
|
108
|
-
if (!pLast || !pEnd) return d;
|
|
109
|
-
d += ` Q ${pLast.x} ${pLast.y} ${pEnd.x} ${pEnd.y}`;
|
|
110
|
-
return d;
|
|
111
|
-
}
|
|
112
|
-
function outlineStrokeToClosedPathD(outline) {
|
|
113
|
-
const len = outline.length;
|
|
114
|
-
if (len === 0) return "";
|
|
115
|
-
const first = outline[0];
|
|
116
|
-
if (!first) return "";
|
|
117
|
-
if (len < 3) {
|
|
118
|
-
let d2 = `M ${first[0]} ${first[1]}`;
|
|
119
|
-
for (let i = 1; i < len; i++) {
|
|
120
|
-
const pt = outline[i];
|
|
121
|
-
if (!pt) continue;
|
|
122
|
-
d2 += ` L ${pt[0]} ${pt[1]}`;
|
|
123
|
-
}
|
|
124
|
-
return `${d2} Z`;
|
|
125
|
-
}
|
|
126
|
-
let d = `M ${first[0]} ${first[1]} Q`;
|
|
127
|
-
for (let i = 0; i < len; i++) {
|
|
128
|
-
const p0 = outline[i];
|
|
129
|
-
const p1 = outline[(i + 1) % len];
|
|
130
|
-
if (!p0 || !p1) continue;
|
|
131
|
-
d += ` ${p0[0]} ${p0[1]} ${(p0[0] + p1[0]) / 2} ${(p0[1] + p1[1]) / 2}`;
|
|
132
|
-
}
|
|
133
|
-
return `${d} Z`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
53
|
// src/scene/text-svg.ts
|
|
137
54
|
function escapeSvgTextContent(s) {
|
|
138
55
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
@@ -264,18 +181,18 @@ function perfectFreehandOptions(toolKind, style, strokeComplete, pressureAware =
|
|
|
264
181
|
...base,
|
|
265
182
|
size: Math.max(2, sw * 1.05),
|
|
266
183
|
thinning: 0.42,
|
|
267
|
-
smoothing: 0.
|
|
268
|
-
streamline: 0.
|
|
269
|
-
simulatePressure:
|
|
184
|
+
smoothing: 0.78,
|
|
185
|
+
streamline: 0.62,
|
|
186
|
+
simulatePressure: true
|
|
270
187
|
};
|
|
271
188
|
}
|
|
272
189
|
return {
|
|
273
190
|
...base,
|
|
274
191
|
size: Math.max(2, sw * 1.18),
|
|
275
192
|
thinning: 0.12,
|
|
276
|
-
smoothing: 0.
|
|
277
|
-
streamline: 0.
|
|
278
|
-
simulatePressure:
|
|
193
|
+
smoothing: 0.85,
|
|
194
|
+
streamline: 0.78,
|
|
195
|
+
simulatePressure: true
|
|
279
196
|
};
|
|
280
197
|
}
|
|
281
198
|
if (toolKind === "brush") {
|
|
@@ -293,7 +210,7 @@ function perfectFreehandOptions(toolKind, style, strokeComplete, pressureAware =
|
|
|
293
210
|
thinning: 0.08,
|
|
294
211
|
smoothing: 0.88,
|
|
295
212
|
streamline: 0.84,
|
|
296
|
-
simulatePressure:
|
|
213
|
+
simulatePressure: true
|
|
297
214
|
};
|
|
298
215
|
}
|
|
299
216
|
function resolveStrokeStyle(item) {
|
|
@@ -363,70 +280,41 @@ function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeCompl
|
|
|
363
280
|
if (pathPointsLocal.length === 1) {
|
|
364
281
|
const p = pathPointsLocal[0];
|
|
365
282
|
if (!p) return null;
|
|
366
|
-
const r = Math.max(0.5, style.strokeWidth / 2);
|
|
367
|
-
return {
|
|
368
|
-
kind: "circle",
|
|
369
|
-
cx: p.x,
|
|
370
|
-
cy: p.y,
|
|
371
|
-
r,
|
|
372
|
-
fill: style.stroke,
|
|
373
|
-
fillOpacity: style.strokeOpacity
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
const minDist = Math.min(0.25, Math.max(0.02, style.strokeWidth * 0.02));
|
|
377
|
-
const pts = dedupeFreehandPoints(pathPointsLocal, minDist);
|
|
378
|
-
if (pts.length === 0) return null;
|
|
379
|
-
if (pts.length === 1) {
|
|
380
|
-
const p = pts[0];
|
|
381
|
-
if (!p) return null;
|
|
382
|
-
const r = Math.max(0.5, style.strokeWidth / 2);
|
|
383
283
|
return {
|
|
384
284
|
kind: "circle",
|
|
385
285
|
cx: p.x,
|
|
386
286
|
cy: p.y,
|
|
387
|
-
r,
|
|
287
|
+
r: Math.max(0.5, style.strokeWidth / 2),
|
|
388
288
|
fill: style.stroke,
|
|
389
289
|
fillOpacity: style.strokeOpacity
|
|
390
290
|
};
|
|
391
291
|
}
|
|
392
|
-
const hasPressure =
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
kind: "strokePath",
|
|
397
|
-
d: d2,
|
|
398
|
-
stroke: style.stroke,
|
|
399
|
-
strokeWidth: style.strokeWidth,
|
|
400
|
-
strokeOpacity: style.strokeOpacity
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
const input = hasPressure ? pts.map(
|
|
292
|
+
const hasPressure = pathPointsLocal.some(
|
|
293
|
+
(p) => p.pressure != null && Number.isFinite(p.pressure)
|
|
294
|
+
);
|
|
295
|
+
const input = hasPressure ? pathPointsLocal.map(
|
|
404
296
|
(p) => [p.x, p.y, Math.min(1, Math.max(0, p.pressure ?? 0.5))]
|
|
405
|
-
) :
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
fill: style.stroke,
|
|
420
|
-
fillOpacity: style.strokeOpacity
|
|
421
|
-
};
|
|
297
|
+
) : pathPointsLocal.map((p) => [p.x, p.y]);
|
|
298
|
+
const stroke = getStroke__default.default(
|
|
299
|
+
input,
|
|
300
|
+
perfectFreehandOptions(toolKind, style, strokeComplete, hasPressure)
|
|
301
|
+
);
|
|
302
|
+
if (stroke.length < 3) return null;
|
|
303
|
+
const first = stroke[0];
|
|
304
|
+
if (!first) return null;
|
|
305
|
+
let d = `M ${first[0]} ${first[1]} Q`;
|
|
306
|
+
for (let i = 0; i < stroke.length; i++) {
|
|
307
|
+
const a = stroke[i];
|
|
308
|
+
const b = stroke[(i + 1) % stroke.length];
|
|
309
|
+
if (!a || !b) continue;
|
|
310
|
+
d += ` ${a[0]} ${a[1]} ${(a[0] + b[0]) / 2} ${(a[1] + b[1]) / 2}`;
|
|
422
311
|
}
|
|
423
|
-
|
|
312
|
+
d += " Z";
|
|
424
313
|
return {
|
|
425
|
-
kind: "
|
|
314
|
+
kind: "fillPath",
|
|
426
315
|
d,
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
strokeOpacity: style.strokeOpacity
|
|
316
|
+
fill: style.stroke,
|
|
317
|
+
fillOpacity: style.strokeOpacity
|
|
430
318
|
};
|
|
431
319
|
}
|
|
432
320
|
function freehandPayloadToSvgString(payload) {
|