"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isUrl = exports.isMobile = exports.isMac = exports.isImage = exports.isDocumentEmpty = exports.IMAGE_TYPES = void 0;
var _isUrl = _interopRequireDefault(require("is-url"));
var _slate = require("slate");
const isMac = () => {
  const platform = navigator.platform;
  return platform === 'Mac68K' || platform === 'MacPPC' || platform === 'Macintosh' || platform === 'MacIntel';
};
exports.isMac = isMac;
const IMAGE_TYPES = exports.IMAGE_TYPES = ['png', 'jpg', 'gif'];
const isImage = url => {
  if (!url) return false;
  if (!isUrl(url)) return false;
  const fileName = url.slice(url.lastIndexOf('/') + 1); // http://xx/mm/*.png
  const suffix = fileName.split('.')[1];
  if (!suffix) return false;
  return IMAGE_TYPES.includes(suffix.toLowerCase());
};
exports.isImage = isImage;
const isUrl = url => {
  if (!url) return false;
  if (!url.startsWith('http')) return false;
  if (!(0, _isUrl.default)(url)) return false;
  return true;
};

// Check document is empty or only contains void nodes
exports.isUrl = isUrl;
const isDocumentEmpty = editor => {
  const document = editor.children;
  const [firstChildNode] = document;
  // Check if document has only one block node
  const isWrapperEmpty = document.length === 1 && _slate.Node.string(firstChildNode).length === 0;
  if (!isWrapperEmpty) return false;
  // Check if the only one block node has only one text node with empty string
  const hasVoidNode = firstChildNode.children.some(node => _slate.Editor.isVoid(editor, node));
  if (hasVoidNode) return false;
  return true;
};
exports.isDocumentEmpty = isDocumentEmpty;
const isMobile = exports.isMobile = typeof window !== 'undefined' && (window.innerWidth < 768 || navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null);