@dajiaoai/algeo-sdk 2.9.0 → 2.9.2
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 +119 -45
- package/dist/algeo-sdk.cjs.js +61 -13
- package/dist/algeo-sdk.esm.js +61 -13
- package/dist/algeo-sdk.umd.js +61 -13
- package/dist/embedded-target.d.ts +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/shared.d.ts +86 -4
- 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
|
### 方式一:演示模式
|
|
@@ -61,7 +34,7 @@ import { createPresentation } from '@dajiaoai/algeo-sdk';
|
|
|
61
34
|
|
|
62
35
|
const container = document.getElementById('algeo-container');
|
|
63
36
|
const presentation = await createPresentation(container, {
|
|
64
|
-
appId: 'YTVJDQZR',
|
|
37
|
+
auth: { appId: 'YTVJDQZR' },
|
|
65
38
|
shareId: '33TA3484',
|
|
66
39
|
ui: {
|
|
67
40
|
logo: false,
|
|
@@ -92,7 +65,7 @@ presentation.mode
|
|
|
92
65
|
```html
|
|
93
66
|
<iframe
|
|
94
67
|
id="algeo-embed"
|
|
95
|
-
src="https://dajiaoai.com/
|
|
68
|
+
src="https://dajiaoai.com/embed/present/YOUR_APP_ID/33TA3484"
|
|
96
69
|
allow="fullscreen"
|
|
97
70
|
referrerpolicy="origin"
|
|
98
71
|
></iframe>
|
|
@@ -261,7 +234,7 @@ create(container, {
|
|
|
261
234
|
|
|
262
235
|
演示模式快捷入口。该函数负责真正创建并初始化 `EmbeddedPresentation`。
|
|
263
236
|
|
|
264
|
-
创建成功后,SDK 会额外调用 `https://open.dajiaoai.com/console/api/whitelist/check`,使用 `options.appId` 与当前页面 `hostname` 做白名单校验。若未命中白名单,iframe 仍会完成初始化并呈现页面,`createPresentation` 仍会成功返回实例,但后续 `loadShareById`、`loadFile`、`switchSlide`、`getSlideCount`、`repl` 等演示模式 API 会被拒绝,并在控制台输出包含方法名的错误,便于接入方感知并处理。
|
|
237
|
+
创建成功后,SDK 会额外调用 `https://open.dajiaoai.com/console/api/whitelist/check`,使用 `options.auth.appId` 与当前页面 `hostname` 做白名单校验。若未命中白名单,iframe 仍会完成初始化并呈现页面,`createPresentation` 仍会成功返回实例,但后续 `loadShareById`、`loadFile`、`switchSlide`、`getSlideCount`、`repl` 等演示模式 API 会被拒绝,并在控制台输出包含方法名的错误,便于接入方感知并处理。
|
|
265
238
|
|
|
266
239
|
```javascript
|
|
267
240
|
create(container, {
|
|
@@ -321,13 +294,13 @@ type AlgeoCreateOptions =
|
|
|
321
294
|
|
|
322
295
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
323
296
|
| --------- | ------------------------------------ | ------ | -------------------------------------------------------- |
|
|
324
|
-
| `
|
|
325
|
-
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/
|
|
297
|
+
| `auth` | `{ appId: string }` | - | 演示模式鉴权参数,`appId` 用于路由及白名单校验 |
|
|
298
|
+
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/embed/present/:appId/:id` |
|
|
326
299
|
| `ui` | `Partial<AlgeoPresentationUiConfig>` | - | 演示模式 UI 配置 |
|
|
327
300
|
|
|
328
301
|
默认路径规则:
|
|
329
302
|
|
|
330
|
-
- `mode: 'presentation'` -> `/
|
|
303
|
+
- `mode: 'presentation'` -> `/embed/present/:appId`,若传 `presentation.shareId` 则生成 `/embed/present/:appId/:id`
|
|
331
304
|
- `mode: 'editor'` -> `/embed/edit/:appId`,其中 `:appId` 来自 `editor.auth.appId`;若传 `editor.shareId` 则生成 `/embed/edit/:appId/:id`
|
|
332
305
|
|
|
333
306
|
**示例:**
|
|
@@ -336,7 +309,7 @@ type AlgeoCreateOptions =
|
|
|
336
309
|
const presentation = await create(container, {
|
|
337
310
|
mode: 'presentation',
|
|
338
311
|
presentation: {
|
|
339
|
-
appId: 'xxxx',
|
|
312
|
+
auth: { appId: 'xxxx' },
|
|
340
313
|
shareId: '33TA3484',
|
|
341
314
|
},
|
|
342
315
|
});
|
|
@@ -378,6 +351,16 @@ const presentation = await create(container, {
|
|
|
378
351
|
| `setUiConfig(config)` | 更新 UI 配置 |
|
|
379
352
|
| `setMasterTemplate(template)` | 设置母版风格 |
|
|
380
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
|
+
---
|
|
363
|
+
|
|
381
364
|
##### `presentation.loadShareById(id: string): Promise<LoadShareByIdResult>`
|
|
382
365
|
|
|
383
366
|
按分享 ID 加载内容。
|
|
@@ -481,17 +464,100 @@ interface FileContent {
|
|
|
481
464
|
|
|
482
465
|
#### `editor.slides`
|
|
483
466
|
|
|
484
|
-
| 方法 | 说明
|
|
485
|
-
| -------------------------------- |
|
|
486
|
-
| `getCount()` | 获取当前已知画板数量
|
|
487
|
-
| `getCurrentIndex()` | 获取当前已知画板索引
|
|
488
|
-
| `switchTo(index)` | 切换画板
|
|
489
|
-
| `add()` | 在末尾新增画板
|
|
490
|
-
| `addAt(index)` | 在指定位置新增画板
|
|
491
|
-
| `remove(index)` | 删除指定画板
|
|
492
|
-
| `duplicate(index, targetIndex?)` | 复制画板
|
|
493
|
-
| `reorder(fromIndex, toIndex)` | 重排画板
|
|
494
|
-
| `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
|
+
```
|
|
495
561
|
|
|
496
562
|
#### `editor.history`
|
|
497
563
|
|
|
@@ -536,6 +602,14 @@ interface FileContent {
|
|
|
536
602
|
| `aiRequest` | `{ type: 'aiRequest', payload, signal }` | iframe 发起 AI 请求,宿主应调用自有后端并将响应流交给 `editor.ai.consumeStream()` |
|
|
537
603
|
| `aiCancel` | `{ type: 'aiCancel', runId, reason }` | 用户停止生成、新请求替代旧请求或 editor 销毁时触发 |
|
|
538
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
|
+
|
|
539
613
|
#### 事件与销毁
|
|
540
614
|
|
|
541
615
|
- `editor.on(event, listener)` / `editor.off(event, listener)`
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -4011,9 +4011,9 @@ function convertToLatest(content) {
|
|
|
4011
4011
|
}
|
|
4012
4012
|
|
|
4013
4013
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4014
|
-
const VERSION = '2.9.
|
|
4014
|
+
const VERSION = '2.9.2';
|
|
4015
4015
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4016
|
-
const DEFAULT_PRESENTATION_PATH = '/
|
|
4016
|
+
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4017
4017
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
4018
4018
|
const EMBED_TIMEOUT_MS = 30000;
|
|
4019
4019
|
let requestIdCounter = 0;
|
|
@@ -4090,18 +4090,12 @@ function buildEmbedSrc(options) {
|
|
|
4090
4090
|
const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
|
|
4091
4091
|
const mode = normalizeMode(options.mode);
|
|
4092
4092
|
const path = getEmbedPath(mode);
|
|
4093
|
-
const
|
|
4093
|
+
const appId = options.auth?.appId?.trim() ?? '';
|
|
4094
4094
|
const initialId = options.initialId?.trim();
|
|
4095
|
-
if (mode === 'editor') {
|
|
4096
|
-
if (!initialId) {
|
|
4097
|
-
return `${baseUrl}${path}/${encodeURIComponent(authAppId)}`;
|
|
4098
|
-
}
|
|
4099
|
-
return `${baseUrl}${path}/${encodeURIComponent(authAppId)}/${encodeURIComponent(initialId)}`;
|
|
4100
|
-
}
|
|
4101
4095
|
if (!initialId) {
|
|
4102
|
-
return `${baseUrl}${path}`;
|
|
4096
|
+
return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
|
|
4103
4097
|
}
|
|
4104
|
-
return `${baseUrl}${path}/${encodeURIComponent(initialId)}`;
|
|
4098
|
+
return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
|
|
4105
4099
|
}
|
|
4106
4100
|
|
|
4107
4101
|
class EmbeddedTarget {
|
|
@@ -4113,6 +4107,10 @@ class EmbeddedTarget {
|
|
|
4113
4107
|
this.destroyed = false;
|
|
4114
4108
|
this._ready = false;
|
|
4115
4109
|
this._version = null;
|
|
4110
|
+
this.lastContainerSize = {
|
|
4111
|
+
width: 0,
|
|
4112
|
+
height: 0,
|
|
4113
|
+
};
|
|
4116
4114
|
}
|
|
4117
4115
|
get ready() {
|
|
4118
4116
|
return this._ready;
|
|
@@ -4120,6 +4118,15 @@ class EmbeddedTarget {
|
|
|
4120
4118
|
get version() {
|
|
4121
4119
|
return this._version;
|
|
4122
4120
|
}
|
|
4121
|
+
/**
|
|
4122
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
4123
|
+
*/
|
|
4124
|
+
resize() {
|
|
4125
|
+
if (this.destroyed || !this._ready) {
|
|
4126
|
+
return;
|
|
4127
|
+
}
|
|
4128
|
+
this.postEvent('resize');
|
|
4129
|
+
}
|
|
4123
4130
|
on(event, listener) {
|
|
4124
4131
|
let bucket = this.listenerBuckets.get(event);
|
|
4125
4132
|
if (!bucket) {
|
|
@@ -4163,6 +4170,7 @@ class EmbeddedTarget {
|
|
|
4163
4170
|
resetRuntimeState() {
|
|
4164
4171
|
this._ready = false;
|
|
4165
4172
|
this._version = null;
|
|
4173
|
+
this.cleanupResizeObserver();
|
|
4166
4174
|
}
|
|
4167
4175
|
async init(options) {
|
|
4168
4176
|
if (this.iframe) {
|
|
@@ -4210,6 +4218,7 @@ class EmbeddedTarget {
|
|
|
4210
4218
|
finalizeFailure(new AlgeoError('iframe 初始化失败', EMBED_ERROR_CODES.IFRAME_NOT_READY));
|
|
4211
4219
|
});
|
|
4212
4220
|
this.container.appendChild(iframe);
|
|
4221
|
+
this.setupResizeObserver();
|
|
4213
4222
|
initTimeoutId = setTimeout(() => {
|
|
4214
4223
|
finalizeFailure(new AlgeoError('iframe 初始化超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4215
4224
|
}, EMBED_TIMEOUT_MS);
|
|
@@ -4224,6 +4233,7 @@ class EmbeddedTarget {
|
|
|
4224
4233
|
}
|
|
4225
4234
|
this._ready = true;
|
|
4226
4235
|
this._version = data.version;
|
|
4236
|
+
this.resize();
|
|
4227
4237
|
this.emit('ready', {
|
|
4228
4238
|
type: 'ready',
|
|
4229
4239
|
mode: this.embedMode,
|
|
@@ -4295,11 +4305,42 @@ class EmbeddedTarget {
|
|
|
4295
4305
|
}
|
|
4296
4306
|
this.iframe?.contentWindow?.postMessage({ type, ...payload }, '*');
|
|
4297
4307
|
}
|
|
4308
|
+
/**
|
|
4309
|
+
* 让内嵌页重新测量尺寸并重绘画布:向 iframe 发送 `resize` 事件。
|
|
4310
|
+
* 真正的重绘逻辑由内嵌页(bridge)监听该消息后执行。
|
|
4311
|
+
*/
|
|
4312
|
+
setupResizeObserver() {
|
|
4313
|
+
if (typeof ResizeObserver === 'undefined' || !this.container) {
|
|
4314
|
+
return;
|
|
4315
|
+
}
|
|
4316
|
+
this.lastContainerSize = {
|
|
4317
|
+
width: this.container.clientWidth,
|
|
4318
|
+
height: this.container.clientHeight,
|
|
4319
|
+
};
|
|
4320
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
4321
|
+
const width = this.container.clientWidth;
|
|
4322
|
+
const height = this.container.clientHeight;
|
|
4323
|
+
const prev = this.lastContainerSize;
|
|
4324
|
+
this.lastContainerSize = { width, height };
|
|
4325
|
+
const becameVisible = (prev.width === 0 || prev.height === 0) && width > 0 && height > 0;
|
|
4326
|
+
if (becameVisible) {
|
|
4327
|
+
this.resize();
|
|
4328
|
+
}
|
|
4329
|
+
});
|
|
4330
|
+
this.resizeObserver.observe(this.container);
|
|
4331
|
+
}
|
|
4332
|
+
cleanupResizeObserver() {
|
|
4333
|
+
if (this.resizeObserver) {
|
|
4334
|
+
this.resizeObserver.disconnect();
|
|
4335
|
+
this.resizeObserver = undefined;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4298
4338
|
async destroy() {
|
|
4299
4339
|
if (this.destroyed) {
|
|
4300
4340
|
return;
|
|
4301
4341
|
}
|
|
4302
4342
|
this.destroyed = true;
|
|
4343
|
+
this.cleanupResizeObserver();
|
|
4303
4344
|
this.cleanupMessageHandler();
|
|
4304
4345
|
this.resetRuntimeState();
|
|
4305
4346
|
this.pending.forEach(({ reject }) => {
|
|
@@ -4335,6 +4376,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4335
4376
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4336
4377
|
await this.init({
|
|
4337
4378
|
baseUrl,
|
|
4379
|
+
auth: options.auth,
|
|
4338
4380
|
initialId: options.shareId,
|
|
4339
4381
|
});
|
|
4340
4382
|
if (Object.keys(this.uiConfig).length > 0) {
|
|
@@ -4435,9 +4477,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4435
4477
|
await this.refreshHistoryState();
|
|
4436
4478
|
},
|
|
4437
4479
|
exportImage: async (options) => {
|
|
4438
|
-
const result = await this.post('exportSlideImage', { options
|
|
4480
|
+
const result = await this.post('exportSlideImage', { options });
|
|
4439
4481
|
return result.images;
|
|
4440
4482
|
},
|
|
4483
|
+
exportLatex: async (options) => {
|
|
4484
|
+
const result = await this.post('exportLatex', {
|
|
4485
|
+
options: options ?? {},
|
|
4486
|
+
});
|
|
4487
|
+
return result.items;
|
|
4488
|
+
},
|
|
4441
4489
|
};
|
|
4442
4490
|
this.history = {
|
|
4443
4491
|
getCount: () => this.historyCount,
|
|
@@ -4832,7 +4880,7 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4832
4880
|
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4833
4881
|
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4834
4882
|
async function checkPresentationWhitelist(options) {
|
|
4835
|
-
const appId = options.appId?.trim() ?? '';
|
|
4883
|
+
const appId = options.auth?.appId?.trim() ?? '';
|
|
4836
4884
|
const host = window.location.host.trim();
|
|
4837
4885
|
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4838
4886
|
url.searchParams.set('appId', appId);
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -4009,9 +4009,9 @@ function convertToLatest(content) {
|
|
|
4009
4009
|
}
|
|
4010
4010
|
|
|
4011
4011
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4012
|
-
const VERSION = '2.9.
|
|
4012
|
+
const VERSION = '2.9.2';
|
|
4013
4013
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4014
|
-
const DEFAULT_PRESENTATION_PATH = '/
|
|
4014
|
+
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4015
4015
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
4016
4016
|
const EMBED_TIMEOUT_MS = 30000;
|
|
4017
4017
|
let requestIdCounter = 0;
|
|
@@ -4088,18 +4088,12 @@ function buildEmbedSrc(options) {
|
|
|
4088
4088
|
const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
|
|
4089
4089
|
const mode = normalizeMode(options.mode);
|
|
4090
4090
|
const path = getEmbedPath(mode);
|
|
4091
|
-
const
|
|
4091
|
+
const appId = options.auth?.appId?.trim() ?? '';
|
|
4092
4092
|
const initialId = options.initialId?.trim();
|
|
4093
|
-
if (mode === 'editor') {
|
|
4094
|
-
if (!initialId) {
|
|
4095
|
-
return `${baseUrl}${path}/${encodeURIComponent(authAppId)}`;
|
|
4096
|
-
}
|
|
4097
|
-
return `${baseUrl}${path}/${encodeURIComponent(authAppId)}/${encodeURIComponent(initialId)}`;
|
|
4098
|
-
}
|
|
4099
4093
|
if (!initialId) {
|
|
4100
|
-
return `${baseUrl}${path}`;
|
|
4094
|
+
return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
|
|
4101
4095
|
}
|
|
4102
|
-
return `${baseUrl}${path}/${encodeURIComponent(initialId)}`;
|
|
4096
|
+
return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
|
|
4103
4097
|
}
|
|
4104
4098
|
|
|
4105
4099
|
class EmbeddedTarget {
|
|
@@ -4111,6 +4105,10 @@ class EmbeddedTarget {
|
|
|
4111
4105
|
this.destroyed = false;
|
|
4112
4106
|
this._ready = false;
|
|
4113
4107
|
this._version = null;
|
|
4108
|
+
this.lastContainerSize = {
|
|
4109
|
+
width: 0,
|
|
4110
|
+
height: 0,
|
|
4111
|
+
};
|
|
4114
4112
|
}
|
|
4115
4113
|
get ready() {
|
|
4116
4114
|
return this._ready;
|
|
@@ -4118,6 +4116,15 @@ class EmbeddedTarget {
|
|
|
4118
4116
|
get version() {
|
|
4119
4117
|
return this._version;
|
|
4120
4118
|
}
|
|
4119
|
+
/**
|
|
4120
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
4121
|
+
*/
|
|
4122
|
+
resize() {
|
|
4123
|
+
if (this.destroyed || !this._ready) {
|
|
4124
|
+
return;
|
|
4125
|
+
}
|
|
4126
|
+
this.postEvent('resize');
|
|
4127
|
+
}
|
|
4121
4128
|
on(event, listener) {
|
|
4122
4129
|
let bucket = this.listenerBuckets.get(event);
|
|
4123
4130
|
if (!bucket) {
|
|
@@ -4161,6 +4168,7 @@ class EmbeddedTarget {
|
|
|
4161
4168
|
resetRuntimeState() {
|
|
4162
4169
|
this._ready = false;
|
|
4163
4170
|
this._version = null;
|
|
4171
|
+
this.cleanupResizeObserver();
|
|
4164
4172
|
}
|
|
4165
4173
|
async init(options) {
|
|
4166
4174
|
if (this.iframe) {
|
|
@@ -4208,6 +4216,7 @@ class EmbeddedTarget {
|
|
|
4208
4216
|
finalizeFailure(new AlgeoError('iframe 初始化失败', EMBED_ERROR_CODES.IFRAME_NOT_READY));
|
|
4209
4217
|
});
|
|
4210
4218
|
this.container.appendChild(iframe);
|
|
4219
|
+
this.setupResizeObserver();
|
|
4211
4220
|
initTimeoutId = setTimeout(() => {
|
|
4212
4221
|
finalizeFailure(new AlgeoError('iframe 初始化超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4213
4222
|
}, EMBED_TIMEOUT_MS);
|
|
@@ -4222,6 +4231,7 @@ class EmbeddedTarget {
|
|
|
4222
4231
|
}
|
|
4223
4232
|
this._ready = true;
|
|
4224
4233
|
this._version = data.version;
|
|
4234
|
+
this.resize();
|
|
4225
4235
|
this.emit('ready', {
|
|
4226
4236
|
type: 'ready',
|
|
4227
4237
|
mode: this.embedMode,
|
|
@@ -4293,11 +4303,42 @@ class EmbeddedTarget {
|
|
|
4293
4303
|
}
|
|
4294
4304
|
this.iframe?.contentWindow?.postMessage({ type, ...payload }, '*');
|
|
4295
4305
|
}
|
|
4306
|
+
/**
|
|
4307
|
+
* 让内嵌页重新测量尺寸并重绘画布:向 iframe 发送 `resize` 事件。
|
|
4308
|
+
* 真正的重绘逻辑由内嵌页(bridge)监听该消息后执行。
|
|
4309
|
+
*/
|
|
4310
|
+
setupResizeObserver() {
|
|
4311
|
+
if (typeof ResizeObserver === 'undefined' || !this.container) {
|
|
4312
|
+
return;
|
|
4313
|
+
}
|
|
4314
|
+
this.lastContainerSize = {
|
|
4315
|
+
width: this.container.clientWidth,
|
|
4316
|
+
height: this.container.clientHeight,
|
|
4317
|
+
};
|
|
4318
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
4319
|
+
const width = this.container.clientWidth;
|
|
4320
|
+
const height = this.container.clientHeight;
|
|
4321
|
+
const prev = this.lastContainerSize;
|
|
4322
|
+
this.lastContainerSize = { width, height };
|
|
4323
|
+
const becameVisible = (prev.width === 0 || prev.height === 0) && width > 0 && height > 0;
|
|
4324
|
+
if (becameVisible) {
|
|
4325
|
+
this.resize();
|
|
4326
|
+
}
|
|
4327
|
+
});
|
|
4328
|
+
this.resizeObserver.observe(this.container);
|
|
4329
|
+
}
|
|
4330
|
+
cleanupResizeObserver() {
|
|
4331
|
+
if (this.resizeObserver) {
|
|
4332
|
+
this.resizeObserver.disconnect();
|
|
4333
|
+
this.resizeObserver = undefined;
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4296
4336
|
async destroy() {
|
|
4297
4337
|
if (this.destroyed) {
|
|
4298
4338
|
return;
|
|
4299
4339
|
}
|
|
4300
4340
|
this.destroyed = true;
|
|
4341
|
+
this.cleanupResizeObserver();
|
|
4301
4342
|
this.cleanupMessageHandler();
|
|
4302
4343
|
this.resetRuntimeState();
|
|
4303
4344
|
this.pending.forEach(({ reject }) => {
|
|
@@ -4333,6 +4374,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4333
4374
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4334
4375
|
await this.init({
|
|
4335
4376
|
baseUrl,
|
|
4377
|
+
auth: options.auth,
|
|
4336
4378
|
initialId: options.shareId,
|
|
4337
4379
|
});
|
|
4338
4380
|
if (Object.keys(this.uiConfig).length > 0) {
|
|
@@ -4433,9 +4475,15 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4433
4475
|
await this.refreshHistoryState();
|
|
4434
4476
|
},
|
|
4435
4477
|
exportImage: async (options) => {
|
|
4436
|
-
const result = await this.post('exportSlideImage', { options
|
|
4478
|
+
const result = await this.post('exportSlideImage', { options });
|
|
4437
4479
|
return result.images;
|
|
4438
4480
|
},
|
|
4481
|
+
exportLatex: async (options) => {
|
|
4482
|
+
const result = await this.post('exportLatex', {
|
|
4483
|
+
options: options ?? {},
|
|
4484
|
+
});
|
|
4485
|
+
return result.items;
|
|
4486
|
+
},
|
|
4439
4487
|
};
|
|
4440
4488
|
this.history = {
|
|
4441
4489
|
getCount: () => this.historyCount,
|
|
@@ -4830,7 +4878,7 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4830
4878
|
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4831
4879
|
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4832
4880
|
async function checkPresentationWhitelist(options) {
|
|
4833
|
-
const appId = options.appId?.trim() ?? '';
|
|
4881
|
+
const appId = options.auth?.appId?.trim() ?? '';
|
|
4834
4882
|
const host = window.location.host.trim();
|
|
4835
4883
|
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4836
4884
|
url.searchParams.set('appId', appId);
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -4015,9 +4015,9 @@
|
|
|
4015
4015
|
}
|
|
4016
4016
|
|
|
4017
4017
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
4018
|
-
const VERSION = '2.9.
|
|
4018
|
+
const VERSION = '2.9.2';
|
|
4019
4019
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
4020
|
-
const DEFAULT_PRESENTATION_PATH = '/
|
|
4020
|
+
const DEFAULT_PRESENTATION_PATH = '/embed/present';
|
|
4021
4021
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
4022
4022
|
const EMBED_TIMEOUT_MS = 30000;
|
|
4023
4023
|
let requestIdCounter = 0;
|
|
@@ -4094,18 +4094,12 @@
|
|
|
4094
4094
|
const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
|
|
4095
4095
|
const mode = normalizeMode(options.mode);
|
|
4096
4096
|
const path = getEmbedPath(mode);
|
|
4097
|
-
const
|
|
4097
|
+
const appId = options.auth?.appId?.trim() ?? '';
|
|
4098
4098
|
const initialId = options.initialId?.trim();
|
|
4099
|
-
if (mode === 'editor') {
|
|
4100
|
-
if (!initialId) {
|
|
4101
|
-
return `${baseUrl}${path}/${encodeURIComponent(authAppId)}`;
|
|
4102
|
-
}
|
|
4103
|
-
return `${baseUrl}${path}/${encodeURIComponent(authAppId)}/${encodeURIComponent(initialId)}`;
|
|
4104
|
-
}
|
|
4105
4099
|
if (!initialId) {
|
|
4106
|
-
return `${baseUrl}${path}`;
|
|
4100
|
+
return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
|
|
4107
4101
|
}
|
|
4108
|
-
return `${baseUrl}${path}/${encodeURIComponent(initialId)}`;
|
|
4102
|
+
return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
|
|
4109
4103
|
}
|
|
4110
4104
|
|
|
4111
4105
|
class EmbeddedTarget {
|
|
@@ -4117,6 +4111,10 @@
|
|
|
4117
4111
|
this.destroyed = false;
|
|
4118
4112
|
this._ready = false;
|
|
4119
4113
|
this._version = null;
|
|
4114
|
+
this.lastContainerSize = {
|
|
4115
|
+
width: 0,
|
|
4116
|
+
height: 0,
|
|
4117
|
+
};
|
|
4120
4118
|
}
|
|
4121
4119
|
get ready() {
|
|
4122
4120
|
return this._ready;
|
|
@@ -4124,6 +4122,15 @@
|
|
|
4124
4122
|
get version() {
|
|
4125
4123
|
return this._version;
|
|
4126
4124
|
}
|
|
4125
|
+
/**
|
|
4126
|
+
* 主动通知内嵌页重新测量尺寸并重绘画布。
|
|
4127
|
+
*/
|
|
4128
|
+
resize() {
|
|
4129
|
+
if (this.destroyed || !this._ready) {
|
|
4130
|
+
return;
|
|
4131
|
+
}
|
|
4132
|
+
this.postEvent('resize');
|
|
4133
|
+
}
|
|
4127
4134
|
on(event, listener) {
|
|
4128
4135
|
let bucket = this.listenerBuckets.get(event);
|
|
4129
4136
|
if (!bucket) {
|
|
@@ -4167,6 +4174,7 @@
|
|
|
4167
4174
|
resetRuntimeState() {
|
|
4168
4175
|
this._ready = false;
|
|
4169
4176
|
this._version = null;
|
|
4177
|
+
this.cleanupResizeObserver();
|
|
4170
4178
|
}
|
|
4171
4179
|
async init(options) {
|
|
4172
4180
|
if (this.iframe) {
|
|
@@ -4214,6 +4222,7 @@
|
|
|
4214
4222
|
finalizeFailure(new AlgeoError('iframe 初始化失败', EMBED_ERROR_CODES.IFRAME_NOT_READY));
|
|
4215
4223
|
});
|
|
4216
4224
|
this.container.appendChild(iframe);
|
|
4225
|
+
this.setupResizeObserver();
|
|
4217
4226
|
initTimeoutId = setTimeout(() => {
|
|
4218
4227
|
finalizeFailure(new AlgeoError('iframe 初始化超时', EMBED_ERROR_CODES.TIMEOUT));
|
|
4219
4228
|
}, EMBED_TIMEOUT_MS);
|
|
@@ -4228,6 +4237,7 @@
|
|
|
4228
4237
|
}
|
|
4229
4238
|
this._ready = true;
|
|
4230
4239
|
this._version = data.version;
|
|
4240
|
+
this.resize();
|
|
4231
4241
|
this.emit('ready', {
|
|
4232
4242
|
type: 'ready',
|
|
4233
4243
|
mode: this.embedMode,
|
|
@@ -4299,11 +4309,42 @@
|
|
|
4299
4309
|
}
|
|
4300
4310
|
this.iframe?.contentWindow?.postMessage({ type, ...payload }, '*');
|
|
4301
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
|
+
}
|
|
4302
4342
|
async destroy() {
|
|
4303
4343
|
if (this.destroyed) {
|
|
4304
4344
|
return;
|
|
4305
4345
|
}
|
|
4306
4346
|
this.destroyed = true;
|
|
4347
|
+
this.cleanupResizeObserver();
|
|
4307
4348
|
this.cleanupMessageHandler();
|
|
4308
4349
|
this.resetRuntimeState();
|
|
4309
4350
|
this.pending.forEach(({ reject }) => {
|
|
@@ -4339,6 +4380,7 @@
|
|
|
4339
4380
|
this.uiConfig = options.ui ? { ...options.ui } : {};
|
|
4340
4381
|
await this.init({
|
|
4341
4382
|
baseUrl,
|
|
4383
|
+
auth: options.auth,
|
|
4342
4384
|
initialId: options.shareId,
|
|
4343
4385
|
});
|
|
4344
4386
|
if (Object.keys(this.uiConfig).length > 0) {
|
|
@@ -4439,9 +4481,15 @@
|
|
|
4439
4481
|
await this.refreshHistoryState();
|
|
4440
4482
|
},
|
|
4441
4483
|
exportImage: async (options) => {
|
|
4442
|
-
const result = await this.post('exportSlideImage', { options
|
|
4484
|
+
const result = await this.post('exportSlideImage', { options });
|
|
4443
4485
|
return result.images;
|
|
4444
4486
|
},
|
|
4487
|
+
exportLatex: async (options) => {
|
|
4488
|
+
const result = await this.post('exportLatex', {
|
|
4489
|
+
options: options ?? {},
|
|
4490
|
+
});
|
|
4491
|
+
return result.items;
|
|
4492
|
+
},
|
|
4445
4493
|
};
|
|
4446
4494
|
this.history = {
|
|
4447
4495
|
getCount: () => this.historyCount,
|
|
@@ -4836,7 +4884,7 @@
|
|
|
4836
4884
|
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4837
4885
|
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4838
4886
|
async function checkPresentationWhitelist(options) {
|
|
4839
|
-
const appId = options.appId?.trim() ?? '';
|
|
4887
|
+
const appId = options.auth?.appId?.trim() ?? '';
|
|
4840
4888
|
const host = window.location.host.trim();
|
|
4841
4889
|
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4842
4890
|
url.searchParams.set('appId', appId);
|
|
@@ -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, ExportImageFormat, 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
|
@@ -43,7 +43,7 @@ export interface AlgeoEditorCreateOptions {
|
|
|
43
43
|
ui?: AlgeoEditorUiConfig;
|
|
44
44
|
}
|
|
45
45
|
export interface AlgeoPresentationCreateOptions {
|
|
46
|
-
|
|
46
|
+
auth?: AlgeoEditorAuthOptions;
|
|
47
47
|
shareId?: string;
|
|
48
48
|
ui?: AlgeoPresentationUiConfig;
|
|
49
49
|
}
|
|
@@ -162,10 +162,67 @@ export interface ReplResult {
|
|
|
162
162
|
export interface SlideIndexResult {
|
|
163
163
|
index: number;
|
|
164
164
|
}
|
|
165
|
-
export type ExportImageFormat = 'png' | 'jpg' | 'svg'
|
|
166
|
-
|
|
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 {
|
|
167
181
|
slideIndices?: number[];
|
|
168
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
|
+
*/
|
|
223
|
+
export interface ExportSlideImageOptions {
|
|
224
|
+
slideIndices?: number[];
|
|
225
|
+
format?: ExportImageFormat | 'latex';
|
|
169
226
|
width?: number;
|
|
170
227
|
height?: number;
|
|
171
228
|
quality?: number;
|
|
@@ -182,6 +239,18 @@ export interface ExportedSlideImage {
|
|
|
182
239
|
export interface ExportSlideImageResult {
|
|
183
240
|
images: ExportedSlideImage[];
|
|
184
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
|
+
}
|
|
185
254
|
export interface GetContentResult {
|
|
186
255
|
content: FileContentLatest;
|
|
187
256
|
}
|
|
@@ -204,7 +273,20 @@ export interface SlidesApi {
|
|
|
204
273
|
remove(index: number): Promise<void>;
|
|
205
274
|
duplicate(index: number, targetIndex?: number): Promise<SlideIndexResult>;
|
|
206
275
|
reorder(fromIndex: number, toIndex: number): Promise<void>;
|
|
207
|
-
|
|
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[]>;
|
|
208
290
|
}
|
|
209
291
|
export interface HistoryApi {
|
|
210
292
|
getCount(): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dajiaoai/algeo-sdk",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.2",
|
|
4
4
|
"description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
|
|
5
5
|
"main": "dist/algeo-sdk.cjs.js",
|
|
6
6
|
"module": "dist/algeo-sdk.esm.js",
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@dajiaoai/algeo-protocol": "^1.5.2"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|