@netless/app-slide 0.3.0-canary.2 → 0.3.0-canary.21

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.
Files changed (47) hide show
  1. package/README-zh.md +17 -7
  2. package/README.md +4 -7
  3. package/dist/Logger.d.ts +12 -0
  4. package/dist/Refrigerator.d.ts +3 -1
  5. package/dist/SlideViewer/footer.d.ts +12 -0
  6. package/dist/{SlideViewer.d.ts → SlideViewer/index.d.ts} +33 -20
  7. package/dist/SlideViewer/sidebar.d.ts +12 -0
  8. package/dist/SlideViewer/typings.d.ts +18 -0
  9. package/dist/SlideViewer/utils.d.ts +7 -0
  10. package/dist/connect.d.ts +14 -0
  11. package/dist/constants.d.ts +1 -1
  12. package/dist/icons/index.d.ts +5 -0
  13. package/dist/icons/save.d.ts +1 -0
  14. package/dist/icons/spinner.d.ts +1 -0
  15. package/dist/index.d.ts +7 -6
  16. package/dist/main.js +3 -0
  17. package/dist/main.js.map +1 -0
  18. package/dist/main.mjs +1406 -0
  19. package/dist/main.mjs.map +1 -0
  20. package/dist/preview.d.ts +5 -0
  21. package/dist/typings.d.ts +9 -18
  22. package/dist/utils.d.ts +12 -0
  23. package/package.json +12 -8
  24. package/src/Logger.ts +38 -0
  25. package/src/Refrigerator.ts +11 -1
  26. package/src/SlideViewer/footer.ts +169 -0
  27. package/src/SlideViewer/index.ts +329 -0
  28. package/src/SlideViewer/sidebar.ts +140 -0
  29. package/src/SlideViewer/typings.ts +21 -0
  30. package/src/SlideViewer/utils.ts +37 -0
  31. package/src/connect.ts +152 -0
  32. package/src/constants.ts +1 -1
  33. package/src/icons/index.ts +5 -0
  34. package/src/icons/save.ts +18 -0
  35. package/src/icons/spinner.ts +37 -0
  36. package/src/index.ts +64 -192
  37. package/src/preview.ts +21 -0
  38. package/src/style.scss +67 -16
  39. package/src/typings.ts +18 -16
  40. package/src/utils.ts +90 -0
  41. package/dist/main.cjs.js +0 -6363
  42. package/dist/main.cjs.js.map +0 -1
  43. package/dist/main.es.js +0 -38214
  44. package/dist/main.es.js.map +0 -1
  45. package/dist/main.iife.js +0 -6363
  46. package/dist/main.iife.js.map +0 -1
  47. package/src/SlideViewer.ts +0 -557
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,12 +19,13 @@ $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 {
17
26
  display: none;
18
27
  position: absolute;
19
- z-index: 6000;
28
+ z-index: 10200;
20
29
  top: 0;
21
30
  left: 0;
22
31
  width: 100%;
@@ -28,7 +37,7 @@ $namespace: "netless-app-slide";
28
37
  flex-direction: column;
29
38
  align-items: center;
30
39
  position: absolute;
31
- z-index: 6100;
40
+ z-index: 10300;
32
41
  top: 0;
33
42
  left: 0;
34
43
  width: 33%;
@@ -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: none;
75
+ @include no-user-select;
66
76
 
67
77
  &:hover,
68
78
  &.#{$namespace}-preview-page-active {
@@ -88,7 +98,25 @@ $namespace: "netless-app-slide";
88
98
  text-align: right;
89
99
  font-size: 12px;
90
100
  color: #5f5f5f;
91
- user-select: none;
101
+ @include no-user-select;
102
+ }
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
+ padding: 10px;
115
+ box-sizing: border-box;
116
+ background: rgba(255, 0, 0, 0.25);
117
+ transition: opacity 0.3s;
118
+ opacity: 0;
119
+ pointer-events: none;
92
120
  }
93
121
 
94
122
  .#{$namespace}-footer {
