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.
@@ -1,5 +1,5 @@
1
- import { P as PlacementPreview, R as RemotePresenceMarkupStroke, O as RemotePresencePeer, Q as RealtimeConnectionState, D as VectorViewportHandle, V as VectorToolDefinition, E as VectorViewportProps, C as CanvasPlugin, d as CanvasPluginRenderContext } from './types-B_rv7p8b.cjs';
2
- export { S as PresenceOverlayRenderContext } from './types-B_rv7p8b.cjs';
1
+ import { P as PlacementPreview, X as RemotePresenceMarkupStroke, Y as RemotePresencePeer, Z as RealtimeConnectionState, J as VectorViewportHandle, b as VectorToolDefinition, K as VectorViewportProps, C as CanvasPlugin, f as CanvasPluginRenderContext } from './types-CW146bKP.cjs';
2
+ export { _ as PresenceOverlayRenderContext } from './types-CW146bKP.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { C as Camera2D } from './camera-BwQjm5oh.cjs';
5
5
  import { V as VectorSceneItem, R as Rect } from './types-CB0TZZuk.cjs';
@@ -1,5 +1,5 @@
1
- import { P as PlacementPreview, R as RemotePresenceMarkupStroke, O as RemotePresencePeer, Q as RealtimeConnectionState, D as VectorViewportHandle, V as VectorToolDefinition, E as VectorViewportProps, C as CanvasPlugin, d as CanvasPluginRenderContext } from './types-BCtWx3zP.js';
2
- export { S as PresenceOverlayRenderContext } from './types-BCtWx3zP.js';
1
+ import { P as PlacementPreview, X as RemotePresenceMarkupStroke, Y as RemotePresencePeer, Z as RealtimeConnectionState, J as VectorViewportHandle, b as VectorToolDefinition, K as VectorViewportProps, C as CanvasPlugin, f as CanvasPluginRenderContext } from './types-CpqlbbCP.js';
2
+ export { _ as PresenceOverlayRenderContext } from './types-CpqlbbCP.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { C as Camera2D } from './camera-KwCYYPhm.js';
5
5
  import { V as VectorSceneItem, R as Rect } from './types-CB0TZZuk.js';
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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
@@ -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.56,
268
- streamline: 0.18,
269
- simulatePressure: false
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.72,
277
- streamline: 0.42,
278
- simulatePressure: false
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: false
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 = toolKind === "draw" && pts.some((p) => p.pressure != null && Number.isFinite(p.pressure));
393
- if (toolKind === "draw" && !hasPressure) {
394
- const d2 = smoothFreehandPointsToPathD(pts);
395
- return {
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
- ) : pts.map((p) => [p.x, p.y]);
406
- const opts = perfectFreehandOptions(toolKind, style, strokeComplete, hasPressure);
407
- let outline = [];
408
- try {
409
- const raw = getStroke__default.default(input, opts);
410
- outline = raw.map(([x, y]) => [x, y]);
411
- } catch {
412
- outline = [];
413
- }
414
- if (outline.length >= 3) {
415
- const d2 = outlineStrokeToClosedPathD(outline);
416
- return {
417
- kind: "fillPath",
418
- d: d2,
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
- const d = smoothFreehandPointsToPathD(pts);
312
+ d += " Z";
424
313
  return {
425
- kind: "strokePath",
314
+ kind: "fillPath",
426
315
  d,
427
- stroke: style.stroke,
428
- strokeWidth: style.strokeWidth,
429
- strokeOpacity: style.strokeOpacity
316
+ fill: style.stroke,
317
+ fillOpacity: style.strokeOpacity
430
318
  };
431
319
  }
432
320
  function freehandPayloadToSvgString(payload) {