goatdee-canvas 0.0.73 → 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.
package/dist/index.cjs CHANGED
@@ -6480,16 +6480,27 @@ const DEFAULT_EXPORT_OPTIONS = {
6480
6480
  quality: 1,
6481
6481
  };
6482
6482
  /**
6483
- * 单线程 wasm 入口 URL:相对路径 `./wasm-single/ZHCanvasCoreSingle.js`。
6484
- * - 生产产物 `goatdee-canvas/dist/`:rollup `copy-wasm` 插件已把 wasm 同步到 `dist/wasm-single/`,
6485
- * `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 的静态资源。
6486
6489
  * - monorepo dev:源码不存在该目录,由 `apps/demo/vite.config.ts` 的 dev middleware
6487
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
+ *
6488
6496
  * 解析失败则返回 null,自动 fallback 到主线程同步导出。
6489
6497
  */
6490
- function resolveWasmUrl() {
6498
+ function resolveWasmUrls() {
6491
6499
  try {
6492
- 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
+ };
6493
6504
  }
6494
6505
  catch (_a) {
6495
6506
  return null;
@@ -6503,7 +6514,7 @@ class ExportImageClient {
6503
6514
  this.pending_ = new Map();
6504
6515
  this.initPromise_ = null;
6505
6516
  // wasm 入口固定为 goatdee-canvas 自带的单线程产物;解析失败时 null,自动回主线程导出。
6506
- this.wasmUrl_ = resolveWasmUrl();
6517
+ this.wasmUrls_ = resolveWasmUrls();
6507
6518
  this.sessionLicense_ = null;
6508
6519
  this.fonts_ = null;
6509
6520
  // 已传给 worker 的图片 src,避免重复传输大 ArrayBuffer
@@ -6536,7 +6547,7 @@ class ExportImageClient {
6536
6547
  }
6537
6548
  }
6538
6549
  isConfigured() {
6539
- return !!(this.wasmUrl_ &&
6550
+ return !!(this.wasmUrls_ &&
6540
6551
  this.sessionLicense_ &&
6541
6552
  this.fonts_ &&
6542
6553
  this.fonts_.length > 0);
@@ -6591,10 +6602,10 @@ class ExportImageClient {
6591
6602
  this.worker_ = this.createWorker();
6592
6603
  this.bindMessageHandler(this.worker_);
6593
6604
  }
6594
- const wasmUrl = this.wasmUrl_;
6605
+ const { jsUrl: wasmUrl, wasmBinaryUrl } = this.wasmUrls_;
6595
6606
  const sessionLicense = this.sessionLicense_;
6596
6607
  const fonts = this.fonts_;
6597
- this.initPromise_ = this.postRequest({ type: 'INIT', wasmUrl, sessionLicense, fonts },
6608
+ this.initPromise_ = this.postRequest({ type: 'INIT', wasmUrl, wasmBinaryUrl, sessionLicense, fonts },
6598
6609
  // 字体 buffer 主 wasm 已 copy 到 heap,这里 transfer 给 worker 后主线程不再使用。
6599
6610
  fonts.map((f) => f.buffer))
6600
6611
  .then(() => undefined)