@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.
@@ -3869,6 +3869,12 @@
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();
3872
3878
  var openAiChatMessageV1Schema = objectType({
3873
3879
  role: stringType(),
3874
3880
  content: unionType([
@@ -3882,9 +3888,23 @@
3882
3888
  name: stringType().optional()
3883
3889
  }).passthrough();
3884
3890
  objectType({
3885
- model_id: stringType(),
3886
- messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3887
- extra_openai_params: recordType(unknownType()).optional()
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
+ }
3888
3908
  });
3889
3909
  objectType({
3890
3910
  id: stringType(),
@@ -4003,19 +4023,47 @@
4003
4023
  }
4004
4024
  };
4005
4025
  }
4006
- function convertToLatest(content) {
4026
+ function convertToLatest$1(content) {
4007
4027
  const version = content.metadata.version;
4008
4028
  if (version === "11") {
4009
4029
  return content;
4010
4030
  }
4011
4031
  if (version === "10") {
4012
- return convertToLatest(upgradeFromV10ToV11(content));
4032
+ return convertToLatest$1(upgradeFromV10ToV11(content));
4013
4033
  }
4014
4034
  throw new Error(`Unsupported FileContent version: ${version}`);
4015
4035
  }
4016
4036
 
4037
+ const SDK_LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="none" viewBox="0 0 36 36">
4038
+ <g clip-path="url(#a)">
4039
+ <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"/>
4040
+ <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"/>
4041
+ <path fill="#A668B8" d="m16.483 13.62 2.182-3.682 3.273 1.91-3.682 6.137-1.773-4.364Z"/>
4042
+ </g>
4043
+ <defs>
4044
+ <clipPath id="a">
4045
+ <path fill="#fff" d="M0 0h36v36H0z"/>
4046
+ </clipPath>
4047
+ </defs>
4048
+ </svg>`;
4049
+ const BADGE_STYLE = 'background-color: #f1faf7; background-position: 9px center;' +
4050
+ 'background-repeat: no-repeat; background-size: 24px 24px;' +
4051
+ 'border: 1px solid #9cd4c5; border-radius: 4px; padding: 6px 12px 6px 42px;' +
4052
+ 'color: #123e35; font-size: 14px; font-weight: bold;';
4053
+ const TITLE_STYLE = 'background-color: #174e42; color: #fff; font-weight: bold; padding: 2px 8px;';
4054
+ const DIVIDER = '+------------------------------------------------------+';
4055
+ function logSdk(...entry) {
4056
+ if (entry[0] === 'debug') {
4057
+ const [, message, ...details] = entry;
4058
+ console.debug('[Algeo SDK]', message, ...details);
4059
+ return;
4060
+ }
4061
+ const [, { title, lines }] = entry;
4062
+ 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'));
4063
+ }
4064
+
4017
4065
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.16.1';
4066
+ const VERSION = '2.17.0';
4019
4067
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4020
4068
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4021
4069
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4023,6 +4071,34 @@
4023
4071
  function isLocalFileHost() {
4024
4072
  return typeof window !== 'undefined' && window.location.protocol === 'file:';
4025
4073
  }
4074
+ function isLocalLoopbackHost() {
4075
+ if (typeof window === 'undefined')
4076
+ return false;
4077
+ const { protocol, hostname } = window.location;
4078
+ return ((protocol === 'http:' || protocol === 'https:') &&
4079
+ ['localhost', '127.0.0.1'].includes(hostname));
4080
+ }
4081
+ function readEmbedAppId(auth) {
4082
+ const appId = auth?.appId?.trim() ?? '';
4083
+ if (!appId) {
4084
+ logSdk('notice', {
4085
+ title: '未配置应用 ID(auth.appId)',
4086
+ lines: [
4087
+ '注册应用 > 配置域名白名单 > 填写 auth.appId',
4088
+ '开放平台 https://open.dajiaoai.com/console',
4089
+ '使用许可 https://open.dajiaoai.com/sdk/2/auth',
4090
+ '',
4091
+ '版权 © 大角几何',
4092
+ ],
4093
+ });
4094
+ }
4095
+ return appId;
4096
+ }
4097
+ function requireHttpHostForAppId(appId) {
4098
+ if (appId && isLocalFileHost()) {
4099
+ throw new AlgeoError('file:// 没有可校验的宿主域名。请通过本地 HTTP 服务打开页面,将该主机加入应用白名单后重试。', EMBED_ERROR_CODES.BAD_REQUEST);
4100
+ }
4101
+ }
4026
4102
  let requestIdCounter = 0;
4027
4103
  function generateRequestId() {
4028
4104
  return `req-${Date.now()}-${++requestIdCounter}`;
@@ -4137,10 +4213,13 @@
4137
4213
  const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
4138
4214
  const mode = normalizeMode(options.mode);
4139
4215
  const path = getEmbedPath(mode);
4140
- const localFile = isLocalFileHost();
4141
- const appId = options.auth?.appId?.trim() || (localFile ? 'local' : '');
4216
+ const appId = options.auth?.appId?.trim();
4217
+ const localFile = !appId && isLocalFileHost();
4218
+ const localLoopback = !appId && isLocalLoopbackHost();
4142
4219
  const initialId = options.initialId?.trim();
4143
- const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4220
+ const initialPath = initialId ? `/${encodeURIComponent(initialId)}` : '';
4221
+ const routeAppId = appId || (localFile || localLoopback ? 'local' : 'public');
4222
+ const src = `${baseUrl}${path}/${encodeURIComponent(routeAppId)}${initialPath}`;
4144
4223
  const params = new URLSearchParams();
4145
4224
  if (mode === 'editor' && options.cameraMode) {
4146
4225
  params.set('cameraMode', options.cameraMode);
@@ -4148,6 +4227,9 @@
4148
4227
  if (mode === 'editor' && localFile) {
4149
4228
  params.set('localFile', '1');
4150
4229
  }
4230
+ if (mode === 'editor' && localLoopback) {
4231
+ params.set('localLoopback', '1');
4232
+ }
4151
4233
  return params.size ? `${src}?${params}` : src;
4152
4234
  }
4153
4235
  const MASTER_TEMPLATE_OPERATIONS = [
@@ -4247,6 +4329,7 @@
4247
4329
  ...options,
4248
4330
  mode: this.embedMode,
4249
4331
  });
4332
+ const iframeOrigin = new URL(src, window.location.href).origin;
4250
4333
  let settled = false;
4251
4334
  let initTimeoutId;
4252
4335
  const finalizeFailure = (error) => {
@@ -4299,6 +4382,19 @@
4299
4382
  iframe.contentWindow?.postMessage({ type: 'localFileHostConfirmed', requestId: data.requestId }, '*');
4300
4383
  return;
4301
4384
  }
4385
+ if (data?.type === 'localLoopbackHostCheck' &&
4386
+ typeof data.requestId === 'string' &&
4387
+ !options.auth?.appId?.trim() &&
4388
+ isLocalLoopbackHost()) {
4389
+ iframe.contentWindow?.postMessage({ type: 'localLoopbackHostConfirmed', requestId: data.requestId }, iframeOrigin);
4390
+ return;
4391
+ }
4392
+ if (this.embedMode === 'editor' &&
4393
+ e.origin === iframeOrigin &&
4394
+ data?.type === 'embedEditAuthorizationFailed') {
4395
+ finalizeFailure(new AlgeoError('白名单校验未通过。请在开放平台将当前主机加入应用白名单后重试。', EMBED_ERROR_CODES.BAD_REQUEST));
4396
+ return;
4397
+ }
4302
4398
  if (isReadyMessage(data)) {
4303
4399
  if (this._ready) {
4304
4400
  return;
@@ -4429,8 +4525,7 @@
4429
4525
  class EmbeddedPresentation extends EmbeddedTarget {
4430
4526
  constructor(container) {
4431
4527
  super(container, 'presentation');
4432
- this.currentSlideIndex = 0;
4433
- this.slideCount = 0;
4528
+ this.appId = '';
4434
4529
  this.uiConfig = {
4435
4530
  logo: true,
4436
4531
  slidePanel: true,
@@ -4440,19 +4535,30 @@
4440
4535
  this.mode = {
4441
4536
  getUiConfig: () => ({ ...this.uiConfig }),
4442
4537
  setUiConfig: async (config) => {
4538
+ await this.ensureWhitelistAccess('setUiConfig');
4443
4539
  await this.post('setUiConfig', { config });
4444
4540
  this.uiConfig = {
4445
4541
  ...this.uiConfig,
4446
4542
  ...config,
4447
4543
  };
4448
4544
  },
4449
- setMasterTemplate: (template) => {
4450
- this.ensureWhitelistAccess('setMasterTemplate');
4545
+ setMasterTemplate: async (template) => {
4546
+ await this.ensureWhitelistAccess('setMasterTemplate');
4451
4547
  return this.post('setMasterTemplate', { template });
4452
4548
  },
4453
4549
  };
4454
4550
  }
4455
4551
  async initialize(options = {}, baseUrl) {
4552
+ const appId = readEmbedAppId(options.auth);
4553
+ if (!this.iframe) {
4554
+ this.appId = appId;
4555
+ this.whitelistCheck = undefined;
4556
+ }
4557
+ // 未配置应用的部署页面按默认样式展示公开分享。
4558
+ if (!appId && !isLocalFileHost() && !isLocalLoopbackHost()) {
4559
+ await this.init({ baseUrl, initialId: options.shareId });
4560
+ return;
4561
+ }
4456
4562
  this.uiConfig = {
4457
4563
  logo: true,
4458
4564
  slidePanel: true,
@@ -4471,7 +4577,7 @@
4471
4577
  if (options.fonts) {
4472
4578
  await this.post('setFontConfig', { config: options.fonts });
4473
4579
  }
4474
- await this.mode.setUiConfig(this.uiConfig);
4580
+ await this.post('setUiConfig', { config: this.uiConfig });
4475
4581
  }
4476
4582
  acceptsEventMessage() {
4477
4583
  return false;
@@ -4479,49 +4585,60 @@
4479
4585
  setWhitelistError(error) {
4480
4586
  this.whitelistError = error;
4481
4587
  }
4482
- ensureWhitelistAccess(methodName) {
4483
- if (!this.whitelistError) {
4484
- return;
4588
+ async checkWhitelist(appId) {
4589
+ if (!appId) {
4590
+ if (isLocalFileHost() || isLocalLoopbackHost())
4591
+ return;
4592
+ throw new AlgeoError('正式接入演示模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4593
+ }
4594
+ requireHttpHostForAppId(appId);
4595
+ const host = window.location.hostname;
4596
+ const url = new URL('https://open.dajiaoai.com/console/api/whitelist/check');
4597
+ url.searchParams.set('appId', appId);
4598
+ url.searchParams.set('host', host);
4599
+ try {
4600
+ const response = await fetch(url.toString(), { cache: 'no-store' });
4601
+ if (response.ok && (await response.json()).matched === true)
4602
+ return;
4603
+ }
4604
+ catch {
4605
+ // 网络或响应解析失败时按鉴权失败处理。
4606
+ }
4607
+ throw new AlgeoError(`白名单校验未通过,appId="${appId}",host="${host}"。请在开放平台将该主机加入应用白名单后重试。`, EMBED_ERROR_CODES.BAD_REQUEST);
4608
+ }
4609
+ async ensureWhitelistAccess(methodName) {
4610
+ try {
4611
+ if (this.whitelistError)
4612
+ throw this.whitelistError;
4613
+ this.whitelistCheck ?? (this.whitelistCheck = this.checkWhitelist(this.appId));
4614
+ await this.whitelistCheck;
4615
+ }
4616
+ catch (cause) {
4617
+ if (!(cause instanceof AlgeoError))
4618
+ throw cause;
4619
+ const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${cause.message}`, cause.code, cause.details);
4620
+ console.error(error);
4621
+ throw error;
4485
4622
  }
