@netless/app-slide 0.3.0-canary.6 → 0.3.0-canary.9
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/dist/SlideViewer.d.ts +15 -0
- package/dist/index.d.ts +4 -1
- package/dist/main.iife.js +2 -2
- package/dist/main.iife.js.map +1 -1
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/dist/main.mjs +383 -373
- package/dist/main.mjs.map +1 -1
- package/dist/typings.d.ts +7 -2
- package/package.json +3 -3
- package/src/SlideViewer.ts +33 -12
- package/src/index.ts +22 -8
- package/src/style.scss +16 -0
- package/src/typings.ts +19 -2
package/src/SlideViewer.ts
CHANGED
|
@@ -45,15 +45,25 @@ interface PreviewPage {
|
|
|
45
45
|
thumbnail: string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
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
|
|
|
@@ -389,6 +395,7 @@ export class SlideViewer {
|
|
|
389
395
|
readonly footer = create_footer();
|
|
390
396
|
readonly $content: HTMLElement;
|
|
391
397
|
readonly $footer: HTMLElement;
|
|
398
|
+
readonly $overlay: HTMLElement;
|
|
392
399
|
|
|
393
400
|
readonly slide;
|
|
394
401
|
|
|
@@ -402,6 +409,9 @@ export class SlideViewer {
|
|
|
402
409
|
this.$content = this.sidebar.$content;
|
|
403
410
|
this.$footer = this.footer.$footer;
|
|
404
411
|
append(this.$content, this.$slide);
|
|
412
|
+
this.$overlay = h("div");
|
|
413
|
+
set_class(this.$overlay, "overlay");
|
|
414
|
+
append(this.$content, this.$overlay);
|
|
405
415
|
|
|
406
416
|
let resolveReady: () => void;
|
|
407
417
|
this._readyPromise = new Promise(resolve => {
|
|
@@ -449,7 +459,6 @@ export class SlideViewer {
|
|
|
449
459
|
|
|
450
460
|
this.slide = new Slide({
|
|
451
461
|
anchor: this.$slide,
|
|
452
|
-
resize: true,
|
|
453
462
|
mode: "local",
|
|
454
463
|
interactive: true,
|
|
455
464
|
enableGlobalClick: true,
|
|
@@ -468,11 +477,23 @@ export class SlideViewer {
|
|
|
468
477
|
});
|
|
469
478
|
|
|
470
479
|
this.slide.on("renderEnd", () => {
|
|
471
|
-
if (!this._ready)
|
|
480
|
+
if (!this._ready) {
|
|
472
481
|
setTimeout(() => {
|
|
473
482
|
this._ready = true;
|
|
474
483
|
resolveReady();
|
|
475
484
|
}, 1000);
|
|
485
|
+
} else {
|
|
486
|
+
this.$overlay.style.opacity = "";
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
this.slide.on("renderError", ({ error, index }) => {
|
|
491
|
+
if (this._destroyed) return;
|
|
492
|
+
if (error) {
|
|
493
|
+
console.error(error);
|
|
494
|
+
this.$overlay.textContent = `Error on slide[index=${index}]: ${error.message}`;
|
|
495
|
+
this.$overlay.style.opacity = "1";
|
|
496
|
+
}
|
|
476
497
|
});
|
|
477
498
|
|
|
478
499
|
const fetching = fetch_slide_info(options).then(({ preview, slide }) => {
|
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
|
|
26
|
-
const
|
|
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(
|
|
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/style.scss
CHANGED
|
@@ -101,6 +101,22 @@ $namespace: "netless-app-slide";
|
|
|
101
101
|
@include no-user-select;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
.#{$namespace}-overlay {
|
|
105
|
+
display: flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
justify-content: center;
|
|
108
|
+
position: absolute;
|
|
109
|
+
z-index: 10100;
|
|
110
|
+
top: 0;
|
|
111
|
+
left: 0;
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: 100%;
|
|
114
|
+
background: rgba(255, 0, 0, 0.25);
|
|
115
|
+
transition: opacity 0.3s;
|
|
116
|
+
opacity: 0;
|
|
117
|
+
pointer-events: none;
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
.#{$namespace}-footer {
|
|
105
121
|
box-sizing: border-box;
|
|
106
122
|
height: 26px;
|
package/src/typings.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
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
|
+
}
|