@netless/app-slide 0.3.0-canary.6 → 0.3.0-canary.7

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.
@@ -45,15 +45,25 @@ interface PreviewPage {
45
45
  thumbnail: string;
46
46
  }
47
47
 
48
- async function fetch_slide_info({ taskId, url }: SlideAttributes) {
48
+ interface PreviewInfo {
49
+ width: number;
50
+ height: number;
51
+ }
52
+
53
+ interface SlideInfo {
54
+ width: number;
55
+ height: number;
56
+ slideCount: number;
57
+ }
58
+
59
+ async function fetch_slide_info({ taskId, url }: SlideAttributes): Promise<{
60
+ preview: PreviewInfo | null;
61
+ slide: SlideInfo;
62
+ }> {
49
63
  const prefix = make_prefix(taskId, url);
50
64
  const imgSrc = `${prefix}/preview/1.png`;
51
65
  const jsonUrl = `${prefix}/jsonOutput/slide-1.json`;
52
66
 
53
- interface PreviewInfo {
54
- width: number;
55
- height: number;
56
- }
57
67
  const p1 = new Promise<PreviewInfo | null>(resolve => {
58
68
  const image = new Image();
59
69
  image.onload = () => resolve(image);
@@ -61,11 +71,6 @@ async function fetch_slide_info({ taskId, url }: SlideAttributes) {
61
71
  image.src = imgSrc;
62
72
  });
63
73
 
64
- interface SlideInfo {
65
- width: number;
66
- height: number;
67
- slideCount: number;
68
- }
69
74
  const p2: Promise<SlideInfo> = fetch(jsonUrl).then(r => r.json());
70
75
 
71
76
  return { preview: await p1, slide: await p2 };
@@ -381,6 +386,7 @@ export interface SlideViewerInfoResponse {
381
386
 
382
387
  export class SlideViewer {
383
388
  static styles = styles;
389
+ static fetchSlideInfo = fetch_slide_info;
384
390
 
385
391
  private readonly sideEffect = new SideEffectManager();
386
392
 
package/src/index.ts CHANGED
@@ -6,10 +6,15 @@ export type { SlideState, AddHooks, AppOptions, Attributes, MagixEvents, SlideVi
6
6
 
7
7
  import ColorString from "color-string";
8
8
  import { SideEffectManager } from "side-effect-manager";
9
+ import { Slide } from "@netless/slide";
9
10
  import { SlideViewer } from "./SlideViewer";
10
11
  import { refrigerator, addHooks } from "./Refrigerator";
12
+ import { DefaultUrl } from "./constants";
11
13
 
12
- export { SlideViewer, refrigerator, addHooks };
14
+ export { Slide, SlideViewer, refrigerator, addHooks, DefaultUrl };
15
+
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ export const usePlugin = /* @__PURE__ */ Slide.usePlugin.bind(Slide) as (plugin: any) => void;
13
18
 
14
19
  export const version = __APP_VERSION__;
15
20
 
@@ -22,8 +27,9 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
22
27
  throw new Error("[Slide] no taskId");
23
28
  }
24
29
 
25
- const options = context.getAppOptions() || {};
26
- const logger = make_logger(context);
30
+ const appOptions = context.getAppOptions() || {};
31
+ const options = appOptions.renderOptions || {};
32
+ const logger = make_logger(context, appOptions.debug);
27
33
  logger.info("[Slide] setup @ " + __APP_VERSION__);
28
34
 
29
35
  const sideEffect = new SideEffectManager();
@@ -35,7 +41,7 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
35
41
  resize: true,
36
42
  enableGlobalClick: true,
37
43
  timestamp: make_timestamp(context),
38
- logger,
44
+ logger: appOptions.logger || logger,
39
45
  renderOptions: {
40
46
  minFPS: options.minFPS || 25,
41
47
  maxFPS: options.maxFPS || 30,
@@ -45,7 +51,12 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
45
51
  maxResolutionLevel: options.maxResolutionLevel,
46
52
  transactionBgColor: options.transactionBgColor || make_bg_color(context.box.$content),
47
53
  },
48
-
54
+ rtcAudio: appOptions.rtcAudio,
55
+ useLocalCache: appOptions.useLocalCache,
56
+ resourceTimeout: appOptions.resourceTimeout,
57
+ loaderDelegate: appOptions.loaderDelegate,
58
+ navigatorDelegate: appOptions.navigatorDelegate,
59
+ fixedFrameSize: appOptions.fixedFrameSize,
49
60
  taskId: context.storage.state.taskId,
50
61
  url: context.storage.state.url,
51
62
  });
@@ -75,15 +86,17 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
75
86
  logger.info("[Slide] destroy");
76
87
  sideEffect.flushAll();
77
88
  });
89
+
90
+ return viewer;
78
91
  },
79
92
  };
80
93
 
81
94
  export default SlideApp;
82
95
 
83
96
  export function previewSlide(options: SlideViewerOptions & { container: HTMLElement }) {
84
- const { container } = options;
97
+ const { container, ...slideOptions } = options;
85
98
  container.style.cssText = "display:flex;flex-direction:column";
86
- const viewer = new SlideViewer(options);
99
+ const viewer = new SlideViewer(slideOptions);
87
100
  container.appendChild(document.createElement("style")).textContent = SlideViewer.styles;
88
101
  container.appendChild(viewer.$content);
89
102
  container.appendChild(viewer.$footer);
@@ -108,7 +121,8 @@ function make_timestamp(context: AppContext): () => number {
108
121
  }
109
122
  }
110
123
 
111
- function make_logger(context: AppContext): { info: (msg: string) => void } {
124
+ function make_logger(context: AppContext, debug?: boolean): { info: (msg: string) => void } {
125
+ void debug; // not used for now
112
126
  if (import.meta.env.DEV) {
113
127
  return { info: console.debug.bind(console) };
114
128
  }
package/src/typings.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ISlideRenderOptions, Slide, SLIDE_EVENTS, SyncEvent } from "@netless/slide";
1
+ import type { ISlideConfig, Slide, SLIDE_EVENTS, SyncEvent } from "@netless/slide";
2
2
  import type { RegisterParams } from "@netless/window-manager";
3
3
 
4
4
  export type SlideState = Slide["slideState"];
@@ -18,6 +18,23 @@ export interface MagixEvents {
18
18
  [SLIDE_EVENTS.syncDispatch]: SyncEvent;
19
19
  }
20
20
 
21
- export interface AppOptions extends ISlideRenderOptions {
21
+ export interface AppOptions
22
+ extends Pick<
23
+ ISlideConfig,
24
+ | "renderOptions"
25
+ | "rtcAudio"
26
+ | "useLocalCache"
27
+ | "resourceTimeout"
28
+ | "loaderDelegate"
29
+ | "navigatorDelegate"
30
+ | "fixedFrameSize"
31
+ | "logger"
32
+ > {
22
33
  debug?: boolean;
23
34
  }
35
+
36
+ export interface ILogger {
37
+ info?(msg: string): void;
38
+ error?(msg: string): void;
39
+ warn?(msg: string): void;
40
+ }