@netless/forge-whiteboard 1.2.0-alpha.1 → 1.2.0-beta.0

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.
Files changed (45) hide show
  1. package/changelog.md +13 -1
  2. package/dist/LiveCursor.d.ts +2 -1
  3. package/dist/LiveCursor.d.ts.map +1 -1
  4. package/dist/Whiteboard.d.ts +10 -0
  5. package/dist/Whiteboard.d.ts.map +1 -1
  6. package/dist/WhiteboardApplication.d.ts +6 -0
  7. package/dist/WhiteboardApplication.d.ts.map +1 -1
  8. package/dist/edit/Editor.d.ts.map +1 -1
  9. package/dist/model/RenderableModel.d.ts +15 -1
  10. package/dist/model/RenderableModel.d.ts.map +1 -1
  11. package/dist/model/renderable/CurveModel.d.ts +6 -3
  12. package/dist/model/renderable/CurveModel.d.ts.map +1 -1
  13. package/dist/model/renderable/ElementModel.d.ts +20 -1
  14. package/dist/model/renderable/ElementModel.d.ts.map +1 -1
  15. package/dist/model/renderable/EraserModel.d.ts +5 -1
  16. package/dist/model/renderable/EraserModel.d.ts.map +1 -1
  17. package/dist/model/renderable/ImageModel.d.ts +4 -1
  18. package/dist/model/renderable/ImageModel.d.ts.map +1 -1
  19. package/dist/model/renderable/LaserPointerModel.d.ts +8 -2
  20. package/dist/model/renderable/LaserPointerModel.d.ts.map +1 -1
  21. package/dist/model/renderable/LineModel.d.ts +5 -1
  22. package/dist/model/renderable/LineModel.d.ts.map +1 -1
  23. package/dist/model/renderable/PointTextModel.d.ts +6 -1
  24. package/dist/model/renderable/PointTextModel.d.ts.map +1 -1
  25. package/dist/model/renderable/RectangleModel.d.ts +5 -1
  26. package/dist/model/renderable/RectangleModel.d.ts.map +1 -1
  27. package/dist/model/renderable/SegmentsModel.d.ts +5 -1
  28. package/dist/model/renderable/SegmentsModel.d.ts.map +1 -1
  29. package/dist/model/renderable/SelectorModel.d.ts +5 -1
  30. package/dist/model/renderable/SelectorModel.d.ts.map +1 -1
  31. package/dist/model/renderable/StraightLineModel.d.ts +5 -1
  32. package/dist/model/renderable/StraightLineModel.d.ts.map +1 -1
  33. package/dist/model/renderable/TriangleModel.d.ts +5 -1
  34. package/dist/model/renderable/TriangleModel.d.ts.map +1 -1
  35. package/dist/tool/CurveTool.d.ts +3 -0
  36. package/dist/tool/CurveTool.d.ts.map +1 -1
  37. package/dist/tool/LaserPointerTool.d.ts.map +1 -1
  38. package/dist/tool/WhiteboardTool.d.ts +4 -0
  39. package/dist/tool/WhiteboardTool.d.ts.map +1 -1
  40. package/dist/utils/paperjs.d.ts.map +1 -1
  41. package/dist/whiteboard.esm.js +794 -278
  42. package/dist/whiteboard.esm.js.map +3 -3
  43. package/dist/whiteboard.js +830 -314
  44. package/dist/whiteboard.js.map +3 -3
  45. package/package.json +2 -2