4486
- const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
4487
- console.error(error);
4488
- throw error;
4489
4623
  }
4490
4624
  async loadShareById(id) {
4491
- this.ensureWhitelistAccess('loadShareById');
4492
- const result = await this.post('loadShareById', {
4493
- id,
4494
- });
4495
- this.currentContent = undefined;
4496
- this.currentSlideIndex = 0;
4497
- this.slideCount = 0;
4498
- return result;
4625
+ await this.ensureWhitelistAccess('loadShareById');
4626
+ return this.post('loadShareById', { id });
4499
4627
  }
4500
4628
  async loadFile(content) {
4501
- this.ensureWhitelistAccess('loadFile');
4502
- const latestContent = convertToLatest(content);
4503
- const result = await this.post('loadContent', {
4504
- content: latestContent,
4505
- });
4506
- this.currentContent = latestContent;
4507
- this.currentSlideIndex = 0;
4508
- this.slideCount = latestContent.slides.length;
4509
- return result;
4629
+ await this.ensureWhitelistAccess('loadFile');
4630
+ return this.post('loadContent', { content });
4510
4631
  }
4511
4632
  async switchSlide(index) {
4512
- this.ensureWhitelistAccess('switchSlide');
4513
- const result = await this.post('switchSlide', { index });
4514
- this.currentSlideIndex = index;
4515
- return result;
4633
+ await this.ensureWhitelistAccess('switchSlide');
4634
+ return this.post('switchSlide', { index });
4516
4635
  }
