@netless/fastboard-core 1.1.5 → 1.1.7

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/dist/index.d.ts CHANGED
@@ -87,6 +87,10 @@ interface InsertDocsDynamic {
87
87
  readonly scenes?: SceneDefinition[];
88
88
  }
89
89
  type InsertDocsParams = InsertDocsStatic | InsertDocsDynamic;
90
+ interface InsertDocsOptions {
91
+ /** Renderer for static documents. Dynamic documents always use Slide. @default "docsViewer" */
92
+ readonly staticRenderer?: "docsViewer" | "presentation";
93
+ }
90
94
  interface ProjectorResponse {
91
95
  uuid: string;
92
96
  status: "Waiting" | "Converting" | "Finished" | "Fail";
@@ -283,12 +287,12 @@ declare class FastboardApp<TEventData extends Record<string, any> = any> extends
283
287
  * Insert PDF/PPTX from conversion result.
284
288
  * @param status https://developer.netless.link/server-en/home/server-conversion#get-query-task-conversion-progress
285
289
  */
286
- insertDocs(filename: string, status: ConversionResponse): Promise<string | undefined>;
290
+ insertDocs(filename: string, status: ConversionResponse, options?: InsertDocsOptions): Promise<string | undefined>;
287
291
  /**
288
292
  * Insert PDF/PPTX from projector conversion result.
289
293
  * @param response https://developer.netless.link/server-zh/home/server-projector#get-%E6%9F%A5%E8%AF%A2%E4%BB%BB%E5%8A%A1%E8%BD%AC%E6%8D%A2%E8%BF%9B%E5%BA%A6
290
294
  */
291
- insertDocs(filename: string, response: ProjectorResponse): Promise<string | undefined>;
295
+ insertDocs(filename: string, response: ProjectorResponse, options?: InsertDocsOptions): Promise<string | undefined>;
292
296
  /**
293
297
  * Manual way.
294
298
  * @example
@@ -299,7 +303,8 @@ declare class FastboardApp<TEventData extends Record<string, any> = any> extends
299
303
  * title: 'Title',
300
304
  * })
301
305
  */
302
- insertDocs(params: InsertDocsParams): Promise<string | undefined>;
306
+ insertDocs(params: InsertDocsParams, options?: InsertDocsOptions): Promise<string | undefined>;
307
+ private _insertDocs;
303
308
  /**
304
309
  * Insert the Media Player app.
305
310
  */
@@ -474,19 +479,24 @@ declare function addPlayerListener<K extends keyof PlayerCallbacks>(player: Play
474
479
  declare function addViewListener<K extends keyof ViewCallbacks>(view: View, name: K, listener: (value: ViewCallbacks[K]) => void): () => void;
475
480
  declare function addManagerListener<K extends keyof PublicEvent>(manager: WindowManager, name: K, listener: (value: PublicEvent[K]) => void): () => void;
476
481
 
482
+ type DocsEvent = "prevPage" | "nextPage" | "prevStep" | "nextStep" | "jumpToPage" | "scalePage";
477
483
  interface DocsEventOptions {
478
484
  /** If provided, will dispatch to the specific app. Default to the focused app. */
479
485
  appId?: string;
480
486
  /** Used by `jumpToPage` event, range from 1 to total pages count. */
481
487
  page?: number;
488
+ /** Used by `scalePage` event. Range from 1 to 4, decimals allowed. `1` means default fitted size. */
489
+ scale?: number;
482
490
  }
483
491
  /**
484
- * Send specific command to the static docs / slide app.
485
- * Only works for apps that were created by `insertDocs()`.
492
+ * Send specific command to the DocsViewer / Presentation / Slide app.
493
+ * This is a compatibility wrapper around `WindowManager.dispatchDocsEvent()`.
494
+ * Works for documents created by `insertDocs()`.
486
495
  *
487
496
  * Returns false if failed to find the app or not writable.
488
497
  *
489
- * For static docs, `nextPage` equals to `nextStep`, as with `prevPage` and `prevStep`.
498
+ * For DocsViewer and Presentation, `nextPage` equals to `nextStep`, as with
499
+ * `prevPage` and `prevStep`.
490
500
  *
491
501
  * @example
492
502
  * ```js
@@ -497,6 +507,6 @@ interface DocsEventOptions {
497
507
  * dispatchDocsEvent(fastboard, "prevPage", {appId:"Slide-1a2b3c4d"})
498
508
  * ```
499
509
  */
500
- declare function dispatchDocsEvent(fastboard: FastboardApp | WindowManager, event: "prevPage" | "nextPage" | "prevStep" | "nextStep" | "jumpToPage", options?: DocsEventOptions): boolean;
510
+ declare function dispatchDocsEvent(fastboard: FastboardApp | WindowManager, event: DocsEvent, options?: DocsEventOptions): boolean;
501
511
 
502
- export { Appliance, AppsConfig, AppsStatus, DocsEventOptions, FastboardApp, FastboardOptions, FastboardPlayer, FastboardReplayOptions, InsertDocsDynamic, InsertDocsParams, InsertDocsStatic, PlayerPhase, ProjectorResponse, Readable, RoomPhase, RoomStateChanged, SetMemberStateFn, Shape, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable, addManagerListener, addPlayerListener, addRoomListener, addViewListener, convertedFileToScene, createFastboard, dispatchDocsEvent, genUID, getImageSize, makeSlideParams, readable, register, replayFastboard, version, warn, writable };
512
+ export { Appliance, AppsConfig, AppsStatus, DocsEvent, DocsEventOptions, FastboardApp, FastboardOptions, FastboardPlayer, FastboardReplayOptions, InsertDocsDynamic, InsertDocsOptions, InsertDocsParams, InsertDocsStatic, PlayerPhase, ProjectorResponse, Readable, RoomPhase, RoomStateChanged, SetMemberStateFn, Shape, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable, addManagerListener, addPlayerListener, addRoomListener, addViewListener, convertedFileToScene, createFastboard, dispatchDocsEvent, genUID, getImageSize, makeSlideParams, readable, register, replayFastboard, version, warn, writable };
package/dist/index.js CHANGED
@@ -251,7 +251,7 @@ for (const kind in DefaultApps) {
251
251
  windowManager.WindowManager.register(__spreadValues({ kind }, options));
252
252
  }
253
253
  }
254
- var version = "1.1.5";
254
+ var version = "1.1.7";
255
255
  if (typeof window !== "undefined") {
256
256
  let str = window.__netlessUA || "";
257
257
  str += ` ${"@netless/fastboard-core"}@${version} `;
@@ -669,10 +669,16 @@ var FastboardApp = class extends FastboardAppBase {
669
669
  const originY = centerY - height / 2;
670
670
  this.manager.moveCameraToContain({ originX, originY, width, height });
671
671
  }
672
- insertDocs(arg1, arg2) {
672
+ insertDocs(arg1, arg2, arg3) {
673
+ const response = typeof arg1 === "string" ? arg2 : void 0;
674
+ const options = typeof arg1 === "string" ? arg3 : arg2;
675
+ const staticAppKind = (options == null ? void 0 : options.staticRenderer) === "presentation" ? "Presentation" : "DocsViewer";
676
+ return this._insertDocs(arg1, response, staticAppKind);
677
+ }
678
+ _insertDocs(arg1, arg2, staticAppKind) {
673
679
  this._assertNotDestroyed();
674
680
  if (typeof arg1 === "object" && "fileType" in arg1) {
675
- return this._insertDocsImpl(arg1);
681
+ return this._insertDocsImpl(arg1, staticAppKind);
676
682
  } else if (arg2 && arg2.status !== "Finished") {
677
683
  throw new Error("FastboardApp cannot insert a converting doc.");
678
684
  } else if (arg2 && "progress" in arg2) {
@@ -681,9 +687,12 @@ var FastboardApp = class extends FastboardAppBase {
681
687
  const scenes1 = arg2.progress.convertedFileList.map(convertedFileToScene);
682
688
  const { scenes, taskId, url } = makeSlideParams(scenes1);
683
689
  if (taskId && url) {
684
- return this._insertDocsImpl({ fileType: "pptx", scenePath, scenes, title, taskId, url });
690
+ return this._insertDocsImpl(
691
+ { fileType: "pptx", scenePath, scenes, title, taskId, url },
692
+ staticAppKind
693
+ );
685
694
  } else {
686
- return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes: scenes1, title });
695
+ return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes: scenes1, title }, staticAppKind);
687
696
  }
688
697
  } else if (arg2 && arg2.images) {
689
698
  const title = arg1;
@@ -693,25 +702,25 @@ var FastboardApp = class extends FastboardAppBase {
693
702
  const { width, height, url } = arg2.images[name];
694
703
  scenes.push({ name, ppt: { width, height, src: url } });
695
704
  }
696
- return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes, title });
705
+ return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes, title }, staticAppKind);
697
706
  } else if (arg2 && arg2.prefix) {
698
707
  const title = arg1;
699
708
  const scenePath = `/${arg2.uuid}/${genUID()}`;
700
709
  const taskId = arg2.uuid;
701
710
  const url = arg2.prefix;
702
- this._insertDocsImpl({ fileType: "pptx", scenePath, taskId, title, url });
711
+ return this._insertDocsImpl({ fileType: "pptx", scenePath, taskId, title, url }, staticAppKind);
703
712
  } else {
704
713
  throw new Error("Invalid input: not found 'progress', 'prefix' nor 'images'");
705
714
  }
