@netless/app-presentation 0.1.13-beta.3 → 0.1.13-beta.4

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.mjs CHANGED
@@ -2013,9 +2013,10 @@ var createPresentationRuntimeTeardown = (box, dispose2) => {
2013
2013
  };
2014
2014
 
2015
2015
  // src/setup-ready.ts
2016
- var waitForCurrentPageImage = (getImage, timeoutMs, isDisposed) => {
2016
+ var waitForCurrentPageImage = (getImage, timeoutMs, isDisposed, options) => {
2017
2017
  return new Promise((resolve) => {
2018
2018
  let settled = false;
2019
+ let timedOut = false;
2019
2020
  let pollTimer;
2020
2021
  const settle = (result) => {
2021
2022
  if (settled)
@@ -2026,13 +2027,22 @@ var waitForCurrentPageImage = (getImage, timeoutMs, isDisposed) => {
2026
2027
  window.clearInterval(pollTimer);
2027
2028
  resolve(result);
2028
2029
  };
2029
- const timeoutTimer = window.setTimeout(() => settle("timeout"), timeoutMs);
2030
+ const timeoutTimer = window.setTimeout(() => {
2031
+ timedOut = true;
2032
+ options == null ? void 0 : options.onTimeout();
2033
+ if (!(options == null ? void 0 : options.waitForReady()))
2034
+ settle("timeout");
2035
+ }, timeoutMs);
2030
2036
  const check = () => {
2031
2037
  var _a, _b;
2032
2038
  if (isDisposed()) {
2033
2039
  settle("disposed");
2034
2040
  return;
2035
2041
  }
2042
+ if (timedOut && !(options == null ? void 0 : options.waitForReady())) {
2043
+ settle("timeout");
2044
+ return;
2045
+ }
2036
2046
  const img = getImage();
2037
2047
  if (img == null ? void 0 : img.complete) {
2038
2048
  if (img.naturalWidth > 0) {
@@ -2107,6 +2117,19 @@ var setupBlurThumbnailDegradation = (config) => {
2107
2117
  const boxBlurClass = box.wrapClassName("blur");
2108
2118
  let blurEpisode = false;
2109
2119
  let reDegradeEnabled = false;
2120
+ let previewSuspended = false;
2121
+ let appliedFocusState = true;
2122
+ let logicalFocused = true;
2123
+ const activityBlocked = () => {
2124
+ var _a, _b;
2125
+ const wm = context.getWindowManager();
2126
+ if ((wm == null ? void 0 : wm.lazySetupInMaximizedMode) !== true)
2127
+ return false;
2128
+ const host = (_a = context.getRuntimeActivity) == null ? void 0 : _a.call(context);
2129
+ if (host)
2130
+ return document.visibilityState === "hidden" || !host.active;
2131
+ return document.visibilityState === "hidden" || wm.boxState === "minimized" || ((_b = wm.attributes) == null ? void 0 : _b.minimized) === true || context.getBoxStatus() === "minimized";
2132
+ };
2110
2133
  let boxBlurred = box.$box.classList.contains(boxBlurClass);
2111
2134
  const setBackgroundSuspended = (suspended) => {
2112
2135
  app.whiteboardDOM.classList.toggle(
@@ -2121,7 +2144,7 @@ var setupBlurThumbnailDegradation = (config) => {
2121
2144
  const thumbnailURL = page.thumbnail;
2122
2145
  const img = findBackgroundImage(view);
2123
2146
  if (!thumbnailURL || !hasUsableThumbnail(page)) {
2124
- if (boxBlurred) {
2147
+ if (boxBlurred || activityBlocked()) {
2125
2148
  setBackgroundSuspended(true);
2126
2149
  if (img && resolveImageUrl(img.src) !== resolveImageUrl(TRANSPARENT_BACKGROUND)) {
2127
2150
  img.src = TRANSPARENT_BACKGROUND;
@@ -2143,9 +2166,12 @@ var setupBlurThumbnailDegradation = (config) => {
2143
2166
  setBackgroundSuspended(false);
2144
2167
  };
2145
2168
  const suspendCachedResources = () => {
2146
- if (!blurEpisode || !boxBlurred)
2169
+ if (!blurEpisode || !boxBlurred && !activityBlocked())
2147
2170
  return;
2148
- app.suspendPreviewResources();
2171
+ if (!previewSuspended) {
2172
+ previewSuspended = true;
2173
+ app.suspendPreviewResources();
2174
+ }
2149
2175
  const page = pages[pageIndex$.value];
2150
2176
  if (!page || !hasUsableThumbnail(page) || reDegradeEnabled) {
2151
2177
  degrade();
@@ -2156,6 +2182,7 @@ var setupBlurThumbnailDegradation = (config) => {
2156
2182
  return;
2157
2183
  blurEpisode = false;
2158
2184
  reDegradeEnabled = false;
2185
+ previewSuspended = false;
2159
2186
  restore2();
2160
2187
  app.preload.resume(pageIndex$.value);
2161
2188
  };
@@ -2186,27 +2213,40 @@ var setupBlurThumbnailDegradation = (config) => {
2186
2213
  return;
2187
2214
  reDegradeEnabled = false;
2188
2215
  };
2189
- const offFocus = context.emitter.on("focus", (isFocused) => {
2216
+ const applyActivity = () => {
2217
+ var _a;
2218
+ const lazy = ((_a = context.getWindowManager()) == null ? void 0 : _a.lazySetupInMaximizedMode) === true;
2219
+ const isFocused = (!lazy || logicalFocused) && !activityBlocked();
2220
+ if (appliedFocusState === isFocused)
2221
+ return;
2222
+ if (!isFocused && !isBlurDegradationAllowed(context) && !activityBlocked())
2223
+ return;
2190
2224
  if (isFocused) {
2191
2225
  restoreFocusedResources();
2192
2226
  } else {
2193
- if (!isBlurDegradationAllowed(context))
2194
- return;
2195
2227
  blurEpisode = true;
2196
2228
  reDegradeEnabled = true;
2197
2229
  degrade();
2198
2230
  app.preload.pause();
2199
2231
  suspendCachedResources();
2200
2232
  }
2233
+ appliedFocusState = isFocused;
2234
+ };
2235
+ const offFocus = context.emitter.on("focus", (isFocused) => {
2236
+ logicalFocused = isFocused;
2237
+ applyActivity();
2201
2238
  });
2202
2239
  dispose2.add(offFocus);
2240
+ dispose2.add(context.emitter.on("runtimeActivity", applyActivity));
2241
+ document.addEventListener("visibilitychange", applyActivity);
2242
+ dispose2.add(() => document.removeEventListener("visibilitychange", applyActivity));
2203
2243
  const updateBoxBlurred = (blurred) => {
2204
2244
  if (boxBlurred === blurred)
2205
2245
  return;
2206
2246
  boxBlurred = blurred;
2207
2247
  if (blurred)
2208
2248
  suspendCachedResources();
2209
- else
2249
+ else if (logicalFocused && !activityBlocked())
2210
2250
  restoreFocusedResources();
2211
2251
  };
2212
2252
  const onBoxBlur = () => updateBoxBlurred(true);
@@ -2653,7 +2693,7 @@ var NetlessAppPresentation = {
2653
2693
  options.useClipView
2654
2694
  )
2655
2695
  );
2656
- app.contentDOM.dataset.appPresentationVersion = "0.1.13-beta.3";
2696
+ app.contentDOM.dataset.appPresentationVersion = "0.1.13-beta.4";
2657
2697
  app.scaleDocsToFit = scaleDocsToFit;
2658
2698
  app.log = log;
2659
2699
  app.warn = warn;
@@ -3125,11 +3165,18 @@ var NetlessAppPresentation = {
3125
3165
  const result = await waitForCurrentPageImage(
3126
3166
  () => findBackgroundImage(view),
3127
3167
  setupReadyTimeout,
3128
- () => disposed
3168
+ () => disposed,
3169
+ {
3170
+ waitForReady: () => Boolean(context.waitForActualSetupReady),
3171
+ onTimeout: () => warn(`[Presentation] setup page image still pending after ${setupReadyTimeout}ms`)
3172
+ }
3129
3173
  );
3130
- if (result === "timeout" && !disposed) {
3131
- warn(`[Presentation] setup ready wait timed out after ${setupReadyTimeout}ms`);
3132
- } else if (result === "error" && !disposed) {
3174
+ if (disposed)
3175
+ throw new Error("[Presentation] disposed before setup ready");
3176
+ if (result === "error" && context.waitForActualSetupReady) {
3177
+ throw new Error("[Presentation] setup page image failed to load");
3178
+ }
3179
+ if (result === "error" && !disposed) {
3133
3180
  warn("[Presentation] setup page image failed to load; continuing setup");
3134
3181
  }
3135
3182
  return controller;
@@ -3219,7 +3266,7 @@ var install = (register, options = {}) => {
3219
3266
  };
3220
3267
 
3221
3268
  // src/index.ts
3222
- var version = "0.1.13-beta.3";
3269
+ var version = "0.1.13-beta.4";
3223
3270
 
3224
3271
  export { NetlessAppPresentation, Presentation, Scrollbar, NetlessAppPresentation as default, install, setupBlurThumbnailDegradation, version };
3225
3272
  //# sourceMappingURL=index.mjs.map