@dajiaoai/algeo-sdk 2.9.0 → 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 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
  ### 方式一:演示模式
@@ -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?)` | 导出画板为图片或可编辑排版内容,返回 `ExportedSlideImage[]`,每项含 `index`、`blob`、`format`、`width`、`height`。可选参数 `slideIndices`(1-based,不传则导出全部)、`format`(`'png'`/`'jpg'`/`'svg'`/`'latex'`)、`width`、`height`、`quality`(0~1,仅 jpg)、`autoFit`、`padding` |
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)`
@@ -4011,7 +4011,7 @@ function convertToLatest(content) {
4011
4011
  }
4012
4012
 
4013
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.9.0';
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 }) => {
@@ -4435,9 +4482,15 @@ class EmbeddedEditor extends EmbeddedTarget {
4435
4482
  await this.refreshHistoryState();
4436
4483
  },
4437
4484
  exportImage: async (options) => {
4438
- const result = await this.post('exportSlideImage', { options: options ?? {} });
4485
+ const result = await this.post('exportSlideImage', { options });
4439
4486
  return result.images;
4440
4487
  },
4488
+ exportLatex: async (options) => {
4489
+ const result = await this.post('exportLatex', {
4490
+ options: options ?? {},
4491
+ });
4492
+ return result.items;
4493
+ },
4441
4494
  };
4442
4495
  this.history = {
4443
4496
  getCount: () => this.historyCount,
@@ -4009,7 +4009,7 @@ function convertToLatest(content) {
4009
4009
  }
4010
4010
 
4011
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4012
- const VERSION = '2.9.0';
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 }) => {
@@ -4433,9 +4480,15 @@ class EmbeddedEditor extends EmbeddedTarget {
4433
4480
  await this.refreshHistoryState();
4434
4481
  },
4435
4482
  exportImage: async (options) => {
4436
- const result = await this.post('exportSlideImage', { options: options ?? {} });
4483
+ const result = await this.post('exportSlideImage', { options });
4437
4484
  return result.images;
4438
4485
  },
4486
+ exportLatex: async (options) => {
4487
+ const result = await this.post('exportLatex', {
4488
+ options: options ?? {},
4489
+ });
4490
+ return result.items;
4491
+ },
4439
4492
  };
4440
4493
  this.history = {
4441
4494
  getCount: () => this.historyCount,
@@ -4015,7 +4015,7 @@
4015
4015
  }
4016
4016
 
4017
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.9.0';
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 }) => {
@@ -4439,9 +4486,15 @@
4439
4486
  await this.refreshHistoryState();
4440
4487
  },
4441
4488
  exportImage: async (options) => {
4442
- const result = await this.post('exportSlideImage', { options: options ?? {} });
4489
+ const result = await this.post('exportSlideImage', { options });
4443
4490
  return result.images;
4444
4491
  },
4492
+ exportLatex: async (options) => {
4493
+ const result = await this.post('exportLatex', {
4494
+ options: options ?? {},
4495
+ });
4496
+ return result.items;
4497
+ },
4445
4498
  };
4446
4499
  this.history = {
4447
4500
  getCount: () => this.historyCount,
@@ -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
@@ -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' | 'latex';
166
- export interface ExportSlideImageOptions {
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
- exportImage(options?: ExportSlideImageOptions): Promise<ExportedSlideImage[]>;
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.0",
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",
@@ -44,4 +44,4 @@
44
44
  "dependencies": {
45
45
  "@dajiaoai/algeo-protocol": "^1.5.2"
46
46
  }
47
- }
47
+ }