@netless/app-presentation 0.1.11 → 0.1.13-beta.0

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.d.ts CHANGED
@@ -378,12 +378,9 @@ declare class Scrollbar {
378
378
  }
379
379
 
380
380
  type Logger = (...data: any[]) => void;
381
- declare const ORIGIN_SIZE_COORDINATE_VERSION = 2;
382
381
  interface PresentationAttributes {
383
382
  /** Shared logical camera reference size. New pages are proportionally contained within it. */
384
383
  originSize?: Size | null;
385
- /** Internal marker for scenes whose ppt size has been normalized to originSize. */
386
- _originSizeCoordinateVersion?: typeof ORIGIN_SIZE_COORDINATE_VERSION;
387
384
  }
388
385
  interface Viewport {
389
386
  readonly x: number;
@@ -472,8 +469,10 @@ interface PresentationController {
472
469
  /** screenshot the current page */
473
470
  screenshotCurrentPageAsync: (context: CanvasRenderingContext2D, width?: number, height?: number) => Promise<void>;
474
471
  }
475
- declare const NetlessAppPresentation: NetlessApp<PresentationAttributes, {}, PresentationAppOptions, PresentationController>;
476
- type RegisterFn = typeof WindowManager["register"];
472
+ declare const NetlessAppPresentation: NetlessApp<PresentationAttributes, {}, PresentationAppOptions, PresentationController> & {
473
+ teardown(context: AppContext): void;
474
+ };
475
+ type RegisterFn = (typeof WindowManager)["register"];
477
476
  interface InstallOptions {
478
477
  /**
479
478
  * Register as another "kind", to hijack existing apps.
@@ -1950,7 +1950,6 @@ var NetlessAppPresentation = (function (exports) {
1950
1950
  // src/app-presentation.ts
1951
1951
  var import_debounce2 = __toESM(require_debounce());
1952
1952
  var emptySceneName = "$$empty$$";
1953
- var ORIGIN_SIZE_COORDINATE_VERSION = 2;
1954
1953
  var ppt2page = (ppt, name, originSize) => {
1955
1954
  if (!ppt)
1956
1955
  return null;
@@ -1968,7 +1967,10 @@ var NetlessAppPresentation = (function (exports) {
1968
1967
  var _a;
1969
1968
  const createAppLogger = context.createLogger;
1970
1969
  if (typeof createAppLogger === "function") {
1971
- return createAppLogger.call(context, "camera", { debounceTime: 300, maxWaitTime: 2e3 });
1970
+ return createAppLogger.call(context, "camera", {
1971
+ debounceTime: 300,
1972
+ maxWaitTime: 2e3
1973
+ });
1972
1974
  }
1973
1975
  const roomLogger = (_a = context.getRoom()) == null ? void 0 : _a.logger;
1974
1976
  const prefix = `[Presentation][${context.appId}][camera]`;
@@ -2025,6 +2027,7 @@ var NetlessAppPresentation = (function (exports) {
2025
2027
  return scene.name === scene2.name && ((_a = scene.ppt) == null ? void 0 : _a.width) === ((_b = scene2.ppt) == null ? void 0 : _b.width) && ((_c = scene.ppt) == null ? void 0 : _c.height) === ((_d = scene2.ppt) == null ? void 0 : _d.height) && ((_e = scene.ppt) == null ? void 0 : _e.src) === ((_f = scene2.ppt) == null ? void 0 : _f.src);
2026
2028
  });
2027
2029
  };
2030
+ var teardownByContext = /* @__PURE__ */ new WeakMap();
2028
2031
  var NetlessAppPresentation = {
2029
2032
  kind: "Presentation",
2030
2033
  setup(context) {
@@ -2032,41 +2035,52 @@ var NetlessAppPresentation = (function (exports) {
2032
2035
  const diagnosticLogger = createDiagnosticLogger(context);
2033
2036
  const view = context.getView();
2034
2037
  if (!view)
2035
- throw new Error("[Presentation]: no whiteboard view, make sure you have added options.scenePath in addApp()");
2038
+ throw new Error(
2039
+ "[Presentation]: no whiteboard view, make sure you have added options.scenePath in addApp()"
2040
+ );
2036
2041
  const options = context.getAppOptions() || {};
2037
2042
  const room = context.getRoom();
2038
2043
  const log = options.log || createLogger(room);
2039
2044
  const roomLogger = room == null ? void 0 : room.logger;
2040
2045
  const warn = (...data) => (roomLogger == null ? void 0 : roomLogger.warn) ? roomLogger.warn(...data) : log(...data);
2041
2046
  const configuredOriginSize = context.storage.state.originSize;
2042
- const originSize = isValidSize(configuredOriginSize) ? { width: configuredOriginSize.width, height: configuredOriginSize.height } : void 0;
2047
+ const originSize = isValidSize(configuredOriginSize) ? {
2048
+ width: configuredOriginSize.width,
2049
+ height: configuredOriginSize.height
2050
+ } : void 0;
2043
2051
  if (configuredOriginSize != null && !originSize) {
2044
- warn(`[Presentation] originSize should contain finite positive width and height, got ${JSON.stringify(configuredOriginSize)}`);
2045
- }
2046
- const useOriginSizeCoordinates = Boolean(
2047
- originSize && (context.isAddApp || context.storage.state._originSizeCoordinateVersion === ORIGIN_SIZE_COORDINATE_VERSION)
2048
- );
2049
- if (originSize && context.isAddApp && context.getIsWritable()) {
2050
- context.storage.setState({
2051
- _originSizeCoordinateVersion: ORIGIN_SIZE_COORDINATE_VERSION
2052
- });
2052
+ warn(
2053
+ `[Presentation] originSize should contain finite positive width and height, got ${JSON.stringify(configuredOriginSize)}`
2054
+ );
2053
2055
  }
2054
- const pages = (_a = context.getScenes()) == null ? void 0 : _a.map(({ ppt, name }) => ppt2page(ppt, name, useOriginSizeCoordinates ? originSize : void 0)).filter(Boolean);
2056
+ const pages = (_a = context.getScenes()) == null ? void 0 : _a.map(({ ppt, name }) => ppt2page(ppt, name, originSize)).filter(Boolean);
2055
2057
  if (!pages || pages.length === 0)
2056
- throw new Error("[Presentation]: empty scenes, make sure you have added options.scenes in addApp()");
2058
+ throw new Error(
2059
+ "[Presentation]: empty scenes, make sure you have added options.scenes in addApp()"
2060
+ );
2057
2061
  if (pages[0].src.startsWith("ppt"))
2058
- throw new Error("[Presentation]: legacy dynamic PPT is unsupported, please use the projector converter and @netless/slide to render it");
2062
+ throw new Error(
2063
+ "[Presentation]: legacy dynamic PPT is unsupported, please use the projector converter and @netless/slide to render it"
2064
+ );
2059
2065
  const scenePath = context.getInitScenePath();
2060
2066
  let maxCameraScale = (_b = options.maxCameraScale) != null ? _b : 3;
2061
2067
  if (!(Number.isFinite(maxCameraScale) && maxCameraScale > 0)) {
2062
- warn(`[Presentation] maxCameraScale should be a positive number, got ${options.maxCameraScale}`);
2068
+ warn(
2069
+ `[Presentation] maxCameraScale should be a positive number, got ${options.maxCameraScale}`
2070
+ );
2063
2071
  maxCameraScale = 3;
2064
2072
  }
2065
2073
  log(`[Presentation] new ${context.appId}`);
2066
2074
  const dispose2 = disposableStore();
2067
2075
  dispose2.add(() => log(`[Presentation] dispose ${context.appId}`));
2068
2076
  dispose2.add(() => diagnosticLogger.flush());
2069
- const view$$ = context.createStorage("view", { uid: "", originX: 0, originY: 0, width: 0, height: 0 });
2077
+ const view$$ = context.createStorage("view", {
2078
+ uid: "",
2079
+ originX: 0,
2080
+ originY: 0,
2081
+ width: 0,
2082
+ height: 0
2083
+ });
2070
2084
  const _addScenePathListener = (name, listener) => {
2071
2085
  const windowManger = context.manager.windowManger;
2072
2086
  windowManger.emitter.on(name, listener);
@@ -2088,13 +2102,16 @@ var NetlessAppPresentation = (function (exports) {
2088
2102
  let pageIndex = getPageIndex(view);
2089
2103
  const pageIndex$ = readable(pageIndex, (set) => {
2090
2104
  set(pageIndex);
2091
- return _addScenePathListener("onAppScenePathChange", (payload) => {
2092
- const { appId } = payload;
2093
- if (appId === context.appId) {
2094
- const _pageIndex = getPageIndex(payload.view);
2095
- set(_pageIndex);
2105
+ return _addScenePathListener(
2106
+ "onAppScenePathChange",
2107
+ (payload) => {
2108
+ const { appId } = payload;
2109
+ if (appId === context.appId) {
2110
+ const _pageIndex = getPageIndex(payload.view);
2111
+ set(_pageIndex);
2112
+ }
2096
2113
  }
2097
- });
2114
+ );
2098
2115
  });
2099
2116
  dispose2.add(() => {
2100
2117
  pageIndex$.dispose();
@@ -2111,7 +2128,12 @@ var NetlessAppPresentation = (function (exports) {
2111
2128
  const p = pages[index];
2112
2129
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
2113
2130
  if (!scenes.some((scene) => scene.name === name)) {
2114
- await context.addPage({ scene: { name, ppt: { width: p.width, height: p.height, src: p.src } } });
2131
+ await context.addPage({
2132
+ scene: {
2133
+ name,
2134
+ ppt: { width: p.width, height: p.height, src: p.src }
2135
+ }
2136
+ });
2115
2137
  }
2116
2138
  if (logger) {
2117
2139
  logger.info(`[Presentation] syncPage ${scenePath}/${name}`);
@@ -2123,15 +2145,21 @@ var NetlessAppPresentation = (function (exports) {
2123
2145
  if (!context.isAddApp)
2124
2146
  return;
2125
2147
  if (pages.length > 100)
2126
- warn(`[Presentation]: too many pages (${pages.length}), may cause performance issues`);
2148
+ warn(
2149
+ `[Presentation]: too many pages (${pages.length}), may cause performance issues`
2150
+ );
2127
2151
  if (!room || !room.isWritable)
2128
2152
  return;
2129
2153
  if (pageIndex$.value < 0 || pageIndex$.value >= pages.length) {
2130
- throw new Error(`[Presentation] Invalid page index: ${pageIndex$.value}, scenes length: ${pages.length}`);
2154
+ throw new Error(
2155
+ `[Presentation] Invalid page index: ${pageIndex$.value}, scenes length: ${pages.length}`
2156
+ );
2131
2157
  }
2132
2158
  const scenes = room.entireScenes()[scenePath];
2133
2159
  if (!scenes || !scenes[pageIndex$.value]) {
2134
- throw new Error(`[Presentation]: no initial scene found at ${scenePath}, page index: ${pageIndex$.value}`);
2160
+ throw new Error(
2161
+ `[Presentation]: no initial scene found at ${scenePath}, page index: ${pageIndex$.value}`
2162
+ );
2135
2163
  }
2136
2164
  const { name, ppt } = scenes[pageIndex$.value];
2137
2165
  const nextScenes = pages.map((page, index) => {
@@ -2160,16 +2188,22 @@ var NetlessAppPresentation = (function (exports) {
2160
2188
  const prepareScenesPromise = prepareScenes();
2161
2189
  const canJumpPage = (index) => {
2162
2190
  if (!context.getIsWritable()) {
2163
- warn("[Presentation]: no permission, make sure you have test room.isWritable");
2191
+ warn(
2192
+ "[Presentation]: no permission, make sure you have test room.isWritable"
2193
+ );
2164
2194
  return false;
2165
2195
  }
2166
2196
  if (!(0 <= index && index < pages.length)) {
2167
- warn(`[Presentation]: page ${index + 1} out of bounds [1, ${pages.length}]`);
2197
+ warn(
2198
+ `[Presentation]: page ${index + 1} out of bounds [1, ${pages.length}]`
2199
+ );
2168
2200
  return false;
2169
2201
  }
2170
2202
  const scenes = context.getDisplayer().entireScenes()[scenePath];
2171
2203
  if (!scenes) {
2172
- warn(`[Presentation]: no scenes found at ${scenePath}, make sure you have added options.scenePath in addApp()`);
2204
+ warn(
2205
+ `[Presentation]: no scenes found at ${scenePath}, make sure you have added options.scenePath in addApp()`
2206
+ );
2173
2207
  return false;
2174
2208
  }
2175
2209
  return true;
@@ -2275,13 +2309,20 @@ var NetlessAppPresentation = (function (exports) {
2275
2309
  try {
2276
2310
  const { camera, size } = view;
2277
2311
  const referenceSize = getCameraReferenceSize(originSize, page);
2278
- const viewport = cameraToSharedViewport(camera, size, referenceSize);
2312
+ const viewport = cameraToSharedViewport(
2313
+ camera,
2314
+ size,
2315
+ referenceSize
2316
+ );
2279
2317
  if (viewport)
2280
2318
  view$$.setState(__spreadValues({ uid: me }, viewport));
2281
2319
  if (pendingMoveCameraRequest) {
2282
2320
  diagnosticLogger.debouncedInfo(
2283
2321
  "moveCamera",
2284
- getCameraDiagnosticState("moveCamera", pendingMoveCameraRequest)
2322
+ getCameraDiagnosticState(
2323
+ "moveCamera",
2324
+ pendingMoveCameraRequest
2325
+ )
2285
2326
  );
2286
2327
  pendingMoveCameraRequest = void 0;
2287
2328
  }
@@ -2289,7 +2330,10 @@ var NetlessAppPresentation = (function (exports) {
2289
2330
  diagnosticLogger.error(
2290
2331
  "syncView.failed",
2291
2332
  error,
2292
- getCameraDiagnosticState("moveCamera", pendingMoveCameraRequest)
2333
+ getCameraDiagnosticState(
2334
+ "moveCamera",
2335
+ pendingMoveCameraRequest
2336
+ )
2293
2337
  );
2294
2338
  pendingMoveCameraRequest = void 0;
2295
2339
  }
@@ -2314,14 +2358,26 @@ var NetlessAppPresentation = (function (exports) {
2314
2358
  });
2315
2359
  }
2316
2360
  };
2317
- dispose2.add(view$$.addStateChangedListener(() => syncViewFromRemote(false, true)));
2361
+ dispose2.add(
2362
+ view$$.addStateChangedListener(() => syncViewFromRemote(false, true))
2363
+ );
2318
2364
  const getPageSize = () => {
2319
2365
  const { width, height } = app.page() || {};
2320
2366
  return { width: width || 0, height: height || 0 };
2321
2367
  };
2322
2368
  const box = context.getBox();
2323
- const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, view, options.thumbnail, options.useClipView));
2324
- app.contentDOM.dataset.appPresentationVersion = "0.1.11";
2369
+ const app = dispose2.add(
2370
+ createPresentation(
2371
+ box,
2372
+ pages,
2373
+ jumpPage,
2374
+ pageIndex$,
2375
+ view,
2376
+ options.thumbnail,
2377
+ options.useClipView
2378
+ )
2379
+ );
2380
+ app.contentDOM.dataset.appPresentationVersion = "0.1.13-beta.0";
2325
2381
  app.scaleDocsToFit = scaleDocsToFit;
2326
2382
  app.log = log;
2327
2383
  app.warn = warn;
@@ -2368,12 +2424,14 @@ var NetlessAppPresentation = (function (exports) {
2368
2424
  };
2369
2425
  if (originSize) {
2370
2426
  let previousPageIndex = pageIndex$.value;
2371
- dispose2.add(pageIndex$.subscribe((nextPageIndex) => {
2372
- if (nextPageIndex === previousPageIndex)
2373
- return;
2374
- previousPageIndex = nextPageIndex;
2375
- scaleDocsToFit();
2376
- }));
2427
+ dispose2.add(
2428
+ pageIndex$.subscribe((nextPageIndex) => {
2429
+ if (nextPageIndex === previousPageIndex)
2430
+ return;
2431
+ previousPageIndex = nextPageIndex;
2432
+ scaleDocsToFit();
2433
+ })
2434
+ );
2377
2435
  }
2378
2436
  if (options.justDocsViewReadonly) {
2379
2437
  app.setDocsViewReadonly(true);
@@ -2422,9 +2480,11 @@ var NetlessAppPresentation = (function (exports) {
2422
2480
  });
2423
2481
  syncViewFromRemote(true);
2424
2482
  reportInitializedCamera("setup");
2425
- dispose2.add(context.emitter.on("writableChange", (isWritable) => {
2426
- app.setReadonly(!isWritable);
2427
- }));
2483
+ dispose2.add(
2484
+ context.emitter.on("writableChange", (isWritable) => {
2485
+ app.setReadonly(!isWritable);
2486
+ })
2487
+ );
2428
2488
  const getOriginScale = () => {
2429
2489
  const page = app.page();
2430
2490
  if (!page || !isValidSize(page))
@@ -2446,29 +2506,53 @@ var NetlessAppPresentation = (function (exports) {
2446
2506
  img.crossOrigin = "Anonymous";
2447
2507
  await new Promise((resolve, reject) => {
2448
2508
  img.onload = () => resolve();
2449
- img.onerror = () => reject(new Error(
2450
- `[Presentation]: failed to load screenshot page image: ${safeResourceLocation(src)}`
2451
- ));
2509
+ img.onerror = () => reject(
2510
+ new Error(
2511
+ `[Presentation]: failed to load screenshot page image: ${safeResourceLocation(src)}`
2512
+ )
2513
+ );
2452
2514
  img.src = src;
2453
2515
  });
2454
- _context.drawImage(img, 0, 0, width, height, 0, 0, _width || width, _height || height);
2516
+ _context.drawImage(
2517
+ img,
2518
+ 0,
2519
+ 0,
2520
+ width,
2521
+ height,
2522
+ 0,
2523
+ 0,
2524
+ _width || width,
2525
+ _height || height
2526
+ );
2455
2527
  const currentScenePath = view.focusScenePath;
2456
2528
  if (!currentScenePath) {
2457
2529
  throw new Error("[Presentation]: current scene path not found");
2458
2530
  }
2459
2531
  const windowManger = context.getWindowManager();
2460
2532
  if (windowManger._appliancePlugin) {
2461
- await windowManger._appliancePlugin.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
2462
- centerX: 0,
2463
- centerY: 0,
2464
- scale: _width && _height ? Math.min(_width / width, _height / height) : 1
2465
- });
2533
+ await windowManger._appliancePlugin.screenshotToCanvasAsync(
2534
+ _context,
2535
+ currentScenePath,
2536
+ _width || width,
2537
+ _height || height,
2538
+ {
2539
+ centerX: 0,
2540
+ centerY: 0,
2541
+ scale: _width && _height ? Math.min(_width / width, _height / height) : 1
2542
+ }
2543
+ );
2466
2544
  } else {
2467
- await view.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
2468
- centerX: 0,
2469
- centerY: 0,
2470
- scale: _width && _height ? Math.min(_width / width, _height / height) : 1
2471
- });
2545
+ await view.screenshotToCanvasAsync(
2546
+ _context,
2547
+ currentScenePath,
2548
+ _width || width,
2549
+ _height || height,
2550
+ {
2551
+ centerX: 0,
2552
+ centerY: 0,
2553
+ scale: _width && _height ? Math.min(_width / width, _height / height) : 1
2554
+ }
2555
+ );
2472
2556
  }
2473
2557
  };
2474
2558
  const screenshotCurrentPageAsync = async (_context, _width, _height) => {
@@ -2486,21 +2570,27 @@ var NetlessAppPresentation = (function (exports) {
2486
2570
  let scrollbar;
2487
2571
  if (options.useScrollbar) {
2488
2572
  dispose2.make(() => {
2489
- scrollbar = new Scrollbar(app.contentDOM, {
2490
- appId: context.appId,
2491
- getPageSize,
2492
- getOriginScale,
2493
- syncView,
2494
- getWritable: () => context.getIsWritable(),
2495
- scrollbarEventCallback: options.scrollbarEventCallback
2496
- }, view);
2573
+ scrollbar = new Scrollbar(
2574
+ app.contentDOM,
2575
+ {
2576
+ appId: context.appId,
2577
+ getPageSize,
2578
+ getOriginScale,
2579
+ syncView,
2580
+ getWritable: () => context.getIsWritable(),
2581
+ scrollbarEventCallback: options.scrollbarEventCallback
2582
+ },
2583
+ view
2584
+ );
2497
2585
  return () => scrollbar == null ? void 0 : scrollbar.destroy();
2498
2586
  });
2499
2587
  }
2500
2588
  const moveCamera = (camera) => {
2501
2589
  try {
2502
2590
  if (!context.getIsWritable()) {
2503
- throw new Error("[Presentation]: moveCamera must be called in writable room");
2591
+ throw new Error(
2592
+ "[Presentation]: moveCamera must be called in writable room"
2593
+ );
2504
2594
  }
2505
2595
  pendingMoveCameraRequest = __spreadValues({}, camera);
2506
2596
  if (scrollbar) {
@@ -2521,9 +2611,29 @@ var NetlessAppPresentation = (function (exports) {
2521
2611
  throw error;
2522
2612
  }
2523
2613
  };
2524
- context.emitter.on("destroy", () => dispose2());
2614
+ let disposed = false;
2615
+ let offDestroy;
2616
+ const teardown = () => {
2617
+ if (disposed)
2618
+ return;
2619
+ disposed = true;
2620
+ const removeDestroy = offDestroy;
2621
+ offDestroy = void 0;
2622
+ removeDestroy == null ? void 0 : removeDestroy();
2623
+ dispose2();
2624
+ };
2625
+ offDestroy = context.emitter.on("destroy", teardown);
2626
+ teardownByContext.set(context, teardown);
2525
2627
  const reportProgress = (progress, result) => {
2526
- window.postMessage({ type: "@netless/_result_save_pdf_", appId: context.appId, progress, result }, "*");
2628
+ window.postMessage(
2629
+ {
2630
+ type: "@netless/_result_save_pdf_",
2631
+ appId: context.appId,
2632
+ progress,
2633
+ result
2634
+ },
2635
+ "*"
2636
+ );
2527
2637
  return result;
2528
2638
  };
2529
2639
  const base64url = async (url) => {
@@ -2563,7 +2673,9 @@ var NetlessAppPresentation = (function (exports) {
2563
2673
  }
2564
2674
  const scenes = context.getDisplayer().entireScenes()[scenePath];
2565
2675
  if (!scenes) {
2566
- throw new Error(`[Presentation]: no scenes found while exporting PDF: ${scenePath}`);
2676
+ throw new Error(
2677
+ `[Presentation]: no scenes found while exporting PDF: ${scenePath}`
2678
+ );
2567
2679
  }
2568
2680
  const stage_canvas = document.createElement("canvas");
2569
2681
  stage_canvas.width = pdfWidth;
@@ -2588,20 +2700,32 @@ var NetlessAppPresentation = (function (exports) {
2588
2700
  const img = document.createElement("img");
2589
2701
  await new Promise((resolve, reject) => {
2590
2702
  img.onload = () => resolve();
2591
- img.onerror = () => reject(new Error(
2592
- `[Presentation]: failed to load PDF page image, page index: ${index}`
2593
- ));
2703
+ img.onerror = () => reject(
2704
+ new Error(
2705
+ `[Presentation]: failed to load PDF page image, page index: ${index}`
2706
+ )
2707
+ );
2594
2708
  img.src = url;
2595
2709
  });
2596
2710
  stage.drawImage(img, 0, 0, width2, height2);
2597
2711
  wb.clearRect(0, 0, pdfWidth, pdfHeight);
2598
2712
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
2599
2713
  if (scenes.some((scene) => scene.name == name)) {
2600
- const camera = { centerX: 0, centerY: 0, scale: Math.min(wb_canvas.width / width2, wb_canvas.height / height2) };
2714
+ const camera = {
2715
+ centerX: 0,
2716
+ centerY: 0,
2717
+ scale: Math.min(wb_canvas.width / width2, wb_canvas.height / height2)
2718
+ };
2601
2719
  const sPath = `${scenePath}/${name}`;
2602
2720
  const windowManger = context.getWindowManager();
2603
2721
  if (windowManger._appliancePlugin) {
2604
- await windowManger._appliancePlugin.screenshotToCanvasAsync(wb, sPath, wb_canvas.width, wb_canvas.height, camera);
2722
+ await windowManger._appliancePlugin.screenshotToCanvasAsync(
2723
+ wb,
2724
+ sPath,
2725
+ wb_canvas.width,
2726
+ wb_canvas.height,
2727
+ camera
2728
+ );
2605
2729
  } else {
2606
2730
  await view.screenshotToCanvasAsync(
2607
2731
  wb,
@@ -2648,14 +2772,20 @@ var NetlessAppPresentation = (function (exports) {
2648
2772
  throw error;
2649
2773
  }
2650
2774
  };
2651
- dispose2.add(listen(window, "message", (ev) => {
2652
- if (ev.data && ev.data.type == "@netless/_request_save_pdf_" && ev.data.appId == context.appId) {
2653
- toPdf().catch((err) => {
2654
- warn(err);
2655
- reportProgress(100, null);
2656
- });
2657
- }
2658
- }));
2775
+ dispose2.add(
2776
+ listen(
2777
+ window,
2778
+ "message",
2779
+ (ev) => {
2780
+ if (ev.data && ev.data.type == "@netless/_request_save_pdf_" && ev.data.appId == context.appId) {
2781
+ toPdf().catch((err) => {
2782
+ warn(err);
2783
+ reportProgress(100, null);
2784
+ });
2785
+ }
2786
+ }
2787
+ )
2788
+ );
2659
2789
  const setDocsViewReadonly = (bol) => {
2660
2790
  app.setDocsViewReadonly(bol);
2661
2791
  };
@@ -2666,19 +2796,52 @@ var NetlessAppPresentation = (function (exports) {
2666
2796
  scrollbar.setReadonly(bol);
2667
2797
  }
2668
2798
  };
2669
- const controller = { app, view, context, jumpPage, prevPage, nextPage, jumpPageAsync, prevPageAsync, nextPageAsync, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale, getPageSize, screenshotCurrentPageAsync };
2670
- dispose2.add(listen(window, "message", (ev) => {
2671
- if (ev.data === "@netless/_presentation_") {
2672
- if (typeof window !== "undefined")
2673
- dispose2.make(() => {
2674
- const debug = window._presentation_ || (window._presentation_ = /* @__PURE__ */ new Set());
2675
- debug.add(controller);
2676
- return () => debug.delete(controller);
2677
- });
2678
- console.log(controller);
2679
- }
2680
- }));
2681
- return prepareScenesPromise.then(() => controller);
2799
+ const controller = {
2800
+ app,
2801
+ view,
2802
+ context,
2803
+ jumpPage,
2804
+ prevPage,
2805
+ nextPage,
2806
+ jumpPageAsync,
2807
+ prevPageAsync,
2808
+ nextPageAsync,
2809
+ pageState,
2810
+ toPdf,
2811
+ log,
2812
+ setDocsViewReadonly,
2813
+ setReadonly,
2814
+ moveCamera,
2815
+ getOriginScale,
2816
+ getScale,
2817
+ getPageSize,
2818
+ screenshotCurrentPageAsync
2819
+ };
2820
+ dispose2.add(
2821
+ listen(
2822
+ window,
2823
+ "message",
2824
+ (ev) => {
2825
+ if (ev.data === "@netless/_presentation_") {
2826
+ if (typeof window !== "undefined")
2827
+ dispose2.make(() => {
2828
+ const debug = window._presentation_ || (window._presentation_ = /* @__PURE__ */ new Set());
2829
+ debug.add(controller);
2830
+ return () => debug.delete(controller);
2831
+ });
2832
+ console.log(controller);
2833
+ }
2834
+ }
2835
+ )
2836
+ );
2837
+ return prepareScenesPromise.then(
2838
+ () => controller
2839
+ );
2840
+ },
2841
+ teardown(context) {
2842
+ var _a;
2843
+ (_a = teardownByContext.get(context)) == null ? void 0 : _a();
2844
+ teardownByContext.delete(context);
2682
2845
  }
2683
2846
  };
2684
2847
  var AppPresentation = class extends Presentation {
@@ -2698,19 +2861,29 @@ var NetlessAppPresentation = (function (exports) {
2698
2861
  if (0 <= index && index < this.pages.length) {
2699
2862
  this.jumpPage(index);
2700
2863
  } else {
2701
- (_a = this.warn) == null ? void 0 : _a.call(this, `[Presentation]: page index ${index} out of bounds [0, ${this.pages.length - 1}]`);
2864
+ (_a = this.warn) == null ? void 0 : _a.call(
2865
+ this,
2866
+ `[Presentation]: page index ${index} out of bounds [0, ${this.pages.length - 1}]`
2867
+ );
2702
2868
  }
2703
2869
  }
2704
2870
  };
2705
2871
  function createPresentation(box, pages, jumpPage, pageIndex$, view, thumbnail, useClipView) {
2706
2872
  box.mountStyles(style_default);
2707
- const app = new AppPresentation({ pages, readonly: box.readonly, jumpPage, thumbnail });
2873
+ const app = new AppPresentation({
2874
+ pages,
2875
+ readonly: box.readonly,
2876
+ jumpPage,
2877
+ thumbnail
2878
+ });
2708
2879
  app.box = box;
2709
2880
  box.mountContent(app.contentDOM);
2710
2881
  box.mountFooter(app.footerDOM);
2711
- app.dispose.add(pageIndex$.subscribe((pageIndex) => {
2712
- app.setPageIndex(pageIndex);
2713
- }));
2882
+ app.dispose.add(
2883
+ pageIndex$.subscribe((pageIndex) => {
2884
+ app.setPageIndex(pageIndex);
2885
+ })
2886
+ );
2714
2887
  if (useClipView && view) {
2715
2888
  const onCameraUpdatedEffectForMaskView = (0, import_debounce2.default)(() => {
2716
2889
  const { width: pageWidth, height: pageHeight } = app.page() || {};
@@ -2719,8 +2892,12 @@ var NetlessAppPresentation = (function (exports) {
2719
2892
  }
2720
2893
  const { scale } = view.camera;
2721
2894
  const { width, height } = view.size;
2722
- const pageRatioX = Math.round((1 - pageWidth * scale / width) / 2 * 100);
2723
- const pageRatioY = Math.round((1 - pageHeight * scale / height) / 2 * 100);
2895
+ const pageRatioX = Math.round(
2896
+ (1 - pageWidth * scale / width) / 2 * 100
2897
+ );
2898
+ const pageRatioY = Math.round(
2899
+ (1 - pageHeight * scale / height) / 2 * 100
2900
+ );
2724
2901
  app.whiteboardDOM.style.clipPath = `inset(${pageRatioY}% ${pageRatioX}%)`;
2725
2902
  }, 50);
2726
2903
  onCameraUpdatedEffectForMaskView();
@@ -2745,7 +2922,7 @@ var NetlessAppPresentation = (function (exports) {
2745
2922
  };
2746
2923
 
2747
2924
  // src/index.ts
2748
- var version = "0.1.11";
2925
+ var version = "0.1.13-beta.0";
2749
2926
 
2750
2927
  exports.NetlessAppPresentation = NetlessAppPresentation;
2751
2928
  exports.Presentation = Presentation;