@netless/app-slide 0.2.2 → 0.3.0-canary.0
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 +1 -4
- package/README.md +1 -4
- package/dist/Refrigerator.d.ts +13 -0
- package/dist/SlideViewer.d.ts +63 -0
- package/dist/constants.d.ts +2 -0
- package/dist/{DocsViewer/icons → icons}/arrow-left.d.ts +0 -0
- package/dist/{DocsViewer/icons → icons}/arrow-right.d.ts +0 -0
- package/dist/{DocsViewer/icons → icons}/pause.d.ts +0 -0
- package/dist/{DocsViewer/icons → icons}/play.d.ts +0 -0
- package/dist/{DocsViewer/icons → icons}/sidebar.d.ts +0 -0
- package/dist/index.d.ts +10 -35
- package/dist/main.cjs.js +177 -177
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.es.js +1901 -2479
- package/dist/main.es.js.map +1 -1
- package/dist/main.iife.js +254 -254
- package/dist/main.iife.js.map +1 -1
- package/dist/typings.d.ts +21 -9
- package/dist/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/Refrigerator.ts +66 -0
- package/src/SlideViewer.ts +543 -0
- package/src/constants.ts +3 -0
- package/src/{DocsViewer/icons → icons}/arrow-left.ts +0 -0
- package/src/{DocsViewer/icons → icons}/arrow-right.ts +0 -0
- package/src/{DocsViewer/icons → icons}/pause.ts +0 -0
- package/src/{DocsViewer/icons → icons}/play.ts +0 -0
- package/src/{DocsViewer/icons → icons}/sidebar.ts +0 -0
- package/src/index.ts +210 -205
- package/src/style.scss +245 -5
- package/src/typings.ts +23 -10
- package/src/utils.ts +3 -0
- package/dist/DocsViewer/index.d.ts +0 -53
- package/dist/SlideController/helpers.d.ts +0 -6
- package/dist/SlideController/index.d.ts +0 -60
- package/dist/SlideDocsViewer/index.d.ts +0 -45
- package/dist/SlidePreviewer/index.d.ts +0 -52
- package/dist/utils/bgcolor.d.ts +0 -3
- package/dist/utils/freezer.d.ts +0 -22
- package/dist/utils/helpers.d.ts +0 -6
- package/dist/utils/logger.d.ts +0 -39
- package/src/DocsViewer/icons/arrow-left.svg +0 -4
- package/src/DocsViewer/icons/arrow-right.svg +0 -4
- package/src/DocsViewer/icons/pause.svg +0 -4
- package/src/DocsViewer/icons/play.svg +0 -4
- package/src/DocsViewer/icons/sidebar.svg +0 -4
- package/src/DocsViewer/index.ts +0 -368
- package/src/DocsViewer/style.scss +0 -228
- package/src/DocsViewer/variables.scss +0 -1
- package/src/SlideController/helpers.ts +0 -48
- package/src/SlideController/index.ts +0 -356
- package/src/SlideDocsViewer/index.ts +0 -210
- package/src/SlideDocsViewer/style.scss +0 -11
- package/src/SlidePreviewer/index.ts +0 -226
- package/src/utils/bgcolor.ts +0 -45
- package/src/utils/freezer.ts +0 -75
- package/src/utils/helpers.ts +0 -26
- package/src/utils/logger.ts +0 -106
|
@@ -1,226 +0,0 @@
|
|
|
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
|
-
resize: true,
|
|
123
|
-
controller: this.debug,
|
|
124
|
-
enableGlobalClick: true,
|
|
125
|
-
renderOptions: {
|
|
126
|
-
minFPS: 25,
|
|
127
|
-
maxFPS: 30,
|
|
128
|
-
autoFPS: true,
|
|
129
|
-
autoResolution: true,
|
|
130
|
-
transactionBgColor: this.bgColor,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
this.registerEventListeners();
|
|
135
|
-
|
|
136
|
-
this.slide.setResource(taskId, url);
|
|
137
|
-
this.slide.renderSlide(1);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected renderStyle(): HTMLElement {
|
|
141
|
-
const element = document.createElement("style");
|
|
142
|
-
element.appendChild(document.createTextNode(style));
|
|
143
|
-
return element;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
protected registerEventListeners() {
|
|
147
|
-
if (!this.slide) return;
|
|
148
|
-
const { slide } = this;
|
|
149
|
-
|
|
150
|
-
slide.on(SLIDE_EVENTS.slideChange, this.onPageChanged);
|
|
151
|
-
slide.on(SLIDE_EVENTS.renderStart, this.onTransitionStart);
|
|
152
|
-
slide.on(SLIDE_EVENTS.renderEnd, this.onTransitionEnd);
|
|
153
|
-
slide.on(SLIDE_EVENTS.mainSeqStepStart, this.onTransitionStart);
|
|
154
|
-
slide.on(SLIDE_EVENTS.mainSeqStepEnd, this.onTransitionEnd);
|
|
155
|
-
slide.on(SLIDE_EVENTS.renderError, this.onError);
|
|
156
|
-
slide.on(SLIDE_EVENTS.renderEnd, this.resolveReady);
|
|
157
|
-
|
|
158
|
-
this.readyPromise.then(this.refreshPages);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
protected onPageChanged = (page: number) => {
|
|
162
|
-
this.viewer.setPageIndex(page - 1);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
protected onTransitionStart = () => {
|
|
166
|
-
this.viewer.setPlaying();
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
protected onTransitionEnd = () => {
|
|
170
|
-
this.viewer.setPaused();
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
protected onError = ({ error }: { error: Error }) => {
|
|
174
|
-
this.viewer.setPaused();
|
|
175
|
-
console.warn("[Slide] render error", error);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
private destroyed = false;
|
|
179
|
-
public destroy() {
|
|
180
|
-
this.sideEffect.flushAll();
|
|
181
|
-
if (this.slide && !this.destroyed) {
|
|
182
|
-
this.slide.destroy();
|
|
183
|
-
this.destroyed = true;
|
|
184
|
-
}
|
|
185
|
-
this.viewer.destroy();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
protected refreshPages = () => {
|
|
189
|
-
if (this.slide) {
|
|
190
|
-
this.viewer.pages = createDocsViewerPages(this.slide);
|
|
191
|
-
this.viewer.setPageIndex(this.getPageIndex(this.slide.slideState.currentSlideIndex));
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
protected getPageIndex(page: number) {
|
|
196
|
-
return (page > 0 ? page : 1) - 1;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
protected renderSlideContainer(): HTMLDivElement {
|
|
200
|
-
if (!this.$slide) {
|
|
201
|
-
const $slide = document.createElement("div");
|
|
202
|
-
$slide.className = this.wrapClassName("slide");
|
|
203
|
-
$slide.dataset.appKind = "Slide";
|
|
204
|
-
this.$slide = $slide;
|
|
205
|
-
}
|
|
206
|
-
return this.$slide;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
protected onPlay = () => {
|
|
210
|
-
if (this.slide) {
|
|
211
|
-
this.slide.nextStep();
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
protected onNewPageIndex = (index: number) => {
|
|
216
|
-
if (this.slide && this.slide.slideCount > 0) {
|
|
217
|
-
this.slide.renderSlide(clamp(index + 1, 1, this.slide.slideCount));
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
protected wrapClassName(className: string) {
|
|
222
|
-
return `${this.namespace}-${className}`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
protected namespace = "netless-app-slide";
|
|
226
|
-
}
|
package/src/utils/bgcolor.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import ColorString from "color-string";
|
|
2
|
-
import { log } from "./logger";
|
|
3
|
-
|
|
4
|
-
export function guessBgColor(el: HTMLElement): string {
|
|
5
|
-
try {
|
|
6
|
-
const bg = window.getComputedStyle(el).backgroundColor;
|
|
7
|
-
if (bg !== "rgba(0, 0, 0, 0)" && bg !== "transparent") {
|
|
8
|
-
return bg;
|
|
9
|
-
}
|
|
10
|
-
if (el.parentElement) {
|
|
11
|
-
return guessBgColor(el.parentElement);
|
|
12
|
-
}
|
|
13
|
-
} catch {
|
|
14
|
-
// ignore any error
|
|
15
|
-
}
|
|
16
|
-
return "#ffffff";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function toHex(color: string): string {
|
|
20
|
-
const result = ColorString.get(color);
|
|
21
|
-
if (result && result.model === "rgb") {
|
|
22
|
-
const args = result.value;
|
|
23
|
-
|
|
24
|
-
// https://github.com/Qix-/color-convert/blob/8dfdbbc6b46fa6a305bf394d942cc1b08e23fca5/conversions.js#L616
|
|
25
|
-
const integer =
|
|
26
|
-
((Math.round(args[0]) & 0xff) << 16) +
|
|
27
|
-
((Math.round(args[1]) & 0xff) << 8) +
|
|
28
|
-
(Math.round(args[2]) & 0xff);
|
|
29
|
-
|
|
30
|
-
const string = integer.toString(16);
|
|
31
|
-
return "#" + "000000".substring(string.length) + string;
|
|
32
|
-
} else {
|
|
33
|
-
return color;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let cachedBgColor = "";
|
|
38
|
-
|
|
39
|
-
export function cachedGetBgColor(el: HTMLElement): string {
|
|
40
|
-
if (!cachedBgColor) {
|
|
41
|
-
cachedBgColor = toHex(guessBgColor(el));
|
|
42
|
-
log("[Slide] guess bg color", cachedBgColor);
|
|
43
|
-
}
|
|
44
|
-
return cachedBgColor;
|
|
45
|
-
}
|
package/src/utils/freezer.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { RegisterParams } from "@netless/window-manager";
|
|
2
|
-
import { log } from "./logger";
|
|
3
|
-
|
|
4
|
-
export interface FreezableSlide {
|
|
5
|
-
freeze: () => void;
|
|
6
|
-
unfreeze: () => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export let useFreezer = false;
|
|
10
|
-
export const FreezerLength = 2;
|
|
11
|
-
|
|
12
|
-
const inspect = (arr: string[]) => {
|
|
13
|
-
return "[" + arr + "]";
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const apps = {
|
|
17
|
-
map: new Map<string, FreezableSlide>(),
|
|
18
|
-
queue: [] as string[],
|
|
19
|
-
validateQueue() {
|
|
20
|
-
log("[Slide] freezer: validate", inspect(this.queue));
|
|
21
|
-
while (this.queue.length > FreezerLength) {
|
|
22
|
-
const appId = this.queue.pop() as string;
|
|
23
|
-
const slide = this.map.get(appId);
|
|
24
|
-
if (slide) {
|
|
25
|
-
log("[Slide] freezer: validate-freeze", appId, inspect(this.queue));
|
|
26
|
-
slide.freeze();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
set(appId: string, slide: FreezableSlide) {
|
|
31
|
-
log("[Slide] freezer: add", appId, inspect(this.queue));
|
|
32
|
-
this.map.set(appId, slide);
|
|
33
|
-
if (!this.queue.includes(appId)) {
|
|
34
|
-
this.queue.unshift(appId);
|
|
35
|
-
}
|
|
36
|
-
this.validateQueue();
|
|
37
|
-
},
|
|
38
|
-
delete(appId: string) {
|
|
39
|
-
this.map.delete(appId);
|
|
40
|
-
this.queue = this.queue.filter(id => id !== appId);
|
|
41
|
-
log("[Slide] freezer: delete", appId, inspect(this.queue));
|
|
42
|
-
},
|
|
43
|
-
focus(appId: string) {
|
|
44
|
-
const slide = this.map.get(appId);
|
|
45
|
-
const index = this.queue.indexOf(appId);
|
|
46
|
-
if (index > -1) {
|
|
47
|
-
this.queue.splice(index, 1);
|
|
48
|
-
}
|
|
49
|
-
this.queue.unshift(appId);
|
|
50
|
-
this.validateQueue();
|
|
51
|
-
log("[Slide] freezer: focus", appId, inspect(this.queue));
|
|
52
|
-
if (slide) {
|
|
53
|
-
slide.unfreeze();
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (import.meta.env.DEV) {
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
(window as any).freezer = apps;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type AddHooks = NonNullable<RegisterParams["addHooks"]>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Put this function in your register code:
|
|
67
|
-
* `WindowManager.register({ addHooks })`
|
|
68
|
-
* So that it will automatically freeze the app when it is not in focus.
|
|
69
|
-
*/
|
|
70
|
-
export const addHooks: AddHooks = emitter => {
|
|
71
|
-
useFreezer = true;
|
|
72
|
-
emitter.on("focus", ({ appId }) => {
|
|
73
|
-
apps.focus(appId);
|
|
74
|
-
});
|
|
75
|
-
};
|
package/src/utils/helpers.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function clamp(value: number, min: number, max: number): number {
|
|
2
|
-
return Math.min(Math.max(value, min), max);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function flattenEvent(ev: MouseEvent | TouchEvent): MouseEvent | Touch {
|
|
6
|
-
return (ev as TouchEvent).touches ? (ev as TouchEvent).touches[0] : (ev as MouseEvent);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function preventEvent(ev: Event): void {
|
|
10
|
-
ev.stopPropagation();
|
|
11
|
-
if (ev.cancelable) {
|
|
12
|
-
ev.preventDefault();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function isObj(obj: unknown) {
|
|
17
|
-
return typeof obj === "object" && obj !== null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function wait(ms: number) {
|
|
21
|
-
return new Promise<void>(resolve => setTimeout(resolve, ms));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function deepClone<T>(obj: T): T {
|
|
25
|
-
return JSON.parse(JSON.stringify(obj));
|
|
26
|
-
}
|
package/src/utils/logger.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import type { AppContext, Displayer } from "@netless/window-manager";
|
|
3
|
-
import type { SlideController } from "../SlideController";
|
|
4
|
-
import { isObj } from "./helpers";
|
|
5
|
-
|
|
6
|
-
type DebugMessage = { slide: boolean | "__instance" | "__debug" };
|
|
7
|
-
|
|
8
|
-
type RoomLogger = {
|
|
9
|
-
debug: (...args: any) => void;
|
|
10
|
-
info: (...args: any) => void;
|
|
11
|
-
warn: (...args: any) => void;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
class Logger {
|
|
15
|
-
public apps: Record<
|
|
16
|
-
string,
|
|
17
|
-
{ context?: AppContext | null; controller?: SlideController | null }
|
|
18
|
-
> = {};
|
|
19
|
-
|
|
20
|
-
setAppContext(appId: string, context: AppContext | null) {
|
|
21
|
-
(this.apps[appId] ||= {}).context = context;
|
|
22
|
-
this.log(`[Slide] new ${appId}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
setAppController(appId: string, controller: SlideController | null) {
|
|
26
|
-
(this.apps[appId] ||= {}).controller = controller;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
deleteApp(appId: string) {
|
|
30
|
-
delete this.apps[appId];
|
|
31
|
-
this.log(`[Slide] delete ${appId}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public level: "debug" | "verbose" = import.meta.env.DEV ? "verbose" : "debug";
|
|
35
|
-
|
|
36
|
-
public roomLogger: RoomLogger | null = null;
|
|
37
|
-
|
|
38
|
-
constructor(public enable: boolean) {
|
|
39
|
-
this.initialize();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
initialize() {
|
|
43
|
-
window.addEventListener("message", this._onMessage);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
dispose() {
|
|
47
|
-
window.removeEventListener("message", this._onMessage);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
log(...args: any[]) {
|
|
51
|
-
if (this.roomLogger) {
|
|
52
|
-
this.roomLogger.info(...args);
|
|
53
|
-
} else if (this.enable) {
|
|
54
|
-
console.log(...args);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
verbose(...args: any[]) {
|
|
59
|
-
if (this.roomLogger) {
|
|
60
|
-
this.roomLogger.debug(...args);
|
|
61
|
-
} else if (this.enable && this.level === "verbose") {
|
|
62
|
-
console.log(...args);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
warn(...args: any[]) {
|
|
67
|
-
if (this.roomLogger) {
|
|
68
|
-
this.roomLogger.warn(...args);
|
|
69
|
-
} else {
|
|
70
|
-
console.warn(...args);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @example
|
|
76
|
-
* window.postMessage({ slide: '__debug' })
|
|
77
|
-
* window.dispatchEvent(new MessageEvent('message', { data: { slide: '__debug' } }))
|
|
78
|
-
*/
|
|
79
|
-
_onMessage = (ev: MessageEvent<DebugMessage> | CustomEvent<DebugMessage>) => {
|
|
80
|
-
let data: DebugMessage | undefined;
|
|
81
|
-
if (ev instanceof CustomEvent) {
|
|
82
|
-
data = ev.detail;
|
|
83
|
-
} else if (isObj(ev.data)) {
|
|
84
|
-
data = ev.data;
|
|
85
|
-
}
|
|
86
|
-
if (data) {
|
|
87
|
-
if (typeof data.slide === "boolean") {
|
|
88
|
-
this.enable = data.slide;
|
|
89
|
-
} else if (data.slide === "__instance") {
|
|
90
|
-
console.log(this);
|
|
91
|
-
} else if (data.slide === "__debug") {
|
|
92
|
-
Object.values(this.apps).forEach(app => {
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
(app.controller?.slide as any)?.createController();
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export const logger = /** @__PURE__ */ new Logger(import.meta.env.DEV);
|
|
102
|
-
export const log = /** @__PURE__ */ logger.log.bind(logger);
|
|
103
|
-
export const verbose = /** @__PURE__ */ logger.verbose.bind(logger);
|
|
104
|
-
export const setRoomLogger = (displayer: Displayer) => {
|
|
105
|
-
logger.roomLogger = (displayer as any).logger;
|
|
106
|
-
};
|