@netless/forge-slide 0.1.1-alpha.1 → 0.1.1-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
- // ../../node_modules/.pnpm/@netless+slide@1.4.15/node_modules/@netless/slide/lib/Slide.js
33
+ // ../../node_modules/.pnpm/@netless+slide@1.4.21/node_modules/@netless/slide/lib/Slide.js
34
34
  var require_Slide = __commonJS({
35
- "../../node_modules/.pnpm/@netless+slide@1.4.15/node_modules/@netless/slide/lib/Slide.js"(exports, module) {
35
+ "../../node_modules/.pnpm/@netless+slide@1.4.21/node_modules/@netless/slide/lib/Slide.js"(exports, module) {
36
36
  module.exports = function(t) {
37
37
  var e = {};
38
38
  function i(n) {
@@ -5703,7 +5703,7 @@ var require_Slide = __commonJS({
5703
5703
  }
5704
5704
  return void 0 === d && (d = setTimeout(b2, e2)), c;
5705
5705
  }
5706
- return e2 = o(e2) || 0, n(i2) && (m = !!i2.leading, u = (g = "maxWait" in i2) ? s(o(i2.maxWait) || 0, e2) : u, v = "trailing" in i2 ? !!i2.trailing : v), E.cancel = function() {
5706
+ return e2 = o(e2) || 0, n(i2) && (m = !!i2.leading, u = (g = "maxWait" in i2) ? s(o(i2.maxWait) || 0, e2) : u, v = "trailing" in i2 ? !!i2.trailing : v), console.log("max wait", u), E.cancel = function() {
5707
5707
  void 0 !== d && clearTimeout(d), f = 0, l2 = p = h = d = void 0;
5708
5708
  }, E.flush = function() {
5709
5709
  return void 0 === d ? c : T(r());
@@ -29372,6 +29372,7 @@ void main(void){
29372
29372
  const r3 = e2[t3], o3 = e2[t3 + 1], [s3, a3] = o3.split(",").map((t4) => Number(t4) / 100);
29373
29373
  i2.push(r3), n2.push({ x: s3, y: a3 });
29374
29374
  }
29375
+ if (n2.length < 4) return false;
29375
29376
  if (this.isSquare(i2, n2)) return true;
29376
29377
  for (let t3 = 0; t3 < 3; t3++) {
29377
29378
  const e3 = n2[t3], i3 = n2[t3 + 1];
@@ -29786,7 +29787,9 @@ void main(void){
29786
29787
  }
29787
29788
  this.delayHide();
29788
29789
  }
29789
- }, this.targetId = t2.targetId, this.ctx = t2.ctx, this.height = t2.height, this.width = t2.width, this.target = t2.target, this.media = t2.media, this.info = t2.info, this.shapeId = t2.shapeId, this.canvasElement = t2.canvasElement, "video" === this.media.type && (this.isVideo = true), this.getMedianContainer(), this.createMediaController(), this.info.cut && (this.start = null !== (e2 = this.info.cut.start) && void 0 !== e2 ? e2 : 0, this.end = null !== (i2 = this.info.cut.end) && void 0 !== i2 ? i2 : 0), this.info.bookmarkList && (this.bookmarkList = this.info.bookmarkList.sort((t3, e3) => t3.time - e3.time));
29790
+ }, this.targetId = t2.targetId, this.ctx = t2.ctx, this.height = t2.height, this.width = t2.width, this.target = t2.target, this.media = t2.media, this.info = t2.info, this.shapeId = t2.shapeId, this.canvasElement = t2.canvasElement, "video" === this.media.type && (this.isVideo = true), this.getMedianContainer(), this.createMediaController(), this.info.cut && (this.start = null !== (e2 = this.info.cut.start) && void 0 !== e2 ? e2 : 0, this.end = null !== (i2 = this.info.cut.end) && void 0 !== i2 ? i2 : 0), this.info.bookmarkList && (this.bookmarkList = this.info.bookmarkList.sort((t3, e3) => t3.time - e3.time)), this.ctx.globalEventHub.on("togglePlayStatus", (t3) => {
29791
+ t3 === this.targetId && (this.media.isPlaying ? this.pauseMediaFromCtrl(false) : this.playMediaFromCtrl(false));
29792
+ });
29790
29793
  }
29791
29794
  getMedianContainer() {
29792
29795
  var t2;
@@ -30307,9 +30310,10 @@ void main(void){
30307
30310
  const a3 = null === (t2 = this.backgroundGraphics) || void 0 === t2 ? void 0 : t2.getPictureMask();
30308
30311
  if ((null === (e2 = this.backgroundGraphics) || void 0 === e2 ? void 0 : e2.isNeedMask(s2.width, s2.height)) && a3 && (s2.mask = a3, this.effectContainer.addChild(a3)), s2.width = this.designWidth, s2.height = this.designHeight, s2 instanceof im && this.ctx.slideScopeEventHub.on("slide-render", this.onSlideRenderPlayGif), this.effectContainer.addChild(s2), this.media) {
30309
30312
  let t3 = this.media.src;
30310
- if ("audio" === this.media.type && /mp4$/.test(t3) && (t3 = t3.replace(/mp4$/, "mp3")), this.ctx.urlInterrupter) {
30311
- const e3 = Date.now();
30312
- t3 = yield this.ctx.urlInterrupter(t3), this.ctx.logger.info("redirect media url by interrupter. time: " + (Date.now() - e3), this.ctx.taskId);
30313
+ const [e3, i3] = t3.split("dynamicConvert");
30314
+ if (i3 && (t3 = `${this.ctx.prefix}${i3}`), "audio" === this.media.type && /mp4$/.test(t3) && (t3 = t3.replace(/mp4$/, "mp3")), this.ctx.urlInterrupter) {
30315
+ const e4 = Date.now();
30316
+ t3 = yield this.ctx.urlInterrupter(t3), this.ctx.logger.info("redirect media url by interrupter. time: " + (Date.now() - e4), this.ctx.taskId);
30313
30317
  }
30314
30318
  this.ctx.loaderDelegate && (t3 = this.ctx.loaderDelegate.redirectMedia(t3), this.ctx.logger.info(`redirect media url to ${t3} by delegate.`, this.ctx.taskId)), this.media.src = t3;
30315
30319
  }
@@ -30759,12 +30763,18 @@ void main(void){
30759
30763
  if ("num" === e2 && this.timingTarget) {
30760
30764
  const e3 = new I_(t4, this.timingTarget);
30761
30765
  this.keyFrames.push([t4.time, e3]);
30766
+ } else if ("str" === e2 && this.timingTarget) {
30767
+ const e3 = new R_(t4, this.timingTarget);
30768
+ this.keyFrames.push([t4.time, e3]);
30762
30769
  }
30763
30770
  }
30764
30771
  const t3 = { time: 1, val: { type: "string", value: this.json.to }, fmla: "" };
30765
30772
  if ("num" === e2 && this.timingTarget) {
30766
30773
  const e3 = new I_(t3, this.timingTarget);
30767
30774
  this.keyFrames.push([t3.time, e3]);
30775
+ } else if ("str" === e2 && this.timingTarget) {
30776
+ const e3 = new R_(t3, this.timingTarget);
30777
+ this.keyFrames.push([t3.time, e3]);
30768
30778
  }
30769
30779
  } else if (this.json.by) {
30770
30780
  const i2 = { time: 0, val: { type: "string", value: this.json.cBhvr.attrList[0] }, fmla: "" };
@@ -31129,7 +31139,8 @@ void main(void){
31129
31139
  const { json: e2, isIterate: i2, isSub: n2, eventHub: r2, ctx: o2, parent: s2, iterateType: a3, iterateIndex: l3, iterateId: h2, isInInteractiveSeq: u2, fromSeqId: c2 } = t2;
31130
31140
  this.json = e2, this.id = e2.cMediaNode.ctn.id, this.commonTimeNode = new Ey({ json: e2.cMediaNode.ctn, isSub: n2, eventHubs: { global: r2, runtime: this.runtimeNodeEventHub }, ctx: o2, parent: s2, isIterate: i2, iterateType: a3, iterateIndex: l3, iterateId: h2, isInInteractiveSeq: u2, fromSeqId: c2 });
31131
31141
  let d2 = e2.cMediaNode.tgtEl;
31132
- o2.loaderDelegate && (d2 = o2.loaderDelegate.redirectMedia(d2), o2.logger.info(`redirect media url from ${e2.cMediaNode.tgtEl} to ${d2} by delegate.`, o2.taskId)), this.audio = new c_(d2, o2.runningAudio, void 0, { enableWebAudio: o2.enableWebAudio }), o2.activeMedia.add(this.audio), this.commonTimeNode.on("timelineStart", () => {
31142
+ const [p2, f2] = d2.split("dynamicConvert");
31143
+ f2 && (d2 = `${o2.prefix}${f2}`), o2.loaderDelegate && (d2 = o2.loaderDelegate.redirectMedia(d2), o2.logger.info(`redirect media url from ${e2.cMediaNode.tgtEl} to ${d2} by delegate.`, o2.taskId)), this.audio = new c_(d2, o2.runningAudio, void 0, { enableWebAudio: o2.enableWebAudio }), o2.activeMedia.add(this.audio), this.commonTimeNode.on("timelineStart", () => {
31133
31144
  this.audio.volume(o2.volumeAdjuster.volume), this.audio.play();
31134
31145
  }), this.commonTimeNode.on("seekToStart", this.stopAudio), this.commonTimeNode.on("seekToEnd", this.stopAudio), this.commonTimeNode.on("timeNodeDestroy", this.destroy), this.ctx = o2, this.ctx.volumeAdjuster.on("update", this.onVolumeUpdate);
31135
31146
  }
@@ -31992,7 +32003,7 @@ void main(void){
31992
32003
  createCtx(t2) {
31993
32004
  const { task: e2 } = this.stageStates[t2];
31994
32005
  e2.addMTask(() => Dy(this, void 0, void 0, function* () {
31995
- const e3 = new Gm(this.loader), i2 = new Za.a(), n2 = { taskId: this.taskId, mode: this.mode, renderer: this.renderer, graphicsTexture: new Km(this.maxResolution), stageWidth: 0, stageHeight: 0, ticker: this.ticker, timingTargets: new $m(i2), eventHub: i2, view: this.view, medias: /* @__PURE__ */ Object.create(null), lastViewedIndex: 0, conflictTimeNodeManager: new Qm(), clock: this.clock, spriteTexture: e3, slideIndex: t2, objectPoolGroup: this.objPoolGroup, hasBackgroundFillShape: false, slideScopeEventHub: new Za.a(), logger: this.logger, sdfManager: this.sdfManager, loaderDelegate: this.loaderDelegate, runningAudio: this.runningAudio, activeMedia: this.activeMedia, isPlayerPaused: this.isPlayerPaused, timingEventHub: new Za.a(), maxResolution: this.maxResolution, animatedIds: /* @__PURE__ */ new Set(), volumeAdjuster: this.volumeAdjuster, forceCanvas: this.forceCanvas, globalEventHub: this.globalEventHub, latestChangeFullscreenTargetId: "", isRendering: false, urlInterrupter: this.urlInterrupter, enableWebAudio: this.enableWebAudio };
32006
+ const e3 = new Gm(this.loader), i2 = new Za.a(), n2 = { taskId: this.taskId, prefix: this.url, mode: this.mode, renderer: this.renderer, graphicsTexture: new Km(this.maxResolution), stageWidth: 0, stageHeight: 0, ticker: this.ticker, timingTargets: new $m(i2), eventHub: i2, view: this.view, medias: /* @__PURE__ */ Object.create(null), lastViewedIndex: 0, conflictTimeNodeManager: new Qm(), clock: this.clock, spriteTexture: e3, slideIndex: t2, objectPoolGroup: this.objPoolGroup, hasBackgroundFillShape: false, slideScopeEventHub: new Za.a(), logger: this.logger, sdfManager: this.sdfManager, loaderDelegate: this.loaderDelegate, runningAudio: this.runningAudio, activeMedia: this.activeMedia, isPlayerPaused: this.isPlayerPaused, timingEventHub: new Za.a(), maxResolution: this.maxResolution, animatedIds: /* @__PURE__ */ new Set(), volumeAdjuster: this.volumeAdjuster, forceCanvas: this.forceCanvas, globalEventHub: this.globalEventHub, latestChangeFullscreenTargetId: "", isRendering: false, urlInterrupter: this.urlInterrupter, enableWebAudio: this.enableWebAudio };
31996
32007
  this.stageCtxs[t2] = n2;
31997
32008
  }), "@StagePool[createCtx]");
31998
32009
  }
@@ -32288,11 +32299,15 @@ void main(void){
32288
32299
  this.app.view.addEventListener("mouseover", e4, false);
32289
32300
  const r3 = { handleEvent: () => {
32290
32301
  this.fullscreenOnMousemove({ index: i3, targetId: n3 });
32302
+ } }, o3 = { handleEvent: () => {
32303
+ var t5;
32304
+ null === (t5 = this.currentStage) || void 0 === t5 || t5.ctx.globalEventHub.emit("togglePlayStatus", n3);
32291
32305
  } };
32292
- this.app.view.addEventListener("mousemove", r3, false), this.cacheFunctionMap.set("mouseover", e4), this.cacheFunctionMap.set("mousemove", r3), this.cacheFunctionMap.set("mouseout", t4);
32306
+ this.app.view.addEventListener("mousemove", r3, false), this.app.view.addEventListener("click", o3, false), this.cacheFunctionMap.set("click", o3), this.cacheFunctionMap.set("mouseover", e4), this.cacheFunctionMap.set("mousemove", r3), this.cacheFunctionMap.set("mouseout", t4);
32293
32307
  } else {
32294
32308
  const t4 = { handleEvent: () => {
32295
- this.fullscreenOnMousemove({ index: i3, targetId: n3 });
32309
+ var t5;
32310
+ this.fullscreenOnMousemove({ index: i3, targetId: n3 }), null === (t5 = this.currentStage) || void 0 === t5 || t5.ctx.globalEventHub.emit("togglePlayStatus", n3);
32296
32311
  } };
32297
32312
  this.app.view.addEventListener("touchstart", t4, false), this.cacheFunctionMap.set("touchstart", t4);
32298
32313
  }
@@ -32602,7 +32617,7 @@ void main(void){
32602
32617
  });
32603
32618
  }
32604
32619
  clearFullscreenEventListenersWithAppView() {
32605
- ["mousemove", "mouseout", "mouseover", "touchstart", "pointerdown"].forEach((t2) => {
32620
+ ["mousemove", "click", "mouseout", "mouseover", "touchstart", "pointerdown"].forEach((t2) => {
32606
32621
  this.cacheFunctionMap.has(t2) && (this.app.view.removeEventListener(t2, this.cacheFunctionMap.get(t2), false), this.cacheFunctionMap.delete(t2));
32607
32622
  });
32608
32623
  }
@@ -34224,23 +34239,44 @@ void main(void){
34224
34239
  };
34225
34240
  }
34226
34241
  };
34227
- function sT(t2, e2, i2, n2) {
34242
+ function sT(t2, e2, i2, n2, r2) {
34228
34243
  return rT(this, void 0, void 0, function() {
34229
- var r2, o2, s2, a3;
34230
- return oT(this, function(l3) {
34231
- switch (l3.label) {
34244
+ var o2, s2, a3, l3, h2, u2;
34245
+ return oT(this, function(c2) {
34246
+ switch (c2.label) {
34232
34247
  case 0:
34233
- return r2 = document.createElement("div"), (o2 = new yT({ anchor: r2, renderOptions: { minFPS: 1, maxFPS: 1, resolution: 1, maxResolutionLevel: i2, forceCanvas: true }, mode: "local", interactive: false, useLocalCache: true })).setResource(t2, e2), [4, o2.getSlideCountAsync()];
34248
+ return o2 = document.createElement("div"), (s2 = new yT({ anchor: o2, renderOptions: { minFPS: 1, maxFPS: 1, resolution: 1, maxResolutionLevel: i2, forceCanvas: true }, mode: "local", interactive: false, useLocalCache: true })).setResource(t2, e2), [4, s2.getSlideCountAsync()];
34234
34249
  case 1:
34235
- s2 = l3.sent(), a3 = 1, l3.label = 2;
34250
+ a3 = c2.sent(), c2.label = 2;
34236
34251
  case 2:
34237
- return a3 <= s2 ? [4, o2.player.stagePool.preload(a3, true)] : [3, 5];
34252
+ if (c2.trys.push([2, 12, 13, 14]), !(r2 && r2.length > 0)) return [3, 7];
34253
+ l3 = r2.filter(function(t3, e3) {
34254
+ return r2.indexOf(t3) === e3;
34255
+ }), u2 = 0, c2.label = 3;
34238
34256
  case 3:
34239
- l3.sent(), n2(Math.round(a3 / s2 * 100) / 100), l3.label = 4;
34257
+ return u2 < l3.length ? (h2 = l3[u2]) > 0 && h2 <= a3 ? [4, s2.player.stagePool.preload(h2, true)] : [3, 5] : [3, 6];
34240
34258
  case 4:
34241
- return a3++, [3, 2];
34259
+ c2.sent(), n2(Math.round((u2 + 1) / l3.length * 100) / 100), c2.label = 5;
34242
34260
  case 5:
34243
- return o2.destroy(), [2];
34261
+ return u2++, [3, 3];
34262
+ case 6:
34263
+ return [3, 11];
34264
+ case 7:
34265
+ u2 = 1, c2.label = 8;
34266
+ case 8:
34267
+ return u2 <= a3 ? [4, s2.player.stagePool.preload(u2, true)] : [3, 11];
34268
+ case 9:
34269
+ c2.sent(), n2(Math.round(u2 / a3 * 100) / 100), c2.label = 10;
34270
+ case 10:
34271
+ return u2++, [3, 8];
34272
+ case 11:
34273
+ return [3, 14];
34274
+ case 12:
34275
+ throw c2.sent();
34276
+ case 13:
34277
+ return s2.destroy(), [7];
34278
+ case 14:
34279
+ return [2];
34244
34280
  }
34245
34281
  });
34246
34282
  });
@@ -34376,7 +34412,7 @@ void main(void){
34376
34412
  }
34377
34413
  var mT = { syncDispatch: "syncDispatch", syncReceive: "syncReceive", syncEventLag: "syncEventLag", renderStart: "renderStart", renderEnd: "renderEnd", renderError: "renderError", slideChange: "slideChange", mainSeqStepStart: "mainSeqStepStart", mainSeqStepEnd: "mainSeqStepEnd", animateStart: "animateStart", animateEnd: "animateEnd", stateChange: "stateChange", slideStepEnd: "slideEnd", slideStepStart: "slideStart" }, gT = { taskId: "", url: "", currentSlideIndex: -1, mainSeqStep: -1, mainSeqState: null, mediaState: /* @__PURE__ */ Object.create(null), interactiveSeqState: /* @__PURE__ */ Object.create(null) }, vT = "";
34378
34414
  try {
34379
- vT = "1.4.14";
34415
+ vT = "1.4.20";
34380
34416
  } catch (t2) {
34381
34417
  vT = "dev";
34382
34418
  }
@@ -34395,7 +34431,7 @@ void main(void){
34395
34431
  return n3.frameResizeHandler();
34396
34432
  }), n3.timestamp = function() {
34397
34433
  return Date.now();
34398
- }, n3.mode = "local", n3.enableGlobalClick = false, n3.lastEmitedState = null, n3.playerController = null, n3.isInitResized = false, n3.cacheImage = document.createElement("img"), n3.isTouchStart = false, n3.touchStartId = void 0, n3.taskId = "", n3.volumeAdjuster = new Hy(), n3.designWidth = 0, n3.designHeight = 0, n3._slideCount = 0, n3._dispatchIncrId = 0, n3._receiveIncrId = 0, n3.resizeView = Ky()(n3._resizeView.bind(n3), 50), n3.handleViewClick = Ky()(n3._handleViewClick.bind(n3), 300), n3.resourceList = [], n3._updateVolumeByStaticAdjuster = function(t3) {
34434
+ }, n3.mode = "local", n3.enableGlobalClick = false, n3.lastEmitedState = null, n3.playerController = null, n3.isInitResized = false, n3.cacheImage = document.createElement("img"), n3.isTouchStart = false, n3.touchStartId = void 0, n3.taskId = "", n3.volumeAdjuster = new Hy(), n3.designWidth = 0, n3.designHeight = 0, n3._slideCount = 0, n3._dispatchIncrId = 0, n3._receiveIncrId = 0, n3.resizeView = Ky()(n3._resizeView.bind(n3), 50), n3.handleViewClick = Ky()(n3._handleViewClick.bind(n3), 300, { leading: true }), n3.resourceList = [], n3._updateVolumeByStaticAdjuster = function(t3) {
34399
34435
  n3.volumeAdjuster.volume = t3;
34400
34436
  }, n3.recoverHandler = function(t3) {
34401
34437
  if ("@slide/_recover_" === t3.data.type && t3.data.slideId === n3.randomId) {
@@ -34577,7 +34613,7 @@ void main(void){
34577
34613
  return o2.setInteractive(this.interactive), o2.updateConfig(t3.renderOptions || {}), o2.on(Vy.renderStart, function(t4) {
34578
34614
  r2.isLoading = true, r2.emit(mT.renderStart, t4), window.postMessage({ type: "@slide/_render_start_", taskId: r2.taskId, index: t4 }, "*");
34579
34615
  }), o2.on(Vy.renderEnd, function(t4) {
34580
- r2.isLoading = false, r2.player && (r2.designHeight = r2.player.designHeight, r2.designWidth = r2.player.designWidth, r2.cacheImage.style.width = r2.player.designWidth + "px", r2.cacheImage.style.height = r2.player.designHeight + "px", r2._slideCount = r2.player.slideCount), r2.emit(mT.renderEnd, t4), window.postMessage({ type: "@slide/_render_end_", taskId: r2.taskId, index: t4 }, "*");
34616
+ r2.isLoading = false, r2.player && (r2.designHeight = r2.player.designHeight, r2.designWidth = r2.player.designWidth, r2.cacheImage.style.width = r2.player.designWidth + "px", r2.cacheImage.style.height = r2.player.designHeight + "px", r2.cacheImage.style.maxWidth = r2.player.designWidth + "px", r2.cacheImage.style.minWidth = r2.player.designHeight + "px", r2._slideCount = r2.player.slideCount), r2.emit(mT.renderEnd, t4), window.postMessage({ type: "@slide/_render_end_", taskId: r2.taskId, index: t4 }, "*");
34581
34617
  }), o2.on(Vy.slideChange, function(t4) {
34582
34618
  r2.__slideState.currentSlideIndex = t4, r2.emitStateChange(), r2.emit(mT.slideChange, t4);
34583
34619
  }), o2.on(Vy.mainSeqStateChange, function(t4) {
@@ -35105,22 +35141,27 @@ void main(void){
35105
35141
  }(Za.a);
35106
35142
  null == _T || _T.clear().catch(function() {
35107
35143
  }), window.addEventListener("__slide_log__", yT.handleLogDownload), window.addEventListener("message", function(t2) {
35144
+ var e2;
35108
35145
  if ("@slide/_request_log_" === t2.data.type) yT.handleLogReport(t2.data.sessionId).catch(function() {
35109
35146
  });
35110
35147
  else if ("@slide/_request_frozen_" === t2.data.type) yT.handleFrozenAllSlide();
35111
35148
  else if ("@slide/_request_release_" === t2.data.type) yT.handleReleaseAllSlide();
35112
35149
  else if ("@slide/_update_volume_" === t2.data.type) {
35113
- var e2 = 0.5;
35150
+ var i2 = 0.5;
35114
35151
  try {
35115
- e2 = parseFloat(t2.data.volume.toString());
35152
+ i2 = parseFloat(t2.data.volume.toString());
35116
35153
  } catch (t3) {
35117
35154
  }
35118
- yT.volumeAdjuster.volume = e2;
35119
- } else "@slide/_get_volume_" === t2.data.type ? window.postMessage({ type: "@slide/_report_volume_", volume: yT.volumeAdjuster.volume, customMessage: "@slide/_report_volume_" }, "*") : "@slide/_preload_slide_" === t2.data.type && yT.preloadResource(t2.data.taskId, t2.data.prefix, t2.data.maxResolutionLevel, function(e3) {
35120
- window.postMessage({ type: "@slide/_preload_slide_progress_", taskId: t2.data.taskId, progress: e3 }, "*");
35121
- }).catch(function(e3) {
35122
- window.postMessage({ type: "@slide/_preload_slide_error_", taskId: t2.data.taskId, error: e3 }, "*");
35123
- });
35155
+ yT.volumeAdjuster.volume = i2;
35156
+ } else if ("@slide/_get_volume_" === t2.data.type) window.postMessage({ type: "@slide/_report_volume_", volume: yT.volumeAdjuster.volume, customMessage: "@slide/_report_volume_" }, "*");
35157
+ else if ("@slide/_preload_slide_" === t2.data.type) {
35158
+ var n2 = null !== (e2 = t2.data.sessionId) && void 0 !== e2 ? e2 : Math.random().toString(32).substr(2);
35159
+ yT.preloadResource(t2.data.taskId, t2.data.prefix, t2.data.maxResolutionLevel, function(e3) {
35160
+ window.postMessage({ type: "@slide/_preload_slide_progress_", sessionId: n2, taskId: t2.data.taskId, progress: e3 }, "*");
35161
+ }, t2.data.pages).catch(function(e3) {
35162
+ window.postMessage({ type: "@slide/_preload_slide_error_", sessionId: n2, taskId: t2.data.taskId, error: e3 }, "*");
35163
+ });
35164
+ }
35124
35165
  }), window.setInterval(function() {
35125
35166
  yT.flushLog().catch(function() {
35126
35167
  });
@@ -35130,38 +35171,47 @@ void main(void){
35130
35171
  });
35131
35172
 
35132
35173
  // ../whiteboard/dist/whiteboard.esm.js
35133
- import { AbstractApplication, log as log3 } from "@netless/forge-room";
35174
+ import { AbstractApplication, log as log4 } from "@netless/forge-room";
35134
35175
  import * as Y15 from "yjs";
35135
35176
  import * as Y12 from "yjs";
35136
- import EventEmitter2 from "eventemitter3";
35177
+ import EventEmitter from "eventemitter3";
35137
35178
  import { v4 as uuidv4 } from "uuid";
35179
+ import { log, removeObserver as removeObserver2 } from "@netless/forge-room";
35138
35180
  import * as Y2 from "yjs";
35139
35181
  import * as Y from "yjs";
35182
+ import { removeDeepObserver } from "@netless/forge-room";
35140
35183
  import * as Y3 from "yjs";
35141
35184
  import * as Y4 from "yjs";
35142
35185
  import * as Y5 from "yjs";
35143
35186
  import * as Y6 from "yjs";
35187
+ import { removeObserver } from "@netless/forge-room";
35144
35188
  import * as Y7 from "yjs";
35145
35189
  import * as Y8 from "yjs";
35146
35190
  import * as Y9 from "yjs";
35147
35191
  import * as Y10 from "yjs";
35148
- import EventEmitter from "eventemitter3";
35192
+ import { AbstractApplicationPermissions } from "@netless/forge-room";
35149
35193
  import * as Y11 from "yjs";
35150
- import EventEmitter3 from "eventemitter3";
35194
+ import EventEmitter2 from "eventemitter3";
35195
+ import { removeObserver as removeObserver3 } from "@netless/forge-room";
35151
35196
  import * as Y13 from "yjs";
35152
- import EventEmitter4 from "eventemitter3";
35197
+ import EventEmitter3 from "eventemitter3";
35198
+ import { removeDeepObserver as removeDeepObserver2 } from "@netless/forge-room";
35199
+ import EventEmitter5 from "eventemitter3";
35200
+ import { EventEmitter as EventEmitter4 } from "eventemitter3";
35201
+ import EventEmitter7 from "eventemitter3";
35153
35202
  import EventEmitter6 from "eventemitter3";
35154
- import { EventEmitter as EventEmitter5 } from "eventemitter3";
35203
+ import { removeObserver as removeObserver4 } from "@netless/forge-room";
35155
35204
  import EventEmitter8 from "eventemitter3";
35156
- import EventEmitter7 from "eventemitter3";
35157
- import EventEmitter9 from "eventemitter3";
35158
35205
  import * as Y14 from "yjs";
35206
+ import EventEmitter9 from "eventemitter3";
35207
+ import { removeDeepObserver as removeDeepObserver3 } from "@netless/forge-room";
35159
35208
  import EventEmitter10 from "eventemitter3";
35209
+ import { log as log2, removeObserver as removeObserver5 } from "@netless/forge-room";
35160
35210
  import EventEmitter11 from "eventemitter3";
35161
- import { log } from "@netless/forge-room";
35211
+ import { log as log3 } from "@netless/forge-room";
35212
+ import { removeObserver as removeObserver6 } from "@netless/forge-room";
35162
35213
  import EventEmitter12 from "eventemitter3";
35163
- import { log as log2 } from "@netless/forge-room";
35164
- import EventEmitter13 from "eventemitter3";
35214
+ import { removeObserver as removeObserver7 } from "@netless/forge-room";
35165
35215
  var __create2 = Object.create;
35166
35216
  var __defProp2 = Object.defineProperty;
35167
35217
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -58936,7 +58986,7 @@ var require_lodash = __commonJS2({
58936
58986
  var defer = baseRest(function(func, args) {
58937
58987
  return baseDelay(func, 1, args);
58938
58988
  });
58939
- var delay22 = baseRest(function(func, wait, args) {
58989
+ var delay2 = baseRest(function(func, wait, args) {
58940
58990
  return baseDelay(func, toNumber(wait) || 0, args);
58941
58991
  });
58942
58992
  function flip(func) {
@@ -60050,7 +60100,7 @@ var require_lodash = __commonJS2({
60050
60100
  lodash.defaults = defaults;
60051
60101
  lodash.defaultsDeep = defaultsDeep;
60052
60102
  lodash.defer = defer;
60053
- lodash.delay = delay22;
60103
+ lodash.delay = delay2;
60054
60104
  lodash.difference = difference;
60055
60105
  lodash.differenceBy = differenceBy;
60056
60106
  lodash.differenceWith = differenceWith;
@@ -60741,11 +60791,12 @@ var ElementModel = class _ElementModel {
60741
60791
  set shadow(value) {
60742
60792
  this.root.set(_ElementModel.KEYS.shadow, value);
60743
60793
  }
60744
- constructor(root, scope) {
60794
+ constructor(root, scope, liveCursor) {
60745
60795
  _defineProperty(this, "shadowEmitter", null);
60746
60796
  _defineProperty(this, "root", void 0);
60747
60797
  _defineProperty(this, "scope", void 0);
60748
60798
  _defineProperty(this, "item", void 0);
60799
+ _defineProperty(this, "liveCursor", void 0);
60749
60800
  _defineProperty(this, "handlePropChange", (events) => {
60750
60801
  if (!this.item) {
60751
60802
  return;
@@ -60754,7 +60805,7 @@ var ElementModel = class _ElementModel {
60754
60805
  if (event.target === this.root) {
60755
60806
  const updatePaperItemKeys = this.vectorKeys().concat([_ElementModel.KEYS.pointsMatrix]);
60756
60807
  for (const [key, value] of event.changes.keys.entries()) {
60757
- if (value.action === "update") {
60808
+ if (value.action === "update" || value.action == "add") {
60758
60809
  const includeKeys = this.styleKeys().include;
60759
60810
  if (includeKeys.indexOf(key) >= 0) {
60760
60811
  this.onStyleKeyUpdate(key);
@@ -60774,6 +60825,10 @@ var ElementModel = class _ElementModel {
60774
60825
  if (this.shadow !== "") {
60775
60826
  this.shadowEmitter?.emit("translateIn", [this.uuid], this.shadow);
60776
60827
  } else {
60828
+ const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
60829
+ if (ownerId) {
60830
+ this.liveCursor.updateCursorVisible(false, ownerId);
60831
+ }
60777
60832
  this.shadowEmitter?.emit("translateOut", [this.uuid], value.oldValue);
60778
60833
  }
60779
60834
  }
@@ -60781,11 +60836,17 @@ var ElementModel = class _ElementModel {
60781
60836
  }
60782
60837
  } else if (event.target === this.root.get(_ElementModel.KEYS.points)) {
60783
60838
  this.onVectorUpdate();
60839
+ const liveCursorPoint = this.liveCursorPoint();
60840
+ const ownerId = this.root.get(_ElementModel.KEYS.ownerId);
60841
+ if (liveCursorPoint && ownerId) {
60842
+ this.liveCursor.updateCursorPosition(liveCursorPoint, this.root.get(_ElementModel.KEYS.ownerId));
60843
+ }
60784
60844
  } else {
60785
60845
  }
60786
60846
  }
60787
60847
  });
60788
60848
  this.scope = scope;
60849
+ this.liveCursor = liveCursor;
60789
60850
  this.root = root;
60790
60851
  if (!this.root.has(_ElementModel.KEYS.pointsMatrix)) {
60791
60852
  this.root.set(_ElementModel.KEYS.pointsMatrix, [1, 0, 0, 1, 0, 0]);
@@ -60843,6 +60904,10 @@ var ElementModel = class _ElementModel {
60843
60904
  const ext = this.styleKeys();
60844
60905
  return Array.from(new Set(["dashArray", "strokeColor", "fillColor", "strokeWidth"].filter((v) => ext.exclude.indexOf(v) < 0).concat(ext.include)));
60845
60906
  }
60907
+ dispose() {
60908
+ this.subDispose();
60909
+ removeDeepObserver(this.root, this.handlePropChange);
60910
+ }
60846
60911
  };
60847
60912
  _defineProperty(ElementModel, "KEYS", {
60848
60913
  index: "index",
@@ -60909,47 +60974,49 @@ function _toPrimitive3(t, r) {
60909
60974
  return ("string" === r ? String : Number)(t);
60910
60975
  }
60911
60976
  var CurveModel = class extends ElementModel {
60912
- constructor(root, scope) {
60913
- super(root, scope);
60977
+ constructor(root, scope, liveCursor) {
60978
+ super(root, scope, liveCursor);
60914
60979
  _defineProperty3(this, "item", null);
60980
+ _defineProperty3(this, "debugPath", void 0);
60981
+ _defineProperty3(this, "debug", false);
60915
60982
  if (!this.root.has("type")) {
60916
60983
  this.root.set("type", "curve");
60917
60984
  }
60918
60985
  if (!this.root.has("points")) {
60919
60986
  this.root.set("points", new Y2.Array());
60920
60987
  }
60988
+ this.debugPath = new scope.Path();
60921
60989
  }
60922
60990
  average(a2, b2) {
60923
60991
  return (a2 + b2) / 2;
60924
60992
  }
60925
60993
  parsePoints(points) {
60926
- const groupPoints = (0, import_lodash.chunk)(points, 2);
60927
- return ae(groupPoints, {
60994
+ return ae(points, {
60928
60995
  size: this.strokeWidth,
60929
- smoothing: 0,
60930
- thinning: 0.5,
60996
+ smoothing: 0.5,
60997
+ thinning: -0.5,
60931
60998
  streamline: 0.5,
60932
60999
  simulatePressure: true,
60933
61000
  start: {
60934
- taper: 10,
61001
+ taper: this.strokeWidth * 10,
60935
61002
  cap: true
60936
61003
  },
60937
61004
  end: {
60938
- taper: 10,
61005
+ taper: this.strokeWidth * 20,
60939
61006
  cap: true
60940
61007
  }
60941
61008
  });
60942
61009
  }
60943
61010
  matrixedPoints() {
60944
- const groupPoints = (0, import_lodash.chunk)(this.points, 2);
60945
- return groupPoints.map((_ref) => {
60946
- let [x, y] = _ref;
60947
- return new this.scope.Point(x, y);
60948
- }).map((p) => p.transform(new this.scope.Matrix(this.pointsMatrix))).reduce((result, next) => {
60949
- result.push(next.x);
60950
- result.push(next.y);
60951
- return result;
60952
- }, []);
61011
+ const points = this.points;
61012
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
61013
+ const output = [];
61014
+ for (let i = 0, len = points.length; i < len; i += 2) {
61015
+ const p = new this.scope.Point(points[i], points[i + 1]);
61016
+ const tp = p.transform(matrix);
61017
+ output.push([tp.x, tp.y]);
61018
+ }
61019
+ return output;
60953
61020
  }
60954
61021
  createPath(points) {
60955
61022
  const path = new this.scope.Path();
@@ -60976,27 +61043,41 @@ var CurveModel = class extends ElementModel {
60976
61043
  }
60977
61044
  return path;
60978
61045
  }
60979
- getNextSegments() {
60980
- const points = this.parsePoints(this.matrixedPoints());
60981
- const path = this.createPath(points);
60982
- return path.segments;
61046
+ updateDebugPath() {
61047
+ this.debugPath = new this.scope.Path();
61048
+ const points = (0, import_lodash.chunk)(this.points, 2);
61049
+ for (let i = 0, len = points.length; i < len; i++) {
61050
+ const point = new this.scope.Point(points[i][0], points[i][1]);
61051
+ if (i === 0) {
61052
+ this.debugPath.moveTo(point);
61053
+ } else {
61054
+ this.debugPath.lineTo(point);
61055
+ }
61056
+ this.debugPath.strokeWidth = 1;
61057
+ this.debugPath.strokeColor = new this.scope.Color(1, 0, 0, 1);
61058
+ }
60983
61059
  }
60984
61060
  onVectorUpdate() {
60985
61061
  if (!this.item) {
60986
61062
  return;
60987
61063
  }
61064
+ if (this.debug) {
61065
+ this.debugPath.remove();
61066
+ this.updateDebugPath();
61067
+ }
61068
+ const points = this.parsePoints(this.matrixedPoints());
61069
+ const path = this.createPath(points);
60988
61070
  this.item.removeSegments();
60989
- this.item.addSegments(this.getNextSegments());
60990
- this.item.simplify(2.5);
61071
+ this.item.addSegments(path.segments);
61072
+ if (this.debug) {
61073
+ this.item.addChild(this.debugPath);
61074
+ }
60991
61075
  }
60992
61076
  createPaperItem() {
60993
61077
  this.item = new this.scope.Path();
60994
- this.item.strokeCap = "round";
60995
- this.item.strokeJoin = "round";
60996
- this.item.strokeScaling = false;
60997
61078
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
60998
61079
  this.item.fillColor = new this.scope.Color(this.strokeColor);
60999
- this.item.addSegments(this.getNextSegments());
61080
+ this.onVectorUpdate();
61000
61081
  }
61001
61082
  editorConfig() {
61002
61083
  return new EditorConfig();
@@ -61006,10 +61087,19 @@ var CurveModel = class extends ElementModel {
61006
61087
  }
61007
61088
  styleKeys() {
61008
61089
  return {
61009
- include: ["strokeColor"],
61010
- exclude: ["fillColor", "dashArray"]
61090
+ include: ["strokeColor", "strokeWidth"],
61091
+ exclude: ["dashArray", "fillColor"]
61011
61092
  };
61012
61093
  }
61094
+ liveCursorPoint() {
61095
+ const yArray = this.root.get(ElementModel.KEYS.points);
61096
+ if (yArray.length < 2) {
61097
+ return null;
61098
+ }
61099
+ const len = yArray.length;
61100
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
61101
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
61102
+ }
61013
61103
  onStyleKeyUpdate(key) {
61014
61104
  if (!this.item) {
61015
61105
  return;
@@ -61017,8 +61107,12 @@ var CurveModel = class extends ElementModel {
61017
61107
  if (key === "strokeColor") {
61018
61108
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
61019
61109
  this.item.fillColor = new this.scope.Color(this.strokeColor);
61110
+ } else if (key === "strokeWidth") {
61111
+ this.onVectorUpdate();
61020
61112
  }
61021
61113
  }
61114
+ subDispose() {
61115
+ }
61022
61116
  };
61023
61117
  function _defineProperty4(e, r, t) {
61024
61118
  return (r = _toPropertyKey4(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -61038,8 +61132,8 @@ function _toPrimitive4(t, r) {
61038
61132
  return ("string" === r ? String : Number)(t);
61039
61133
  }
61040
61134
  var SelectorModel = class extends ElementModel {
61041
- constructor(root, scope) {
61042
- super(root, scope);
61135
+ constructor(root, scope, liveCursor) {
61136
+ super(root, scope, liveCursor);
61043
61137
  _defineProperty4(this, "item", null);
61044
61138
  if (!this.root.has("type")) {
61045
61139
  this.root.set("type", "selector");
@@ -61050,14 +61144,15 @@ var SelectorModel = class extends ElementModel {
61050
61144
  this.root.set("points", initPoints);
61051
61145
  }
61052
61146
  }
61147
+ liveCursorPoint() {
61148
+ return null;
61149
+ }
61150
+ subDispose() {
61151
+ }
61053
61152
  createPaperRect() {
61054
61153
  const scope = this.scope;
61055
61154
  const bounds = new scope.Rectangle(new scope.Point(this.points[0], this.points[1]), new scope.Size(this.points[2], this.points[3]));
61056
- return new scope.Path.Rectangle(
61057
- bounds,
61058
- new scope.Point(this.points[4], this.points[4])
61059
- // 圆角
61060
- );
61155
+ return new scope.Path.Rectangle(bounds, new scope.Point(this.points[4], this.points[4]));
61061
61156
  }
61062
61157
  onVectorUpdate() {
61063
61158
  if (!this.item) {
@@ -61083,7 +61178,7 @@ var SelectorModel = class extends ElementModel {
61083
61178
  exclude: []
61084
61179
  };
61085
61180
  }
61086
- onStyleKeyUpdate(key) {
61181
+ onStyleKeyUpdate(_key) {
61087
61182
  }
61088
61183
  };
61089
61184
  var import_lodash2 = __toESM2(require_lodash(), 1);
@@ -61130,7 +61225,7 @@ var AnimationFrame = class {
61130
61225
  _defineProperty5(this, "lastTime", 0);
61131
61226
  _defineProperty5(this, "fps", 45);
61132
61227
  _defineProperty5(this, "handleCallbacks", () => {
61133
- let functions = this.callbacks;
61228
+ const functions = this.callbacks;
61134
61229
  this.callbacks = [];
61135
61230
  for (let i = 0, l2 = functions.length; i < l2; i++) {
61136
61231
  functions[i]();
@@ -61171,8 +61266,8 @@ function _toPrimitive6(t, r) {
61171
61266
  return ("string" === r ? String : Number)(t);
61172
61267
  }
61173
61268
  var SegmentsModel = class extends ElementModel {
61174
- constructor(root, scope, type) {
61175
- super(root, scope);
61269
+ constructor(root, scope, type, liveCursor) {
61270
+ super(root, scope, liveCursor);
61176
61271
  _defineProperty6(this, "item", null);
61177
61272
  if (!this.root.has("type")) {
61178
61273
  this.root.set("type", type);
@@ -61181,6 +61276,16 @@ var SegmentsModel = class extends ElementModel {
61181
61276
  this.root.set("points", new Y4.Array());
61182
61277
  }
61183
61278
  }
61279
+ subDispose() {
61280
+ }
61281
+ liveCursorPoint() {
61282
+ const yArray = this.root.get(ElementModel.KEYS.points);
61283
+ if (yArray.length < 2) {
61284
+ return null;
61285
+ }
61286
+ const point = new this.scope.Point(yArray.get(0), yArray.get(1));
61287
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
61288
+ }
61184
61289
  onVectorUpdate() {
61185
61290
  if (!this.item) {
61186
61291
  return;
@@ -61215,7 +61320,7 @@ var SegmentsModel = class extends ElementModel {
61215
61320
  exclude: []
61216
61321
  };
61217
61322
  }
61218
- onStyleKeyUpdate(key) {
61323
+ onStyleKeyUpdate(_key) {
61219
61324
  }
61220
61325
  };
61221
61326
  var import_lodash4 = __toESM2(require_lodash(), 1);
@@ -61299,9 +61404,13 @@ var LineTool = class extends WhiteboardTool {
61299
61404
  _defineProperty8(this, "elementModel", null);
61300
61405
  _defineProperty8(this, "from", null);
61301
61406
  _defineProperty8(this, "to", null);
61407
+ _defineProperty8(this, "showLiveCursor", true);
61302
61408
  this.tool.minDistance = 1;
61303
61409
  }
61304
61410
  onMouseDown(event) {
61411
+ if (this.elementModel) {
61412
+ this.elementModel.dispose();
61413
+ }
61305
61414
  this.elementModel = this.modelGetter().createLinePath(true);
61306
61415
  this.from = event.point.clone();
61307
61416
  this.to = event.point.clone();
@@ -61358,8 +61467,8 @@ var LineModel = class extends ElementModel {
61358
61467
  set tailArrow(value) {
61359
61468
  this.root.set("tailArrow", value);
61360
61469
  }
61361
- constructor(root, scope) {
61362
- super(root, scope);
61470
+ constructor(root, scope, liveCursor) {
61471
+ super(root, scope, liveCursor);
61363
61472
  _defineProperty9(this, "controlledPoints", []);
61364
61473
  _defineProperty9(this, "item", null);
61365
61474
  if (!this.root.has("type")) {
@@ -61375,6 +61484,8 @@ var LineModel = class extends ElementModel {
61375
61484
  this.root.set("tailArrow", "normal");
61376
61485
  }
61377
61486
  }
61487
+ subDispose() {
61488
+ }
61378
61489
  onVectorUpdate() {
61379
61490
  if (!this.item) {
61380
61491
  return;
@@ -61406,12 +61517,21 @@ var LineModel = class extends ElementModel {
61406
61517
  });
61407
61518
  return [head, path, tail];
61408
61519
  }
61520
+ liveCursorPoint() {
61521
+ const yArray = this.root.get(ElementModel.KEYS.points);
61522
+ if (yArray.length < 2) {
61523
+ return null;
61524
+ }
61525
+ const len = yArray.length;
61526
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
61527
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
61528
+ }
61409
61529
  createPaperItem() {
61410
61530
  this.item = new this.scope.Group();
61411
61531
  this.item.addChildren(this.renderLine());
61412
61532
  }
61413
61533
  createArrow(path) {
61414
- let [headPath, tailPath] = [new this.scope.Path(), new this.scope.Path()];
61534
+ const [headPath, tailPath] = [new this.scope.Path(), new this.scope.Path()];
61415
61535
  if (!path) {
61416
61536
  return [headPath, tailPath];
61417
61537
  }
@@ -61465,7 +61585,7 @@ var LineModel = class extends ElementModel {
61465
61585
  exclude: ["fillColor"]
61466
61586
  };
61467
61587
  }
61468
- onStyleKeyUpdate(key) {
61588
+ onStyleKeyUpdate(_key) {
61469
61589
  this.onVectorUpdate();
61470
61590
  }
61471
61591
  };
@@ -61553,8 +61673,8 @@ var PointTextModel = class extends ElementModel {
61553
61673
  set fontFamily(value) {
61554
61674
  this.root.set("font-family", value);
61555
61675
  }
61556
- constructor(root, scope) {
61557
- super(root, scope);
61676
+ constructor(root, scope, liveCursor) {
61677
+ super(root, scope, liveCursor);
61558
61678
  _defineProperty10(this, "item", null);
61559
61679
  _defineProperty10(this, "handleTextPropChange", (event) => {
61560
61680
  if (!this.item) {
@@ -61585,6 +61705,18 @@ var PointTextModel = class extends ElementModel {
61585
61705
  }, 60);
61586
61706
  }
61587
61707
  }
61708
+ subDispose() {
61709
+ removeObserver(this.root, this.handleTextPropChange);
61710
+ }
61711
+ liveCursorPoint() {
61712
+ const points = this.points;
61713
+ if (points.length < 1) {
61714
+ return null;
61715
+ }
61716
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
61717
+ const topLeft = new this.scope.Point(points[0], points[1]).transform(matrix);
61718
+ return topLeft;
61719
+ }
61588
61720
  getInternalMeasurement() {
61589
61721
  if (!this.item) {
61590
61722
  return null;
@@ -61677,8 +61809,8 @@ function _toPrimitive11(t, r) {
61677
61809
  return ("string" === r ? String : Number)(t);
61678
61810
  }
61679
61811
  var TriangleModel = class extends ElementModel {
61680
- constructor(root, scope) {
61681
- super(root, scope);
61812
+ constructor(root, scope, liveCursor) {
61813
+ super(root, scope, liveCursor);
61682
61814
  _defineProperty11(this, "item", null);
61683
61815
  if (!this.root.has("type")) {
61684
61816
  this.root.set("type", "triangle");
@@ -61687,6 +61819,17 @@ var TriangleModel = class extends ElementModel {
61687
61819
  this.root.set("points", new Y7.Array());
61688
61820
  }
61689
61821
  }
61822
+ liveCursorPoint() {
61823
+ const yArray = this.root.get(ElementModel.KEYS.points);
61824
+ if (yArray.length < 6) {
61825
+ return null;
61826
+ }
61827
+ const len = yArray.length;
61828
+ const point = new this.scope.Point(yArray.get(len - 4), yArray.get(len - 3));
61829
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
61830
+ }
61831
+ subDispose() {
61832
+ }
61690
61833
  createPaperItem() {
61691
61834
  this.item = new this.scope.Path();
61692
61835
  this.item.strokeCap = "butt";
@@ -61743,7 +61886,7 @@ var TriangleModel = class extends ElementModel {
61743
61886
  exclude: []
61744
61887
  };
61745
61888
  }
61746
- onStyleKeyUpdate(key) {
61889
+ onStyleKeyUpdate(_key) {
61747
61890
  }
61748
61891
  };
61749
61892
  function _defineProperty12(e, r, t) {
@@ -61764,8 +61907,8 @@ function _toPrimitive12(t, r) {
61764
61907
  return ("string" === r ? String : Number)(t);
61765
61908
  }
61766
61909
  var RectangleModel = class extends ElementModel {
61767
- constructor(root, scope) {
61768
- super(root, scope);
61910
+ constructor(root, scope, liveCursor) {
61911
+ super(root, scope, liveCursor);
61769
61912
  _defineProperty12(this, "item", null);
61770
61913
  if (!this.root.has("type")) {
61771
61914
  this.root.set("type", "rectangle");
@@ -61779,6 +61922,16 @@ var RectangleModel = class extends ElementModel {
61779
61922
  this.root.set("radius", 0);
61780
61923
  }
61781
61924
  }
61925
+ subDispose() {
61926
+ }
61927
+ liveCursorPoint() {
61928
+ const points = this.points;
61929
+ if (points.length < 4) {
61930
+ return null;
61931
+ }
61932
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
61933
+ return new this.scope.Point(points[2], points[3]).transform(matrix);
61934
+ }
61782
61935
  createSegments() {
61783
61936
  const [a2, b2, c, d] = this.points;
61784
61937
  const matrix = new this.scope.Matrix(this.pointsMatrix);
@@ -61910,7 +62063,7 @@ var RectangleModel = class extends ElementModel {
61910
62063
  exclude: []
61911
62064
  };
61912
62065
  }
61913
- onStyleKeyUpdate(key) {
62066
+ onStyleKeyUpdate(_key) {
61914
62067
  }
61915
62068
  };
61916
62069
  var elementsUndoOrigin = "elementsUndoOrigin";
@@ -61933,8 +62086,8 @@ function _toPrimitive13(t, r) {
61933
62086
  return ("string" === r ? String : Number)(t);
61934
62087
  }
61935
62088
  var EraserModel = class extends ElementModel {
61936
- constructor(root, scope) {
61937
- super(root, scope);
62089
+ constructor(root, scope, liveCursor) {
62090
+ super(root, scope, liveCursor);
61938
62091
  _defineProperty13(this, "item", null);
61939
62092
  _defineProperty13(this, "sliceBegin", 0);
61940
62093
  if (!this.root.has("type")) {
@@ -61973,14 +62126,189 @@ var EraserModel = class extends ElementModel {
61973
62126
  return path;
61974
62127
  }
61975
62128
  parsePoints(points) {
61976
- return ae(points, {
62129
+ const groupPoints = (0, import_lodash5.chunk)(points, 2);
62130
+ return ae(groupPoints, {
61977
62131
  size: this.strokeWidth,
62132
+ smoothing: 0.5,
62133
+ thinning: -0.5,
62134
+ streamline: 0.5,
62135
+ simulatePressure: true,
62136
+ start: {
62137
+ taper: this.strokeWidth * 10,
62138
+ cap: true
62139
+ },
62140
+ end: {
62141
+ taper: this.strokeWidth * 20,
62142
+ cap: true
62143
+ }
62144
+ });
62145
+ }
62146
+ matrixedPoints() {
62147
+ const currentPoints = (0, import_lodash5.chunk)(this.points, 2).slice(this.sliceBegin);
62148
+ return currentPoints.map((_ref) => {
62149
+ let [x, y] = _ref;
62150
+ return new this.scope.Point(x, y);
62151
+ }).map((p) => p.transform(new this.scope.Matrix(this.pointsMatrix))).reduce((result, next) => {
62152
+ result.push(next.x);
62153
+ result.push(next.y);
62154
+ return result;
62155
+ }, []);
62156
+ }
62157
+ onVectorUpdate() {
62158
+ if (!this.item) {
62159
+ return;
62160
+ }
62161
+ const points = this.parsePoints(this.matrixedPoints());
62162
+ const path = this.createPath(points);
62163
+ this.item.removeSegments();
62164
+ this.item.addSegments(path.segments);
62165
+ }
62166
+ createPaperItem() {
62167
+ this.item = new this.scope.Path();
62168
+ this.item.strokeCap = "round";
62169
+ this.item.strokeJoin = "round";
62170
+ this.item.strokeScaling = false;
62171
+ this.item.strokeColor = new this.scope.Color(this.strokeColor);
62172
+ this.item.fillColor = new this.scope.Color(this.strokeColor);
62173
+ this.onVectorUpdate();
62174
+ this.item.onFrame = () => {
62175
+ if (!this.points) {
62176
+ return;
62177
+ }
62178
+ if (this.points.length / 2 > 50) {
62179
+ this.sliceBegin = this.points.length / 2 - 50;
62180
+ }
62181
+ };
62182
+ }
62183
+ editorConfig() {
62184
+ return new EditorConfig();
62185
+ }
62186
+ vectorKeys() {
62187
+ return [];
62188
+ }
62189
+ styleKeys() {
62190
+ return {
62191
+ include: [],
62192
+ exclude: []
62193
+ };
62194
+ }
62195
+ onStyleKeyUpdate(_key) {
62196
+ return;
62197
+ }
62198
+ subDispose() {
62199
+ }
62200
+ liveCursorPoint() {
62201
+ const yArray = this.root.get(ElementModel.KEYS.points);
62202
+ if (yArray.length < 2) {
62203
+ return null;
62204
+ }
62205
+ const len = yArray.length;
62206
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
62207
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
62208
+ }
62209
+ };
62210
+ var import_lodash6 = __toESM2(require_lodash(), 1);
62211
+ function _defineProperty14(e, r, t) {
62212
+ return (r = _toPropertyKey14(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62213
+ }
62214
+ function _toPropertyKey14(t) {
62215
+ var i = _toPrimitive14(t, "string");
62216
+ return "symbol" == typeof i ? i : i + "";
62217
+ }
62218
+ function _toPrimitive14(t, r) {
62219
+ if ("object" != typeof t || !t) return t;
62220
+ var e = t[Symbol.toPrimitive];
62221
+ if (void 0 !== e) {
62222
+ var i = e.call(t, r || "default");
62223
+ if ("object" != typeof i) return i;
62224
+ throw new TypeError("@@toPrimitive must return a primitive value.");
62225
+ }
62226
+ return ("string" === r ? String : Number)(t);
62227
+ }
62228
+ var LaserPointerModel = class extends ElementModel {
62229
+ constructor(clientId, root, scope, liveCursor, removeElement) {
62230
+ super(root, scope, liveCursor);
62231
+ _defineProperty14(this, "item", null);
62232
+ _defineProperty14(this, "clientId", void 0);
62233
+ _defineProperty14(this, "sliceBegin", 0);
62234
+ _defineProperty14(this, "displayStrokeWidth", 8);
62235
+ _defineProperty14(this, "cachedPoints", null);
62236
+ this.clientId = clientId;
62237
+ if (!this.root.has("type")) {
62238
+ this.root.set("type", "laser");
62239
+ }
62240
+ if (!this.root.has("points")) {
62241
+ this.root.set("points", new Y10.Array());
62242
+ }
62243
+ if (!this.root.has("removed")) {
62244
+ this.root.set("removed", false);
62245
+ }
62246
+ this.root.observe((event) => {
62247
+ if (!this.item) {
62248
+ return;
62249
+ }
62250
+ for (const [key] of event.changes.keys.entries()) {
62251
+ if (key === "removed") {
62252
+ if (this.cachedPoints == null) {
62253
+ this.cachedPoints = this.points;
62254
+ }
62255
+ this.item.onFrame = (evt) => {
62256
+ this.displayStrokeWidth = Math.max(0.1, this.displayStrokeWidth -= 8 / 30);
62257
+ if (evt.count >= 20) {
62258
+ const points = this.cachedPoints || this.points;
62259
+ this.sliceBegin += Math.ceil(points.length / 2 / 20);
62260
+ }
62261
+ this.onVectorUpdate();
62262
+ if (evt.count >= 30) {
62263
+ if (this.ownerId === this.clientId) {
62264
+ removeElement(this.uuid);
62265
+ }
62266
+ }
62267
+ };
62268
+ }
62269
+ }
62270
+ });
62271
+ }
62272
+ beginRemoveAnimate() {
62273
+ this.root.set("removed", true);
62274
+ }
62275
+ average(a2, b2) {
62276
+ return (a2 + b2) / 2;
62277
+ }
62278
+ createPath(points) {
62279
+ const path = new this.scope.Path();
62280
+ const len = points.length;
62281
+ if (len < 4) {
62282
+ return path;
62283
+ }
62284
+ let control = new this.scope.Point(0, 0);
62285
+ let current = new this.scope.Point(0, 0);
62286
+ let a2 = points[0];
62287
+ let b2 = points[1];
62288
+ const c = points[2];
62289
+ current = new this.scope.Point(a2[0], a2[1]);
62290
+ path.moveTo(current);
62291
+ control = new this.scope.Point(b2[0], b2[1]);
62292
+ current = new this.scope.Point(this.average(b2[0], c[0]), this.average(b2[1], c[1]));
62293
+ path.quadraticCurveTo(control, current);
62294
+ for (let i = 2, max = len - 1; i < max; i++) {
62295
+ a2 = points[i];
62296
+ b2 = points[i + 1];
62297
+ control = current.multiply(2).subtract(control);
62298
+ current = new this.scope.Point(this.average(a2[0], b2[0]), this.average(a2[1], b2[1]));
62299
+ path.quadraticCurveTo(control, current);
62300
+ }
62301
+ return path;
62302
+ }
62303
+ parsePoints(points) {
62304
+ return ae(points, {
62305
+ size: this.displayStrokeWidth,
61978
62306
  smoothing: 0,
61979
62307
  thinning: 0.5,
61980
- streamline: 0.5,
62308
+ streamline: 0,
61981
62309
  simulatePressure: true,
61982
62310
  start: {
61983
- taper: true,
62311
+ taper: 0,
61984
62312
  cap: true
61985
62313
  },
61986
62314
  end: {
@@ -61991,7 +62319,8 @@ var EraserModel = class extends ElementModel {
61991
62319
  }
61992
62320
  matrixedPoints() {
61993
62321
  const matrix = new this.scope.Matrix(this.pointsMatrix);
61994
- const groupPoints = (0, import_lodash5.chunk)(this.points, 2).slice(this.sliceBegin);
62322
+ const points = this.cachedPoints || this.points;
62323
+ const groupPoints = (0, import_lodash6.chunk)(points, 2).slice(this.sliceBegin);
61995
62324
  return groupPoints.map((_ref) => {
61996
62325
  let [x, y] = _ref;
61997
62326
  return matrix.transform([x, y]);
@@ -62017,22 +62346,6 @@ var EraserModel = class extends ElementModel {
62017
62346
  this.item.strokeColor = new this.scope.Color(this.strokeColor);
62018
62347
  this.item.fillColor = new this.scope.Color(this.strokeColor);
62019
62348
  this.item.addSegments(this.getNextSegments());
62020
- let isBegin = false;
62021
- this.item.onFrame = () => {
62022
- if (!this.points) {
62023
- return;
62024
- }
62025
- if (this.points.length / 2 - this.sliceBegin >= 10 && !isBegin) {
62026
- isBegin = true;
62027
- }
62028
- if (this.points.length / 2 <= this.sliceBegin) {
62029
- isBegin = false;
62030
- }
62031
- if (isBegin) {
62032
- this.sliceBegin += 1;
62033
- this.onVectorUpdate();
62034
- }
62035
- };
62036
62349
  }
62037
62350
  editorConfig() {
62038
62351
  return new EditorConfig();
@@ -62046,183 +62359,21 @@ var EraserModel = class extends ElementModel {
62046
62359
  exclude: []
62047
62360
  };
62048
62361
  }
62049
- onStyleKeyUpdate(key) {
62362
+ onStyleKeyUpdate(_key) {
62050
62363
  return;
62051
62364
  }
62052
- };
62053
- var import_lodash6 = __toESM2(require_lodash(), 1);
62054
- function _defineProperty14(e, r, t) {
62055
- return (r = _toPropertyKey14(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62056
- }
62057
- function _toPropertyKey14(t) {
62058
- var i = _toPrimitive14(t, "string");
62059
- return "symbol" == typeof i ? i : i + "";
62060
- }
62061
- function _toPrimitive14(t, r) {
62062
- if ("object" != typeof t || !t) return t;
62063
- var e = t[Symbol.toPrimitive];
62064
- if (void 0 !== e) {
62065
- var i = e.call(t, r || "default");
62066
- if ("object" != typeof i) return i;
62067
- throw new TypeError("@@toPrimitive must return a primitive value.");
62068
- }
62069
- return ("string" === r ? String : Number)(t);
62070
- }
62071
- var LaserPointerModel = class extends ElementModel {
62072
- constructor(clientId, root, scope, removeElement) {
62073
- super(root, scope);
62074
- _defineProperty14(this, "item", null);
62075
- _defineProperty14(this, "clientId", void 0);
62076
- _defineProperty14(this, "sliceBegin", 0);
62077
- _defineProperty14(this, "displayStrokeWidth", 8);
62078
- _defineProperty14(this, "cachedPoints", null);
62079
- this.clientId = clientId;
62080
- if (!this.root.has("type")) {
62081
- this.root.set("type", "laser");
62082
- }
62083
- if (!this.root.has("points")) {
62084
- this.root.set("points", new Y10.Array());
62085
- }
62086
- if (!this.root.has("removed")) {
62087
- this.root.set("removed", false);
62088
- }
62089
- this.root.observe((event) => {
62090
- if (!this.item) {
62091
- return;
62092
- }
62093
- for (const [key] of event.changes.keys.entries()) {
62094
- if (key === "removed") {
62095
- if (this.cachedPoints == null) {
62096
- this.cachedPoints = this.points;
62097
- }
62098
- this.item.onFrame = (evt) => {
62099
- this.displayStrokeWidth = Math.max(0.1, this.displayStrokeWidth -= 8 / 30);
62100
- if (evt.count >= 20) {
62101
- const points = this.cachedPoints || this.points;
62102
- this.sliceBegin += Math.ceil(points.length / 2 / 20);
62103
- }
62104
- this.onVectorUpdate();
62105
- if (evt.count >= 30) {
62106
- if (this.ownerId === this.clientId) {
62107
- removeElement(this.uuid);
62108
- }
62109
- }
62110
- };
62111
- }
62112
- }
62113
- });
62114
- }
62115
- beginRemoveAnimate() {
62116
- this.root.set("removed", true);
62117
- }
62118
- average(a2, b2) {
62119
- return (a2 + b2) / 2;
62120
- }
62121
- createPath(points) {
62122
- const path = new this.scope.Path();
62123
- const len = points.length;
62124
- if (len < 4) {
62125
- return path;
62126
- }
62127
- let control = new this.scope.Point(0, 0);
62128
- let current = new this.scope.Point(0, 0);
62129
- let a2 = points[0];
62130
- let b2 = points[1];
62131
- const c = points[2];
62132
- current = new this.scope.Point(a2[0], a2[1]);
62133
- path.moveTo(current);
62134
- control = new this.scope.Point(b2[0], b2[1]);
62135
- current = new this.scope.Point(this.average(b2[0], c[0]), this.average(b2[1], c[1]));
62136
- path.quadraticCurveTo(control, current);
62137
- for (let i = 2, max = len - 1; i < max; i++) {
62138
- a2 = points[i];
62139
- b2 = points[i + 1];
62140
- control = current.multiply(2).subtract(control);
62141
- current = new this.scope.Point(this.average(a2[0], b2[0]), this.average(a2[1], b2[1]));
62142
- path.quadraticCurveTo(control, current);
62143
- }
62144
- return path;
62145
- }
62146
- parsePoints(points) {
62147
- return ae(points, {
62148
- size: this.displayStrokeWidth,
62149
- smoothing: 0,
62150
- thinning: 0.5,
62151
- streamline: 0,
62152
- simulatePressure: true,
62153
- start: {
62154
- taper: 0,
62155
- cap: true
62156
- },
62157
- end: {
62158
- taper: 0,
62159
- cap: true
62160
- }
62161
- });
62365
+ subDispose() {
62162
62366
  }
62163
- matrixedPoints() {
62164
- const matrix = new this.scope.Matrix(this.pointsMatrix);
62165
- const points = this.cachedPoints || this.points;
62166
- const groupPoints = (0, import_lodash6.chunk)(points, 2).slice(this.sliceBegin);
62167
- return groupPoints.map((_ref) => {
62168
- let [x, y] = _ref;
62169
- return matrix.transform([x, y]);
62170
- }).map((p) => [p.x, p.y]);
62171
- }
62172
- getNextSegments() {
62173
- const points = this.parsePoints(this.matrixedPoints());
62174
- const path = this.createPath(points);
62175
- return path.segments;
62176
- }
62177
- onVectorUpdate() {
62178
- if (!this.item) {
62179
- return;
62367
+ liveCursorPoint() {
62368
+ const yArray = this.root.get(ElementModel.KEYS.points);
62369
+ if (yArray.length < 2) {
62370
+ return null;
62180
62371
  }
62181
- this.item.removeSegments();
62182
- this.item.addSegments(this.getNextSegments());
62183
- }
62184
- createPaperItem() {
62185
- this.item = new this.scope.Path();
62186
- this.item.strokeCap = "round";
62187
- this.item.strokeJoin = "round";
62188
- this.item.strokeScaling = false;
62189
- this.item.strokeColor = new this.scope.Color(this.strokeColor);
62190
- this.item.fillColor = new this.scope.Color(this.strokeColor);
62191
- this.item.addSegments(this.getNextSegments());
62192
- }
62193
- editorConfig() {
62194
- return new EditorConfig();
62195
- }
62196
- vectorKeys() {
62197
- return [];
62198
- }
62199
- styleKeys() {
62200
- return {
62201
- include: [],
62202
- exclude: []
62203
- };
62204
- }
62205
- onStyleKeyUpdate(key) {
62206
- return;
62372
+ const len = yArray.length;
62373
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
62374
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
62207
62375
  }
62208
62376
  };
62209
- function _defineProperty15(e, r, t) {
62210
- return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62211
- }
62212
- function _toPropertyKey15(t) {
62213
- var i = _toPrimitive15(t, "string");
62214
- return "symbol" == typeof i ? i : i + "";
62215
- }
62216
- function _toPrimitive15(t, r) {
62217
- if ("object" != typeof t || !t) return t;
62218
- var e = t[Symbol.toPrimitive];
62219
- if (void 0 !== e) {
62220
- var i = e.call(t, r || "default");
62221
- if ("object" != typeof i) return i;
62222
- throw new TypeError("@@toPrimitive must return a primitive value.");
62223
- }
62224
- return ("string" === r ? String : Number)(t);
62225
- }
62226
62377
  var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
62227
62378
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["none"] = 0] = "none";
62228
62379
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["draw"] = 1] = "draw";
@@ -62235,117 +62386,25 @@ var WhiteboardPermissionFlag = function(WhiteboardPermissionFlag2) {
62235
62386
  WhiteboardPermissionFlag2[WhiteboardPermissionFlag2["all"] = WhiteboardPermissionFlag2.draw | WhiteboardPermissionFlag2.editSelf | WhiteboardPermissionFlag2.editOthers | WhiteboardPermissionFlag2.deleteSelf | WhiteboardPermissionFlag2.deleteOthers | WhiteboardPermissionFlag2.mainView | WhiteboardPermissionFlag2.setOthersView] = "all";
62236
62387
  return WhiteboardPermissionFlag2;
62237
62388
  }({});
62238
- var WhiteboardPermissions = class extends EventEmitter {
62239
- constructor(userManager, requestUserMap) {
62240
- super();
62241
- _defineProperty15(this, "requestUserMap", void 0);
62242
- _defineProperty15(this, "userManager", void 0);
62243
- _defineProperty15(this, "observers", /* @__PURE__ */ new Map());
62244
- _defineProperty15(this, "handleUserLeave", (user) => {
62245
- const cb = this.observers.get(user.id);
62246
- if (cb) {
62247
- this.requestUserMap(user.id).unobserve(cb);
62248
- }
62249
- });
62250
- _defineProperty15(this, "handleUserJoin", (user) => {
62251
- this.addObserve(user.id);
62252
- });
62253
- this.userManager = userManager;
62254
- this.requestUserMap = requestUserMap;
62255
- this.createModel(this.userManager.selfId);
62256
- this.userManager.userIdList().forEach((userId) => {
62257
- this.addObserve(userId);
62258
- });
62259
- this.userManager.on("join", this.handleUserJoin);
62260
- this.userManager.on("leave", this.handleUserLeave);
62261
- }
62262
- addObserve(userId) {
62263
- if (this.observers.has(userId)) {
62264
- return;
62265
- }
62266
- const observer = (evt) => {
62267
- this.handleUserPermissionChange(userId, evt);
62268
- };
62269
- this.observers.set(userId, observer);
62270
- this.requestUserMap(userId).observe(observer);
62271
- }
62272
- createModel(userId) {
62273
- const userMap = this.requestUserMap(userId);
62274
- if (!userMap.has("permission")) {
62275
- userMap.set("permission", 0);
62276
- }
62277
- }
62278
- handleUserPermissionChange(userId, evt) {
62279
- for (const [key, value] of evt.changes.keys.entries()) {
62280
- if (key === "permission") {
62281
- if (value.action === "add" || value.action === "update") {
62282
- const newValue = this.requestUserMap(userId).get("permission");
62283
- this.emit("change", userId, this.resolveFlags(newValue), newValue);
62284
- }
62285
- }
62286
- }
62287
- }
62389
+ var WhiteboardPermissions = class extends AbstractApplicationPermissions {
62288
62390
  /**
62289
- * 解析权限列表组合
62290
- * @param {number} value - 权限数字值
62291
- * @return {WhiteboardPermissionFlag[]} - 权限列表
62292
- */
62391
+ * 解析权限列表组合
62392
+ * @param {number} value - 权限数字值
62393
+ * @return {WhiteboardPermissionFlag[]} - 权限列表
62394
+ */
62293
62395
  resolveFlags(value) {
62294
62396
  return [WhiteboardPermissionFlag.draw, WhiteboardPermissionFlag.editSelf, WhiteboardPermissionFlag.editOthers, WhiteboardPermissionFlag.deleteSelf, WhiteboardPermissionFlag.deleteOthers, WhiteboardPermissionFlag.mainView, WhiteboardPermissionFlag.setOthersView].filter((v) => (v & value) !== 0);
62295
62397
  }
62296
- /**
62297
- * 获取权限列表组合对应的数值
62298
- * @param { string } userId 不传表示获取自己
62299
- */
62300
- getPermissionValue(userId) {
62301
- return this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
62302
- }
62303
- /**
62304
- * 获取权限列表
62305
- * @param {string=} userId 可选, 不传表示获取自己
62306
- */
62307
- getPermissionFlags(userId) {
62308
- const value = this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
62309
- return this.resolveFlags(value);
62310
- }
62311
- /**
62312
- * 返回对应 userId 是否有相应权限
62313
- * @param {string=} userId 可选, 不传表示返回自己是否有相应权限
62314
- * @param {WhiteboardPermissionFlag} flag
62315
- */
62316
- hasPermission(flag, userId) {
62317
- return ((this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0) & flag) !== 0;
62318
- }
62319
- /**
62320
- * 添加权限
62321
- * @param {WhiteboardPermissionFlag} flag 权限标记
62322
- * @param {string=} userId 可选, 为 userId 添加权限, 不传表示为自己添加权限
62323
- */
62324
- addPermission(flag, userId) {
62325
- const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
62326
- const oldValue = userMap.get("permission") ?? 0;
62327
- this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue | flag);
62328
- }
62329
- /**
62330
- * 移除权限
62331
- * @param {WhiteboardPermissionFlag} flag 权限标记
62332
- * @param {string=} userId 可选, 为 userId 移除权限, 不传表示为自己移除权限
62333
- */
62334
- removePermission(flag, userId) {
62335
- const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
62336
- const oldValue = userMap.get("permission") ?? 0;
62337
- this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue & ~flag);
62338
- }
62339
62398
  };
62340
62399
  var import_lodash7 = __toESM2(require_lodash(), 1);
62341
- function _defineProperty16(e, r, t) {
62342
- return (r = _toPropertyKey16(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62400
+ function _defineProperty15(e, r, t) {
62401
+ return (r = _toPropertyKey15(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62343
62402
  }
62344
- function _toPropertyKey16(t) {
62345
- var i = _toPrimitive16(t, "string");
62403
+ function _toPropertyKey15(t) {
62404
+ var i = _toPrimitive15(t, "string");
62346
62405
  return "symbol" == typeof i ? i : i + "";
62347
62406
  }
62348
- function _toPrimitive16(t, r) {
62407
+ function _toPrimitive15(t, r) {
62349
62408
  if ("object" != typeof t || !t) return t;
62350
62409
  var e = t[Symbol.toPrimitive];
62351
62410
  if (void 0 !== e) {
@@ -62356,9 +62415,9 @@ function _toPrimitive16(t, r) {
62356
62415
  return ("string" === r ? String : Number)(t);
62357
62416
  }
62358
62417
  var StraightLineModel = class extends ElementModel {
62359
- constructor(root, scope) {
62360
- super(root, scope);
62361
- _defineProperty16(this, "item", null);
62418
+ constructor(root, scope, liveCursor) {
62419
+ super(root, scope, liveCursor);
62420
+ _defineProperty15(this, "item", null);
62362
62421
  if (!this.root.has("type")) {
62363
62422
  this.root.set("type", "line");
62364
62423
  }
@@ -62366,6 +62425,17 @@ var StraightLineModel = class extends ElementModel {
62366
62425
  this.root.set("points", new Y11.Array());
62367
62426
  }
62368
62427
  }
62428
+ liveCursorPoint() {
62429
+ const yArray = this.root.get(ElementModel.KEYS.points);
62430
+ if (yArray.length < 2) {
62431
+ return null;
62432
+ }
62433
+ const len = yArray.length;
62434
+ const point = new this.scope.Point(yArray.get(len - 2), yArray.get(len - 1));
62435
+ return point.transform(new this.scope.Matrix(this.pointsMatrix));
62436
+ }
62437
+ subDispose() {
62438
+ }
62369
62439
  onVectorUpdate() {
62370
62440
  if (!this.item) {
62371
62441
  return;
@@ -62439,7 +62509,7 @@ var StraightLineModel = class extends ElementModel {
62439
62509
  exclude: ["fillColor"]
62440
62510
  };
62441
62511
  }
62442
- onStyleKeyUpdate(key) {
62512
+ onStyleKeyUpdate(_key) {
62443
62513
  if (!this.item) {
62444
62514
  return;
62445
62515
  }
@@ -62448,6 +62518,84 @@ var StraightLineModel = class extends ElementModel {
62448
62518
  this.item.addSegments(path.segments);
62449
62519
  }
62450
62520
  };
62521
+ function _defineProperty16(e, r, t) {
62522
+ return (r = _toPropertyKey16(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62523
+ }
62524
+ function _toPropertyKey16(t) {
62525
+ var i = _toPrimitive16(t, "string");
62526
+ return "symbol" == typeof i ? i : i + "";
62527
+ }
62528
+ function _toPrimitive16(t, r) {
62529
+ if ("object" != typeof t || !t) return t;
62530
+ var e = t[Symbol.toPrimitive];
62531
+ if (void 0 !== e) {
62532
+ var i = e.call(t, r || "default");
62533
+ if ("object" != typeof i) return i;
62534
+ throw new TypeError("@@toPrimitive must return a primitive value.");
62535
+ }
62536
+ return ("string" === r ? String : Number)(t);
62537
+ }
62538
+ var ImageModel = class extends ElementModel {
62539
+ get src() {
62540
+ return this.root.get("src");
62541
+ }
62542
+ constructor(root, scope, imageSets, liveCursor) {
62543
+ super(root, scope, liveCursor);
62544
+ _defineProperty16(this, "item", null);
62545
+ _defineProperty16(this, "imageSets", void 0);
62546
+ this.imageSets = imageSets;
62547
+ if (!this.root.has("type")) {
62548
+ this.root.set("type", "image");
62549
+ }
62550
+ this.root.set(ElementModel.KEYS.shadow, "");
62551
+ }
62552
+ subDispose() {
62553
+ const img = this.imageSets.querySelector(`[id='${this.uuid}']`);
62554
+ if (img) {
62555
+ img.remove();
62556
+ }
62557
+ }
62558
+ createPaperItem() {
62559
+ if (this.item) {
62560
+ return;
62561
+ }
62562
+ if (!this.imageSets.querySelector(`[id='${this.uuid}']`)) {
62563
+ const img = document.createElement("img");
62564
+ img.src = this.src;
62565
+ img.id = this.uuid;
62566
+ this.imageSets.appendChild(img);
62567
+ }
62568
+ this.item = new this.scope.Raster(this.uuid);
62569
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
62570
+ this.item.matrix = matrix;
62571
+ }
62572
+ onVectorUpdate() {
62573
+ const matrix = new this.scope.Matrix(this.pointsMatrix);
62574
+ if (this.item) {
62575
+ this.item.matrix = matrix;
62576
+ }
62577
+ }
62578
+ vectorKeys() {
62579
+ return [];
62580
+ }
62581
+ styleKeys() {
62582
+ return {
62583
+ include: [],
62584
+ exclude: ["dashArray", "strokeColor", "fillColor", "strokeWidth"]
62585
+ };
62586
+ }
62587
+ onStyleKeyUpdate(_key) {
62588
+ }
62589
+ editorConfig() {
62590
+ const cfg = new EditorConfig();
62591
+ cfg.resizeModel = () => "four-corner";
62592
+ cfg.uniformScale = () => true;
62593
+ return cfg;
62594
+ }
62595
+ liveCursorPoint() {
62596
+ return null;
62597
+ }
62598
+ };
62451
62599
  function _defineProperty17(e, r, t) {
62452
62600
  return (r = _toPropertyKey17(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
62453
62601
  }
@@ -62465,11 +62613,11 @@ function _toPrimitive17(t, r) {
62465
62613
  }
62466
62614
  return ("string" === r ? String : Number)(t);
62467
62615
  }
62468
- var RenderableModel = class extends EventEmitter2 {
62616
+ var RenderableModel = class extends EventEmitter {
62469
62617
  get uuid() {
62470
- return uuidv4();
62618
+ return uuidv4().replace(/-/g, "");
62471
62619
  }
62472
- constructor(layerId, shadowEmitter, elements, scope, toolbarModel, userManager, hasPermission) {
62620
+ constructor(layerId, shadowEmitter, elements, scope, toolbarModel, userManager, imageSets, liveCursor, hasPermission) {
62473
62621
  super();
62474
62622
  _defineProperty17(this, "scope", void 0);
62475
62623
  _defineProperty17(this, "toolbarModel", void 0);
@@ -62480,6 +62628,8 @@ var RenderableModel = class extends EventEmitter2 {
62480
62628
  _defineProperty17(this, "maxIndex", -1);
62481
62629
  _defineProperty17(this, "hasPermission", void 0);
62482
62630
  _defineProperty17(this, "shadowEmitter", void 0);
62631
+ _defineProperty17(this, "imageSets", void 0);
62632
+ _defineProperty17(this, "liveCursor", void 0);
62483
62633
  _defineProperty17(this, "onElementsChange", (event) => {
62484
62634
  for (const [key, value] of event.changes.keys.entries()) {
62485
62635
  if (value.action === "add") {
@@ -62487,7 +62637,9 @@ var RenderableModel = class extends EventEmitter2 {
62487
62637
  if (root) {
62488
62638
  const model = this.convertToModel(root);
62489
62639
  if (model) {
62490
- this.emit("elementInsert", [model]);
62640
+ setTimeout(() => {
62641
+ this.emit("elementInsert", [model]);
62642
+ });
62491
62643
  }
62492
62644
  }
62493
62645
  } else if (value.action === "delete") {
@@ -62495,6 +62647,8 @@ var RenderableModel = class extends EventEmitter2 {
62495
62647
  }
62496
62648
  }
62497
62649
  });
62650
+ this.liveCursor = liveCursor;
62651
+ this.imageSets = imageSets;
62498
62652
  this.hasPermission = hasPermission;
62499
62653
  this.shadowEmitter = shadowEmitter;
62500
62654
  this.layerId = layerId;
@@ -62533,27 +62687,29 @@ var RenderableModel = class extends EventEmitter2 {
62533
62687
  const type = yMap.get("type");
62534
62688
  let model = null;
62535
62689
  if (type === "curve") {
62536
- model = new CurveModel(yMap, this.scope);
62690
+ model = new CurveModel(yMap, this.scope, this.liveCursor);
62537
62691
  } else if (["ellipse"].indexOf(type) >= 0) {
62538
- model = new SegmentsModel(yMap, this.scope, type);
62692
+ model = new SegmentsModel(yMap, this.scope, type, this.liveCursor);
62539
62693
  } else if (type === "selector") {
62540
- model = new SelectorModel(yMap, this.scope);
62694
+ model = new SelectorModel(yMap, this.scope, this.liveCursor);
62541
62695
  } else if (type === "arrow") {
62542
- model = new LineModel(yMap, this.scope);
62696
+ model = new LineModel(yMap, this.scope, this.liveCursor);
62543
62697
  } else if (type === "line") {
62544
- model = new StraightLineModel(yMap, this.scope);
62698
+ model = new StraightLineModel(yMap, this.scope, this.liveCursor);
62545
62699
  } else if (type === "point-text") {
62546
- model = new PointTextModel(yMap, this.scope);
62700
+ model = new PointTextModel(yMap, this.scope, this.liveCursor);
62547
62701
  } else if (type === "triangle") {
62548
- model = new TriangleModel(yMap, this.scope);
62702
+ model = new TriangleModel(yMap, this.scope, this.liveCursor);
62549
62703
  } else if (type === "rectangle") {
62550
- model = new RectangleModel(yMap, this.scope);
62704
+ model = new RectangleModel(yMap, this.scope, this.liveCursor);
62551
62705
  } else if (type === "eraser") {
62552
- model = new EraserModel(yMap, this.scope);
62706
+ model = new EraserModel(yMap, this.scope, this.liveCursor);
62553
62707
  } else if (type === "laser") {
62554
- model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, (uuid) => {
62708
+ model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid) => {
62555
62709
  this.removeElementItem(uuid);
62556
62710
  });
62711
+ } else if (type === "image") {
62712
+ model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor);
62557
62713
  }
62558
62714
  if (model) {
62559
62715
  model.shadowEmitter = this.shadowEmitter;
@@ -62562,142 +62718,271 @@ var RenderableModel = class extends EventEmitter2 {
62562
62718
  return model;
62563
62719
  }
62564
62720
  initElement(element) {
62565
- let shadow = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
62566
- if (shadow) {
62567
- element.shadow = "layer";
62568
- }
62569
- element.strokeWidth = this.toolbarModel.strokeWidth;
62570
- element.strokeColor = this.toolbarModel.strokeColor;
62571
- element.fillColor = this.toolbarModel.fillColor;
62572
- element.ownerId = this.userManager.selfId;
62573
62721
  element.shadowEmitter = this.shadowEmitter;
62574
62722
  }
62575
62723
  removeElementItem(uuid) {
62576
62724
  this.elements.delete(uuid);
62577
62725
  }
62578
- addElementToDoc(map) {
62579
- this.elements.doc?.transact(() => {
62580
- const uuid = this.uuid;
62581
- map.set(ElementModel.KEYS.index, ++this.maxIndex);
62582
- map.set(ElementModel.KEYS.uuid, uuid);
62583
- this.elements.set(uuid, map);
62584
- }, elementsUndoOrigin);
62585
- }
62586
62726
  confirmPermission() {
62587
62727
  const hasPermission = this.hasPermission(WhiteboardPermissionFlag.draw);
62588
62728
  if (!hasPermission) {
62589
- console.warn("[@netless/forge-whiteboard] no permission to draw");
62729
+ log("[@netless/forge-whiteboard] no permission to draw", {}, "warning");
62590
62730
  }
62591
62731
  return hasPermission;
62592
62732
  }
62733
+ createImage(src) {
62734
+ if (!this.confirmPermission()) {
62735
+ return;
62736
+ }
62737
+ const yMap = new Y12.Map();
62738
+ this.elements.doc?.transact(() => {
62739
+ const uuid = this.uuid;
62740
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62741
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62742
+ yMap.set("type", "image");
62743
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62744
+ this.elements.set(uuid, yMap);
62745
+ }, elementsUndoOrigin);
62746
+ const model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor);
62747
+ model.root.set("src", src);
62748
+ const initMatrix = new this.scope.Matrix();
62749
+ const center = this.scope.project.view.center;
62750
+ initMatrix.translate({
62751
+ x: center.x,
62752
+ y: center.y
62753
+ });
62754
+ model.appendPointsMatrix(initMatrix);
62755
+ model.ownerId = this.userManager.selfId;
62756
+ }
62593
62757
  createCurve() {
62594
62758
  let shadow = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
62595
62759
  if (!this.confirmPermission()) {
62596
62760
  return null;
62597
62761
  }
62598
- const curveModel = new CurveModel(new Y12.Map(), this.scope);
62599
- this.initElement(curveModel, shadow);
62600
- this.addElementToDoc(curveModel.root);
62762
+ const yMap = new Y12.Map();
62763
+ this.elements.doc?.transact(() => {
62764
+ const uuid = this.uuid;
62765
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62766
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62767
+ yMap.set("type", "curve");
62768
+ if (shadow) {
62769
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62770
+ }
62771
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62772
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62773
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62774
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62775
+ this.elements.set(uuid, yMap);
62776
+ }, elementsUndoOrigin);
62777
+ const curveModel = new CurveModel(yMap, this.scope, this.liveCursor);
62778
+ this.initElement(curveModel);
62601
62779
  return curveModel;
62602
62780
  }
62603
62781
  createLaserPointer() {
62604
62782
  if (!this.confirmPermission()) {
62605
62783
  return null;
62606
62784
  }
62607
- const model = new LaserPointerModel(this.userManager.selfId, new Y12.Map(), this.scope, (uuid) => {
62785
+ const yMap = new Y12.Map();
62786
+ this.elements.doc?.transact(() => {
62787
+ const uuid = this.uuid;
62788
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62789
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62790
+ yMap.set("type", "laser");
62791
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62792
+ yMap.set(ElementModel.KEYS.strokeWidth, 8);
62793
+ yMap.set(ElementModel.KEYS.strokeColor, "#F44336");
62794
+ yMap.set(ElementModel.KEYS.fillColor, "#F44336");
62795
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62796
+ this.elements.set(uuid, yMap);
62797
+ }, elementsUndoOrigin);
62798
+ const model = new LaserPointerModel(this.userManager.selfId, yMap, this.scope, this.liveCursor, (uuid) => {
62608
62799
  this.removeElementItem(uuid);
62609
62800
  });
62610
- model.strokeWidth = 8;
62611
- model.strokeColor = "#F44336";
62612
- model.fillColor = "#F44336";
62613
- model.ownerId = this.userManager.selfId;
62614
- model.shadow = "layer";
62615
- this.addElementToDoc(model.root);
62616
62801
  return model;
62617
62802
  }
62618
62803
  createEraser() {
62619
62804
  if (!this.hasPermission(WhiteboardPermissionFlag.deleteSelf) && !this.hasPermission(WhiteboardPermissionFlag.deleteOthers)) {
62620
62805
  return null;
62621
62806
  }
62622
- const model = new EraserModel(new Y12.Map(), this.scope);
62623
- model.strokeWidth = 12;
62624
- model.strokeColor = "#9E9E9E";
62625
- model.fillColor = "#9E9E9E";
62626
- model.ownerId = this.userManager.selfId;
62627
- model.shadow = "layer";
62628
- this.addElementToDoc(model.root);
62807
+ const yMap = new Y12.Map();
62808
+ this.elements.doc?.transact(() => {
62809
+ const uuid = this.uuid;
62810
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62811
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62812
+ yMap.set("type", "eraser");
62813
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62814
+ yMap.set(ElementModel.KEYS.strokeWidth, 4);
62815
+ yMap.set(ElementModel.KEYS.strokeColor, "#9E9E9E");
62816
+ yMap.set(ElementModel.KEYS.fillColor, "#9E9E9E");
62817
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62818
+ this.elements.set(uuid, yMap);
62819
+ }, elementsUndoOrigin);
62820
+ const model = new EraserModel(yMap, this.scope, this.liveCursor);
62629
62821
  return model;
62630
62822
  }
62631
62823
  createTriangle(shadow) {
62632
62824
  if (!this.confirmPermission()) {
62633
62825
  return null;
62634
62826
  }
62635
- const triangle = new TriangleModel(new Y12.Map(), this.scope);
62636
- this.initElement(triangle, shadow);
62827
+ const yMap = new Y12.Map();
62828
+ this.elements.doc?.transact(() => {
62829
+ const uuid = this.uuid;
62830
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62831
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62832
+ yMap.set("type", "triangle");
62833
+ if (shadow) {
62834
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62835
+ }
62836
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62837
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62838
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62839
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62840
+ this.elements.set(uuid, yMap);
62841
+ }, elementsUndoOrigin);
62842
+ const triangle = new TriangleModel(yMap, this.scope, this.liveCursor);
62843
+ this.initElement(triangle);
62637
62844
  triangle.dashArray = this.toolbarModel.dashArray;
62638
- this.addElementToDoc(triangle.root);
62639
62845
  return triangle;
62640
62846
  }
62641
62847
  createRectangle(shadow) {
62642
62848
  if (!this.confirmPermission()) {
62643
62849
  return null;
62644
62850
  }
62645
- const rect = new RectangleModel(new Y12.Map(), this.scope);
62646
- this.initElement(rect, shadow);
62851
+ const yMap = new Y12.Map();
62852
+ this.elements.doc?.transact(() => {
62853
+ const uuid = this.uuid;
62854
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62855
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62856
+ yMap.set("type", "rectangle");
62857
+ if (shadow) {
62858
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62859
+ }
62860
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62861
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62862
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62863
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62864
+ this.elements.set(uuid, yMap);
62865
+ }, elementsUndoOrigin);
62866
+ const rect = new RectangleModel(yMap, this.scope, this.liveCursor);
62867
+ this.initElement(rect);
62647
62868
  rect.dashArray = this.toolbarModel.dashArray;
62648
- this.addElementToDoc(rect.root);
62649
62869
  return rect;
62650
62870
  }
62651
62871
  createSegmentedPath(type, shadow) {
62652
62872
  if (!this.confirmPermission()) {
62653
62873
  return null;
62654
62874
  }
62655
- const segmentsModel = new SegmentsModel(new Y12.Map(), this.scope, type);
62656
- this.initElement(segmentsModel, shadow);
62875
+ const yMap = new Y12.Map();
62876
+ this.elements.doc?.transact(() => {
62877
+ const uuid = this.uuid;
62878
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62879
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62880
+ yMap.set("type", type);
62881
+ if (shadow) {
62882
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62883
+ }
62884
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62885
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62886
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62887
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62888
+ this.elements.set(uuid, yMap);
62889
+ }, elementsUndoOrigin);
62890
+ const segmentsModel = new SegmentsModel(yMap, this.scope, type, this.liveCursor);
62891
+ this.initElement(segmentsModel);
62657
62892
  segmentsModel.dashArray = this.toolbarModel.dashArray;
62658
- this.addElementToDoc(segmentsModel.root);
62659
62893
  return segmentsModel;
62660
62894
  }
62661
62895
  createSelector() {
62662
- let shadow = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
62896
+ let _shadow = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
62663
62897
  if (!this.hasPermission(WhiteboardPermissionFlag.editSelf) && !this.hasPermission(WhiteboardPermissionFlag.deleteOthers)) {
62664
62898
  return null;
62665
62899
  }
62666
- const selectorModel = new SelectorModel(new Y12.Map(), this.scope);
62900
+ const yMap = new Y12.Map();
62901
+ this.elements.doc?.transact(() => {
62902
+ const uuid = this.uuid;
62903
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62904
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62905
+ yMap.set("type", "selector");
62906
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62907
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62908
+ this.elements.set(uuid, yMap);
62909
+ }, elementsUndoOrigin);
62910
+ const selectorModel = new SelectorModel(yMap, this.scope, this.liveCursor);
62667
62911
  selectorModel.shadow = "layer";
62668
- this.addElementToDoc(selectorModel.root);
62669
62912
  return selectorModel;
62670
62913
  }
62671
62914
  createStraightLine(shadow) {
62672
62915
  if (!this.confirmPermission()) {
62673
62916
  return null;
62674
62917
  }
62675
- const straightLineModel = new StraightLineModel(new Y12.Map(), this.scope);
62676
- this.initElement(straightLineModel, shadow);
62918
+ const yMap = new Y12.Map();
62919
+ this.elements.doc?.transact(() => {
62920
+ const uuid = this.uuid;
62921
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62922
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62923
+ yMap.set("type", "line");
62924
+ if (shadow) {
62925
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62926
+ }
62927
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62928
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62929
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62930
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62931
+ this.elements.set(uuid, yMap);
62932
+ }, elementsUndoOrigin);
62933
+ const straightLineModel = new StraightLineModel(yMap, this.scope, this.liveCursor);
62934
+ this.initElement(straightLineModel);
62677
62935
  straightLineModel.dashArray = this.toolbarModel.dashArray;
62678
- this.addElementToDoc(straightLineModel.root);
62679
62936
  return straightLineModel;
62680
62937
  }
62681
62938
  createLinePath(shadow) {
62682
62939
  if (!this.confirmPermission()) {
62683
62940
  return null;
62684
62941
  }
62685
- const lineModel = new LineModel(new Y12.Map(), this.scope);
62686
- this.initElement(lineModel, shadow);
62942
+ const yMap = new Y12.Map();
62943
+ this.elements.doc?.transact(() => {
62944
+ const uuid = this.uuid;
62945
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62946
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62947
+ yMap.set("type", "arrow");
62948
+ if (shadow) {
62949
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62950
+ }
62951
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62952
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62953
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62954
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62955
+ this.elements.set(uuid, yMap);
62956
+ }, elementsUndoOrigin);
62957
+ const lineModel = new LineModel(yMap, this.scope, this.liveCursor);
62958
+ this.initElement(lineModel);
62687
62959
  lineModel.dashArray = this.toolbarModel.dashArray;
62688
- this.addElementToDoc(lineModel.root);
62689
62960
  return lineModel;
62690
62961
  }
62691
62962
  createPointText(x, y, shadow) {
62692
62963
  if (!this.confirmPermission()) {
62693
62964
  return null;
62694
62965
  }
62695
- const pointTextModel = new PointTextModel(new Y12.Map(), this.scope);
62966
+ const yMap = new Y12.Map();
62967
+ this.elements.doc?.transact(() => {
62968
+ const uuid = this.uuid;
62969
+ yMap.set(ElementModel.KEYS.index, ++this.maxIndex);
62970
+ yMap.set(ElementModel.KEYS.uuid, uuid);
62971
+ yMap.set("type", "point-text");
62972
+ if (shadow) {
62973
+ yMap.set(ElementModel.KEYS.shadow, "layer");
62974
+ }
62975
+ yMap.set(ElementModel.KEYS.strokeWidth, this.toolbarModel.strokeWidth);
62976
+ yMap.set(ElementModel.KEYS.strokeColor, this.toolbarModel.strokeColor);
62977
+ yMap.set(ElementModel.KEYS.fillColor, this.toolbarModel.fillColor);
62978
+ yMap.set(ElementModel.KEYS.ownerId, this.userManager.selfId);
62979
+ this.elements.set(uuid, yMap);
62980
+ }, elementsUndoOrigin);
62981
+ const pointTextModel = new PointTextModel(yMap, this.scope, this.liveCursor);
62696
62982
  pointTextModel.setPoints([x, y]);
62697
62983
  pointTextModel.fontSize = this.toolbarModel.fontSize;
62698
62984
  pointTextModel.fontFamily = this.toolbarModel.fontFamily;
62699
- this.initElement(pointTextModel, shadow);
62700
- this.addElementToDoc(pointTextModel.root);
62985
+ this.initElement(pointTextModel);
62701
62986
  return pointTextModel;
62702
62987
  }
62703
62988
  clearElement() {
@@ -62715,8 +63000,14 @@ var RenderableModel = class extends EventEmitter2 {
62715
63000
  removeIds.forEach((id) => this.elements.delete(id));
62716
63001
  });
62717
63002
  }
62718
- dispose() {
62719
- this.elements.clear();
63003
+ dispose(clearElements) {
63004
+ removeObserver2(this.elements, this.onElementsChange);
63005
+ if (clearElements) {
63006
+ this.elements.clear();
63007
+ }
63008
+ Array.from(this.elementModels.values()).forEach((model) => {
63009
+ model.dispose();
63010
+ });
62720
63011
  }
62721
63012
  };
62722
63013
  var import_lodash8 = __toESM2(require_lodash(), 1);
@@ -62755,10 +63046,10 @@ var AnglePrecision = Deg2Rad(2);
62755
63046
  var Phi = 0.5 * (-1 + Math.sqrt(5));
62756
63047
  function DollarRecognizer() {
62757
63048
  this.Unistrokes = new Array(3);
62758
- this.Unistrokes[0] = new Unistroke("triangle", new Array(new Point(137, 139), new Point(135, 141), new Point(133, 144), new Point(132, 146), new Point(130, 149), new Point(128, 151), new Point(126, 155), new Point(123, 160), new Point(120, 166), new Point(116, 171), new Point(112, 177), new Point(107, 183), new Point(102, 188), new Point(100, 191), new Point(95, 195), new Point(90, 199), new Point(86, 203), new Point(82, 206), new Point(80, 209), new Point(75, 213), new Point(73, 213), new Point(70, 216), new Point(67, 219), new Point(64, 221), new Point(61, 223), new Point(60, 225), new Point(62, 226), new Point(65, 225), new Point(67, 226), new Point(74, 226), new Point(77, 227), new Point(85, 229), new Point(91, 230), new Point(99, 231), new Point(108, 232), new Point(116, 233), new Point(125, 233), new Point(134, 234), new Point(145, 233), new Point(153, 232), new Point(160, 233), new Point(170, 234), new Point(177, 235), new Point(179, 236), new Point(186, 237), new Point(193, 238), new Point(198, 239), new Point(200, 237), new Point(202, 239), new Point(204, 238), new Point(206, 234), new Point(205, 230), new Point(202, 222), new Point(197, 216), new Point(192, 207), new Point(186, 198), new Point(179, 189), new Point(174, 183), new Point(170, 178), new Point(164, 171), new Point(161, 168), new Point(154, 160), new Point(148, 155), new Point(143, 150), new Point(138, 148), new Point(136, 148)));
62759
- this.Unistrokes[1] = new Unistroke("rectangle", new Array(new Point(78, 149), new Point(78, 153), new Point(78, 157), new Point(78, 160), new Point(79, 162), new Point(79, 164), new Point(79, 167), new Point(79, 169), new Point(79, 173), new Point(79, 178), new Point(79, 183), new Point(80, 189), new Point(80, 193), new Point(80, 198), new Point(80, 202), new Point(81, 208), new Point(81, 210), new Point(81, 216), new Point(82, 222), new Point(82, 224), new Point(82, 227), new Point(83, 229), new Point(83, 231), new Point(85, 230), new Point(88, 232), new Point(90, 233), new Point(92, 232), new Point(94, 233), new Point(99, 232), new Point(102, 233), new Point(106, 233), new Point(109, 234), new Point(117, 235), new Point(123, 236), new Point(126, 236), new Point(135, 237), new Point(142, 238), new Point(145, 238), new Point(152, 238), new Point(154, 239), new Point(165, 238), new Point(174, 237), new Point(179, 236), new Point(186, 235), new Point(191, 235), new Point(195, 233), new Point(197, 233), new Point(200, 233), new Point(201, 235), new Point(201, 233), new Point(199, 231), new Point(198, 226), new Point(198, 220), new Point(196, 207), new Point(195, 195), new Point(195, 181), new Point(195, 173), new Point(195, 163), new Point(194, 155), new Point(192, 145), new Point(192, 143), new Point(192, 138), new Point(191, 135), new Point(191, 133), new Point(191, 130), new Point(190, 128), new Point(188, 129), new Point(186, 129), new Point(181, 132), new Point(173, 131), new Point(162, 131), new Point(151, 132), new Point(149, 132), new Point(138, 132), new Point(136, 132), new Point(122, 131), new Point(120, 131), new Point(109, 130), new Point(107, 130), new Point(90, 132), new Point(81, 133), new Point(76, 133)));
62760
- this.Unistrokes[2] = new Unistroke("circle", new Array(new Point(127, 141), new Point(124, 140), new Point(120, 139), new Point(118, 139), new Point(116, 139), new Point(111, 140), new Point(109, 141), new Point(104, 144), new Point(100, 147), new Point(96, 152), new Point(93, 157), new Point(90, 163), new Point(87, 169), new Point(85, 175), new Point(83, 181), new Point(82, 190), new Point(82, 195), new Point(83, 200), new Point(84, 205), new Point(88, 213), new Point(91, 216), new Point(96, 219), new Point(103, 222), new Point(108, 224), new Point(111, 224), new Point(120, 224), new Point(133, 223), new Point(142, 222), new Point(152, 218), new Point(160, 214), new Point(167, 210), new Point(173, 204), new Point(178, 198), new Point(179, 196), new Point(182, 188), new Point(182, 177), new Point(178, 167), new Point(170, 150), new Point(163, 138), new Point(152, 130), new Point(143, 129), new Point(140, 131), new Point(129, 136), new Point(126, 139)));
62761
- this.Unistrokes[3] = new Unistroke("arrow", new Array(new Point(68, 222), new Point(70, 220), new Point(73, 218), new Point(75, 217), new Point(77, 215), new Point(80, 213), new Point(82, 212), new Point(84, 210), new Point(87, 209), new Point(89, 208), new Point(92, 206), new Point(95, 204), new Point(101, 201), new Point(106, 198), new Point(112, 194), new Point(118, 191), new Point(124, 187), new Point(127, 186), new Point(132, 183), new Point(138, 181), new Point(141, 180), new Point(146, 178), new Point(154, 173), new Point(159, 171), new Point(161, 170), new Point(166, 167), new Point(168, 167), new Point(171, 166), new Point(174, 164), new Point(177, 162), new Point(180, 160), new Point(182, 158), new Point(183, 156), new Point(181, 154), new Point(178, 153), new Point(171, 153), new Point(164, 153), new Point(160, 153), new Point(150, 154), new Point(147, 155), new Point(141, 157), new Point(137, 158), new Point(135, 158), new Point(137, 158), new Point(140, 157), new Point(143, 156), new Point(151, 154), new Point(160, 152), new Point(170, 149), new Point(179, 147), new Point(185, 145), new Point(192, 144), new Point(196, 144), new Point(198, 144), new Point(200, 144), new Point(201, 147), new Point(199, 149), new Point(194, 157), new Point(191, 160), new Point(186, 167), new Point(180, 176), new Point(177, 179), new Point(171, 187), new Point(169, 189), new Point(165, 194), new Point(164, 196)));
63049
+ this.Unistrokes[0] = new Unistroke("triangle", [new Point(137, 139), new Point(135, 141), new Point(133, 144), new Point(132, 146), new Point(130, 149), new Point(128, 151), new Point(126, 155), new Point(123, 160), new Point(120, 166), new Point(116, 171), new Point(112, 177), new Point(107, 183), new Point(102, 188), new Point(100, 191), new Point(95, 195), new Point(90, 199), new Point(86, 203), new Point(82, 206), new Point(80, 209), new Point(75, 213), new Point(73, 213), new Point(70, 216), new Point(67, 219), new Point(64, 221), new Point(61, 223), new Point(60, 225), new Point(62, 226), new Point(65, 225), new Point(67, 226), new Point(74, 226), new Point(77, 227), new Point(85, 229), new Point(91, 230), new Point(99, 231), new Point(108, 232), new Point(116, 233), new Point(125, 233), new Point(134, 234), new Point(145, 233), new Point(153, 232), new Point(160, 233), new Point(170, 234), new Point(177, 235), new Point(179, 236), new Point(186, 237), new Point(193, 238), new Point(198, 239), new Point(200, 237), new Point(202, 239), new Point(204, 238), new Point(206, 234), new Point(205, 230), new Point(202, 222), new Point(197, 216), new Point(192, 207), new Point(186, 198), new Point(179, 189), new Point(174, 183), new Point(170, 178), new Point(164, 171), new Point(161, 168), new Point(154, 160), new Point(148, 155), new Point(143, 150), new Point(138, 148), new Point(136, 148)]);
63050
+ this.Unistrokes[1] = new Unistroke("rectangle", [new Point(78, 149), new Point(78, 153), new Point(78, 157), new Point(78, 160), new Point(79, 162), new Point(79, 164), new Point(79, 167), new Point(79, 169), new Point(79, 173), new Point(79, 178), new Point(79, 183), new Point(80, 189), new Point(80, 193), new Point(80, 198), new Point(80, 202), new Point(81, 208), new Point(81, 210), new Point(81, 216), new Point(82, 222), new Point(82, 224), new Point(82, 227), new Point(83, 229), new Point(83, 231), new Point(85, 230), new Point(88, 232), new Point(90, 233), new Point(92, 232), new Point(94, 233), new Point(99, 232), new Point(102, 233), new Point(106, 233), new Point(109, 234), new Point(117, 235), new Point(123, 236), new Point(126, 236), new Point(135, 237), new Point(142, 238), new Point(145, 238), new Point(152, 238), new Point(154, 239), new Point(165, 238), new Point(174, 237), new Point(179, 236), new Point(186, 235), new Point(191, 235), new Point(195, 233), new Point(197, 233), new Point(200, 233), new Point(201, 235), new Point(201, 233), new Point(199, 231), new Point(198, 226), new Point(198, 220), new Point(196, 207), new Point(195, 195), new Point(195, 181), new Point(195, 173), new Point(195, 163), new Point(194, 155), new Point(192, 145), new Point(192, 143), new Point(192, 138), new Point(191, 135), new Point(191, 133), new Point(191, 130), new Point(190, 128), new Point(188, 129), new Point(186, 129), new Point(181, 132), new Point(173, 131), new Point(162, 131), new Point(151, 132), new Point(149, 132), new Point(138, 132), new Point(136, 132), new Point(122, 131), new Point(120, 131), new Point(109, 130), new Point(107, 130), new Point(90, 132), new Point(81, 133), new Point(76, 133)]);
63051
+ this.Unistrokes[2] = new Unistroke("circle", [new Point(127, 141), new Point(124, 140), new Point(120, 139), new Point(118, 139), new Point(116, 139), new Point(111, 140), new Point(109, 141), new Point(104, 144), new Point(100, 147), new Point(96, 152), new Point(93, 157), new Point(90, 163), new Point(87, 169), new Point(85, 175), new Point(83, 181), new Point(82, 190), new Point(82, 195), new Point(83, 200), new Point(84, 205), new Point(88, 213), new Point(91, 216), new Point(96, 219), new Point(103, 222), new Point(108, 224), new Point(111, 224), new Point(120, 224), new Point(133, 223), new Point(142, 222), new Point(152, 218), new Point(160, 214), new Point(167, 210), new Point(173, 204), new Point(178, 198), new Point(179, 196), new Point(182, 188), new Point(182, 177), new Point(178, 167), new Point(170, 150), new Point(163, 138), new Point(152, 130), new Point(143, 129), new Point(140, 131), new Point(129, 136), new Point(126, 139)]);
63052
+ this.Unistrokes[3] = new Unistroke("arrow", [new Point(68, 222), new Point(70, 220), new Point(73, 218), new Point(75, 217), new Point(77, 215), new Point(80, 213), new Point(82, 212), new Point(84, 210), new Point(87, 209), new Point(89, 208), new Point(92, 206), new Point(95, 204), new Point(101, 201), new Point(106, 198), new Point(112, 194), new Point(118, 191), new Point(124, 187), new Point(127, 186), new Point(132, 183), new Point(138, 181), new Point(141, 180), new Point(146, 178), new Point(154, 173), new Point(159, 171), new Point(161, 170), new Point(166, 167), new Point(168, 167), new Point(171, 166), new Point(174, 164), new Point(177, 162), new Point(180, 160), new Point(182, 158), new Point(183, 156), new Point(181, 154), new Point(178, 153), new Point(171, 153), new Point(164, 153), new Point(160, 153), new Point(150, 154), new Point(147, 155), new Point(141, 157), new Point(137, 158), new Point(135, 158), new Point(137, 158), new Point(140, 157), new Point(143, 156), new Point(151, 154), new Point(160, 152), new Point(170, 149), new Point(179, 147), new Point(185, 145), new Point(192, 144), new Point(196, 144), new Point(198, 144), new Point(200, 144), new Point(201, 147), new Point(199, 149), new Point(194, 157), new Point(191, 160), new Point(186, 167), new Point(180, 176), new Point(177, 179), new Point(171, 187), new Point(169, 189), new Point(165, 194), new Point(164, 196)]);
62762
63053
  this.Recognize = function(points, useProtractor) {
62763
63054
  var t0 = Date.now();
62764
63055
  var candidate = new Unistroke("", points);
@@ -62819,7 +63110,7 @@ function RotateBy(points, radians) {
62819
63110
  var c = Centroid(points);
62820
63111
  var cos = Math.cos(radians);
62821
63112
  var sin = Math.sin(radians);
62822
- var newpoints = new Array();
63113
+ var newpoints = [];
62823
63114
  for (var i = 0; i < points.length; i++) {
62824
63115
  var qx = (points[i].X - c.X) * cos - (points[i].Y - c.Y) * sin + c.X;
62825
63116
  var qy = (points[i].X - c.X) * sin + (points[i].Y - c.Y) * cos + c.Y;
@@ -62829,7 +63120,7 @@ function RotateBy(points, radians) {
62829
63120
  }
62830
63121
  function ScaleTo(points, size) {
62831
63122
  var B2 = BoundingBox(points);
62832
- var newpoints = new Array();
63123
+ var newpoints = [];
62833
63124
  for (var i = 0; i < points.length; i++) {
62834
63125
  var qx = points[i].X * (size / B2.Width);
62835
63126
  var qy = points[i].Y * (size / B2.Height);
@@ -62839,7 +63130,7 @@ function ScaleTo(points, size) {
62839
63130
  }
62840
63131
  function TranslateTo(points, pt) {
62841
63132
  var c = Centroid(points);
62842
- var newpoints = new Array();
63133
+ var newpoints = [];
62843
63134
  for (var i = 0; i < points.length; i++) {
62844
63135
  var qx = points[i].X + pt.X - c.X;
62845
63136
  var qy = points[i].Y + pt.Y - c.Y;
@@ -62849,14 +63140,14 @@ function TranslateTo(points, pt) {
62849
63140
  }
62850
63141
  function Vectorize(points) {
62851
63142
  var sum = 0;
62852
- var vector = new Array();
62853
- for (var i = 0; i < points.length; i++) {
63143
+ var vector = [];
63144
+ for (let i = 0; i < points.length; i++) {
62854
63145
  vector[vector.length] = points[i].X;
62855
63146
  vector[vector.length] = points[i].Y;
62856
63147
  sum += points[i].X * points[i].X + points[i].Y * points[i].Y;
62857
63148
  }
62858
63149
  var magnitude = Math.sqrt(sum);
62859
- for (var i = 0; i < vector.length; i++)
63150
+ for (let i = 0; i < vector.length; i++)
62860
63151
  vector[i] /= magnitude;
62861
63152
  return vector;
62862
63153
  }
@@ -63004,19 +63295,38 @@ var CurveTool = class extends WhiteboardTool {
63004
63295
  _defineProperty19(this, "elementModel", null);
63005
63296
  _defineProperty19(this, "recognizer", new Recognizer());
63006
63297
  _defineProperty19(this, "pointCount", 0);
63007
- this.tool.minDistance = 1;
63298
+ _defineProperty19(this, "showLiveCursor", true);
63299
+ this.tool.minDistance = 5;
63008
63300
  }
63009
- onMouseDown(event) {
63301
+ onMouseDown(_event) {
63010
63302
  this.pointCount = 0;
63303
+ if (this.elementModel) {
63304
+ this.elementModel.dispose();
63305
+ }
63011
63306
  this.elementModel = this.modelGetter().createCurve(true);
63012
63307
  }
63013
63308
  onMouseDrag(event) {
63014
63309
  if (this.pointCount > 1024) {
63015
63310
  return;
63016
63311
  }
63312
+ const MIN_DISTANCE = 4;
63017
63313
  if (this.elementModel) {
63018
- this.pointCount += 1;
63019
- this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
63314
+ const len = this.elementModel.points.length;
63315
+ let last = {
63316
+ x: 0,
63317
+ y: 0
63318
+ };
63319
+ if (len >= 2) {
63320
+ last = {
63321
+ x: this.elementModel.points[len - 2],
63322
+ y: this.elementModel.points[len - 1]
63323
+ };
63324
+ }
63325
+ const dist = Math.max(Math.abs(last.x - event.point.x), Math.abs(last.y - event.point.y));
63326
+ if (dist >= MIN_DISTANCE) {
63327
+ this.pointCount += 1;
63328
+ this.elementModel.appendPoints([Math.round(event.point.x), Math.round(event.point.y)]);
63329
+ }
63020
63330
  }
63021
63331
  }
63022
63332
  onMouseUp(event) {
@@ -63073,9 +63383,13 @@ var RectangleTool = class extends WhiteboardTool {
63073
63383
  _defineProperty20(this, "elementModel", null);
63074
63384
  _defineProperty20(this, "from", null);
63075
63385
  _defineProperty20(this, "to", null);
63386
+ _defineProperty20(this, "showLiveCursor", true);
63076
63387
  this.tool.minDistance = 1;
63077
63388
  }
63078
63389
  onMouseDown(event) {
63390
+ if (this.elementModel) {
63391
+ this.elementModel.dispose();
63392
+ }
63079
63393
  this.elementModel = this.modelGetter().createRectangle(true);
63080
63394
  this.from = event.point.clone();
63081
63395
  this.to = event.point.clone();
@@ -63121,7 +63435,7 @@ var TOOLBAR_KEYS = {
63121
63435
  strokeWidth: "strokeWidth",
63122
63436
  dashArray: "dashArray"
63123
63437
  };
63124
- var ToolbarModel = class extends EventEmitter3 {
63438
+ var ToolbarModel = class extends EventEmitter2 {
63125
63439
  get currentTool() {
63126
63440
  return this.root.get(TOOLBAR_KEYS.tool);
63127
63441
  }
@@ -63190,6 +63504,10 @@ var ToolbarModel = class extends EventEmitter3 {
63190
63504
  }
63191
63505
  });
63192
63506
  }
63507
+ dispose() {
63508
+ removeObserver3(this.root, this.handleRootUpdate);
63509
+ this.removeAllListeners();
63510
+ }
63193
63511
  };
63194
63512
  function _defineProperty22(e, r, t) {
63195
63513
  return (r = _toPropertyKey22(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -63216,11 +63534,15 @@ var SelectorTool = class extends WhiteboardTool {
63216
63534
  _defineProperty22(this, "to", null);
63217
63535
  _defineProperty22(this, "selectElementsModel", void 0);
63218
63536
  _defineProperty22(this, "selectElements", /* @__PURE__ */ new Map());
63537
+ _defineProperty22(this, "showLiveCursor", false);
63219
63538
  this.selectElementsModel = selectElementsModel;
63220
63539
  }
63221
63540
  onMouseDown(event) {
63222
63541
  this.from = null;
63223
63542
  this.to = null;
63543
+ if (this.elementModel) {
63544
+ this.elementModel.dispose();
63545
+ }
63224
63546
  this.elementModel = this.modelGetter().createSelector();
63225
63547
  this.from = event.point.clone();
63226
63548
  this.to = event.point.clone();
@@ -63293,7 +63615,7 @@ function _toPrimitive23(t, r) {
63293
63615
  }
63294
63616
  return ("string" === r ? String : Number)(t);
63295
63617
  }
63296
- var SelectElementsModel = class extends EventEmitter4 {
63618
+ var SelectElementsModel = class extends EventEmitter3 {
63297
63619
  get hasEditSelfPermission() {
63298
63620
  return this.hasPermission(WhiteboardPermissionFlag.editSelf);
63299
63621
  }
@@ -63309,13 +63631,17 @@ var SelectElementsModel = class extends EventEmitter4 {
63309
63631
  _defineProperty23(this, "handleUserLeave", (user) => {
63310
63632
  const cb = this.observers.get(user.id);
63311
63633
  if (cb) {
63312
- this.requestUserMap(user.id).unobserveDeep(cb);
63634
+ removeDeepObserver2(this.requestUserMap(user.id), cb);
63635
+ this.observers.delete(user.id);
63313
63636
  }
63314
63637
  });
63315
63638
  _defineProperty23(this, "handleUserJoin", (user) => {
63316
63639
  const observer = (evts) => {
63317
63640
  this.handleUserSelectElementsChange(user.id, evts);
63318
63641
  };
63642
+ if (this.observers.has(user.id)) {
63643
+ removeDeepObserver2(this.requestUserMap(user.id), this.observers.get(user.id));
63644
+ }
63319
63645
  this.requestUserMap(user.id).observeDeep(observer);
63320
63646
  this.observers.set(user.id, observer);
63321
63647
  });
@@ -63335,6 +63661,9 @@ var SelectElementsModel = class extends EventEmitter4 {
63335
63661
  const observer = (evts) => {
63336
63662
  this.handleUserSelectElementsChange(userId, evts);
63337
63663
  };
63664
+ if (this.observers.has(userId)) {
63665
+ removeDeepObserver2(this.requestUserMap(userId), this.observers.get(userId));
63666
+ }
63338
63667
  this.requestUserMap(userId).observeDeep(observer);
63339
63668
  this.observers.set(userId, observer);
63340
63669
  });
@@ -63389,12 +63718,9 @@ var SelectElementsModel = class extends EventEmitter4 {
63389
63718
  });
63390
63719
  }
63391
63720
  dispose() {
63392
- this.userManager.userIdList().forEach((userId) => {
63393
- const cb = this.observers.get(userId);
63394
- if (cb) {
63395
- this.requestUserMap(userId).unobserveDeep(cb);
63396
- }
63397
- });
63721
+ for (const [key, value] of this.observers.entries()) {
63722
+ removeDeepObserver2(this.requestUserMap(key), value);
63723
+ }
63398
63724
  this.observers.clear();
63399
63725
  this.userManager.off("leave", this.handleUserLeave);
63400
63726
  this.userManager.off("join", this.handleUserJoin);
@@ -63417,7 +63743,7 @@ function _toPrimitive24(t, r) {
63417
63743
  }
63418
63744
  return ("string" === r ? String : Number)(t);
63419
63745
  }
63420
- var TextEditor = class extends EventEmitter5 {
63746
+ var TextEditor = class extends EventEmitter4 {
63421
63747
  constructor(camera) {
63422
63748
  super();
63423
63749
  _defineProperty24(this, "rootView", void 0);
@@ -63450,12 +63776,12 @@ var TextEditor = class extends EventEmitter5 {
63450
63776
  });
63451
63777
  this.camera = camera;
63452
63778
  this.rootView = document.createElement("div");
63453
- this.rootView.style.cssText = `position:absolute;width:100%;height:100%;top:0;left:0;overflow:hidden;`;
63779
+ this.rootView.style.cssText = "position:absolute;width:100%;height:100%;top:0;left:0;overflow:hidden;";
63454
63780
  this.content = document.createElement("div");
63455
63781
  this.content.setAttribute("spellcheck", "false");
63456
63782
  this.content.textContent = "";
63457
63783
  this.content.setAttribute("contenteditable", "plaintext-only");
63458
- this.content.style.cssText = `white-space: nowrap;border:1px solid red;text-wrap:nowrap;caret-color:red;line-height:1.2em;position:absolute;z-index:2;color:transparent;outline:none;`;
63784
+ this.content.style.cssText = "white-space: nowrap;border:1px solid red;text-wrap:nowrap;caret-color:red;line-height:1.2em;position:absolute;z-index:2;color:transparent;outline:none;";
63459
63785
  this.content.style.transformOrigin = "0 0";
63460
63786
  this.rootView.appendChild(this.content);
63461
63787
  this.content.addEventListener("input", this.handleContentInput);
@@ -63558,7 +63884,7 @@ var ANCHOR_STYLE = {
63558
63884
  b: "cursor:s-resize;bottom:-3px;left:50%;translate:-50%;",
63559
63885
  br: "cursor:se-resize;bottom:-3px;right:-3px"
63560
63886
  };
63561
- var Bounds = class extends EventEmitter6 {
63887
+ var Bounds = class extends EventEmitter5 {
63562
63888
  get width() {
63563
63889
  return this.maxX - this.minX;
63564
63890
  }
@@ -63697,7 +64023,7 @@ var Bounds = class extends EventEmitter6 {
63697
64023
  this.maxY = maxY;
63698
64024
  }
63699
64025
  };
63700
- var Editor = class extends EventEmitter6 {
64026
+ var Editor = class extends EventEmitter5 {
63701
64027
  constructor(scope, shadowScope, shadowEmitter, canvasElement, camera, initConfig) {
63702
64028
  super();
63703
64029
  _defineProperty25(this, "rootView", void 0);
@@ -63798,7 +64124,7 @@ var Editor = class extends EventEmitter6 {
63798
64124
  }
63799
64125
  if (this.editMode === "matrix" && this.editAnchor && this.lastEditPoint) {
63800
64126
  const offsetX = evt.pageX - this.lastEditPoint.x;
63801
- let offsetY = evt.pageY - this.lastEditPoint.y;
64127
+ const offsetY = evt.pageY - this.lastEditPoint.y;
63802
64128
  this.bounds.offsetBy(this.editAnchor, offsetX, offsetY, this.uniformScale ? this.aspectRatio : -1);
63803
64129
  this.lastEditPoint = {
63804
64130
  x: evt.pageX,
@@ -63823,7 +64149,7 @@ var Editor = class extends EventEmitter6 {
63823
64149
  }
63824
64150
  if (this.editMode === "translate" && this.lastEditPoint) {
63825
64151
  const offsetX = evt.pageX - this.lastEditPoint.x;
63826
- let offsetY = evt.pageY - this.lastEditPoint.y;
64152
+ const offsetY = evt.pageY - this.lastEditPoint.y;
63827
64153
  this.bounds.translate(offsetX, offsetY);
63828
64154
  this.updateBoundsByShadow();
63829
64155
  this.lastEditPoint = {
@@ -63900,7 +64226,7 @@ var Editor = class extends EventEmitter6 {
63900
64226
  this.ctrlId = initConfig.ctrlId;
63901
64227
  this.ctrlNickName = initConfig.ctrlNickName;
63902
64228
  this.rootView = document.createElement("div");
63903
- this.rootView.style.cssText = `position:absolute;display:none;width:100%;height:100%;top:50%;left:50%;transform:translate(-50%,-50%);`;
64229
+ this.rootView.style.cssText = "overflow:hidden;position:absolute;display:none;width:100%;height:100%;top:50%;left:50%;transform:translate(-50%,-50%);";
63904
64230
  this.frame = document.createElement("div");
63905
64231
  this.frame.style.position = "absolute";
63906
64232
  this.frame.style.padding = "8px";
@@ -63921,7 +64247,7 @@ var Editor = class extends EventEmitter6 {
63921
64247
  } else {
63922
64248
  this.title = document.createElement("div");
63923
64249
  this.title.textContent = `${this.ctrlNickName}`;
63924
- this.title.style.cssText = `color:#fff;font-size:12px;padding: 0.2em 0.4em;border-radius: 0.4em;position: absolute;top: 0%;left: 0;margin: -0.4em;transform: translate(-100%, -100%);`;
64250
+ this.title.style.cssText = "color:#fff;font-size:12px;padding: 0.2em 0.4em;border-radius: 0.4em;position: absolute;top: 0%;left: 0;margin: -0.4em;transform: translate(-100%, -100%);";
63925
64251
  this.frame.appendChild(this.title);
63926
64252
  this.rootView.style.pointerEvents = "none";
63927
64253
  }
@@ -64144,6 +64470,7 @@ var TextTool = class extends WhiteboardTool {
64144
64470
  _defineProperty26(this, "elementModel", null);
64145
64471
  _defineProperty26(this, "toolbarModel", void 0);
64146
64472
  _defineProperty26(this, "camera", void 0);
64473
+ _defineProperty26(this, "showLiveCursor", false);
64147
64474
  this.rootView = rootView;
64148
64475
  this.canvasElement = canvasElement;
64149
64476
  this.toolbarModel = toolbarModel;
@@ -64152,7 +64479,7 @@ var TextTool = class extends WhiteboardTool {
64152
64479
  onMouseDown(event) {
64153
64480
  this.from = event.point.clone();
64154
64481
  }
64155
- onMouseDrag(event) {
64482
+ onMouseDrag(_event) {
64156
64483
  }
64157
64484
  onMouseUp(event) {
64158
64485
  this.to = event.point.clone();
@@ -64164,6 +64491,9 @@ var TextTool = class extends WhiteboardTool {
64164
64491
  }
64165
64492
  }
64166
64493
  createPointEditor(x, y) {
64494
+ if (this.elementModel) {
64495
+ this.elementModel.dispose();
64496
+ }
64167
64497
  this.elementModel = this.modelGetter().createPointText(x, y, true);
64168
64498
  if (this.elementModel === null) {
64169
64499
  return;
@@ -64219,7 +64549,7 @@ function _toPrimitive27(t, r) {
64219
64549
  }
64220
64550
  return ("string" === r ? String : Number)(t);
64221
64551
  }
64222
- var Gesture = class extends EventEmitter7 {
64552
+ var Gesture = class extends EventEmitter6 {
64223
64553
  constructor(element, scope) {
64224
64554
  super();
64225
64555
  _defineProperty27(this, "element", void 0);
@@ -64298,7 +64628,7 @@ function _toPrimitive28(t, r) {
64298
64628
  }
64299
64629
  return ("string" === r ? String : Number)(t);
64300
64630
  }
64301
- var Camera = class extends EventEmitter8 {
64631
+ var Camera = class extends EventEmitter7 {
64302
64632
  get inherentMatrix() {
64303
64633
  const inherentMatrix = new this.scope.Matrix();
64304
64634
  inherentMatrix.scale(this.inherentScale, [0, 0]);
@@ -64354,13 +64684,16 @@ var Camera = class extends EventEmitter8 {
64354
64684
  _defineProperty28(this, "handleUserLeave", (user) => {
64355
64685
  const cb = this.observers.get(user.id);
64356
64686
  if (cb) {
64357
- this.requestUserMap(user.id).unobserve(cb);
64687
+ removeObserver4(this.requestUserMap(user.id), cb);
64358
64688
  }
64359
64689
  });
64360
64690
  _defineProperty28(this, "handleUserJoin", (user) => {
64361
64691
  const observer = (evt) => {
64362
64692
  this.handleViewMatrixUpdate(user.id, evt);
64363
64693
  };
64694
+ if (this.observers.has(user.id)) {
64695
+ removeObserver4(this.requestUserMap(user.id), observer);
64696
+ }
64364
64697
  this.requestUserMap(user.id).observe(observer);
64365
64698
  this.observers.set(user.id, observer);
64366
64699
  });
@@ -64440,7 +64773,7 @@ var Camera = class extends EventEmitter8 {
64440
64773
  });
64441
64774
  this.maxScale = maxScale;
64442
64775
  this.bound = window.document.createElement("div");
64443
- this.bound.style.cssText = `transition: box-shadow 100ms;pointer-events:none;z-index:99;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);`;
64776
+ this.bound.style.cssText = "transition: box-shadow 100ms;pointer-events:none;z-index:99;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);";
64444
64777
  this.initSize = initSize;
64445
64778
  this.hasPermission = hasPermission;
64446
64779
  this.paperSize = _paperSize;
@@ -64465,6 +64798,9 @@ var Camera = class extends EventEmitter8 {
64465
64798
  const observer = (evt) => {
64466
64799
  this.handleViewMatrixUpdate(userId, evt);
64467
64800
  };
64801
+ if (this.observers.has(userId)) {
64802
+ removeObserver4(this.requestUserMap(userId), observer);
64803
+ }
64468
64804
  this.requestUserMap(userId).observe(observer);
64469
64805
  this.observers.set(userId, observer);
64470
64806
  });
@@ -64501,7 +64837,7 @@ var Camera = class extends EventEmitter8 {
64501
64837
  this.bound.style.boxShadow = `inset 0px 0px 6px 2px ${this.boundaryColor}`;
64502
64838
  window.clearTimeout(this.boundTiemoutId);
64503
64839
  this.boundTiemoutId = window.setTimeout(() => {
64504
- this.bound.style.boxShadow = `none`;
64840
+ this.bound.style.boxShadow = "none";
64505
64841
  }, 100);
64506
64842
  }
64507
64843
  }
@@ -64511,6 +64847,9 @@ var Camera = class extends EventEmitter8 {
64511
64847
  updateInherentScale(scale) {
64512
64848
  this.inherentScale = scale;
64513
64849
  }
64850
+ getInherentScale() {
64851
+ return this.inherentScale;
64852
+ }
64514
64853
  getActiveMatrix() {
64515
64854
  const cameraMode = this.requestUserMap(this.userManager.selfId).get(WhiteboardKeys.cameraMode);
64516
64855
  let matrixValue;
@@ -64653,6 +64992,19 @@ var Camera = class extends EventEmitter8 {
64653
64992
  y: 0
64654
64993
  };
64655
64994
  }
64995
+ dispose() {
64996
+ Array.from(this.observers.keys()).forEach((userId) => {
64997
+ const cb = this.observers.get(userId);
64998
+ if (cb) {
64999
+ removeObserver4(this.requestUserMap(userId), cb);
65000
+ }
65001
+ });
65002
+ removeObserver4(this.whiteboardAttrsMap, this.handleMainCameraChange);
65003
+ this.userManager.off("join", this.handleUserJoin);
65004
+ this.userManager.off("leave", this.handleUserLeave);
65005
+ this.gesture.removeAllListeners();
65006
+ this.removeAllListeners();
65007
+ }
64656
65008
  };
64657
65009
  function _defineProperty29(e, r, t) {
64658
65010
  return (r = _toPropertyKey29(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -64677,9 +65029,13 @@ var EllipseTool = class extends WhiteboardTool {
64677
65029
  _defineProperty29(this, "elementModel", null);
64678
65030
  _defineProperty29(this, "from", null);
64679
65031
  _defineProperty29(this, "to", null);
65032
+ _defineProperty29(this, "showLiveCursor", true);
64680
65033
  this.tool.minDistance = 1;
64681
65034
  }
64682
65035
  onMouseDown(event) {
65036
+ if (this.elementModel) {
65037
+ this.elementModel.dispose();
65038
+ }
64683
65039
  this.elementModel = this.modelGetter().createSegmentedPath("ellipse", true);
64684
65040
  this.from = event.point.clone();
64685
65041
  this.to = event.point.clone();
@@ -64726,9 +65082,13 @@ var TriangleTool = class extends WhiteboardTool {
64726
65082
  _defineProperty30(this, "elementModel", null);
64727
65083
  _defineProperty30(this, "from", null);
64728
65084
  _defineProperty30(this, "to", null);
65085
+ _defineProperty30(this, "showLiveCursor", true);
64729
65086
  this.tool.minDistance = 1;
64730
65087
  }
64731
65088
  onMouseDown(event) {
65089
+ if (this.elementModel) {
65090
+ this.elementModel.dispose();
65091
+ }
64732
65092
  this.elementModel = this.modelGetter().createTriangle(true);
64733
65093
  this.from = event.point.clone();
64734
65094
  this.to = event.point.clone();
@@ -64765,8 +65125,7 @@ function _toPrimitive31(t, r) {
64765
65125
  }
64766
65126
  return ("string" === r ? String : Number)(t);
64767
65127
  }
64768
- var Whiteboard = class extends EventEmitter9 {
64769
- // public insertImage!: (src: string) => void;
65128
+ var Whiteboard = class extends EventEmitter8 {
64770
65129
  constructor(view) {
64771
65130
  super();
64772
65131
  _defineProperty31(this, "view", void 0);
@@ -64785,6 +65144,7 @@ var Whiteboard = class extends EventEmitter9 {
64785
65144
  _defineProperty31(this, "enableCameraBoundaryHighlight", void 0);
64786
65145
  _defineProperty31(this, "getElementAttribute", void 0);
64787
65146
  _defineProperty31(this, "setElementAttribute", void 0);
65147
+ _defineProperty31(this, "removeElement", void 0);
64788
65148
  _defineProperty31(this, "getCurrentTool", void 0);
64789
65149
  _defineProperty31(this, "setCurrentTool", void 0);
64790
65150
  _defineProperty31(this, "setCanvasBackgroundColor", void 0);
@@ -64799,6 +65159,8 @@ var Whiteboard = class extends EventEmitter9 {
64799
65159
  _defineProperty31(this, "translateCamera", void 0);
64800
65160
  _defineProperty31(this, "scaleCamera", void 0);
64801
65161
  _defineProperty31(this, "resetCamera", void 0);
65162
+ _defineProperty31(this, "showLiveCursor", void 0);
65163
+ _defineProperty31(this, "updateViewport", void 0);
64802
65164
  _defineProperty31(this, "setFreeModelUserPage", void 0);
64803
65165
  _defineProperty31(this, "indexedNavigation", void 0);
64804
65166
  _defineProperty31(this, "setViewModeToFree", void 0);
@@ -64811,6 +65173,7 @@ var Whiteboard = class extends EventEmitter9 {
64811
65173
  _defineProperty31(this, "rasterizeElementsBounds", void 0);
64812
65174
  _defineProperty31(this, "rasterizeMaxBounds", void 0);
64813
65175
  _defineProperty31(this, "setInputType", void 0);
65176
+ _defineProperty31(this, "insertImage", void 0);
64814
65177
  this.view = view;
64815
65178
  }
64816
65179
  };
@@ -64832,16 +65195,22 @@ function _toPrimitive32(t, r) {
64832
65195
  return ("string" === r ? String : Number)(t);
64833
65196
  }
64834
65197
  var EraserTool = class extends WhiteboardTool {
64835
- constructor(enableToolEvent, renderableModel, shadowEmitter, scope, trashedElementsModel) {
65198
+ constructor(enableToolEvent, renderableModel, shadowEmitter, scope, trashedElementsModel, shadowScope) {
64836
65199
  super(enableToolEvent, renderableModel, shadowEmitter, scope);
64837
65200
  _defineProperty32(this, "elementModel", null);
64838
65201
  _defineProperty32(this, "trashedElementsModel", void 0);
64839
65202
  _defineProperty32(this, "pointCount", 0);
65203
+ _defineProperty32(this, "showLiveCursor", true);
65204
+ _defineProperty32(this, "shadowScope", void 0);
64840
65205
  this.trashedElementsModel = trashedElementsModel;
64841
- this.tool.minDistance = 1;
65206
+ this.tool.minDistance = 2;
65207
+ this.shadowScope = shadowScope;
64842
65208
  }
64843
- onMouseDown(event) {
65209
+ onMouseDown(_event) {
64844
65210
  this.pointCount = 0;
65211
+ if (this.elementModel) {
65212
+ this.elementModel.dispose();
65213
+ }
64845
65214
  this.elementModel = this.modelGetter().createEraser();
64846
65215
  }
64847
65216
  onMouseDrag(event) {
@@ -64862,8 +65231,18 @@ var EraserTool = class extends WhiteboardTool {
64862
65231
  this.trashedElementsModel.addTrashedElementForSelf(item.data.uuid, item.data.ownerId);
64863
65232
  }
64864
65233
  });
65234
+ this.shadowScope.project.activeLayer.children.forEach((item) => {
65235
+ if (item.data.type && ["selector", "eraser", "laser"].indexOf(item.data.type) < 0 && item.hitTest(event.point, {
65236
+ segments: true,
65237
+ stroke: true,
65238
+ fill: true,
65239
+ tolerance: 5
65240
+ })) {
65241
+ this.trashedElementsModel.addTrashedElementForSelf(item.data.uuid, item.data.ownerId);
65242
+ }
65243
+ });
64865
65244
  }
64866
- onMouseUp(event) {
65245
+ onMouseUp(_event) {
64867
65246
  if (this.elementModel) {
64868
65247
  this.modelGetter().removeElementItem(this.elementModel.uuid);
64869
65248
  }
@@ -64887,7 +65266,7 @@ function _toPrimitive33(t, r) {
64887
65266
  }
64888
65267
  return ("string" === r ? String : Number)(t);
64889
65268
  }
64890
- var TrashedElementsModel = class extends EventEmitter10 {
65269
+ var TrashedElementsModel = class extends EventEmitter9 {
64891
65270
  get hasDeleteSelfPermission() {
64892
65271
  return this.hasPermission(WhiteboardPermissionFlag.deleteSelf);
64893
65272
  }
@@ -64903,13 +65282,16 @@ var TrashedElementsModel = class extends EventEmitter10 {
64903
65282
  _defineProperty33(this, "handleUserLeave", (user) => {
64904
65283
  const cb = this.observers.get(user.id);
64905
65284
  if (cb) {
64906
- this.requestUserMap(user.id).unobserveDeep(cb);
65285
+ removeDeepObserver3(this.requestUserMap(user.id), cb);
64907
65286
  }
64908
65287
  });
64909
65288
  _defineProperty33(this, "handleUserJoin", (user) => {
64910
65289
  const observer = (evts) => {
64911
65290
  this.handleUserTrashElementsChange(user.id, evts);
64912
65291
  };
65292
+ if (this.observers.has(user.id)) {
65293
+ removeDeepObserver3(this.requestUserMap(user.id), this.observers.get(user.id));
65294
+ }
64913
65295
  this.requestUserMap(user.id).observeDeep(observer);
64914
65296
  this.observers.set(user.id, observer);
64915
65297
  });
@@ -64921,6 +65303,9 @@ var TrashedElementsModel = class extends EventEmitter10 {
64921
65303
  const observer = (evts) => {
64922
65304
  this.handleUserTrashElementsChange(userId, evts);
64923
65305
  };
65306
+ if (this.observers.has(userId)) {
65307
+ removeDeepObserver3(this.requestUserMap(userId), userId);
65308
+ }
64924
65309
  this.requestUserMap(userId).observeDeep(observer);
64925
65310
  this.observers.set(userId, observer);
64926
65311
  });
@@ -64975,12 +65360,9 @@ var TrashedElementsModel = class extends EventEmitter10 {
64975
65360
  });
64976
65361
  }
64977
65362
  dispose() {
64978
- this.userManager.userIdList().forEach((userId) => {
64979
- const cb = this.observers.get(userId);
64980
- if (cb) {
64981
- this.requestUserMap(userId).unobserveDeep(cb);
64982
- }
64983
- });
65363
+ for (const [key, value] of this.observers.entries()) {
65364
+ removeDeepObserver3(this.requestUserMap(key), value);
65365
+ }
64984
65366
  this.observers.clear();
64985
65367
  this.userManager.off("leave", this.handleUserLeave);
64986
65368
  this.userManager.off("join", this.handleUserJoin);
@@ -65008,10 +65390,14 @@ var LaserPointerTool = class extends WhiteboardTool {
65008
65390
  super(enableToolEvent, modelGetter, shadowEmitter, scope);
65009
65391
  _defineProperty34(this, "elementModel", null);
65010
65392
  _defineProperty34(this, "pointCount", 0);
65393
+ _defineProperty34(this, "showLiveCursor", true);
65011
65394
  this.tool.minDistance = 5;
65012
65395
  }
65013
- onMouseDown(event) {
65396
+ onMouseDown(_event) {
65014
65397
  this.pointCount = 0;
65398
+ if (this.elementModel) {
65399
+ this.elementModel.dispose();
65400
+ }
65015
65401
  this.elementModel = this.modelGetter().createLaserPointer();
65016
65402
  }
65017
65403
  onMouseDrag(event) {
@@ -65023,7 +65409,7 @@ var LaserPointerTool = class extends WhiteboardTool {
65023
65409
  this.elementModel.appendPoints([event.point.x, event.point.y]);
65024
65410
  }
65025
65411
  }
65026
- onMouseUp(event) {
65412
+ onMouseUp(_event) {
65027
65413
  if (this.elementModel) {
65028
65414
  this.elementModel.beginRemoveAnimate();
65029
65415
  }
@@ -65046,7 +65432,7 @@ function _toPrimitive35(t, r) {
65046
65432
  }
65047
65433
  return ("string" === r ? String : Number)(t);
65048
65434
  }
65049
- var PageModel = class extends EventEmitter11 {
65435
+ var PageModel = class extends EventEmitter10 {
65050
65436
  constructor(whiteboardAttrsMap, userManager, requestUserMap, pageMap, hasPermission) {
65051
65437
  super();
65052
65438
  _defineProperty35(this, "whiteboardAttrsMap", void 0);
@@ -65058,7 +65444,7 @@ var PageModel = class extends EventEmitter11 {
65058
65444
  _defineProperty35(this, "handleUserLeave", (user) => {
65059
65445
  const cb = this.observers.get(user.id);
65060
65446
  if (cb) {
65061
- this.requestUserMap(user.id).unobserve(cb);
65447
+ removeObserver5(this.requestUserMap(user.id), cb);
65062
65448
  }
65063
65449
  });
65064
65450
  _defineProperty35(this, "handleUserJoin", (user) => {
@@ -65072,7 +65458,7 @@ var PageModel = class extends EventEmitter11 {
65072
65458
  if (cameraMode === "main") {
65073
65459
  const targetPage = this.whiteboardAttrsMap.get(WhiteboardKeys.currentPage);
65074
65460
  if (!this.pageMap.has(targetPage) && targetPage !== "_i_") {
65075
- log(`main page {${targetPage}} not found.`, {}, "error");
65461
+ log2(`main page {${targetPage}} not found.`, {}, "error");
65076
65462
  return;
65077
65463
  }
65078
65464
  this.requestUserMap(this.userManager.selfId).set(WhiteboardKeys.currentPage, targetPage);
@@ -65141,11 +65527,11 @@ var PageModel = class extends EventEmitter11 {
65141
65527
  }
65142
65528
  const cameraMode = this.requestUserMap(this.userManager.selfId).get(WhiteboardKeys.cameraMode);
65143
65529
  if (cameraMode !== "main") {
65144
- console.warn(`cannot modify pages in non-main view mode.`);
65530
+ console.warn("cannot modify pages in non-main view mode.");
65145
65531
  return false;
65146
65532
  }
65147
65533
  if (!this.hasPermission(WhiteboardPermissionFlag.mainView)) {
65148
- console.warn(`cannot modify pages without WhiteboardPermissionFlag.mainView.`);
65534
+ console.warn("cannot modify pages without WhiteboardPermissionFlag.mainView.");
65149
65535
  return false;
65150
65536
  }
65151
65537
  return true;
@@ -65197,13 +65583,22 @@ var PageModel = class extends EventEmitter11 {
65197
65583
  }
65198
65584
  }
65199
65585
  }
65586
+ dispose() {
65587
+ for (const entry of this.observers.entries()) {
65588
+ const [userId, observer] = entry;
65589
+ removeObserver5(this.requestUserMap(userId), observer);
65590
+ }
65591
+ this.userManager.off("join", this.handleUserJoin);
65592
+ this.userManager.off("leave", this.handleUserLeave);
65593
+ removeObserver5(this.whiteboardAttrsMap, this.handleMainPageChange);
65594
+ removeObserver5(this.pageMap, this.handlePageMapChange);
65595
+ }
65200
65596
  };
65201
65597
  var delay = (value) => new Promise((resolve) => setTimeout(resolve, value));
65202
65598
  async function waitUntil(fn, timeout) {
65203
- let start = Date.now();
65599
+ const start = Date.now();
65204
65600
  while (!fn() && Date.now() - start < timeout) {
65205
65601
  await delay(50);
65206
- start = Date.now();
65207
65602
  }
65208
65603
  }
65209
65604
  function _defineProperty36(e, r, t) {
@@ -65223,19 +65618,19 @@ function _toPrimitive36(t, r) {
65223
65618
  }
65224
65619
  return ("string" === r ? String : Number)(t);
65225
65620
  }
65226
- var IndexedNavigation = class extends EventEmitter12 {
65621
+ var IndexedNavigation = class extends EventEmitter11 {
65227
65622
  get idList() {
65228
65623
  return this.pageModel.pageList().filter((id) => /^_i_/.test(id));
65229
65624
  }
65230
65625
  get head() {
65231
- let headId = Object.keys(this.list).find((key) => {
65626
+ const headId = Object.keys(this.list).find((key) => {
65232
65627
  return this.list[key] && this.list[key].prev === "";
65233
65628
  });
65234
65629
  if (!headId) {
65235
- log2(`indexed navigation confusion`, {
65630
+ log3("indexed navigation confusion", {
65236
65631
  list: JSON.stringify(this.list)
65237
65632
  }, "error");
65238
- throw new Error(`indexed navigation confusion`);
65633
+ throw new Error("indexed navigation confusion");
65239
65634
  }
65240
65635
  return headId;
65241
65636
  }
@@ -65256,7 +65651,7 @@ var IndexedNavigation = class extends EventEmitter12 {
65256
65651
  _defineProperty36(this, "indexedPageMap", void 0);
65257
65652
  _defineProperty36(this, "list", {});
65258
65653
  _defineProperty36(this, "hasPermission", void 0);
65259
- _defineProperty36(this, "handleIndexedPageMapUpdate", (evt) => {
65654
+ _defineProperty36(this, "handleIndexedPageMapUpdate", (_evt) => {
65260
65655
  this.list = this.indexedPageMap.get("list");
65261
65656
  const needRemoveList = this.pageModel.pageList().filter((v) => /^_i_/.test(v) && Object.keys(this.list).indexOf(v) < 0);
65262
65657
  const needAddList = Object.keys(this.list).filter((v) => this.pageModel.pageList().indexOf(v) < 0);
@@ -65311,8 +65706,8 @@ var IndexedNavigation = class extends EventEmitter12 {
65311
65706
  initIndexed() {
65312
65707
  return new Promise((resolve) => {
65313
65708
  setTimeout(() => {
65709
+ this.pageModel.addPage("_i_");
65314
65710
  if (this.pageModel.pageList().length === 0) {
65315
- this.pageModel.addPage("_i_");
65316
65711
  resolve(true);
65317
65712
  } else {
65318
65713
  resolve(false);
@@ -65321,19 +65716,22 @@ var IndexedNavigation = class extends EventEmitter12 {
65321
65716
  });
65322
65717
  }
65323
65718
  /**
65324
- * 获取总页数
65325
- * @returns {number}
65326
- */
65719
+ * 获取总页数
65720
+ * @returns {number}
65721
+ */
65327
65722
  get pageCount() {
65328
65723
  return this.idList.length;
65329
65724
  }
65330
65725
  /**
65331
- * 获取当前页索引
65332
- */
65726
+ * 获取当前页索引
65727
+ */
65333
65728
  get currentPageIndex() {
65334
65729
  const userPageId = this.userMap.get(WhiteboardKeys.currentPage);
65335
65730
  return this.getPageIndex(userPageId);
65336
65731
  }
65732
+ get currentPageId() {
65733
+ return this.userMap.get(WhiteboardKeys.currentPage);
65734
+ }
65337
65735
  getPageIndex(pageId) {
65338
65736
  let i = 0;
65339
65737
  let currentId = this.head;
@@ -65349,9 +65747,9 @@ var IndexedNavigation = class extends EventEmitter12 {
65349
65747
  return i;
65350
65748
  }
65351
65749
  /**
65352
- * 获取指定索引对应的 pageId
65353
- * @param {number} index
65354
- */
65750
+ * 获取指定索引对应的 pageId
65751
+ * @param {number} index
65752
+ */
65355
65753
  getPageId(index) {
65356
65754
  const firstKey = this.head;
65357
65755
  if (firstKey) {
@@ -65373,20 +65771,20 @@ var IndexedNavigation = class extends EventEmitter12 {
65373
65771
  modifyDetect() {
65374
65772
  const cameraMode = this.userMap.get(WhiteboardKeys.cameraMode);
65375
65773
  if (cameraMode !== "main") {
65376
- console.warn(`cannot modify pages in non-main view mode.`);
65774
+ console.warn("cannot modify pages in non-main view mode.");
65377
65775
  return false;
65378
65776
  }
65379
65777
  if (!this.hasPermission(WhiteboardPermissionFlag.mainView)) {
65380
- console.warn(`cannot modify pages without WhiteboardPermissionFlag.mainView.`);
65778
+ console.warn("cannot modify pages without WhiteboardPermissionFlag.mainView.");
65381
65779
  return false;
65382
65780
  }
65383
65781
  return true;
65384
65782
  }
65385
65783
  /**
65386
- * 在尾部插入新页面
65387
- * @param {boolean=} goto 是否跳转到新页面, 默认 true
65388
- * @return 总页数
65389
- */
65784
+ * 在尾部插入新页面
65785
+ * @param {boolean=} goto 是否跳转到新页面, 默认 true
65786
+ * @return 总页数
65787
+ */
65390
65788
  pushPage() {
65391
65789
  let goto = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
65392
65790
  this.indexedPageMap.doc.transact(() => {
@@ -65415,11 +65813,11 @@ var IndexedNavigation = class extends EventEmitter12 {
65415
65813
  return this.pageCount;
65416
65814
  }
65417
65815
  /**
65418
- * 在 after 之后插入新页面
65419
- * @param {number} after 在此页之后插入
65420
- * @param {boolean=} goto 是否跳转到新页面, 默认 true
65421
- * @return 总页数
65422
- */
65816
+ * 在 after 之后插入新页面
65817
+ * @param {number} after 在此页之后插入
65818
+ * @param {boolean=} goto 是否跳转到新页面, 默认 true
65819
+ * @return 总页数
65820
+ */
65423
65821
  insertPage(after) {
65424
65822
  let goto = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
65425
65823
  const afterPageId = this.getPageId(after);
@@ -65428,7 +65826,7 @@ var IndexedNavigation = class extends EventEmitter12 {
65428
65826
  }
65429
65827
  const cameraMode = this.userMap.get(WhiteboardKeys.cameraMode);
65430
65828
  if (cameraMode !== "main") {
65431
- console.warn(`cannot modify pages in non-main view mode.`);
65829
+ console.warn("cannot modify pages in non-main view mode.");
65432
65830
  return this.pageCount;
65433
65831
  }
65434
65832
  const prev = this.list[afterPageId];
@@ -65471,8 +65869,8 @@ var IndexedNavigation = class extends EventEmitter12 {
65471
65869
  return this.pageCount;
65472
65870
  }
65473
65871
  /**
65474
- * 跳转至上一页, 并返回跳转后的页面索引.
65475
- */
65872
+ * 跳转至上一页, 并返回跳转后的页面索引.
65873
+ */
65476
65874
  prevPage() {
65477
65875
  const currentPageId = this.userMap.get(WhiteboardKeys.currentPage);
65478
65876
  const data = this.list[currentPageId];
@@ -65484,8 +65882,8 @@ var IndexedNavigation = class extends EventEmitter12 {
65484
65882
  return nextIndex;
65485
65883
  }
65486
65884
  /**
65487
- * 跳转至下一页, 并返回跳转后的页面索引.
65488
- */
65885
+ * 跳转至下一页, 并返回跳转后的页面索引.
65886
+ */
65489
65887
  nextPage() {
65490
65888
  const currentPageId = this.userMap.get(WhiteboardKeys.currentPage);
65491
65889
  const data = this.list[currentPageId];
@@ -65497,16 +65895,14 @@ var IndexedNavigation = class extends EventEmitter12 {
65497
65895
  return nextIndex;
65498
65896
  }
65499
65897
  /**
65500
- * 删除指定页面
65501
- * @param {number} index
65502
- */
65898
+ * 删除指定页面
65899
+ * @param {number} index
65900
+ */
65503
65901
  removePage(index) {
65504
65902
  if (this.pageCount <= 1) {
65505
65903
  return this.pageCount;
65506
65904
  }
65507
- const cameraMode = this.userMap.get(WhiteboardKeys.cameraMode);
65508
- if (cameraMode !== "main") {
65509
- console.warn(`cannot modify pages in non-main view mode.`);
65905
+ if (!this.modifyDetect()) {
65510
65906
  return this.pageCount;
65511
65907
  }
65512
65908
  const targetId = this.getPageId(index);
@@ -65546,6 +65942,11 @@ var IndexedNavigation = class extends EventEmitter12 {
65546
65942
  this.pageModel.gotoPage(targetId);
65547
65943
  }
65548
65944
  }
65945
+ dispose() {
65946
+ removeObserver6(this.indexedPageMap, this.handleIndexedPageMapUpdate);
65947
+ this.pageModel.off("switchPage");
65948
+ this.pageModel.off("pagesChange");
65949
+ }
65549
65950
  };
65550
65951
  function _defineProperty37(e, r, t) {
65551
65952
  return (r = _toPropertyKey37(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
@@ -65564,7 +65965,7 @@ function _toPrimitive37(t, r) {
65564
65965
  }
65565
65966
  return ("string" === r ? String : Number)(t);
65566
65967
  }
65567
- var ShadowEmitter = class extends EventEmitter13 {
65968
+ var ShadowEmitter = class extends EventEmitter12 {
65568
65969
  constructor(userMap) {
65569
65970
  super();
65570
65971
  _defineProperty37(this, "userMap", void 0);
@@ -65600,9 +66001,13 @@ var StraightLineTool = class extends WhiteboardTool {
65600
66001
  _defineProperty38(this, "elementModel", null);
65601
66002
  _defineProperty38(this, "from", null);
65602
66003
  _defineProperty38(this, "to", null);
66004
+ _defineProperty38(this, "showLiveCursor", true);
65603
66005
  this.tool.minDistance = 1;
65604
66006
  }
65605
66007
  onMouseDown(event) {
66008
+ if (this.elementModel) {
66009
+ this.elementModel.dispose();
66010
+ }
65606
66011
  this.elementModel = this.modelGetter().createStraightLine(true);
65607
66012
  this.from = event.point.clone();
65608
66013
  this.to = event.point.clone();
@@ -65644,6 +66049,7 @@ var GrabTool = class extends WhiteboardTool {
65644
66049
  super(enableToolEvent, modelGetter, shadowEmitter, scope);
65645
66050
  _defineProperty39(this, "camera", void 0);
65646
66051
  _defineProperty39(this, "downPoint", null);
66052
+ _defineProperty39(this, "showLiveCursor", false);
65647
66053
  this.camera = camera;
65648
66054
  }
65649
66055
  onMouseDown(event) {
@@ -65662,25 +66068,207 @@ var GrabTool = class extends WhiteboardTool {
65662
66068
  this.shadowEmitter.emit("grabUp");
65663
66069
  }
65664
66070
  };
66071
+ function _defineProperty40(e, r, t) {
66072
+ return (r = _toPropertyKey40(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
66073
+ }
66074
+ function _toPropertyKey40(t) {
66075
+ var i = _toPrimitive40(t, "string");
66076
+ return "symbol" == typeof i ? i : i + "";
66077
+ }
66078
+ function _toPrimitive40(t, r) {
66079
+ if ("object" != typeof t || !t) return t;
66080
+ var e = t[Symbol.toPrimitive];
66081
+ if (void 0 !== e) {
66082
+ var i = e.call(t, r || "default");
66083
+ if ("object" != typeof i) return i;
66084
+ throw new TypeError("@@toPrimitive must return a primitive value.");
66085
+ }
66086
+ return ("string" === r ? String : Number)(t);
66087
+ }
65665
66088
  var PointerTool = class extends WhiteboardTool {
65666
66089
  constructor(enableToolEvent, modelGetter, shadowEmitter, scope) {
65667
66090
  super(enableToolEvent, modelGetter, shadowEmitter, scope);
66091
+ _defineProperty40(this, "showLiveCursor", false);
65668
66092
  }
65669
- onMouseDown(event) {
66093
+ onMouseDown(_event) {
65670
66094
  }
65671
- onMouseDrag(event) {
66095
+ onMouseDrag(_event) {
65672
66096
  }
65673
66097
  onMouseUp() {
65674
66098
  }
65675
66099
  };
65676
- function _defineProperty40(e, r, t) {
65677
- return (r = _toPropertyKey40(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
66100
+ function _defineProperty41(e, r, t) {
66101
+ return (r = _toPropertyKey41(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
65678
66102
  }
65679
- function _toPropertyKey40(t) {
65680
- var i = _toPrimitive40(t, "string");
66103
+ function _toPropertyKey41(t) {
66104
+ var i = _toPrimitive41(t, "string");
65681
66105
  return "symbol" == typeof i ? i : i + "";
65682
66106
  }
65683
- function _toPrimitive40(t, r) {
66107
+ function _toPrimitive41(t, r) {
66108
+ if ("object" != typeof t || !t) return t;
66109
+ var e = t[Symbol.toPrimitive];
66110
+ if (void 0 !== e) {
66111
+ var i = e.call(t, r || "default");
66112
+ if ("object" != typeof i) return i;
66113
+ throw new TypeError("@@toPrimitive must return a primitive value.");
66114
+ }
66115
+ return ("string" === r ? String : Number)(t);
66116
+ }
66117
+ var SequenceExecutor = class {
66118
+ constructor() {
66119
+ _defineProperty41(this, "tasks", []);
66120
+ _defineProperty41(this, "isRunning", false);
66121
+ }
66122
+ addTask(task) {
66123
+ this.tasks.push(task);
66124
+ if (!this.isRunning) {
66125
+ this.execute();
66126
+ }
66127
+ }
66128
+ async execute() {
66129
+ if (this.isRunning) {
66130
+ return;
66131
+ }
66132
+ this.isRunning = true;
66133
+ while (this.tasks.length > 0) {
66134
+ const task = this.tasks.shift();
66135
+ if (task) {
66136
+ try {
66137
+ await task();
66138
+ } catch (e) {
66139
+ }
66140
+ }
66141
+ }
66142
+ this.isRunning = false;
66143
+ }
66144
+ };
66145
+ function _defineProperty42(e, r, t) {
66146
+ return (r = _toPropertyKey42(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
66147
+ }
66148
+ function _toPropertyKey42(t) {
66149
+ var i = _toPrimitive42(t, "string");
66150
+ return "symbol" == typeof i ? i : i + "";
66151
+ }
66152
+ function _toPrimitive42(t, r) {
66153
+ if ("object" != typeof t || !t) return t;
66154
+ var e = t[Symbol.toPrimitive];
66155
+ if (void 0 !== e) {
66156
+ var i = e.call(t, r || "default");
66157
+ if ("object" != typeof i) return i;
66158
+ throw new TypeError("@@toPrimitive must return a primitive value.");
66159
+ }
66160
+ return ("string" === r ? String : Number)(t);
66161
+ }
66162
+ var LiveCursor = class {
66163
+ constructor(canvasElement, paperScope, userManager, requestUserMap) {
66164
+ _defineProperty42(this, "container", document.createElement("div"));
66165
+ _defineProperty42(this, "showLiveCursor", true);
66166
+ _defineProperty42(this, "userManager", void 0);
66167
+ _defineProperty42(this, "requestUserMap", void 0);
66168
+ _defineProperty42(this, "cursors", /* @__PURE__ */ new Map());
66169
+ _defineProperty42(this, "paperScope", void 0);
66170
+ _defineProperty42(this, "resizeobserver", void 0);
66171
+ _defineProperty42(this, "timeoutIdMap", /* @__PURE__ */ new Map());
66172
+ _defineProperty42(this, "lastVisibleChangeTimes", /* @__PURE__ */ new Map());
66173
+ this.userManager = userManager;
66174
+ this.paperScope = paperScope;
66175
+ this.requestUserMap = requestUserMap;
66176
+ this.container.setAttribute("data-forge-cursors", "");
66177
+ this.container.style.cssText = "overflow:hidden;pointer-events:none;z-index:999;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);";
66178
+ this.container.style.pointerEvents = "none";
66179
+ this.resizeobserver = new ResizeObserver(() => {
66180
+ const bounds = canvasElement.getBoundingClientRect();
66181
+ this.container.style.width = bounds.width + "px";
66182
+ this.container.style.height = bounds.height + "px";
66183
+ });
66184
+ this.resizeobserver.observe(canvasElement);
66185
+ }
66186
+ createCursor(userId) {
66187
+ const cursor = document.createElement("fcursor");
66188
+ cursor.setAttribute("data-forge-cursor", userId);
66189
+ cursor.style.backgroundColor = this.requestUserMap(userId).get(WhiteboardKeys.themeColor);
66190
+ cursor.style.color = "#fff";
66191
+ cursor.style.position = "absolute";
66192
+ cursor.style.whiteSpace = "nowrap";
66193
+ cursor.style.display = "block";
66194
+ cursor.style.fontSize = "12px";
66195
+ cursor.style.padding = "2px 4px";
66196
+ cursor.style.borderRadius = "4px";
66197
+ cursor.textContent = this.userManager.getUser(userId)?.nickName ?? userId;
66198
+ return cursor;
66199
+ }
66200
+ isOnSamePage(userId) {
66201
+ const otherPage = this.requestUserMap(userId).get(WhiteboardKeys.currentPage);
66202
+ const selfPage = this.requestUserMap(this.userManager.selfId).get(WhiteboardKeys.currentPage);
66203
+ if (otherPage !== selfPage) {
66204
+ return false;
66205
+ }
66206
+ return true;
66207
+ }
66208
+ detectEnable(userId) {
66209
+ if (!this.showLiveCursor) {
66210
+ const cursor = this.cursors.get(userId);
66211
+ if (cursor) {
66212
+ cursor.style.display = "none";
66213
+ }
66214
+ }
66215
+ return this.showLiveCursor;
66216
+ }
66217
+ updateCursorPosition(point, userId) {
66218
+ if (!this.isOnSamePage(userId) || userId === this.userManager.selfId) {
66219
+ return;
66220
+ }
66221
+ if (!this.detectEnable(userId)) {
66222
+ return;
66223
+ }
66224
+ const lastVisibleChangeTime = this.lastVisibleChangeTimes.get(userId);
66225
+ if (lastVisibleChangeTime && Date.now() - lastVisibleChangeTime < 100) {
66226
+ return;
66227
+ }
66228
+ if (!this.cursors.has(userId)) {
66229
+ const cursor2 = this.createCursor(userId);
66230
+ this.cursors.set(userId, cursor2);
66231
+ this.container.appendChild(cursor2);
66232
+ }
66233
+ const cursor = this.cursors.get(userId);
66234
+ if (cursor) {
66235
+ const viewPoint = this.paperScope.project.view.projectToView(point);
66236
+ cursor.style.left = viewPoint.x + "px";
66237
+ cursor.style.top = viewPoint.y + "px";
66238
+ cursor.style.display = "block";
66239
+ }
66240
+ if (this.timeoutIdMap.has(userId)) {
66241
+ clearTimeout(this.timeoutIdMap.get(userId));
66242
+ }
66243
+ this.timeoutIdMap.set(userId, setTimeout(() => {
66244
+ const cursor2 = this.cursors.get(userId);
66245
+ if (cursor2) {
66246
+ cursor2.style.display = "none";
66247
+ }
66248
+ }, 5e3));
66249
+ }
66250
+ updateCursorVisible(visible, userId) {
66251
+ if (!this.isOnSamePage(userId) || userId === this.userManager.selfId) {
66252
+ return;
66253
+ }
66254
+ if (!this.detectEnable(userId)) {
66255
+ return;
66256
+ }
66257
+ this.lastVisibleChangeTimes.set(userId, Date.now());
66258
+ const cursor = this.cursors.get(userId);
66259
+ if (cursor) {
66260
+ cursor.style.display = visible ? "block" : "none";
66261
+ }
66262
+ }
66263
+ };
66264
+ function _defineProperty43(e, r, t) {
66265
+ return (r = _toPropertyKey43(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
66266
+ }
66267
+ function _toPropertyKey43(t) {
66268
+ var i = _toPrimitive43(t, "string");
66269
+ return "symbol" == typeof i ? i : i + "";
66270
+ }
66271
+ function _toPrimitive43(t, r) {
65684
66272
  if ("object" != typeof t || !t) return t;
65685
66273
  var e = t[Symbol.toPrimitive];
65686
66274
  if (void 0 !== e) {
@@ -65691,6 +66279,21 @@ function _toPrimitive40(t, r) {
65691
66279
  return ("string" === r ? String : Number)(t);
65692
66280
  }
65693
66281
  var WHITEBOARD_APP_NAME = "whiteboard";
66282
+ var AsyncMap = class {
66283
+ constructor() {
66284
+ _defineProperty43(this, "map", void 0);
66285
+ this.map = /* @__PURE__ */ new Map();
66286
+ }
66287
+ get(key) {
66288
+ return Promise.resolve(this.map.get(key));
66289
+ }
66290
+ set(key, value) {
66291
+ this.map.set(key, value);
66292
+ }
66293
+ };
66294
+ if (!window.__forge_gl_wb_status__) {
66295
+ window.__forge_gl_wb_status__ = new AsyncMap();
66296
+ }
65694
66297
  var WhiteboardApplication = class extends AbstractApplication {
65695
66298
  get undoManager() {
65696
66299
  const page = this.pageModel.getCurrentPage(this.userId);
@@ -65699,47 +66302,116 @@ var WhiteboardApplication = class extends AbstractApplication {
65699
66302
  }
65700
66303
  return null;
65701
66304
  }
66305
+ get viewportWidth() {
66306
+ const vw = this.getMap("attrs").get("viewportWidth");
66307
+ if (vw) {
66308
+ return vw;
66309
+ }
66310
+ return this.option.width;
66311
+ }
66312
+ get viewportHeight() {
66313
+ const vh = this.getMap("attrs").get("viewportHeight");
66314
+ if (vh) {
66315
+ return vh;
66316
+ }
66317
+ return this.option.height;
66318
+ }
65702
66319
  constructor() {
65703
66320
  var _this;
65704
66321
  super();
65705
66322
  _this = this;
65706
- _defineProperty40(this, "name", WHITEBOARD_APP_NAME);
65707
- _defineProperty40(this, "emitter", void 0);
65708
- _defineProperty40(this, "toolbarModel", void 0);
65709
- _defineProperty40(this, "selectElementsModel", void 0);
65710
- _defineProperty40(this, "trashedElementsModel", void 0);
65711
- _defineProperty40(this, "pageModel", void 0);
65712
- _defineProperty40(this, "layers", /* @__PURE__ */ new Map());
65713
- _defineProperty40(this, "undoManagers", /* @__PURE__ */ new Map());
65714
- _defineProperty40(this, "rootElement", document.createElement("div"));
65715
- _defineProperty40(this, "paperScope", new import_paper.default.PaperScope());
65716
- _defineProperty40(this, "canvasElement", document.createElement("canvas"));
65717
- _defineProperty40(this, "shadowScope", new import_paper.default.PaperScope());
65718
- _defineProperty40(this, "snapshotCanvasElement", document.createElement("canvas"));
65719
- _defineProperty40(this, "snapshotScope", new import_paper.default.PaperScope());
65720
- _defineProperty40(this, "shadowCanvasElement", document.createElement("canvas"));
65721
- _defineProperty40(this, "shadowEmitter", void 0);
65722
- _defineProperty40(this, "tools", void 0);
65723
- _defineProperty40(this, "editors", /* @__PURE__ */ new Map());
65724
- _defineProperty40(this, "camera", void 0);
65725
- _defineProperty40(this, "resizeObserver", void 0);
65726
- _defineProperty40(this, "option", void 0);
65727
- _defineProperty40(this, "permissions", void 0);
65728
- _defineProperty40(this, "inputType", "any");
65729
- _defineProperty40(this, "isPenEvent", false);
65730
- _defineProperty40(this, "hasPenInput", null);
65731
- _defineProperty40(this, "disableViewModelUpdate", false);
65732
- _defineProperty40(this, "internalResizeObserver", true);
65733
- _defineProperty40(this, "linkTarget", null);
65734
- _defineProperty40(this, "enableToolEvent", () => {
66323
+ _defineProperty43(this, "name", WHITEBOARD_APP_NAME);
66324
+ _defineProperty43(this, "emitter", void 0);
66325
+ _defineProperty43(this, "toolbarModel", void 0);
66326
+ _defineProperty43(this, "selectElementsModel", void 0);
66327
+ _defineProperty43(this, "trashedElementsModel", void 0);
66328
+ _defineProperty43(this, "pageModel", void 0);
66329
+ _defineProperty43(this, "layers", /* @__PURE__ */ new Map());
66330
+ _defineProperty43(this, "undoManagers", /* @__PURE__ */ new Map());
66331
+ _defineProperty43(this, "imageSets", document.createElement("div"));
66332
+ _defineProperty43(this, "rootElement", document.createElement("div"));
66333
+ _defineProperty43(this, "paperScope", new import_paper.default.PaperScope());
66334
+ _defineProperty43(this, "canvasElement", document.createElement("canvas"));
66335
+ _defineProperty43(this, "shadowScope", new import_paper.default.PaperScope());
66336
+ _defineProperty43(this, "snapshotCanvasElement", document.createElement("canvas"));
66337
+ _defineProperty43(this, "snapshotScope", new import_paper.default.PaperScope());
66338
+ _defineProperty43(this, "shadowCanvasElement", document.createElement("canvas"));
66339
+ _defineProperty43(this, "shadowEmitter", void 0);
66340
+ _defineProperty43(this, "tools", void 0);
66341
+ _defineProperty43(this, "editors", /* @__PURE__ */ new Map());
66342
+ _defineProperty43(this, "camera", void 0);
66343
+ _defineProperty43(this, "resizeObserver", void 0);
66344
+ _defineProperty43(this, "option", void 0);
66345
+ _defineProperty43(this, "permissions", void 0);
66346
+ _defineProperty43(this, "inputType", "any");
66347
+ _defineProperty43(this, "isPenEvent", false);
66348
+ _defineProperty43(this, "hasPenInput", null);
66349
+ _defineProperty43(this, "disableViewModelUpdate", false);
66350
+ _defineProperty43(this, "internalResizeObserver", true);
66351
+ _defineProperty43(this, "sequenceExecutor", new SequenceExecutor());
66352
+ _defineProperty43(this, "linkWhiteboardId", null);
66353
+ _defineProperty43(this, "liveCursor", void 0);
66354
+ _defineProperty43(this, "delayTranslateOut", -1);
66355
+ _defineProperty43(this, "addWhiteboardStatus", (evt) => {
66356
+ if (evt.detail.whiteboardAppId && evt.detail.status) {
66357
+ if (this.linkWhiteboardId === evt.detail.whiteboardAppId) {
66358
+ this.toolbarModel.currentTool = evt.detail.status.currentTool;
66359
+ this.toolbarModel.strokeColor = evt.detail.status.strokeColor;
66360
+ this.toolbarModel.fillColor = evt.detail.status.fillColor;
66361
+ this.toolbarModel.fontSize = evt.detail.status.fontSize;
66362
+ this.toolbarModel.fontFamily = evt.detail.status.fontFamily;
66363
+ this.toolbarModel.strokeWidth = evt.detail.status.strokeWidth;
66364
+ this.toolbarModel.dashArray = evt.detail.status.dashArray;
66365
+ this.permissions.removePermission(WhiteboardPermissionFlag.all);
66366
+ this.permissions.addPermission(evt.detail.status.permission);
66367
+ }
66368
+ }
66369
+ });
66370
+ _defineProperty43(this, "enableToolEvent", () => {
65735
66371
  return !(this.inputType === "pen" && !this.isPenEvent);
65736
66372
  });
65737
- _defineProperty40(this, "handlePageSwitch", (pageId) => {
65738
- for (const editor of this.editors.values()) {
65739
- editor.hidden();
66373
+ _defineProperty43(this, "handleViewportUpdate", (evt) => {
66374
+ if (evt.keysChanged.has("viewportWidth") || evt.keysChanged.has("viewportHeight")) {
66375
+ const rect = this.rootElement.getBoundingClientRect();
66376
+ this.adjustByOutFrame(rect.width, rect.height);
65740
66377
  }
65741
- this.selectElementsModel.clearSelectElementForSelf();
65742
- waitUntil(() => this.layers.has(pageId), 3e3).then(() => {
66378
+ });
66379
+ _defineProperty43(this, "handleElementTranslateOut", (ids, container) => {
66380
+ const shadowLayer = this.shadowScope.project.activeLayer;
66381
+ let parent = null;
66382
+ if (container === "layer") {
66383
+ parent = shadowLayer;
66384
+ } else {
66385
+ parent = shadowLayer.children.find((child) => child.data.uuid === container) ?? null;
66386
+ }
66387
+ if (parent) {
66388
+ ids.forEach((id) => {
66389
+ const target = parent.children.find((child) => child.data.uuid === id);
66390
+ if (target) {
66391
+ target.remove();
66392
+ this.insertElementToParent(target, this.paperScope.project.activeLayer);
66393
+ } else {
66394
+ const pageId = this.pageModel.getCurrentPage(this.userId);
66395
+ if (pageId) {
66396
+ const page = this.layers.get(pageId);
66397
+ if (page) {
66398
+ const model = page.elementModels.get(id);
66399
+ if (model && model.item) {
66400
+ this.insertElementToParent(model.item, this.paperScope.project.activeLayer);
66401
+ }
66402
+ }
66403
+ }
66404
+ }
66405
+ });
66406
+ }
66407
+ });
66408
+ _defineProperty43(this, "handlePageSwitch", (pageId) => {
66409
+ this.sequenceExecutor.addTask(async () => {
66410
+ for (const editor of this.editors.values()) {
66411
+ editor.hidden();
66412
+ }
66413
+ this.selectElementsModel.clearSelectElementForSelf();
66414
+ await waitUntil(() => this.layers.has(pageId), 1e3);
65743
66415
  if (this.layers.has(pageId)) {
65744
66416
  for (const entry of this.layers.entries()) {
65745
66417
  entry[1].off("elementInsert", this.handleElementInsert);
@@ -65751,6 +66423,7 @@ var WhiteboardApplication = class extends AbstractApplication {
65751
66423
  renderableModel.on("elementRemove", this.handleElementRemove);
65752
66424
  renderableModel.on("elementClear", this.handleElementClear);
65753
66425
  renderableModel.flushRenderables();
66426
+ this.paperScope.project.activeLayer.data.pageId = pageId;
65754
66427
  const others = this.userManager.userIdList().filter((v) => v !== this.userId);
65755
66428
  for (const other of others) {
65756
66429
  if (this.userMap(other).get(WhiteboardKeys.currentPage) === pageId) {
@@ -65760,9 +66433,11 @@ var WhiteboardApplication = class extends AbstractApplication {
65760
66433
  }
65761
66434
  }
65762
66435
  }
66436
+ } else {
66437
+ console.warn(`[@netless/forge-whiteboard] page ${pageId} not found`);
66438
+ log4(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warning");
65763
66439
  }
65764
- });
65765
- waitUntil(() => this.undoManagers.has(pageId), 3e3).then(() => {
66440
+ await waitUntil(() => this.undoManagers.has(pageId), 1e3);
65766
66441
  if (this.undoManagers.has(pageId)) {
65767
66442
  for (const entry of this.undoManagers.entries()) {
65768
66443
  entry[1].off("stack-item-added", this.handleStackItemAdded);
@@ -65770,29 +66445,32 @@ var WhiteboardApplication = class extends AbstractApplication {
65770
66445
  }
65771
66446
  this.undoManagers.get(pageId).on("stack-item-added", this.handleStackItemAdded);
65772
66447
  this.undoManagers.get(pageId).on("stack-item-popped", this.handleStackItemPopped);
66448
+ } else {
66449
+ console.warn(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`);
66450
+ log4(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warning");
65773
66451
  }
66452
+ this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
66453
+ this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
65774
66454
  });
65775
- this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
65776
- this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
65777
66455
  });
65778
- _defineProperty40(this, "hasPermission", (flag) => {
66456
+ _defineProperty43(this, "hasPermission", (flag) => {
65779
66457
  return this.permissions.hasPermission(flag, this.userId);
65780
66458
  });
65781
- _defineProperty40(this, "handleStackItemAdded", () => {
66459
+ _defineProperty43(this, "handleStackItemAdded", () => {
65782
66460
  this.selectElementsModel.clearSelectElementForSelf();
65783
66461
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
65784
66462
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
65785
66463
  });
65786
- _defineProperty40(this, "handleStackItemPopped", () => {
66464
+ _defineProperty43(this, "handleStackItemPopped", () => {
65787
66465
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
65788
66466
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
65789
66467
  });
65790
- _defineProperty40(this, "handleLayersChange", (ids) => {
66468
+ _defineProperty43(this, "handleLayersChange", (ids) => {
65791
66469
  for (let i = 0, len = ids.length; i < len; i++) {
65792
66470
  const id = ids[i];
65793
66471
  if (!this.layers.has(id)) {
65794
66472
  const elementsMap = this.getMap(`layer/${id}/elements`);
65795
- const renderableModel = new RenderableModel(id, this.shadowEmitter, elementsMap, this.paperScope, this.toolbarModel, this.userManager, this.hasPermission);
66473
+ const renderableModel = new RenderableModel(id, this.shadowEmitter, elementsMap, this.paperScope, this.toolbarModel, this.userManager, this.imageSets, this.liveCursor, this.hasPermission);
65796
66474
  this.layers.set(id, renderableModel);
65797
66475
  }
65798
66476
  if (!this.undoManagers.has(id)) {
@@ -65803,12 +66481,12 @@ var WhiteboardApplication = class extends AbstractApplication {
65803
66481
  this.undoManagers.set(id, undoManager);
65804
66482
  }
65805
66483
  }
65806
- for (let entry of this.layers.entries()) {
66484
+ for (const entry of this.layers.entries()) {
65807
66485
  if (ids.indexOf(entry[0]) < 0) {
65808
66486
  const renderableModel = this.layers.get(entry[0]);
65809
66487
  this.layers.delete(entry[0]);
65810
66488
  if (renderableModel) {
65811
- renderableModel.dispose();
66489
+ renderableModel.dispose(true);
65812
66490
  }
65813
66491
  const cameraMode = this.userMap(this.userId).get(WhiteboardKeys.cameraMode);
65814
66492
  const currentPage = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
@@ -65819,17 +66497,18 @@ var WhiteboardApplication = class extends AbstractApplication {
65819
66497
  }
65820
66498
  }
65821
66499
  });
65822
- _defineProperty40(this, "getCurrentRenderableModel", () => {
65823
- let layerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
66500
+ _defineProperty43(this, "getCurrentRenderableModel", () => {
66501
+ const layerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
65824
66502
  if (!this.layers.has(layerId)) {
65825
66503
  this.emitter.emit("error", 300002, `target page: ${layerId} not found`);
65826
66504
  }
65827
66505
  return this.layers.get(layerId);
65828
66506
  });
65829
- _defineProperty40(this, "handleElementClear", () => {
66507
+ _defineProperty43(this, "handleElementClear", () => {
66508
+ this.shadowScope.project.activeLayer.removeChildren();
65830
66509
  this.paperScope.project.activeLayer.removeChildren();
65831
66510
  });
65832
- _defineProperty40(this, "handleElementInsert", (elements) => {
66511
+ _defineProperty43(this, "handleElementInsert", (elements) => {
65833
66512
  for (const element of elements) {
65834
66513
  element.createPaperElement();
65835
66514
  const scope = element.shadow === "" ? this.paperScope : this.shadowScope;
@@ -65841,7 +66520,7 @@ var WhiteboardApplication = class extends AbstractApplication {
65841
66520
  this.insertElementToParent(element.item, scope.project.activeLayer);
65842
66521
  }
65843
66522
  });
65844
- _defineProperty40(this, "handleElementRemove", (elementId, layerId) => {
66523
+ _defineProperty43(this, "handleElementRemove", (elementId, layerId) => {
65845
66524
  const layerModel = this.layers.get(layerId);
65846
66525
  if (!layerModel) {
65847
66526
  return;
@@ -65852,11 +66531,11 @@ var WhiteboardApplication = class extends AbstractApplication {
65852
66531
  }
65853
66532
  layerModel.elementModels.delete(elementId);
65854
66533
  });
65855
- _defineProperty40(this, "handleRemoveTrashedElementForSelf", (userId, elementId) => {
66534
+ _defineProperty43(this, "handleRemoveTrashedElementForSelf", (userId, elementId) => {
65856
66535
  const selfLayerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
65857
66536
  this.layers.get(selfLayerId)?.removeElementItem(elementId);
65858
66537
  });
65859
- _defineProperty40(this, "handleElementsTrash", (userId, elements) => {
66538
+ _defineProperty43(this, "handleElementsTrash", (userId, elements) => {
65860
66539
  const targetLayerId = this.userMap(userId).get(WhiteboardKeys.currentPage);
65861
66540
  const selfLayerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
65862
66541
  if (targetLayerId !== selfLayerId || !this.layers.has(targetLayerId)) {
@@ -65869,7 +66548,7 @@ var WhiteboardApplication = class extends AbstractApplication {
65869
66548
  }
65870
66549
  });
65871
66550
  });
65872
- _defineProperty40(this, "handleElementsSelect", (userId, elements) => {
66551
+ _defineProperty43(this, "handleElementsSelect", (userId, elements) => {
65873
66552
  if (!this.editors.has(userId)) {
65874
66553
  const ctrl = this.userManager.getUser(userId);
65875
66554
  const editor2 = new Editor(this.paperScope, this.shadowScope, this.shadowEmitter, this.canvasElement, this.camera, {
@@ -65901,7 +66580,7 @@ var WhiteboardApplication = class extends AbstractApplication {
65901
66580
  }).filter((v) => !!v);
65902
66581
  editor.setTargets(elementModels);
65903
66582
  if (elementModels.length === 1) {
65904
- let model = elementModels[0];
66583
+ const model = elementModels[0];
65905
66584
  if (model.item) {
65906
66585
  const topLeft = this.paperScope.project.view.projectToView(model.item.bounds.topLeft);
65907
66586
  const bottomRight = this.paperScope.project.view.projectToView(model.item.bounds.bottomRight);
@@ -65912,34 +66591,44 @@ var WhiteboardApplication = class extends AbstractApplication {
65912
66591
  this.emitter.emit("elementDeselected", userId);
65913
66592
  }
65914
66593
  });
65915
- _defineProperty40(this, "handleLinkedMapChange", (evt) => {
65916
- for (const [key, value] of evt.changes.keys.entries()) {
65917
- if (Object.keys(TOOLBAR_KEYS).indexOf(key) >= 0 && (value.action === "add" || value.action === "update")) {
65918
- this.toolbarModel.currentTool = evt.target.get(TOOLBAR_KEYS.tool);
65919
- this.toolbarModel.strokeColor = evt.target.get(TOOLBAR_KEYS.strokeColor);
65920
- this.toolbarModel.fillColor = evt.target.get(TOOLBAR_KEYS.fillColor);
65921
- this.toolbarModel.fontSize = evt.target.get(TOOLBAR_KEYS.fontSize);
65922
- this.toolbarModel.fontFamily = evt.target.get(TOOLBAR_KEYS.fontFamily);
65923
- this.toolbarModel.strokeWidth = evt.target.get(TOOLBAR_KEYS.strokeWidth);
65924
- this.toolbarModel.dashArray = evt.target.get(TOOLBAR_KEYS.dashArray);
65925
- }
65926
- if (key === "permission" && (value.action === "add" || value.action === "update")) {
65927
- this.permissions.removePermission(WhiteboardPermissionFlag.all);
65928
- this.permissions.addPermission(evt.target.get("permission"), this.userId);
65929
- }
66594
+ _defineProperty43(this, "handleSyncedWhiteboardStatusChange", (evt) => {
66595
+ if ([TOOLBAR_KEYS.tool, TOOLBAR_KEYS.strokeColor, TOOLBAR_KEYS.fillColor, TOOLBAR_KEYS.fontSize, TOOLBAR_KEYS.fontFamily, TOOLBAR_KEYS.strokeWidth, TOOLBAR_KEYS.dashArray, "permission"].some((key) => evt.keysChanged.has(key))) {
66596
+ const nextState = {
66597
+ currentTool: evt.target.get(TOOLBAR_KEYS.tool),
66598
+ strokeColor: evt.target.get(TOOLBAR_KEYS.strokeColor),
66599
+ fillColor: evt.target.get(TOOLBAR_KEYS.fillColor),
66600
+ fontSize: evt.target.get(TOOLBAR_KEYS.fontSize),
66601
+ fontFamily: evt.target.get(TOOLBAR_KEYS.fontFamily),
66602
+ strokeWidth: evt.target.get(TOOLBAR_KEYS.strokeWidth),
66603
+ dashArray: evt.target.get(TOOLBAR_KEYS.dashArray),
66604
+ permission: evt.target.get("permission")
66605
+ };
66606
+ window.__forge_gl_wb_status__.set(this.appId, nextState);
66607
+ window.dispatchEvent(new CustomEvent("forge-whiteboard-synced-status", {
66608
+ detail: {
66609
+ whiteboardAppId: this.appId,
66610
+ status: nextState,
66611
+ userId: this.userId
66612
+ }
66613
+ }));
65930
66614
  }
65931
66615
  });
65932
- _defineProperty40(this, "adjustByOutFrame", (frameWidth, frameHeight) => {
65933
- if (this.option.width > 0 && this.option.height > 0) {
66616
+ _defineProperty43(this, "adjustByOutFrame", (frameWidth, frameHeight) => {
66617
+ if (!this.paperScope.project.view || !this.shadowScope.project.view) {
66618
+ return;
66619
+ }
66620
+ const viewportWidth = this.viewportWidth;
66621
+ const viewportHeight = this.viewportHeight;
66622
+ if (viewportWidth > 0 && viewportHeight > 0) {
65934
66623
  const minWidth = Math.max(frameWidth, 10);
65935
66624
  const minHeight = Math.max(frameHeight, 10);
65936
66625
  let width = minWidth;
65937
- let height = width * this.option.height / this.option.width;
66626
+ let height = width * viewportHeight / viewportWidth;
65938
66627
  if (height > minHeight) {
65939
66628
  height = minHeight;
65940
- width = height * this.option.width / this.option.height;
66629
+ width = height * viewportWidth / viewportHeight;
65941
66630
  }
65942
- this.camera.updateInherentScale(width / this.option.width);
66631
+ this.camera.updateInherentScale(width / viewportWidth);
65943
66632
  this.paperScope.project.view.viewSize = new this.paperScope.Size(width, height);
65944
66633
  this.shadowScope.project.view.viewSize = new this.paperScope.Size(width, height);
65945
66634
  this.camera.triggerZoom();
@@ -65947,7 +66636,11 @@ var WhiteboardApplication = class extends AbstractApplication {
65947
66636
  });
65948
66637
  requestAnimationFrameHook(this.paperScope);
65949
66638
  requestAnimationFrameHook(this.shadowScope);
66639
+ const that = this;
65950
66640
  this.rootElement.setAttribute("data-forge-app", "whiteboard");
66641
+ this.imageSets.style.display = "none";
66642
+ this.imageSets.setAttribute("data-image-sets", "");
66643
+ this.rootElement.appendChild(this.imageSets);
65951
66644
  document.body.addEventListener("pointerdown", (evt) => {
65952
66645
  this.isPenEvent = evt.pointerType === "pen";
65953
66646
  if (evt.pointerType === "pen" && this.hasPenInput === null) {
@@ -66009,7 +66702,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66009
66702
  this.emitter.setViewModeToFree = (userId) => {
66010
66703
  if (that.disableViewModelUpdate) {
66011
66704
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
66012
- log3("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
66705
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
66013
66706
  return;
66014
66707
  }
66015
66708
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -66020,7 +66713,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66020
66713
  this.emitter.setViewModeToFlow = (flowId, userId) => {
66021
66714
  if (that.disableViewModelUpdate) {
66022
66715
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
66023
- log3("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
66716
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
66024
66717
  return;
66025
66718
  }
66026
66719
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -66035,7 +66728,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66035
66728
  this.emitter.setViewModeToMain = (userId) => {
66036
66729
  if (that.disableViewModelUpdate) {
66037
66730
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
66038
- log3("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
66731
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
66039
66732
  return;
66040
66733
  }
66041
66734
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -66047,6 +66740,30 @@ var WhiteboardApplication = class extends AbstractApplication {
66047
66740
  this.camera.resetViewMatrixToMain();
66048
66741
  }
66049
66742
  };
66743
+ this.emitter.insertImage = (src, pageId) => {
66744
+ if (!/https/.test(src)) {
66745
+ log4("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
66746
+ src
66747
+ }, "warning");
66748
+ return;
66749
+ }
66750
+ let targetPageId = pageId;
66751
+ if (!targetPageId) {
66752
+ targetPageId = this.pageModel.getCurrentPage(this.userManager.selfId);
66753
+ }
66754
+ if (!targetPageId) {
66755
+ log4("[@netless/forge-whiteboard] page not found", {}, "warning");
66756
+ return;
66757
+ }
66758
+ this.layers.get(targetPageId)?.createImage(src);
66759
+ };
66760
+ this.emitter.removeElement = (pageId, elementId) => {
66761
+ if (!this.layers.has(pageId)) {
66762
+ log4("[@netless/forge-whiteboard] page not found", {}, "warning");
66763
+ return;
66764
+ }
66765
+ this.layers.get(pageId)?.removeElementItem(elementId);
66766
+ };
66050
66767
  this.emitter.getViewModel = (userId) => {
66051
66768
  const targetId = userId ? userId : this.userId;
66052
66769
  return this.userMap(targetId).get(WhiteboardKeys.cameraMode);
@@ -66062,7 +66779,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66062
66779
  const source = this.getMap(`layer/${sourceId}/elements`);
66063
66780
  const target = this.getMap(`layer/${targetId}/elements`);
66064
66781
  if (!this.layers.has(targetId)) {
66065
- this.layers.set(targetId, new RenderableModel(targetId, this.shadowEmitter, target, this.paperScope, this.toolbarModel, this.userManager, this.hasPermission));
66782
+ this.layers.set(targetId, new RenderableModel(targetId, this.shadowEmitter, target, this.paperScope, this.toolbarModel, this.userManager, this.imageSets, this.liveCursor, this.hasPermission));
66066
66783
  }
66067
66784
  if (!this.undoManagers.has(targetId)) {
66068
66785
  const undoManager = new Y15.UndoManager(target, {
@@ -66112,13 +66829,29 @@ var WhiteboardApplication = class extends AbstractApplication {
66112
66829
  this.emitter.resetCamera = () => {
66113
66830
  this.camera.reset();
66114
66831
  };
66832
+ this.emitter.showLiveCursor = (value) => {
66833
+ this.liveCursor.showLiveCursor = value;
66834
+ };
66835
+ this.emitter.updateViewport = (width, height) => {
66836
+ this.updateOptionSize(width, height);
66837
+ };
66838
+ this.emitter.__setMainCanvasVisible = (visible) => {
66839
+ this.canvasElement.style.opacity = visible ? "1" : "0";
66840
+ };
66115
66841
  this.emitter.on("error", (errorCode, errorMessage) => {
66116
- log3("WhiteboardApplicationError", {
66842
+ log4("WhiteboardApplicationError", {
66117
66843
  errorCode,
66118
66844
  errorMessage
66119
66845
  });
66120
66846
  });
66121
- const that = this;
66847
+ Object.defineProperty(this.emitter, "__delayTranslateOut", {
66848
+ get() {
66849
+ return that.delayTranslateOut;
66850
+ },
66851
+ set(value) {
66852
+ that.delayTranslateOut = value;
66853
+ }
66854
+ });
66122
66855
  Object.defineProperty(this.emitter, "tool", {
66123
66856
  get() {
66124
66857
  return that.toolbarModel.currentTool;
@@ -66207,6 +66940,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66207
66940
  that.camera.enableBoundaryHighlight = value;
66208
66941
  }
66209
66942
  });
66943
+ window.addEventListener("forge-whiteboard-synced-status", this.addWhiteboardStatus);
66210
66944
  }
66211
66945
  userMap(userId) {
66212
66946
  return this.getMap(`user/${userId}`);
@@ -66215,10 +66949,23 @@ var WhiteboardApplication = class extends AbstractApplication {
66215
66949
  this.permissions = new WhiteboardPermissions(this.userManager, (userId) => {
66216
66950
  return this.userMap(userId);
66217
66951
  });
66952
+ this.permissions.setPermission(WhiteboardPermissionFlag.all);
66218
66953
  this.emitter["permissions"] = this.permissions;
66219
66954
  this.emitter["selfUserId"] = this.userId;
66220
66955
  this.option = option;
66956
+ if (this.option.stretchToFill) {
66957
+ this.getMap("attrs").set("viewportWidth", -1);
66958
+ this.getMap("attrs").set("viewportHeight", -1);
66959
+ } else {
66960
+ if (!this.getMap("attrs").has("viewportWidth")) {
66961
+ this.getMap("attrs").set("viewportWidth", option.width);
66962
+ }
66963
+ if (!this.getMap("attrs").has("viewportHeight")) {
66964
+ this.getMap("attrs").set("viewportHeight", option.height);
66965
+ }
66966
+ }
66221
66967
  this.userMap(this.userId).set(WhiteboardKeys.themeColor, "#009688");
66968
+ this.userMap(this.userId).observe(this.handleSyncedWhiteboardStatusChange);
66222
66969
  this.shadowEmitter = new ShadowEmitter(this.userMap(this.userId));
66223
66970
  this.pageModel = new PageModel(this.getMap("attrs"), this.userManager, (userId) => {
66224
66971
  return this.userMap(userId);
@@ -66266,6 +67013,9 @@ var WhiteboardApplication = class extends AbstractApplication {
66266
67013
  this.selectElementsModel = new SelectElementsModel(this.userManager, (userId) => {
66267
67014
  return this.userMap(userId);
66268
67015
  }, this.hasPermission);
67016
+ this.liveCursor = new LiveCursor(this.canvasElement, this.paperScope, this.userManager, (userId) => {
67017
+ return this.userMap(userId);
67018
+ });
66269
67019
  this.tools = {
66270
67020
  pointer: new PointerTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
66271
67021
  curve: new CurveTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
@@ -66276,7 +67026,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66276
67026
  text: new TextTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.rootElement, this.canvasElement, this.toolbarModel, this.camera),
66277
67027
  ellipse: new EllipseTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
66278
67028
  triangle: new TriangleTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
66279
- eraser: new EraserTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.trashedElementsModel),
67029
+ eraser: new EraserTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.trashedElementsModel, this.shadowScope),
66280
67030
  laser: new LaserPointerTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope),
66281
67031
  grab: new GrabTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.camera)
66282
67032
  };
@@ -66297,7 +67047,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66297
67047
  this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
66298
67048
  } else {
66299
67049
  this.paperScope.tool = this.tools["curve"].tool;
66300
- log3(`${this.toolbarModel.currentTool} not supported, backup to curve`);
67050
+ log4(`${this.toolbarModel.currentTool} not supported, backup to curve`);
66301
67051
  }
66302
67052
  this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
66303
67053
  this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
@@ -66348,32 +67098,12 @@ var WhiteboardApplication = class extends AbstractApplication {
66348
67098
  }
66349
67099
  });
66350
67100
  this.shadowEmitter.on("translateOut", (ids, container) => {
66351
- const shadowLayer = this.shadowScope.project.activeLayer;
66352
- let parent = null;
66353
- if (container === "layer") {
66354
- parent = shadowLayer;
67101
+ if (this.delayTranslateOut > 0) {
67102
+ setTimeout(() => {
67103
+ this.handleElementTranslateOut(ids, container);
67104
+ }, this.delayTranslateOut);
66355
67105
  } else {
66356
- parent = shadowLayer.children.find((child) => child.data.uuid === container) ?? null;
66357
- }
66358
- if (parent) {
66359
- ids.forEach((id) => {
66360
- const target = parent.children.find((child) => child.data.uuid === id);
66361
- if (target) {
66362
- target.remove();
66363
- this.insertElementToParent(target, this.paperScope.project.activeLayer);
66364
- } else {
66365
- const pageId = this.pageModel.getCurrentPage(this.userId);
66366
- if (pageId) {
66367
- const page = this.layers.get(pageId);
66368
- if (page) {
66369
- const model = page.elementModels.get(id);
66370
- if (model && model.item) {
66371
- this.insertElementToParent(model.item, this.paperScope.project.activeLayer);
66372
- }
66373
- }
66374
- }
66375
- }
66376
- });
67106
+ this.handleElementTranslateOut(ids, container);
66377
67107
  }
66378
67108
  });
66379
67109
  this.shadowEmitter.on("translateIn", (ids, container) => {
@@ -66400,6 +67130,15 @@ var WhiteboardApplication = class extends AbstractApplication {
66400
67130
  this.emitter.emit("grabUp");
66401
67131
  });
66402
67132
  this.clearElements();
67133
+ if (this.option.stretchToFill) {
67134
+ window.addEventListener("resize", () => {
67135
+ const bounds = this.rootElement.getBoundingClientRect();
67136
+ this.updateOptionSize(bounds.width, bounds.height);
67137
+ this.adjustByOutFrame(bounds.width, bounds.height);
67138
+ });
67139
+ }
67140
+ this.rootElement.appendChild(this.liveCursor.container);
67141
+ this.getMap("attrs").observe(this.handleViewportUpdate);
66403
67142
  }
66404
67143
  clearElements() {
66405
67144
  const userIds = this.userManager.userIdList();
@@ -66466,7 +67205,7 @@ var WhiteboardApplication = class extends AbstractApplication {
66466
67205
  if (renderableModel.elementModels.has(key)) {
66467
67206
  elementModel = renderableModel.elementModels.get(key) ?? null;
66468
67207
  } else {
66469
- let elementMap = renderableModel.elements.get(key);
67208
+ const elementMap = renderableModel.elements.get(key);
66470
67209
  if (elementMap) {
66471
67210
  elementModel = renderableModel.convertToModel(elementMap);
66472
67211
  }
@@ -66495,10 +67234,10 @@ var WhiteboardApplication = class extends AbstractApplication {
66495
67234
  this.snapshotScope.view.viewSize = bounds.size.multiply(scale2);
66496
67235
  this.snapshotScope.view.matrix = matrix;
66497
67236
  } else if (area === "maxScale" && this.option.maxScaleRatio && this.option.maxScaleRatio !== -1) {
66498
- const width = this.option.width * this.option.maxScaleRatio;
66499
- const height = this.option.height * this.option.maxScaleRatio;
66500
- const offsetX = this.option.width * (this.option.maxScaleRatio - 1) / 2;
66501
- const offsetY = this.option.height * (this.option.maxScaleRatio - 1) / 2;
67237
+ const width = this.viewportWidth * this.option.maxScaleRatio;
67238
+ const height = this.viewportHeight * this.option.maxScaleRatio;
67239
+ const offsetX = this.viewportWidth * (this.option.maxScaleRatio - 1) / 2;
67240
+ const offsetY = this.viewportHeight * (this.option.maxScaleRatio - 1) / 2;
66502
67241
  const matrix = new this.paperScope.Matrix();
66503
67242
  matrix.scale(scale);
66504
67243
  matrix.translate({
@@ -66522,28 +67261,23 @@ var WhiteboardApplication = class extends AbstractApplication {
66522
67261
  this.disableViewModelUpdate = true;
66523
67262
  }
66524
67263
  linkToWhiteboard(targetId) {
66525
- if (this.linkTarget) {
66526
- this.unlink();
66527
- }
66528
- this.userMap(this.userId);
66529
- this.linkTarget = this.roomDoc.getMap(`@app/${this.name}/${targetId}/user/${this.userId}`);
66530
- if (this.linkTarget) {
66531
- this.toolbarModel.currentTool = this.linkTarget.get(TOOLBAR_KEYS.tool);
66532
- this.toolbarModel.strokeColor = this.linkTarget.get(TOOLBAR_KEYS.strokeColor);
66533
- this.toolbarModel.fillColor = this.linkTarget.get(TOOLBAR_KEYS.fillColor);
66534
- this.toolbarModel.fontSize = this.linkTarget.get(TOOLBAR_KEYS.fontSize);
66535
- this.toolbarModel.fontFamily = this.linkTarget.get(TOOLBAR_KEYS.fontFamily);
66536
- this.toolbarModel.strokeWidth = this.linkTarget.get(TOOLBAR_KEYS.strokeWidth);
66537
- this.toolbarModel.dashArray = this.linkTarget.get(TOOLBAR_KEYS.dashArray);
66538
- this.permissions.removePermission(WhiteboardPermissionFlag.all);
66539
- this.permissions.addPermission(this.linkTarget.get("permission"), this.userId);
66540
- this.linkTarget.observe(this.handleLinkedMapChange);
66541
- }
67264
+ this.linkWhiteboardId = targetId;
67265
+ window.__forge_gl_wb_status__.get(targetId).then((currentStatus) => {
67266
+ if (currentStatus) {
67267
+ this.toolbarModel.currentTool = currentStatus.currentTool;
67268
+ this.toolbarModel.strokeColor = currentStatus.strokeColor;
67269
+ this.toolbarModel.fillColor = currentStatus.fillColor;
67270
+ this.toolbarModel.fontSize = currentStatus.fontSize;
67271
+ this.toolbarModel.fontFamily = currentStatus.fontFamily;
67272
+ this.toolbarModel.strokeWidth = currentStatus.strokeWidth;
67273
+ this.toolbarModel.dashArray = currentStatus.dashArray;
67274
+ this.permissions.removePermission(WhiteboardPermissionFlag.all);
67275
+ this.permissions.addPermission(currentStatus.permission);
67276
+ }
67277
+ });
66542
67278
  }
66543
67279
  unlink() {
66544
- if (this.linkTarget) {
66545
- this.linkTarget.unobserve(this.handleLinkedMapChange);
66546
- }
67280
+ this.linkWhiteboardId = null;
66547
67281
  }
66548
67282
  setViewSize(width, height) {
66549
67283
  this.paperScope.project.view.viewSize = new this.paperScope.Size(width, height);
@@ -66553,15 +67287,21 @@ var WhiteboardApplication = class extends AbstractApplication {
66553
67287
  const size = this.paperScope.view.viewSize;
66554
67288
  return [size.width, size.height];
66555
67289
  }
67290
+ getInherentScale() {
67291
+ return this.camera.getInherentScale();
67292
+ }
66556
67293
  updateInternalResizeObserverStatus(value) {
66557
67294
  this.internalResizeObserver = value;
66558
67295
  }
66559
67296
  updateOptionSize(width, height) {
66560
- this.option.width = width;
66561
- this.option.height = height;
67297
+ this.getMap("attrs").set("viewportWidth", width);
67298
+ this.getMap("attrs").set("viewportHeight", height);
66562
67299
  this.camera.updateInitSize(new import_paper.default.Size(width, height));
66563
67300
  }
66564
- async dispose() {
67301
+ async dispose(removeSubDoc) {
67302
+ if (removeSubDoc) {
67303
+ this.deleteSubDoc(this.appId);
67304
+ }
66565
67305
  this.selectElementsModel.dispose();
66566
67306
  this.trashedElementsModel.dispose();
66567
67307
  this.paperScope.view.remove();
@@ -66572,72 +67312,92 @@ var WhiteboardApplication = class extends AbstractApplication {
66572
67312
  this.shadowScope.project.clear();
66573
67313
  this.snapshotScope.project.clear();
66574
67314
  this.resizeObserver.disconnect();
67315
+ this.unlink();
67316
+ for (const entry of this.undoManagers.entries()) {
67317
+ entry[1].off("stack-item-added", this.handleStackItemAdded);
67318
+ entry[1].off("stack-item-popped", this.handleStackItemPopped);
67319
+ }
67320
+ for (const entry of this.layers.entries()) {
67321
+ entry[1].dispose(removeSubDoc);
67322
+ entry[1].removeAllListeners();
67323
+ }
67324
+ this.camera.dispose();
67325
+ this.pageModel.dispose();
67326
+ this.pageModel.removeAllListeners();
67327
+ for (const entry of this.editors.entries()) {
67328
+ entry[1].dispose();
67329
+ }
67330
+ this.toolbarModel.dispose();
67331
+ this.emitter.indexedNavigation.dispose();
67332
+ this.permissions.dispose();
67333
+ removeObserver7(this.userMap(this.userId), this.handleSyncedWhiteboardStatusChange);
66575
67334
  }
66576
67335
  };
66577
- _defineProperty40(WhiteboardApplication, "applicationName", WHITEBOARD_APP_NAME);
67336
+ _defineProperty43(WhiteboardApplication, "applicationName", WHITEBOARD_APP_NAME);
66578
67337
 
66579
67338
  // src/SlideApplication.ts
66580
67339
  var import_slide = __toESM(require_Slide());
66581
- import { AbstractApplication as AbstractApplication2 } from "@netless/forge-room";
67340
+ import { AbstractApplication as AbstractApplication2, kvStore as kvStore2 } from "@netless/forge-room";
66582
67341
 
66583
67342
  // src/Slide.ts
66584
- import EventEmitter14 from "eventemitter3";
66585
- var SlideForge = class extends EventEmitter14 {
67343
+ import EventEmitter13 from "eventemitter3";
67344
+ var SlideForge = class extends EventEmitter13 {
66586
67345
  view;
66587
67346
  permissions;
66588
67347
  footView;
67348
+ sideBarView;
66589
67349
  /**
66590
- * 当前页面索引, 从 0 开始
66591
- */
67350
+ * 当前页面索引, 从 0 开始
67351
+ */
66592
67352
  pageIndex;
66593
67353
  /**
66594
- * 总页数
66595
- */
67354
+ * 总页数
67355
+ */
66596
67356
  pageCount;
66597
67357
  /**
66598
- * 切换到参数指定页面, index 从 0 开始
66599
- * @param {number} index 页面索引
66600
- */
67358
+ * 切换到参数指定页面, index 从 0 开始
67359
+ * @param {number} index 页面索引
67360
+ */
66601
67361
  goto;
66602
67362
  /**
66603
- * 下一步, 如果已经是本页的最后一步, 则切换到下一页
66604
- */
67363
+ * 下一步, 如果已经是本页的最后一步, 则切换到下一页
67364
+ */
66605
67365
  nextStep;
66606
67366
  /**
66607
- * 上一步, 如果已经是本页的第一步, 则切换到上一页
66608
- */
67367
+ * 上一步, 如果已经是本页的第一步, 则切换到上一页
67368
+ */
66609
67369
  prevStep;
66610
67370
  /**
66611
- * 下一页, 如果是最后一页, 则不执行任何操作
66612
- */
67371
+ * 下一页, 如果是最后一页, 则不执行任何操作
67372
+ */
66613
67373
  nextPage;
66614
67374
  /**
66615
- * 上一页, 如果是第一页, 则不执行任何操作
66616
- */
67375
+ * 上一页, 如果是第一页, 则不执行任何操作
67376
+ */
66617
67377
  prevPage;
66618
67378
  /**
66619
- * 切换侧栏显示状态
66620
- */
67379
+ * 切换侧栏显示状态
67380
+ */
66621
67381
  sideBarToggle;
66622
67382
  /**
66623
- * 获取预览图图片内容, base64 编码
66624
- * @param {number} index 页面索引
66625
- */
67383
+ * 获取预览图图片内容, base64 编码
67384
+ * @param {number} index 页面索引
67385
+ */
66626
67386
  imgContent;
66627
67387
  /**
66628
- * 获取预览图图片链接
66629
- * @param {number} index 页面索引
66630
- */
67388
+ * 获取预览图图片链接
67389
+ * @param {number} index 页面索引
67390
+ */
66631
67391
  imgUrl;
66632
67392
  /**
66633
- * 获取预览图图片尺寸
66634
- * @param {number} index 页面索引
66635
- */
67393
+ * 获取预览图图片尺寸
67394
+ * @param {number} index 页面索引
67395
+ */
66636
67396
  imgSize;
66637
67397
  };
66638
67398
 
66639
67399
  // src/ForgeSlidePermession.ts
66640
- import EventEmitter15 from "eventemitter3";
67400
+ import { AbstractApplicationPermissions as AbstractApplicationPermissions2 } from "@netless/forge-room";
66641
67401
  var ForgeSlidePermissionFlag = /* @__PURE__ */ ((ForgeSlidePermissionFlag2) => {
66642
67402
  ForgeSlidePermissionFlag2[ForgeSlidePermissionFlag2["none"] = 0] = "none";
66643
67403
  ForgeSlidePermissionFlag2[ForgeSlidePermissionFlag2["changeStep"] = 1] = "changeStep";
@@ -66646,58 +67406,12 @@ var ForgeSlidePermissionFlag = /* @__PURE__ */ ((ForgeSlidePermissionFlag2) => {
66646
67406
  ForgeSlidePermissionFlag2[ForgeSlidePermissionFlag2["all"] = 7] = "all";
66647
67407
  return ForgeSlidePermissionFlag2;
66648
67408
  })(ForgeSlidePermissionFlag || {});
66649
- var ForgeSlidePermissions = class extends EventEmitter15 {
66650
- requestUserMap;
66651
- userManager;
66652
- observers = /* @__PURE__ */ new Map();
66653
- constructor(userManager, requestUserMap) {
66654
- super();
66655
- this.userManager = userManager;
66656
- this.requestUserMap = requestUserMap;
66657
- this.createModel(this.userManager.selfId);
66658
- this.userManager.userIdList().forEach((userId) => {
66659
- this.addObserve(userId);
66660
- });
66661
- this.userManager.on("join", this.handleUserJoin);
66662
- this.userManager.on("leave", this.handleUserLeave);
66663
- }
66664
- handleUserLeave = (user) => {
66665
- const cb = this.observers.get(user.id);
66666
- if (cb) {
66667
- this.requestUserMap(user.id).unobserve(cb);
66668
- }
66669
- };
66670
- handleUserJoin = (user) => {
66671
- this.addObserve(user.id);
66672
- };
66673
- addObserve(userId) {
66674
- const observer = (evt) => {
66675
- this.handleUserPermissionChange(userId, evt);
66676
- };
66677
- this.observers.set(userId, observer);
66678
- this.requestUserMap(userId).observe(observer);
66679
- }
66680
- createModel(userId) {
66681
- const userMap = this.requestUserMap(userId);
66682
- if (!userMap.has("permission")) {
66683
- userMap.set("permission", 0);
66684
- }
66685
- }
66686
- handleUserPermissionChange(userId, evt) {
66687
- for (const [key, value] of evt.changes.keys.entries()) {
66688
- if (key === "permission") {
66689
- if (value.action === "add" || value.action === "update") {
66690
- const newValue = this.requestUserMap(userId).get("permission");
66691
- this.emit("change", userId, this.resolveFlags(newValue), newValue);
66692
- }
66693
- }
66694
- }
66695
- }
67409
+ var ForgeSlidePermissions = class extends AbstractApplicationPermissions2 {
66696
67410
  /**
66697
- * 解析权限列表组合
66698
- * @param {number} value - 权限数字值
66699
- * @return {WhiteboardPermissionFlag[]} - 权限列表
66700
- */
67411
+ * 解析权限列表组合
67412
+ * @param {number} value - 权限数字值
67413
+ * @return {WhiteboardPermissionFlag[]} - 权限列表
67414
+ */
66701
67415
  resolveFlags(value) {
66702
67416
  return [
66703
67417
  2 /* changePage */,
@@ -66705,53 +67419,10 @@ var ForgeSlidePermissions = class extends EventEmitter15 {
66705
67419
  4 /* clickAnim */
66706
67420
  ].filter((v) => (v & value) !== 0);
66707
67421
  }
66708
- /**
66709
- * 获取权限列表组合对应的数值
66710
- * @param { string } userId 不传表示获取自己
66711
- */
66712
- getPermissionValue(userId) {
66713
- return this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
66714
- }
66715
- /**
66716
- * 获取权限列表
66717
- * @param {string=} userId 可选, 不传表示获取自己
66718
- */
66719
- getPermissionFlags(userId) {
66720
- const value = this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0;
66721
- return this.resolveFlags(value);
66722
- }
66723
- /**
66724
- * 返回对应 userId 是否有相应权限
66725
- * @param {string=} userId 可选, 不传表示返回自己是否有相应权限
66726
- * @param {WhiteboardPermissionFlag} flag
66727
- */
66728
- hasPermission(flag, userId) {
66729
- return ((this.requestUserMap(userId ?? this.userManager.selfId).get("permission") ?? 0) & flag) !== 0;
66730
- }
66731
- /**
66732
- * 添加权限
66733
- * @param {WhiteboardPermissionFlag} flag 权限标记
66734
- * @param {string=} userId 可选, 为 userId 添加权限, 不传表示为自己添加权限
66735
- */
66736
- addPermission(flag, userId) {
66737
- const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
66738
- const oldValue = userMap.get("permission") ?? 0;
66739
- this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue | flag);
66740
- }
66741
- /**
66742
- * 移除权限
66743
- * @param {WhiteboardPermissionFlag} flag 权限标记
66744
- * @param {string=} userId 可选, 为 userId 移除权限, 不传表示为自己移除权限
66745
- */
66746
- removePermission(flag, userId) {
66747
- const userMap = this.requestUserMap(userId ?? this.userManager.selfId);
66748
- const oldValue = userMap.get("permission") ?? 0;
66749
- this.requestUserMap(userId ?? this.userManager.selfId).set("permission", oldValue & ~flag);
66750
- }
66751
67422
  };
66752
67423
 
66753
- // src/FoorerView.ts
66754
- import EventEmitter16 from "eventemitter3";
67424
+ // src/FooterView.ts
67425
+ import EventEmitter14 from "eventemitter3";
66755
67426
 
66756
67427
  // src/icons.ts
66757
67428
  var prevPage = (color) => `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none">
@@ -66780,18 +67451,20 @@ var Icons = {
66780
67451
  sideBar
66781
67452
  };
66782
67453
 
66783
- // src/FoorerView.ts
67454
+ // src/FooterView.ts
66784
67455
  var EM_COLOR = "#8C8C8C";
66785
- var FooterView = class extends EventEmitter16 {
67456
+ var FooterView = class extends EventEmitter14 {
66786
67457
  root;
66787
67458
  prevStep;
66788
67459
  nextStep;
66789
67460
  prevPage;
66790
67461
  nextPage;
66791
67462
  sideBarToggle;
67463
+ eventMap = /* @__PURE__ */ new Map();
66792
67464
  constructor() {
66793
67465
  super();
66794
67466
  this.root = document.createElement("div");
67467
+ this.root.classList.add("forge-slide-footer");
66795
67468
  this.root.style.height = "24px";
66796
67469
  this.root.style.zIndex = "6";
66797
67470
  this.root.style.display = "flex";
@@ -66851,28 +67524,53 @@ var FooterView = class extends EventEmitter16 {
66851
67524
  icon.style.borderRadius = "2px";
66852
67525
  icon.style.margin = "6px";
66853
67526
  icon.innerHTML = svgContent;
66854
- icon.addEventListener("click", () => {
67527
+ const onClickHandle = () => {
66855
67528
  action();
66856
- });
66857
- icon.addEventListener("mouseover", () => {
67529
+ };
67530
+ const onMouseOverHandle = () => {
66858
67531
  icon.style.backgroundColor = "#f0f0f0";
66859
- });
66860
- icon.addEventListener("mouseout", () => {
67532
+ };
67533
+ const onMouseOutHandle = () => {
66861
67534
  icon.style.backgroundColor = "transparent";
66862
- });
67535
+ };
67536
+ icon.addEventListener("click", onClickHandle);
67537
+ icon.addEventListener("mouseover", onMouseOverHandle);
67538
+ icon.addEventListener("mouseout", onMouseOutHandle);
67539
+ this.eventMap.set(icon, [onClickHandle, onMouseOutHandle, onMouseOverHandle]);
66863
67540
  return icon;
66864
67541
  }
67542
+ clearHTMLEventListeners() {
67543
+ this.eventMap.forEach((value, key) => {
67544
+ if (key) {
67545
+ const [clickEvent, mouseOutEvent, mouseOverEvent] = value;
67546
+ key.removeEventListener("click", clickEvent);
67547
+ key.removeEventListener("mouseover", mouseOverEvent);
67548
+ key.removeEventListener("mouseout", mouseOutEvent);
67549
+ }
67550
+ });
67551
+ }
67552
+ dispose() {
67553
+ this.removeAllListeners();
67554
+ this.clearHTMLEventListeners();
67555
+ }
66865
67556
  };
66866
67557
 
66867
67558
  // src/SiderBarView.ts
66868
- import EventEmitter17 from "eventemitter3";
66869
- var SideBarView = class extends EventEmitter17 {
67559
+ import EventEmitter15 from "eventemitter3";
67560
+ import { kvStore } from "@netless/forge-room";
67561
+ var SideBarView = class extends EventEmitter15 {
66870
67562
  root = document.createElement("div");
66871
- itemList = [];
67563
+ isShow = false;
67564
+ eventsMap = /* @__PURE__ */ new Map();
67565
+ taskId = "";
67566
+ prefix = "";
67567
+ addImagesPool = [];
67568
+ scheduleId = 0;
67569
+ isSchedule = false;
66872
67570
  constructor() {
66873
67571
  super();
66874
67572
  this.root.style.backgroundColor = "#eee";
66875
- this.root.className = "slide-sidebar";
67573
+ this.root.className = "forge-slide-sidebar";
66876
67574
  this.root.style.width = "240px";
66877
67575
  this.root.style.height = "100%";
66878
67576
  this.root.style.position = "absolute";
@@ -66881,65 +67579,147 @@ var SideBarView = class extends EventEmitter17 {
66881
67579
  this.root.style.zIndex = "5";
66882
67580
  this.root.style.transition = "left 0.3s ease-in-out";
66883
67581
  this.root.style.overflow = "auto";
66884
- this.root.style.border = "1px solid #ccc";
66885
- this.root.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.1)";
66886
67582
  this.root.style.display = "flex";
66887
67583
  this.root.style.flexDirection = "column";
66888
67584
  this.root.style.justifyContent = "flex-start";
66889
67585
  this.root.style.alignItems = "center";
66890
67586
  }
66891
- onMouseOver = (itemContainer) => {
66892
- itemContainer.style.borderColor = "#ccc";
66893
- };
66894
- onMouseOut = (itemContainer) => {
66895
- itemContainer.style.borderColor = "transparent";
66896
- };
66897
- onClickHandle = (index) => {
66898
- this.emit("pageChange", index);
66899
- };
67587
+ get isShowSideBar() {
67588
+ return this.isShow;
67589
+ }
67590
+ async getPreviewImage(imageUrl) {
67591
+ const image = await fetch(imageUrl);
67592
+ const blob = await image.blob();
67593
+ return new Promise((resolve) => {
67594
+ const reader = new FileReader();
67595
+ reader.onloadend = () => {
67596
+ const base64Data = reader.result;
67597
+ const img = document.createElement("img");
67598
+ img.src = base64Data;
67599
+ img.onload = () => {
67600
+ resolve({
67601
+ url: imageUrl,
67602
+ src: base64Data,
67603
+ width: img.width,
67604
+ height: img.height
67605
+ });
67606
+ };
67607
+ };
67608
+ reader.readAsDataURL(blob);
67609
+ });
67610
+ }
67611
+ async appendPreviewImage(pageIndex) {
67612
+ const itemContainer = document.createElement("div");
67613
+ itemContainer.style.width = "60%";
67614
+ itemContainer.style.display = "flex";
67615
+ itemContainer.style.justifyContent = "center";
67616
+ itemContainer.style.alignItems = "flex-start";
67617
+ itemContainer.style.position = "relative";
67618
+ itemContainer.style.borderRadius = "4px";
67619
+ itemContainer.style.transition = "border-color .3s";
67620
+ itemContainer.style.marginBottom = "10px";
67621
+ const onMouseOverHandle = () => {
67622
+ itemContainer.style.borderColor = "#ccc";
67623
+ };
67624
+ const onMouseOutHandle = () => {
67625
+ itemContainer.style.borderColor = "transparent";
67626
+ };
67627
+ const onClickHandle = () => {
67628
+ this.emit("pageChange", pageIndex);
67629
+ };
67630
+ itemContainer.addEventListener("click", onClickHandle);
67631
+ itemContainer.addEventListener("mouseover", onMouseOverHandle);
67632
+ itemContainer.addEventListener("mouseout", onMouseOutHandle);
67633
+ this.eventsMap.set(itemContainer, [onClickHandle, onMouseOverHandle, onMouseOutHandle]);
67634
+ const pageIndexContainer = document.createElement("span");
67635
+ pageIndexContainer.textContent = `${pageIndex}`;
67636
+ pageIndexContainer.style.position = "absolute";
67637
+ pageIndexContainer.style.top = "1px";
67638
+ pageIndexContainer.style.left = "-10px";
67639
+ pageIndexContainer.style.transform = "translate(-100%)";
67640
+ pageIndexContainer.style.fontSize = "12px";
67641
+ pageIndexContainer.style.color = "#5f5f5f";
67642
+ const previewUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex}.png`;
67643
+ const preview = document.createElement("img");
67644
+ const cachePreview = await kvStore.getItem(previewUrl);
67645
+ if (cachePreview) {
67646
+ const { src } = JSON.parse(cachePreview);
67647
+ preview.src = src;
67648
+ } else {
67649
+ const previewInfo = await this.getPreviewImage(previewUrl);
67650
+ await kvStore.setItem(previewUrl, JSON.stringify(previewInfo));
67651
+ const { src } = previewInfo;
67652
+ preview.src = src;
67653
+ }
67654
+ preview.style.width = "100%";
67655
+ preview.style.display = "inline-block";
67656
+ itemContainer.appendChild(preview);
67657
+ itemContainer.appendChild(pageIndexContainer);
67658
+ this.root.appendChild(itemContainer);
67659
+ }
67660
+ async scheduleGetPreviewImage() {
67661
+ if (!this.isSchedule) {
67662
+ this.scheduleId = setTimeout(async () => {
67663
+ await this.scheduleGetPreviewImage();
67664
+ }, 32);
67665
+ return;
67666
+ }
67667
+ const pageIndex = this.addImagesPool.shift();
67668
+ if (!pageIndex) {
67669
+ clearTimeout(this.scheduleId);
67670
+ this.scheduleId = 0;
67671
+ return;
67672
+ }
67673
+ await this.appendPreviewImage(pageIndex);
67674
+ this.scheduleId = setTimeout(async () => {
67675
+ await this.scheduleGetPreviewImage();
67676
+ }, 32);
67677
+ }
67678
+ async startGetPreviewImageSchedule() {
67679
+ this.isSchedule = true;
67680
+ }
67681
+ pauseGetPreviewImageSchedule() {
67682
+ this.isSchedule = false;
67683
+ }
66900
67684
  initialize(slideCount, option) {
67685
+ this.taskId = option.taskId;
67686
+ this.prefix = option.prefix;
66901
67687
  for (let i = 1; i <= slideCount; i++) {
66902
- const itemContainer = document.createElement("div");
66903
- this.itemList.push(itemContainer);
66904
- itemContainer.style.width = "60%";
66905
- itemContainer.style.display = "flex";
66906
- itemContainer.style.justifyContent = "center";
66907
- itemContainer.style.alignItems = "flex-start";
66908
- itemContainer.style.border = "7px solid transparent";
66909
- itemContainer.style.position = "relative";
66910
- itemContainer.style.borderRadius = "4px";
66911
- itemContainer.style.transition = "border-color .3s";
66912
- itemContainer.style.marginBottom = "10px";
66913
- itemContainer.addEventListener("mouseover", () => this.onMouseOver(itemContainer));
66914
- itemContainer.addEventListener("mouseout", () => this.onMouseOut(itemContainer));
66915
- itemContainer.addEventListener("click", () => this.onClickHandle(i));
66916
- const pageIndex = document.createElement("span");
66917
- pageIndex.textContent = `${i}`;
66918
- pageIndex.style.position = "absolute";
66919
- pageIndex.style.top = "1px";
66920
- pageIndex.style.left = "-10px";
66921
- pageIndex.style.transform = "translate(-100%)";
66922
- pageIndex.style.fontSize = "12px";
66923
- pageIndex.style.color = "#5f5f5f";
66924
- const preview = document.createElement("img");
66925
- preview.style.width = "100%";
66926
- preview.style.display = "inline-block";
66927
- preview.src = `${option.prefix}/${option.taskId}/preview/${i}.png`;
66928
- itemContainer.appendChild(preview);
66929
- itemContainer.appendChild(pageIndex);
66930
- this.root.appendChild(itemContainer);
67688
+ this.addImagesPool.push(i);
67689
+ }
67690
+ this.scheduleGetPreviewImage();
67691
+ }
67692
+ hidden() {
67693
+ if (!this.root || !this.isShow) {
67694
+ return;
67695
+ }
67696
+ this.root.style.left = "-240px";
67697
+ this.root.style.border = "none";
67698
+ this.root.style.boxShadow = "none";
67699
+ this.isShow = false;
67700
+ }
67701
+ show() {
67702
+ if (!this.root) {
67703
+ return;
66931
67704
  }
67705
+ this.root.style.left = "0";
67706
+ this.root.style.border = "1px solid #ccc";
67707
+ this.root.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.1)";
67708
+ this.isShow = true;
66932
67709
  }
66933
67710
  dispose() {
66934
- this.itemList.forEach((item) => {
66935
- item.removeEventListener("mouseover", () => this.onMouseOver(item));
66936
- item.removeEventListener("mouseout", () => this.onMouseOut(item));
67711
+ this.removeAllListeners();
67712
+ this.eventsMap.forEach((handlers, element) => {
67713
+ const [clickEvent, mouseOverEvent, mouseOutEvent] = handlers;
67714
+ element.removeEventListener("click", clickEvent);
67715
+ element.removeEventListener("mouseover", mouseOverEvent);
67716
+ element.removeEventListener("mouseout", mouseOutEvent);
66937
67717
  });
66938
67718
  }
66939
67719
  };
66940
67720
 
66941
67721
  // src/utils.ts
66942
- function deepEqual(a2, b2, excludeKeys = ["time"]) {
67722
+ function deepEqual(a2, b2, excludeKeys = ["mediaState"]) {
66943
67723
  if (a2 === b2) return true;
66944
67724
  if (typeof a2 !== "object" || a2 === null || typeof b2 !== "object" || b2 === null) return false;
66945
67725
  if (a2.constructor !== b2.constructor) return false;
@@ -66972,12 +67752,8 @@ function arrayEqual(arr1, arr2) {
66972
67752
  }
66973
67753
  return true;
66974
67754
  }
66975
- async function delay2(time) {
66976
- return new Promise((resolve) => setTimeout(resolve, time));
66977
- }
66978
67755
 
66979
67756
  // src/SlideApplication.ts
66980
- import { kvStore } from "@netless/forge-room";
66981
67757
  var Slide_APP_NAME = "forge_slide";
66982
67758
  var SlideApplication = class extends AbstractApplication2 {
66983
67759
  static applicationName = Slide_APP_NAME;
@@ -66996,11 +67772,15 @@ var SlideApplication = class extends AbstractApplication2 {
66996
67772
  currentSlideIndex = 0;
66997
67773
  taskId = "";
66998
67774
  prefix = "";
67775
+ slideCount = 0;
67776
+ lastDispatchUuid = "";
67777
+ syncMessageQueue = [];
67778
+ isSyncing = false;
66999
67779
  constructor() {
67000
67780
  super();
67001
67781
  window.emitter = this.emitter;
67002
67782
  this.rootView.setAttribute("data-forge-app", Slide_APP_NAME);
67003
- this.rootView.style.background = "#f0f0f0f0";
67783
+ this.rootView.style.background = "#f9f9fc";
67004
67784
  this.rootView.style.overflow = "hidden";
67005
67785
  this.contentContainer.style.width = "100%";
67006
67786
  this.contentContainer.style.height = "100%";
@@ -67011,7 +67791,7 @@ var SlideApplication = class extends AbstractApplication2 {
67011
67791
  this.footer = new FooterView();
67012
67792
  this.sideBar = new SideBarView();
67013
67793
  this.sideBar.on("pageChange", (index) => {
67014
- if (index > 0 && index <= this.slide.slideCount) {
67794
+ if (index > 0 && index <= this.slideCount) {
67015
67795
  this.slide.renderSlide(index);
67016
67796
  }
67017
67797
  });
@@ -67053,7 +67833,7 @@ var SlideApplication = class extends AbstractApplication2 {
67053
67833
  if (!this.permissions.hasPermission(2 /* changePage */)) {
67054
67834
  return;
67055
67835
  }
67056
- if (this.currentSlideIndex < this.slide.slideCount) {
67836
+ if (this.currentSlideIndex < this.slideCount) {
67057
67837
  this.slide.renderSlide(this.currentSlideIndex + 1);
67058
67838
  }
67059
67839
  });
@@ -67061,10 +67841,10 @@ var SlideApplication = class extends AbstractApplication2 {
67061
67841
  if (!this.permissions.hasPermission(2 /* changePage */)) {
67062
67842
  return;
67063
67843
  }
67064
- if (this.sideBar.root.style.left === "0px") {
67065
- this.sideBar.root.style.left = "-240px";
67844
+ if (this.sideBar.isShowSideBar) {
67845
+ this.sideBar.hidden();
67066
67846
  } else {
67067
- this.sideBar.root.style.left = "0px";
67847
+ this.sideBar.show();
67068
67848
  }
67069
67849
  });
67070
67850
  this.rootView.appendChild(this.contentContainer);
@@ -67087,6 +67867,11 @@ var SlideApplication = class extends AbstractApplication2 {
67087
67867
  return that.footer.root;
67088
67868
  }
67089
67869
  });
67870
+ Object.defineProperty(this.emitter, "sidebarView", {
67871
+ get() {
67872
+ return that.sideBar.root;
67873
+ }
67874
+ });
67090
67875
  Object.defineProperty(this.emitter, "pageIndex", {
67091
67876
  get() {
67092
67877
  return that.currentSlideIndex;
@@ -67094,7 +67879,7 @@ var SlideApplication = class extends AbstractApplication2 {
67094
67879
  });
67095
67880
  Object.defineProperty(this.emitter, "pageCount", {
67096
67881
  get() {
67097
- return that.slide.slideCount;
67882
+ return that.slideCount;
67098
67883
  }
67099
67884
  });
67100
67885
  Object.defineProperty(this.emitter, "goto", {
@@ -67160,37 +67945,22 @@ var SlideApplication = class extends AbstractApplication2 {
67160
67945
  return this.getImageSize(pageIndex);
67161
67946
  }
67162
67947
  });
67948
+ this.applySlideState();
67163
67949
  }
67164
- async getPreviewImage(imageUrl) {
67165
- const image = fetch(imageUrl);
67166
- return await image.then((res) => res.blob()).then((blob) => {
67167
- return new Promise((resolve) => {
67168
- const reader = new FileReader();
67169
- reader.onloadend = () => {
67170
- const base64Data = reader.result;
67171
- const img = document.createElement("img");
67172
- img.src = base64Data;
67173
- img.onload = () => {
67174
- resolve({
67175
- url: imageUrl,
67176
- src: base64Data,
67177
- width: img.width,
67178
- height: img.height
67179
- });
67180
- };
67181
- };
67182
- reader.readAsDataURL(blob);
67183
- });
67184
- });
67950
+ getPreviewImageUrl(pageIndex) {
67951
+ if (pageIndex < 1 || pageIndex > this.slideCount) {
67952
+ throw new Error("pageIndex out of range");
67953
+ }
67954
+ return `${this.prefix}/${this.taskId}/preview/${pageIndex}.png`;
67185
67955
  }
67186
67956
  async getImageUrl(pageIndex) {
67187
- return `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
67957
+ return this.getPreviewImageUrl(pageIndex);
67188
67958
  }
67189
67959
  async getImageSize(pageIndex) {
67190
- const imageUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
67960
+ const imageUrl = this.getPreviewImageUrl(pageIndex);
67191
67961
  let preview = null;
67192
67962
  try {
67193
- const result = await kvStore.getItem(imageUrl);
67963
+ const result = await kvStore2.getItem(imageUrl);
67194
67964
  preview = result ? JSON.parse(result) : null;
67195
67965
  } catch (e) {
67196
67966
  console.warn("kvStore getItem error", e);
@@ -67198,15 +67968,15 @@ var SlideApplication = class extends AbstractApplication2 {
67198
67968
  if (preview) {
67199
67969
  return { width: preview.width, height: preview.height };
67200
67970
  }
67201
- preview = await this.getPreviewImage(imageUrl);
67202
- await kvStore.setItem(imageUrl, JSON.stringify(preview));
67971
+ preview = await this.sideBar.getPreviewImage(imageUrl);
67972
+ await kvStore2.setItem(imageUrl, JSON.stringify(preview));
67203
67973
  return { width: preview.width, height: preview.height };
67204
67974
  }
67205
67975
  async getImageContent(pageIndex) {
67206
- const imageUrl = `${this.prefix}/${this.taskId}/preview/${pageIndex + 1}.png`;
67976
+ const imageUrl = this.getPreviewImageUrl(pageIndex);
67207
67977
  let preview = null;
67208
67978
  try {
67209
- const result = await kvStore.getItem(imageUrl);
67979
+ const result = await kvStore2.getItem(imageUrl);
67210
67980
  preview = result ? JSON.parse(result) : null;
67211
67981
  } catch (e) {
67212
67982
  console.warn("kvStore getItem error", e);
@@ -67214,43 +67984,96 @@ var SlideApplication = class extends AbstractApplication2 {
67214
67984
  if (preview) {
67215
67985
  return preview.src;
67216
67986
  }
67217
- preview = await this.getPreviewImage(imageUrl);
67218
- await kvStore.setItem(imageUrl, JSON.stringify(preview));
67987
+ preview = await this.sideBar.getPreviewImage(imageUrl);
67988
+ await kvStore2.setItem(imageUrl, JSON.stringify(preview));
67219
67989
  return preview.src;
67220
67990
  }
67221
- applySlideState = async (slideState, lastDispatch) => {
67222
- if (this.slide.slideState.currentSlideIndex < 0) {
67223
- this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
67991
+ nextTick = () => {
67992
+ this.isSyncing = false;
67993
+ requestAnimationFrame(() => {
67994
+ this.applySlideState().catch((error) => {
67995
+ console.error("Error in applySlideState:", error);
67996
+ });
67997
+ });
67998
+ };
67999
+ applySlideState = async () => {
68000
+ if (this.isSyncing) {
67224
68001
  return;
67225
68002
  }
67226
- if (this.slide.slideState.currentSlideIndex > 0 && deepEqual(this.slide.slideState, slideState)) {
67227
- this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
68003
+ const lastSyncMessage = this.syncMessageQueue.pop();
68004
+ if (!lastSyncMessage) {
68005
+ return this.nextTick();
68006
+ }
68007
+ this.syncMessageQueue = [];
68008
+ this.isSyncing = true;
68009
+ const { state, dispatch } = lastSyncMessage;
68010
+ let ignoreKeys = void 0;
68011
+ if (dispatch.type === "mediaPlay" || dispatch.type === "mediaPause" || dispatch.type === "mediaFullscreen") {
68012
+ ignoreKeys = [dispatch.id];
68013
+ }
68014
+ if (this.slide.slideState.currentSlideIndex < 0 || state.currentSlideIndex < 0) {
68015
+ await this.slide.receiveSyncHandler(dispatch);
68016
+ return this.nextTick();
68017
+ } else if (!deepEqual(this.slide.slideState, state, ignoreKeys)) {
68018
+ await this.slide.setSlideState(state);
68019
+ await this.slide.receiveSyncHandler(dispatch);
67228
68020
  } else {
67229
- await this.slide.setSlideState(slideState);
67230
- await delay2(200);
67231
- this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, lastDispatch);
68021
+ this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, dispatch);
67232
68022
  }
68023
+ return this.nextTick();
67233
68024
  };
67234
68025
  onSlideEventHandler = async (event) => {
67235
68026
  for (const [key, value] of event.changes.keys.entries()) {
67236
68027
  if (key === "syncSlide") {
67237
68028
  if (value.action === "add" || value.action === "update") {
67238
68029
  const { slideState: slideStateFromServer, dispatch: dispatchFromServer } = this.getMap(this.name).get("syncSlide");
67239
- this.applySlideState(slideStateFromServer, dispatchFromServer);
68030
+ if (this.lastDispatchUuid === dispatchFromServer.uuid) {
68031
+ return;
68032
+ }
68033
+ this.lastDispatchUuid = dispatchFromServer.uuid;
68034
+ this.syncMessageQueue.push({
68035
+ state: slideStateFromServer,
68036
+ dispatch: dispatchFromServer
68037
+ });
68038
+ this.applySlideState();
67240
68039
  }
67241
68040
  }
67242
68041
  }
67243
68042
  };
68043
+ keyBoardEvents = (event) => {
68044
+ if (event.key === "ArrowLeft") {
68045
+ this.footer.emit("prevStep");
68046
+ } else if (event.key === "ArrowRight") {
68047
+ this.footer.emit("nextStep");
68048
+ } else if (event.key === "ArrowUp") {
68049
+ this.footer.emit("prevPage");
68050
+ } else if (event.key === "ArrowDown") {
68051
+ this.footer.emit("nextPage");
68052
+ }
68053
+ };
68054
+ bindKeyBoardEvent() {
68055
+ document.addEventListener("keydown", this.keyBoardEvents);
68056
+ }
68057
+ unbindKeyBoardEvent() {
68058
+ document.removeEventListener("keydown", this.keyBoardEvents);
68059
+ }
68060
+ async onFocusInstance() {
68061
+ this.bindKeyBoardEvent();
68062
+ }
68063
+ onRefocusInstance() {
68064
+ this.unbindKeyBoardEvent();
68065
+ }
67244
68066
  async initialize(option) {
67245
68067
  this.prefix = option.prefix;
67246
68068
  this.taskId = option.taskId;
67247
68069
  const whiteboardApp = new WhiteboardApplication();
67248
- whiteboardApp.roomDoc = this.roomDoc;
67249
- whiteboardApp.appId = `${option.taskId}_wb`;
68070
+ whiteboardApp.appDoc = this.appDoc;
68071
+ whiteboardApp.appId = `${this.appId}_wb`;
67250
68072
  whiteboardApp.userId = this.userId;
67251
68073
  whiteboardApp.userManager = this.userManager;
67252
- whiteboardApp.applicationManager = this.applicationManager;
68074
+ whiteboardApp.deleteSubDoc = this.deleteSubDoc;
67253
68075
  const json = await fetch(`${option.prefix}/${option.taskId}/jsonOutput/slide-1.json`).then((res) => res.json());
68076
+ this.slideCount = json.slideCount;
67254
68077
  await whiteboardApp.initialize({
67255
68078
  width: json.width,
67256
68079
  height: json.height
@@ -67265,11 +68088,13 @@ var SlideApplication = class extends AbstractApplication2 {
67265
68088
  this.whiteboard.view.style.top = "0";
67266
68089
  this.whiteboard.view.style.left = "0";
67267
68090
  this.whiteboard.view.style.zIndex = "4";
68091
+ this.whiteboard.view.classList.add("slide-whiteboard");
67268
68092
  this.whiteboard.permissions.addPermission(WhiteboardPermissionFlag.all);
67269
68093
  this.whiteboard.setCanvasBackgroundColor("#f0f0f000");
67270
68094
  this.whiteboardContainer.style.position = "relative";
67271
68095
  this.whiteboardContainer.style.flex = "0 0 auto";
67272
68096
  this.whiteboardContainer.style.height = "calc(100% - 24px)";
68097
+ this.whiteboardContainer.classList.add("forge-slide-whiteboard-container");
67273
68098
  this.whiteboardContainer.appendChild(this.whiteboard.view);
67274
68099
  this.whiteboardContainer.appendChild(this.slideContainer);
67275
68100
  this.contentContainer.appendChild(this.whiteboardContainer);
@@ -67284,7 +68109,13 @@ var SlideApplication = class extends AbstractApplication2 {
67284
68109
  ...option.options,
67285
68110
  interactive: true,
67286
68111
  anchor: this.slideContainer,
67287
- mode: "interactive"
68112
+ mode: "interactive",
68113
+ clientId: Math.random().toString(36).substring(2, 15),
68114
+ timestamp: () => {
68115
+ console.log("timestamp");
68116
+ console.log(Date.now, this.calibrationTimestamp, Date.now() - this.calibrationTimestamp);
68117
+ return this.calibrationTimestamp;
68118
+ }
67288
68119
  // logger: {
67289
68120
  // info: console.log,
67290
68121
  // warn: console.warn,
@@ -67293,39 +68124,54 @@ var SlideApplication = class extends AbstractApplication2 {
67293
68124
  });
67294
68125
  this.slide.setResource(option.taskId, option.prefix);
67295
68126
  this.sideBar.initialize(json.slideCount, option);
67296
- this.slide.on("syncDispatch", (event) => {
68127
+ this.slide.on(import_slide.SLIDE_EVENTS.syncDispatch, (event) => {
67297
68128
  this.getMap(this.name).set("syncSlide", {
67298
68129
  slideState: this.slide.slideState,
67299
68130
  dispatch: event
67300
68131
  });
67301
68132
  });
67302
- this.slide.on("mainSeqStepStart", (animateIndex) => {
68133
+ this.slide.on(import_slide.SLIDE_EVENTS.mainSeqStepStart, (animateIndex) => {
67303
68134
  this.emitter.emit("mainSeqStepStart", animateIndex);
67304
68135
  });
67305
- this.slide.on("mainSeqStepEnd", (animateIndex) => {
68136
+ this.slide.on(import_slide.SLIDE_EVENTS.mainSeqStepEnd, (animateIndex) => {
67306
68137
  this.emitter.emit("mainSeqStepEnd", animateIndex);
67307
68138
  });
67308
- this.slide.on("renderStart", (slideIndex) => {
67309
- this.whiteboardApp.emitter.view.style.opacity = "0";
67310
- this.whiteboardApp.emitter.addPage(`${slideIndex}`);
67311
- this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
67312
- this.emitter.emit("renderStart", slideIndex);
68139
+ this.slide.on(import_slide.SLIDE_EVENTS.renderError, ({ error, index }) => {
68140
+ if (error.errorType === "CANVAS_CRASH") {
68141
+ this.slide.renderSlide(index);
68142
+ }
67313
68143
  });
67314
- this.slide.on("renderEnd", (slideIndex) => {
67315
- this.currentSlideIndex = slideIndex;
67316
- this.whiteboardApp.emitter.view.style.opacity = "1";
67317
- this.emitter.emit("renderEnd", slideIndex);
68144
+ this.slide.on(import_slide.SLIDE_EVENTS.renderStart, (slideIndex) => {
68145
+ if (slideIndex >= 0) {
68146
+ this.sideBar.pauseGetPreviewImageSchedule();
68147
+ this.whiteboardApp.emitter.view.style.opacity = "0";
68148
+ this.whiteboardApp.emitter.addPage(`${slideIndex}`);
68149
+ this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
68150
+ this.sideBar.hidden();
68151
+ this.emitter.emit("renderStart", slideIndex);
68152
+ }
68153
+ });
68154
+ this.slide.on(import_slide.SLIDE_EVENTS.renderEnd, (slideIndex) => {
68155
+ if (slideIndex >= 0) {
68156
+ this.sideBar.startGetPreviewImageSchedule();
68157
+ this.currentSlideIndex = slideIndex;
68158
+ this.whiteboardApp.emitter.view.style.opacity = "1";
68159
+ this.emitter.emit("renderEnd", slideIndex);
68160
+ }
67318
68161
  });
67319
- this.slide.on("stateChange", (state) => {
68162
+ this.slide.on(import_slide.SLIDE_EVENTS.stateChange, (state) => {
67320
68163
  this.getMap(this.name).set("slideState", state);
67321
68164
  });
67322
68165
  this.getMap(this.name).observe(this.onSlideEventHandler);
67323
68166
  window.slide = this.slide;
67324
68167
  window.slideWhiteboard = this.whiteboardApp;
67325
68168
  window.forgeSlide = this;
68169
+ this.whiteboardContainer.addEventListener("click", () => {
68170
+ this.sideBar.hidden();
68171
+ }, false);
67326
68172
  const syncSlide = this.getMap(this.name).get("slideState");
67327
68173
  if (syncSlide && syncSlide.taskId === option.taskId) {
67328
- await this.slide.setSlideState(syncSlide);
68174
+ this.slide.setSlideState(syncSlide);
67329
68175
  } else {
67330
68176
  this.slide.renderSlide(1);
67331
68177
  }
@@ -67342,8 +68188,32 @@ var SlideApplication = class extends AbstractApplication2 {
67342
68188
  }
67343
68189
  }
67344
68190
  });
67345
- this.permissions.addPermission(7 /* all */);
68191
+ this.permissions.setPermission(7 /* all */);
67346
68192
  this.whiteboardApp.disableViewModel();
68193
+ if (this.window) {
68194
+ let prevStatus = "normal";
68195
+ this.window.on("statusChange", (status) => {
68196
+ if (prevStatus === "minimized") {
68197
+ this.onFocusInstance();
68198
+ prevStatus = status;
68199
+ return;
68200
+ }
68201
+ prevStatus = status;
68202
+ if (status === "normal") {
68203
+ this.onFocusInstance();
68204
+ } else if (status === "minimized") {
68205
+ this.onRefocusInstance();
68206
+ }
68207
+ });
68208
+ this.window.on("focusedChange", (status) => {
68209
+ if (status) {
68210
+ this.onFocusInstance();
68211
+ } else {
68212
+ this.onRefocusInstance();
68213
+ }
68214
+ });
68215
+ this.bindKeyBoardEvent();
68216
+ }
67347
68217
  window.__forge_slide = this;
67348
68218
  window.slidePermissions = this.permissions;
67349
68219
  return Promise.resolve(void 0);
@@ -67351,13 +68221,17 @@ var SlideApplication = class extends AbstractApplication2 {
67351
68221
  userMap(userId) {
67352
68222
  return this.getMap(`user/${userId}`);
67353
68223
  }
67354
- async dispose() {
67355
- await this.whiteboardApp.dispose();
68224
+ async dispose(removeSubDoc) {
68225
+ if (removeSubDoc) {
68226
+ this.deleteSubDoc(this.appId);
68227
+ }
68228
+ await this.whiteboardApp.dispose(removeSubDoc);
67356
68229
  this.rootView.parentElement?.removeChild(this.rootView);
67357
68230
  this.slide.destroy();
67358
68231
  this.sideBar.dispose();
67359
68232
  this.getMap(this.name).unobserve(this.onSlideEventHandler);
67360
- return Promise.resolve(void 0);
68233
+ this.permissions.dispose();
68234
+ this.footer.dispose();
67361
68235
  }
67362
68236
  };
67363
68237
  export {