"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.meta = exports.default = void 0;
var _postcss_plugin = _interopRequireDefault(require("../helpers/postcss_plugin"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/** @module */

/**
 * Marpit PostCSS meta plugin.
 *
 * Parse CSS comment written in the format of `@key value`.
 *
 * @function meta
 * @param {Object} [opts]
 * @param {Object} [opts.metaType] An object for defined types for metadata.
 */
const meta = exports.meta = (0, _postcss_plugin.default)('marpit-postcss-meta', (opts = {}) => (css, {
  result
}) => {
  const metaType = opts.metaType || {};
  result.marpitMeta = result.marpitMeta || {};
  css.walkComments(comment => {
    comment.text.slice(0).replace(/^[*!\s]*@([\w-]+)\s+(.+)$/gim, (_, metaName, value) => {
      if (metaType[metaName] === Array) {
        // Array meta
        result.marpitMeta[metaName] = [...(result.marpitMeta[metaName] || []), value];
      } else {
        // String meta (default)
        result.marpitMeta[metaName] = value;
      }
    });
  });
});
var _default = exports.default = meta;