@netless/forge-whiteboard 1.1.3 → 1.1.5

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.
@@ -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_room13 = 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_room5 = 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);
@@ -25973,7 +25973,20 @@ var ElementModel = class _ElementModel {
25973
25973
  } else {
25974
25974
  this.root.set(_ElementModel.KEYS.pointsMatrix, [1, 0, 0, 1, 0, 0]);
25975
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;
25976
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() {
25977
25990
  }
25978
25991
  handlePointsChangeDirect() {
25979
25992
  this.onVectorUpdate();
@@ -26114,6 +26127,9 @@ var ElementModel = class _ElementModel {
26114
26127
  }
26115
26128
  dispose() {
26116
26129
  this.subDispose();
26130
+ }
26131
+ disposeObserver() {
26132
+ console.log(`[][][] disposeObserver uuid=${this.uuid}`);
26117
26133
  (0, import_forge_room.removeDeepObserver)(this.root, this.handlePropChange);
26118
26134
  }
26119
26135
  };
@@ -26224,14 +26240,33 @@ var CurveModel = class extends ElementModel {
26224
26240
  }
26225
26241
  });
26226
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
+ }
26227
26261
  matrixedPoints() {
26228
26262
  const points = this.localPoints.length === 0 ? this.points : this.localPoints;
26229
26263
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26230
26264
  const output = [];
26231
- for (let i = 0, len = points.length; i < len; i += 3) {
26265
+ const stride = this.pointStride(points);
26266
+ for (let i = 0, len = points.length; i + 1 < len; i += stride) {
26232
26267
  const p = new this.scope.Point(points[i], points[i + 1]);
26233
26268
  const tp = p.transform(matrix);
26234
- const pressure = points[i + 2] ?? 0;
26269
+ const pressure = stride === 3 ? points[i + 2] ?? 0 : 0;
26235
26270
  output.push([tp.x, tp.y, pressure]);
26236
26271
  }
26237
26272
  return output;
@@ -26307,11 +26342,13 @@ var CurveModel = class extends ElementModel {
26307
26342
  }
26308
26343
  liveCursorPoint() {
26309
26344
  const yArray = this.root.get(ElementModel.KEYS.points);
26310
- if (yArray.length < 3) {
26345
+ const points = yArray.toArray();
26346
+ const stride = this.pointStride(points);
26347
+ if (points.length < stride) {
26311
26348
  return null;
26312
26349
  }
26313
- const len = yArray.length;
26314
- const point = new this.scope.Point(yArray.get(len - 3), yArray.get(len - 2));
26350
+ const len = points.length;
26351
+ const point = new this.scope.Point(points[len - stride], points[len - stride + 1]);
26315
26352
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
26316
26353
  }
26317
26354
  onStyleKeyUpdate(key) {
@@ -27048,6 +27085,10 @@ var PointTextModel = class extends ElementModel {
27048
27085
  subDispose() {
27049
27086
  (0, import_forge_room3.removeObserver)(this.root, this.handleTextPropChange);
27050
27087
  }
27088
+ subBindObserver() {
27089
+ (0, import_forge_room3.removeObserver)(this.root, this.handleTextPropChange);
27090
+ this.root.observe(this.handleTextPropChange);
27091
+ }
27051
27092
  liveCursorPoint() {
27052
27093
  const points = this.points;
27053
27094
  if (points.length < 1) {
@@ -27590,6 +27631,7 @@ var EraserModel = class extends ElementModel {
27590
27631
  // src/model/renderable/LaserPointerModel.ts
27591
27632
  var Y10 = __toESM(require("yjs"), 1);
27592
27633
  var import_lodash5 = __toESM(require_lodash(), 1);
27634
+ var import_forge_room4 = require("@netless/forge-room");
27593
27635
  function _defineProperty14(e, r, t) {
27594
27636
  return (r = _toPropertyKey14(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27595
27637
  }
@@ -27618,17 +27660,8 @@ var LaserPointerModel = class extends ElementModel {
27618
27660
  _defineProperty14(this, "clearLocalPointsWhenYPointsChange", false);
27619
27661
  _defineProperty14(this, "shouldUseLocalPoints", false);
27620
27662
  _defineProperty14(this, "localPointsPick", 4);
27621
- this.clientId = clientId;
27622
- if (this.root.doc && !this.root.has("type")) {
27623
- this.root.set("type", "laser");
27624
- }
27625
- if (this.root.doc && !this.root.has("points")) {
27626
- this.root.set("points", new Y10.Array());
27627
- }
27628
- if (this.root.doc && !this.root.has("removed")) {
27629
- this.root.set("removed", false);
27630
- }
27631
- this.root.observe((event) => {
27663
+ _defineProperty14(this, "removeElement", void 0);
27664
+ _defineProperty14(this, "handleLaserPropChange", (event) => {
27632
27665
  if (!this.item) {
27633
27666
  return;
27634
27667
  }
@@ -27646,13 +27679,31 @@ var LaserPointerModel = class extends ElementModel {
27646
27679
  this.onVectorUpdate();
27647
27680
  if (evt.count >= 30) {
27648
27681
  if (this.ownerId === this.clientId) {
27649
- removeElement(this.uuid);
27682
+ this.removeElement(this.uuid);
27650
27683
  }
27651
27684
  }
27652
27685
  };
27653
27686
  }
27654
27687
  }
27655
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);
27656
27707
  }
27657
27708
  beginRemoveAnimate() {
27658
27709
  this.root.set("removed", true);
@@ -27748,8 +27799,6 @@ var LaserPointerModel = class extends ElementModel {
27748
27799
  onStyleKeyUpdate(_key) {
27749
27800
  return;
27750
27801
  }
27751
- subDispose() {
27752
- }
27753
27802
  liveCursorPoint() {
27754
27803
  const yArray = this.root.get(ElementModel.KEYS.points);
27755
27804
  if (yArray.length < 2) {
@@ -27762,7 +27811,7 @@ var LaserPointerModel = class extends ElementModel {
27762
27811
  };
27763
27812
 
27764
27813
  // src/WhitePermissions.ts
27765
- var import_forge_room4 = require("@netless/forge-room");
27814
+ var import_forge_room5 = require("@netless/forge-room");
27766
27815
  var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
27767
27816
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["none"] = 0] = "none";
27768
27817
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["draw"] = 1] = "draw";
@@ -27775,7 +27824,7 @@ var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
27775
27824
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["all"] = WhiteboardPermissionFlag2.draw | WhiteboardPermissionFlag2.editSelf | WhiteboardPermissionFlag2.editOthers | WhiteboardPermissionFlag2.deleteSelf | WhiteboardPermissionFlag2.deleteOthers | WhiteboardPermissionFlag2.mainView | WhiteboardPermissionFlag2.setOthersView] = "all";
27776
27825
  return WhiteboardPermissionFlag2;
27777
27826
  }({});
27778
- var WhiteboardPermissions = class extends import_forge_room4.AbstractApplicationPermissions {
27827
+ var WhiteboardPermissions = class extends import_forge_room5.AbstractApplicationPermissions {
27779
27828
  /**
27780
27829
  * 解析权限列表组合
27781
27830
  * @param {number} value - 权限数字值
@@ -28110,6 +28159,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28110
28159
  const existingModel = this.elementModels.get(uuid);
28111
28160
  if (existingModel) {
28112
28161
  existingModel.shadowEmitter = this.shadowEmitter;
28162
+ existingModel.bindObserver();
28113
28163
  return existingModel;
28114
28164
  }
28115
28165
  }
@@ -28140,6 +28190,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28140
28190
  }
28141
28191
  if (model) {
28142
28192
  model.shadowEmitter = this.shadowEmitter;
28193
+ model.bindObserver();
28143
28194
  this.elementModels.set(model.uuid, model);
28144
28195
  }
28145
28196
  return model;
@@ -28153,7 +28204,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28153
28204
  confirmPermission() {
28154
28205
  const hasPermission = this.hasPermission(WhiteboardPermissionFlag.draw);
28155
28206
  if (!hasPermission) {
28156
- (0, import_forge_room5.log)("[@netless/forge-whiteboard] no permission to draw", {}, "warn");
28207
+ (0, import_forge_room6.log)("[@netless/forge-whiteboard] no permission to draw", {}, "warn");
28157
28208
  }
28158
28209
  return hasPermission;
28159
28210
  }
@@ -28171,6 +28222,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28171
28222
  this.elements.set(uuid, yMap);
28172
28223
  }, elementsUndoOrigin);
28173
28224
  const model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor, this.isPerformanceMode);
28225
+ model.bindObserver();
28174
28226
  model.root.set("src", src);
28175
28227
  const initMatrix = new this.scope.Matrix();
28176
28228
  const center = this.scope.project.view.center;
@@ -28203,6 +28255,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28203
28255
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28204
28256
  this.elements.set(uuid, yMap);
28205
28257
  }, elementsUndoOrigin);
28258
+ curveModel.bindObserver();
28206
28259
  this.initElement(curveModel);
28207
28260
  return curveModel;
28208
28261
  }
@@ -28229,6 +28282,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28229
28282
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28230
28283
  this.elements.set(uuid, yMap);
28231
28284
  }, elementsUndoOrigin);
28285
+ model.bindObserver();
28232
28286
  this.initElement(model);
28233
28287
  return model;
28234
28288
  }
@@ -28252,6 +28306,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28252
28306
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28253
28307
  this.elements.set(uuid, yMap);
28254
28308
  }, elementsUndoOrigin);
28309
+ model.bindObserver();
28255
28310
  return model;
28256
28311
  }
28257
28312
  createTriangle(shadow) {
@@ -28276,6 +28331,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28276
28331
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28277
28332
  this.elements.set(uuid, yMap);
28278
28333
  }, elementsUndoOrigin);
28334
+ triangleModel.bindObserver();
28279
28335
  this.initElement(triangleModel);
28280
28336
  triangleModel.dashArray = this.toolbarModel.dashArray;
28281
28337
  return triangleModel;
@@ -28305,6 +28361,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28305
28361
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28306
28362
  this.elements.set(uuid, yMap);
28307
28363
  }, elementsUndoOrigin);
28364
+ rect.bindObserver();
28308
28365
  this.initElement(rect);
28309
28366
  rect.dashArray = this.toolbarModel.dashArray;
28310
28367
  return rect;
@@ -28331,6 +28388,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28331
28388
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28332
28389
  this.elements.set(uuid, yMap);
28333
28390
  }, elementsUndoOrigin);
28391
+ segmentsModel.bindObserver();
28334
28392
  this.initElement(segmentsModel);
28335
28393
  segmentsModel.dashArray = this.toolbarModel.dashArray;
28336
28394
  return segmentsModel;
@@ -28355,6 +28413,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28355
28413
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28356
28414
  this.elements.set(uuid, yMap);
28357
28415
  }, elementsUndoOrigin);
28416
+ selectorModel.bindObserver();
28358
28417
  selectorModel.shadow = "layer";
28359
28418
  return selectorModel;
28360
28419
  }
@@ -28380,6 +28439,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28380
28439
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28381
28440
  this.elements.set(uuid, yMap);
28382
28441
  }, elementsUndoOrigin);
28442
+ straightLineModel.bindObserver();
28383
28443
  this.initElement(straightLineModel);
28384
28444
  straightLineModel.dashArray = this.toolbarModel.dashArray;
28385
28445
  return straightLineModel;
@@ -28408,6 +28468,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28408
28468
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28409
28469
  this.elements.set(uuid, yMap);
28410
28470
  }, elementsUndoOrigin);
28471
+ lineModel.bindObserver();
28411
28472
  this.initElement(lineModel);
28412
28473
  lineModel.dashArray = this.toolbarModel.dashArray;
28413
28474
  return lineModel;
@@ -28434,6 +28495,7 @@ var RenderableModel = class extends import_eventemitter3.default {
28434
28495
  yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
28435
28496
  this.elements.set(uuid, yMap);
28436
28497
  }, elementsUndoOrigin);
28498
+ pointTextModel.bindObserver();
28437
28499
  pointTextModel.setPoints([x, y]);
28438
28500
  pointTextModel.fontSize = this.toolbarModel.fontSize;
28439
28501
  pointTextModel.fontFamily = this.toolbarModel.fontFamily;
@@ -28456,12 +28518,13 @@ var RenderableModel = class extends import_eventemitter3.default {
28456
28518
  });
28457
28519
  }
28458
28520
  dispose(clearElements) {
28459
- (0, import_forge_room5.removeObserver)(this.elements, this.onElementsChange);
28521
+ (0, import_forge_room6.removeObserver)(this.elements, this.onElementsChange);
28460
28522
  if (clearElements) {
28461
28523
  this.elements.clear();
28462
28524
  }
28463
28525
  Array.from(this.elementModels.values()).forEach((model) => {
28464
28526
  model.dispose();
28527
+ model.disposeObserver();
28465
28528
  });
28466
28529
  }
28467
28530
  };
@@ -28922,7 +28985,7 @@ var RectangleTool = class extends WhiteboardTool {
28922
28985
 
28923
28986
  // src/model/ToolbarModel.ts
28924
28987
  var import_eventemitter32 = __toESM(require("eventemitter3"), 1);
28925
- var import_forge_room6 = require("@netless/forge-room");
28988
+ var import_forge_room7 = require("@netless/forge-room");
28926
28989
  function _defineProperty21(e, r, t) {
28927
28990
  return (r = _toPropertyKey21(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
28928
28991
  }
@@ -29019,7 +29082,7 @@ var ToolbarModel = class extends import_eventemitter32.default {
29019
29082
  });
29020
29083
  }
29021
29084
  dispose() {
29022
- (0, import_forge_room6.removeObserver)(this.root, this.handleRootUpdate);
29085
+ (0, import_forge_room7.removeObserver)(this.root, this.handleRootUpdate);
29023
29086
  this.removeAllListeners();
29024
29087
  }
29025
29088
  };
@@ -29118,7 +29181,7 @@ var SelectorTool = class extends WhiteboardTool {
29118
29181
  // src/model/SelectElementsModel.ts
29119
29182
  var Y13 = __toESM(require("yjs"), 1);
29120
29183
  var import_eventemitter33 = __toESM(require("eventemitter3"), 1);
29121
- var import_forge_room7 = require("@netless/forge-room");
29184
+ var import_forge_room8 = require("@netless/forge-room");
29122
29185
 
29123
29186
  // src/WhiteboardKeys.ts
29124
29187
  var WhiteboardKeys = {
@@ -29168,7 +29231,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
29168
29231
  }
29169
29232
  const cb = this.observers.get(user.id);
29170
29233
  if (cb) {
29171
- (0, import_forge_room7.removeDeepObserver)(this.requestUserMap(user.id), cb);
29234
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), cb);
29172
29235
  this.observers.delete(user.id);
29173
29236
  }
29174
29237
  });
@@ -29177,7 +29240,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
29177
29240
  this.handleUserSelectElementsChange(user.id, evts);
29178
29241
  };
29179
29242
  if (this.observers.has(user.id)) {
29180
- (0, import_forge_room7.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
29243
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
29181
29244
  this.observers.delete(user.id);
29182
29245
  }
29183
29246
  this.requestUserMap(user.id).observeDeep(observer);
@@ -29200,7 +29263,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
29200
29263
  this.handleUserSelectElementsChange(userId, evts);
29201
29264
  };
29202
29265
  if (this.observers.has(userId)) {
29203
- (0, import_forge_room7.removeDeepObserver)(this.requestUserMap(userId), this.observers.get(userId));
29266
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(userId), this.observers.get(userId));
29204
29267
  }
29205
29268
  this.requestUserMap(userId).observeDeep(observer);
29206
29269
  this.observers.set(userId, observer);
@@ -29264,7 +29327,7 @@ var SelectElementsModel = class extends import_eventemitter33.default {
29264
29327
  }
29265
29328
  dispose() {
29266
29329
  for (const [key, value] of this.observers.entries()) {
29267
- (0, import_forge_room7.removeDeepObserver)(this.requestUserMap(key), value);
29330
+ (0, import_forge_room8.removeDeepObserver)(this.requestUserMap(key), value);
29268
29331
  }
29269
29332
  this.observers.clear();
29270
29333
  this.userManager.off("leave", this.handleUserLeave);
@@ -29953,6 +30016,7 @@ var Editor = class extends import_eventemitter35.default {
29953
30016
  this.shadowContainer.remove();
29954
30017
  this.shadowScope.project.activeLayer.addChild(this.shadowContainer);
29955
30018
  this.targets.forEach((model) => {
30019
+ console.log("[][][] translateShadow model", model.root._dEH);
29956
30020
  model.shadow = this.shadowContainer.data.uuid;
29957
30021
  });
29958
30022
  }
@@ -30179,7 +30243,7 @@ var Gesture = class extends import_eventemitter36.default {
30179
30243
  };
30180
30244
 
30181
30245
  // src/Camera.ts
30182
- var import_forge_room8 = require("@netless/forge-room");
30246
+ var import_forge_room9 = require("@netless/forge-room");
30183
30247
  function _defineProperty28(e, r, t) {
30184
30248
  return (r = _toPropertyKey28(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30185
30249
  }
@@ -30256,14 +30320,14 @@ var Camera = class extends import_eventemitter37.default {
30256
30320
  }
30257
30321
  const cb = this.observers.get(user.id);
30258
30322
  if (cb) {
30259
- (0, import_forge_room8.removeObserver)(this.requestUserMap(user.id), cb);
30323
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(user.id), cb);
30260
30324
  }
30261
30325
  });
30262
30326
  _defineProperty28(this, "handleUserJoin", (user) => {
30263
30327
  if (this.observers.has(user.id)) {
30264
30328
  const cb = this.observers.get(user.id);
30265
30329
  if (cb) {
30266
- (0, import_forge_room8.removeObserver)(this.requestUserMap(user.id), cb);
30330
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(user.id), cb);
30267
30331
  this.observers.delete(user.id);
30268
30332
  }
30269
30333
  }
@@ -30375,7 +30439,7 @@ var Camera = class extends import_eventemitter37.default {
30375
30439
  this.handleViewMatrixUpdate(userId, evt);
30376
30440
  };
30377
30441
  if (this.observers.has(userId)) {
30378
- (0, import_forge_room8.removeObserver)(this.requestUserMap(userId), observer);
30442
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), observer);
30379
30443
  }
30380
30444
  this.requestUserMap(userId).observe(observer);
30381
30445
  this.observers.set(userId, observer);
@@ -30572,10 +30636,10 @@ var Camera = class extends import_eventemitter37.default {
30572
30636
  Array.from(this.observers.keys()).forEach((userId) => {
30573
30637
  const cb = this.observers.get(userId);
30574
30638
  if (cb) {
30575
- (0, import_forge_room8.removeObserver)(this.requestUserMap(userId), cb);
30639
+ (0, import_forge_room9.removeObserver)(this.requestUserMap(userId), cb);
30576
30640
  }
30577
30641
  });
30578
- (0, import_forge_room8.removeObserver)(this.whiteboardAttrsMap, this.handleMainCameraChange);
30642
+ (0, import_forge_room9.removeObserver)(this.whiteboardAttrsMap, this.handleMainCameraChange);
30579
30643
  this.userManager.off("join", this.handleUserJoin);
30580
30644
  this.userManager.off("leave", this.handleUserLeave);
30581
30645
  this.gesture.removeAllListeners();
@@ -30868,7 +30932,7 @@ var EraserTool = class extends WhiteboardTool {
30868
30932
  // src/model/TrashedElementsModel.ts
30869
30933
  var Y14 = __toESM(require("yjs"), 1);
30870
30934
  var import_eventemitter39 = __toESM(require("eventemitter3"), 1);
30871
- var import_forge_room9 = require("@netless/forge-room");
30935
+ var import_forge_room10 = require("@netless/forge-room");
30872
30936
  function _defineProperty33(e, r, t) {
30873
30937
  return (r = _toPropertyKey33(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30874
30938
  }
@@ -30905,14 +30969,14 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30905
30969
  }
30906
30970
  const cb = this.observers.get(user.id);
30907
30971
  if (cb) {
30908
- (0, import_forge_room9.removeDeepObserver)(this.requestUserMap(user.id), cb);
30972
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(user.id), cb);
30909
30973
  }
30910
30974
  });
30911
30975
  _defineProperty33(this, "handleUserJoin", (user) => {
30912
30976
  if (this.observers.has(user.id)) {
30913
30977
  const cb = this.observers.get(user.id);
30914
30978
  if (cb) {
30915
- (0, import_forge_room9.removeDeepObserver)(this.requestUserMap(user.id), cb);
30979
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(user.id), cb);
30916
30980
  this.observers.delete(user.id);
30917
30981
  }
30918
30982
  }
@@ -30920,7 +30984,7 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30920
30984
  this.handleUserTrashElementsChange(user.id, evts);
30921
30985
  };
30922
30986
  if (this.observers.has(user.id)) {
30923
- (0, import_forge_room9.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
30987
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(user.id), this.observers.get(user.id));
30924
30988
  }
30925
30989
  this.requestUserMap(user.id).observeDeep(observer);
30926
30990
  this.observers.set(user.id, observer);
@@ -30934,7 +30998,7 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30934
30998
  this.handleUserTrashElementsChange(userId, evts);
30935
30999
  };
30936
31000
  if (this.observers.has(userId)) {
30937
- (0, import_forge_room9.removeDeepObserver)(this.requestUserMap(userId), userId);
31001
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(userId), userId);
30938
31002
  }
30939
31003
  this.requestUserMap(userId).observeDeep(observer);
30940
31004
  this.observers.set(userId, observer);
@@ -30996,7 +31060,7 @@ var TrashedElementsModel = class extends import_eventemitter39.default {
30996
31060
  }
30997
31061
  dispose() {
30998
31062
  for (const [key, value] of this.observers.entries()) {
30999
- (0, import_forge_room9.removeDeepObserver)(this.requestUserMap(key), value);
31063
+ (0, import_forge_room10.removeDeepObserver)(this.requestUserMap(key), value);
31000
31064
  }
31001
31065
  this.observers.clear();
31002
31066
  this.userManager.off("leave", this.handleUserLeave);
@@ -31075,7 +31139,7 @@ var LaserPointerTool = class extends WhiteboardTool {
31075
31139
 
31076
31140
  // src/model/PageModel.ts
31077
31141
  var import_eventemitter310 = __toESM(require("eventemitter3"), 1);
31078
- var import_forge_room10 = require("@netless/forge-room");
31142
+ var import_forge_room11 = require("@netless/forge-room");
31079
31143
  function _defineProperty35(e, r, t) {
31080
31144
  return (r = _toPropertyKey35(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
31081
31145
  }
@@ -31108,7 +31172,7 @@ var PageModel = class extends import_eventemitter310.default {
31108
31172
  }
31109
31173
  const cb = this.observers.get(user.id);
31110
31174
  if (cb) {
31111
- (0, import_forge_room10.removeObserver)(this.requestUserMap(user.id), cb);
31175
+ (0, import_forge_room11.removeObserver)(this.requestUserMap(user.id), cb);
31112
31176
  }
31113
31177
  });
31114
31178
  _defineProperty35(this, "handleUserJoin", (user) => {
@@ -31122,7 +31186,7 @@ var PageModel = class extends import_eventemitter310.default {
31122
31186
  if (cameraMode === "main") {
31123
31187
  const targetPage = this.whiteboardAttrsMap.get(WhiteboardKeys.currentPage);
31124
31188
  if (!this.pageMap.has(targetPage) && targetPage !== "_i_") {
31125
- (0, import_forge_room10.log)(`main page {${targetPage}} not found.`, {}, "error");
31189
+ (0, import_forge_room11.log)(`main page {${targetPage}} not found.`, {}, "error");
31126
31190
  return;
31127
31191
  }
31128
31192
  this.requestUserMap(this.userManager.selfId).set(WhiteboardKeys.currentPage, targetPage);
@@ -31169,7 +31233,7 @@ var PageModel = class extends import_eventemitter310.default {
31169
31233
  if (this.observers.has(userId)) {
31170
31234
  const cb = this.observers.get(userId);
31171
31235
  if (cb) {
31172
- (0, import_forge_room10.removeObserver)(this.requestUserMap(userId), cb);
31236
+ (0, import_forge_room11.removeObserver)(this.requestUserMap(userId), cb);
31173
31237
  this.observers.delete(userId);
31174
31238
  }
31175
31239
  }
@@ -31258,12 +31322,12 @@ var PageModel = class extends import_eventemitter310.default {
31258
31322
  dispose() {
31259
31323
  for (const entry of this.observers.entries()) {
31260
31324
  const [userId, observer] = entry;
31261
- (0, import_forge_room10.removeObserver)(this.requestUserMap(userId), observer);
31325
+ (0, import_forge_room11.removeObserver)(this.requestUserMap(userId), observer);
31262
31326
  }
31263
31327
  this.userManager.off("join", this.handleUserJoin);
31264
31328
  this.userManager.off("leave", this.handleUserLeave);
31265
- (0, import_forge_room10.removeObserver)(this.whiteboardAttrsMap, this.handleMainPageChange);
31266
- (0, import_forge_room10.removeObserver)(this.pageMap, this.handlePageMapChange);
31329
+ (0, import_forge_room11.removeObserver)(this.whiteboardAttrsMap, this.handleMainPageChange);
31330
+ (0, import_forge_room11.removeObserver)(this.pageMap, this.handlePageMapChange);
31267
31331
  }
31268
31332
  };
31269
31333
 
@@ -31278,8 +31342,8 @@ async function waitUntil(fn, timeout) {
31278
31342
 
31279
31343
  // src/IndexedNavigation.ts
31280
31344
  var import_eventemitter311 = __toESM(require("eventemitter3"), 1);
31281
- var import_forge_room11 = require("@netless/forge-room");
31282
31345
  var import_forge_room12 = require("@netless/forge-room");
31346
+ var import_forge_room13 = require("@netless/forge-room");
31283
31347
  function _defineProperty36(e, r, t) {
31284
31348
  return (r = _toPropertyKey36(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
31285
31349
  }
@@ -31306,7 +31370,7 @@ var IndexedNavigation = class extends import_eventemitter311.default {
31306
31370
  return this.list[key] && this.list[key].prev === "";
31307
31371
  });
31308
31372
  if (!headId) {
31309
- (0, import_forge_room11.log)("indexed navigation confusion", {
31373
+ (0, import_forge_room12.log)("indexed navigation confusion", {
31310
31374
  list: JSON.stringify(this.list)
31311
31375
  }, "error");
31312
31376
  throw new Error("indexed navigation confusion");
@@ -31622,7 +31686,7 @@ var IndexedNavigation = class extends import_eventemitter311.default {
31622
31686
  }
31623
31687
  }
31624
31688
  dispose() {
31625
- (0, import_forge_room12.removeObserver)(this.indexedPageMap, this.handleIndexedPageMapUpdate);
31689
+ (0, import_forge_room13.removeObserver)(this.indexedPageMap, this.handleIndexedPageMapUpdate);
31626
31690
  this.pageModel.off("switchPage");
31627
31691
  this.pageModel.off("pagesChange");
31628
31692
  }
@@ -31843,7 +31907,7 @@ var SequenceExecutor = class {
31843
31907
  };
31844
31908
 
31845
31909
  // src/WhiteboardApplication.ts
31846
- var import_forge_room14 = require("@netless/forge-room");
31910
+ var import_forge_room15 = require("@netless/forge-room");
31847
31911
 
31848
31912
  // src/LiveCursor.ts
31849
31913
  function _defineProperty42(e, r, t) {
@@ -31898,9 +31962,19 @@ var LiveCursor = class {
31898
31962
  cursor.style.fontSize = "12px";
31899
31963
  cursor.style.padding = "2px 4px";
31900
31964
  cursor.style.borderRadius = "4px";
31901
- cursor.textContent = this.userManager.getUser(userId)?.nickName ?? userId;
31965
+ this.updateCursorLabel(userId, cursor);
31902
31966
  return cursor;
31903
31967
  }
31968
+ updateCursorLabel(userId, cursor) {
31969
+ const target = cursor ?? this.cursors.get(userId);
31970
+ if (!target) {
31971
+ return;
31972
+ }
31973
+ if (target.textContent && target.textContent !== userId) {
31974
+ return;
31975
+ }
31976
+ target.textContent = this.userManager.getUser(userId)?.nickName ?? userId;
31977
+ }
31904
31978
  isOnSamePage(userId) {
31905
31979
  const otherPage = this.requestUserMap(userId).get(WhiteboardKeys.currentPage);
31906
31980
  const selfPage = this.requestUserMap(this.userManager.selfId).get(WhiteboardKeys.currentPage);
@@ -31936,6 +32010,7 @@ var LiveCursor = class {
31936
32010
  }
31937
32011
  const cursor = this.cursors.get(userId);
31938
32012
  if (cursor) {
32013
+ this.updateCursorLabel(userId, cursor);
31939
32014
  const viewPoint = this.paperScope.project.view.projectToView(point);
31940
32015
  cursor.style.left = viewPoint.x + "px";
31941
32016
  cursor.style.top = viewPoint.y + "px";
@@ -32000,7 +32075,7 @@ var AsyncMap = class {
32000
32075
  if (!window.__forge_gl_wb_status__) {
32001
32076
  window.__forge_gl_wb_status__ = new AsyncMap();
32002
32077
  }
32003
- var WhiteboardApplication = class _WhiteboardApplication extends import_forge_room13.AbstractApplication {
32078
+ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_room14.AbstractApplication {
32004
32079
  get undoManager() {
32005
32080
  const page = this.pageModel.getCurrentPage(this.userId);
32006
32081
  if (page) {
@@ -32147,7 +32222,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32147
32222
  }
32148
32223
  } else {
32149
32224
  console.warn(`[@netless/forge-whiteboard] page ${pageId} not found`);
32150
- (0, import_forge_room13.log)(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warn");
32225
+ (0, import_forge_room14.log)(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warn");
32151
32226
  }
32152
32227
  await waitUntil(() => this.undoManagers.has(pageId), 1e3);
32153
32228
  if (this.undoManagers.has(pageId)) {
@@ -32159,7 +32234,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32159
32234
  this.undoManagers.get(pageId).on("stack-item-popped", this.handleStackItemPopped);
32160
32235
  } else {
32161
32236
  console.warn(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`);
32162
- (0, import_forge_room13.log)(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warn");
32237
+ (0, import_forge_room14.log)(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warn");
32163
32238
  }
32164
32239
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
32165
32240
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
@@ -32463,7 +32538,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32463
32538
  this.emitter.setViewModeToFree = (userId) => {
32464
32539
  if (that.disableViewModelUpdate) {
32465
32540
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32466
- (0, import_forge_room13.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32541
+ (0, import_forge_room14.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32467
32542
  return;
32468
32543
  }
32469
32544
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32474,7 +32549,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32474
32549
  this.emitter.setViewModeToFlow = (flowId, userId) => {
32475
32550
  if (that.disableViewModelUpdate) {
32476
32551
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32477
- (0, import_forge_room13.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32552
+ (0, import_forge_room14.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32478
32553
  return;
32479
32554
  }
32480
32555
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32495,7 +32570,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32495
32570
  this.emitter.setViewModeToMain = (userId) => {
32496
32571
  if (that.disableViewModelUpdate) {
32497
32572
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32498
- (0, import_forge_room13.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32573
+ (0, import_forge_room14.log)("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32499
32574
  return;
32500
32575
  }
32501
32576
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32509,7 +32584,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32509
32584
  };
32510
32585
  this.emitter.insertImage = (src, pageId) => {
32511
32586
  if (!/https/.test(src)) {
32512
- (0, import_forge_room13.log)("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
32587
+ (0, import_forge_room14.log)("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
32513
32588
  src
32514
32589
  }, "warn");
32515
32590
  return;
@@ -32519,14 +32594,14 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32519
32594
  targetPageId = this.pageModel.getCurrentPage(this.userManager.selfId);
32520
32595
  }
32521
32596
  if (!targetPageId) {
32522
- (0, import_forge_room13.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32597
+ (0, import_forge_room14.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32523
32598
  return;
32524
32599
  }
32525
32600
  this.layers.get(targetPageId)?.createImage(src);
32526
32601
  };
32527
32602
  this.emitter.removeElement = (pageId, elementId) => {
32528
32603
  if (!this.layers.has(pageId)) {
32529
- (0, import_forge_room13.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32604
+ (0, import_forge_room14.log)("[@netless/forge-whiteboard] page not found", {}, "warn");
32530
32605
  return;
32531
32606
  }
32532
32607
  this.layers.get(pageId)?.removeElementItem(elementId);
@@ -32626,15 +32701,15 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32626
32701
  this.liveCursor.showLiveCursor = value;
32627
32702
  };
32628
32703
  this.emitter.updateViewport = (width, height) => {
32629
- (0, import_forge_room13.log)(`call updateViewport with width: ${width}, height: ${height}`);
32704
+ (0, import_forge_room14.log)(`call updateViewport with width: ${width}, height: ${height}`);
32630
32705
  this.updateOptionSize(width, height);
32631
32706
  };
32632
32707
  this.emitter.__setMainCanvasVisible = (visible) => {
32633
- (0, import_forge_room13.log)(`call __setMainCanvasVisible with visible: ${visible}`);
32708
+ (0, import_forge_room14.log)(`call __setMainCanvasVisible with visible: ${visible}`);
32634
32709
  this.canvasElement.style.opacity = visible ? "1" : "0";
32635
32710
  };
32636
32711
  this.emitter.on("error", (errorCode, errorMessage) => {
32637
- (0, import_forge_room13.log)("WhiteboardApplicationError", {
32712
+ (0, import_forge_room14.log)("WhiteboardApplicationError", {
32638
32713
  errorCode,
32639
32714
  errorMessage
32640
32715
  });
@@ -32644,7 +32719,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32644
32719
  return that.delayTranslateOut;
32645
32720
  },
32646
32721
  set(value) {
32647
- (0, import_forge_room13.log)(`call __delayTranslateOut with value: ${value}`);
32722
+ (0, import_forge_room14.log)(`call __delayTranslateOut with value: ${value}`);
32648
32723
  that.delayTranslateOut = value;
32649
32724
  }
32650
32725
  });
@@ -32747,7 +32822,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32747
32822
  }
32748
32823
  async initialize(option) {
32749
32824
  _WhiteboardApplication.instanceCount.set(this.appId, (_WhiteboardApplication.instanceCount.get(this.appId) ?? 0) + 1);
32750
- (0, import_forge_room13.log)(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32825
+ (0, import_forge_room14.log)(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32751
32826
  this.appDoc.transact(() => {
32752
32827
  this.permissions = new WhiteboardPermissions(this.writableManager, this.userManager, (userId) => {
32753
32828
  return this.userMap(userId);
@@ -32858,7 +32933,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
32858
32933
  this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
32859
32934
  } else {
32860
32935
  this.paperScope.tool = this.tools["curve"].tool;
32861
- (0, import_forge_room13.log)(`${this.toolbarModel.currentTool} not supported, backup to curve`);
32936
+ (0, import_forge_room14.log)(`${this.toolbarModel.currentTool} not supported, backup to curve`);
32862
32937
  }
32863
32938
  this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
32864
32939
  this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
@@ -33145,8 +33220,8 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
33145
33220
  this.toolbarModel.dispose();
33146
33221
  this.emitter.indexedNavigation.dispose();
33147
33222
  this.permissions.dispose();
33148
- (0, import_forge_room14.removeObserver)(this.userMap(this.userId), this.handleSyncedWhiteboardStatusChange);
33149
- (0, import_forge_room13.log)(`whiteboard ${this.appId} disposed. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
33223
+ (0, import_forge_room15.removeObserver)(this.userMap(this.userId), this.handleSyncedWhiteboardStatusChange);
33224
+ (0, import_forge_room14.log)(`whiteboard ${this.appId} disposed. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
33150
33225
  }
33151
33226
  };
33152
33227
  _defineProperty43(WhiteboardApplication, "instanceCount", /* @__PURE__ */ new Map());