emf-converter 4.4.0 → 4.4.2

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.js CHANGED
@@ -10332,6 +10332,16 @@ function decodeImageCodecFallback(bytes) {
10332
10332
  if (!f || !validSize(f.image.descriptor.width, f.image.descriptor.height)) return null;
10333
10333
  const frame2 = (0, import_gifuct_js.decompressFrame)(f, gif.gct, true);
10334
10334
  const data = new Uint8ClampedArray(width * height * 4);
10335
+ const transparent = frame2.transparentIndex !== void 0;
10336
+ const background = transparent ? frame2.colorTable[frame2.transparentIndex] : gif.gct?.[gif.lsd.backgroundColorIndex];
10337
+ if (background) {
10338
+ for (let i = 0; i < data.length; i += 4) {
10339
+ data[i] = background[0];
10340
+ data[i + 1] = background[1];
10341
+ data[i + 2] = background[2];
10342
+ data[i + 3] = transparent ? 0 : 255;
10343
+ }
10344
+ }
10335
10345
  const { top, left, width: fw, height: fh } = frame2.dims;
10336
10346
  for (let y = 0; y < fh && top + y < height; y++) {
10337
10347
  const n = Math.min(fw, width - left);
@@ -10355,6 +10365,15 @@ function decodeImageCodecFallback(bytes) {
10355
10365
  return null;
10356
10366
  }
10357
10367
 
10368
+ // src/node-canvas-loader.ts
10369
+ async function loadNodeCanvasModule() {
10370
+ return import(
10371
+ /* webpackIgnore: true */
10372
+ /* @vite-ignore */
10373
+ '@napi-rs/canvas'
10374
+ );
10375
+ }
10376
+
10358
10377
  // src/png-encoder.ts
10359
10378
  var crcTable = null;
10360
10379
  function crc32(bytes, start, end) {
@@ -14290,11 +14309,7 @@ async function ensureNodeCanvasModule() {
14290
14309
  return nodeCanvasModule;
14291
14310
  }
14292
14311
  try {
14293
- nodeCanvasModule = await import(
14294
- /* webpackIgnore: true */
14295
- /* @vite-ignore */
14296
- '@napi-rs/canvas'
14297
- );
14312
+ nodeCanvasModule = await loadNodeCanvasModule();
14298
14313
  } catch {
14299
14314
  nodeCanvasModule = null;
14300
14315
  }
@@ -30405,6 +30420,7 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30405
30420
  }
30406
30421
  const enlarging = W >= SW && H >= SH && (W > SW || H > SH);
30407
30422
  const reducing = W < SW && H < SH;
30423
+ const mixed = W > SW && H < SH || W < SW && H > SH;
30408
30424
  if (enlarging) {
30409
30425
  halftoneDespeckle(rect, SW, SH);
30410
30426
  }
@@ -30413,6 +30429,19 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30413
30429
  }
30414
30430
  const cols = halftoneAxis(0, SW, W, flipX);
30415
30431
  const rows = halftoneAxis(0, SH, H, flipY);
30432
+ if (mixed) {
30433
+ const linear = (taps, src2, dst, reverse) => {
30434
+ if (dst <= src2) return;
30435
+ for (let i = 0; i < dst; i++) {
30436
+ const position = Math.max(0, Math.min(src2 - 1, (i + 0.5) * src2 / dst - 0.5));
30437
+ const left = Math.floor(position), fraction = position - left;
30438
+ const at = (k) => reverse ? src2 - 1 - k : k;
30439
+ taps[i] = [[at(left), 1 - fraction], [at(Math.min(src2 - 1, left + 1)), fraction]];
30440
+ }
30441
+ };
30442
+ linear(cols, SW, W, flipX);
30443
+ linear(rows, SH, H, flipY);
30444
+ }
30416
30445
  const out = new Int32Array(W * H * 3);
30417
30446
  for (let y = 0; y < H; y++) {
30418
30447
  const ys = rows[y];
@@ -30433,14 +30462,27 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30433
30462
  }
30434
30463
  }
30435
30464
  const o = (y * W + x) * 3;
30436
- out[o] = Math.floor((2 * r + total) / (2 * total));
30437
- out[o + 1] = Math.floor((2 * g + total) / (2 * total));
30438
- out[o + 2] = Math.floor((2 * b + total) / (2 * total));
30465
+ out[o] = mixed ? Math.ceil(r / total - 0.5) : Math.floor((2 * r + total) / (2 * total));
30466
+ out[o + 1] = mixed ? Math.ceil(g / total - 0.5) : Math.floor((2 * g + total) / (2 * total));
30467
+ out[o + 2] = mixed ? Math.ceil(b / total - 0.5) : Math.floor((2 * b + total) / (2 * total));
30439
30468
  }