@@ -20839,8 +20839,8 @@ var require_lodash = __commonJS({
20839
20839
  }
20840
20840
  var runInContext = function runInContext2(context) {
20841
20841
  context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
20842
- var Array13 = context.Array, Date2 = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
20843
- var arrayProto = Array13.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
20842
+ var Array14 = context.Array, Date2 = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
20843
+ var arrayProto = Array14.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
20844
20844
  var coreJsData = context["__core-js_shared__"];
20845
20845
  var funcToString = funcProto.toString;
20846
20846
  var hasOwnProperty = objectProto.hasOwnProperty;
@@ -21263,7 +21263,7 @@ var require_lodash = __commonJS({
21263
21263
  }
21264
21264
  }
21265
21265
  function baseAt(object, paths) {
21266
- var index = -1, length = paths.length, result2 = Array13(length), skip = object == null;
21266
+ var index = -1, length = paths.length, result2 = Array14(length), skip = object == null;
21267
21267
  while (++index < length) {
21268
21268
  result2[index] = skip ? undefined2 : get(object, paths[index]);
21269
21269
  }
@@ -21509,7 +21509,7 @@ var require_lodash = __commonJS({
21509
21509
  return number >= nativeMin(start, end) && number < nativeMax(start, end);
21510
21510
  }
21511
21511
  function baseIntersection(arrays, iteratee2, comparator) {
21512
- var includes2 = comparator ? arrayIncludesWith : arrayIncludes, length = arrays[0].length, othLength = arrays.length, othIndex = othLength, caches = Array13(othLength), maxLength = Infinity, result2 = [];
21512
+ var includes2 = comparator ? arrayIncludesWith : arrayIncludes, length = arrays[0].length, othLength = arrays.length, othIndex = othLength, caches = Array14(othLength), maxLength = Infinity, result2 = [];
21513
21513
  while (othIndex--) {
21514
21514
  var array = arrays[othIndex];
21515
21515
  if (othIndex && iteratee2) {
@@ -21690,7 +21690,7 @@ var require_lodash = __commonJS({
21690
21690
  return value < other;
21691
21691
  }
21692
21692
  function baseMap(collection, iteratee2) {
21693
- var index = -1, result2 = isArrayLike(collection) ? Array13(collection.length) : [];
21693
+ var index = -1, result2 = isArrayLike(collection) ? Array14(collection.length) : [];
21694
21694
  baseEach(collection, function(value, key, collection2) {
21695
21695
  result2[++index] = iteratee2(value, key, collection2);
21696
21696
  });
@@ -21865,7 +21865,7 @@ var require_lodash = __commonJS({
21865
21865
  return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
21866
21866
  }
21867
21867
  function baseRange(start, end, step, fromRight) {
21868
- var index = -1, length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), result2 = Array13(length);
21868
+ var index = -1, length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), result2 = Array14(length);
21869
21869
  while (length--) {
21870
21870
  result2[fromRight ? length : ++index] = start;
21871
21871
  start += step;
@@ -21947,7 +21947,7 @@ var require_lodash = __commonJS({
21947
21947
  }
21948
21948
  length = start > end ? 0 : end - start >>> 0;
21949
21949
  start >>>= 0;
21950
- var result2 = Array13(length);
21950
+ var result2 = Array14(length);
21951
21951
  while (++index < length) {
21952
21952
  result2[index] = array[index + start];
21953
21953
  }
@@ -22107,7 +22107,7 @@ var require_lodash = __commonJS({
22107
22107
  if (length < 2) {
22108
22108
  return length ? baseUniq(arrays[0]) : [];
22109
22109
  }
22110
- var index = -1, result2 = Array13(length);
22110
+ var index = -1, result2 = Array14(length);
22111
22111
  while (++index < length) {
22112
22112
  var array = arrays[index], othIndex = -1;
22113
22113
  while (++othIndex < length) {
@@ -22204,7 +22204,7 @@ var require_lodash = __commonJS({
22204
22204
  return object.index - other.index;
22205
22205
  }
22206
22206
  function composeArgs(args, partials, holders, isCurried) {
22207
- var argsIndex = -1, argsLength = args.length, holdersLength = holders.length, leftIndex = -1, leftLength = partials.length, rangeLength = nativeMax(argsLength - holdersLength, 0), result2 = Array13(leftLength + rangeLength), isUncurried = !isCurried;
22207
+ var argsIndex = -1, argsLength = args.length, holdersLength = holders.length, leftIndex = -1, leftLength = partials.length, rangeLength = nativeMax(argsLength - holdersLength, 0), result2 = Array14(leftLength + rangeLength), isUncurried = !isCurried;
22208
22208
  while (++leftIndex < leftLength) {
22209
22209
  result2[leftIndex] = partials[leftIndex];
22210
22210
  }
@@ -22219,7 +22219,7 @@ var require_lodash = __commonJS({
22219
22219
  return result2;
22220
22220
  }
22221
22221
  function composeArgsRight(args, partials, holders, isCurried) {
22222
- var argsIndex = -1, argsLength = args.length, holdersIndex = -1, holdersLength = holders.length, rightIndex = -1, rightLength = partials.length, rangeLength = nativeMax(argsLength - holdersLength, 0), result2 = Array13(rangeLength + rightLength), isUncurried = !isCurried;
22222
+ var argsIndex = -1, argsLength = args.length, holdersIndex = -1, holdersLength = holders.length, rightIndex = -1, rightLength = partials.length, rangeLength = nativeMax(argsLength - holdersLength, 0), result2 = Array14(rangeLength + rightLength), isUncurried = !isCurried;
22223
22223
  while (++argsIndex < rangeLength) {
22224
22224
  result2[argsIndex] = args[argsIndex];
22225
22225
  }
@@ -22236,7 +22236,7 @@ var require_lodash = __commonJS({
22236
22236
  }
22237
22237
  function copyArray(source, array) {
22238
22238
  var index = -1, length = source.length;
22239
- array || (array = Array13(length));
22239
+ array || (array = Array14(length));
22240
22240
  while (++index < length) {
22241
22241
  array[index] = source[index];
22242
22242
  }
@@ -22369,7 +22369,7 @@ var require_lodash = __commonJS({
22369
22369
  function createCurry(func, bitmask, arity) {
22370
22370
  var Ctor = createCtor(func);
22371
22371
  function wrapper() {
22372
- var length = arguments.length, args = Array13(length), index = length, placeholder = getHolder(wrapper);
22372
+ var length = arguments.length, args = Array14(length), index = length, placeholder = getHolder(wrapper);
22373
22373
  while (index--) {
22374
22374
  args[index] = arguments[index];
22375
22375
  }
@@ -22449,7 +22449,7 @@ var require_lodash = __commonJS({
22449
22449
  function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary2, arity) {
22450
22450
  var isAry = bitmask & WRAP_ARY_FLAG, isBind = bitmask & WRAP_BIND_FLAG, isBindKey = bitmask & WRAP_BIND_KEY_FLAG, isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), isFlip = bitmask & WRAP_FLIP_FLAG, Ctor = isBindKey ? undefined2 : createCtor(func);
22451
22451
  function wrapper() {
22452
- var length = arguments.length, args = Array13(length), index = length;
22452
+ var length = arguments.length, args = Array14(length), index = length;
22453
22453
  while (index--) {
22454
22454
  args[index] = arguments[index];
22455
22455
  }
@@ -22548,7 +22548,7 @@ var require_lodash = __commonJS({
22548
22548
  function createPartial(func, bitmask, thisArg, partials) {
22549
22549
  var isBind = bitmask & WRAP_BIND_FLAG, Ctor = createCtor(func);
22550
22550
  function wrapper() {
22551
- var argsIndex = -1, argsLength = arguments.length, leftIndex = -1, leftLength = partials.length, args = Array13(leftLength + argsLength), fn = this && this !== root && this instanceof wrapper ? Ctor : func;
22551
+ var argsIndex = -1, argsLength = arguments.length, leftIndex = -1, leftLength = partials.length, args = Array14(leftLength + argsLength), fn = this && this !== root && this instanceof wrapper ? Ctor : func;
22552
22552
  while (++leftIndex < leftLength) {
22553
22553
  args[leftIndex] = partials[leftIndex];
22554
22554
  }
@@ -23161,12 +23161,12 @@ var require_lodash = __commonJS({
23161
23161
  function overRest(func, start, transform2) {
23162
23162
  start = nativeMax(start === undefined2 ? func.length - 1 : start, 0);
23163
23163
  return function() {
23164
- var args = arguments, index = -1, length = nativeMax(args.length - start, 0), array = Array13(length);
23164
+ var args = arguments, index = -1, length = nativeMax(args.length - start, 0), array = Array14(length);
23165
23165
  while (++index < length) {
23166
23166
  array[index] = args[start + index];
23167
23167
  }
23168
23168
  index = -1;
23169
- var otherArgs = Array13(start + 1);
23169
+ var otherArgs = Array14(start + 1);
23170
23170
  while (++index < start) {
23171
23171
  otherArgs[index] = args[index];
23172
23172
  }
@@ -23278,7 +23278,7 @@ var require_lodash = __commonJS({
23278
23278
  result2.__values__ = wrapper.__values__;
23279
23279
  return result2;
23280
23280
  }
23281
- function chunk8(array, size2, guard) {
23281
+ function chunk7(array, size2, guard) {
23282
23282
  if (guard ? isIterateeCall(array, size2, guard) : size2 === undefined2) {
23283
23283
  size2 = 1;
23284
23284
  } else {
@@ -23288,7 +23288,7 @@ var require_lodash = __commonJS({
23288
23288
  if (!length || size2 < 1) {
23289
23289
  return [];
23290
23290
  }
23291
- var index = 0, resIndex = 0, result2 = Array13(nativeCeil(length / size2));
23291
+ var index = 0, resIndex = 0, result2 = Array14(nativeCeil(length / size2));
23292
23292
  while (index < length) {
23293
23293
  result2[resIndex++] = baseSlice(array, index, index += size2);
23294
23294
  }
@@ -23309,7 +23309,7 @@ var require_lodash = __commonJS({
23309
23309
  if (!length) {
23310
23310
  return [];
23311
23311
  }
23312
- var args = Array13(length - 1), array = arguments[0], index = length;
23312
+ var args = Array14(length - 1), array = arguments[0], index = length;
23313
23313
  while (index--) {
23314
23314
  args[index - 1] = arguments[index];
23315
23315
  }
@@ -23811,7 +23811,7 @@ var require_lodash = __commonJS({
23811
23811
  return isString(collection) ? fromIndex <= length && collection.indexOf(value, fromIndex) > -1 : !!length && baseIndexOf(collection, value, fromIndex) > -1;
23812
23812
  }
23813
23813
  var invokeMap = baseRest(function(collection, path, args) {
23814
- var index = -1, isFunc = typeof path == "function", result2 = isArrayLike(collection) ? Array13(collection.length) : [];
23814
+ var index = -1, isFunc = typeof path == "function", result2 = isArrayLike(collection) ? Array14(collection.length) : [];
23815
23815
  baseEach(collection, function(value) {
23816
23816
  result2[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
23817
23817
  });
@@ -24194,7 +24194,7 @@ var require_lodash = __commonJS({
24194
24194
  }()) ? baseIsArguments : function(value) {
24195
24195
  return isObjectLike(value) && hasOwnProperty.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
24196
24196
  };
24197
- var isArray = Array13.isArray;
24197
+ var isArray = Array14.isArray;
24198
24198
  var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
24199
24199
  function isArrayLike(value) {
24200
24200
  return value != null && isLength(value.length) && !isFunction(value);
@@ -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 = chunk8;
25153
+ lodash.chunk = chunk7;
25154
25154
  lodash.compact = compact;
25155
25155
  lodash.concat = concat;
25156
25156
  lodash.cond = cond;
@@ -25639,7 +25639,7 @@ __export(src_exports, {
25639
25639
  module.exports = __toCommonJS(src_exports);
25640
25640
 
25641
25641
  // src/WhiteboardApplication.ts
25642
- var import_forge_room12 = require("@netless/forge-room");
25642
+ var import_forge_room14 = require("@netless/forge-room");
25643
25643
  var Y15 = __toESM(require("yjs"), 1);
25644
25644
  var import_paper = __toESM(require_paper_full(), 1);
25645
25645
 
@@ -25647,7 +25647,7 @@ var import_paper = __toESM(require_paper_full(), 1);
25647
25647
  var Y12 = __toESM(require("yjs"), 1);
25648
25648
  var import_eventemitter3 = __toESM(require("eventemitter3"), 1);
25649
25649
  var import_uuid = require("uuid");
25650
- var import_forge_room4 = require("@netless/forge-room");
25650
+ 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);
@@ -25800,9 +25800,6 @@ function ae(e, t = {}) {
25800
25800
  return ce(me(e, t), t);
25801
25801
  }
25802
25802
 
25803
- // src/model/renderable/CurveModel.ts
25804
- var import_lodash = __toESM(require_lodash(), 1);
25805
-
25806
25803
  // src/model/renderable/ElementModel.ts
25807
25804
  var Y = __toESM(require("yjs"), 1);
25808
25805
  var import_forge_room = require("@netless/forge-room");
@@ -25890,12 +25887,23 @@ var ElementModel = class _ElementModel {
25890
25887
  set shadow(value) {
25891
25888
  this.root.set(_ElementModel.KEYS.shadow, value);
25892
25889
  }
25893
- constructor(root, scope, liveCursor) {
25890
+ get isPerformanceEnvironment() {
25891
+ return this.isPerformanceMode() && this.shouldUseLocalPoints;
25892
+ }
25893
+ constructor(root, scope, liveCursor, isPerformanceMode) {
25894
25894
  _defineProperty(this, "shadowEmitter", null);
25895
25895
  _defineProperty(this, "root", void 0);
25896
25896
  _defineProperty(this, "scope", void 0);
25897
25897
  _defineProperty(this, "item", void 0);
25898
+ _defineProperty(this, "clearLocalPointsWhenYPointsChange", void 0);
25899
+ _defineProperty(this, "shouldUseLocalPoints", void 0);
25900
+ _defineProperty(this, "localPointsPick", void 0);
25898
25901
  _defineProperty(this, "liveCursor", void 0);
25902
+ _defineProperty(this, "appendPointsTimer", null);
25903
+ _defineProperty(this, "setPointsTimer", null);
25904
+ _defineProperty(this, "pointsUpdateTimer", null);
25905
+ _defineProperty(this, "isPerformanceMode", void 0);
25906
+ _defineProperty(this, "localPoints", []);
25899
25907
  _defineProperty(this, "handlePropChange", (events) => {
25900
25908
  if (!this.item) {
25901
25909
  return;
@@ -25934,23 +25942,80 @@ var ElementModel = class _ElementModel {
25934
25942
  }
25935
25943
  }
25936
25944
  } else if (event.target === this.root.get(_ElementModel.KEYS.points)) {
25937
- this.onVectorUpdate();
25938
- const liveCursorPoint = this.liveCursorPoint();
25939
- const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
25940
- if (liveCursorPoint && ownerId) {
25941
- this.liveCursor.updateCursorPosition(liveCursorPoint, this.root.get(_ElementModel.KEYS.ownerId));
25945
+ if (this.isPerformanceEnvironment) {
25946
+ this.handlePointsChangePerformance();
25947
+ } else {
25948
+ this.handlePointsChangeDirect();
25942
25949
  }
25943
25950
  } else {
25944
25951
  }
25945
25952
  }
25946
25953
  });
25954
+ _defineProperty(this, "onPointsArrayChange", (points) => {
25955
+ if (this.localPoints.length >= points.length) {
25956
+ return;
25957
+ }
25958
+ const pointsChunk = points.slice(this.localPoints.length, this.localPoints.length + this.localPointsPick);
25959
+ this.localPoints = this.localPoints.concat(pointsChunk);
25960
+ this.onVectorUpdate();
25961
+ this.pointsUpdateTimer = window.requestAnimationFrame(() => {
25962
+ this.onPointsArrayChange(points);
25963
+ });
25964
+ });
25965
+ this.isPerformanceMode = isPerformanceMode;
25947
25966
  this.scope = scope;
25948
25967
  this.liveCursor = liveCursor;
25949
25968
  this.root = root;
25950
- if (!this.root.has(_ElementModel.KEYS.pointsMatrix)) {
25969
+ if (this.root.doc) {
25970
+ if (!this.root.has(_ElementModel.KEYS.pointsMatrix)) {
25971
+ this.root.set(_ElementModel.KEYS.pointsMatrix, [1, 0, 0, 1, 0, 0]);
25972
+ }
25973
+ } else {
25951
25974
  this.root.set(_ElementModel.KEYS.pointsMatrix, [1, 0, 0, 1, 0, 0]);
25952
25975
  }
25976
+ }
25977
+ bindObserver() {
25978
+ const beforeL = this.root._eH?.l?.length ?? -1;
25979
+ const beforeDL = this.root._dEH?.l?.length ?? -1;
25980
+ (0, import_forge_room.removeDeepObserver)(this.root, this.handlePropChange);
25981
+ this.subBindObserver();
25982
+ const afterRemoveL = this.root._eH?.l?.length ?? -1;
25983
+ const afterRemoveDL = this.root._dEH?.l?.length ?? -1;
25953
25984
  this.root.observeDeep(this.handlePropChange);
25985
+ const afterAddL = this.root._eH?.l?.length ?? -1;
25986
+ const afterAddDL = this.root._dEH?.l?.length ?? -1;
25987
+ console.log(`[][][] bindObserver uuid=${this.uuid} doc=${!!this.root.doc} _eH: ${beforeL}->${afterRemoveL}->${afterAddL} _dEH: ${beforeDL}->${afterRemoveDL}->${afterAddDL}`);
25988
+ }
25989
+ subBindObserver() {
25990
+ }
25991
+ handlePointsChangeDirect() {
25992
+ this.onVectorUpdate();
25993
+ const liveCursorPoint = this.liveCursorPoint();
25994
+ const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
25995
+ if (liveCursorPoint && ownerId) {
25996
+ this.liveCursor.updateCursorPosition(liveCursorPoint, this.root.get(_ElementModel.KEYS.ownerId));
25997
+ }
25998
+ }
25999
+ handlePointsChangePerformance() {
26000
+ const liveCursorPoint = this.liveCursorPoint();
26001
+ const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
26002
+ if (liveCursorPoint && ownerId) {
26003
+ this.liveCursor.updateCursorPosition(liveCursorPoint, this.root.get(_ElementModel.KEYS.ownerId));
26004
+ }
26005
+ if (this.liveCursor.userManager.selfId !== ownerId || this.localPoints.length === 0) {
26006
+ if (this.pointsUpdateTimer) {
26007
+ window.cancelAnimationFrame(this.pointsUpdateTimer);
26008
+ }
26009
+ if (this.shadow == "") {
26010
+ this.localPoints = this.points;
26011
+ this.onVectorUpdate();
26012
+ } else {
26013
+ if (this.clearLocalPointsWhenYPointsChange) {
26014
+ this.localPoints = [];
26015
+ }
26016
+ this.onPointsArrayChange(this.points);
26017
+ }
26018
+ }
25954
26019
  }
25955
26020
  createPaperElement() {
25956
26021
  this.createPaperItem();
@@ -25963,14 +26028,48 @@ var ElementModel = class _ElementModel {
25963
26028
  }
25964
26029
  }
25965
26030
  appendPoints(points) {
26031
+ if (this.isPerformanceEnvironment) {
26032
+ this.appendPointsPerformance(points);
26033
+ } else {
26034
+ this.appendPointsDirect(points);
26035
+ }
26036
+ }
26037
+ appendPointsDirect(points) {
25966
26038
  this.root.get(_ElementModel.KEYS.points).push(points);
25967
26039
  }
26040
+ appendPointsPerformance(points) {
26041
+ this.localPoints = this.localPoints.concat(points);
26042
+ this.onVectorUpdate();
26043
+ if (this.appendPointsTimer) {
26044
+ window.clearTimeout(this.appendPointsTimer);
26045
+ }
26046
+ if (this.localPoints.length % 80 === 0) {
26047
+ const yArray = this.root.get(_ElementModel.KEYS.points);
26048
+ yArray?.push(this.localPoints.slice(yArray.length));
26049
+ }
26050
+ this.appendPointsTimer = window.setTimeout(() => {
26051
+ this.appendPointsTimer = null;
26052
+ if (this.localPoints.length > 0) {
26053
+ const yArray = this.root.get(_ElementModel.KEYS.points);
26054
+ yArray?.push(this.localPoints.slice(yArray.length));
26055
+ }
26056
+ }, 100);
26057
+ }
25968
26058
  setPoints(points) {
26059
+ if (this.isPerformanceEnvironment) {
26060
+ this.setPointsPerformance(points);
26061
+ } else {
26062
+ this.setPointsDirect(points);
26063
+ }
26064
+ }
26065
+ setPointsDirect(points) {
25969
26066
  if (this.root.doc) {
25970
26067
  this.root.doc.transact(() => {
25971
26068
  const yArray = this.root.get(_ElementModel.KEYS.points);
25972
- yArray.delete(0, yArray.length);
25973
- yArray.push(points);
26069
+ if (yArray) {
26070
+ yArray.delete(0, yArray.length);
26071
+ yArray.push(points);
26072
+ }
25974
26073
  });
25975
26074
  } else {
25976
26075
  const yArray = this.root.get(_ElementModel.KEYS.points) || new Y.Array();
@@ -25979,6 +26078,29 @@ var ElementModel = class _ElementModel {
25979
26078
  this.root.set(_ElementModel.KEYS.points, yArray);
25980
26079
  }
25981
26080
  }
26081
+ setPointsPerformance(points) {
26082
+ this.localPoints = points;
26083
+ this.onVectorUpdate();
26084
+ if (this.setPointsTimer) {
26085
+ window.clearTimeout(this.setPointsTimer);
26086
+ }
26087
+ this.setPointsTimer = window.setTimeout(() => {
26088
+ if (this.root.doc) {
26089
+ this.root.doc.transact(() => {
26090
+ const yArray = this.root.get(_ElementModel.KEYS.points);
26091
+ if (yArray) {
26092
+ yArray.delete(0, yArray.length);
26093
+ yArray.push(points);
26094
+ }
26095
+ });
26096
+ } else {
26097
+ const yArray = this.root.get(_ElementModel.KEYS.points) || new Y.Array();
26098
+ yArray.delete(0, yArray.length);
26099
+ yArray.push(points);
26100
+ this.root.set(_ElementModel.KEYS.points, yArray);
26101
+ }
26102
+ }, 100);
26103
+ }
25982
26104
  appendPointsMatrix(matrix) {
25983
26105
  const current = new this.scope.Matrix(this.pointsMatrix);
25984
26106
  const next = matrix.appended(current);
@@ -26005,6 +26127,9 @@ var ElementModel = class _ElementModel {
26005
26127
  }
26006
26128
  dispose() {
26007
26129
  this.subDispose();
26130
+ }
26131
+ disposeObserver() {
26132
+ console.log(`[][][] disposeObserver uuid=${this.uuid}`);
26008
26133
  (0, import_forge_room.removeDeepObserver)(this.root, this.handlePropChange);
26009
26134
  }
26010
26135
  };
@@ -26077,47 +26202,72 @@ function _toPrimitive3(t, r) {
26077
26202
  return ("string" === r ? String : Number)(t);
26078
26203
  }
26079
26204
  var CurveModel = class extends ElementModel {
26080
- constructor(root, scope, liveCursor) {
26081
- super(root, scope, liveCursor);
26205
+ constructor(root, scope, liveCursor, isPerformanceMode) {
26206
+ super(root, scope, liveCursor, isPerformanceMode);
26082
26207
  _defineProperty3(this, "item", null);
26083
- _defineProperty3(this, "debugPath", void 0);
26084
26208
  _defineProperty3(this, "debug", false);
26085
- if (!this.root.has("type")) {
26209
+ _defineProperty3(this, "clearLocalPointsWhenYPointsChange", false);
26210
+ _defineProperty3(this, "shouldUseLocalPoints", true);
26211
+ _defineProperty3(this, "localPointsPick", 6);
26212
+ if (!this.root.doc || !this.root.has("type")) {
26086
26213
  this.root.set("type", "curve");
26087
26214
  }
26088
- if (!this.root.has("points")) {
26215
+ if (!this.root.doc || !this.root.has("points")) {
26089
26216
  this.root.set("points", new Y2.Array());
26090
26217
  }
26091
- this.debugPath = new scope.Path();
26092
26218
  }
26093
26219
  average(a2, b2) {
26094
26220
  return (a2 + b2) / 2;
26095
26221
  }
26096
26222
  parsePoints(points) {
26223
+ const hasRealPressure = points.some((p) => p.length >= 3 && p[2] > 0);
26224
+ const viewScale = this.scope.project.view.matrix.scaling.x || 1;
26225
+ const taper = this.strokeWidth * 5 / viewScale;
26226
+ const streamline = Math.min(0.7, 0.7 * viewScale);
26097
26227
  return ae(points, {
26098
26228
  size: this.strokeWidth,
26099
- smoothing: 0.5,
26100
- thinning: -0.5,
26101
- streamline: 0.5,
26102
- simulatePressure: true,
26229
+ smoothing: 0.7,
26230
+ thinning: 0.5,
26231
+ streamline,
26232
+ simulatePressure: !hasRealPressure,
26103
26233
  start: {
26104
- taper: this.strokeWidth * 10,
26234
+ taper,
26105
26235
  cap: true
26106
26236
  },
26107
26237
  end: {
26108
- taper: this.strokeWidth * 20,
26238
+ taper,
26109
26239
  cap: true
26110
26240
  }
26111
26241
  });
26112
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
+ }
26113
26261
  matrixedPoints() {
26114
- const points = this.points;
26262
+ const points = this.localPoints.length === 0 ? this.points : this.localPoints;
26115
26263
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26116
26264
  const output = [];
26117
- for (let i = 0, len = points.length; i < len; i += 2) {
26265
+ const stride = this.pointStride(points);
26266
+ for (let i = 0, len = points.length; i + 1 < len; i += stride) {
26118
26267
  const p = new this.scope.Point(points[i], points[i + 1]);
26119
26268
  const tp = p.transform(matrix);
26120
- output.push([tp.x, tp.y]);
26269
+ const pressure = stride === 3 ? points[i + 2] ?? 0 : 0;
26270
+ output.push([tp.x, tp.y, pressure]);
26121
26271
  }
26122
26272
  return output;
26123
26273
  }
@@ -26146,34 +26296,30 @@ var CurveModel = class extends ElementModel {
26146
26296
  }
26147
26297
  return path;
26148
26298
  }
26149
- updateDebugPath() {
26150
- this.debugPath = new this.scope.Path();
26151
- const points = (0, import_lodash.chunk)(this.points, 2);
26152
- for (let i = 0, len = points.length; i < len; i++) {
26153
- const point = new this.scope.Point(points[i][0], points[i][1]);
26154
- if (i === 0) {
26155
- this.debugPath.moveTo(point);
26156
- } else {
26157
- this.debugPath.lineTo(point);
26158
- }
26159
- this.debugPath.strokeWidth = 1;
26160
- this.debugPath.strokeColor = new this.scope.Color(1, 0, 0, 1);
26161
- }
26162
- }
26163
26299
  onVectorUpdate() {
26164
26300
  if (!this.item) {
26165
26301
  return;
26166
26302
  }
26303
+ const matrixedPts = this.matrixedPoints();
26167
26304
  if (this.debug) {
26168
- this.debugPath.remove();
26169
- this.updateDebugPath();
26170
- }
26171
- const points = this.parsePoints(this.matrixedPoints());
26172
- const path = this.createPath(points);
26173
- this.item.removeSegments();
26174
- this.item.addSegments(path.segments);
26175
- if (this.debug) {
26176
- this.item.addChild(this.debugPath);
26305
+ const path = new this.scope.Path();
26306
+ for (let i = 0; i < matrixedPts.length; i++) {
26307
+ const p = new this.scope.Point(matrixedPts[i][0], matrixedPts[i][1]);
26308
+ if (i === 0) {
26309
+ path.moveTo(p);
26310
+ } else {
26311
+ path.lineTo(p);
26312
+ }
26313
+ }
26314
+ this.item.removeSegments();
26315
+ this.item.addSegments(path.segments);
26316
+ this.item.fillColor = null;
26317
+ this.item.strokeWidth = this.strokeWidth;
26318
+ } else {
26319
+ const points = this.parsePoints(matrixedPts);
26320
+ const path = this.createPath(points);
26321
+ this.item.removeSegments();
26322
+ this.item.addSegments(path.segments);
26177
26323
  }
26178
26324
  }
26179
26325
  createPaperItem() {
@@ -26196,11 +26342,13 @@ var CurveModel = class extends ElementModel {
26196
26342
  }
26197
26343
  liveCursorPoint() {
26198
26344
  const yArray = this.root.get(ElementModel.KEYS.points);
26199
- if (yArray.length < 2) {
26345
+ const points = yArray.toArray();
26346
+ const stride = this.pointStride(points);
26347
+ if (points.length < stride) {
26200
26348
  return null;
26201
26349
  }
26202
- const len = yArray.length;
26203
- const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
26350
+ const len = points.length;
26351
+ const point = new this.scope.Point(points[len - stride], points[len - stride + 1]);
26204
26352
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
26205
26353
  }
26206
26354
  onStyleKeyUpdate(key) {
@@ -26238,15 +26386,24 @@ function _toPrimitive4(t, r) {
26238
26386
  return ("string" === r ? String : Number)(t);
26239
26387
  }
26240
26388
  var SelectorModel = class extends ElementModel {
26241
- constructor(root, scope, liveCursor) {
26242
- super(root, scope, liveCursor);
26389
+ get drawPoints() {
26390
+ if (this.localPoints.length >= 4) {
26391
+ return this.localPoints;
26392
+ }
26393
+ return this.points;
26394
+ }
26395
+ constructor(root, scope, liveCursor, isPerformanceMode) {
26396
+ super(root, scope, liveCursor, isPerformanceMode);
26243
26397
  _defineProperty4(this, "item", null);
26244
- if (!this.root.has("type")) {
26398
+ _defineProperty4(this, "clearLocalPointsWhenYPointsChange", true);
26399
+ _defineProperty4(this, "shouldUseLocalPoints", true);
26400
+ _defineProperty4(this, "localPointsPick", 4);
26401
+ if (this.root.doc && !this.root.has("type")) {
26245
26402
  this.root.set("type", "selector");
26246
26403
  }
26247
- if (!this.root.has("points")) {
26404
+ if (this.root.doc && !this.root.has("points")) {
26248
26405
  const initPoints = new Y3.Array();
26249
- initPoints.push([0, 0, 0, 0, 0]);
26406
+ initPoints.push([0, 0, 0, 0]);
26250
26407
  this.root.set("points", initPoints);
26251
26408
  }
26252
26409
  }
@@ -26257,8 +26414,8 @@ var SelectorModel = class extends ElementModel {
26257
26414
  }
26258
26415
  createPaperRect() {
26259
26416
  const scope = this.scope;
26260
- const bounds = new scope.Rectangle(new scope.Point(this.points[0], this.points[1]), new scope.Size(this.points[2], this.points[3]));
26261
- return new scope.Path.Rectangle(bounds, new scope.Point(this.points[4], this.points[4]));
26417
+ const bounds = new scope.Rectangle(new scope.Point(this.drawPoints[0], this.drawPoints[1]), new scope.Size(this.drawPoints[2], this.drawPoints[3]));
26418
+ return new scope.Path.Rectangle(bounds);
26262
26419
  }
26263
26420
  onVectorUpdate() {
26264
26421
  if (!this.item) {
@@ -26292,7 +26449,8 @@ var SelectorModel = class extends ElementModel {
26292
26449
  var Y4 = __toESM(require("yjs"), 1);
26293
26450
 
26294
26451
  // src/utils/paperjs.ts
26295
- var import_lodash2 = __toESM(require_lodash(), 1);
26452
+ var import_lodash = __toESM(require_lodash(), 1);
26453
+ var import_forge_room2 = require("@netless/forge-room");
26296
26454
  function _defineProperty5(e, r, t) {
26297
26455
  return (r = _toPropertyKey5(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
26298
26456
  }
@@ -26325,7 +26483,7 @@ function serializePath(path) {
26325
26483
  }, []);
26326
26484
  }
26327
26485
  function deserializePath(points, scope, matrix) {
26328
- const segmentGroup = (0, import_lodash2.chunk)(points, 6);
26486
+ const segmentGroup = (0, import_lodash.chunk)(points, 6);
26329
26487
  const path = new scope.Path();
26330
26488
  path.segments = segmentGroup.map((v) => deserializeSegment(v, scope, matrix));
26331
26489
  return path;
@@ -26335,7 +26493,27 @@ var AnimationFrame = class {
26335
26493
  _defineProperty5(this, "callbacks", []);
26336
26494
  _defineProperty5(this, "lastTime", 0);
26337
26495
  _defineProperty5(this, "fps", 45);
26496
+ _defineProperty5(this, "lastCallbackTime", 0);
26497
+ _defineProperty5(this, "fpsBuffer", []);
26498
+ _defineProperty5(this, "FPS_REPORT_INTERVAL", 2700);
26338
26499
  _defineProperty5(this, "handleCallbacks", () => {
26500
+ const now = performance.now();
26501
+ if (this.lastCallbackTime > 0) {
26502
+ const actualFps = 1e3 / (now - this.lastCallbackTime);
26503
+ this.fpsBuffer.push(actualFps);
26504
+ if (this.fpsBuffer.length >= this.FPS_REPORT_INTERVAL) {
26505
+ const avg = this.fpsBuffer.reduce((a2, b2) => a2 + b2, 0) / this.fpsBuffer.length;
26506
+ const min = Math.min(...this.fpsBuffer);
26507
+ const sorted = [...this.fpsBuffer].sort((a2, b2) => a2 - b2);
26508
+ const p90 = sorted[Math.floor(sorted.length * 0.9)];
26509
+ (0, import_forge_room2.metrics)().gauge("fps", Math.round(avg), {
26510
+ min: Math.round(min),
26511
+ p90: Math.round(p90)
26512
+ });
26513
+ this.fpsBuffer = [];
26514
+ }
26515
+ }
26516
+ this.lastCallbackTime = now;
26339
26517
  const functions = this.callbacks;
26340
26518
  this.callbacks = [];
26341
26519
  for (let i = 0, l2 = functions.length; i < l2; i++) {
@@ -26379,13 +26557,22 @@ function _toPrimitive6(t, r) {
26379
26557
  return ("string" === r ? String : Number)(t);
26380
26558
  }
26381
26559
  var SegmentsModel = class extends ElementModel {
26382
- constructor(root, scope, type, liveCursor) {
26383
- super(root, scope, liveCursor);
26560
+ get drawPoints() {
26561
+ if (this.localPoints.length >= 4) {
26562
+ return this.localPoints;
26563
+ }
26564
+ return this.points;
26565
+ }
26566
+ constructor(root, scope, type, liveCursor, isPerformanceMode) {
26567
+ super(root, scope, liveCursor, isPerformanceMode);
26384
26568
  _defineProperty6(this, "item", null);
26385
- if (!this.root.has("type")) {
26569
+ _defineProperty6(this, "clearLocalPointsWhenYPointsChange", true);
26570
+ _defineProperty6(this, "shouldUseLocalPoints", true);
26571
+ _defineProperty6(this, "localPointsPick", 24);
26572
+ if (this.root.doc && !this.root.has("type")) {
26386
26573
  this.root.set("type", type);
26387
26574
  }
26388
- if (!this.root.has("points")) {
26575
+ if (this.root.doc && !this.root.has("points")) {
26389
26576
  this.root.set("points", new Y4.Array());
26390
26577
  }
26391
26578
  }
@@ -26405,13 +26592,13 @@ var SegmentsModel = class extends ElementModel {
26405
26592
  }
26406
26593
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26407
26594
  this.item.removeSegments();
26408
- const next = deserializePath(this.points, this.scope, matrix);
26595
+ const next = deserializePath(this.drawPoints, this.scope, matrix);
26409
26596
  this.item.addSegments(next.segments);
26410
26597
  this.item.closePath();
26411
26598
  }
26412
26599
  createPaperItem() {
26413
26600
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26414
- this.item = deserializePath(this.points, this.scope, matrix);
26601
+ this.item = deserializePath(this.drawPoints, this.scope, matrix);
26415
26602
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
26416
26603
  this.item.dashArray = this.dashArray;
26417
26604
  this.item.strokeWidth = this.strokeWidth;
@@ -26439,7 +26626,7 @@ var SegmentsModel = class extends ElementModel {
26439
26626
 
26440
26627
  // src/model/renderable/LineModel.ts
26441
26628
  var Y5 = __toESM(require("yjs"), 1);
26442
- var import_lodash4 = __toESM(require_lodash(), 1);
26629
+ var import_lodash3 = __toESM(require_lodash(), 1);
26443
26630
 
26444
26631
  // src/tool/WhiteboardTool.ts
26445
26632
  function _defineProperty7(e, r, t) {
@@ -26459,6 +26646,8 @@ function _toPrimitive7(t, r) {
26459
26646
  }
26460
26647
  return ("string" === r ? String : Number)(t);
26461
26648
  }
26649
+ var DRAG_FPS = 10;
26650
+ var DRAG_FRAME_MS = 1e3 / DRAG_FPS;
26462
26651
  var WhiteboardTool = class {
26463
26652
  constructor(enableToolEvent, modelGetter, shadowEmitter, scope) {
26464
26653
  _defineProperty7(this, "modelGetter", void 0);
@@ -26467,24 +26656,60 @@ var WhiteboardTool = class {
26467
26656
  _defineProperty7(this, "shadowEmitter", void 0);
26468
26657
  _defineProperty7(this, "enableToolEvent", void 0);
26469
26658
  _defineProperty7(this, "eventAvailable", false);
26659
+ _defineProperty7(this, "lastDragTime", 0);
26660
+ _defineProperty7(this, "dragRafId", 0);
26661
+ _defineProperty7(this, "pendingDragEvent", null);
26470
26662
  _defineProperty7(this, "onMouseDownSelf", (event) => {
26471
26663
  this.eventAvailable = this.enableToolEvent();
26472
26664
  if (!this.eventAvailable) {
26473
26665
  return;
26474
26666
  }
26667
+ this.lastDragTime = 0;
26668
+ if (this.dragRafId) {
26669
+ cancelAnimationFrame(this.dragRafId);
26670
+ this.dragRafId = 0;
26671
+ }
26672
+ this.pendingDragEvent = null;
26475
26673
  this.shadowEmitter.setActive(true);
26476
26674
  this.onMouseDown(event);
26477
26675
  });
26676
+ _defineProperty7(this, "flushPendingDrag", () => {
26677
+ this.dragRafId = 0;
26678
+ if (this.pendingDragEvent) {
26679
+ this.lastDragTime = performance.now();
26680
+ const event = this.pendingDragEvent;
26681
+ this.pendingDragEvent = null;
26682
+ this.onMouseDrag(event);
26683
+ }
26684
+ });
26478
26685
  _defineProperty7(this, "onMouseDragSelf", (event) => {
26479
26686
  if (!this.eventAvailable) {
26480
26687
  return;
26481
26688
  }
26482
- this.onMouseDrag(event);
26689
+ const now = performance.now();
26690
+ if (now - this.lastDragTime >= DRAG_FRAME_MS) {
26691
+ this.lastDragTime = now;
26692
+ this.pendingDragEvent = null;
26693
+ this.onMouseDrag(event);
26694
+ } else {
26695
+ this.pendingDragEvent = event;
26696
+ if (!this.dragRafId) {
26697
+ this.dragRafId = requestAnimationFrame(this.flushPendingDrag);
26698
+ }
26699
+ }
26483
26700
  });
26484
26701
  _defineProperty7(this, "onMouseUpSelf", (event) => {
26485
26702
  if (!this.eventAvailable) {
26486
26703
  return;
26487
26704
  }
26705
+ if (this.dragRafId) {
26706
+ cancelAnimationFrame(this.dragRafId);
26707
+ this.dragRafId = 0;
26708
+ }
26709
+ if (this.pendingDragEvent) {
26710
+ this.onMouseDrag(this.pendingDragEvent);
26711
+ this.pendingDragEvent = null;
26712
+ }
26488
26713
  this.onMouseUp(event);
26489
26714
  this.shadowEmitter.setActive(false);
26490
26715
  });
@@ -26500,7 +26725,7 @@ var WhiteboardTool = class {
26500
26725
  };
26501
26726
 
26502
26727
  // src/tool/LineTool.ts
26503
- var import_lodash3 = __toESM(require_lodash(), 1);
26728
+ var import_lodash2 = __toESM(require_lodash(), 1);
26504
26729
  function _defineProperty8(e, r, t) {
26505
26730
  return (r = _toPropertyKey8(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
26506
26731
  }
@@ -26549,7 +26774,7 @@ var LineTool = class extends WhiteboardTool {
26549
26774
  const point = path.getPointAt(distance);
26550
26775
  return [point.x, point.y];
26551
26776
  });
26552
- this.elementModel.setPoints((0, import_lodash3.flattenDeep)(points));
26777
+ this.elementModel.setPoints((0, import_lodash2.flattenDeep)(points));
26553
26778
  }
26554
26779
  }
26555
26780
  onMouseUp(_event) {
@@ -26579,6 +26804,12 @@ function _toPrimitive9(t, r) {
26579
26804
  return ("string" === r ? String : Number)(t);
26580
26805
  }
26581
26806
  var LineModel = class extends ElementModel {
26807
+ get drawPoints() {
26808
+ if (this.localPoints.length > 0) {
26809
+ return this.localPoints;
26810
+ }
26811
+ return this.points;
26812
+ }
26582
26813
  get arrowSize() {
26583
26814
  return this.strokeWidth * 5 + 15;
26584
26815
  }
@@ -26594,20 +26825,23 @@ var LineModel = class extends ElementModel {
26594
26825
  set tailArrow(value) {
26595
26826
  this.root.set("tailArrow", value);
26596
26827
  }
26597
- constructor(root, scope, liveCursor) {
26598
- super(root, scope, liveCursor);
26828
+ constructor(root, scope, liveCursor, isPerformanceMode) {
26829
+ super(root, scope, liveCursor, isPerformanceMode);
26599
26830
  _defineProperty9(this, "controlledPoints", []);
26831
+ _defineProperty9(this, "clearLocalPointsWhenYPointsChange", true);
26832
+ _defineProperty9(this, "shouldUseLocalPoints", true);
26833
+ _defineProperty9(this, "localPointsPick", 99);
26600
26834
  _defineProperty9(this, "item", null);
26601
- if (!this.root.has("type")) {
26835
+ if (this.root.doc && !this.root.has("type")) {
26602
26836
  this.root.set("type", "arrow");
26603
26837
  }
26604
- if (!this.root.has("points")) {
26838
+ if (this.root.doc && !this.root.has("points")) {
26605
26839
  this.root.set("points", new Y5.Array());
26606
26840
  }
26607
- if (!this.root.has("headArrow")) {
26841
+ if (this.root.doc && !this.root.has("headArrow")) {
26608
26842
  this.root.set("headArrow", "none");
26609
26843
  }
26610
- if (!this.root.has("tailArrow")) {
26844
+ if (this.root.doc && !this.root.has("tailArrow")) {
26611
26845
  this.root.set("tailArrow", "normal");
26612
26846
  }
26613
26847
  }
@@ -26623,7 +26857,7 @@ var LineModel = class extends ElementModel {
26623
26857
  }
26624
26858
  renderLine() {
26625
26859
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26626
- const papperPoints = (0, import_lodash4.chunk)(this.points, 2).map((item) => {
26860
+ const papperPoints = (0, import_lodash3.chunk)(this.drawPoints, 2).map((item) => {
26627
26861
  return new this.scope.Point(item[0], item[1]).transform(matrix);
26628
26862
  });
26629
26863
  const path = new this.scope.Path();
@@ -26737,13 +26971,14 @@ var LineControlPoint = class {
26737
26971
  if (this.position) {
26738
26972
  return this.model.scope.project.view.projectToView(this.position.transform(matrix));
26739
26973
  }
26974
+ const points = this.model["drawPoints"];
26740
26975
  const from = {
26741
- x: this.model.points[0],
26742
- y: this.model.points[1]
26976
+ x: points[0],
26977
+ y: points[1]
26743
26978
  };
26744
26979
  const to = {
26745
- x: this.model.points[this.model.points.length - 2],
26746
- y: this.model.points[this.model.points.length - 1]
26980
+ x: points[points.length - 2],
26981
+ y: points[points.length - 1]
26747
26982
  };
26748
26983
  const clonedPath = new this.scope.Path.Line(from, to);
26749
26984
  this.position = clonedPath.getPointAt(clonedPath.length * distance);
@@ -26756,9 +26991,9 @@ var LineControlPoint = class {
26756
26991
  }
26757
26992
  const pointsMatrix = new this.model.scope.Matrix(this.model.pointsMatrix);
26758
26993
  const invertedPoint = point.transform(pointsMatrix.inverted());
26759
- const points = this.model.points;
26994
+ const points = this.model["drawPoints"];
26760
26995
  this.position = invertedPoint;
26761
- const clonedPoints = (0, import_lodash4.cloneDeep)(points);
26996
+ const clonedPoints = (0, import_lodash3.cloneDeep)(points);
26762
26997
  clonedPoints[this.options.index * 2] = invertedPoint.x;
26763
26998
  clonedPoints[this.options.index * 2 + 1] = invertedPoint.y;
26764
26999
  this.model.setPoints(clonedPoints);
@@ -26767,7 +27002,7 @@ var LineControlPoint = class {
26767
27002
 
26768
27003
  // src/model/renderable/PointTextModel.ts
26769
27004
  var Y6 = __toESM(require("yjs"), 1);
26770
- var import_forge_room2 = require("@netless/forge-room");
27005
+ var import_forge_room3 = require("@netless/forge-room");
26771
27006
  function _defineProperty10(e, r, t) {
26772
27007
  return (r = _toPropertyKey10(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
26773
27008
  }
@@ -26804,9 +27039,18 @@ var PointTextModel = class extends ElementModel {
26804
27039
  set fontFamily(value) {
26805
27040
  this.root.set("font-family", value);
26806
27041
  }
26807
- constructor(root, scope, liveCursor) {
26808
- super(root, scope, liveCursor);
27042
+ get drawPoints() {
27043
+ if (this.localPoints.length > 1) {
27044
+ return this.localPoints;
27045
+ }
27046
+ return this.points;
27047
+ }
27048
+ constructor(root, scope, liveCursor, isPerformanceMode) {
27049
+ super(root, scope, liveCursor, isPerformanceMode);
26809
27050
  _defineProperty10(this, "item", null);
27051
+ _defineProperty10(this, "clearLocalPointsWhenYPointsChange", true);
27052
+ _defineProperty10(this, "shouldUseLocalPoints", false);
27053
+ _defineProperty10(this, "localPointsPick", 2);
26810
27054
  _defineProperty10(this, "handleTextPropChange", (event) => {
26811
27055
  if (!this.item) {
26812
27056
  return;
@@ -26823,21 +27067,27 @@ var PointTextModel = class extends ElementModel {
26823
27067
  }
26824
27068
  }
26825
27069
  });
26826
- if (!this.root.has("type")) {
27070
+ if (this.root.doc && !this.root.has("type")) {
26827
27071
  this.root.set("type", "point-text");
26828
27072
  }
26829
- if (!this.root.has(ElementModel.KEYS.points)) {
27073
+ if (this.root.doc && !this.root.has(ElementModel.KEYS.points)) {
26830
27074
  this.root.set(ElementModel.KEYS.points, new Y6.Array());
26831
27075
  }
26832
27076
  this.root.observe(this.handleTextPropChange);
26833
- if (this.root.has("font-size")) {
26834
- setTimeout(() => {
26835
- this.updateTextPosition();
26836
- }, 60);
26837
- }
27077
+ setTimeout(() => {
27078
+ if (this.root && this.root.has("font-size")) {
27079
+ setTimeout(() => {
27080
+ this.updateTextPosition();
27081
+ }, 60);
27082
+ }
27083
+ }, 60);
26838
27084
  }
26839
27085
  subDispose() {
26840
- (0, import_forge_room2.removeObserver)(this.root, this.handleTextPropChange);
27086
+ (0, import_forge_room3.removeObserver)(this.root, this.handleTextPropChange);
27087
+ }
27088
+ subBindObserver() {
27089
+ (0, import_forge_room3.removeObserver)(this.root, this.handleTextPropChange);
27090
+ this.root.observe(this.handleTextPropChange);
26841
27091
  }
26842
27092
  liveCursorPoint() {
26843
27093
  const points = this.points;
@@ -26852,10 +27102,11 @@ var PointTextModel = class extends ElementModel {
26852
27102
  if (!this.item) {
26853
27103
  return null;
26854
27104
  }
27105
+ console.log("[][][] drawPoints", this.drawPoints);
26855
27106
  const bounds = this.item.internalBounds;
26856
27107
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26857
- const topLeft = new this.scope.Point(this.points[0], this.points[1]).transform(matrix);
26858
- const topRight = new this.scope.Point(this.points[0] + bounds.width, this.points[1]).transform(matrix);
27108
+ const topLeft = new this.scope.Point(this.drawPoints[0], this.drawPoints[1]).transform(matrix);
27109
+ const topRight = new this.scope.Point(this.drawPoints[0] + bounds.width, this.drawPoints[1]).transform(matrix);
26859
27110
  let scaleX = topRight.getDistance(topLeft) / bounds.width;
26860
27111
  scaleX = Number.isNaN(scaleX) ? 1 : scaleX;
26861
27112
  const angle = topRight.subtract(topLeft).angle;
@@ -26943,13 +27194,22 @@ function _toPrimitive11(t, r) {
26943
27194
  return ("string" === r ? String : Number)(t);
26944
27195
  }
26945
27196
  var TriangleModel = class extends ElementModel {
26946
- constructor(root, scope, liveCursor) {
26947
- super(root, scope, liveCursor);
27197
+ get drawPoints() {
27198
+ if (this.localPoints.length >= 6) {
27199
+ return this.localPoints;
27200
+ }
27201
+ return this.points;
27202
+ }
27203
+ constructor(root, scope, liveCursor, isPerformanceMode) {
27204
+ super(root, scope, liveCursor, isPerformanceMode);
26948
27205
  _defineProperty11(this, "item", null);
26949
- if (!this.root.has("type")) {
27206
+ _defineProperty11(this, "clearLocalPointsWhenYPointsChange", true);
27207
+ _defineProperty11(this, "shouldUseLocalPoints", true);
27208
+ _defineProperty11(this, "localPointsPick", 6);
27209
+ if (this.root.doc && !this.root.has("type")) {
26950
27210
  this.root.set("type", "triangle");
26951
27211
  }
26952
- if (!this.root.has("points")) {
27212
+ if (this.root.doc && !this.root.has("points")) {
26953
27213
  this.root.set("points", new Y7.Array());
26954
27214
  }
26955
27215
  }
@@ -26981,9 +27241,9 @@ var TriangleModel = class extends ElementModel {
26981
27241
  return;
26982
27242
  }
26983
27243
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26984
- const p1 = new this.scope.Point(this.points[0], this.points[1]).transform(matrix);
26985
- const p2 = new this.scope.Point(this.points[2], this.points[3]).transform(matrix);
26986
- const p3 = new this.scope.Point(this.points[4], this.points[5]).transform(matrix);
27244
+ const p1 = new this.scope.Point(this.drawPoints[0], this.drawPoints[1]).transform(matrix);
27245
+ const p2 = new this.scope.Point(this.drawPoints[2], this.drawPoints[3]).transform(matrix);
27246
+ const p3 = new this.scope.Point(this.drawPoints[4], this.drawPoints[5]).transform(matrix);
26987
27247
  this.item.removeSegments();
26988
27248
  this.item.moveTo(p1);
26989
27249
  this.item.lineTo(p2);
@@ -26995,7 +27255,7 @@ var TriangleModel = class extends ElementModel {
26995
27255
  config.controlPoints.push({
26996
27256
  name: "triangle",
26997
27257
  getPosition: () => {
26998
- const point = new this.scope.Point(this.points[0], this.points[1]);
27258
+ const point = new this.scope.Point(this.drawPoints[0], this.drawPoints[1]);
26999
27259
  const pointsMatrix = new this.scope.Matrix(this.pointsMatrix);
27000
27260
  return this.scope.project.view.projectToView(point.transform(pointsMatrix));
27001
27261
  },
@@ -27005,7 +27265,7 @@ var TriangleModel = class extends ElementModel {
27005
27265
  }
27006
27266
  const pointsMatrix = new this.scope.Matrix(this.pointsMatrix);
27007
27267
  const trPoint = point.transform(pointsMatrix.inverted());
27008
- const oldPoints = this.points;
27268
+ const oldPoints = this.drawPoints;
27009
27269
  this.setPoints([trPoint.x, trPoint.y, oldPoints[2], oldPoints[3], oldPoints[4], oldPoints[5]]);
27010
27270
  }
27011
27271
  });
@@ -27044,25 +27304,34 @@ function _toPrimitive12(t, r) {
27044
27304
  return ("string" === r ? String : Number)(t);
27045
27305
  }
27046
27306
  var RectangleModel = class extends ElementModel {
27047
- constructor(root, scope, liveCursor) {
27048
- super(root, scope, liveCursor);
27307
+ get drawPoints() {
27308
+ if (this.localPoints.length >= 4) {
27309
+ return this.localPoints;
27310
+ }
27311
+ return this.points;
27312
+ }
27313
+ constructor(root, scope, liveCursor, isPerformanceMode) {
27314
+ super(root, scope, liveCursor, isPerformanceMode);
27049
27315
  _defineProperty12(this, "item", null);
27050
- if (!this.root.has("type")) {
27316
+ _defineProperty12(this, "clearLocalPointsWhenYPointsChange", true);
27317
+ _defineProperty12(this, "shouldUseLocalPoints", true);
27318
+ _defineProperty12(this, "localPointsPick", 4);
27319
+ if (this.root.doc && !this.root.has("type")) {
27051
27320
  this.root.set("type", "rectangle");
27052
27321
  }
27053
- if (!this.root.has("points")) {
27322
+ if (this.root.doc && !this.root.has("points")) {
27054
27323
  const initPoints = new Y8.Array();
27055
27324
  initPoints.push([0, 0, 0, 0]);
27056
27325
  this.root.set("points", initPoints);
27057
27326
  }
27058
- if (!this.root.has("radius")) {
27327
+ if (this.root.doc && !this.root.has("radius")) {
27059
27328
  this.root.set("radius", 0);
27060
27329
  }
27061
27330
  }
27062
27331
  subDispose() {
27063
27332
  }
27064
27333
  liveCursorPoint() {
27065
- const points = this.points;
27334
+ const points = this.drawPoints;
27066
27335
  if (points.length < 4) {
27067
27336
  return null;
27068
27337
  }
@@ -27070,7 +27339,7 @@ var RectangleModel = class extends ElementModel {
27070
27339
  return new this.scope.Point(points[2], points[3]).transform(matrix);
27071
27340
  }
27072
27341
  createSegments() {
27073
- const [a2, b2, c, d] = this.points;
27342
+ const [a2, b2, c, d] = this.drawPoints;
27074
27343
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27075
27344
  const maxRadius = this.maxRadiusLength();
27076
27345
  const radius = this.root.get("radius") * maxRadius;
@@ -27135,7 +27404,7 @@ var RectangleModel = class extends ElementModel {
27135
27404
  }
27136
27405
  maxRadiusLength() {
27137
27406
  const pointsMatrix = new this.scope.Matrix(this.pointsMatrix);
27138
- const points = this.points;
27407
+ const points = this.drawPoints;
27139
27408
  const topLeft = new this.scope.Point(points[0], points[1]).transform(pointsMatrix);
27140
27409
  const topRight = new this.scope.Point(points[2], points[1]).transform(pointsMatrix);
27141
27410
  const bottomLeft = new this.scope.Point(points[0], points[3]).transform(pointsMatrix);
@@ -27160,7 +27429,7 @@ var RectangleModel = class extends ElementModel {
27160
27429
  name: "rect-radius",
27161
27430
  getPosition: () => {
27162
27431
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27163
- const points = this.points;
27432
+ const points = this.drawPoints;
27164
27433
  const radius = this.root.get("radius") * this.maxRadiusLength();
27165
27434
  let c1 = new this.scope.Point(points[0], points[1]).transform(matrix);
27166
27435
  const c3 = new this.scope.Point(points[2], points[3]).transform(matrix);
@@ -27179,7 +27448,7 @@ var RectangleModel = class extends ElementModel {
27179
27448
  if (!this.item) {
27180
27449
  return;
27181
27450
  }
27182
- const points = this.points;
27451
+ const points = this.drawPoints;
27183
27452
  const pointsMatrix = new this.scope.Matrix(this.pointsMatrix);
27184
27453
  const maxRadius = Math.min(points[2] - points[0], points[3] - points[1]) / 2;
27185
27454
  const trPoint = point.transform(pointsMatrix.inverted());
@@ -27209,7 +27478,7 @@ var elementsUndoOrigin = "elementsUndoOrigin";
27209
27478
 
27210
27479
  // src/model/renderable/EraserModel.ts
27211
27480
  var Y9 = __toESM(require("yjs"), 1);
27212
- var import_lodash5 = __toESM(require_lodash(), 1);
27481
+ var import_lodash4 = __toESM(require_lodash(), 1);
27213
27482
  function _defineProperty13(e, r, t) {
27214
27483
  return (r = _toPropertyKey13(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27215
27484
  }
@@ -27228,14 +27497,23 @@ function _toPrimitive13(t, r) {
27228
27497
  return ("string" === r ? String : Number)(t);
27229
27498
  }
27230
27499
  var EraserModel = class extends ElementModel {
27231
- constructor(root, scope, liveCursor) {
27232
- super(root, scope, liveCursor);
27500
+ get drawPoints() {
27501
+ if (this.localPoints.length > 0) {
27502
+ return this.localPoints;
27503
+ }
27504
+ return this.points;
27505
+ }
27506
+ constructor(root, scope, liveCursor, isPerformanceMode) {
27507
+ super(root, scope, liveCursor, isPerformanceMode);
27233
27508
  _defineProperty13(this, "item", null);
27234
27509
  _defineProperty13(this, "sliceBegin", 0);
27235
- if (!this.root.has("type")) {
27510
+ _defineProperty13(this, "clearLocalPointsWhenYPointsChange", false);
27511
+ _defineProperty13(this, "shouldUseLocalPoints", true);
27512
+ _defineProperty13(this, "localPointsPick", 4);
27513
+ if (this.root.doc && !this.root.has("type")) {
27236
27514
  this.root.set("type", "eraser");
27237
27515
  }
27238
- if (!this.root.has("points")) {
27516
+ if (this.root.doc && !this.root.has("points")) {
27239
27517
  this.root.set("points", new Y9.Array());
27240
27518
  }
27241
27519
  }
@@ -27268,7 +27546,7 @@ var EraserModel = class extends ElementModel {
27268
27546
  return path;
27269
27547
  }
27270
27548
  parsePoints(points) {
27271
- const groupPoints = (0, import_lodash5.chunk)(points, 2);
27549
+ const groupPoints = (0, import_lodash4.chunk)(points, 2);
27272
27550
  return ae(groupPoints, {
27273
27551
  size: this.strokeWidth,
27274
27552
  smoothing: 0.5,
@@ -27286,7 +27564,7 @@ var EraserModel = class extends ElementModel {
27286
27564
  });
27287
27565
  }
27288
27566
  matrixedPoints() {
27289
- const currentPoints = (0, import_lodash5.chunk)(this.points, 2).slice(this.sliceBegin);
27567
+ const currentPoints = (0, import_lodash4.chunk)(this.drawPoints, 2).slice(this.sliceBegin);
27290
27568
  return currentPoints.map((_ref) => {
27291
27569
  let [x, y] = _ref;
27292
27570
  return new this.scope.Point(x, y);
@@ -27314,11 +27592,11 @@ var EraserModel = class extends ElementModel {
27314
27592
  this.item.fillColor = new this.scope.Color(this.strokeColor);
27315
27593
  this.onVectorUpdate();
27316
27594
  this.item.onFrame = () => {
27317
- if (!this.points) {
27595
+ if (!this.drawPoints) {
27318
27596
  return;
27319
27597
  }
27320
- if (this.points.length / 2 > 50) {
27321
- this.sliceBegin = this.points.length / 2 - 50;
27598
+ if (this.drawPoints.length / 2 > 50) {
27599
+ this.sliceBegin = this.drawPoints.length / 2 - 50;
27322
27600
  }
27323
27601
  };
27324
27602
  }
@@ -27352,7 +27630,8 @@ var EraserModel = class extends ElementModel {
27352
27630
 
27353
27631
  // src/model/renderable/LaserPointerModel.ts
27354
27632
  var Y10 = __toESM(require("yjs"), 1);
27355
- var import_lodash6 = __toESM(require_lodash(), 1);
27633
+ var import_lodash5 = __toESM(require_lodash(), 1);
27634
+ var import_forge_room4 = require("@netless/forge-room");
27356
27635
  function _defineProperty14(e, r, t) {
27357
27636
  return (r = _toPropertyKey14(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27358
27637
  }
@@ -27371,24 +27650,18 @@ function _toPrimitive14(t, r) {
27371
27650
  return ("string" === r ? String : Number)(t);
27372
27651
  }
27373
27652
  var LaserPointerModel = class extends ElementModel {
27374
- constructor(clientId, root, scope, liveCursor, removeElement) {
27375
- super(root, scope, liveCursor);
27653
+ constructor(clientId, root, scope, liveCursor, removeElement, isPerformanceMode) {
27654
+ super(root, scope, liveCursor, isPerformanceMode);
27376
27655
  _defineProperty14(this, "item", null);
27377
27656
  _defineProperty14(this, "clientId", void 0);
27378
27657
  _defineProperty14(this, "sliceBegin", 0);
27379
27658
  _defineProperty14(this, "displayStrokeWidth", 8);
27380
27659
  _defineProperty14(this, "cachedPoints", null);
27381
- this.clientId = clientId;
27382
- if (!this.root.has("type")) {
27383
- this.root.set("type", "laser");
27384
- }
27385
- if (!this.root.has("points")) {
27386
- this.root.set("points", new Y10.Array());
27387
- }
27388
- if (!this.root.has("removed")) {
27389
- this.root.set("removed", false);
27390
- }
27391
- this.root.observe((event) => {
27660
+ _defineProperty14(this, "clearLocalPointsWhenYPointsChange", false);
27661
+ _defineProperty14(this, "shouldUseLocalPoints", false);
27662
+ _defineProperty14(this, "localPointsPick", 4);
27663
+ _defineProperty14(this, "removeElement", void 0);
27664
+ _defineProperty14(this, "handleLaserPropChange", (event) => {
27392
27665
  if (!this.item) {
27393
27666
  return;
27394
27667
  }
@@ -27406,13 +27679,31 @@ var LaserPointerModel = class extends ElementModel {
27406
27679
  this.onVectorUpdate();
27407
27680
  if (evt.count >= 30) {
27408
27681
  if (this.ownerId === this.clientId) {
27409
- removeElement(this.uuid);
27682
+ this.removeElement(this.uuid);
27410
27683
  }
27411
27684
  }
27412
27685
  };
27413
27686
  }
27414
27687
  }
27415
27688
  });
27689
+ this.clientId = clientId;
27690
+ this.removeElement = removeElement;
27691
+ if (this.root.doc && !this.root.has("type")) {
27692
+ this.root.set("type", "laser");
27693
+ }
27694
+ if (this.root.doc && !this.root.has("points")) {
27695
+ this.root.set("points", new Y10.Array());
27696
+ }
27697
+ if (this.root.doc && !this.root.has("removed")) {
27698
+ this.root.set("removed", false);
27699
+ }
27700
+ }
27701
+ subBindObserver() {
27702
+ (0, import_forge_room4.removeObserver)(this.root, this.handleLaserPropChange);
27703
+ this.root.observe(this.handleLaserPropChange);
27704
+ }
27705
+ subDispose() {
27706
+ (0, import_forge_room4.removeObserver)(this.root, this.handleLaserPropChange);
27416
27707
  }
27417
27708
  beginRemoveAnimate() {
27418
27709
  this.root.set("removed", true);
@@ -27465,7 +27756,8 @@ var LaserPointerModel = class extends ElementModel {
27465
27756
  matrixedPoints() {
27466
27757
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27467
27758
  const points = this.cachedPoints || this.points;
27468
- const groupPoints = (0, import_lodash6.chunk)(points, 2).slice(this.sliceBegin);
27759
+ console.log("[][][] ,", this.points.length, this.cachedPoints?.length, this.localPoints.length);
27760
+ const groupPoints = (0, import_lodash5.chunk)(points, 2).slice(this.sliceBegin);
27469
27761
  return groupPoints.map((_ref) => {
27470
27762
  let [x, y] = _ref;
27471
27763
  return matrix.transform([x, y]);
@@ -27507,8 +27799,6 @@ var LaserPointerModel = class extends ElementModel {
27507
27799
  onStyleKeyUpdate(_key) {
27508
27800
  return;
27509
27801
  }
27510
- subDispose() {
27511
- }
27512
27802
  liveCursorPoint() {
27513
27803
  const yArray = this.root.get(ElementModel.KEYS.points);
27514
27804
  if (yArray.length < 2) {
@@ -27521,7 +27811,7 @@ var LaserPointerModel = class extends ElementModel {
27521
27811
  };
27522
27812
 
27523
27813
  // src/WhitePermissions.ts
27524
- var import_forge_room3 = require("@netless/forge-room");
27814
+ var import_forge_room5 = require("@netless/forge-room");
27525
27815
  var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
27526
27816
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["none"] = 0] = "none";
27527
27817
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["draw"] = 1] = "draw";
@@ -27534,7 +27824,7 @@ var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
27534
27824
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["all"] = WhiteboardPermissionFlag2.draw | WhiteboardPermissionFlag2.editSelf | WhiteboardPermissionFlag2.editOthers | WhiteboardPermissionFlag2.deleteSelf | WhiteboardPermissionFlag2.deleteOthers | WhiteboardPermissionFlag2.mainView | WhiteboardPermissionFlag2.setOthersView] = "all";
27535
27825
  return WhiteboardPermissionFlag2;
27536
27826
  }({});
27537
- var WhiteboardPermissions = class extends import_forge_room3.AbstractApplicationPermissions {
27827
+ var WhiteboardPermissions = class extends import_forge_room5.AbstractApplicationPermissions {
27538
27828
  /**
27539
27829
  * 解析权限列表组合
27540
27830
  * @param {number} value - 权限数字值
@@ -27547,7 +27837,7 @@ var WhiteboardPermissions = class extends import_forge_room3.AbstractApplication
27547
27837
 
27548
27838
  // src/model/renderable/StraightLineModel.ts
27549
27839
  var Y11 = __toESM(require("yjs"), 1);
27550
- var import_lodash7 = __toESM(require_lodash(), 1);
27840
+ var import_lodash6 = __toESM(require_lodash(), 1);
27551
27841
  function _defineProperty15(e, r, t) {
27552
27842
  return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27553
27843
  }
@@ -27566,13 +27856,22 @@ function _toPrimitive15(t, r) {
27566
27856
  return ("string" === r ? String : Number)(t);
27567
27857
  }
27568
27858
  var StraightLineModel = class extends ElementModel {
27569
- constructor(root, scope, liveCursor) {
27570
- super(root, scope, liveCursor);
27859
+ get drawPoints() {
27860
+ if (this.localPoints.length >= 4) {
27861
+ return this.localPoints;
27862
+ }
27863
+ return this.points;
27864
+ }
27865
+ constructor(root, scope, liveCursor, isPerformanceMode) {
27866
+ super(root, scope, liveCursor, isPerformanceMode);
27571
27867
  _defineProperty15(this, "item", null);
27572
- if (!this.root.has("type")) {
27868
+ _defineProperty15(this, "clearLocalPointsWhenYPointsChange", true);
27869
+ _defineProperty15(this, "shouldUseLocalPoints", true);
27870
+ _defineProperty15(this, "localPointsPick", 4);
27871
+ if (this.root.doc && !this.root.has("type")) {
27573
27872
  this.root.set("type", "line");
27574
27873
  }
27575
- if (!this.root.has("points")) {
27874
+ if (this.root.doc && !this.root.has("points")) {
27576
27875
  this.root.set("points", new Y11.Array());
27577
27876
  }
27578
27877
  }
@@ -27597,7 +27896,7 @@ var StraightLineModel = class extends ElementModel {
27597
27896
  }
27598
27897
  renderLine() {
27599
27898
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27600
- const papperPoints = (0, import_lodash7.chunk)(this.points, 2).map((item) => {
27899
+ const papperPoints = (0, import_lodash6.chunk)(this.drawPoints, 2).map((item) => {
27601
27900
  return new this.scope.Point(item[0], item[1]).transform(matrix);
27602
27901
  });
27603
27902
  const path = new this.scope.Path();
@@ -27619,7 +27918,7 @@ var StraightLineModel = class extends ElementModel {
27619
27918
  name: "line-start",
27620
27919
  getPosition: () => {
27621
27920
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27622
- const points = this.points;
27921
+ const points = this.drawPoints;
27623
27922
  const start = new this.scope.Point(points[0], points[1]);
27624
27923
  return this.scope.project.view.projectToView(start.transform(matrix));
27625
27924
  },
@@ -27629,14 +27928,15 @@ var StraightLineModel = class extends ElementModel {
27629
27928
  }
27630
27929
  const pointsMatrix = new this.scope.Matrix(this.pointsMatrix);
27631
27930
  const trPoint = point.transform(pointsMatrix.inverted());
27632
- this.setPoints([trPoint.x, trPoint.y, this.points[2], this.points[3]]);
27931
+ const oldPoints = this.drawPoints;
27932
+ this.setPoints([trPoint.x, trPoint.y, oldPoints[2], oldPoints[3]]);
27633
27933
  }
27634
27934
  });
27635
27935
  cfg.controlPoints.push({
27636
27936
  name: "line-end",
27637
27937
  getPosition: () => {
27638
27938
  const matrix = new this.scope.Matrix(this.pointsMatrix);
27639
- const points = this.points;
27939
+ const points = this.drawPoints;
27640
27940
  const end = new this.scope.Point(points[2], points[3]);
27641
27941
  return this.scope.project.view.projectToView(end.transform(matrix));
27642
27942
  },
@@ -27646,7 +27946,8 @@ var StraightLineModel = class extends ElementModel {
27646
27946
  }
27647
27947
  const pointsMatrix = new this.scope.Matrix(this.pointsMatrix);
27648
27948
  const trPoint = point.transform(pointsMatrix.inverted());
27649
- this.setPoints([this.points[0], this.points[1], trPoint.x, trPoint.y]);
27949
+ const oldPoints = this.drawPoints;
27950
+ this.setPoints([oldPoints[0], oldPoints[1], trPoint.x, trPoint.y]);
27650
27951
  }
27651
27952
  });
27652
27953
  return cfg;
@@ -27692,10 +27993,13 @@ var ImageModel = class extends ElementModel {
27692
27993
  get src() {
27693
27994
  return this.root.get("src");
27694
27995
  }
27695
- constructor(root, scope, imageSets, liveCursor) {
27696
- super(root, scope, liveCursor);
27996
+ constructor(root, scope, imageSets, liveCursor, isPerformanceMode) {
27997
+ super(root, scope, liveCursor, isPerformanceMode);
27697
27998
  _defineProperty16(this, "item", null);
27698
27999
  _defineProperty16(this, "imageSets", void 0);
28000
+ _defineProperty16(this, "clearLocalPointsWhenYPointsChange", true);
28001
+ _defineProperty16(this, "shouldUseLocalPoints", true);
28002
+ _defineProperty16(this, "localPointsPick", 4);
27699
28003
  this.imageSets = imageSets;
27700
28004
  if (!this.root.has("type")) {
27701
28005
  this.root.set("type", "image");
@@ -27714,6 +28018,7 @@ var ImageModel = class extends ElementModel {
27714
28018
  }
27715
28019
  if (!this.imageSets.querySelector(`[id='${this.uuid}']`)) {
27716
28020
  const img = document.createElement("img");
28021
+ img.crossOrigin = "anonymous";
27717
28022
  img.src = this.src;
27718
28023
  img.id = this.uuid;
27719
28024
  this.imageSets.appendChild(img);
@@ -27778,7 +28083,7 @@ var RenderableModel = class extends import_eventemitter3.default {
27778
28083
  get uuid() {
27779
28084
  return (0, import_uuid.v4)().replace(/-/g, "");
27780
28085
  }
27781
- constructor(layerId, shadowEmitter, elements, scope, toolbarModel, userManager, imageSets, liveCursor, hasPermission) {
28086
+ constructor(options) {
27782
28087
  super();
27783
28088
  _defineProperty17(this, "scope", void 0);
27784
28089
  _defineProperty17(this, "toolbarModel", void 0);
@@ -27791,6 +28096,7 @@ var RenderableModel = class extends import_eventemitter3.default {
27791
28096
  _defineProperty17(this, "shadowEmitter", void 0);
27792
28097
  _defineProperty17(this, "imageSets", void 0);
27793
28098
  _defineProperty17(this, "liveCursor", void 0);
28099
+ _defineProperty17(this, "isPerformanceMode", void 0);
27794
28100
  _defineProperty17(this, "onElementsChange", (event) => {
27795
28101
  for (const [key, value] of event.changes.keys.entries()) {
27796
28102
  if (value.action === "add") {
@@ -27809,15 +28115,16 @@ var RenderableModel = class extends import_eventemitter3.default {
27809
28115
  }
27810
28116
  }
27811
28117
  });
27812
- this.liveCursor = liveCursor;
27813
- this.imageSets = imageSets;
27814
- this.hasPermission = hasPermission;
27815
- this.shadowEmitter = shadowEmitter;
27816
- this.layerId = layerId;
27817
- this.userManager = userManager;
27818
- this.elements = elements;
27819
- this.scope = scope;
27820
- this.toolbarModel = toolbarModel;
28118
+ this.isPerformanceMode = options.isPerformanceMode;
28119
+ this.liveCursor = options.liveCursor;
28120
+ this.imageSets = options.imageSets;
28121
+ this.hasPermission = options.hasPermission;
28122
+ this.shadowEmitter = options.shadowEmitter;
28123
+ this.layerId = options.layerId;
28124
+ this.userManager = options.userManager;
28125
+ this.elements = options.elements;
28126
+ this.scope = options.scope;
28127
+ this.toolbarModel = options.toolbarModel;
27821
28128
  this.elementModels = /* @__PURE__ */ new Map();
27822
28129
  for (const key of this.elements.keys()) {
27823
28130
  const type = this.elements.get(key)?.get("type");
@@ -27848,33 +28155,43 @@ var RenderableModel = class extends import_eventemitter3.default {
27848
28155
  convertToModel(yMap) {
27849
28156
  const type = yMap.get("type");
27850
28157
  let model = null;
28158
+ const uuid = yMap.get(ElementModel.KEYS.uuid);
28159
+ if (uuid) {
28160
+ const existingModel = this.elementModels.get(uuid);
28161
+ if (existingModel) {
28162
+ existingModel.shadowEmitter = this.shadowEmitter;
28163
+ existingModel.bindObserver();
28164
+ return existingModel;
28165
+ }
28166
+ }
27851
28167
  if (type === "curve") {
27852
- model = new CurveModel(yMap, this.scope, this.liveCursor);
28168
+ model = new CurveModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27853
28169
  } else if (["ellipse"].indexOf(type) >= 0) {
27854
- model = new SegmentsModel(yMap, this.scope, type, this.liveCursor);
28170
+ model = new SegmentsModel(yMap, this.scope, type, this.liveCursor, this.isPerformanceMode);
27855
28171
  } else if (type === "selector") {
27856
- model = new SelectorModel(yMap, this.scope, this.liveCursor);
28172
+ model = new SelectorModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27857
28173
  } else if (type === "arrow") {
27858
- model = new LineModel(yMap, this.scope, this.liveCursor);
28174
+ model = new LineModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27859
28175
  } else if (type === "line") {
27860
- model = new StraightLineModel(yMap, this.scope, this.liveCursor);
28176
+ model = new StraightLineModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27861
28177
  } else if (type === "point-text") {
27862
- model = new PointTextModel(yMap, this.scope, this.liveCursor);
28178
+ model = new PointTextModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27863
28179
  } else if (type === "triangle") {
27864
- model = new TriangleModel(yMap, this.scope, this.liveCursor);
28180
+ model = new TriangleModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27865
28181
  } else if (type === "rectangle") {
27866
- model = new RectangleModel(yMap, this.scope, this.liveCursor);
28182
+ model = new RectangleModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27867
28183
  } else if (type === "eraser") {
27868
- model = new EraserModel(yMap, this.scope, this.liveCursor);
28184
+ model = new EraserModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
27869
28185
  } else if (type === "laser") {
27870
- model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid) => {
27871
- this.removeElementItem(uuid);
27872
- });
28186
+ model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid2) => {
28187
+ this.removeElementItem(uuid2);
28188
+ }, this.isPerformanceMode);
27873
28189
  } else if (type === "image") {
27874
- model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor);
28190
+ model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor, this.isPerformanceMode);
27875
28191
  }
27876
28192
  if (model) {
27877
28193
  model.shadowEmitter = this.shadowEmitter;
28194
+ model.bindObserver();
27878
28195
  this.elementModels.set(model.uuid, model);
27879
28196
  }
27880
28197
  return model;
@@ -27888,7 +28205,7 @@ var RenderableModel = class extends import_eventemitter3.default {
27888
28205
  confirmPermission() {
27889
28206
  const hasPermission = this.hasPermission(WhiteboardPermissionFlag.draw);
27890
28207
  if (!hasPermission) {
27891
- (0, import_forge_room4.log)("[@netless/forge-whiteboard] no permission to draw", {}, "warn");
28208
+ (0, import_forge_room6.log)("[@netless/forge-whiteboard] no permission to draw", {}, "warn");
27892
28209
  }
27893
28210
  return hasPermission;
27894
28211
  }
@@ -27905,16 +28222,58 @@ var RenderableModel = class extends import_eventemitter3.default {
27905
28222
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
27906
28223
  this.elements.set(uuid, yMap);
27907
28224
  }, elementsUndoOrigin);
27908
- const model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor);
28225
+ const model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor, this.isPerformanceMode);
28226
+ model.bindObserver();
27909
28227
  model.root.set("src", src);
27910
- const initMatrix = new this.scope.Matrix();
28228
+ model.ownerId = this.userManager.selfId;
28229
+ this.fitImageToViewport(src, model);
28230
+ }
28231
+ fitImageToViewport(src, model) {
27911
28232
  const center = this.scope.project.view.center;
27912
- initMatrix.translate({
28233
+ const fallbackMatrix = new this.scope.Matrix();
28234
+ fallbackMatrix.translate({
27913
28235
  x: center.x,
27914
28236
  y: center.y
27915
28237
  });
27916
- model.appendPointsMatrix(initMatrix);
27917
- model.ownerId = this.userManager.selfId;
28238
+ this.setElementPointsMatrix(model, fallbackMatrix);
28239
+ const img = document.createElement("img");
28240
+ img.crossOrigin = "anonymous";
28241
+ img.onload = () => {
28242
+ const naturalWidth = img.naturalWidth || img.width;
28243
+ const naturalHeight = img.naturalHeight || img.height;
28244
+ if (naturalWidth <= 0 || naturalHeight <= 0) {
28245
+ return;
28246
+ }
28247
+ const viewportBounds = this.scope.project.view.bounds;
28248
+ const maxWidth = viewportBounds.width * 2 / 3;
28249
+ const maxHeight = viewportBounds.height * 2 / 3;
28250
+ const fitScale = Math.min(maxWidth / naturalWidth, maxHeight / naturalHeight, 1);
28251
+ const nextMatrix = new this.scope.Matrix();
28252
+ nextMatrix.translate({
28253
+ x: center.x,
28254
+ y: center.y
28255
+ });
28256
+ if (fitScale > 0 && Number.isFinite(fitScale)) {
28257
+ nextMatrix.scale(fitScale);
28258
+ }
28259
+ this.setElementPointsMatrix(model, nextMatrix);
28260
+ };
28261
+ img.onerror = () => {
28262
+ (0, import_forge_room6.log)("[@netless/forge-whiteboard] failed to preload image for viewport fitting", {
28263
+ src
28264
+ }, "warn");
28265
+ };
28266
+ img.src = src;
28267
+ }
28268
+ setElementPointsMatrix(model, matrix) {
28269
+ const values = [matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty];
28270
+ if (model.root.doc) {
28271
+ model.root.doc.transact(() => {
28272
+ model.root.set(ElementModel.KEYS.pointsMatrix, values);
28273
+ }, elementsUndoOrigin);
28274
+ } else {
28275
+ model.root.set(ElementModel.KEYS.pointsMatrix, values);
28276
+ }
27918
28277
  }
27919
28278
  createCurve() {
27920
28279
  let shadow = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
@@ -27922,8 +28281,10 @@ var RenderableModel = class extends import_eventemitter3.default {
27922
28281
  return null;
27923
28282
  }
27924
28283
  const yMap = new Y12.Map();
28284
+ const uuid = this.uuid;
28285
+ const curveModel = new CurveModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28286
+ this.elementModels.set(uuid, curveModel);
27925
28287
  this.elements.doc?.transact(() => {
27926
- const uuid = this.uuid;
27927
28288
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
27928
28289
  yMap.set(ElementModel.KEYS.uuid, uuid);
27929
28290
  yMap.set("type", "curve");
@@ -27936,7 +28297,7 @@ var RenderableModel = class extends import_eventemitter3.default {
27936
28297
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
27937
28298
  this.elements.set(uuid, yMap);
27938
28299
  }, elementsUndoOrigin);
27939
- const curveModel = new CurveModel(yMap, this.scope, this.liveCursor);
28300
+ curveModel.bindObserver();
27940
28301
  this.initElement(curveModel);
27941
28302
  return curveModel;
27942
28303
  }
@@ -27945,11 +28306,17 @@ var RenderableModel = class extends import_eventemitter3.default {
27945
28306
  return null;
27946
28307
  }
27947
28308
  const yMap = new Y12.Map();
28309
+ const uuid = this.uuid;
28310
+ const model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid2) => {
28311
+ this.removeElementItem(uuid2);
28312
+ }, this.isPerformanceMode);
28313
+ this.elementModels.set(uuid, model);
27948
28314
  this.elements.doc?.transact(() => {
27949
- const uuid = this.uuid;
27950
28315
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
27951
28316
  yMap.set(ElementModel.KEYS.uuid, uuid);
27952
28317
  yMap.set("type", "laser");
28318
+ yMap.set(ElementModel.KEYS.points, new Y12.Array());
28319
+ yMap.set("removed", false);
27953
28320
  yMap.set(ElementModel.KEYS.shadow, "layer");
27954
28321
  yMap.set(ElementModel.KEYS.strokeWidth, 8);
27955
28322
  yMap.set(ElementModel.KEYS.strokeColor, "#F44336");
@@ -27957,9 +28324,8 @@ var RenderableModel = class extends import_eventemitter3.default {
27957
28324
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
27958
28325
  this.elements.set(uuid, yMap);
27959
28326
  }, elementsUndoOrigin);
27960
- const model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid) => {
27961
- this.removeElementItem(uuid);
27962
- });
28327
+ model.bindObserver();
28328
+ this.initElement(model);
27963
28329
  return model;
27964
28330
  }
27965
28331
  createEraser() {
@@ -27967,11 +28333,14 @@ var RenderableModel = class extends import_eventemitter3.default {
27967
28333
  return null;
27968
28334
  }
27969
28335
  const yMap = new Y12.Map();
28336
+ const uuid = this.uuid;
28337
+ const model = new EraserModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28338
+ this.elementModels.set(uuid, model);
27970
28339
  this.elements.doc?.transact(() => {
27971
- const uuid = this.uuid;
27972
28340
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
27973
28341
  yMap.set(ElementModel.KEYS.uuid, uuid);
27974
28342
  yMap.set("type", "eraser");
28343
+ yMap.set(ElementModel.KEYS.points, new Y12.Array());
27975
28344
  yMap.set(ElementModel.KEYS.shadow, "layer");
27976
28345
  yMap.set(ElementModel.KEYS.strokeWidth, 4);
27977
28346
  yMap.set(ElementModel.KEYS.strokeColor, "#9E9E9E");
@@ -27979,7 +28348,7 @@ var RenderableModel = class extends import_eventemitter3.default {
27979
28348
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
27980
28349
  this.elements.set(uuid, yMap);
27981
28350
  }, elementsUndoOrigin);
27982
- const model = new EraserModel(yMap, this.scope, this.liveCursor);
28351
+ model.bindObserver();
27983
28352
  return model;
27984
28353
  }
27985
28354
  createTriangle(shadow) {
@@ -27987,45 +28356,54 @@ var RenderableModel = class extends import_eventemitter3.default {
27987
28356
  return null;
27988
28357
  }
27989
28358
  const yMap = new Y12.Map();
28359
+ const uuid = this.uuid;
28360
+ const triangleModel = new TriangleModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28361
+ this.elementModels.set(uuid, triangleModel);
27990
28362
  this.elements.doc?.transact(() => {
27991
- const uuid = this.uuid;
27992
28363
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
27993
28364
  yMap.set(ElementModel.KEYS.uuid, uuid);
27994
28365
  yMap.set("type", "triangle");
27995
28366
  if (shadow) {
27996
28367
  yMap.set(ElementModel.KEYS.shadow, "layer");
27997
28368
  }
28369
+ yMap.set("points", new Y12.Array());
27998
28370
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
27999
28371
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28000
28372
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
28001
28373
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28002
28374
  this.elements.set(uuid, yMap);
28003
28375
  }, elementsUndoOrigin);
28004
- const triangle = new TriangleModel(yMap, this.scope, this.liveCursor);
28005
- this.initElement(triangle);
28006
- triangle.dashArray = this.toolbarModel.dashArray;
28007
- return triangle;
28376
+ triangleModel.bindObserver();
28377
+ this.initElement(triangleModel);
28378
+ triangleModel.dashArray = this.toolbarModel.dashArray;
28379
+ return triangleModel;
28008
28380
  }
28009
28381
  createRectangle(shadow) {
28010
28382
  if (!this.confirmPermission()) {
28011
28383
  return null;
28012
28384
  }
28013
28385
  const yMap = new Y12.Map();
28386
+ const uuid = this.uuid;
28387
+ const rect = new RectangleModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28388
+ this.elementModels.set(uuid, rect);
28014
28389
  this.elements.doc?.transact(() => {
28015
- const uuid = this.uuid;
28016
28390
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
28017
28391
  yMap.set(ElementModel.KEYS.uuid, uuid);
28018
28392
  yMap.set("type", "rectangle");
28019
28393
  if (shadow) {
28020
28394
  yMap.set(ElementModel.KEYS.shadow, "layer");
28021
28395
  }
28396
+ const initPoints = new Y12.Array();
28397
+ initPoints.push([0, 0, 0, 0]);
28398
+ yMap.set("points", initPoints);
28399
+ yMap.set("radius", 0);
28022
28400
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
28023
28401
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28024
28402
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
28025
28403
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28026
28404
  this.elements.set(uuid, yMap);
28027
28405
  }, elementsUndoOrigin);
28028
- const rect = new RectangleModel(yMap, this.scope, this.liveCursor);
28406
+ rect.bindObserver();
28029
28407
  this.initElement(rect);
28030
28408
  rect.dashArray = this.toolbarModel.dashArray;
28031
28409
  return rect;
@@ -28035,21 +28413,24 @@ var RenderableModel = class extends import_eventemitter3.default {
28035
28413
  return null;
28036
28414
  }
28037
28415
  const yMap = new Y12.Map();
28416
+ const uuid = this.uuid;
28417
+ const segmentsModel = new SegmentsModel(yMap, this.scope, type, this.liveCursor, this.isPerformanceMode);
28418
+ this.elementModels.set(uuid, segmentsModel);
28038
28419
  this.elements.doc?.transact(() => {
28039
- const uuid = this.uuid;
28040
28420
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
28041
28421
  yMap.set(ElementModel.KEYS.uuid, uuid);
28042
28422
  yMap.set("type", type);
28043
28423
  if (shadow) {
28044
28424
  yMap.set(ElementModel.KEYS.shadow, "layer");
28045
28425
  }
28426
+ yMap.set(ElementModel.KEYS.points, new Y12.Array());
28046
28427
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
28047
28428
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28048
28429
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
28049
28430
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28050
28431
  this.elements.set(uuid, yMap);
28051
28432
  }, elementsUndoOrigin);
28052
- const segmentsModel = new SegmentsModel(yMap, this.scope, type, this.liveCursor);
28433
+ segmentsModel.bindObserver();
28053
28434
  this.initElement(segmentsModel);
28054
28435
  segmentsModel.dashArray = this.toolbarModel.dashArray;
28055
28436
  return segmentsModel;
@@ -28060,16 +28441,21 @@ var RenderableModel = class extends import_eventemitter3.default {
28060
28441
  return null;
28061
28442
  }
28062
28443
  const yMap = new Y12.Map();
28444
+ const uuid = this.uuid;
28445
+ const selectorModel = new SelectorModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28446
+ this.elementModels.set(uuid, selectorModel);
28063
28447
  this.elements.doc?.transact(() => {
28064
- const uuid = this.uuid;
28065
28448
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
28066
28449
  yMap.set(ElementModel.KEYS.uuid, uuid);
28067
28450
  yMap.set("type", "selector");
28451
+ const initPoints = new Y12.Array();
28452
+ initPoints.push([0, 0, 0, 0]);
28453
+ yMap.set(ElementModel.KEYS.points, initPoints);
28068
28454
  yMap.set(ElementModel.KEYS.shadow, "layer");
28069
28455
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28070
28456
  this.elements.set(uuid, yMap);
28071
28457
  }, elementsUndoOrigin);
28072
- const selectorModel = new SelectorModel(yMap, this.scope, this.liveCursor);
28458
+ selectorModel.bindObserver();
28073
28459
  selectorModel.shadow = "layer";
28074
28460
  return selectorModel;
28075
28461
  }
@@ -28078,21 +28464,24 @@ var RenderableModel = class extends import_eventemitter3.default {
28078
28464
  return null;
28079
28465
  }
28080
28466
  const yMap = new Y12.Map();
28467
+ const uuid = this.uuid;
28468
+ const straightLineModel = new StraightLineModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28469
+ this.elementModels.set(uuid, straightLineModel);
28081
28470
  this.elements.doc?.transact(() => {
28082
- const uuid = this.uuid;
28083
28471
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
28084
28472
  yMap.set(ElementModel.KEYS.uuid, uuid);
28085
28473
  yMap.set("type", "line");
28086
28474
  if (shadow) {
28087
28475
  yMap.set(ElementModel.KEYS.shadow, "layer");
28088
28476
  }
28477
+ yMap.set("points", new Y12.Array());
28089
28478
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
28090
28479
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28091
28480
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
28092
28481
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28093
28482
  this.elements.set(uuid, yMap);
28094
28483
  }, elementsUndoOrigin);
28095
- const straightLineModel = new StraightLineModel(yMap, this.scope, this.liveCursor);
28484
+ straightLineModel.bindObserver();
28096
28485
  this.initElement(straightLineModel);
28097
28486
  straightLineModel.dashArray = this.toolbarModel.dashArray;
28098
28487
  return straightLineModel;
@@ -28102,21 +28491,26 @@ var RenderableModel = class extends import_eventemitter3.default {
28102
28491
  return null;
28103
28492
  }
28104
28493
  const yMap = new Y12.Map();
28494
+ const uuid = this.uuid;
28495
+ const lineModel = new LineModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28496
+ this.elementModels.set(uuid, lineModel);
28105
28497
  this.elements.doc?.transact(() => {
28106
- const uuid = this.uuid;
28107
28498
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
28108
28499
  yMap.set(ElementModel.KEYS.uuid, uuid);
28109
28500
  yMap.set("type", "arrow");
28110
28501
  if (shadow) {
28111
28502
  yMap.set(ElementModel.KEYS.shadow, "layer");
28112
28503
  }
28504
+ yMap.set("headArrow", "none");
28505
+ yMap.set("tailArrow", "normal");
28506
+ yMap.set(ElementModel.KEYS.points, new Y12.Array());
28113
28507
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
28114
28508
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28115
28509
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
28116
28510
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28117
28511
  this.elements.set(uuid, yMap);
28118
28512
  }, elementsUndoOrigin);
28119
- const lineModel = new LineModel(yMap, this.scope, this.liveCursor);
28513
+ lineModel.bindObserver();
28120
28514
  this.initElement(lineModel);
28121
28515
  lineModel.dashArray = this.toolbarModel.dashArray;
28122
28516
  return lineModel;
@@ -28126,21 +28520,24 @@ var RenderableModel = class extends import_eventemitter3.default {
28126
28520
  return null;
28127
28521
  }
28128
28522
  const yMap = new Y12.Map();
28523
+ const uuid = this.uuid;
28524
+ const pointTextModel = new PointTextModel(yMap, this.scope, this.liveCursor, this.isPerformanceMode);
28525
+ this.elementModels.set(uuid, pointTextModel);
28129
28526
  this.elements.doc?.transact(() => {
28130
- const uuid = this.uuid;
28131
28527
  yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
28132
28528
  yMap.set(ElementModel.KEYS.uuid, uuid);
28133
28529
  yMap.set("type", "point-text");
28134
28530
  if (shadow) {
28135
28531
  yMap.set(ElementModel.KEYS.shadow, "layer");
28136
28532
  }
28533
+ yMap.set(ElementModel.KEYS.points, new Y12.Array());
28137
28534
  yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
28138
28535
  yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
28139
28536
  yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
28140
28537
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28141
28538
  this.elements.set(uuid, yMap);
28142
28539
  }, elementsUndoOrigin);
28143
- const pointTextModel = new PointTextModel(yMap, this.scope, this.liveCursor);
28540
+ pointTextModel.bindObserver();
28144
28541
  pointTextModel.setPoints([x, y]);
28145
28542
  pointTextModel.fontSize = this.toolbarModel.fontSize;
28146
28543
  pointTextModel.fontFamily = this.toolbarModel.fontFamily;
@@ -28163,18 +28560,19 @@ var RenderableModel = class extends import_eventemitter3.default {
28163
28560
  });
28164
28561
  }
28165
28562
  dispose(clearElements) {
28166
- (0, import_forge_room4.removeObserver)(this.elements, this.onElementsChange);
28563
+ (0, import_forge_room6.removeObserver)(this.elements, this.onElementsChange);
28167
28564
  if (clearElements) {
28168
28565
  this.elements.clear();
28169
28566
  }
28170
28567
  Array.from(this.elementModels.values()).forEach((model) => {
28171
28568
  model.dispose();
28569
+ model.disposeObserver();
28172
28570
  });
28173
28571
  }
28174
28572
  };
28175
28573
 
28176
28574
  // src/utils/Recognizer.ts
28177
- var import_lodash8 = __toESM(require_lodash(), 1);
28575
+ var import_lodash7 = __toESM(require_lodash(), 1);
28178
28576
 
28179
28577
  // src/utils/UnistrokeRecognizer.js
28180
28578
  function Point(x, y) {
@@ -28421,7 +28819,7 @@ var Recognizer = class {
28421
28819
  let maxX = -Number.MAX_VALUE;
28422
28820
  let minY = Number.MAX_VALUE;
28423
28821
  let maxY = -Number.MAX_VALUE;
28424
- const result = this.dollar.Recognize((0, import_lodash8.chunk)(points, 2).map((v) => {
28822
+ const result = this.dollar.Recognize((0, import_lodash7.chunk)(points, 3).map((v) => {
28425
28823
  minX = Math.min(minX, v[0]);
28426
28824
  maxX = Math.max(maxX, v[0]);
28427
28825
  minY = Math.min(minY, v[1]);
@@ -28465,11 +28863,24 @@ var CurveTool = class extends WhiteboardTool {
28465
28863
  _defineProperty19(this, "elementModel", null);
28466
28864
  _defineProperty19(this, "recognizer", new Recognizer());
28467
28865
  _defineProperty19(this, "pointCount", 0);
28866
+ _defineProperty19(this, "pendingPoints", []);
28867
+ _defineProperty19(this, "flushRafId", 0);
28468
28868
  _defineProperty19(this, "showLiveCursor", true);
28469
- this.tool.minDistance = 5;
28869
+ _defineProperty19(this, "flushPendingPoints", () => {
28870
+ this.flushRafId = 0;
28871
+ if (this.elementModel && this.pendingPoints.length > 0) {
28872
+ this.elementModel.appendPoints(this.pendingPoints);
28873
+ this.pendingPoints = [];
28874
+ }
28875
+ });
28470
28876
  }
28471
28877
  onMouseDown(_event) {
28472
28878
  this.pointCount = 0;
28879
+ this.pendingPoints = [];
28880
+ if (this.flushRafId) {
28881
+ cancelAnimationFrame(this.flushRafId);
28882
+ this.flushRafId = 0;
28883
+ }
28473
28884
  if (this.elementModel) {
28474
28885
  this.elementModel.dispose();
28475
28886
  }
@@ -28484,27 +28895,38 @@ var CurveTool = class extends WhiteboardTool {
28484
28895
  if (this.pointCount > 1024) {
28485
28896
  return;
28486
28897
  }
28487
- const MIN_DISTANCE = 4;
28898
+ const MIN_DISTANCE = 2;
28488
28899
  if (this.elementModel) {
28489
- const len = this.elementModel.points.length;
28490
- let last = {
28491
- x: 0,
28492
- y: 0
28493
- };
28494
- if (len >= 2) {
28495
- last = {
28496
- x: this.elementModel.points[len - 2],
28497
- y: this.elementModel.points[len - 1]
28498
- };
28900
+ let lastX = 0;
28901
+ 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];
28905
+ } else {
28906
+ const len = this.elementModel.points.length;
28907
+ if (len >= 3) {
28908
+ lastX = this.elementModel.points[len - 3];
28909
+ lastY = this.elementModel.points[len - 2];
28910
+ }
28499
28911
  }
28500
- const dist = Math.max(Math.abs(last.x - event.point.x), Math.abs(last.y - event.point.y));
28912
+ const dist = Math.max(Math.abs(lastX - event.point.x), Math.abs(lastY - event.point.y));
28501
28913
  if (dist >= MIN_DISTANCE) {
28502
28914
  this.pointCount += 1;
28503
- this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
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);
28918
+ if (!this.flushRafId) {
28919
+ this.flushRafId = requestAnimationFrame(this.flushPendingPoints);
28920
+ }
28504
28921
  }
28505
28922
  }
28506
28923
  }
28507
28924
  onMouseUp(event) {
28925
+ if (this.flushRafId) {
28926
+ cancelAnimationFrame(this.flushRafId);
28927
+ this.flushRafId = 0;
28928
+ }
28929
+ this.flushPendingPoints();
28508
28930
  this.modelGetter().then((model) => {
28509
28931
  if (!model) {
28510
28932
  return;
@@ -28605,7 +29027,7 @@ var RectangleTool = class extends WhiteboardTool {
28605
29027
 
28606
29028
  // src/model/ToolbarModel.ts
28607
29029
  var import_eventemitter32 = __toESM(require("eventemitter3"), 1);
28608
- var import_forge_room5 = require("@netless/forge-room");
29030
+ var import_forge_room7 = require("@netless/forge-room");
28609
29031
  function _defineProperty21(e, r, t) {
28610
29032
  return (r = _toPropertyKey21(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
28611
29033
  }
@@ -28702,7 +29124,7 @@ var ToolbarModel = class extends import_eventemitter32.default {
28702
29124
  });
28703
29125
  }
28704
29126
  dispose() {
28705
- (0, import_forge_room5.removeObserver)(this.root, this.handleRootUpdate);
29127
+ (0, import_forge_room7.removeObserver)(this.root, this.handleRootUpdate);
28706
29128
  this.removeAllListeners();
28707
29129
  }
28708
29130
  };
@@ -28801,7 +29223,7 @@ var SelectorTool = class extends WhiteboardTool {
28801
29223
  // src/model/SelectElementsModel.ts
28802
29224
  var Y13 = __toESM(require("yjs"), 1);
28803
29225
  var import_eventemitter33 = __toESM(require("eventemitter3"), 1);
28804
- var import_forge_room6 = require("@netless/forge-room");
29226
+ var import_forge_room8 = require("@netless/forge-room");
28805
29227
 
28806
29228
  // src/WhiteboardKeys.ts
28807
29229
  var WhiteboardKeys = {
@@ -28851,7 +29273,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
28851
29273
  }
28852
29274
  const cb = this.observers.get(user.id);
28853
29275
  if (cb) {
28854
- (0, import_forge_room6.removeDeepObserver)(this.requestUserMap(user.id), cb);
29276
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), cb);
28855
29277
  this.observers.delete(user.id);
28856
29278
  }
28857
29279
  });
@@ -28860,7 +29282,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
28860
29282
  this.handleUserSelectElementsChange(user.id, evts);
28861
29283
  };
28862
29284
  if (this.observers.has(user.id)) {
28863
- (0, import_forge_room6.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
29285
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
28864
29286
  this.observers.delete(user.id);
28865
29287
  }
28866
29288
  this.requestUserMap(user.id).observeDeep(observer);
@@ -28883,7 +29305,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
28883
29305
  this.handleUserSelectElementsChange(userId, evts);
28884
29306
  };
28885
29307
  if (this.observers.has(userId)) {
28886
- (0, import_forge_room6.removeDeepObserver)(this.requestUserMap(userId), this.observers.get(userId));
29308
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(userId), this.observers.get(userId));
28887
29309
  }
28888
29310
  this.requestUserMap(userId).observeDeep(observer);
28889
29311
  this.observers.set(userId, observer);
@@ -28947,7 +29369,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
28947
29369
  }
28948
29370
  dispose() {
28949
29371
  for (const [key, value] of this.observers.entries()) {
28950
- (0, import_forge_room6.removeDeepObserver)(this.requestUserMap(key), value);
29372
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(key), value);
28951
29373
  }
28952
29374
  this.observers.clear();
28953
29375
  this.userManager.off("leave", this.handleUserLeave);
@@ -29636,6 +30058,7 @@ var Editor = class extends import_eventemitter35.default {
29636
30058
  this.shadowContainer.remove();
29637
30059
  this.shadowScope.project.activeLayer.addChild(this.shadowContainer);
29638
30060
  this.targets.forEach((model) => {
30061
+ console.log("[][][] translateShadow model", model.root._dEH);
29639
30062
  model.shadow = this.shadowContainer.data.uuid;
29640
30063
  });
29641
30064
  }
@@ -29862,7 +30285,7 @@ var Gesture = class extends import_eventemitter36.default {
29862
30285
  };
29863
30286
 
29864
30287
  // src/Camera.ts
29865
- var import_forge_room7 = require("@netless/forge-room");
30288
+ var import_forge_room9 = require("@netless/forge-room");
29866
30289
  function _defineProperty28(e, r, t) {
29867
30290
  return (r = _toPropertyKey28(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
29868
30291
  }
@@ -29939,14 +30362,14 @@ var Camera = class extends import_eventemitter37.default {
29939
30362
  }
29940
30363
  const cb = this.observers.get(user.id);
29941
30364
  if (cb) {
29942
- (0, import_forge_room7.removeObserver)(this.requestUserMap(user.id), cb);
30365
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(user.id), cb);
29943
30366
  }
29944
30367
  });
29945
30368
  _defineProperty28(this, "handleUserJoin", (user) => {
29946
30369
  if (this.observers.has(user.id)) {
29947
30370
  const cb = this.observers.get(user.id);
29948
30371
  if (cb) {
29949
- (0, import_forge_room7.removeObserver)(this.requestUserMap(user.id), cb);
30372
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(user.id), cb);
29950
30373
  this.observers.delete(user.id);
29951
30374
  }
29952
30375
  }
@@ -30058,7 +30481,7 @@ var Camera = class extends import_eventemitter37.default {
30058
30481
  this.handleViewMatrixUpdate(userId, evt);
30059
30482
  };
30060
30483
  if (this.observers.has(userId)) {
30061
- (0, import_forge_room7.removeObserver)(this.requestUserMap(userId), observer);
30484
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), observer);
30062
30485
  }
30063
30486
  this.requestUserMap(userId).observe(observer);
30064
30487
  this.observers.set(userId, observer);
@@ -30255,10 +30678,10 @@ var Camera = class extends import_eventemitter37.default {
30255
30678
  Array.from(this.observers.keys()).forEach((userId) => {
30256
30679
  const cb = this.observers.get(userId);
30257
30680
  if (cb) {
30258
- (0, import_forge_room7.removeObserver)(this.requestUserMap(userId), cb);
30681
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), cb);
30259
30682
  }
30260
30683
  });
30261
- (0, import_forge_room7.removeObserver)(this.whiteboardAttrsMap, this.handleMainCameraChange);
30684
+ (0, import_forge_room9.removeObserver)(this.whiteboardAttrsMap, this.handleMainCameraChange);
30262
30685
  this.userManager.off("join", this.handleUserJoin);
30263
30686
  this.userManager.off("leave", this.handleUserLeave);
30264
30687
  this.gesture.removeAllListeners();
@@ -30429,6 +30852,8 @@ var Whiteboard = class extends import_eventemitter38.default {
30429
30852
  _defineProperty31(this, "enableCameraBoundaryHighlight", void 0);
30430
30853
  _defineProperty31(this, "getElementAttribute", void 0);
30431
30854
  _defineProperty31(this, "setElementAttribute", void 0);
30855
+ _defineProperty31(this, "setPerformanceMode", void 0);
30856
+ _defineProperty31(this, "isPerformanceMode", void 0);
30432
30857
  _defineProperty31(this, "removeElement", void 0);
30433
30858
  _defineProperty31(this, "getCurrentTool", void 0);
30434
30859
  _defineProperty31(this, "setCurrentTool", void 0);
@@ -30549,7 +30974,7 @@ var EraserTool = class extends WhiteboardTool {
30549
30974
  // src/model/TrashedElementsModel.ts
30550
30975
  var Y14 = __toESM(require("yjs"), 1);
30551
30976
  var import_eventemitter39 = __toESM(require("eventemitter3"), 1);
30552
- var import_forge_room8 = require("@netless/forge-room");
30977
+ var import_forge_room10 = require("@netless/forge-room");
30553
30978
  function _defineProperty33(e, r, t) {
30554
30979
  return (r = _toPropertyKey33(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30555
30980
  }
@@ -30586,14 +31011,14 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30586
31011
  }
30587
31012
  const cb = this.observers.get(user.id);
30588
31013
  if (cb) {
30589
- (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), cb);
31014
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(user.id), cb);
30590
31015
  }
30591
31016
  });
30592
31017
  _defineProperty33(this, "handleUserJoin", (user) => {
30593
31018
  if (this.observers.has(user.id)) {
30594
31019
  const cb = this.observers.get(user.id);
30595
31020
  if (cb) {
30596
- (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), cb);
31021
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(user.id), cb);
30597
31022
  this.observers.delete(user.id);
30598
31023
  }
30599
31024
  }
@@ -30601,7 +31026,7 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30601
31026
  this.handleUserTrashElementsChange(user.id, evts);
30602
31027
  };
30603
31028
  if (this.observers.has(user.id)) {
30604
- (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
31029
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
30605
31030
  }
30606
31031
  this.requestUserMap(user.id).observeDeep(observer);
30607
31032
  this.observers.set(user.id, observer);
@@ -30615,7 +31040,7 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30615
31040
  this.handleUserTrashElementsChange(userId, evts);
30616
31041
  };
30617
31042
  if (this.observers.has(userId)) {
30618
- (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(userId), userId);
31043
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(userId), userId);
30619
31044
  }
30620
31045
  this.requestUserMap(userId).observeDeep(observer);
30621
31046
  this.observers.set(userId, observer);
@@ -30677,7 +31102,7 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30677
31102
  }
30678
31103
  dispose() {
30679
31104
  for (const [key, value] of this.observers.entries()) {
30680
- (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(key), value);
31105
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(key), value);
30681
31106
  }
30682
31107
  this.observers.clear();
30683
31108
  this.userManager.off("leave", this.handleUserLeave);
@@ -30727,9 +31152,24 @@ var LaserPointerTool = class extends WhiteboardTool {
30727
31152
  if (this.pointCount > 1024) {
30728
31153
  return;
30729
31154
  }
31155
+ const MIN_DISTANCE = 4;
30730
31156
  if (this.elementModel) {
30731
- this.pointCount += 1;
30732
- this.elementModel.appendPoints([event.point.x, event.point.y]);
31157
+ const len = this.elementModel.points.length;
31158
+ let last = {
31159
+ x: 0,
31160
+ y: 0
31161
+ };
31162
+ if (len >= 2) {
31163
+ last = {
31164
+ x: this.elementModel.points[len - 2],
31165
+ y: this.elementModel.points[len - 1]
31166
+ };
31167
+ }
31168
+ const dist = Math.max(Math.abs(last.x - event.point.x), Math.abs(last.y - event.point.y));
31169
+ if (dist >= MIN_DISTANCE) {
31170
+ this.pointCount += 1;
31171
+ this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
31172
+ }
30733
31173
  }
30734
31174
  }
30735
31175
  onMouseUp(_event) {
@@ -30741,7 +31181,7 @@ var LaserPointerTool = class extends WhiteboardTool {
30741
31181
 
30742
31182
  // src/model/PageModel.ts
30743
31183
  var import_eventemitter310 = __toESM(require("eventemitter3"), 1);
30744
- var import_forge_room9 = require("@netless/forge-room");
31184
+ var import_forge_room11 = require("@netless/forge-room");
30745
31185
  function _defineProperty35(e, r, t) {
30746
31186
  return (r = _toPropertyKey35(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30747
31187
  }
@@ -30774,7 +31214,7 @@ var PageModel = class extends import_eventemitter310.default {
30774
31214
  }
30775
31215
  const cb = this.observers.get(user.id);
30776
31216
  if (cb) {
30777
- (0, import_forge_room9.removeObserver)(this.requestUserMap(user.id), cb);
31217
+ (0, import_forge_room11.removeObserver)(this.requestUserMap(user.id), cb);
30778
31218
  }
30779
31219
  });
30780
31220
  _defineProperty35(this, "handleUserJoin", (user) => {
@@ -30788,7 +31228,7 @@ var PageModel = class extends import_eventemitter310.default {
30788
31228
  if (cameraMode === "main") {
30789
31229
  const targetPage = this.whiteboardAttrsMap.get(WhiteboardKeys.currentPage);
30790
31230
  if (!this.pageMap.has(targetPage) && targetPage !== "_i_") {
30791
- (0, import_forge_room9.log)(`main page {${targetPage}} not found.`, {}, "error");
31231
+ (0, import_forge_room11.log)(`main page {${targetPage}} not found.`, {}, "error");
30792
31232
  return;
30793
31233
  }
30794
31234
  this.requestUserMap(this.userManager.selfId).set(WhiteboardKeys.currentPage, targetPage);
@@ -30835,7 +31275,7 @@ var PageModel = class extends import_eventemitter310.default {
30835
31275
  if (this.observers.has(userId)) {
30836
31276
  const cb = this.observers.get(userId);
30837
31277
  if (cb) {
30838
- (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), cb);
31278
+ (0, import_forge_room11.removeObserver)(this.requestUserMap(userId), cb);
30839
31279
  this.observers.delete(userId);
30840
31280
  }
30841
31281
  }
@@ -30924,12 +31364,12 @@ var PageModel = class extends import_eventemitter310.default {
30924
31364
  dispose() {
30925
31365
  for (const entry of this.observers.entries()) {
30926
31366
  const [userId, observer] = entry;
30927
- (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), observer);
31367
+ (0, import_forge_room11.removeObserver)(this.requestUserMap(userId), observer);
30928
31368
  }
30929
31369
  this.userManager.off("join", this.handleUserJoin);
30930
31370
  this.userManager.off("leave", this.handleUserLeave);
30931
- (0, import_forge_room9.removeObserver)(this.whiteboardAttrsMap, this.handleMainPageChange);
30932
- (0, import_forge_room9.removeObserver)(this.pageMap, this.handlePageMapChange);
31371
+ (0, import_forge_room11.removeObserver)(this.whiteboardAttrsMap, this.handleMainPageChange);
31372
+ (0, import_forge_room11.removeObserver)(this.pageMap, this.handlePageMapChange);
30933
31373
  }
30934
31374
  };
30935
31375
 
@@ -30944,8 +31384,8 @@ async function waitUntil(fn, timeout) {
30944
31384
 
30945
31385
  // src/IndexedNavigation.ts
30946
31386
  var import_eventemitter311 = __toESM(require("eventemitter3"), 1);
30947
- var import_forge_room10 = require("@netless/forge-room");
30948
- var import_forge_room11 = require("@netless/forge-room");
31387
+ var import_forge_room12 = require("@netless/forge-room");
31388
+ var import_forge_room13 = require("@netless/forge-room");
30949
31389
  function _defineProperty36(e, r, t) {
30950
31390
  return (r = _toPropertyKey36(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30951
31391
  }
@@ -30972,7 +31412,7 @@ var IndexedNavigation = class extends import_eventemitter311.default {
30972
31412
  return this.list[key] && this.list[key].prev === "";
30973
31413
  });
30974
31414
  if (!headId) {
30975
- (0, import_forge_room10.log)("indexed navigation confusion", {
31415
+ (0, import_forge_room12.log)("indexed navigation confusion", {
30976
31416
  list: JSON.stringify(this.list)
30977
31417
  }, "error");
30978
31418
  throw new Error("indexed navigation confusion");
@@ -31288,7 +31728,7 @@ var IndexedNavigation = class extends import_eventemitter311.default {
31288
31728
  }
31289
31729
  }
31290
31730
  dispose() {
31291
- (0, import_forge_room11.removeObserver)(this.indexedPageMap, this.handleIndexedPageMapUpdate);
31731
+ (0, import_forge_room13.removeObserver)(this.indexedPageMap, this.handleIndexedPageMapUpdate);
31292
31732
  this.pageModel.off("switchPage");
31293
31733
  this.pageModel.off("pagesChange");
31294
31734
  }
@@ -31509,7 +31949,7 @@ var SequenceExecutor = class {
31509
31949
  };
31510
31950
 
31511
31951
  // src/WhiteboardApplication.ts
31512
- var import_forge_room13 = require("@netless/forge-room");
31952
+ var import_forge_room15 = require("@netless/forge-room");
31513
31953
 
31514
31954
  // src/LiveCursor.ts
31515
31955
  function _defineProperty42(e, r, t) {
@@ -31564,9 +32004,19 @@ var LiveCursor = class {
31564
32004
  cursor.style.fontSize = "12px";
31565
32005
  cursor.style.padding = "2px 4px";
31566
32006
  cursor.style.borderRadius = "4px";
31567
- cursor.textContent = this.userManager.getUser(userId)?.nickName ?? userId;
32007
+ this.updateCursorLabel(userId, cursor);
31568
32008
  return cursor;
31569
32009
  }
32010
+ updateCursorLabel(userId, cursor) {
32011
+ const target = cursor ?? this.cursors.get(userId);
32012
+ if (!target) {
32013
+ return;
32014
+ }
32015
+ if (target.textContent && target.textContent !== userId) {
32016
+ return;
32017
+ }
32018
+ target.textContent = this.userManager.getUser(userId)?.nickName ?? userId;
32019
+ }
31570
32020
  isOnSamePage(userId) {
31571
32021
  const otherPage = this.requestUserMap(userId).get(WhiteboardKeys.currentPage);
31572
32022
  const selfPage = this.requestUserMap(this.userManager.selfId).get(WhiteboardKeys.currentPage);
@@ -31602,6 +32052,7 @@ var LiveCursor = class {
31602
32052
  }
31603
32053
  const cursor = this.cursors.get(userId);
31604
32054
  if (cursor) {
32055
+ this.updateCursorLabel(userId, cursor);
31605
32056
  const viewPoint = this.paperScope.project.view.projectToView(point);
31606
32057
  cursor.style.left = viewPoint.x + "px";
31607
32058
  cursor.style.top = viewPoint.y + "px";
@@ -31666,7 +32117,7 @@ var AsyncMap = class {
31666
32117
  if (!window.__forge_gl_wb_status__) {
31667
32118
  window.__forge_gl_wb_status__ = new AsyncMap();
31668
32119
  }
31669
- var WhiteboardApplication = class _WhiteboardApplication extends import_forge_room12.AbstractApplication {
32120
+ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_room14.AbstractApplication {
31670
32121
  get undoManager() {
31671
32122
  const page = this.pageModel.getCurrentPage(this.userId);
31672
32123
  if (page) {
@@ -31717,6 +32168,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
31717
32168
  _defineProperty43(this, "permissions", void 0);
31718
32169
  _defineProperty43(this, "inputType", "any");
31719
32170
  _defineProperty43(this, "isPenEvent", false);
32171
+ _defineProperty43(this, "activePenPointerId", null);
31720
32172
  _defineProperty43(this, "hasPenInput", null);
31721
32173
  _defineProperty43(this, "disableViewModelUpdate", false);
31722
32174
  _defineProperty43(this, "internalResizeObserver", true);
@@ -31812,7 +32264,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
31812
32264
  }
31813
32265
  } else {
31814
32266
  console.warn(`[@netless/forge-whiteboard] page ${pageId} not found`);
31815
- (0, import_forge_room12.log)(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warn");
32267
+ (0, import_forge_room14.log)(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warn");
31816
32268
  }
31817
32269
  await waitUntil(() => this.undoManagers.has(pageId), 1e3);
31818
32270
  if (this.undoManagers.has(pageId)) {
@@ -31824,7 +32276,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
31824
32276
  this.undoManagers.get(pageId).on("stack-item-popped", this.handleStackItemPopped);
31825
32277
  } else {
31826
32278
  console.warn(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`);
31827
- (0, import_forge_room12.log)(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warn");
32279
+ (0, import_forge_room14.log)(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warn");
31828
32280
  }
31829
32281
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
31830
32282
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
@@ -31833,6 +32285,9 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
31833
32285
  _defineProperty43(this, "hasPermission", (flag) => {
31834
32286
  return this.permissions.hasPermission(flag, this.userId);
31835
32287
  });
32288
+ _defineProperty43(this, "isPerformanceMode", () => {
32289
+ return this.option.performance ?? false;
32290
+ });
31836
32291
  _defineProperty43(this, "handleStackItemAdded", () => {
31837
32292
  this.selectElementsModel.clearSelectElementForSelf();
31838
32293
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
@@ -31847,7 +32302,18 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
31847
32302
  const id = ids[i];
31848
32303
  if (!this.layers.has(id)) {
31849
32304
  const elementsMap = this.getMap(`layer/${id}/elements`);
31850
- const renderableModel = new RenderableModel(id, this.shadowEmitter, elementsMap, this.paperScope, this.toolbarModel, this.userManager, this.imageSets, this.liveCursor, this.hasPermission);
32305
+ const renderableModel = new RenderableModel({
32306
+ layerId: id,
32307
+ shadowEmitter: this.shadowEmitter,
32308
+ elements: elementsMap,
32309
+ scope: this.paperScope,
32310
+ toolbarModel: this.toolbarModel,
32311
+ userManager: this.userManager,
32312
+ imageSets: this.imageSets,
32313
+ liveCursor: this.liveCursor,
32314
+ hasPermission: this.hasPermission,
32315
+ isPerformanceMode: this.isPerformanceMode
32316
+ });
31851
32317
  this.layers.set(id, renderableModel);
31852
32318
  }
31853
32319
  if (!this.undoManagers.has(id)) {
@@ -32031,11 +32497,34 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32031
32497
  this.imageSets.setAttribute("data-image-sets", "");
32032
32498
  this.rootElement.appendChild(this.imageSets);
32033
32499
  document.body.addEventListener("pointerdown", (evt) => {
32034
- this.isPenEvent = evt.pointerType === "pen";
32035
- if (evt.pointerType === "pen" && this.hasPenInput === null) {
32036
- this.hasPenInput = true;
32037
- this.inputType = "pen";
32038
- this.emitter.emit("inputTypeChange", this.inputType);
32500
+ if (evt.pointerType === "pen") {
32501
+ this.isPenEvent = true;
32502
+ this.activePenPointerId = evt.pointerId;
32503
+ if (this.hasPenInput === null) {
32504
+ this.hasPenInput = true;
32505
+ this.inputType = "pen";
32506
+ this.emitter.emit("inputTypeChange", this.inputType);
32507
+ }
32508
+ } else {
32509
+ if (this.activePenPointerId === null) {
32510
+ this.isPenEvent = false;
32511
+ }
32512
+ }
32513
+ }, {
32514
+ capture: true
32515
+ });
32516
+ document.body.addEventListener("pointerup", (evt) => {
32517
+ if (evt.pointerId === this.activePenPointerId) {
32518
+ this.activePenPointerId = null;
32519
+ this.isPenEvent = false;
32520
+ }
32521
+ }, {
32522
+ capture: true
32523
+ });
32524
+ document.body.addEventListener("pointercancel", (evt) => {
32525
+ if (evt.pointerId === this.activePenPointerId) {
32526
+ this.activePenPointerId = null;
32527
+ this.isPenEvent = false;
32039
32528
  }
32040
32529
  }, {
32041
32530
  capture: true
@@ -32091,7 +32580,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32091
32580
  this.emitter.setViewModeToFree = (userId) => {
32092
32581
  if (that.disableViewModelUpdate) {
32093
32582
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32094
- (0, import_forge_room12.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32583
+ (0, import_forge_room14.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32095
32584
  return;
32096
32585
  }
32097
32586
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32102,7 +32591,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32102
32591
  this.emitter.setViewModeToFlow = (flowId, userId) => {
32103
32592
  if (that.disableViewModelUpdate) {
32104
32593
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32105
- (0, import_forge_room12.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32594
+ (0, import_forge_room14.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32106
32595
  return;
32107
32596
  }
32108
32597
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32114,10 +32603,16 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32114
32603
  this.camera.resetViewMatrixToFlow(flowId);
32115
32604
  }
32116
32605
  };
32606
+ this.emitter.setPerformanceMode = (enabled) => {
32607
+ this.option.performance = enabled;
32608
+ };
32609
+ this.emitter.isPerformanceMode = () => {
32610
+ return this.isPerformanceMode();
32611
+ };
32117
32612
  this.emitter.setViewModeToMain = (userId) => {
32118
32613
  if (that.disableViewModelUpdate) {
32119
32614
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32120
- (0, import_forge_room12.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32615
+ (0, import_forge_room14.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32121
32616
  return;
32122
32617
  }
32123
32618
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32131,7 +32626,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32131
32626
  };
32132
32627
  this.emitter.insertImage = (src, pageId) => {
32133
32628
  if (!/https/.test(src)) {
32134
- (0, import_forge_room12.log)("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
32629
+ (0, import_forge_room14.log)("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
32135
32630
  src
32136
32631
  }, "warn");
32137
32632
  return;
@@ -32141,14 +32636,14 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32141
32636
  targetPageId = this.pageModel.getCurrentPage(this.userManager.selfId);
32142
32637
  }
32143
32638
  if (!targetPageId) {
32144
- (0, import_forge_room12.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32639
+ (0, import_forge_room14.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32145
32640
  return;
32146
32641
  }
32147
32642
  this.layers.get(targetPageId)?.createImage(src);
32148
32643
  };
32149
32644
  this.emitter.removeElement = (pageId, elementId) => {
32150
32645
  if (!this.layers.has(pageId)) {
32151
- (0, import_forge_room12.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32646
+ (0, import_forge_room14.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32152
32647
  return;
32153
32648
  }
32154
32649
  this.layers.get(pageId)?.removeElementItem(elementId);
@@ -32168,7 +32663,18 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32168
32663
  const source = this.getMap(`layer/${sourceId}/elements`);
32169
32664
  const target = this.getMap(`layer/${targetId}/elements`);
32170
32665
  if (!this.layers.has(targetId)) {
32171
- this.layers.set(targetId, new RenderableModel(targetId, this.shadowEmitter, target, this.paperScope, this.toolbarModel, this.userManager, this.imageSets, this.liveCursor, this.hasPermission));
32666
+ this.layers.set(targetId, new RenderableModel({
32667
+ layerId: targetId,
32668
+ shadowEmitter: this.shadowEmitter,
32669
+ elements: target,
32670
+ scope: this.paperScope,
32671
+ toolbarModel: this.toolbarModel,
32672
+ userManager: this.userManager,
32673
+ imageSets: this.imageSets,
32674
+ liveCursor: this.liveCursor,
32675
+ hasPermission: this.hasPermission,
32676
+ isPerformanceMode: this.isPerformanceMode
32677
+ }));
32172
32678
  }
32173
32679
  if (!this.undoManagers.has(targetId)) {
32174
32680
  const undoManager = new Y15.UndoManager(target, {
@@ -32237,15 +32743,15 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32237
32743
  this.liveCursor.showLiveCursor = value;
32238
32744
  };
32239
32745
  this.emitter.updateViewport = (width, height) => {
32240
- (0, import_forge_room12.log)(`call updateViewport with width: ${width}, height: ${height}`);
32746
+ (0, import_forge_room14.log)(`call updateViewport with width: ${width}, height: ${height}`);
32241
32747
  this.updateOptionSize(width, height);
32242
32748
  };
32243
32749
  this.emitter.__setMainCanvasVisible = (visible) => {
32244
- (0, import_forge_room12.log)(`call __setMainCanvasVisible with visible: ${visible}`);
32750
+ (0, import_forge_room14.log)(`call __setMainCanvasVisible with visible: ${visible}`);
32245
32751
  this.canvasElement.style.opacity = visible ? "1" : "0";
32246
32752
  };
32247
32753
  this.emitter.on("error", (errorCode, errorMessage) => {
32248
- (0, import_forge_room12.log)("WhiteboardApplicationError", {
32754
+ (0, import_forge_room14.log)("WhiteboardApplicationError", {
32249
32755
  errorCode,
32250
32756
  errorMessage
32251
32757
  });
@@ -32255,7 +32761,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32255
32761
  return that.delayTranslateOut;
32256
32762
  },
32257
32763
  set(value) {
32258
- (0, import_forge_room12.log)(`call __delayTranslateOut with value: ${value}`);
32764
+ (0, import_forge_room14.log)(`call __delayTranslateOut with value: ${value}`);
32259
32765
  that.delayTranslateOut = value;
32260
32766
  }
32261
32767
  });
@@ -32358,7 +32864,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32358
32864
  }
32359
32865
  async initialize(option) {
32360
32866
  _WhiteboardApplication.instanceCount.set(this.appId, (_WhiteboardApplication.instanceCount.get(this.appId) ?? 0) + 1);
32361
- (0, import_forge_room12.log)(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32867
+ (0, import_forge_room14.log)(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32362
32868
  this.appDoc.transact(() => {
32363
32869
  this.permissions = new WhiteboardPermissions(this.writableManager, this.userManager, (userId) => {
32364
32870
  return this.userMap(userId);
@@ -32403,6 +32909,11 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32403
32909
  this.editors.forEach((editor) => {
32404
32910
  editor.updateBounds();
32405
32911
  });
32912
+ const area = this.paperScope.project.view.size.width * this.paperScope.project.view.size.height;
32913
+ const minDistance = Math.ceil(area / 4e5);
32914
+ Object.keys(this.tools).forEach((key) => {
32915
+ this.tools[key].tool.minDistance = minDistance;
32916
+ });
32406
32917
  });
32407
32918
  this.camera.on("userPageChange", (userId, pageId) => {
32408
32919
  this.emitter.emit("activePageChange", userId, pageId);
@@ -32464,7 +32975,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32464
32975
  this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
32465
32976
  } else {
32466
32977
  this.paperScope.tool = this.tools["curve"].tool;
32467
- (0, import_forge_room12.log)(`${this.toolbarModel.currentTool} not supported, backup to curve`);
32978
+ (0, import_forge_room14.log)(`${this.toolbarModel.currentTool} not supported, backup to curve`);
32468
32979
  }
32469
32980
  this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
32470
32981
  this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
@@ -32671,9 +33182,14 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32671
33182
  this.snapshotScope.view.matrix.scale(scale, this.paperScope.project.view.bounds.topLeft);
32672
33183
  this.snapshotScope.view.viewSize = this.paperScope.project.view.viewSize.clone().multiply(scale);
32673
33184
  }
32674
- return new Promise((resolve) => {
33185
+ return new Promise((resolve, reject) => {
32675
33186
  setTimeout(() => {
32676
- resolve(this.snapshotScope.view.element.toDataURL("image/png"));
33187
+ try {
33188
+ const res = this.snapshotScope.view.element.toDataURL("image/png");
33189
+ resolve(res);
33190
+ } catch (error) {
33191
+ reject(error);
33192
+ }
32677
33193
  }, 32);
32678
33194
  });
32679
33195
  }
@@ -32751,8 +33267,8 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32751
33267
  this.toolbarModel.dispose();
32752
33268
  this.emitter.indexedNavigation.dispose();
32753
33269
  this.permissions.dispose();
32754
- (0, import_forge_room13.removeObserver)(this.userMap(this.userId), this.handleSyncedWhiteboardStatusChange);
32755
- (0, import_forge_room12.log)(`whiteboard ${this.appId} disposed. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
33270
+ (0, import_forge_room15.removeObserver)(this.userMap(this.userId), this.handleSyncedWhiteboardStatusChange);
33271
+ (0, import_forge_room14.log)(`whiteboard ${this.appId} disposed. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32756
33272
  }
32757
33273
  };
32758
33274
  _defineProperty43(WhiteboardApplication, "instanceCount", /* @__PURE__ */ new Map());