@netless/app-slide 0.3.0-canary.1 → 0.3.0-canary.4

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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@netless/app-slide",
3
- "version": "0.3.0-canary.1",
4
- "main": "dist/main.cjs.js",
5
- "module": "dist/main.es.js",
3
+ "version": "0.3.0-canary.4",
4
+ "main": "dist/main.js",
5
+ "module": "dist/main.mjs",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "src",
@@ -10,10 +10,10 @@
10
10
  "README-zh.md"
11
11
  ],
12
12
  "devDependencies": {
13
- "@netless/slide": "^0.4.7",
13
+ "@netless/slide": "^0.5.3",
14
14
  "@types/color-string": "^1.5.2",
15
15
  "color-string": "^1.9.1",
16
- "side-effect-manager": "^1.1.0",
16
+ "side-effect-manager": "^1.1.1",
17
17
  "value-enhancer": "^1.3.0",
18
18
  "vanilla-lazyload": "^17.8.2"
19
19
  },
@@ -371,7 +371,10 @@ function on_visibility_change(callback: (visible: boolean) => void) {
371
371
  return noop;
372
372
  }
373
373
 
374
- export type SlideViewerOptions = Omit<ISlideConfig, "anchor"> & SlideAttributes;
374
+ export type SlideViewerOptions = Omit<ISlideConfig, "anchor" | "mode" | "interactive"> & {
375
+ mode?: ISlideConfig["mode"];
376
+ interactive?: ISlideConfig["interactive"];
377
+ } & SlideAttributes;
375
378
 
