@dajiaoai/algeo-sdk 2.14.1 → 2.15.0

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
@@ -2,6 +2,8 @@
2
2
 
3
3
  大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
4
4
 
5
+ 当前版本:**2.15.0**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.15.0)。
6
+
5
7
  ## 交流与支持
6
8
 
7
9
  欢迎扫描下方二维码加入微信群,与我们交流 SDK 接入问题、使用反馈和功能建议。
@@ -314,9 +316,12 @@ type AlgeoCreateOptions =
314
316
  | `auth` | `{ appId: string }` | - | 编辑模式鉴权参数,其中 `appId` 会参与默认路由生成 |
315
317
  | `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
316
318
  | `initialContent` | `FileContentAny` | - | 初始化后自动注入的文件内容;SDK 会自动转换为最新格式 |
319
+ | `initialMode` | `'2d' \| '3d'` | `'2d'` | 空白画板模式,仅在没有初始内容或分享文件时生效 |
317
320
  | `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
318
321
  | `fonts` | `AlgeoFontConfig` | - | 字体资源、字体选择器列表及默认字体配置 |
319
322
 
323
+ 初始化优先级:`initialContent` > `shareId` > 指定 `initialMode` 的空画板。提供 `initialContent` 时不会请求分享文件;加载已有内容时保留内容中的画板模式。
324
+
320
325
  **AlgeoEditorUiConfig:**
321
326
 
322
327
  | 属性 | 类型 | 默认值 | 说明 |
