@dajiaoai/algeo-sdk 2.11.0 → 2.12.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 +82 -1
- package/dist/algeo-sdk.cjs.js +41 -24
- package/dist/algeo-sdk.esm.js +41 -24
- package/dist/algeo-sdk.umd.js +41 -24
- package/dist/index.d.ts +1 -1
- package/dist/shared.d.ts +55 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
|
|
4
4
|
|
|
5
|
+
## 交流与支持
|
|
6
|
+
|
|
7
|
+
欢迎扫描下方二维码加入微信群,与我们交流 SDK 接入问题、使用反馈和功能建议。
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
5
11
|
## 安装
|
|
6
12
|
|
|
7
13
|
### npm
|
|
@@ -309,6 +315,7 @@ type AlgeoCreateOptions =
|
|
|
309
315
|
| `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
|
|
310
316
|
| `initialContent` | `FileContentLatest` | - | 初始化后自动注入的文件内容 |
|
|
311
317
|
| `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
|
|
318
|
+
| `fonts` | `AlgeoFontConfig` | - | 字体资源、字体选择器列表及默认字体配置 |
|
|
312
319
|
|
|
313
320
|
**AlgeoEditorUiConfig:**
|
|
314
321
|
|
|
@@ -329,6 +336,7 @@ type AlgeoCreateOptions =
|
|
|
329
336
|
| `auth` | `{ appId: string }` | - | 演示模式鉴权参数,`appId` 用于路由及白名单校验 |
|
|
330
337
|
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/embed/present/:appId/:id` |
|
|
331
338
|
| `ui` | `Partial<AlgeoPresentationUiConfig>` | - | 演示模式 UI 配置 |
|
|
339
|
+
| `fonts` | `AlgeoFontConfig` | - | 字体资源及默认字体配置 |
|
|
332
340
|
|
|
333
341
|
**AlgeoPresentationUiConfig:**
|
|
334
342
|
|
|
@@ -339,6 +347,58 @@ type AlgeoCreateOptions =
|
|
|
339
347
|
| `pencilToolbar` | `boolean` | `true` | 是否展示教具栏 |
|
|
340
348
|
| `zoomControl` | `boolean` | `true` | 是否展示缩放栏 |
|
|
341
349
|
|
|
350
|
+
**AlgeoFontConfig:**
|
|
351
|
+
|
|
352
|
+
编辑和演示模式使用同一套字体协议。SDK 在 iframe ready 后、其他初始化操作前发送字体配置。通常使用 URL 加载字体;字体 URL 无法满足跨域要求时,可以传入 base64。
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
interface AlgeoFontConfig {
|
|
356
|
+
resources?: AlgeoFontResource[];
|
|
357
|
+
catalog?: AlgeoFontOption[];
|
|
358
|
+
defaultFont?: string;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface AlgeoFontResource {
|
|
362
|
+
key: string;
|
|
363
|
+
source:
|
|
364
|
+
| { type: 'url'; url: string; format?: AlgeoFontFormat }
|
|
365
|
+
| {
|
|
366
|
+
type: 'base64';
|
|
367
|
+
data: string;
|
|
368
|
+
mimeType?: string;
|
|
369
|
+
format?: AlgeoFontFormat;
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
interface AlgeoFontOption {
|
|
374
|
+
key: string;
|
|
375
|
+
name: string;
|
|
376
|
+
type?: 'custom' | 'system';
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
`key` 同时作为 FontFace family、CSS `font-family` 和文档字体标识。字重、字号、斜体等属于文档排版内容,不在字体配置中传递。
|
|
381
|
+
|
|
382
|
+
```javascript
|
|
383
|
+
const fonts = {
|
|
384
|
+
resources: [
|
|
385
|
+
{
|
|
386
|
+
key: 'brand-sans',
|
|
387
|
+
source: {
|
|
388
|
+
type: 'url',
|
|
389
|
+
url: 'https://cdn.example.com/brand-sans.woff2',
|
|
390
|
+
format: 'woff2',
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
catalog: [
|
|
395
|
+
{ key: 'brand-sans', name: '品牌字体' },
|
|
396
|
+
{ key: 'sans-serif', name: '系统非衬线字体', type: 'system' },
|
|
397
|
+
],
|
|
398
|
+
defaultFont: 'brand-sans',
|
|
399
|
+
};
|
|
400
|
+
```
|
|
401
|
+
|
|
342
402
|
默认路径规则:
|
|
343
403
|
|
|
344
404
|
- `mode: 'presentation'` -> `/embed/present/:appId`,若传 `presentation.shareId` 则生成 `/embed/present/:appId/:id`
|
|
@@ -522,7 +582,7 @@ interface FileContent {
|
|
|
522
582
|
|
|
523
583
|
所有模式均读取文件中的 `camera.scale`;文件未提供时默认为 `50`。`slideIndices` 使用从 `1` 开始的画板索引,省略时导出全部画板。
|
|
524
584
|
|
|
525
|
-
|
|
585
|
+
适合精确指定导出视野时使用 `view`。2D 画板传 `viewBounds`:
|
|
526
586
|
|
|
527
587
|
```ts
|
|
528
588
|
const images = await editor.slides.exportImage({
|
|
@@ -536,6 +596,27 @@ const images = await editor.slides.exportImage({
|
|
|
536
596
|
|
|
537
597
|
`viewBounds` 的位置和宽高均为世界坐标,`scale` 为可选的相机缩放比例。省略 `scale` 时使用目标画板文件中的 `camera.scale`。
|
|
538
598
|
|
|
599
|
+
3D 画板传同级的 `viewCamera3d`。其中 `width`、`height` 必填;`width`、`height` 为世界坐标视野范围。`offset`、`yaw`、`pitch`、`scale` 可选且省略时沿用文件相机;投影方式与斜投影参数始终沿用画板文件。
|
|
600
|
+
|
|
601
|
+
```ts
|
|
602
|
+
const images = await editor.slides.exportImage({
|
|
603
|
+
mode: 'view',
|
|
604
|
+
slideIndices: [2],
|
|
605
|
+
format: 'png',
|
|
606
|
+
viewCamera3d: {
|
|
607
|
+
offset: [0, 0, 0],
|
|
608
|
+
yaw: Math.PI / 4,
|
|
609
|
+
pitch: Math.PI / 6,
|
|
610
|
+
scale: 0.2,
|
|
611
|
+
width: 12,
|
|
612
|
+
height: 8,
|
|
613
|
+
},
|
|
614
|
+
pixelRatio: 2,
|
|
615
|
+
});
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
一个 `view` 请求可以同时传 `viewBounds` 与 `viewCamera3d`,用于批量导出混合 2D/3D 画板;每张画板自动读取适用字段。2D 画板未提供 `viewBounds`、或 3D 画板未提供 `viewCamera3d` 时会报错。3D 仅支持 PNG、JPG;对 3D 画板请求 SVG 会报错。
|
|
619
|
+
|
|
539
620
|
适合完整包住全部内容且不限定最终宽高时使用 `contain`:
|
|
540
621
|
|
|
541
622
|
```ts
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -3865,12 +3865,6 @@ var AlgeoError = class extends Error {
|
|
|
3865
3865
|
this.name = "AlgeoError";
|
|
3866
3866
|
}
|
|
3867
3867
|
};
|
|
3868
|
-
objectType({
|
|
3869
|
-
text: stringType().optional(),
|
|
3870
|
-
images: arrayType(stringType().trim().min(1)).optional(),
|
|
3871
|
-
openPanel: booleanType().optional(),
|
|
3872
|
-
focus: booleanType().optional()
|
|
3873
|
-
}).passthrough();
|
|
3874
3868
|
var openAiChatMessageV1Schema = objectType({
|
|
3875
3869
|
role: stringType(),
|
|
3876
3870
|
content: unionType([
|
|
@@ -3884,23 +3878,9 @@ var openAiChatMessageV1Schema = objectType({
|
|
|
3884
3878
|
name: stringType().optional()
|
|
3885
3879
|
}).passthrough();
|
|
3886
3880
|
objectType({
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
|
|
3891
|
-
]).optional(),
|
|
3892
|
-
previous_response_id: stringType().trim().min(1).optional(),
|
|
3893
|
-
instructions: stringType().optional(),
|
|
3894
|
-
temperature: numberType().min(0).max(2).optional(),
|
|
3895
|
-
max_output_tokens: numberType().int().positive().optional(),
|
|
3896
|
-
metadata: recordType(unknownType()).optional()
|
|
3897
|
-
}).passthrough().superRefine((value, ctx) => {
|
|
3898
|
-
if (!("input" in value) && !("previous_response_id" in value)) {
|
|
3899
|
-
ctx.addIssue({
|
|
3900
|
-
code: ZodIssueCode.custom,
|
|
3901
|
-
message: "input or previous_response_id is required."
|
|
3902
|
-
});
|
|
3903
|
-
}
|
|
3881
|
+
model_id: stringType(),
|
|
3882
|
+
messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
|
|
3883
|
+
extra_openai_params: recordType(unknownType()).optional()
|
|
3904
3884
|
});
|
|
3905
3885
|
objectType({
|
|
3906
3886
|
id: stringType(),
|
|
@@ -4031,7 +4011,7 @@ function convertToLatest(content) {
|
|
|
4031
4011
|
}
|
|
4032
4012
|
|
|
4033
4013
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4034
|
-
const VERSION = '2.
|
|
4014
|
+
const VERSION = '2.12.1';
|
|
4035
4015
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4036
4016
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4037
4017
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4040,6 +4020,31 @@ let requestIdCounter = 0;
|
|
|
4040
4020
|
function generateRequestId() {
|
|
4041
4021
|
return `req-${Date.now()}-${++requestIdCounter}`;
|
|
4042
4022
|
}
|
|
4023
|
+
function validateFontConfig(config) {
|
|
4024
|
+
const resourceKeys = new Set();
|
|
4025
|
+
for (const resource of config.resources ?? []) {
|
|
4026
|
+
const key = resource.key.trim();
|
|
4027
|
+
if (!key) {
|
|
4028
|
+
throw new AlgeoError('fonts.resources[].key 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4029
|
+
}
|
|
4030
|
+
resourceKeys.add(key);
|
|
4031
|
+
}
|
|
4032
|
+
const catalogKeys = new Set();
|
|
4033
|
+
for (const option of config.catalog ?? []) {
|
|
4034
|
+
const key = option.key.trim();
|
|
4035
|
+
if (!key || !option.name.trim()) {
|
|
4036
|
+
throw new AlgeoError('fonts.catalog[] 的 key 和 name 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4037
|
+
}
|
|
4038
|
+
if ((option.type ?? 'custom') === 'custom' && !resourceKeys.has(key)) {
|
|
4039
|
+
throw new AlgeoError(`自定义字体 ${key} 未提供对应的字体资源。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4040
|
+
}
|
|
4041
|
+
catalogKeys.add(key);
|
|
4042
|
+
}
|
|
4043
|
+
const defaultFont = config.defaultFont?.trim();
|
|
4044
|
+
if (defaultFont && config.catalog && !catalogKeys.has(defaultFont)) {
|
|
4045
|
+
throw new AlgeoError(`默认字体 ${defaultFont} 不在 fonts.catalog 中。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4043
4048
|
function isResponseMessage(msg) {
|
|
4044
4049
|
return (typeof msg === 'object' &&
|
|
4045
4050
|
msg !== null &&
|
|
@@ -4422,11 +4427,17 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4422
4427
|
zoomControl: true,
|
|
4423
4428
|
...options.ui,
|
|
4424
4429
|
};
|
|
4430
|
+
if (options.fonts) {
|
|
4431
|
+
validateFontConfig(options.fonts);
|
|
4432
|
+
}
|
|
4425
4433
|
await this.init({
|
|
4426
4434
|
baseUrl,
|
|
4427
4435
|
auth: options.auth,
|
|
4428
4436
|
initialId: options.shareId,
|
|
4429
4437
|
});
|
|
4438
|
+
if (options.fonts) {
|
|
4439
|
+
await this.post('setFontConfig', { config: options.fonts });
|
|
4440
|
+
}
|
|
4430
4441
|
await this.mode.setUiConfig(this.uiConfig);
|
|
4431
4442
|
}
|
|
4432
4443
|
acceptsEventMessage() {
|
|
@@ -4588,11 +4599,17 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4588
4599
|
}
|
|
4589
4600
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4590
4601
|
this.resourceLibrary = options.resourceLibrary;
|
|
4602
|
+
if (options.fonts) {
|
|
4603
|
+
validateFontConfig(options.fonts);
|
|
4604
|
+
}
|
|
4591
4605
|
await this.init({
|
|
4592
4606
|
baseUrl,
|
|
4593
4607
|
auth: options.auth,
|
|
4594
4608
|
initialId: options.shareId,
|
|
4595
4609
|
});
|
|
4610
|
+
if (options.fonts) {
|
|
4611
|
+
await this.post('setFontConfig', { config: options.fonts });
|
|
4612
|
+
}
|
|
4596
4613
|
await this.post('setResourceLibraryAvailability', {
|
|
4597
4614
|
available: Boolean(this.resourceLibrary),
|
|
4598
4615
|
});
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -3863,12 +3863,6 @@ var AlgeoError = class extends Error {
|
|
|
3863
3863
|
this.name = "AlgeoError";
|
|
3864
3864
|
}
|
|
3865
3865
|
};
|
|
3866
|
-
objectType({
|
|
3867
|
-
text: stringType().optional(),
|
|
3868
|
-
images: arrayType(stringType().trim().min(1)).optional(),
|
|
3869
|
-
openPanel: booleanType().optional(),
|
|
3870
|
-
focus: booleanType().optional()
|
|
3871
|
-
}).passthrough();
|
|
3872
3866
|
var openAiChatMessageV1Schema = objectType({
|
|
3873
3867
|
role: stringType(),
|
|
3874
3868
|
content: unionType([
|
|
@@ -3882,23 +3876,9 @@ var openAiChatMessageV1Schema = objectType({
|
|
|
3882
3876
|
name: stringType().optional()
|
|
3883
3877
|
}).passthrough();
|
|
3884
3878
|
objectType({
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
|
|
3889
|
-
]).optional(),
|
|
3890
|
-
previous_response_id: stringType().trim().min(1).optional(),
|
|
3891
|
-
instructions: stringType().optional(),
|
|
3892
|
-
temperature: numberType().min(0).max(2).optional(),
|
|
3893
|
-
max_output_tokens: numberType().int().positive().optional(),
|
|
3894
|
-
metadata: recordType(unknownType()).optional()
|
|
3895
|
-
}).passthrough().superRefine((value, ctx) => {
|
|
3896
|
-
if (!("input" in value) && !("previous_response_id" in value)) {
|
|
3897
|
-
ctx.addIssue({
|
|
3898
|
-
code: ZodIssueCode.custom,
|
|
3899
|
-
message: "input or previous_response_id is required."
|
|
3900
|
-
});
|
|
3901
|
-
}
|
|
3879
|
+
model_id: stringType(),
|
|
3880
|
+
messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
|
|
3881
|
+
extra_openai_params: recordType(unknownType()).optional()
|
|
3902
3882
|
});
|
|
3903
3883
|
objectType({
|
|
3904
3884
|
id: stringType(),
|
|
@@ -4029,7 +4009,7 @@ function convertToLatest(content) {
|
|
|
4029
4009
|
}
|
|
4030
4010
|
|
|
4031
4011
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4032
|
-
const VERSION = '2.
|
|
4012
|
+
const VERSION = '2.12.1';
|
|
4033
4013
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4034
4014
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4035
4015
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4038,6 +4018,31 @@ let requestIdCounter = 0;
|
|
|
4038
4018
|
function generateRequestId() {
|
|
4039
4019
|
return `req-${Date.now()}-${++requestIdCounter}`;
|
|
4040
4020
|
}
|
|
4021
|
+
function validateFontConfig(config) {
|
|
4022
|
+
const resourceKeys = new Set();
|
|
4023
|
+
for (const resource of config.resources ?? []) {
|
|
4024
|
+
const key = resource.key.trim();
|
|
4025
|
+
if (!key) {
|
|
4026
|
+
throw new AlgeoError('fonts.resources[].key 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4027
|
+
}
|
|
4028
|
+
resourceKeys.add(key);
|
|
4029
|
+
}
|
|
4030
|
+
const catalogKeys = new Set();
|
|
4031
|
+
for (const option of config.catalog ?? []) {
|
|
4032
|
+
const key = option.key.trim();
|
|
4033
|
+
if (!key || !option.name.trim()) {
|
|
4034
|
+
throw new AlgeoError('fonts.catalog[] 的 key 和 name 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4035
|
+
}
|
|
4036
|
+
if ((option.type ?? 'custom') === 'custom' && !resourceKeys.has(key)) {
|
|
4037
|
+
throw new AlgeoError(`自定义字体 ${key} 未提供对应的字体资源。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4038
|
+
}
|
|
4039
|
+
catalogKeys.add(key);
|
|
4040
|
+
}
|
|
4041
|
+
const defaultFont = config.defaultFont?.trim();
|
|
4042
|
+
if (defaultFont && config.catalog && !catalogKeys.has(defaultFont)) {
|
|
4043
|
+
throw new AlgeoError(`默认字体 ${defaultFont} 不在 fonts.catalog 中。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4041
4046
|
function isResponseMessage(msg) {
|
|
4042
4047
|
return (typeof msg === 'object' &&
|
|
4043
4048
|
msg !== null &&
|
|
@@ -4420,11 +4425,17 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4420
4425
|
zoomControl: true,
|
|
4421
4426
|
...options.ui,
|
|
4422
4427
|
};
|
|
4428
|
+
if (options.fonts) {
|
|
4429
|
+
validateFontConfig(options.fonts);
|
|
4430
|
+
}
|
|
4423
4431
|
await this.init({
|
|
4424
4432
|
baseUrl,
|
|
4425
4433
|
auth: options.auth,
|
|
4426
4434
|
initialId: options.shareId,
|
|
4427
4435
|
});
|
|
4436
|
+
if (options.fonts) {
|
|
4437
|
+
await this.post('setFontConfig', { config: options.fonts });
|
|
4438
|
+
}
|
|
4428
4439
|
await this.mode.setUiConfig(this.uiConfig);
|
|
4429
4440
|
}
|
|
4430
4441
|
acceptsEventMessage() {
|
|
@@ -4586,11 +4597,17 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4586
4597
|
}
|
|
4587
4598
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4588
4599
|
this.resourceLibrary = options.resourceLibrary;
|
|
4600
|
+
if (options.fonts) {
|
|
4601
|
+
validateFontConfig(options.fonts);
|
|
4602
|
+
}
|
|
4589
4603
|
await this.init({
|
|
4590
4604
|
baseUrl,
|
|
4591
4605
|
auth: options.auth,
|
|
4592
4606
|
initialId: options.shareId,
|
|
4593
4607
|
});
|
|
4608
|
+
if (options.fonts) {
|
|
4609
|
+
await this.post('setFontConfig', { config: options.fonts });
|
|
4610
|
+
}
|
|
4594
4611
|
await this.post('setResourceLibraryAvailability', {
|
|
4595
4612
|
available: Boolean(this.resourceLibrary),
|
|
4596
4613
|
});
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -3869,12 +3869,6 @@
|
|
|
3869
3869
|
this.name = "AlgeoError";
|
|
3870
3870
|
}
|
|
3871
3871
|
};
|
|
3872
|
-
objectType({
|
|
3873
|
-
text: stringType().optional(),
|
|
3874
|
-
images: arrayType(stringType().trim().min(1)).optional(),
|
|
3875
|
-
openPanel: booleanType().optional(),
|
|
3876
|
-
focus: booleanType().optional()
|
|
3877
|
-
}).passthrough();
|
|
3878
3872
|
var openAiChatMessageV1Schema = objectType({
|
|
3879
3873
|
role: stringType(),
|
|
3880
3874
|
content: unionType([
|
|
@@ -3888,23 +3882,9 @@
|
|
|
3888
3882
|
name: stringType().optional()
|
|
3889
3883
|
}).passthrough();
|
|
3890
3884
|
objectType({
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
|
|
3895
|
-
]).optional(),
|
|
3896
|
-
previous_response_id: stringType().trim().min(1).optional(),
|
|
3897
|
-
instructions: stringType().optional(),
|
|
3898
|
-
temperature: numberType().min(0).max(2).optional(),
|
|
3899
|
-
max_output_tokens: numberType().int().positive().optional(),
|
|
3900
|
-
metadata: recordType(unknownType()).optional()
|
|
3901
|
-
}).passthrough().superRefine((value, ctx) => {
|
|
3902
|
-
if (!("input" in value) && !("previous_response_id" in value)) {
|
|
3903
|
-
ctx.addIssue({
|
|
3904
|
-
code: ZodIssueCode.custom,
|
|
3905
|
-
message: "input or previous_response_id is required."
|
|
3906
|
-
});
|
|
3907
|
-
}
|
|
3885
|
+
model_id: stringType(),
|
|
3886
|
+
messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
|
|
3887
|
+
extra_openai_params: recordType(unknownType()).optional()
|
|
3908
3888
|
});
|
|
3909
3889
|
objectType({
|
|
3910
3890
|
id: stringType(),
|
|
@@ -4035,7 +4015,7 @@
|
|
|
4035
4015
|
}
|
|
4036
4016
|
|
|
4037
4017
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4038
|
-
const VERSION = '2.
|
|
4018
|
+
const VERSION = '2.12.1';
|
|
4039
4019
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4040
4020
|
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4041
4021
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4044,6 +4024,31 @@
|
|
|
4044
4024
|
function generateRequestId() {
|
|
4045
4025
|
return `req-${Date.now()}-${++requestIdCounter}`;
|
|
4046
4026
|
}
|
|
4027
|
+
function validateFontConfig(config) {
|
|
4028
|
+
const resourceKeys = new Set();
|
|
4029
|
+
for (const resource of config.resources ?? []) {
|
|
4030
|
+
const key = resource.key.trim();
|
|
4031
|
+
if (!key) {
|
|
4032
|
+
throw new AlgeoError('fonts.resources[].key 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4033
|
+
}
|
|
4034
|
+
resourceKeys.add(key);
|
|
4035
|
+
}
|
|
4036
|
+
const catalogKeys = new Set();
|
|
4037
|
+
for (const option of config.catalog ?? []) {
|
|
4038
|
+
const key = option.key.trim();
|
|
4039
|
+
if (!key || !option.name.trim()) {
|
|
4040
|
+
throw new AlgeoError('fonts.catalog[] 的 key 和 name 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4041
|
+
}
|
|
4042
|
+
if ((option.type ?? 'custom') === 'custom' && !resourceKeys.has(key)) {
|
|
4043
|
+
throw new AlgeoError(`自定义字体 ${key} 未提供对应的字体资源。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4044
|
+
}
|
|
4045
|
+
catalogKeys.add(key);
|
|
4046
|
+
}
|
|
4047
|
+
const defaultFont = config.defaultFont?.trim();
|
|
4048
|
+
if (defaultFont && config.catalog && !catalogKeys.has(defaultFont)) {
|
|
4049
|
+
throw new AlgeoError(`默认字体 ${defaultFont} 不在 fonts.catalog 中。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4047
4052
|
function isResponseMessage(msg) {
|
|
4048
4053
|
return (typeof msg === 'object' &&
|
|
4049
4054
|
msg !== null &&
|
|
@@ -4426,11 +4431,17 @@
|
|
|
4426
4431
|
zoomControl: true,
|
|
4427
4432
|
...options.ui,
|
|
4428
4433
|
};
|
|
4434
|
+
if (options.fonts) {
|
|
4435
|
+
validateFontConfig(options.fonts);
|
|
4436
|
+
}
|
|
4429
4437
|
await this.init({
|
|
4430
4438
|
baseUrl,
|
|
4431
4439
|
auth: options.auth,
|
|
4432
4440
|
initialId: options.shareId,
|
|
4433
4441
|
});
|
|
4442
|
+
if (options.fonts) {
|
|
4443
|
+
await this.post('setFontConfig', { config: options.fonts });
|
|
4444
|
+
}
|
|
4434
4445
|
await this.mode.setUiConfig(this.uiConfig);
|
|
4435
4446
|
}
|
|
4436
4447
|
acceptsEventMessage() {
|
|
@@ -4592,11 +4603,17 @@
|
|
|
4592
4603
|
}
|
|
4593
4604
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4594
4605
|
this.resourceLibrary = options.resourceLibrary;
|
|
4606
|
+
if (options.fonts) {
|
|
4607
|
+
validateFontConfig(options.fonts);
|
|
4608
|
+
}
|
|
4595
4609
|
await this.init({
|
|
4596
4610
|
baseUrl,
|
|
4597
4611
|
auth: options.auth,
|
|
4598
4612
|
initialId: options.shareId,
|
|
4599
4613
|
});
|
|
4614
|
+
if (options.fonts) {
|
|
4615
|
+
await this.post('setFontConfig', { config: options.fonts });
|
|
4616
|
+
}
|
|
4600
4617
|
await this.post('setResourceLibraryAvailability', {
|
|
4601
4618
|
available: Boolean(this.resourceLibrary),
|
|
4602
4619
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
|
|
2
2
|
export type { FileContentLatest } from '@dajiaoai/algeo-protocol';
|
|
3
3
|
export { convertToLatest } from '@dajiaoai/algeo-protocol';
|
|
4
|
-
export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBounds, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
4
|
+
export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBounds, ExportViewCamera3D, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
5
5
|
export { EmbeddedPresentation } from './embedded-presentation';
|
|
6
6
|
export { EmbeddedEditor } from './embedded-editor';
|
|
7
7
|
export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
|
package/dist/shared.d.ts
CHANGED
|
@@ -33,6 +33,39 @@ export interface AlgeoPresentationUiConfig {
|
|
|
33
33
|
pencilToolbar?: boolean;
|
|
34
34
|
zoomControl?: boolean;
|
|
35
35
|
}
|
|
36
|
+
export type AlgeoFontFormat = 'woff2' | 'woff' | 'truetype' | 'opentype';
|
|
37
|
+
export type AlgeoFontSource = {
|
|
38
|
+
type: 'url';
|
|
39
|
+
url: string;
|
|
40
|
+
format?: AlgeoFontFormat;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'base64';
|
|
43
|
+
/** 支持纯 base64 字符串或完整的 data URL。 */
|
|
44
|
+
data: string;
|
|
45
|
+
mimeType?: string;
|
|
46
|
+
format?: AlgeoFontFormat;
|
|
47
|
+
};
|
|
48
|
+
export interface AlgeoFontResource {
|
|
49
|
+
/** 字体标识,同时作为 FontFace family、CSS font-family 和文档字体标识。 */
|
|
50
|
+
key: string;
|
|
51
|
+
source: AlgeoFontSource;
|
|
52
|
+
}
|
|
53
|
+
export interface AlgeoFontOption {
|
|
54
|
+
/** 对应自定义字体资源的 key,或系统 font-family。 */
|
|
55
|
+
key: string;
|
|
56
|
+
/** 字体选择器中的展示名称。 */
|
|
57
|
+
name: string;
|
|
58
|
+
/** 默认 custom;system 类型不要求存在对应字体资源。 */
|
|
59
|
+
type?: 'custom' | 'system';
|
|
60
|
+
}
|
|
61
|
+
export interface AlgeoFontConfig {
|
|
62
|
+
/** 需要在内嵌页面中加载并注册的字体文件。 */
|
|
63
|
+
resources?: AlgeoFontResource[];
|
|
64
|
+
/** 编辑器字体选择器中展示的字体及顺序。 */
|
|
65
|
+
catalog?: AlgeoFontOption[];
|
|
66
|
+
/** 新建文本使用的默认字体 key。 */
|
|
67
|
+
defaultFont?: string;
|
|
68
|
+
}
|
|
36
69
|
export type AlgeoEditorSaveResult = {
|
|
37
70
|
status: 'success';
|
|
38
71
|
} | {
|
|
@@ -44,6 +77,8 @@ export interface AlgeoEditorCreateOptions {
|
|
|
44
77
|
shareId?: string;
|
|
45
78
|
initialContent?: FileContentLatest;
|
|
46
79
|
ui?: AlgeoEditorUiConfig;
|
|
80
|
+
/** 字体资源、字体选择器列表及默认字体配置。 */
|
|
81
|
+
fonts?: AlgeoFontConfig;
|
|
47
82
|
/** 接入方提供的只读图片资源库。 */
|
|
48
83
|
resourceLibrary?: ResourceLibraryProvider;
|
|
49
84
|
}
|
|
@@ -85,6 +120,8 @@ export interface AlgeoPresentationCreateOptions {
|
|
|
85
120
|
auth?: AlgeoEditorAuthOptions;
|
|
86
121
|
shareId?: string;
|
|
87
122
|
ui?: AlgeoPresentationUiConfig;
|
|
123
|
+
/** 字体资源及默认字体配置。 */
|
|
124
|
+
fonts?: AlgeoFontConfig;
|
|
88
125
|
}
|
|
89
126
|
export type AlgeoCreateOptions = {
|
|
90
127
|
baseUrl?: string;
|
|
@@ -225,6 +262,19 @@ export interface ExportViewBounds {
|
|
|
225
262
|
*/
|
|
226
263
|
scale?: number;
|
|
227
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* 3D 画板的导出相机覆盖项。未提供的字段沿用画板当前 camera3d。
|
|
267
|
+
*/
|
|
268
|
+
export interface ExportViewCamera3D {
|
|
269
|
+
offset?: [number, number, number];
|
|
270
|
+
pitch?: number;
|
|
271
|
+
yaw?: number;
|
|
272
|
+
scale?: number;
|
|
273
|
+
/** 3D 导出视野的世界坐标宽度。 */
|
|
274
|
+
width: number;
|
|
275
|
+
/** 3D 导出视野的世界坐标高度。 */
|
|
276
|
+
height: number;
|
|
277
|
+
}
|
|
228
278
|
/** 导出留白,单位为输出像素 px。 */
|
|
229
279
|
export type ExportPadding = number | {
|
|
230
280
|
horizontal?: number;
|
|
@@ -255,7 +305,10 @@ export interface ExportImageSizeMode extends ExportImageBaseOptions {
|
|
|
255
305
|
*/
|
|
256
306
|
export interface ExportImageViewMode extends ExportImageBaseOptions {
|
|
257
307
|
mode: 'view';
|
|
258
|
-
|
|
308
|
+
/** 2D 画板的世界坐标视野。 */
|
|
309
|
+
viewBounds?: ExportViewBounds;
|
|
310
|
+
/** 3D 画板的相机视野。 */
|
|
311
|
+
viewCamera3d?: ExportViewCamera3D;
|
|
259
312
|
pixelRatio?: number;
|
|
260
313
|
}
|
|
261
314
|
/**
|
|
@@ -373,6 +426,7 @@ export interface PresentationModeApi {
|
|
|
373
426
|
setMasterTemplate(template: string): Promise<SetMasterTemplateResult>;
|
|
374
427
|
}
|
|
375
428
|
export declare function generateRequestId(): string;
|
|
429
|
+
export declare function validateFontConfig(config: AlgeoFontConfig): void;
|
|
376
430
|
export declare function isResponseMessage(msg: unknown): msg is EmbedResponseMessage;
|
|
377
431
|
export declare function isReadyMessage(msg: unknown): msg is EmbedReadyMessage;
|
|
378
432
|
export type EmbedEventMessage = ContentChangeEvent | SlideChangeEvent | SaveSuccessEvent | AiCancelEvent;
|