@netless/app-slide 0.3.0-canary.4 → 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.
- package/dist/SlideViewer.d.ts +16 -2
- package/dist/index.d.ts +4 -1
- package/dist/main.iife.js +2 -6362
- package/dist/main.iife.js.map +1 -1
- package/dist/main.js +2 -6362
- package/dist/main.js.map +1 -1
- package/dist/main.mjs +757 -41568
- package/dist/main.mjs.map +1 -1
- package/dist/typings.d.ts +7 -15
- package/package.json +7 -5
- package/src/SlideViewer.ts +24 -19
- package/src/index.ts +24 -9
- package/src/style.scss +15 -5
- package/src/typings.ts +19 -15
package/dist/typings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { 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
|
export declare type SlideState = Slide["slideState"];
|
|
4
4
|
export declare type AddHooks = NonNullable<RegisterParams["addHooks"]>;
|
|
@@ -13,19 +13,11 @@ export interface Attributes {
|
|
|
13
13
|
export interface MagixEvents {
|
|
14
14
|
[SLIDE_EVENTS.syncDispatch]: SyncEvent;
|
|
15
15
|
}
|
|
16
|
-
export interface AppOptions {
|
|
17
|
-
/** show debug controller */
|
|
16
|
+
export interface AppOptions extends Pick<ISlideConfig, "renderOptions" | "rtcAudio" | "useLocalCache" | "resourceTimeout" | "loaderDelegate" | "navigatorDelegate" | "fixedFrameSize" | "logger"> {
|
|
18
17
|
debug?: boolean;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
minFPS?: number;
|
|
25
|
-
/** maximal fps (default: 30) */
|
|
26
|
-
maxFPS?: number;
|
|
27
|
-
/** automatically decrease fps (default: true) */
|
|
28
|
-
autoFPS?: boolean;
|
|
29
|
-
/** whether to re-scale automatically (default: true) */
|
|
30
|
-
autoResolution?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ILogger {
|
|
20
|
+
info?(msg: string): void;
|
|
21
|
+
error?(msg: string): void;
|
|
22
|
+
warn?(msg: string): void;
|
|
31
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/app-slide",
|
|
3
|
-
"version": "0.3.0-canary.
|
|
3
|
+
"version": "0.3.0-canary.7",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"module": "dist/main.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
"dist",
|
|
10
10
|
"README-zh.md"
|
|
11
11
|
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@netless/slide": "^0.5.13"
|
|
14
|
+
},
|
|
12
15
|
"devDependencies": {
|
|
13
|
-
"@netless/slide": "^0.5.3",
|
|
14
16
|
"@types/color-string": "^1.5.2",
|
|
15
17
|
"color-string": "^1.9.1",
|
|
16
|
-
"side-effect-manager": "^1.1.
|
|
17
|
-
"value-enhancer": "^1.3.
|
|
18
|
-
"vanilla-lazyload": "^17.8.
|
|
18
|
+
"side-effect-manager": "^1.1.2",
|
|
19
|
+
"value-enhancer": "^1.3.2",
|
|
20
|
+
"vanilla-lazyload": "^17.8.3"
|
|
19
21
|
},
|
|
20
22
|
"scripts": {
|
|
21
23
|
"types": "cross-env NODE_ENV=production tsc --declaration --emitDeclarationOnly --outDir dist",
|
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 };
|
|
@@ -176,8 +181,8 @@ function create_sidebar() {
|
|
|
176
181
|
}
|
|
177
182
|
}
|
|
178
183
|
|
|
179
|
-
function set_page_index(page_index_: number) {
|
|
180
|
-
if (page_index !== page_index_) {
|
|
184
|
+
function set_page_index(page_index_: number, force = false) {
|
|
185
|
+
if (force || page_index !== page_index_) {
|
|
181
186
|
page_index = page_index_;
|
|
182
187
|
const $page = $preview.querySelector<HTMLElement>(
|
|
183
188
|
`.${wrap_class(`preview-page-${page_index}`)}`
|
|
@@ -292,9 +297,6 @@ function create_footer() {
|
|
|
292
297
|
const $pageNumberInput = h("input");
|
|
293
298
|
set_class($pageNumberInput, "page-number-input");
|
|
294
299
|
$pageNumberInput.value = String(page_index + 1);
|
|
295
|
-
$pageNumberInput.onfocus = function on_focus_page_number_input() {
|
|
296
|
-
$pageNumberInput.select();
|
|
297
|
-
};
|
|
298
300
|
$pageNumberInput.onchange = function on_change_page_number_input() {
|
|
299
301
|
if (readonly) return;
|
|
300
302
|
if ($pageNumberInput.value) {
|
|
@@ -329,8 +331,8 @@ function create_footer() {
|
|
|
329
331
|
}
|
|
330
332
|
}
|
|
331
333
|
|
|
332
|
-
function set_page_index(page_index_: number) {
|
|
333
|
-
if (page_index !== page_index_) {
|
|
334
|
+
function set_page_index(page_index_: number, force = false) {
|
|
335
|
+
if (force || page_index !== page_index_) {
|
|
334
336
|
page_index = page_index_;
|
|
335
337
|
$pageNumberInput.value = String(page_index + 1);
|
|
336
338
|
}
|
|
@@ -384,6 +386,7 @@ export interface SlideViewerInfoResponse {
|
|
|
384
386
|
|
|
385
387
|
export class SlideViewer {
|
|
386
388
|
static styles = styles;
|
|
389
|
+
static fetchSlideInfo = fetch_slide_info;
|
|
387
390
|
|
|
388
391
|
private readonly sideEffect = new SideEffectManager();
|
|
389
392
|
|
|
@@ -414,6 +417,8 @@ export class SlideViewer {
|
|
|
414
417
|
const on_new_page_index = (index: number) => {
|
|
415
418
|
if (this._ready && index >= 0 && index < this._slideCount) {
|
|
416
419
|
this.slide.renderSlide(index + 1);
|
|
420
|
+
} else {
|
|
421
|
+
this.setPage(this.slide.slideState.currentSlideIndex);
|
|
417
422
|
}
|
|
418
423
|
};
|
|
419
424
|
this.sidebar.on_new_page_index(on_new_page_index);
|
|
@@ -533,8 +538,8 @@ export class SlideViewer {
|
|
|
533
538
|
}
|
|
534
539
|
|
|
535
540
|
setPage(page: number) {
|
|
536
|
-
this.sidebar.set_page_index(page - 1);
|
|
537
|
-
this.footer.set_page_index(page - 1);
|
|
541
|
+
this.sidebar.set_page_index(page - 1, true);
|
|
542
|
+
this.footer.set_page_index(page - 1, true);
|
|
538
543
|
}
|
|
539
544
|
|
|
540
545
|
private _isFrozen = false;
|
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,16 +41,22 @@ 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,
|
|
42
48
|
autoFPS: options.autoFPS ?? true,
|
|
43
49
|
autoResolution: options.autoResolution ?? true,
|
|
44
50
|
resolution: options.resolution,
|
|
45
|
-
|
|
51
|
+
maxResolutionLevel: options.maxResolutionLevel,
|
|
52
|
+
transactionBgColor: options.transactionBgColor || make_bg_color(context.box.$content),
|
|
46
53
|
},
|
|
47
|
-
|
|
54
|
+
rtcAudio: appOptions.rtcAudio,
|
|
55
|
+
useLocalCache: appOptions.useLocalCache,
|
|
56
|
+
resourceTimeout: appOptions.resourceTimeout,
|
|
57
|
+
loaderDelegate: appOptions.loaderDelegate,
|
|
58
|
+
navigatorDelegate: appOptions.navigatorDelegate,
|
|
59
|
+
fixedFrameSize: appOptions.fixedFrameSize,
|
|
48
60
|
taskId: context.storage.state.taskId,
|
|
49
61
|
url: context.storage.state.url,
|
|
50
62
|
});
|
|
@@ -74,15 +86,17 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
|
|
|
74
86
|
logger.info("[Slide] destroy");
|
|
75
87
|
sideEffect.flushAll();
|
|
76
88
|
});
|
|
89
|
+
|
|
90
|
+
return viewer;
|
|
77
91
|
},
|
|
78
92
|
};
|
|
79
93
|
|
|
80
94
|
export default SlideApp;
|
|
81
95
|
|
|
82
96
|
export function previewSlide(options: SlideViewerOptions & { container: HTMLElement }) {
|
|
83
|
-
const { container } = options;
|
|
97
|
+
const { container, ...slideOptions } = options;
|
|
84
98
|
container.style.cssText = "display:flex;flex-direction:column";
|
|
85
|
-
const viewer = new SlideViewer(
|
|
99
|
+
const viewer = new SlideViewer(slideOptions);
|
|
86
100
|
container.appendChild(document.createElement("style")).textContent = SlideViewer.styles;
|
|
87
101
|
container.appendChild(viewer.$content);
|
|
88
102
|
container.appendChild(viewer.$footer);
|
|
@@ -107,7 +121,8 @@ function make_timestamp(context: AppContext): () => number {
|
|
|
107
121
|
}
|
|
108
122
|
}
|
|
109
123
|
|
|
110
|
-
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
|
|
111
126
|
if (import.meta.env.DEV) {
|
|
112
127
|
return { info: console.debug.bind(console) };
|
|
113
128
|
}
|
package/src/style.scss
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
@import "./fancy-scrollbar.scss";
|
|
2
2
|
|
|
3
|
+
@mixin no-user-select {
|
|
4
|
+
-webkit-touch-callout: none;
|
|
5
|
+
-webkit-user-select: none;
|
|
6
|
+
-moz-user-select: none;
|
|
7
|
+
-ms-user-select: none;
|
|
8
|
+
user-select: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
$namespace: "netless-app-slide";
|
|
4
12
|
|
|
5
13
|
.#{$namespace}-content {
|
|
@@ -11,6 +19,7 @@ $namespace: "netless-app-slide";
|
|
|
11
19
|
.#{$namespace}-slide {
|
|
12
20
|
width: 100%;
|
|
13
21
|
height: 100%;
|
|
22
|
+
@include no-user-select;
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
.#{$namespace}-preview-mask {
|
|
@@ -39,6 +48,7 @@ $namespace: "netless-app-slide";
|
|
|
39
48
|
background: rgba(237, 237, 240, 0.9);
|
|
40
49
|
box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.11);
|
|
41
50
|
transition: transform 0.4s;
|
|
51
|
+
@include no-user-select;
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
.#{$namespace}-preview-active {
|
|
@@ -62,7 +72,7 @@ $namespace: "netless-app-slide";
|
|
|
62
72
|
border: 7px solid transparent;
|
|
63
73
|
border-radius: 4px;
|
|
64
74
|
transition: border-color 0.3s;
|
|
65
|
-
user-select
|
|
75
|
+
@include no-user-select;
|
|
66
76
|
|
|
67
77
|
&:hover,
|
|
68
78
|
&.#{$namespace}-preview-page-active {
|
|
@@ -88,7 +98,7 @@ $namespace: "netless-app-slide";
|
|
|
88
98
|
text-align: right;
|
|
89
99
|
font-size: 12px;
|
|
90
100
|
color: #5f5f5f;
|
|
91
|
-
user-select
|
|
101
|
+
@include no-user-select;
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
.#{$namespace}-footer {
|
|
@@ -127,7 +137,7 @@ $namespace: "netless-app-slide";
|
|
|
127
137
|
background: transparent;
|
|
128
138
|
transition: background 0.4s;
|
|
129
139
|
cursor: pointer;
|
|
130
|
-
user-select
|
|
140
|
+
@include no-user-select;
|
|
131
141
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
132
142
|
|
|
133
143
|
&:hover {
|
|
@@ -177,7 +187,7 @@ $namespace: "netless-app-slide";
|
|
|
177
187
|
height: 26px;
|
|
178
188
|
margin-left: auto;
|
|
179
189
|
font-size: 13px;
|
|
180
|
-
user-select
|
|
190
|
+
@include no-user-select;
|
|
181
191
|
white-space: nowrap;
|
|
182
192
|
word-break: keep-all;
|
|
183
193
|
font-variant-numeric: tabular-nums;
|
|
@@ -200,13 +210,13 @@ $namespace: "netless-app-slide";
|
|
|
200
210
|
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
201
211
|
background: transparent;
|
|
202
212
|
transition: background 0.4s;
|
|
203
|
-
user-select: text;
|
|
204
213
|
font-variant-numeric: tabular-nums;
|
|
205
214
|
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
206
215
|
|
|
207
216
|
&:hover,
|
|
208
217
|
&:focus,
|
|
209
218
|
&:active {
|
|
219
|
+
user-select: text;
|
|
210
220
|
background: #fff;
|
|
211
221
|
box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
|
|
212
222
|
}
|
package/src/typings.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { 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,19 +18,23 @@ export interface MagixEvents {
|
|
|
18
18
|
[SLIDE_EVENTS.syncDispatch]: SyncEvent;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export interface AppOptions
|
|
22
|
-
|
|
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
|
+
> {
|
|
23
33
|
debug?: boolean;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** maximal fps (default: 30) */
|
|
31
|
-
maxFPS?: number;
|
|
32
|
-
/** automatically decrease fps (default: true) */
|
|
33
|
-
autoFPS?: boolean;
|
|
34
|
-
/** whether to re-scale automatically (default: true) */
|
|
35
|
-
autoResolution?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ILogger {
|
|
37
|
+
info?(msg: string): void;
|
|
38
|
+
error?(msg: string): void;
|
|
39
|
+
warn?(msg: string): void;
|
|
36
40
|
}
|