@netless/app-presentation 0.1.9-beta.3 → 0.1.9-beta.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/app-presentation",
3
- "version": "0.1.9-beta.3",
3
+ "version": "0.1.9-beta.5",
4
4
  "description": "Netless App for presentation slides (images)",
5
5
  "author": "netless",
6
6
  "license": "MIT",
@@ -72,6 +72,8 @@ export interface PresentationController {
72
72
  moveCamera: (camera: { centerX: number, centerY: number, scale: number }) => void;
73
73
  /** get the origin scale */
74
74
  getOriginScale: () => number;
75
+ /** get the view scale */
76
+ getScale: () =>number;
75
77
  }
76
78
 
77
79
  export { styles }
@@ -391,6 +393,10 @@ export const NetlessAppPresentation: NetlessApp<{}, {}, PresentationAppOptions,
391
393
  return Math.min(size.height / height, size.width / width);
392
394
  }
393
395
 
396
+ const getScale =() => {
397
+ return view.camera.scale
398
+ }
399
+
394
400
  const moveCamera = (camera: { centerX: number, centerY: number, scale: number }) => {
395
401
  if (context.getIsWritable()) {
396
402
  view.moveCamera({...camera, animationMode: 'immediately' as AnimationMode});
@@ -404,6 +410,7 @@ export const NetlessAppPresentation: NetlessApp<{}, {}, PresentationAppOptions,
404
410
  if (options.useScrollbar) {
405
411
  dispose.make(() => {
406
412
  scrollbar = new Scrollbar(app.contentDOM, {
413
+ appId: context.appId,
407
414
  getPageSize,
408
415
  getOriginScale,
409
416
  syncView,
@@ -540,7 +547,7 @@ export const NetlessAppPresentation: NetlessApp<{}, {}, PresentationAppOptions,
540
547
  }
541
548
  }
542
549
 
543
- const controller: PresentationController = { app, view, context, jumpPage, prevPage, nextPage, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale }
550
+ const controller: PresentationController = { app, view, context, jumpPage, prevPage, nextPage, pageState, toPdf, log, setDocsViewReadonly, setReadonly, moveCamera, getOriginScale, getScale }
544
551
 
545
552
  dispose.add(listen(window, 'message', (ev: MessageEvent<"@netless/_presentation_">) => {
546
553
  if (ev.data === "@netless/_presentation_") {
@@ -4,6 +4,7 @@ import { makeDraggable } from "./Draggable";
4
4
  import { debounce } from 'lodash';
5
5
 
6
6
  export interface ScrollbarOption {
7
+ appId: string;
7
8
  readonly?: boolean;
8
9
  getPageSize: () => {
9
10
  width: number;
@@ -20,14 +21,16 @@ export interface ScrollbarEventCallback {
20
21
  onScrollbarDragEnd?: () => void;
21
22
  onScrollbarDragX?: (x: number) => void;
22
23
  onScrollbarDragY?: (y: number) => void;
23
- onScrollCameraUpdated?: (originScale: number, scale: number) => void;
24
- }
24
+ onScrollCameraUpdated?: (appid: string, originScale: number, scale: number) => void;
25
+ }
25
26
 
26
27
  export class Scrollbar {
27
28
  readonly namespace = "netless-app-presentation"
29
+ readonly appId: string;
28
30
  private container: HTMLElement;
29
31
  private scrollContainer: HTMLDivElement = document.createElement('div');
30
32
  private option: ScrollbarOption = {
33
+ appId: '',
31
34
  getPageSize: () => {
32
35
  return {
33
36
  width: 0,
@@ -55,6 +58,7 @@ export class Scrollbar {
55
58
  this.scrollContainer.className = this.c('scrollbar-container');
56
59
  this.container = container;
57
60
  this.option = option;
61
+ this.appId = option.appId;
58
62
  this.readonly = option.readonly || false;
59
63
  this.view = view;
60
64
  this.init();
@@ -65,9 +69,8 @@ export class Scrollbar {
65
69
 
66
70
  setReadonly(bol: boolean){
67
71
  this.readonly = bol;
68
- if (this.readonly) {
69
- this.destroy()
70
- } else {
72
+ this.destroy()
73
+ if (!this.readonly) {
71
74
  this.init();
72
75
  }
73
76
  }
@@ -89,7 +92,7 @@ export class Scrollbar {
89
92
  this.scrollbarY.style.display = ratio === 1 ? 'none' : 'block';
90
93
  this.scrollbarY.style.transform = `translateY(${scrollY}px)`;
91
94
  }
92
- this.option.scrollbarEventCallback?.onScrollCameraUpdated?.(originScale, scale);
95
+ this.option.scrollbarEventCallback?.onScrollCameraUpdated?.(this.appId, originScale, scale);
93
96
  }, 50)
94
97
 
95
98
  onDragStart = () => {
@@ -215,15 +218,27 @@ export class Scrollbar {
215
218
 
216
219
  destroy() {
217
220
  this.view.callbacks.off('onCameraUpdated', this.onCameraUpdated);
218
- this.scrollbarX?.remove();
219
- this.scrollbarY?.remove();
220
- this.scrollbarX = undefined;
221
- this.scrollbarY = undefined;
222
-
223
- this.draggableX?.destroy();
224
- this.draggableY?.destroy();
225
- this.draggableX = undefined;
226
- this.draggableY = undefined;
221
+ if (this.scrollbarX && this.scrollbarContainerX) {
222
+ this.scrollbarContainerX.removeChild(this.scrollbarX);
223
+ this.scrollbarX.remove();
224
+ this.scrollbarContainerX.remove();
225
+ this.scrollbarX = undefined;
226
+ }
227
+ if (this.scrollbarY && this.scrollbarContainerY) {
228
+ this.scrollbarContainerY.removeChild(this.scrollbarY);
229
+ this.scrollbarY.remove();
230
+ this.scrollbarContainerY.remove();
231
+ this.scrollbarY = undefined;
232
+ }
233
+ if (this.draggableX) {
234
+ this.draggableX.destroy();
235
+ this.draggableX = undefined;
236
+ }
237
+ if (this.draggableY) {
238
+ this.draggableY.destroy();
239
+ this.draggableY = undefined;
240
+ }
241
+
227
242
  }
228
243
 
229
244
  }