@netless/forge-whiteboard 0.1.15 → 0.1.17

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 (78) hide show
  1. package/README.md +15 -6
  2. package/changelog.md +11 -1
  3. package/dist/Camera.d.ts.map +1 -1
  4. package/dist/IndexedNavigation.d.ts +1 -0
  5. package/dist/IndexedNavigation.d.ts.map +1 -1
  6. package/dist/LiveCursor.d.ts +20 -0
  7. package/dist/LiveCursor.d.ts.map +1 -0
  8. package/dist/WhitePermissions.d.ts +3 -43
  9. package/dist/WhitePermissions.d.ts.map +1 -1
  10. package/dist/Whiteboard.d.ts +18 -2
  11. package/dist/Whiteboard.d.ts.map +1 -1
  12. package/dist/WhiteboardApplication.d.ts +8 -0
  13. package/dist/WhiteboardApplication.d.ts.map +1 -1
  14. package/dist/model/PageModel.d.ts.map +1 -1
  15. package/dist/model/RenderableModel.d.ts +6 -2
  16. package/dist/model/RenderableModel.d.ts.map +1 -1
  17. package/dist/model/SelectElementsModel.d.ts +1 -1
  18. package/dist/model/SelectElementsModel.d.ts.map +1 -1
  19. package/dist/model/ToolbarModel.d.ts.map +1 -1
  20. package/dist/model/TrashedElementsModel.d.ts +1 -1
  21. package/dist/model/TrashedElementsModel.d.ts.map +1 -1
  22. package/dist/model/renderable/CurveModel.d.ts +6 -2
  23. package/dist/model/renderable/CurveModel.d.ts.map +1 -1
  24. package/dist/model/renderable/CurveModel_old.d.ts +28 -0
  25. package/dist/model/renderable/CurveModel_old.d.ts.map +1 -0
  26. package/dist/model/renderable/ElementModel.d.ts +4 -1
  27. package/dist/model/renderable/ElementModel.d.ts.map +1 -1
  28. package/dist/model/renderable/EraserModel.d.ts +3 -2
  29. package/dist/model/renderable/EraserModel.d.ts.map +1 -1
  30. package/dist/model/renderable/ImageModel.d.ts +22 -0
  31. package/dist/model/renderable/ImageModel.d.ts.map +1 -0
  32. package/dist/model/renderable/LaserPointerModel.d.ts +3 -1
  33. package/dist/model/renderable/LaserPointerModel.d.ts.map +1 -1
  34. package/dist/model/renderable/LineModel.d.ts +3 -1
  35. package/dist/model/renderable/LineModel.d.ts.map +1 -1
  36. package/dist/model/renderable/PointTextModel.d.ts +3 -1
  37. package/dist/model/renderable/PointTextModel.d.ts.map +1 -1
  38. package/dist/model/renderable/RectangleModel.d.ts +3 -1
  39. package/dist/model/renderable/RectangleModel.d.ts.map +1 -1
  40. package/dist/model/renderable/SegmentsModel.d.ts +3 -1
  41. package/dist/model/renderable/SegmentsModel.d.ts.map +1 -1
  42. package/dist/model/renderable/SelectorModel.d.ts +3 -1
  43. package/dist/model/renderable/SelectorModel.d.ts.map +1 -1
  44. package/dist/model/renderable/StraightLineModel.d.ts +3 -1
  45. package/dist/model/renderable/StraightLineModel.d.ts.map +1 -1
  46. package/dist/model/renderable/TriangleModel.d.ts +3 -1
  47. package/dist/model/renderable/TriangleModel.d.ts.map +1 -1
  48. package/dist/tool/CurveTool.d.ts +1 -0
  49. package/dist/tool/CurveTool.d.ts.map +1 -1
  50. package/dist/tool/EllipseTool.d.ts +1 -0
  51. package/dist/tool/EllipseTool.d.ts.map +1 -1
  52. package/dist/tool/EraserTool.d.ts +3 -1
  53. package/dist/tool/EraserTool.d.ts.map +1 -1
  54. package/dist/tool/GrabTool.d.ts +1 -0
  55. package/dist/tool/GrabTool.d.ts.map +1 -1
  56. package/dist/tool/LaserPointerTool.d.ts +1 -0
  57. package/dist/tool/LaserPointerTool.d.ts.map +1 -1
  58. package/dist/tool/LineTool.d.ts +1 -0
  59. package/dist/tool/LineTool.d.ts.map +1 -1
  60. package/dist/tool/PointerTool.d.ts +1 -0
  61. package/dist/tool/PointerTool.d.ts.map +1 -1
  62. package/dist/tool/RectangleTool.d.ts +1 -0
  63. package/dist/tool/RectangleTool.d.ts.map +1 -1
  64. package/dist/tool/SelectorTool.d.ts +1 -0
  65. package/dist/tool/SelectorTool.d.ts.map +1 -1
  66. package/dist/tool/StraightLineTool.d.ts +1 -0
  67. package/dist/tool/StraightLineTool.d.ts.map +1 -1
  68. package/dist/tool/TextTool.d.ts +1 -0
  69. package/dist/tool/TextTool.d.ts.map +1 -1
  70. package/dist/tool/TriangleTool.d.ts +1 -0
  71. package/dist/tool/TriangleTool.d.ts.map +1 -1
  72. package/dist/utils/FPS.d.ts +15 -0
  73. package/dist/utils/FPS.d.ts.map +1 -0
  74. package/dist/whiteboard.esm.js +747 -389
  75. package/dist/whiteboard.esm.js.map +4 -4
  76. package/dist/whiteboard.js +748 -390
  77. package/dist/whiteboard.js.map +4 -4
  78. package/package.json +2 -2
