@netless/forge-slide 1.1.0-beta.1 → 1.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/slide.js CHANGED
@@ -59385,7 +59385,7 @@ var require_lodash = __commonJS2({
59385
59385
  var defer = baseRest(function(func, args) {
59386
59386
  return baseDelay(func, 1, args);
59387
59387
  });
59388
- var delay2 = baseRest(function(func, wait, args) {
59388
+ var delay22 = baseRest(function(func, wait, args) {
59389
59389
  return baseDelay(func, toNumber(wait) || 0, args);
59390
59390
  });
59391
59391
  function flip(func) {
@@ -60499,7 +60499,7 @@ var require_lodash = __commonJS2({
60499
60499
  lodash.defaults = defaults;
60500
60500
  lodash.defaultsDeep = defaultsDeep;
60501
60501
  lodash.defer = defer;
60502
- lodash.delay = delay2;
60502
+ lodash.delay = delay22;
60503
60503
  lodash.difference = difference;
60504
60504
  lodash.differenceBy = differenceBy;
60505
60505
  lodash.differenceWith = differenceWith;
@@ -65188,6 +65188,8 @@ var Camera = class extends import_eventemitter36.default {
65188
65188
  this.emit("userViewModeChange", userId, this.requestUserMap(userId).get(WhiteboardKeys.cameraMode), value.oldValue);
65189
65189
  }
65190
65190
  }
65191
+ } else if (value.action === "delete") {
65192
+ debugger;
65191
65193
  }
65192
65194
  }
65193
65195
  });
@@ -67523,6 +67525,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
67523
67525
  _WhiteboardApplication.instanceCount.set(this.appId, (_WhiteboardApplication.instanceCount.get(this.appId) ?? 0) + 1);
67524
67526
  (0, import_forge_room.log)(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
67525
67527
  this.appDoc.transact(() => {
67528
+ console.warn("initialize whiteboard application");
67526
67529
  this.permissions = new WhiteboardPermissions(this.writableManager, this.userManager, (userId) => {
67527
67530
  return this.userMap(userId);
67528
67531
  });
@@ -67651,6 +67654,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
67651
67654
  this.shadowScope.settings.insertItems = false;
67652
67655
  this.snapshotCanvasElement.setAttribute("id", `${this.appId}-snapshot`);
67653
67656
  this.snapshotScope.setup(this.snapshotCanvasElement);
67657
+ this.snapshotScope.settings.insertItems = false;
67654
67658
  this.resizeObserver = new ResizeObserver(() => {
67655
67659
  if (this.internalResizeObserver) {
67656
67660
  const rootBounds = this.rootElement.getBoundingClientRect();
@@ -67720,6 +67724,8 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
67720
67724
  this.rootElement.appendChild(this.liveCursor.container);
67721
67725
  this.getMap("attrs").observe(this.handleViewportUpdate);
67722
67726
  this.writableManager().on("writableChanged", this.handleWritableChanged);
67727
+ console.warn("initialize whiteboard application end");
67728
+ console.log(this.appDoc.toJSON());
67723
67729
  }, "whiteboard-initialize");
67724
67730
  }
67725
67731
  clearElements() {
@@ -67980,6 +67986,16 @@ var SlideForge = class extends import_eventemitter313.default {
67980
67986
  * @param {number} index 页面索引
67981
67987
  */
67982
67988
  imgSize;
67989
+ /**
67990
+ * 冻结当前幻灯片, 释放资源
67991
+ * @param {() => void} [callback] 冻结完成回调
67992
+ */
67993
+ frozen;
67994
+ /**
67995
+ * 解冻冻结的幻灯片, 重新获取资源
67996
+ * @param {() => void} [callback] 解冻完成回调
67997
+ */
67998
+ release;
67983
67999
  };
67984
68000
 
67985
68001
  // src/ForgeSlidePermession.ts
@@ -68365,11 +68381,109 @@ function arrayEqual(arr1, arr2) {
68365
68381
  }
68366
68382
  return true;
68367
68383
  }
68384
+ async function delay2(time) {
68385
+ return new Promise((resolve) => setTimeout(resolve, time));
68386
+ }
68387
+
68388
+ // src/SlidePool.ts
68389
+ var SlidePool = class {
68390
+ pool = [];
68391
+ maxActiveSize = 2;
68392
+ renderingQueue = [];
68393
+ renderingQueueCallback;
68394
+ constructor(maxActiveSize) {
68395
+ if (maxActiveSize) {
68396
+ this.setMaxActiveSize(maxActiveSize);
68397
+ }
68398
+ }
68399
+ async freeze(poolItem) {
68400
+ return new Promise((resolve, _reject) => {
68401
+ if (!poolItem.slide.view) {
68402
+ resolve(false);
68403
+ } else {
68404
+ poolItem.slide.frozen(() => {
68405
+ resolve(true);
68406
+ });
68407
+ }
68408
+ });
68409
+ }
68410
+ async unfreeze(poolItem) {
68411
+ return new Promise((resolve, _reject) => {
68412
+ if (poolItem.slide.view) {
68413
+ resolve(false);
68414
+ } else {
68415
+ poolItem.slide.release(() => {
68416
+ resolve(true);
68417
+ });
68418
+ }
68419
+ });
68420
+ }
68421
+ async checkPool() {
68422
+ for (let i = 0; i < this.pool.length; i++) {
68423
+ const poolItem = this.pool[i];
68424
+ if (i < this.maxActiveSize) {
68425
+ await this.unfreeze(poolItem);
68426
+ } else {
68427
+ await this.freeze(poolItem);
68428
+ }
68429
+ }
68430
+ }
68431
+ onRenderEnd(appId, isFocus) {
68432
+ const index = this.renderingQueue.findIndex((item) => item === appId);
68433
+ if (index > -1) {
68434
+ this.renderingQueue.splice(index, 1);
68435
+ }
68436
+ if (isFocus) {
68437
+ this.renderingQueueCallback = () => {
68438
+ const poolItem = this.pool.find((item) => item.key === appId);
68439
+ if (poolItem) {
68440
+ this.active(appId, poolItem.slide);
68441
+ }
68442
+ };
68443
+ }
68444
+ if (this.renderingQueue.length === 0 && this.renderingQueueCallback) {
68445
+ this.renderingQueueCallback();
68446
+ }
68447
+ }
68448
+ setMaxActiveSize(maxActiveSize) {
68449
+ this.maxActiveSize = maxActiveSize > 8 ? 8 : maxActiveSize;
68450
+ if (maxActiveSize > 8) {
68451
+ console.warn("maxActiveSize should not be greater than 8");
68452
+ }
68453
+ }
68454
+ async waitUntilReady(appId) {
68455
+ if (this.renderingQueue.length < this.maxActiveSize) {
68456
+ this.renderingQueue.push(appId);
68457
+ return;
68458
+ } else {
68459
+ await delay2(200);
68460
+ await this.waitUntilReady(appId);
68461
+ }
68462
+ }
68463
+ async active(key, slide) {
68464
+ const index = this.pool.findIndex((item) => item.key === key);
68465
+ if (index < 0) {
68466
+ this.pool.unshift({ key, slide });
68467
+ } else {
68468
+ this.pool.splice(index, 1);
68469
+ this.pool.unshift({ key, slide });
68470
+ }
68471
+ await this.checkPool();
68472
+ }
68473
+ remove(key) {
68474
+ const index = this.pool.findIndex((item) => item.key === key);
68475
+ if (index >= 0) {
68476
+ this.pool.splice(index, 1);
68477
+ }
68478
+ }
68479
+ };
68480
+ var slidePool = new SlidePool();
68368
68481
 
68369
68482
  // src/SlideApplication.ts
68370
68483
  var Slide_APP_NAME = "forge_slide";
68371
- var SlideApplication = class extends import_forge_room16.AbstractApplication {
68484
+ var SlideApplication = class _SlideApplication extends import_forge_room16.AbstractApplication {
68372
68485
  static applicationName = Slide_APP_NAME;
68486
+ static slidePool = new SlidePool();
68373
68487
  name = Slide_APP_NAME;
68374
68488
  emitter = new SlideForge();
68375
68489
  whiteboardApp;
@@ -68558,7 +68672,20 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68558
68672
  return this.getImageSize(pageIndex);
68559
68673
  }
68560
68674
  });
68561
- this.applySlideState();
68675
+ Object.defineProperty(this.emitter, "frozen", {
68676
+ writable: false,
68677
+ enumerable: false,
68678
+ value: (callback) => {
68679
+ return this.slide.frozen(callback);
68680
+ }
68681
+ });
68682
+ Object.defineProperty(this.emitter, "release", {
68683
+ writable: false,
68684
+ enumerable: false,
68685
+ value: (callback) => {
68686
+ return this.slide.release(callback);
68687
+ }
68688
+ });
68562
68689
  }
68563
68690
  getPreviewImageUrl(pageIndex) {
68564
68691
  if (pageIndex < 1 || pageIndex > this.slideCount) {
@@ -68601,24 +68728,17 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68601
68728
  await import_forge_room16.kvStore.setItem(imageUrl, JSON.stringify(preview));
68602
68729
  return preview.src;
68603
68730
  }
68604
- nextTick = () => {
68605
- this.isSyncing = false;
68606
- requestAnimationFrame(() => {
68607
- this.applySlideState().catch((error) => {
68608
- console.error("Error in applySlideState:", error);
68609
- });
68610
- });
68611
- };
68612
68731
  applySlideState = async () => {
68613
68732
  if (this.isSyncing) {
68733
+ requestAnimationFrame(this.applySlideState);
68614
68734
  return;
68615
68735
  }
68616
68736
  const lastSyncMessage = this.syncMessageQueue.pop();
68617
68737
  if (!lastSyncMessage) {
68618
- return this.nextTick();
68738
+ return;
68619
68739
  }
68620
- this.syncMessageQueue = [];
68621
68740
  this.isSyncing = true;
68741
+ this.syncMessageQueue = [];
68622
68742
  const { state, dispatch } = lastSyncMessage;
68623
68743
  let ignoreKeys = void 0;
68624
68744
  if (dispatch.type === "mediaPlay" || dispatch.type === "mediaPause" || dispatch.type === "mediaFullscreen") {
@@ -68626,14 +68746,13 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68626
68746
  }
68627
68747
  if (this.slide.slideState.currentSlideIndex < 0 || state.currentSlideIndex < 0) {
68628
68748
  await this.slide.receiveSyncHandler(dispatch);
68629
- return this.nextTick();
68630
68749
  } else if (!deepEqual(this.slide.slideState, state, ignoreKeys)) {
68631
68750
  await this.slide.setSlideState(state);
68632
68751
  await this.slide.receiveSyncHandler(dispatch);
68633
68752
  } else {
68634
68753
  this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, dispatch);
68635
68754
  }
68636
- return this.nextTick();
68755
+ this.isSyncing = false;
68637
68756
  };
68638
68757
  onSlideEventHandler = async (event) => {
68639
68758
  for (const [key, value] of event.changes.keys.entries()) {
@@ -68672,6 +68791,7 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68672
68791
  }
68673
68792
  async onFocusInstance() {
68674
68793
  this.bindKeyBoardEvent();
68794
+ await _SlideApplication.slidePool.active(this.appId, this.slide);
68675
68795
  }
68676
68796
  onRefocusInstance() {
68677
68797
  this.unbindKeyBoardEvent();
@@ -68721,7 +68841,12 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68721
68841
  whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
68722
68842
  }
68723
68843
  this.whiteboard.setViewModeToMain();
68844
+ for (let i = 0; i < json.slideCount; i++) {
68845
+ this.whiteboardApp.addPage(String(i), true);
68846
+ }
68847
+ this.whiteboard.setViewModeToFree();
68724
68848
  this.slideContainer.setAttribute("builder", "slide-builder");
68849
+ await _SlideApplication.slidePool.waitUntilReady(this.appId);
68725
68850
  this.slide = new import_slide.Slide({
68726
68851
  ...option.options,
68727
68852
  interactive: true,
@@ -68764,8 +68889,7 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68764
68889
  if (slideIndex >= 0) {
68765
68890
  this.sideBar.pauseGetPreviewImageSchedule();
68766
68891
  this.whiteboardApp.emitter.view.style.opacity = "0";
68767
- this.whiteboardApp.emitter.addPage(`${slideIndex}`);
68768
- this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
68892
+ this.whiteboardApp.emitter.gotoPage(String(slideIndex));
68769
68893
  this.sideBar.hidden();
68770
68894
  this.footer.changeIconToPause();
68771
68895
  this.emitter.emit("renderStart", slideIndex);
@@ -68777,6 +68901,8 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68777
68901
  this.currentSlideIndex = slideIndex;
68778
68902
  this.whiteboardApp.emitter.view.style.opacity = "1";
68779
68903
  this.footer.setCurrentPageIndex(slideIndex);
68904
+ _SlideApplication.slidePool.active(this.appId, this.slide);
68905
+ _SlideApplication.slidePool.onRenderEnd(this.appId, this.window?.focused ?? false);
68780
68906
  this.footer.changeIconToNextStep();
68781
68907
  this.emitter.emit("renderEnd", slideIndex);
68782
68908
  }
@@ -68852,6 +68978,7 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68852
68978
  this.getMap(this.name).unobserve(this.onSlideEventHandler);
68853
68979
  this.permissions.dispose();
68854
68980
  this.footer.dispose();
68981
+ _SlideApplication.slidePool.remove(this.appId);
68855
68982
  }
68856
68983
  };
68857
68984
  /*! Bundled license information: