@netless/app-slide 0.2.57 → 0.2.59

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.57",
3
+ "version": "0.2.59",
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.8",
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 {
@@ -76,6 +78,9 @@ export class SlideController {
76
78
 
77
79
  private invisibleBehavior: "frozen" | "pause";
78
80
 
81
+ // 签名后的预览图
82
+ public previewList: string[] = [];
83
+
79
84
  public constructor({
80
85
  context,
81
86
  anchor,
@@ -153,8 +158,13 @@ export class SlideController {
153
158
  if (context.getIsWritable()) {
154
159
  context.storage.ensureState(EmptyAttributes);
155
160
  }
156
- const { taskId, url, state } = context.storage.state;
157
- 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
+ }
158
168
  if (state) {
159
169
  // if we already have state, try restore from it
160
170
  log("[Slide] init with state", JSON.stringify(state));
@@ -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/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.