@netless/forge-whiteboard 1.2.0-beta.0 → 1.2.0-beta.3

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.
@@ -23278,7 +23278,7 @@ var require_lodash = __commonJS({
23278
23278
  result2.__values__ = wrapper.__values__;
23279
23279
  return result2;
23280
23280
  }
23281
- function chunk7(array, size2, guard) {
23281
+ function chunk8(array, size2, guard) {
23282
23282
  if (guard ? isIterateeCall(array, size2, guard) : size2 === undefined2) {
23283
23283
  size2 = 1;
23284
23284
  } else {
@@ -25150,7 +25150,7 @@ var require_lodash = __commonJS({
25150
25150
  lodash.bindKey = bindKey;
25151
25151
  lodash.castArray = castArray;
25152
25152
  lodash.chain = chain;
25153
- lodash.chunk = chunk7;
25153
+ lodash.chunk = chunk8;
25154
25154
  lodash.compact = compact;
25155
25155
  lodash.concat = concat;
25156
25156
  lodash.cond = cond;
@@ -25651,6 +25651,7 @@ var import_forge_room6 = require("@netless/forge-room");
25651
25651
 
25652
25652
  // src/model/renderable/CurveModel.ts
25653
25653
  var Y2 = __toESM(require("yjs"), 1);
25654
+ var import_lodash = __toESM(require_lodash(), 1);
25654
25655
 
25655
25656
  // ../../node_modules/.pnpm/perfect-freehand@1.2.2/node_modules/perfect-freehand/dist/esm/index.mjs
25656
25657
  function $(e, t, u, x = (h) => h) {
@@ -26208,7 +26209,7 @@ var CurveModel = class extends ElementModel {
26208
26209
  _defineProperty3(this, "debug", false);
26209
26210
  _defineProperty3(this, "clearLocalPointsWhenYPointsChange", false);
26210
26211
  _defineProperty3(this, "shouldUseLocalPoints", true);
26211
- _defineProperty3(this, "localPointsPick", 6);
26212
+ _defineProperty3(this, "localPointsPick", 4);
26212
26213
  if (!this.root.doc || !this.root.has("type")) {
26213
26214
  this.root.set("type", "curve");
26214
26215
  }
@@ -26220,7 +26221,6 @@ var CurveModel = class extends ElementModel {
26220
26221
  return (a2 + b2) / 2;
26221
26222
  }
26222
26223
  parsePoints(points) {
26223
- const hasRealPressure = points.some((p) => p.length >= 3 && p[2] > 0);
26224
26224
  const viewScale = this.scope.project.view.matrix.scaling.x || 1;
26225
26225
  const taper = this.strokeWidth * 5 / viewScale;
26226
26226
  const streamline = Math.min(0.7, 0.7 * viewScale);
@@ -26229,7 +26229,7 @@ var CurveModel = class extends ElementModel {
26229
26229
  smoothing: 0.7,
26230
26230
  thinning: 0.5,
26231
26231
  streamline,
26232
- simulatePressure: !hasRealPressure,
26232
+ simulatePressure: true,
26233
26233
  start: {
26234
26234
  taper,
26235
26235
  cap: true
@@ -26240,36 +26240,13 @@ var CurveModel = class extends ElementModel {
26240
26240
  }
26241
26241
  });
26242
26242
  }
26243
- isPressureValue(value) {
26244
- return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
26245
- }
26246
- pointStride(points) {
26247
- if (points.length >= 3 && points.length % 3 === 0) {
26248
- let hasPressureSlot = false;
26249
- for (let i = 2; i < points.length; i += 3) {
26250
- if (!this.isPressureValue(points[i])) {
26251
- return 2;
26252
- }
26253
- hasPressureSlot = true;
26254
- }
26255
- if (hasPressureSlot) {
26256
- return 3;
26257
- }
26258
- }
26259
- return 2;
26260
- }
26261
26243
  matrixedPoints() {
26262
26244
  const points = this.localPoints.length === 0 ? this.points : this.localPoints;
26263
26245
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26264
- const output = [];
26265
- const stride = this.pointStride(points);
26266
- for (let i = 0, len = points.length; i + 1 < len; i += stride) {
26267
- const p = new this.scope.Point(points[i], points[i + 1]);
26268
- const tp = p.transform(matrix);
26269
- const pressure = stride === 3 ? points[i + 2] ?? 0 : 0;
26270
- output.push([tp.x, tp.y, pressure]);
26271
- }
26272
- return output;
26246
+ return (0, import_lodash.chunk)(points, 2).filter((point) => point.length === 2).map((_ref) => {
26247
+ let [x, y] = _ref;
26248
+ return new this.scope.Point(x, y).transform(matrix);
26249
+ }).map((point) => [point.x, point.y]);
26273
26250
  }
26274
26251
  createPath(points) {
26275
26252
  const path = new this.scope.Path();
@@ -26343,12 +26320,11 @@ var CurveModel = class extends ElementModel {
26343
26320
  liveCursorPoint() {
26344
26321
  const yArray = this.root.get(ElementModel.KEYS.points);
26345
26322
  const points = yArray.toArray();
26346
- const stride = this.pointStride(points);
26347
- if (points.length < stride) {
26323
+ if (points.length < 2) {
26348
26324
  return null;
26349
26325
  }
26350
26326
  const len = points.length;
26351
- const point = new this.scope.Point(points[len - stride], points[len - stride + 1]);
26327
+ const point = new this.scope.Point(points[len - 2], points[len - 1]);
26352
26328
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
26353
26329
  }
26354
26330
  onStyleKeyUpdate(key) {
@@ -26449,7 +26425,7 @@ var SelectorModel = class extends ElementModel {
26449
26425
  var Y4 = __toESM(require("yjs"), 1);
26450
26426
 
26451
26427
  // src/utils/paperjs.ts
26452
- var import_lodash = __toESM(require_lodash(), 1);
26428
+ var import_lodash2 = __toESM(require_lodash(), 1);
26453
26429
  var import_forge_room2 = require("@netless/forge-room");
26454
26430
  function _defineProperty5(e, r, t) {
26455
26431
  return (r = _toPropertyKey5(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -26483,7 +26459,7 @@ function serializePath(path) {
26483
26459
  }, []);
26484
26460
  }
26485
26461
  function deserializePath(points, scope, matrix) {
26486
- const segmentGroup = (0, import_lodash.chunk)(points, 6);
26462
+ const segmentGroup = (0, import_lodash2.chunk)(points, 6);
26487
26463
  const path = new scope.Path();
26488
26464
  path.segments = segmentGroup.map((v) => deserializeSegment(v, scope, matrix));
26489
26465
  return path;
@@ -26626,7 +26602,7 @@ var SegmentsModel = class extends ElementModel {
26626
26602
 
26627
26603
  // src/model/renderable/LineModel.ts
26628
26604
  var Y5 = __toESM(require("yjs"), 1);
26629
- var import_lodash3 = __toESM(require_lodash(), 1);
26605
+ var import_lodash4 = __toESM(require_lodash(), 1);
26630
26606
 
26631
26607
  // src/tool/WhiteboardTool.ts
26632
26608
  function _defineProperty7(e, r, t) {
@@ -26725,7 +26701,7 @@ var WhiteboardTool = class {
26725
26701
  };
26726
26702
 
26727
26703
  // src/tool/LineTool.ts
26728
- var import_lodash2 = __toESM(require_lodash(), 1);
26704
+ var import_lodash3 = __toESM(require_lodash(), 1);
26729
26705
  function _defineProperty8(e, r, t) {
26730
26706
  return (r = _toPropertyKey8(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
26731
26707
  }
@@ -26774,7 +26750,7 @@ var LineTool = class extends WhiteboardTool {
26774
26750
  const point = path.getPointAt(distance);
26775
26751
  return [point.x, point.y];
26776
26752
  });
26777
- this.elementModel.setPoints((0, import_lodash2.flattenDeep)(points));
26753
+ this.elementModel.setPoints((0, import_lodash3.flattenDeep)(points));
26778
26754
  }
26779
26755
  }
26780
26756
  onMouseUp(_event) {
@@ -26857,7 +26833,7 @@ var LineModel = class extends ElementModel {
26857
26833
  }
26858
26834
  renderLine() {
26859
26835
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26860
- const papperPoints = (0, import_lodash3.chunk)(this.drawPoints, 2).map((item) => {
26836
+ const papperPoints = (0, import_lodash4.chunk)(this.drawPoints, 2).map((item) => {
26861
26837
  return new this.scope.Point(item[0], item[1]).transform(matrix);
26862
26838
  });
26863
26839
  const path = new this.scope.Path();
@@ -26993,7 +26969,7 @@ var LineControlPoint = class {
26993
26969
  const invertedPoint = point.transform(pointsMatrix.inverted());
26994
26970
  const points = this.model["drawPoints"];
26995
26971
  this.position = invertedPoint;
26996
- const clonedPoints = (0, import_lodash3.cloneDeep)(points);
26972
+ const clonedPoints = (0, import_lodash4.cloneDeep)(points);
26997
26973
  clonedPoints[this.options.index * 2] = invertedPoint.x;
26998
26974
  clonedPoints[this.options.index * 2 + 1] = invertedPoint.y;
26999
26975
  this.model.setPoints(clonedPoints);
@@ -27478,7 +27454,7 @@ var elementsUndoOrigin = "elementsUndoOrigin";
27478
27454
 
27479
27455
  // src/model/renderable/EraserModel.ts
27480
27456
  var Y9 = __toESM(require("yjs"), 1);
27481
- var import_lodash4 = __toESM(require_lodash(), 1);
27457
+ var import_lodash5 = __toESM(require_lodash(), 1);
27482
27458
  function _defineProperty13(e, r, t) {
27483
27459
  return (r = _toPropertyKey13(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27484
27460
  }
@@ -27546,7 +27522,7 @@ var EraserModel = class extends ElementModel {
27546
27522
  return path;
27547
27523
  }
27548
27524
  parsePoints(points) {
27549
- const groupPoints = (0, import_lodash4.chunk)(points, 2);
27525
+ const groupPoints = (0, import_lodash5.chunk)(points, 2);
27550
27526
  return ae(groupPoints, {
27551
27527
  size: this.strokeWidth,
27552
27528
  smoothing: 0.5,
@@ -27564,7 +27540,7 @@ var EraserModel = class extends ElementModel {
27564
27540
  });
27565
27541
  }
27566
27542
  matrixedPoints() {
27567
- const currentPoints = (0, import_lodash4.chunk)(this.drawPoints, 2).slice(this.sliceBegin);
27543
+ const currentPoints = (0, import_lodash5.chunk)(this.drawPoints, 2).slice(this.sliceBegin);
27568
27544
  return currentPoints.map((_ref) => {
27569
27545
  let [x, y] = _ref;
27570
27546
  return new this.scope.Point(x, y);
@@ -27630,7 +27606,7 @@ var EraserModel = class extends ElementModel {
27630
27606
 
27631
27607
  // src/model/renderable/LaserPointerModel.ts
27632
27608
  var Y10 = __toESM(require("yjs"), 1);
27633
- var import_lodash5 = __toESM(require_lodash(), 1);
27609
+ var import_lodash6 = __toESM(require_lodash(), 1);
27634
27610
  var import_forge_room4 = require("@netless/forge-room");
27635
27611
  function _defineProperty14(e, r, t) {
27636
27612
  return (r = _toPropertyKey14(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -27757,7 +27733,7 @@ var LaserPointerModel = class extends ElementModel {
27757
27733
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27758
27734
  const points = this.cachedPoints || this.points;
27759
27735
  console.log("[][][] ,", this.points.length, this.cachedPoints?.length, this.localPoints.length);
27760
- const groupPoints = (0, import_lodash5.chunk)(points, 2).slice(this.sliceBegin);
27736
+ const groupPoints = (0, import_lodash6.chunk)(points, 2).slice(this.sliceBegin);
27761
27737
  return groupPoints.map((_ref) => {
27762
27738
  let [x, y] = _ref;
27763
27739
  return matrix.transform([x, y]);
@@ -27837,7 +27813,7 @@ var WhiteboardPermissions = class extends import_forge_room5.AbstractApplication
27837
27813
 
27838
27814
  // src/model/renderable/StraightLineModel.ts
27839
27815
  var Y11 = __toESM(require("yjs"), 1);
27840
- var import_lodash6 = __toESM(require_lodash(), 1);
27816
+ var import_lodash7 = __toESM(require_lodash(), 1);
27841
27817
  function _defineProperty15(e, r, t) {
27842
27818
  return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27843
27819
  }
@@ -27896,7 +27872,7 @@ var StraightLineModel = class extends ElementModel {
27896
27872
  }
27897
27873
  renderLine() {
27898
27874
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27899
- const papperPoints = (0, import_lodash6.chunk)(this.drawPoints, 2).map((item) => {
27875
+ const papperPoints = (0, import_lodash7.chunk)(this.drawPoints, 2).map((item) => {
27900
27876
  return new this.scope.Point(item[0], item[1]).transform(matrix);
27901
27877
  });
27902
27878
  const path = new this.scope.Path();
@@ -28530,7 +28506,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28530
28506
  if (shadow) {
28531
28507
  yMap.set(ElementModel.KEYS.shadow, "layer");
28532
28508
  }
28533
- yMap.set(ElementModel.KEYS.points, new Y12.Array());
28509
+ yMap.set(ElementModel.KEYS.points, Y12.Array.from([x, y]));
28534
28510
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
28535
28511
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28536
28512
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
@@ -28538,7 +28514,6 @@ var RenderableModel = class extends import_eventemitter3.default {
28538
28514
  this.elements.set(uuid, yMap);
28539
28515
  }, elementsUndoOrigin);
28540
28516
  pointTextModel.bindObserver();
28541
- pointTextModel.setPoints([x, y]);
28542
28517
  pointTextModel.fontSize = this.toolbarModel.fontSize;
28543
28518
  pointTextModel.fontFamily = this.toolbarModel.fontFamily;
28544
28519
  this.initElement(pointTextModel);
@@ -28572,7 +28547,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28572
28547
  };
28573
28548
 
28574
28549
  // src/utils/Recognizer.ts
28575
- var import_lodash7 = __toESM(require_lodash(), 1);
28550
+ var import_lodash8 = __toESM(require_lodash(), 1);
28576
28551
 
28577
28552
  // src/utils/UnistrokeRecognizer.js
28578
28553
  function Point(x, y) {
@@ -28819,7 +28794,7 @@ var Recognizer = class {
28819
28794
  let maxX = -Number.MAX_VALUE;
28820
28795
  let minY = Number.MAX_VALUE;
28821
28796
  let maxY = -Number.MAX_VALUE;
28822
- const result = this.dollar.Recognize((0, import_lodash7.chunk)(points, 3).map((v) => {
28797
+ const result = this.dollar.Recognize((0, import_lodash8.chunk)(points, 2).map((v) => {
28823
28798
  minX = Math.min(minX, v[0]);
28824
28799
  maxX = Math.max(maxX, v[0]);
28825
28800
  minY = Math.min(minY, v[1]);
@@ -28899,22 +28874,20 @@ var CurveTool = class extends WhiteboardTool {
28899
28874
  if (this.elementModel) {
28900
28875
  let lastX = 0;
28901
28876
  let lastY = 0;
28902
- if (this.pendingPoints.length >= 3) {
28903
- lastX = this.pendingPoints[this.pendingPoints.length - 3];
28904
- lastY = this.pendingPoints[this.pendingPoints.length - 2];
28877
+ if (this.pendingPoints.length >= 2) {
28878
+ lastX = this.pendingPoints[this.pendingPoints.length - 2];
28879
+ lastY = this.pendingPoints[this.pendingPoints.length - 1];
28905
28880
  } else {
28906
28881
  const len = this.elementModel.points.length;
28907
- if (len >= 3) {
28908
- lastX = this.elementModel.points[len - 3];
28909
- lastY = this.elementModel.points[len - 2];
28882
+ if (len >= 2) {
28883
+ lastX = this.elementModel.points[len - 2];
28884
+ lastY = this.elementModel.points[len - 1];
28910
28885
  }
28911
28886
  }
28912
28887
  const dist = Math.max(Math.abs(lastX - event.point.x), Math.abs(lastY - event.point.y));
28913
28888
  if (dist >= MIN_DISTANCE) {
28914
28889
  this.pointCount += 1;
28915
- const nativeEvent = event.event;
28916
- const pressure = nativeEvent.pointerType === "pen" && nativeEvent.pressure > 0 ? nativeEvent.pressure : 0;
28917
- this.pendingPoints.push(event.point.x, event.point.y, pressure);
28890
+ this.pendingPoints.push(event.point.x, event.point.y);
28918
28891
  if (!this.flushRafId) {
28919
28892
  this.flushRafId = requestAnimationFrame(this.flushPendingPoints);
28920
28893
  }