@dajiaoai/algeo-sdk 2.15.3 → 2.16.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
@@ -2,7 +2,7 @@
2
2
 
3
3
  大角几何内嵌画板 SDK,支持在任意网页中嵌入几何画板,通过 postMessage 与内嵌页通信。
4
4
 
5
- 当前版本:**2.15.3**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.15.3)。
5
+ 当前版本:**2.16.1**。版本变更与升级注意事项见 [GitHub Release](https://github.com/dajiaoai/algeo-sdk/releases/tag/2.16.1)。
6
6
 
7
7
  ## 交流与支持
8
8
 
@@ -35,6 +35,15 @@ npm install @dajiaoai/algeo-sdk
35
35
 
36
36
  ## 使用方式
37
37
 
38
+ ### 本地 HTML 文件
39
+
40
+ 通过 `file://` 直接打开 HTML 时,演示和编辑模式都可以省略 `auth` 或将 `appId` 留空。
41
+
42
+ ```javascript
43
+ const presentation = await createPresentation(container, { shareId: '33TA3484' });
44
+ const editor = await createEditor(container);
45
+ ```
46
+
38
47
  ### 方式一:演示模式
39
48
 
40
49
  ```javascript
@@ -4011,11 +4011,14 @@ function convertToLatest(content) {
4011
4011
  }
4012
4012
 
4013
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4014
- const VERSION = '2.15.3';
4014
+ const VERSION = '2.16.1';
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';
4018
4018
  const EMBED_TIMEOUT_MS = 30000;
4019
+ function isLocalFileHost() {
4020
+ return typeof window !== 'undefined' && window.location.protocol === 'file:';
4021
+ }
4019
4022
  let requestIdCounter = 0;
4020
4023
  function generateRequestId() {
4021
4024
  return `req-${Date.now()}-${++requestIdCounter}`;
@@ -4130,12 +4133,18 @@ function buildEmbedSrc(options) {
4130
4133
  const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
4131
4134
  const mode = normalizeMode(options.mode);
4132
4135
  const path = getEmbedPath(mode);
4133
- const appId = options.auth?.appId?.trim() ?? '';
4136
+ const localFile = isLocalFileHost();
4137
+ const appId = options.auth?.appId?.trim() || (localFile ? 'local' : '');
4134
4138
  const initialId = options.initialId?.trim();
4135
4139
  const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4136
- return mode === 'editor' && options.cameraMode
4137
- ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4138
- : src;
4140
+ const params = new URLSearchParams();
4141
+ if (mode === 'editor' && options.cameraMode) {
4142
+ params.set('cameraMode', options.cameraMode);
4143
+ }
4144
+ if (mode === 'editor' && localFile) {
4145
+ params.set('localFile', '1');
4146
+ }
4147
+ return params.size ? `${src}?${params}` : src;
4139
4148
  }
4140
4149
  const MASTER_TEMPLATE_OPERATIONS = [
4141
4150
  'listSystem',
@@ -4280,6 +4289,12 @@ class EmbeddedTarget {
4280
4289
  return;
4281
4290
  }
4282
4291
  const { data } = e;
4292
+ if (data?.type === 'localFileHostCheck' &&
4293
+ typeof data.requestId === 'string' &&
4294
+ isLocalFileHost()) {
4295
+ iframe.contentWindow?.postMessage({ type: 'localFileHostConfirmed', requestId: data.requestId }, '*');
4296
+ return;
4297
+ }
4283
4298
  if (isReadyMessage(data)) {
4284
4299
  if (this._ready) {
4285
4300
  return;
@@ -4690,7 +4705,7 @@ class EmbeddedEditor extends EmbeddedTarget {
4690
4705
  this.historyCurrentIndex = state.historyCurrentIndex;
4691
4706
  }
4692
4707
  async initialize(options = {}, baseUrl) {
4693
- if (!options.auth?.appId?.trim()) {
4708
+ if (!options.auth?.appId?.trim() && !isLocalFileHost()) {
4694
4709
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4695
4710
  }
4696
4711
  this.uiConfig = options.ui ? { ...options.ui } : {};
@@ -5203,6 +5218,8 @@ class EmbeddedEditor extends EmbeddedTarget {
5203
5218
  const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
5204
5219
  const WHITELIST_CHECK_PATH = '/api/whitelist/check';
5205
5220
  async function checkPresentationWhitelist(options) {
5221
+ if (isLocalFileHost())
5222
+ return null;
5206
5223
  const appId = options.auth?.appId?.trim() ?? '';
5207
5224
  const host = window.location.hostname.trim();
5208
5225
  const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
@@ -4009,11 +4009,14 @@ function convertToLatest(content) {
4009
4009
  }
4010
4010
 
4011
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4012
- const VERSION = '2.15.3';
4012
+ const VERSION = '2.16.1';
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';
4016
4016
  const EMBED_TIMEOUT_MS = 30000;
4017
+ function isLocalFileHost() {
4018
+ return typeof window !== 'undefined' && window.location.protocol === 'file:';
4019
+ }
4017
4020
  let requestIdCounter = 0;
4018
4021
  function generateRequestId() {
4019
4022
  return `req-${Date.now()}-${++requestIdCounter}`;
@@ -4128,12 +4131,18 @@ function buildEmbedSrc(options) {
4128
4131
  const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
4129
4132
  const mode = normalizeMode(options.mode);
4130
4133
  const path = getEmbedPath(mode);
4131
- const appId = options.auth?.appId?.trim() ?? '';
4134
+ const localFile = isLocalFileHost();
4135
+ const appId = options.auth?.appId?.trim() || (localFile ? 'local' : '');
4132
4136
  const initialId = options.initialId?.trim();
4133
4137
  const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4134
- return mode === 'editor' && options.cameraMode
4135
- ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4136
- : src;
4138
+ const params = new URLSearchParams();
4139
+ if (mode === 'editor' && options.cameraMode) {
4140
+ params.set('cameraMode', options.cameraMode);
4141
+ }
4142
+ if (mode === 'editor' && localFile) {
4143
+ params.set('localFile', '1');
4144
+ }
4145
+ return params.size ? `${src}?${params}` : src;
4137
4146
  }
4138
4147
  const MASTER_TEMPLATE_OPERATIONS = [
4139
4148
  'listSystem',
@@ -4278,6 +4287,12 @@ class EmbeddedTarget {
4278
4287
  return;
4279
4288
  }
4280
4289
  const { data } = e;
4290
+ if (data?.type === 'localFileHostCheck' &&
4291
+ typeof data.requestId === 'string' &&
4292
+ isLocalFileHost()) {
4293
+ iframe.contentWindow?.postMessage({ type: 'localFileHostConfirmed', requestId: data.requestId }, '*');
4294
+ return;
4295
+ }
4281
4296
  if (isReadyMessage(data)) {
4282
4297
  if (this._ready) {
4283
4298
  return;
@@ -4688,7 +4703,7 @@ class EmbeddedEditor extends EmbeddedTarget {
4688
4703
  this.historyCurrentIndex = state.historyCurrentIndex;
4689
4704
  }
4690
4705
  async initialize(options = {}, baseUrl) {
4691
- if (!options.auth?.appId?.trim()) {
4706
+ if (!options.auth?.appId?.trim() && !isLocalFileHost()) {
4692
4707
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4693
4708
  }
4694
4709
  this.uiConfig = options.ui ? { ...options.ui } : {};
@@ -5201,6 +5216,8 @@ class EmbeddedEditor extends EmbeddedTarget {
5201
5216
  const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
5202
5217
  const WHITELIST_CHECK_PATH = '/api/whitelist/check';
5203
5218
  async function checkPresentationWhitelist(options) {
5219
+ if (isLocalFileHost())
5220
+ return null;
5204
5221
  const appId = options.auth?.appId?.trim() ?? '';
5205
5222
  const host = window.location.hostname.trim();
5206
5223
  const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
@@ -4015,11 +4015,14 @@
4015
4015
  }
4016
4016
 
4017
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4018
- const VERSION = '2.15.3';
4018
+ const VERSION = '2.16.1';
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';
4022
4022
  const EMBED_TIMEOUT_MS = 30000;
4023
+ function isLocalFileHost() {
4024
+ return typeof window !== 'undefined' && window.location.protocol === 'file:';
4025
+ }
4023
4026
  let requestIdCounter = 0;
4024
4027
  function generateRequestId() {
4025
4028
  return `req-${Date.now()}-${++requestIdCounter}`;
@@ -4134,12 +4137,18 @@
4134
4137
  const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_EMBED_BASE);
4135
4138
  const mode = normalizeMode(options.mode);
4136
4139
  const path = getEmbedPath(mode);
4137
- const appId = options.auth?.appId?.trim() ?? '';
4140
+ const localFile = isLocalFileHost();
4141
+ const appId = options.auth?.appId?.trim() || (localFile ? 'local' : '');
4138
4142
  const initialId = options.initialId?.trim();
4139
4143
  const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4140
- return mode === 'editor' && options.cameraMode
4141
- ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4142
- : src;
4144
+ const params = new URLSearchParams();
4145
+ if (mode === 'editor' && options.cameraMode) {
4146
+ params.set('cameraMode', options.cameraMode);
4147
+ }
4148
+ if (mode === 'editor' && localFile) {
4149
+ params.set('localFile', '1');
4150
+ }
4151
+ return params.size ? `${src}?${params}` : src;
4143
4152
  }
4144
4153
  const MASTER_TEMPLATE_OPERATIONS = [
4145
4154
  'listSystem',
@@ -4284,6 +4293,12 @@
4284
4293
  return;
4285
4294
  }
4286
4295
  const { data } = e;
4296
+ if (data?.type === 'localFileHostCheck' &&
4297
+ typeof data.requestId === 'string' &&
4298
+ isLocalFileHost()) {
4299
+ iframe.contentWindow?.postMessage({ type: 'localFileHostConfirmed', requestId: data.requestId }, '*');
4300
+ return;
4301
+ }
4287
4302
  if (isReadyMessage(data)) {
4288
4303
  if (this._ready) {
4289
4304
  return;
@@ -4694,7 +4709,7 @@
4694
4709
  this.historyCurrentIndex = state.historyCurrentIndex;
4695
4710
  }
4696
4711
  async initialize(options = {}, baseUrl) {
4697
- if (!options.auth?.appId?.trim()) {
4712
+ if (!options.auth?.appId?.trim() && !isLocalFileHost()) {
4698
4713
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
4699
4714
  }
4700
4715
  this.uiConfig = options.ui ? { ...options.ui } : {};
@@ -5207,6 +5222,8 @@
5207
5222
  const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
5208
5223
  const WHITELIST_CHECK_PATH = '/api/whitelist/check';
5209
5224
  async function checkPresentationWhitelist(options) {
5225
+ if (isLocalFileHost())
5226
+ return null;
5210
5227
  const appId = options.auth?.appId?.trim() ?? '';
5211
5228
  const host = window.location.hostname.trim();
5212
5229
  const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
package/dist/shared.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface AlgeoSdkOptions {
15
15
  initialId?: string;
16
16
  }
17
17
  export type AlgeoEmbedMode = 'presentation' | 'editor';
18
+ export declare function isLocalFileHost(): boolean;
18
19
  export interface AlgeoEditorAuthOptions {
19
20
  appId: string;
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.15.3",
3
+ "version": "2.16.1",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",