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

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.2",
3
+ "version": "0.1.9-beta.3",
4
4
  "description": "Netless App for presentation slides (images)",
5
5
  "author": "netless",
6
6
  "license": "MIT",
@@ -33,6 +33,7 @@
33
33
  "@hyrious/esbuild-dev": "^0.10.5",
34
34
  "@netless/fastboard": "^1.0.6",
35
35
  "@netless/window-manager": "^1.0.4",
36
+ "@types/lodash": "^4.17.20",
36
37
  "@types/node": "^20.11.30",
37
38
  "@wopjs/disposable": "^0.1.5",
38
39
  "@wopjs/dom": "^0.1.3",
@@ -42,5 +43,8 @@
42
43
  "sass": "^1.72.0",
43
44
  "vanilla-lazyload": "^18.0.0",
44
45
  "vite": "^5.2.6"
46
+ },
47
+ "dependencies": {
48
+ "lodash": "^4.17.21"
45
49
  }
46
50
  }
@@ -6,7 +6,7 @@ import { listen } from '@wopjs/dom'
6
6
  import styles from './style.scss?inline'
7
7
  import { Presentation, type PresentationConfig, type PresentationPage } from "./presentation";
8
8
  import { readable, type Readable } from "./store";
9
- import { Scrollbar } from "./scrollbar";
9
+ import { Scrollbar, type ScrollbarEventCallback } from "./scrollbar";
10
10
 
11
11
  export type Logger = (...data: any[]) => void
12
12
 
@@ -45,6 +45,7 @@ export interface PresentationAppOptions {
45
45
  useScrollbar?: boolean;
46
46
  /** debounceSync is used to set the presentation debounce sync, it will be used in the presentation, and the presentation will be debounce sync when the app is initialized */
47
47
  debounceSync?: boolean;
48
+ scrollbarEventCallback?: ScrollbarEventCallback
48
49
  }
49
50
 
50
51
  export interface PresentationController {
@@ -407,6 +408,7 @@ export const NetlessAppPresentation: NetlessApp<{}, {}, PresentationAppOptions,
407
408
  getOriginScale,
408
409
  syncView,
409
410
  getWritable: () => context.getIsWritable(),
411
+ scrollbarEventCallback: options.scrollbarEventCallback
410
412
  }, view)
411
413
  return () => scrollbar?.destroy()
412
414
  })
@@ -1,6 +1,7 @@
1
1
  import './style.scss?inline';
2
2
  import type { View, AnimationMode } from "@netless/window-manager";
3
3
  import { makeDraggable } from "./Draggable";
4
+ import { debounce } from 'lodash';
4
5
 
5
6
  export interface ScrollbarOption {
6
7
  readonly?: boolean;
@@ -11,8 +12,17 @@ export interface ScrollbarOption {
11
12
  getWritable: () => boolean;
12
13
  getOriginScale: () => number;
13
14
  syncView: () => void;
15
+ scrollbarEventCallback?: ScrollbarEventCallback;
14
16
  }
15
17
 
18
+ export interface ScrollbarEventCallback {
19
+ onScrollbarDragStart?: () => void;
20
+ onScrollbarDragEnd?: () => void;
21
+ onScrollbarDragX?: (x: number) => void;
22
+ onScrollbarDragY?: (y: number) => void;
23
+ onScrollCameraUpdated?: (originScale: number, scale: number) => void;
24
+ }
25
+
16
26
  export class Scrollbar {
17
27
  readonly namespace = "netless-app-presentation"
18
28
  private container: HTMLElement;
@@ -62,7 +72,7 @@ export class Scrollbar {
62
72
  }
63
73
  }
64
74
 
65
- onCameraUpdated = () => {
75
+ onCameraUpdated = debounce(() => {
66
76
  if (this.readonly) return;
67
77
  const { scale, centerX, centerY } = this.view.camera;
68
78
  const originScale = this.option.getOriginScale();
@@ -79,7 +89,8 @@ export class Scrollbar {
79
89
  this.scrollbarY.style.display = ratio === 1 ? 'none' : 'block';
80
90
  this.scrollbarY.style.transform = `translateY(${scrollY}px)`;
81
91
  }
82
- }
92
+ this.option.scrollbarEventCallback?.onScrollCameraUpdated?.(originScale, scale);
93
+ }, 50)
83
94
 
84
95
  onDragStart = () => {
85
96
  const camera = this.view.camera;
@@ -88,6 +99,7 @@ export class Scrollbar {
88
99
  centerY: camera.centerY,
89
100
  scale: camera.scale,
90
101
  }
102
+ this.option.scrollbarEventCallback?.onScrollbarDragStart?.();
91
103
  }
92
104
 
93
105
  getScrollXRange(camera: {scale: number}) {
@@ -128,6 +140,7 @@ export class Scrollbar {
128
140
  centerX,
129
141
  animationMode: 'immediately' as AnimationMode
130
142
  })
143
+ this.option.scrollbarEventCallback?.onScrollbarDragY?.(centerX);
131
144
  }
132
145
  }
133
146
 
@@ -146,13 +159,15 @@ export class Scrollbar {
146
159
  this.view.moveCamera({
147
160
  centerY,
148
161
  animationMode: 'immediately' as AnimationMode
149
- })
162
+ })
163
+ this.option.scrollbarEventCallback?.onScrollbarDragY?.(centerY);
150
164
  }
151
165
  }
152
166
 
153
167
  onDragEnd = () => {
154
168
  this.cameraCache = undefined
155
169
  this.option.syncView();
170
+ this.option.scrollbarEventCallback?.onScrollbarDragEnd?.();
156
171
  }
157
172
 
158
173
  private init() {
@@ -195,7 +210,7 @@ export class Scrollbar {
195
210
  this.scrollContainer.append(this.scrollbarContainerX, this.scrollbarContainerY);
196
211
  this.container.appendChild(this.scrollContainer);
197
212
  this.view.callbacks.on('onCameraUpdated', this.onCameraUpdated);
198
- this.onCameraUpdated()
213
+ this.onCameraUpdated();
199
214
  }
200
215
 
201
216
  destroy() {