import { Node } from 'prosemirror-model';
// [FS] IRAD-1061 2020-09-19
// Now loaded locally, so that it works in closed networks as well.

export var FONT_TYPE_NAMES = [
// SERIF
'Aclonica', 'Acme', 'Alegreya', 'Arial', 'Arial Black', 'Georgia', 'Tahoma', 'Times New Roman', 'Times', 'Verdana',
// MONOSPACE
'Courier New'];

// FS IRAD-988 2020-06-18
// Preload fonts that are listed by default,
// so that even if the font is not available locally, load from the web.
export function preLoadFonts() {
  FONT_TYPE_NAMES.forEach(function (name) {
    loadAndCacheFont(name);
  });
}

// Resolve each font after it is loaded.
var RESOLVED_FONT_NAMES = new Set([]);
function loadAndCacheFont(name) {
  // Cache custom fonts
  RESOLVED_FONT_NAMES.add(name);
}
var FontTypeMarkSpec = {
  attrs: {
    name: '',
    overridden: {
      "default": false
    }
  },
  inline: true,
  group: 'inline',
  parseDOM: [{
    tag: 'span[style*=font-family]',
    getAttrs: function getAttrs(domNode) {
      var _domNode$parentNode, _domNode$parentNode2;
      var name = domNode.style.fontFamily || '';
      var parentFontName = ((_domNode$parentNode = domNode.parentNode) === null || _domNode$parentNode === void 0 ? void 0 : _domNode$parentNode.style.fontFamily) || '';
      var _mOverriden = domNode.getAttribute('overridden');
      var mparent_overriden = (_domNode$parentNode2 = domNode.parentNode) === null || _domNode$parentNode2 === void 0 ? void 0 : _domNode$parentNode2.getAttribute('overridden');
      if (name !== '') {
        name = name ? name.replace(/["']/g, '') : '';
      }
      if (parentFontName !== '') {
        parentFontName = parentFontName ? parentFontName.replace(/["']/g, '') : '';
      }
      var overridden = _mOverriden === 'true' && name !== '' || parentFontName !== '' && mparent_overriden === 'true'; // Check if the font is overridden

      return {
        name: name || parentFontName || 'Arial',
        // Clean up the font name
        overridden: overridden
      };
    }
  }],
  toDOM: function toDOM(node) {
    var _node$attrs = node.attrs,
      name = _node$attrs.name,
      overridden = _node$attrs.overridden;
    var attrs = {
      overridden: overridden
    };
    if (name) {
      if (!RESOLVED_FONT_NAMES.has(name)) {
        loadAndCacheFont(name);
      }
      attrs.style = "font-family: ".concat(name);
    }
    return ['span', attrs, 0];
  }
};
export default FontTypeMarkSpec;
import { bpfrpt_proptype_MarkSpec } from "./Types.js";