{"size": 5966, "ext": "js", "max_stars_repo_path": "documents/marp/node_modules/@marp-team/marpit/lib/markdown/background_image/advanced.js", "max_stars_repo_name": "sharner/notecalc", "max_stars_repo_stars_event_min_datetime": "2020-09-17T14:04:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-25T19:01:14.000Z", "max_issues_repo_path": "node_modules/@marp-team/marpit/lib/markdown/background_image/advanced.js", "max_issues_repo_name": "skleanthous/presentations", "max_issues_repo_issues_event_min_datetime": "2021-06-20T23:58:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-20T23:58:37.000Z", "max_forks_repo_path": "documents/marp/node_modules/@marp-team/marpit/lib/markdown/background_image/advanced.js", "max_forks_repo_name": "sharner/notecalc", "max_forks_repo_forks_event_min_datetime": "2020-10-26T11:17:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-26T11:17:29.000Z"}
{"max_stars_count": 3, "max_issues_count": 5, "max_forks_count": 1, "avg_line_length": 45.196969697, "max_line_length": 534, "alphanum_fraction": 0.640295005}
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _inline_style = _interopRequireDefault(require("../../helpers/inline_style"));

var _wrap_tokens = _interopRequireDefault(require("../../helpers/wrap_tokens"));

var _plugin = _interopRequireDefault(require("../../plugin"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Marpit advanced background image plugin.
 *
 * Support the advanced features for background image, by using `<figure>`
 * element(s) instead of CSS backgrounds. It works by creating the isolated
 * layer into inline SVG.
 *
 * @alias module:markdown/background_image/advanced
 * @param {MarkdownIt} md markdown-it instance.
 */
function advancedBackground(md) {
  md.core.ruler.after('marpit_directives_apply', 'marpit_advanced_background', state => {
    let current;
    const newTokens = [];

    for (const t of state.tokens) {
      if (t.type === 'marpit_inline_svg_content_open' && t.meta && t.meta.marpitBackground) {
        current = t;
        const {
          height,
          images,
          open,
          width
        } = t.meta.marpitBackground;
        open.attrSet('data-marpit-advanced-background', 'content'); // Aligned direction

        const direction = t.meta.marpitBackground.direction || 'horizontal'; // Split backgrounds

        const splitSide = t.meta.marpitBackground.split;

        if (splitSide) {
          open.attrSet('data-marpit-advanced-background-split', splitSide);
          const splitBgSize = t.meta.marpitBackground.splitSize || '50%';
          t.attrSet('width', `${100 - Number.parseFloat(splitBgSize.slice(0, -1))}%`);
          if (splitSide === 'left') t.attrSet('x', splitBgSize);
          const style = new _inline_style.default(open.attrGet('style'));
          style.set('--marpit-advanced-background-split', splitBgSize);
          open.attrSet('style', style.toString());
        } // Add the isolated layer for background image


        newTokens.push(...(0, _wrap_tokens.default)(state.Token, 'marpit_advanced_background_foreign_object', {
          tag: 'foreignObject',
          width,
          height
        }, (0, _wrap_tokens.default)(state.Token, 'marpit_advanced_background_section', _objectSpread(_objectSpread({}, open.attrs.reduce((o, [k, v]) => _objectSpread(_objectSpread({}, o), {}, {
          [k]: v
        }), {})), {}, {
          tag: 'section',
          id: undefined,
          'data-marpit-advanced-background': 'background'
        }), (0, _wrap_tokens.default)(state.Token, 'marpit_advanced_background_image_container', {
          tag: 'div',
          'data-marpit-advanced-background-container': true,
          'data-marpit-advanced-background-direction': direction
        }, (() => {
          const imageTokens = []; // Add multiple image elements

          for (const img of images) {
            const style = new _inline_style.default({
              'background-image': `url("${img.url}")`
            }); // Image sizing

            if (img.size) style.set('background-size', img.size); // Image filter for backgrounds (Only in advanced BG)

            if (img.filter) style.set('filter', img.filter);
            imageTokens.push(...(0, _wrap_tokens.default)(state.Token, 'marpit_advanced_background_image', {
              tag: 'figure',
              style: style.toString()
            }));
          }

          return imageTokens;
        })()))), t);
      } else if (current && t.type === 'marpit_inline_svg_content_close') {
        const {
          open,
          height,
          width
        } = current.meta.marpitBackground; // Apply styles

        const style = new _inline_style.default();
        if (open.meta && open.meta.marpitDirectives && open.meta.marpitDirectives.color) style.set('color', open.meta.marpitDirectives.color); // Add the isolated layer for pseudo contents (e.g. Page number)

        newTokens.push(t, ...(0, _wrap_tokens.default)(state.Token, 'marpit_advanced_background_foreign_object', {
          tag: 'foreignObject',
          width,
          height,
          'data-marpit-advanced-background': 'pseudo'
        }, (0, _wrap_tokens.default)(state.Token, 'marpit_advanced_pseudo_section', {
          tag: 'section',
          class: open.attrGet('class'),
          style: style.toString(),
          'data-marpit-advanced-background': 'pseudo',
          // For pagination styling
          'data-marpit-pagination': open.attrGet('data-marpit-pagination'),
          'data-marpit-pagination-total': open.attrGet('data-marpit-pagination-total')
        })));
        current = undefined;
      } else {
        newTokens.push(t);
      }
    }

    state.tokens = newTokens;
  });
}

var _default = (0, _plugin.default)(advancedBackground);

exports.default = _default;