@@ -98,7 +126,8 @@ $namespace: "netless-app-slide";
98
126
  align-items: center;
99
127
  padding: 0 16px;
100
128
  border-top: 1px solid #eeeef7;
101
- color: #191919;
129
+ font-family: system-ui, -apple-system, "Segoe UI", "Roboto", "Ubuntu", "Cantarell", "Noto Sans",
130
+ sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
102
131
  }
103
132
 
104
133
  .#{$namespace}-float-footer {
@@ -126,7 +155,7 @@ $namespace: "netless-app-slide";
126
155
  background: transparent;
127
156
  transition: background 0.4s;
128
157
  cursor: pointer;
129
- user-select: none;
158
+ @include no-user-select;
130
159
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
131
160
 
132
161
  &:hover {
@@ -171,11 +200,15 @@ $namespace: "netless-app-slide";
171
200
  }
172
201
 
173
202
  .#{$namespace}-page-number {
203
+ display: flex;
204
+ align-items: center;
205
+ height: 26px;
174
206
  margin-left: auto;
175
207
  font-size: 13px;
176
- user-select: none;
208
+ @include no-user-select;
177
209
  white-space: nowrap;
178
210
  word-break: keep-all;
211
+ font-variant-numeric: tabular-nums;
179
212
  }
180
213
 
181
214
  .#{$namespace}-page-number-input {
@@ -183,22 +216,24 @@ $namespace: "netless-app-slide";
183
216
  outline: none;
184
217
  width: 3em;
185
218
  margin: 0;
186
- padding: 0 2px;
219
+ padding: 0 0.5em 0 2px;
187
220
  text-align: right;
188
221
  font-size: 13px;
189
222
  line-height: 1;
190
223
  font-weight: normal;
191
- font-family: inherit;
192
224
  border-radius: 2px;
193
225
  color: currentColor;
226
+ font-family: system-ui, -apple-system, "Segoe UI", "Roboto", "Ubuntu", "Cantarell", "Noto Sans",
227
+ sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
194
228
  background: transparent;
195
229
  transition: background 0.4s;
196
- user-select: text;
230
+ font-variant-numeric: tabular-nums;
197
231
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
198
232
 
199
233
  &:hover,
200
234
  &:focus,
201
235
  &:active {
236
+ user-select: text;
202
237
  background: #fff;
203
238
  box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
204
239
  }
@@ -233,18 +268,18 @@ $namespace: "netless-app-slide";
233
268
  }
234
269
  }
235
270
 
271
+ .#{$namespace}-wb-view-hidden {
272
+ display: none;
273
+ }
274
+
236
275
  .telebox-color-scheme-dark {
237
- .#{$namespace}-page-number-input {
238
- color: #a6a6a8;
239
- }
240
276
  .#{$namespace}-page-number-input:active,
241
277
  .#{$namespace}-page-number-input:focus,
242
278
  .#{$namespace}-page-number-input:hover {
243
- color: #222;
279
+ color: currentColor;
280
+ background: #25282e;
244
281
  }
245
282
  .#{$namespace}-footer {
246
- color: #a6a6a8;
247
- background: #2d2d33;
248
283
  border-top: none;
249
284
  }
250
285
  .#{$namespace}-footer-btn:hover {
@@ -254,3 +289,19 @@ $namespace: "netless-app-slide";
254
289
  background: rgba(50, 50, 50, 0.9);
255
290
  }
256
291
  }
292
+
293
+ .#{$namespace}-preview-wrapper {
294
+ width: 100%;
295
+ height: 100%;
296
+ overflow: hidden;
297
+ display: flex;
298
+ flex-flow: column nowrap;
299
+
300
+ .#{$namespace}-content {
301
+ flex: 1;
302
+ }
303
+
304
+ .#{$namespace}-footer {
305
+ flex-shrink: 0;
306
+ }
307
+ }
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,21 @@ export interface MagixEvents {
18
18
  [SLIDE_EVENTS.syncDispatch]: SyncEvent;
19
19
  }
