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