4517
4636
  async getSlideCount() {
4518
- this.ensureWhitelistAccess('getSlideCount');
4519
- const result = await this.post('getSlideCount', {});
4520
- this.slideCount = result.count;
4521
- return result;
4637
+ await this.ensureWhitelistAccess('getSlideCount');
4638
+ return this.post('getSlideCount', {});
4522
4639
  }
4523
4640
  async repl(command) {
4524
- this.ensureWhitelistAccess('repl');
4641
+ await this.ensureWhitelistAccess('repl');
4525
4642
  return this.post('repl', { command });
4526
4643
  }
4527
4644
  }
@@ -4567,12 +4684,9 @@
4567
4684
  this.historyCurrentIndex = -1;
4568
4685
  this.uiConfig = {};
4569
4686
  this.document = {
4570
- loadContent: async (content) => {
4571
- await this.loadContent(content, 'loadContent');
4572
- },
4687
+ loadContent: (content) => this.loadContent(content),
4573
4688
  getContent: async () => {
4574
4689
  const result = await this.post('getContent', {});
4575
- this.currentContent = result.content;
4576
4690
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(result.content.slides.length - 1, 0));
4577
4691
  this.slideCount = result.content.slides.length;
4578
4692
  await this.refreshHistoryState();
@@ -4702,14 +4816,15 @@
4702
4816
  }
