@dajiaoai/algeo-sdk 2.8.1 → 2.9.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 +138 -46
- package/dist/algeo-sdk.cjs.js +66 -2
- package/dist/algeo-sdk.esm.js +66 -2
- package/dist/algeo-sdk.umd.js +66 -2
- package/dist/embedded-target.d.ts +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/shared.d.ts +99 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,29 +9,6 @@
|
|
|
9
9
|
```bash
|
|
10
10
|
# 安装最新版本
|
|
11
11
|
npm install @dajiaoai/algeo-sdk
|
|
12
|
-
|
|
13
|
-
# 安装指定主次版本
|
|
14
|
-
npm install @dajiaoai/algeo-sdk@2.7.0
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
在 `package.json` 中:
|
|
18
|
-
|
|
19
|
-
```json
|
|
20
|
-
{
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@dajiaoai/algeo-sdk": "~2.7.0"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
或使用 semver 范围:
|
|
28
|
-
|
|
29
|
-
```json
|
|
30
|
-
{
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@dajiaoai/algeo-sdk": "^2.7.0" // 兼容 2.x 的更新(升级范围更大)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
12
|
```
|
|
36
13
|
|
|
37
14
|
### CDN
|
|
@@ -39,19 +16,15 @@ npm install @dajiaoai/algeo-sdk
|
|
|
39
16
|
**unpkg**:
|
|
40
17
|
|
|
41
18
|
```html
|
|
42
|
-
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.7.0/dist/algeo-sdk.umd.min.js"></script>
|
|
43
19
|
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.min.js"></script>
|
|
44
20
|
```
|
|
45
21
|
|
|
46
22
|
**jsDelivr**:
|
|
47
23
|
|
|
48
24
|
```html
|
|
49
|
-
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.7.0/dist/algeo-sdk.umd.min.js"></script>
|
|
50
25
|
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.min.js"></script>
|
|
51
26
|
```
|
|
52
27
|
|
|
53
|
-
> 生产环境建议锁定到 **2.7.x**(如 `~2.7.0`),在兼容边界内自动接收修复版本。
|
|
54
|
-
|
|
55
28
|
## 使用方式
|
|
56
29
|
|
|
57
30
|
### 方式一:演示模式
|
|
@@ -77,6 +50,9 @@ presentation
|
|
|
77
50
|
.getSlideCount()
|
|
78
51
|
.then(({ count }) => console.log('画板数量:', count));
|
|
79
52
|
presentation.switchSlide(1).then(() => console.log('切换画板'));
|
|
53
|
+
presentation.mode
|
|
54
|
+
.setMasterTemplate(masterTemplateContent)
|
|
55
|
+
.then(() => console.log('母版风格已更新'));
|
|
80
56
|
|
|
81
57
|
// 销毁
|
|
82
58
|
// presentation.destroy();
|
|
@@ -134,6 +110,8 @@ editor.on('slideChange', (event) => {
|
|
|
134
110
|
console.log('用户切换后的最新画板索引', event.index);
|
|
135
111
|
});
|
|
136
112
|
|
|
113
|
+
await editor.mode.setMasterTemplate(masterTemplateContent);
|
|
114
|
+
|
|
137
115
|
editor.on('save', async (event) => {
|
|
138
116
|
if (event.stage === 'request') {
|
|
139
117
|
const response = await fetch('/api/geometry-doc/save', {
|
|
@@ -185,6 +163,15 @@ editor.on('aiRequest', async ({ payload, signal }) => {
|
|
|
185
163
|
editor.on('aiCancel', ({ runId, reason }) => {
|
|
186
164
|
console.log('用户取消 AI 生成', runId, reason);
|
|
187
165
|
});
|
|
166
|
+
|
|
167
|
+
await editor.ai.setDraft({
|
|
168
|
+
text: '请根据这张图生成一道几何题',
|
|
169
|
+
images: ['https://example.com/figure.png'],
|
|
170
|
+
openPanel: true,
|
|
171
|
+
focus: true,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await editor.ai.clearDraft();
|
|
188
175
|
```
|
|
189
176
|
|
|
190
177
|
编辑器内嵌页点击保存按钮时,会触发 `editor.on('save', listener)` 的请求阶段监听器。只有宿主返回 `{ status: 'success' }` 后,iframe 才会展示成功态,并向外触发 `save` 的成功阶段事件。
|
|
@@ -358,10 +345,21 @@ const presentation = await create(container, {
|
|
|
358
345
|
|
|
359
346
|
##### `presentation.mode`
|
|
360
347
|
|
|
361
|
-
| 方法
|
|
362
|
-
|
|
|
363
|
-
| `getUiConfig()`
|
|
364
|
-
| `setUiConfig(config)`
|
|
348
|
+
| 方法 | 说明 |
|
|
349
|
+
| ----------------------------- | ---------------- |
|
|
350
|
+
| `getUiConfig()` | 获取当前 UI 配置 |
|
|
351
|
+
| `setUiConfig(config)` | 更新 UI 配置 |
|
|
352
|
+
| `setMasterTemplate(template)` | 设置母版风格 |
|
|
353
|
+
|
|
354
|
+
##### `presentation.resize(): void`
|
|
355
|
+
|
|
356
|
+
主动通知内嵌页重新测量容器尺寸并重绘画布。
|
|
357
|
+
|
|
358
|
+
调用后会通过 `postMessage` 向 iframe 发送一条 `{ type: 'resize' }` 消息;内嵌页(如 studio-web 的 `embedBridge`)收到后会自行测量容器尺寸并同步重绘画布一帧,使画布采用恢复可见后的真实尺寸。
|
|
359
|
+
|
|
360
|
+
SDK 内部已通过 `ResizeObserver` 在容器从隐藏(`display:none`,尺寸为 0)变为可见时**自动触发一次** `resize`;当宿主以其它方式改变容器尺寸(如布局切换、面板展开)而未触发该场景时,可手动调用此方法强制刷新。
|
|
361
|
+
|
|
362
|
+
---
|
|
365
363
|
|
|
366
364
|
##### `presentation.loadShareById(id: string): Promise<LoadShareByIdResult>`
|
|
367
365
|
|
|
@@ -466,17 +464,100 @@ interface FileContent {
|
|
|
466
464
|
|
|
467
465
|
#### `editor.slides`
|
|
468
466
|
|
|
469
|
-
| 方法 | 说明
|
|
470
|
-
| -------------------------------- |
|
|
471
|
-
| `getCount()` | 获取当前已知画板数量
|
|
472
|
-
| `getCurrentIndex()` | 获取当前已知画板索引
|
|
473
|
-
| `switchTo(index)` | 切换画板
|
|
474
|
-
| `add()` | 在末尾新增画板
|
|
475
|
-
| `addAt(index)` | 在指定位置新增画板
|
|
476
|
-
| `remove(index)` | 删除指定画板
|
|
477
|
-
| `duplicate(index, targetIndex?)` | 复制画板
|
|
478
|
-
| `reorder(fromIndex, toIndex)` | 重排画板
|
|
479
|
-
| `exportImage(options
|
|
467
|
+
| 方法 | 说明 |
|
|
468
|
+
| -------------------------------- | ------------------------------------------------------------------------------------ |
|
|
469
|
+
| `getCount()` | 获取当前已知画板数量 |
|
|
470
|
+
| `getCurrentIndex()` | 获取当前已知画板索引 |
|
|
471
|
+
| `switchTo(index)` | 切换画板 |
|
|
472
|
+
| `add()` | 在末尾新增画板 |
|
|
473
|
+
| `addAt(index)` | 在指定位置新增画板 |
|
|
474
|
+
| `remove(index)` | 删除指定画板 |
|
|
475
|
+
| `duplicate(index, targetIndex?)` | 复制画板 |
|
|
476
|
+
| `reorder(fromIndex, toIndex)` | 重排画板 |
|
|
477
|
+
| `exportImage(options)` | 按 `view` / `contain` / `size` 模式导出 PNG、JPG 或 SVG,返回 `ExportedSlideImage[]` |
|
|
478
|
+
| `exportLatex(options?)` | 将画板导出为 LaTeX/TikZ 源码,返回 `ExportedLatex[]` |
|
|
479
|
+
|
|
480
|
+
##### `editor.slides.exportImage(options)`
|
|
481
|
+
|
|
482
|
+
所有模式均读取文件中的 `camera.scale`;文件未提供时默认为 `50`。`slideIndices` 使用从 `1` 开始的画板索引,省略时导出全部画板。
|
|
483
|
+
|
|
484
|
+
适合精确导出一个世界坐标视野时使用 `view`:
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
const images = await editor.slides.exportImage({
|
|
488
|
+
mode: 'view',
|
|
489
|
+
slideIndices: [1],
|
|
490
|
+
format: 'png',
|
|
491
|
+
viewBounds: { x: -5, y: -5, width: 10, height: 10 },
|
|
492
|
+
pixelRatio: 2,
|
|
493
|
+
});
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
`viewBounds` 的位置和宽高均为世界坐标。输出尺寸为 `viewBounds × camera.scale × pixelRatio`。
|
|
497
|
+
|
|
498
|
+
适合完整包住全部内容且不限定最终宽高时使用 `contain`:
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
const images = await editor.slides.exportImage({
|
|
502
|
+
mode: 'contain',
|
|
503
|
+
format: 'svg',
|
|
504
|
+
pixelRatio: 1,
|
|
505
|
+
padding: { horizontal: 24, vertical: 16 },
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
输出相机以内容可视包围盒为中心。最终尺寸为 `内容包围盒 × camera.scale × pixelRatio`,再加两侧 `padding`。`padding` 是最终输出中的每侧绝对像素,也可传单个数字表示四边相同。
|
|
510
|
+
|
|
511
|
+
适合需要固定最终输出宽高时使用 `size`:
|
|
512
|
+
|
|
513
|
+
```ts
|
|
514
|
+
const images = await editor.slides.exportImage({
|
|
515
|
+
mode: 'size',
|
|
516
|
+
format: 'jpg',
|
|
517
|
+
width: 1200,
|
|
518
|
+
height: 900,
|
|
519
|
+
minPadding: { horizontal: 40, vertical: 32 },
|
|
520
|
+
quality: 0.92,
|
|
521
|
+
});
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
`size` 不接收 `pixelRatio`。实现会从目标宽高扣除每侧 `minPadding`,再根据内容可视包围盒自动计算 pixelRatio,使内容完整缩放、居中,并严格输出指定的 `width × height`。`quality` 仅对 JPG 生效,范围为 `0~1`。
|
|
525
|
+
|
|
526
|
+
每张图片的返回结构为:
|
|
527
|
+
|
|
528
|
+
```ts
|
|
529
|
+
interface ExportedSlideImage {
|
|
530
|
+
index: number; // 1-based 画板索引
|
|
531
|
+
blob: Blob;
|
|
532
|
+
format: 'png' | 'jpg' | 'svg';
|
|
533
|
+
width: number;
|
|
534
|
+
height: number;
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
##### `editor.slides.exportLatex(options?)`
|
|
539
|
+
|
|
540
|
+
需要继续编辑、排版或编译几何图形时,可直接导出 LaTeX/TikZ 源码:
|
|
541
|
+
|
|
542
|
+
```ts
|
|
543
|
+
const items = await editor.slides.exportLatex({
|
|
544
|
+
slideIndices: [1, 3],
|
|
545
|
+
standalone: true,
|
|
546
|
+
});
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
- `slideIndices`:可选,使用从 `1` 开始的索引;省略时导出全部画板。
|
|
550
|
+
- `standalone`:可选,默认 `true`。为 `true` 时生成包含 document class、依赖宏包及 document 环境的可独立编译文档;为 `false` 时仅生成 TikZ 片段。
|
|
551
|
+
- 导出使用文件中的 camera 信息,并按画板完整可视包围盒确定 TikZ 的 bounding box 与裁剪区域。
|
|
552
|
+
|
|
553
|
+
返回结构为:
|
|
554
|
+
|
|
555
|
+
```ts
|
|
556
|
+
interface ExportedLatex {
|
|
557
|
+
index: number; // 1-based 画板索引
|
|
558
|
+
code: string;
|
|
559
|
+
}
|
|
560
|
+
```
|
|
480
561
|
|
|
481
562
|
#### `editor.history`
|
|
482
563
|
|
|
@@ -493,15 +574,18 @@ interface FileContent {
|
|
|
493
574
|
|
|
494
575
|
#### `editor.mode`
|
|
495
576
|
|
|
496
|
-
| 方法
|
|
497
|
-
|
|
|
498
|
-
| `getUiConfig()`
|
|
499
|
-
| `setUiConfig(config)`
|
|
577
|
+
| 方法 | 说明 |
|
|
578
|
+
| ----------------------------- | ---------------- |
|
|
579
|
+
| `getUiConfig()` | 获取当前 UI 配置 |
|
|
580
|
+
| `setUiConfig(config)` | 更新 UI 配置 |
|
|
581
|
+
| `setMasterTemplate(template)` | 设置母版风格 |
|
|
500
582
|
|
|
501
583
|
#### `editor.ai`
|
|
502
584
|
|
|
503
585
|
| 方法 | 说明 |
|
|
504
586
|
| ------------------- | ------------------------------------------------------------------- |
|
|
587
|
+
| `setDraft()` | 设置 AI 对话框草稿,支持 `text`、`images`、`openPanel`、`focus` |
|
|
588
|
+
| `clearDraft()` | 清空 AI 对话框草稿文本与图片 |
|
|
505
589
|
| `consumeStream()` | 消费接入方后端返回的大角几何标准 SSE 流,并实时转发给 iframe |
|
|
506
590
|
| `pushStreamEvent()` | 高级接口;接入方已自行解析 SSE 或使用非标准传输时,手动推送流式事件 |
|
|
507
591
|
|
|
@@ -518,6 +602,14 @@ interface FileContent {
|
|
|
518
602
|
| `aiRequest` | `{ type: 'aiRequest', payload, signal }` | iframe 发起 AI 请求,宿主应调用自有后端并将响应流交给 `editor.ai.consumeStream()` |
|
|
519
603
|
| `aiCancel` | `{ type: 'aiCancel', runId, reason }` | 用户停止生成、新请求替代旧请求或 editor 销毁时触发 |
|
|
520
604
|
|
|
605
|
+
#### `editor.resize(): void`
|
|
606
|
+
|
|
607
|
+
主动通知内嵌页重新测量容器尺寸并重绘画布。
|
|
608
|
+
|
|
609
|
+
调用后会通过 `postMessage` 向 iframe 发送一条 `{ type: 'resize' }` 消息;内嵌页(如 studio-web 的 `embedEditBridge`)收到后会自行测量容器尺寸并同步重绘画布一帧,使画布采用恢复可见后的真实尺寸。
|
|
610
|
+
|
|
611
|
+
SDK 内部已通过 `ResizeObserver` 在容器从隐藏(`display:none`,尺寸为 0)变为可见时**自动触发一次** `resize`;当宿主以其它方式改变容器尺寸(如布局切换、面板展开)而未触发该场景时,可手动调用此方法强制刷新。
|
|
612
|
+
|
|
521
613
|
#### 事件与销毁
|
|
522
614
|
|
|
523
615
|
- `editor.on(event, listener)` / `editor.off(event, listener)`
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -4011,7 +4011,7 @@ function convertToLatest(content) {
|
|
|
4011
4011
|
}
|
|
4012
4012
|
|
|
4013
4013
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4014
|
-
const VERSION = '2.
|
|
4014
|
+
const VERSION = '2.9.1';
|
|
4015
4015
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4016
4016
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
4017
4017
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4113,6 +4113,10 @@ class EmbeddedTarget {
|
|
|
4113
4113
|
this.destroyed = false;
|
|
4114
4114
|
this._ready = false;
|
|
4115
4115
|
this._version = null;
|
|
4116
|
+
this.lastContainerSize = {
|
|
4117
|
+
width: 0,
|
|
4118
|
+
height: 0,
|
|
4119
|
+
};
|
|
4116
4120
|
}
|
|
4117
4121
|
get ready() {
|
|
4118
4122
|
return this._ready;
|
|
@@ -4120,6 +4124,15 @@ class EmbeddedTarget {
|
|
|
4120
4124
|
get version() {
|
|
4121
4125
|
return this._version;
|
|
4122
4126
|
}
|
|
4127
|
+
/**
|
|
4128
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
4129
|
+
*/
|
|
4130
|
+
resize() {
|
|
4131
|
+
if (this.destroyed || !this._ready) {
|
|
4132
|
+
return;
|
|
4133
|
+
}
|
|
4134
|
+
this.postEvent('resize');
|
|
4135
|
+
}
|
|
4123
4136
|
on(event, listener) {
|
|
4124
4137
|
let bucket = this.listenerBuckets.get(event);
|
|
4125
4138
|
if (!bucket) {
|
|
@@ -4163,6 +4176,7 @@ class EmbeddedTarget {
|
|
|
4163
4176
|
resetRuntimeState() {
|
|
4164
4177
|
this._ready = false;
|
|
4165
4178
|
this._version = null;
|
|
4179
|
+
this.cleanupResizeObserver();
|
|
4166
4180
|
}
|
|
4167
4181
|
async init(options) {
|
|
4168
4182
|
if (this.iframe) {
|
|
@@ -4210,6 +4224,7 @@ class EmbeddedTarget {
|
|
|
4210
4224
|
finalizeFailure(new AlgeoError('iframe 初始化失败', EMBED_ERROR_CODES.IFRAME_NOT_READY));
|
|
4211
4225
|
});
|
|
4212
4226
|
this.container.appendChild(iframe);
|
|
4227
|
+
this.setupResizeObserver();
|
|
4213
4228
|
initTimeoutId = setTimeout(() => {
|
|
4214
4229
|
finalizeFailure(new AlgeoError('iframe 初始化超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4215
4230
|
}, EMBED_TIMEOUT_MS);
|
|
@@ -4224,6 +4239,7 @@ class EmbeddedTarget {
|
|
|
4224
4239
|
}
|
|
4225
4240
|
this._ready = true;
|
|
4226
4241
|
this._version = data.version;
|
|
4242
|
+
this.resize();
|
|
4227
4243
|
this.emit('ready', {
|
|
4228
4244
|
type: 'ready',
|
|
4229
4245
|
mode: this.embedMode,
|
|
@@ -4295,11 +4311,42 @@ class EmbeddedTarget {
|
|
|
4295
4311
|
}
|
|
4296
4312
|
this.iframe?.contentWindow?.postMessage({ type, ...payload }, '*');
|
|
4297
4313
|
}
|
|
4314
|
+
/**
|
|
4315
|
+
* 让内嵌页重新测量尺寸并重绘画布:向 iframe 发送 `resize` 事件。
|
|
4316
|
+
* 真正的重绘逻辑由内嵌页(bridge)监听该消息后执行。
|
|
4317
|
+
*/
|
|
4318
|
+
setupResizeObserver() {
|
|
4319
|
+
if (typeof ResizeObserver === 'undefined' || !this.container) {
|
|
4320
|
+
return;
|
|
4321
|
+
}
|
|
4322
|
+
this.lastContainerSize = {
|
|
4323
|
+
width: this.container.clientWidth,
|
|
4324
|
+
height: this.container.clientHeight,
|
|
4325
|
+
};
|
|
4326
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
4327
|
+
const width = this.container.clientWidth;
|
|
4328
|
+
const height = this.container.clientHeight;
|
|
4329
|
+
const prev = this.lastContainerSize;
|
|
4330
|
+
this.lastContainerSize = { width, height };
|
|
4331
|
+
const becameVisible = (prev.width === 0 || prev.height === 0) && width > 0 && height > 0;
|
|
4332
|
+
if (becameVisible) {
|
|
4333
|
+
this.resize();
|
|
4334
|
+
}
|
|
4335
|
+
});
|
|
4336
|
+
this.resizeObserver.observe(this.container);
|
|
4337
|
+
}
|
|
4338
|
+
cleanupResizeObserver() {
|
|
4339
|
+
if (this.resizeObserver) {
|
|
4340
|
+
this.resizeObserver.disconnect();
|
|
4341
|
+
this.resizeObserver = undefined;
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4298
4344
|
async destroy() {
|
|
4299
4345
|
if (this.destroyed) {
|
|
4300
4346
|
return;
|
|
4301
4347
|
}
|
|
4302
4348
|
this.destroyed = true;
|
|
4349
|
+
this.cleanupResizeObserver();
|
|
4303
4350
|
this.cleanupMessageHandler();
|
|
4304
4351
|
this.resetRuntimeState();
|
|
4305
4352
|
this.pending.forEach(({ reject }) => {
|
|
@@ -4325,6 +4372,10 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4325
4372
|
...config,
|
|
4326
4373
|
};
|
|
4327
4374
|
},
|
|
4375
|
+
setMasterTemplate: (template) => {
|
|
4376
|
+
this.ensureWhitelistAccess('setMasterTemplate');
|
|
4377
|
+
return this.post('setMasterTemplate', { template });
|
|
4378
|
+
},
|
|
4328
4379
|
};
|
|
4329
4380
|
}
|
|
4330
4381
|
async initialize(options = {}, baseUrl) {
|
|
@@ -4431,9 +4482,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4431
4482
|
await this.refreshHistoryState();
|
|
4432
4483
|
},
|
|
4433
4484
|
exportImage: async (options) => {
|
|
4434
|
-
const result = await this.post('exportSlideImage', { options
|
|
4485
|
+
const result = await this.post('exportSlideImage', { options });
|
|
4435
4486
|
return result.images;
|
|
4436
4487
|
},
|
|
4488
|
+
exportLatex: async (options) => {
|
|
4489
|
+
const result = await this.post('exportLatex', {
|
|
4490
|
+
options: options ?? {},
|
|
4491
|
+
});
|
|
4492
|
+
return result.items;
|
|
4493
|
+
},
|
|
4437
4494
|
};
|
|
4438
4495
|
this.history = {
|
|
4439
4496
|
getCount: () => this.historyCount,
|
|
@@ -4466,8 +4523,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4466
4523
|
...config,
|
|
4467
4524
|
};
|
|
4468
4525
|
},
|
|
4526
|
+
setMasterTemplate: (template) => this.post('setMasterTemplate', { template }),
|
|
4469
4527
|
};
|
|
4470
4528
|
this.ai = {
|
|
4529
|
+
setDraft: async (draft) => {
|
|
4530
|
+
await this.post('setAiDraft', { draft });
|
|
4531
|
+
},
|
|
4532
|
+
clearDraft: async () => {
|
|
4533
|
+
await this.post('clearAiDraft', {});
|
|
4534
|
+
},
|
|
4471
4535
|
consumeStream: async ({ stream, signal }) => {
|
|
4472
4536
|
await this.consumeAiStream(stream, signal);
|
|
4473
4537
|
},
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -4009,7 +4009,7 @@ function convertToLatest(content) {
|
|
|
4009
4009
|
}
|
|
4010
4010
|
|
|
4011
4011
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4012
|
-
const VERSION = '2.
|
|
4012
|
+
const VERSION = '2.9.1';
|
|
4013
4013
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4014
4014
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
4015
4015
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4111,6 +4111,10 @@ class EmbeddedTarget {
|
|
|
4111
4111
|
this.destroyed = false;
|
|
4112
4112
|
this._ready = false;
|
|
4113
4113
|
this._version = null;
|
|
4114
|
+
this.lastContainerSize = {
|
|
4115
|
+
width: 0,
|
|
4116
|
+
height: 0,
|
|
4117
|
+
};
|
|
4114
4118
|
}
|
|
4115
4119
|
get ready() {
|
|
4116
4120
|
return this._ready;
|
|
@@ -4118,6 +4122,15 @@ class EmbeddedTarget {
|
|
|
4118
4122
|
get version() {
|
|
4119
4123
|
return this._version;
|
|
4120
4124
|
}
|
|
4125
|
+
/**
|
|
4126
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
4127
|
+
*/
|
|
4128
|
+
resize() {
|
|
4129
|
+
if (this.destroyed || !this._ready) {
|
|
4130
|
+
return;
|
|
4131
|
+
}
|
|
4132
|
+
this.postEvent('resize');
|
|
4133
|
+
}
|
|
4121
4134
|
on(event, listener) {
|
|
4122
4135
|
let bucket = this.listenerBuckets.get(event);
|
|
4123
4136
|
if (!bucket) {
|
|
@@ -4161,6 +4174,7 @@ class EmbeddedTarget {
|
|
|
4161
4174
|
resetRuntimeState() {
|
|
4162
4175
|
this._ready = false;
|
|
4163
4176
|
this._version = null;
|
|
4177
|
+
this.cleanupResizeObserver();
|
|
4164
4178
|
}
|
|
4165
4179
|
async init(options) {
|
|
4166
4180
|
if (this.iframe) {
|
|
@@ -4208,6 +4222,7 @@ class EmbeddedTarget {
|
|
|
4208
4222
|
finalizeFailure(new AlgeoError('iframe 初始化失败', EMBED_ERROR_CODES.IFRAME_NOT_READY));
|
|
4209
4223
|
});
|
|
4210
4224
|
this.container.appendChild(iframe);
|
|
4225
|
+
this.setupResizeObserver();
|
|
4211
4226
|
initTimeoutId = setTimeout(() => {
|
|
4212
4227
|
finalizeFailure(new AlgeoError('iframe 初始化超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4213
4228
|
}, EMBED_TIMEOUT_MS);
|
|
@@ -4222,6 +4237,7 @@ class EmbeddedTarget {
|
|
|
4222
4237
|
}
|
|
4223
4238
|
this._ready = true;
|
|
4224
4239
|
this._version = data.version;
|
|
4240
|
+
this.resize();
|
|
4225
4241
|
this.emit('ready', {
|
|
4226
4242
|
type: 'ready',
|
|
4227
4243
|
mode: this.embedMode,
|
|
@@ -4293,11 +4309,42 @@ class EmbeddedTarget {
|
|
|
4293
4309
|
}
|
|
4294
4310
|
this.iframe?.contentWindow?.postMessage({ type, ...payload }, '*');
|
|
4295
4311
|
}
|
|
4312
|
+
/**
|
|
4313
|
+
* 让内嵌页重新测量尺寸并重绘画布:向 iframe 发送 `resize` 事件。
|
|
4314
|
+
* 真正的重绘逻辑由内嵌页(bridge)监听该消息后执行。
|
|
4315
|
+
*/
|
|
4316
|
+
setupResizeObserver() {
|
|
4317
|
+
if (typeof ResizeObserver === 'undefined' || !this.container) {
|
|
4318
|
+
return;
|
|
4319
|
+
}
|
|
4320
|
+
this.lastContainerSize = {
|
|
4321
|
+
width: this.container.clientWidth,
|
|
4322
|
+
height: this.container.clientHeight,
|
|
4323
|
+
};
|
|
4324
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
4325
|
+
const width = this.container.clientWidth;
|
|
4326
|
+
const height = this.container.clientHeight;
|
|
4327
|
+
const prev = this.lastContainerSize;
|
|
4328
|
+
this.lastContainerSize = { width, height };
|
|
4329
|
+
const becameVisible = (prev.width === 0 || prev.height === 0) && width > 0 && height > 0;
|
|
4330
|
+
if (becameVisible) {
|
|
4331
|
+
this.resize();
|
|
4332
|
+
}
|
|
4333
|
+
});
|
|
4334
|
+
this.resizeObserver.observe(this.container);
|
|
4335
|
+
}
|
|
4336
|
+
cleanupResizeObserver() {
|
|
4337
|
+
if (this.resizeObserver) {
|
|
4338
|
+
this.resizeObserver.disconnect();
|
|
4339
|
+
this.resizeObserver = undefined;
|
|
4340
|
+
}
|
|
4341
|
+
}
|
|
4296
4342
|
async destroy() {
|
|
4297
4343
|
if (this.destroyed) {
|
|
4298
4344
|
return;
|
|
4299
4345
|
}
|
|
4300
4346
|
this.destroyed = true;
|
|
4347
|
+
this.cleanupResizeObserver();
|
|
4301
4348
|
this.cleanupMessageHandler();
|
|
4302
4349
|
this.resetRuntimeState();
|
|
4303
4350
|
this.pending.forEach(({ reject }) => {
|
|
@@ -4323,6 +4370,10 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4323
4370
|
...config,
|
|
4324
4371
|
};
|
|
4325
4372
|
},
|
|
4373
|
+
setMasterTemplate: (template) => {
|
|
4374
|
+
this.ensureWhitelistAccess('setMasterTemplate');
|
|
4375
|
+
return this.post('setMasterTemplate', { template });
|
|
4376
|
+
},
|
|
4326
4377
|
};
|
|
4327
4378
|
}
|
|
4328
4379
|
async initialize(options = {}, baseUrl) {
|
|
@@ -4429,9 +4480,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4429
4480
|
await this.refreshHistoryState();
|
|
4430
4481
|
},
|
|
4431
4482
|
exportImage: async (options) => {
|
|
4432
|
-
const result = await this.post('exportSlideImage', { options
|
|
4483
|
+
const result = await this.post('exportSlideImage', { options });
|
|
4433
4484
|
return result.images;
|
|
4434
4485
|
},
|
|
4486
|
+
exportLatex: async (options) => {
|
|
4487
|
+
const result = await this.post('exportLatex', {
|
|
4488
|
+
options: options ?? {},
|
|
4489
|
+
});
|
|
4490
|
+
return result.items;
|
|
4491
|
+
},
|
|
4435
4492
|
};
|
|
4436
4493
|
this.history = {
|
|
4437
4494
|
getCount: () => this.historyCount,
|
|
@@ -4464,8 +4521,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4464
4521
|
...config,
|
|
4465
4522
|
};
|
|
4466
4523
|
},
|
|
4524
|
+
setMasterTemplate: (template) => this.post('setMasterTemplate', { template }),
|
|
4467
4525
|
};
|
|
4468
4526
|
this.ai = {
|
|
4527
|
+
setDraft: async (draft) => {
|
|
4528
|
+
await this.post('setAiDraft', { draft });
|
|
4529
|
+
},
|
|
4530
|
+
clearDraft: async () => {
|
|
4531
|
+
await this.post('clearAiDraft', {});
|
|
4532
|
+
},
|
|
4469
4533
|
consumeStream: async ({ stream, signal }) => {
|
|
4470
4534
|
await this.consumeAiStream(stream, signal);
|
|
4471
4535
|
},
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -4015,7 +4015,7 @@
|
|
|
4015
4015
|
}
|
|
4016
4016
|
|
|
4017
4017
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4018
|
-
const VERSION = '2.
|
|
4018
|
+
const VERSION = '2.9.1';
|
|
4019
4019
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4020
4020
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
4021
4021
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4117,6 +4117,10 @@
|
|
|
4117
4117
|
this.destroyed = false;
|
|
4118
4118
|
this._ready = false;
|
|
4119
4119
|
this._version = null;
|
|
4120
|
+
this.lastContainerSize = {
|
|
4121
|
+
width: 0,
|
|
4122
|
+
height: 0,
|
|
4123
|
+
};
|
|
4120
4124
|
}
|
|
4121
4125
|
get ready() {
|
|
4122
4126
|
return this._ready;
|
|
@@ -4124,6 +4128,15 @@
|
|
|
4124
4128
|
get version() {
|
|
4125
4129
|
return this._version;
|
|
4126
4130
|
}
|
|
4131
|
+
/**
|
|
4132
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
4133
|
+
*/
|
|
4134
|
+
resize() {
|
|
4135
|
+
if (this.destroyed || !this._ready) {
|
|
4136
|
+
return;
|
|
4137
|
+
}
|
|
4138
|
+
this.postEvent('resize');
|
|
4139
|
+
}
|
|
4127
4140
|
on(event, listener) {
|
|
4128
4141
|
let bucket = this.listenerBuckets.get(event);
|
|
4129
4142
|
if (!bucket) {
|
|
@@ -4167,6 +4180,7 @@
|
|
|
4167
4180
|
resetRuntimeState() {
|
|
4168
4181
|
this._ready = false;
|
|
4169
4182
|
this._version = null;
|
|
4183
|
+
this.cleanupResizeObserver();
|
|
4170
4184
|
}
|
|
4171
4185
|
async init(options) {
|
|
4172
4186
|
if (this.iframe) {
|
|
@@ -4214,6 +4228,7 @@
|
|
|
4214
4228
|
finalizeFailure(new AlgeoError('iframe 初始化失败', EMBED_ERROR_CODES.IFRAME_NOT_READY));
|
|
4215
4229
|
});
|
|
4216
4230
|
this.container.appendChild(iframe);
|
|
4231
|
+
this.setupResizeObserver();
|
|
4217
4232
|
initTimeoutId = setTimeout(() => {
|
|
4218
4233
|
finalizeFailure(new AlgeoError('iframe 初始化超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4219
4234
|
}, EMBED_TIMEOUT_MS);
|
|
@@ -4228,6 +4243,7 @@
|
|
|
4228
4243
|
}
|
|
4229
4244
|
this._ready = true;
|
|
4230
4245
|
this._version = data.version;
|
|
4246
|
+
this.resize();
|
|
4231
4247
|
this.emit('ready', {
|
|
4232
4248
|
type: 'ready',
|
|
4233
4249
|
mode: this.embedMode,
|
|
@@ -4299,11 +4315,42 @@
|
|
|
4299
4315
|
}
|
|
4300
4316
|
this.iframe?.contentWindow?.postMessage({ type, ...payload }, '*');
|
|
4301
4317
|
}
|
|
4318
|
+
/**
|
|
4319
|
+
* 让内嵌页重新测量尺寸并重绘画布:向 iframe 发送 `resize` 事件。
|
|
4320
|
+
* 真正的重绘逻辑由内嵌页(bridge)监听该消息后执行。
|
|
4321
|
+
*/
|
|
4322
|
+
setupResizeObserver() {
|
|
4323
|
+
if (typeof ResizeObserver === 'undefined' || !this.container) {
|
|
4324
|
+
return;
|
|
4325
|
+
}
|
|
4326
|
+
this.lastContainerSize = {
|
|
4327
|
+
width: this.container.clientWidth,
|
|
4328
|
+
height: this.container.clientHeight,
|
|
4329
|
+
};
|
|
4330
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
4331
|
+
const width = this.container.clientWidth;
|
|
4332
|
+
const height = this.container.clientHeight;
|
|
4333
|
+
const prev = this.lastContainerSize;
|
|
4334
|
+
this.lastContainerSize = { width, height };
|
|
4335
|
+
const becameVisible = (prev.width === 0 || prev.height === 0) && width > 0 && height > 0;
|
|
4336
|
+
if (becameVisible) {
|
|
4337
|
+
this.resize();
|
|
4338
|
+
}
|
|
4339
|
+
});
|
|
4340
|
+
this.resizeObserver.observe(this.container);
|
|
4341
|
+
}
|
|
4342
|
+
cleanupResizeObserver() {
|
|
4343
|
+
if (this.resizeObserver) {
|
|
4344
|
+
this.resizeObserver.disconnect();
|
|
4345
|
+
this.resizeObserver = undefined;
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4302
4348
|
async destroy() {
|
|
4303
4349
|
if (this.destroyed) {
|
|
4304
4350
|
return;
|
|
4305
4351
|
}
|
|
4306
4352
|
this.destroyed = true;
|
|
4353
|
+
this.cleanupResizeObserver();
|
|
4307
4354
|
this.cleanupMessageHandler();
|
|
4308
4355
|
this.resetRuntimeState();
|
|
4309
4356
|
this.pending.forEach(({ reject }) => {
|
|
@@ -4329,6 +4376,10 @@
|
|
|
4329
4376
|
...config,
|
|
4330
4377
|
};
|
|
4331
4378
|
},
|
|
4379
|
+
setMasterTemplate: (template) => {
|
|
4380
|
+
this.ensureWhitelistAccess('setMasterTemplate');
|
|
4381
|
+
return this.post('setMasterTemplate', { template });
|
|
4382
|
+
},
|
|
4332
4383
|
};
|
|
4333
4384
|
}
|
|
4334
4385
|
async initialize(options = {}, baseUrl) {
|
|
@@ -4435,9 +4486,15 @@
|
|
|
4435
4486
|
await this.refreshHistoryState();
|
|
4436
4487
|
},
|
|
4437
4488
|
exportImage: async (options) => {
|
|
4438
|
-
const result = await this.post('exportSlideImage', { options
|
|
4489
|
+
const result = await this.post('exportSlideImage', { options });
|
|
4439
4490
|
return result.images;
|
|
4440
4491
|
},
|
|
4492
|
+
exportLatex: async (options) => {
|
|
4493
|
+
const result = await this.post('exportLatex', {
|
|
4494
|
+
options: options ?? {},
|
|
4495
|
+
});
|
|
4496
|
+
return result.items;
|
|
4497
|
+
},
|
|
4441
4498
|
};
|
|
4442
4499
|
this.history = {
|
|
4443
4500
|
getCount: () => this.historyCount,
|
|
@@ -4470,8 +4527,15 @@
|
|
|
4470
4527
|
...config,
|
|
4471
4528
|
};
|
|
4472
4529
|
},
|
|
4530
|
+
setMasterTemplate: (template) => this.post('setMasterTemplate', { template }),
|
|
4473
4531
|
};
|
|
4474
4532
|
this.ai = {
|
|
4533
|
+
setDraft: async (draft) => {
|
|
4534
|
+
await this.post('setAiDraft', { draft });
|
|
4535
|
+
},
|
|
4536
|
+
clearDraft: async () => {
|
|
4537
|
+
await this.post('clearAiDraft', {});
|
|
4538
|
+
},
|
|
4475
4539
|
consumeStream: async ({ stream, signal }) => {
|
|
4476
4540
|
await this.consumeAiStream(stream, signal);
|
|
4477
4541
|
},
|
|
@@ -14,9 +14,15 @@ export declare abstract class EmbeddedTarget<EventMap extends {
|
|
|
14
14
|
private destroyed;
|
|
15
15
|
protected _ready: boolean;
|
|
16
16
|
protected _version: string | null;
|
|
17
|
+
private resizeObserver?;
|
|
18
|
+
private lastContainerSize;
|
|
17
19
|
protected constructor(container: HTMLElement, embedMode: AlgeoEmbedMode);
|
|
18
20
|
get ready(): boolean;
|
|
19
21
|
get version(): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
24
|
+
*/
|
|
25
|
+
resize(): void;
|
|
20
26
|
on<T extends EventName>(event: T, listener: ListenerMap[T]): () => void;
|
|
21
27
|
protected getListeners<T extends EventName>(event: T): ListenerMap[T][];
|
|
22
28
|
off<T extends EventName>(event: T, listener: ListenerMap[T]): void;
|
|
@@ -32,5 +38,11 @@ export declare abstract class EmbeddedTarget<EventMap extends {
|
|
|
32
38
|
timeoutMs?: number;
|
|
33
39
|
}): Promise<T>;
|
|
34
40
|
protected postEvent(type: string, payload?: Record<string, unknown>): void;
|
|
41
|
+
/**
|
|
42
|
+
* 让内嵌页重新测量尺寸并重绘画布:向 iframe 发送 `resize` 事件。
|
|
43
|
+
* 真正的重绘逻辑由内嵌页(bridge)监听该消息后执行。
|
|
44
|
+
*/
|
|
45
|
+
private setupResizeObserver;
|
|
46
|
+
private cleanupResizeObserver;
|
|
35
47
|
destroy(): Promise<void>;
|
|
36
48
|
}
|
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, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
|
|
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, 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
|
@@ -88,12 +88,20 @@ export interface SaveRequestMessage {
|
|
|
88
88
|
content: FileContentLatest;
|
|
89
89
|
}
|
|
90
90
|
export interface AiApi {
|
|
91
|
+
setDraft(draft: AiDraftPayloadV1): Promise<void>;
|
|
92
|
+
clearDraft(): Promise<void>;
|
|
91
93
|
consumeStream(input: {
|
|
92
94
|
stream: ReadableStream<Uint8Array>;
|
|
93
95
|
signal?: AbortSignal;
|
|
94
96
|
}): Promise<void>;
|
|
95
97
|
pushStreamEvent(event: AiStreamEventV1): void;
|
|
96
98
|
}
|
|
99
|
+
export interface AiDraftPayloadV1 {
|
|
100
|
+
text?: string;
|
|
101
|
+
images?: string[];
|
|
102
|
+
openPanel?: boolean;
|
|
103
|
+
focus?: boolean;
|
|
104
|
+
}
|
|
97
105
|
export interface AiRequestEvent {
|
|
98
106
|
type: 'aiRequest';
|
|
99
107
|
payload: AiRunPayloadV1;
|
|
@@ -139,6 +147,9 @@ export interface LoadShareByIdResult {
|
|
|
139
147
|
export interface LoadFileResult {
|
|
140
148
|
success: true;
|
|
141
149
|
}
|
|
150
|
+
export interface SetMasterTemplateResult {
|
|
151
|
+
success: true;
|
|
152
|
+
}
|
|
142
153
|
export interface SwitchSlideResult {
|
|
143
154
|
success: true;
|
|
144
155
|
}
|
|
@@ -151,9 +162,67 @@ export interface ReplResult {
|
|
|
151
162
|
export interface SlideIndexResult {
|
|
152
163
|
index: number;
|
|
153
164
|
}
|
|
165
|
+
export type ExportImageFormat = 'png' | 'jpg' | 'svg';
|
|
166
|
+
/**
|
|
167
|
+
* 导出的逻辑视野区域(世界坐标)。
|
|
168
|
+
*/
|
|
169
|
+
export interface ExportViewBounds {
|
|
170
|
+
x: number;
|
|
171
|
+
y: number;
|
|
172
|
+
width: number;
|
|
173
|
+
height: number;
|
|
174
|
+
}
|
|
175
|
+
/** 导出留白,单位为输出像素 px。 */
|
|
176
|
+
export type ExportPadding = number | {
|
|
177
|
+
horizontal?: number;
|
|
178
|
+
vertical?: number;
|
|
179
|
+
};
|
|
180
|
+
interface ExportImageBaseOptions {
|
|
181
|
+
slideIndices?: number[];
|
|
182
|
+
format?: ExportImageFormat;
|
|
183
|
+
/** 仅 jpg 生效,0~1 */
|
|
184
|
+
quality?: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 场景一(size):
|
|
188
|
+
* 从目标输出宽高扣除每侧 minPadding 后,根据图形可视包围盒自动计算 pixelRatio,
|
|
189
|
+
* 使图形完整 contain 在可用区域并居中;最终画布严格等于指定输出宽高。
|
|
190
|
+
*/
|
|
191
|
+
export interface ExportImageSizeMode extends ExportImageBaseOptions {
|
|
192
|
+
mode: 'size';
|
|
193
|
+
width: number;
|
|
194
|
+
height: number;
|
|
195
|
+
/** 每侧最小留白,单位为输出像素 px。 */
|
|
196
|
+
minPadding?: ExportPadding;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 场景二(view):viewBounds 的位置及宽高均为世界坐标,渲染相机从文件读取
|
|
200
|
+
* 输出像素 = viewBounds 世界尺寸 x camera.scale x pixelRatio。
|
|
201
|
+
*/
|
|
202
|
+
export interface ExportImageViewMode extends ExportImageBaseOptions {
|
|
203
|
+
mode: 'view';
|
|
204
|
+
viewBounds: ExportViewBounds;
|
|
205
|
+
pixelRatio?: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 场景三(contain):
|
|
209
|
+
* 内容按文件 camera 的 scale 1:1 渲染,最终画布 = 包围盒世界尺寸 x scale x pixelRatio + 两侧 padding。
|
|
210
|
+
* padding 为最终输出的绝对像素,可分别指定水平与垂直方向。
|
|
211
|
+
*/
|
|
212
|
+
export interface ExportImageContainMode extends ExportImageBaseOptions {
|
|
213
|
+
mode: 'contain';
|
|
214
|
+
pixelRatio?: number;
|
|
215
|
+
/** 每侧绝对留白,单位为最终输出像素 px */
|
|
216
|
+
padding?: ExportPadding;
|
|
217
|
+
}
|
|
218
|
+
export type ExportImageOptions = ExportImageSizeMode | ExportImageViewMode | ExportImageContainMode;
|
|
219
|
+
/**
|
|
220
|
+
* 旧的扁平导出参数。
|
|
221
|
+
* @deprecated 请改用 ExportImageOptions 的三种 mode;format:'latex' 请改用 exportLatex。
|
|
222
|
+
*/
|
|
154
223
|
export interface ExportSlideImageOptions {
|
|
155
224
|
slideIndices?: number[];
|
|
156
|
-
format?:
|
|
225
|
+
format?: ExportImageFormat | 'latex';
|
|
157
226
|
width?: number;
|
|
158
227
|
height?: number;
|
|
159
228
|
quality?: number;
|
|
@@ -163,13 +232,25 @@ export interface ExportSlideImageOptions {
|
|
|
163
232
|
export interface ExportedSlideImage {
|
|
164
233
|
index: number;
|
|
165
234
|
blob: Blob;
|
|
166
|
-
format:
|
|
235
|
+
format: ExportImageFormat;
|
|
167
236
|
width: number;
|
|
168
237
|
height: number;
|
|
169
238
|
}
|
|
170
239
|
export interface ExportSlideImageResult {
|
|
171
240
|
images: ExportedSlideImage[];
|
|
172
241
|
}
|
|
242
|
+
export interface ExportLatexOptions {
|
|
243
|
+
slideIndices?: number[];
|
|
244
|
+
/** 是否生成可独立编译的 standalone 文档,默认 true */
|
|
245
|
+
standalone?: boolean;
|
|
246
|
+
}
|
|
247
|
+
export interface ExportedLatex {
|
|
248
|
+
index: number;
|
|
249
|
+
code: string;
|
|
250
|
+
}
|
|
251
|
+
export interface ExportLatexResult {
|
|
252
|
+
items: ExportedLatex[];
|
|
253
|
+
}
|
|
173
254
|
export interface GetContentResult {
|
|
174
255
|
content: FileContentLatest;
|
|
175
256
|
}
|
|
@@ -192,7 +273,20 @@ export interface SlidesApi {
|
|
|
192
273
|
remove(index: number): Promise<void>;
|
|
193
274
|
duplicate(index: number, targetIndex?: number): Promise<SlideIndexResult>;
|
|
194
275
|
reorder(fromIndex: number, toIndex: number): Promise<void>;
|
|
195
|
-
|
|
276
|
+
/**
|
|
277
|
+
/**
|
|
278
|
+
* 导出画板图片。支持三种 mode:
|
|
279
|
+
* - size:目标输出宽高、minPadding 与图形包围盒
|
|
280
|
+
* 自动计算 pixelRatio,使图形完整 contain 在可用区域。
|
|
281
|
+
* - view:指定视野 viewBounds 与 pixelRatio
|
|
282
|
+
* - contain:由 pixelRatio 与绝对 px padding 自动计算最终宽高。
|
|
283
|
+
*
|
|
284
|
+
* 旧的扁平 ExportSlideImageOptions 已废弃,实现层不再接受;请改用上述三模式 ExportImageOptions。
|
|
285
|
+
* format:'latex' 请改用 exportLatex。
|
|
286
|
+
*/
|
|
287
|
+
exportImage(options: ExportImageOptions): Promise<ExportedSlideImage[]>;
|
|
288
|
+
/** 导出画板为 LaTeX/TikZ 源码 */
|
|
289
|
+
exportLatex(options?: ExportLatexOptions): Promise<ExportedLatex[]>;
|
|
196
290
|
}
|
|
197
291
|
export interface HistoryApi {
|
|
198
292
|
getCount(): number;
|
|
@@ -207,10 +301,12 @@ export interface HistoryApi {
|
|
|
207
301
|
export interface ModeApi {
|
|
208
302
|
getUiConfig(): AlgeoEditorUiConfig;
|
|
209
303
|
setUiConfig(config: Partial<AlgeoEditorUiConfig>): Promise<void>;
|
|
304
|
+
setMasterTemplate(template: string): Promise<SetMasterTemplateResult>;
|
|
210
305
|
}
|
|
211
306
|
export interface PresentationModeApi {
|
|
212
307
|
getUiConfig(): AlgeoPresentationUiConfig;
|
|
213
308
|
setUiConfig(config: Partial<AlgeoPresentationUiConfig>): Promise<void>;
|
|
309
|
+
setMasterTemplate(template: string): Promise<SetMasterTemplateResult>;
|
|
214
310
|
}
|
|
215
311
|
export declare function generateRequestId(): string;
|
|
216
312
|
export declare function isResponseMessage(msg: unknown): msg is EmbedResponseMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dajiaoai/algeo-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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.5.
|
|
45
|
+
"@dajiaoai/algeo-protocol": "^1.5.2"
|
|
46
46
|
}
|
|
47
47
|
}
|