@netless/forge-slide 1.0.10 → 1.1.0-beta.2

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;
@@ -67651,6 +67651,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
67651
67651
  this.shadowScope.settings.insertItems = false;
67652
67652
  this.snapshotCanvasElement.setAttribute("id", `${this.appId}-snapshot`);
67653
67653
  this.snapshotScope.setup(this.snapshotCanvasElement);
67654
+ this.snapshotScope.settings.insertItems = false;
67654
67655
  this.resizeObserver = new ResizeObserver(() => {
67655
67656
  if (this.internalResizeObserver) {
67656
67657
  const rootBounds = this.rootElement.getBoundingClientRect();
@@ -67980,6 +67981,16 @@ var SlideForge = class extends import_eventemitter313.default {
67980
67981
  * @param {number} index 页面索引
67981
67982
  */
67982
67983
  imgSize;
67984
+ /**
67985
+ * 冻结当前幻灯片, 释放资源
67986
+ * @param {() => void} [callback] 冻结完成回调
67987
+ */
67988
+ frozen;
67989
+ /**
67990
+ * 解冻冻结的幻灯片, 重新获取资源
67991
+ * @param {() => void} [callback] 解冻完成回调
67992
+ */
67993
+ release;
67983
67994
  };
67984
67995
 
67985
67996
  // src/ForgeSlidePermession.ts
@@ -68365,11 +68376,109 @@ function arrayEqual(arr1, arr2) {
68365
68376
  }
68366
68377
  return true;
68367
68378
  }
68379
+ async function delay2(time) {
68380
+ return new Promise((resolve) => setTimeout(resolve, time));
68381
+ }
68382
+
68383
+ // src/SlidePool.ts
68384
+ var SlidePool = class {
68385
+ pool = [];
68386
+ maxActiveSize = 2;
68387
+ renderingQueue = [];
68388
+ renderingQueueCallback;
68389
+ constructor(maxActiveSize) {
68390
+ if (maxActiveSize) {
68391
+ this.setMaxActiveSize(maxActiveSize);
68392
+ }
68393
+ }
68394
+ async freeze(poolItem) {
68395
+ return new Promise((resolve, _reject) => {
68396
+ if (!poolItem.slide.view) {
68397
+ resolve(false);
68398
+ } else {
68399
+ poolItem.slide.frozen(() => {
68400
+ resolve(true);
68401
+ });
68402
+ }
68403
+ });
68404
+ }
68405
+ async unfreeze(poolItem) {
68406
+ return new Promise((resolve, _reject) => {
68407
+ if (poolItem.slide.view) {
68408
+ resolve(false);
68409
+ } else {
68410
+ poolItem.slide.release(() => {
68411
+ resolve(true);
68412
+ });
68413
+ }
68414
+ });
68415
+ }
68416
+ async checkPool() {
68417
+ for (let i = 0; i < this.pool.length; i++) {
68418
+ const poolItem = this.pool[i];
68419
+ if (i < this.maxActiveSize) {
68420
+ await this.unfreeze(poolItem);
68421
+ } else {
68422
+ await this.freeze(poolItem);
68423
+ }
68424
+ }
68425
+ }
68426
+ onRenderEnd(appId, isFocus) {
68427
+ const index = this.renderingQueue.findIndex((item) => item === appId);
68428
+ if (index > -1) {
68429
+ this.renderingQueue.splice(index, 1);
68430
+ }
68431
+ if (isFocus) {
68432
+ this.renderingQueueCallback = () => {
68433
+ const poolItem = this.pool.find((item) => item.key === appId);
68434
+ if (poolItem) {
68435
+ this.active(appId, poolItem.slide);
68436
+ }
68437
+ };
68438
+ }
68439
+ if (this.renderingQueue.length === 0 && this.renderingQueueCallback) {
68440
+ this.renderingQueueCallback();
68441
+ }
68442
+ }
68443
+ setMaxActiveSize(maxActiveSize) {
68444
+ this.maxActiveSize = maxActiveSize > 8 ? 8 : maxActiveSize;
68445
+ if (maxActiveSize > 8) {
68446
+ console.warn("maxActiveSize should not be greater than 8");
68447
+ }
68448
+ }
68449
+ async waitUntilReady(appId) {
68450
+ if (this.renderingQueue.length < this.maxActiveSize) {
68451
+ this.renderingQueue.push(appId);
68452
+ return;
68453
+ } else {
68454
+ await delay2(200);
68455
+ await this.waitUntilReady(appId);
68456
+ }
68457
+ }
68458
+ async active(key, slide) {
68459
+ const index = this.pool.findIndex((item) => item.key === key);
68460
+ if (index < 0) {
68461
+ this.pool.unshift({ key, slide });
68462
+ } else {
68463
+ this.pool.splice(index, 1);
68464
+ this.pool.unshift({ key, slide });
68465
+ }
68466
+ await this.checkPool();
68467
+ }
68468
+ remove(key) {
68469
+ const index = this.pool.findIndex((item) => item.key === key);
68470
+ if (index >= 0) {
68471
+ this.pool.splice(index, 1);
68472
+ }
68473
+ }
68474
+ };
68475
+ var slidePool = new SlidePool();
68368
68476
 
68369
68477
  // src/SlideApplication.ts
68370
68478
  var Slide_APP_NAME = "forge_slide";
68371
- var SlideApplication = class extends import_forge_room16.AbstractApplication {
68479
+ var SlideApplication = class _SlideApplication extends import_forge_room16.AbstractApplication {
68372
68480
  static applicationName = Slide_APP_NAME;
68481
+ static slidePool = new SlidePool();
68373
68482
  name = Slide_APP_NAME;
68374
68483
  emitter = new SlideForge();
68375
68484
  whiteboardApp;
@@ -68558,7 +68667,20 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68558
68667
  return this.getImageSize(pageIndex);
68559
68668
  }
68560
68669
  });
68561
- this.applySlideState();
68670
+ Object.defineProperty(this.emitter, "frozen", {
68671
+ writable: false,
68672
+ enumerable: false,
68673
+ value: (callback) => {
68674
+ return this.slide.frozen(callback);
68675
+ }
68676
+ });
68677
+ Object.defineProperty(this.emitter, "release", {
68678
+ writable: false,
68679
+ enumerable: false,
68680
+ value: (callback) => {
68681
+ return this.slide.release(callback);
68682
+ }
68683
+ });
68562
68684
  }