30440
30469
  }
30441
30470
  if (reducing) {
30442
30471
  halftoneSharpen(out, W, H);
30443
30472
  }
30473
+ if (mixed) {
30474
+ const source = out.slice();
30475
+ const at = (x, y, c) => source[(Math.max(0, Math.min(H - 1, y)) * W + Math.max(0, Math.min(W - 1, x))) * 3 + c];
30476
+ for (let y = 0; y < H; y++) {
30477
+ for (let x = 0; x < W; x++) {
30478
+ for (let c = 0; c < 3; c++) {
30479
+ const v = at(x, y, c);
30480
+ const sum = W < SW ? at(x - 1, y, c) + at(x + 1, y, c) : at(x, y - 1, c) + at(x, y + 1, c);
30481
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, v + Math.floor((2 * v - sum) / 4)));
30482
+ }
30483
+ }
30484
+ }
30485
+ }
30444
30486
  for (let i = 0, o = 0; i < W * H; i++, o += 3) {
30445
30487
  data[i * 4] = out[o];
30446
30488
  data[i * 4 + 1] = out[o + 1];
package/dist/index.mjs CHANGED
@@ -10330,6 +10330,16 @@ function decodeImageCodecFallback(bytes) {
10330
10330
  if (!f || !validSize(f.image.descriptor.width, f.image.descriptor.height)) return null;
10331
10331
  const frame2 = (0, import_gifuct_js.decompressFrame)(f, gif.gct, true);
10332
10332
  const data = new Uint8ClampedArray(width * height * 4);
10333
+ const transparent = frame2.transparentIndex !== void 0;
10334
+ const background = transparent ? frame2.colorTable[frame2.transparentIndex] : gif.gct?.[gif.lsd.backgroundColorIndex];
10335
+ if (background) {
10336
+ for (let i = 0; i < data.length; i += 4) {
10337
+ data[i] = background[0];
10338
+ data[i + 1] = background[1];
10339
+ data[i + 2] = background[2];
10340
+ data[i + 3] = transparent ? 0 : 255;
10341
+ }
10342
+ }
10333
10343
  const { top, left, width: fw, height: fh } = frame2.dims;
10334
10344
  for (let y = 0; y < fh && top + y < height; y++) {
10335
10345
  const n = Math.min(fw, width - left);
@@ -10353,6 +10363,15 @@ function decodeImageCodecFallback(bytes) {
10353
10363
  return null;
10354
10364
  }
10355
10365
 
10366
+ // src/node-canvas-loader.ts
10367
+ async function loadNodeCanvasModule() {
10368
+ return import(
10369
+ /* webpackIgnore: true */
10370
+ /* @vite-ignore */
10371
+ '@napi-rs/canvas'
10372
+ );
10373
+ }
10374
+
10356
10375
  // src/png-encoder.ts
10357
10376
  var crcTable = null;
10358
10377
  function crc32(bytes, start, end) {
@@ -14288,11 +14307,7 @@ async function ensureNodeCanvasModule() {
14288
14307
  return nodeCanvasModule;
14289
14308
  }
14290
14309
  try {
14291
- nodeCanvasModule = await import(
14292
- /* webpackIgnore: true */
14293
- /* @vite-ignore */
14294
- '@napi-rs/canvas'
14295
- );
14310
+ nodeCanvasModule = await loadNodeCanvasModule();
14296
14311
  } catch {
14297
14312
  nodeCanvasModule = null;
14298
14313
  }
@@ -30403,6 +30418,7 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30403
30418
  }
30404
30419
  const enlarging = W >= SW && H >= SH && (W > SW || H > SH);
30405
30420
  const reducing = W < SW && H < SH;
30421
+ const mixed = W > SW && H < SH || W < SW && H > SH;
30406
30422
  if (enlarging) {
30407
30423
  halftoneDespeckle(rect, SW, SH);
30408
30424
  }
@@ -30411,6 +30427,19 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30411
30427
  }
30412
30428
  const cols = halftoneAxis(0, SW, W, flipX);
30413
30429
  const rows = halftoneAxis(0, SH, H, flipY);
30430
+ if (mixed) {
30431
+ const linear = (taps, src2, dst, reverse) => {
30432
+ if (dst <= src2) return;
30433
+ for (let i = 0; i < dst; i++) {
30434
+ const position = Math.max(0, Math.min(src2 - 1, (i + 0.5) * src2 / dst - 0.5));
30435
+ const left = Math.floor(position), fraction = position - left;
30436
+ const at = (k) => reverse ? src2 - 1 - k : k;
30437
+ taps[i] = [[at(left), 1 - fraction], [at(Math.min(src2 - 1, left + 1)), fraction]];
30438
+ }
30439
+ };
30440
+ linear(cols, SW, W, flipX);
30441
+ linear(rows, SH, H, flipY);
30442
+ }
30414
30443
  const out = new Int32Array(W * H * 3);
30415
30444
  for (let y = 0; y < H; y++) {
30416
30445
  const ys = rows[y];
@@ -30431,14 +30460,27 @@ function stretchHalftone(src, sx, sy, sw, sh, dw, dh, adjust) {
30431
30460
  }
30432
30461
  }
30433
30462
  const o = (y * W + x) * 3;
30434
- out[o] = Math.floor((2 * r + total) / (2 * total));
30435
- out[o + 1] = Math.floor((2 * g + total) / (2 * total));
30436
- out[o + 2] = Math.floor((2 * b + total) / (2 * total));
30463
+ out[o] = mixed ? Math.ceil(r / total - 0.5) : Math.floor((2 * r + total) / (2 * total));
30464
+ out[o + 1] = mixed ? Math.ceil(g / total - 0.5) : Math.floor((2 * g + total) / (2 * total));
30465
+ out[o + 2] = mixed ? Math.ceil(b / total - 0.5) : Math.floor((2 * b + total) / (2 * total));
30437
30466
  }
30438
30467
  }
