@dajiaoai/algeo-sdk 2.16.1 → 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.1**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.16.1)。
5
+ 当前版本:**2.17.0**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases)。
6
6
 
7
7
  ## 交流与支持
8
8
 
@@ -35,9 +35,9 @@ npm install @dajiaoai/algeo-sdk
35
35
 
36
36
  ## 使用方式
37
37
 
38
- ### 本地 HTML 文件
38
+ ### 本地使用
39
39
 
40
- 通过 `file://` 直接打开 HTML 时,演示和编辑模式都可以省略 `auth` 或将 `appId` 留空。
40
+ 通过 `file://` 直接打开本地文件,或通过 `localhost`、`127.0.0.1` 访问本地服务时,演示和编辑模式都可以省略 `auth`。本地联调应用授权时,请使用本地 HTTP 服务并配置 `auth.appId` 和域名白名单。详见 [SDK 鉴权说明](https://open.dajiaoai.com/sdk/2/auth)。
41
41
 
42
42
  ```javascript
43
43
  const presentation = await createPresentation(container, { shareId: '33TA3484' });
@@ -301,7 +301,7 @@ create(container, {
301
301
 
302
302
  演示模式快捷入口。该函数负责真正创建并初始化 `EmbeddedPresentation`。
303
303
 
304
- 创建成功后,SDK 会额外调用 `https://open.dajiaoai.com/console/api/whitelist/check`,使用 `options.auth.appId` 与当前页面 `hostname` 做白名单校验。若未命中白名单,iframe 仍会完成初始化并呈现页面,`createPresentation` 仍会成功返回实例,但后续 `loadShareById`、`loadFile`、`switchSlide`、`getSlideCount`、`repl` 等演示模式 API 会被拒绝,并在控制台输出包含方法名的错误,便于接入方感知并处理。
304
+ `createPresentation` 初始化时会加载画板。首次调用 `switchSlide` 等需要授权的方法时,SDK 才校验应用和宿主主机名。校验失败时,该方法返回错误。
305
305
 
306
306
  ```javascript
307
307
  create(container, {
@@ -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`
@@ -3865,6 +3865,12 @@ 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();
3868
3874
  var openAiChatMessageV1Schema = objectType({
3869
3875
  role: stringType(),
3870
3876
  content: unionType([
@@ -3878,9 +3884,23 @@ var openAiChatMessageV1Schema = objectType({
3878
3884
  name: stringType().optional()
3879
3885
  }).passthrough();
3880
3886
  objectType({
3881
- model_id: stringType(),
3882
- messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3883
- 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
+ }
3884
3904
  });
3885
3905
  objectType({
3886
3906
  id: stringType(),
@@ -3999,19 +4019,47 @@ function upgradeFromV10ToV11(content) {
3999
4019
  }
4000
4020
  };
4001
4021
  }
4002
- function convertToLatest(content) {
4022
+ function convertToLatest$1(content) {
4003
4023
  const version = content.metadata.version;
4004
4024
  if (version === "11") {
4005
4025
  return content;
4006
4026
  }
4007
4027
  if (version === "10") {
4008
- return convertToLatest(upgradeFromV10ToV11(content));
4028
+ return convertToLatest$1(upgradeFromV10ToV11(content));
4009
4029
  }
4010
4030
  throw new Error(`Unsupported FileContent version: ${version}`);
4011
4031
  }
4012
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
+
4013
4061
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.16.1';
4062
+ const VERSION = '2.17.0';
4015
4063
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4016
4064
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4017
4065
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4019,6 +4067,34 @@ const EMBED_TIMEOUT_MS = 30000;
4019
4067
  function isLocalFileHost() {
4020
4068
  return typeof window !== 'undefined' && window.location.protocol === 'file:';
4021
4069
  }
4070
+ function isLocalLoopbackHost() {
4071
+ if (typeof window === 'undefined')
4072
+ return false;
4073
+ const { protocol, hostname } = window.location;
4074
+ return ((protocol === 'http:' || protocol === 'https:') &&
4075
+ ['localhost', '127.0.0.1'].includes(hostname));
4076
+ }
4077
+ function readEmbedAppId(auth) {
4078
+ const appId = auth?.appId?.trim() ?? '';
4079
+ if (!appId) {
4080
+ logSdk('notice', {
4081
+ title: '未配置应用 ID(auth.appId)',
4082
+ lines: [
4083
+ '注册应用 > 配置域名白名单 > 填写 auth.appId',
4084
+ '开放平台 https://open.dajiaoai.com/console',
4085
+ '使用许可 https://open.dajiaoai.com/sdk/2/auth',
4086
+ '',
4087
+ '版权 © 大角几何',
4088
+ ],
4089
+ });
4090
+ }
4091
+ return appId;
4092
+ }
4093
+ function requireHttpHostForAppId(appId) {
4094
+ if (appId && isLocalFileHost()) {
4095
+ throw new AlgeoError('file:// 没有可校验的宿主域名。请通过本地 HTTP 服务打开页面,将该主机加入应用白名单后重试。', EMBED_ERROR_CODES.BAD_REQUEST);
4096
+ }
4097
+ }
4022
4098
  let requestIdCounter = 0;
4023
4099
  function generateRequestId() {
4024
4100
  return `req-${Date.now()}-${++requestIdCounter}`;
@@ -4133,10 +4209,13 @@ function buildEmbedSrc(options) {
4133
4209
  const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
4134
4210
  const mode = normalizeMode(options.mode);
4135
4211
  const path = getEmbedPath(mode);
4136
- const localFile = isLocalFileHost();
4137
- const appId = options.auth?.appId?.trim() || (localFile ? 'local' : '');
4212
+ const appId = options.auth?.appId?.trim();
4213
+ const localFile = !appId && isLocalFileHost();
4214
+ const localLoopback = !appId && isLocalLoopbackHost();
4138
4215
  const initialId = options.initialId?.trim();
4139
- const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4216
+ const initialPath = initialId ? `/${encodeURIComponent(initialId)}` : '';
4217
+ const routeAppId = appId || (localFile || localLoopback ? 'local' : 'public');
4218
+ const src = `${baseUrl}${path}/${encodeURIComponent(routeAppId)}${initialPath}`;
4140
4219
  const params = new URLSearchParams();
4141
4220
  if (mode === 'editor' && options.cameraMode) {
4142
4221
  params.set('cameraMode', options.cameraMode);
@@ -4144,6 +4223,9 @@ function buildEmbedSrc(options) {
4144
4223
  if (mode === 'editor' && localFile) {
4145
4224
  params.set('localFile', '1');
4146
4225
  }
4226
+ if (mode === 'editor' && localLoopback) {
4227
+ params.set('localLoopback', '1');
4228
+ }
4147
4229
  return params.size ? `${src}?${params}` : src;
4148
4230
  }
4149
4231
  const MASTER_TEMPLATE_OPERATIONS = [
@@ -4243,6 +4325,7 @@ class EmbeddedTarget {
4243
4325
  ...options,
4244
4326
  mode: this.embedMode,
4245
4327
  });
4328
+ const iframeOrigin = new URL(src, window.location.href).origin;
4246
4329
  let settled = false;
4247
4330
  let initTimeoutId;
4248
4331
  const finalizeFailure = (error) => {
@@ -4295,6 +4378,19 @@ class EmbeddedTarget {
4295
4378
  iframe.contentWindow?.postMessage({ type: 'localFileHostConfirmed', requestId: data.requestId }, '*');
4296
4379
  return;
4297
4380
  }
4381
+ if (data?.type === 'localLoopbackHostCheck' &&
4382
+ typeof data.requestId === 'string' &&
4383
+ !options.auth?.appId?.trim() &&
4384
+ isLocalLoopbackHost()) {
4385
+ iframe.contentWindow?.postMessage({ type: 'localLoopbackHostConfirmed', requestId: data.requestId }, iframeOrigin);
4386
+ return;
4387
+ }
4388
+ if (this.embedMode === 'editor' &&
4389
+ e.origin === iframeOrigin &&
4390
+ data?.type === 'embedEditAuthorizationFailed') {
4391
+ finalizeFailure(new AlgeoError('白名单校验未通过。请在开放平台将当前主机加入应用白名单后重试。', EMBED_ERROR_CODES.BAD_REQUEST));
4392
+ return;
4393
+ }
4298
4394
  if (isReadyMessage(data)) {
4299
4395
  if (this._ready) {
4300
4396
  return;
@@ -4425,8 +4521,7 @@ class EmbeddedTarget {
4425
4521
  class EmbeddedPresentation extends EmbeddedTarget {
4426
4522
  constructor(container) {
4427
4523
  super(container, 'presentation');
4428
- this.currentSlideIndex = 0;
4429
- this.slideCount = 0;
4524
+ this.appId = '';
4430
4525
  this.uiConfig = {
4431
4526
  logo: true,
4432
4527
  slidePanel: true,
@@ -4436,19 +4531,30 @@ class EmbeddedPresentation extends EmbeddedTarget {
4436
4531
  this.mode = {
4437
4532
  getUiConfig: () => ({ ...this.uiConfig }),
4438
4533
  setUiConfig: async (config) => {
4534
+ await this.ensureWhitelistAccess('setUiConfig');
4439
4535
  await this.post('setUiConfig', { config });
4440
4536
  this.uiConfig = {
4441
4537
  ...this.uiConfig,
4442
4538
  ...config,
4443
4539
  };
4444
4540
  },
4445
- setMasterTemplate: (template) => {
4446
- this.ensureWhitelistAccess('setMasterTemplate');
4541
+ setMasterTemplate: async (template) => {
4542
+ await this.ensureWhitelistAccess('setMasterTemplate');
4447
4543
  return this.post('setMasterTemplate', { template });
4448
4544
  },
4449
4545
  };
4450
4546
  }
4451
4547
  async initialize(options = {}, baseUrl) {
4548
+ const appId = readEmbedAppId(options.auth);
4549
+ if (!this.iframe) {
4550
+ this.appId = appId;
4551
+ this.whitelistCheck = undefined;
4552
+ }
4553
+ // 未配置应用的部署页面按默认样式展示公开分享。
4554
+ if (!appId && !isLocalFileHost() && !isLocalLoopbackHost()) {
4555
+ await this.init({ baseUrl, initialId: options.shareId });
4556
+ return;
4557
+ }
4452
4558
  this.uiConfig = {
4453
4559
  logo: true,
4454
4560
  slidePanel: true,
@@ -4467,7 +4573,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
4467
4573
  if (options.fonts) {
4468
4574
  await this.post('setFontConfig', { config: options.fonts });
4469
4575
  }
4470
- await this.mode.setUiConfig(this.uiConfig);
4576
+ await this.post('setUiConfig', { config: this.uiConfig });
4471
4577
  }
4472
4578
  acceptsEventMessage() {
4473
4579
  return false;
@@ -4475,49 +4581,60 @@ class EmbeddedPresentation extends EmbeddedTarget {
4475
4581
  setWhitelistError(error) {
4476
4582
  this.whitelistError = error;
4477
4583
  }
4478
- ensureWhitelistAccess(methodName) {
4479
- if (!this.whitelistError) {
4480
- return;
4584
+ async checkWhitelist(appId) {
4585
+ if (!appId) {
4586
+ if (isLocalFileHost() || isLocalLoopbackHost())
4587
+ return;
4588
+ throw new AlgeoError('正式接入演示模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4589
+ }
4590
+ requireHttpHostForAppId(appId);
4591
+ const host = window.location.hostname;
4592
+ const url = new URL('https://open.dajiaoai.com/console/api/whitelist/check');
4593
+ url.searchParams.set('appId', appId);
4594
+ url.searchParams.set('host', host);
4595
+ try {
4596
+ const response = await fetch(url.toString(), { cache: 'no-store' });
4597
+ if (response.ok && (await response.json()).matched === true)
4598
+ return;
4599
+ }
4600
+ catch {
4601
+ // 网络或响应解析失败时按鉴权失败处理。
4602
+ }
4603
+ throw new AlgeoError(`白名单校验未通过,appId="${appId}",host="${host}"。请在开放平台将该主机加入应用白名单后重试。`, EMBED_ERROR_CODES.BAD_REQUEST);
4604
+ }
4605
+ async ensureWhitelistAccess(methodName) {
4606
+ try {
4607
+ if (this.whitelistError)
4608
+ throw this.whitelistError;
4609
+ this.whitelistCheck ?? (this.whitelistCheck = this.checkWhitelist(this.appId));
4610
+ await this.whitelistCheck;
4611
+ }
4612
+ catch (cause) {
4613
+ if (!(cause instanceof AlgeoError))
4614
+ throw cause;
4615
+ const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${cause.message}`, cause.code, cause.details);
4616
+ console.error(error);
4617
+ throw error;
4481
4618
  }
4482
- const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
4483
- console.error(error);
4484
- throw error;
4485
4619
  }
4486
4620
  async loadShareById(id) {
4487
- this.ensureWhitelistAccess('loadShareById');
4488
- const result = await this.post('loadShareById', {
4489
- id,
4490
- });
4491
- this.currentContent = undefined;
4492
- this.currentSlideIndex = 0;
4493
- this.slideCount = 0;
4494
- return result;
4621
+ await this.ensureWhitelistAccess('loadShareById');
4622
+ return this.post('loadShareById', { id });
4495
4623
  }
4496
4624
  async loadFile(content) {
4497
- this.ensureWhitelistAccess('loadFile');
4498
- const latestContent = convertToLatest(content);
4499
- const result = await this.post('loadContent', {
4500
- content: latestContent,
4501
- });
4502
- this.currentContent = latestContent;
4503
- this.currentSlideIndex = 0;
4504
- this.slideCount = latestContent.slides.length;
4505
- return result;
4625
+ await this.ensureWhitelistAccess('loadFile');
4626
+ return this.post('loadContent', { content });
4506
4627
  }
4507
4628
  async switchSlide(index) {
4508
- this.ensureWhitelistAccess('switchSlide');
4509
- const result = await this.post('switchSlide', { index });
4510
- this.currentSlideIndex = index;
4511
- return result;
4629
+ await this.ensureWhitelistAccess('switchSlide');
4630
+ return this.post('switchSlide', { index });
4512
4631
  }
4513
4632
  async getSlideCount() {
4514
- this.ensureWhitelistAccess('getSlideCount');
4515
- const result = await this.post('getSlideCount', {});
4516
- this.slideCount = result.count;
4517
- return result;
4633
+ await this.ensureWhitelistAccess('getSlideCount');
4634
+ return this.post('getSlideCount', {});
4518
4635
  }
4519
4636
  async repl(command) {
4520
- this.ensureWhitelistAccess('repl');
4637
+ await this.ensureWhitelistAccess('repl');
4521
4638
  return this.post('repl', { command });
4522
4639
  }
4523
4640
  }
@@ -4563,12 +4680,9 @@ class EmbeddedEditor extends EmbeddedTarget {
4563
4680
  this.historyCurrentIndex = -1;
4564
4681
  this.uiConfig = {};
4565
4682
  this.document = {
4566
- loadContent: async (content) => {
4567
- await this.loadContent(content, 'loadContent');
4568
- },
4683
+ loadContent: (content) => this.loadContent(content),
4569
4684
  getContent: async () => {
4570
4685
  const result = await this.post('getContent', {});
4571
- this.currentContent = result.content;
4572
4686
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(result.content.slides.length - 1, 0));
4573
4687
  this.slideCount = result.content.slides.length;
4574
4688
  await this.refreshHistoryState();
@@ -4698,14 +4812,15 @@ class EmbeddedEditor extends EmbeddedTarget {
4698
4812
  }
4699
4813
  }
4700
4814
  applyReplState(state) {
4701
- this.currentContent = undefined;
4702
4815
  this.slideCount = state.slideCount;
4703
4816
  this.currentSlideIndex = state.currentSlideIndex;
4704
4817
  this.historyCount = state.historyCount;
4705
4818
  this.historyCurrentIndex = state.historyCurrentIndex;
4706
4819
  }
4707
4820
  async initialize(options = {}, baseUrl) {
4708
- if (!options.auth?.appId?.trim() && !isLocalFileHost()) {
4821
+ const appId = readEmbedAppId(options.auth);
4822
+ requireHttpHostForAppId(appId);
4823
+ if (!appId && !isLocalFileHost() && !isLocalLoopbackHost()) {
4709
4824
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4710
4825
  }
4711
4826
  this.uiConfig = options.ui ? { ...options.ui } : {};
@@ -4734,19 +4849,17 @@ class EmbeddedEditor extends EmbeddedTarget {
4734
4849
  if (Object.keys(this.uiConfig).length > 0) {
4735
4850
  await this.mode.setUiConfig(this.uiConfig);
4736
4851
  }
4737
- const content = await this.document.getContent();
4738
- this.currentContent = content;
4739
- this.slideCount = content.slides.length;
4740
4852
  this.currentSlideIndex = 0;
4741
- await this.refreshHistoryState();
4742
4853
  if (options.initialContent) {
4743
- await this.loadContent(options.initialContent, 'initialContent');
4854
+ await this.loadContent(options.initialContent);
4855
+ }
4856
+ else {
4857
+ await this.document.getContent();
4744
4858
  }
4745
4859
  }
4746
4860
  handleEventMessage(event) {
4747
4861
  if (event.type === 'contentChange') {
4748
4862
  if (event.content) {
4749
- this.currentContent = event.content;
4750
4863
  this.slideCount = event.content.slides.length;
4751
4864
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4752
4865
  }
@@ -4761,7 +4874,6 @@ class EmbeddedEditor extends EmbeddedTarget {
4761
4874
  this.cancelActiveAi(event.reason, false);
4762
4875
  return;
4763
4876
  }
4764
- this.currentContent = event.content;
4765
4877
  this.slideCount = event.content.slides.length;
4766
4878
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4767
4879
  }
@@ -4931,13 +5043,10 @@ class EmbeddedEditor extends EmbeddedTarget {
4931
5043
  return false;
4932
5044
  }
4933
5045
  }
4934
- async loadContent(content, source) {
4935
- const latestContent = convertToLatest(content);
4936
- await this.post('loadContent', { content: latestContent });
4937
- this.currentContent = latestContent;
5046
+ async loadContent(content) {
5047
+ await this.post('loadContent', { content });
4938
5048
  this.currentSlideIndex = 0;
4939
- this.slideCount = latestContent.slides.length;
4940
- await this.refreshHistoryState();
5049
+ await this.document.getContent();
4941
5050
  }
4942
5051
  async switchTo(index) {
4943
5052
  await this.post('switchSlide', { index });
@@ -5215,35 +5324,6 @@ class EmbeddedEditor extends EmbeddedTarget {
5215
5324
  }
5216
5325
  }
5217
5326
 
5218
- const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
5219
- const WHITELIST_CHECK_PATH = '/api/whitelist/check';
5220
- async function checkPresentationWhitelist(options) {
5221
- if (isLocalFileHost())
5222
- return null;
5223
- const appId = options.auth?.appId?.trim() ?? '';
5224
- const host = window.location.hostname.trim();
5225
- const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
5226
- url.searchParams.set('appId', appId);
5227
- url.searchParams.set('host', host);
5228
- let matched = false;
5229
- try {
5230
- const response = await fetch(url.toString(), {
5231
- method: 'GET',
5232
- cache: 'no-store',
5233
- });
5234
- if (response.ok) {
5235
- const payload = (await response.json());
5236
- matched = payload.matched === true;
5237
- }
5238
- }
5239
- catch {
5240
- matched = false;
5241
- }
5242
- if (matched) {
5243
- return null;
5244
- }
5245
- return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
5246
- }
5247
5327
  async function createEditorInstance(container, options = {}, baseUrl) {
5248
5328
  const editor = new EmbeddedEditor(container);
5249
5329
  await editor.initialize(options, baseUrl);
@@ -5252,10 +5332,6 @@ async function createEditorInstance(container, options = {}, baseUrl) {
5252
5332
  async function createPresentationInstance(container, options = {}, baseUrl) {
5253
5333
  const presentation = new EmbeddedPresentation(container);
5254
5334
  await presentation.initialize(options, baseUrl);
5255
- const whitelistError = await checkPresentationWhitelist(options);
5256
- if (whitelistError) {
5257
- presentation.setWhitelistError(whitelistError);
5258
- }
5259
5335
  return presentation;
5260
5336
  }
5261
5337
  function createEmbeddedInstance(container, options) {
@@ -5286,6 +5362,16 @@ async function createPresentation(container, options = {}) {
5286
5362
  return createPresentationInstance(container, options);
5287
5363
  }
5288
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
+
5289
5375
  exports.AlgeoError = AlgeoError;
5290
5376
  exports.AlgeoSdk = AlgeoSdk;
5291
5377
  exports.EMBED_ERROR_CODES = EMBED_ERROR_CODES;