@dajiaoai/algeo-sdk 2.4.2 → 2.6.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 +34 -25
- package/dist/algeo-sdk.cjs.js +56 -3
- package/dist/algeo-sdk.esm.js +56 -3
- package/dist/algeo-sdk.umd.js +56 -3
- package/dist/embedded-presentation.d.ts +4 -1
- package/dist/embedded-target.d.ts +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/shared.d.ts +21 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
npm install @dajiaoai/algeo-sdk
|
|
12
12
|
|
|
13
13
|
# 安装指定版本(推荐生产环境锁定版本)
|
|
14
|
-
npm install @dajiaoai/algeo-sdk@2.
|
|
14
|
+
npm install @dajiaoai/algeo-sdk@2.6.0
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
在 `package.json` 中:
|
|
@@ -19,7 +19,7 @@ npm install @dajiaoai/algeo-sdk@2.0.0
|
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dajiaoai/algeo-sdk": "2.
|
|
22
|
+
"@dajiaoai/algeo-sdk": "2.6.0" // 精确版本,生产推荐
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
```
|
|
@@ -29,7 +29,7 @@ npm install @dajiaoai/algeo-sdk@2.0.0
|
|
|
29
29
|
```json
|
|
30
30
|
{
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dajiaoai/algeo-sdk": "^2.
|
|
32
|
+
"@dajiaoai/algeo-sdk": "^2.6.0" // 兼容 2.x 的更新
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
```
|
|
@@ -39,14 +39,14 @@ npm install @dajiaoai/algeo-sdk@2.0.0
|
|
|
39
39
|
**unpkg**:
|
|
40
40
|
|
|
41
41
|
```html
|
|
42
|
-
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.
|
|
42
|
+
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.6.0/dist/algeo-sdk.umd.js"></script>
|
|
43
43
|
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
**jsDelivr**:
|
|
47
47
|
|
|
48
48
|
```html
|
|
49
|
-
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.6.0/dist/algeo-sdk.umd.js"></script>
|
|
50
50
|
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -61,6 +61,7 @@ import { createPresentation } from '@dajiaoai/algeo-sdk';
|
|
|
61
61
|
|
|
62
62
|
const container = document.getElementById('algeo-container');
|
|
63
63
|
const presentation = await createPresentation(container, {
|
|
64
|
+
appId: 'YTVJDQZR',
|
|
64
65
|
shareId: '33TA3484',
|
|
65
66
|
});
|
|
66
67
|
|
|
@@ -87,6 +88,7 @@ presentation.switchSlide(1).then(() => console.log('切换画板'));
|
|
|
87
88
|
id="algeo-embed"
|
|
88
89
|
src="https://dajiaoai.com/e/33TA3484"
|
|
89
90
|
allow="fullscreen"
|
|
91
|
+
referrerpolicy="origin"
|
|
90
92
|
></iframe>
|
|
91
93
|
```
|
|
92
94
|
|
|
@@ -94,6 +96,8 @@ presentation.switchSlide(1).then(() => console.log('切换画板'));
|
|
|
94
96
|
|
|
95
97
|
> **全屏支持**:建议在 iframe 上添加 `allow="fullscreen"`,以便内嵌画板使用全屏功能。SDK 方式创建的 iframe 已自动包含此属性。
|
|
96
98
|
|
|
99
|
+
> **Referrer 透传**:SDK 方式创建的 iframe 会自动设置 `referrerpolicy="origin"`,便于内嵌页稳定获取宿主域名信息;若使用直接 iframe 方式,建议手动补上该属性。
|
|
100
|
+
|
|
97
101
|
### 方式三:编辑模式
|
|
98
102
|
|
|
99
103
|
```javascript
|
|
@@ -209,6 +213,8 @@ create(container, {
|
|
|
209
213
|
|
|
210
214
|
演示模式快捷入口。该函数负责真正创建并初始化 `EmbeddedPresentation`。
|
|
211
215
|
|
|
216
|
+
创建成功后,SDK 会额外调用 `https://open.dajiaoai.com/console/api/whitelist/check`,使用 `options.appId` 与当前页面 `hostname` 做白名单校验。若未命中白名单,iframe 仍会完成初始化并呈现页面,`createPresentation` 仍会成功返回实例,但后续 `loadShareById`、`loadFile`、`switchSlide`、`getSlideCount`、`repl` 等演示模式 API 会被拒绝,并在控制台输出包含方法名的错误,便于接入方感知并处理。
|
|
217
|
+
|
|
212
218
|
```javascript
|
|
213
219
|
create(container, {
|
|
214
220
|
mode: 'presentation',
|
|
@@ -253,9 +259,10 @@ type AlgeoCreateOptions =
|
|
|
253
259
|
|
|
254
260
|
**AlgeoPresentationCreateOptions:**
|
|
255
261
|
|
|
256
|
-
| 属性 | 类型 | 默认值 | 说明
|
|
257
|
-
| --------- | -------- | ------ |
|
|
258
|
-
| `
|
|
262
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
263
|
+
| --------- | -------- | ------ | -------------------------------------------------------- |
|
|
264
|
+
| `appId` | `string` | `''` | 演示模式白名单校验使用的应用标识,SDK 会用它请求校验接口 |
|
|
265
|
+
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/e/:id` |
|
|
259
266
|
|
|
260
267
|
默认路径规则:
|
|
261
268
|
|
|
@@ -268,6 +275,7 @@ type AlgeoCreateOptions =
|
|
|
268
275
|
const presentation = await create(container, {
|
|
269
276
|
mode: 'presentation',
|
|
270
277
|
presentation: {
|
|
278
|
+
appId: 'xxxx',
|
|
271
279
|
shareId: '33TA3484',
|
|
272
280
|
},
|
|
273
281
|
});
|
|
@@ -402,16 +410,17 @@ interface FileContent {
|
|
|
402
410
|
|
|
403
411
|
#### `editor.slides`
|
|
404
412
|
|
|
405
|
-
| 方法 | 说明
|
|
406
|
-
| -------------------------------- |
|
|
407
|
-
| `getCount()` | 获取当前已知画板数量
|
|
408
|
-
| `getCurrentIndex()` | 获取当前已知画板索引
|
|
409
|
-
| `switchTo(index)` | 切换画板
|
|
410
|
-
| `add()` | 在末尾新增画板
|
|
411
|
-
| `addAt(index)` | 在指定位置新增画板
|
|
412
|
-
| `remove(index)` | 删除指定画板
|
|
413
|
-
| `duplicate(index, targetIndex?)` | 复制画板
|
|
414
|
-
| `reorder(fromIndex, toIndex)` | 重排画板
|
|
413
|
+
| 方法 | 说明 |
|
|
414
|
+
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
415
|
+
| `getCount()` | 获取当前已知画板数量 |
|
|
416
|
+
| `getCurrentIndex()` | 获取当前已知画板索引 |
|
|
417
|
+
| `switchTo(index)` | 切换画板 |
|
|
418
|
+
| `add()` | 在末尾新增画板 |
|
|
419
|
+
| `addAt(index)` | 在指定位置新增画板 |
|
|
420
|
+
| `remove(index)` | 删除指定画板 |
|
|
421
|
+
| `duplicate(index, targetIndex?)` | 复制画板 |
|
|
422
|
+
| `reorder(fromIndex, toIndex)` | 重排画板 |
|
|
423
|
+
| `exportImage(options?)` | 导出画板为图片,返回 `ExportedSlideImage[]`,每项含 `index`、`blob`、`format`、`width`、`height`。可选参数 `slideIndices`(1-based,不传则导出全部)、`format`(`'png'`/`'jpg'`)、`width`、`height`、`quality`(0~1,仅 jpg)、`autoFit`、`padding` |
|
|
415
424
|
|
|
416
425
|
#### `editor.history`
|
|
417
426
|
|
|
@@ -471,10 +480,10 @@ try {
|
|
|
471
480
|
|
|
472
481
|
**常见错误码:**
|
|
473
482
|
|
|
474
|
-
| 错误码 | 说明
|
|
475
|
-
| ------------------ |
|
|
476
|
-
| `IFRAME_NOT_READY` | iframe 未加载完成即调用方法
|
|
477
|
-
| `TIMEOUT` | 请求或初始化超时(30 秒)
|
|
478
|
-
| `DESTROYED` | SDK 已销毁
|
|
479
|
-
| `MISSING_APP_ID` | 编辑模式缺少 `auth.appId`
|
|
480
|
-
| `BAD_REQUEST` | 非法请求(如重复 init
|
|
483
|
+
| 错误码 | 说明 |
|
|
484
|
+
| ------------------ | ------------------------------------------------- |
|
|
485
|
+
| `IFRAME_NOT_READY` | iframe 未加载完成即调用方法 |
|
|
486
|
+
| `TIMEOUT` | 请求或初始化超时(30 秒) |
|
|
487
|
+
| `DESTROYED` | SDK 已销毁 |
|
|
488
|
+
| `MISSING_APP_ID` | 编辑模式缺少 `auth.appId` |
|
|
489
|
+
| `BAD_REQUEST` | 非法请求(如重复 init、演示模式白名单校验未通过) |
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -3897,7 +3897,7 @@ objectType({
|
|
|
3897
3897
|
});
|
|
3898
3898
|
|
|
3899
3899
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3900
|
-
const VERSION = '2.
|
|
3900
|
+
const VERSION = '2.6.0';
|
|
3901
3901
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3902
3902
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3903
3903
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4073,6 +4073,7 @@ class EmbeddedTarget {
|
|
|
4073
4073
|
iframe.id = 'algeo-embed';
|
|
4074
4074
|
iframe.src = src;
|
|
4075
4075
|
iframe.allow = 'fullscreen';
|
|
4076
|
+
iframe.referrerPolicy = 'origin';
|
|
4076
4077
|
iframe.style.width = '100%';
|
|
4077
4078
|
iframe.style.height = '100%';
|
|
4078
4079
|
iframe.style.border = 'none';
|
|
@@ -4128,9 +4129,10 @@ class EmbeddedTarget {
|
|
|
4128
4129
|
window.addEventListener('message', this.messageHandler);
|
|
4129
4130
|
});
|
|
4130
4131
|
}
|
|
4131
|
-
post(type, payload) {
|
|
4132
|
+
post(type, payload, options = {}) {
|
|
4132
4133
|
const requestId = generateRequestId();
|
|
4133
4134
|
const msg = { type, requestId, ...payload };
|
|
4135
|
+
const timeoutMs = options.timeoutMs ?? EMBED_TIMEOUT_MS;
|
|
4134
4136
|
return new Promise((resolve, reject) => {
|
|
4135
4137
|
if (this.destroyed) {
|
|
4136
4138
|
reject(new AlgeoError('SDK 已销毁', EMBED_ERROR_CODES.DESTROYED));
|
|
@@ -4155,7 +4157,7 @@ class EmbeddedTarget {
|
|
|
4155
4157
|
this.pending.delete(requestId);
|
|
4156
4158
|
reject(new AlgeoError('请求超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4157
4159
|
}
|
|
4158
|
-
},
|
|
4160
|
+
}, timeoutMs);
|
|
4159
4161
|
});
|
|
4160
4162
|
}
|
|
4161
4163
|
async destroy() {
|
|
@@ -4188,7 +4190,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4188
4190
|
acceptsEventMessage() {
|
|
4189
4191
|
return false;
|
|
4190
4192
|
}
|
|
4193
|
+
setWhitelistError(error) {
|
|
4194
|
+
this.whitelistError = error;
|
|
4195
|
+
}
|
|
4196
|
+
ensureWhitelistAccess(methodName) {
|
|
4197
|
+
if (!this.whitelistError) {
|
|
4198
|
+
return;
|
|
4199
|
+
}
|
|
4200
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4201
|
+
console.error(error);
|
|
4202
|
+
throw error;
|
|
4203
|
+
}
|
|
4191
4204
|
async loadShareById(id) {
|
|
4205
|
+
this.ensureWhitelistAccess('loadShareById');
|
|
4192
4206
|
const result = await this.post('loadShareById', {
|
|
4193
4207
|
id,
|
|
4194
4208
|
});
|
|
@@ -4198,6 +4212,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4198
4212
|
return result;
|
|
4199
4213
|
}
|
|
4200
4214
|
async loadFile(content) {
|
|
4215
|
+
this.ensureWhitelistAccess('loadFile');
|
|
4201
4216
|
const result = await this.post('loadContent', { content });
|
|
4202
4217
|
this.currentContent = content;
|
|
4203
4218
|
this.currentSlideIndex = 0;
|
|
@@ -4205,16 +4220,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4205
4220
|
return result;
|
|
4206
4221
|
}
|
|
4207
4222
|
async switchSlide(index) {
|
|
4223
|
+
this.ensureWhitelistAccess('switchSlide');
|
|
4208
4224
|
const result = await this.post('switchSlide', { index });
|
|
4209
4225
|
this.currentSlideIndex = index;
|
|
4210
4226
|
return result;
|
|
4211
4227
|
}
|
|
4212
4228
|
async getSlideCount() {
|
|
4229
|
+
this.ensureWhitelistAccess('getSlideCount');
|
|
4213
4230
|
const result = await this.post('getSlideCount', {});
|
|
4214
4231
|
this.slideCount = result.count;
|
|
4215
4232
|
return result;
|
|
4216
4233
|
}
|
|
4217
4234
|
async repl(command) {
|
|
4235
|
+
this.ensureWhitelistAccess('repl');
|
|
4218
4236
|
return this.post('repl', { command });
|
|
4219
4237
|
}
|
|
4220
4238
|
}
|
|
@@ -4262,6 +4280,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4262
4280
|
}
|
|
4263
4281
|
await this.refreshHistoryState();
|
|
4264
4282
|
},
|
|
4283
|
+
exportImage: async (options) => {
|
|
4284
|
+
const result = await this.post('exportSlideImage', { options: options ?? {} });
|
|
4285
|
+
return result.images;
|
|
4286
|
+
},
|
|
4265
4287
|
};
|
|
4266
4288
|
this.history = {
|
|
4267
4289
|
getCount: () => this.historyCount,
|
|
@@ -4407,6 +4429,33 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4407
4429
|
}
|
|
4408
4430
|
}
|
|
4409
4431
|
|
|
4432
|
+
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4433
|
+
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4434
|
+
async function checkPresentationWhitelist(options) {
|
|
4435
|
+
const appId = options.appId?.trim() ?? '';
|
|
4436
|
+
const host = window.location.host.trim();
|
|
4437
|
+
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4438
|
+
url.searchParams.set('appId', appId);
|
|
4439
|
+
url.searchParams.set('host', host);
|
|
4440
|
+
let matched = false;
|
|
4441
|
+
try {
|
|
4442
|
+
const response = await fetch(url.toString(), {
|
|
4443
|
+
method: 'GET',
|
|
4444
|
+
cache: 'no-store',
|
|
4445
|
+
});
|
|
4446
|
+
if (response.ok) {
|
|
4447
|
+
const payload = (await response.json());
|
|
4448
|
+
matched = payload.matched === true;
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
catch {
|
|
4452
|
+
matched = false;
|
|
4453
|
+
}
|
|
4454
|
+
if (matched) {
|
|
4455
|
+
return null;
|
|
4456
|
+
}
|
|
4457
|
+
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4458
|
+
}
|
|
4410
4459
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
4411
4460
|
const editor = new EmbeddedEditor(container);
|
|
4412
4461
|
await editor.initialize(options, baseUrl);
|
|
@@ -4415,6 +4464,10 @@ async function createEditorInstance(container, options = {}, baseUrl) {
|
|
|
4415
4464
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
4416
4465
|
const presentation = new EmbeddedPresentation(container);
|
|
4417
4466
|
await presentation.initialize(options, baseUrl);
|
|
4467
|
+
const whitelistError = await checkPresentationWhitelist(options);
|
|
4468
|
+
if (whitelistError) {
|
|
4469
|
+
presentation.setWhitelistError(whitelistError);
|
|
4470
|
+
}
|
|
4418
4471
|
return presentation;
|
|
4419
4472
|
}
|
|
4420
4473
|
function createEmbeddedInstance(container, options) {
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -3895,7 +3895,7 @@ objectType({
|
|
|
3895
3895
|
});
|
|
3896
3896
|
|
|
3897
3897
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3898
|
-
const VERSION = '2.
|
|
3898
|
+
const VERSION = '2.6.0';
|
|
3899
3899
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3900
3900
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3901
3901
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4071,6 +4071,7 @@ class EmbeddedTarget {
|
|
|
4071
4071
|
iframe.id = 'algeo-embed';
|
|
4072
4072
|
iframe.src = src;
|
|
4073
4073
|
iframe.allow = 'fullscreen';
|
|
4074
|
+
iframe.referrerPolicy = 'origin';
|
|
4074
4075
|
iframe.style.width = '100%';
|
|
4075
4076
|
iframe.style.height = '100%';
|
|
4076
4077
|
iframe.style.border = 'none';
|
|
@@ -4126,9 +4127,10 @@ class EmbeddedTarget {
|
|
|
4126
4127
|
window.addEventListener('message', this.messageHandler);
|
|
4127
4128
|
});
|
|
4128
4129
|
}
|
|
4129
|
-
post(type, payload) {
|
|
4130
|
+
post(type, payload, options = {}) {
|
|
4130
4131
|
const requestId = generateRequestId();
|
|
4131
4132
|
const msg = { type, requestId, ...payload };
|
|
4133
|
+
const timeoutMs = options.timeoutMs ?? EMBED_TIMEOUT_MS;
|
|
4132
4134
|
return new Promise((resolve, reject) => {
|
|
4133
4135
|
if (this.destroyed) {
|
|
4134
4136
|
reject(new AlgeoError('SDK 已销毁', EMBED_ERROR_CODES.DESTROYED));
|
|
@@ -4153,7 +4155,7 @@ class EmbeddedTarget {
|
|
|
4153
4155
|
this.pending.delete(requestId);
|
|
4154
4156
|
reject(new AlgeoError('请求超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4155
4157
|
}
|
|
4156
|
-
},
|
|
4158
|
+
}, timeoutMs);
|
|
4157
4159
|
});
|
|
4158
4160
|
}
|
|
4159
4161
|
async destroy() {
|
|
@@ -4186,7 +4188,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4186
4188
|
acceptsEventMessage() {
|
|
4187
4189
|
return false;
|
|
4188
4190
|
}
|
|
4191
|
+
setWhitelistError(error) {
|
|
4192
|
+
this.whitelistError = error;
|
|
4193
|
+
}
|
|
4194
|
+
ensureWhitelistAccess(methodName) {
|
|
4195
|
+
if (!this.whitelistError) {
|
|
4196
|
+
return;
|
|
4197
|
+
}
|
|
4198
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4199
|
+
console.error(error);
|
|
4200
|
+
throw error;
|
|
4201
|
+
}
|
|
4189
4202
|
async loadShareById(id) {
|
|
4203
|
+
this.ensureWhitelistAccess('loadShareById');
|
|
4190
4204
|
const result = await this.post('loadShareById', {
|
|
4191
4205
|
id,
|
|
4192
4206
|
});
|
|
@@ -4196,6 +4210,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4196
4210
|
return result;
|
|
4197
4211
|
}
|
|
4198
4212
|
async loadFile(content) {
|
|
4213
|
+
this.ensureWhitelistAccess('loadFile');
|
|
4199
4214
|
const result = await this.post('loadContent', { content });
|
|
4200
4215
|
this.currentContent = content;
|
|
4201
4216
|
this.currentSlideIndex = 0;
|
|
@@ -4203,16 +4218,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4203
4218
|
return result;
|
|
4204
4219
|
}
|
|
4205
4220
|
async switchSlide(index) {
|
|
4221
|
+
this.ensureWhitelistAccess('switchSlide');
|
|
4206
4222
|
const result = await this.post('switchSlide', { index });
|
|
4207
4223
|
this.currentSlideIndex = index;
|
|
4208
4224
|
return result;
|
|
4209
4225
|
}
|
|
4210
4226
|
async getSlideCount() {
|
|
4227
|
+
this.ensureWhitelistAccess('getSlideCount');
|
|
4211
4228
|
const result = await this.post('getSlideCount', {});
|
|
4212
4229
|
this.slideCount = result.count;
|
|
4213
4230
|
return result;
|
|
4214
4231
|
}
|
|
4215
4232
|
async repl(command) {
|
|
4233
|
+
this.ensureWhitelistAccess('repl');
|
|
4216
4234
|
return this.post('repl', { command });
|
|
4217
4235
|
}
|
|
4218
4236
|
}
|
|
@@ -4260,6 +4278,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4260
4278
|
}
|
|
4261
4279
|
await this.refreshHistoryState();
|
|
4262
4280
|
},
|
|
4281
|
+
exportImage: async (options) => {
|
|
4282
|
+
const result = await this.post('exportSlideImage', { options: options ?? {} });
|
|
4283
|
+
return result.images;
|
|
4284
|
+
},
|
|
4263
4285
|
};
|
|
4264
4286
|
this.history = {
|
|
4265
4287
|
getCount: () => this.historyCount,
|
|
@@ -4405,6 +4427,33 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4405
4427
|
}
|
|
4406
4428
|
}
|
|
4407
4429
|
|
|
4430
|
+
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4431
|
+
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4432
|
+
async function checkPresentationWhitelist(options) {
|
|
4433
|
+
const appId = options.appId?.trim() ?? '';
|
|
4434
|
+
const host = window.location.host.trim();
|
|
4435
|
+
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4436
|
+
url.searchParams.set('appId', appId);
|
|
4437
|
+
url.searchParams.set('host', host);
|
|
4438
|
+
let matched = false;
|
|
4439
|
+
try {
|
|
4440
|
+
const response = await fetch(url.toString(), {
|
|
4441
|
+
method: 'GET',
|
|
4442
|
+
cache: 'no-store',
|
|
4443
|
+
});
|
|
4444
|
+
if (response.ok) {
|
|
4445
|
+
const payload = (await response.json());
|
|
4446
|
+
matched = payload.matched === true;
|
|
4447
|
+
}
|
|
4448
|
+
}
|
|
4449
|
+
catch {
|
|
4450
|
+
matched = false;
|
|
4451
|
+
}
|
|
4452
|
+
if (matched) {
|
|
4453
|
+
return null;
|
|
4454
|
+
}
|
|
4455
|
+
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4456
|
+
}
|
|
4408
4457
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
4409
4458
|
const editor = new EmbeddedEditor(container);
|
|
4410
4459
|
await editor.initialize(options, baseUrl);
|
|
@@ -4413,6 +4462,10 @@ async function createEditorInstance(container, options = {}, baseUrl) {
|
|
|
4413
4462
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
4414
4463
|
const presentation = new EmbeddedPresentation(container);
|
|
4415
4464
|
await presentation.initialize(options, baseUrl);
|
|
4465
|
+
const whitelistError = await checkPresentationWhitelist(options);
|
|
4466
|
+
if (whitelistError) {
|
|
4467
|
+
presentation.setWhitelistError(whitelistError);
|
|
4468
|
+
}
|
|
4416
4469
|
return presentation;
|
|
4417
4470
|
}
|
|
4418
4471
|
function createEmbeddedInstance(container, options) {
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -3901,7 +3901,7 @@
|
|
|
3901
3901
|
});
|
|
3902
3902
|
|
|
3903
3903
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3904
|
-
const VERSION = '2.
|
|
3904
|
+
const VERSION = '2.6.0';
|
|
3905
3905
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3906
3906
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3907
3907
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4077,6 +4077,7 @@
|
|
|
4077
4077
|
iframe.id = 'algeo-embed';
|
|
4078
4078
|
iframe.src = src;
|
|
4079
4079
|
iframe.allow = 'fullscreen';
|
|
4080
|
+
iframe.referrerPolicy = 'origin';
|
|
4080
4081
|
iframe.style.width = '100%';
|
|
4081
4082
|
iframe.style.height = '100%';
|
|
4082
4083
|
iframe.style.border = 'none';
|
|
@@ -4132,9 +4133,10 @@
|
|
|
4132
4133
|
window.addEventListener('message', this.messageHandler);
|
|
4133
4134
|
});
|
|
4134
4135
|
}
|
|
4135
|
-
post(type, payload) {
|
|
4136
|
+
post(type, payload, options = {}) {
|
|
4136
4137
|
const requestId = generateRequestId();
|
|
4137
4138
|
const msg = { type, requestId, ...payload };
|
|
4139
|
+
const timeoutMs = options.timeoutMs ?? EMBED_TIMEOUT_MS;
|
|
4138
4140
|
return new Promise((resolve, reject) => {
|
|
4139
4141
|
if (this.destroyed) {
|
|
4140
4142
|
reject(new AlgeoError('SDK 已销毁', EMBED_ERROR_CODES.DESTROYED));
|
|
@@ -4159,7 +4161,7 @@
|
|
|
4159
4161
|
this.pending.delete(requestId);
|
|
4160
4162
|
reject(new AlgeoError('请求超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4161
4163
|
}
|
|
4162
|
-
},
|
|
4164
|
+
}, timeoutMs);
|
|
4163
4165
|
});
|
|
4164
4166
|
}
|
|
4165
4167
|
async destroy() {
|
|
@@ -4192,7 +4194,19 @@
|
|
|
4192
4194
|
acceptsEventMessage() {
|
|
4193
4195
|
return false;
|
|
4194
4196
|
}
|
|
4197
|
+
setWhitelistError(error) {
|
|
4198
|
+
this.whitelistError = error;
|
|
4199
|
+
}
|
|
4200
|
+
ensureWhitelistAccess(methodName) {
|
|
4201
|
+
if (!this.whitelistError) {
|
|
4202
|
+
return;
|
|
4203
|
+
}
|
|
4204
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4205
|
+
console.error(error);
|
|
4206
|
+
throw error;
|
|
4207
|
+
}
|
|
4195
4208
|
async loadShareById(id) {
|
|
4209
|
+
this.ensureWhitelistAccess('loadShareById');
|
|
4196
4210
|
const result = await this.post('loadShareById', {
|
|
4197
4211
|
id,
|
|
4198
4212
|
});
|
|
@@ -4202,6 +4216,7 @@
|
|
|
4202
4216
|
return result;
|
|
4203
4217
|
}
|
|
4204
4218
|
async loadFile(content) {
|
|
4219
|
+
this.ensureWhitelistAccess('loadFile');
|
|
4205
4220
|
const result = await this.post('loadContent', { content });
|
|
4206
4221
|
this.currentContent = content;
|
|
4207
4222
|
this.currentSlideIndex = 0;
|
|
@@ -4209,16 +4224,19 @@
|
|
|
4209
4224
|
return result;
|
|
4210
4225
|
}
|
|
4211
4226
|
async switchSlide(index) {
|
|
4227
|
+
this.ensureWhitelistAccess('switchSlide');
|
|
4212
4228
|
const result = await this.post('switchSlide', { index });
|
|
4213
4229
|
this.currentSlideIndex = index;
|
|
4214
4230
|
return result;
|
|
4215
4231
|
}
|
|
4216
4232
|
async getSlideCount() {
|
|
4233
|
+
this.ensureWhitelistAccess('getSlideCount');
|
|
4217
4234
|
const result = await this.post('getSlideCount', {});
|
|
4218
4235
|
this.slideCount = result.count;
|
|
4219
4236
|
return result;
|
|
4220
4237
|
}
|
|
4221
4238
|
async repl(command) {
|
|
4239
|
+
this.ensureWhitelistAccess('repl');
|
|
4222
4240
|
return this.post('repl', { command });
|
|
4223
4241
|
}
|
|
4224
4242
|
}
|
|
@@ -4266,6 +4284,10 @@
|
|
|
4266
4284
|
}
|
|
4267
4285
|
await this.refreshHistoryState();
|
|
4268
4286
|
},
|
|
4287
|
+
exportImage: async (options) => {
|
|
4288
|
+
const result = await this.post('exportSlideImage', { options: options ?? {} });
|
|
4289
|
+
return result.images;
|
|
4290
|
+
},
|
|
4269
4291
|
};
|
|
4270
4292
|
this.history = {
|
|
4271
4293
|
getCount: () => this.historyCount,
|
|
@@ -4411,6 +4433,33 @@
|
|
|
4411
4433
|
}
|
|
4412
4434
|
}
|
|
4413
4435
|
|
|
4436
|
+
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4437
|
+
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4438
|
+
async function checkPresentationWhitelist(options) {
|
|
4439
|
+
const appId = options.appId?.trim() ?? '';
|
|
4440
|
+
const host = window.location.host.trim();
|
|
4441
|
+
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4442
|
+
url.searchParams.set('appId', appId);
|
|
4443
|
+
url.searchParams.set('host', host);
|
|
4444
|
+
let matched = false;
|
|
4445
|
+
try {
|
|
4446
|
+
const response = await fetch(url.toString(), {
|
|
4447
|
+
method: 'GET',
|
|
4448
|
+
cache: 'no-store',
|
|
4449
|
+
});
|
|
4450
|
+
if (response.ok) {
|
|
4451
|
+
const payload = (await response.json());
|
|
4452
|
+
matched = payload.matched === true;
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
catch {
|
|
4456
|
+
matched = false;
|
|
4457
|
+
}
|
|
4458
|
+
if (matched) {
|
|
4459
|
+
return null;
|
|
4460
|
+
}
|
|
4461
|
+
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4462
|
+
}
|
|
4414
4463
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
4415
4464
|
const editor = new EmbeddedEditor(container);
|
|
4416
4465
|
await editor.initialize(options, baseUrl);
|
|
@@ -4419,6 +4468,10 @@
|
|
|
4419
4468
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
4420
4469
|
const presentation = new EmbeddedPresentation(container);
|
|
4421
4470
|
await presentation.initialize(options, baseUrl);
|
|
4471
|
+
const whitelistError = await checkPresentationWhitelist(options);
|
|
4472
|
+
if (whitelistError) {
|
|
4473
|
+
presentation.setWhitelistError(whitelistError);
|
|
4474
|
+
}
|
|
4422
4475
|
return presentation;
|
|
4423
4476
|
}
|
|
4424
4477
|
function createEmbeddedInstance(container, options) {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { EmbeddedTarget } from './embedded-target';
|
|
2
|
-
import { type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentV10, type GetSlideCountResult, type LoadFileResult, type LoadShareByIdResult, type ReplResult, type SwitchSlideResult } from './shared';
|
|
2
|
+
import { AlgeoError, type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentV10, type GetSlideCountResult, type LoadFileResult, type LoadShareByIdResult, type ReplResult, type SwitchSlideResult } from './shared';
|
|
3
3
|
export declare class EmbeddedPresentation extends EmbeddedTarget<EmbeddedPresentationEventMap, EmbeddedPresentationEventName, EmbeddedPresentationEventListenerMap> {
|
|
4
4
|
private currentContent?;
|
|
5
5
|
private currentSlideIndex;
|
|
6
6
|
private slideCount;
|
|
7
|
+
private whitelistError?;
|
|
7
8
|
constructor(container: HTMLElement);
|
|
8
9
|
initialize(options?: AlgeoPresentationCreateOptions, baseUrl?: string): Promise<void>;
|
|
9
10
|
protected acceptsEventMessage(): boolean;
|
|
11
|
+
setWhitelistError(error: AlgeoError): void;
|
|
12
|
+
private ensureWhitelistAccess;
|
|
10
13
|
loadShareById(id: string): Promise<LoadShareByIdResult>;
|
|
11
14
|
loadFile(content: FileContentV10): Promise<LoadFileResult>;
|
|
12
15
|
switchSlide(index: number): Promise<SwitchSlideResult>;
|
|
@@ -28,6 +28,8 @@ export declare abstract class EmbeddedTarget<EventMap extends {
|
|
|
28
28
|
private cleanupIframe;
|
|
29
29
|
private resetRuntimeState;
|
|
30
30
|
protected init(options: EmbedInitOptions): Promise<void>;
|
|
31
|
-
protected post<T>(type: string, payload: Record<string, unknown
|
|
31
|
+
protected post<T>(type: string, payload: Record<string, unknown>, options?: {
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
}): Promise<T>;
|
|
32
34
|
destroy(): Promise<void>;
|
|
33
35
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
|
|
2
2
|
export type { FileContentV10 } from '@dajiaoai/algeo-protocol';
|
|
3
|
-
export type { AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoPresentationCreateOptions, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, ReadyEvent, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
3
|
+
export type { AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoPresentationCreateOptions, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, ReadyEvent, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
4
4
|
export { EmbeddedPresentation } from './embedded-presentation';
|
|
5
5
|
export { EmbeddedEditor } from './embedded-editor';
|
|
6
6
|
export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
|
package/dist/shared.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface AlgeoEditorCreateOptions {
|
|
|
37
37
|
ui?: AlgeoEditorUiConfig;
|
|
38
38
|
}
|
|
39
39
|
export interface AlgeoPresentationCreateOptions {
|
|
40
|
+
appId?: string;
|
|
40
41
|
shareId?: string;
|
|
41
42
|
}
|
|
42
43
|
export type AlgeoCreateOptions = {
|
|
@@ -117,6 +118,25 @@ export interface ReplResult {
|
|
|
117
118
|
export interface SlideIndexResult {
|
|
118
119
|
index: number;
|
|
119
120
|
}
|
|
121
|
+
export interface ExportSlideImageOptions {
|
|
122
|
+
slideIndices?: number[];
|
|
123
|
+
format?: 'png' | 'jpg';
|
|
124
|
+
width?: number;
|
|
125
|
+
height?: number;
|
|
126
|
+
quality?: number;
|
|
127
|
+
autoFit?: boolean;
|
|
128
|
+
padding?: number;
|
|
129
|
+
}
|
|
130
|
+
export interface ExportedSlideImage {
|
|
131
|
+
index: number;
|
|
132
|
+
blob: Blob;
|
|
133
|
+
format: 'png' | 'jpg';
|
|
134
|
+
width: number;
|
|
135
|
+
height: number;
|
|
136
|
+
}
|
|
137
|
+
export interface ExportSlideImageResult {
|
|
138
|
+
images: ExportedSlideImage[];
|
|
139
|
+
}
|
|
120
140
|
export interface GetContentResult {
|
|
121
141
|
content: FileContentV10;
|
|
122
142
|
}
|
|
@@ -139,6 +159,7 @@ export interface SlidesApi {
|
|
|
139
159
|
remove(index: number): Promise<void>;
|
|
140
160
|
duplicate(index: number, targetIndex?: number): Promise<SlideIndexResult>;
|
|
141
161
|
reorder(fromIndex: number, toIndex: number): Promise<void>;
|
|
162
|
+
exportImage(options?: ExportSlideImageOptions): Promise<ExportedSlideImage[]>;
|
|
142
163
|
}
|
|
143
164
|
export interface HistoryApi {
|
|
144
165
|
getCount(): number;
|