@netless/app-slide 0.2.105-beta.1 → 0.2.105-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/app-slide",
3
- "version": "0.2.105-beta.1",
3
+ "version": "0.2.105-beta.3",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -130,9 +130,6 @@ export class ResizableContainer {
130
130
  }
131
131
  }
132
132
 
133
- this.translateX = 0.5;
134
- this.translateY = 0.5;
135
-
136
133
  this.renderScrollBar(
137
134
  parentBounds.width,
138
135
  parentBounds.width * this.scale,
@@ -141,7 +138,8 @@ export class ResizableContainer {
141
138
  );
142
139
  this.handleNormalizeTranslate(this.translateX, this.translateY, {
143
140
  triggerScrollBar: true,
144
- triggerSync: true,
141
+ triggerSync: false,
142
+ force: true,
145
143
  });
146
144
 
147
145
  // enableScale / scaleView 只改变内部 container 的像素尺寸,box 本身不变。
@@ -158,12 +156,14 @@ export class ResizableContainer {
158
156
  options: {
159
157
  triggerScrollBar: boolean;
160
158
  triggerSync: boolean;
159
+ force?: boolean;
161
160
  }
162
161
  ) {
163
162
  if (
164
163
  Math.abs(x - this.translateX) < 0.001 &&
165
164
  Math.abs(y - this.translateY) < 0.001 &&
166
- !options.triggerSync
165
+ !options.triggerSync &&
166
+ !options.force
167
167
  ) {
168
168
  return;
169
169
  }
@@ -163,6 +163,13 @@ export class SlideDocsViewer {
163
163
  console.log("[SlideDocsViewer] No initial slideScale found");
164
164
  }
165
165
 
166
+ const initialTranslateX = this.context.storage.state.translateX ?? 0.5;
167
+ const initialTranslateY = this.context.storage.state.translateY ?? 0.5;
168
+ this.resizableContainer.handleNormalizeTranslate(initialTranslateX, initialTranslateY, {
169
+ triggerScrollBar: true,
170
+ triggerSync: false,
171
+ });
172
+
166
173
  const handler: StorageStateChangedListener<Attributes> = diff => {
167
174
  if (diff.slideScale !== undefined) {
168
175
  // slideScale 是一个包含 newValue 和 oldValue 的对象
package/src/index.ts CHANGED
@@ -202,6 +202,9 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> & {
202
202
  (window as any).slideController = slideController;
203
203
  }
204
204
  slideController.readyPromise.then(options.onReady).then(() => {
205
+ // Teardown may have destroyed the box while this deferred callback
206
+ // was pending; syncing scenes against a destroyed app throws.
207
+ if (disposed) return;
205
208
  const room = context.getRoom();
206
209
  let synced = false;
207
210
  if (room && context.getIsWritable()) {
@@ -266,6 +269,46 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> & {
266
269
  });
267
270
  }
268
271
 
272
+ // Blur freeze (same semantics as the Presentation blur thumbnail
273
+ // degradation): while the app is cached and loses focus in a
274
+ // maximized/minimized workspace, freeze the slide (destroy the player,
275
+ // keep a snapshot); on focus, unfreeze. Freezing is skipped in normal
276
+ // mode where several windows are visible side by side. The whole flow is
277
+ // a lazy-mode-only cache optimization: inactive unless the WindowManager
278
+ // runs with lazySetupInMaximizedMode enabled (read dynamically — lazy can
279
+ // be disabled at runtime, e.g. when forceMaximized is cleared).
280
+ const isLazySetupMode = (): boolean =>
281
+ (context.getWindowManager() as any)?.lazySetupInMaximizedMode === true;
282
+ const isBlurFreezeAllowed = (): boolean => {
283
+ const boxStatus = context.getBoxStatus();
284
+ if (boxStatus) return boxStatus !== "normal";
285
+ const boxState = context.getWindowManager()?.boxState;
286
+ return boxState != null && boxState !== "normal";
287
+ };
288
+ sideEffect.add(
289
+ () =>
290
+ context.emitter.on("focus", (isFocused: boolean) => {
291
+ if (disposed) return;
292
+ if (!isLazySetupMode()) return;
293
+ const controller = docsViewer?.slideController;
294
+ if (!controller) return;
295
+ if (!isFocused) {
296
+ if (!isBlurFreezeAllowed()) return;
297
+ if (!controller.isFrozen) {
298
+ log("[Slide] blur freeze", context.appId);
299
+ controller.freeze();
300
+ }
301
+ return;
302
+ }
303
+ if (useFreezer) {
304
+ apps.focus(context.appId);
305
+ } else if (controller.isFrozen) {
306
+ log("[Slide] focus unfreeze", context.appId);
307
+ controller.unfreeze();
308
+ }
309
+ }),
310
+ );
311
+
269
312
  let disposed = false;
270
313
  let offDestroy: (() => void) | undefined;
271
314
  const teardown = () => {
@@ -333,6 +376,10 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> & {
333
376
  translateX: 0.5,
334
377
  translateY: 0.5,
335
378
  });
379
+ container.handleNormalizeTranslate(0.5, 0.5, {
380
+ triggerScrollBar: true,
381
+ triggerSync: false,
382
+ });
336
383
  container.scaleContainer(applyScale);
337
384
  },
338
385
  getViewScale: () => {