@netless/app-slide 0.2.38 → 0.2.39-alpha.1
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/README-zh.md +53 -53
- package/README.md +68 -68
- package/dist/index.d.ts +294 -294
- package/dist/main.cjs.js +2 -2
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.es.js +8 -11
- package/dist/main.es.js.map +1 -1
- package/dist/main.iife.js +2 -2
- package/dist/main.iife.js.map +1 -1
- package/package.json +8 -8
- package/src/DocsViewer/icons/arrow-left.svg +4 -4
- package/src/DocsViewer/icons/arrow-left.ts +18 -18
- package/src/DocsViewer/icons/arrow-right.svg +4 -4
- package/src/DocsViewer/icons/arrow-right.ts +18 -18
- package/src/DocsViewer/icons/pause.svg +4 -4
- package/src/DocsViewer/icons/pause.ts +18 -18
- package/src/DocsViewer/icons/play.svg +4 -4
- package/src/DocsViewer/icons/play.ts +18 -18
- package/src/DocsViewer/icons/sidebar.svg +4 -4
- package/src/DocsViewer/icons/sidebar.ts +18 -18
- package/src/DocsViewer/index.ts +381 -381
- package/src/DocsViewer/style.scss +228 -228
- package/src/DocsViewer/variables.scss +1 -1
- package/src/SlideController/helpers.ts +48 -48
- package/src/SlideController/index.ts +351 -351
- package/src/SlideDocsViewer/index.ts +11 -11
- package/src/SlideDocsViewer/style.scss +28 -28
- package/src/SlidePreviewer/index.ts +225 -225
- package/src/index.ts +283 -283
- package/src/style.scss +14 -14
- package/src/typings.ts +21 -21
- package/src/utils/bgcolor.ts +45 -45
- package/src/utils/freezer.ts +116 -116
- package/src/utils/helpers.ts +32 -32
- package/src/utils/logger.ts +106 -106
- package/LICENSE +0 -21
|
@@ -266,20 +266,20 @@ export class SlideDocsViewer {
|
|
|
266
266
|
private getWhiteSnapshot(
|
|
267
267
|
pageIndex: number,
|
|
268
268
|
canvas: HTMLCanvasElement,
|
|
269
|
-
ctx: CanvasRenderingContext2D
|
|
269
|
+
ctx: CanvasRenderingContext2D,
|
|
270
|
+
slideWidth: number,
|
|
271
|
+
slideHeight: number
|
|
270
272
|
) {
|
|
271
|
-
|
|
272
|
-
canvas.width = width;
|
|
273
|
-
canvas.height = height;
|
|
273
|
+
// Render whiteboard into canvas, and it must fit the slide size.
|
|
274
274
|
this.whiteboardView.screenshotToCanvas(
|
|
275
275
|
ctx,
|
|
276
276
|
`${this.baseScenePath}/${pageIndex}`,
|
|
277
|
-
width,
|
|
278
|
-
height,
|
|
277
|
+
canvas.width,
|
|
278
|
+
canvas.height,
|
|
279
279
|
{
|
|
280
280
|
centerX: 0,
|
|
281
281
|
centerY: 0,
|
|
282
|
-
scale:
|
|
282
|
+
scale: Math.min(canvas.width / slideWidth, canvas.height / slideHeight),
|
|
283
283
|
}
|
|
284
284
|
);
|
|
285
285
|
}
|
|
@@ -317,8 +317,8 @@ export class SlideDocsViewer {
|
|
|
317
317
|
resizeCanvas.height = pdfHeight;
|
|
318
318
|
|
|
319
319
|
const whiteSnapshotCanvas = document.createElement("canvas");
|
|
320
|
-
whiteSnapshotCanvas.width =
|
|
321
|
-
whiteSnapshotCanvas.height =
|
|
320
|
+
whiteSnapshotCanvas.width = pdfWidth;
|
|
321
|
+
whiteSnapshotCanvas.height = pdfHeight;
|
|
322
322
|
const whiteCtx = whiteSnapshotCanvas.getContext("2d");
|
|
323
323
|
if (!whiteCtx || !this.getWhiteSnapshot || !resizeCtx) {
|
|
324
324
|
this.reportProgress(100, null);
|
|
@@ -347,8 +347,8 @@ export class SlideDocsViewer {
|
|
|
347
347
|
await new Promise(resolve => (img.onload = resolve));
|
|
348
348
|
resizeCtx.drawImage(img, 0, 0, pdfWidth, pdfHeight);
|
|
349
349
|
}
|
|
350
|
-
whiteCtx.clearRect(0, 0,
|
|
351
|
-
this.getWhiteSnapshot(i, whiteSnapshotCanvas, whiteCtx);
|
|
350
|
+
whiteCtx.clearRect(0, 0, pdfWidth, pdfHeight);
|
|
351
|
+
this.getWhiteSnapshot(i, whiteSnapshotCanvas, whiteCtx, width, height);
|
|
352
352
|
try {
|
|
353
353
|
const whiteSnapshot = whiteSnapshotCanvas.toDataURL("image/png");
|
|
354
354
|
const whiteImg = document.createElement("img");
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
$namespace: "netless-app-slide";
|
|
2
|
-
|
|
3
|
-
.#{$namespace}-wb-view {
|
|
4
|
-
position: absolute;
|
|
5
|
-
top: 0;
|
|
6
|
-
left: 0;
|
|
7
|
-
width: 100%;
|
|
8
|
-
height: 100%;
|
|
9
|
-
z-index: 100;
|
|
10
|
-
overflow: hidden;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.#{$namespace}-overlay {
|
|
14
|
-
display: flex;
|
|
15
|
-
align-items: center;
|
|
16
|
-
justify-content: center;
|
|
17
|
-
position: absolute;
|
|
18
|
-
z-index: 200;
|
|
19
|
-
top: 0;
|
|
20
|
-
left: 0;
|
|
21
|
-
width: 100%;
|
|
22
|
-
height: 100%;
|
|
23
|
-
padding: 8px;
|
|
24
|
-
background: rgba(255, 0, 0, 0.25);
|
|
25
|
-
transition: opacity 0.3s;
|
|
26
|
-
opacity: 0;
|
|
27
|
-
pointer-events: none;
|
|
28
|
-
}
|
|
1
|
+
$namespace: "netless-app-slide";
|
|
2
|
+
|
|
3
|
+
.#{$namespace}-wb-view {
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 0;
|
|
6
|
+
left: 0;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
z-index: 100;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.#{$namespace}-overlay {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
position: absolute;
|
|
18
|
+
z-index: 200;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
padding: 8px;
|
|
24
|
+
background: rgba(255, 0, 0, 0.25);
|
|
25
|
+
transition: opacity 0.3s;
|
|
26
|
+
opacity: 0;
|
|
27
|
+
pointer-events: none;
|
|
28
|
+
}
|
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import { SideEffectManager } from "side-effect-manager";
|
|
2
|
-
import { Slide, SLIDE_EVENTS } from "@netless/slide";
|
|
3
|
-
import { DocsViewer } from "../DocsViewer";
|
|
4
|
-
import { createDocsViewerPages, DefaultUrl } from "../SlideController";
|
|
5
|
-
import { cachedGetBgColor } from "../utils/bgcolor";
|
|
6
|
-
import { clamp } from "../utils/helpers";
|
|
7
|
-
import style from "../style.scss?inline";
|
|
8
|
-
|
|
9
|
-
export interface PreviewParams {
|
|
10
|
-
container: HTMLElement;
|
|
11
|
-
taskId: string;
|
|
12
|
-
url?: string;
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default function previewSlide({
|
|
17
|
-
container,
|
|
18
|
-
taskId,
|
|
19
|
-
url = DefaultUrl,
|
|
20
|
-
debug = import.meta.env.DEV,
|
|
21
|
-
}: PreviewParams) {
|
|
22
|
-
if (!taskId) {
|
|
23
|
-
throw new Error("[Slide] taskId is required");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
container.style.cssText += `display:flex;flex-direction:column`;
|
|
27
|
-
const previewer = new SlidePreviewer({ target: container });
|
|
28
|
-
previewer.debug = !!debug;
|
|
29
|
-
|
|
30
|
-
previewer.mount(taskId, url);
|
|
31
|
-
|
|
32
|
-
return previewer;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (import.meta.env.DEV) {
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
(window as any).previewSlide = previewSlide;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export class SlidePreviewer {
|
|
41
|
-
public readonly viewer: DocsViewer;
|
|
42
|
-
public readonly bgColor: string;
|
|
43
|
-
public readonly target: HTMLElement;
|
|
44
|
-
public slide: Slide | null = null;
|
|
45
|
-
public debug = import.meta.env.DEV;
|
|
46
|
-
|
|
47
|
-
public $slide!: HTMLDivElement;
|
|
48
|
-
|
|
49
|
-
private readonly sideEffect = new SideEffectManager();
|
|
50
|
-
|
|
51
|
-
public ready = false;
|
|
52
|
-
private resolveReady!: () => void;
|
|
53
|
-
public readonly readyPromise = new Promise<void>(resolve => {
|
|
54
|
-
this.resolveReady = () => {
|
|
55
|
-
this.ready = true;
|
|
56
|
-
resolve();
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
public constructor(config: { target: HTMLElement }) {
|
|
61
|
-
this.target = config.target;
|
|
62
|
-
this.bgColor = cachedGetBgColor(this.target);
|
|
63
|
-
this.viewer = new DocsViewer({
|
|
64
|
-
readonly: false,
|
|
65
|
-
onNewPageIndex: this.onNewPageIndex,
|
|
66
|
-
onPlay: this.onPlay,
|
|
67
|
-
});
|
|
68
|
-
this.render();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public render() {
|
|
72
|
-
this.viewer.$content.appendChild(this.renderSlideContainer());
|
|
73
|
-
this.registerHotKeys(window);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* In case you have a different window -- for example, in electron.
|
|
78
|
-
* Use this method to re-register hotkeys.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* previewer.registerHotKeys(windowLike)
|
|
82
|
-
*/
|
|
83
|
-
public registerHotKeys(windowLike: Window) {
|
|
84
|
-
this.sideEffect.addEventListener(
|
|
85
|
-
windowLike,
|
|
86
|
-
"keydown",
|
|
87
|
-
this.hotkeyListener,
|
|
88
|
-
undefined,
|
|
89
|
-
"hotkey"
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private hotkeyListener = (ev: KeyboardEvent) => {
|
|
94
|
-
if (this.slide) {
|
|
95
|
-
switch (ev.key) {
|
|
96
|
-
case "ArrowUp":
|
|
97
|
-
case "ArrowLeft": {
|
|
98
|
-
this.slide.prevStep();
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case "ArrowRight":
|
|
102
|
-
case "ArrowDown": {
|
|
103
|
-
this.slide.nextStep();
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
default: {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
public mount(taskId: string, url: string) {
|
|
114
|
-
this.target.appendChild(this.renderStyle());
|
|
115
|
-
this.target.appendChild(this.viewer.$content);
|
|
116
|
-
this.target.appendChild(this.viewer.$footer);
|
|
117
|
-
|
|
118
|
-
this.slide = new Slide({
|
|
119
|
-
anchor: this.$slide,
|
|
120
|
-
interactive: true,
|
|
121
|
-
mode: "local",
|
|
122
|
-
controller: this.debug,
|
|
123
|
-
enableGlobalClick: true,
|
|
124
|
-
renderOptions: {
|
|
125
|
-
minFPS: 25,
|
|
126
|
-
maxFPS: 30,
|
|
127
|
-
autoFPS: true,
|
|
128
|
-
autoResolution: true,
|
|
129
|
-
transactionBgColor: this.bgColor,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
this.registerEventListeners();
|
|
134
|
-
|
|
135
|
-
this.slide.setResource(taskId, url);
|
|
136
|
-
this.slide.renderSlide(1);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
protected renderStyle(): HTMLElement {
|
|
140
|
-
const element = document.createElement("style");
|
|
141
|
-
element.appendChild(document.createTextNode(style));
|
|
142
|
-
return element;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
protected registerEventListeners() {
|
|
146
|
-
if (!this.slide) return;
|
|
147
|
-
const { slide } = this;
|
|
148
|
-
|
|
149
|
-
slide.on(SLIDE_EVENTS.slideChange, this.onPageChanged);
|
|
150
|
-
slide.on(SLIDE_EVENTS.renderStart, this.onTransitionStart);
|
|
151
|
-
slide.on(SLIDE_EVENTS.renderEnd, this.onTransitionEnd);
|
|
152
|
-
slide.on(SLIDE_EVENTS.mainSeqStepStart, this.onTransitionStart);
|
|
153
|
-
slide.on(SLIDE_EVENTS.mainSeqStepEnd, this.onTransitionEnd);
|
|
154
|
-
slide.on(SLIDE_EVENTS.renderError, this.onError);
|
|
155
|
-
slide.on(SLIDE_EVENTS.renderEnd, this.resolveReady);
|
|
156
|
-
|
|
157
|
-
this.readyPromise.then(this.refreshPages);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
protected onPageChanged = (page: number) => {
|
|
161
|
-
this.viewer.setPageIndex(page - 1);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
protected onTransitionStart = () => {
|
|
165
|
-
this.viewer.setPlaying();
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
protected onTransitionEnd = () => {
|
|
169
|
-
this.viewer.setPaused();
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
protected onError = ({ error }: { error: Error }) => {
|
|
173
|
-
this.viewer.setPaused();
|
|
174
|
-
console.warn("[Slide] render error", error);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
private destroyed = false;
|
|
178
|
-
public destroy() {
|
|
179
|
-
this.sideEffect.flushAll();
|
|
180
|
-
if (this.slide && !this.destroyed) {
|
|
181
|
-
this.slide.destroy();
|
|
182
|
-
this.destroyed = true;
|
|
183
|
-
}
|
|
184
|
-
this.viewer.destroy();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
protected refreshPages = () => {
|
|
188
|
-
if (this.slide) {
|
|
189
|
-
this.viewer.pages = createDocsViewerPages(this.slide);
|
|
190
|
-
this.viewer.setPageIndex(this.getPageIndex(this.slide.slideState.currentSlideIndex));
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
protected getPageIndex(page: number) {
|
|
195
|
-
return (page > 0 ? page : 1) - 1;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
protected renderSlideContainer(): HTMLDivElement {
|
|
199
|
-
if (!this.$slide) {
|
|
200
|
-
const $slide = document.createElement("div");
|
|
201
|
-
$slide.className = this.wrapClassName("slide");
|
|
202
|
-
$slide.dataset.appKind = "Slide";
|
|
203
|
-
this.$slide = $slide;
|
|
204
|
-
}
|
|
205
|
-
return this.$slide;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
protected onPlay = () => {
|
|
209
|
-
if (this.slide) {
|
|
210
|
-
this.slide.nextStep();
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
protected onNewPageIndex = (index: number) => {
|
|
215
|
-
if (this.slide && this.slide.slideCount > 0) {
|
|
216
|
-
this.slide.renderSlide(clamp(index + 1, 1, this.slide.slideCount));
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
protected wrapClassName(className: string) {
|
|
221
|
-
return `${this.namespace}-${className}`;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
protected namespace = "netless-app-slide";
|
|
225
|
-
}
|
|
1
|
+
import { SideEffectManager } from "side-effect-manager";
|
|
2
|
+
import { Slide, SLIDE_EVENTS } from "@netless/slide";
|
|
3
|
+
import { DocsViewer } from "../DocsViewer";
|
|
4
|
+
import { createDocsViewerPages, DefaultUrl } from "../SlideController";
|
|
5
|
+
import { cachedGetBgColor } from "../utils/bgcolor";
|
|
6
|
+
import { clamp } from "../utils/helpers";
|
|
7
|
+
import style from "../style.scss?inline";
|
|
8
|
+
|
|
9
|
+
export interface PreviewParams {
|
|
10
|
+
container: HTMLElement;
|
|
11
|
+
taskId: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default function previewSlide({
|
|
17
|
+
container,
|
|
18
|
+
taskId,
|
|
19
|
+
url = DefaultUrl,
|
|
20
|
+
debug = import.meta.env.DEV,
|
|
21
|
+
}: PreviewParams) {
|
|
22
|
+
if (!taskId) {
|
|
23
|
+
throw new Error("[Slide] taskId is required");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
container.style.cssText += `display:flex;flex-direction:column`;
|
|
27
|
+
const previewer = new SlidePreviewer({ target: container });
|
|
28
|
+
previewer.debug = !!debug;
|
|
29
|
+
|
|
30
|
+
previewer.mount(taskId, url);
|
|
31
|
+
|
|
32
|
+
return previewer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (import.meta.env.DEV) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
(window as any).previewSlide = previewSlide;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class SlidePreviewer {
|
|
41
|
+
public readonly viewer: DocsViewer;
|
|
42
|
+
public readonly bgColor: string;
|
|
43
|
+
public readonly target: HTMLElement;
|
|
44
|
+
public slide: Slide | null = null;
|
|
45
|
+
public debug = import.meta.env.DEV;
|
|
46
|
+
|
|
47
|
+
public $slide!: HTMLDivElement;
|
|
48
|
+
|
|
49
|
+
private readonly sideEffect = new SideEffectManager();
|
|
50
|
+
|
|
51
|
+
public ready = false;
|
|
52
|
+
private resolveReady!: () => void;
|
|
53
|
+
public readonly readyPromise = new Promise<void>(resolve => {
|
|
54
|
+
this.resolveReady = () => {
|
|
55
|
+
this.ready = true;
|
|
56
|
+
resolve();
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
public constructor(config: { target: HTMLElement }) {
|
|
61
|
+
this.target = config.target;
|
|
62
|
+
this.bgColor = cachedGetBgColor(this.target);
|
|
63
|
+
this.viewer = new DocsViewer({
|
|
64
|
+
readonly: false,
|
|
65
|
+
onNewPageIndex: this.onNewPageIndex,
|
|
66
|
+
onPlay: this.onPlay,
|
|
67
|
+
});
|
|
68
|
+
this.render();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public render() {
|
|
72
|
+
this.viewer.$content.appendChild(this.renderSlideContainer());
|
|
73
|
+
this.registerHotKeys(window);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* In case you have a different window -- for example, in electron.
|
|
78
|
+
* Use this method to re-register hotkeys.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* previewer.registerHotKeys(windowLike)
|
|
82
|
+
*/
|
|
83
|
+
public registerHotKeys(windowLike: Window) {
|
|
84
|
+
this.sideEffect.addEventListener(
|
|
85
|
+
windowLike,
|
|
86
|
+
"keydown",
|
|
87
|
+
this.hotkeyListener,
|
|
88
|
+
undefined,
|
|
89
|
+
"hotkey"
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private hotkeyListener = (ev: KeyboardEvent) => {
|
|
94
|
+
if (this.slide) {
|
|
95
|
+
switch (ev.key) {
|
|
96
|
+
case "ArrowUp":
|
|
97
|
+
case "ArrowLeft": {
|
|
98
|
+
this.slide.prevStep();
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case "ArrowRight":
|
|
102
|
+
case "ArrowDown": {
|
|
103
|
+
this.slide.nextStep();
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
default: {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
public mount(taskId: string, url: string) {
|
|
114
|
+
this.target.appendChild(this.renderStyle());
|
|
115
|
+
this.target.appendChild(this.viewer.$content);
|
|
116
|
+
this.target.appendChild(this.viewer.$footer);
|
|
117
|
+
|
|
118
|
+
this.slide = new Slide({
|
|
119
|
+
anchor: this.$slide,
|
|
120
|
+
interactive: true,
|
|
121
|
+
mode: "local",
|
|
122
|
+
controller: this.debug,
|
|
123
|
+
enableGlobalClick: true,
|
|
124
|
+
renderOptions: {
|
|
125
|
+
minFPS: 25,
|
|
126
|
+
maxFPS: 30,
|
|
127
|
+
autoFPS: true,
|
|
128
|
+
autoResolution: true,
|
|
129
|
+
transactionBgColor: this.bgColor,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
this.registerEventListeners();
|
|
134
|
+
|
|
135
|
+
this.slide.setResource(taskId, url);
|
|
136
|
+
this.slide.renderSlide(1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
protected renderStyle(): HTMLElement {
|
|
140
|
+
const element = document.createElement("style");
|
|
141
|
+
element.appendChild(document.createTextNode(style));
|
|
142
|
+
return element;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
protected registerEventListeners() {
|
|
146
|
+
if (!this.slide) return;
|
|
147
|
+
const { slide } = this;
|
|
148
|
+
|
|
149
|
+
slide.on(SLIDE_EVENTS.slideChange, this.onPageChanged);
|
|
150
|
+
slide.on(SLIDE_EVENTS.renderStart, this.onTransitionStart);
|
|
151
|
+
slide.on(SLIDE_EVENTS.renderEnd, this.onTransitionEnd);
|
|
152
|
+
slide.on(SLIDE_EVENTS.mainSeqStepStart, this.onTransitionStart);
|
|
153
|
+
slide.on(SLIDE_EVENTS.mainSeqStepEnd, this.onTransitionEnd);
|
|
154
|
+
slide.on(SLIDE_EVENTS.renderError, this.onError);
|
|
155
|
+
slide.on(SLIDE_EVENTS.renderEnd, this.resolveReady);
|
|
156
|
+
|
|
157
|
+
this.readyPromise.then(this.refreshPages);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected onPageChanged = (page: number) => {
|
|
161
|
+
this.viewer.setPageIndex(page - 1);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
protected onTransitionStart = () => {
|
|
165
|
+
this.viewer.setPlaying();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
protected onTransitionEnd = () => {
|
|
169
|
+
this.viewer.setPaused();
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
protected onError = ({ error }: { error: Error }) => {
|
|
173
|
+
this.viewer.setPaused();
|
|
174
|
+
console.warn("[Slide] render error", error);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
private destroyed = false;
|
|
178
|
+
public destroy() {
|
|
179
|
+
this.sideEffect.flushAll();
|
|
180
|
+
if (this.slide && !this.destroyed) {
|
|
181
|
+
this.slide.destroy();
|
|
182
|
+
this.destroyed = true;
|
|
183
|
+
}
|
|
184
|
+
this.viewer.destroy();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
protected refreshPages = () => {
|
|
188
|
+
if (this.slide) {
|
|
189
|
+
this.viewer.pages = createDocsViewerPages(this.slide);
|
|
190
|
+
this.viewer.setPageIndex(this.getPageIndex(this.slide.slideState.currentSlideIndex));
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
protected getPageIndex(page: number) {
|
|
195
|
+
return (page > 0 ? page : 1) - 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
protected renderSlideContainer(): HTMLDivElement {
|
|
199
|
+
if (!this.$slide) {
|
|
200
|
+
const $slide = document.createElement("div");
|
|
201
|
+
$slide.className = this.wrapClassName("slide");
|
|
202
|
+
$slide.dataset.appKind = "Slide";
|
|
203
|
+
this.$slide = $slide;
|
|
204
|
+
}
|
|
205
|
+
return this.$slide;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
protected onPlay = () => {
|
|
209
|
+
if (this.slide) {
|
|
210
|
+
this.slide.nextStep();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
protected onNewPageIndex = (index: number) => {
|
|
215
|
+
if (this.slide && this.slide.slideCount > 0) {
|
|
216
|
+
this.slide.renderSlide(clamp(index + 1, 1, this.slide.slideCount));
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
protected wrapClassName(className: string) {
|
|
221
|
+
return `${this.namespace}-${className}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
protected namespace = "netless-app-slide";
|
|
225
|
+
}
|