@dajiaoai/algeo-sdk 2.16.2 → 2.17.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,7 +2,7 @@
2
2
 
3
3
  大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
4
4
 
5
- 当前版本:**2.16.2**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.16.2)。
5
+ 当前版本:**2.17.0**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases)。
6
6
 
7
7
  ## 交流与支持
8
8
 
@@ -342,7 +342,7 @@ type AlgeoCreateOptions =
342
342
  | ---------------- | ------------------------------ | ------ | ------------------------------------------------------ |
343
343
  | `auth` | `{ appId: string }` | - | 编辑模式鉴权参数,其中 `appId` 会参与默认路由生成 |
344
344
  | `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
345
- | `initialContent` | `FileContentAny` | - | 初始化后自动注入的文件内容;SDK 会自动转换为最新格式 |
345
+ | `initialContent` | `FileContentInput` | - | 初始化后加载的文件内容,由几何画板业务判断版本并迁移 |
346
346
  | `initialMode` | `'2d' \| '3d'` | `'2d'` | 空白画板模式,仅在没有初始内容或分享文件时生效 |
347
347
  | `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
348
348
  | `masterTemplates` | `MasterTemplateCallbacks` | - | 只读系统母版列表回调 |
@@ -508,13 +508,15 @@ SDK 内部已通过 `ResizeObserver` 在容器从隐藏(`display:none`,尺
508
508
 
509
509
  ---
510
510
 
511
- ##### `presentation.loadFile(content: FileContentAny): Promise<LoadFileResult>`
511
+ SDK 将文件内容原样传给主站。
512
+
513
+ ##### `presentation.loadFile(content: FileContentInput): Promise<LoadFileResult>`
512
514
 
513
515
  加载完整文件数据(覆盖式)。
514
516
 
515
517
  | 参数 | 类型 | 说明 |
516
518
  | --------- | ------------- | ------------ |
517
- | `content` | `FileContentAny` | 协议包支持读取的文件内容对象 |
519
+ | `content` | `FileContentInput` | 传给主站进行版本判断、迁移和校验的文件内容对象 |
518
520
 
519
521
  **返回值:** `{ success: true }`
520
522
 
@@ -583,7 +585,7 @@ const { output } = await presentation.repl('list');
583
585
 
584
586
  | 方法 | 说明 |
585
587
  | ---------------------- | -------------------------------- |
586
- | `loadContent(content: FileContentAny)` | 加载完整画板文件内容,并自动转换为最新格式 |
588
+ | `loadContent(content: FileContentInput)` | 加载完整画板文件内容,由主站判断版本、迁移和校验 |
587
589
  | `getContent(): Promise<FileContentLatest>` | 异步获取 iframe 当前实时画板内容 |
588
590
 
589
591
  #### `editor.slides`
@@ -1,33 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const SDK_LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="none" viewBox="0 0 36 36">
4
- <g clip-path="url(#a)">
5
- <path stroke="#A668B8" stroke-width="3.819" d="m30.261 29.85-5.368-23.9c-.163-.723-1.126-.875-1.503-.237l-9.082 15.349a.818.818 0 0 0 .288 1.12l14.45 8.551a.818.818 0 0 0 1.215-.884Z"/>
6
- <path stroke="#01B88B" stroke-width="3.819" d="M5.335 11.746V30.12c6.605.315 14.644.647 15.468-8.963.165-1.922-.34-4.035-.824-5.9-.851-3.276-3.854-5.913-12.59-5.913"/>
7
- <path fill="#A668B8" d="m16.483 13.62 2.182-3.682 3.273 1.91-3.682 6.137-1.773-4.364Z"/>
8
- </g>
9
- <defs>
10
- <clipPath id="a">
11
- <path fill="#fff" d="M0 0h36v36H0z"/>
12
- </clipPath>
13
- </defs>
14
- </svg>`;
15
- const BADGE_STYLE = 'background-color: #f1faf7; background-position: 9px center;' +
16
- 'background-repeat: no-repeat; background-size: 24px 24px;' +
17
- 'border: 1px solid #9cd4c5; border-radius: 4px; padding: 6px 12px 6px 42px;' +
18
- 'color: #123e35; font-size: 14px; font-weight: bold;';
19
- const TITLE_STYLE = 'background-color: #174e42; color: #fff; font-weight: bold; padding: 2px 8px;';
20
- const DIVIDER = '+------------------------------------------------------+';
21
- function logSdk(...entry) {
22
- if (entry[0] === 'debug') {
23
- const [, message, ...details] = entry;
24
- console.debug('[Algeo SDK]', message, ...details);
25
- return;
26
- }
27
- const [, { title, lines }] = entry;
28
- console.info(`%cALGEO SDK / 大角几何%c\n\n${DIVIDER}\n| %c%s%c\n%s\n${DIVIDER}`, `background-image: url(data:image/svg+xml;base64,${btoa(SDK_LOGO)});${BADGE_STYLE}`, '', TITLE_STYLE, title, '', ['|', ...lines.map((line) => (line ? `| ${line}` : '|'))].join('\n'));
29
- }
30
-
31
3
  var util;
32
4
  (function (util) {
33
5
  util.assertEqual = (_) => { };
@@ -3893,6 +3865,12 @@ var AlgeoError = class extends Error {
3893
3865
  this.name = "AlgeoError";
3894
3866
  }
3895
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();
3896
3874
  var openAiChatMessageV1Schema = objectType({
3897
3875
  role: stringType(),
3898
3876
  content: unionType([
@@ -3906,9 +3884,23 @@ var openAiChatMessageV1Schema = objectType({
3906
3884
  name: stringType().optional()
3907
3885
  }).passthrough();
3908
3886
  objectType({
3909
- model_id: stringType(),
3910
- messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3911
- extra_openai_params: recordType(unknownType()).optional()
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
+ }
3912
3904
  });
3913
3905
  objectType({
3914
3906
  id: stringType(),
@@ -4027,19 +4019,47 @@ function upgradeFromV10ToV11(content) {
4027
4019
  }
4028
4020
  };
4029
4021
  }
4030
- function convertToLatest(content) {
4022
+ function convertToLatest$1(content) {
4031
4023
  const version = content.metadata.version;
4032
4024
  if (version === "11") {
4033
4025
  return content;
4034
4026
  }
4035
4027
  if (version === "10") {
4036
- return convertToLatest(upgradeFromV10ToV11(content));
4028
+ return convertToLatest$1(upgradeFromV10ToV11(content));
4037
4029
  }
4038
4030
  throw new Error(`Unsupported FileContent version: ${version}`);
4039
4031
  }
4040
4032
 
4033
+ const SDK_LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="none" viewBox="0 0 36 36">
4034
+ <g clip-path="url(#a)">
4035
+ <path stroke="#A668B8" stroke-width="3.819" d="m30.261 29.85-5.368-23.9c-.163-.723-1.126-.875-1.503-.237l-9.082 15.349a.818.818 0 0 0 .288 1.12l14.45 8.551a.818.818 0 0 0 1.215-.884Z"/>
4036
+ <path stroke="#01B88B" stroke-width="3.819" d="M5.335 11.746V30.12c6.605.315 14.644.647 15.468-8.963.165-1.922-.34-4.035-.824-5.9-.851-3.276-3.854-5.913-12.59-5.913"/>
4037
+ <path fill="#A668B8" d="m16.483 13.62 2.182-3.682 3.273 1.91-3.682 6.137-1.773-4.364Z"/>
4038
+ </g>
4039
+ <defs>
4040
+ <clipPath id="a">
4041
+ <path fill="#fff" d="M0 0h36v36H0z"/>
4042
+ </clipPath>
4043
+ </defs>
4044
+ </svg>`;
4045
+ const BADGE_STYLE = 'background-color: #f1faf7; background-position: 9px center;' +
4046
+ 'background-repeat: no-repeat; background-size: 24px 24px;' +
4047
+ 'border: 1px solid #9cd4c5; border-radius: 4px; padding: 6px 12px 6px 42px;' +
4048
+ 'color: #123e35; font-size: 14px; font-weight: bold;';
4049
+ const TITLE_STYLE = 'background-color: #174e42; color: #fff; font-weight: bold; padding: 2px 8px;';
4050
+ const DIVIDER = '+------------------------------------------------------+';
4051
+ function logSdk(...entry) {
4052
+ if (entry[0] === 'debug') {
4053
+ const [, message, ...details] = entry;
4054
+ console.debug('[Algeo SDK]', message, ...details);
4055
+ return;
4056
+ }
4057
+ const [, { title, lines }] = entry;
4058
+ console.info(`%cALGEO SDK / 大角几何%c\n\n${DIVIDER}\n| %c%s%c\n%s\n${DIVIDER}`, `background-image: url(data:image/svg+xml;base64,${btoa(SDK_LOGO)});${BADGE_STYLE}`, '', TITLE_STYLE, title, '', ['|', ...lines.map((line) => (line ? `| ${line}` : '|'))].join('\n'));
4059
+ }
4060
+
4041
4061
  /** SDK 版本号,构建时由 rollup 注入 */
4042
- const VERSION = '2.16.2';
4062
+ const VERSION = '2.17.0';
4043
4063
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4044
4064
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4045
4065
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4501,8 +4521,6 @@ class EmbeddedTarget {
4501
4521
  class EmbeddedPresentation extends EmbeddedTarget {
4502
4522
  constructor(container) {
4503
4523
  super(container, 'presentation');
4504
- this.currentSlideIndex = 0;
4505
- this.slideCount = 0;
4506
4524
  this.appId = '';
4507
4525
  this.uiConfig = {
4508
4526
  logo: true,
@@ -4601,36 +4619,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
4601
4619
  }
4602
4620
  async loadShareById(id) {
4603
4621
  await this.ensureWhitelistAccess('loadShareById');
4604
- const result = await this.post('loadShareById', {
4605
- id,
4606
- });
4607
- this.currentContent = undefined;
4608
- this.currentSlideIndex = 0;
4609
- this.slideCount = 0;
4610
- return result;
4622
+ return this.post('loadShareById', { id });
4611
4623
  }
4612
4624
  async loadFile(content) {
4613
4625
  await this.ensureWhitelistAccess('loadFile');
4614
- const latestContent = convertToLatest(content);
4615
- const result = await this.post('loadContent', {
4616
- content: latestContent,
4617
- });
4618
- this.currentContent = latestContent;
4619
- this.currentSlideIndex = 0;
4620
- this.slideCount = latestContent.slides.length;
4621
- return result;
4626
+ return this.post('loadContent', { content });
4622
4627
  }
4623
4628
  async switchSlide(index) {
4624
4629
  await this.ensureWhitelistAccess('switchSlide');
4625
- const result = await this.post('switchSlide', { index });
4626
- this.currentSlideIndex = index;
4627
- return result;
4630
+ return this.post('switchSlide', { index });
4628
4631
  }
4629
4632
  async getSlideCount() {
4630
4633
  await this.ensureWhitelistAccess('getSlideCount');
4631
- const result = await this.post('getSlideCount', {});
4632
- this.slideCount = result.count;
4633
- return result;
4634
+ return this.post('getSlideCount', {});
4634
4635
  }
4635
4636
  async repl(command) {
4636
4637
  await this.ensureWhitelistAccess('repl');
@@ -4679,12 +4680,9 @@ class EmbeddedEditor extends EmbeddedTarget {
4679
4680
  this.historyCurrentIndex = -1;
4680
4681
  this.uiConfig = {};
4681
4682
  this.document = {
4682
- loadContent: async (content) => {
4683
- await this.loadContent(content, 'loadContent');
4684
- },
4683
+ loadContent: (content) => this.loadContent(content),
4685
4684
  getContent: async () => {
4686
4685
  const result = await this.post('getContent', {});
4687
- this.currentContent = result.content;
4688
4686
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(result.content.slides.length - 1, 0));
4689
4687
  this.slideCount = result.content.slides.length;
4690
4688
  await this.refreshHistoryState();
@@ -4814,7 +4812,6 @@ class EmbeddedEditor extends EmbeddedTarget {
4814
4812
  }
4815
4813
  }
4816
4814
  applyReplState(state) {
4817
- this.currentContent = undefined;
4818
4815
  this.slideCount = state.slideCount;
4819
4816
  this.currentSlideIndex = state.currentSlideIndex;
4820
4817
  this.historyCount = state.historyCount;
@@ -4852,19 +4849,17 @@ class EmbeddedEditor extends EmbeddedTarget {
4852
4849
  if (Object.keys(this.uiConfig).length > 0) {
4853
4850
  await this.mode.setUiConfig(this.uiConfig);
4854
4851
  }
4855
- const content = await this.document.getContent();
4856
- this.currentContent = content;
4857
- this.slideCount = content.slides.length;
4858
4852
  this.currentSlideIndex = 0;
4859
- await this.refreshHistoryState();
4860
4853
  if (options.initialContent) {
4861
- await this.loadContent(options.initialContent, 'initialContent');
4854
+ await this.loadContent(options.initialContent);
4855
+ }
4856
+ else {
4857
+ await this.document.getContent();
4862
4858
  }
4863
4859
  }
4864
4860
  handleEventMessage(event) {
4865
4861
  if (event.type === 'contentChange') {
4866
4862
  if (event.content) {
4867
- this.currentContent = event.content;
4868
4863
  this.slideCount = event.content.slides.length;
4869
4864
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4870
4865
  }
@@ -4879,7 +4874,6 @@ class EmbeddedEditor extends EmbeddedTarget {
4879
4874
  this.cancelActiveAi(event.reason, false);
4880
4875
  return;
4881
4876
  }
4882
- this.currentContent = event.content;
4883
4877
  this.slideCount = event.content.slides.length;
4884
4878
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4885
4879
  }
@@ -5049,13 +5043,10 @@ class EmbeddedEditor extends EmbeddedTarget {
5049
5043
  return false;
5050
5044
  }
5051
5045
  }
5052
- async loadContent(content, source) {
5053
- const latestContent = convertToLatest(content);
5054
- await this.post('loadContent', { content: latestContent });
5055
- this.currentContent = latestContent;
5046
+ async loadContent(content) {
5047
+ await this.post('loadContent', { content });
5056
5048
  this.currentSlideIndex = 0;
5057
- this.slideCount = latestContent.slides.length;
5058
- await this.refreshHistoryState();
5049
+ await this.document.getContent();
5059
5050
  }
5060
5051
  async switchTo(index) {
5061
5052
  await this.post('switchSlide', { index });
@@ -5371,6 +5362,16 @@ async function createPresentation(container, options = {}) {
5371
5362
  return createPresentationInstance(container, options);
5372
5363
  }
5373
5364
 
5365
+ let hasWarnedAboutConvertToLatest = false;
5366
+ /** @deprecated The iframe handles file migration when content is loaded. */
5367
+ const convertToLatest = (content) => {
5368
+ if (!hasWarnedAboutConvertToLatest) {
5369
+ hasWarnedAboutConvertToLatest = true;
5370
+ console.warn('[Algeo SDK] convertToLatest is deprecated. The iframe handles file migration when content is loaded.');
5371
+ }
5372
+ return convertToLatest$1(content);
5373
+ };
5374
+
5374
5375
  exports.AlgeoError = AlgeoError;
5375
5376
  exports.AlgeoSdk = AlgeoSdk;
5376
5377
  exports.EMBED_ERROR_CODES = EMBED_ERROR_CODES;
@@ -1,31 +1,3 @@
1
- const SDK_LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="none" viewBox="0 0 36 36">
2
- <g clip-path="url(#a)">
3
- <path stroke="#A668B8" stroke-width="3.819" d="m30.261 29.85-5.368-23.9c-.163-.723-1.126-.875-1.503-.237l-9.082 15.349a.818.818 0 0 0 .288 1.12l14.45 8.551a.818.818 0 0 0 1.215-.884Z"/>
4
- <path stroke="#01B88B" stroke-width="3.819" d="M5.335 11.746V30.12c6.605.315 14.644.647 15.468-8.963.165-1.922-.34-4.035-.824-5.9-.851-3.276-3.854-5.913-12.59-5.913"/>
5
- <path fill="#A668B8" d="m16.483 13.62 2.182-3.682 3.273 1.91-3.682 6.137-1.773-4.364Z"/>
6
- </g>
7
- <defs>
8
- <clipPath id="a">
9
- <path fill="#fff" d="M0 0h36v36H0z"/>
10
- </clipPath>
11
- </defs>
12
- </svg>`;
13
- const BADGE_STYLE = 'background-color: #f1faf7; background-position: 9px center;' +
14
- 'background-repeat: no-repeat; background-size: 24px 24px;' +
15
- 'border: 1px solid #9cd4c5; border-radius: 4px; padding: 6px 12px 6px 42px;' +
16
- 'color: #123e35; font-size: 14px; font-weight: bold;';
17
- const TITLE_STYLE = 'background-color: #174e42; color: #fff; font-weight: bold; padding: 2px 8px;';
18
- const DIVIDER = '+------------------------------------------------------+';
19
- function logSdk(...entry) {
20
- if (entry[0] === 'debug') {
21
- const [, message, ...details] = entry;
22
- console.debug('[Algeo SDK]', message, ...details);
23
- return;
24
- }
25
- const [, { title, lines }] = entry;
26
- console.info(`%cALGEO SDK / 大角几何%c\n\n${DIVIDER}\n| %c%s%c\n%s\n${DIVIDER}`, `background-image: url(data:image/svg+xml;base64,${btoa(SDK_LOGO)});${BADGE_STYLE}`, '', TITLE_STYLE, title, '', ['|', ...lines.map((line) => (line ? `| ${line}` : '|'))].join('\n'));
27
- }
28
-
29
1
  var util;
30
2
  (function (util) {
31
3
  util.assertEqual = (_) => { };
@@ -3891,6 +3863,12 @@ var AlgeoError = class extends Error {
3891
3863
  this.name = "AlgeoError";
3892
3864
  }
3893
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();
3894
3872
  var openAiChatMessageV1Schema = objectType({
3895
3873
  role: stringType(),
3896
3874
  content: unionType([
@@ -3904,9 +3882,23 @@ var openAiChatMessageV1Schema = objectType({
3904
3882
  name: stringType().optional()
3905
3883
  }).passthrough();
3906
3884
  objectType({
3907
- model_id: stringType(),
3908
- messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3909
- extra_openai_params: recordType(unknownType()).optional()
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
+ }
3910
3902
  });
3911
3903
  objectType({
3912
3904
  id: stringType(),
@@ -4025,19 +4017,47 @@ function upgradeFromV10ToV11(content) {
4025
4017
  }
4026
4018
  };
4027
4019
  }
4028
- function convertToLatest(content) {
4020
+ function convertToLatest$1(content) {
4029
4021
  const version = content.metadata.version;
4030
4022
  if (version === "11") {
4031
4023
  return content;
4032
4024
  }
4033
4025
  if (version === "10") {
4034
- return convertToLatest(upgradeFromV10ToV11(content));
4026
+ return convertToLatest$1(upgradeFromV10ToV11(content));
4035
4027
  }
4036
4028
  throw new Error(`Unsupported FileContent version: ${version}`);
4037
4029
  }
4038
4030
 
4031
+ const SDK_LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="none" viewBox="0 0 36 36">
4032
+ <g clip-path="url(#a)">
4033
+ <path stroke="#A668B8" stroke-width="3.819" d="m30.261 29.85-5.368-23.9c-.163-.723-1.126-.875-1.503-.237l-9.082 15.349a.818.818 0 0 0 .288 1.12l14.45 8.551a.818.818 0 0 0 1.215-.884Z"/>
4034
+ <path stroke="#01B88B" stroke-width="3.819" d="M5.335 11.746V30.12c6.605.315 14.644.647 15.468-8.963.165-1.922-.34-4.035-.824-5.9-.851-3.276-3.854-5.913-12.59-5.913"/>
4035
+ <path fill="#A668B8" d="m16.483 13.62 2.182-3.682 3.273 1.91-3.682 6.137-1.773-4.364Z"/>
4036
+ </g>
4037
+ <defs>
4038
+ <clipPath id="a">
4039
+ <path fill="#fff" d="M0 0h36v36H0z"/>
4040
+ </clipPath>
4041
+ </defs>
4042
+ </svg>`;
4043
+ const BADGE_STYLE = 'background-color: #f1faf7; background-position: 9px center;' +
4044
+ 'background-repeat: no-repeat; background-size: 24px 24px;' +
4045
+ 'border: 1px solid #9cd4c5; border-radius: 4px; padding: 6px 12px 6px 42px;' +
4046
+ 'color: #123e35; font-size: 14px; font-weight: bold;';
4047
+ const TITLE_STYLE = 'background-color: #174e42; color: #fff; font-weight: bold; padding: 2px 8px;';
4048
+ const DIVIDER = '+------------------------------------------------------+';
4049
+ function logSdk(...entry) {
4050
+ if (entry[0] === 'debug') {
4051
+ const [, message, ...details] = entry;
4052
+ console.debug('[Algeo SDK]', message, ...details);
4053
+ return;
4054
+ }
4055
+ const [, { title, lines }] = entry;
4056
+ console.info(`%cALGEO SDK / 大角几何%c\n\n${DIVIDER}\n| %c%s%c\n%s\n${DIVIDER}`, `background-image: url(data:image/svg+xml;base64,${btoa(SDK_LOGO)});${BADGE_STYLE}`, '', TITLE_STYLE, title, '', ['|', ...lines.map((line) => (line ? `| ${line}` : '|'))].join('\n'));
4057
+ }
4058
+
4039
4059
  /** SDK 版本号,构建时由 rollup 注入 */
4040
- const VERSION = '2.16.2';
4060
+ const VERSION = '2.17.0';
4041
4061
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4042
4062
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4043
4063
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4499,8 +4519,6 @@ class EmbeddedTarget {
4499
4519
  class EmbeddedPresentation extends EmbeddedTarget {
4500
4520
  constructor(container) {
4501
4521
  super(container, 'presentation');
4502
- this.currentSlideIndex = 0;
4503
- this.slideCount = 0;
4504
4522
  this.appId = '';
4505
4523
  this.uiConfig = {
4506
4524
  logo: true,
@@ -4599,36 +4617,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
4599
4617
  }
4600
4618
  async loadShareById(id) {
4601
4619
  await this.ensureWhitelistAccess('loadShareById');
4602
- const result = await this.post('loadShareById', {
4603
- id,
4604
- });
4605
- this.currentContent = undefined;
4606
- this.currentSlideIndex = 0;
4607
- this.slideCount = 0;
4608
- return result;
4620
+ return this.post('loadShareById', { id });
4609
4621
  }
4610
4622
  async loadFile(content) {
4611
4623
  await this.ensureWhitelistAccess('loadFile');
4612
- const latestContent = convertToLatest(content);
4613
- const result = await this.post('loadContent', {
4614
- content: latestContent,
4615
- });
4616
- this.currentContent = latestContent;
4617
- this.currentSlideIndex = 0;
4618
- this.slideCount = latestContent.slides.length;
4619
- return result;
4624
+ return this.post('loadContent', { content });
4620
4625
  }
4621
4626
  async switchSlide(index) {
4622
4627
  await this.ensureWhitelistAccess('switchSlide');
4623
- const result = await this.post('switchSlide', { index });
4624
- this.currentSlideIndex = index;
4625
- return result;
4628
+ return this.post('switchSlide', { index });
4626
4629
  }
4627
4630
  async getSlideCount() {
4628
4631
  await this.ensureWhitelistAccess('getSlideCount');
4629
- const result = await this.post('getSlideCount', {});
4630
- this.slideCount = result.count;
4631
- return result;
4632
+ return this.post('getSlideCount', {});
4632
4633
  }
4633
4634
  async repl(command) {
4634
4635
  await this.ensureWhitelistAccess('repl');
@@ -4677,12 +4678,9 @@ class EmbeddedEditor extends EmbeddedTarget {
4677
4678
  this.historyCurrentIndex = -1;
4678
4679
  this.uiConfig = {};
4679
4680
  this.document = {
4680
- loadContent: async (content) => {
4681
- await this.loadContent(content, 'loadContent');
4682
- },
4681
+ loadContent: (content) => this.loadContent(content),
4683
4682
  getContent: async () => {
4684
4683
  const result = await this.post('getContent', {});
4685
- this.currentContent = result.content;
4686
4684
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(result.content.slides.length - 1, 0));
4687
4685
  this.slideCount = result.content.slides.length;
4688
4686
  await this.refreshHistoryState();
@@ -4812,7 +4810,6 @@ class EmbeddedEditor extends EmbeddedTarget {
4812
4810
  }
4813
4811
  }
4814
4812
  applyReplState(state) {
4815
- this.currentContent = undefined;
4816
4813
  this.slideCount = state.slideCount;
4817
4814
  this.currentSlideIndex = state.currentSlideIndex;
4818
4815
  this.historyCount = state.historyCount;
@@ -4850,19 +4847,17 @@ class EmbeddedEditor extends EmbeddedTarget {
4850
4847
  if (Object.keys(this.uiConfig).length > 0) {
4851
4848
  await this.mode.setUiConfig(this.uiConfig);
4852
4849
  }
4853
- const content = await this.document.getContent();
4854
- this.currentContent = content;
4855
- this.slideCount = content.slides.length;
4856
4850
  this.currentSlideIndex = 0;
4857
- await this.refreshHistoryState();
4858
4851
  if (options.initialContent) {
4859
- await this.loadContent(options.initialContent, 'initialContent');
4852
+ await this.loadContent(options.initialContent);
4853
+ }
4854
+ else {
4855
+ await this.document.getContent();
4860
4856
  }
4861
4857
  }
4862
4858
  handleEventMessage(event) {
4863
4859
  if (event.type === 'contentChange') {
4864
4860
  if (event.content) {
4865
- this.currentContent = event.content;
4866
4861
  this.slideCount = event.content.slides.length;
4867
4862
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4868
4863
  }
@@ -4877,7 +4872,6 @@ class EmbeddedEditor extends EmbeddedTarget {
4877
4872
  this.cancelActiveAi(event.reason, false);
4878
4873
  return;
4879
4874
  }
4880
- this.currentContent = event.content;
4881
4875
  this.slideCount = event.content.slides.length;
4882
4876
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4883
4877
  }
@@ -5047,13 +5041,10 @@ class EmbeddedEditor extends EmbeddedTarget {
5047
5041
  return false;
5048
5042
  }
5049
5043
  }
5050
- async loadContent(content, source) {
5051
- const latestContent = convertToLatest(content);
5052
- await this.post('loadContent', { content: latestContent });
5053
- this.currentContent = latestContent;
5044
+ async loadContent(content) {
5045
+ await this.post('loadContent', { content });
5054
5046
  this.currentSlideIndex = 0;
5055
- this.slideCount = latestContent.slides.length;
5056
- await this.refreshHistoryState();
5047
+ await this.document.getContent();
5057
5048
  }
5058
5049
  async switchTo(index) {
5059
5050
  await this.post('switchSlide', { index });
@@ -5369,4 +5360,14 @@ async function createPresentation(container, options = {}) {
5369
5360
  return createPresentationInstance(container, options);
5370
5361
  }
5371
5362
 
5363
+ let hasWarnedAboutConvertToLatest = false;
5364
+ /** @deprecated The iframe handles file migration when content is loaded. */
5365
+ const convertToLatest = (content) => {
5366
+ if (!hasWarnedAboutConvertToLatest) {
5367
+ hasWarnedAboutConvertToLatest = true;
5368
+ console.warn('[Algeo SDK] convertToLatest is deprecated. The iframe handles file migration when content is loaded.');
5369
+ }
5370
+ return convertToLatest$1(content);
5371
+ };
5372
+
5372
5373
  export { AlgeoError, AlgeoSdk, EMBED_ERROR_CODES, EmbeddedEditor, EmbeddedPresentation, VERSION, convertToLatest, create, createEditor, createPresentation };