@netless/app-presentation 0.1.12 → 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
@@ -469,8 +469,10 @@ interface PresentationController {
469
469
  /** screenshot the current page */
470
470
  screenshotCurrentPageAsync: (context: CanvasRenderingContext2D, width?: number, height?: number) => Promise<void>;
471
471
  }
472
- declare const NetlessAppPresentation: NetlessApp<PresentationAttributes, {}, PresentationAppOptions, PresentationController>;
473
- 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"];
474
476
  interface InstallOptions {
475
477
  /**
476
478
  * Register as another "kind", to hijack existing apps.
@@ -1967,7 +1967,10 @@ var NetlessAppPresentation = (function (exports) {
1967
1967
  var _a;
1968
1968
  const createAppLogger = context.createLogger;
1969
1969
  if (typeof createAppLogger === "function") {
1970
- return createAppLogger.call(context, "camera", { debounceTime: 300, maxWaitTime: 2e3 });
1970
+ return createAppLogger.call(context, "camera", {
1971
+ debounceTime: 300,
1972
+ maxWaitTime: 2e3
1973
+ });
1971
1974
  }
1972
1975
  const roomLogger = (_a = context.getRoom()) == null ? void 0 : _a.logger;
1973
1976
  const prefix = `[Presentation][${context.appId}][camera]`;
@@ -2024,6 +2027,7 @@ var NetlessAppPresentation = (function (exports) {
2024
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);
2025
2028
  });
2026
2029
  };
2030
+ var teardownByContext = /* @__PURE__ */ new WeakMap();
2027
2031
  var NetlessAppPresentation = {
2028
2032
  kind: "Presentation",
2029
2033
  setup(context) {
@@ -2031,33 +2035,52 @@ var NetlessAppPresentation = (function (exports) {
2031
2035
  const diagnosticLogger = createDiagnosticLogger(context);
2032
2036
  const view = context.getView();
2033
2037
  if (!view)
2034
- 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
+ );
2035
2041
  const options = context.getAppOptions() || {};
2036
2042
  const room = context.getRoom();
2037
2043
  const log = options.log || createLogger(room);
2038
2044
  const roomLogger = room == null ? void 0 : room.logger;
2039
2045
  const warn = (...data) => (roomLogger == null ? void 0 : roomLogger.warn) ? roomLogger.warn(...data) : log(...data);
2040
2046
  const configuredOriginSize = context.storage.state.originSize;
2041
- 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;
2042
2051
  if (configuredOriginSize != null && !originSize) {
2043
- warn(`[Presentation] originSize should contain finite positive width and height, got ${JSON.stringify(configuredOriginSize)}`);
2052
+ warn(
2053
+ `[Presentation] originSize should contain finite positive width and height, got ${JSON.stringify(configuredOriginSize)}`
2054
+ );
2044
2055
  }
2045
2056
  const pages = (_a = context.getScenes()) == null ? void 0 : _a.map(({ ppt, name }) => ppt2page(ppt, name, originSize)).filter(Boolean);
2046
2057
  if (!pages || pages.length === 0)
2047
- 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
+ );
2048
2061
  if (pages[0].src.startsWith("ppt"))
2049
- 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
+ );
2050
2065
  const scenePath = context.getInitScenePath();
2051
2066
  let maxCameraScale = (_b = options.maxCameraScale) != null ? _b : 3;
2052
2067
  if (!(Number.isFinite(maxCameraScale) && maxCameraScale > 0)) {
2053
- 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
+ );
2054
2071
  maxCameraScale = 3;
2055
2072
  }
2056
2073
  log(`[Presentation] new ${context.appId}`);
2057
2074
  const dispose2 = disposableStore();
2058
2075
  dispose2.add(() => log(`[Presentation] dispose ${context.appId}`));
2059
2076
  dispose2.add(() => diagnosticLogger.flush());
2060
- 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
+ });
2061
2084
  const _addScenePathListener = (name, listener) => {
2062
2085
  const windowManger = context.manager.windowManger;
2063
2086
  windowManger.emitter.on(name, listener);
@@ -2079,13 +2102,16 @@ var NetlessAppPresentation = (function (exports) {
2079
2102
  let pageIndex = getPageIndex(view);
2080
2103
  const pageIndex$ = readable(pageIndex, (set) => {
2081
2104
  set(pageIndex);
2082
- return _addScenePathListener("onAppScenePathChange", (payload) => {
2083
- const { appId } = payload;
2084
- if (appId === context.appId) {
2085
- const _pageIndex = getPageIndex(payload.view);
2086
- 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
+ }
2087
2113
  }
2088
- });
2114
+ );
2089
2115
  });
2090
2116
  dispose2.add(() => {
2091
2117
  pageIndex$.dispose();
@@ -2102,7 +2128,12 @@ var NetlessAppPresentation = (function (exports) {
2102
2128
  const p = pages[index];
2103
2129
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
2104
2130
  if (!scenes.some((scene) => scene.name === name)) {
2105
- 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
+ });
2106
2137
  }
2107
2138
  if (logger) {
2108
2139
  logger.info(`[Presentation] syncPage ${scenePath}/${name}`);
@@ -2114,15 +2145,21 @@ var NetlessAppPresentation = (function (exports) {
2114
2145
  if (!context.isAddApp)
2115
2146
  return;
2116
2147
  if (pages.length > 100)
2117
- 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
+ );
2118
2151
  if (!room || !room.isWritable)
2119
2152
  return;
2120
2153
  if (pageIndex$.value < 0 || pageIndex$.value >= pages.length) {
2121
- 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
+ );
2122
2157
  }
2123
2158
  const scenes = room.entireScenes()[scenePath];
2124
2159
  if (!scenes || !scenes[pageIndex$.value]) {
2125
- 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
+ );
2126
2163
  }
2127
2164
  const { name, ppt } = scenes[pageIndex$.value];
2128
2165
  const nextScenes = pages.map((page, index) => {
@@ -2151,16 +2188,22 @@ var NetlessAppPresentation = (function (exports) {
2151
2188
  const prepareScenesPromise = prepareScenes();
2152
2189
  const canJumpPage = (index) => {
2153
2190
  if (!context.getIsWritable()) {
2154
- 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
+ );
2155
2194
  return false;
2156
2195
  }
2157
2196
  if (!(0 <= index && index < pages.length)) {
2158
- 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
+ );
2159
2200
  return false;
2160
2201
  }
2161
2202
  const scenes = context.getDisplayer().entireScenes()[scenePath];
2162
2203
  if (!scenes) {
2163
- 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
+ );
2164
2207
  return false;
2165
2208
  }
2166
2209
  return true;
@@ -2266,13 +2309,20 @@ var NetlessAppPresentation = (function (exports) {
2266
2309
  try {
2267
2310
  const { camera, size } = view;
2268
2311
  const referenceSize = getCameraReferenceSize(originSize, page);
2269
- const viewport = cameraToSharedViewport(camera, size, referenceSize);
2312
+ const viewport = cameraToSharedViewport(
2313
+ camera,
2314
+ size,
2315
+ referenceSize
2316
+ );
2270
2317
  if (viewport)
2271
2318
  view$$.setState(__spreadValues({ uid: me }, viewport));
2272
2319
  if (pendingMoveCameraRequest) {
2273
2320
  diagnosticLogger.debouncedInfo(
2274
2321
  "moveCamera",
2275
- getCameraDiagnosticState("moveCamera", pendingMoveCameraRequest)
2322
+ getCameraDiagnosticState(
2323
+ "moveCamera",
2324
+ pendingMoveCameraRequest
2325
+ )
2276
2326
  );
2277
2327
  pendingMoveCameraRequest = void 0;
2278
2328
  }
@@ -2280,7 +2330,10 @@ var NetlessAppPresentation = (function (exports) {
2280
2330
  diagnosticLogger.error(
2281
2331
  "syncView.failed",
2282
2332
  error,
2283
- getCameraDiagnosticState("moveCamera", pendingMoveCameraRequest)
2333
+ getCameraDiagnosticState(
2334
+ "moveCamera",
2335
+ pendingMoveCameraRequest
2336
+ )
2284
2337
  );
2285
2338
  pendingMoveCameraRequest = void 0;
2286
2339
  }
@@ -2305,14 +2358,26 @@ var NetlessAppPresentation = (function (exports) {
2305
2358
  });
2306
2359
  }
2307
2360
  };
2308
- dispose2.add(view$$.addStateChangedListener(() => syncViewFromRemote(false, true)));
2361
+ dispose2.add(
2362
+ view$$.addStateChangedListener(() => syncViewFromRemote(false, true))
2363
+ );
2309
2364
  const getPageSize = () => {
2310
2365
  const { width, height } = app.page() || {};
2311
2366
  return { width: width || 0, height: height || 0 };
2312
2367
  };
2313
2368
  const box = context.getBox();
2314
- const app = dispose2.add(createPresentation(box, pages, jumpPage, pageIndex$, view, options.thumbnail, options.useClipView));
2315
- app.contentDOM.dataset.appPresentationVersion = "0.1.12";
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";
2316
2381
  app.scaleDocsToFit = scaleDocsToFit;
2317
2382
  app.log = log;
2318
2383
  app.warn = warn;
@@ -2359,12 +2424,14 @@ var NetlessAppPresentation = (function (exports) {
2359
2424
  };
2360
2425
  if (originSize) {
2361
2426
  let previousPageIndex = pageIndex$.value;
2362
- dispose2.add(pageIndex$.subscribe((nextPageIndex) => {
2363
- if (nextPageIndex === previousPageIndex)
2364
- return;
2365
- previousPageIndex = nextPageIndex;
2366
- scaleDocsToFit();
2367
- }));
2427
+ dispose2.add(
2428
+ pageIndex$.subscribe((nextPageIndex) => {
2429
+ if (nextPageIndex === previousPageIndex)
2430
+ return;
2431
+ previousPageIndex = nextPageIndex;
2432
+ scaleDocsToFit();
2433
+ })
2434
+ );
2368
2435
  }
2369
2436
  if (options.justDocsViewReadonly) {
2370
2437
  app.setDocsViewReadonly(true);
@@ -2413,9 +2480,11 @@ var NetlessAppPresentation = (function (exports) {
2413
2480
  });
2414
2481
  syncViewFromRemote(true);
2415
2482
  reportInitializedCamera("setup");
2416
- dispose2.add(context.emitter.on("writableChange", (isWritable) => {
2417
- app.setReadonly(!isWritable);
2418
- }));
2483
+ dispose2.add(
2484
+ context.emitter.on("writableChange", (isWritable) => {
2485
+ app.setReadonly(!isWritable);
2486
+ })
2487
+ );
2419
2488
  const getOriginScale = () => {
2420
2489
  const page = app.page();
2421
2490
  if (!page || !isValidSize(page))
@@ -2437,29 +2506,53 @@ var NetlessAppPresentation = (function (exports) {
2437
2506
  img.crossOrigin = "Anonymous";
2438
2507
  await new Promise((resolve, reject) => {
2439
2508
  img.onload = () => resolve();
2440
- img.onerror = () => reject(new Error(
2441
- `[Presentation]: failed to load screenshot page image: ${safeResourceLocation(src)}`
2442
- ));
2509
+ img.onerror = () => reject(
2510
+ new Error(
2511
+ `[Presentation]: failed to load screenshot page image: ${safeResourceLocation(src)}`
2512
+ )
2513
+ );
2443
2514
  img.src = src;
2444
2515
  });
2445
- _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
+ );
2446
2527
  const currentScenePath = view.focusScenePath;
2447
2528
  if (!currentScenePath) {
2448
2529
  throw new Error("[Presentation]: current scene path not found");
2449
2530
  }
2450
2531
  const windowManger = context.getWindowManager();
2451
2532
  if (windowManger._appliancePlugin) {
2452
- await windowManger._appliancePlugin.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
2453
- centerX: 0,
2454
- centerY: 0,
2455
- scale: _width && _height ? Math.min(_width / width, _height / height) : 1
2456
- });
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
+ );
2457
2544
  } else {
2458
- await view.screenshotToCanvasAsync(_context, currentScenePath, _width || width, _height || height, {
2459
- centerX: 0,
2460
- centerY: 0,
2461
- scale: _width && _height ? Math.min(_width / width, _height / height) : 1
2462
- });
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
+ );
2463
2556
  }
2464
2557
  };
2465
2558
  const screenshotCurrentPageAsync = async (_context, _width, _height) => {
@@ -2477,21 +2570,27 @@ var NetlessAppPresentation = (function (exports) {
2477
2570
  let scrollbar;
2478
2571
  if (options.useScrollbar) {
2479
2572
  dispose2.make(() => {
2480
- scrollbar = new Scrollbar(app.contentDOM, {
2481
- appId: context.appId,
2482
- getPageSize,
2483
- getOriginScale,
2484
- syncView,
2485
- getWritable: () => context.getIsWritable(),
2486
- scrollbarEventCallback: options.scrollbarEventCallback
2487
- }, 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
+ );
2488
2585
  return () => scrollbar == null ? void 0 : scrollbar.destroy();
2489
2586
  });
2490
2587
  }
2491
2588
  const moveCamera = (camera) => {
2492
2589
  try {
2493
2590
  if (!context.getIsWritable()) {
2494
- 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
+ );
2495
2594
  }
2496
2595
  pendingMoveCameraRequest = __spreadValues({}, camera);
2497
2596
  if (scrollbar) {
@@ -2512,9 +2611,29 @@ var NetlessAppPresentation = (function (exports) {
2512
2611
  throw error;
2513
2612
  }
2514
2613
  };
2515
- 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);
2516
2627
  const reportProgress = (progress, result) => {
2517
- 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
+ );
2518
2637
  return result;
2519
2638
  };
2520
2639
  const base64url = async (url) => {
@@ -2554,7 +2673,9 @@ var NetlessAppPresentation = (function (exports) {
2554
2673
  }
2555
2674
  const scenes = context.getDisplayer().entireScenes()[scenePath];
2556
2675
  if (!scenes) {
2557
- 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
+ );
2558
2679
  }
2559
2680
  const stage_canvas = document.createElement("canvas");
2560
2681
  stage_canvas.width = pdfWidth;
@@ -2579,20 +2700,32 @@ var NetlessAppPresentation = (function (exports) {
2579
2700
  const img = document.createElement("img");
2580
2701
  await new Promise((resolve, reject) => {
2581
2702
  img.onload = () => resolve();
2582
- img.onerror = () => reject(new Error(
2583
- `[Presentation]: failed to load PDF page image, page index: ${index}`
2584
- ));
2703
+ img.onerror = () => reject(
2704
+ new Error(
2705
+ `[Presentation]: failed to load PDF page image, page index: ${index}`
2706
+ )
2707
+ );
2585
2708
  img.src = url;
2586
2709
  });
2587
2710
  stage.drawImage(img, 0, 0, width2, height2);
2588
2711
  wb.clearRect(0, 0, pdfWidth, pdfHeight);
2589
2712
  const name = (_a2 = p.name) != null ? _a2 : String(index + 1);
2590
2713
  if (scenes.some((scene) => scene.name == name)) {
2591
- 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
+ };
2592
2719
  const sPath = `${scenePath}/${name}`;
2593
2720
  const windowManger = context.getWindowManager();
2594
2721
  if (windowManger._appliancePlugin) {
2595
- 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
+ );
2596
2729
  } else {
2597
2730
  await view.screenshotToCanvasAsync(
2598
2731
  wb,
@@ -2639,14 +2772,20 @@ var NetlessAppPresentation = (function (exports) {
2639
2772
  throw error;
2640
2773
  }
2641
2774
  };
2642
- dispose2.add(listen(window, "message", (ev) => {
2643
- if (ev.data && ev.data.type == "@netless/_request_save_pdf_" && ev.data.appId == context.appId) {
2644
- toPdf().catch((err) => {
2645
- warn(err);
2646
- reportProgress(100, null);
2647
- });
2648
- }
2649
- }));
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
+ );
2650
2789
  const setDocsViewReadonly = (bol) => {
2651
2790
  app.setDocsViewReadonly(bol);
2652
2791
  };
@@ -2657,19 +2796,52 @@ var NetlessAppPresentation = (function (exports) {
2657
2796
  scrollbar.setReadonly(bol);
2658
2797
  }
2659
2798
  };
2660
- const controller = { app, view, context, jumpPage, prevPage, nextPage, jumpPageAsync, prevPageAsync, nextPageAsync, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale, getPageSize, screenshotCurrentPageAsync };
2661
- dispose2.add(listen(window, "message", (ev) => {
2662
- if (ev.data === "@netless/_presentation_") {
2663
- if (typeof window !== "undefined")
2664
- dispose2.make(() => {
2665
- const debug = window._presentation_ || (window._presentation_ = /* @__PURE__ */ new Set());
2666
- debug.add(controller);
2667
- return () => debug.delete(controller);
2668
- });
2669
- console.log(controller);
2670
- }
2671
- }));
2672
- 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);
2673
2845
  }
2674
2846
  };
2675
2847
  var AppPresentation = class extends Presentation {
@@ -2689,19 +2861,29 @@ var NetlessAppPresentation = (function (exports) {
2689
2861
  if (0 <= index && index < this.pages.length) {
2690
2862
  this.jumpPage(index);
2691
2863
  } else {
2692
- (_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
+ );
2693
2868
  }
2694
2869
  }
2695
2870
  };
2696
2871
  function createPresentation(box, pages, jumpPage, pageIndex$, view, thumbnail, useClipView) {
2697
2872
  box.mountStyles(style_default);
2698
- 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
+ });
2699
2879
  app.box = box;
2700
2880
  box.mountContent(app.contentDOM);
2701
2881
  box.mountFooter(app.footerDOM);
2702
- app.dispose.add(pageIndex$.subscribe((pageIndex) => {
2703
- app.setPageIndex(pageIndex);
2704
- }));
2882
+ app.dispose.add(
2883
+ pageIndex$.subscribe((pageIndex) => {
2884
+ app.setPageIndex(pageIndex);
2885
+ })
2886
+ );
2705
2887
  if (useClipView && view) {
2706
2888
  const onCameraUpdatedEffectForMaskView = (0, import_debounce2.default)(() => {
2707
2889
  const { width: pageWidth, height: pageHeight } = app.page() || {};
@@ -2710,8 +2892,12 @@ var NetlessAppPresentation = (function (exports) {
2710
2892
  }
2711
2893
  const { scale } = view.camera;
2712
2894
  const { width, height } = view.size;
2713
- const pageRatioX = Math.round((1 - pageWidth * scale / width) / 2 * 100);
2714
- 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
+ );
2715
2901
  app.whiteboardDOM.style.clipPath = `inset(${pageRatioY}% ${pageRatioX}%)`;
2716
2902
  }, 50);
2717
2903
  onCameraUpdatedEffectForMaskView();
@@ -2736,7 +2922,7 @@ var NetlessAppPresentation = (function (exports) {
2736
2922
  };
2737
2923
 
2738
2924
  // src/index.ts
2739
- var version = "0.1.12";
2925
+ var version = "0.1.13-beta.0";
2740
2926
 
2741
2927
  exports.NetlessAppPresentation = NetlessAppPresentation;
2742
2928
  exports.Presentation = Presentation;