@netless/forge-whiteboard 0.1.9 → 0.1.10

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.
@@ -29363,17 +29363,33 @@ var Whiteboard = class extends import_eventemitter39.default {
29363
29363
  */
29364
29364
  redo;
29365
29365
  /**
29366
- * 光栅化指定页面
29367
- * @param {string | number | undefined} page 指定页码, string 指示页码 id, number 指示 IndexedNavigation 页面索引, undefined 指示光栅化当前页
29368
- * @return {Promise<string>} 异步返回光栅化结果, 图片 png 对应的 base64 url, 如果页面不存在返回 null
29366
+ * 光栅化指定页面的可视区域
29367
+ * @param {number} scale 缩放比例
29368
+ * @param {string=} page string 指示页码 id; number 指示 IndexedNavigation 页面索引; undefined 指示光栅化当前页
29369
+ * @return {Promise<string>} 异步返回光栅化结果, 图片 png 对应的 base64 url. 如果页面不存在返回 null
29369
29370
  */
29370
- rasterize;
29371
+ rasterizeViewport;
29372
+ /**
29373
+ * 光栅化指定页面包含所有元素的包围盒
29374
+ * @param {number} outputMaxWidth 输出图片最大宽度, 在保证高宽比的情况下限值输出图片的宽度小于等于此值
29375
+ * @param {number} outputMaxHeight 输出图片最大高度, 在保证高宽比的情况下限值输出图片的高度小于等于此值
29376
+ * @param {string=} page string 指示页码 id; number 指示 IndexedNavigation 页面索引; undefined 指示光栅化当前页
29377
+ * @return {Promise<string>} 异步返回光栅化结果, 图片 png 对应的 base64 url. 如果页面不存在返回 null
29378
+ */
29379
+ rasterizeElementsBounds;
29380
+ /**
29381
+ * 光栅化指定页面最大缩放区域, 如果没有指定 `WhiteboardOption.maxScaleRatio` 或者指定的值为 -1, 则按 `rasterizeViewport` 返回结果.
29382
+ * @param {number} scale 缩放比例
29383
+ * @param {string=} page string 指示页码 id; number 指示 IndexedNavigation 页面索引; undefined 指示光栅化当前页
29384
+ * @return {Promise<string>} 异步返回光栅化结果, 图片 png 对应的 base64 url. 如果页面不存在返回 null
29385
+ */
29386
+ rasterizeMaxBounds;
29371
29387
  /**
29372
29388
  * 设置输入类型, "pen" 仅接受手写笔输入, "any" 接受任意输入, 当首次侦测到手写笔输入时, 将自动切换为 "pen"
29373
29389
  * @param {"pen" | "any"} type 输入类型
29374
29390
  */
29375
29391
  setInputType;
29376
- insertImage;
29392
+ // public insertImage!: (src: string) => void;
29377
29393
  constructor(view) {
29378
29394
  super();
29379
29395
  this.view = view;
@@ -30275,8 +30291,14 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30275
30291
  this.emitter.redo = () => {
30276
30292
  this.undoManager?.redo();
30277
30293
  };
30278
- this.emitter.rasterize = (page) => {
30279
- return this.rasterize(page);
30294
+ this.emitter.rasterizeViewport = (scale, page) => {
30295
+ return this.rasterize(1, 1, scale, "viewport", page);
30296
+ };
30297
+ this.emitter.rasterizeElementsBounds = (outputMaxWidth, outputMaxHeight, page) => {
30298
+ return this.rasterize(outputMaxWidth, outputMaxHeight, 1, "bounds", page);
30299
+ };
30300
+ this.emitter.rasterizeMaxBounds = (scale, page) => {
30301
+ return this.rasterize(1, 1, scale, "maxScale", page);
30280
30302
  };
30281
30303
  this.emitter.setInputType = (type) => {
30282
30304
  this.inputType = type;
@@ -30386,6 +30408,7 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30386
30408
  that.camera.enableBoundaryHighlight = value;
30387
30409
  }
30388
30410
  });
30411
+ window["__wb"] = this;
30389
30412
  }
30390
30413
  userMap(userId) {
30391
30414
  return this.getMap(`user/${userId}`);
@@ -30834,7 +30857,10 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30834
30857
  this.emitter.emit("elementDeselected", userId);
30835
30858
  }
30836
30859
  };
30837
- rasterize(page) {
30860
+ ensureScale(outputWidth, outputHeight, originSize) {
30861
+ return Math.min(outputWidth / originSize.width, outputHeight / originSize.height);
30862
+ }
30863
+ rasterize(outputMaxWidth, outputMaxHeight, scale, area, page) {
30838
30864
  let pageId;
30839
30865
  if (typeof page === "string") {
30840
30866
  pageId = page;
@@ -30848,8 +30874,6 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30848
30874
  return Promise.resolve(null);
30849
30875
  }
30850
30876
  this.snapshotScope.project.activeLayer.removeChildren();
30851
- this.snapshotScope.view.matrix = this.paperScope.project.view.matrix.clone();
30852
- this.snapshotScope.view.viewSize = this.paperScope.project.view.viewSize.clone();
30853
30877
  for (const key of Array.from(renderableModel.elements.keys())) {
30854
30878
  let elementModel = null;
30855
30879
  if (renderableModel.elementModels.has(key)) {
@@ -30870,6 +30894,29 @@ var WhiteboardApplication = class extends import_forge_room3.AbstractApplication
30870
30894
  }
30871
30895
  }
30872
30896
  }
30897
+ if (area === "bounds") {
30898
+ const bounds = this.snapshotScope.project.activeLayer.bounds;
30899
+ const scale2 = this.ensureScale(outputMaxWidth, outputMaxHeight, bounds.size);
30900
+ const matrix = new this.paperScope.Matrix();
30901
+ matrix.scale(scale2);
30902
+ matrix.translate({ x: -bounds.x, y: -bounds.y });
30903
+ this.snapshotScope.view.viewSize = bounds.size.multiply(scale2);
30904
+ this.snapshotScope.view.matrix = matrix;
30905
+ } else if (area === "maxScale" && this.option.maxScaleRatio && this.option.maxScaleRatio !== -1) {
30906
+ const width = this.option.width * this.option.maxScaleRatio;
30907
+ const height = this.option.height * this.option.maxScaleRatio;
30908
+ const offsetX = this.option.width * (this.option.maxScaleRatio - 1) / 2;
30909
+ const offsetY = this.option.height * (this.option.maxScaleRatio - 1) / 2;
30910
+ const matrix = new this.paperScope.Matrix();
30911
+ matrix.scale(scale);
30912
+ matrix.translate({ x: offsetX, y: offsetY });
30913
+ this.snapshotScope.view.viewSize = new this.snapshotScope.Size(width, height).multiply(scale);
30914
+ this.snapshotScope.view.matrix = matrix;
30915
+ } else {
30916
+ this.snapshotScope.view.matrix = this.paperScope.project.view.matrix.clone();
30917
+ this.snapshotScope.view.matrix.scale(scale, this.paperScope.project.view.bounds.topLeft);
30918
+ this.snapshotScope.view.viewSize = this.paperScope.project.view.viewSize.clone().multiply(scale);
30919
+ }
30873
30920
  return new Promise((resolve) => {
30874
30921
  setTimeout(() => {
30875
30922
  resolve(this.snapshotScope.view.element.toDataURL("image/png"));