@netless/app-slide 0.2.56 → 0.2.58

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,16 +1,22 @@
1
1
  {
2
2
  "name": "@netless/app-slide",
3
- "version": "0.2.56",
3
+ "version": "0.2.58",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "types": "node scripts/build-types.mjs",
9
+ "build": "vite build && npm run types",
10
+ "build:dev": "vite build --mode development && npm run types",
11
+ "cleanup": "rimraf ./dist"
12
+ },
7
13
  "files": [
8
14
  "src",
9
15
  "dist",
10
16
  "README-zh.md"
11
17
  ],
12
18
  "devDependencies": {
13
- "@netless/slide": "^1.4.0",
19
+ "@netless/slide": "^1.4.7",
14
20
  "@types/color-string": "^1.5.2",
15
21
  "color-string": "^1.9.1",
16
22
  "jspdf": "2.5.1",
@@ -24,11 +30,5 @@
24
30
  "jspdf": {
25
31
  "optional": true
26
32
  }
27
- },
28
- "scripts": {
29
- "types": "node scripts/build-types.mjs",
30
- "build": "vite build && npm run types",
31
- "build:dev": "vite build --mode development && npm run types",
32
- "cleanup": "rimraf ./dist"
33
33
  }
34
- }
34
+ }
@@ -4,12 +4,17 @@ import type { Slide } from "@netless/slide";
4
4
  import type { DocsViewerPage } from "../DocsViewer";
5
5
  import type { Attributes } from "../typings";
6
6
 
