@dajiaoai/algeo-sdk 2.5.0 → 2.6.1
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 +23 -22
- package/dist/algeo-sdk.cjs.js +91 -4
- package/dist/algeo-sdk.esm.js +91 -5
- package/dist/algeo-sdk.umd.js +91 -4
- package/dist/embedded-presentation.d.ts +2 -2
- package/dist/embedded-target.d.ts +3 -1
- package/dist/index.d.ts +3 -2
- package/dist/shared.d.ts +30 -10
- package/package.json +2 -2
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.5.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.5.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,15 +39,15 @@ npm install @dajiaoai/algeo-sdk@2.5.0
|
|
|
39
39
|
**unpkg**:
|
|
40
40
|
|
|
41
41
|
```html
|
|
42
|
-
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.
|
|
43
|
-
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
42
|
+
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.6.0/dist/algeo-sdk.umd.min.js"></script>
|
|
43
|
+
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.min.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.
|
|
50
|
-
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.6.0/dist/algeo-sdk.umd.min.js"></script>
|
|
50
|
+
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.min.js"></script>
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
> 生产环境建议使用**具体版本号**,避免自动升级带来的兼容性风险。
|
|
@@ -254,7 +254,7 @@ type AlgeoCreateOptions =
|
|
|
254
254
|
| ---------------- | ------------------------------ | ------ | ------------------------------------------------------ |
|
|
255
255
|
| `auth` | `{ appId: string }` | - | 编辑模式鉴权参数,其中 `appId` 会参与默认路由生成 |
|
|
256
256
|
| `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
|
|
257
|
-
| `initialContent` | `
|
|
257
|
+
| `initialContent` | `FileContentLatest` | - | 初始化后自动注入的文件内容 |
|
|
258
258
|
| `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
|
|
259
259
|
|
|
260
260
|
**AlgeoPresentationCreateOptions:**
|
|
@@ -322,7 +322,7 @@ const presentation = await create(container, {
|
|
|
322
322
|
|
|
323
323
|
##### `presentation.loadFile(content: FileContent): Promise<LoadFileResult>`
|
|
324
324
|
|
|
325
|
-
加载完整文件数据(覆盖式),需符合
|
|
325
|
+
加载完整文件数据(覆盖式),需符合 FileContentLatest 格式。
|
|
326
326
|
|
|
327
327
|
| 参数 | 类型 | 说明 |
|
|
328
328
|
| --------- | ------------- | ------------ |
|
|
@@ -333,9 +333,9 @@ const presentation = await create(container, {
|
|
|
333
333
|
```typescript
|
|
334
334
|
interface FileContent {
|
|
335
335
|
slides: unknown[]; // 画板数据数组
|
|
336
|
-
messages: unknown[]; //
|
|
336
|
+
messages: unknown[]; // 消息数据(最新版本为会话数组)
|
|
337
337
|
metadata: {
|
|
338
|
-
version: string; // 如 '
|
|
338
|
+
version: string; // 如 '11'
|
|
339
339
|
shareOptions?: unknown;
|
|
340
340
|
};
|
|
341
341
|
}
|
|
@@ -410,16 +410,17 @@ interface FileContent {
|
|
|
410
410
|
|
|
411
411
|
#### `editor.slides`
|
|
412
412
|
|
|
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)` | 重排画板
|
|
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` |
|
|
423
424
|
|
|
424
425
|
#### `editor.history`
|
|
425
426
|
|
|
@@ -448,7 +449,7 @@ interface FileContent {
|
|
|
448
449
|
| 事件名 | 事件数据 | 说明 |
|
|
449
450
|
| --------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
450
451
|
| `ready` | `{ type: 'ready', mode, version }` | iframe 初始化完成 |
|
|
451
|
-
| `contentChange` | `{ type: 'contentChange', source: 'user', content }` | 用户在 iframe 内编辑后回传完整 `
|
|
452
|
+
| `contentChange` | `{ type: 'contentChange', source: 'user', content }` | 用户在 iframe 内编辑后回传完整 `FileContentLatest` |
|
|
452
453
|
| `slideChange` | `{ type: 'slideChange', index }` | 用户在 iframe 内切换画板后回传当前索引 |
|
|
453
454
|
| `save` | `{ type: 'save', stage: 'request' \| 'success', content }` | `stage: 'request'` 时用于宿主处理保存,`stage: 'success'` 时表示保存成功后的通知 |
|
|
454
455
|
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -3875,6 +3875,10 @@ var fileContentV10MetadataSchema = objectType({
|
|
|
3875
3875
|
version: literalType("10"),
|
|
3876
3876
|
shareOptions: shareOptionsSchema.optional()
|
|
3877
3877
|
});
|
|
3878
|
+
var fileContentV11MetadataSchema = objectType({
|
|
3879
|
+
version: literalType("11"),
|
|
3880
|
+
shareOptions: shareOptionsSchema.optional()
|
|
3881
|
+
});
|
|
3878
3882
|
var definitionV2Schema = objectType({
|
|
3879
3883
|
kind: stringType(),
|
|
3880
3884
|
id: stringType()
|
|
@@ -3883,7 +3887,11 @@ var slideV2Schema = objectType({
|
|
|
3883
3887
|
definitions: arrayType(definitionV2Schema),
|
|
3884
3888
|
uvarMap: arrayType(tupleType([stringType(), numberType()])),
|
|
3885
3889
|
styleSheet: recordType(stringType(), unknownType()),
|
|
3886
|
-
doc: arrayType(unknownType())
|
|
3890
|
+
doc: arrayType(unknownType()),
|
|
3891
|
+
camera: objectType({
|
|
3892
|
+
offset: tupleType([numberType(), numberType()]),
|
|
3893
|
+
scale: numberType()
|
|
3894
|
+
}).optional()
|
|
3887
3895
|
});
|
|
3888
3896
|
var seedChatMessageSchema = objectType({
|
|
3889
3897
|
id: stringType(),
|
|
@@ -3895,9 +3903,82 @@ objectType({
|
|
|
3895
3903
|
messages: arrayType(seedChatMessageSchema),
|
|
3896
3904
|
metadata: fileContentV10MetadataSchema
|
|
3897
3905
|
});
|
|
3906
|
+
objectType({
|
|
3907
|
+
slides: arrayType(slideV2Schema),
|
|
3908
|
+
messages: arrayType(arrayType(seedChatMessageSchema)),
|
|
3909
|
+
metadata: fileContentV11MetadataSchema
|
|
3910
|
+
});
|
|
3911
|
+
function upgradeFromV10ToV11(content) {
|
|
3912
|
+
const normalizeTextStyleOpacityInRecord = (style) => {
|
|
3913
|
+
if (!style) {
|
|
3914
|
+
return {};
|
|
3915
|
+
}
|
|
3916
|
+
return {
|
|
3917
|
+
...style,
|
|
3918
|
+
fillOpacity: style.fillOpacity ? style.fillOpacity * 100 : 100,
|
|
3919
|
+
strokeOpacity: style.strokeOpacity ? style.strokeOpacity * 100 : 100
|
|
3920
|
+
};
|
|
3921
|
+
};
|
|
3922
|
+
const normalizeDistanceMode = (value) => {
|
|
3923
|
+
if (value === "half-pi") {
|
|
3924
|
+
return "half_pi";
|
|
3925
|
+
}
|
|
3926
|
+
return value;
|
|
3927
|
+
};
|
|
3928
|
+
return {
|
|
3929
|
+
slides: content.slides.map((slide) => ({
|
|
3930
|
+
...slide,
|
|
3931
|
+
styleSheet: {
|
|
3932
|
+
...slide.styleSheet,
|
|
3933
|
+
xaxis: {
|
|
3934
|
+
...slide.styleSheet.xaxis,
|
|
3935
|
+
distanceMode: normalizeDistanceMode(
|
|
3936
|
+
slide.styleSheet.xaxis.distanceMode
|
|
3937
|
+
)
|
|
3938
|
+
},
|
|
3939
|
+
yaxis: {
|
|
3940
|
+
...slide.styleSheet.yaxis,
|
|
3941
|
+
distanceMode: normalizeDistanceMode(
|
|
3942
|
+
slide.styleSheet.yaxis.distanceMode
|
|
3943
|
+
)
|
|
3944
|
+
},
|
|
3945
|
+
grid: {
|
|
3946
|
+
...slide.styleSheet.grid,
|
|
3947
|
+
distanceMode: normalizeDistanceMode(
|
|
3948
|
+
slide.styleSheet.grid.distanceMode
|
|
3949
|
+
)
|
|
3950
|
+
},
|
|
3951
|
+
textType: normalizeTextStyleOpacityInRecord(
|
|
3952
|
+
slide.styleSheet.textType
|
|
3953
|
+
),
|
|
3954
|
+
texts: slide.styleSheet.texts.map(([id, style]) => [
|
|
3955
|
+
id,
|
|
3956
|
+
normalizeTextStyleOpacityInRecord(
|
|
3957
|
+
style
|
|
3958
|
+
)
|
|
3959
|
+
])
|
|
3960
|
+
}
|
|
3961
|
+
})),
|
|
3962
|
+
messages: [content.messages],
|
|
3963
|
+
metadata: {
|
|
3964
|
+
...content.metadata,
|
|
3965
|
+
version: "11"
|
|
3966
|
+
}
|
|
3967
|
+
};
|
|
3968
|
+
}
|
|
3969
|
+
function convertToLatest(content) {
|
|
3970
|
+
const version = content.metadata.version;
|
|
3971
|
+
if (version === "11") {
|
|
3972
|
+
return content;
|
|
3973
|
+
}
|
|
3974
|
+
if (version === "10") {
|
|
3975
|
+
return convertToLatest(upgradeFromV10ToV11(content));
|
|
3976
|
+
}
|
|
3977
|
+
throw new Error(`Unsupported FileContent version: ${version}`);
|
|
3978
|
+
}
|
|
3898
3979
|
|
|
3899
3980
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3900
|
-
const VERSION = '2.
|
|
3981
|
+
const VERSION = '2.6.1';
|
|
3901
3982
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3902
3983
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3903
3984
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4129,9 +4210,10 @@ class EmbeddedTarget {
|
|
|
4129
4210
|
window.addEventListener('message', this.messageHandler);
|
|
4130
4211
|
});
|
|
4131
4212
|
}
|
|
4132
|
-
post(type, payload) {
|
|
4213
|
+
post(type, payload, options = {}) {
|
|
4133
4214
|
const requestId = generateRequestId();
|
|
4134
4215
|
const msg = { type, requestId, ...payload };
|
|
4216
|
+
const timeoutMs = options.timeoutMs ?? EMBED_TIMEOUT_MS;
|
|
4135
4217
|
return new Promise((resolve, reject) => {
|
|
4136
4218
|
if (this.destroyed) {
|
|
4137
4219
|
reject(new AlgeoError('SDK 已销毁', EMBED_ERROR_CODES.DESTROYED));
|
|
@@ -4156,7 +4238,7 @@ class EmbeddedTarget {
|
|
|
4156
4238
|
this.pending.delete(requestId);
|
|
4157
4239
|
reject(new AlgeoError('请求超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4158
4240
|
}
|
|
4159
|
-
},
|
|
4241
|
+
}, timeoutMs);
|
|
4160
4242
|
});
|
|
4161
4243
|
}
|
|
4162
4244
|
async destroy() {
|
|
@@ -4279,6 +4361,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4279
4361
|
}
|
|
4280
4362
|
await this.refreshHistoryState();
|
|
4281
4363
|
},
|
|
4364
|
+
exportImage: async (options) => {
|
|
4365
|
+
const result = await this.post('exportSlideImage', { options: options ?? {} });
|
|
4366
|
+
return result.images;
|
|
4367
|
+
},
|
|
4282
4368
|
};
|
|
4283
4369
|
this.history = {
|
|
4284
4370
|
getCount: () => this.historyCount,
|
|
@@ -4499,6 +4585,7 @@ exports.EMBED_ERROR_CODES = EMBED_ERROR_CODES;
|
|
|
4499
4585
|
exports.EmbeddedEditor = EmbeddedEditor;
|
|
4500
4586
|
exports.EmbeddedPresentation = EmbeddedPresentation;
|
|
4501
4587
|
exports.VERSION = VERSION;
|
|
4588
|
+
exports.convertToLatest = convertToLatest;
|
|
4502
4589
|
exports.create = create;
|
|
4503
4590
|
exports.createEditor = createEditor;
|
|
4504
4591
|
exports.createPresentation = createPresentation;
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -3873,6 +3873,10 @@ var fileContentV10MetadataSchema = objectType({
|
|
|
3873
3873
|
version: literalType("10"),
|
|
3874
3874
|
shareOptions: shareOptionsSchema.optional()
|
|
3875
3875
|
});
|
|
3876
|
+
var fileContentV11MetadataSchema = objectType({
|
|
3877
|
+
version: literalType("11"),
|
|
3878
|
+
shareOptions: shareOptionsSchema.optional()
|
|
3879
|
+
});
|
|
3876
3880
|
var definitionV2Schema = objectType({
|
|
3877
3881
|
kind: stringType(),
|
|
3878
3882
|
id: stringType()
|
|
@@ -3881,7 +3885,11 @@ var slideV2Schema = objectType({
|
|
|
3881
3885
|
definitions: arrayType(definitionV2Schema),
|
|
3882
3886
|
uvarMap: arrayType(tupleType([stringType(), numberType()])),
|
|
3883
3887
|
styleSheet: recordType(stringType(), unknownType()),
|
|
3884
|
-
doc: arrayType(unknownType())
|
|
3888
|
+
doc: arrayType(unknownType()),
|
|
3889
|
+
camera: objectType({
|
|
3890
|
+
offset: tupleType([numberType(), numberType()]),
|
|
3891
|
+
scale: numberType()
|
|
3892
|
+
}).optional()
|
|
3885
3893
|
});
|
|
3886
3894
|
var seedChatMessageSchema = objectType({
|
|
3887
3895
|
id: stringType(),
|
|
@@ -3893,9 +3901,82 @@ objectType({
|
|
|
3893
3901
|
messages: arrayType(seedChatMessageSchema),
|
|
3894
3902
|
metadata: fileContentV10MetadataSchema
|
|
3895
3903
|
});
|
|
3904
|
+
objectType({
|
|
3905
|
+
slides: arrayType(slideV2Schema),
|
|
3906
|
+
messages: arrayType(arrayType(seedChatMessageSchema)),
|
|
3907
|
+
metadata: fileContentV11MetadataSchema
|
|
3908
|
+
});
|
|
3909
|
+
function upgradeFromV10ToV11(content) {
|
|
3910
|
+
const normalizeTextStyleOpacityInRecord = (style) => {
|
|
3911
|
+
if (!style) {
|
|
3912
|
+
return {};
|
|
3913
|
+
}
|
|
3914
|
+
return {
|
|
3915
|
+
...style,
|
|
3916
|
+
fillOpacity: style.fillOpacity ? style.fillOpacity * 100 : 100,
|
|
3917
|
+
strokeOpacity: style.strokeOpacity ? style.strokeOpacity * 100 : 100
|
|
3918
|
+
};
|
|
3919
|
+
};
|
|
3920
|
+
const normalizeDistanceMode = (value) => {
|
|
3921
|
+
if (value === "half-pi") {
|
|
3922
|
+
return "half_pi";
|
|
3923
|
+
}
|
|
3924
|
+
return value;
|
|
3925
|
+
};
|
|
3926
|
+
return {
|
|
3927
|
+
slides: content.slides.map((slide) => ({
|
|
3928
|
+
...slide,
|
|
3929
|
+
styleSheet: {
|
|
3930
|
+
...slide.styleSheet,
|
|
3931
|
+
xaxis: {
|
|
3932
|
+
...slide.styleSheet.xaxis,
|
|
3933
|
+
distanceMode: normalizeDistanceMode(
|
|
3934
|
+
slide.styleSheet.xaxis.distanceMode
|
|
3935
|
+
)
|
|
3936
|
+
},
|
|
3937
|
+
yaxis: {
|
|
3938
|
+
...slide.styleSheet.yaxis,
|
|
3939
|
+
distanceMode: normalizeDistanceMode(
|
|
3940
|
+
slide.styleSheet.yaxis.distanceMode
|
|
3941
|
+
)
|
|
3942
|
+
},
|
|
3943
|
+
grid: {
|
|
3944
|
+
...slide.styleSheet.grid,
|
|
3945
|
+
distanceMode: normalizeDistanceMode(
|
|
3946
|
+
slide.styleSheet.grid.distanceMode
|
|
3947
|
+
)
|
|
3948
|
+
},
|
|
3949
|
+
textType: normalizeTextStyleOpacityInRecord(
|
|
3950
|
+
slide.styleSheet.textType
|
|
3951
|
+
),
|
|
3952
|
+
texts: slide.styleSheet.texts.map(([id, style]) => [
|
|
3953
|
+
id,
|
|
3954
|
+
normalizeTextStyleOpacityInRecord(
|
|
3955
|
+
style
|
|
3956
|
+
)
|
|
3957
|
+
])
|
|
3958
|
+
}
|
|
3959
|
+
})),
|
|
3960
|
+
messages: [content.messages],
|
|
3961
|
+
metadata: {
|
|
3962
|
+
...content.metadata,
|
|
3963
|
+
version: "11"
|
|
3964
|
+
}
|
|
3965
|
+
};
|
|
3966
|
+
}
|
|
3967
|
+
function convertToLatest(content) {
|
|
3968
|
+
const version = content.metadata.version;
|
|
3969
|
+
if (version === "11") {
|
|
3970
|
+
return content;
|
|
3971
|
+
}
|
|
3972
|
+
if (version === "10") {
|
|
3973
|
+
return convertToLatest(upgradeFromV10ToV11(content));
|
|
3974
|
+
}
|
|
3975
|
+
throw new Error(`Unsupported FileContent version: ${version}`);
|
|
3976
|
+
}
|
|
3896
3977
|
|
|
3897
3978
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3898
|
-
const VERSION = '2.
|
|
3979
|
+
const VERSION = '2.6.1';
|
|
3899
3980
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3900
3981
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3901
3982
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4127,9 +4208,10 @@ class EmbeddedTarget {
|
|
|
4127
4208
|
window.addEventListener('message', this.messageHandler);
|
|
4128
4209
|
});
|
|
4129
4210
|
}
|
|
4130
|
-
post(type, payload) {
|
|
4211
|
+
post(type, payload, options = {}) {
|
|
4131
4212
|
const requestId = generateRequestId();
|
|
4132
4213
|
const msg = { type, requestId, ...payload };
|
|
4214
|
+
const timeoutMs = options.timeoutMs ?? EMBED_TIMEOUT_MS;
|
|
4133
4215
|
return new Promise((resolve, reject) => {
|
|
4134
4216
|
if (this.destroyed) {
|
|
4135
4217
|
reject(new AlgeoError('SDK 已销毁', EMBED_ERROR_CODES.DESTROYED));
|
|
@@ -4154,7 +4236,7 @@ class EmbeddedTarget {
|
|
|
4154
4236
|
this.pending.delete(requestId);
|
|
4155
4237
|
reject(new AlgeoError('请求超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4156
4238
|
}
|
|
4157
|
-
},
|
|
4239
|
+
}, timeoutMs);
|
|
4158
4240
|
});
|
|
4159
4241
|
}
|
|
4160
4242
|
async destroy() {
|
|
@@ -4277,6 +4359,10 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4277
4359
|
}
|
|
4278
4360
|
await this.refreshHistoryState();
|
|
4279
4361
|
},
|
|
4362
|
+
exportImage: async (options) => {
|
|
4363
|
+
const result = await this.post('exportSlideImage', { options: options ?? {} });
|
|
4364
|
+
return result.images;
|
|
4365
|
+
},
|
|
4280
4366
|
};
|
|
4281
4367
|
this.history = {
|
|
4282
4368
|
getCount: () => this.historyCount,
|
|
@@ -4491,4 +4577,4 @@ async function createPresentation(container, options = {}) {
|
|
|
4491
4577
|
return createPresentationInstance(container, options);
|
|
4492
4578
|
}
|
|
4493
4579
|
|
|
4494
|
-
export { AlgeoError, AlgeoSdk, EMBED_ERROR_CODES, EmbeddedEditor, EmbeddedPresentation, VERSION, create, createEditor, createPresentation };
|
|
4580
|
+
export { AlgeoError, AlgeoSdk, EMBED_ERROR_CODES, EmbeddedEditor, EmbeddedPresentation, VERSION, convertToLatest, create, createEditor, createPresentation };
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -3879,6 +3879,10 @@
|
|
|
3879
3879
|
version: literalType("10"),
|
|
3880
3880
|
shareOptions: shareOptionsSchema.optional()
|
|
3881
3881
|
});
|
|
3882
|
+
var fileContentV11MetadataSchema = objectType({
|
|
3883
|
+
version: literalType("11"),
|
|
3884
|
+
shareOptions: shareOptionsSchema.optional()
|
|
3885
|
+
});
|
|
3882
3886
|
var definitionV2Schema = objectType({
|
|
3883
3887
|
kind: stringType(),
|
|
3884
3888
|
id: stringType()
|
|
@@ -3887,7 +3891,11 @@
|
|
|
3887
3891
|
definitions: arrayType(definitionV2Schema),
|
|
3888
3892
|
uvarMap: arrayType(tupleType([stringType(), numberType()])),
|
|
3889
3893
|
styleSheet: recordType(stringType(), unknownType()),
|
|
3890
|
-
doc: arrayType(unknownType())
|
|
3894
|
+
doc: arrayType(unknownType()),
|
|
3895
|
+
camera: objectType({
|
|
3896
|
+
offset: tupleType([numberType(), numberType()]),
|
|
3897
|
+
scale: numberType()
|
|
3898
|
+
}).optional()
|
|
3891
3899
|
});
|
|
3892
3900
|
var seedChatMessageSchema = objectType({
|
|
3893
3901
|
id: stringType(),
|
|
@@ -3899,9 +3907,82 @@
|
|
|
3899
3907
|
messages: arrayType(seedChatMessageSchema),
|
|
3900
3908
|
metadata: fileContentV10MetadataSchema
|
|
3901
3909
|
});
|
|
3910
|
+
objectType({
|
|
3911
|
+
slides: arrayType(slideV2Schema),
|
|
3912
|
+
messages: arrayType(arrayType(seedChatMessageSchema)),
|
|
3913
|
+
metadata: fileContentV11MetadataSchema
|
|
3914
|
+
});
|
|
3915
|
+
function upgradeFromV10ToV11(content) {
|
|
3916
|
+
const normalizeTextStyleOpacityInRecord = (style) => {
|
|
3917
|
+
if (!style) {
|
|
3918
|
+
return {};
|
|
3919
|
+
}
|
|
3920
|
+
return {
|
|
3921
|
+
...style,
|
|
3922
|
+
fillOpacity: style.fillOpacity ? style.fillOpacity * 100 : 100,
|
|
3923
|
+
strokeOpacity: style.strokeOpacity ? style.strokeOpacity * 100 : 100
|
|
3924
|
+
};
|
|
3925
|
+
};
|
|
3926
|
+
const normalizeDistanceMode = (value) => {
|
|
3927
|
+
if (value === "half-pi") {
|
|
3928
|
+
return "half_pi";
|
|
3929
|
+
}
|
|
3930
|
+
return value;
|
|
3931
|
+
};
|
|
3932
|
+
return {
|
|
3933
|
+
slides: content.slides.map((slide) => ({
|
|
3934
|
+
...slide,
|
|
3935
|
+
styleSheet: {
|
|
3936
|
+
...slide.styleSheet,
|
|
3937
|
+
xaxis: {
|
|
3938
|
+
...slide.styleSheet.xaxis,
|
|
3939
|
+
distanceMode: normalizeDistanceMode(
|
|
3940
|
+
slide.styleSheet.xaxis.distanceMode
|
|
3941
|
+
)
|
|
3942
|
+
},
|
|
3943
|
+
yaxis: {
|
|
3944
|
+
...slide.styleSheet.yaxis,
|
|
3945
|
+
distanceMode: normalizeDistanceMode(
|
|
3946
|
+
slide.styleSheet.yaxis.distanceMode
|
|
3947
|
+
)
|
|
3948
|
+
},
|
|
3949
|
+
grid: {
|
|
3950
|
+
...slide.styleSheet.grid,
|
|
3951
|
+
distanceMode: normalizeDistanceMode(
|
|
3952
|
+
slide.styleSheet.grid.distanceMode
|
|
3953
|
+
)
|
|
3954
|
+
},
|
|
3955
|
+
textType: normalizeTextStyleOpacityInRecord(
|
|
3956
|
+
slide.styleSheet.textType
|
|
3957
|
+
),
|
|
3958
|
+
texts: slide.styleSheet.texts.map(([id, style]) => [
|
|
3959
|
+
id,
|
|
3960
|
+
normalizeTextStyleOpacityInRecord(
|
|
3961
|
+
style
|
|
3962
|
+
)
|
|
3963
|
+
])
|
|
3964
|
+
}
|
|
3965
|
+
})),
|
|
3966
|
+
messages: [content.messages],
|
|
3967
|
+
metadata: {
|
|
3968
|
+
...content.metadata,
|
|
3969
|
+
version: "11"
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
}
|
|
3973
|
+
function convertToLatest(content) {
|
|
3974
|
+
const version = content.metadata.version;
|
|
3975
|
+
if (version === "11") {
|
|
3976
|
+
return content;
|
|
3977
|
+
}
|
|
3978
|
+
if (version === "10") {
|
|
3979
|
+
return convertToLatest(upgradeFromV10ToV11(content));
|
|
3980
|
+
}
|
|
3981
|
+
throw new Error(`Unsupported FileContent version: ${version}`);
|
|
3982
|
+
}
|
|
3902
3983
|
|
|
3903
3984
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3904
|
-
const VERSION = '2.
|
|
3985
|
+
const VERSION = '2.6.1';
|
|
3905
3986
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3906
3987
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3907
3988
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4133,9 +4214,10 @@
|
|
|
4133
4214
|
window.addEventListener('message', this.messageHandler);
|
|
4134
4215
|
});
|
|
4135
4216
|
}
|
|
4136
|
-
post(type, payload) {
|
|
4217
|
+
post(type, payload, options = {}) {
|
|
4137
4218
|
const requestId = generateRequestId();
|
|
4138
4219
|
const msg = { type, requestId, ...payload };
|
|
4220
|
+
const timeoutMs = options.timeoutMs ?? EMBED_TIMEOUT_MS;
|
|
4139
4221
|
return new Promise((resolve, reject) => {
|
|
4140
4222
|
if (this.destroyed) {
|
|
4141
4223
|
reject(new AlgeoError('SDK 已销毁', EMBED_ERROR_CODES.DESTROYED));
|
|
@@ -4160,7 +4242,7 @@
|
|
|
4160
4242
|
this.pending.delete(requestId);
|
|
4161
4243
|
reject(new AlgeoError('请求超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4162
4244
|
}
|
|
4163
|
-
},
|
|
4245
|
+
}, timeoutMs);
|
|
4164
4246
|
});
|
|
4165
4247
|
}
|
|
4166
4248
|
async destroy() {
|
|
@@ -4283,6 +4365,10 @@
|
|
|
4283
4365
|
}
|
|
4284
4366
|
await this.refreshHistoryState();
|
|
4285
4367
|
},
|
|
4368
|
+
exportImage: async (options) => {
|
|
4369
|
+
const result = await this.post('exportSlideImage', { options: options ?? {} });
|
|
4370
|
+
return result.images;
|
|
4371
|
+
},
|
|
4286
4372
|
};
|
|
4287
4373
|
this.history = {
|
|
4288
4374
|
getCount: () => this.historyCount,
|
|
@@ -4503,6 +4589,7 @@
|
|
|
4503
4589
|
exports.EmbeddedEditor = EmbeddedEditor;
|
|
4504
4590
|
exports.EmbeddedPresentation = EmbeddedPresentation;
|
|
4505
4591
|
exports.VERSION = VERSION;
|
|
4592
|
+
exports.convertToLatest = convertToLatest;
|
|
4506
4593
|
exports.create = create;
|
|
4507
4594
|
exports.createEditor = createEditor;
|
|
4508
4595
|
exports.createPresentation = createPresentation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EmbeddedTarget } from './embedded-target';
|
|
2
|
-
import { AlgeoError, type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type
|
|
2
|
+
import { AlgeoError, type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentLatest, 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;
|
|
@@ -11,7 +11,7 @@ export declare class EmbeddedPresentation extends EmbeddedTarget<EmbeddedPresent
|
|
|
11
11
|
setWhitelistError(error: AlgeoError): void;
|
|
12
12
|
private ensureWhitelistAccess;
|
|
13
13
|
loadShareById(id: string): Promise<LoadShareByIdResult>;
|
|
14
|
-
loadFile(content:
|
|
14
|
+
loadFile(content: FileContentLatest): Promise<LoadFileResult>;
|
|
15
15
|
switchSlide(index: number): Promise<SwitchSlideResult>;
|
|
16
16
|
getSlideCount(): Promise<GetSlideCountResult>;
|
|
17
17
|
repl(command: string): Promise<ReplResult>;
|
|
@@ -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,7 @@
|
|
|
1
1
|
export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
|
|
2
|
-
export type {
|
|
3
|
-
export
|
|
2
|
+
export type { FileContentLatest } from '@dajiaoai/algeo-protocol';
|
|
3
|
+
export { convertToLatest } from '@dajiaoai/algeo-protocol';
|
|
4
|
+
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
5
|
export { EmbeddedPresentation } from './embedded-presentation';
|
|
5
6
|
export { EmbeddedEditor } from './embedded-editor';
|
|
6
7
|
export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AlgeoError, type AlgeoErrorPayload, type EmbedReadyMessage, type EmbedResponseMessage, type
|
|
1
|
+
import { AlgeoError, type AlgeoErrorPayload, type EmbedReadyMessage, type EmbedResponseMessage, type FileContentLatest, EMBED_ERROR_CODES } from '@dajiaoai/algeo-protocol';
|
|
2
2
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3
3
|
export declare const VERSION = "__ALGEO_SDK_VERSION__";
|
|
4
4
|
/** 从协议层 re-export,供外部使用 */
|
|
5
|
-
export type {
|
|
5
|
+
export type { FileContentLatest, AlgeoErrorPayload };
|
|
6
6
|
export { AlgeoError, EMBED_ERROR_CODES };
|
|
7
7
|
export declare const EMBED_TIMEOUT_MS = 30000;
|
|
8
8
|
export interface AlgeoSdkOptions {
|
|
@@ -33,7 +33,7 @@ export type AlgeoEditorSaveResult = {
|
|
|
33
33
|
export interface AlgeoEditorCreateOptions {
|
|
34
34
|
auth?: AlgeoEditorAuthOptions;
|
|
35
35
|
shareId?: string;
|
|
36
|
-
initialContent?:
|
|
36
|
+
initialContent?: FileContentLatest;
|
|
37
37
|
ui?: AlgeoEditorUiConfig;
|
|
38
38
|
}
|
|
39
39
|
export interface AlgeoPresentationCreateOptions {
|
|
@@ -57,7 +57,7 @@ export interface ReadyEvent {
|
|
|
57
57
|
export interface ContentChangeEvent {
|
|
58
58
|
type: 'contentChange';
|
|
59
59
|
source: 'loadContent' | 'loadFile' | 'loadShareById' | 'initialContent' | 'user';
|
|
60
|
-
content?:
|
|
60
|
+
content?: FileContentLatest;
|
|
61
61
|
shareId?: string;
|
|
62
62
|
}
|
|
63
63
|
export interface SlideChangeEvent {
|
|
@@ -66,19 +66,19 @@ export interface SlideChangeEvent {
|
|
|
66
66
|
}
|
|
67
67
|
export interface SaveRequestEvent {
|
|
68
68
|
type: 'save';
|
|
69
|
-
content:
|
|
69
|
+
content: FileContentLatest;
|
|
70
70
|
stage: 'request';
|
|
71
71
|
}
|
|
72
72
|
export interface SaveSuccessEvent {
|
|
73
73
|
type: 'save';
|
|
74
|
-
content:
|
|
74
|
+
content: FileContentLatest;
|
|
75
75
|
stage: 'success';
|
|
76
76
|
}
|
|
77
77
|
export type SaveEvent = SaveRequestEvent | SaveSuccessEvent;
|
|
78
78
|
export interface SaveRequestMessage {
|
|
79
79
|
type: 'save';
|
|
80
80
|
requestId: string;
|
|
81
|
-
content:
|
|
81
|
+
content: FileContentLatest;
|
|
82
82
|
}
|
|
83
83
|
export interface EmbeddedEditorEventMap {
|
|
84
84
|
ready: ReadyEvent;
|
|
@@ -118,8 +118,27 @@ export interface ReplResult {
|
|
|
118
118
|
export interface SlideIndexResult {
|
|
119
119
|
index: number;
|
|
120
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
|
+
}
|
|
121
140
|
export interface GetContentResult {
|
|
122
|
-
content:
|
|
141
|
+
content: FileContentLatest;
|
|
123
142
|
}
|
|
124
143
|
export interface GetHistoryStateResult {
|
|
125
144
|
count: number;
|
|
@@ -128,8 +147,8 @@ export interface GetHistoryStateResult {
|
|
|
128
147
|
canRedo: boolean;
|
|
129
148
|
}
|
|
130
149
|
export interface DocumentApi {
|
|
131
|
-
loadContent(content:
|
|
132
|
-
getContent(): Promise<
|
|
150
|
+
loadContent(content: FileContentLatest): Promise<void>;
|
|
151
|
+
getContent(): Promise<FileContentLatest>;
|
|
133
152
|
}
|
|
134
153
|
export interface SlidesApi {
|
|
135
154
|
getCount(): number;
|
|
@@ -140,6 +159,7 @@ export interface SlidesApi {
|
|
|
140
159
|
remove(index: number): Promise<void>;
|
|
141
160
|
duplicate(index: number, targetIndex?: number): Promise<SlideIndexResult>;
|
|
142
161
|
reorder(fromIndex: number, toIndex: number): Promise<void>;
|
|
162
|
+
exportImage(options?: ExportSlideImageOptions): Promise<ExportedSlideImage[]>;
|
|
143
163
|
}
|
|
144
164
|
export interface HistoryApi {
|
|
145
165
|
getCount(): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dajiaoai/algeo-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
|
|
5
5
|
"main": "dist/algeo-sdk.cjs.js",
|
|
6
6
|
"module": "dist/algeo-sdk.esm.js",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"typescript": "^5.9.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@dajiaoai/algeo-protocol": "^1.
|
|
45
|
+
"@dajiaoai/algeo-protocol": "^1.4.0"
|
|
46
46
|
}
|
|
47
47
|
}
|