@netless/app-slide 0.2.84 → 0.2.86

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/src/index.ts CHANGED
@@ -76,6 +76,7 @@ export interface AppOptions
76
76
  invisibleBehavior?: "frozen" | "pause";
77
77
  /** just readonly, no operate silder */
78
78
  justSildeReadonly?: true;
79
+ enableScale?: boolean;
79
80
  }
80
81
 
81
82
  export interface ILogger {
@@ -189,6 +190,7 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
189
190
  baseScenePath,
190
191
  appId: context.appId,
191
192
  urlInterrupter: context.getAppOptions()?.urlInterrupter,
193
+ enableScale: context.getAppOptions()?.enableScale ?? false,
192
194
  onPagesReady: ({ length }) => {
193
195
  const index = docsViewer?.viewer.pageIndex || 0;
194
196
  context.dispatchAppEvent("pageStateChange", { index, length });
@@ -243,6 +245,63 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
243
245
  docsViewer.mount();
244
246
 
245
247
  return {
248
+ onScaleChanged: (cb: (scale: number) => void) => {
249
+ if (!docsViewer) {
250
+ return;
251
+ }
252
+ docsViewer.resizableContainer.onScaleChanged = cb;
253
+ },
254
+ scaleView: (to: number) => {
255
+ let applyScale = Number(to);
256
+ if (Number.isNaN(applyScale)) {
257
+ applyScale = 1;
258
+ }
259
+ if (applyScale < 1.0) {
260
+ applyScale = 1.0;
261
+ }
262
+ if (applyScale > 4.0) {
263
+ applyScale = 4.0;
264
+ }
265
+
266
+ context.storage.setState({ slideScale: applyScale });
267
+ context.storage.setState({ translateX: 0.5, translateY: 0.5 });
268
+ docsViewer?.resizableContainer.scaleContainer(applyScale);
269
+ },
270
+ getViewScale: () => {
271
+ return docsViewer?.resizableContainer.getScale();
272
+ },
273
+ translateView: (offsetX: number, offsetY: number) => {
274
+ if (docsViewer?.resizableContainer) {
275
+ const container = docsViewer.resizableContainer;
276
+ const parentBounds = context.getBox().$content.getBoundingClientRect();
277
+ const containerBounds = container.container.getBoundingClientRect();
278
+
279
+ // 计算当前的最大可滚动像素范围
280
+ const maxScrollX = containerBounds.width - parentBounds.width;
281
+ const maxScrollY = containerBounds.height - parentBounds.height;
282
+
283
+ if (maxScrollX > 0 || maxScrollY > 0) {
284
+ // 获取当前标准化位置 (0 ~ 1)
285
+ const currentX = container['translateX'] ?? 0.5;
286
+ const currentY = container['translateY'] ?? 0.5;
287
+
288
+ // 将像素偏移转换为标准化偏移
289
+ const normalizedDeltaX = maxScrollX > 0 ? offsetX / maxScrollX : 0;
290
+ const normalizedDeltaY = maxScrollY > 0 ? offsetY / maxScrollY : 0;
291
+
292
+ // 计算新的标准化位置
293
+ const newX = Math.max(0, Math.min(1, currentX + normalizedDeltaX));
294
+ const newY = Math.max(0, Math.min(1, currentY + normalizedDeltaY));
295
+
296
+ // 存储到 context.storage 实现跨客户端同步
297
+ context.storage.setState({ translateX: newX, translateY: newY });
298
+ container.handleNormalizeTranslate(newX, newY, {
299
+ triggerScrollBar: true,
300
+ triggerSync: false,
301
+ });
302
+ }
303
+ }
304
+ },
246
305
  setSildeReadonly: (bol: boolean) => {
247
306
  docsViewer?.setJustSildeReadonly(bol);
248
307
  },
package/src/typings.ts CHANGED
@@ -12,6 +12,9 @@ export interface Attributes {
12
12
  resourceList: string[];
13
13
  previewList: string[];
14
14
  customLinks: CustomLink[];
15
+ slideScale: number;
16
+ translateX: number;
17
+ translateY: number;
15
18
  }
16
19
 
17
20
  export type MagixPayload = {