single-file-core 1.5.120 → 1.5.121

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.
@@ -397,6 +397,9 @@ function getProcessorHelperClass(utilInstance) {
397
397
  }
398
398
  }
399
399
  }
400
+ if (options.imageReductionFactor > 1 && expectedType == "image") {
401
+ content = await resizeImage(doc, content, options);
402
+ }
400
403
  if (removeElementIfMissing && this.testEmptyResource(content)) {
401
404
  resourceElement.remove();
402
405
  } else if (!this.testEmptyResource(content)) {
@@ -420,9 +423,6 @@ function getProcessorHelperClass(utilInstance) {
420
423
  const isSVG = content.startsWith(PREFIX_DATA_URI_IMAGE_SVG);
421
424
  const maxSizeDuplicateImages = options.maxSizeDuplicateImages || SINGLE_FILE_VARIABLE_MAX_SIZE;
422
425
  if (processDuplicates && duplicate && !isSVG && util.getContentSize(content) < maxSizeDuplicateImages) {
423
- if (options.imageReductionFactor > 1 && expectedType == "image") {
424
- content = await resizeImage(doc, content, options);
425
- }
426
426
  if (this.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options)) {
427
427
  resources.cssVariables.set(indexResource, { content, url: originURL });
428
428
  const declarationList = cssTree.parse(resourceElement.getAttribute("style"), { context: "declarationList", parseCustomProperty: true });
package/core/util.js CHANGED
@@ -63,6 +63,8 @@ const CONTENT_TYPE_EXTENSIONS = {
63
63
  "font/collection": ".ttc"
64
64
  };
65
65
  const CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
66
+ const CONTENT_TYPES_HTML = ["text/html", "application/xhtml+xml"];
67
+ const EXPECTED_TYPES_MEDIA = ["font", "image", "video", "audio"];
66
68
 
67
69
  const URL = globalThis.URL;
68
70
  const DOMParser = globalThis.DOMParser;
@@ -308,7 +310,7 @@ function getInstance(utilOptions) {
308
310
  charset = options.charset;
309
311
  }
310
312
  if (options.asBinary) {
311
- if (response.status >= 400) {
313
+ if (response.status >= 400 || (EXPECTED_TYPES_MEDIA.includes(options.expectedType) && CONTENT_TYPES_HTML.includes(contentType))) {
312
314
  return getFetchResponse(resourceURL, options);
313
315
  }
314
316
  try {