20
20
 
21
- export interface AppOptions {
22
- /** show debug controller */
23
- debug?: boolean;
24
- /** scale */
25
- resolution?: number;
26
- /** background color for slide animations */
27
- bgColor?: string;
28
- /** minimal fps (default: 25) */
29
- minFPS?: number;
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;
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
+ > {}
33
+
34
+ export interface ILogger {
35
+ info?(msg: string): void;
36
+ error?(msg: string): void;
37
+ warn?(msg: string): void;
36
38
  }
package/src/utils.ts CHANGED
@@ -1,3 +1,93 @@
1
+ import type { AppContext, Player } from "@netless/window-manager";
2
+
3
+ import ColorString from "color-string";
4
+ import { class_name } from "./constants";
5
+
1
6
  export function noop() {
2
7
  return;
3
8
  }
9
+
10
+ export function h<K extends keyof HTMLElementTagNameMap>(tag: K) {
11
+ return document.createElement(tag);
12
+ }
13
+
14
+ export function hc<K extends keyof HTMLElementTagNameMap>(tag: K, name: string) {
15
+ const el = h(tag);
16
+ set_class(el, name);
17
+ return el;
18
+ }
19
+
20
+ export function append(parent: HTMLElement, child: HTMLElement) {
21
+ return parent.appendChild(child);
22
+ }
23
+
24
+ export function wrap_class(name: string) {
25
+ return `${class_name}-${name}`;
26
+ }
27
+
28
+ export function set_class(el: HTMLElement, name: string) {
29
+ el.className = wrap_class(name);
30
+ }
31
+
32
+ export function trim_slash(s: string) {
33
+ return s.endsWith("/") ? s.slice(0, -1) : s;
34
+ }
35
+
36
+ export function get(o: unknown, k: string): unknown {
37
+ if (typeof o === "object" && o !== null) return (o as Record<string, unknown>)[k];
38
+ }
39
+
40
+ export function block<T = void>(): [p: Promise<T>, resolve: (t: T) => void] {
41
+ let resolve!: (t: T) => void;
42
+ const p = new Promise<T>(r => {
43
+ resolve = r;
44
+ });
45
+ return [p, resolve];
46
+ }
47
+
48
+ export function make_timestamp(context: AppContext): () => number {
49
+ const room = context.room;
50
+ const player = context.displayer as Player;
51
+ if (room) {
52
+ return () => room.calibrationTimestamp;
53
+ } else if (player) {
54
+ return () => player.beginTimestamp + player.progressTime;
55
+ } else {
56
+ return () => Date.now();
57
+ }
58
+ }
59
+
60
+ export function make_bg_color(el: HTMLElement): string {
61
+ try {
62
+ let bg = window.getComputedStyle(el).backgroundColor;
63
+ if (bg !== "rgba(0, 0, 0, 0)" && bg !== "transparent") {
64
+ bg = hex(bg);
65
+ console.log("[Slide] guess bg color:", bg);
66
+ return bg;
67
+ }
68
+ if (el.parentElement) {
69
+ return make_bg_color(el.parentElement);
70
+ }
71
+ } catch {
72
+ // ignored
73
+ }
74
+ return "#ffffff";
75
+ }
76
+
77
+ // https://github.com/Qix-/color-convert/blob/8dfdbbc6b46fa6a305bf394d942cc1b08e23fca5/conversions.js#L616
78
+ export function hex(color: string): string {
79
+ const result = ColorString.get(color);
80
+ if (result && result.model === "rgb") {
81
+ const args = result.value;
82
+
83
+ const integer =
84
+ ((Math.round(args[0]) & 0xff) << 16) +
85
+ ((Math.round(args[1]) & 0xff) << 8) +
86
+ (Math.round(args[2]) & 0xff);
87
+
88
+ const string = integer.toString(16);
89
+ return "#" + "000000".substring(string.length) + string;
90
+ } else {
91
+ return color;
92
+ }
93
+ }