4703
4817
  }
4704
4818
  applyReplState(state) {
4705
- this.currentContent = undefined;
4706
4819
  this.slideCount = state.slideCount;
4707
4820
  this.currentSlideIndex = state.currentSlideIndex;
4708
4821
  this.historyCount = state.historyCount;
4709
4822
  this.historyCurrentIndex = state.historyCurrentIndex;
4710
4823
  }
4711
4824
  async initialize(options = {}, baseUrl) {
4712
- if (!options.auth?.appId?.trim() && !isLocalFileHost()) {
4825
+ const appId = readEmbedAppId(options.auth);
4826
+ requireHttpHostForAppId(appId);
4827
+ if (!appId && !isLocalFileHost() && !isLocalLoopbackHost()) {
4713
4828
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4714
4829
  }
4715
4830
  this.uiConfig = options.ui ? { ...options.ui } : {};
@@ -4738,19 +4853,17 @@
4738
4853
  if (Object.keys(this.uiConfig).length > 0) {
4739
4854
  await this.mode.setUiConfig(this.uiConfig);
4740
4855
  }
4741
- const content = await this.document.getContent();
4742
- this.currentContent = content;
4743
- this.slideCount = content.slides.length;
4744
4856
  this.currentSlideIndex = 0;
4745
- await this.refreshHistoryState();
4746
4857
  if (options.initialContent) {
4747
- await this.loadContent(options.initialContent, 'initialContent');
4858
+ await this.loadContent(options.initialContent);
4859
+ }
4860
+ else {
4861
+ await this.document.getContent();
4748
4862
  }
4749
4863
  }
4750
4864
  handleEventMessage(event) {
4751
4865
  if (event.type === 'contentChange') {
4752
4866
  if (event.content) {
4753
- this.currentContent = event.content;
4754
4867
  this.slideCount = event.content.slides.length;
4755
4868
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4756
4869
  }
@@ -4765,7 +4878,6 @@
4765
4878
  this.cancelActiveAi(event.reason, false);
4766
4879
  return;
4767
4880
  }
4768
- this.currentContent = event.content;
4769
4881
  this.slideCount = event.content.slides.length;
4770
4882
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4771
4883
  }
@@ -4935,13 +5047,10 @@
4935
5047
  return false;
4936
5048
  }
4937
5049
  }
4938
- async loadContent(content, source) {
4939
- const latestContent = convertToLatest(content);
4940
- await this.post('loadContent', { content: latestContent });
4941
- this.currentContent = latestContent;
5050
+ async loadContent(content) {
5051
+ await this.post('loadContent', { content });
4942
5052
  this.currentSlideIndex = 0;
4943
- this.slideCount = latestContent.slides.length;
4944
- await this.refreshHistoryState();
5053
+ await this.document.getContent();
4945
5054
  }
4946
5055
  async switchTo(index) {
4947
5056
  await this.post('switchSlide', { index });
@@ -5219,35 +5328,6 @@
5219
5328
  }
5220
5329
  }
