@dajiaoai/algeo-sdk 2.6.0 → 2.7.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 +35 -22
- package/dist/algeo-sdk.cjs.js +103 -3
- package/dist/algeo-sdk.esm.js +103 -4
- package/dist/algeo-sdk.umd.js +103 -3
- package/dist/embedded-presentation.d.ts +4 -2
- package/dist/index.d.ts +3 -2
- package/dist/shared.d.ts +19 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
# 安装最新版本
|
|
11
11
|
npm install @dajiaoai/algeo-sdk
|
|
12
12
|
|
|
13
|
-
#
|
|
14
|
-
npm install @dajiaoai/algeo-sdk@2.
|
|
13
|
+
# 安装指定主次版本
|
|
14
|
+
npm install @dajiaoai/algeo-sdk@2.7.0
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
在 `package.json` 中:
|
|
@@ -19,7 +19,7 @@ npm install @dajiaoai/algeo-sdk@2.6.0
|
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dajiaoai/algeo-sdk": "2.
|
|
22
|
+
"@dajiaoai/algeo-sdk": "~2.7.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
```
|
|
@@ -29,7 +29,7 @@ npm install @dajiaoai/algeo-sdk@2.6.0
|
|
|
29
29
|
```json
|
|
30
30
|
{
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dajiaoai/algeo-sdk": "^2.
|
|
32
|
+
"@dajiaoai/algeo-sdk": "^2.7.0" // 兼容 2.x 的更新(升级范围更大)
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
```
|
|
@@ -39,18 +39,18 @@ npm install @dajiaoai/algeo-sdk@2.6.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.7.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.7.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
|
+
> 生产环境建议锁定到 **2.7.x**(如 `~2.7.0`),在兼容边界内自动接收修复版本。
|
|
54
54
|
|
|
55
55
|
## 使用方式
|
|
56
56
|
|
|
@@ -63,6 +63,9 @@ const container = document.getElementById('algeo-container');
|
|
|
63
63
|
const presentation = await createPresentation(container, {
|
|
64
64
|
appId: 'YTVJDQZR',
|
|
65
65
|
shareId: '33TA3484',
|
|
66
|
+
ui: {
|
|
67
|
+
logo: false,
|
|
68
|
+
},
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
presentation.on('ready', (event) => {
|
|
@@ -114,6 +117,7 @@ const editor = await createEditor(document.getElementById('editor-root'), {
|
|
|
114
117
|
toolboxPanel: true,
|
|
115
118
|
algebraPanel: false,
|
|
116
119
|
docPanel: false,
|
|
120
|
+
helpEntry: false,
|
|
117
121
|
},
|
|
118
122
|
});
|
|
119
123
|
|
|
@@ -254,15 +258,16 @@ type AlgeoCreateOptions =
|
|
|
254
258
|
| ---------------- | ------------------------------ | ------ | ------------------------------------------------------ |
|
|
255
259
|
| `auth` | `{ appId: string }` | - | 编辑模式鉴权参数,其中 `appId` 会参与默认路由生成 |
|
|
256
260
|
| `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
|
|
257
|
-
| `initialContent` | `
|
|
261
|
+
| `initialContent` | `FileContentLatest` | - | 初始化后自动注入的文件内容 |
|
|
258
262
|
| `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
|
|
259
263
|
|
|
260
264
|
**AlgeoPresentationCreateOptions:**
|
|
261
265
|
|
|
262
|
-
| 属性 | 类型
|
|
263
|
-
| --------- |
|
|
264
|
-
| `appId` | `string`
|
|
265
|
-
| `shareId` | `string`
|
|
266
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
267
|
+
| --------- | ------------------------------------ | ------ | -------------------------------------------------------- |
|
|
268
|
+
| `appId` | `string` | `''` | 演示模式白名单校验使用的应用标识,SDK 会用它请求校验接口 |
|
|
269
|
+
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/e/:id` |
|
|
270
|
+
| `ui` | `Partial<AlgeoPresentationUiConfig>` | - | 演示模式 UI 配置 |
|
|
266
271
|
|
|
267
272
|
默认路径规则:
|
|
268
273
|
|
|
@@ -289,10 +294,11 @@ const presentation = await create(container, {
|
|
|
289
294
|
|
|
290
295
|
#### 实例属性(只读)
|
|
291
296
|
|
|
292
|
-
| 属性 | 类型
|
|
293
|
-
| --------- |
|
|
294
|
-
| `ready` | `boolean`
|
|
295
|
-
| `version` | `string \| null`
|
|
297
|
+
| 属性 | 类型 | 说明 |
|
|
298
|
+
| --------- | --------------------- | ------------------------------------ |
|
|
299
|
+
| `ready` | `boolean` | 是否已就绪(收到 iframe ready 通知) |
|
|
300
|
+
| `version` | `string \| null` | 内嵌页协议版本 |
|
|
301
|
+
| `mode` | `PresentationModeApi` | 演示模式展示控制能力 |
|
|
296
302
|
|
|
297
303
|
#### 事件订阅
|
|
298
304
|
|
|
@@ -308,6 +314,13 @@ const presentation = await create(container, {
|
|
|
308
314
|
|
|
309
315
|
#### 实例方法
|
|
310
316
|
|
|
317
|
+
##### `presentation.mode`
|
|
318
|
+
|
|
319
|
+
| 方法 | 说明 |
|
|
320
|
+
| --------------------- | ---------------- |
|
|
321
|
+
| `getUiConfig()` | 获取当前 UI 配置 |
|
|
322
|
+
| `setUiConfig(config)` | 更新 UI 配置 |
|
|
323
|
+
|
|
311
324
|
##### `presentation.loadShareById(id: string): Promise<LoadShareByIdResult>`
|
|
312
325
|
|
|
313
326
|
按分享 ID 加载内容。
|
|
@@ -322,7 +335,7 @@ const presentation = await create(container, {
|
|
|
322
335
|
|
|
323
336
|
##### `presentation.loadFile(content: FileContent): Promise<LoadFileResult>`
|
|
324
337
|
|
|
325
|
-
加载完整文件数据(覆盖式),需符合
|
|
338
|
+
加载完整文件数据(覆盖式),需符合 FileContentLatest 格式。
|
|
326
339
|
|
|
327
340
|
| 参数 | 类型 | 说明 |
|
|
328
341
|
| --------- | ------------- | ------------ |
|
|
@@ -333,9 +346,9 @@ const presentation = await create(container, {
|
|
|
333
346
|
```typescript
|
|
334
347
|
interface FileContent {
|
|
335
348
|
slides: unknown[]; // 画板数据数组
|
|
336
|
-
messages: unknown[]; //
|
|
349
|
+
messages: unknown[]; // 消息数据(最新版本为会话数组)
|
|
337
350
|
metadata: {
|
|
338
|
-
version: string; // 如 '
|
|
351
|
+
version: string; // 如 '11'
|
|
339
352
|
shareOptions?: unknown;
|
|
340
353
|
};
|
|
341
354
|
}
|
|
@@ -449,7 +462,7 @@ interface FileContent {
|
|
|
449
462
|
| 事件名 | 事件数据 | 说明 |
|
|
450
463
|
| --------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
451
464
|
| `ready` | `{ type: 'ready', mode, version }` | iframe 初始化完成 |
|
|
452
|
-
| `contentChange` | `{ type: 'contentChange', source: 'user', content }` | 用户在 iframe 内编辑后回传完整 `
|
|
465
|
+
| `contentChange` | `{ type: 'contentChange', source: 'user', content }` | 用户在 iframe 内编辑后回传完整 `FileContentLatest` |
|
|
453
466
|
| `slideChange` | `{ type: 'slideChange', index }` | 用户在 iframe 内切换画板后回传当前索引 |
|
|
454
467
|
| `save` | `{ type: 'save', stage: 'request' \| 'success', content }` | `stage: 'request'` 时用于宿主处理保存,`stage: 'success'` 时表示保存成功后的通知 |
|
|
455
468
|
|
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.7.0';
|
|
3901
3982
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3902
3983
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3903
3984
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4180,12 +4261,27 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4180
4261
|
super(container, 'presentation');
|
|
4181
4262
|
this.currentSlideIndex = 0;
|
|
4182
4263
|
this.slideCount = 0;
|
|
4264
|
+
this.uiConfig = {};
|
|
4265
|
+
this.mode = {
|
|
4266
|
+
getUiConfig: () => ({ ...this.uiConfig }),
|
|
4267
|
+
setUiConfig: async (config) => {
|
|
4268
|
+
await this.post('setUiConfig', { config });
|
|
4269
|
+
this.uiConfig = {
|
|
4270
|
+
...this.uiConfig,
|
|
4271
|
+
...config,
|
|
4272
|
+
};
|
|
4273
|
+
},
|
|
4274
|
+
};
|
|
4183
4275
|
}
|
|
4184
4276
|
async initialize(options = {}, baseUrl) {
|
|
4277
|
+
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4185
4278
|
await this.init({
|
|
4186
4279
|
baseUrl,
|
|
4187
4280
|
initialId: options.shareId,
|
|
4188
4281
|
});
|
|
4282
|
+
if (Object.keys(this.uiConfig).length > 0) {
|
|
4283
|
+
await this.mode.setUiConfig(this.uiConfig);
|
|
4284
|
+
}
|
|
4189
4285
|
}
|
|
4190
4286
|
acceptsEventMessage() {
|
|
4191
4287
|
return false;
|
|
@@ -4322,12 +4418,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4322
4418
|
if (!options.auth?.appId?.trim()) {
|
|
4323
4419
|
throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
|
|
4324
4420
|
}
|
|
4325
|
-
this.uiConfig = options.ui
|
|
4421
|
+
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4326
4422
|
await this.init({
|
|
4327
4423
|
baseUrl,
|
|
4328
4424
|
auth: options.auth,
|
|
4329
4425
|
initialId: options.shareId,
|
|
4330
4426
|
});
|
|
4427
|
+
if (Object.keys(this.uiConfig).length > 0) {
|
|
4428
|
+
await this.mode.setUiConfig(this.uiConfig);
|
|
4429
|
+
}
|
|
4331
4430
|
const content = await this.document.getContent();
|
|
4332
4431
|
this.currentContent = content;
|
|
4333
4432
|
this.slideCount = content.slides.length;
|
|
@@ -4504,6 +4603,7 @@ exports.EMBED_ERROR_CODES = EMBED_ERROR_CODES;
|
|
|
4504
4603
|
exports.EmbeddedEditor = EmbeddedEditor;
|
|
4505
4604
|
exports.EmbeddedPresentation = EmbeddedPresentation;
|
|
4506
4605
|
exports.VERSION = VERSION;
|
|
4606
|
+
exports.convertToLatest = convertToLatest;
|
|
4507
4607
|
exports.create = create;
|
|
4508
4608
|
exports.createEditor = createEditor;
|
|
4509
4609
|
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.7.0';
|
|
3899
3980
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3900
3981
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3901
3982
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4178,12 +4259,27 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4178
4259
|
super(container, 'presentation');
|
|
4179
4260
|
this.currentSlideIndex = 0;
|
|
4180
4261
|
this.slideCount = 0;
|
|
4262
|
+
this.uiConfig = {};
|
|
4263
|
+
this.mode = {
|
|
4264
|
+
getUiConfig: () => ({ ...this.uiConfig }),
|
|
4265
|
+
setUiConfig: async (config) => {
|
|
4266
|
+
await this.post('setUiConfig', { config });
|
|
4267
|
+
this.uiConfig = {
|
|
4268
|
+
...this.uiConfig,
|
|
4269
|
+
...config,
|
|
4270
|
+
};
|
|
4271
|
+
},
|
|
4272
|
+
};
|
|
4181
4273
|
}
|
|
4182
4274
|
async initialize(options = {}, baseUrl) {
|
|
4275
|
+
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4183
4276
|
await this.init({
|
|
4184
4277
|
baseUrl,
|
|
4185
4278
|
initialId: options.shareId,
|
|
4186
4279
|
});
|
|
4280
|
+
if (Object.keys(this.uiConfig).length > 0) {
|
|
4281
|
+
await this.mode.setUiConfig(this.uiConfig);
|
|
4282
|
+
}
|
|
4187
4283
|
}
|
|
4188
4284
|
acceptsEventMessage() {
|
|
4189
4285
|
return false;
|
|
@@ -4320,12 +4416,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4320
4416
|
if (!options.auth?.appId?.trim()) {
|
|
4321
4417
|
throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
|
|
4322
4418
|
}
|
|
4323
|
-
this.uiConfig = options.ui
|
|
4419
|
+
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4324
4420
|
await this.init({
|
|
4325
4421
|
baseUrl,
|
|
4326
4422
|
auth: options.auth,
|
|
4327
4423
|
initialId: options.shareId,
|
|
4328
4424
|
});
|
|
4425
|
+
if (Object.keys(this.uiConfig).length > 0) {
|
|
4426
|
+
await this.mode.setUiConfig(this.uiConfig);
|
|
4427
|
+
}
|
|
4329
4428
|
const content = await this.document.getContent();
|
|
4330
4429
|
this.currentContent = content;
|
|
4331
4430
|
this.slideCount = content.slides.length;
|
|
@@ -4496,4 +4595,4 @@ async function createPresentation(container, options = {}) {
|
|
|
4496
4595
|
return createPresentationInstance(container, options);
|
|
4497
4596
|
}
|
|
4498
4597
|
|
|
4499
|
-
export { AlgeoError, AlgeoSdk, EMBED_ERROR_CODES, EmbeddedEditor, EmbeddedPresentation, VERSION, create, createEditor, createPresentation };
|
|
4598
|
+
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.7.0';
|
|
3905
3986
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3906
3987
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3907
3988
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4184,12 +4265,27 @@
|
|
|
4184
4265
|
super(container, 'presentation');
|
|
4185
4266
|
this.currentSlideIndex = 0;
|
|
4186
4267
|
this.slideCount = 0;
|
|
4268
|
+
this.uiConfig = {};
|
|
4269
|
+
this.mode = {
|
|
4270
|
+
getUiConfig: () => ({ ...this.uiConfig }),
|
|
4271
|
+
setUiConfig: async (config) => {
|
|
4272
|
+
await this.post('setUiConfig', { config });
|
|
4273
|
+
this.uiConfig = {
|
|
4274
|
+
...this.uiConfig,
|
|
4275
|
+
...config,
|
|
4276
|
+
};
|
|
4277
|
+
},
|
|
4278
|
+
};
|
|
4187
4279
|
}
|
|
4188
4280
|
async initialize(options = {}, baseUrl) {
|
|
4281
|
+
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4189
4282
|
await this.init({
|
|
4190
4283
|
baseUrl,
|
|
4191
4284
|
initialId: options.shareId,
|
|
4192
4285
|
});
|
|
4286
|
+
if (Object.keys(this.uiConfig).length > 0) {
|
|
4287
|
+
await this.mode.setUiConfig(this.uiConfig);
|
|
4288
|
+
}
|
|
4193
4289
|
}
|
|
4194
4290
|
acceptsEventMessage() {
|
|
4195
4291
|
return false;
|
|
@@ -4326,12 +4422,15 @@
|
|
|
4326
4422
|
if (!options.auth?.appId?.trim()) {
|
|
4327
4423
|
throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
|
|
4328
4424
|
}
|
|
4329
|
-
this.uiConfig = options.ui
|
|
4425
|
+
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4330
4426
|
await this.init({
|
|
4331
4427
|
baseUrl,
|
|
4332
4428
|
auth: options.auth,
|
|
4333
4429
|
initialId: options.shareId,
|
|
4334
4430
|
});
|
|
4431
|
+
if (Object.keys(this.uiConfig).length > 0) {
|
|
4432
|
+
await this.mode.setUiConfig(this.uiConfig);
|
|
4433
|
+
}
|
|
4335
4434
|
const content = await this.document.getContent();
|
|
4336
4435
|
this.currentContent = content;
|
|
4337
4436
|
this.slideCount = content.slides.length;
|
|
@@ -4508,6 +4607,7 @@
|
|
|
4508
4607
|
exports.EmbeddedEditor = EmbeddedEditor;
|
|
4509
4608
|
exports.EmbeddedPresentation = EmbeddedPresentation;
|
|
4510
4609
|
exports.VERSION = VERSION;
|
|
4610
|
+
exports.convertToLatest = convertToLatest;
|
|
4511
4611
|
exports.create = create;
|
|
4512
4612
|
exports.createEditor = createEditor;
|
|
4513
4613
|
exports.createPresentation = createPresentation;
|
|
@@ -1,17 +1,19 @@
|
|
|
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 PresentationModeApi, type ReplResult, type SwitchSlideResult } from './shared';
|
|
3
3
|
export declare class EmbeddedPresentation extends EmbeddedTarget<EmbeddedPresentationEventMap, EmbeddedPresentationEventName, EmbeddedPresentationEventListenerMap> {
|
|
4
|
+
readonly mode: PresentationModeApi;
|
|
4
5
|
private currentContent?;
|
|
5
6
|
private currentSlideIndex;
|
|
6
7
|
private slideCount;
|
|
7
8
|
private whitelistError?;
|
|
9
|
+
private uiConfig;
|
|
8
10
|
constructor(container: HTMLElement);
|
|
9
11
|
initialize(options?: AlgeoPresentationCreateOptions, baseUrl?: string): Promise<void>;
|
|
10
12
|
protected acceptsEventMessage(): boolean;
|
|
11
13
|
setWhitelistError(error: AlgeoError): void;
|
|
12
14
|
private ensureWhitelistAccess;
|
|
13
15
|
loadShareById(id: string): Promise<LoadShareByIdResult>;
|
|
14
|
-
loadFile(content:
|
|
16
|
+
loadFile(content: FileContentLatest): Promise<LoadFileResult>;
|
|
15
17
|
switchSlide(index: number): Promise<SwitchSlideResult>;
|
|
16
18
|
getSlideCount(): Promise<GetSlideCountResult>;
|
|
17
19
|
repl(command: string): Promise<ReplResult>;
|
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, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, 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 {
|
|
@@ -23,6 +23,10 @@ export interface AlgeoEditorUiConfig {
|
|
|
23
23
|
toolboxPanel?: boolean;
|
|
24
24
|
algebraPanel?: boolean;
|
|
25
25
|
docPanel?: boolean;
|
|
26
|
+
helpEntry?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface AlgeoPresentationUiConfig {
|
|
29
|
+
logo?: boolean;
|
|
26
30
|
}
|
|
27
31
|
export type AlgeoEditorSaveResult = {
|
|
28
32
|
status: 'success';
|
|
@@ -33,12 +37,13 @@ export type AlgeoEditorSaveResult = {
|
|
|
33
37
|
export interface AlgeoEditorCreateOptions {
|
|
34
38
|
auth?: AlgeoEditorAuthOptions;
|
|
35
39
|
shareId?: string;
|
|
36
|
-
initialContent?:
|
|
40
|
+
initialContent?: FileContentLatest;
|
|
37
41
|
ui?: AlgeoEditorUiConfig;
|
|
38
42
|
}
|
|
39
43
|
export interface AlgeoPresentationCreateOptions {
|
|
40
44
|
appId?: string;
|
|
41
45
|
shareId?: string;
|
|
46
|
+
ui?: AlgeoPresentationUiConfig;
|
|
42
47
|
}
|
|
43
48
|
export type AlgeoCreateOptions = {
|
|
44
49
|
baseUrl?: string;
|
|
@@ -57,7 +62,7 @@ export interface ReadyEvent {
|
|
|
57
62
|
export interface ContentChangeEvent {
|
|
58
63
|
type: 'contentChange';
|
|
59
64
|
source: 'loadContent' | 'loadFile' | 'loadShareById' | 'initialContent' | 'user';
|
|
60
|
-
content?:
|
|
65
|
+
content?: FileContentLatest;
|
|
61
66
|
shareId?: string;
|
|
62
67
|
}
|
|
63
68
|
export interface SlideChangeEvent {
|
|
@@ -66,19 +71,19 @@ export interface SlideChangeEvent {
|
|
|
66
71
|
}
|
|
67
72
|
export interface SaveRequestEvent {
|
|
68
73
|
type: 'save';
|
|
69
|
-
content:
|
|
74
|
+
content: FileContentLatest;
|
|
70
75
|
stage: 'request';
|
|
71
76
|
}
|
|
72
77
|
export interface SaveSuccessEvent {
|
|
73
78
|
type: 'save';
|
|
74
|
-
content:
|
|
79
|
+
content: FileContentLatest;
|
|
75
80
|
stage: 'success';
|
|
76
81
|
}
|
|
77
82
|
export type SaveEvent = SaveRequestEvent | SaveSuccessEvent;
|
|
78
83
|
export interface SaveRequestMessage {
|
|
79
84
|
type: 'save';
|
|
80
85
|
requestId: string;
|
|
81
|
-
content:
|
|
86
|
+
content: FileContentLatest;
|
|
82
87
|
}
|
|
83
88
|
export interface EmbeddedEditorEventMap {
|
|
84
89
|
ready: ReadyEvent;
|
|
@@ -138,7 +143,7 @@ export interface ExportSlideImageResult {
|
|
|
138
143
|
images: ExportedSlideImage[];
|
|
139
144
|
}
|
|
140
145
|
export interface GetContentResult {
|
|
141
|
-
content:
|
|
146
|
+
content: FileContentLatest;
|
|
142
147
|
}
|
|
143
148
|
export interface GetHistoryStateResult {
|
|
144
149
|
count: number;
|
|
@@ -147,8 +152,8 @@ export interface GetHistoryStateResult {
|
|
|
147
152
|
canRedo: boolean;
|
|
148
153
|
}
|
|
149
154
|
export interface DocumentApi {
|
|
150
|
-
loadContent(content:
|
|
151
|
-
getContent(): Promise<
|
|
155
|
+
loadContent(content: FileContentLatest): Promise<void>;
|
|
156
|
+
getContent(): Promise<FileContentLatest>;
|
|
152
157
|
}
|
|
153
158
|
export interface SlidesApi {
|
|
154
159
|
getCount(): number;
|
|
@@ -175,6 +180,10 @@ export interface ModeApi {
|
|
|
175
180
|
getUiConfig(): AlgeoEditorUiConfig;
|
|
176
181
|
setUiConfig(config: Partial<AlgeoEditorUiConfig>): Promise<void>;
|
|
177
182
|
}
|
|
183
|
+
export interface PresentationModeApi {
|
|
184
|
+
getUiConfig(): AlgeoPresentationUiConfig;
|
|
185
|
+
setUiConfig(config: Partial<AlgeoPresentationUiConfig>): Promise<void>;
|
|
186
|
+
}
|
|
178
187
|
export declare function generateRequestId(): string;
|
|
179
188
|
export declare function isResponseMessage(msg: unknown): msg is EmbedResponseMessage;
|
|
180
189
|
export declare function isReadyMessage(msg: unknown): msg is EmbedReadyMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dajiaoai/algeo-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
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
|
}
|