68563
68685
  getPreviewImageUrl(pageIndex) {
68564
68686
  if (pageIndex < 1 || pageIndex > this.slideCount) {
@@ -68601,24 +68723,17 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68601
68723
  await import_forge_room16.kvStore.setItem(imageUrl, JSON.stringify(preview));
68602
68724
  return preview.src;
68603
68725
  }
68604
- nextTick = () => {
68605
- this.isSyncing = false;
68606
- requestAnimationFrame(() => {
68607
- this.applySlideState().catch((error) => {
68608
- console.error("Error in applySlideState:", error);
68609
- });
68610
- });
68611
- };
68612
68726
  applySlideState = async () => {
68613
68727
  if (this.isSyncing) {
68728
+ requestAnimationFrame(this.applySlideState);
68614
68729
  return;
68615
68730
  }
68616
68731
  const lastSyncMessage = this.syncMessageQueue.pop();
68617
68732
  if (!lastSyncMessage) {
68618
- return this.nextTick();
68733
+ return;
68619
68734
  }
68620
- this.syncMessageQueue = [];
68621
68735
  this.isSyncing = true;
68736
+ this.syncMessageQueue = [];
68622
68737
  const { state, dispatch } = lastSyncMessage;
68623
68738
  let ignoreKeys = void 0;
68624
68739
  if (dispatch.type === "mediaPlay" || dispatch.type === "mediaPause" || dispatch.type === "mediaFullscreen") {
@@ -68626,14 +68741,13 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68626
68741
  }
68627
68742
  if (this.slide.slideState.currentSlideIndex < 0 || state.currentSlideIndex < 0) {
68628
68743
  await this.slide.receiveSyncHandler(dispatch);
68629
- return this.nextTick();
68630
68744
  } else if (!deepEqual(this.slide.slideState, state, ignoreKeys)) {
68631
68745
  await this.slide.setSlideState(state);
68632
68746
  await this.slide.receiveSyncHandler(dispatch);
68633
68747
  } else {
68634
68748
  this.slide.emit(import_slide.SLIDE_EVENTS.syncReceive, dispatch);
68635
68749
  }
68636
- return this.nextTick();
68750
+ this.isSyncing = false;
68637
68751
  };
68638
68752
  onSlideEventHandler = async (event) => {
68639
68753
  for (const [key, value] of event.changes.keys.entries()) {
@@ -68672,6 +68786,7 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68672
68786
  }
68673
68787
  async onFocusInstance() {
68674
68788
  this.bindKeyBoardEvent();
68789
+ await _SlideApplication.slidePool.active(this.appId, this.slide);
68675
68790
  }
68676
68791
  onRefocusInstance() {
68677
68792
  this.unbindKeyBoardEvent();
@@ -68721,7 +68836,12 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68721
68836
  whiteboardApp.linkToWhiteboard(option.inheritWhiteboardId);
68722
68837
  }
68723
68838
  this.whiteboard.setViewModeToMain();
68839
+ for (let i = 0; i < json.slideCount; i++) {
68840
+ this.whiteboardApp.addPage(String(i), true);
68841
+ }
68842
+ this.whiteboard.setViewModeToFree();
68724
68843
  this.slideContainer.setAttribute("builder", "slide-builder");
68844
+ await _SlideApplication.slidePool.waitUntilReady(this.appId);
68725
68845
  this.slide = new import_slide.Slide({
68726
68846
  ...option.options,
68727
68847
  interactive: true,
@@ -68764,8 +68884,7 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68764
68884
  if (slideIndex >= 0) {
68765
68885
  this.sideBar.pauseGetPreviewImageSchedule();
68766
68886
  this.whiteboardApp.emitter.view.style.opacity = "0";
68767
- this.whiteboardApp.emitter.addPage(`${slideIndex}`);
68768
- this.whiteboardApp.emitter.gotoPage(`${slideIndex}`);
68887
+ this.whiteboardApp.emitter.gotoPage(String(slideIndex));
68769
68888
  this.sideBar.hidden();
68770
68889
  this.footer.changeIconToPause();
68771
68890
  this.emitter.emit("renderStart", slideIndex);
@@ -68777,6 +68896,8 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68777
68896
  this.currentSlideIndex = slideIndex;
68778
68897
  this.whiteboardApp.emitter.view.style.opacity = "1";
68779
68898
  this.footer.setCurrentPageIndex(slideIndex);
68899
+ _SlideApplication.slidePool.active(this.appId, this.slide);
68900
+ _SlideApplication.slidePool.onRenderEnd(this.appId, this.window?.focused ?? false);
68780
68901
  this.footer.changeIconToNextStep();
68781
68902
  this.emitter.emit("renderEnd", slideIndex);
68782
68903
  }
@@ -68852,6 +68973,7 @@ var SlideApplication = class extends import_forge_room16.AbstractApplication {
68852
68973
  this.getMap(this.name).unobserve(this.onSlideEventHandler);
68853
68974
  this.permissions.dispose();
68854
68975
  this.footer.dispose();
68976
+ _SlideApplication.slidePool.remove(this.appId);
68855
68977
  }
68856
68978
  };
68857
68979
  /*! Bundled license information: