"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.configAudioLoader = configAudioLoader;
exports.configFontLoader = configFontLoader;
exports.configImageLoader = configImageLoader;
exports.configSVGLoader = configSVGLoader;
exports.configVideoLoader = configVideoLoader;

var _nameTemplates = require("../common/nameTemplates");

const ImageExtRegex = /\.jpe?g$|\.gif$|\.png|\.webp$/;
const FontExtRegex = /\.woff2|\.woff$|\.ttf$|\.eot$/;
const SVGExtRegex = /\.svg$/;
const AudioExtRegex = /\.ogg|\.mp3$/;
const VideoExtRegex = /\.mp4|\.webm$/;

function createAssetLoader({
  test,
  nameTemplate,
  limit
}) {
  const conf = {
    test,
    type: 'asset'
  };

  if (limit) {
    conf.parser = {
      dataUrlCondition: {
        maxSize: limit // 4 * 1024 // 4kb

      }
    };
  } else {
    conf.type = 'asset/resource';
  }

  if (nameTemplate) {
    conf.generator = {
      filename: nameTemplate
    };
  }

  return conf;
}

function configImageLoader(options) {
  return createAssetLoader({
    test: ImageExtRegex,
    nameTemplate: (0, _nameTemplates.nameTemplates)('image', options),
    limit: 1000
  });
}

function configFontLoader(options) {
  return createAssetLoader({
    test: FontExtRegex,
    nameTemplate: (0, _nameTemplates.nameTemplates)('font', options),
    limit: 1000
  });
}

function configSVGLoader(options) {
  return createAssetLoader({
    test: SVGExtRegex,
    nameTemplate: (0, _nameTemplates.nameTemplates)('svg', options),
    limit: 1000
  });
}

function configAudioLoader(options) {
  return createAssetLoader({
    test: AudioExtRegex,
    nameTemplate: (0, _nameTemplates.nameTemplates)('audio', options)
  });
}

function configVideoLoader(options) {
  return createAssetLoader({
    test: VideoExtRegex,
    nameTemplate: (0, _nameTemplates.nameTemplates)('video', options)
  });
}