@dajiaoai/algeo-sdk 2.10.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
4
4
 
5
+ ## 交流与支持
6
+
7
+ 欢迎扫描下方二维码加入微信群,与我们交流 SDK 接入问题、使用反馈和功能建议。
8
+
9
+ ![扫码加入大角几何微信群](./assets/wechat-community-banner.jpg)
10
+
5
11
  ## 安装
6
12
 
7
13
  ### npm
@@ -192,6 +198,38 @@ const editor = await create(document.getElementById('editor-root'), {
192
198
  });
193
199
  ```
194
200
 
201
+ ### 接入自有资源库
202
+
203
+ 编辑模式支持由宿主提供只读图片资源库。图片仍由接入方存储和鉴权,SDK 只在内嵌页需要数据时调用 `query`:
204
+
205
+ ```typescript
206
+ const editor = await createEditor(document.getElementById('editor-root'), {
207
+ auth: { appId: 'xxxx' },
208
+ resourceLibrary: {
209
+ query: async (params, { signal }) => {
210
+ const response = await fetch(
211
+ `/api/material/list?page=${params.page}&pageSize=${params.pageSize}`,
212
+ { signal },
213
+ );
214
+ if (!response.ok) throw new Error('资源库请求失败');
215
+
216
+ const data = await response.json();
217
+ return {
218
+ items: data.items,
219
+ pageInfo: {
220
+ page: params.page,
221
+ pageSize: params.pageSize,
222
+ hasNext: data.hasNext,
223
+ total: data.total,
224
+ },
225
+ };
226
+ },
227
+ },
228
+ });
229
+ ```
230
+
231
+ `query` 返回的资源必须具有非空且不重复的 `id`、非空 `name`、`image/*` MIME 类型和完整 HTTP(S) URL。`width`、`height`、`size` 如提供,必须是正整数。搜索条件变化、面板关闭或 SDK 销毁时,请求可能通过 `signal` 被取消。
232
+
195
233
  ## API
196
234
 
197
235
  ### 常量
@@ -277,6 +315,7 @@ type AlgeoCreateOptions =
277
315
  | `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
278
316
  | `initialContent` | `FileContentLatest` | - | 初始化后自动注入的文件内容 |
279
317
  | `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
318
+ | `fonts` | `AlgeoFontConfig` | - | 字体资源、字体选择器列表及默认字体配置 |
280
319
 
281
320
  **AlgeoEditorUiConfig:**
282
321
 
@@ -297,6 +336,7 @@ type AlgeoCreateOptions =
297
336
  | `auth` | `{ appId: string }` | - | 演示模式鉴权参数,`appId` 用于路由及白名单校验 |
298
337
  | `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/embed/present/:appId/:id` |
299
338
  | `ui` | `Partial<AlgeoPresentationUiConfig>` | - | 演示模式 UI 配置 |
339
+ | `fonts` | `AlgeoFontConfig` | - | 字体资源及默认字体配置 |
300
340
 
301
341
  **AlgeoPresentationUiConfig:**
302
342
 
@@ -307,6 +347,58 @@ type AlgeoCreateOptions =
307
347
  | `pencilToolbar` | `boolean` | `true` | 是否展示教具栏 |
308
348
  | `zoomControl` | `boolean` | `true` | 是否展示缩放栏 |
309
349
 
350
+ **AlgeoFontConfig:**
351
+
352
+ 编辑和演示模式使用同一套字体协议。SDK 在 iframe ready 后、其他初始化操作前发送字体配置。通常使用 URL 加载字体;字体 URL 无法满足跨域要求时,可以传入 base64。
353
+
354
+ ```typescript
355
+ interface AlgeoFontConfig {
356
+ resources?: AlgeoFontResource[];
357
+ catalog?: AlgeoFontOption[];
358
+ defaultFont?: string;
359
+ }
360
+
361
+ interface AlgeoFontResource {
362
+ key: string;
363
+ source:
364
+ | { type: 'url'; url: string; format?: AlgeoFontFormat }
365
+ | {
366
+ type: 'base64';
367
+ data: string;
368
+ mimeType?: string;
369
+ format?: AlgeoFontFormat;
370
+ };
371
+ }
372
+
373
+ interface AlgeoFontOption {
374
+ key: string;
375
+ name: string;
376
+ type?: 'custom' | 'system';
377
+ }
378
+ ```
379
+
380
+ `key` 同时作为 FontFace family、CSS `font-family` 和文档字体标识。字重、字号、斜体等属于文档排版内容,不在字体配置中传递。
381
+
382
+ ```javascript
383
+ const fonts = {
384
+ resources: [
385
+ {
386
+ key: 'brand-sans',
387
+ source: {
388
+ type: 'url',
389
+ url: 'https://cdn.example.com/brand-sans.woff2',
390
+ format: 'woff2',
391
+ },
392
+ },
393
+ ],
394
+ catalog: [
395
+ { key: 'brand-sans', name: '品牌字体' },
396
+ { key: 'sans-serif', name: '系统非衬线字体', type: 'system' },
397
+ ],
398
+ defaultFont: 'brand-sans',
399
+ };
400
+ ```
401
+
310
402
  默认路径规则:
311
403
 
312
404
  - `mode: 'presentation'` -> `/embed/present/:appId`,若传 `presentation.shareId` 则生成 `/embed/present/:appId/:id`
@@ -565,9 +657,16 @@ const items = await editor.slides.exportLatex({
565
657
  interface ExportedLatex {
566
658
  index: number; // 1-based 画板索引
567
659
  code: string;
660
+ assets: Array<{ path: string; blob: Blob; mediaType: string }>;
661
+ blob: Blob; // 有图片时为 ZIP,否则为 TeX
662
+ fileName: string;
663
+ format: 'tex' | 'zip';
568
664
  }
569
665
  ```
570
666
 
667
+ `blob` 可直接下载;当画板包含图片时,ZIP 内同时包含 `slide-N.tex` 和
668
+ TikZ 通过相对路径引用的 `images/*` 文件。
669
+
571
670
  #### `editor.history`
572
671
 
573
672
  | 方法 | 说明 |
@@ -4011,7 +4011,7 @@ function convertToLatest(content) {
4011
4011
  }
4012
4012
 
4013
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.10.0';
4014
+ const VERSION = '2.12.0';
4015
4015
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4016
4016
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4017
4017
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4020,6 +4020,31 @@ let requestIdCounter = 0;
4020
4020
  function generateRequestId() {
4021
4021
  return `req-${Date.now()}-${++requestIdCounter}`;
4022
4022
  }
4023
+ function validateFontConfig(config) {
4024
+ const resourceKeys = new Set();
4025
+ for (const resource of config.resources ?? []) {
4026
+ const key = resource.key.trim();
4027
+ if (!key) {
4028
+ throw new AlgeoError('fonts.resources[].key 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
4029
+ }
4030
+ resourceKeys.add(key);
4031
+ }
4032
+ const catalogKeys = new Set();
4033
+ for (const option of config.catalog ?? []) {
4034
+ const key = option.key.trim();
4035
+ if (!key || !option.name.trim()) {
4036
+ throw new AlgeoError('fonts.catalog[] 的 key 和 name 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
4037
+ }
4038
+ if ((option.type ?? 'custom') === 'custom' && !resourceKeys.has(key)) {
4039
+ throw new AlgeoError(`自定义字体 ${key} 未提供对应的字体资源。`, EMBED_ERROR_CODES.BAD_REQUEST);
4040
+ }
4041
+ catalogKeys.add(key);
4042
+ }
4043
+ const defaultFont = config.defaultFont?.trim();
4044
+ if (defaultFont && config.catalog && !catalogKeys.has(defaultFont)) {
4045
+ throw new AlgeoError(`默认字体 ${defaultFont} 不在 fonts.catalog 中。`, EMBED_ERROR_CODES.BAD_REQUEST);
4046
+ }
4047
+ }
4023
4048
  function isResponseMessage(msg) {
4024
4049
  return (typeof msg === 'object' &&
4025
4050
  msg !== null &&
@@ -4050,6 +4075,21 @@ function isAiRequestMessage(msg) {
4050
4075
  typeof msg.payload === 'object' &&
4051
4076
  msg.payload !== null);
4052
4077
  }
4078
+ function isResourceLibraryRequestMessage(msg) {
4079
+ if (typeof msg !== 'object' || msg === null) {
4080
+ return false;
4081
+ }
4082
+ const value = msg;
4083
+ if (typeof value.requestId !== 'string') {
4084
+ return false;
4085
+ }
4086
+ if (value.type === 'resourceLibraryCancel') {
4087
+ return true;
4088
+ }
4089
+ return (value.type === 'resourceLibraryQuery' &&
4090
+ typeof value.params === 'object' &&
4091
+ value.params !== null);
4092
+ }
4053
4093
  function isEmbedEventMessage(msg) {
4054
4094
  if (typeof msg !== 'object' || msg == null || !('type' in msg)) {
4055
4095
  return false;
@@ -4256,7 +4296,9 @@ class EmbeddedTarget {
4256
4296
  pending.reject(new AlgeoError(err?.message ?? '未知错误', err?.code ?? EMBED_ERROR_CODES.UNKNOWN_ERROR, err?.details));
4257
4297
  return;
4258
4298
  }
4259
- if ((isSaveRequestMessage(data) || isAiRequestMessage(data)) &&
4299
+ if ((isSaveRequestMessage(data) ||
4300
+ isAiRequestMessage(data) ||
4301
+ isResourceLibraryRequestMessage(data)) &&
4260
4302
  this.handleRequestMessage(data, iframe.contentWindow)) {
4261
4303
  return;
4262
4304
  }
@@ -4385,11 +4427,17 @@ class EmbeddedPresentation extends EmbeddedTarget {
4385
4427
  zoomControl: true,
4386
4428
  ...options.ui,
4387
4429
  };
4430
+ if (options.fonts) {
4431
+ validateFontConfig(options.fonts);
4432
+ }
4388
4433
  await this.init({
4389
4434
  baseUrl,
4390
4435
  auth: options.auth,
4391
4436
  initialId: options.shareId,
4392
4437
  });
4438
+ if (options.fonts) {
4439
+ await this.post('setFontConfig', { config: options.fonts });
4440
+ }
4393
4441
  await this.mode.setUiConfig(this.uiConfig);
4394
4442
  }
4395
4443
  acceptsEventMessage() {
@@ -4445,6 +4493,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
4445
4493
  class EmbeddedEditor extends EmbeddedTarget {
4446
4494
  constructor(container) {
4447
4495
  super(container, 'editor');
4496
+ this.resourceLibraryRequests = new Map();
4448
4497
  this.currentSlideIndex = 0;
4449
4498
  this.slideCount = 0;
4450
4499
  this.historyCount = 0;
@@ -4549,11 +4598,21 @@ class EmbeddedEditor extends EmbeddedTarget {
4549
4598
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4550
4599
  }
4551
4600
  this.uiConfig = options.ui ? { ...options.ui } : {};
4601
+ this.resourceLibrary = options.resourceLibrary;
4602
+ if (options.fonts) {
4603
+ validateFontConfig(options.fonts);
4604
+ }
4552
4605
  await this.init({
4553
4606
  baseUrl,
4554
4607
  auth: options.auth,
4555
4608
  initialId: options.shareId,
4556
4609
  });
4610
+ if (options.fonts) {
4611
+ await this.post('setFontConfig', { config: options.fonts });
4612
+ }
4613
+ await this.post('setResourceLibraryAvailability', {
4614
+ available: Boolean(this.resourceLibrary),
4615
+ });
4557
4616
  if (Object.keys(this.uiConfig).length > 0) {
4558
4617
  await this.mode.setUiConfig(this.uiConfig);
4559
4618
  }
@@ -4589,6 +4648,15 @@ class EmbeddedEditor extends EmbeddedTarget {
4589
4648
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4590
4649
  }
4591
4650
  handleRequestMessage(message, sourceWindow) {
4651
+ if (message.type === 'resourceLibraryCancel') {
4652
+ this.resourceLibraryRequests.get(message.requestId)?.abort();
4653
+ this.resourceLibraryRequests.delete(message.requestId);
4654
+ return true;
4655
+ }
4656
+ if (message.type === 'resourceLibraryQuery') {
4657
+ void this.handleResourceLibraryQuery(message, sourceWindow);
4658
+ return true;
4659
+ }
4592
4660
  if (message.type === 'save') {
4593
4661
  void this.handleSaveRequest(message, sourceWindow);
4594
4662
  return true;
@@ -4600,9 +4668,116 @@ class EmbeddedEditor extends EmbeddedTarget {
4600
4668
  return false;
4601
4669
  }
4602
4670
  async destroy() {
4671
+ this.resourceLibraryRequests.forEach((controller) => controller.abort());
4672
+ this.resourceLibraryRequests.clear();
4603
4673
  this.cancelActiveAi('destroyed', true);
4604
4674
  await super.destroy();
4605
4675
  }
4676
+ async handleResourceLibraryQuery(message, sourceWindow) {
4677
+ const controller = new AbortController();
4678
+ this.resourceLibraryRequests.set(message.requestId, controller);
4679
+ const respond = (payload) => {
4680
+ if (!controller.signal.aborted) {
4681
+ sourceWindow.postMessage(payload, '*');
4682
+ }
4683
+ };
4684
+ try {
4685
+ if (!this.resourceLibrary) {
4686
+ throw new AlgeoError('宿主未配置 resourceLibrary.query', EMBED_ERROR_CODES.BAD_REQUEST);
4687
+ }
4688
+ this.validateResourceLibraryQuery(message.params);
4689
+ const result = await this.resourceLibrary.query(message.params, {
4690
+ signal: controller.signal,
4691
+ });
4692
+ if (controller.signal.aborted)
4693
+ return;
4694
+ this.validateResourceLibraryResult(result, message.params);
4695
+ respond({
4696
+ type: 'response',
4697
+ requestId: message.requestId,
4698
+ success: true,
4699
+ result,
4700
+ });
4701
+ }
4702
+ catch (error) {
4703
+ if (controller.signal.aborted)
4704
+ return;
4705
+ respond({
4706
+ type: 'response',
4707
+ requestId: message.requestId,
4708
+ success: false,
4709
+ error: {
4710
+ code: error instanceof AlgeoError
4711
+ ? error.code
4712
+ : EMBED_ERROR_CODES.UNKNOWN_ERROR,
4713
+ message: error instanceof Error ? error.message : String(error),
4714
+ },
4715
+ });
4716
+ }
4717
+ finally {
4718
+ if (this.resourceLibraryRequests.get(message.requestId) === controller) {
4719
+ this.resourceLibraryRequests.delete(message.requestId);
4720
+ }
4721
+ }
4722
+ }
4723
+ validateResourceLibraryQuery(params) {
4724
+ if (!Number.isInteger(params.page) ||
4725
+ params.page < 1 ||
4726
+ !Number.isInteger(params.pageSize) ||
4727
+ params.pageSize < 1 ||
4728
+ params.pageSize > 100 ||
4729
+ (params.keyword !== undefined && typeof params.keyword !== 'string') ||
4730
+ (params.mediaTypes !== undefined &&
4731
+ (!Array.isArray(params.mediaTypes) ||
4732
+ params.mediaTypes.some((value) => typeof value !== 'string')))) {
4733
+ throw new AlgeoError('资源库查询参数无效', EMBED_ERROR_CODES.BAD_REQUEST);
4734
+ }
4735
+ }
4736
+ validateResourceLibraryResult(result, params) {
4737
+ const invalid = () => {
4738
+ throw new AlgeoError('资源数据格式无效', EMBED_ERROR_CODES.BAD_REQUEST);
4739
+ };
4740
+ if (!result || !Array.isArray(result.items) || !result.pageInfo)
4741
+ invalid();
4742
+ const pageInfo = result.pageInfo;
4743
+ if (pageInfo.page !== params.page ||
4744
+ pageInfo.pageSize !== params.pageSize ||
4745
+ typeof pageInfo.hasNext !== 'boolean' ||
4746
+ (pageInfo.total !== undefined &&
4747
+ (!Number.isInteger(pageInfo.total) || pageInfo.total < 0)))
4748
+ invalid();
4749
+ const ids = new Set();
4750
+ for (const item of result.items) {
4751
+ if (!item ||
4752
+ typeof item.id !== 'string' ||
4753
+ !item.id.trim() ||
4754
+ ids.has(item.id) ||
4755
+ typeof item.name !== 'string' ||
4756
+ !item.name.trim() ||
4757
+ typeof item.mediaType !== 'string' ||
4758
+ !item.mediaType.startsWith('image/') ||
4759
+ !this.isHttpUrl(item.url) ||
4760
+ (item.thumbnailUrl !== undefined && !this.isHttpUrl(item.thumbnailUrl)))
4761
+ invalid();
4762
+ ids.add(item.id);
4763
+ for (const value of [item.width, item.height, item.size]) {
4764
+ if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {
4765
+ invalid();
4766
+ }
4767
+ }
4768
+ }
4769
+ }
4770
+ isHttpUrl(value) {
4771
+ if (typeof value !== 'string')
4772
+ return false;
4773
+ try {
4774
+ const url = new URL(value);
4775
+ return url.protocol === 'http:' || url.protocol === 'https:';
4776
+ }
4777
+ catch {
4778
+ return false;
4779
+ }
4780
+ }
4606
4781
  async loadContent(content, source) {
4607
4782
  await this.post('loadContent', { content });
4608
4783
  this.currentContent = content;
@@ -4009,7 +4009,7 @@ function convertToLatest(content) {
4009
4009
  }
4010
4010
 
4011
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4012
- const VERSION = '2.10.0';
4012
+ const VERSION = '2.12.0';
4013
4013
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4014
4014
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4015
4015
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4018,6 +4018,31 @@ let requestIdCounter = 0;
4018
4018
  function generateRequestId() {
4019
4019
  return `req-${Date.now()}-${++requestIdCounter}`;
4020
4020
  }
4021
+ function validateFontConfig(config) {
4022
+ const resourceKeys = new Set();
4023
+ for (const resource of config.resources ?? []) {
4024
+ const key = resource.key.trim();
4025
+ if (!key) {
4026
+ throw new AlgeoError('fonts.resources[].key 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
4027
+ }
4028
+ resourceKeys.add(key);
4029
+ }
4030
+ const catalogKeys = new Set();
4031
+ for (const option of config.catalog ?? []) {
4032
+ const key = option.key.trim();
4033
+ if (!key || !option.name.trim()) {
4034
+ throw new AlgeoError('fonts.catalog[] 的 key 和 name 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
4035
+ }
4036
+ if ((option.type ?? 'custom') === 'custom' && !resourceKeys.has(key)) {
4037
+ throw new AlgeoError(`自定义字体 ${key} 未提供对应的字体资源。`, EMBED_ERROR_CODES.BAD_REQUEST);
4038
+ }
4039
+ catalogKeys.add(key);
4040
+ }
4041
+ const defaultFont = config.defaultFont?.trim();
4042
+ if (defaultFont && config.catalog && !catalogKeys.has(defaultFont)) {
4043
+ throw new AlgeoError(`默认字体 ${defaultFont} 不在 fonts.catalog 中。`, EMBED_ERROR_CODES.BAD_REQUEST);
4044
+ }
4045
+ }
4021
4046
  function isResponseMessage(msg) {
4022
4047
  return (typeof msg === 'object' &&
4023
4048
  msg !== null &&
@@ -4048,6 +4073,21 @@ function isAiRequestMessage(msg) {
4048
4073
  typeof msg.payload === 'object' &&
4049
4074
  msg.payload !== null);
4050
4075
  }
4076
+ function isResourceLibraryRequestMessage(msg) {
4077
+ if (typeof msg !== 'object' || msg === null) {
4078
+ return false;
4079
+ }
4080
+ const value = msg;
4081
+ if (typeof value.requestId !== 'string') {
4082
+ return false;
4083
+ }
4084
+ if (value.type === 'resourceLibraryCancel') {
4085
+ return true;
4086
+ }
4087
+ return (value.type === 'resourceLibraryQuery' &&
4088
+ typeof value.params === 'object' &&
4089
+ value.params !== null);
4090
+ }
4051
4091
  function isEmbedEventMessage(msg) {
4052
4092
  if (typeof msg !== 'object' || msg == null || !('type' in msg)) {
4053
4093
  return false;
@@ -4254,7 +4294,9 @@ class EmbeddedTarget {
4254
4294
  pending.reject(new AlgeoError(err?.message ?? '未知错误', err?.code ?? EMBED_ERROR_CODES.UNKNOWN_ERROR, err?.details));
4255
4295
  return;
4256
4296
  }
4257
- if ((isSaveRequestMessage(data) || isAiRequestMessage(data)) &&
4297
+ if ((isSaveRequestMessage(data) ||
4298
+ isAiRequestMessage(data) ||
4299
+ isResourceLibraryRequestMessage(data)) &&
4258
4300
  this.handleRequestMessage(data, iframe.contentWindow)) {
4259
4301
  return;
4260
4302
  }
@@ -4383,11 +4425,17 @@ class EmbeddedPresentation extends EmbeddedTarget {
4383
4425
  zoomControl: true,
4384
4426
  ...options.ui,
4385
4427
  };
4428
+ if (options.fonts) {
4429
+ validateFontConfig(options.fonts);
4430
+ }
4386
4431
  await this.init({
4387
4432
  baseUrl,
4388
4433
  auth: options.auth,
4389
4434
  initialId: options.shareId,
4390
4435
  });
4436
+ if (options.fonts) {
4437
+ await this.post('setFontConfig', { config: options.fonts });
4438
+ }
4391
4439
  await this.mode.setUiConfig(this.uiConfig);
4392
4440
  }
4393
4441
  acceptsEventMessage() {
@@ -4443,6 +4491,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
4443
4491
  class EmbeddedEditor extends EmbeddedTarget {
4444
4492
  constructor(container) {
4445
4493
  super(container, 'editor');
4494
+ this.resourceLibraryRequests = new Map();
4446
4495
  this.currentSlideIndex = 0;
4447
4496
  this.slideCount = 0;
4448
4497
  this.historyCount = 0;
@@ -4547,11 +4596,21 @@ class EmbeddedEditor extends EmbeddedTarget {
4547
4596
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4548
4597
  }
4549
4598
  this.uiConfig = options.ui ? { ...options.ui } : {};
4599
+ this.resourceLibrary = options.resourceLibrary;
4600
+ if (options.fonts) {
4601
+ validateFontConfig(options.fonts);
4602
+ }
4550
4603
  await this.init({
4551
4604
  baseUrl,
4552
4605
  auth: options.auth,
4553
4606
  initialId: options.shareId,
4554
4607
  });
4608
+ if (options.fonts) {
4609
+ await this.post('setFontConfig', { config: options.fonts });
4610
+ }
4611
+ await this.post('setResourceLibraryAvailability', {
4612
+ available: Boolean(this.resourceLibrary),
4613
+ });
4555
4614
  if (Object.keys(this.uiConfig).length > 0) {
4556
4615
  await this.mode.setUiConfig(this.uiConfig);
4557
4616
  }
@@ -4587,6 +4646,15 @@ class EmbeddedEditor extends EmbeddedTarget {
4587
4646
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4588
4647
  }
4589
4648
  handleRequestMessage(message, sourceWindow) {
4649
+ if (message.type === 'resourceLibraryCancel') {
4650
+ this.resourceLibraryRequests.get(message.requestId)?.abort();
4651
+ this.resourceLibraryRequests.delete(message.requestId);
4652
+ return true;
4653
+ }
4654
+ if (message.type === 'resourceLibraryQuery') {
4655
+ void this.handleResourceLibraryQuery(message, sourceWindow);
4656
+ return true;
4657
+ }
4590
4658
  if (message.type === 'save') {
4591
4659
  void this.handleSaveRequest(message, sourceWindow);
4592
4660
  return true;
@@ -4598,9 +4666,116 @@ class EmbeddedEditor extends EmbeddedTarget {
4598
4666
  return false;
4599
4667
  }
4600
4668
  async destroy() {
4669
+ this.resourceLibraryRequests.forEach((controller) => controller.abort());
4670
+ this.resourceLibraryRequests.clear();
4601
4671
  this.cancelActiveAi('destroyed', true);
4602
4672
  await super.destroy();
4603
4673
  }
4674
+ async handleResourceLibraryQuery(message, sourceWindow) {
4675
+ const controller = new AbortController();
4676
+ this.resourceLibraryRequests.set(message.requestId, controller);
4677
+ const respond = (payload) => {
4678
+ if (!controller.signal.aborted) {
4679
+ sourceWindow.postMessage(payload, '*');
4680
+ }
4681
+ };
4682
+ try {
4683
+ if (!this.resourceLibrary) {
4684
+ throw new AlgeoError('宿主未配置 resourceLibrary.query', EMBED_ERROR_CODES.BAD_REQUEST);
4685
+ }
4686
+ this.validateResourceLibraryQuery(message.params);
4687
+ const result = await this.resourceLibrary.query(message.params, {
4688
+ signal: controller.signal,
4689
+ });
4690
+ if (controller.signal.aborted)
4691
+ return;
4692
+ this.validateResourceLibraryResult(result, message.params);
4693
+ respond({
4694
+ type: 'response',
4695
+ requestId: message.requestId,
4696
+ success: true,
4697
+ result,
4698
+ });
4699
+ }
4700
+ catch (error) {
4701
+ if (controller.signal.aborted)
4702
+ return;
4703
+ respond({
4704
+ type: 'response',
4705
+ requestId: message.requestId,
4706
+ success: false,
4707
+ error: {
4708
+ code: error instanceof AlgeoError
4709
+ ? error.code
4710
+ : EMBED_ERROR_CODES.UNKNOWN_ERROR,
4711
+ message: error instanceof Error ? error.message : String(error),
4712
+ },
4713
+ });
4714
+ }
4715
+ finally {
4716
+ if (this.resourceLibraryRequests.get(message.requestId) === controller) {
4717
+ this.resourceLibraryRequests.delete(message.requestId);
4718
+ }
4719
+ }
4720
+ }
4721
+ validateResourceLibraryQuery(params) {
4722
+ if (!Number.isInteger(params.page) ||
4723
+ params.page < 1 ||
4724
+ !Number.isInteger(params.pageSize) ||
4725
+ params.pageSize < 1 ||
4726
+ params.pageSize > 100 ||
4727
+ (params.keyword !== undefined && typeof params.keyword !== 'string') ||
4728
+ (params.mediaTypes !== undefined &&
4729
+ (!Array.isArray(params.mediaTypes) ||
4730
+ params.mediaTypes.some((value) => typeof value !== 'string')))) {
4731
+ throw new AlgeoError('资源库查询参数无效', EMBED_ERROR_CODES.BAD_REQUEST);
4732
+ }
4733
+ }
4734
+ validateResourceLibraryResult(result, params) {
4735
+ const invalid = () => {
4736
+ throw new AlgeoError('资源数据格式无效', EMBED_ERROR_CODES.BAD_REQUEST);
4737
+ };
4738
+ if (!result || !Array.isArray(result.items) || !result.pageInfo)
4739
+ invalid();
4740
+ const pageInfo = result.pageInfo;
4741
+ if (pageInfo.page !== params.page ||
4742
+ pageInfo.pageSize !== params.pageSize ||
4743
+ typeof pageInfo.hasNext !== 'boolean' ||
4744
+ (pageInfo.total !== undefined &&
4745
+ (!Number.isInteger(pageInfo.total) || pageInfo.total < 0)))
4746
+ invalid();
4747
+ const ids = new Set();
4748
+ for (const item of result.items) {
4749
+ if (!item ||
4750
+ typeof item.id !== 'string' ||
4751
+ !item.id.trim() ||
4752
+ ids.has(item.id) ||
4753
+ typeof item.name !== 'string' ||
4754
+ !item.name.trim() ||
4755
+ typeof item.mediaType !== 'string' ||
4756
+ !item.mediaType.startsWith('image/') ||
4757
+ !this.isHttpUrl(item.url) ||
4758
+ (item.thumbnailUrl !== undefined && !this.isHttpUrl(item.thumbnailUrl)))
4759
+ invalid();
4760
+ ids.add(item.id);
4761
+ for (const value of [item.width, item.height, item.size]) {
4762
+ if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {
4763
+ invalid();
4764
+ }
4765
+ }
4766
+ }
4767
+ }
4768
+ isHttpUrl(value) {
4769
+ if (typeof value !== 'string')
4770
+ return false;
4771
+ try {
4772
+ const url = new URL(value);
4773
+ return url.protocol === 'http:' || url.protocol === 'https:';
4774
+ }
4775
+ catch {
4776
+ return false;
4777
+ }
4778
+ }
4604
4779
  async loadContent(content, source) {
4605
4780
  await this.post('loadContent', { content });
4606
4781
  this.currentContent = content;
@@ -4015,7 +4015,7 @@
4015
4015
  }
4016
4016
 
4017
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.10.0';
4018
+ const VERSION = '2.12.0';
4019
4019
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4020
4020
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4021
4021
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4024,6 +4024,31 @@
4024
4024
  function generateRequestId() {
4025
4025
  return `req-${Date.now()}-${++requestIdCounter}`;
4026
4026
  }
4027
+ function validateFontConfig(config) {
4028
+ const resourceKeys = new Set();
4029
+ for (const resource of config.resources ?? []) {
4030
+ const key = resource.key.trim();
4031
+ if (!key) {
4032
+ throw new AlgeoError('fonts.resources[].key 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
4033
+ }
4034
+ resourceKeys.add(key);
4035
+ }
4036
+ const catalogKeys = new Set();
4037
+ for (const option of config.catalog ?? []) {
4038
+ const key = option.key.trim();
4039
+ if (!key || !option.name.trim()) {
4040
+ throw new AlgeoError('fonts.catalog[] 的 key 和 name 不能为空。', EMBED_ERROR_CODES.BAD_REQUEST);
4041
+ }
4042
+ if ((option.type ?? 'custom') === 'custom' && !resourceKeys.has(key)) {
4043
+ throw new AlgeoError(`自定义字体 ${key} 未提供对应的字体资源。`, EMBED_ERROR_CODES.BAD_REQUEST);
4044
+ }
4045
+ catalogKeys.add(key);
4046
+ }
4047
+ const defaultFont = config.defaultFont?.trim();
4048
+ if (defaultFont && config.catalog && !catalogKeys.has(defaultFont)) {
4049
+ throw new AlgeoError(`默认字体 ${defaultFont} 不在 fonts.catalog 中。`, EMBED_ERROR_CODES.BAD_REQUEST);
4050
+ }
4051
+ }
4027
4052
  function isResponseMessage(msg) {
4028
4053
  return (typeof msg === 'object' &&
4029
4054
  msg !== null &&
@@ -4054,6 +4079,21 @@
4054
4079
  typeof msg.payload === 'object' &&
4055
4080
  msg.payload !== null);
4056
4081
  }
4082
+ function isResourceLibraryRequestMessage(msg) {
4083
+ if (typeof msg !== 'object' || msg === null) {
4084
+ return false;
4085
+ }
4086
+ const value = msg;
4087
+ if (typeof value.requestId !== 'string') {
4088
+ return false;
4089
+ }
4090
+ if (value.type === 'resourceLibraryCancel') {
4091
+ return true;
4092
+ }
4093
+ return (value.type === 'resourceLibraryQuery' &&
4094
+ typeof value.params === 'object' &&
4095
+ value.params !== null);
4096
+ }
4057
4097
  function isEmbedEventMessage(msg) {
4058
4098
  if (typeof msg !== 'object' || msg == null || !('type' in msg)) {
4059
4099
  return false;
@@ -4260,7 +4300,9 @@
4260
4300
  pending.reject(new AlgeoError(err?.message ?? '未知错误', err?.code ?? EMBED_ERROR_CODES.UNKNOWN_ERROR, err?.details));
4261
4301
  return;
4262
4302
  }
4263
- if ((isSaveRequestMessage(data) || isAiRequestMessage(data)) &&
4303
+ if ((isSaveRequestMessage(data) ||
4304
+ isAiRequestMessage(data) ||
4305
+ isResourceLibraryRequestMessage(data)) &&
4264
4306
  this.handleRequestMessage(data, iframe.contentWindow)) {
4265
4307
  return;
4266
4308
  }
@@ -4389,11 +4431,17 @@
4389
4431
  zoomControl: true,
4390
4432
  ...options.ui,
4391
4433
  };
4434
+ if (options.fonts) {
4435
+ validateFontConfig(options.fonts);
4436
+ }
4392
4437
  await this.init({
4393
4438
  baseUrl,
4394
4439
  auth: options.auth,
4395
4440
  initialId: options.shareId,
4396
4441
  });
4442
+ if (options.fonts) {
4443
+ await this.post('setFontConfig', { config: options.fonts });
4444
+ }
4397
4445
  await this.mode.setUiConfig(this.uiConfig);
4398
4446
  }
4399
4447
  acceptsEventMessage() {
@@ -4449,6 +4497,7 @@
4449
4497
  class EmbeddedEditor extends EmbeddedTarget {
4450
4498
  constructor(container) {
4451
4499
  super(container, 'editor');
4500
+ this.resourceLibraryRequests = new Map();
4452
4501
  this.currentSlideIndex = 0;
4453
4502
  this.slideCount = 0;
4454
4503
  this.historyCount = 0;
@@ -4553,11 +4602,21 @@
4553
4602
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4554
4603
  }
4555
4604
  this.uiConfig = options.ui ? { ...options.ui } : {};
4605
+ this.resourceLibrary = options.resourceLibrary;
4606
+ if (options.fonts) {
4607
+ validateFontConfig(options.fonts);
4608
+ }
4556
4609
  await this.init({
4557
4610
  baseUrl,
4558
4611
  auth: options.auth,
4559
4612
  initialId: options.shareId,
4560
4613
  });
4614
+ if (options.fonts) {
4615
+ await this.post('setFontConfig', { config: options.fonts });
4616
+ }
4617
+ await this.post('setResourceLibraryAvailability', {
4618
+ available: Boolean(this.resourceLibrary),
4619
+ });
4561
4620
  if (Object.keys(this.uiConfig).length > 0) {
4562
4621
  await this.mode.setUiConfig(this.uiConfig);
4563
4622
  }
@@ -4593,6 +4652,15 @@
4593
4652
  this.currentSlideIndex = Math.min(this.currentSlideIndex, Math.max(this.slideCount - 1, 0));
4594
4653
  }
4595
4654
  handleRequestMessage(message, sourceWindow) {
4655
+ if (message.type === 'resourceLibraryCancel') {
4656
+ this.resourceLibraryRequests.get(message.requestId)?.abort();
4657
+ this.resourceLibraryRequests.delete(message.requestId);
4658
+ return true;
4659
+ }
4660
+ if (message.type === 'resourceLibraryQuery') {
4661
+ void this.handleResourceLibraryQuery(message, sourceWindow);
4662
+ return true;
4663
+ }
4596
4664
  if (message.type === 'save') {
4597
4665
  void this.handleSaveRequest(message, sourceWindow);
4598
4666
  return true;
@@ -4604,9 +4672,116 @@
4604
4672
  return false;
4605
4673
  }
4606
4674
  async destroy() {
4675
+ this.resourceLibraryRequests.forEach((controller) => controller.abort());
4676
+ this.resourceLibraryRequests.clear();
4607
4677
  this.cancelActiveAi('destroyed', true);
4608
4678
  await super.destroy();
4609
4679
  }
4680
+ async handleResourceLibraryQuery(message, sourceWindow) {
4681
+ const controller = new AbortController();
4682
+ this.resourceLibraryRequests.set(message.requestId, controller);
4683
+ const respond = (payload) => {
4684
+ if (!controller.signal.aborted) {
4685
+ sourceWindow.postMessage(payload, '*');
4686
+ }
4687
+ };
4688
+ try {
4689
+ if (!this.resourceLibrary) {
4690
+ throw new AlgeoError('宿主未配置 resourceLibrary.query', EMBED_ERROR_CODES.BAD_REQUEST);
4691
+ }
4692
+ this.validateResourceLibraryQuery(message.params);
4693
+ const result = await this.resourceLibrary.query(message.params, {
4694
+ signal: controller.signal,
4695
+ });
4696
+ if (controller.signal.aborted)
4697
+ return;
4698
+ this.validateResourceLibraryResult(result, message.params);
4699
+ respond({
4700
+ type: 'response',
4701
+ requestId: message.requestId,
4702
+ success: true,
4703
+ result,
4704
+ });
4705
+ }
4706
+ catch (error) {
4707
+ if (controller.signal.aborted)
4708
+ return;
4709
+ respond({
4710
+ type: 'response',
4711
+ requestId: message.requestId,
4712
+ success: false,
4713
+ error: {
4714
+ code: error instanceof AlgeoError
4715
+ ? error.code
4716
+ : EMBED_ERROR_CODES.UNKNOWN_ERROR,
4717
+ message: error instanceof Error ? error.message : String(error),
4718
+ },
4719
+ });
4720
+ }
4721
+ finally {
4722
+ if (this.resourceLibraryRequests.get(message.requestId) === controller) {
4723
+ this.resourceLibraryRequests.delete(message.requestId);
4724
+ }
4725
+ }
4726
+ }
4727
+ validateResourceLibraryQuery(params) {
4728
+ if (!Number.isInteger(params.page) ||
4729
+ params.page < 1 ||
4730
+ !Number.isInteger(params.pageSize) ||
4731
+ params.pageSize < 1 ||
4732
+ params.pageSize > 100 ||
4733
+ (params.keyword !== undefined && typeof params.keyword !== 'string') ||
4734
+ (params.mediaTypes !== undefined &&
4735
+ (!Array.isArray(params.mediaTypes) ||
4736
+ params.mediaTypes.some((value) => typeof value !== 'string')))) {
4737
+ throw new AlgeoError('资源库查询参数无效', EMBED_ERROR_CODES.BAD_REQUEST);
4738
+ }
4739
+ }
4740
+ validateResourceLibraryResult(result, params) {
4741
+ const invalid = () => {
4742
+ throw new AlgeoError('资源数据格式无效', EMBED_ERROR_CODES.BAD_REQUEST);
4743
+ };
4744
+ if (!result || !Array.isArray(result.items) || !result.pageInfo)
4745
+ invalid();
4746
+ const pageInfo = result.pageInfo;
4747
+ if (pageInfo.page !== params.page ||
4748
+ pageInfo.pageSize !== params.pageSize ||
4749
+ typeof pageInfo.hasNext !== 'boolean' ||
4750
+ (pageInfo.total !== undefined &&
4751
+ (!Number.isInteger(pageInfo.total) || pageInfo.total < 0)))
4752
+ invalid();
4753
+ const ids = new Set();
4754
+ for (const item of result.items) {
4755
+ if (!item ||
4756
+ typeof item.id !== 'string' ||
4757
+ !item.id.trim() ||
4758
+ ids.has(item.id) ||
4759
+ typeof item.name !== 'string' ||
4760
+ !item.name.trim() ||
4761
+ typeof item.mediaType !== 'string' ||
4762
+ !item.mediaType.startsWith('image/') ||
4763
+ !this.isHttpUrl(item.url) ||
4764
+ (item.thumbnailUrl !== undefined && !this.isHttpUrl(item.thumbnailUrl)))
4765
+ invalid();
4766
+ ids.add(item.id);
4767
+ for (const value of [item.width, item.height, item.size]) {
4768
+ if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {
4769
+ invalid();
4770
+ }
4771
+ }
4772
+ }
4773
+ }
4774
+ isHttpUrl(value) {
4775
+ if (typeof value !== 'string')
4776
+ return false;
4777
+ try {
4778
+ const url = new URL(value);
4779
+ return url.protocol === 'http:' || url.protocol === 'https:';
4780
+ }
4781
+ catch {
4782
+ return false;
4783
+ }
4784
+ }
4610
4785
  async loadContent(content, source) {
4611
4786
  await this.post('loadContent', { content });
4612
4787
  this.currentContent = content;
@@ -1,6 +1,8 @@
1
1
  import { EmbeddedTarget } from './embedded-target';
2
2
  import { type AiApi, type AiCancelEvent, type AlgeoEditorCreateOptions, type ContentChangeEvent, type DocumentApi, type EmbedRequestMessage, type EmbeddedEditorEventListenerMap, type EmbeddedEditorEventMap, type EmbeddedEditorEventName, type HistoryApi, type ModeApi, type SaveEvent, type SlidesApi } from './shared';
3
3
  export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedEditorEventListenerMap> {
4
+ private resourceLibrary?;
5
+ private readonly resourceLibraryRequests;
4
6
  readonly document: DocumentApi;
5
7
  readonly slides: SlidesApi;
6
8
  readonly history: HistoryApi;
@@ -21,6 +23,10 @@ export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMa
21
23
  } | AiCancelEvent): void;
22
24
  protected handleRequestMessage(message: EmbedRequestMessage, sourceWindow: Window): boolean;
23
25
  destroy(): Promise<void>;
26
+ private handleResourceLibraryQuery;
27
+ private validateResourceLibraryQuery;
28
+ private validateResourceLibraryResult;
29
+ private isHttpUrl;
24
30
  private loadContent;
25
31
  private switchTo;
26
32
  private addSlide;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
2
2
  export type { FileContentLatest } from '@dajiaoai/algeo-protocol';
3
3
  export { convertToLatest } from '@dajiaoai/algeo-protocol';
4
- export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBounds, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
4
+ export type { AiApi, AiCancelEvent, AiRawSseEventV1, AiRequestEvent, AiRunPayloadV1, AiStreamEventV1, AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoFontConfig, AlgeoFontFormat, AlgeoFontOption, AlgeoFontResource, AlgeoFontSource, AlgeoPresentationCreateOptions, AlgeoPresentationUiConfig, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, ExportImageFormat, ExportImageOptions, ExportImageSizeMode, ExportImageViewMode, ExportImageContainMode, ExportViewBounds, ExportPadding, ExportSlideImageOptions, ExportedSlideImage, ExportSlideImageResult, ExportLatexOptions, ExportedLatex, ExportLatexResult, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, PresentationModeApi, ReadyEvent, ResourceLibraryItem, ResourceLibraryPageInfo, ResourceLibraryProvider, ResourceLibraryQuery, ResourceLibraryQueryContext, ResourceLibraryResult, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
5
5
  export { EmbeddedPresentation } from './embedded-presentation';
6
6
  export { EmbeddedEditor } from './embedded-editor';
7
7
  export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
package/dist/shared.d.ts CHANGED
@@ -33,6 +33,39 @@ export interface AlgeoPresentationUiConfig {
33
33
  pencilToolbar?: boolean;
34
34
  zoomControl?: boolean;
35
35
  }
36
+ export type AlgeoFontFormat = 'woff2' | 'woff' | 'truetype' | 'opentype';
37
+ export type AlgeoFontSource = {
38
+ type: 'url';
39
+ url: string;
40
+ format?: AlgeoFontFormat;
41
+ } | {
42
+ type: 'base64';
43
+ /** 支持纯 base64 字符串或完整的 data URL。 */
44
+ data: string;
45
+ mimeType?: string;
46
+ format?: AlgeoFontFormat;
47
+ };
48
+ export interface AlgeoFontResource {
49
+ /** 字体标识,同时作为 FontFace family、CSS font-family 和文档字体标识。 */
50
+ key: string;
51
+ source: AlgeoFontSource;
52
+ }
53
+ export interface AlgeoFontOption {
54
+ /** 对应自定义字体资源的 key,或系统 font-family。 */
55
+ key: string;
56
+ /** 字体选择器中的展示名称。 */
57
+ name: string;
58
+ /** 默认 custom;system 类型不要求存在对应字体资源。 */
59
+ type?: 'custom' | 'system';
60
+ }
61
+ export interface AlgeoFontConfig {
62
+ /** 需要在内嵌页面中加载并注册的字体文件。 */
63
+ resources?: AlgeoFontResource[];
64
+ /** 编辑器字体选择器中展示的字体及顺序。 */
65
+ catalog?: AlgeoFontOption[];
66
+ /** 新建文本使用的默认字体 key。 */
67
+ defaultFont?: string;
68
+ }
36
69
  export type AlgeoEditorSaveResult = {
37
70
  status: 'success';
38
71
  } | {
@@ -44,11 +77,51 @@ export interface AlgeoEditorCreateOptions {
44
77
  shareId?: string;
45
78
  initialContent?: FileContentLatest;
46
79
  ui?: AlgeoEditorUiConfig;
80
+ /** 字体资源、字体选择器列表及默认字体配置。 */
81
+ fonts?: AlgeoFontConfig;
82
+ /** 接入方提供的只读图片资源库。 */
83
+ resourceLibrary?: ResourceLibraryProvider;
84
+ }
85
+ export interface ResourceLibraryQuery {
86
+ /** 页码,从 1 开始。 */
87
+ page: number;
88
+ /** 每页数量,最大 100。 */
89
+ pageSize: number;
90
+ keyword?: string;
91
+ mediaTypes?: string[];
92
+ }
93
+ export interface ResourceLibraryQueryContext {
94
+ signal: AbortSignal;
95
+ }
96
+ export interface ResourceLibraryProvider {
97
+ query(params: ResourceLibraryQuery, context: ResourceLibraryQueryContext): Promise<ResourceLibraryResult>;
98
+ }
99
+ export interface ResourceLibraryItem {
100
+ id: string;
101
+ name: string;
102
+ mediaType: string;
103
+ url: string;
104
+ thumbnailUrl?: string;
105
+ width?: number;
106
+ height?: number;
107
+ size?: number;
108
+ }
109
+ export interface ResourceLibraryPageInfo {
110
+ page: number;
111
+ pageSize: number;
112
+ hasNext: boolean;
113
+ total?: number;
114
+ }
115
+ export interface ResourceLibraryResult {
116
+ items: ResourceLibraryItem[];
117
+ pageInfo: ResourceLibraryPageInfo;
47
118
  }
48
119
  export interface AlgeoPresentationCreateOptions {
49
120
  auth?: AlgeoEditorAuthOptions;
50
121
  shareId?: string;
51
122
  ui?: AlgeoPresentationUiConfig;
123
+ /** 字体资源及默认字体配置。 */
124
+ fonts?: AlgeoFontConfig;
52
125
  }
53
126
  export type AlgeoCreateOptions = {
54
127
  baseUrl?: string;
@@ -120,6 +193,15 @@ export interface AiRequestMessage {
120
193
  requestId: string;
121
194
  payload: AiRunPayloadV1;
122
195
  }
196
+ export interface ResourceLibraryQueryMessage {
197
+ type: 'resourceLibraryQuery';
198
+ requestId: string;
199
+ params: ResourceLibraryQuery;
200
+ }
201
+ export interface ResourceLibraryCancelMessage {
202
+ type: 'resourceLibraryCancel';
203
+ requestId: string;
204
+ }
123
205
  export interface EmbeddedEditorEventMap {
124
206
  ready: ReadyEvent;
125
207
  contentChange: ContentChangeEvent;
@@ -256,6 +338,16 @@ export interface ExportLatexOptions {
256
338
  export interface ExportedLatex {
257
339
  index: number;
258
340
  code: string;
341
+ /** TikZ 通过 path 引用的图片资源;调用方应保持相对目录结构落盘。 */
342
+ assets: Array<{
343
+ path: string;
344
+ blob: Blob;
345
+ mediaType: string;
346
+ }>;
347
+ /** 可直接下载的导出文件;包含图片时为 ZIP,否则为 TeX。 */
348
+ blob: Blob;
349
+ fileName: string;
350
+ format: 'tex' | 'zip';
259
351
  }
260
352
  export interface ExportLatexResult {
261
353
  items: ExportedLatex[];
@@ -318,12 +410,14 @@ export interface PresentationModeApi {
318
410
  setMasterTemplate(template: string): Promise<SetMasterTemplateResult>;
319
411
  }
320
412
  export declare function generateRequestId(): string;
413
+ export declare function validateFontConfig(config: AlgeoFontConfig): void;
321
414
  export declare function isResponseMessage(msg: unknown): msg is EmbedResponseMessage;
322
415
  export declare function isReadyMessage(msg: unknown): msg is EmbedReadyMessage;
323
416
  export type EmbedEventMessage = ContentChangeEvent | SlideChangeEvent | SaveSuccessEvent | AiCancelEvent;
324
- export type EmbedRequestMessage = SaveRequestMessage | AiRequestMessage;
417
+ export type EmbedRequestMessage = SaveRequestMessage | AiRequestMessage | ResourceLibraryQueryMessage | ResourceLibraryCancelMessage;
325
418
  export declare function isSaveRequestMessage(msg: unknown): msg is SaveRequestMessage;
326
419
  export declare function isAiRequestMessage(msg: unknown): msg is AiRequestMessage;
420
+ export declare function isResourceLibraryRequestMessage(msg: unknown): msg is ResourceLibraryQueryMessage | ResourceLibraryCancelMessage;
327
421
  export declare function isEmbedEventMessage(msg: unknown): msg is EmbedEventMessage;
328
422
  export declare function normalizeBaseUrl(baseUrl: string): string;
329
423
  export declare function normalizeMode(mode?: AlgeoEmbedMode): AlgeoEmbedMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.10.0",
3
+ "version": "2.12.0",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",