@netless/app-slide 0.2.106-beta.1 → 0.2.106-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/main.es.js CHANGED
@@ -32263,7 +32263,12 @@ void main(void){
32263
32263
  }, this.showController = (t3) => {
32264
32264
  t3.stopPropagation(), this.show();
32265
32265
  }, this.getMediaDuration = () => {
32266
- this.duration && !Number.isNaN(this.duration) || (this.duration = this.media.duration, this.start && (this.duration -= this.start, this.jumpToTime()), this.end && (this.duration -= this.end)), this.totalTime.innerText = Dy.formatTime(this.duration);
32266
+ if (this.duration <= 0 || !Number.isFinite(this.duration)) {
32267
+ if (!Number.isFinite(this.media.duration) || this.media.duration <= 0)
32268
+ return;
32269
+ this.duration = this.media.duration, this.start && (this.duration -= this.start, 0 === this.seekGeneration && this.jumpToTime()), this.end && (this.duration -= this.end), this.duration = Math.max(0, this.duration);
32270
+ }
32271
+ this.totalTime.innerText = Dy.formatTime(this.duration);
32267
32272
  }, this.playMedia = () => Oy(this, void 0, void 0, function* () {
32268
32273
  this.playButton.style.display = "none", this.pauseButton.style.display = "block", yield this.media.play(), this.medianIsEnd && (this.medianIsEnd = false, this.jumpToTime()), this.playCallBackList.forEach((t3) => {
32269
32274
  t3();
@@ -32284,7 +32289,7 @@ void main(void){
32284
32289
  }, this.onPlayMedia = () => {
32285
32290
  this.fadeState = { in: false, out: false }, this.fadeHit(0), this.playButton.style.display = "none", this.pauseButton.style.display = "block", this.playCallBackList.forEach((t3) => {
32286
32291
  t3();
32287
- }), this.media.currentTime < this.start && this.jumpToTime();
32292
+ }), this.duration > 0 && this.media.currentTime < this.start && this.jumpToTime();
32288
32293
  }, this._playMediaFromCtrl = () => {
32289
32294
  this.playMediaFromCtrl(false);
32290
32295
  }, this._pauseMediaFromCtrl = () => {
@@ -32707,7 +32712,7 @@ void main(void){
32707
32712
  class Uy extends Ka.a {
32708
32713
  constructor(t2) {
32709
32714
  var e2, i2, n2, r2, o2, s2, a2, l2;
32710
- super(), this.type = "video", this.sprite = new np(), this.rtcAudio = null, this.isPlaying = false, this.audioNeedsUserGesture = false, this.videoNeedsUserGesture = false, this.isGlobalPause = false, this.fullscreen = false, this.url = "", this.isLoaded = false, this.destroyed = false, this.videoEventListeners = /* @__PURE__ */ new Map(), this.operationGeneration = 0, this.spriteVisibilityTimeout = "", this.onVideoResourceLoaded = () => {
32715
+ super(), this.type = "video", this.sprite = new np(), this.rtcAudio = null, this.isPlaying = false, this.audioNeedsUserGesture = false, this.videoNeedsUserGesture = false, this.isGlobalPause = false, this.fullscreen = false, this.url = "", this.isLoaded = false, this.destroyed = false, this.videoEventListeners = /* @__PURE__ */ new Map(), this.operationGeneration = 0, this.spriteVisibilityTimeout = "", this.audioRecoveryInProgress = false, this.onVideoResourceLoaded = () => {
32711
32716
  this.destroyed || (this.isLoaded = true, this.notifyUserGestureRequirement());
32712
32717
  }, this.onRtcAudioLoad = () => {
32713
32718
  this.notifyUserGestureRequirement();
@@ -32845,10 +32850,17 @@ void main(void){
32845
32850
  recoverAudioAfterVideoStart() {
32846
32851
  var t2;
32847
32852
  const { operationGeneration: e2 } = this;
32848
- if (this.destroyed || !this.isPlaying || this.audioPlayGeneration !== e2 || this.audioRecoveryGeneration === e2)
32853
+ if (this.destroyed || !this.isPlaying || this.audioPlayGeneration !== e2 || this.audioRecoveryGeneration === e2 || this.audioRecoveryInProgress)
32849
32854
  return;
32850
32855
  const i2 = this.videoElement;
32851
- !i2 || i2.paused || !Number.isFinite(i2.currentTime) || i2.currentTime <= 0 || (this.audioRecoveryGeneration = e2, null === (t2 = this.rtcAudio) || void 0 === t2 || t2.recoverFromNativePause(i2.currentTime));
32856
+ if (i2 && !i2.paused && Number.isFinite(i2.currentTime) && !(i2.currentTime <= 0)) {
32857
+ this.audioRecoveryInProgress = true;
32858
+ try {
32859
+ (null === (t2 = this.rtcAudio) || void 0 === t2 ? void 0 : t2.recoverFromNativePause(i2.currentTime)) && (this.audioRecoveryGeneration = e2);
32860
+ } finally {
32861
+ this.audioRecoveryInProgress = false;
32862
+ }
32863
+ }
32852
32864
  }
32853
32865
  showController() {
32854
32866
  this.controller.show();
@@ -33345,6 +33357,8 @@ void main(void){
33345
33357
  this.triggerParams = t2;
33346
33358
  }
33347
33359
  addCond(t2) {
33360
+ if (t2.event && void 0 !== this.cond[t2.event])
33361
+ return;
33348
33362
  const e2 = (...e3) => {
33349
33363
  this.condHandle(t2, e3);
33350
33364
  }, i2 = (t3, i3) => {
@@ -33397,7 +33411,10 @@ void main(void){
33397
33411
  }
33398
33412
  };
33399
33413
  const { json: e2, iterateType: i2, isIterate: n2, isSub: r2, parent: o2, ctx: s2, eventHub: a2, iterateIndex: l2, iterateId: h2, isInInteractiveSeq: u2 } = t2;
33400
- this.isMainSeq = "mainSeq" === e2.ctn.nodeType, this.isInteractiveSeq = "interactiveSeq" === e2.ctn.nodeType, this.id = e2.ctn.id, this.isIterate = n2, this.json = e2, this.ctx = s2, this.timingClock = s2.timingClock, this.globalEventHub = a2, this.commonTimeNode = new Z_({ json: e2.ctn, isSub: r2, eventHubs: { global: a2, runtime: this.runtimeNodeEventHub }, ctx: s2, parent: o2, isIterate: false, iterateType: i2, iterateIndex: l2, iterateId: h2, isInInteractiveSeq: u2 || this.isInteractiveSeq, fromSeqId: this.isInteractiveSeq ? this.json.ctn.id : "" }), this.bindShapeEvent(), this.nextConds = new Xy("mainSeq", e2.nextCondLst, { global: a2, runtime: this.runtimeNodeEventHub }, this.ctx), this.prevConds = new Xy("mainSeq", e2.preCondLst, { global: a2, runtime: this.runtimeNodeEventHub }, this.ctx), this.commonTimeNode.on("timeNodeRestart", () => {
33414
+ this.isMainSeq = "mainSeq" === e2.ctn.nodeType, this.isInteractiveSeq = "interactiveSeq" === e2.ctn.nodeType, this.id = e2.ctn.id, this.isIterate = n2, this.json = e2, this.ctx = s2, this.timingClock = s2.timingClock, this.globalEventHub = a2, this.commonTimeNode = new Z_({ json: e2.ctn, isSub: r2, eventHubs: { global: a2, runtime: this.runtimeNodeEventHub }, ctx: s2, parent: o2, isIterate: false, iterateType: i2, iterateIndex: l2, iterateId: h2, isInInteractiveSeq: u2 || this.isInteractiveSeq, fromSeqId: this.isInteractiveSeq ? this.json.ctn.id : "" }), this.bindShapeEvent(), this.nextConds = new Xy("mainSeq", e2.nextCondLst, { global: a2, runtime: this.runtimeNodeEventHub }, this.ctx), this.prevConds = new Xy("mainSeq", e2.preCondLst, { global: a2, runtime: this.runtimeNodeEventHub }, this.ctx), this.isInteractiveSeq && 0 === e2.nextCondLst.length && this.commonTimeNode.on("timeNodeStart", () => {
33415
+ var t3;
33416
+ null === (t3 = this.commonTimeNode.children[0]) || void 0 === t3 || t3.commonTimeNode.startTimeNodeForce();
33417
+ }), this.commonTimeNode.on("timeNodeRestart", () => {
33401
33418
  this.currentSeqIndex = 0, this.currentSeqState = "idle";
33402
33419
  }), this.commonTimeNode.on("childTimeNodeStart", (t3) => {
33403
33420
  const e3 = this.commonTimeNode.children.findIndex((e4) => e4.commonTimeNode.uuid === t3.id);
@@ -33459,23 +33476,26 @@ void main(void){
33459
33476
  t2.isInfiniteRepeat() ? e2.result = t2 : t2.children.map((t3) => t3.commonTimeNode).forEach((t3) => this.findChildInfiniteRepeat(t3, e2));
33460
33477
  }
33461
33478
  bindShapeEvent() {
33462
- "interactiveSeq" === this.json.ctn.nodeType && this.json.nextCondLst.forEach((t2) => {
33463
- if (/^shape/.test(t2.event)) {
33464
- const e2 = t2.event.split(" ")[1];
33465
- if (e2) {
33466
- const t3 = this.ctx.timingTargets.getTargetById(e2);
33467
- if (t3) {
33468
- t3.interactiveContainer.interactive = true, t3.interactiveContainer.cursor = "pointer";
33469
- const i2 = () => {
33470
- this.ctx.eventHub.emit(tb.userInput);
33471
- const t4 = `shape ${e2} onClick`, { mode: i3 } = this.ctx;
33472
- "interactive" !== i3 && "sync" !== i3 || this.ctx.eventHub.emit(tb.interactiveSeqAction, { action: t4, seqId: this.json.ctn.id }), "sync" !== i3 && "local" !== i3 || this.globalEventHub.emit(t4);
33473
- };
33474
- t3.interactiveContainer.on("pointerdown", i2), this.interactiveListeners.push([t3, i2]);
33479
+ if ("interactiveSeq" === this.json.ctn.nodeType) {
33480
+ const t2 = (this.json.ctn.stCondLst || []).filter((t3) => /^shape \S+ onClick$/.test(t3.event)), e2 = /* @__PURE__ */ new Set();
33481
+ [...this.json.nextCondLst, ...t2].forEach((t3) => {
33482
+ if (/^shape/.test(t3.event)) {
33483
+ const i2 = t3.event.split(" ")[1];
33484
+ if (i2 && !e2.has(i2)) {
33485
+ const t4 = this.ctx.timingTargets.getTargetById(i2);
33486
+ if (t4) {
33487
+ e2.add(i2), t4.interactiveContainer.interactive = true, t4.interactiveContainer.cursor = "pointer";
33488
+ const n2 = () => {
33489
+ this.ctx.eventHub.emit(tb.userInput);
33490
+ const t5 = `shape ${i2} onClick`, { mode: e3 } = this.ctx;
33491
+ "interactive" !== e3 && "sync" !== e3 || this.ctx.eventHub.emit(tb.interactiveSeqAction, { action: t5, seqId: this.json.ctn.id }), "sync" !== e3 && "local" !== e3 || this.globalEventHub.emit(t5);
33492
+ };
33493
+ t4.interactiveContainer.on("pointerdown", n2), this.interactiveListeners.push([t4, n2]);
33494
+ }
33475
33495
  }
33476
33496
  }
33477
- }
33478
- });
33497
+ });
33498
+ }
33479
33499
  }
33480
33500
  setCurrentStep(t2, e2) {
33481
33501
  const { length: i2 } = this.commonTimeNode.children;
@@ -34639,19 +34659,28 @@ void main(void){
34639
34659
  }(t2, r2, n2);
34640
34660
  if (e2)
34641
34661
  if (void 0 !== i2) {
34642
- if (t2.clippedDuration <= 0 && t2.isReadyForUserGesture && (yield t2.play(), !o2()))
34662
+ const e3 = (t3) => {
34663
+ const e4 = () => !o2() || t3();
34664
+ return n2 ? n2.waitUntil(e4, 5e3, 16) : Lm(e4, 5e3);
34665
+ };
34666
+ if (yield e3(() => t2.clippedDuration > 0 || !!t2.isReadyForUserGesture), !o2())
34643
34667
  return;
34644
- if (n2 ? yield n2.waitUntil(() => t2.clippedDuration > 0, 5e3, 16) : yield Lm(() => t2.clippedDuration > 0, 5e3), !o2())
34668
+ if (t2.clippedDuration <= 0 && t2.isReadyForUserGesture) {
34669
+ if (yield t2.play(), !o2())
34670
+ return;
34671
+ yield e3(() => t2.clippedDuration > 0);
34672
+ }
34673
+ if (!o2())
34645
34674
  return;
34646
34675
  if (i2 < t2.clippedDuration)
34647
34676
  if (t2.isPlaying)
34648
34677
  yield t2.seek(i2);
34649
34678
  else {
34650
- const e3 = () => {
34679
+ const e4 = () => {
34651
34680
  tx.delete(t2), o2() && Promise.resolve(t2.seek(i2)).catch(() => {
34652
34681
  });
34653
34682
  };
34654
- tx.set(t2, e3), t2.once("play", e3), yield t2.play(), o2() || nx(t2);
34683
+ tx.set(t2, e4), t2.once("play", e4), yield t2.play(), o2() || nx(t2);
34655
34684
  }
34656
34685
  } else
34657
34686
  yield t2.play();
@@ -38731,19 +38760,12 @@ geometry=${JSON.stringify(o2)}`;
38731
38760
  }
38732
38761
  };
38733
38762
  }
38734
- return t2.prototype.getRunningTask = function() {
38735
- var t3;
38736
- return null !== (t3 = this.runningTask) && void 0 !== t3 ? t3 : null;
38737
- }, t2.prototype.addTask = function(t3, e2) {
38763
+ return t2.prototype.addTask = function(t3, e2) {
38764
+ var i2;
38738
38765
  if (this.isDestroy)
38739
38766
  return Promise.resolve();
38740
- var i2 = this.getRunningTask();
38741
- if (i2 && t3 === i2.type)
38742
- return i2.promise;
38743
- var n2, r2, o2 = this.tasks.find(function(e3) {
38744
- return e3.type === t3;
38745
- });
38746
- if (o2)
38767
+ var n2, r2, o2 = null !== (i2 = this.tasks[this.tasks.length - 1]) && void 0 !== i2 ? i2 : this.runningTask;
38768
+ if ((null == o2 ? void 0 : o2.type) === t3)
38747
38769
  return o2.promise;
38748
38770
  var s2 = new Promise(function(t4, e3) {
38749
38771
  n2 = t4, r2 = e3;
@@ -39439,7 +39461,7 @@ geometry=${JSON.stringify(o2)}`;
39439
39461
  }
39440
39462
  var Nw = { 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", useraddLink: "useraddLink" }, Dw = { taskId: "", url: "", currentSlideIndex: -1, mainSeqStep: -1, mainSeqState: null, mediaState: /* @__PURE__ */ Object.create(null), interactiveSeqState: /* @__PURE__ */ Object.create(null) }, Fw = "";
39441
39463
  try {
39442
- Fw = "1.4.61-beta.0";
39464
+ Fw = "1.4.61";
39443
39465
  } catch (t2) {
39444
39466
  Fw = "-dev-";
39445
39467
  }
@@ -40220,25 +40242,25 @@ geometry=${JSON.stringify(o2)}`;
40220
40242
  }, e2.prototype._doRelease = function(t3) {
40221
40243
  var e3, i3;
40222
40244
  return Mw(this, void 0, void 0, function() {
40223
- var n2, r3, o2, s2;
40224
- return Cw(this, function(a2) {
40225
- switch (a2.label) {
40245
+ var n2, r3, o2, s2, a2;
40246
+ return Cw(this, function(l2) {
40247
+ switch (l2.label) {
40226
40248
  case 0:
40227
40249
  if (this.logger.info("do release slide", this.taskId), this.tracker({ name: "releaseSlide", reason: "", result: "", payload: { taskId: this.taskId } }), this.player)
40228
40250
  return [2];
40229
- this.isReleasing = true, a2.label = 1;
40251
+ this.isReleasing = true, l2.label = 1;
40230
40252
  case 1:
40231
- return a2.trys.push([1, , 5, 6]), [4, ww(eb.platform)];
40253
+ return l2.trys.push([1, , 5, 6]), [4, ww(eb.platform)];
40232
40254
  case 2:
40233
- if (a2.sent(), "alive" !== this.lifecycle || this.player)
40255
+ if (l2.sent(), "alive" !== this.lifecycle || this.player)
40234
40256
  return [2];
40235
- for (r3 in this.player = this.initPlayer(this.config), (null === (e3 = this.config) || void 0 === e3 ? void 0 : e3.controller) && this.createController(), this.player.view && (this.canvasContainer.appendChild(this.player.view), this.player.view.style.visibility = "hidden"), n2 = this.__slideState, this.__slideState = hb()(Dw), n2.mediaState)
40236
- "play" === (o2 = n2.mediaState[r3]).type && (s2 = Math.max(null !== (i3 = o2.frozenTime) && void 0 !== i3 ? i3 : 0, o2.time), o2.time = this.timestamp() - (s2 - o2.time), o2.frozenTime = void 0);
40237
- return [4, this.setSlideState(n2)];
40257
+ for (o2 in n2 = this.player = this.initPlayer(this.config), (null === (e3 = this.config) || void 0 === e3 ? void 0 : e3.controller) && this.createController(), this.player.view && (this.canvasContainer.appendChild(this.player.view), this.player.view.style.visibility = "hidden"), r3 = this.__slideState, this.__slideState = hb()(Dw), r3.mediaState)
40258
+ "play" === (s2 = r3.mediaState[o2]).type && (a2 = Math.max(null !== (i3 = s2.frozenTime) && void 0 !== i3 ? i3 : 0, s2.time), s2.time = this.timestamp() - (a2 - s2.time), s2.frozenTime = void 0);
40259
+ return [4, this.setSlideState(r3)];
40238
40260
  case 3:
40239
- return a2.sent(), [4, this.player.clock.delay(333)];
40261
+ return l2.sent(), "alive" !== this.lifecycle || this.player !== n2 ? [2] : [4, Ow(333)];
40240
40262
  case 4:
40241
- return a2.sent(), this.player.view && (this.player.view.style.visibility = "visible"), "hidden" === this.frame.style.visibility && (this.frame.style.visibility = "visible"), this.cacheImage.style.display = "none", t3 && t3(), [3, 6];
40263
+ return l2.sent(), "alive" !== this.lifecycle || this.player !== n2 ? [2] : (n2.view && (n2.view.style.visibility = "visible"), "hidden" === this.frame.style.visibility && (this.frame.style.visibility = "visible"), this.cacheImage.style.display = "none", t3 && t3(), [3, 6]);
40242
40264
  case 5:
40243
40265
  return this.isReleasing = false, this.notifyPptMediaPermissionRequest(), [7];
40244
40266
  case 6:
@@ -40301,7 +40323,7 @@ geometry=${JSON.stringify(o2)}`;
40301
40323
  return this.player ? this.player.preloadResource(t3) : Promise.resolve();
40302
40324
  }, e2.prototype.destroy = function() {
40303
40325
  var t3, e3 = this;
40304
- return "disposed" === this.lifecycle ? Promise.resolve() : (this.destroyPromise || (this.lifecycle = "disposing", this.lifecycleGeneration += 1, this.renderVisibilityTimers.forEach(function(t4) {
40326
+ return this.destroyPromise ? this.destroyPromise : "disposed" === this.lifecycle ? Promise.resolve() : (this.lifecycle = "disposing", this.lifecycleGeneration += 1, this.renderVisibilityTimers.forEach(function(t4) {
40305
40327
  return clearTimeout(t4);
40306
40328
  }), this.renderVisibilityTimers.clear(), this.renderingTaskManager.destroy(), null === (t3 = this.player) || void 0 === t3 || t3.destroy(), this.logger.info("pre destroy slide", ""), this.destroyPromise = Mw(e3, void 0, void 0, function() {
40307
40329
  var t4;
@@ -40321,7 +40343,7 @@ geometry=${JSON.stringify(o2)}`;
40321
40343
  return [2];
40322
40344
  }
40323
40345
  });
40324
- })), this.destroyPromise);
40346
+ }), this.destroyPromise);
40325
40347
  }, e2.prototype.clearSlideCache = function() {
40326
40348
  var t3;
40327
40349
  null === (t3 = this.player) || void 0 === t3 || t3.clearLocalCache();
@@ -41087,6 +41109,32 @@ function cachedGetBgColor(el) {
41087
41109
  const getRoomTracker = (displayer) => {
41088
41110
  return displayer.tracker;
41089
41111
  };
41112
+ function shouldSlideRuntimeBeActive(isFocused, isVisible, isMinimized) {
41113
+ return isFocused && isVisible && !isMinimized;
41114
+ }
41115
+ function createFocusTransitionQueue(initialState, apply, onError) {
41116
+ let acceptedState = initialState;
41117
+ let revision = 0;
41118
+ let queue = Promise.resolve();
41119
+ let acceptedPromise = Promise.resolve();
41120
+ return (isFocused, force = false) => {
41121
+ if (!force && isFocused === acceptedState)
41122
+ return acceptedPromise;
41123
+ acceptedState = isFocused;
41124
+ const transitionRevision = ++revision;
41125
+ const transition = queue.then(() => apply(isFocused)).catch((error) => {
41126
+ if (revision === transitionRevision) {
41127
+ acceptedState = void 0;
41128
+ acceptedPromise = Promise.resolve();
41129
+ }
41130
+ onError == null ? void 0 : onError(error);
41131
+ throw error;
41132
+ });
41133
+ queue = transition.catch(() => void 0);
41134
+ acceptedPromise = transition;
41135
+ return transition;
41136
+ };
41137
+ }
41090
41138
  function createDocsViewerPages(slide, previewUrls = []) {
41091
41139
  const { width, height, slideCount, slideState } = slide;
41092
41140
  const { taskId, url } = slideState;
@@ -41144,6 +41192,7 @@ const noop$1 = function noop2() {
41144
41192
  class SlideControllerBase {
41145
41193
  constructor(props) {
41146
41194
  this.sideEffect = new SideEffectManager();
41195
+ this.focused = true;
41147
41196
  this.previewList = [];
41148
41197
  this.ready = false;
41149
41198
  this.readyPromise = new Promise((resolve) => {
@@ -41152,7 +41201,11 @@ class SlideControllerBase {
41152
41201
  log("[Slide] render end", slideIndex);
41153
41202
  } else {
41154
41203
  setTimeout(() => {
41204
+ if (this.destroyed)
41205
+ return;
41155
41206
  this.ready = true;
41207
+ if (this.isLazySetupMode())
41208
+ void this.reconcileActivity(true).catch(() => void 0);
41156
41209
  resolve();
41157
41210
  }, 1e3);
41158
41211
  }
@@ -41185,6 +41238,10 @@ class SlideControllerBase {
41185
41238
  this.pollCount = 0;
41186
41239
  this.pollReadyState = () => {
41187
41240
  if (this.ready) {
41241
+ if (this.isLazySetupMode()) {
41242
+ void this.reconcileActivity().catch(() => void 0);
41243
+ return;
41244
+ }
41188
41245
  if (this._toFreeze === 1) {
41189
41246
  this.freeze();
41190
41247
  } else if (this._toFreeze === -1) {
@@ -41210,48 +41267,108 @@ class SlideControllerBase {
41210
41267
  }
41211
41268
  };
41212
41269
  this.isFrozen = false;
41270
+ this.resourceStateUnknown = false;
41271
+ this.managedActivity = false;
41213
41272
  this._toFreeze = 0;
41214
- this.freeze = () => {
41273
+ this.setFocusedState = (focused) => {
41274
+ this.focused = focused;
41275
+ return this.reconcileActivity();
41276
+ };
41277
+ this.resourceTransition = createFocusTransitionQueue(
41278
+ void 0,
41279
+ async (active) => {
41280
+ if (this.destroyed)
41281
+ return;
41282
+ if (active && this.shouldBeActive())
41283
+ await this.unfreeze();
41284
+ else
41285
+ await this.freeze();
41286
+ },
41287
+ (error) => logger.warn("[Slide] resource transition failed", this.context.appId, error)
41288
+ );
41289
+ this.shouldBeActive = () => {
41290
+ var _a, _b, _c;
41291
+ const wm = this.context.getWindowManager();
41292
+ const host = (_b = (_a = this.context).getRuntimeActivity) == null ? void 0 : _b.call(_a);
41293
+ const lazy = this.isLazySetupMode();
41294
+ const minimized = lazy && host ? !host.active : (wm == null ? void 0 : wm.boxState) === "minimized" || ((_c = wm == null ? void 0 : wm.attributes) == null ? void 0 : _c.minimized) === true || this.context.getBoxStatus() === "minimized";
41295
+ return shouldSlideRuntimeBeActive(
41296
+ !lazy || this.focused,
41297
+ document.visibilityState !== "hidden",
41298
+ minimized
41299
+ ) && (!lazy || (host == null ? void 0 : host.active) !== false);
41300
+ };
41301
+ this.reconcileActivity = (force = false) => {
41302
+ if (this.destroyed)
41303
+ return Promise.resolve();
41304
+ if (this.isLazySetupMode())
41305
+ this.managedActivity = true;
41306
+ if (!this.managedActivity)
41307
+ return Promise.resolve();
41308
+ this.visible = document.visibilityState !== "hidden";
41309
+ return this.resourceTransition(this.shouldBeActive(), force);
41310
+ };
41311
+ this.freeze = async () => {
41312
+ const previousIsFrozen = this.isFrozen;
41313
+ const previousToFreeze = this._toFreeze;
41215
41314
  this.isFrozen = true;
41216
- if (this.ready) {
41217
- log("[Slide] freeze", this.context.appId);
41218
- if (this.invisibleBehavior === "frozen") {
41219
- return Promise.resolve(this.slide.frozen());
41315
+ try {
41316
+ if (this.ready) {
41317
+ log("[Slide] freeze", this.context.appId);
41318
+ if (this.invisibleBehavior === "frozen") {
41319
+ await this.slide.frozen();
41320
+ } else {
41321
+ this.slide.pause();
41322
+ }
41220
41323
  } else {
41221
- this.slide.pause();
41324
+ this._toFreeze = 1;
41222
41325
  }
41223
- } else {
41224
- this._toFreeze = 1;
41326
+ this.resourceStateUnknown = false;
41327
+ } catch (error) {
41328
+ this.resourceStateUnknown = true;
41329
+ this.isFrozen = previousIsFrozen;
41330
+ this._toFreeze = previousToFreeze;
41331
+ throw error;
41225
41332
  }
41226
- return Promise.resolve();
41227
41333
  };
41228
41334
  this.unfreeze = async () => {
41229
41335
  if (!this.visible)
41230
41336
  return;
41231
- if (!this.isFrozen && this.ready)
41337
+ if (!this.isFrozen && this.ready && !this.resourceStateUnknown)
41232
41338
  return;
41339
+ const previousIsFrozen = this.isFrozen;
41340
+ const previousToFreeze = this._toFreeze;
41233
41341
  this.isFrozen = false;
41234
- if (this.ready) {
41235
- let isNeedSyncState = false;
41236
- log("[Slide] unfreeze", this.context.appId);
41237
- if (this.invisibleBehavior === "frozen") {
41238
- await this.slide.release(() => {
41342
+ try {
41343
+ if (this.ready) {
41344
+ let isNeedSyncState = false;
41345
+ log("[Slide] unfreeze", this.context.appId);
41346
+ if (this.invisibleBehavior === "frozen") {
41347
+ await this.slide.release(() => {
41348
+ if (!this.isLazySetupMode() || this.shouldBeActive())
41349
+ this.slide.notifyFrameResize();
41350
+ });
41351
+ isNeedSyncState = true;
41352
+ } else {
41353
+ this.slide.resume();
41239
41354
  this.slide.notifyFrameResize();
41240
- });
41241
- isNeedSyncState = true;
41242
- } else {
41243
- this.slide.resume();
41244
- this.slide.notifyFrameResize();
41245
- }
41246
- if (isNeedSyncState) {
41247
- const state = this.context.storage.state.state;
41248
- if (state) {
41249
- log("[Slide] sync storage", JSON.stringify(state));
41250
- this.slide.setSlideState(state);
41251
41355
  }
41356
+ if (isNeedSyncState && (!this.isLazySetupMode() || this.shouldBeActive())) {
41357
+ const state = this.context.storage.state.state;
41358
+ if (state) {
41359
+ log("[Slide] sync storage", JSON.stringify(state));
41360
+ await this.slide.setSlideState(state);
41361
+ }
41362
+ }
41363
+ } else {
41364
+ this._toFreeze = -1;
41252
41365
  }
41253
- } else {
41254
- this._toFreeze = -1;
41366
+ this.resourceStateUnknown = false;
41367
+ } catch (error) {
41368
+ this.resourceStateUnknown = true;
41369
+ this.isFrozen = previousIsFrozen;
41370
+ this._toFreeze = previousToFreeze;
41371
+ throw error;
41255
41372
  }
41256
41373
  };
41257
41374
  this.bindAppStateChangeEvent = () => {
@@ -41275,6 +41392,10 @@ class SlideControllerBase {
41275
41392
  }
41276
41393
  };
41277
41394
  this.onAppStateChangeHandler = (state) => {
41395
+ if (this.isLazySetupMode() || this.managedActivity) {
41396
+ void this.reconcileActivity().catch(() => void 0);
41397
+ return;
41398
+ }
41278
41399
  if (state === "minimized") {
41279
41400
  log("[Slide] freeze because app state is minimized");
41280
41401
  this.freeze();
@@ -41282,6 +41403,10 @@ class SlideControllerBase {
41282
41403
  };
41283
41404
  this.onAppStatusChangeHandler = (payload) => {
41284
41405
  const { appId, status } = payload;
41406
+ if (appId === this.context.appId && (this.isLazySetupMode() || this.managedActivity)) {
41407
+ void this.reconcileActivity().catch(() => void 0);
41408
+ return;
41409
+ }
41285
41410
  if (appId === this.context.appId && status === "minimized") {
41286
41411
  log("[Slide] freeze because app status is minimized");
41287
41412
  this.freeze();
@@ -41300,21 +41425,35 @@ class SlideControllerBase {
41300
41425
  return void 0;
41301
41426
  }
41302
41427
  };
41428
+ this.isLazySetupMode = () => {
41429
+ var _a;
41430
+ try {
41431
+ return ((_a = this.context.getWindowManager()) == null ? void 0 : _a.lazySetupInMaximizedMode) === true;
41432
+ } catch {
41433
+ return false;
41434
+ }
41435
+ };
41303
41436
  this.onVisibilityChange = async () => {
41437
+ this.visible = document.visibilityState === "visible";
41438
+ if (this.isLazySetupMode() || this.managedActivity) {
41439
+ await this.reconcileActivity().catch(() => void 0);
41440
+ return;
41441
+ }
41304
41442
  const appStatus = this.getAppStatus();
41443
+ if (!this.visible) {
41444
+ this.savedIsFrozen = this.isFrozen;
41445
+ log("[Slide] freeze because tab becomes invisible");
41446
+ if (!this.isFrozen)
41447
+ await this.freeze();
41448
+ return;
41449
+ }
41305
41450
  if (appStatus === "minimized") {
41306
41451
  log("[Slide] do nothing because app state is minimized");
41307
41452
  return;
41308
41453
  }
41309
- if (!(this.visible = document.visibilityState === "visible")) {
41310
- this.savedIsFrozen = this.isFrozen;
41311
- log("[Slide] freeze because tab becomes invisible");
41312
- this.freeze();
41313
- } else {
41314
- if (!this.savedIsFrozen) {
41315
- log("[Slide] unfreeze because tab becomes visible", { savedIsFrozen: this.savedIsFrozen });
41316
- this.unfreeze();
41317
- }
41454
+ if (!this.savedIsFrozen) {
41455
+ log("[Slide] unfreeze because tab becomes visible", { savedIsFrozen: this.savedIsFrozen });
41456
+ await this.unfreeze();
41318
41457
  }
41319
41458
  };
41320
41459
  const {
@@ -42936,6 +43075,18 @@ class ResizableContainer {
42936
43075
  (_a = this.scrollBar) == null ? void 0 : _a.destroy();
42937
43076
  }
42938
43077
  }
43078
+ function resolveNavigationButtonMode(mode) {
43079
+ return mode != null ? mode : "page";
43080
+ }
43081
+ function navigateWithNavigationButton(mode, origin, currentPageIndex, targetPageIndex, controller, onNavigate) {
43082
+ if (mode === "step" && origin === "navigation") {
43083
+ const action = targetPageIndex < currentPageIndex ? "prevStep" : "nextStep";
43084
+ controller.slide[action]();
43085
+ onNavigate(controller.page, origin);
43086
+ return;
43087
+ }
43088
+ controller.jumpToPage(targetPageIndex + 1, origin);
43089
+ }
42939
43090
  var resizeObservers = [];
42940
43091
  var hasActiveObservations = function() {
42941
43092
  return resizeObservers.some(function(ro) {
@@ -43466,6 +43617,7 @@ class SlideDocsViewer {
43466
43617
  appId,
43467
43618
  urlInterrupter,
43468
43619
  enableScale,
43620
+ navigationButtonMode,
43469
43621
  onPagesReady,
43470
43622
  onNavigate
43471
43623
  }) {
@@ -43598,7 +43750,14 @@ class SlideDocsViewer {
43598
43750
  };
43599
43751
  this.onNewPageIndex = (index, origin) => {
43600
43752
  if (this.slideController) {
43601
- this.slideController.jumpToPage(index + 1, origin);
43753
+ navigateWithNavigationButton(
43754
+ this.navigationButtonMode,
43755
+ origin,
43756
+ this.viewer.pageIndex,
43757
+ index,
43758
+ this.slideController,
43759
+ this.onNavigate
43760
+ );
43602
43761
  }
43603
43762
  };
43604
43763
  this.sideEffect = new SideEffectManager();
@@ -43685,6 +43844,7 @@ class SlideDocsViewer {
43685
43844
  this.onNavigate = onNavigate || noop;
43686
43845
  this.baseScenePath = baseScenePath;
43687
43846
  this.enableScale = enableScale != null ? enableScale : false;
43847
+ this.navigationButtonMode = resolveNavigationButtonMode(navigationButtonMode);
43688
43848
  this.appId = appId;
43689
43849
  this.viewer = new DocsViewer({
43690
43850
  readonly: box.readonly,
@@ -43845,6 +44005,7 @@ class SlideDocsViewer {
43845
44005
  }
43846
44006
  mount() {
43847
44007
  var _a, _b, _c, _d;
44008
+ this.unmountPromise = void 0;
43848
44009
  this.box.mountContent(this.viewer.$content);
43849
44010
  this.box.mountFooter(this.viewer.$footer);
43850
44011
  this.slideController = this.mountSlideController({
@@ -43900,28 +44061,38 @@ class SlideDocsViewer {
43900
44061
  getPageIndex(page) {
43901
44062
  return (page > 0 ? page : 1) - 1;
43902
44063
  }
43903
- async unmount() {
43904
- var _a, _b;
43905
- (_a = this.offBoxSizeChange) == null ? void 0 : _a.call(this);
43906
- this.offBoxSizeChange = void 0;
43907
- (_b = this.contentResizeObserver) == null ? void 0 : _b.disconnect();
43908
- this.contentResizeObserver = void 0;
43909
- if (this.slideController) {
43910
- const controller = this.slideController;
43911
- this.slideController = null;
43912
- await controller.destroy();
43913
- }
43914
- this.viewer.unmount();
43915
- this.resizableContainer.destroy(this.box);
43916
- return this;
44064
+ unmount() {
44065
+ if (!this.unmountPromise) {
44066
+ this.unmountPromise = Promise.resolve().then(async () => {
44067
+ var _a, _b;
44068
+ (_a = this.offBoxSizeChange) == null ? void 0 : _a.call(this);
44069
+ this.offBoxSizeChange = void 0;
44070
+ (_b = this.contentResizeObserver) == null ? void 0 : _b.disconnect();
44071
+ this.contentResizeObserver = void 0;
44072
+ if (this.slideController) {
44073
+ const controller = this.slideController;
44074
+ this.slideController = null;
44075
+ await controller.destroy();
44076
+ }
44077
+ this.viewer.unmount();
44078
+ this.resizableContainer.destroy(this.box);
44079
+ return this;
44080
+ });
44081
+ }
44082
+ return this.unmountPromise;
43917
44083
  }
43918
44084
  setReadonly(readonly) {
43919
44085
  this.viewer.setReadonly(readonly);
43920
44086
  }
43921
- async destroy() {
43922
- this.sideEffect.flushAll();
43923
- await this.unmount();
43924
- this.viewer.destroy();
44087
+ destroy() {
44088
+ if (!this.destroyPromise) {
44089
+ this.destroyPromise = Promise.resolve().then(async () => {
44090
+ this.sideEffect.flushAll();
44091
+ await this.unmount();
44092
+ this.viewer.destroy();
44093
+ });
44094
+ }
44095
+ return this.destroyPromise;
43925
44096
  }
43926
44097
  toggleClickThrough(tool) {
43927
44098
  this.$whiteboardView.style.pointerEvents = !tool || ClickThroughAppliances.has(tool) ? "none" : "auto";
@@ -44211,12 +44382,12 @@ class SlidePreviewer {
44211
44382
  }
44212
44383
  }
44213
44384
  const usePlugin = /* @__PURE__ */ Slide.Slide.usePlugin.bind(Slide.Slide);
44214
- const version = "0.2.106-beta.1";
44385
+ const version = "0.2.106-beta.3";
44215
44386
  const DEFAULT_SLIDE_SETUP_READY_TIMEOUT = 5e3;
44216
44387
  const SlideApp = {
44217
44388
  kind: "Slide",
44218
44389
  setup(context) {
44219
- var _a, _b, _c, _d, _e, _f;
44390
+ var _a, _b, _c, _d, _e, _f, _g;
44220
44391
  console.log("[Slide] setup @ " + version);
44221
44392
  if (context.getIsWritable()) {
44222
44393
  context.storage.ensureState(EmptyAttributes);
@@ -44305,6 +44476,7 @@ const SlideApp = {
44305
44476
  appId: context.appId,
44306
44477
  urlInterrupter: (_a = context.getAppOptions()) == null ? void 0 : _a.urlInterrupter,
44307
44478
  enableScale: (_c = (_b = context.getAppOptions()) == null ? void 0 : _b.enableScale) != null ? _c : false,
44479
+ navigationButtonMode: (_d = context.getAppOptions()) == null ? void 0 : _d.navigationButtonMode,
44308
44480
  onPagesReady: ({ length }) => {
44309
44481
  const index = (docsViewer == null ? void 0 : docsViewer.viewer.pageIndex) || 0;
44310
44482
  context.dispatchAppEvent("pageStateChange", { index, length });
@@ -44314,8 +44486,8 @@ const SlideApp = {
44314
44486
  }
44315
44487
  });
44316
44488
  const appOptions = context.getAppOptions();
44317
- docsViewer.setSyncEventQueuePolicy((_d = appOptions == null ? void 0 : appOptions.syncEventQueuePolicy) != null ? _d : "fifo");
44318
- docsViewer.setJustSildeReadonly((_e = appOptions == null ? void 0 : appOptions.justSildeReadonly) != null ? _e : false);
44489
+ docsViewer.setSyncEventQueuePolicy((_e = appOptions == null ? void 0 : appOptions.syncEventQueuePolicy) != null ? _e : "fifo");
44490
+ docsViewer.setJustSildeReadonly((_f = appOptions == null ? void 0 : appOptions.justSildeReadonly) != null ? _f : false);
44319
44491
  const room = context.getRoom();
44320
44492
  const sideEffect = new SideEffectManager();
44321
44493
  sideEffect.add(() => {
@@ -44337,56 +44509,43 @@ const SlideApp = {
44337
44509
  return () => room.callbacks.off("onRoomStateChanged", onRoomStateChanged);
44338
44510
  });
44339
44511
  }
44340
- const isBlurFreezeAllowed = () => {
44341
- var _a2;
44342
- const boxStatus = context.getBoxStatus();
44343
- if (boxStatus)
44344
- return boxStatus !== "normal";
44345
- const boxState = (_a2 = context.getWindowManager()) == null ? void 0 : _a2.boxState;
44346
- return boxState != null && boxState !== "normal";
44347
- };
44348
44512
  sideEffect.add(
44349
- () => context.emitter.on("focus", async (isFocused) => {
44513
+ () => context.emitter.on("focus", (isFocused) => {
44350
44514
  if (disposed)
44351
44515
  return;
44352
- if (!isLazySetupMode())
44353
- return;
44354
44516
  const controller = docsViewer == null ? void 0 : docsViewer.slideController;
44355
- if (!controller)
44356
- return;
44357
- if (!isFocused) {
44358
- if (!isBlurFreezeAllowed())
44359
- return;
44360
- if (!controller.isFrozen) {
44361
- log("[Slide] blur freeze", context.appId);
44362
- await controller.freeze();
44363
- }
44364
- return;
44365
- }
44366
- if (controller.isFrozen) {
44367
- log("[Slide] focus unfreeze", context.appId);
44368
- await controller.unfreeze();
44369
- }
44517
+ return controller == null ? void 0 : controller.setFocusedState(isFocused);
44518
+ })
44519
+ );
44520
+ sideEffect.add(
44521
+ () => context.emitter.on("runtimeActivity", () => {
44522
+ var _a2;
44523
+ if (!disposed)
44524
+ return (_a2 = docsViewer == null ? void 0 : docsViewer.slideController) == null ? void 0 : _a2.reconcileActivity();
44370
44525
  })
44371
44526
  );
44372
44527
  let disposed = false;
44373
44528
  let offDestroy;
44374
- const teardown = async () => {
44375
- if (disposed)
44376
- return;
44529
+ let teardownPromise;
44530
+ const teardown = () => {
44531
+ if (teardownPromise)
44532
+ return teardownPromise;
44377
44533
  disposed = true;
44378
- const removeDestroy = offDestroy;
44379
- offDestroy = void 0;
44380
- removeDestroy == null ? void 0 : removeDestroy();
44381
- log("[Slide] destroy", context.appId);
44382
- if (useFreezer)
44383
- apps.delete(context.appId);
44384
- sideEffect.flushAll();
44385
- if (docsViewer) {
44386
- const viewer = docsViewer;
44387
- docsViewer = null;
44388
- await viewer.destroy();
44389
- }
44534
+ teardownPromise = Promise.resolve().then(async () => {
44535
+ const removeDestroy = offDestroy;
44536
+ offDestroy = void 0;
44537
+ removeDestroy == null ? void 0 : removeDestroy();
44538
+ log("[Slide] destroy", context.appId);
44539
+ if (useFreezer)
44540
+ apps.delete(context.appId);
44541
+ sideEffect.flushAll();
44542
+ if (docsViewer) {
44543
+ const viewer = docsViewer;
44544
+ docsViewer = null;
44545
+ await viewer.destroy();
44546
+ }
44547
+ });
44548
+ return teardownPromise;
44390
44549
  };
44391
44550
  offDestroy = context.emitter.on("destroy", teardown);
44392
44551
  docsViewer.mount();
@@ -44394,6 +44553,7 @@ const SlideApp = {
44394
44553
  SlideApp.__teardownByContext.set(context, teardown);
44395
44554
  const waitForFirstRender = (timeoutMs) => new Promise((resolve) => {
44396
44555
  let settled = false;
44556
+ let timedOut = false;
44397
44557
  const settle = (loaded) => {
44398
44558
  if (settled)
44399
44559
  return;
@@ -44402,7 +44562,12 @@ const SlideApp = {
44402
44562
  window.clearInterval(pollTimer);
44403
44563
  resolve(loaded);
44404
44564
  };
44405
- const timeoutTimer = window.setTimeout(() => settle(false), timeoutMs);
44565
+ const timeoutTimer = window.setTimeout(() => {
44566
+ timedOut = true;
44567
+ logger.warn("[Slide] first render still pending", context.appId, timeoutMs);
44568
+ if (!context.waitForActualSetupReady)
44569
+ settle(false);
44570
+ }, timeoutMs);
44406
44571
  slideControllerRef == null ? void 0 : slideControllerRef.readyPromise.then(
44407
44572
  () => settle(!firstRenderFailed),
44408
44573
  () => settle(false)
@@ -44410,6 +44575,8 @@ const SlideApp = {
44410
44575
  const pollTimer = window.setInterval(() => {
44411
44576
  if (disposed || firstRenderFailed)
44412
44577
  settle(false);
44578
+ else if (timedOut && !context.waitForActualSetupReady)
44579
+ settle(false);
44413
44580
  }, 100);
44414
44581
  });
44415
44582
  const appResult = {
@@ -44544,8 +44711,10 @@ const SlideApp = {
44544
44711
  return false;
44545
44712
  }
44546
44713
  };
44547
- const setupReadyTimeout = (_f = appOptions == null ? void 0 : appOptions.setupReadyTimeout) != null ? _f : DEFAULT_SLIDE_SETUP_READY_TIMEOUT;
44714
+ const setupReadyTimeout = (_g = appOptions == null ? void 0 : appOptions.setupReadyTimeout) != null ? _g : DEFAULT_SLIDE_SETUP_READY_TIMEOUT;
44548
44715
  return waitForFirstRender(setupReadyTimeout).then(() => {
44716
+ if (disposed)
44717
+ throw new Error("[Slide] disposed before first render");
44549
44718
  if (firstRenderFailed) {
44550
44719
  throw new Error("[Slide] first render failed before ready");
44551
44720
  }