7
- export function createDocsViewerPages(slide: Slide): DocsViewerPage[] {
7
+ export function createDocsViewerPages(slide: Slide, previewUrls: string[] = []): DocsViewerPage[] {
8
8
  const { width, height, slideCount, slideState } = slide;
9
9
  const { taskId, url } = slideState;
10
10
  const pages: DocsViewerPage[] = [];
11
11
  for (let i = 1; i <= slideCount; ++i) {
12
- pages.push({ width, height, thumbnail: `${url}/${taskId}/preview/${i}.png`, src: "ppt" });
12
+ const signedUrl = previewUrls.find(v => v.indexOf(`preview/${i}.png`) >= 0);
13
+ if (signedUrl) {
14
+ pages.push({ width, height, thumbnail: signedUrl, src: "ppt" });
15
+ } else {
16
+ pages.push({ width, height, thumbnail: `${url}/${taskId}/preview/${i}.png`, src: "ppt" });
17
+ }
13
18
  }
14
19
  return pages;
15
20
  }
@@ -27,6 +27,8 @@ export const EmptyAttributes: Attributes = {
27
27
  taskId: "",
28
28
  url: "",
29
29
  state: null,
30
+ resourceList: [],
31
+ previewList: [],
30
32
  };
31
33
 
32
34
  export interface SlideControllerOptions {
@@ -41,6 +43,7 @@ export interface SlideControllerOptions {
41
43
  onRenderError?: (error: Error, pageIndex: number) => void;
42
44
  onNavigate?: (index: number, origin?: string) => void;
43
45
  showRenderError?: boolean;
46
+ invisibleBehavior?: "frozen" | "pause";
44
47
  }
45
48
 
46
49
  const noop = function noop() {
@@ -73,6 +76,11 @@ export class SlideController {
73
76
  private visible: boolean;
74
77
  private savedIsFrozen: boolean;
75
78
 
79
+ private invisibleBehavior: "frozen" | "pause";
80
+
81
+ // 签名后的预览图
82
+ public previewList: string[] = [];
83
+
76
84
  public constructor({
77
85
  context,
78
86
  anchor,
@@ -84,7 +92,9 @@ export class SlideController {
84
92
  onError,
85
93
  onRenderError,
86
94
  showRenderError,
95
+ invisibleBehavior,
87
96
  }: SlideControllerOptions) {
97
+ this.invisibleBehavior = invisibleBehavior ?? "frozen";
88
98
  this.onRenderStart = onRenderStart;
89
99
  this.onPageChanged = onPageChanged;
90
100
  this.onTransitionStart = onTransitionStart;
@@ -148,8 +158,13 @@ export class SlideController {
148
158
  if (context.getIsWritable()) {
149
159
  context.storage.ensureState(EmptyAttributes);
150
160
  }
151
- const { taskId, url, state } = context.storage.state;
152
- slide.setResource(taskId, url || DefaultUrl);
161
+ const { taskId, url, resourceList, previewList, state } = context.storage.state;
162
+ this.previewList = previewList;
163
+ if (resourceList && resourceList.length > 0) {
164
+ slide.setResourceList(taskId, resourceList);
165
+ } else {
166
+ slide.setResource(taskId, url || DefaultUrl);
167
+ }
153
168
  if (state) {
154
169
  // if we already have state, try restore from it
155
170
  log("[Slide] init with state", JSON.stringify(state));
@@ -341,7 +356,11 @@ export class SlideController {
341
356
  this.isFrozen = true;
342
357
  if (this.ready) {
343
358
  log("[Slide] freeze", this.context.appId);
344
- this.slide.frozen();
359
+ if (this.invisibleBehavior === "frozen") {
360
+ this.slide.frozen();
361
+ } else {
362
+ this.slide.pause();
363
+ }
345
364
  } else {
346
365
  this._toFreeze = 1;
347
366
  }
@@ -352,7 +371,11 @@ export class SlideController {
352
371
  this.isFrozen = false;
353
372
  if (this.ready) {
354
373
  log("[Slide] unfreeze", this.context.appId);
355
- this.slide.release();
374
+ if (this.invisibleBehavior === "frozen") {
375
+ this.slide.release();
376
+ } else {
377
+ this.slide.resume();
378
+ }
356
379
  } else {
357
380
  this._toFreeze = -1;
358
381
  }
@@ -213,7 +213,7 @@ export class SlideDocsViewer {
213
213
 
214
214
  protected refreshPages = () => {
215
215
  if (this.slideController) {
216
- this.viewer.pages = createDocsViewerPages(this.slideController.slide);
216
+ this.viewer.pages = createDocsViewerPages(this.slideController.slide, this.slideController.previewList);
217
217
  this.viewer.setPageIndex(this.getPageIndex(this.slideController.page));
218
218
  this.scaleDocsToFit();
219
219
  }
@@ -11,11 +11,13 @@ export interface PreviewParams {
11
11
  taskId: string;
12
12
  url?: string;
13
13
  debug?: boolean;
14
+ resourceList?: string[];
14
15
  }
15
16
 
16
17
  export default function previewSlide({
17
18
  container,
18
19
  taskId,
20
+ resourceList = [],
19
21
  url = DefaultUrl,
20
22
  debug = import.meta.env.DEV,
21
23
  }: PreviewParams) {
@@ -27,7 +29,7 @@ export default function previewSlide({
27
29
  const previewer = new SlidePreviewer({ target: container });
28
30
  previewer.debug = !!debug;
29
31
 
30
- previewer.mount(taskId, url);
32
+ previewer.mount(taskId, url, resourceList);
31
33
 
32
34
  return previewer;
33
35
  }
@@ -46,6 +48,8 @@ export class SlidePreviewer {
46
48
 
47
49
  public $slide!: HTMLDivElement;
48
50
 
51
+ private previewList: string[] = [];
52
+
49
53
  private readonly sideEffect = new SideEffectManager();
50
54
 
51
55
  public ready = false;
@@ -110,7 +114,7 @@ export class SlidePreviewer {
110
114
  }
111
115
  };
112
116
 
113
- public mount(taskId: string, url: string) {
117
+ public mount(taskId: string, url: string, resourceList: string[], previewList: string[] = []) {
114
118
  this.target.appendChild(this.renderStyle());
115
119
  this.target.appendChild(this.viewer.$content);
116
120
  this.target.appendChild(this.viewer.$footer);
@@ -132,8 +136,13 @@ export class SlidePreviewer {
132
136
 
133
137
  this.registerEventListeners();
134
138
 
135
- this.slide.setResource(taskId, url);
139
+ if (resourceList.length > 0) {
140
+ this.slide.setResourceList(taskId, resourceList);
141
+ } else {
142
+ this.slide.setResource(taskId, url);
143
+ }
136
144
  this.slide.renderSlide(1);
145
+ this.previewList = previewList;
137
146
  }
138
147
 
139
148
  protected renderStyle(): HTMLElement {
@@ -186,7 +195,7 @@ export class SlidePreviewer {
186
195
 
187
196
  protected refreshPages = () => {
188
197
  if (this.slide) {
189
- this.viewer.pages = createDocsViewerPages(this.slide);
198
+ this.viewer.pages = createDocsViewerPages(this.slide, this.previewList);
190
199
  this.viewer.setPageIndex(this.getPageIndex(this.slide.slideState.currentSlideIndex));
191
200
  }
192
201
  };
package/src/index.ts CHANGED
@@ -69,6 +69,8 @@ export interface AppOptions
69
69
  onRenderError?: (error: Error, pageIndex: number) => void;
70
70
  /** whether to show an overlay of error message @default: true */
71
71
  showRenderError?: boolean;
72
+ /** Specify the behavior after hiding the slide; Freeze will destroy the slide and replace it with a snapshot, while Pause simply pauses the slide @default: 'frozen' */
73
+ invisibleBehavior?: "frozen" | "pause";
72
74
  }
73
75
 
74
76
  export interface ILogger {
@@ -150,6 +152,7 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
150
152
  onNavigate: options.onNavigate,
151
153
  onRenderError: appOptions.onRenderError,
152
154
  showRenderError: appOptions.showRenderError,
155
+ invisibleBehavior: appOptions.invisibleBehavior,
153
156
  });
154
157
  if (useFreezer) apps.set(context.appId, slideController, box);
155
158
  logger.setAppController(context.appId, slideController);
package/src/typings.ts CHANGED
@@ -9,6 +9,8 @@ export interface Attributes {
9
9
  url: string;
10
10
  /** internal state of slide, do not change */
11
11
  state: SlideState | null;
12
+ resourceList: string[];
13
+ previewList: string[];
12
14
  }
13
15
 
14
16
  export type MagixPayload = {
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 netless
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.