@vyaz/core 0.0.14 → 0.0.16

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.
@@ -43,13 +43,6 @@ var __export = (target, all) => {
43
43
  });
44
44
  };
45
45
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
46
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
47
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
48
- }) : x)(function(x) {
49
- if (typeof require !== "undefined")
50
- return require.apply(this, arguments);
51
- throw Error('Dynamic require of "' + x + '" is not supported');
52
- });
53
46
 
54
47
  // src/measure/canvas-polyfill.ts
55
48
  var exports_canvas_polyfill = {};
@@ -58,13 +51,26 @@ __export(exports_canvas_polyfill, {
58
51
  enableOfficeTextMeasure: () => enableOfficeTextMeasure,
59
52
  disableOfficeTextMeasure: () => disableOfficeTextMeasure
60
53
  });
61
- async function _initNodeDeps() {
54
+ function _initNodeDepsSync() {
62
55
  try {
63
- const m = await import("module");
64
- _require = m.createRequire(import.meta.url);
65
- const canvas = _require("@napi-rs/canvas");
66
- _createCanvas = canvas.createCanvas;
56
+ let moduleBuiltin = null;
57
+ if (typeof _process?.getBuiltinModule === "function") {
58
+ moduleBuiltin = _process.getBuiltinModule("module");
59
+ }
60
+ if (moduleBuiltin) {
61
+ _require = moduleBuiltin.createRequire(import.meta.url);
62
+ } else {
63
+ const cjsRequire = globalThis["require"];
64
+ if (typeof cjsRequire === "function") {
65
+ _require = cjsRequire;
66
+ }
67
+ }
68
+ if (_require) {
69
+ const canvas = _require("@napi-rs/canvas");
70
+ _createCanvas = canvas.createCanvas;
71
+ }
67
72
  } catch {
73
+ _require = null;
68
74
  _createCanvas = null;
69
75
  }
70
76
  }
@@ -170,10 +176,10 @@ function disableOfficeTextMeasure() {
170
176
  }
171
177
  }
172
178
  var _process, _require = null, _createCanvas = null, originalMeasureText, officeFontCache = null, officeEnabled = false;
