@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 +10 -8
- package/dist/algeo-sdk.cjs.js +184 -98
- package/dist/algeo-sdk.esm.js +184 -98
- package/dist/algeo-sdk.umd.js +184 -98
- package/dist/embedded-editor.d.ts +0 -1
- package/dist/embedded-presentation.d.ts +5 -5
- package/dist/index.d.ts +4 -2
- package/dist/sdkLogger.d.ts +6 -0
- package/dist/shared.d.ts +7 -2
- package/package.json +1 -1
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -3863,6 +3863,12 @@ 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();
|
|
3866
3872
|
var openAiChatMessageV1Schema = objectType({
|
|
3867
3873
|
role: stringType(),
|
|
3868
3874
|
content: unionType([
|
|
@@ -3876,9 +3882,23 @@ var openAiChatMessageV1Schema = objectType({
|
|
|
3876
3882
|
name: stringType().optional()
|
|
3877
3883
|
}).passthrough();
|
|
3878
3884
|
objectType({
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
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
|
+
}
|
|
3882
3902
|
});
|
|
3883
3903
|
objectType({
|
|
3884
3904
|
id: stringType(),
|
|
@@ -3997,19 +4017,47 @@ function upgradeFromV10ToV11(content) {
|
|
|
3997
4017
|
}
|
|
3998
4018
|
};
|
|
3999
4019
|
}
|
|
4000
|
-
function convertToLatest(content) {
|
|
4020
|
+
function convertToLatest$1(content) {
|
|
4001
4021
|
const version = content.metadata.version;
|
|
4002
4022
|
if (version === "11") {
|
|
4003
4023
|
return content;
|
|
4004
4024
|
}
|
|
4005
4025
|
if (version === "10") {
|
|
4006
|
-
return convertToLatest(upgradeFromV10ToV11(content));
|
|
4026
|
+
return convertToLatest$1(upgradeFromV10ToV11(content));
|
|
4007
4027
|
}
|
|
4008
4028
|
throw new Error(`Unsupported FileContent version: ${version}`);
|
|
4009
4029
|
}
|
|
4010
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
|
+
|
|
4011
4059
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4012
|
-
const VERSION = '2.
|
|
4060
|
+
const VERSION = '2.17.0';
|
|
4013
4061
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4014
4062
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4015
4063
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4017,6 +4065,34 @@ const EMBED_TIMEOUT_MS = 30000;
|
|
|
4017
4065
|
function isLocalFileHost() {
|
|
4018
4066
|
return typeof window !== 'undefined' && window.location.protocol === 'file:';
|
|
4019
4067
|
}
|
|
4068
|
+
function isLocalLoopbackHost() {
|
|
4069
|
+
if (typeof window === 'undefined')
|
|
4070
|
+
return false;
|
|
4071
|
+
const { protocol, hostname } = window.location;
|
|
4072
|
+
return ((protocol === 'http:' || protocol === 'https:') &&
|
|
4073
|
+
['localhost', '127.0.0.1'].includes(hostname));
|
|
4074
|
+
}
|
|
4075
|
+
function readEmbedAppId(auth) {
|
|
4076
|
+
const appId = auth?.appId?.trim() ?? '';
|
|
4077
|
+
if (!appId) {
|
|
4078
|
+
logSdk('notice', {
|
|
4079
|
+
title: '未配置应用 ID(auth.appId)',
|
|
4080
|
+
lines: [
|
|
4081
|
+
'注册应用 > 配置域名白名单 > 填写 auth.appId',
|
|
4082
|
+
'开放平台 https://open.dajiaoai.com/console',
|
|
4083
|
+
'使用许可 https://open.dajiaoai.com/sdk/2/auth',
|
|
4084
|
+
'',
|
|
4085
|
+
'版权 © 大角几何',
|
|
4086
|
+
],
|
|
4087
|
+
});
|
|
4088
|
+
}
|
|
4089
|
+
return appId;
|
|
4090
|
+
}
|
|
4091
|
+
function requireHttpHostForAppId(appId) {
|
|
4092
|
+
if (appId && isLocalFileHost()) {
|
|
4093
|
+
throw new AlgeoError('file:// 没有可校验的宿主域名。请通过本地 HTTP 服务打开页面,将该主机加入应用白名单后重试。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4020
4096
|
let requestIdCounter = 0;
|
|
4021
4097
|
function generateRequestId() {
|
|
4022
4098
|
return `req-${Date.now()}-${++requestIdCounter}`;
|
|
@@ -4131,10 +4207,13 @@ function buildEmbedSrc(options) {
|
|
|
4131
4207
|
const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
|
|
4132
4208
|
const mode = normalizeMode(options.mode);
|
|
4133
4209
|
const path = getEmbedPath(mode);
|
|
4134
|
-
const
|
|
4135
|
-
const
|
|
4210
|
+
const appId = options.auth?.appId?.trim();
|
|
4211
|
+
const localFile = !appId && isLocalFileHost();
|
|
4212
|
+
const localLoopback = !appId && isLocalLoopbackHost();
|
|
4136
4213
|
const initialId = options.initialId?.trim();
|
|
4137
|
-
const
|
|
4214
|
+
const initialPath = initialId ? `/${encodeURIComponent(initialId)}` : '';
|
|
4215
|
+
const routeAppId = appId || (localFile || localLoopback ? 'local' : 'public');
|
|
4216
|
+
const src = `${baseUrl}${path}/${encodeURIComponent(routeAppId)}${initialPath}`;
|
|
4138
4217
|
const params = new URLSearchParams();
|
|
4139
4218
|
if (mode === 'editor' && options.cameraMode) {
|
|
4140
4219
|
params.set('cameraMode', options.cameraMode);
|
|
@@ -4142,6 +4221,9 @@ function buildEmbedSrc(options) {
|
|
|
4142
4221
|
if (mode === 'editor' && localFile) {
|
|
4143
4222
|
params.set('localFile', '1');
|
|
4144
4223
|
}
|
|
4224
|
+
if (mode === 'editor' && localLoopback) {
|
|
4225
|
+
params.set('localLoopback', '1');
|
|
4226
|
+
}
|
|
4145
4227
|
return params.size ? `${src}?${params}` : src;
|
|
4146
4228
|
}
|
|
4147
4229
|
const MASTER_TEMPLATE_OPERATIONS = [
|
|
@@ -4241,6 +4323,7 @@ class EmbeddedTarget {
|
|
|
4241
4323
|
...options,
|
|
4242
4324
|
mode: this.embedMode,
|
|
4243
4325
|
});
|
|
4326
|
+
const iframeOrigin = new URL(src, window.location.href).origin;
|
|
4244
4327
|
let settled = false;
|
|
4245
4328
|
let initTimeoutId;
|
|
4246
4329
|
const finalizeFailure = (error) => {
|
|
@@ -4293,6 +4376,19 @@ class EmbeddedTarget {
|
|
|
4293
4376
|
iframe.contentWindow?.postMessage({ type: 'localFileHostConfirmed', requestId: data.requestId }, '*');
|
|
4294
4377
|
return;
|
|
4295
4378
|
}
|
|
4379
|
+
if (data?.type === 'localLoopbackHostCheck' &&
|
|
4380
|
+
typeof data.requestId === 'string' &&
|
|
4381
|
+
!options.auth?.appId?.trim() &&
|
|
4382
|
+
isLocalLoopbackHost()) {
|
|
4383
|
+
iframe.contentWindow?.postMessage({ type: 'localLoopbackHostConfirmed', requestId: data.requestId }, iframeOrigin);
|
|
4384
|
+
return;
|
|
4385
|
+
}
|
|
4386
|
+
if (this.embedMode === 'editor' &&
|
|
4387
|
+
e.origin === iframeOrigin &&
|
|
4388
|
+
data?.type === 'embedEditAuthorizationFailed') {
|
|
4389
|
+
finalizeFailure(new AlgeoError('白名单校验未通过。请在开放平台将当前主机加入应用白名单后重试。', EMBED_ERROR_CODES.BAD_REQUEST));
|
|
4390
|
+
return;
|
|
4391
|
+
}
|
|
4296
4392
|
if (isReadyMessage(data)) {
|
|
4297
4393
|
if (this._ready) {
|
|
4298
4394
|
return;
|
|
@@ -4423,8 +4519,7 @@ class EmbeddedTarget {
|
|
|
4423
4519
|
class EmbeddedPresentation extends EmbeddedTarget {
|
|
4424
4520
|
constructor(container) {
|
|
4425
4521
|
super(container, 'presentation');
|
|
4426
|
-
this.
|
|
4427
|
-
this.slideCount = 0;
|
|
4522
|
+
this.appId = '';
|
|
4428
4523
|
this.uiConfig = {
|
|
4429
4524
|
logo: true,
|
|
4430
4525
|
slidePanel: true,
|
|
@@ -4434,19 +4529,30 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4434
4529
|
this.mode = {
|
|
4435
4530
|
getUiConfig: () => ({ ...this.uiConfig }),
|
|
4436
4531
|
setUiConfig: async (config) => {
|
|
4532
|
+
await this.ensureWhitelistAccess('setUiConfig');
|
|
4437
4533
|
await this.post('setUiConfig', { config });
|
|
4438
4534
|
this.uiConfig = {
|
|
4439
4535
|
...this.uiConfig,
|
|
4440
4536
|
...config,
|
|
4441
4537
|
};
|
|
4442
4538
|
},
|
|
4443
|
-
setMasterTemplate: (template) => {
|
|
4444
|
-
this.ensureWhitelistAccess('setMasterTemplate');
|
|
4539
|
+
setMasterTemplate: async (template) => {
|
|
4540
|
+
await this.ensureWhitelistAccess('setMasterTemplate');
|
|
4445
4541
|
return this.post('setMasterTemplate', { template });
|
|
4446
4542
|
},
|
|
4447
4543
|
};
|
|
4448
4544
|
}
|
|
4449
4545
|
async initialize(options = {}, baseUrl) {
|
|
4546
|
+
const appId = readEmbedAppId(options.auth);
|
|
4547
|
+
if (!this.iframe) {
|
|
4548
|
+
this.appId = appId;
|
|
4549
|
+
this.whitelistCheck = undefined;
|
|
4550
|
+
}
|
|
4551
|
+
// 未配置应用的部署页面按默认样式展示公开分享。
|
|
4552
|
+
if (!appId && !isLocalFileHost() && !isLocalLoopbackHost()) {
|
|
4553
|
+
await this.init({ baseUrl, initialId: options.shareId });
|
|
4554
|
+
return;
|
|
4555
|
+
}
|
|
4450
4556
|
this.uiConfig = {
|
|
4451
4557
|
logo: true,
|
|
4452
4558
|
slidePanel: true,
|
|
@@ -4465,7 +4571,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4465
4571
|
if (options.fonts) {
|
|
4466
4572
|
await this.post('setFontConfig', { config: options.fonts });
|
|
4467
4573
|
}
|
|
4468
|
-
await this.
|
|
4574
|
+
await this.post('setUiConfig', { config: this.uiConfig });
|
|
4469
4575
|
}
|
|
4470
4576
|
acceptsEventMessage() {
|
|
4471
4577
|
return false;
|
|
@@ -4473,49 +4579,60 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4473
4579
|
setWhitelistError(error) {
|
|
4474
4580
|
this.whitelistError = error;
|
|
4475
4581
|
}
|
|
4476
|
-
|
|
4477
|
-
if (!
|
|
4478
|
-
|
|
4582
|
+
async checkWhitelist(appId) {
|
|
4583
|
+
if (!appId) {
|
|
4584
|
+
if (isLocalFileHost() || isLocalLoopbackHost())
|
|
4585
|
+
return;
|
|
4586
|
+
throw new AlgeoError('正式接入演示模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
|
|
4587
|
+
}
|
|
4588
|
+
requireHttpHostForAppId(appId);
|
|
4589
|
+
const host = window.location.hostname;
|
|
4590
|
+
const url = new URL('https://open.dajiaoai.com/console/api/whitelist/check');
|
|
4591
|
+
url.searchParams.set('appId', appId);
|
|
4592
|
+
url.searchParams.set('host', host);
|
|
4593
|
+
try {
|
|
4594
|
+
const response = await fetch(url.toString(), { cache: 'no-store' });
|
|
4595
|
+
if (response.ok && (await response.json()).matched === true)
|
|
4596
|
+
return;
|
|
4597
|
+
}
|
|
4598
|
+
catch {
|
|
4599
|
+
// 网络或响应解析失败时按鉴权失败处理。
|
|
4600
|
+
}
|
|
4601
|
+
throw new AlgeoError(`白名单校验未通过,appId="${appId}",host="${host}"。请在开放平台将该主机加入应用白名单后重试。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4602
|
+
}
|
|
4603
|
+
async ensureWhitelistAccess(methodName) {
|
|
4604
|
+
try {
|
|
4605
|
+
if (this.whitelistError)
|
|
4606
|
+
throw this.whitelistError;
|
|
4607
|
+
this.whitelistCheck ?? (this.whitelistCheck = this.checkWhitelist(this.appId));
|
|
4608
|
+
await this.whitelistCheck;
|
|
4609
|
+
}
|
|
4610
|
+
catch (cause) {
|
|
4611
|
+
if (!(cause instanceof AlgeoError))
|
|
4612
|
+
throw cause;
|
|
4613
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${cause.message}`, cause.code, cause.details);
|
|
4614
|
+
console.error(error);
|
|
4615
|
+
throw error;
|
|
4479
4616
|
}
|
|
4480
|
-
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4481
|
-
console.error(error);
|
|
4482
|
-
throw error;
|
|
4483
4617
|
}
|
|
4484
4618
|
async loadShareById(id) {
|
|
4485
|
-
this.ensureWhitelistAccess('loadShareById');
|
|
4486
|
-
|
|
4487
|
-
id,
|
|
4488
|
-
});
|
|
4489
|
-
this.currentContent = undefined;
|
|
4490
|
-
this.currentSlideIndex = 0;
|
|
4491
|
-
this.slideCount = 0;
|
|
4492
|
-
return result;
|
|
4619
|
+
await this.ensureWhitelistAccess('loadShareById');
|
|
4620
|
+
return this.post('loadShareById', { id });
|
|
4493
4621
|
}
|
|
4494
4622
|
async loadFile(content) {
|
|
4495
|
-
this.ensureWhitelistAccess('loadFile');
|
|
4496
|
-
|
|
4497
|
-
const result = await this.post('loadContent', {
|
|
4498
|
-
content: latestContent,
|
|
4499
|
-
});
|
|
4500
|
-
this.currentContent = latestContent;
|
|
4501
|
-
this.currentSlideIndex = 0;
|
|
4502
|
-
this.slideCount = latestContent.slides.length;
|
|
4503
|
-
return result;
|
|
4623
|
+
await this.ensureWhitelistAccess('loadFile');
|
|
4624
|
+
return this.post('loadContent', { content });
|
|
4504
4625
|
}
|
|
4505
4626
|
async switchSlide(index) {
|
|
4506
|
-
this.ensureWhitelistAccess('switchSlide');
|
|
4507
|
-
|
|
4508
|
-
this.currentSlideIndex = index;
|
|
4509
|
-
return result;
|
|
4627
|
+
await this.ensureWhitelistAccess('switchSlide');
|
|
4628
|
+
return this.post('switchSlide', { index });
|
|
4510
4629
|
}
|
|
4511
4630
|
async getSlideCount() {
|
|
4512
|
-
this.ensureWhitelistAccess('getSlideCount');
|
|
4513
|
-
|
|
4514
|
-
this.slideCount = result.count;
|
|
4515
|
-
return result;
|
|
4631
|
+
await this.ensureWhitelistAccess('getSlideCount');
|
|
4632
|
+
return this.post('getSlideCount', {});
|
|
4516
4633
|
}
|
|
4517
4634
|
async repl(command) {
|
|
4518
|
-
this.ensureWhitelistAccess('repl');
|
|
4635
|
+
await this.ensureWhitelistAccess('repl');
|
|
4519
4636
|
return this.post('repl', { command });
|
|
4520
4637
|
}
|
|
4521
4638
|
}
|
|
@@ -4561,12 +4678,9 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4561
4678
|
this.historyCurrentIndex = -1;
|
|
4562
4679
|
this.uiConfig = {};
|
|
4563
4680
|
this.document = {
|
|
4564
|
-
loadContent:
|
|
4565
|
-
await this.loadContent(content, 'loadContent');
|
|
4566
|
-
},
|
|
4681
|
+
loadContent: (content) => this.loadContent(content),
|
|
4567
4682
|
getContent: async () => {
|
|
4568
4683
|
const result = await this.post('getContent', {});
|
|
4569
|
-
this.currentContent = result.content;
|
|
4570
4684
|
this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(result.content.slides.length - 1, 0));
|
|
4571
4685
|
this.slideCount = result.content.slides.length;
|
|
4572
4686
|
await this.refreshHistoryState();
|
|
@@ -4696,14 +4810,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4696
4810
|
}
|
|
4697
4811
|
}
|
|
4698
4812
|
applyReplState(state) {
|
|
4699
|
-
this.currentContent = undefined;
|
|
4700
4813
|
this.slideCount = state.slideCount;
|
|
4701
4814
|
this.currentSlideIndex = state.currentSlideIndex;
|
|
4702
4815
|
this.historyCount = state.historyCount;
|
|
4703
4816
|
this.historyCurrentIndex = state.historyCurrentIndex;
|
|
4704
4817
|
}
|
|
4705
4818
|
async initialize(options = {}, baseUrl) {
|
|
4706
|
-
|
|
4819
|
+
const appId = readEmbedAppId(options.auth);
|
|
4820
|
+
requireHttpHostForAppId(appId);
|
|
4821
|
+
if (!appId && !isLocalFileHost() && !isLocalLoopbackHost()) {
|
|
4707
4822
|
throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
|
|
4708
4823
|
}
|
|
4709
4824
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
@@ -4732,19 +4847,17 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4732
4847
|
if (Object.keys(this.uiConfig).length > 0) {
|
|
4733
4848
|
await this.mode.setUiConfig(this.uiConfig);
|
|
4734
4849
|
}
|
|
4735
|
-
const content = await this.document.getContent();
|
|
4736
|
-
this.currentContent = content;
|
|
4737
|
-
this.slideCount = content.slides.length;
|
|
4738
4850
|
this.currentSlideIndex = 0;
|
|
4739
|
-
await this.refreshHistoryState();
|
|
4740
4851
|
if (options.initialContent) {
|
|
4741
|
-
await this.loadContent(options.initialContent
|
|
4852
|
+
await this.loadContent(options.initialContent);
|
|
4853
|
+
}
|
|
4854
|
+
else {
|
|
4855
|
+
await this.document.getContent();
|
|
4742
4856
|
}
|
|
4743
4857
|
}
|
|
4744
4858
|
handleEventMessage(event) {
|
|
4745
4859
|
if (event.type === 'contentChange') {
|
|
4746
4860
|
if (event.content) {
|
|
4747
|
-
this.currentContent = event.content;
|
|
4748
4861
|
this.slideCount = event.content.slides.length;
|
|
4749
4862
|
this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
|
|
4750
4863
|
}
|
|
@@ -4759,7 +4872,6 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4759
4872
|
this.cancelActiveAi(event.reason, false);
|
|
4760
4873
|
return;
|
|
4761
4874
|
}
|
|
4762
|
-
this.currentContent = event.content;
|
|
4763
4875
|
this.slideCount = event.content.slides.length;
|
|
4764
4876
|
this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
|
|
4765
4877
|
}
|
|
@@ -4929,13 +5041,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4929
5041
|
return false;
|
|
4930
5042
|
}
|
|
4931
5043
|
}
|
|
4932
|
-
async loadContent(content
|
|
4933
|
-
|
|
4934
|
-
await this.post('loadContent', { content: latestContent });
|
|
4935
|
-
this.currentContent = latestContent;
|
|
5044
|
+
async loadContent(content) {
|
|
5045
|
+
await this.post('loadContent', { content });
|
|
4936
5046
|
this.currentSlideIndex = 0;
|
|
4937
|
-
this.
|
|
4938
|
-
await this.refreshHistoryState();
|
|
5047
|
+
await this.document.getContent();
|
|
4939
5048
|
}
|
|
4940
5049
|
async switchTo(index) {
|
|
4941
5050
|
await this.post('switchSlide', { index });
|
|
@@ -5213,35 +5322,6 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
5213
5322
|
}
|
|
5214
5323
|
}
|
|
5215
5324
|
|
|
5216
|
-
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
5217
|
-
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
5218
|
-
async function checkPresentationWhitelist(options) {
|
|
5219
|
-
if (isLocalFileHost())
|
|
5220
|
-
return null;
|
|
5221
|
-
const appId = options.auth?.appId?.trim() ?? '';
|
|
5222
|
-
const host = window.location.hostname.trim();
|
|
5223
|
-
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
5224
|
-
url.searchParams.set('appId', appId);
|
|
5225
|
-
url.searchParams.set('host', host);
|
|
5226
|
-
let matched = false;
|
|
5227
|
-
try {
|
|
5228
|
-
const response = await fetch(url.toString(), {
|
|
5229
|
-
method: 'GET',
|
|
5230
|
-
cache: 'no-store',
|
|
5231
|
-
});
|
|
5232
|
-
if (response.ok) {
|
|
5233
|
-
const payload = (await response.json());
|
|
5234
|
-
matched = payload.matched === true;
|
|
5235
|
-
}
|
|
5236
|
-
}
|
|
5237
|
-
catch {
|
|
5238
|
-
matched = false;
|
|
5239
|
-
}
|
|
5240
|
-
if (matched) {
|
|
5241
|
-
return null;
|
|
5242
|
-
}
|
|
5243
|
-
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
5244
|
-
}
|
|
5245
5325
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
5246
5326
|
const editor = new EmbeddedEditor(container);
|
|
5247
5327
|
await editor.initialize(options, baseUrl);
|
|
@@ -5250,10 +5330,6 @@ async function createEditorInstance(container, options = {}, baseUrl) {
|
|
|
5250
5330
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
5251
5331
|
const presentation = new EmbeddedPresentation(container);
|
|
5252
5332
|
await presentation.initialize(options, baseUrl);
|
|
5253
|
-
const whitelistError = await checkPresentationWhitelist(options);
|
|
5254
|
-
if (whitelistError) {
|
|
5255
|
-
presentation.setWhitelistError(whitelistError);
|
|
5256
|
-
}
|
|
5257
5333
|
return presentation;
|
|
5258
5334
|
}
|
|
5259
5335
|
function createEmbeddedInstance(container, options) {
|
|
@@ -5284,4 +5360,14 @@ async function createPresentation(container, options = {}) {
|
|
|
5284
5360
|
return createPresentationInstance(container, options);
|
|
5285
5361
|
}
|
|
5286
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
|
+
|
|
5287
5373
|
export { AlgeoError, AlgeoSdk, EMBED_ERROR_CODES, EmbeddedEditor, EmbeddedPresentation, VERSION, convertToLatest, create, createEditor, createPresentation };
|