@dajiaoai/algeo-sdk 2.12.1 → 2.13.1

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/README.md CHANGED
@@ -569,6 +569,7 @@ interface FileContent {
569
569
  | -------------------------------- | ------------------------------------------------------------------------------------ |
570
570
  | `getCount()` | 获取当前已知画板数量 |
571
571
  | `getCurrentIndex()` | 获取当前已知画板索引 |
572
+ | `getCurrentViewBounds()` | 异步获取当前有限画布的导出视野 `{ left, top, right, bottom, scale }`;可直接传给 `exportImage`;无限画布返回 `null` |
572
573
  | `switchTo(index)` | 切换画板 |
573
574
  | `add()` | 在末尾新增画板 |
574
575
  | `addAt(index)` | 在指定位置新增画板 |
@@ -582,21 +583,21 @@ interface FileContent {
582
583
 
583
584
  所有模式均读取文件中的 `camera.scale`;文件未提供时默认为 `50`。`slideIndices` 使用从 `1` 开始的画板索引,省略时导出全部画板。
584
585
 
585
- 适合精确指定导出视野时使用 `view`。2D 画板传 `viewBounds`:
586
+ 适合精确指定导出视野时使用 `view`。2D 画板传 `viewBound`:
586
587
 
587
588
  ```ts
588
589
  const images = await editor.slides.exportImage({
589
590
  mode: 'view',
590
591
  slideIndices: [1],
591
592
  format: 'png',
592
- viewBounds: { x: -5, y: -5, width: 10, height: 10, scale: 50 },
593
+ viewBound: { left: -5, top: -5, right: 5, bottom: 5, scale: 50 },
593
594
  pixelRatio: 2,
594
595
  });
595
596
  ```
596
597
 
597
- `viewBounds` 的位置和宽高均为世界坐标,`scale` 为可选的相机缩放比例。省略 `scale` 时使用目标画板文件中的 `camera.scale`。
598
+ `viewBound` 的 `left`、`top`、`right`、`bottom` 均为世界坐标边界,`scale` 为可选的相机缩放比例。省略 `scale` 时使用目标画板文件中的 `camera.scale`。
598
599
 
599
- 3D 画板传同级的 `viewCamera3d`。其中 `width`、`height` 必填;`width`、`height` 为世界坐标视野范围。`offset`、`yaw`、`pitch`、`scale` 可选且省略时沿用文件相机;投影方式与斜投影参数始终沿用画板文件。
600
+ 3D 画板传同级的 `viewCamera3d`。其中 `width`、`height` 为逻辑输出像素,省略时均为 `1024`;`pixelRatio` 只放大最终物理像素。`offset`、`yaw`、`pitch`、`scale` 可选且省略时沿用文件相机;`scale` 独立决定相机远近与可见世界范围。投影方式与斜投影参数始终沿用画板文件。
600
601
 
601
602
  ```ts
602
603
  const images = await editor.slides.exportImage({
@@ -608,14 +609,14 @@ const images = await editor.slides.exportImage({
608
609
  yaw: Math.PI / 4,
609
610
  pitch: Math.PI / 6,
610
611
  scale: 0.2,
611
- width: 12,
612
- height: 8,
612
+ width: 1200,
613
+ height: 800,
613
614
  },
614
615
  pixelRatio: 2,
615
616
  });
616
617
  ```
617
618
 
618
- 一个 `view` 请求可以同时传 `viewBounds` 与 `viewCamera3d`,用于批量导出混合 2D/3D 画板;每张画板自动读取适用字段。2D 画板未提供 `viewBounds`、或 3D 画板未提供 `viewCamera3d` 时会报错。3D 仅支持 PNG、JPG;对 3D 画板请求 SVG 会报错。
619
+ 一个 `view` 请求可以同时传 `viewBound` 与 `viewCamera3d`,用于批量导出混合 2D/3D 画板;每张画板自动读取适用字段。2D 画板未提供 `viewBound`、或 3D 画板未提供 `viewCamera3d` 时会报错。3D 仅支持 PNG、JPG;对 3D 画板请求 SVG 会报错。
619
620
 
620
621
  适合完整包住全部内容且不限定最终宽高时使用 `contain`:
621
622
 
@@ -4011,7 +4011,7 @@ function convertToLatest(content) {
4011
4011
  }
4012
4012
 
4013
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.12.1';
4014
+ const VERSION = '2.13.1';
4015
4015
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4016
4016
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4017
4017
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4515,6 +4515,10 @@ class EmbeddedEditor extends EmbeddedTarget {
4515
4515
  this.slides = {
4516
4516
  getCount: () => this.slideCount,
4517
4517
  getCurrentIndex: () => this.currentSlideIndex,
4518
+ getCurrentViewBounds: async () => {
4519
+ const result = await this.post('getCurrentViewBounds', {});
4520
+ return result.viewBounds;
4521
+ },
4518
4522
  switchTo: async (index) => {
4519
4523
  await this.switchTo(index);
4520
4524
  },
@@ -4535,7 +4539,9 @@ class EmbeddedEditor extends EmbeddedTarget {
4535
4539
  await this.refreshHistoryState();
4536
4540
  },
4537
4541
  exportImage: async (options) => {
4538
- const result = await this.post('exportSlideImage', { options });
4542
+ const result = await this.post(options.mode === 'view' && options.viewBound !== undefined
4543
+ ? 'exportSlideImageV2'
4544
+ : 'exportSlideImage', { options });
4539
4545
  return result.images;
4540
4546
  },
4541
4547
  exportLatex: async (options) => {
@@ -4009,7 +4009,7 @@ function convertToLatest(content) {
4009
4009
  }
4010
4010
 
4011
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4012
- const VERSION = '2.12.1';
4012
+ const VERSION = '2.13.1';
4013
4013
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4014
4014
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4015
4015
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4513,6 +4513,10 @@ class EmbeddedEditor extends EmbeddedTarget {
4513
4513
  this.slides = {
4514
4514
  getCount: () => this.slideCount,
4515
4515
  getCurrentIndex: () => this.currentSlideIndex,
4516
+ getCurrentViewBounds: async () => {
4517
+ const result = await this.post('getCurrentViewBounds', {});
4518
+ return result.viewBounds;
4519
+ },
4516
4520
  switchTo: async (index) => {
4517
4521
  await this.switchTo(index);
4518
4522
  },
@@ -4533,7 +4537,9 @@ class EmbeddedEditor extends EmbeddedTarget {
4533
4537
  await this.refreshHistoryState();
4534
4538
  },
4535
4539
  exportImage: async (options) => {
4536
- const result = await this.post('exportSlideImage', { options });
4540
+ const result = await this.post(options.mode === 'view' && options.viewBound !== undefined
4541
+ ? 'exportSlideImageV2'
4542
+ : 'exportSlideImage', { options });
4537
4543
  return result.images;
4538
4544
  },
4539
4545
  exportLatex: async (options) => {
@@ -4015,7 +4015,7 @@
4015
4015
  }
4016
4016
 
4017
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.12.1';
4018
+ const VERSION = '2.13.1';
4019
4019
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4020
4020
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4021
4021
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4519,6 +4519,10 @@
4519
4519
  this.slides = {
4520
4520
  getCount: () => this.slideCount,
4521
4521
  getCurrentIndex: () => this.currentSlideIndex,
4522
+ getCurrentViewBounds: async () => {
4523
+ const result = await this.post('getCurrentViewBounds', {});
4524
+ return result.viewBounds;
4525
+ },
4522
4526
  switchTo: async (index) => {
4523
4527
  await this.switchTo(index);
4524
4528
  },
@@ -4539,7 +4543,9 @@
4539
4543
  await this.refreshHistoryState();
4540
4544
  },
4541
4545
  exportImage: async (options) => {
4542
- const result = await this.post('exportSlideImage', { options });
4546
+ const result = await this.post(options.mode === 'view' && options.viewBound !== undefined
4547
+ ? 'exportSlideImageV2'
4548
+ : 'exportSlideImage', { options });
4543
4549
  return result.images;
4544
4550
  },
4545
4551
  exportLatex: async (options) => {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
2
2
  export type { FileContentLatest } from '@dajiaoai/algeo-protocol';
3
3
  export { convertToLatest } from '@dajiaoai/algeo-protocol';
4
- export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBounds, ExportViewCamera3D, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
4
+ export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBound, ExportViewBounds, ExportViewCamera3D, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
5
5
  export { EmbeddedPresentation } from './embedded-presentation';
6
6
  export { EmbeddedEditor } from './embedded-editor';
7
7
  export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
package/dist/shared.d.ts CHANGED
@@ -241,6 +241,10 @@ export interface SwitchSlideResult {
241
241
  export interface GetSlideCountResult {
242
242
  count: number;
243
243
  }
244
+ export interface GetCurrentViewBoundsResult {
245
+ /** 与 ExportImageViewMode.viewBound 格式一致,可直接传给 exportImage。 */
246
+ viewBounds: ExportViewBound | null;
247
+ }
244
248
  export interface ReplResult {
245
249
  output: string;
246
250
  }
@@ -251,11 +255,25 @@ export type ExportImageFormat = 'png' | 'jpg' | 'svg';
251
255
  /**
252
256
  * 导出的逻辑视野区域(世界坐标)。
253
257
  */
258
+ /**
259
+ * 旧版 2D 导出视野(世界坐标)。使用时会调用兼容的 exportSlideImage 实现。
260
+ * @deprecated 请改用 ExportViewBound(left/top/right/bottom)。
261
+ */
254
262
  export interface ExportViewBounds {
255
263
  x: number;
256
264
  y: number;
257
265
  width: number;
258
266
  height: number;
267
+ scale?: number;
268
+ }
269
+ /**
270
+ * 2D 导出视野的四条世界坐标边界。
271
+ */
272
+ export interface ExportViewBound {
273
+ left: number;
274
+ top: number;
275
+ right: number;
276
+ bottom: number;
259
277
  /**
260
278
  * 相机缩放比例(每世界坐标单位对应的像素数)。
261
279
  * 省略时使用目标画板文件中的 camera.scale。
@@ -270,10 +288,10 @@ export interface ExportViewCamera3D {
270
288
  pitch?: number;
271
289
  yaw?: number;
272
290
  scale?: number;
273
- /** 3D 导出视野的世界坐标宽度。 */
274
- width: number;
275
- /** 3D 导出视野的世界坐标高度。 */
276
- height: number;
291
+ /** 3D 导出的逻辑输出宽度(px),默认 1024。 */
292
+ width?: number;
293
+ /** 3D 导出的逻辑输出高度(px),默认 1024。 */
294
+ height?: number;
277
295
  }
278
296
  /** 导出留白,单位为输出像素 px。 */
279
297
  export type ExportPadding = number | {
@@ -299,13 +317,18 @@ export interface ExportImageSizeMode extends ExportImageBaseOptions {
299
317
  minPadding?: ExportPadding;
300
318
  }
301
319
  /**
302
- * 场景二(view):viewBounds 的位置及宽高均为世界坐标。
320
+ * 场景二(view):viewBound 的四条边界均为世界坐标。
303
321
  * scale 省略时从文件的 camera.scale 读取。
304
- * 输出像素 = viewBounds 世界尺寸 x viewBounds.scale x pixelRatio。
322
+ * 输出像素 = (right - left, bottom - top) x viewBound.scale x pixelRatio。
305
323
  */
306
324
  export interface ExportImageViewMode extends ExportImageBaseOptions {
307
325
  mode: 'view';
308
- /** 2D 画板的世界坐标视野。 */
326
+ /** 2D 画板的世界坐标视野;使用新宿主导出实现。 */
327
+ viewBound?: ExportViewBound;
328
+ /**
329
+ * 2D 画板的旧版世界坐标视野;使用兼容的旧宿主导出实现。
330
+ * @deprecated 请改用 viewBound。
331
+ */
309
332
  viewBounds?: ExportViewBounds;
310
333
  /** 3D 画板的相机视野。 */
311
334
  viewCamera3d?: ExportViewCamera3D;
@@ -384,6 +407,7 @@ export interface DocumentApi {
384
407
  export interface SlidesApi {
385
408
  getCount(): number;
386
409
  getCurrentIndex(): number;
410
+ getCurrentViewBounds(): Promise<ExportViewBound | null>;
387
411
  switchTo(index: number): Promise<void>;
388
412
  add(): Promise<SlideIndexResult>;
389
413
  addAt(index: number): Promise<SlideIndexResult>;
@@ -395,7 +419,7 @@ export interface SlidesApi {
395
419
  * 导出画板图片。支持三种 mode:
396
420
  * - size:目标输出宽高、minPadding 与图形包围盒
397
421
  * 自动计算 pixelRatio,使图形完整 contain 在可用区域。
398
- * - view:指定视野 viewBounds 与 pixelRatio
422
+ * - view:指定视野 viewBound 与 pixelRatio
399
423
  * - contain:由 pixelRatio 与绝对 px padding 自动计算最终宽高。
400
424
  *
401
425
  * 旧的扁平 ExportSlideImageOptions 已废弃,实现层不再接受;请改用上述三模式 ExportImageOptions。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.12.1",
3
+ "version": "2.13.1",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",