canvu-react 0.3.7 → 0.3.8
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 +1388 -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 +1388 -1354
- package/dist/react.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- 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-CW146bKP.d.cts} +117 -1
- package/dist/{types-BCtWx3zP.d.ts → types-CpqlbbCP.d.ts} +117 -1
- package/package.json +1 -1
package/dist/native.cjs
CHANGED
|
@@ -129,32 +129,6 @@ function getRotationHandleWorldPosition(bounds, rotationRad, handleOffsetWorld)
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// src/scene/freehand-path.ts
|
|
132
|
-
function dedupeFreehandPoints(points, minDist) {
|
|
133
|
-
if (points.length <= 2) {
|
|
134
|
-
return points.map((p) => ({ ...p }));
|
|
135
|
-
}
|
|
136
|
-
const minSq = minDist * minDist;
|
|
137
|
-
const first = points[0];
|
|
138
|
-
if (!first) return [];
|
|
139
|
-
const out = [{ ...first }];
|
|
140
|
-
for (let i = 1; i < points.length - 1; i++) {
|
|
141
|
-
const p = points[i];
|
|
142
|
-
const last = out[out.length - 1];
|
|
143
|
-
if (!p || !last) continue;
|
|
144
|
-
const dx = p.x - last.x;
|
|
145
|
-
const dy = p.y - last.y;
|
|
146
|
-
if (dx * dx + dy * dy >= minSq) {
|
|
147
|
-
out.push({ ...p });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const end = points[points.length - 1];
|
|
151
|
-
const lastKept = out[out.length - 1];
|
|
152
|
-
if (!end || !lastKept) return out;
|
|
153
|
-
if ((end.x - lastKept.x) ** 2 + (end.y - lastKept.y) ** 2 > 1e-12) {
|
|
154
|
-
out.push({ ...end });
|
|
155
|
-
}
|
|
156
|
-
return out;
|
|
157
|
-
}
|
|
158
132
|
function smoothFreehandPointsToPathD(points) {
|
|
159
133
|
const n = points.length;
|
|
160
134
|
if (n === 0) return "";
|
|
@@ -187,29 +161,6 @@ function smoothFreehandPointsToPathD(points) {
|
|
|
187
161
|
d += ` Q ${pLast.x} ${pLast.y} ${pEnd.x} ${pEnd.y}`;
|
|
188
162
|
return d;
|
|
189
163
|
}
|
|
190
|
-
function outlineStrokeToClosedPathD(outline) {
|
|
191
|
-
const len = outline.length;
|
|
192
|
-
if (len === 0) return "";
|
|
193
|
-
const first = outline[0];
|
|
194
|
-
if (!first) return "";
|
|
195
|
-
if (len < 3) {
|
|
196
|
-
let d2 = `M ${first[0]} ${first[1]}`;
|
|
197
|
-
for (let i = 1; i < len; i++) {
|
|
198
|
-
const pt = outline[i];
|
|
199
|
-
if (!pt) continue;
|
|
200
|
-
d2 += ` L ${pt[0]} ${pt[1]}`;
|
|
201
|
-
}
|
|
202
|
-
return `${d2} Z`;
|
|
203
|
-
}
|
|
204
|
-
let d = `M ${first[0]} ${first[1]} Q`;
|
|
205
|
-
for (let i = 0; i < len; i++) {
|
|
206
|
-
const p0 = outline[i];
|
|
207
|
-
const p1 = outline[(i + 1) % len];
|
|
208
|
-
if (!p0 || !p1) continue;
|
|
209
|
-
d += ` ${p0[0]} ${p0[1]} ${(p0[0] + p1[0]) / 2} ${(p0[1] + p1[1]) / 2}`;
|
|
210
|
-
}
|
|
211
|
-
return `${d} Z`;
|
|
212
|
-
}
|
|
213
164
|
|
|
214
165
|
// src/scene/custom-shape.ts
|
|
215
166
|
function buildCustomShapeChildrenSvg(inner, intrinsic, bounds) {
|
|
@@ -339,7 +290,7 @@ var DEFAULT_STROKE_STYLE = {
|
|
|
339
290
|
strokeWidth: 2
|
|
340
291
|
};
|
|
341
292
|
var TOOL_FREEHAND_DEFAULTS = {
|
|
342
|
-
draw: { strokeWidth:
|
|
293
|
+
draw: { strokeWidth: 10 },
|
|
343
294
|
pencil: { strokeWidth: 3 },
|
|
344
295
|
brush: { strokeWidth: 10 },
|
|
345
296
|
marker: { stroke: "#fde047", strokeWidth: 16, strokeOpacity: 0.5 }
|
|
@@ -356,18 +307,18 @@ function perfectFreehandOptions(toolKind, style, strokeComplete, pressureAware =
|
|
|
356
307
|
...base,
|
|
357
308
|
size: Math.max(2, sw * 1.05),
|
|
358
309
|
thinning: 0.42,
|
|
359
|
-
smoothing: 0.
|
|
360
|
-
streamline: 0.
|
|
361
|
-
simulatePressure:
|
|
310
|
+
smoothing: 0.78,
|
|
311
|
+
streamline: 0.62,
|
|
312
|
+
simulatePressure: true
|
|
362
313
|
};
|
|
363
314
|
}
|
|
364
315
|
return {
|
|
365
316
|
...base,
|
|
366
317
|
size: Math.max(2, sw * 1.18),
|
|
367
318
|
thinning: 0.12,
|
|
368
|
-
smoothing: 0.
|
|
369
|
-
streamline: 0.
|
|
370
|
-
simulatePressure:
|
|
319
|
+
smoothing: 0.85,
|
|
320
|
+
streamline: 0.78,
|
|
321
|
+
simulatePressure: true
|
|
371
322
|
};
|
|
372
323
|
}
|
|
373
324
|
if (toolKind === "brush") {
|
|
@@ -385,7 +336,7 @@ function perfectFreehandOptions(toolKind, style, strokeComplete, pressureAware =
|
|
|
385
336
|
thinning: 0.08,
|
|
386
337
|
smoothing: 0.88,
|
|
387
338
|
streamline: 0.84,
|
|
388
|
-
simulatePressure:
|
|
339
|
+
simulatePressure: true
|
|
389
340
|
};
|
|
390
341
|
}
|
|
391
342
|
function resolveStrokeStyle(item) {
|
|
@@ -455,70 +406,41 @@ function computeFreehandSvgPayload(pathPointsLocal, style, toolKind, strokeCompl
|
|
|
455
406
|
if (pathPointsLocal.length === 1) {
|
|
456
407
|
const p = pathPointsLocal[0];
|
|
457
408
|
if (!p) return null;
|
|
458
|
-
const r = Math.max(0.5, style.strokeWidth / 2);
|
|
459
409
|
return {
|
|
460
410
|
kind: "circle",
|
|
461
411
|
cx: p.x,
|
|
462
412
|
cy: p.y,
|
|
463
|
-
r,
|
|
413
|
+
r: Math.max(0.5, style.strokeWidth / 2),
|
|
464
414
|
fill: style.stroke,
|
|
465
415
|
fillOpacity: style.strokeOpacity
|
|
466
416
|
};
|
|
467
417
|
}
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
const p = pts[0];
|
|
473
|
-
if (!p) return null;
|
|
474
|
-
const r = Math.max(0.5, style.strokeWidth / 2);
|
|
475
|
-
return {
|
|
476
|
-
kind: "circle",
|
|
477
|
-
cx: p.x,
|
|
478
|
-
cy: p.y,
|
|
479
|
-
r,
|
|
480
|
-
fill: style.stroke,
|
|
481
|
-
fillOpacity: style.strokeOpacity
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
const hasPressure = toolKind === "draw" && pts.some((p) => p.pressure != null && Number.isFinite(p.pressure));
|
|
485
|
-
if (toolKind === "draw" && !hasPressure) {
|
|
486
|
-
const d2 = smoothFreehandPointsToPathD(pts);
|
|
487
|
-
return {
|
|
488
|
-
kind: "strokePath",
|
|
489
|
-
d: d2,
|
|
490
|
-
stroke: style.stroke,
|
|
491
|
-
strokeWidth: style.strokeWidth,
|
|
492
|
-
strokeOpacity: style.strokeOpacity
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
const input = hasPressure ? pts.map(
|
|
418
|
+
const hasPressure = pathPointsLocal.some(
|
|
419
|
+
(p) => p.pressure != null && Number.isFinite(p.pressure)
|
|
420
|
+
);
|
|
421
|
+
const input = hasPressure ? pathPointsLocal.map(
|
|
496
422
|
(p) => [p.x, p.y, Math.min(1, Math.max(0, p.pressure ?? 0.5))]
|
|
497
|
-
) :
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
fill: style.stroke,
|
|
512
|
-
fillOpacity: style.strokeOpacity
|
|
513
|
-
};
|
|
423
|
+
) : pathPointsLocal.map((p) => [p.x, p.y]);
|
|
424
|
+
const stroke = getStroke__default.default(
|
|
425
|
+
input,
|
|
426
|
+
perfectFreehandOptions(toolKind, style, strokeComplete, hasPressure)
|
|
427
|
+
);
|
|
428
|
+
if (stroke.length < 3) return null;
|
|
429
|
+
const first = stroke[0];
|
|
430
|
+
if (!first) return null;
|
|
431
|
+
let d = `M ${first[0]} ${first[1]} Q`;
|
|
432
|
+
for (let i = 0; i < stroke.length; i++) {
|
|
433
|
+
const a = stroke[i];
|
|
434
|
+
const b = stroke[(i + 1) % stroke.length];
|
|
435
|
+
if (!a || !b) continue;
|
|
436
|
+
d += ` ${a[0]} ${a[1]} ${(a[0] + b[0]) / 2} ${(a[1] + b[1]) / 2}`;
|
|
514
437
|
}
|
|
515
|
-
|
|
438
|
+
d += " Z";
|
|
516
439
|
return {
|
|
517
|
-
kind: "
|
|
440
|
+
kind: "fillPath",
|
|
518
441
|
d,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
strokeOpacity: style.strokeOpacity
|
|
442
|
+
fill: style.stroke,
|
|
443
|
+
fillOpacity: style.strokeOpacity
|
|
522
444
|
};
|
|
523
445
|
}
|
|
524
446
|
function freehandPayloadToSvgString(payload) {
|