5221
5330
 
5222
- const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
5223
- const WHITELIST_CHECK_PATH = '/api/whitelist/check';
5224
- async function checkPresentationWhitelist(options) {
5225
- if (isLocalFileHost())
5226
- return null;
5227
- const appId = options.auth?.appId?.trim() ?? '';
5228
- const host = window.location.hostname.trim();
5229
- const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
5230
- url.searchParams.set('appId', appId);
5231
- url.searchParams.set('host', host);
5232
- let matched = false;
5233
- try {
5234
- const response = await fetch(url.toString(), {
5235
- method: 'GET',
5236
- cache: 'no-store',
5237
- });
5238
- if (response.ok) {
5239
- const payload = (await response.json());
5240
- matched = payload.matched === true;
5241
- }
5242
- }
5243
- catch {
5244
- matched = false;
5245
- }
5246
- if (matched) {
5247
- return null;
5248
- }
5249
- return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
5250
- }
5251
5331
  async function createEditorInstance(container, options = {}, baseUrl) {
5252
5332
  const editor = new EmbeddedEditor(container);
5253
5333
  await editor.initialize(options, baseUrl);
@@ -5256,10 +5336,6 @@
5256
5336
  async function createPresentationInstance(container, options = {}, baseUrl) {
5257
5337
  const presentation = new EmbeddedPresentation(container);
5258
5338
  await presentation.initialize(options, baseUrl);
5259
- const whitelistError = await checkPresentationWhitelist(options);
5260
- if (whitelistError) {
5261
- presentation.setWhitelistError(whitelistError);
5262
- }
5263
5339
  return presentation;
5264
5340
  }
5265
5341
  function createEmbeddedInstance(container, options) {
@@ -5290,6 +5366,16 @@
5290
5366
  return createPresentationInstance(container, options);
5291
5367
  }
5292
5368
 
5369
+ let hasWarnedAboutConvertToLatest = false;
5370
+ /** @deprecated The iframe handles file migration when content is loaded. */
5371
+ const convertToLatest = (content) => {
5372
+ if (!hasWarnedAboutConvertToLatest) {
5373
+ hasWarnedAboutConvertToLatest = true;
5374
+ console.warn('[Algeo SDK] convertToLatest is deprecated. The iframe handles file migration when content is loaded.');
5375
+ }
5376
+ return convertToLatest$1(content);
5377
+ };
5378
+
5293
5379
  exports.AlgeoError = AlgeoError;
5294
5380
  exports.AlgeoSdk = AlgeoSdk;
5295
5381
  exports.EMBED_ERROR_CODES = EMBED_ERROR_CODES;
@@ -10,7 +10,6 @@ export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMa
10
10
  readonly history: HistoryApi;
11
11
  readonly mode: ModeApi;
12
12
  readonly ai: AiApi;
13
- private currentContent?;
14
13
  private currentSlideIndex;
15
14
  private slideCount;
16
15
  private historyCount;
@@ -1,19 +1,19 @@
1
1
  import { EmbeddedTarget } from './embedded-target';
2
- import { AlgeoError, type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentAny, type GetSlideCountResult, type LoadFileResult, type LoadShareByIdResult, type PresentationModeApi, type ReplResult, type SwitchSlideResult } from './shared';
2
+ import { AlgeoError, type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentInput, type GetSlideCountResult, type LoadFileResult, type LoadShareByIdResult, type PresentationModeApi, type ReplResult, type SwitchSlideResult } from './shared';
3
3
  export declare class EmbeddedPresentation extends EmbeddedTarget<EmbeddedPresentationEventMap, EmbeddedPresentationEventName, EmbeddedPresentationEventListenerMap> {
4
4
  readonly mode: PresentationModeApi;
5
- private currentContent?;
6
- private currentSlideIndex;
7
- private slideCount;
5
+ private appId;
6
+ private whitelistCheck?;
8
7
  private whitelistError?;
9
8
  private uiConfig;
10
9
  constructor(container: HTMLElement);
11
10
  initialize(options?: AlgeoPresentationCreateOptions, baseUrl?: string): Promise<void>;
12
11
  protected acceptsEventMessage(): boolean;
13
12
  setWhitelistError(error: AlgeoError): void;
13
+ private checkWhitelist;
14
14
  private ensureWhitelistAccess;
15
15
  loadShareById(id: string): Promise<LoadShareByIdResult>;
16
- loadFile(content: FileContentAny): Promise<LoadFileResult>;
16
+ loadFile(content: FileContentInput): Promise<LoadFileResult>;
17
17
  switchSlide(index: number): Promise<SwitchSlideResult>;
18
18
  getSlideCount(): Promise<GetSlideCountResult>;
19
19
  repl(command: string): Promise<ReplResult>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { convertToLatest as convertProtocolContentToLatest } from '@dajiaoai/algeo-protocol';
1
2
  export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
2
3
  export type { FileContentAny, FileContentLatest, } from '@dajiaoai/algeo-protocol';
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, MasterTemplateItem, MasterTemplateCallbacks, MasterTemplateOperation, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SetViewBoundsOptions, SetViewCamera3dOptions, ViewCamera3d, SlideChangeEvent, SlideIndexResult, SlideInfo, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
4
+ /** @deprecated The iframe handles file migration when content is loaded. */
5
+ export declare const convertToLatest: typeof convertProtocolContentToLatest;
6
+ export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, FileContentInput, 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, MasterTemplateItem, MasterTemplateCallbacks, MasterTemplateOperation, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SetViewBoundsOptions, SetViewCamera3dOptions, ViewCamera3d, SlideChangeEvent, SlideIndexResult, SlideInfo, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
5
7
  export { EmbeddedPresentation } from './embedded-presentation';
6
8
  export { EmbeddedEditor } from './embedded-editor';
7
9
  export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
@@ -0,0 +1,6 @@
1
+ interface SdkNotice {
2
+ title: string;
3
+ lines: readonly string[];
4
+ }
5
+ export declare function logSdk(...entry: [kind: 'notice', notice: SdkNotice] | [kind: 'debug', message: string, ...details: unknown[]]): void;
6
+ export {};
package/dist/shared.d.ts CHANGED
@@ -3,6 +3,8 @@ import { AlgeoError, type AlgeoErrorPayload, type AiRunPayloadV1, type AiStreamE
3
3
  export declare const VERSION = "__ALGEO_SDK_VERSION__";
4
4
  /** 从协议层 re-export,供外部使用 */
5
5
  export type { FileContentAny, FileContentLatest, AlgeoErrorPayload };
6
+ /** Project data forwarded to the iframe for version detection and validation. */
7
+ export type FileContentInput = object;
6
8
  export type { AiRawSseEventV1, AiResponseRecordV1, AiRunPayloadV1, AiStreamEventV1, GeometryOpV1, OpenAiChatMessageV1, } from '@dajiaoai/algeo-protocol';
7
9
  export { AlgeoError, EMBED_ERROR_CODES };
8
10
  export declare const EMBED_TIMEOUT_MS = 30000;
@@ -16,6 +18,9 @@ export interface AlgeoSdkOptions {
16
18
  }
17
19
  export type AlgeoEmbedMode = 'presentation' | 'editor';
18
20
  export declare function isLocalFileHost(): boolean;
21
+ export declare function isLocalLoopbackHost(): boolean;
22
+ export declare function readEmbedAppId(auth?: AlgeoEditorAuthOptions): string;
23
+ export declare function requireHttpHostForAppId(appId: string): void;
19
24
  export interface AlgeoEditorAuthOptions {
20
25
  appId: string;
21
26
  }
@@ -78,7 +83,7 @@ export type AlgeoEditorSaveResult = {
78
83
  export interface AlgeoEditorCreateOptions {
79
84
  auth?: AlgeoEditorAuthOptions;
80
85
  shareId?: string;
81
- initialContent?: FileContentAny;
86
+ initialContent?: FileContentInput;
82
87
  /** 空白画板模式,默认 2d。初始化优先级:initialContent > shareId > 空白画板。 */
83
88
  initialMode?: '2d' | '3d';
84
89
  ui?: AlgeoEditorUiConfig;
@@ -470,7 +475,7 @@ export interface GetHistoryStateResult {
470
475
  canRedo: boolean;
471
476
  }
472
477
  export interface DocumentApi {
473
- loadContent(content: FileContentAny): Promise<void>;
478
+ loadContent(content: FileContentInput): Promise<void>;
474
479
  getContent(): Promise<FileContentLatest>;
475
480
  }
476
481
  export interface SlidesApi {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.16.1",
3
+ "version": "2.17.0",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",