@@ -506,24 +511,26 @@ SDK 内部已通过 `ResizeObserver` 在容器从隐藏(`display:none`,尺
506
511
 
507
512
  ---
508
513
 
509
- ##### `presentation.repl(command: string): Promise<ReplResult>`
514
+ ##### `editor.repl(command: string): Promise<ReplResult>`
515
+
516
+ 执行 REPL 指令,返回 `{ output: string }`。修改支持撤销、重做,调用后自动同步画板和历史状态。
517
+
518
+ ```ts
519
+ const { output } = await editor.repl('def A := Point(0,0)');
520
+ await editor.history.undo();
521
+ ```
510
522
 
511
- 执行 REPL 指令,返回面向 AI 的文档/文本内容。需先通过 `loadShareById` 或 `loadFile` 加载内容后,部分指令才有数据可查。
523
+ 调用不触发 `contentChange` / `slideChange`,读取最新内容请用 `editor.document.getContent()`。执行失败时,已完成的修改不会自动回滚。
512
524
 
513
- | 参数 | 类型 | 说明 |
514
- | --------- | -------- | --------- |
515
- | `command` | `string` | REPL 指令 |
525
+ ##### `presentation.repl(command: string): Promise<ReplResult>`
516
526
 
517
- **常用指令:**
527
+ 执行 REPL 指令,返回 `{ output: string }`。查询已有内容前,可通过 `loadShareById` 或 `loadFile` 加载画板。
518
528
 
519
- | 指令 | 说明 |
520
- | ------------- | ----------------------------- |
521
- | `help` | 查看 REPL 帮助 |
522
- | `list` | 列出当前画板中的对象 |
523
- | `list_slides` | 列出所有画板 |
524
- | `eval` | 执行表达式(具体用法见 help) |
529
+ ```ts
530
+ const { output } = await presentation.repl('list');
531
+ ```
525
532
 
526
- **返回值:** `{ output: string }` — 指令输出的文本内容
533
+ 两种模式均可通过 `repl('help')` 查看命令帮助,或参考 [REPL 指令实验室](examples/20-repl.html)。
527
534
 
528
535
  ---
529
536
 
@@ -556,6 +563,9 @@ SDK 内部已通过 `ResizeObserver` 在容器从隐藏(`display:none`,尺
556
563
  | -------------------------------- | ------------------------------------------------------------------------------------ |
557
564
  | `getCount()` | 获取当前已知画板数量 |
558
565
  | `getCurrentIndex()` | 获取当前已知画板索引 |
566
+ | `getInfo(index?)` | 异步查询指定或当前画板信息 `{ index, exportIndex, cameraMode }`;`index` 从 0 开始,`exportIndex = index + 1`,`cameraMode` 为 `2d` 或 `3d`;自 SDK `2.15.0` 起支持 |
567
+ | `getViewCamera3d(index?)` | 优先读取已启用的 3D 固定视图,否则读取画板相机参数;2D 返回 `null` |
568
+ | `setViewCamera3d(options)` | 局部更新 3D 固定视图及启用状态,默认尺寸 1920 × 1080 |
559
569
  | `getViewBounds(index?)` | 异步获取指定或当前画板的有限画布导出视野 `{ left, top, right, bottom, scale }`;可直接传给 `exportImage`;无限画布返回 `null` |
560
570
  | `setViewBounds(options)` | 设置指定或当前画板的有限画布边界 |
561
571
  | `switchTo(index)` | 切换画板 |
@@ -599,7 +609,7 @@ const images = await editor.slides.exportImage({
599
609
 
600
610
  `viewBound` 的 `left`、`top`、`right`、`bottom` 均为世界坐标边界,`scale` 为可选的相机缩放比例。省略 `scale` 时使用目标画板文件中的 `camera.scale`。
601
611
 
602
- 3D 画板传同级的 `viewCamera3d`。其中 `width`、`height` 为逻辑输出像素,省略时均为 `1024`;`pixelRatio` 只放大最终物理像素。`offset`、`yaw`、`pitch`、`scale` 可选且省略时沿用文件相机;`scale` 独立决定相机远近与可见世界范围。投影方式与斜投影参数始终沿用画板文件。
612
+ 3D 画板传同级的 `viewCamera3d`,允许传入 `{}`。本次传入的字段覆盖基础视图:优先使用目标画板已启用的固定视图;未启用或没有配置时使用该画板的 `camera3d`,逻辑视口默认 `1024 × 1024` 且不截取。已关闭但保留的配置不参与读取。`width`、`height` 是完整逻辑视口尺寸;`pixelRatio` 放大最终物理像素,`scale` 决定可见世界范围。可覆盖 `projection`、`obliqueAngle`、`obliqueScaleRatio`,以及 `cropEnabled` / `crop`;单次导出的角度单位为弧度。
603
613
 
604
614
  ```ts
605
615
  const images = await editor.slides.exportImage({
@@ -776,3 +786,39 @@ try {
776
786
  | `DESTROYED` | SDK 已销毁 |
777
787
  | `MISSING_APP_ID` | 编辑模式缺少 `auth.appId` |
778
788
  | `BAD_REQUEST` | 非法请求(如重复 init、演示模式白名单校验未通过) |
789
+
790
+
791
+ ### 3D 固定视图
792
+
793
+ 3D 画板使用 `exportImage` 的 `contain` / `size` 模式时,视角和投影参数优先读取目标画板已启用的固定视图,未启用或没有配置时读取目标画板相机;完整内容的包围盒决定导出构图,不使用固定视图的截取范围。
794
+
795
+ `slides.getViewCamera3d(index?)` 查询指定画板的固定视图,`index` 从 0 开始,省略时查询当前画板。3D 画板优先返回已启用的固定视图;未启用或没有配置时返回画板相机已有的 offset、角度、scale 和投影参数,width、height、crop 字段省略。2D 画板返回 `null`。
796
+
797
+ `slides.setViewCamera3d({ index?, enabled?, viewCamera3d? })` 设置 3D 固定视图,支持局部更新。提供 `viewCamera3d` 时默认启用;显式指定 `enabled` 时以其为准。`enabled: false` 仅关闭,保留已有参数;单独设置 `enabled: true` 会启用已有参数,无配置时创建默认视图。参数和开关作为一次可撤销操作保存,不切换画板,也不移动编辑相机。2D 画板不能设置此配置。
798
+
799
+ ```typescript
800
+ const view = await editor.slides.getViewCamera3d(0);
801
+ await editor.slides.setViewCamera3d({
802
+ index: 0,
803
+ viewCamera3d: {
804
+ yawDeg: 45,
805
+ pitchDeg: 30,
806
+ width: 1920,
807
+ height: 1080,
808
+ crop: { left: 240, top: 135, right: 1680, bottom: 945 },
809
+ },
810
+ });
811
+ await editor.slides.setViewCamera3d({ index: 0, viewCamera3d: { crop: null } });
812
+ await editor.slides.setViewCamera3d({ index: 0, enabled: false });
813
+ // 此时 getViewCamera3d(0) 返回画板 camera3d 的已有参数,不读取保留的固定视图。
814
+ ```
815
+
816
+ 固定视图已启用时返回的 `Partial<ViewCamera3d>` 包含 `offset`、`yawDeg`、`pitchDeg`、`scale`、`projection`、`obliqueAngleDeg`、`obliqueScaleRatio`、`width`、`height`、`crop`。设置时均为可选字段,省略字段沿用保存值。无保存值时默认:`offset: [0,0,0]`、三个角度均为 `45`、`scale: 0.1`、`projection: 'orthographic'`、`obliqueScaleRatio: 0.5`、`width: 1920`、`height: 1080`、`crop: null`。
817
+
818
+ 所有角度单位为**度**,内部持久化为弧度。`projection` 支持 `orthographic`、`perspective`、`oblique`。所有数值必须有限;`scale` 范围为 `0.0001–100`,宽高为 `100–2000` 的整数,与编辑器固定视图限制一致;`obliqueScaleRatio >= 0`。
819
+
820
+ `crop` 为完整逻辑视口内的截取矩形,左上角为原点,X 向右、Y 向下,单位为逻辑像素,满足 `0 <= left < right <= width`、`0 <= top < bottom <= height`,截取宽高至少为 1 像素。传入 `crop: null` 取消截取;省略则保留。缩小视口导致原截取框越界时会报错,可同时更新或清除截取框。`pixelRatio` 仅属于单次导出,不写入固定视图。
821
+
822
+ 无效索引抛出 `INVALID_SLIDE_INDEX`;设置 2D 画板抛出 `UNSUPPORTED_CAMERA_MODE`;无效配置抛出 `INVALID_VIEW_CAMERA_3D`。固定视图接口使用的度数字段与旧版 `exportImage` 相机覆盖项的弧度字段不同,不能将角度字段直接混用。
823
+
824
+
@@ -3865,12 +3865,6 @@ var AlgeoError = class extends Error {
3865
3865
  this.name = "AlgeoError";
3866
3866
  }
3867
3867
  };
3868
- objectType({
3869
- text: stringType().optional(),
3870
- images: arrayType(stringType().trim().min(1)).optional(),
3871
- openPanel: booleanType().optional(),
3872
- focus: booleanType().optional()
3873
- }).passthrough();
3874
3868
  var openAiChatMessageV1Schema = objectType({
3875
3869
  role: stringType(),
3876
3870
  content: unionType([
@@ -3884,23 +3878,9 @@ var openAiChatMessageV1Schema = objectType({
3884
3878
  name: stringType().optional()
3885
3879
  }).passthrough();
3886
3880
  objectType({
3887
- model: stringType().trim().min(1),
3888
- input: unionType([
3889
- stringType(),
3890
- arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
3891
- ]).optional(),
3892
- previous_response_id: stringType().trim().min(1).optional(),
3893
- instructions: stringType().optional(),
3894
- temperature: numberType().min(0).max(2).optional(),
3895
- max_output_tokens: numberType().int().positive().optional(),
3896
- metadata: recordType(unknownType()).optional()
3897
- }).passthrough().superRefine((value, ctx) => {
3898
- if (!("input" in value) && !("previous_response_id" in value)) {
3899
- ctx.addIssue({
3900
- code: ZodIssueCode.custom,
3901
- message: "input or previous_response_id is required."
3902
- });
3903
- }
3881
+ model_id: stringType(),
3882
+ messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3883
+ extra_openai_params: recordType(unknownType()).optional()
3904
3884
  });
3905
3885
  objectType({
3906
3886
  id: stringType(),
@@ -4031,7 +4011,7 @@ function convertToLatest(content) {
4031
4011
  }
4032
4012
 
4033
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4034
- const VERSION = '2.14.1';
4014
+ const VERSION = '2.15.0';
4035
4015
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4036
4016
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4037
4017
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4152,10 +4132,10 @@ function buildEmbedSrc(options) {
4152
4132
  const path = getEmbedPath(mode);
4153
4133
  const appId = options.auth?.appId?.trim() ?? '';
4154
4134
  const initialId = options.initialId?.trim();
4155
- if (!initialId) {
4156
- return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
4157
- }
4158
- return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
4135
+ const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4136
+ return mode === 'editor' && options.cameraMode
4137
+ ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4138
+ : src;
4159
4139
  }
4160
4140
 
4161
4141
  class EmbeddedTarget {
@@ -4538,12 +4518,25 @@ class EmbeddedEditor extends EmbeddedTarget {
4538
4518
  this.slides = {
4539
4519
  getCount: () => this.slideCount,
4540
4520
  getCurrentIndex: () => this.currentSlideIndex,
4521
+ getInfo: async (index) => this.post('getSlideInfo', {
4522
+ ...(index === undefined ? {} : { index }),
4523
+ }),
4541
4524
  getViewBounds: async (index) => {
4542
4525
  const result = await this.post('getViewBounds', {
4543
4526
  ...(index === undefined ? {} : { index }),
4544
4527
  });
4545
4528
  return result.viewBounds;
4546
4529
  },
4530
+ getViewCamera3d: async (index) => {
4531
+ const result = await this.post('getViewCamera3d', {
4532
+ ...(index === undefined ? {} : { index }),
4533
+ });
4534
+ return result.viewCamera3d;
4535
+ },
4536
+ setViewCamera3d: async (options) => {
4537
+ await this.post('setViewCamera3d', { ...options });
4538
+ await this.refreshHistoryState();
4539
+ },
4547
4540
  setViewBounds: async (options) => {
4548
4541
  await this.post('setViewBounds', { ...options });
4549
4542
  },
@@ -4627,6 +4620,30 @@ class EmbeddedEditor extends EmbeddedTarget {
4627
4620
  },
4628
4621
  };
4629
4622
  }
4623
+ /** Execute a REPL command and synchronize editor state before resolving. */
4624
+ async repl(command) {
4625
+ try {
4626
+ const result = await this.post('repl', { command });
4627
+ this.applyReplState(result.state);
4628
+ return { output: result.output };
4629
+ }
4630
+ catch (error) {
4631
+ // REPL execution can fail after applying some operations.
4632
+ if (error instanceof AlgeoError) {
4633
+ const details = error.details;
4634
+ if (details?.state)
4635
+ this.applyReplState(details.state);
4636
+ }
4637
+ throw error;
4638
+ }
4639
+ }
4640
+ applyReplState(state) {
4641
+ this.currentContent = undefined;
4642
+ this.slideCount = state.slideCount;
4643
+ this.currentSlideIndex = state.currentSlideIndex;
4644
+ this.historyCount = state.historyCount;
4645
+ this.historyCurrentIndex = state.historyCurrentIndex;
4646
+ }
4630
4647
  async initialize(options = {}, baseUrl) {
4631
4648
  if (!options.auth?.appId?.trim()) {
4632
4649
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
@@ -4639,7 +4656,8 @@ class EmbeddedEditor extends EmbeddedTarget {
4639
4656
  await this.init({
4640
4657
  baseUrl,
4641
4658
  auth: options.auth,
4642
- initialId: options.shareId,
4659
+ initialId: options.initialContent ? undefined : options.shareId,
4660
+ cameraMode: options.initialContent ? undefined : options.initialMode,
4643
4661
  });
4644
4662
  if (options.fonts) {
4645
4663
  await this.post('setFontConfig', { config: options.fonts });
@@ -3863,12 +3863,6 @@ var AlgeoError = class extends Error {
3863
3863
  this.name = "AlgeoError";
3864
3864
  }
3865
3865
  };
3866
- objectType({
3867
- text: stringType().optional(),
3868
- images: arrayType(stringType().trim().min(1)).optional(),
3869
- openPanel: booleanType().optional(),
3870
- focus: booleanType().optional()
3871
- }).passthrough();
3872
3866
  var openAiChatMessageV1Schema = objectType({
3873
3867
  role: stringType(),
3874
3868
  content: unionType([
@@ -3882,23 +3876,9 @@ var openAiChatMessageV1Schema = objectType({
3882
3876
  name: stringType().optional()
3883
3877
  }).passthrough();
3884
3878
  objectType({
3885
- model: stringType().trim().min(1),
3886
- input: unionType([
3887
- stringType(),
3888
- arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
3889
- ]).optional(),
3890
- previous_response_id: stringType().trim().min(1).optional(),
3891
- instructions: stringType().optional(),
3892
- temperature: numberType().min(0).max(2).optional(),
3893
- max_output_tokens: numberType().int().positive().optional(),
3894
- metadata: recordType(unknownType()).optional()
3895
- }).passthrough().superRefine((value, ctx) => {
3896
- if (!("input" in value) && !("previous_response_id" in value)) {
3897
- ctx.addIssue({
3898
- code: ZodIssueCode.custom,
3899
- message: "input or previous_response_id is required."
3900
- });
3901
- }
3879
+ model_id: stringType(),
3880
+ messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3881
+ extra_openai_params: recordType(unknownType()).optional()
3902
3882
  });
3903
3883
  objectType({
3904
3884
  id: stringType(),
@@ -4029,7 +4009,7 @@ function convertToLatest(content) {
4029
4009
  }
4030
4010
 
4031
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4032
- const VERSION = '2.14.1';
4012
+ const VERSION = '2.15.0';
4033
4013
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4034
4014
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4035
4015
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4150,10 +4130,10 @@ function buildEmbedSrc(options) {
4150
4130
  const path = getEmbedPath(mode);
4151
4131
  const appId = options.auth?.appId?.trim() ?? '';
4152
4132
  const initialId = options.initialId?.trim();
4153
- if (!initialId) {
4154
- return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
4155
- }
4156
- return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
4133
+ const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4134
+ return mode === 'editor' && options.cameraMode
4135
+ ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4136
+ : src;
4157
4137
  }
4158
4138
 
4159
4139
  class EmbeddedTarget {
@@ -4536,12 +4516,25 @@ class EmbeddedEditor extends EmbeddedTarget {
4536
4516
  this.slides = {
4537
4517
  getCount: () => this.slideCount,
4538
4518
  getCurrentIndex: () => this.currentSlideIndex,
4519
+ getInfo: async (index) => this.post('getSlideInfo', {
4520
+ ...(index === undefined ? {} : { index }),
4521
+ }),
4539
4522
  getViewBounds: async (index) => {
4540
4523
  const result = await this.post('getViewBounds', {
4541
4524
  ...(index === undefined ? {} : { index }),
4542
4525
  });
4543
4526
  return result.viewBounds;
4544
4527
  },
4528
+ getViewCamera3d: async (index) => {
4529
+ const result = await this.post('getViewCamera3d', {
4530
+ ...(index === undefined ? {} : { index }),
4531
+ });
4532
+ return result.viewCamera3d;
4533
+ },
4534
+ setViewCamera3d: async (options) => {
4535
+ await this.post('setViewCamera3d', { ...options });
4536
+ await this.refreshHistoryState();
4537
+ },
4545
4538
  setViewBounds: async (options) => {
4546
4539
  await this.post('setViewBounds', { ...options });
4547
4540
  },
@@ -4625,6 +4618,30 @@ class EmbeddedEditor extends EmbeddedTarget {
4625
4618
  },
4626
4619
  };
4627
4620
  }
4621
+ /** Execute a REPL command and synchronize editor state before resolving. */
4622
+ async repl(command) {
4623
+ try {
4624
+ const result = await this.post('repl', { command });
4625
+ this.applyReplState(result.state);
4626
+ return { output: result.output };
4627
+ }
4628
+ catch (error) {
4629
+ // REPL execution can fail after applying some operations.
4630
+ if (error instanceof AlgeoError) {
4631
+ const details = error.details;
4632
+ if (details?.state)
4633
+ this.applyReplState(details.state);
4634
+ }
4635
+ throw error;
4636
+ }
4637
+ }
4638
+ applyReplState(state) {
4639
+ this.currentContent = undefined;
4640
+ this.slideCount = state.slideCount;
4641
+ this.currentSlideIndex = state.currentSlideIndex;
4642
+ this.historyCount = state.historyCount;
4643
+ this.historyCurrentIndex = state.historyCurrentIndex;
4644
+ }
4628
4645
  async initialize(options = {}, baseUrl) {
4629
4646
  if (!options.auth?.appId?.trim()) {
4630
4647
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
@@ -4637,7 +4654,8 @@ class EmbeddedEditor extends EmbeddedTarget {
4637
4654
  await this.init({
4638
4655
  baseUrl,
4639
4656
  auth: options.auth,
4640
- initialId: options.shareId,
4657
+ initialId: options.initialContent ? undefined : options.shareId,
4658
+ cameraMode: options.initialContent ? undefined : options.initialMode,
4641
4659
  });
4642
4660
  if (options.fonts) {
4643
4661
  await this.post('setFontConfig', { config: options.fonts });
@@ -3869,12 +3869,6 @@
3869
3869
  this.name = "AlgeoError";
3870
3870
  }
3871
3871
  };
3872
- objectType({
3873
- text: stringType().optional(),
3874
- images: arrayType(stringType().trim().min(1)).optional(),
3875
- openPanel: booleanType().optional(),
3876
- focus: booleanType().optional()
3877
- }).passthrough();
3878
3872
  var openAiChatMessageV1Schema = objectType({
3879
3873
  role: stringType(),
3880
3874
  content: unionType([
@@ -3888,23 +3882,9 @@
3888
3882
  name: stringType().optional()
3889
3883
  }).passthrough();
3890
3884
  objectType({
3891
- model: stringType().trim().min(1),
3892
- input: unionType([
3893
- stringType(),
3894
- arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
3895
- ]).optional(),
3896
- previous_response_id: stringType().trim().min(1).optional(),
3897
- instructions: stringType().optional(),
3898
- temperature: numberType().min(0).max(2).optional(),
3899
- max_output_tokens: numberType().int().positive().optional(),
3900
- metadata: recordType(unknownType()).optional()
3901
- }).passthrough().superRefine((value, ctx) => {
3902
- if (!("input" in value) && !("previous_response_id" in value)) {
3903
- ctx.addIssue({
3904
- code: ZodIssueCode.custom,
3905
- message: "input or previous_response_id is required."
3906
- });
3907
- }
3885
+ model_id: stringType(),
3886
+ messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3887
+ extra_openai_params: recordType(unknownType()).optional()
3908
3888
  });
3909
3889
  objectType({
3910
3890
  id: stringType(),
@@ -4035,7 +4015,7 @@
4035
4015
  }
4036
4016
 
4037
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4038
- const VERSION = '2.14.1';
4018
+ const VERSION = '2.15.0';
4039
4019
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4040
4020
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4041
4021
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4156,10 +4136,10 @@
4156
4136
  const path = getEmbedPath(mode);
4157
4137
  const appId = options.auth?.appId?.trim() ?? '';
4158
4138
  const initialId = options.initialId?.trim();
4159
- if (!initialId) {
4160
- return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
4161
- }
4162
- return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
4139
+ const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4140
+ return mode === 'editor' && options.cameraMode
4141
+ ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4142
+ : src;
4163
4143
  }
4164
4144
 
4165
4145
  class EmbeddedTarget {
@@ -4542,12 +4522,25 @@
4542
4522
  this.slides = {
4543
4523
  getCount: () => this.slideCount,
4544
4524
  getCurrentIndex: () => this.currentSlideIndex,
4525
+ getInfo: async (index) => this.post('getSlideInfo', {
4526
+ ...(index === undefined ? {} : { index }),
4527
+ }),
4545
4528
  getViewBounds: async (index) => {
4546
4529
  const result = await this.post('getViewBounds', {
4547
4530
  ...(index === undefined ? {} : { index }),
4548
4531
  });
4549
4532
  return result.viewBounds;
4550
4533
  },
4534
+ getViewCamera3d: async (index) => {
4535
+ const result = await this.post('getViewCamera3d', {
4536
+ ...(index === undefined ? {} : { index }),
4537
+ });
4538
+ return result.viewCamera3d;
4539
+ },
4540
+ setViewCamera3d: async (options) => {
4541
+ await this.post('setViewCamera3d', { ...options });
4542
+ await this.refreshHistoryState();
4543
+ },
4551
4544
  setViewBounds: async (options) => {
4552
4545
  await this.post('setViewBounds', { ...options });
4553
4546
  },
@@ -4631,6 +4624,30 @@
4631
4624
  },
4632
4625
  };
4633
4626
  }
4627
+ /** Execute a REPL command and synchronize editor state before resolving. */
4628
+ async repl(command) {
4629
+ try {
4630
+ const result = await this.post('repl', { command });
4631
+ this.applyReplState(result.state);
4632
+ return { output: result.output };
4633
+ }
4634
+ catch (error) {
4635
+ // REPL execution can fail after applying some operations.
4636
+ if (error instanceof AlgeoError) {
4637
+ const details = error.details;
4638
+ if (details?.state)
4639
+ this.applyReplState(details.state);
4640
+ }
4641
+ throw error;
4642
+ }
4643
+ }
4644
+ applyReplState(state) {
4645
+ this.currentContent = undefined;
4646
+ this.slideCount = state.slideCount;
4647
+ this.currentSlideIndex = state.currentSlideIndex;
4648
+ this.historyCount = state.historyCount;
4649
+ this.historyCurrentIndex = state.historyCurrentIndex;
4650
+ }
4634
4651
  async initialize(options = {}, baseUrl) {
4635
4652
  if (!options.auth?.appId?.trim()) {
4636
4653
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
@@ -4643,7 +4660,8 @@
4643
4660
  await this.init({
4644
4661
  baseUrl,
4645
4662
  auth: options.auth,
4646
- initialId: options.shareId,
4663
+ initialId: options.initialContent ? undefined : options.shareId,
4664
+ cameraMode: options.initialContent ? undefined : options.initialMode,
4647
4665
  });
4648
4666
  if (options.fonts) {
4649
4667
  await this.post('setFontConfig', { config: options.fonts });
@@ -1,5 +1,5 @@
1
1
  import { EmbeddedTarget } from './embedded-target';
2
- import { type AiApi, type AiCancelEvent, type AlgeoEditorCreateOptions, type ContentChangeEvent, type DocumentApi, type EmbedRequestMessage, type EmbeddedEditorEventListenerMap, type EmbeddedEditorEventMap, type EmbeddedEditorEventName, type HistoryApi, type ModeApi, type SaveEvent, type SlidesApi } from './shared';
2
+ import { type AiApi, type AiCancelEvent, type ReplResult, type AlgeoEditorCreateOptions, type ContentChangeEvent, type DocumentApi, type EmbedRequestMessage, type EmbeddedEditorEventListenerMap, type EmbeddedEditorEventMap, type EmbeddedEditorEventName, type HistoryApi, type ModeApi, type SaveEvent, type SlidesApi } from './shared';
3
3
  export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedEditorEventListenerMap> {
4
4
  private resourceLibrary?;
5
5
  private readonly resourceLibraryRequests;
@@ -16,6 +16,9 @@ export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMa
16
16
  private uiConfig;
17
17
  private activeAiRun?;
18
18
  constructor(container: HTMLElement);
19
+ /** Execute a REPL command and synchronize editor state before resolving. */
20
+ repl(command: string): Promise<ReplResult>;
21
+ private applyReplState;
19
22
  initialize(options?: AlgeoEditorCreateOptions, baseUrl?: string): Promise<void>;
20
23
  protected handleEventMessage(event: ContentChangeEvent | SaveEvent | {
21
24
  type: 'slideChange';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
2
2
  export type { FileContentAny, 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, 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, SetViewBoundsOptions, 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, SetViewBoundsOptions, SetViewCamera3dOptions, ViewCamera3d, SlideChangeEvent, SlideIndexResult, SlideInfo, 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
@@ -76,6 +76,8 @@ export interface AlgeoEditorCreateOptions {
76
76
  auth?: AlgeoEditorAuthOptions;
77
77
  shareId?: string;
78
78
  initialContent?: FileContentAny;
79
+ /** 空白画板模式,默认 2d。初始化优先级:initialContent > shareId > 空白画板。 */
80
+ initialMode?: '2d' | '3d';
79
81
  ui?: AlgeoEditorUiConfig;
80
82
  /** 字体资源、字体选择器列表及默认字体配置。 */
81
83
  fonts?: AlgeoFontConfig;
@@ -238,9 +240,46 @@ export interface SetMasterTemplateResult {
238
240
  export interface SwitchSlideResult {
239
241
  success: true;
240
242
  }
243
+ export interface SlideInfo {
244
+ /** 画板索引,从 0 开始。 */
245
+ index: number;
246
+ /** 导出功能使用的画板索引,等于 index + 1。 */
247
+ exportIndex: number;
248
+ cameraMode: '2d' | '3d';
249
+ }
241
250
  export interface GetSlideCountResult {
242
251
  count: number;
243
252
  }
253
+ /** 3D 固定视图的对外参数;角度单位为度,尺寸和截取坐标单位为逻辑像素。 */
254
+ export interface ViewCamera3d {
255
+ offset: [number, number, number];
256
+ yawDeg: number;
257
+ pitchDeg: number;
258
+ scale: number;
259
+ projection: 'orthographic' | 'perspective' | 'oblique';
260
+ obliqueAngleDeg: number;
261
+ obliqueScaleRatio: number;
262
+ width: number;
263
+ height: number;
264
+ /** null 表示不截取,截取坐标原点为完整视口左上角。 */
265
+ crop: {
266
+ left: number;
267
+ top: number;
268
+ right: number;
269
+ bottom: number;
270
+ } | null;
271
+ }
272
+ export interface GetViewCamera3dResult {
273
+ viewCamera3d: Partial<ViewCamera3d> | null;
274
+ }
275
+ export interface SetViewCamera3dOptions {
276
+ /** 从 0 开始;省略时操作当前画板。 */
277
+ index?: number;
278
+ /** 提供参数时默认启用;false 关闭固定视图但保留参数。 */
279
+ enabled?: boolean;
280
+ /** 局部更新;省略字段沿用保存值,无保存值时使用默认值(1920 × 1080)。 */
281
+ viewCamera3d?: Partial<ViewCamera3d>;
282
+ }
244
283
  export interface GetViewBoundsResult {
245
284
  /** 与 ExportImageViewMode.viewBound 格式一致,可直接传给 exportImage。 */
246
285
  viewBounds: ExportViewBound | null;
@@ -295,6 +334,18 @@ export interface ExportViewBound {
295
334
  * 3D 画板的导出相机覆盖项。未提供的字段沿用画板当前 camera3d。
296
335
  */
297
336
  export interface ExportViewCamera3D {
337
+ projection?: 'orthographic' | 'perspective' | 'oblique';
338
+ /** 斜投影方向角,单位为弧度。 */
339
+ obliqueAngle?: number;
340
+ obliqueScaleRatio?: number;
341
+ cropEnabled?: boolean;
342
+ /** 完整逻辑视口内的截取范围,原点为左上角。 */
343
+ crop?: {
344
+ left: number;
345
+ top: number;
346
+ right: number;
347
+ bottom: number;
348
+ };
298
349
  offset?: [number, number, number];
299
350
  pitch?: number;
300
351
  yaw?: number;
@@ -420,8 +471,13 @@ export interface DocumentApi {
420
471
  export interface SlidesApi {
421
472
  getCount(): number;
422
473
  getCurrentIndex(): number;
474
+ /** 查询指定画板的信息;index 从 0 开始,省略时读取当前画板。 */
475
+ getInfo(index?: number): Promise<SlideInfo>;
423
476
  getViewBounds(index?: number): Promise<ExportViewBound | null>;
424
477
  setViewBounds(options: SetViewBoundsOptions): Promise<void>;
478
+ /** 优先返回已启用的 3D 固定视图,否则返回画板相机已有参数(不含宽高和截取);2D 返回 null。 */
479
+ getViewCamera3d(index?: number): Promise<Partial<ViewCamera3d> | null>;
480
+ setViewCamera3d(options: SetViewCamera3dOptions): Promise<void>;
425
481
  switchTo(index: number): Promise<void>;
426
482
  add(): Promise<SlideIndexResult>;
427
483
  addAt(index: number): Promise<SlideIndexResult>;
@@ -478,6 +534,7 @@ export declare function normalizeMode(mode?: AlgeoEmbedMode): AlgeoEmbedMode;
478
534
  export declare function getEmbedPath(mode: AlgeoEmbedMode): string;
479
535
  export interface EmbedInitOptions extends AlgeoSdkOptions {
480
536
  auth?: AlgeoEditorAuthOptions;
537
+ cameraMode?: '2d' | '3d';
481
538
  }
482
539
  export declare function buildEmbedSrc(options: EmbedInitOptions): string;
483
540
  export type KnownEventName = 'ready' | 'contentChange' | 'slideChange' | 'save' | 'aiRequest' | 'aiCancel';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.14.1",
3
+ "version": "2.15.0",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",