@@ -21876,7 +21876,7 @@ var require_lodash = __commonJS({
21876
21876
  end = end === undefined2 ? length : end;
21877
21877
  return !start && end >= length ? array : baseSlice(array, start, end);
21878
21878
  }
21879
- var clearTimeout = ctxClearTimeout || function(id) {
21879
+ var clearTimeout2 = ctxClearTimeout || function(id) {
21880
21880
  return root.clearTimeout(id);
21881
21881
  };
21882
21882
  function cloneBuffer(buffer, isDeep) {
@@ -23747,7 +23747,7 @@ var require_lodash = __commonJS({
23747
23747
  }
23748
23748
  function cancel() {
23749
23749
  if (timerId !== undefined2) {
23750
- clearTimeout(timerId);
23750
+ clearTimeout2(timerId);
23751
23751
  }
23752
23752
  lastInvokeTime = 0;
23753
23753
  lastArgs = lastCallTime = lastThis = timerId = undefined2;
@@ -23765,7 +23765,7 @@ var require_lodash = __commonJS({
23765
23765
  return leadingEdge(lastCallTime);
23766
23766
  }
23767
23767
  if (maxing) {
23768
- clearTimeout(timerId);
23768
+ clearTimeout2(timerId);
23769
23769
  timerId = setTimeout2(timerExpired, wait);
23770
23770
  return invokeFunc(lastCallTime);
23771
23771
  }
@@ -25362,13 +25362,14 @@ var require_lodash = __commonJS({
25362
25362
 
25363
25363
  // src/WhiteboardApplication.ts
25364
25364
  var import_paper = __toESM(require_paper_full(), 1);
25365
- import { AbstractApplication, log as log3 } from "@netless/forge-room";
25365
+ import { AbstractApplication, log as log4 } from "@netless/forge-room";
25366
25366
  import * as Y15 from "yjs";
25367
25367
 
25368
25368
  // src/model/RenderableModel.ts
25369
25369
  import * as Y12 from "yjs";
25370
- import EventEmitter2 from "eventemitter3";
25370
+ import EventEmitter from "eventemitter3";
25371
25371
  import { v4 as uuidv4 } from "uuid";
25372
+ import { log, removeObserver as removeObserver2 } from "@netless/forge-room";
25372
25373
 
25373
25374
  // src/model/renderable/CurveModel.ts
25374
25375
  import * as Y2 from "yjs";
@@ -25526,6 +25527,7 @@ var import_lodash = __toESM(require_lodash(), 1);
25526
25527
 
25527
25528
  // src/model/renderable/ElementModel.ts
25528
25529
  import * as Y from "yjs";
25530
+ import { removeDeepObserver } from "@netless/forge-room";
25529
25531
  function _defineProperty(e, r, t) {
25530
25532
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
25531
25533
  }
@@ -25606,11 +25608,12 @@ var ElementModel = class _ElementModel {
25606
25608
  set shadow(value) {
25607
25609
  this.root.set(_ElementModel.KEYS.shadow, value);
25608
25610
  }
25609
- constructor(root, scope) {
25611
+ constructor(root, scope, liveCursor) {
25610
25612
  _defineProperty(this, "shadowEmitter", null);
25611
25613
  _defineProperty(this, "root", void 0);
25612
25614
  _defineProperty(this, "scope", void 0);
25613
25615
  _defineProperty(this, "item", void 0);
25616
+ _defineProperty(this, "liveCursor", void 0);
25614
25617
  _defineProperty(this, "handlePropChange", (events) => {
25615
25618
  if (!this.item) {
25616
25619
  return;
@@ -25619,7 +25622,7 @@ var ElementModel = class _ElementModel {
25619
25622
  if (event.target === this.root) {
25620
25623
  const updatePaperItemKeys = this.vectorKeys().concat([_ElementModel.KEYS.pointsMatrix]);
25621
25624
  for (const [key, value] of event.changes.keys.entries()) {
25622
- if (value.action === "update") {
25625
+ if (value.action === "update" || value.action == "add") {
25623
25626
  const includeKeys = this.styleKeys().include;
25624
25627
  if (includeKeys.indexOf(key) >= 0) {
25625
25628
  this.onStyleKeyUpdate(key);
@@ -25639,6 +25642,10 @@ var ElementModel = class _ElementModel {
25639
25642
  if (this.shadow !== "") {
25640
25643
  this.shadowEmitter?.emit("translateIn", [this.uuid], this.shadow);
25641
25644
  } else {
25645
+ const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
25646
+ if (ownerId) {
25647
+ this.liveCursor.updateCursorVisible(false, ownerId);
25648
+ }
25642
25649
  this.shadowEmitter?.emit("translateOut", [this.uuid], value.oldValue);
25643
25650
  }
25644
25651
  }
@@ -25646,11 +25653,17 @@ var ElementModel = class _ElementModel {
25646
25653
  }
25647
25654
  } else if (event.target === this.root.get(_ElementModel.KEYS.points)) {
25648
25655
  this.onVectorUpdate();
25656
+ const liveCursorPoint = this.liveCursorPoint();
25657
+ const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
25658
+ if (liveCursorPoint && ownerId) {
25659
+ this.liveCursor.updateCursorPosition(liveCursorPoint, this.root.get(_ElementModel.KEYS.ownerId));
25660
+ }
25649
25661
  } else {
25650
25662
  }
25651
25663
  }
25652
25664
  });
25653
25665
  this.scope = scope;
25666
+ this.liveCursor = liveCursor;
25654
25667
  this.root = root;
25655
25668
  if (!this.root.has(_ElementModel.KEYS.pointsMatrix)) {
25656
25669
  this.root.set(_ElementModel.KEYS.pointsMatrix, [1, 0, 0, 1, 0, 0]);
@@ -25710,7 +25723,7 @@ var ElementModel = class _ElementModel {
25710
25723
  }
25711
25724
  dispose() {
25712
25725
  this.subDispose();
25713
- this.root.unobserveDeep(this.handlePropChange);
25726
+ removeDeepObserver(this.root, this.handlePropChange);
25714
25727
  }
25715
25728
  };
25716
25729
  _defineProperty(ElementModel, "KEYS", {
@@ -25782,15 +25795,18 @@ function _toPrimitive3(t, r) {
25782
25795
  return ("string" === r ? String : Number)(t);
25783
25796
  }
25784
25797
  var CurveModel = class extends ElementModel {
25785
- constructor(root, scope) {
25786
- super(root, scope);
25798
+ constructor(root, scope, liveCursor) {
25799
+ super(root, scope, liveCursor);
25787
25800
  _defineProperty3(this, "item", null);
25801
+ _defineProperty3(this, "debugPath", void 0);
25802
+ _defineProperty3(this, "debug", false);
25788
25803
  if (!this.root.has("type")) {
25789
25804
  this.root.set("type", "curve");
25790
25805
  }
25791
25806
  if (!this.root.has("points")) {
25792
25807
  this.root.set("points", new Y2.Array());
25793
25808
  }
25809
+ this.debugPath = new scope.Path();
25794
25810
  }
25795
25811
  average(a2, b2) {
25796
25812
  return (a2 + b2) / 2;
@@ -25799,23 +25815,23 @@ var CurveModel = class extends ElementModel {
25799
25815
  const groupPoints = (0, import_lodash.chunk)(points, 2);
25800
25816
  return ae(groupPoints, {
25801
25817
  size: this.strokeWidth,
25802
- smoothing: 0,
25803
- thinning: 0.5,
25818
+ smoothing: 0.5,
25819
+ thinning: -0.5,
25804
25820
  streamline: 0.5,
25805
25821
  simulatePressure: true,
25806
25822
  start: {
25807
- taper: 10,
25823
+ taper: this.strokeWidth * 10,
25808
25824
  cap: true
25809
25825
  },
25810
25826
  end: {
25811
- taper: 10,
25827
+ taper: this.strokeWidth * 20,
25812
25828
  cap: true
25813
25829
  }
25814
25830
  });
25815
25831
  }
25816
25832
  matrixedPoints() {
25817
- const groupPoints = (0, import_lodash.chunk)(this.points, 2);
25818
- return groupPoints.map((_ref) => {
25833
+ const currentPoints = (0, import_lodash.chunk)(this.points, 2);
25834
+ return currentPoints.map((_ref) => {
25819
25835
  let [x, y] = _ref;
25820
25836
  return new this.scope.Point(x, y);
25821
25837
  }).map((p) => p.transform(new this.scope.Matrix(this.pointsMatrix))).reduce((result, next) => {
@@ -25849,27 +25865,41 @@ var CurveModel = class extends ElementModel {
25849
25865
  }
25850
25866
  return path;
25851
25867
  }
25852
- getNextSegments() {
25853
- const points = this.parsePoints(this.matrixedPoints());
25854
- const path = this.createPath(points);
25855
- return path.segments;
25868
+ updateDebugPath() {
25869
+ this.debugPath = new this.scope.Path();
25870
+ const points = (0, import_lodash.chunk)(this.points, 2);
25871
+ for (let i = 0, len = points.length; i < len; i++) {
25872
+ const point = new this.scope.Point(points[i][0], points[i][1]);
25873
+ if (i === 0) {
25874
+ this.debugPath.moveTo(point);
25875
+ } else {
25876
+ this.debugPath.lineTo(point);
25877
+ }
25878
+ this.debugPath.strokeWidth = 1;
25879
+ this.debugPath.strokeColor = new this.scope.Color(1, 0, 0, 1);
25880
+ }
25856
25881
  }
25857
25882
  onVectorUpdate() {
25858
25883
  if (!this.item) {
25859
25884
  return;
25860
25885
  }
25886
+ if (this.debug) {
25887
+ this.debugPath.remove();
25888
+ this.updateDebugPath();
25889
+ }
25890
+ const points = this.parsePoints(this.matrixedPoints());
25891
+ const path = this.createPath(points);
25861
25892
  this.item.removeSegments();
25862
- this.item.addSegments(this.getNextSegments());
25863
- this.item.simplify(2.5);
25893
+ this.item.addSegments(path.segments);
25894
+ if (this.debug) {
25895
+ this.item.addChild(this.debugPath);
25896
+ }
25864
25897
  }
25865
25898
  createPaperItem() {
25866
25899
  this.item = new this.scope.Path();
25867
- this.item.strokeCap = "round";
25868
- this.item.strokeJoin = "round";
25869
- this.item.strokeScaling = false;
25870
25900
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
25871
25901
  this.item.fillColor = new this.scope.Color(this.strokeColor);
25872
- this.item.addSegments(this.getNextSegments());
25902
+ this.onVectorUpdate();
25873
25903
  }
25874
25904
  editorConfig() {
25875
25905
  return new EditorConfig();
@@ -25879,10 +25909,19 @@ var CurveModel = class extends ElementModel {
25879
25909
  }
25880
25910
  styleKeys() {
25881
25911
  return {
25882
- include: ["strokeColor"],
25883
- exclude: ["fillColor", "dashArray"]
25912
+ include: ["strokeColor", "strokeWidth"],
25913
+ exclude: ["dashArray", "fillColor"]
25884
25914
  };
25885
25915
  }
25916
+ liveCursorPoint() {
25917
+ const yArray = this.root.get(ElementModel.KEYS.points);
25918
+ if (yArray.length < 2) {
25919
+ return null;
25920
+ }
25921
+ const len = yArray.length;
25922
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
25923
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
25924
+ }
25886
25925
  onStyleKeyUpdate(key) {
25887
25926
  if (!this.item) {
25888
25927
  return;
@@ -25890,6 +25929,8 @@ var CurveModel = class extends ElementModel {
25890
25929
  if (key === "strokeColor") {
25891
25930
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
25892
25931
  this.item.fillColor = new this.scope.Color(this.strokeColor);
25932
+ } else if (key === "strokeWidth") {
25933
+ this.onVectorUpdate();
25893
25934
  }
25894
25935
  }
25895
25936
  subDispose() {
@@ -25916,8 +25957,8 @@ function _toPrimitive4(t, r) {
25916
25957
  return ("string" === r ? String : Number)(t);
25917
25958
  }
25918
25959
  var SelectorModel = class extends ElementModel {
25919
- constructor(root, scope) {
25920
- super(root, scope);
25960
+ constructor(root, scope, liveCursor) {
25961
+ super(root, scope, liveCursor);
25921
25962
  _defineProperty4(this, "item", null);
25922
25963
  if (!this.root.has("type")) {
25923
25964
  this.root.set("type", "selector");
@@ -25928,6 +25969,9 @@ var SelectorModel = class extends ElementModel {
25928
25969
  this.root.set("points", initPoints);
25929
25970
  }
25930
25971
  }
25972
+ liveCursorPoint() {
25973
+ return null;
25974
+ }
25931
25975
  subDispose() {
25932
25976
  }
25933
25977
  createPaperRect() {
@@ -26054,8 +26098,8 @@ function _toPrimitive6(t, r) {
26054
26098
  return ("string" === r ? String : Number)(t);
26055
26099
  }
26056
26100
  var SegmentsModel = class extends ElementModel {
26057
- constructor(root, scope, type) {
26058
- super(root, scope);
26101
+ constructor(root, scope, type, liveCursor) {
26102
+ super(root, scope, liveCursor);
26059
26103
  _defineProperty6(this, "item", null);
26060
26104
  if (!this.root.has("type")) {
26061
26105
  this.root.set("type", type);
@@ -26066,6 +26110,14 @@ var SegmentsModel = class extends ElementModel {
26066
26110
  }
26067
26111
  subDispose() {
26068
26112
  }
26113
+ liveCursorPoint() {
26114
+ const yArray = this.root.get(ElementModel.KEYS.points);
26115
+ if (yArray.length < 2) {
26116
+ return null;
26117
+ }
26118
+ const point = new this.scope.Point(yArray.get(0), yArray.get(1));
26119
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
26120
+ }
26069
26121
  onVectorUpdate() {
26070
26122
  if (!this.item) {
26071
26123
  return;
@@ -26191,6 +26243,7 @@ var LineTool = class extends WhiteboardTool {
26191
26243
  _defineProperty8(this, "elementModel", null);
26192
26244
  _defineProperty8(this, "from", null);
26193
26245
  _defineProperty8(this, "to", null);
26246
+ _defineProperty8(this, "showLiveCursor", true);
26194
26247
  this.tool.minDistance = 1;
26195
26248
  }
26196
26249
  onMouseDown(event) {
@@ -26255,8 +26308,8 @@ var LineModel = class extends ElementModel {
26255
26308
  set tailArrow(value) {
26256
26309
  this.root.set("tailArrow", value);
26257
26310
  }
26258
- constructor(root, scope) {
26259
- super(root, scope);
26311
+ constructor(root, scope, liveCursor) {
26312
+ super(root, scope, liveCursor);
26260
26313
  _defineProperty9(this, "controlledPoints", []);
26261
26314
  _defineProperty9(this, "item", null);
26262
26315
  if (!this.root.has("type")) {
@@ -26305,6 +26358,15 @@ var LineModel = class extends ElementModel {
26305
26358
  });
26306
26359
  return [head, path, tail];
26307
26360
  }
26361
+ liveCursorPoint() {
26362
+ const yArray = this.root.get(ElementModel.KEYS.points);
26363
+ if (yArray.length < 2) {
26364
+ return null;
26365
+ }
26366
+ const len = yArray.length;
26367
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
26368
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
26369
+ }
26308
26370
  createPaperItem() {
26309
26371
  this.item = new this.scope.Group();
26310
26372
  this.item.addChildren(this.renderLine());
@@ -26419,6 +26481,7 @@ var LineControlPoint = class {
26419
26481
 
26420
26482
  // src/model/renderable/PointTextModel.ts
26421
26483
  import * as Y6 from "yjs";
26484
+ import { removeObserver } from "@netless/forge-room";
26422
26485
  function _defineProperty10(e, r, t) {
26423
26486
  return (r = _toPropertyKey10(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
26424
26487
  }
@@ -26455,8 +26518,8 @@ var PointTextModel = class extends ElementModel {
26455
26518
  set fontFamily(value) {
26456
26519
  this.root.set("font-family", value);
26457
26520
  }
26458
- constructor(root, scope) {
26459
- super(root, scope);
26521
+ constructor(root, scope, liveCursor) {
26522
+ super(root, scope, liveCursor);
26460
26523
  _defineProperty10(this, "item", null);
26461
26524
  _defineProperty10(this, "handleTextPropChange", (event) => {
26462
26525
  if (!this.item) {
@@ -26488,7 +26551,16 @@ var PointTextModel = class extends ElementModel {
26488
26551
  }
26489
26552
  }
26490
26553
  subDispose() {
26491
- this.root.unobserve(this.handleTextPropChange);
26554
+ removeObserver(this.root, this.handleTextPropChange);
26555
+ }
26556
+ liveCursorPoint() {
26557
+ const points = this.points;
26558
+ if (points.length < 1) {
26559
+ return null;
26560
+ }
26561
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
26562
+ const topLeft = new this.scope.Point(points[0], points[1]).transform(matrix);
26563
+ return topLeft;
26492
26564
  }
26493
26565
  getInternalMeasurement() {
26494
26566
  if (!this.item) {
@@ -26585,8 +26657,8 @@ function _toPrimitive11(t, r) {
26585
26657
  return ("string" === r ? String : Number)(t);
26586
26658
  }
26587
26659
  var TriangleModel = class extends ElementModel {
26588
- constructor(root, scope) {
26589
- super(root, scope);
26660
+ constructor(root, scope, liveCursor) {
26661
+ super(root, scope, liveCursor);
26590
26662
  _defineProperty11(this, "item", null);
26591
26663
  if (!this.root.has("type")) {
26592
26664
  this.root.set("type", "triangle");
@@ -26595,6 +26667,15 @@ var TriangleModel = class extends ElementModel {
26595
26667
  this.root.set("points", new Y7.Array());
26596
26668
  }
26597
26669
  }
26670
+ liveCursorPoint() {
26671
+ const yArray = this.root.get(ElementModel.KEYS.points);
26672
+ if (yArray.length < 6) {
26673
+ return null;
26674
+ }
26675
+ const len = yArray.length;
26676
+ const point = new this.scope.Point(yArray.get(len - 4), yArray.get(len - 3));
26677
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
26678
+ }
26598
26679
  subDispose() {
26599
26680
  }
26600
26681
  createPaperItem() {
@@ -26677,8 +26758,8 @@ function _toPrimitive12(t, r) {
26677
26758
  return ("string" === r ? String : Number)(t);
26678
26759
  }
26679
26760
  var RectangleModel = class extends ElementModel {
26680
- constructor(root, scope) {
26681
- super(root, scope);
26761
+ constructor(root, scope, liveCursor) {
26762
+ super(root, scope, liveCursor);
26682
26763
  _defineProperty12(this, "item", null);
26683
26764
  if (!this.root.has("type")) {
26684
26765
  this.root.set("type", "rectangle");
@@ -26694,6 +26775,14 @@ var RectangleModel = class extends ElementModel {
26694
26775
  }
26695
26776
  subDispose() {
26696
26777
  }
26778
+ liveCursorPoint() {
26779
+ const points = this.points;
26780
+ if (points.length < 4) {
26781
+ return null;
26782
+ }
26783
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
26784
+ return new this.scope.Point(points[2], points[3]).transform(matrix);
26785
+ }
26697
26786
  createSegments() {
26698
26787
  const [a2, b2, c, d] = this.points;
26699
26788
  const matrix = new this.scope.Matrix(this.pointsMatrix);
@@ -26853,8 +26942,8 @@ function _toPrimitive13(t, r) {
26853
26942
  return ("string" === r ? String : Number)(t);
26854
26943
  }
26855
26944
  var EraserModel = class extends ElementModel {
26856
- constructor(root, scope) {
26857
- super(root, scope);
26945
+ constructor(root, scope, liveCursor) {
26946
+ super(root, scope, liveCursor);
26858
26947
  _defineProperty13(this, "item", null);
26859
26948
  _defineProperty13(this, "sliceBegin", 0);
26860
26949
  if (!this.root.has("type")) {
@@ -26893,41 +26982,42 @@ var EraserModel = class extends ElementModel {
26893
26982
  return path;
26894
26983
  }
26895
26984
  parsePoints(points) {
26896
- return ae(points, {
26985
+ const groupPoints = (0, import_lodash5.chunk)(points, 2);
26986
+ return ae(groupPoints, {
26897
26987
  size: this.strokeWidth,
26898
- smoothing: 0,
26899
- thinning: 0.5,
26988
+ smoothing: 0.5,
26989
+ thinning: -0.5,
26900
26990
  streamline: 0.5,
26901
26991
  simulatePressure: true,
26902
26992
  start: {
26903
- taper: true,
26993
+ taper: this.strokeWidth * 10,
26904
26994
  cap: true
26905
26995
  },
26906
26996
  end: {
26907
- taper: 0,
26997
+ taper: this.strokeWidth * 20,
26908
26998
  cap: true
26909
26999
  }
26910
27000
  });
26911
27001
  }
26912
27002
  matrixedPoints() {
26913
- const matrix = new this.scope.Matrix(this.pointsMatrix);
26914
- const groupPoints = (0, import_lodash5.chunk)(this.points, 2).slice(this.sliceBegin);
26915
- return groupPoints.map((_ref) => {
27003
+ const currentPoints = (0, import_lodash5.chunk)(this.points, 2).slice(this.sliceBegin);
27004
+ return currentPoints.map((_ref) => {
26916
27005
  let [x, y] = _ref;
26917
- return matrix.transform([x, y]);
26918
- }).map((p) => [p.x, p.y]);
26919
- }
26920
- getNextSegments() {
26921
- const points = this.parsePoints(this.matrixedPoints());
26922
- const path = this.createPath(points);
26923
- return path.segments;
27006
+ return new this.scope.Point(x, y);
27007
+ }).map((p) => p.transform(new this.scope.Matrix(this.pointsMatrix))).reduce((result, next) => {
27008
+ result.push(next.x);
27009
+ result.push(next.y);
27010
+ return result;
27011
+ }, []);
26924
27012
  }
26925
27013
  onVectorUpdate() {
26926
27014
  if (!this.item) {
26927
27015
  return;
26928
27016
  }
27017
+ const points = this.parsePoints(this.matrixedPoints());
27018
+ const path = this.createPath(points);
26929
27019
  this.item.removeSegments();
26930
- this.item.addSegments(this.getNextSegments());
27020
+ this.item.addSegments(path.segments);
26931
27021
  }
26932
27022
  createPaperItem() {
26933
27023
  this.item = new this.scope.Path();
@@ -26936,21 +27026,13 @@ var EraserModel = class extends ElementModel {
26936
27026
  this.item.strokeScaling = false;
26937
27027
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
26938
27028
  this.item.fillColor = new this.scope.Color(this.strokeColor);
26939
- this.item.addSegments(this.getNextSegments());
26940
- let isBegin = false;
27029
+ this.onVectorUpdate();
26941
27030
  this.item.onFrame = () => {
26942
27031
  if (!this.points) {
26943
27032
  return;
26944
27033
  }
26945
- if (this.points.length / 2 - this.sliceBegin >= 10 && !isBegin) {
26946
- isBegin = true;
26947
- }
26948
- if (this.points.length / 2 <= this.sliceBegin) {
26949
- isBegin = false;
26950
- }
26951
- if (isBegin) {
26952
- this.sliceBegin += 1;
26953
- this.onVectorUpdate();
27034
+ if (this.points.length / 2 > 50) {
27035
+ this.sliceBegin = this.points.length / 2 - 50;
26954
27036
  }
26955
27037
  };
26956
27038
  }
@@ -26971,6 +27053,15 @@ var EraserModel = class extends ElementModel {
26971
27053
  }
26972
27054
  subDispose() {
26973
27055
  }
27056
+ liveCursorPoint() {
27057
+ const yArray = this.root.get(ElementModel.KEYS.points);
27058
+ if (yArray.length < 2) {
27059
+ return null;
27060
+ }
27061
+ const len = yArray.length;
27062
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
27063
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
27064
+ }
26974
27065
  };
26975
27066
 
26976
27067
  // src/model/renderable/LaserPointerModel.ts
@@ -26994,8 +27085,8 @@ function _toPrimitive14(t, r) {
26994
27085
  return ("string" === r ? String : Number)(t);
26995
27086
  }
26996
27087
  var LaserPointerModel = class extends ElementModel {
26997
- constructor(clientId, root, scope, removeElement) {
26998
- super(root, scope);
27088
+ constructor(clientId, root, scope, liveCursor, removeElement) {
27089
+ super(root, scope, liveCursor);
26999
27090
  _defineProperty14(this, "item", null);
27000
27091
  _defineProperty14(this, "clientId", void 0);
27001
27092
  _defineProperty14(this, "sliceBegin", 0);
@@ -27132,27 +27223,19 @@ var LaserPointerModel = class extends ElementModel {
27132
27223
  }
27133
27224
  subDispose() {
27134
27225
  }
27226
+ liveCursorPoint() {
27227
+ const yArray = this.root.get(ElementModel.KEYS.points);
27228
+ if (yArray.length < 2) {
27229
+ return null;
27230
+ }
27231
+ const len = yArray.length;
27232
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
27233
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
27234
+ }
27135
27235
  };
27136
27236
 
27137
27237
  // src/WhitePermissions.ts
27138
- import EventEmitter from "eventemitter3";
27139
- function _defineProperty15(e, r, t) {
27140
- return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27141
- }
27142
- function _toPropertyKey15(t) {
27143
- var i = _toPrimitive15(t, "string");
27144
- return "symbol" == typeof i ? i : i + "";
27145
- }
27146
- function _toPrimitive15(t, r) {
27147
- if ("object" != typeof t || !t) return t;
27148
- var e = t[Symbol.toPrimitive];
27149
- if (void 0 !== e) {
27150
- var i = e.call(t, r || "default");
27151
- if ("object" != typeof i) return i;
27152
- throw new TypeError("@@toPrimitive must return a primitive value.");
27153
- }
27154
- return ("string" === r ? String : Number)(t);
27155
- }
27238
+ import { AbstractApplicationPermissions } from "@netless/forge-room";
27156
27239
  var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
27157
27240
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["none"] = 0] = "none";
27158
27241
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["draw"] = 1] = "draw";
@@ -27165,59 +27248,7 @@ var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
27165
27248
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["all"] = WhiteboardPermissionFlag2.draw | WhiteboardPermissionFlag2.editSelf | WhiteboardPermissionFlag2.editOthers | WhiteboardPermissionFlag2.deleteSelf | WhiteboardPermissionFlag2.deleteOthers | WhiteboardPermissionFlag2.mainView | WhiteboardPermissionFlag2.setOthersView] = "all";
27166
27249
  return WhiteboardPermissionFlag2;
27167
27250
  }({});
27168
- var WhiteboardPermissions = class extends EventEmitter {
27169
- constructor(userManager, requestUserMap) {
27170
- super();
27171
- _defineProperty15(this, "requestUserMap", void 0);
27172
- _defineProperty15(this, "userManager", void 0);
27173
- _defineProperty15(this, "observers", /* @__PURE__ */ new Map());
27174
- _defineProperty15(this, "handleUserLeave", (user) => {
27175
- const cb = this.observers.get(user.id);
27176
- if (cb) {
27177
- this.requestUserMap(user.id).unobserve(cb);
27178
- }
27179
- });
27180
- _defineProperty15(this, "handleUserJoin", (user) => {
27181
- this.addObserve(user.id);
27182
- });
27183
- this.userManager = userManager;
27184
- this.requestUserMap = requestUserMap;
27185
- this.createModel(this.userManager.selfId);
27186
- this.userManager.userIdList().forEach((userId) => {
27187
- this.addObserve(userId);
27188
- });
27189
- this.userManager.on("join", this.handleUserJoin);
27190
- this.userManager.on("leave", this.handleUserLeave);
27191
- }
27192
- addObserve(userId) {
27193
- if (this.observers.has(userId)) {
27194
- return;
27195
- }
27196
- const observer = (evt) => {
27197
- this.handleUserPermissionChange(userId, evt);
27198
- };
27199
- if (this.observers.has(userId)) {
27200
- this.requestUserMap(userId).unobserve(this.observers.get(userId));
27201
- }
27202
- this.observers.set(userId, observer);
27203
- this.requestUserMap(userId).observe(observer);
27204
- }
27205
- createModel(userId) {
27206
- const userMap = this.requestUserMap(userId);
27207
- if (!userMap.has("permission")) {
27208
- userMap.set("permission", 0);
27209
- }
27210
- }
27211
- handleUserPermissionChange(userId, evt) {
27212
- for (const [key, value] of evt.changes.keys.entries()) {
27213
- if (key === "permission") {
27214
- if (value.action === "add" || value.action === "update") {
27215
- const newValue = this.requestUserMap(userId).get("permission");
27216
- this.emit("change", userId, this.resolveFlags(newValue), newValue);
27217
- }
27218
- }
27219
- }
27220
- }
27251
+ var WhiteboardPermissions = class extends AbstractApplicationPermissions {
27221
27252
  /**
27222
27253
  * 解析权限列表组合
27223
27254
  * @param {number} value - 权限数字值
@@ -27226,70 +27257,19 @@ var WhiteboardPermissions = class extends EventEmitter {
27226
27257
  resolveFlags(value) {
27227
27258
  return [WhiteboardPermissionFlag.draw, WhiteboardPermissionFlag.editSelf, WhiteboardPermissionFlag.editOthers, WhiteboardPermissionFlag.deleteSelf, WhiteboardPermissionFlag.deleteOthers, WhiteboardPermissionFlag.mainView, WhiteboardPermissionFlag.setOthersView].filter((v) => (v & value) !== 0);
27228
27259
  }
27229
- /**
27230
- * 获取权限列表组合对应的数值
27231
- * @param { string } userId 不传表示获取自己
27232
- */
27233
- getPermissionValue(userId) {
27234
- return this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
27235
- }
27236
- /**
27237
- * 获取权限列表
27238
- * @param {string=} userId 可选, 不传表示获取自己
27239
- */
27240
- getPermissionFlags(userId) {
27241
- const value = this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
27242
- return this.resolveFlags(value);
27243
- }
27244
- /**
27245
- * 返回对应 userId 是否有相应权限
27246
- * @param {string=} userId 可选, 不传表示返回自己是否有相应权限
27247
- * @param {WhiteboardPermissionFlag} flag
27248
- */
27249
- hasPermission(flag, userId) {
27250
- return ((this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0) & flag) !== 0;
27251
- }
27252
- /**
27253
- * 添加权限
27254
- * @param {WhiteboardPermissionFlag} flag 权限标记
27255
- * @param {string=} userId 可选, 为 userId 添加权限, 不传表示为自己添加权限
27256
- */
27257
- addPermission(flag, userId) {
27258
- const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
27259
- const oldValue = userMap.get("permission") ?? 0;
27260
- this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue | flag);
27261
- }
27262
- /**
27263
- * 移除权限
27264
- * @param {WhiteboardPermissionFlag} flag 权限标记
27265
- * @param {string=} userId 可选, 为 userId 移除权限, 不传表示为自己移除权限
27266
- */
27267
- removePermission(flag, userId) {
27268
- const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
27269
- const oldValue = userMap.get("permission") ?? 0;
27270
- this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue & ~flag);
27271
- }
27272
- dispose() {
27273
- this.userManager.off("join", this.handleUserJoin);
27274
- this.userManager.off("leave", this.handleUserLeave);
27275
- this.observers.forEach((cb, userId) => {
27276
- this.requestUserMap(userId).unobserve(cb);
27277
- });
27278
- this.observers.clear();
27279
- }
27280
27260
  };
27281
27261
 
27282
27262
  // src/model/renderable/StraightLineModel.ts
27283
27263
  var import_lodash7 = __toESM(require_lodash(), 1);
27284
27264
  import * as Y11 from "yjs";
27285
- function _defineProperty16(e, r, t) {
27286
- return (r = _toPropertyKey16(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27265
+ function _defineProperty15(e, r, t) {
27266
+ return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27287
27267
  }
27288
- function _toPropertyKey16(t) {
27289
- var i = _toPrimitive16(t, "string");
27268
+ function _toPropertyKey15(t) {
27269
+ var i = _toPrimitive15(t, "string");
27290
27270
  return "symbol" == typeof i ? i : i + "";
27291
27271
  }
27292
- function _toPrimitive16(t, r) {
27272
+ function _toPrimitive15(t, r) {
27293
27273
  if ("object" != typeof t || !t) return t;
27294
27274
  var e = t[Symbol.toPrimitive];
27295
27275
  if (void 0 !== e) {
@@ -27300,9 +27280,9 @@ function _toPrimitive16(t, r) {
27300
27280
  return ("string" === r ? String : Number)(t);
27301
27281
  }
27302
27282
  var StraightLineModel = class extends ElementModel {
27303
- constructor(root, scope) {
27304
- super(root, scope);
27305
- _defineProperty16(this, "item", null);
27283
+ constructor(root, scope, liveCursor) {
27284
+ super(root, scope, liveCursor);
27285
+ _defineProperty15(this, "item", null);
27306
27286
  if (!this.root.has("type")) {
27307
27287
  this.root.set("type", "line");
27308
27288
  }
@@ -27310,6 +27290,15 @@ var StraightLineModel = class extends ElementModel {
27310
27290
  this.root.set("points", new Y11.Array());
27311
27291
  }
27312
27292
  }
27293
+ liveCursorPoint() {
27294
+ const yArray = this.root.get(ElementModel.KEYS.points);
27295
+ if (yArray.length < 2) {
27296
+ return null;
27297
+ }
27298
+ const len = yArray.length;
27299
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
27300
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
27301
+ }
27313
27302
  subDispose() {
27314
27303
  }
27315
27304
  onVectorUpdate() {
@@ -27395,6 +27384,86 @@ var StraightLineModel = class extends ElementModel {
27395
27384
  }
27396
27385
  };
27397
27386
 
27387
+ // src/model/renderable/ImageModel.ts
27388
+ function _defineProperty16(e, r, t) {
27389
+ return (r = _toPropertyKey16(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
27390
+ }
27391
+ function _toPropertyKey16(t) {
27392
+ var i = _toPrimitive16(t, "string");
27393
+ return "symbol" == typeof i ? i : i + "";
27394
+ }
27395
+ function _toPrimitive16(t, r) {
27396
+ if ("object" != typeof t || !t) return t;
27397
+ var e = t[Symbol.toPrimitive];
27398
+ if (void 0 !== e) {
27399
+ var i = e.call(t, r || "default");
27400
+ if ("object" != typeof i) return i;
27401
+ throw new TypeError("@@toPrimitive must return a primitive value.");
27402
+ }
27403
+ return ("string" === r ? String : Number)(t);
27404
+ }
27405
+ var ImageModel = class extends ElementModel {
27406
+ get src() {
27407
+ return this.root.get("src");
27408
+ }
27409
+ constructor(root, scope, imageSets, liveCursor) {
27410
+ super(root, scope, liveCursor);
27411
+ _defineProperty16(this, "item", null);
27412
+ _defineProperty16(this, "imageSets", void 0);
27413
+ this.imageSets = imageSets;
27414
+ if (!this.root.has("type")) {
27415
+ this.root.set("type", "image");
27416
+ }
27417
+ this.root.set(ElementModel.KEYS.shadow, "");
27418
+ }
27419
+ subDispose() {
27420
+ const img = this.imageSets.querySelector(`[id='${this.uuid}']`);
27421
+ if (img) {
27422
+ img.remove();
27423
+ }
27424
+ }
27425
+ createPaperItem() {
27426
+ if (this.item) {
27427
+ return;
27428
+ }
27429
+ if (!this.imageSets.querySelector(`[id='${this.uuid}']`)) {
27430
+ const img = document.createElement("img");
27431
+ img.src = this.src;
27432
+ img.id = this.uuid;
27433
+ this.imageSets.appendChild(img);
27434
+ }
27435
+ this.item = new this.scope.Raster(this.uuid);
27436
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
27437
+ this.item.matrix = matrix;
27438
+ }
27439
+ onVectorUpdate() {
27440
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
27441
+ if (this.item) {
27442
+ this.item.matrix = matrix;
27443
+ }
27444
+ }
27445
+ vectorKeys() {
27446
+ return [];
27447
+ }
27448
+ styleKeys() {
27449
+ return {
27450
+ include: [],
27451
+ exclude: ["dashArray", "strokeColor", "fillColor", "strokeWidth"]
27452
+ };
27453
+ }
27454
+ onStyleKeyUpdate(_key) {
27455
+ }
27456
+ editorConfig() {
27457
+ const cfg = new EditorConfig();
27458
+ cfg.resizeModel = () => "four-corner";
27459
+ cfg.uniformScale = () => true;
27460
+ return cfg;
27461
+ }
27462
+ liveCursorPoint() {
27463
+ return null;
27464
+ }
27465
+ };
27466
+
27398
27467
  // src/model/RenderableModel.ts
27399
27468
  function _defineProperty17(e, r, t) {
27400
27469
  return (r = _toPropertyKey17(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -27413,11 +27482,11 @@ function _toPrimitive17(t, r) {
27413
27482
  }
27414
27483
  return ("string" === r ? String : Number)(t);
27415
27484
  }
27416
- var RenderableModel = class extends EventEmitter2 {
27485
+ var RenderableModel = class extends EventEmitter {
27417
27486
  get uuid() {
27418
- return uuidv4();
27487
+ return uuidv4().replace(/-/g, "");
27419
27488
  }
27420
- constructor(layerId, shadowEmitter, elements, scope, toolbarModel, userManager, hasPermission) {
27489
+ constructor(layerId, shadowEmitter, elements, scope, toolbarModel, userManager, imageSets, liveCursor, hasPermission) {
27421
27490
  super();
27422
27491
  _defineProperty17(this, "scope", void 0);
27423
27492
  _defineProperty17(this, "toolbarModel", void 0);
@@ -27428,6 +27497,8 @@ var RenderableModel = class extends EventEmitter2 {
27428
27497
  _defineProperty17(this, "maxIndex", -1);
27429
27498
  _defineProperty17(this, "hasPermission", void 0);
27430
27499
  _defineProperty17(this, "shadowEmitter", void 0);
27500
+ _defineProperty17(this, "imageSets", void 0);
27501
+ _defineProperty17(this, "liveCursor", void 0);
27431
27502
  _defineProperty17(this, "onElementsChange", (event) => {
27432
27503
  for (const [key, value] of event.changes.keys.entries()) {
27433
27504
  if (value.action === "add") {
@@ -27435,7 +27506,9 @@ var RenderableModel = class extends EventEmitter2 {
27435
27506
  if (root) {
27436
27507
  const model = this.convertToModel(root);
27437
27508
  if (model) {
27438
- this.emit("elementInsert", [model]);
27509
+ setTimeout(() => {
27510
+ this.emit("elementInsert", [model]);
27511
+ });
27439
27512
  }
27440
27513
  }
27441
27514
  } else if (value.action === "delete") {
@@ -27443,6 +27516,8 @@ var RenderableModel = class extends EventEmitter2 {
27443
27516
  }
27444
27517
  }
27445
27518
  });
27519
+ this.liveCursor = liveCursor;
27520
+ this.imageSets = imageSets;
27446
27521
  this.hasPermission = hasPermission;
27447
27522
  this.shadowEmitter = shadowEmitter;
27448
27523
  this.layerId = layerId;
@@ -27481,27 +27556,29 @@ var RenderableModel = class extends EventEmitter2 {
27481
27556
  const type = yMap.get("type");
27482
27557
  let model = null;
27483
27558
  if (type === "curve") {
27484
- model = new CurveModel(yMap, this.scope);
27559
+ model = new CurveModel(yMap, this.scope, this.liveCursor);
27485
27560
  } else if (["ellipse"].indexOf(type) >= 0) {
27486
- model = new SegmentsModel(yMap, this.scope, type);
27561
+ model = new SegmentsModel(yMap, this.scope, type, this.liveCursor);
27487
27562
  } else if (type === "selector") {
27488
- model = new SelectorModel(yMap, this.scope);
27563
+ model = new SelectorModel(yMap, this.scope, this.liveCursor);
27489
27564
  } else if (type === "arrow") {
27490
- model = new LineModel(yMap, this.scope);
27565
+ model = new LineModel(yMap, this.scope, this.liveCursor);
27491
27566
  } else if (type === "line") {
27492
- model = new StraightLineModel(yMap, this.scope);
27567
+ model = new StraightLineModel(yMap, this.scope, this.liveCursor);
27493
27568
  } else if (type === "point-text") {
27494
- model = new PointTextModel(yMap, this.scope);
27569
+ model = new PointTextModel(yMap, this.scope, this.liveCursor);
27495
27570
  } else if (type === "triangle") {
27496
- model = new TriangleModel(yMap, this.scope);
27571
+ model = new TriangleModel(yMap, this.scope, this.liveCursor);
27497
27572
  } else if (type === "rectangle") {
27498
- model = new RectangleModel(yMap, this.scope);
27573
+ model = new RectangleModel(yMap, this.scope, this.liveCursor);
27499
27574
  } else if (type === "eraser") {
27500
- model = new EraserModel(yMap, this.scope);
27575
+ model = new EraserModel(yMap, this.scope, this.liveCursor);
27501
27576
  } else if (type === "laser") {
27502
- model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, (uuid) => {
27577
+ model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid) => {
27503
27578
  this.removeElementItem(uuid);
27504
27579
  });
27580
+ } else if (type === "image") {
27581
+ model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor);
27505
27582
  }
27506
27583
  if (model) {
27507
27584
  model.shadowEmitter = this.shadowEmitter;
@@ -27523,36 +27600,57 @@ var RenderableModel = class extends EventEmitter2 {
27523
27600
  removeElementItem(uuid) {
27524
27601
  this.elements.delete(uuid);
27525
27602
  }
27526
- addElementToDoc(map) {
27603
+ addElementToDoc(map, type) {
27527
27604
  this.elements.doc?.transact(() => {
27528
27605
  const uuid = this.uuid;
27529
27606
  map.set(ElementModel.KEYS.index, ++this.maxIndex);
27530
27607
  map.set(ElementModel.KEYS.uuid, uuid);
27608
+ map.set("type", type);
27531
27609
  this.elements.set(uuid, map);
27532
27610
  }, elementsUndoOrigin);
27533
27611
  }
27534
27612
  confirmPermission() {
27535
27613
  const hasPermission = this.hasPermission(WhiteboardPermissionFlag.draw);
27536
27614
  if (!hasPermission) {
27537
- console.warn("[@netless/forge-whiteboard] no permission to draw");
27615
+ log("[@netless/forge-whiteboard] no permission to draw", {}, "warning");
27538
27616
  }
27539
27617
  return hasPermission;
27540
27618
  }
27619
+ createImage(src) {
27620
+ if (!this.confirmPermission()) {
27621
+ return;
27622
+ }
27623
+ const yMap = new Y12.Map();
27624
+ this.addElementToDoc(yMap, "image");
27625
+ const model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor);
27626
+ model.root.set("src", src);
27627
+ const initMatrix = new this.scope.Matrix();
27628
+ const center = this.scope.project.view.center;
27629
+ initMatrix.translate({
27630
+ x: center.x,
27631
+ y: center.y
27632
+ });
27633
+ model.appendPointsMatrix(initMatrix);
27634
+ model.ownerId = this.userManager.selfId;
27635
+ }
27541
27636
  createCurve() {
27542
27637
  let shadow = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
27543
27638
  if (!this.confirmPermission()) {
27544
27639
  return null;
27545
27640
  }
27546
- const curveModel = new CurveModel(new Y12.Map(), this.scope);
27641
+ const yMap = new Y12.Map();
27642
+ this.addElementToDoc(yMap, "curve");
27643
+ const curveModel = new CurveModel(yMap, this.scope, this.liveCursor);
27547
27644
  this.initElement(curveModel, shadow);
27548
- this.addElementToDoc(curveModel.root);
27549
27645
  return curveModel;
27550
27646
  }
27551
27647
  createLaserPointer() {
27552
27648
  if (!this.confirmPermission()) {
27553
27649
  return null;
27554
27650
  }
27555
- const model = new LaserPointerModel(this.userManager.selfId, new Y12.Map(), this.scope, (uuid) => {
27651
+ const yMap = new Y12.Map();
27652
+ this.addElementToDoc(yMap, "laser");
27653
+ const model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid) => {
27556
27654
  this.removeElementItem(uuid);
27557
27655
  });
27558
27656
  model.strokeWidth = 8;
@@ -27560,50 +27658,53 @@ var RenderableModel = class extends EventEmitter2 {
27560
27658
  model.fillColor = "#F44336";
27561
27659
  model.ownerId = this.userManager.selfId;
27562
27660
  model.shadow = "layer";
27563
- this.addElementToDoc(model.root);
27564
27661
  return model;
27565
27662
  }
27566
27663
  createEraser() {
27567
27664
  if (!this.hasPermission(WhiteboardPermissionFlag.deleteSelf) && !this.hasPermission(WhiteboardPermissionFlag.deleteOthers)) {
27568
27665
  return null;
27569
27666
  }
27570
- const model = new EraserModel(new Y12.Map(), this.scope);
27571
- model.strokeWidth = 12;
27667
+ const yMap = new Y12.Map();
27668
+ this.addElementToDoc(yMap, "eraser");
27669
+ const model = new EraserModel(yMap, this.scope, this.liveCursor);
27670
+ model.strokeWidth = 4;
27572
27671
  model.strokeColor = "#9E9E9E";
27573
27672
  model.fillColor = "#9E9E9E";
27574
27673
  model.ownerId = this.userManager.selfId;
27575
27674
  model.shadow = "layer";
27576
- this.addElementToDoc(model.root);
27577
27675
  return model;
27578
27676
  }
27579
27677
  createTriangle(shadow) {
27580
27678
  if (!this.confirmPermission()) {
27581
27679
  return null;
27582
27680
  }
27583
- const triangle = new TriangleModel(new Y12.Map(), this.scope);
27681
+ const yMap = new Y12.Map();
27682
+ this.addElementToDoc(yMap, "triangle");
27683
+ const triangle = new TriangleModel(yMap, this.scope, this.liveCursor);
27584
27684
  this.initElement(triangle, shadow);
27585
27685
  triangle.dashArray = this.toolbarModel.dashArray;
27586
- this.addElementToDoc(triangle.root);
27587
27686
  return triangle;
27588
27687
  }
27589
27688
  createRectangle(shadow) {
27590
27689
  if (!this.confirmPermission()) {
27591
27690
  return null;
27592
27691
  }
27593
- const rect = new RectangleModel(new Y12.Map(), this.scope);
27692
+ const yMap = new Y12.Map();
27693
+ this.addElementToDoc(yMap, "rectangle");
27694
+ const rect = new RectangleModel(yMap, this.scope, this.liveCursor);
27594
27695
  this.initElement(rect, shadow);
27595
27696
  rect.dashArray = this.toolbarModel.dashArray;
27596
- this.addElementToDoc(rect.root);
27597
27697
  return rect;
27598
27698
  }
27599
27699
  createSegmentedPath(type, shadow) {
27600
27700
  if (!this.confirmPermission()) {
27601
27701
  return null;
27602
27702
  }
27603
- const segmentsModel = new SegmentsModel(new Y12.Map(), this.scope, type);
27703
+ const yMap = new Y12.Map();
27704
+ this.addElementToDoc(yMap, type);
27705
+ const segmentsModel = new SegmentsModel(yMap, this.scope, type, this.liveCursor);
27604
27706
  this.initElement(segmentsModel, shadow);
27605
27707
  segmentsModel.dashArray = this.toolbarModel.dashArray;
27606
- this.addElementToDoc(segmentsModel.root);
27607
27708
  return segmentsModel;
27608
27709
  }
27609
27710
  createSelector() {
@@ -27611,41 +27712,45 @@ var RenderableModel = class extends EventEmitter2 {
27611
27712
  if (!this.hasPermission(WhiteboardPermissionFlag.editSelf) && !this.hasPermission(WhiteboardPermissionFlag.deleteOthers)) {
27612
27713
  return null;
27613
27714
  }
27614
- const selectorModel = new SelectorModel(new Y12.Map(), this.scope);
27715
+ const yMap = new Y12.Map();
27716
+ this.addElementToDoc(yMap, "selector");
27717
+ const selectorModel = new SelectorModel(yMap, this.scope, this.liveCursor);
27615
27718
  selectorModel.shadow = "layer";
27616
- this.addElementToDoc(selectorModel.root);
27617
27719
  return selectorModel;
27618
27720
  }
27619
27721
  createStraightLine(shadow) {
27620
27722
  if (!this.confirmPermission()) {
27621
27723
  return null;
27622
27724
  }
27623
- const straightLineModel = new StraightLineModel(new Y12.Map(), this.scope);
27725
+ const yMap = new Y12.Map();
27726
+ this.addElementToDoc(yMap, "line");
27727
+ const straightLineModel = new StraightLineModel(yMap, this.scope, this.liveCursor);
27624
27728
  this.initElement(straightLineModel, shadow);
27625
27729
  straightLineModel.dashArray = this.toolbarModel.dashArray;
27626
- this.addElementToDoc(straightLineModel.root);
27627
27730
  return straightLineModel;
27628
27731
  }
27629
27732
  createLinePath(shadow) {
27630
27733
  if (!this.confirmPermission()) {
27631
27734
  return null;
27632
27735
  }
27633
- const lineModel = new LineModel(new Y12.Map(), this.scope);
27736
+ const yMap = new Y12.Map();
27737
+ this.addElementToDoc(yMap, "arrow");
27738
+ const lineModel = new LineModel(yMap, this.scope, this.liveCursor);
27634
27739
  this.initElement(lineModel, shadow);
27635
27740
  lineModel.dashArray = this.toolbarModel.dashArray;
27636
- this.addElementToDoc(lineModel.root);
27637
27741
  return lineModel;
27638
27742
  }
27639
27743
  createPointText(x, y, shadow) {
27640
27744
  if (!this.confirmPermission()) {
27641
27745
  return null;
27642
27746
  }
27643
- const pointTextModel = new PointTextModel(new Y12.Map(), this.scope);
27747
+ const yMap = new Y12.Map();
27748
+ this.addElementToDoc(yMap, "point-text");
27749
+ const pointTextModel = new PointTextModel(yMap, this.scope, this.liveCursor);
27644
27750
  pointTextModel.setPoints([x, y]);
27645
27751
  pointTextModel.fontSize = this.toolbarModel.fontSize;
27646
27752
  pointTextModel.fontFamily = this.toolbarModel.fontFamily;
27647
27753
  this.initElement(pointTextModel, shadow);
27648
- this.addElementToDoc(pointTextModel.root);
27649
27754
  return pointTextModel;
27650
27755
  }
27651
27756
  clearElement() {
@@ -27664,7 +27769,7 @@ var RenderableModel = class extends EventEmitter2 {
27664
27769
  });
27665
27770
  }
27666
27771
  dispose() {
27667
- this.elements.unobserve(this.onElementsChange);
27772
+ removeObserver2(this.elements, this.onElementsChange);
27668
27773
  this.elements.clear();
27669
27774
  Array.from(this.elementModels.values()).forEach((model) => {
27670
27775
  model.dispose();
@@ -27964,7 +28069,8 @@ var CurveTool = class extends WhiteboardTool {
27964
28069
  _defineProperty19(this, "elementModel", null);
27965
28070
  _defineProperty19(this, "recognizer", new Recognizer());
27966
28071
  _defineProperty19(this, "pointCount", 0);
27967
- this.tool.minDistance = 1;
28072
+ _defineProperty19(this, "showLiveCursor", true);
28073
+ this.tool.minDistance = 5;
27968
28074
  }
27969
28075
  onMouseDown(_event) {
27970
28076
  this.pointCount = 0;
@@ -27977,9 +28083,24 @@ var CurveTool = class extends WhiteboardTool {
27977
28083
  if (this.pointCount > 1024) {
27978
28084
  return;
27979
28085
  }
28086
+ const MIN_DISTANCE = 4;
27980
28087
  if (this.elementModel) {
27981
- this.pointCount += 1;
27982
- this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
28088
+ const len = this.elementModel.points.length;
28089
+ let last = {
28090
+ x: 0,
28091
+ y: 0
28092
+ };
28093
+ if (len >= 2) {
28094
+ last = {
28095
+ x: this.elementModel.points[len - 2],
28096
+ y: this.elementModel.points[len - 1]
28097
+ };
28098
+ }
28099
+ const dist = Math.max(Math.abs(last.x - event.point.x), Math.abs(last.y - event.point.y));
28100
+ if (dist >= MIN_DISTANCE) {
28101
+ this.pointCount += 1;
28102
+ this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
28103
+ }
27983
28104
  }
27984
28105
  }
27985
28106
  onMouseUp(event) {
@@ -28038,6 +28159,7 @@ var RectangleTool = class extends WhiteboardTool {
28038
28159
  _defineProperty20(this, "elementModel", null);
28039
28160
  _defineProperty20(this, "from", null);
28040
28161
  _defineProperty20(this, "to", null);
28162
+ _defineProperty20(this, "showLiveCursor", true);
28041
28163
  this.tool.minDistance = 1;
28042
28164
  }
28043
28165
  onMouseDown(event) {
@@ -28065,7 +28187,8 @@ var RectangleTool = class extends WhiteboardTool {
28065
28187
  };
28066
28188
 
28067
28189
  // src/model/ToolbarModel.ts
28068
- import EventEmitter3 from "eventemitter3";
28190
+ import EventEmitter2 from "eventemitter3";
28191
+ import { removeObserver as removeObserver3 } from "@netless/forge-room";
28069
28192
  function _defineProperty21(e, r, t) {
28070
28193
  return (r = _toPropertyKey21(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
28071
28194
  }
@@ -28092,7 +28215,7 @@ var TOOLBAR_KEYS = {
28092
28215
  strokeWidth: "strokeWidth",
28093
28216
  dashArray: "dashArray"
28094
28217
  };
28095
- var ToolbarModel = class extends EventEmitter3 {
28218
+ var ToolbarModel = class extends EventEmitter2 {
28096
28219
  get currentTool() {
28097
28220
  return this.root.get(TOOLBAR_KEYS.tool);
28098
28221
  }
@@ -28162,7 +28285,7 @@ var ToolbarModel = class extends EventEmitter3 {
28162
28285
  });
28163
28286
  }
28164
28287
  dispose() {
28165
- this.root.unobserve(this.handleRootUpdate);
28288
+ removeObserver3(this.root, this.handleRootUpdate);
28166
28289
  this.removeAllListeners();
28167
28290
  }
28168
28291
  };
@@ -28193,6 +28316,7 @@ var SelectorTool = class extends WhiteboardTool {
28193
28316
  _defineProperty22(this, "to", null);
28194
28317
  _defineProperty22(this, "selectElementsModel", void 0);
28195
28318
  _defineProperty22(this, "selectElements", /* @__PURE__ */ new Map());
28319
+ _defineProperty22(this, "showLiveCursor", false);
28196
28320
  this.selectElementsModel = selectElementsModel;
28197
28321
  }
28198
28322
  onMouseDown(event) {
@@ -28250,7 +28374,8 @@ var SelectorTool = class extends WhiteboardTool {
28250
28374
 
28251
28375
  // src/model/SelectElementsModel.ts
28252
28376
  import * as Y13 from "yjs";
28253
- import EventEmitter4 from "eventemitter3";
28377
+ import EventEmitter3 from "eventemitter3";
28378
+ import { removeDeepObserver as removeDeepObserver2 } from "@netless/forge-room";
28254
28379
 
28255
28380
  // src/WhiteboardKeys.ts
28256
28381
  var WhiteboardKeys = {
@@ -28281,7 +28406,7 @@ function _toPrimitive23(t, r) {
28281
28406
  }
28282
28407
  return ("string" === r ? String : Number)(t);
28283
28408
  }
28284
- var SelectElementsModel = class extends EventEmitter4 {
28409
+ var SelectElementsModel = class extends EventEmitter3 {
28285
28410
  get hasEditSelfPermission() {
28286
28411
  return this.hasPermission(WhiteboardPermissionFlag.editSelf);
28287
28412
  }
@@ -28297,7 +28422,7 @@ var SelectElementsModel = class extends EventEmitter4 {
28297
28422
  _defineProperty23(this, "handleUserLeave", (user) => {
28298
28423
  const cb = this.observers.get(user.id);
28299
28424
  if (cb) {
28300
- this.requestUserMap(user.id).unobserveDeep(cb);
28425
+ removeDeepObserver2(this.requestUserMap(user.id), cb);
28301
28426
  this.observers.delete(user.id);
28302
28427
  }
28303
28428
  });
@@ -28306,7 +28431,7 @@ var SelectElementsModel = class extends EventEmitter4 {
28306
28431
  this.handleUserSelectElementsChange(user.id, evts);
28307
28432
  };
28308
28433
  if (this.observers.has(user.id)) {
28309
- this.requestUserMap(user.id).unobserveDeep(this.observers.get(user.id));
28434
+ removeDeepObserver2(this.requestUserMap(user.id), this.observers.get(user.id));
28310
28435
  }
28311
28436
  this.requestUserMap(user.id).observeDeep(observer);
28312
28437
  this.observers.set(user.id, observer);
@@ -28328,7 +28453,7 @@ var SelectElementsModel = class extends EventEmitter4 {
28328
28453
  this.handleUserSelectElementsChange(userId, evts);
28329
28454
  };
28330
28455
  if (this.observers.has(userId)) {
28331
- this.requestUserMap(userId).unobserveDeep(this.observers.get(userId));
28456
+ removeDeepObserver2(this.requestUserMap(userId), this.observers.get(userId));
28332
28457
  }
28333
28458
  this.requestUserMap(userId).observeDeep(observer);
28334
28459
  this.observers.set(userId, observer);
@@ -28385,7 +28510,7 @@ var SelectElementsModel = class extends EventEmitter4 {
28385
28510
  }
28386
28511
  dispose() {
28387
28512
  for (const [key, value] of this.observers.entries()) {
28388
- this.requestUserMap(key).unobserveDeep(value);
28513
+ removeDeepObserver2(this.requestUserMap(key), value);
28389
28514
  }
28390
28515
  this.observers.clear();
28391
28516
  this.userManager.off("leave", this.handleUserLeave);
@@ -28394,10 +28519,10 @@ var SelectElementsModel = class extends EventEmitter4 {
28394
28519
  };
28395
28520
 
28396
28521
  // src/edit/Editor.ts
28397
- import EventEmitter6 from "eventemitter3";
28522
+ import EventEmitter5 from "eventemitter3";
28398
28523
 
28399
28524
  // src/edit/TextEditor.ts
28400
- import { EventEmitter as EventEmitter5 } from "eventemitter3";
28525
+ import { EventEmitter as EventEmitter4 } from "eventemitter3";
28401
28526
  function _defineProperty24(e, r, t) {
28402
28527
  return (r = _toPropertyKey24(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
28403
28528
  }
@@ -28415,7 +28540,7 @@ function _toPrimitive24(t, r) {
28415
28540
  }
28416
28541
  return ("string" === r ? String : Number)(t);
28417
28542
  }
28418
- var TextEditor = class extends EventEmitter5 {
28543
+ var TextEditor = class extends EventEmitter4 {
28419
28544
  constructor(camera) {
28420
28545
  super();
28421
28546
  _defineProperty24(this, "rootView", void 0);
@@ -28558,7 +28683,7 @@ var ANCHOR_STYLE = {
28558
28683
  b: "cursor:s-resize;bottom:-3px;left:50%;translate:-50%;",
28559
28684
  br: "cursor:se-resize;bottom:-3px;right:-3px"
28560
28685
  };
28561
- var Bounds = class extends EventEmitter6 {
28686
+ var Bounds = class extends EventEmitter5 {
28562
28687
  get width() {
28563
28688
  return this.maxX - this.minX;
28564
28689
  }
@@ -28697,7 +28822,7 @@ var Bounds = class extends EventEmitter6 {
28697
28822
  this.maxY = maxY;
28698
28823
  }
28699
28824
  };
28700
- var Editor = class extends EventEmitter6 {
28825
+ var Editor = class extends EventEmitter5 {
28701
28826
  constructor(scope, shadowScope, shadowEmitter, canvasElement, camera, initConfig) {
28702
28827
  super();
28703
28828
  _defineProperty25(this, "rootView", void 0);
@@ -28900,7 +29025,7 @@ var Editor = class extends EventEmitter6 {
28900
29025
  this.ctrlId = initConfig.ctrlId;
28901
29026
  this.ctrlNickName = initConfig.ctrlNickName;
28902
29027
  this.rootView = document.createElement("div");
28903
- this.rootView.style.cssText = "position:absolute;display:none;width:100%;height:100%;top:50%;left:50%;transform:translate(-50%,-50%);";
29028
+ this.rootView.style.cssText = "overflow:hidden;position:absolute;display:none;width:100%;height:100%;top:50%;left:50%;transform:translate(-50%,-50%);";
28904
29029
  this.frame = document.createElement("div");
28905
29030
  this.frame.style.position = "absolute";
28906
29031
  this.frame.style.padding = "8px";
@@ -29146,6 +29271,7 @@ var TextTool = class extends WhiteboardTool {
29146
29271
  _defineProperty26(this, "elementModel", null);
29147
29272
  _defineProperty26(this, "toolbarModel", void 0);
29148
29273
  _defineProperty26(this, "camera", void 0);
29274
+ _defineProperty26(this, "showLiveCursor", false);
29149
29275
  this.rootView = rootView;
29150
29276
  this.canvasElement = canvasElement;
29151
29277
  this.toolbarModel = toolbarModel;
@@ -29209,10 +29335,10 @@ var TextTool = class extends WhiteboardTool {
29209
29335
  };
29210
29336
 
29211
29337
  // src/Camera.ts
29212
- import EventEmitter8 from "eventemitter3";
29338
+ import EventEmitter7 from "eventemitter3";
29213
29339
 
29214
29340
  // src/Gesture.ts
29215
- import EventEmitter7 from "eventemitter3";
29341
+ import EventEmitter6 from "eventemitter3";
29216
29342
  function _defineProperty27(e, r, t) {
29217
29343
  return (r = _toPropertyKey27(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
29218
29344
  }
@@ -29230,7 +29356,7 @@ function _toPrimitive27(t, r) {
29230
29356
  }
29231
29357
  return ("string" === r ? String : Number)(t);
29232
29358
  }
29233
- var Gesture = class extends EventEmitter7 {
29359
+ var Gesture = class extends EventEmitter6 {
29234
29360
  constructor(element, scope) {
29235
29361
  super();
29236
29362
  _defineProperty27(this, "element", void 0);
@@ -29294,6 +29420,7 @@ var Gesture = class extends EventEmitter7 {
29294
29420
  };
29295
29421
 
29296
29422
  // src/Camera.ts
29423
+ import { removeObserver as removeObserver4 } from "@netless/forge-room";
29297
29424
  function _defineProperty28(e, r, t) {
29298
29425
  return (r = _toPropertyKey28(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
29299
29426
  }
@@ -29311,7 +29438,7 @@ function _toPrimitive28(t, r) {
29311
29438
  }
29312
29439
  return ("string" === r ? String : Number)(t);
29313
29440
  }
29314
- var Camera = class extends EventEmitter8 {
29441
+ var Camera = class extends EventEmitter7 {
29315
29442
  get inherentMatrix() {
29316
29443
  const inherentMatrix = new this.scope.Matrix();
29317
29444
  inherentMatrix.scale(this.inherentScale, [0, 0]);
@@ -29367,7 +29494,7 @@ var Camera = class extends EventEmitter8 {
29367
29494
  _defineProperty28(this, "handleUserLeave", (user) => {
29368
29495
  const cb = this.observers.get(user.id);
29369
29496
  if (cb) {
29370
- this.requestUserMap(user.id).unobserve(cb);
29497
+ removeObserver4(this.requestUserMap(user.id), cb);
29371
29498
  }
29372
29499
  });
29373
29500
  _defineProperty28(this, "handleUserJoin", (user) => {
@@ -29375,7 +29502,7 @@ var Camera = class extends EventEmitter8 {
29375
29502
  this.handleViewMatrixUpdate(user.id, evt);
29376
29503
  };
29377
29504
  if (this.observers.has(user.id)) {
29378
- this.requestUserMap(user.id).unobserve(observer);
29505
+ removeObserver4(this.requestUserMap(user.id), observer);
29379
29506
  }
29380
29507
  this.requestUserMap(user.id).observe(observer);
29381
29508
  this.observers.set(user.id, observer);
@@ -29482,7 +29609,7 @@ var Camera = class extends EventEmitter8 {
29482
29609
  this.handleViewMatrixUpdate(userId, evt);
29483
29610
  };
29484
29611
  if (this.observers.has(userId)) {
29485
- this.requestUserMap(userId).unobserve(observer);
29612
+ removeObserver4(this.requestUserMap(userId), observer);
29486
29613
  }
29487
29614
  this.requestUserMap(userId).observe(observer);
29488
29615
  this.observers.set(userId, observer);
@@ -29679,10 +29806,10 @@ var Camera = class extends EventEmitter8 {
29679
29806
  Array.from(this.observers.keys()).forEach((userId) => {
29680
29807
  const cb = this.observers.get(userId);
29681
29808
  if (cb) {
29682
- this.requestUserMap(userId).unobserve(cb);
29809
+ removeObserver4(this.requestUserMap(userId), cb);
29683
29810
  }
29684
29811
  });
29685
- this.whiteboardAttrsMap.unobserve(this.handleMainCameraChange);
29812
+ removeObserver4(this.whiteboardAttrsMap, this.handleMainCameraChange);
29686
29813
  this.userManager.off("join", this.handleUserJoin);
29687
29814
  this.userManager.off("leave", this.handleUserLeave);
29688
29815
  this.gesture.removeAllListeners();
@@ -29714,6 +29841,7 @@ var EllipseTool = class extends WhiteboardTool {
29714
29841
  _defineProperty29(this, "elementModel", null);
29715
29842
  _defineProperty29(this, "from", null);
29716
29843
  _defineProperty29(this, "to", null);
29844
+ _defineProperty29(this, "showLiveCursor", true);
29717
29845
  this.tool.minDistance = 1;
29718
29846
  }
29719
29847
  onMouseDown(event) {
@@ -29768,6 +29896,7 @@ var TriangleTool = class extends WhiteboardTool {
29768
29896
  _defineProperty30(this, "elementModel", null);
29769
29897
  _defineProperty30(this, "from", null);
29770
29898
  _defineProperty30(this, "to", null);
29899
+ _defineProperty30(this, "showLiveCursor", true);
29771
29900
  this.tool.minDistance = 1;
29772
29901
  }
29773
29902
  onMouseDown(event) {
@@ -29795,7 +29924,7 @@ var TriangleTool = class extends WhiteboardTool {
29795
29924
  };
29796
29925
 
29797
29926
  // src/Whiteboard.ts
29798
- import EventEmitter9 from "eventemitter3";
29927
+ import EventEmitter8 from "eventemitter3";
29799
29928
  function _defineProperty31(e, r, t) {
29800
29929
  return (r = _toPropertyKey31(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
29801
29930
  }
@@ -29813,8 +29942,7 @@ function _toPrimitive31(t, r) {
29813
29942
  }
29814
29943
  return ("string" === r ? String : Number)(t);
29815
29944
  }
29816
- var Whiteboard = class extends EventEmitter9 {
29817
- // public insertImage!: (src: string) => void;
29945
+ var Whiteboard = class extends EventEmitter8 {
29818
29946
  constructor(view) {
29819
29947
  super();
29820
29948
  _defineProperty31(this, "view", void 0);
@@ -29833,6 +29961,7 @@ var Whiteboard = class extends EventEmitter9 {
29833
29961
  _defineProperty31(this, "enableCameraBoundaryHighlight", void 0);
29834
29962
  _defineProperty31(this, "getElementAttribute", void 0);
29835
29963
  _defineProperty31(this, "setElementAttribute", void 0);
29964
+ _defineProperty31(this, "removeElement", void 0);
29836
29965
  _defineProperty31(this, "getCurrentTool", void 0);
29837
29966
  _defineProperty31(this, "setCurrentTool", void 0);
29838
29967
  _defineProperty31(this, "setCanvasBackgroundColor", void 0);
@@ -29847,6 +29976,7 @@ var Whiteboard = class extends EventEmitter9 {
29847
29976
  _defineProperty31(this, "translateCamera", void 0);
29848
29977
  _defineProperty31(this, "scaleCamera", void 0);
29849
29978
  _defineProperty31(this, "resetCamera", void 0);
29979
+ _defineProperty31(this, "showLiveCursor", void 0);
29850
29980
  _defineProperty31(this, "setFreeModelUserPage", void 0);
29851
29981
  _defineProperty31(this, "indexedNavigation", void 0);
29852
29982
  _defineProperty31(this, "setViewModeToFree", void 0);
@@ -29859,6 +29989,7 @@ var Whiteboard = class extends EventEmitter9 {
29859
29989
  _defineProperty31(this, "rasterizeElementsBounds", void 0);
29860
29990
  _defineProperty31(this, "rasterizeMaxBounds", void 0);
29861
29991
  _defineProperty31(this, "setInputType", void 0);
29992
+ _defineProperty31(this, "insertImage", void 0);
29862
29993
  this.view = view;
29863
29994
  }
29864
29995
  };
@@ -29882,13 +30013,16 @@ function _toPrimitive32(t, r) {
29882
30013
  return ("string" === r ? String : Number)(t);
29883
30014
  }
29884
30015
  var EraserTool = class extends WhiteboardTool {
29885
- constructor(enableToolEvent, renderableModel, shadowEmitter, scope, trashedElementsModel) {
30016
+ constructor(enableToolEvent, renderableModel, shadowEmitter, scope, trashedElementsModel, shadowScope) {
29886
30017
  super(enableToolEvent, renderableModel, shadowEmitter, scope);
29887
30018
  _defineProperty32(this, "elementModel", null);
29888
30019
  _defineProperty32(this, "trashedElementsModel", void 0);
29889
30020
  _defineProperty32(this, "pointCount", 0);
30021
+ _defineProperty32(this, "showLiveCursor", true);
30022
+ _defineProperty32(this, "shadowScope", void 0);
29890
30023
  this.trashedElementsModel = trashedElementsModel;
29891
- this.tool.minDistance = 1;
30024
+ this.tool.minDistance = 2;
30025
+ this.shadowScope = shadowScope;
29892
30026
  }
29893
30027
  onMouseDown(_event) {
29894
30028
  this.pointCount = 0;
@@ -29915,6 +30049,16 @@ var EraserTool = class extends WhiteboardTool {
29915
30049
  this.trashedElementsModel.addTrashedElementForSelf(item.data.uuid, item.data.ownerId);
29916
30050
  }
29917
30051
  });
30052
+ this.shadowScope.project.activeLayer.children.forEach((item) => {
30053
+ if (item.data.type && ["selector", "eraser", "laser"].indexOf(item.data.type) < 0 && item.hitTest(event.point, {
30054
+ segments: true,
30055
+ stroke: true,
30056
+ fill: true,
30057
+ tolerance: 5
30058
+ })) {
30059
+ this.trashedElementsModel.addTrashedElementForSelf(item.data.uuid, item.data.ownerId);
30060
+ }
30061
+ });
29918
30062
  }
29919
30063
  onMouseUp(_event) {
29920
30064
  if (this.elementModel) {
@@ -29926,7 +30070,8 @@ var EraserTool = class extends WhiteboardTool {
29926
30070
 
29927
30071
  // src/model/TrashedElementsModel.ts
29928
30072
  import * as Y14 from "yjs";
29929
- import EventEmitter10 from "eventemitter3";
30073
+ import EventEmitter9 from "eventemitter3";
30074
+ import { removeDeepObserver as removeDeepObserver3 } from "@netless/forge-room";
29930
30075
  function _defineProperty33(e, r, t) {
29931
30076
  return (r = _toPropertyKey33(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
29932
30077
  }
@@ -29944,7 +30089,7 @@ function _toPrimitive33(t, r) {
29944
30089
  }
29945
30090
  return ("string" === r ? String : Number)(t);
29946
30091
  }
29947
- var TrashedElementsModel = class extends EventEmitter10 {
30092
+ var TrashedElementsModel = class extends EventEmitter9 {
29948
30093
  get hasDeleteSelfPermission() {
29949
30094
  return this.hasPermission(WhiteboardPermissionFlag.deleteSelf);
29950
30095
  }
@@ -29960,7 +30105,7 @@ var TrashedElementsModel = class extends EventEmitter10 {
29960
30105
  _defineProperty33(this, "handleUserLeave", (user) => {
29961
30106
  const cb = this.observers.get(user.id);
29962
30107
  if (cb) {
29963
- this.requestUserMap(user.id).unobserveDeep(cb);
30108
+ removeDeepObserver3(this.requestUserMap(user.id), cb);
29964
30109
  }
29965
30110
  });
29966
30111
  _defineProperty33(this, "handleUserJoin", (user) => {
@@ -29968,7 +30113,7 @@ var TrashedElementsModel = class extends EventEmitter10 {
29968
30113
  this.handleUserTrashElementsChange(user.id, evts);
29969
30114
  };
29970
30115
  if (this.observers.has(user.id)) {
29971
- this.requestUserMap(user.id).unobserveDeep(this.observers.get(user.id));
30116
+ removeDeepObserver3(this.requestUserMap(user.id), this.observers.get(user.id));
29972
30117
  }
29973
30118
  this.requestUserMap(user.id).observeDeep(observer);
29974
30119
  this.observers.set(user.id, observer);
@@ -29982,7 +30127,7 @@ var TrashedElementsModel = class extends EventEmitter10 {
29982
30127
  this.handleUserTrashElementsChange(userId, evts);
29983
30128
  };
29984
30129
  if (this.observers.has(userId)) {
29985
- this.requestUserMap(userId).unobserveDeep(this.observers.get(userId));
30130
+ removeDeepObserver3(this.requestUserMap(userId), userId);
29986
30131
  }
29987
30132
  this.requestUserMap(userId).observeDeep(observer);
29988
30133
  this.observers.set(userId, observer);
@@ -30039,7 +30184,7 @@ var TrashedElementsModel = class extends EventEmitter10 {
30039
30184
  }
30040
30185
  dispose() {
30041
30186
  for (const [key, value] of this.observers.entries()) {
30042
- this.requestUserMap(key).unobserveDeep(value);
30187
+ removeDeepObserver3(this.requestUserMap(key), value);
30043
30188
  }
30044
30189
  this.observers.clear();
30045
30190
  this.userManager.off("leave", this.handleUserLeave);
@@ -30070,6 +30215,7 @@ var LaserPointerTool = class extends WhiteboardTool {
30070
30215
  super(enableToolEvent, modelGetter, shadowEmitter, scope);
30071
30216
  _defineProperty34(this, "elementModel", null);
30072
30217
  _defineProperty34(this, "pointCount", 0);
30218
+ _defineProperty34(this, "showLiveCursor", true);
30073
30219
  this.tool.minDistance = 5;
30074
30220
  }
30075
30221
  onMouseDown(_event) {
@@ -30096,8 +30242,8 @@ var LaserPointerTool = class extends WhiteboardTool {
30096
30242
  };
30097
30243
 
30098
30244
  // src/model/PageModel.ts
30099
- import EventEmitter11 from "eventemitter3";
30100
- import { log } from "@netless/forge-room";
30245
+ import EventEmitter10 from "eventemitter3";
30246
+ import { log as log2, removeObserver as removeObserver5 } from "@netless/forge-room";
30101
30247
  function _defineProperty35(e, r, t) {
30102
30248
  return (r = _toPropertyKey35(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30103
30249
  }
@@ -30115,7 +30261,7 @@ function _toPrimitive35(t, r) {
30115
30261
  }
30116
30262
  return ("string" === r ? String : Number)(t);
30117
30263
  }
30118
- var PageModel = class extends EventEmitter11 {
30264
+ var PageModel = class extends EventEmitter10 {
30119
30265
  constructor(whiteboardAttrsMap, userManager, requestUserMap, pageMap, hasPermission) {
30120
30266
  super();
30121
30267
  _defineProperty35(this, "whiteboardAttrsMap", void 0);
@@ -30127,7 +30273,7 @@ var PageModel = class extends EventEmitter11 {
30127
30273
  _defineProperty35(this, "handleUserLeave", (user) => {
30128
30274
  const cb = this.observers.get(user.id);
30129
30275
  if (cb) {
30130
- this.requestUserMap(user.id).unobserve(cb);
30276
+ removeObserver5(this.requestUserMap(user.id), cb);
30131
30277
  }
30132
30278
  });
30133
30279
  _defineProperty35(this, "handleUserJoin", (user) => {
@@ -30141,7 +30287,7 @@ var PageModel = class extends EventEmitter11 {
30141
30287
  if (cameraMode === "main") {
30142
30288
  const targetPage = this.whiteboardAttrsMap.get(WhiteboardKeys.currentPage);
30143
30289
  if (!this.pageMap.has(targetPage) && targetPage !== "_i_") {
30144
- log(`main page {${targetPage}} not found.`, {}, "error");
30290
+ log2(`main page {${targetPage}} not found.`, {}, "error");
30145
30291
  return;
30146
30292
  }
30147
30293
  this.requestUserMap(this.userManager.selfId).set(WhiteboardKeys.currentPage, targetPage);
@@ -30269,12 +30415,12 @@ var PageModel = class extends EventEmitter11 {
30269
30415
  dispose() {
30270
30416
  for (const entry of this.observers.entries()) {
30271
30417
  const [userId, observer] = entry;
30272
- this.requestUserMap(userId).unobserve(observer);
30418
+ removeObserver5(this.requestUserMap(userId), observer);
30273
30419
  }
30274
30420
  this.userManager.off("join", this.handleUserJoin);
30275
30421
  this.userManager.off("leave", this.handleUserLeave);
30276
- this.whiteboardAttrsMap.unobserve(this.handleMainPageChange);
30277
- this.pageMap.unobserve(this.handlePageMapChange);
30422
+ removeObserver5(this.whiteboardAttrsMap, this.handleMainPageChange);
30423
+ removeObserver5(this.pageMap, this.handlePageMapChange);
30278
30424
  }
30279
30425
  };
30280
30426
 
@@ -30288,8 +30434,9 @@ async function waitUntil(fn, timeout) {
30288
30434
  }
30289
30435
 
30290
30436
  // src/IndexedNavigation.ts
30291
- import EventEmitter12 from "eventemitter3";
30292
- import { log as log2 } from "@netless/forge-room";
30437
+ import EventEmitter11 from "eventemitter3";
30438
+ import { log as log3 } from "@netless/forge-room";
30439
+ import { removeObserver as removeObserver6 } from "@netless/forge-room";
30293
30440
  function _defineProperty36(e, r, t) {
30294
30441
  return (r = _toPropertyKey36(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30295
30442
  }
@@ -30307,7 +30454,7 @@ function _toPrimitive36(t, r) {
30307
30454
  }
30308
30455
  return ("string" === r ? String : Number)(t);
30309
30456
  }
30310
- var IndexedNavigation = class extends EventEmitter12 {
30457
+ var IndexedNavigation = class extends EventEmitter11 {
30311
30458
  get idList() {
30312
30459
  return this.pageModel.pageList().filter((id) => /^_i_/.test(id));
30313
30460
  }
@@ -30316,7 +30463,7 @@ var IndexedNavigation = class extends EventEmitter12 {
30316
30463
  return this.list[key] && this.list[key].prev === "";
30317
30464
  });
30318
30465
  if (!headId) {
30319
- log2("indexed navigation confusion", {
30466
+ log3("indexed navigation confusion", {
30320
30467
  list: JSON.stringify(this.list)
30321
30468
  }, "error");
30322
30469
  throw new Error("indexed navigation confusion");
@@ -30418,6 +30565,9 @@ var IndexedNavigation = class extends EventEmitter12 {
30418
30565
  const userPageId = this.userMap.get(WhiteboardKeys.currentPage);
30419
30566
  return this.getPageIndex(userPageId);
30420
30567
  }
30568
+ get currentPageId() {
30569
+ return this.userMap.get(WhiteboardKeys.currentPage);
30570
+ }
30421
30571
  getPageIndex(pageId) {
30422
30572
  let i = 0;
30423
30573
  let currentId = this.head;
@@ -30588,9 +30738,7 @@ var IndexedNavigation = class extends EventEmitter12 {
30588
30738
  if (this.pageCount <= 1) {
30589
30739
  return this.pageCount;
30590
30740
  }
30591
- const cameraMode = this.userMap.get(WhiteboardKeys.cameraMode);
30592
- if (cameraMode !== "main") {
30593
- console.warn("cannot modify pages in non-main view mode.");
30741
+ if (!this.modifyDetect()) {
30594
30742
  return this.pageCount;
30595
30743
  }
30596
30744
  const targetId = this.getPageId(index);
@@ -30631,14 +30779,14 @@ var IndexedNavigation = class extends EventEmitter12 {
30631
30779
  }
30632
30780
  }
30633
30781
  dispose() {
30634
- this.indexedPageMap.unobserve(this.handleIndexedPageMapUpdate);
30782
+ removeObserver6(this.indexedPageMap, this.handleIndexedPageMapUpdate);
30635
30783
  this.pageModel.off("switchPage");
30636
30784
  this.pageModel.off("pagesChange");
30637
30785
  }
30638
30786
  };
30639
30787
 
30640
30788
  // src/utils/ShadowEmitter.ts
30641
- import EventEmitter13 from "eventemitter3";
30789
+ import EventEmitter12 from "eventemitter3";
30642
30790
  function _defineProperty37(e, r, t) {
30643
30791
  return (r = _toPropertyKey37(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30644
30792
  }
@@ -30656,7 +30804,7 @@ function _toPrimitive37(t, r) {
30656
30804
  }
30657
30805
  return ("string" === r ? String : Number)(t);
30658
30806
  }
30659
- var ShadowEmitter = class extends EventEmitter13 {
30807
+ var ShadowEmitter = class extends EventEmitter12 {
30660
30808
  constructor(userMap) {
30661
30809
  super();
30662
30810
  _defineProperty37(this, "userMap", void 0);
@@ -30694,6 +30842,7 @@ var StraightLineTool = class extends WhiteboardTool {
30694
30842
  _defineProperty38(this, "elementModel", null);
30695
30843
  _defineProperty38(this, "from", null);
30696
30844
  _defineProperty38(this, "to", null);
30845
+ _defineProperty38(this, "showLiveCursor", true);
30697
30846
  this.tool.minDistance = 1;
30698
30847
  }
30699
30848
  onMouseDown(event) {
@@ -30743,6 +30892,7 @@ var GrabTool = class extends WhiteboardTool {
30743
30892
  super(enableToolEvent, modelGetter, shadowEmitter, scope);
30744
30893
  _defineProperty39(this, "camera", void 0);
30745
30894
  _defineProperty39(this, "downPoint", null);
30895
+ _defineProperty39(this, "showLiveCursor", false);
30746
30896
  this.camera = camera;
30747
30897
  }
30748
30898
  onMouseDown(event) {
@@ -30763,9 +30913,27 @@ var GrabTool = class extends WhiteboardTool {
30763
30913
  };
30764
30914
 
30765
30915
  // src/tool/PointerTool.ts
30916
+ function _defineProperty40(e, r, t) {
30917
+ return (r = _toPropertyKey40(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30918
+ }
30919
+ function _toPropertyKey40(t) {
30920
+ var i = _toPrimitive40(t, "string");
30921
+ return "symbol" == typeof i ? i : i + "";
30922
+ }
30923
+ function _toPrimitive40(t, r) {
30924
+ if ("object" != typeof t || !t) return t;
30925
+ var e = t[Symbol.toPrimitive];
30926
+ if (void 0 !== e) {
30927
+ var i = e.call(t, r || "default");
30928
+ if ("object" != typeof i) return i;
30929
+ throw new TypeError("@@toPrimitive must return a primitive value.");
30930
+ }
30931
+ return ("string" === r ? String : Number)(t);
30932
+ }
30766
30933
  var PointerTool = class extends WhiteboardTool {
30767
30934
  constructor(enableToolEvent, modelGetter, shadowEmitter, scope) {
30768
30935
  super(enableToolEvent, modelGetter, shadowEmitter, scope);
30936
+ _defineProperty40(this, "showLiveCursor", false);
30769
30937
  }
30770
30938
  onMouseDown(_event) {
30771
30939
  }
@@ -30776,14 +30944,14 @@ var PointerTool = class extends WhiteboardTool {
30776
30944
  };
30777
30945
 
30778
30946
  // src/SequenceExecutor.ts
30779
- function _defineProperty40(e, r, t) {
30780
- return (r = _toPropertyKey40(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30947
+ function _defineProperty41(e, r, t) {
30948
+ return (r = _toPropertyKey41(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30781
30949
  }
30782
- function _toPropertyKey40(t) {
30783
- var i = _toPrimitive40(t, "string");
30950
+ function _toPropertyKey41(t) {
30951
+ var i = _toPrimitive41(t, "string");
30784
30952
  return "symbol" == typeof i ? i : i + "";
30785
30953
  }
30786
- function _toPrimitive40(t, r) {
30954
+ function _toPrimitive41(t, r) {
30787
30955
  if ("object" != typeof t || !t) return t;
30788
30956
  var e = t[Symbol.toPrimitive];
30789
30957
  if (void 0 !== e) {
@@ -30795,8 +30963,8 @@ function _toPrimitive40(t, r) {
30795
30963
  }
30796
30964
  var SequenceExecutor = class {
30797
30965
  constructor() {
30798
- _defineProperty40(this, "tasks", []);
30799
- _defineProperty40(this, "isRunning", false);
30966
+ _defineProperty41(this, "tasks", []);
30967
+ _defineProperty41(this, "isRunning", false);
30800
30968
  }
30801
30969
  addTask(task) {
30802
30970
  this.tasks.push(task);
@@ -30823,14 +30991,138 @@ var SequenceExecutor = class {
30823
30991
  };
30824
30992
 
30825
30993
  // src/WhiteboardApplication.ts
30826
- function _defineProperty41(e, r, t) {
30827
- return (r = _toPropertyKey41(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30994
+ import { removeObserver as removeObserver7 } from "@netless/forge-room";
30995
+
30996
+ // src/LiveCursor.ts
30997
+ function _defineProperty42(e, r, t) {
30998
+ return (r = _toPropertyKey42(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
30828
30999
  }
30829
- function _toPropertyKey41(t) {
30830
- var i = _toPrimitive41(t, "string");
31000
+ function _toPropertyKey42(t) {
31001
+ var i = _toPrimitive42(t, "string");
30831
31002
  return "symbol" == typeof i ? i : i + "";
30832
31003
  }
30833
- function _toPrimitive41(t, r) {
31004
+ function _toPrimitive42(t, r) {
31005
+ if ("object" != typeof t || !t) return t;
31006
+ var e = t[Symbol.toPrimitive];
31007
+ if (void 0 !== e) {
31008
+ var i = e.call(t, r || "default");
31009
+ if ("object" != typeof i) return i;
31010
+ throw new TypeError("@@toPrimitive must return a primitive value.");
31011
+ }
31012
+ return ("string" === r ? String : Number)(t);
31013
+ }
31014
+ var LiveCursor = class {
31015
+ constructor(canvasElement, paperScope, userManager, requestUserMap) {
31016
+ _defineProperty42(this, "container", document.createElement("div"));
31017
+ _defineProperty42(this, "showLiveCursor", true);
31018
+ _defineProperty42(this, "userManager", void 0);
31019
+ _defineProperty42(this, "requestUserMap", void 0);
31020
+ _defineProperty42(this, "cursors", /* @__PURE__ */ new Map());
31021
+ _defineProperty42(this, "paperScope", void 0);
31022
+ _defineProperty42(this, "resizeobserver", void 0);
31023
+ _defineProperty42(this, "timeoutIdMap", /* @__PURE__ */ new Map());
31024
+ _defineProperty42(this, "lastVisibleChangeTimes", /* @__PURE__ */ new Map());
31025
+ this.userManager = userManager;
31026
+ this.paperScope = paperScope;
31027
+ this.requestUserMap = requestUserMap;
31028
+ this.container.setAttribute("data-forge-cursors", "");
31029
+ this.container.style.cssText = "overflow:hidden;pointer-events:none;z-index:999;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);";
31030
+ this.container.style.pointerEvents = "none";
31031
+ this.resizeobserver = new ResizeObserver(() => {
31032
+ const bounds = canvasElement.getBoundingClientRect();
31033
+ this.container.style.width = bounds.width + "px";
31034
+ this.container.style.height = bounds.height + "px";
31035
+ });
31036
+ this.resizeobserver.observe(canvasElement);
31037
+ }
31038
+ createCursor(userId) {
31039
+ const cursor = document.createElement("fcursor");
31040
+ cursor.setAttribute("data-forge-cursor", userId);
31041
+ cursor.style.backgroundColor = this.requestUserMap(userId).get(WhiteboardKeys.themeColor);
31042
+ cursor.style.color = "#fff";
31043
+ cursor.style.position = "absolute";
31044
+ cursor.style.whiteSpace = "nowrap";
31045
+ cursor.style.display = "block";
31046
+ cursor.style.fontSize = "12px";
31047
+ cursor.style.padding = "2px 4px";
31048
+ cursor.style.borderRadius = "4px";
31049
+ cursor.textContent = this.userManager.getUser(userId)?.nickName ?? userId;
31050
+ return cursor;
31051
+ }
31052
+ isOnSamePage(userId) {
31053
+ const otherPage = this.requestUserMap(userId).get(WhiteboardKeys.currentPage);
31054
+ const selfPage = this.requestUserMap(this.userManager.selfId).get(WhiteboardKeys.currentPage);
31055
+ if (otherPage !== selfPage) {
31056
+ return false;
31057
+ }
31058
+ return true;
31059
+ }
31060
+ detectEnable(userId) {
31061
+ if (!this.showLiveCursor) {
31062
+ const cursor = this.cursors.get(userId);
31063
+ if (cursor) {
31064
+ cursor.style.display = "none";
31065
+ }
31066
+ }
31067
+ return this.showLiveCursor;
31068
+ }
31069
+ updateCursorPosition(point, userId) {
31070
+ if (!this.isOnSamePage(userId) || userId === this.userManager.selfId) {
31071
+ return;
31072
+ }
31073
+ if (!this.detectEnable(userId)) {
31074
+ return;
31075
+ }
31076
+ const lastVisibleChangeTime = this.lastVisibleChangeTimes.get(userId);
31077
+ if (lastVisibleChangeTime && Date.now() - lastVisibleChangeTime < 100) {
31078
+ return;
31079
+ }
31080
+ if (!this.cursors.has(userId)) {
31081
+ const cursor2 = this.createCursor(userId);
31082
+ this.cursors.set(userId, cursor2);
31083
+ this.container.appendChild(cursor2);
31084
+ }
31085
+ const cursor = this.cursors.get(userId);
31086
+ if (cursor) {
31087
+ const viewPoint = this.paperScope.project.view.projectToView(point);
31088
+ cursor.style.left = viewPoint.x + "px";
31089
+ cursor.style.top = viewPoint.y + "px";
31090
+ cursor.style.display = "block";
31091
+ }
31092
+ if (this.timeoutIdMap.has(userId)) {
31093
+ clearTimeout(this.timeoutIdMap.get(userId));
31094
+ }
31095
+ this.timeoutIdMap.set(userId, setTimeout(() => {
31096
+ const cursor2 = this.cursors.get(userId);
31097
+ if (cursor2) {
31098
+ cursor2.style.display = "none";
31099
+ }
31100
+ }, 5e3));
31101
+ }
31102
+ updateCursorVisible(visible, userId) {
31103
+ if (!this.isOnSamePage(userId) || userId === this.userManager.selfId) {
31104
+ return;
31105
+ }
31106
+ if (!this.detectEnable(userId)) {
31107
+ return;
31108
+ }
31109
+ this.lastVisibleChangeTimes.set(userId, Date.now());
31110
+ const cursor = this.cursors.get(userId);
31111
+ if (cursor) {
31112
+ cursor.style.display = visible ? "block" : "none";
31113
+ }
31114
+ }
31115
+ };
31116
+
31117
+ // src/WhiteboardApplication.ts
31118
+ function _defineProperty43(e, r, t) {
31119
+ return (r = _toPropertyKey43(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
31120
+ }
31121
+ function _toPropertyKey43(t) {
31122
+ var i = _toPrimitive43(t, "string");
31123
+ return "symbol" == typeof i ? i : i + "";
31124
+ }
31125
+ function _toPrimitive43(t, r) {
30834
31126
  if ("object" != typeof t || !t) return t;
30835
31127
  var e = t[Symbol.toPrimitive];
30836
31128
  if (void 0 !== e) {
@@ -30853,39 +31145,71 @@ var WhiteboardApplication = class extends AbstractApplication {
30853
31145
  var _this;
30854
31146
  super();
30855
31147
  _this = this;
30856
- _defineProperty41(this, "name", WHITEBOARD_APP_NAME);
30857
- _defineProperty41(this, "emitter", void 0);
30858
- _defineProperty41(this, "toolbarModel", void 0);
30859
- _defineProperty41(this, "selectElementsModel", void 0);
30860
- _defineProperty41(this, "trashedElementsModel", void 0);
30861
- _defineProperty41(this, "pageModel", void 0);
30862
- _defineProperty41(this, "layers", /* @__PURE__ */ new Map());
30863
- _defineProperty41(this, "undoManagers", /* @__PURE__ */ new Map());
30864
- _defineProperty41(this, "rootElement", document.createElement("div"));
30865
- _defineProperty41(this, "paperScope", new import_paper.default.PaperScope());
30866
- _defineProperty41(this, "canvasElement", document.createElement("canvas"));
30867
- _defineProperty41(this, "shadowScope", new import_paper.default.PaperScope());
30868
- _defineProperty41(this, "snapshotCanvasElement", document.createElement("canvas"));
30869
- _defineProperty41(this, "snapshotScope", new import_paper.default.PaperScope());
30870
- _defineProperty41(this, "shadowCanvasElement", document.createElement("canvas"));
30871
- _defineProperty41(this, "shadowEmitter", void 0);
30872
- _defineProperty41(this, "tools", void 0);
30873
- _defineProperty41(this, "editors", /* @__PURE__ */ new Map());
30874
- _defineProperty41(this, "camera", void 0);
30875
- _defineProperty41(this, "resizeObserver", void 0);
30876
- _defineProperty41(this, "option", void 0);
30877
- _defineProperty41(this, "permissions", void 0);
30878
- _defineProperty41(this, "inputType", "any");
30879
- _defineProperty41(this, "isPenEvent", false);
30880
- _defineProperty41(this, "hasPenInput", null);
30881
- _defineProperty41(this, "disableViewModelUpdate", false);
30882
- _defineProperty41(this, "internalResizeObserver", true);
30883
- _defineProperty41(this, "sequenceExecutor", new SequenceExecutor());
30884
- _defineProperty41(this, "linkTarget", null);
30885
- _defineProperty41(this, "enableToolEvent", () => {
31148
+ _defineProperty43(this, "name", WHITEBOARD_APP_NAME);
31149
+ _defineProperty43(this, "emitter", void 0);
31150
+ _defineProperty43(this, "toolbarModel", void 0);
31151
+ _defineProperty43(this, "selectElementsModel", void 0);
31152
+ _defineProperty43(this, "trashedElementsModel", void 0);
31153
+ _defineProperty43(this, "pageModel", void 0);
31154
+ _defineProperty43(this, "layers", /* @__PURE__ */ new Map());
31155
+ _defineProperty43(this, "undoManagers", /* @__PURE__ */ new Map());
31156
+ _defineProperty43(this, "imageSets", document.createElement("div"));
31157
+ _defineProperty43(this, "rootElement", document.createElement("div"));
31158
+ _defineProperty43(this, "paperScope", new import_paper.default.PaperScope());
31159
+ _defineProperty43(this, "canvasElement", document.createElement("canvas"));
31160
+ _defineProperty43(this, "shadowScope", new import_paper.default.PaperScope());
31161
+ _defineProperty43(this, "snapshotCanvasElement", document.createElement("canvas"));
31162
+ _defineProperty43(this, "snapshotScope", new import_paper.default.PaperScope());
31163
+ _defineProperty43(this, "shadowCanvasElement", document.createElement("canvas"));
31164
+ _defineProperty43(this, "shadowEmitter", void 0);
31165
+ _defineProperty43(this, "tools", void 0);
31166
+ _defineProperty43(this, "editors", /* @__PURE__ */ new Map());
31167
+ _defineProperty43(this, "camera", void 0);
31168
+ _defineProperty43(this, "resizeObserver", void 0);
31169
+ _defineProperty43(this, "option", void 0);
31170
+ _defineProperty43(this, "permissions", void 0);
31171
+ _defineProperty43(this, "inputType", "any");
31172
+ _defineProperty43(this, "isPenEvent", false);
31173
+ _defineProperty43(this, "hasPenInput", null);
31174
+ _defineProperty43(this, "disableViewModelUpdate", false);
31175
+ _defineProperty43(this, "internalResizeObserver", true);
31176
+ _defineProperty43(this, "sequenceExecutor", new SequenceExecutor());
31177
+ _defineProperty43(this, "linkTarget", null);
31178
+ _defineProperty43(this, "liveCursor", void 0);
31179
+ _defineProperty43(this, "delayTranslateOut", -1);
31180
+ _defineProperty43(this, "enableToolEvent", () => {
30886
31181
  return !(this.inputType === "pen" && !this.isPenEvent);
30887
31182
  });
30888
- _defineProperty41(this, "handlePageSwitch", (pageId) => {
31183
+ _defineProperty43(this, "handleElementTranslateOut", (ids, container) => {
31184
+ const shadowLayer = this.shadowScope.project.activeLayer;
31185
+ let parent = null;
31186
+ if (container === "layer") {
31187
+ parent = shadowLayer;
31188
+ } else {
31189
+ parent = shadowLayer.children.find((child) => child.data.uuid === container) ?? null;
31190
+ }
31191
+ if (parent) {
31192
+ ids.forEach((id) => {
31193
+ const target = parent.children.find((child) => child.data.uuid === id);
31194
+ if (target) {
31195
+ target.remove();
31196
+ this.insertElementToParent(target, this.paperScope.project.activeLayer);
31197
+ } else {
31198
+ const pageId = this.pageModel.getCurrentPage(this.userId);
31199
+ if (pageId) {
31200
+ const page = this.layers.get(pageId);
31201
+ if (page) {
31202
+ const model = page.elementModels.get(id);
31203
+ if (model && model.item) {
31204
+ this.insertElementToParent(model.item, this.paperScope.project.activeLayer);
31205
+ }
31206
+ }
31207
+ }
31208
+ }
31209
+ });
31210
+ }
31211
+ });
31212
+ _defineProperty43(this, "handlePageSwitch", (pageId) => {
30889
31213
  this.sequenceExecutor.addTask(async () => {
30890
31214
  for (const editor of this.editors.values()) {
30891
31215
  editor.hidden();
@@ -30915,7 +31239,7 @@ var WhiteboardApplication = class extends AbstractApplication {
30915
31239
  }
30916
31240
  } else {
30917
31241
  console.warn(`[@netless/forge-whiteboard] page ${pageId} not found`);
30918
- log3(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warning");
31242
+ log4(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warning");
30919
31243
  }
30920
31244
  await waitUntil(() => this.undoManagers.has(pageId), 1e3);
30921
31245
  if (this.undoManagers.has(pageId)) {
@@ -30927,30 +31251,30 @@ var WhiteboardApplication = class extends AbstractApplication {
30927
31251
  this.undoManagers.get(pageId).on("stack-item-popped", this.handleStackItemPopped);
30928
31252
  } else {
30929
31253
  console.warn(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`);
30930
- log3(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warning");
31254
+ log4(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warning");
30931
31255
  }
30932
31256
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
30933
31257
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
30934
31258
  });
30935
31259
  });
30936
- _defineProperty41(this, "hasPermission", (flag) => {
31260
+ _defineProperty43(this, "hasPermission", (flag) => {
30937
31261
  return this.permissions.hasPermission(flag, this.userId);
30938
31262
  });
30939
- _defineProperty41(this, "handleStackItemAdded", () => {
31263
+ _defineProperty43(this, "handleStackItemAdded", () => {
30940
31264
  this.selectElementsModel.clearSelectElementForSelf();
30941
31265
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
30942
31266
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
30943
31267
  });
30944
- _defineProperty41(this, "handleStackItemPopped", () => {
31268
+ _defineProperty43(this, "handleStackItemPopped", () => {
30945
31269
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
30946
31270
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
30947
31271
  });
30948
- _defineProperty41(this, "handleLayersChange", (ids) => {
31272
+ _defineProperty43(this, "handleLayersChange", (ids) => {
30949
31273
  for (let i = 0, len = ids.length; i < len; i++) {
30950
31274
  const id = ids[i];
30951
31275
  if (!this.layers.has(id)) {
30952
31276
  const elementsMap = this.getMap(`layer/${id}/elements`);
30953
- const renderableModel = new RenderableModel(id, this.shadowEmitter, elementsMap, this.paperScope, this.toolbarModel, this.userManager, this.hasPermission);
31277
+ const renderableModel = new RenderableModel(id, this.shadowEmitter, elementsMap, this.paperScope, this.toolbarModel, this.userManager, this.imageSets, this.liveCursor, this.hasPermission);
30954
31278
  this.layers.set(id, renderableModel);
30955
31279
  }
30956
31280
  if (!this.undoManagers.has(id)) {
@@ -30977,17 +31301,17 @@ var WhiteboardApplication = class extends AbstractApplication {
30977
31301
  }
30978
31302
  }
30979
31303
  });
30980
- _defineProperty41(this, "getCurrentRenderableModel", () => {
31304
+ _defineProperty43(this, "getCurrentRenderableModel", () => {
30981
31305
  const layerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
30982
31306
  if (!this.layers.has(layerId)) {
30983
31307
  this.emitter.emit("error", 300002, `target page: ${layerId} not found`);
30984
31308
  }
30985
31309
  return this.layers.get(layerId);
30986
31310
  });
30987
- _defineProperty41(this, "handleElementClear", () => {
31311
+ _defineProperty43(this, "handleElementClear", () => {
30988
31312
  this.paperScope.project.activeLayer.removeChildren();
30989
31313
  });
30990
- _defineProperty41(this, "handleElementInsert", (elements) => {
31314
+ _defineProperty43(this, "handleElementInsert", (elements) => {
30991
31315
  for (const element of elements) {
30992
31316
  element.createPaperElement();
30993
31317
  const scope = element.shadow === "" ? this.paperScope : this.shadowScope;
@@ -30999,7 +31323,7 @@ var WhiteboardApplication = class extends AbstractApplication {
30999
31323
  this.insertElementToParent(element.item, scope.project.activeLayer);
31000
31324
  }
31001
31325
  });
31002
- _defineProperty41(this, "handleElementRemove", (elementId, layerId) => {
31326
+ _defineProperty43(this, "handleElementRemove", (elementId, layerId) => {
31003
31327
  const layerModel = this.layers.get(layerId);
31004
31328
  if (!layerModel) {
31005
31329
  return;
@@ -31010,11 +31334,11 @@ var WhiteboardApplication = class extends AbstractApplication {
31010
31334
  }
31011
31335
  layerModel.elementModels.delete(elementId);
31012
31336
  });
31013
- _defineProperty41(this, "handleRemoveTrashedElementForSelf", (userId, elementId) => {
31337
+ _defineProperty43(this, "handleRemoveTrashedElementForSelf", (userId, elementId) => {
31014
31338
  const selfLayerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
31015
31339
  this.layers.get(selfLayerId)?.removeElementItem(elementId);
31016
31340
  });
31017
- _defineProperty41(this, "handleElementsTrash", (userId, elements) => {
31341
+ _defineProperty43(this, "handleElementsTrash", (userId, elements) => {
31018
31342
  const targetLayerId = this.userMap(userId).get(WhiteboardKeys.currentPage);
31019
31343
  const selfLayerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
31020
31344
  if (targetLayerId !== selfLayerId || !this.layers.has(targetLayerId)) {
@@ -31027,7 +31351,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31027
31351
  }
31028
31352
  });
31029
31353
  });
31030
- _defineProperty41(this, "handleElementsSelect", (userId, elements) => {
31354
+ _defineProperty43(this, "handleElementsSelect", (userId, elements) => {
31031
31355
  if (!this.editors.has(userId)) {
31032
31356
  const ctrl = this.userManager.getUser(userId);
31033
31357
  const editor2 = new Editor(this.paperScope, this.shadowScope, this.shadowEmitter, this.canvasElement, this.camera, {
@@ -31070,7 +31394,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31070
31394
  this.emitter.emit("elementDeselected", userId);
31071
31395
  }
31072
31396
  });
31073
- _defineProperty41(this, "handleLinkedMapChange", (evt) => {
31397
+ _defineProperty43(this, "handleLinkedMapChange", (evt) => {
31074
31398
  for (const [key, value] of evt.changes.keys.entries()) {
31075
31399
  if (Object.keys(TOOLBAR_KEYS).indexOf(key) >= 0 && (value.action === "add" || value.action === "update")) {
31076
31400
  this.toolbarModel.currentTool = evt.target.get(TOOLBAR_KEYS.tool);
@@ -31087,7 +31411,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31087
31411
  }
31088
31412
  }
31089
31413
  });
31090
- _defineProperty41(this, "adjustByOutFrame", (frameWidth, frameHeight) => {
31414
+ _defineProperty43(this, "adjustByOutFrame", (frameWidth, frameHeight) => {
31091
31415
  if (this.option.width > 0 && this.option.height > 0) {
31092
31416
  const minWidth = Math.max(frameWidth, 10);
31093
31417
  const minHeight = Math.max(frameHeight, 10);
@@ -31107,6 +31431,9 @@ var WhiteboardApplication = class extends AbstractApplication {
31107
31431
  requestAnimationFrameHook(this.shadowScope);
31108
31432
  const that = this;
31109
31433
  this.rootElement.setAttribute("data-forge-app", "whiteboard");
31434
+ this.imageSets.style.display = "none";
31435
+ this.imageSets.setAttribute("data-image-sets", "");
31436
+ this.rootElement.appendChild(this.imageSets);
31110
31437
  document.body.addEventListener("pointerdown", (evt) => {
31111
31438
  this.isPenEvent = evt.pointerType === "pen";
31112
31439
  if (evt.pointerType === "pen" && this.hasPenInput === null) {
@@ -31168,7 +31495,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31168
31495
  this.emitter.setViewModeToFree = (userId) => {
31169
31496
  if (that.disableViewModelUpdate) {
31170
31497
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
31171
- log3("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
31498
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
31172
31499
  return;
31173
31500
  }
31174
31501
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -31179,7 +31506,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31179
31506
  this.emitter.setViewModeToFlow = (flowId, userId) => {
31180
31507
  if (that.disableViewModelUpdate) {
31181
31508
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
31182
- log3("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
31509
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
31183
31510
  return;
31184
31511
  }
31185
31512
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -31194,7 +31521,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31194
31521
  this.emitter.setViewModeToMain = (userId) => {
31195
31522
  if (that.disableViewModelUpdate) {
31196
31523
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
31197
- log3("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
31524
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
31198
31525
  return;
31199
31526
  }
31200
31527
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -31206,6 +31533,30 @@ var WhiteboardApplication = class extends AbstractApplication {
31206
31533
  this.camera.resetViewMatrixToMain();
31207
31534
  }
31208
31535
  };
31536
+ this.emitter.insertImage = (src, pageId) => {
31537
+ if (!/https/.test(src)) {
31538
+ log4("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
31539
+ src
31540
+ }, "warning");
31541
+ return;
31542
+ }
31543
+ let targetPageId = pageId;
31544
+ if (!targetPageId) {
31545
+ targetPageId = this.pageModel.getCurrentPage(this.userManager.selfId);
31546
+ }
31547
+ if (!targetPageId) {
31548
+ log4("[@netless/forge-whiteboard] page not found", {}, "warning");
31549
+ return;
31550
+ }
31551
+ this.layers.get(targetPageId)?.createImage(src);
31552
+ };
31553
+ this.emitter.removeElement = (pageId, elementId) => {
31554
+ if (!this.layers.has(pageId)) {
31555
+ log4("[@netless/forge-whiteboard] page not found", {}, "warning");
31556
+ return;
31557
+ }
31558
+ this.layers.get(pageId)?.removeElementItem(elementId);
31559
+ };
31209
31560
  this.emitter.getViewModel = (userId) => {
31210
31561
  const targetId = userId ? userId : this.userId;
31211
31562
  return this.userMap(targetId).get(WhiteboardKeys.cameraMode);
@@ -31221,7 +31572,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31221
31572
  const source = this.getMap(`layer/${sourceId}/elements`);
31222
31573
  const target = this.getMap(`layer/${targetId}/elements`);
31223
31574
  if (!this.layers.has(targetId)) {
31224
- this.layers.set(targetId, new RenderableModel(targetId, this.shadowEmitter, target, this.paperScope, this.toolbarModel, this.userManager, this.hasPermission));
31575
+ this.layers.set(targetId, new RenderableModel(targetId, this.shadowEmitter, target, this.paperScope, this.toolbarModel, this.userManager, this.imageSets, this.liveCursor, this.hasPermission));
31225
31576
  }
31226
31577
  if (!this.undoManagers.has(targetId)) {
31227
31578
  const undoManager = new Y15.UndoManager(target, {
@@ -31271,12 +31622,23 @@ var WhiteboardApplication = class extends AbstractApplication {
31271
31622
  this.emitter.resetCamera = () => {
31272
31623
  this.camera.reset();
31273
31624
  };
31625
+ this.emitter.showLiveCursor = (value) => {
31626
+ this.liveCursor.showLiveCursor = value;
31627
+ };
31274
31628
  this.emitter.on("error", (errorCode, errorMessage) => {
31275
- log3("WhiteboardApplicationError", {
31629
+ log4("WhiteboardApplicationError", {
31276
31630
  errorCode,
31277
31631
  errorMessage
31278
31632
  });
31279
31633
  });
31634
+ Object.defineProperty(this.emitter, "__delayTranslateOut", {
31635
+ get() {
31636
+ return that.delayTranslateOut;
31637
+ },
31638
+ set(value) {
31639
+ that.delayTranslateOut = value;
31640
+ }
31641
+ });
31280
31642
  Object.defineProperty(this.emitter, "tool", {
31281
31643
  get() {
31282
31644
  return that.toolbarModel.currentTool;
@@ -31373,9 +31735,14 @@ var WhiteboardApplication = class extends AbstractApplication {
31373
31735
  this.permissions = new WhiteboardPermissions(this.userManager, (userId) => {
31374
31736
  return this.userMap(userId);
31375
31737
  });
31738
+ this.permissions.setPermission(WhiteboardPermissionFlag.all);
31376
31739
  this.emitter["permissions"] = this.permissions;
31377
31740
  this.emitter["selfUserId"] = this.userId;
31378
31741
  this.option = option;
31742
+ if (this.option.stretchToFill) {
31743
+ this.option.width = -1;
31744
+ this.option.height = -1;
31745
+ }
31379
31746
  this.userMap(this.userId).set(WhiteboardKeys.themeColor, "#009688");
31380
31747
  this.shadowEmitter = new ShadowEmitter(this.userMap(this.userId));
31381
31748
  this.pageModel = new PageModel(this.getMap("attrs"), this.userManager, (userId) => {
@@ -31424,6 +31791,9 @@ var WhiteboardApplication = class extends AbstractApplication {
31424
31791
  this.selectElementsModel = new SelectElementsModel(this.userManager, (userId) => {
31425
31792
  return this.userMap(userId);
31426
31793
  }, this.hasPermission);
31794
+ this.liveCursor = new LiveCursor(this.canvasElement, this.paperScope, this.userManager, (userId) => {
31795
+ return this.userMap(userId);
31796
+ });
31427
31797
  this.tools = {
31428
31798
  pointer: new PointerTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
31429
31799
  curve: new CurveTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
@@ -31434,7 +31804,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31434
31804
  text: new TextTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.rootElement, this.canvasElement, this.toolbarModel, this.camera),
31435
31805
  ellipse: new EllipseTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
31436
31806
  triangle: new TriangleTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
31437
- eraser: new EraserTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.trashedElementsModel),
31807
+ eraser: new EraserTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.trashedElementsModel, this.shadowScope),
31438
31808
  laser: new LaserPointerTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
31439
31809
  grab: new GrabTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.camera)
31440
31810
  };
@@ -31455,7 +31825,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31455
31825
  this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
31456
31826
  } else {
31457
31827
  this.paperScope.tool = this.tools["curve"].tool;
31458
- log3(`${this.toolbarModel.currentTool} not supported, backup to curve`);
31828
+ log4(`${this.toolbarModel.currentTool} not supported, backup to curve`);
31459
31829
  }
31460
31830
  this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
31461
31831
  this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
@@ -31506,32 +31876,12 @@ var WhiteboardApplication = class extends AbstractApplication {
31506
31876
  }
31507
31877
  });
31508
31878
  this.shadowEmitter.on("translateOut", (ids, container) => {
31509
- const shadowLayer = this.shadowScope.project.activeLayer;
31510
- let parent = null;
31511
- if (container === "layer") {
31512
- parent = shadowLayer;
31879
+ if (this.delayTranslateOut > 0) {
31880
+ setTimeout(() => {
31881
+ this.handleElementTranslateOut(ids, container);
31882
+ }, this.delayTranslateOut);
31513
31883
  } else {
31514
- parent = shadowLayer.children.find((child) => child.data.uuid === container) ?? null;
31515
- }
31516
- if (parent) {
31517
- ids.forEach((id) => {
31518
- const target = parent.children.find((child) => child.data.uuid === id);
31519
- if (target) {
31520
- target.remove();
31521
- this.insertElementToParent(target, this.paperScope.project.activeLayer);
31522
- } else {
31523
- const pageId = this.pageModel.getCurrentPage(this.userId);
31524
- if (pageId) {
31525
- const page = this.layers.get(pageId);
31526
- if (page) {
31527
- const model = page.elementModels.get(id);
31528
- if (model && model.item) {
31529
- this.insertElementToParent(model.item, this.paperScope.project.activeLayer);
31530
- }
31531
- }
31532
- }
31533
- }
31534
- });
31884
+ this.handleElementTranslateOut(ids, container);
31535
31885
  }
31536
31886
  });
31537
31887
  this.shadowEmitter.on("translateIn", (ids, container) => {
@@ -31558,6 +31908,14 @@ var WhiteboardApplication = class extends AbstractApplication {
31558
31908
  this.emitter.emit("grabUp");
31559
31909
  });
31560
31910
  this.clearElements();
31911
+ if (this.option.stretchToFill) {
31912
+ window.addEventListener("resize", () => {
31913
+ const bounds = document.body.getBoundingClientRect();
31914
+ this.updateOptionSize(bounds.width, bounds.height);
31915
+ this.adjustByOutFrame(bounds.width, bounds.height);
31916
+ });
31917
+ }
31918
+ this.rootElement.appendChild(this.liveCursor.container);
31561
31919
  }
31562
31920
  clearElements() {
31563
31921
  const userIds = this.userManager.userIdList();
@@ -31700,7 +32058,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31700
32058
  }
31701
32059
  unlink() {
31702
32060
  if (this.linkTarget) {
31703
- this.linkTarget.unobserve(this.handleLinkedMapChange);
32061
+ removeObserver7(this.linkTarget, this.handleLinkedMapChange);
31704
32062
  }
31705
32063
  }
31706
32064
  setViewSize(width, height) {
@@ -31753,7 +32111,7 @@ var WhiteboardApplication = class extends AbstractApplication {
31753
32111
  this.permissions.dispose();
31754
32112
  }
31755
32113
  };
31756
- _defineProperty41(WhiteboardApplication, "applicationName", WHITEBOARD_APP_NAME);
32114
+ _defineProperty43(WhiteboardApplication, "applicationName", WHITEBOARD_APP_NAME);
31757
32115
  export {
31758
32116
  Whiteboard,
31759
32117
  WhiteboardApplication,