goatdee-canvas 0.0.72 → 0.0.74

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.
Binary file
package/dist/index.cjs CHANGED
@@ -2491,39 +2491,6 @@ const unmark = (id, index) => {
2491
2491
  console.warn("Canvas operation(unmark) failed:", error);
2492
2492
  }
2493
2493
  };
2494
- /**
2495
- * 获取当前激活态的标注信息。
2496
- * 配合 `onAction("mark" | "activate mark")` 使用:事件触发后按需调用,避免 dispatch 时反复算屏幕坐标。
2497
- * @category 对象操作
2498
- * @returns 激活态标注信息;无激活时返回 null
2499
- */
2500
- const getActiveMark = () => {
2501
- try {
2502
- const canvas = manager.getCanvas();
2503
- const jsonStr = canvas.getActiveMark();
2504
- return jsonStr ? JSON.parse(jsonStr) : null;
2505
- }
2506
- catch (error) {
2507
- console.warn("Canvas operation(getActiveMark) failed:", error);
2508
- return null;
2509
- }
2510
- };
2511
- /**
2512
- * 获取全部标注信息。
2513
- * @category 对象操作
2514
- * @returns 标注信息数组;无标注时返回 `[]`
2515
- */
2516
- const getAllMarks = () => {
2517
- try {
2518
- const canvas = manager.getCanvas();
2519
- const jsonStr = canvas.getAllMarks();
2520
- return jsonStr ? JSON.parse(jsonStr) : [];
2521
- }
2522
- catch (error) {
2523
- console.warn("Canvas operation(getAllMarks) failed:", error);
2524
- return [];
2525
- }
2526
- };
2527
2494
  /**
2528
2495
  * 向画布添加对象到指定父容器下。
2529
2496
  * @category 对象操作
@@ -3302,9 +3269,7 @@ var ManagerAPI = /*#__PURE__*/Object.freeze({
3302
3269
  exportImages: exportImages,
3303
3270
  exportToJSON: exportToJSON,
3304
3271
  fitToScreen: fitToScreen,
3305
- getActiveMark: getActiveMark,
3306
3272
  getActiveObjects: getActiveObjects,
3307
- getAllMarks: getAllMarks,
3308
3273
  getBounds: getBounds,
3309
3274
  getCrop: getCrop,
3310
3275
  getGPUMemoryStats: getGPUMemoryStats,
@@ -4479,8 +4444,6 @@ function useCanvasImperativeHandle(ref, args) {
4479
4444
  reportAction("unmark", { id, index });
4480
4445
  unmark(id, index);
4481
4446
  },
4482
- getActiveMark: () => getActiveMark(),
4483
- getAllMarks: () => getAllMarks(),
4484
4447
  add: async (parentId, properties) => {
4485
4448
  reportAction("add", { parentId, properties });
4486
4449
  return add(parentId, properties);
@@ -6517,16 +6480,27 @@ const DEFAULT_EXPORT_OPTIONS = {
6517
6480
  quality: 1,
6518
6481
  };
6519
6482
  /**
6520
- * 单线程 wasm 入口 URL:相对路径 `./wasm-single/ZHCanvasCoreSingle.js`。
6521
- * - 生产产物 `goatdee-canvas/dist/`:rollup `copy-wasm` 插件已把 wasm 同步到 `dist/wasm-single/`,
6522
- * `import.meta.url` `dist/index.js`,相对解析正好命中;消费者的 bundler 把它 emit 为静态资源。
6483
+ * 单线程 wasm 入口:同时显式引用 `.js` 和 `.wasm`,让 bundler 都 emit 为静态资源。
6484
+ *
6485
+ * - 生产产物 `goatdee-canvas/dist/`:rollup `copy-wasm` 插件已把两个文件同步到
6486
+ * `dist/wasm-single/`,`import.meta.url` 指向 `dist/index.js`,相对解析正好命中;
6487
+ * 消费者的 bundler(webpack/vite/rspack 等)按 `new URL(..., import.meta.url)`
6488
+ * 模式把两份资源都 emit 为带 hash 的静态资源。
6523
6489
  * - monorepo dev:源码不存在该目录,由 `apps/demo/vite.config.ts` 的 dev middleware
6524
6490
  * 把任何 `wasm-single/ZHCanvasCoreSingle.*` 请求转发到 `packages/infinite-canvas-single/wasm/`。
6491
+ *
6492
+ * ⚠️ 必须同时声明 `.wasm` 的 `new URL` 引用,否则消费者 bundler 只 emit `.js`,
6493
+ * Emscripten 运行时按 sibling 路径 fetch wasm 会拿到 SPA fallback 的 HTML,
6494
+ * 报 "expected magic word 00 61 73 6d, found 3c 21 44 4f"。
6495
+ *
6525
6496
  * 解析失败则返回 null,自动 fallback 到主线程同步导出。
6526
6497
  */
6527
- function resolveWasmUrl() {
6498
+ function resolveWasmUrls() {
6528
6499
  try {
6529
- return new URL('./wasm-single/ZHCanvasCoreSingle.js', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href;
6500
+ return {
6501
+ jsUrl: new URL('./wasm-single/ZHCanvasCoreSingle.js', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href,
6502
+ wasmBinaryUrl: new URL('./wasm-single/ZHCanvasCoreSingle.wasm', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href,
6503
+ };
6530
6504
  }
6531
6505
  catch (_a) {
6532
6506
  return null;
@@ -6540,7 +6514,7 @@ class ExportImageClient {
6540
6514
  this.pending_ = new Map();
6541
6515
  this.initPromise_ = null;
6542
6516
  // wasm 入口固定为 goatdee-canvas 自带的单线程产物;解析失败时 null,自动回主线程导出。
6543
- this.wasmUrl_ = resolveWasmUrl();
6517
+ this.wasmUrls_ = resolveWasmUrls();
6544
6518
  this.sessionLicense_ = null;
6545
6519
  this.fonts_ = null;
6546
6520
  // 已传给 worker 的图片 src,避免重复传输大 ArrayBuffer
@@ -6573,7 +6547,7 @@ class ExportImageClient {
6573
6547
  }
6574
6548
  }
6575
6549
  isConfigured() {
6576
- return !!(this.wasmUrl_ &&
6550
+ return !!(this.wasmUrls_ &&
6577
6551
  this.sessionLicense_ &&
6578
6552
  this.fonts_ &&
6579
6553
  this.fonts_.length > 0);
@@ -6628,10 +6602,10 @@ class ExportImageClient {
6628
6602
  this.worker_ = this.createWorker();
6629
6603
  this.bindMessageHandler(this.worker_);
6630
6604
  }
6631
- const wasmUrl = this.wasmUrl_;
6605
+ const { jsUrl: wasmUrl, wasmBinaryUrl } = this.wasmUrls_;
6632
6606
  const sessionLicense = this.sessionLicense_;
6633
6607
  const fonts = this.fonts_;
6634
- this.initPromise_ = this.postRequest({ type: 'INIT', wasmUrl, sessionLicense, fonts },
6608
+ this.initPromise_ = this.postRequest({ type: 'INIT', wasmUrl, wasmBinaryUrl, sessionLicense, fonts },
6635
6609
  // 字体 buffer 主 wasm 已 copy 到 heap,这里 transfer 给 worker 后主线程不再使用。
6636
6610
  fonts.map((f) => f.buffer))
6637
6611
  .then(() => undefined)