376
379
  export interface SlideViewerInfoResponse {
377
380
  width: number;
@@ -426,6 +429,11 @@ export class SlideViewer {
426
429
 
427
430
  this.sideEffect.addDisposer(this.sidebar.destroy);
428
431
  this.sideEffect.addDisposer(() => this.slide.destroy());
432
+ this.sideEffect.addDisposer(() => {
433
+ this.$content.parentElement && this.$content.remove();
434
+ this.$footer.parentElement && this.$footer.remove();
435
+ this.$slide.parentElement && this.$slide.remove();
436
+ });
429
437
 
430
438
  let saved_is_frozen = false;
431
439
  this.sideEffect.addDisposer(
@@ -443,6 +451,8 @@ export class SlideViewer {
443
451
  this.slide = new Slide({
444
452
  anchor: this.$slide,
445
453
  resize: true,
454
+ mode: "local",
455
+ interactive: true,
446
456
  enableGlobalClick: true,
447
457
  ...options,
448
458
  });
@@ -453,6 +463,11 @@ export class SlideViewer {
453
463
  resolveFetching = resolve;
454
464
  });
455
465
 
466
+ this.slide.on("slideChange", page => {
467
+ if (this._destroyed) return;
468
+ this.setPage(page);
469
+ });
470
+
456
471
  this.slide.on("renderEnd", () => {
457
472
  if (!this._ready)
458
473
  setTimeout(() => {
@@ -523,25 +538,18 @@ export class SlideViewer {
523
538
  }
524
539
 
525
540
  private _isFrozen = false;
526
- private _freezePromise: Promise<void> | null = null;
527
541
 
528
542
  freeze() {
529
543
  if (this._destroyed) return;
530
544
  this._isFrozen = true;
531
- if (!this._ready || this._freezePromise) return;
532
- this._freezePromise = this.slide.frozen().then(() => {
533
- this._freezePromise = null;
534
- if (!this._isFrozen) this.unfreeze();
535
- });
545
+ if (!this._ready) return;
546
+ this.slide.frozen();
536
547
  }
537
548
 
538
549
  unfreeze() {
539
550
  if (this._destroyed) return;
540
551
  this._isFrozen = false;
541
- if (!this._ready || this._freezePromise) return;
542
- this._freezePromise = this.slide.release().then(() => {
543
- this._freezePromise = null;
544
- if (this._isFrozen) this.freeze();
545
- });
552
+ if (!this._ready) return;
553
+ this.slide.release();
546
554
  }
547
555
  }
package/src/index.ts CHANGED
@@ -8,7 +8,6 @@ import ColorString from "color-string";
8
8
  import { SideEffectManager } from "side-effect-manager";
9
9
  import { SlideViewer } from "./SlideViewer";
10
10
  import { refrigerator, addHooks } from "./Refrigerator";
11
- import { noop } from "./utils";
12
11
 
13
12
  export { SlideViewer, refrigerator, addHooks };
14
13
 
@@ -24,19 +23,19 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
24
23
  }
25
24
 
26
25
  const options = context.getAppOptions() || {};
27
- const debug = Boolean(options.debug);
26
+ const logger = make_logger(context);
27
+ logger.info("[Slide] setup @ " + __APP_VERSION__);
28
28
 
29
29
  const sideEffect = new SideEffectManager();
30
30
 
31
- // create ui
31
+ // Create UI
32
32
  const viewer = new SlideViewer({
33
33
  interactive: true,
34
34
  mode: "interactive",
35
35
  resize: true,
36
36
  enableGlobalClick: true,
37
- controller: debug,
38
37
  timestamp: make_timestamp(context),
39
- logger: make_logger(context),
38
+ logger,
40
39
  renderOptions: {
41
40
  minFPS: options.minFPS || 25,
42
41
  maxFPS: options.maxFPS || 30,
@@ -61,18 +60,18 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, void> = {
61
60
  (window as any).slideViewer = viewer;
62
61
  }
63
62
 
64
- // mount ui
63
+ // Mount UI
65
64
  context.box.mountStyles(SlideViewer.styles);
66
65
  context.box.mountStage(viewer.$slide);
67
66
  context.box.mountFooter(viewer.$footer);
68
67
  context.box.mountContent(viewer.$content);
69
68
  sideEffect.addDisposer(() => viewer.destroy());
70
69
 
71
- // connect ui with netless app
72
- connect({ context, viewer, sideEffect, debug });
70
+ // Connect UI with Netless App
71
+ connect({ context, viewer, sideEffect, logger });
73
72
 
74
73
  onUnmount(context, () => {
75
- console.log("[Slide] destroy");
74
+ logger.info("[Slide] destroy");
76
75
  sideEffect.flushAll();
77
76
  });
78
77
  },
@@ -88,10 +87,14 @@ export function previewSlide(options: SlideViewerOptions & { container: HTMLElem
88
87
  container.appendChild(viewer.$content);
89
88
  container.appendChild(viewer.$footer);
90
89
  viewer.prepare(() => viewer.slide.renderSlide(1));
91
- viewer.slide.on("slideChange", page => viewer.setPage(page));
92
90
  return viewer;
93
91
  }
94
92
 
93
+ if (import.meta.env.DEV) {
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ (window as any).previewSlide = previewSlide;
96
+ }
97
+
95
98
  function make_timestamp(context: AppContext): () => number {
96
99
  const room = context.room;
97
100
  const player = context.displayer as Player;
@@ -104,7 +107,7 @@ function make_timestamp(context: AppContext): () => number {
104
107
  }
105
108
  }
106
109
 
107
- function make_logger(context: AppContext) {
110
+ function make_logger(context: AppContext): { info: (msg: string) => void } {
108
111
  if (import.meta.env.DEV) {
109
112
  return { info: console.debug.bind(console) };
110
113
  }
@@ -155,18 +158,19 @@ interface ConnectParams {
155
158
  context: AppContext;
156
159
  viewer: SlideViewer;
157
160
  sideEffect: SideEffectManager;
158
- debug: boolean;
161
+ logger: { info: (msg: string) => void };
159
162
  }
160
163
 
161
- function connect({ context, viewer, sideEffect, debug }: ConnectParams) {
162
- const log = debug ? console.log.bind(console) : noop;
164
+ function connect({ context, viewer, sideEffect, logger }: ConnectParams) {
165
+ const log = import.meta.env.DEV ? console.log.bind(console) : logger.info.bind(logger);
163
166
 
164
167
  let whiteboard: WhiteBoardView | null = null;
165
168
 
166
169
  viewer.prepare(({ width, height, slideCount }) => {
167
170
  if (context.destroyed) return;
168
171
  width && context.box.setStageRatio(height / width);
169
- whiteboard = context.createWhiteBoardView(slideCount);
172
+ whiteboard = context.createWhiteBoardView({ size: slideCount });
173
+ whiteboard.setBaseRect({ width, height });
170
174
  kick_start();
171
175
  });
172
176
 
@@ -229,9 +233,10 @@ function connect({ context, viewer, sideEffect, debug }: ConnectParams) {
229
233
 
230
234
  // save state
231
235
  slide.on("slideChange", page => {
232
- log("[Slide] page to", page);
233
- whiteboard && whiteboard.jumpPage(page - 1);
234
- viewer.setPage(page);
236
+ if (context.isWritable && whiteboard) {
237
+ log("[Slide] page to", page);
238
+ whiteboard.jumpPage(page - 1);
239
+ }
235
240
  });
236
241
 
237
242
  // handle ui events
package/src/style.scss CHANGED
@@ -16,7 +16,7 @@ $namespace: "netless-app-slide";
16
16
  .#{$namespace}-preview-mask {
17
17
  display: none;
18
18
  position: absolute;
19
- z-index: 6000;
19
+ z-index: 10200;
20
20
  top: 0;
21
21
  left: 0;
22
22
  width: 100%;
@@ -28,7 +28,7 @@ $namespace: "netless-app-slide";
28
28
  flex-direction: column;
29
29
  align-items: center;
30
30
  position: absolute;
31
- z-index: 6100;
31
+ z-index: 10300;
32
32
  top: 0;
33
33
  left: 0;
34
34
  width: 33%;
@@ -98,7 +98,8 @@ $namespace: "netless-app-slide";
98
98
  align-items: center;
99
99
  padding: 0 16px;
100
100
  border-top: 1px solid #eeeef7;
101
- color: #191919;
101
+ font-family: system-ui, -apple-system, "Segoe UI", "Roboto", "Ubuntu", "Cantarell", "Noto Sans",
102
+ sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
102
103
  }
103
104
 
104
105
  .#{$namespace}-float-footer {
@@ -171,11 +172,15 @@ $namespace: "netless-app-slide";
171
172
  }
172
173
 
173
174
  .#{$namespace}-page-number {
175
+ display: flex;
176
+ align-items: center;
177
+ height: 26px;
174
178
  margin-left: auto;
175
179
  font-size: 13px;
176
180
  user-select: none;
177
181
  white-space: nowrap;
178
182
  word-break: keep-all;
183
+ font-variant-numeric: tabular-nums;
179
184
  }
180
185
 
181
186
  .#{$namespace}-page-number-input {
@@ -183,7 +188,7 @@ $namespace: "netless-app-slide";
183
188
  outline: none;
184
189
  width: 3em;
185
190
  margin: 0;
186
- padding: 0 2px;
191
+ padding: 0 0.5em 0 2px;
187
192
  text-align: right;
188
193
  font-size: 13px;
189
194
  line-height: 1;
@@ -191,9 +196,12 @@ $namespace: "netless-app-slide";
191
196
  font-family: inherit;
192
197
  border-radius: 2px;
193
198
  color: currentColor;
199
+ font-family: system-ui, -apple-system, "Segoe UI", "Roboto", "Ubuntu", "Cantarell", "Noto Sans",
200
+ sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
194
201
  background: transparent;
195
202
  transition: background 0.4s;
196
203
  user-select: text;
204
+ font-variant-numeric: tabular-nums;
197
205
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
198
206
 
199
207
  &:hover,
@@ -234,17 +242,13 @@ $namespace: "netless-app-slide";
234
242
  }
235
243
 
236
244
  .telebox-color-scheme-dark {
237
- .#{$namespace}-page-number-input {
238
- color: #a6a6a8;
239
- }
240
245
  .#{$namespace}-page-number-input:active,
241
246
  .#{$namespace}-page-number-input:focus,
242
247
  .#{$namespace}-page-number-input:hover {
243
- color: #222;
248
+ color: currentColor;
249
+ background: #25282e;
244
250
  }
245
251
  .#{$namespace}-footer {
246
- color: #a6a6a8;
247
- background: #2d2d33;
248
252
  border-top: none;
249
253
  }
250
254
  .#{$namespace}-footer-btn:hover {