function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
import { EditorState, Plugin, PluginKey } from 'prosemirror-state';
import { ATTRIBUTE_LAYOUT, LAYOUT } from './DocNodeSpec.js';
var SPEC = {
  // [FS] IRAD-1005 2020-07-07
  // Upgrade outdated packages.
  key: new PluginKey('EditorPageLayoutPlugin'),
  props: {
    attributes: renderAttributes
  }
};
function renderAttributes(editorState) {
  var doc = editorState.doc;
  var attrs = {
    "class": 'czi-prosemirror-editor'
  };
  var _doc$attrs = doc.attrs,
    width = _doc$attrs.width,
    padding = _doc$attrs.padding,
    layout = _doc$attrs.layout;
  var style = '';
  var computedLayout;
  if (width) {
    var inWidth = width / 72;
    var cmWidth = inWidth * 2.54;
    if (!computedLayout && inWidth >= 10.9 && inWidth <= 11.1) {
      // Round up to letter size.
      computedLayout = LAYOUT.US_LETTER_LANDSCAPE;
    } else if (!computedLayout && inWidth >= 8.4 && inWidth <= 8.6) {
      // Round up to letter size.
      computedLayout = LAYOUT.US_LETTER_PORTRAIT;
    } else if (!computedLayout && cmWidth >= 29.5 && cmWidth <= 30.1) {
      // Round up to letter size.
      computedLayout = LAYOUT.A4_LANDSCAPE;
    } else if (!computedLayout && cmWidth >= 20.5 && cmWidth <= 21.5) {
      // Round up to letter size.
      computedLayout = LAYOUT.A4_PORTRAIT;
    } else {
      // Use custom width (e.g. imported from google doc).
      style += "width: ".concat(width, "pt;");
    }
    if (padding) {
      style += "padding-left: ".concat(padding, "pt;");
      style += "padding-right: ".concat(padding, "pt;");
    }
    attrs.style = style;
  } else {
    computedLayout = layout;
  }
  if (computedLayout) {
    attrs[ATTRIBUTE_LAYOUT] = computedLayout;
  }
  return attrs;
}

// Unfortunately the root node `doc` does not supoort `toDOM`, thus
// we'd have to assign its `attributes` manually.
var EditorPageLayoutPlugin = /*#__PURE__*/function (_Plugin) {
  function EditorPageLayoutPlugin() {
    _classCallCheck(this, EditorPageLayoutPlugin);
    return _callSuper(this, EditorPageLayoutPlugin, [SPEC]);
  }
  _inherits(EditorPageLayoutPlugin, _Plugin);
  return _createClass(EditorPageLayoutPlugin);
}(Plugin);
export default EditorPageLayoutPlugin;