30439
30468
  if (reducing) {
30440
30469
  halftoneSharpen(out, W, H);
30441
30470
  }
30471
+ if (mixed) {
30472
+ const source = out.slice();
30473
+ const at = (x, y, c) => source[(Math.max(0, Math.min(H - 1, y)) * W + Math.max(0, Math.min(W - 1, x))) * 3 + c];
30474
+ for (let y = 0; y < H; y++) {
30475
+ for (let x = 0; x < W; x++) {
30476
+ for (let c = 0; c < 3; c++) {
30477
+ const v = at(x, y, c);
30478
+ const sum = W < SW ? at(x - 1, y, c) + at(x + 1, y, c) : at(x, y - 1, c) + at(x, y + 1, c);
30479
+ out[(y * W + x) * 3 + c] = Math.max(0, Math.min(255, v + Math.floor((2 * v - sum) / 4)));
30480
+ }
30481
+ }
30482
+ }
30483
+ }
30442
30484
  for (let i = 0, o = 0; i < W * H; i++, o += 3) {
30443
30485
  data[i * 4] = out[o];
30444
30486
  data[i * 4 + 1] = out[o + 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.4.0",
3
+ "version": "4.4.2",
4
4
  "description": "Convert EMF/WMF metafile binaries to PNG data URLs or SVG (markup, data URL, React/JSX)",
5
5
  "keywords": [
6
6
  "canvas",
@@ -31,19 +31,25 @@
31
31
  ],
32
32
  "main": "dist/index.js",
33
33
  "module": "dist/index.mjs",
34
+ "browser": "dist/browser.mjs",
34
35
  "types": "dist/index.d.ts",
35
36
  "exports": {
36
37
  ".": {
37
38
  "types": "./dist/index.d.ts",
39
+ "browser": {
40
+ "import": "./dist/browser.mjs",
41
+ "require": "./dist/browser.js"
42
+ },
38
43
  "import": "./dist/index.mjs",
39
44
  "require": "./dist/index.js"
40
45
  }
41
46
  },
42
47
  "scripts": {
43
- "build": "tsup",
48
+ "build": "tsup && tsup --config tsup.browser.config.ts",
44
49
  "dev": "tsup --watch",
45
50
  "typecheck": "tsc --noEmit --pretty",
46
51
  "test": "vitest run",
52
+ "test:browser-package": "node scripts/check-browser-package.mjs",
47
53
  "test:watch": "vitest",
48
54
  "pack": "bun run build && bun pm pack",
49
55
  "docs:typecheck": "vue-tsc --noEmit -p docs/tsconfig.json",