"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataTransferType = void 0;
exports.isIosSafariShare = isIosSafariShare;
exports.isFilesOnly = isFilesOnly;
exports.isFilesFromHtml = isFilesFromHtml;
exports.isImageFile = isImageFile;
exports.extractTextContentFromHtml = extractTextContentFromHtml;
/** Сontains all data formats known to us */
var DataTransferType;
(function (DataTransferType) {
    DataTransferType["Text"] = "text/plain";
    DataTransferType["Html"] = "text/html";
    DataTransferType["Yfm"] = "text/yfm";
    DataTransferType["Rtf"] = "text/rtf";
    DataTransferType["UriList"] = "text/uri-list";
    DataTransferType["VSCodeData"] = "vscode-editor-data";
    DataTransferType["Files"] = "Files";
})(DataTransferType || (exports.DataTransferType = DataTransferType = {}));
function isIosSafariShare({ types }) {
    // if link is copied from ios safari share button,
    // then data transfer only have text/uri-list data type
    return (types.includes(DataTransferType.UriList) &&
        !types.includes(DataTransferType.Text) &&
        !types.includes(DataTransferType.Html));
}
function isFilesOnly({ types }) {
    return types.length === 1 && types[0] === DataTransferType.Files;
}
function isFilesFromHtml({ types }) {
    return (types.length === 2 &&
        types.includes(DataTransferType.Files) &&
        types.includes(DataTransferType.Html));
}
function isImageFile(file) {
    return file.type.startsWith('image/');
}
function extractTextContentFromHtml(html) {
    const element = document.createElement('div');
    element.innerHTML = html;
    element.replaceChildren(...Array.from(element.children).filter((v) => v.nodeName !== 'META'));
    // Look if all nodes are div or span. That they don't have any classname and have only text child.
    if (Array.from(element.children).every(({ nodeName, classList, childNodes }) => {
        return ((nodeName === 'DIV' || nodeName === 'SPAN') &&
            !classList.length &&
            childNodes.length === 1 &&
            (childNodes[0].nodeName === '#text' || childNodes[0].nodeName === 'BR'));
    })) {
        return Array.from(element.children).reduce((a, v) => a + v.textContent + '\n', '');
    }
    return null;
}
//# sourceMappingURL=utils.js.map
