emf-converter 4.4.4 → 4.4.6

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/browser.js CHANGED
@@ -10316,6 +10316,49 @@ async function decodePng(bytes) {
10316
10316
  var import_jpeg_js = __toESM(require_jpeg_js());
10317
10317
  var import_gifuct_js = __toESM(require_lib2());
10318
10318
  var UTIF = __toESM(require_UTIF());
10319
+
10320
+ // src/tiff-group3.ts
10321
+ function normalizeGroup3(buffer, page) {
10322
+ const options = Array.isArray(page.t292) ? Number(page.t292[0]) : 0;
10323
+ if (!Array.isArray(page.t259) || page.t259[0] !== 3 || (options & 3) !== 0) return buffer;
10324
+ const offsets = page.t273, lengths = page.t279;
10325
+ if (!Array.isArray(offsets) || !Array.isArray(lengths) || offsets.length !== lengths.length) return buffer;
10326
+ const source = new Uint8Array(buffer);
10327
+ const leastFirst = Array.isArray(page.t266) && page.t266[0] === 2;
10328
+ const strips = offsets.map((offset, i) => {
10329
+ const start = Number(offset), length = Number(lengths[i]);
10330
+ if (!Number.isInteger(start) || !Number.isInteger(length) || start < 0 || length < 0 || start + length > source.length) throw new Error("Invalid TIFF strip");
10331
+ const output = new Uint8Array(Math.ceil(length * 8 * 13 / 12 / 8) + 1);
10332
+ let position2 = 0, zeros = 0;
10333
+ const write = (bit) => {
10334
+ if (bit) output[position2 >>> 3] |= 1 << (leastFirst ? position2 & 7 : 7 - (position2 & 7));
10335
+ position2++;
10336
+ };
10337
+ for (let bitPosition = 0; bitPosition < length * 8; bitPosition++) {
10338
+ const bit = source[start + (bitPosition >>> 3)] >>> (leastFirst ? bitPosition & 7 : 7 - (bitPosition & 7)) & 1;
10339
+ write(bit);
10340
+ if (bit) {
10341
+ if (zeros >= 11) write(1);
10342
+ zeros = 0;
10343
+ } else zeros++;
10344
+ }
10345
+ return output.subarray(0, Math.ceil(position2 / 8));
10346
+ });
10347
+ const normalized = new Uint8Array(strips.reduce((size, strip) => size + strip.length, source.length));
10348
+ normalized.set(source);
10349
+ let position = source.length;
10350
+ page.t273 = strips.map((strip) => {
10351
+ const offset = position;
10352
+ normalized.set(strip, position);
10353
+ position += strip.length;
10354
+ return offset;
10355
+ });
10356
+ page.t279 = strips.map((strip) => strip.length);
10357
+ page.t292 = [options | 1];
10358
+ return normalized.buffer;
10359
+ }
10360
+
10361
+ // src/image-codec-fallback.ts
10319
10362
  var validSize = (w, h) => Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0 && w <= 8192 && h <= 8192;
10320
10363
  function decodeImageCodecFallback(bytes) {
10321
10364
  try {
@@ -10354,7 +10397,7 @@ function decodeImageCodecFallback(bytes) {
10354
10397
  const pages = UTIF.decode(buffer);
10355
10398
  const page = pages.find((p) => p.t256 && p.t257);
10356
10399
  if (!page || !Array.isArray(page.t256) || !Array.isArray(page.t257) || !validSize(Number(page.t256[0]), Number(page.t257[0]))) return null;
10357
- UTIF.decodeImage(buffer, page);
10400
+ UTIF.decodeImage(normalizeGroup3(buffer, page), page);
10358
10401
  const width = page.width, height = page.height;
10359
10402
  if (!validSize(width, height)) return null;
10360
10403
  const data = UTIF.toRGBA8(page);
package/dist/browser.mjs CHANGED
@@ -10314,6 +10314,49 @@ async function decodePng(bytes) {
10314
10314
  var import_jpeg_js = __toESM(require_jpeg_js());
10315
10315
  var import_gifuct_js = __toESM(require_lib2());
10316
10316
  var UTIF = __toESM(require_UTIF());
10317
+
10318
+ // src/tiff-group3.ts
10319
+ function normalizeGroup3(buffer, page) {
10320
+ const options = Array.isArray(page.t292) ? Number(page.t292[0]) : 0;
10321
+ if (!Array.isArray(page.t259) || page.t259[0] !== 3 || (options & 3) !== 0) return buffer;
10322
+ const offsets = page.t273, lengths = page.t279;
10323
+ if (!Array.isArray(offsets) || !Array.isArray(lengths) || offsets.length !== lengths.length) return buffer;
10324
+ const source = new Uint8Array(buffer);
10325
+ const leastFirst = Array.isArray(page.t266) && page.t266[0] === 2;
10326
+ const strips = offsets.map((offset, i) => {
10327
+ const start = Number(offset), length = Number(lengths[i]);
10328
+ if (!Number.isInteger(start) || !Number.isInteger(length) || start < 0 || length < 0 || start + length > source.length) throw new Error("Invalid TIFF strip");
10329
+ const output = new Uint8Array(Math.ceil(length * 8 * 13 / 12 / 8) + 1);
10330
+ let position2 = 0, zeros = 0;
10331
+ const write = (bit) => {
10332
+ if (bit) output[position2 >>> 3] |= 1 << (leastFirst ? position2 & 7 : 7 - (position2 & 7));
10333
+ position2++;
10334
+ };
10335
+ for (let bitPosition = 0; bitPosition < length * 8; bitPosition++) {
10336
+ const bit = source[start + (bitPosition >>> 3)] >>> (leastFirst ? bitPosition & 7 : 7 - (bitPosition & 7)) & 1;
10337
+ write(bit);
10338
+ if (bit) {
10339
+ if (zeros >= 11) write(1);
10340
+ zeros = 0;
10341
+ } else zeros++;
10342
+ }
10343
+ return output.subarray(0, Math.ceil(position2 / 8));
10344
+ });
10345
+ const normalized = new Uint8Array(strips.reduce((size, strip) => size + strip.length, source.length));
10346
+ normalized.set(source);
10347
+ let position = source.length;
10348
+ page.t273 = strips.map((strip) => {
10349
+ const offset = position;
10350
+ normalized.set(strip, position);
10351
+ position += strip.length;
10352
+ return offset;
10353
+ });
10354
+ page.t279 = strips.map((strip) => strip.length);
10355
+ page.t292 = [options | 1];
10356
+ return normalized.buffer;
10357
+ }
10358
+
10359
+ // src/image-codec-fallback.ts
10317
10360
  var validSize = (w, h) => Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0 && w <= 8192 && h <= 8192;
10318
10361
  function decodeImageCodecFallback(bytes) {
10319
10362
  try {
@@ -10352,7 +10395,7 @@ function decodeImageCodecFallback(bytes) {
10352
10395
  const pages = UTIF.decode(buffer);
10353
10396
  const page = pages.find((p) => p.t256 && p.t257);
10354
10397
  if (!page || !Array.isArray(page.t256) || !Array.isArray(page.t257) || !validSize(Number(page.t256[0]), Number(page.t257[0]))) return null;
10355
- UTIF.decodeImage(buffer, page);
10398
+ UTIF.decodeImage(normalizeGroup3(buffer, page), page);
10356
10399
  const width = page.width, height = page.height;
10357
10400
  if (!validSize(width, height)) return null;
10358
10401
  const data = UTIF.toRGBA8(page);
package/dist/index.js CHANGED
@@ -10316,6 +10316,49 @@ async function decodePng(bytes) {
10316
10316
  var import_jpeg_js = __toESM(require_jpeg_js());
10317
10317
  var import_gifuct_js = __toESM(require_lib2());
10318
10318
  var UTIF = __toESM(require_UTIF());
10319
+
10320
+ // src/tiff-group3.ts
10321
+ function normalizeGroup3(buffer, page) {
10322
+ const options = Array.isArray(page.t292) ? Number(page.t292[0]) : 0;
10323
+ if (!Array.isArray(page.t259) || page.t259[0] !== 3 || (options & 3) !== 0) return buffer;
10324
+ const offsets = page.t273, lengths = page.t279;
10325
+ if (!Array.isArray(offsets) || !Array.isArray(lengths) || offsets.length !== lengths.length) return buffer;
10326
+ const source = new Uint8Array(buffer);
10327
+ const leastFirst = Array.isArray(page.t266) && page.t266[0] === 2;
10328
+ const strips = offsets.map((offset, i) => {
10329
+ const start = Number(offset), length = Number(lengths[i]);
10330
+ if (!Number.isInteger(start) || !Number.isInteger(length) || start < 0 || length < 0 || start + length > source.length) throw new Error("Invalid TIFF strip");
10331
+ const output = new Uint8Array(Math.ceil(length * 8 * 13 / 12 / 8) + 1);
10332
+ let position2 = 0, zeros = 0;
10333
+ const write = (bit) => {
10334
+ if (bit) output[position2 >>> 3] |= 1 << (leastFirst ? position2 & 7 : 7 - (position2 & 7));
10335
+ position2++;
10336
+ };
10337
+ for (let bitPosition = 0; bitPosition < length * 8; bitPosition++) {
10338
+ const bit = source[start + (bitPosition >>> 3)] >>> (leastFirst ? bitPosition & 7 : 7 - (bitPosition & 7)) & 1;
10339
+ write(bit);
10340
+ if (bit) {
10341
+ if (zeros >= 11) write(1);
10342
+ zeros = 0;
10343
+ } else zeros++;
10344
+ }
10345
+ return output.subarray(0, Math.ceil(position2 / 8));
10346
+ });
10347
+ const normalized = new Uint8Array(strips.reduce((size, strip) => size + strip.length, source.length));
10348
+ normalized.set(source);
10349
+ let position = source.length;
10350
+ page.t273 = strips.map((strip) => {
10351
+ const offset = position;
10352
+ normalized.set(strip, position);
10353
+ position += strip.length;
10354
+ return offset;
10355
+ });
10356
+ page.t279 = strips.map((strip) => strip.length);
10357
+ page.t292 = [options | 1];
10358
+ return normalized.buffer;
10359
+ }
10360
+
10361
+ // src/image-codec-fallback.ts
10319
10362
  var validSize = (w, h) => Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0 && w <= 8192 && h <= 8192;
10320
10363
  function decodeImageCodecFallback(bytes) {
10321
10364
  try {
@@ -10354,7 +10397,7 @@ function decodeImageCodecFallback(bytes) {
10354
10397
  const pages = UTIF.decode(buffer);
10355
10398
  const page = pages.find((p) => p.t256 && p.t257);
10356
10399
  if (!page || !Array.isArray(page.t256) || !Array.isArray(page.t257) || !validSize(Number(page.t256[0]), Number(page.t257[0]))) return null;
10357
- UTIF.decodeImage(buffer, page);
10400
+ UTIF.decodeImage(normalizeGroup3(buffer, page), page);
10358
10401
  const width = page.width, height = page.height;
10359
10402
  if (!validSize(width, height)) return null;
10360
10403
  const data = UTIF.toRGBA8(page);
package/dist/index.mjs CHANGED
@@ -10314,6 +10314,49 @@ async function decodePng(bytes) {
10314
10314
  var import_jpeg_js = __toESM(require_jpeg_js());
10315
10315
  var import_gifuct_js = __toESM(require_lib2());
10316
10316
  var UTIF = __toESM(require_UTIF());
10317
+
10318
+ // src/tiff-group3.ts
10319
+ function normalizeGroup3(buffer, page) {
10320
+ const options = Array.isArray(page.t292) ? Number(page.t292[0]) : 0;
10321
+ if (!Array.isArray(page.t259) || page.t259[0] !== 3 || (options & 3) !== 0) return buffer;
10322
+ const offsets = page.t273, lengths = page.t279;
10323
+ if (!Array.isArray(offsets) || !Array.isArray(lengths) || offsets.length !== lengths.length) return buffer;
10324
+ const source = new Uint8Array(buffer);
10325
+ const leastFirst = Array.isArray(page.t266) && page.t266[0] === 2;
10326
+ const strips = offsets.map((offset, i) => {
10327
+ const start = Number(offset), length = Number(lengths[i]);
10328
+ if (!Number.isInteger(start) || !Number.isInteger(length) || start < 0 || length < 0 || start + length > source.length) throw new Error("Invalid TIFF strip");
10329
+ const output = new Uint8Array(Math.ceil(length * 8 * 13 / 12 / 8) + 1);
10330
+ let position2 = 0, zeros = 0;
10331
+ const write = (bit) => {
10332
+ if (bit) output[position2 >>> 3] |= 1 << (leastFirst ? position2 & 7 : 7 - (position2 & 7));
10333
+ position2++;
10334
+ };
10335
+ for (let bitPosition = 0; bitPosition < length * 8; bitPosition++) {
10336
+ const bit = source[start + (bitPosition >>> 3)] >>> (leastFirst ? bitPosition & 7 : 7 - (bitPosition & 7)) & 1;
10337
+ write(bit);
10338
+ if (bit) {
10339
+ if (zeros >= 11) write(1);
10340
+ zeros = 0;
10341
+ } else zeros++;
10342
+ }
10343
+ return output.subarray(0, Math.ceil(position2 / 8));
10344
+ });
10345
+ const normalized = new Uint8Array(strips.reduce((size, strip) => size + strip.length, source.length));
10346
+ normalized.set(source);
10347
+ let position = source.length;
10348
+ page.t273 = strips.map((strip) => {
10349
+ const offset = position;
10350
+ normalized.set(strip, position);
10351
+ position += strip.length;
10352
+ return offset;
10353
+ });
10354
+ page.t279 = strips.map((strip) => strip.length);
10355
+ page.t292 = [options | 1];
10356
+ return normalized.buffer;
10357
+ }
10358
+
10359
+ // src/image-codec-fallback.ts
10317
10360
  var validSize = (w, h) => Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0 && w <= 8192 && h <= 8192;
10318
10361
  function decodeImageCodecFallback(bytes) {
10319
10362
  try {
@@ -10352,7 +10395,7 @@ function decodeImageCodecFallback(bytes) {
10352
10395
  const pages = UTIF.decode(buffer);
10353
10396
  const page = pages.find((p) => p.t256 && p.t257);
10354
10397
  if (!page || !Array.isArray(page.t256) || !Array.isArray(page.t257) || !validSize(Number(page.t256[0]), Number(page.t257[0]))) return null;
10355
- UTIF.decodeImage(buffer, page);
10398
+ UTIF.decodeImage(normalizeGroup3(buffer, page), page);
10356
10399
  const width = page.width, height = page.height;
10357
10400
  if (!validSize(width, height)) return null;
10358
10401
  const data = UTIF.toRGBA8(page);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.4.4",
3
+ "version": "4.4.6",
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",