function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _define_property(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;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
/* eslint-disable @typescript-eslint/no-this-alias */ /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/no-unused-expressions */ /* eslint-disable no-param-reassign */ import { customAlphabet } from "nanoid";
export var nid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 13);
export var copy = function copy(data) {
    return JSON.parse(JSON.stringify(data));
};
export var isMod = function isMod(e) {
    return e.metaKey || e.ctrlKey;
};
export { download, modal$ } from "./sideEffects";
export { isMarkdown } from "./isMarkdown";
export function debounce(func, delay) {
    var timer = null;
    var fn = function fn() {
        var _this = this, _arguments = arguments;
        clearTimeout(timer);
        timer = setTimeout(function() {
            //@ts-ignore
            func.apply(_this, _arguments);
        }, delay);
    };
    fn.flush = function() {
        clearTimeout(timer);
        //@ts-ignore
        func.apply(this, arguments);
    };
    fn.cancel = function() {
        clearTimeout(timer);
    };
    return fn;
}
import { useCallback, useEffect, useRef } from "react";
function useTimeoutFn(fn) {
    var ms = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
    var ready = useRef(false);
    var timeout = useRef();
    var callback = useRef(fn);
    var isReady = useCallback(function() {
        return ready.current;
    }, []);
    var set = useCallback(function() {
        ready.current = false;
        timeout.current && clearTimeout(timeout.current);
        timeout.current = setTimeout(function() {
            ready.current = true;
            callback.current();
        }, ms);
    }, [
        ms
    ]);
    var clear = useCallback(function() {
        ready.current = null;
        timeout.current && clearTimeout(timeout.current);
    }, []);
    // update ref when function changes
    useEffect(function() {
        callback.current = fn;
    }, [
        fn
    ]);
    // set on mount, clear on unmount
    useEffect(function() {
        set();
        return clear;
    }, [
        ms
    ]);
    return [
        isReady,
        clear,
        set
    ];
}
export function useDebounce(fn) {
    var ms = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, deps = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
    var _useTimeoutFn = _sliced_to_array(useTimeoutFn(fn, ms), 3), isReady = _useTimeoutFn[0], cancel = _useTimeoutFn[1], reset = _useTimeoutFn[2];
    useEffect(reset, deps);
    return [
        isReady,
        cancel
    ];
}
import { useReducer } from "react";
var updateReducer = function updateReducer(num) {
    return (num + 1) % 1000000;
};
function useUpdate() {
    var _useReducer = _sliced_to_array(useReducer(updateReducer, 0), 2), update = _useReducer[1];
    return update;
}
export var useGetSetState = function useGetSetState() {
    var initialState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
    if (process.env.NODE_ENV !== 'production') {
        if ((typeof initialState === "undefined" ? "undefined" : _type_of(initialState)) !== 'object') {
            console.error('useGetSetState initial state must be an object.');
        }
    }
    var update = useUpdate();
    var state = useRef(_object_spread({}, initialState));
    var get = useCallback(function() {
        return state.current;
    }, []);
    var set = useCallback(function(patch) {
        if (!patch) {
            return;
        }
        if (process.env.NODE_ENV !== 'production') {
            if ((typeof patch === "undefined" ? "undefined" : _type_of(patch)) !== 'object') {
                console.error('useGetSetState setter patch must be an object.');
            }
        }
        Object.assign(state.current, patch);
        update();
    }, []);
    return [
        get,
        set
    ];
};
export var MARKDOWN_EDITOR_EVENTS = {
    SELECTIONCHANGE: 'md-editor-selectionchange',
    FOCUS: 'md-editor-focus',
    BLUR: 'md-editor-blur'
};
export * from "../parser/parserSlateNodeToMarkdown";
export * from "./editorUtils";
export * from "./keyboard";
export * from "./media";
export * from "./path";
export * from "./useLocalState";