173
- var init_canvas_polyfill = __esm(async () => {
179
+ var init_canvas_polyfill = __esm(() => {
174
180
  _process = typeof globalThis !== "undefined" ? globalThis.process : undefined;
175
181
  if (_process && (_process.versions?.node || _process.versions?.bun)) {
176
- await _initNodeDeps();
182
+ _initNodeDepsSync();
177
183
  }
178
184
  if (needsCanvasPolyfill()) {
179
185
  globalThis.document = {
@@ -18163,7 +18169,7 @@ function getParagraphText(paragraph) {
18163
18169
  }
18164
18170
 
18165
18171
  // src/measure/FontMetricsProvider.ts
18166
- await init_canvas_polyfill();
18172
+ init_canvas_polyfill();
18167
18173
 
18168
18174
  // src/measure/FontNotFoundError.ts
18169
18175
  class FontNotFoundError extends Error {
@@ -18274,7 +18280,7 @@ class FontMetricsProvider {
18274
18280
  }
18275
18281
  async _registerFontInternal(family, options, source, sourcePath) {
18276
18282
  const { createFontFace: createFontFace2 } = await Promise.resolve().then(() => exports_FontEngine);
18277
- const { registerCanvasFont: registerCanvasFont2 } = await init_canvas_polyfill().then(() => exports_canvas_polyfill);
18283
+ const { registerCanvasFont: registerCanvasFont2 } = await Promise.resolve().then(() => (init_canvas_polyfill(), exports_canvas_polyfill));
18278
18284
  if (typeof source === "string") {
18279
18285
  const { getFontBuffer: getFontBuffer2 } = await Promise.resolve().then(() => exports_font);
18280
18286
  source = await getFontBuffer2(source);
package/dist/index.js CHANGED
@@ -23,13 +23,26 @@ __export(exports_canvas_polyfill, {
23
23
  enableOfficeTextMeasure: () => enableOfficeTextMeasure,
24
24
  disableOfficeTextMeasure: () => disableOfficeTextMeasure
25
25
  });
26
- async function _initNodeDeps() {
26
+ function _initNodeDepsSync() {
27
27
  try {
28
- const m = await import("module");
29
- _require = m.createRequire(import.meta.url);
30
- const canvas = _require("@napi-rs/canvas");
31
- _createCanvas = canvas.createCanvas;
28
+ let moduleBuiltin = null;
29
+ if (typeof _process?.getBuiltinModule === "function") {
30
+ moduleBuiltin = _process.getBuiltinModule("module");
31
+ }
32
+ if (moduleBuiltin) {
33
+ _require = moduleBuiltin.createRequire(import.meta.url);
34
+ } else {
35
+ const cjsRequire = globalThis["require"];
36
+ if (typeof cjsRequire === "function") {
37
+ _require = cjsRequire;
38
+ }
39
+ }
40
+ if (_require) {
41
+ const canvas = _require("@napi-rs/canvas");
42
+ _createCanvas = canvas.createCanvas;
43
+ }
32
44
  } catch {
45
+ _require = null;
33
46
  _createCanvas = null;
34
47
  }
35
48
  }
@@ -135,10 +148,10 @@ function disableOfficeTextMeasure() {
135
148
  }
136
149
  }
137
150
  var _process, _require = null, _createCanvas = null, originalMeasureText, officeFontCache = null, officeEnabled = false;
138
- var init_canvas_polyfill = __esm(async () => {
151
+ var init_canvas_polyfill = __esm(() => {
139
152
  _process = typeof globalThis !== "undefined" ? globalThis.process : undefined;
140
153
  if (_process && (_process.versions?.node || _process.versions?.bun)) {
141
- await _initNodeDeps();
154
+ _initNodeDepsSync();
142
155
  }
143
156
  if (needsCanvasPolyfill()) {
144
157
  globalThis.document = {
@@ -460,7 +473,7 @@ function getParagraphText(paragraph) {
460
473
  }
461
474
 
462
475
  // src/measure/FontMetricsProvider.ts
463
- await init_canvas_polyfill();
476
+ init_canvas_polyfill();
464
477
 
465
478
  // src/measure/FontNotFoundError.ts
466
479
  class FontNotFoundError extends Error {
@@ -571,7 +584,7 @@ class FontMetricsProvider {
571
584
  }
572
585
  async _registerFontInternal(family, options, source, sourcePath) {
573
586
  const { createFontFace: createFontFace2 } = await Promise.resolve().then(() => exports_FontEngine);
574
- const { registerCanvasFont: registerCanvasFont2 } = await init_canvas_polyfill().then(() => exports_canvas_polyfill);
587
+ const { registerCanvasFont: registerCanvasFont2 } = await Promise.resolve().then(() => (init_canvas_polyfill(), exports_canvas_polyfill));
575
588
  if (typeof source === "string") {
576
589
  const { getFontBuffer: getFontBuffer2 } = await Promise.resolve().then(() => exports_font);
577
590
  source = await getFontBuffer2(source);
@@ -11,8 +11,13 @@
11
11
  * Exports enableOfficeTextMeasure / disableOfficeTextMeasure —
12
12
  * ctx.measureText override for FontEngine-based measurements in Office mode.
13
13
  *
14
- * ⚠️ All Node.js built-in module imports are dynamic (lazy) to avoid
15
- * Vite/Webpack externalization errors in browser builds.
14
+ * ⚠️ Node.js built-in module access is synchronous via process.getBuiltinModule
15
+ * (Node ≥20.16 / ≥22, Bun ≥1.1) to avoid top-level await race conditions
16
+ * in worker threads (e.g. Piscina). The previous implementation used
17
+ * `await import('module')` which created a race window where layoutTextFrame
18
+ * could be called before the polyfill initialised, returning 0×0.
19
+ *
20
+ * @see https://nodejs.org/api/process.html#processgetbuiltinmoduleid
16
21
  */
17
22
  /**
18
23
  * Register a font with @napi-rs/canvas so ctx.measureText() works in Node.js.
@@ -1 +1 @@
1
- {"version":3,"file":"canvas-polyfill.d.ts","sourceRoot":"","sources":["../../src/measure/canvas-polyfill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAwLH;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAUzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CASzE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAS/C"}
1
+ {"version":3,"file":"canvas-polyfill.d.ts","sourceRoot":"","sources":["../../src/measure/canvas-polyfill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAkNH;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAUzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CASzE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAS/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyaz/core",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",