@netless/forge-slide 1.1.1 → 1.1.2

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/slide.esm.js CHANGED
@@ -35304,6 +35304,7 @@ import * as Y from "yjs";
35304
35304
  import { removeDeepObserver } from "@netless/forge-room";
35305
35305
  import * as Y3 from "yjs";
35306
35306
  import * as Y4 from "yjs";
35307
+ import { metrics } from "@netless/forge-room";
35307
35308
  import * as Y5 from "yjs";
35308
35309
  import * as Y6 from "yjs";
35309
35310
  import { removeObserver } from "@netless/forge-room";
@@ -58604,7 +58605,7 @@ var require_lodash = __commonJS2({
58604
58605
  result2.__values__ = wrapper.__values__;
58605
58606
  return result2;
58606
58607
  }
58607
- function chunk8(array, size2, guard) {
58608
+ function chunk7(array, size2, guard) {
58608
58609
  if (guard ? isIterateeCall(array, size2, guard) : size2 === undefined2) {
58609
58610
  size2 = 1;
58610
58611
  } else {
@@ -60476,7 +60477,7 @@ var require_lodash = __commonJS2({
60476
60477
  lodash.bindKey = bindKey;
60477
60478
  lodash.castArray = castArray;
60478
60479
  lodash.chain = chain;
60479
- lodash.chunk = chunk8;
60480
+ lodash.chunk = chunk7;
60480
60481
  lodash.compact = compact;
60481
60482
  lodash.concat = concat;
60482
60483
  lodash.cond = cond;
@@ -61100,7 +61101,6 @@ function me(e, t = {}) {
61100
61101
  function ae(e, t = {}) {
61101
61102
  return ce(me(e, t), t);
61102
61103
  }
61103
- var import_lodash = __toESM2(require_lodash(), 1);
61104
61104
  function _defineProperty(e, r, t) {
61105
61105
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
61106
61106
  }
@@ -61483,35 +61483,37 @@ var CurveModel = class extends ElementModel {
61483
61483
  constructor(root, scope, liveCursor, isPerformanceMode) {
61484
61484
  super(root, scope, liveCursor, isPerformanceMode);
61485
61485
  _defineProperty3(this, "item", null);
61486
- _defineProperty3(this, "debugPath", void 0);
61487
61486
  _defineProperty3(this, "debug", false);
61488
61487
  _defineProperty3(this, "clearLocalPointsWhenYPointsChange", false);
61489
61488
  _defineProperty3(this, "shouldUseLocalPoints", true);
61490
- _defineProperty3(this, "localPointsPick", 4);
61489
+ _defineProperty3(this, "localPointsPick", 6);
61491
61490
  if (!this.root.doc || !this.root.has("type")) {
61492
61491
  this.root.set("type", "curve");
61493
61492
  }
61494
61493
  if (!this.root.doc || !this.root.has("points")) {
61495
61494
  this.root.set("points", new Y2.Array());
61496
61495
  }
61497
- this.debugPath = new scope.Path();
61498
61496
  }
61499
61497
  average(a2, b2) {
61500
61498
  return (a2 + b2) / 2;
61501
61499
  }
61502
61500
  parsePoints(points) {
61501
+ const hasRealPressure = points.some((p) => p.length >= 3 && p[2] > 0);
61502
+ const viewScale = this.scope.project.view.matrix.scaling.x || 1;
61503
+ const taper = this.strokeWidth * 5 / viewScale;
61504
+ const streamline = Math.min(0.7, 0.7 * viewScale);
61503
61505
  return ae(points, {
61504
61506
  size: this.strokeWidth,
61505
- smoothing: 0.5,
61506
- thinning: -0.5,
61507
- streamline: 0.5,
61508
- simulatePressure: true,
61507
+ smoothing: 0.7,
61508
+ thinning: 0.5,
61509
+ streamline,
61510
+ simulatePressure: !hasRealPressure,
61509
61511
  start: {
61510
- taper: this.strokeWidth * 10,
61512
+ taper,
61511
61513
  cap: true
61512
61514
  },
61513
61515
  end: {
61514
- taper: this.strokeWidth * 20,
61516
+ taper,
61515
61517
  cap: true
61516
61518
  }
61517
61519
  });
@@ -61520,10 +61522,11 @@ var CurveModel = class extends ElementModel {
61520
61522
  const points = this.localPoints.length === 0 ? this.points : this.localPoints;
61521
61523
  const matrix = new this.scope.Matrix(this.pointsMatrix);
61522
61524
  const output = [];
61523
- for (let i = 0, len = points.length; i < len; i += 2) {
61525
+ for (let i = 0, len = points.length; i < len; i += 3) {
61524
61526
  const p = new this.scope.Point(points[i], points[i + 1]);
61525
61527
  const tp = p.transform(matrix);
61526
- output.push([tp.x, tp.y]);
61528
+ const pressure = points[i + 2] ?? 0;
61529
+ output.push([tp.x, tp.y, pressure]);
61527
61530
  }
61528
61531
  return output;
61529
61532
  }
@@ -61552,34 +61555,30 @@ var CurveModel = class extends ElementModel {
61552
61555
  }
61553
61556
  return path;
61554
61557
  }
61555
- updateDebugPath() {
61556
- this.debugPath = new this.scope.Path();
61557
- const points = (0, import_lodash.chunk)(this.points, 2);
61558
- for (let i = 0, len = points.length; i < len; i++) {
61559
- const point = new this.scope.Point(points[i][0], points[i][1]);
61560
- if (i === 0) {
61561
- this.debugPath.moveTo(point);
61562
- } else {
61563
- this.debugPath.lineTo(point);
61564
- }
61565
- this.debugPath.strokeWidth = 1;
61566
- this.debugPath.strokeColor = new this.scope.Color(1, 0, 0, 1);
61567
- }
61568
- }
61569
61558
  onVectorUpdate() {
61570
61559
  if (!this.item) {
61571
61560
  return;
61572
61561
  }
61562
+ const matrixedPts = this.matrixedPoints();
61573
61563
  if (this.debug) {
61574
- this.debugPath.remove();
61575
- this.updateDebugPath();
61576
- }
61577
- const points = this.parsePoints(this.matrixedPoints());
61578
- const path = this.createPath(points);
61579
- this.item.removeSegments();
61580
- this.item.addSegments(path.segments);
61581
- if (this.debug) {
61582
- this.item.addChild(this.debugPath);
61564
+ const path = new this.scope.Path();
61565
+ for (let i = 0; i < matrixedPts.length; i++) {
61566
+ const p = new this.scope.Point(matrixedPts[i][0], matrixedPts[i][1]);
61567
+ if (i === 0) {
61568
+ path.moveTo(p);
61569
+ } else {
61570
+ path.lineTo(p);
61571
+ }
61572
+ }
61573
+ this.item.removeSegments();
61574
+ this.item.addSegments(path.segments);
61575
+ this.item.fillColor = null;
61576
+ this.item.strokeWidth = this.strokeWidth;
61577
+ } else {
61578
+ const points = this.parsePoints(matrixedPts);
61579
+ const path = this.createPath(points);
61580
+ this.item.removeSegments();
61581
+ this.item.addSegments(path.segments);
61583
61582
  }
61584
61583
  }
61585
61584
  createPaperItem() {
@@ -61602,11 +61601,11 @@ var CurveModel = class extends ElementModel {
61602
61601
  }
61603
61602
  liveCursorPoint() {
61604
61603
  const yArray = this.root.get(ElementModel.KEYS.points);
61605
- if (yArray.length < 2) {
61604
+ if (yArray.length < 3) {
61606
61605
  return null;
61607
61606
  }
61608
61607
  const len = yArray.length;
61609
- const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
61608
+ const point = new this.scope.Point(yArray.get(len - 3), yArray.get(len - 2));
61610
61609
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
61611
61610
  }
61612
61611
  onStyleKeyUpdate(key) {
@@ -61699,7 +61698,7 @@ var SelectorModel = class extends ElementModel {
61699
61698
  onStyleKeyUpdate(_key) {
61700
61699
  }
61701
61700
  };
61702
- var import_lodash2 = __toESM2(require_lodash(), 1);
61701
+ var import_lodash = __toESM2(require_lodash(), 1);
61703
61702
  function _defineProperty5(e, r, t) {
61704
61703
  return (r = _toPropertyKey5(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
61705
61704
  }
@@ -61732,7 +61731,7 @@ function serializePath(path) {
61732
61731
  }, []);
61733
61732
  }
61734
61733
  function deserializePath(points, scope, matrix) {
61735
- const segmentGroup = (0, import_lodash2.chunk)(points, 6);
61734
+ const segmentGroup = (0, import_lodash.chunk)(points, 6);
61736
61735
  const path = new scope.Path();
61737
61736
  path.segments = segmentGroup.map((v) => deserializeSegment(v, scope, matrix));
61738
61737
  return path;
@@ -61742,7 +61741,27 @@ var AnimationFrame = class {
61742
61741
  _defineProperty5(this, "callbacks", []);
61743
61742
  _defineProperty5(this, "lastTime", 0);
61744
61743
  _defineProperty5(this, "fps", 45);
61744
+ _defineProperty5(this, "lastCallbackTime", 0);
61745
+ _defineProperty5(this, "fpsBuffer", []);
61746
+ _defineProperty5(this, "FPS_REPORT_INTERVAL", 2700);
61745
61747
  _defineProperty5(this, "handleCallbacks", () => {
61748
+ const now = performance.now();
61749
+ if (this.lastCallbackTime > 0) {
61750
+ const actualFps = 1e3 / (now - this.lastCallbackTime);
61751
+ this.fpsBuffer.push(actualFps);
61752
+ if (this.fpsBuffer.length >= this.FPS_REPORT_INTERVAL) {
61753
+ const avg = this.fpsBuffer.reduce((a2, b2) => a2 + b2, 0) / this.fpsBuffer.length;
61754
+ const min = Math.min(...this.fpsBuffer);
61755
+ const sorted = [...this.fpsBuffer].sort((a2, b2) => a2 - b2);
61756
+ const p90 = sorted[Math.floor(sorted.length * 0.9)];
61757
+ metrics().gauge("fps", Math.round(avg), {
61758
+ min: Math.round(min),
61759
+ p90: Math.round(p90)
61760
+ });
61761
+ this.fpsBuffer = [];
61762
+ }
61763
+ }
61764
+ this.lastCallbackTime = now;
61746
61765
  const functions = this.callbacks;
61747
61766
  this.callbacks = [];
61748
61767
  for (let i = 0, l2 = functions.length; i < l2; i++) {
@@ -61850,7 +61869,7 @@ var SegmentsModel = class extends ElementModel {
61850
61869
  onStyleKeyUpdate(_key) {
61851
61870
  }
61852
61871
  };
61853
- var import_lodash4 = __toESM2(require_lodash(), 1);
61872
+ var import_lodash3 = __toESM2(require_lodash(), 1);
61854
61873
  function _defineProperty7(e, r, t) {
61855
61874
  return (r = _toPropertyKey7(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
61856
61875
  }
@@ -61868,6 +61887,8 @@ function _toPrimitive7(t, r) {
61868
61887
  }
61869
61888
  return ("string" === r ? String : Number)(t);
61870
61889
  }
61890
+ var DRAG_FPS = 10;
61891
+ var DRAG_FRAME_MS = 1e3 / DRAG_FPS;
61871
61892
  var WhiteboardTool = class {
61872
61893
  constructor(enableToolEvent, modelGetter, shadowEmitter, scope) {
61873
61894
  _defineProperty7(this, "modelGetter", void 0);
@@ -61876,24 +61897,60 @@ var WhiteboardTool = class {
61876
61897
  _defineProperty7(this, "shadowEmitter", void 0);
61877
61898
  _defineProperty7(this, "enableToolEvent", void 0);
61878
61899
  _defineProperty7(this, "eventAvailable", false);
61900
+ _defineProperty7(this, "lastDragTime", 0);
61901
+ _defineProperty7(this, "dragRafId", 0);
61902
+ _defineProperty7(this, "pendingDragEvent", null);
61879
61903
  _defineProperty7(this, "onMouseDownSelf", (event) => {
61880
61904
  this.eventAvailable = this.enableToolEvent();
61881
61905
  if (!this.eventAvailable) {
61882
61906
  return;
61883
61907
  }
61908
+ this.lastDragTime = 0;
61909
+ if (this.dragRafId) {
61910
+ cancelAnimationFrame(this.dragRafId);
61911
+ this.dragRafId = 0;
61912
+ }
61913
+ this.pendingDragEvent = null;
61884
61914
  this.shadowEmitter.setActive(true);
61885
61915
  this.onMouseDown(event);
61886
61916
  });
61917
+ _defineProperty7(this, "flushPendingDrag", () => {
61918
+ this.dragRafId = 0;
61919
+ if (this.pendingDragEvent) {
61920
+ this.lastDragTime = performance.now();
61921
+ const event = this.pendingDragEvent;
61922
+ this.pendingDragEvent = null;
61923
+ this.onMouseDrag(event);
61924
+ }
61925
+ });
61887
61926
  _defineProperty7(this, "onMouseDragSelf", (event) => {
61888
61927
  if (!this.eventAvailable) {
61889
61928
  return;
61890
61929
  }
61891
- this.onMouseDrag(event);
61930
+ const now = performance.now();
61931
+ if (now - this.lastDragTime >= DRAG_FRAME_MS) {
61932
+ this.lastDragTime = now;
61933
+ this.pendingDragEvent = null;
61934
+ this.onMouseDrag(event);
61935
+ } else {
61936
+ this.pendingDragEvent = event;
61937
+ if (!this.dragRafId) {
61938
+ this.dragRafId = requestAnimationFrame(this.flushPendingDrag);
61939
+ }
61940
+ }
61892
61941
  });
61893
61942
  _defineProperty7(this, "onMouseUpSelf", (event) => {
61894
61943
  if (!this.eventAvailable) {
61895
61944
  return;
61896
61945
  }
61946
+ if (this.dragRafId) {
61947
+ cancelAnimationFrame(this.dragRafId);
61948
+ this.dragRafId = 0;
61949
+ }
61950
+ if (this.pendingDragEvent) {
61951
+ this.onMouseDrag(this.pendingDragEvent);
61952
+ this.pendingDragEvent = null;
61953
+ }
61897
61954
  this.onMouseUp(event);
61898
61955
  this.shadowEmitter.setActive(false);
61899
61956
  });
@@ -61907,7 +61964,7 @@ var WhiteboardTool = class {
61907
61964
  this.tool.onMouseUp = this.onMouseUpSelf;
61908
61965
  }
61909
61966
  };
61910
- var import_lodash3 = __toESM2(require_lodash(), 1);
61967
+ var import_lodash2 = __toESM2(require_lodash(), 1);
61911
61968
  function _defineProperty8(e, r, t) {
61912
61969
  return (r = _toPropertyKey8(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
61913
61970
  }
@@ -61956,7 +62013,7 @@ var LineTool = class extends WhiteboardTool {
61956
62013
  const point = path.getPointAt(distance);
61957
62014
  return [point.x, point.y];
61958
62015
  });
61959
- this.elementModel.setPoints((0, import_lodash3.flattenDeep)(points));
62016
+ this.elementModel.setPoints((0, import_lodash2.flattenDeep)(points));
61960
62017
  }
61961
62018
  }
61962
62019
  onMouseUp(_event) {
@@ -62037,7 +62094,7 @@ var LineModel = class extends ElementModel {
62037
62094
  }
62038
62095
  renderLine() {
62039
62096
  const matrix = new this.scope.Matrix(this.pointsMatrix);
62040
- const papperPoints = (0, import_lodash4.chunk)(this.drawPoints, 2).map((item) => {
62097
+ const papperPoints = (0, import_lodash3.chunk)(this.drawPoints, 2).map((item) => {
62041
62098
  return new this.scope.Point(item[0], item[1]).transform(matrix);
62042
62099
  });
62043
62100
  const path = new this.scope.Path();
@@ -62173,7 +62230,7 @@ var LineControlPoint = class {
62173
62230
  const invertedPoint = point.transform(pointsMatrix.inverted());
62174
62231
  const points = this.model["drawPoints"];
62175
62232
  this.position = invertedPoint;
62176
- const clonedPoints = (0, import_lodash4.cloneDeep)(points);
62233
+ const clonedPoints = (0, import_lodash3.cloneDeep)(points);
62177
62234
  clonedPoints[this.options.index * 2] = invertedPoint.x;
62178
62235
  clonedPoints[this.options.index * 2 + 1] = invertedPoint.y;
62179
62236
  this.model.setPoints(clonedPoints);
@@ -62639,7 +62696,7 @@ var RectangleModel = class extends ElementModel {
62639
62696
  }
62640
62697
  };
62641
62698
  var elementsUndoOrigin = "elementsUndoOrigin";
62642
- var import_lodash5 = __toESM2(require_lodash(), 1);
62699
+ var import_lodash4 = __toESM2(require_lodash(), 1);
62643
62700
  function _defineProperty13(e, r, t) {
62644
62701
  return (r = _toPropertyKey13(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62645
62702
  }
@@ -62707,7 +62764,7 @@ var EraserModel = class extends ElementModel {
62707
62764
  return path;
62708
62765
  }
62709
62766
  parsePoints(points) {
62710
- const groupPoints = (0, import_lodash5.chunk)(points, 2);
62767
+ const groupPoints = (0, import_lodash4.chunk)(points, 2);
62711
62768
  return ae(groupPoints, {
62712
62769
  size: this.strokeWidth,
62713
62770
  smoothing: 0.5,
@@ -62725,7 +62782,7 @@ var EraserModel = class extends ElementModel {
62725
62782
  });
62726
62783
  }
62727
62784
  matrixedPoints() {
62728
- const currentPoints = (0, import_lodash5.chunk)(this.drawPoints, 2).slice(this.sliceBegin);
62785
+ const currentPoints = (0, import_lodash4.chunk)(this.drawPoints, 2).slice(this.sliceBegin);
62729
62786
  return currentPoints.map((_ref) => {
62730
62787
  let [x, y] = _ref;
62731
62788
  return new this.scope.Point(x, y);
@@ -62788,7 +62845,7 @@ var EraserModel = class extends ElementModel {
62788
62845
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
62789
62846
  }
62790
62847
  };
62791
- var import_lodash6 = __toESM2(require_lodash(), 1);
62848
+ var import_lodash5 = __toESM2(require_lodash(), 1);
62792
62849
  function _defineProperty14(e, r, t) {
62793
62850
  return (r = _toPropertyKey14(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62794
62851
  }
@@ -62905,7 +62962,7 @@ var LaserPointerModel = class extends ElementModel {
62905
62962
  const matrix = new this.scope.Matrix(this.pointsMatrix);
62906
62963
  const points = this.cachedPoints || this.points;
62907
62964
  console.log("[][][] ,", this.points.length, this.cachedPoints?.length, this.localPoints.length);
62908
- const groupPoints = (0, import_lodash6.chunk)(points, 2).slice(this.sliceBegin);
62965
+ const groupPoints = (0, import_lodash5.chunk)(points, 2).slice(this.sliceBegin);
62909
62966
  return groupPoints.map((_ref) => {
62910
62967
  let [x, y] = _ref;
62911
62968
  return matrix.transform([x, y]);
@@ -62981,7 +63038,7 @@ var WhiteboardPermissions = class extends AbstractApplicationPermissions {
62981
63038
  return [WhiteboardPermissionFlag.draw, WhiteboardPermissionFlag.editSelf, WhiteboardPermissionFlag.editOthers, WhiteboardPermissionFlag.deleteSelf, WhiteboardPermissionFlag.deleteOthers, WhiteboardPermissionFlag.mainView, WhiteboardPermissionFlag.setOthersView].filter((v) => (v & value) !== 0);
62982
63039
  }
62983
63040
  };
62984
- var import_lodash7 = __toESM2(require_lodash(), 1);
63041
+ var import_lodash6 = __toESM2(require_lodash(), 1);
62985
63042
  function _defineProperty15(e, r, t) {
62986
63043
  return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62987
63044
  }
@@ -63040,7 +63097,7 @@ var StraightLineModel = class extends ElementModel {
63040
63097
  }
63041
63098
  renderLine() {
63042
63099
  const matrix = new this.scope.Matrix(this.pointsMatrix);
63043
- const papperPoints = (0, import_lodash7.chunk)(this.drawPoints, 2).map((item) => {
63100
+ const papperPoints = (0, import_lodash6.chunk)(this.drawPoints, 2).map((item) => {
63044
63101
  return new this.scope.Point(item[0], item[1]).transform(matrix);
63045
63102
  });
63046
63103
  const path = new this.scope.Path();
@@ -63654,7 +63711,7 @@ var RenderableModel = class extends EventEmitter {
63654
63711
  });
63655
63712
  }
63656
63713
  };
63657
- var import_lodash8 = __toESM2(require_lodash(), 1);
63714
+ var import_lodash7 = __toESM2(require_lodash(), 1);
63658
63715
  function Point(x, y) {
63659
63716
  this.X = x;
63660
63717
  this.Y = y;
@@ -63897,7 +63954,7 @@ var Recognizer = class {
63897
63954
  let maxX = -Number.MAX_VALUE;
63898
63955
  let minY = Number.MAX_VALUE;
63899
63956
  let maxY = -Number.MAX_VALUE;
63900
- const result = this.dollar.Recognize((0, import_lodash8.chunk)(points, 2).map((v) => {
63957
+ const result = this.dollar.Recognize((0, import_lodash7.chunk)(points, 3).map((v) => {
63901
63958
  minX = Math.min(minX, v[0]);
63902
63959
  maxX = Math.max(maxX, v[0]);
63903
63960
  minY = Math.min(minY, v[1]);
@@ -63939,11 +63996,24 @@ var CurveTool = class extends WhiteboardTool {
63939
63996
  _defineProperty19(this, "elementModel", null);
63940
63997
  _defineProperty19(this, "recognizer", new Recognizer());
63941
63998
  _defineProperty19(this, "pointCount", 0);
63999
+ _defineProperty19(this, "pendingPoints", []);
64000
+ _defineProperty19(this, "flushRafId", 0);
63942
64001
  _defineProperty19(this, "showLiveCursor", true);
63943
- this.tool.minDistance = 20;
64002
+ _defineProperty19(this, "flushPendingPoints", () => {
64003
+ this.flushRafId = 0;
64004
+ if (this.elementModel && this.pendingPoints.length > 0) {
64005
+ this.elementModel.appendPoints(this.pendingPoints);
64006
+ this.pendingPoints = [];
64007
+ }
64008
+ });
63944
64009
  }
63945
64010
  onMouseDown(_event) {
63946
64011
  this.pointCount = 0;
64012
+ this.pendingPoints = [];
64013
+ if (this.flushRafId) {
64014
+ cancelAnimationFrame(this.flushRafId);
64015
+ this.flushRafId = 0;
64016
+ }
63947
64017
  if (this.elementModel) {
63948
64018
  this.elementModel.dispose();
63949
64019
  }
@@ -63958,27 +64028,38 @@ var CurveTool = class extends WhiteboardTool {
63958
64028
  if (this.pointCount > 1024) {
63959
64029
  return;
63960
64030
  }
63961
- const MIN_DISTANCE = 4;
64031
+ const MIN_DISTANCE = 2;
63962
64032
  if (this.elementModel) {
63963
- const len = this.elementModel.points.length;
63964
- let last = {
63965
- x: 0,
63966
- y: 0
63967
- };
63968
- if (len >= 2) {
63969
- last = {
63970
- x: this.elementModel.points[len - 2],
63971
- y: this.elementModel.points[len - 1]
63972
- };
64033
+ let lastX = 0;
64034
+ let lastY = 0;
64035
+ if (this.pendingPoints.length >= 3) {
64036
+ lastX = this.pendingPoints[this.pendingPoints.length - 3];
64037
+ lastY = this.pendingPoints[this.pendingPoints.length - 2];
64038
+ } else {
64039
+ const len = this.elementModel.points.length;
64040
+ if (len >= 3) {
64041
+ lastX = this.elementModel.points[len - 3];
64042
+ lastY = this.elementModel.points[len - 2];
64043
+ }
63973
64044
  }
63974
- const dist = Math.max(Math.abs(last.x - event.point.x), Math.abs(last.y - event.point.y));
64045
+ const dist = Math.max(Math.abs(lastX - event.point.x), Math.abs(lastY - event.point.y));
63975
64046
  if (dist >= MIN_DISTANCE) {
63976
64047
  this.pointCount += 1;
63977
- this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
64048
+ const nativeEvent = event.event;
64049
+ const pressure = nativeEvent.pointerType === "pen" && nativeEvent.pressure > 0 ? nativeEvent.pressure : 0;
64050
+ this.pendingPoints.push(event.point.x, event.point.y, pressure);
64051
+ if (!this.flushRafId) {
64052
+ this.flushRafId = requestAnimationFrame(this.flushPendingPoints);
64053
+ }
63978
64054
  }
63979
64055
  }
63980
64056
  }
63981
64057
  onMouseUp(event) {
64058
+ if (this.flushRafId) {
64059
+ cancelAnimationFrame(this.flushRafId);
64060
+ this.flushRafId = 0;
64061
+ }
64062
+ this.flushPendingPoints();
63982
64063
  this.modelGetter().then((model) => {
63983
64064
  if (!model) {
63984
64065
  return;
@@ -67127,6 +67208,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
67127
67208
  _defineProperty43(this, "permissions", void 0);
67128
67209
  _defineProperty43(this, "inputType", "any");
67129
67210
  _defineProperty43(this, "isPenEvent", false);
67211
+ _defineProperty43(this, "activePenPointerId", null);
67130
67212
  _defineProperty43(this, "hasPenInput", null);
67131
67213
  _defineProperty43(this, "disableViewModelUpdate", false);
67132
67214
  _defineProperty43(this, "internalResizeObserver", true);
@@ -67455,11 +67537,34 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
67455
67537
  this.imageSets.setAttribute("data-image-sets", "");
67456
67538
  this.rootElement.appendChild(this.imageSets);
67457
67539
  document.body.addEventListener("pointerdown", (evt) => {
67458
- this.isPenEvent = evt.pointerType === "pen";
67459
- if (evt.pointerType === "pen" && this.hasPenInput === null) {
67460
- this.hasPenInput = true;
67461
- this.inputType = "pen";
67462
- this.emitter.emit("inputTypeChange", this.inputType);
67540
+ if (evt.pointerType === "pen") {
67541
+ this.isPenEvent = true;
67542
+ this.activePenPointerId = evt.pointerId;
67543
+ if (this.hasPenInput === null) {
67544
+ this.hasPenInput = true;
67545
+ this.inputType = "pen";
67546
+ this.emitter.emit("inputTypeChange", this.inputType);
67547
+ }
67548
+ } else {
67549
+ if (this.activePenPointerId === null) {
67550
+ this.isPenEvent = false;
67551
+ }
67552
+ }
67553
+ }, {
67554
+ capture: true
67555
+ });
67556
+ document.body.addEventListener("pointerup", (evt) => {
67557
+ if (evt.pointerId === this.activePenPointerId) {
67558
+ this.activePenPointerId = null;
67559
+ this.isPenEvent = false;
67560
+ }
67561
+ }, {
67562
+ capture: true
67563
+ });
67564
+ document.body.addEventListener("pointercancel", (evt) => {
67565
+ if (evt.pointerId === this.activePenPointerId) {
67566
+ this.activePenPointerId = null;
67567
+ this.isPenEvent = false;
67463
67568
  }
67464
67569
  }, {
67465
67570
  capture: true