@dajiaoai/algeo-sdk 2.9.1 → 2.10.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
@@ -34,7 +34,7 @@ import { createPresentation } from '@dajiaoai/algeo-sdk';
34
34
 
35
35
  const container = document.getElementById('algeo-container');
36
36
  const presentation = await createPresentation(container, {
37
- appId: 'YTVJDQZR',
37
+ auth: { appId: 'YTVJDQZR' },
38
38
  shareId: '33TA3484',
39
39
  ui: {
40
40
  logo: false,
@@ -65,7 +65,7 @@ presentation.mode
65
65
  ```html
66
66
  <iframe
67
67
  id="algeo-embed"
68
- src="https://dajiaoai.com/e/33TA3484"
68
+ src="https://dajiaoai.com/embed/present/YOUR_APP_ID/33TA3484"
69
69
  allow="fullscreen"
70
70
  referrerpolicy="origin"
71
71
  ></iframe>
@@ -234,7 +234,7 @@ create(container, {
234
234
 
235
235
  演示模式快捷入口。该函数负责真正创建并初始化 `EmbeddedPresentation`。
236
236
 
237
- 创建成功后,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 会被拒绝,并在控制台输出包含方法名的错误,便于接入方感知并处理。
238
238
 
239
239
  ```javascript
240
240
  create(container, {
@@ -292,15 +292,24 @@ type AlgeoCreateOptions =
292
292
 
293
293
  **AlgeoPresentationCreateOptions:**
294
294
 
295
- | 属性 | 类型 | 默认值 | 说明 |
296
- | --------- | ------------------------------------ | ------ | -------------------------------------------------------- |
297
- | `appId` | `string` | `''` | 演示模式白名单校验使用的应用标识,SDK 会用它请求校验接口 |
298
- | `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/e/:id` |
299
- | `ui` | `Partial<AlgeoPresentationUiConfig>` | - | 演示模式 UI 配置 |
295
+ | 属性 | 类型 | 默认值 | 说明 |
296
+ | --------- | ------------------------------------ | ------ | --------------------------------------------------------- |
297
+ | `auth` | `{ appId: string }` | - | 演示模式鉴权参数,`appId` 用于路由及白名单校验 |
298
+ | `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/embed/present/:appId/:id` |
299
+ | `ui` | `Partial<AlgeoPresentationUiConfig>` | - | 演示模式 UI 配置 |
300
+
301
+ **AlgeoPresentationUiConfig:**
302
+
303
+ | 属性 | 类型 | 默认值 | 说明 |
304
+ | --------------- | --------- | ------ | ------------------ |
305
+ | `logo` | `boolean` | `true` | 是否展示 logo |
306
+ | `slidePanel` | `boolean` | `true` | 是否展示画板管理器 |
307
+ | `pencilToolbar` | `boolean` | `true` | 是否展示教具栏 |
308
+ | `zoomControl` | `boolean` | `true` | 是否展示缩放栏 |
300
309
 
301
310
  默认路径规则:
302
311
 
303
- - `mode: 'presentation'` -> `/e`,若传 `presentation.shareId` 则生成 `/e/:id`
312
+ - `mode: 'presentation'` -> `/embed/present/:appId`,若传 `presentation.shareId` 则生成 `/embed/present/:appId/:id`
304
313
  - `mode: 'editor'` -> `/embed/edit/:appId`,其中 `:appId` 来自 `editor.auth.appId`;若传 `editor.shareId` 则生成 `/embed/edit/:appId/:id`
305
314
 
306
315
  **示例:**
@@ -309,7 +318,7 @@ type AlgeoCreateOptions =
309
318
  const presentation = await create(container, {
310
319
  mode: 'presentation',
311
320
  presentation: {
312
- appId: 'xxxx',
321
+ auth: { appId: 'xxxx' },
313
322
  shareId: '33TA3484',
314
323
  },
315
324
  });
@@ -488,12 +497,12 @@ const images = await editor.slides.exportImage({
488
497
  mode: 'view',
489
498
  slideIndices: [1],
490
499
  format: 'png',
491
- viewBounds: { x: -5, y: -5, width: 10, height: 10 },
500
+ viewBounds: { x: -5, y: -5, width: 10, height: 10, scale: 50 },
492
501
  pixelRatio: 2,
493
502
  });
494
503
  ```
495
504
 
496
- `viewBounds` 的位置和宽高均为世界坐标。输出尺寸为 `viewBounds × camera.scale × pixelRatio`。
505
+ `viewBounds` 的位置和宽高均为世界坐标,`scale` 为可选的相机缩放比例。省略 `scale` 时使用目标画板文件中的 `camera.scale`。
497
506
 
498
507
  适合完整包住全部内容且不限定最终宽高时使用 `contain`:
499
508
 
@@ -4011,9 +4011,9 @@ function convertToLatest(content) {
4011
4011
  }
4012
4012
 
4013
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.9.1';
4014
+ const VERSION = '2.10.0';
4015
4015
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4016
- const DEFAULT_PRESENTATION_PATH = '/e';
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 authAppId = options.auth?.appId?.trim() ?? '';
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 {
@@ -4362,7 +4356,12 @@ class EmbeddedPresentation extends EmbeddedTarget {
4362
4356
  super(container, 'presentation');
4363
4357
  this.currentSlideIndex = 0;
4364
4358
  this.slideCount = 0;
4365
- this.uiConfig = {};
4359
+ this.uiConfig = {
4360
+ logo: true,
4361
+ slidePanel: true,
4362
+ pencilToolbar: true,
4363
+ zoomControl: true,
4364
+ };
4366
4365
  this.mode = {
4367
4366
  getUiConfig: () => ({ ...this.uiConfig }),
4368
4367
  setUiConfig: async (config) => {
@@ -4379,14 +4378,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
4379
4378
  };
4380
4379
  }
4381
4380
  async initialize(options = {}, baseUrl) {
4382
- this.uiConfig = options.ui ? { ...options.ui } : {};
4381
+ this.uiConfig = {
4382
+ logo: true,
4383
+ slidePanel: true,
4384
+ pencilToolbar: true,
4385
+ zoomControl: true,
4386
+ ...options.ui,
4387
+ };
4383
4388
  await this.init({
4384
4389
  baseUrl,
4390
+ auth: options.auth,
4385
4391
  initialId: options.shareId,
4386
4392
  });
4387
- if (Object.keys(this.uiConfig).length > 0) {
4388
- await this.mode.setUiConfig(this.uiConfig);
4389
- }
4393
+ await this.mode.setUiConfig(this.uiConfig);
4390
4394
  }
4391
4395
  acceptsEventMessage() {
4392
4396
  return false;
@@ -4885,7 +4889,7 @@ class EmbeddedEditor extends EmbeddedTarget {
4885
4889
  const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
4886
4890
  const WHITELIST_CHECK_PATH = '/api/whitelist/check';
4887
4891
  async function checkPresentationWhitelist(options) {
4888
- const appId = options.appId?.trim() ?? '';
4892
+ const appId = options.auth?.appId?.trim() ?? '';
4889
4893
  const host = window.location.host.trim();
4890
4894
  const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
4891
4895
  url.searchParams.set('appId', appId);
@@ -4009,9 +4009,9 @@ function convertToLatest(content) {
4009
4009
  }
4010
4010
 
4011
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4012
- const VERSION = '2.9.1';
4012
+ const VERSION = '2.10.0';
4013
4013
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4014
- const DEFAULT_PRESENTATION_PATH = '/e';
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 authAppId = options.auth?.appId?.trim() ?? '';
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 {
@@ -4360,7 +4354,12 @@ class EmbeddedPresentation extends EmbeddedTarget {
4360
4354
  super(container, 'presentation');
4361
4355
  this.currentSlideIndex = 0;
4362
4356
  this.slideCount = 0;
4363
- this.uiConfig = {};
4357
+ this.uiConfig = {
4358
+ logo: true,
4359
+ slidePanel: true,
4360
+ pencilToolbar: true,
4361
+ zoomControl: true,
4362
+ };
4364
4363
  this.mode = {
4365
4364
  getUiConfig: () => ({ ...this.uiConfig }),
4366
4365
  setUiConfig: async (config) => {
@@ -4377,14 +4376,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
4377
4376
  };
4378
4377
  }
4379
4378
  async initialize(options = {}, baseUrl) {
4380
- this.uiConfig = options.ui ? { ...options.ui } : {};
4379
+ this.uiConfig = {
4380
+ logo: true,
4381
+ slidePanel: true,
4382
+ pencilToolbar: true,
4383
+ zoomControl: true,
4384
+ ...options.ui,
4385
+ };
4381
4386
  await this.init({
4382
4387
  baseUrl,
4388
+ auth: options.auth,
4383
4389
  initialId: options.shareId,
4384
4390
  });
4385
- if (Object.keys(this.uiConfig).length > 0) {
4386
- await this.mode.setUiConfig(this.uiConfig);
4387
- }
4391
+ await this.mode.setUiConfig(this.uiConfig);
4388
4392
  }
4389
4393
  acceptsEventMessage() {
4390
4394
  return false;
@@ -4883,7 +4887,7 @@ class EmbeddedEditor extends EmbeddedTarget {
4883
4887
  const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
4884
4888
  const WHITELIST_CHECK_PATH = '/api/whitelist/check';
4885
4889
  async function checkPresentationWhitelist(options) {
4886
- const appId = options.appId?.trim() ?? '';
4890
+ const appId = options.auth?.appId?.trim() ?? '';
4887
4891
  const host = window.location.host.trim();
4888
4892
  const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
4889
4893
  url.searchParams.set('appId', appId);
@@ -4015,9 +4015,9 @@
4015
4015
  }
4016
4016
 
4017
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.9.1';
4018
+ const VERSION = '2.10.0';
4019
4019
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4020
- const DEFAULT_PRESENTATION_PATH = '/e';
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 authAppId = options.auth?.appId?.trim() ?? '';
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 {
@@ -4366,7 +4360,12 @@
4366
4360
  super(container, 'presentation');
4367
4361
  this.currentSlideIndex = 0;
4368
4362
  this.slideCount = 0;
4369
- this.uiConfig = {};
4363
+ this.uiConfig = {
4364
+ logo: true,
4365
+ slidePanel: true,
4366
+ pencilToolbar: true,
4367
+ zoomControl: true,
4368
+ };
4370
4369
  this.mode = {
4371
4370
  getUiConfig: () => ({ ...this.uiConfig }),
4372
4371
  setUiConfig: async (config) => {
@@ -4383,14 +4382,19 @@
4383
4382
  };
4384
4383
  }
4385
4384
  async initialize(options = {}, baseUrl) {
4386
- this.uiConfig = options.ui ? { ...options.ui } : {};
4385
+ this.uiConfig = {
4386
+ logo: true,
4387
+ slidePanel: true,
4388
+ pencilToolbar: true,
4389
+ zoomControl: true,
4390
+ ...options.ui,
4391
+ };
4387
4392
  await this.init({
4388
4393
  baseUrl,
4394
+ auth: options.auth,
4389
4395
  initialId: options.shareId,
4390
4396
  });
4391
- if (Object.keys(this.uiConfig).length > 0) {
4392
- await this.mode.setUiConfig(this.uiConfig);
4393
- }
4397
+ await this.mode.setUiConfig(this.uiConfig);
4394
4398
  }
4395
4399
  acceptsEventMessage() {
4396
4400
  return false;
@@ -4889,7 +4893,7 @@
4889
4893
  const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
4890
4894
  const WHITELIST_CHECK_PATH = '/api/whitelist/check';
4891
4895
  async function checkPresentationWhitelist(options) {
4892
- const appId = options.appId?.trim() ?? '';
4896
+ const appId = options.auth?.appId?.trim() ?? '';
4893
4897
  const host = window.location.host.trim();
4894
4898
  const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
4895
4899
  url.searchParams.set('appId', appId);
package/dist/shared.d.ts CHANGED
@@ -29,6 +29,9 @@ export interface AlgeoEditorUiConfig {
29
29
  }
30
30
  export interface AlgeoPresentationUiConfig {
31
31
  logo?: boolean;
32
+ slidePanel?: boolean;
33
+ pencilToolbar?: boolean;
34
+ zoomControl?: boolean;
32
35
  }
33
36
  export type AlgeoEditorSaveResult = {
34
37
  status: 'success';
@@ -43,7 +46,7 @@ export interface AlgeoEditorCreateOptions {
43
46
  ui?: AlgeoEditorUiConfig;
44
47
  }
45
48
  export interface AlgeoPresentationCreateOptions {
46
- appId?: string;
49
+ auth?: AlgeoEditorAuthOptions;
47
50
  shareId?: string;
48
51
  ui?: AlgeoPresentationUiConfig;
49
52
  }
@@ -171,6 +174,11 @@ export interface ExportViewBounds {
171
174
  y: number;
172
175
  width: number;
173
176
  height: number;
177
+ /**
178
+ * 相机缩放比例(每世界坐标单位对应的像素数)。
179
+ * 省略时使用目标画板文件中的 camera.scale。
180
+ */
181
+ scale?: number;
174
182
  }
175
183
  /** 导出留白,单位为输出像素 px。 */
176
184
  export type ExportPadding = number | {
@@ -196,8 +204,9 @@ export interface ExportImageSizeMode extends ExportImageBaseOptions {
196
204
  minPadding?: ExportPadding;
197
205
  }
198
206
  /**
199
- * 场景二(view):viewBounds 的位置及宽高均为世界坐标,渲染相机从文件读取
200
- * 输出像素 = viewBounds 世界尺寸 x camera.scale x pixelRatio。
207
+ * 场景二(view):viewBounds 的位置及宽高均为世界坐标。
208
+ * scale 省略时从文件的 camera.scale 读取。
209
+ * 输出像素 = viewBounds 世界尺寸 x viewBounds.scale x pixelRatio。
201
210
  */
202
211
  export interface ExportImageViewMode extends ExportImageBaseOptions {
203
212
  mode: 'view';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",