706
715
  }
707
716
  /** @internal */
708
- _insertDocsImpl(_a) {
717
+ _insertDocsImpl(_a, staticAppKind) {
709
718
  var _b = _a, { fileType, scenePath, title, scenes } = _b, attributes = __objRest(_b, ["fileType", "scenePath", "title", "scenes"]);
710
719
  this._assertNotDestroyed();
711
720
  switch (fileType) {
712
721
  case "pdf":
713
722
  return this.manager.addApp({
714
- kind: "DocsViewer",
723
+ kind: staticAppKind,
715
724
  options: { scenePath, title, scenes }
716
725
  });
717
726
  case "pptx":
@@ -808,7 +817,7 @@ async function createFastboard(_a) {
808
817
  _AppInMainViewPlugin = AppInMainViewPlugin;
809
818
  joinRoomParamsWithPlugin.invisiblePlugins = [
810
819
  ...joinRoomParamsWithPlugin.invisiblePlugins,
811
- _AppInMainViewPlugin
820
+ AppInMainViewPlugin
812
821
  ];
813
822
  }
814
823
  const sdk = new whiteWebSdk.WhiteWebSdk(__spreadProps(__spreadValues({}, sdkConfig), {
@@ -1082,7 +1091,7 @@ async function replayFastboard(_a) {
1082
1091
  _AppInMainViewPlugin = AppInMainViewPlugin;
1083
1092
  replayRoomParamsWithPlugin.invisiblePlugins = [
1084
1093
  ...replayRoomParamsWithPlugin.invisiblePlugins,
1085
- _AppInMainViewPlugin
1094
+ AppInMainViewPlugin
1086
1095
  ];
1087
1096
  }
1088
1097
  const sdk = new whiteWebSdk.WhiteWebSdk(__spreadProps(__spreadValues({}, sdkConfig), {
@@ -1160,77 +1169,13 @@ function addManagerListener(manager, name, listener) {
1160
1169
 
1161
1170
  // src/helpers/docs.ts
1162
1171
  function dispatchDocsEvent(fastboard, event, options = {}) {
1163
- var _a, _b, _c;
1164
1172
  const manager = "manager" in fastboard ? fastboard.manager : fastboard;
1165
- const appId = options.appId || manager.focused;
1166
- if (!appId) {
1167
- console.warn("not found " + (options.appId || "focused app"));
1168
- return false;
1169
- }
1170
- let page, input;
1171
- if (appId.startsWith("DocsViewer-")) {
1172
- const dom = (_b = (_a = manager.queryOne(appId)) == null ? void 0 : _a.box) == null ? void 0 : _b.$footer;
1173
- if (!dom) {
1174
- console.warn("not found app with id " + appId);
1175
- return false;
1176
- }
1177
- const click = (el) => {
1178
- el && el.dispatchEvent(new MouseEvent("click"));
1179
- };
1180
- switch (event) {
1181
- case "prevPage":
1182
- case "prevStep":
1183
- click(dom.querySelector('button[class$="btn-page-back"]'));
1184
- break;
1185
- case "nextPage":
1186
- case "nextStep":
1187
- click(dom.querySelector('button[class$="btn-page-next"]'));
1188
- break;
1189
- case "jumpToPage":
1190
- page = options.page;
1191
- input = dom.querySelector('input[class$="page-number-input"]');
1192
- if (!input || typeof page !== "number") {
1193
- console.warn("failed to jump" + (page ? " to page " + page : ""));
1194
- return false;
1195
- }
1196
- input.value = "" + page;
1197
- input.dispatchEvent(new InputEvent("change"));
1198
- break;
1199
- default:
1200
- console.warn("unknown event " + event);
1201
- return false;
1202
- }
1203
- return true;
1204
- } else if (appId.startsWith("Slide-")) {
1205
- const app = (_c = manager.queryOne(appId)) == null ? void 0 : _c.appResult;
1206
- if (!app) {
1207
- console.warn("not found app with id " + appId);
1208
- return false;
1209
- }
1210
- switch (event) {
1211
- case "prevPage":
1212
- return app.prevPage();
1213
- case "nextPage":
1214
- return app.nextPage();
1215
- case "prevStep":
1216
- return app.prevStep();
1217
- case "nextStep":
1218
- return app.nextStep();
1219
- case "jumpToPage":
1220
- page = options.page;
1221
- if (typeof page !== "number") {
1222
- console.warn("failed to jump" + (page ? " to page " + page : ""));
1223
- return false;
1224
- }
1225
- return app.jumpToPage(page);
1226
- default:
1227
- console.warn("unknown event " + event);
1228
- return false;
1229
- }
1230
- } else {
1231
- console.warn("not supported app " + appId);
1173
+ const dispatchDocsEvent2 = manager.dispatchDocsEvent;
1174
+ if (!dispatchDocsEvent2) {
1175
+ console.warn("window manager does not support dispatchDocsEvent");
1232
1176
  return false;
1233
1177
  }
1178
+ return dispatchDocsEvent2.call(manager, event, options);
1234
1179
  }
1235
1180
  windowManager.WindowManager.register({
1236
1181
  kind: "Slide",