/* 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 */ 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 _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(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 _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
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 _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread 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 _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
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);
}
import { customAlphabet } from "nanoid";
import { Subject } from "rxjs";
export var nid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 13);
var kb = 1024;
var mb = kb * 1024;
var gb = mb * 1024;
export var sizeUnit = function sizeUnit(size) {
    if (size > gb) return (size / gb).toFixed(2) + ' GB';
    if (size > mb) return (size / mb).toFixed(2) + ' MB';
    if (size > kb) return (size / kb).toFixed(2) + ' KB';
    return size + ' B';
};
export var copy = function copy(data) {
    return JSON.parse(JSON.stringify(data));
};
export var isMod = function isMod(e) {
    return e.metaKey || e.ctrlKey;
};
export function base64ToArrayBuffer(base64) {
    var binaryString = atob(base64);
    var bytes = new Uint8Array(binaryString.length);
    for(var i = 0; i < binaryString.length; i++){
        bytes[i] = binaryString.charCodeAt(i);
    }
    return bytes.buffer;
}
export var getImageData = function getImageData() {
    var filePath = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : '';
    if (filePath.startsWith('data:image')) {
        return filePath;
    }
    return filePath;
};
export function toArrayBuffer(buffer) {
    var arrayBuffer = new ArrayBuffer(buffer.length);
    var view = new Uint8Array(arrayBuffer);
    for(var i = 0; i < buffer.length; ++i){
        view[i] = buffer[i];
    }
    return arrayBuffer;
}
export var download = function download(data, fileName) {
    data = _instanceof(data, Uint8Array) ? new Blob([
        data
    ]) : data;
    var link = document.createElement('a');
    if (link.download !== undefined) {
        var url = URL.createObjectURL(data);
        link.addEventListener('click', function(e) {
            return e.stopPropagation();
        });
        link.setAttribute('href', url);
        link.setAttribute('download', fileName);
        link.style.visibility = 'hidden';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }
};
export var modal$ = new Subject();
export var encodeHtml = function encodeHtml(str) {
    var encodeHTMLRules = {
        '&': '&#38;',
        '<': '&#60;',
        '>': '&#62;',
        '"': '&#34;',
        "'": '&#39;',
        '/': '&#47;'
    }, matchHTML = /&(?!#?\w+;)|<|>|"|'|\//g;
    return str.replace(matchHTML, function(m) {
        //@ts-ignore
        return encodeHTMLRules[m] || m;
    });
};
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";
/**
 * 创建一个延时执行函数的Hook。
 *
 * @param fn - 需要延时执行的函数
 * @param ms - 延时时间（毫秒），默认为0
 * @returns 返回一个数组，包含三个元素：
 * - isReady - 用于检查定时器是否已经触发的函数
 * - clear - 用于清除定时器的函数
 * - set - 用于重新设置定时器的函数
 *
 * @example
 * ```ts
 * const [isReady, clear, set] = useTimeoutFn(() => {
 *   console.log('Timeout triggered');
 * }, 1000);
 * ```
 *
 * @remarks
 * - 当组件挂载时，定时器会自动启动
 * - 当传入的函数(fn)发生变化时，会自动更新回调函数
 * - 当延时时间(ms)发生变化时，定时器会自动重置
 * - 当组件卸载时，定时器会自动清除
 */ export 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
    ];
}
/**
 * 创建一个防抖函数的 Hook。
 *
 * @param fn - 需要进行防抖处理的函数
 * @param ms - 防抖延迟时间(毫秒)。默认为0
 * @param deps - 依赖数组，当依赖项改变时会重置防抖计时器。默认为空数组
 * @returns 返回一个元组 [isReady, cancel]
 *          - isReady: 一个函数，用于检查防抖是否已经准备好执行
 *          - cancel: 一个函数，用于取消当前的防抖计时器
 *
 * @example
 * ```typescript
 * const [isReady, cancel] = useDebounce(() => {
 *   // 执行一些操作
 * }, 1000);
 * ```
 */ 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;
};
export default 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 function throttle(fn, wait) {
    var pre = Date.now();
    var runFn = function runFn() {
        //@ts-ignore
        var context = this;
        var args = arguments;
        var now = Date.now();
        if (now - pre >= wait) {
            fn.apply(context, args);
            pre = Date.now();
        }
    };
    runFn.flush = function() {
        {
            pre = Date.now();
            //@ts-ignore
            fn.apply(this, arguments);
        }
    };
    runFn.cancel = function() {
        pre = Date.now();
    };
    return runFn;
}
export var debugLog = function debugLog(path) {
    for(var _len = arguments.length, msg = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
        msg[_key - 1] = arguments[_key];
    }
    var _window;
    if (typeof window === 'undefined') return;
    //@ts-expect-error
    if ((_window = window) === null || _window === void 0 ? void 0 : _window.debug) {
        var _console;
        (_console = console).log.apply(_console, [
            "debug「".concat(path, "」--->")
        ].concat(_to_consumable_array(msg)));
    }
};
/**
 * Markdown 编辑器事件常量对象
 * @constant
 * @description 包含编辑器的主要事件名称
 * @property {string} SELECTIONCHANGE - 当编辑器选区发生变化时触发的事件名
 * @property {string} FOCUS - 当编辑器获得焦点时触发的事件名
 * @property {string} BLUR - 当编辑器失去焦点时触发的事件名
 */ 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";
