@netless/app-slide 0.2.61 → 0.2.62

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.61",
3
+ "version": "0.2.62",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "README-zh.md"
17
17
  ],
18
18
  "devDependencies": {
19
- "@netless/slide": "^1.4.9",
19
+ "@netless/slide": "^1.4.10",
20
20
  "@types/color-string": "^1.5.2",
21
21
  "color-string": "^1.9.1",
22
22
  "jspdf": "2.5.1",
@@ -1,4 +1,5 @@
1
- import type { ReadonlyTeleBox, AnimationMode, View } from "@netless/window-manager";
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import type { ReadonlyTeleBox, AnimationMode, View, AppContext } from "@netless/window-manager";
2
3
  import type { SlideController, SlideControllerOptions } from "../SlideController";
3
4
 
4
5
  import { SideEffectManager } from "side-effect-manager";
@@ -6,6 +7,8 @@ import { createDocsViewerPages } from "../SlideController";
6
7
  import { DocsViewer, type DocsViewerPage } from "../DocsViewer";
7
8
  import { logger } from "../utils/logger";
8
9
  import { isEditable } from "../utils/helpers";
10
+ import type { Attributes, MagixEvents } from "../typings";
11
+ import type { AppOptions } from "..";
9
12
 
10
13
  export const ClickThroughAppliances = new Set(["clicker"]);
11
14
 
@@ -18,6 +21,7 @@ export type MountSlideOptions = Omit<SlideControllerOptions, "context" | "onPage
18
21
  };
19
22
 
20
23
  export interface SlideDocsViewerConfig {
24
+ context: AppContext<Attributes, MagixEvents, AppOptions>;
21
25
  box: ReadonlyTeleBox;
22
26
  view: View;
23
27
  mountSlideController: (options: MountSlideOptions) => SlideController;
@@ -35,6 +39,7 @@ export interface SavePdfConfig {
35
39
  }
36
40
 
37
41
  export class SlideDocsViewer {
42
+ readonly context: AppContext<Attributes, MagixEvents, AppOptions>
38
43
  public viewer: DocsViewer;
39
44
  public slideController: SlideController | null = null;
40
45
 
@@ -48,6 +53,7 @@ export class SlideDocsViewer {
48
53
  private isViewMounted = false;
49
54
 
50
55
  public constructor({
56
+ context,
51
57
  box,
52
58
  view,
53
59
  mountSlideController,
@@ -58,6 +64,7 @@ export class SlideDocsViewer {
58
64
  onPagesReady,
59
65
  onNavigate,
60
66
  }: SlideDocsViewerConfig) {
67
+ this.context = context;
61
68
  this.box = box;
62
69
  this.whiteboardView = view;
63
70
  this.mountSlideController = mountSlideController;
@@ -299,25 +306,33 @@ export class SlideDocsViewer {
299
306
 
300
307
  protected namespace = "netless-app-slide";
301
308
 
302
- private getWhiteSnapshot(
309
+ private async getWhiteSnapshot(
303
310
  pageIndex: number,
304
311
  canvas: HTMLCanvasElement,
305
312
  ctx: CanvasRenderingContext2D,
306
313
  slideWidth: number,
307
314
  slideHeight: number
308
315
  ) {
309
- // Render whiteboard into canvas, and it must fit the slide size.
310
- this.whiteboardView.screenshotToCanvas(
311
- ctx,
312
- `${this.baseScenePath}/${pageIndex}`,
313
- canvas.width,
314
- canvas.height,
315
- {
316
+ const camera = {
316
317
  centerX: 0,
317
318
  centerY: 0,
318
319
  scale: Math.min(canvas.width / slideWidth, canvas.height / slideHeight),
320
+ };
321
+ const scenePath = `${this.baseScenePath}/${pageIndex}`;
322
+ // appliancePlugin is a performance optimization for whiteboard;
323
+ const windowManger = (this.context as any).manager.windowManger as any;
324
+ if (windowManger._appliancePlugin) {
325
+ await windowManger._appliancePlugin.screenshotToCanvasAsync(ctx, scenePath, canvas.width, canvas.height, camera);
326
+ } else {
327
+ // Render whiteboard into canvas, and it must fit the slide size.
328
+ this.whiteboardView.screenshotToCanvas(
329
+ ctx,
330
+ scenePath,
331
+ canvas.width,
332
+ canvas.height,
333
+ camera
334
+ );
319
335
  }
320
- );
321
336
  }
322
337
 
323
338
  private reportProgress(progress: number, result: { pdf: ArrayBuffer; title: string } | null) {
@@ -384,7 +399,7 @@ export class SlideDocsViewer {
384
399
  resizeCtx.drawImage(img, 0, 0, pdfWidth, pdfHeight);
385
400
  }
386
401
  whiteCtx.clearRect(0, 0, pdfWidth, pdfHeight);
387
- this.getWhiteSnapshot(i, whiteSnapshotCanvas, whiteCtx, width, height);
402
+ await this.getWhiteSnapshot(i, whiteSnapshotCanvas, whiteCtx, width, height);
388
403
  try {
389
404
  const whiteSnapshot = whiteSnapshotCanvas.toDataURL("image/png");
390
405
  const whiteImg = document.createElement("img");
package/src/index.ts CHANGED
@@ -175,6 +175,7 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
175
175
  };
176
176
 
177
177
  docsViewer = new SlideDocsViewer({
178
+ context,
178
179
  box,
179
180
  view,
180
181
  mountSlideController,