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 _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
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 ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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 _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 no-param-reassign */ import { Editor, Element, Node, Path, Point, Range, Text, Transforms } from "slate";
import { ReactEditor } from "slate-react";
import { getMediaType } from "./dom";
export var EditorUtils = /*#__PURE__*/ function() {
    "use strict";
    function EditorUtils() {
        _class_call_check(this, EditorUtils);
    }
    _create_class(EditorUtils, null, [
        {
            key: "p",
            get: function get() {
                return {
                    type: 'paragraph',
                    children: [
                        {
                            text: ''
                        }
                    ]
                };
            }
        },
        {
            key: "hasPath",
            value: function hasPath(editor, path) {
                return Editor.hasPath(editor, path);
            }
        },
        {
            key: "focus",
            value: function focus(editor) {
                try {
                    ReactEditor.focus(editor);
                } catch (e) {
                    console.error(e);
                }
            }
        },
        {
            key: "blur",
            value: function blur(editor) {
                try {
                    ReactEditor.blur(editor);
                } catch (e) {
                    console.error(e);
                }
            }
        },
        {
            key: "isPrevious",
            value: function isPrevious(firstPath, nextPath) {
                return Path.equals(Path.parent(firstPath), Path.parent(nextPath)) && Path.compare(firstPath, nextPath) === -1;
            }
        },
        {
            key: "isNextPath",
            value: function isNextPath(firstPath, nextPath) {
                return Path.equals(Path.parent(firstPath), Path.parent(nextPath)) && Path.compare(firstPath, nextPath) === 1;
            }
        },
        {
            key: "isDirtLeaf",
            value: function isDirtLeaf(leaf) {
                return leaf.bold || leaf.code || leaf.italic || leaf.strikethrough || !!(leaf === null || leaf === void 0 ? void 0 : leaf.url) || leaf.fnd || leaf.fnc || leaf.html || leaf.highColor;
            }
        },
        {
            key: "isTop",
            value: function isTop(editor, path) {
                var p = Editor.parent(editor, path);
                return Editor.isEditor(p[0]);
            }
        },
        {
            key: "findPrev",
            value: function findPrev(editor, path) {
                while(path.length){
                    if (Path.hasPrevious(path)) {
                        var _Node_get;
                        if (((_Node_get = Node.get(editor, Path.previous(path))) === null || _Node_get === void 0 ? void 0 : _Node_get.type) === 'hr') {
                            path = Path.previous(path);
                        } else {
                            return Path.previous(path);
                        }
                    } else {
                        path = Path.parent(path);
                    }
                }
                return [];
            }
        },
        {
            key: "findMediaInsertPath",
            value: function findMediaInsertPath(editor) {
                var _cur_, _cur_1, _cur_2;
                var _Editor_nodes = _sliced_to_array(Editor.nodes(editor, {
                    match: function(n) {
                        return Element.isElement(n);
                    },
                    mode: 'lowest'
                }), 1), cur = _Editor_nodes[0];
                if (!cur) return null;
                var path = cur[1];
                if ((cur === null || cur === void 0 ? void 0 : (_cur_ = cur[0]) === null || _cur_ === void 0 ? void 0 : _cur_.type) === 'table-cell') {
                    path = Path.next(Path.parent(Path.parent(cur[1])));
                }
                if ((cur === null || cur === void 0 ? void 0 : (_cur_1 = cur[0]) === null || _cur_1 === void 0 ? void 0 : _cur_1.type) === 'head') {
                    path = Path.next(path);
                }
                if ((cur === null || cur === void 0 ? void 0 : (_cur_2 = cur[0]) === null || _cur_2 === void 0 ? void 0 : _cur_2.type) === 'paragraph' && Node.string(cur[0])) {
                    path = Path.next(cur[1]);
                }
                return path;
            }
        },
        {
            key: "findNext",
            value: function findNext(editor, path) {
                while(path.length){
                    if (Editor.hasPath(editor, Path.next(path))) {
                        return Path.next(path);
                    } else {
                        path = Path.parent(path);
                    }
                }
                return undefined;
            }
        },
        {
            key: "moveNodes",
            value: function moveNodes(editor, from, to) {
                var index = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 1;
                var count = 0;
                while(Editor.hasPath(editor, from)){
                    if (count > 100) break;
                    Transforms.moveNodes(editor, {
                        at: from,
                        to: _to_consumable_array(to).concat([
                            index
                        ])
                    });
                    index++;
                    count++;
                }
            }
        },
        {
            key: "moveAfterSpace",
            value: function moveAfterSpace(editor, path) {
                var next = Editor.next(editor, {
                    at: path
                });
                if (!next || !Text.isText(next[0])) {
                    Transforms.transform(editor, {
                        type: 'insert_node',
                        path: Path.next(path),
                        node: {
                            text: ''
                        }
                    });
                    Transforms.select(editor, Path.next(path));
                } else {
                    Transforms.move(editor, {
                        unit: 'offset'
                    });
                }
            }
        },
        {
            key: "moveBeforeSpace",
            value: function moveBeforeSpace(editor, path) {
                if (!Path.hasPrevious(path)) {
                    Transforms.transform(editor, {
                        type: 'insert_node',
                        path: path,
                        node: {
                            text: ''
                        }
                    });
                }
                Transforms.move(editor, {
                    unit: 'offset',
                    reverse: true
                });
            }
        },
        {
            key: "clearMarks",
            value: /**
   * 清除编辑器中选中的文本的所有标记
   *
   * @param editor - 编辑器实例
   * @param split - 是否在格式边界处分割文本节点，默认为 false
   *
   * @description
   * 该方法执行以下操作：
   * 1. 移除选中文本的所有格式标记
   * 2. 处理列表项的提升和转换
   * 3. 将选中区域转换为段落格式
   *
   * 当 split=true 时，会在不同格式的边界处分割文本节点，
   * 这允许对部分文本应用/移除格式而不影响相邻文本
   */ function clearMarks(editor) {
                var split = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
                if (!editor.selection) return;
                // 移除所有格式标记
                Transforms.unsetNodes(editor, EditorUtils.CLEARABLE_MARKS, {
                    split: split,
                    match: Text.isText
                });
                var anchorPath = editor.selection.anchor.path;
                var parentPath = Path.parent(anchorPath);
                try {
                    var node = Node.get(editor, parentPath);
                    // 向上查找非段落的父节点
                    if (node.type === 'paragraph' && Editor.hasPath(editor, Path.parent(parentPath))) {
                        node = Node.get(editor, Path.parent(parentPath));
                    }
                    // 处理列表项的提升
                    if (node.type === 'list-item') {
                        Transforms.liftNodes(editor, {
                            at: Path.parent(anchorPath),
                            mode: 'highest'
                        });
                    }
                    // 查找最高级别的选中元素节点
                    var nodeEntries = Array.from(Editor.nodes(editor, {
                        match: function(n) {
                            return Element.isElement(n);
                        },
                        mode: 'highest'
                    }));
                    if (nodeEntries.length > 0) {
                        var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 2), selectNodes = _nodeEntries_[0], selectPath = _nodeEntries_[1];
                        // 处理列表转段落的特殊情况
                        if (selectNodes.type === 'list' || selectNodes.type === 'bulleted-list' || selectNodes.type === 'numbered-list') {
                            Transforms.removeNodes(editor, {
                                at: selectPath,
                                voids: true
                            });
                            var paragraphNodes = EditorUtils.listToParagraph(editor, selectNodes);
                            if (paragraphNodes.length > 0) {
                                Transforms.insertNodes(editor, paragraphNodes, {
                                    at: editor.selection
                                });
                            }
                            return;
                        }
                    }
                    // 将选中区域转换为段落
                    Transforms.setNodes(editor, {
                        type: 'paragraph'
                    }, {
                        at: parentPath
                    });
                } catch (error) {
                    console.error('Error in clearMarks:', error);
                }
            }
        },
        {
            key: "listToParagraph",
            value: /**
   * 将列表节点转换为段落节点数组
   *
   * @param editor - 编辑器实例
   * @param listNode - 要处理的列表节点
   * @returns 从列表节点中提取的所有段落节点的数组
   *
   * @description
   * 该方法通过递归遍历列表节点及其子节点，提取所有段落节点，
   * 并将它们汇集成一个扁平化的数组。支持嵌套列表的处理。
   */ function listToParagraph(editor, listNode) {
                if (!listNode.children || listNode.children.length === 0) {
                    return [];
                }
                var paragraphNodes = [];
                var extractParagraphs = function(children) {
                    children.forEach(function(item) {
                        if (!(item === null || item === void 0 ? void 0 : item.children)) return;
                        item.children.forEach(function(child) {
                            if (child.type === 'paragraph') {
                                paragraphNodes.push(child);
                            } else if (child.type === 'list' || child.type === 'bulleted-list' || child.type === 'numbered-list') {
                                var _paragraphNodes;
                                // 递归处理嵌套列表
                                var nestedParagraphs = EditorUtils.listToParagraph(editor, child);
                                (_paragraphNodes = paragraphNodes).push.apply(_paragraphNodes, _to_consumable_array(nestedParagraphs));
                            }
                        });
                    });
                };
                extractParagraphs(listNode.children);
                return paragraphNodes.flat();
            }
        },
        {
            key: "deleteAll",
            value: /**
   * 删除编辑器中的所有内容，并插入新的节点
   *
   * @param editor - 编辑器实例
   * @param insertNodes - 要插入的新节点数组。如果未提供，将插入默认段落节点
   */ function deleteAll(editor, insertNodes) {
                var allNodes = Array.from(Editor.nodes(editor, {
                    at: [],
                    match: function(n) {
                        return Element.isElement(n);
                    },
                    mode: 'highest',
                    reverse: true
                }));
                if (allNodes.length > 0) {
                    var firstNode = allNodes[allNodes.length - 1];
                    var lastNode = allNodes[0];
                    Transforms.delete(editor, {
                        at: {
                            anchor: Editor.start(editor, firstNode[1]),
                            focus: Editor.end(editor, lastNode[1])
                        }
                    });
                    // 删除剩余的第一个节点
                    if (Editor.hasPath(editor, [
                        0
                    ])) {
                        Transforms.delete(editor, {
                            at: [
                                0
                            ]
                        });
                    }
                }
                var nodesToInsert = insertNodes || [
                    EditorUtils.p
                ];
                Transforms.insertNodes(editor, nodesToInsert, {
                    at: [
                        0
                    ]
                });
            }
        },
        {
            key: "reset",
            value: /**
   * 重置编辑器的内容，并可选地插入新的节点和重置历史记录
   *
   * @param editor - 要重置的编辑器实例
   * @param insertNodes - 可选的插入节点数组。如果未提供，则使用默认段落节点
   * @param force - 可选的布尔值或历史记录对象。如果为布尔值，则强制重置历史记录；如果为历史记录对象，则使用提供的历史记录
   */ function reset(editor, insertNodes, force) {
                var nodesToInsert = insertNodes || [
                    EditorUtils.p
                ];
                // 深克隆节点以避免引用问题
                editor.children = JSON.parse(JSON.stringify(nodesToInsert));
                if (force) {
                    editor.history = typeof force === 'boolean' ? {
                        redos: [],
                        undos: []
                    } : force;
                }
                editor.onChange();
            }
        },
        {
            key: "includeAll",
            value: /**
   * 检查选区是否完全包含在指定节点路径中。
   *
   * @param editor - 编辑器实例。
   * @param sel - 选区范围。
   * @param nodePath - 节点路径。
   * @returns 如果选区完全包含在节点路径中，则返回 true，否则返回 false。
   */ function includeAll(editor, sel, nodePath) {
                var _Range_edges = _sliced_to_array(Range.edges(sel), 2), start = _Range_edges[0], end = _Range_edges[1];
                return Point.compare(start, Editor.start(editor, nodePath)) !== 1 && Point.compare(end, Editor.end(editor, nodePath)) !== -1;
            }
        },
        {
            key: "copy",
            value: function copy(data) {
                return JSON.parse(JSON.stringify(data));
            }
        },
        {
            key: "copyText",
            value: /**
   * 复制指定范围内的文本内容。
   *
   * @param editor - 编辑器实例。
   * @param start - 文本复制的起始位置。
   * @param end - （可选）文本复制的结束位置。如果未提供，则复制从起始位置到文档末尾的所有文本。
   * @returns 返回指定范围内的文本内容。
   */ function copyText(editor, start, end) {
                var _leaf_text;
                var leaf = Node.leaf(editor, start.path);
                var text = '';
                // Handle first leaf node from start offset
                text += ((_leaf_text = leaf.text) === null || _leaf_text === void 0 ? void 0 : _leaf_text.slice(start.offset)) || '';
                // Get next nodes until we reach the end point
                var next = Editor.next(editor, {
                    at: start.path
                });
                while(next){
                    if (end && Path.equals(next[1], end.path)) {
                        var _next__text;
                        // If we reach the end path, slice until end offset
                        text += ((_next__text = next[0].text) === null || _next__text === void 0 ? void 0 : _next__text.slice(0, end.offset)) || '';
                        break;
                    } else {
                        // Add full text content of intermediate nodes
                        text += next[0].text || '';
                        next = Editor.next(editor, {
                            at: next[1]
                        });
                    }
                }
                return text;
            }
        },
        {
            key: "cutText",
            value: /**
   * 从编辑器中剪切文本。
   *
   * @param editor - 编辑器实例。
   * @param start - 开始位置的点。
   * @param end - 结束位置的点（可选）。
   * @returns 剪切的文本数组，每个元素为一个 CustomLeaf 对象。
   */ function cutText(editor, start, end) {
                var _leaf_text;
                var leaf = Node.leaf(editor, start.path);
                var texts = [
                    _object_spread_props(_object_spread({}, leaf), {
                        text: ((_leaf_text = leaf.text) === null || _leaf_text === void 0 ? void 0 : _leaf_text.slice(start.offset)) || ''
                    })
                ];
                var next = Editor.next(editor, {
                    at: start.path
                });
                while(next){
                    if (end && Path.equals(next[1], end.path)) {
                        var _next__text;
                        texts.push(_object_spread_props(_object_spread({}, next[0]), {
                            text: ((_next__text = next[0].text) === null || _next__text === void 0 ? void 0 : _next__text.slice(0, end.offset)) || ''
                        }));
                        break;
                    } else {
                        texts.push(next[0]);
                        next = Editor.next(editor, {
                            at: next[1]
                        });
                    }
                }
                return texts;
            }
        },
        {
            key: "isFormatActive",
            value: /**
   * 检查编辑器中是否有指定格式的活动节点
   *
   * @param editor - 编辑器实例
   * @param format - 要检查的格式名称
   * @param value - 可选的值，用于进一步验证格式是否匹配
   * @returns 如果存在匹配的格式节点，则返回 true；否则返回 false
   */ function isFormatActive(editor, format, value) {
                try {
                    var nodeEntries = Array.from(Editor.nodes(editor, {
                        match: function(n) {
                            return !!n[format];
                        },
                        mode: 'lowest'
                    }));
                    if (nodeEntries.length === 0) return false;
                    var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 1), node = _nodeEntries_[0];
                    return value ? node[format] === value : !!node[format];
                } catch (error) {
                    console.error('Error checking format active:', error);
                    return false;
                }
            }
        },
        {
            key: "getUrl",
            value: /**
   * 获取编辑器中选中文本的URL
   *
   * @param editor - 编辑器实例
   * @returns 返回选中文本的URL，如果没有则返回空字符串
   */ function getUrl(editor) {
                try {
                    var _nodeEntries__;
                    var nodeEntries = Array.from(Editor.nodes(editor, {
                        match: function(n) {
                            return Text.isText(n) && !!(n === null || n === void 0 ? void 0 : n.url);
                        },
                        mode: 'lowest'
                    }));
                    return nodeEntries.length > 0 ? ((_nodeEntries__ = nodeEntries[0][0]) === null || _nodeEntries__ === void 0 ? void 0 : _nodeEntries__.url) || '' : '';
                } catch (error) {
                    console.error('Error getting URL:', error);
                    return '';
                }
            }
        },
        {
            key: "toggleFormat",
            value: /**
   * 切换文本格式（加粗、斜体等）
   *
   * @param editor - 编辑器实例
   * @param format - 要切换的格式类型
   */ function toggleFormat(editor, format) {
                if (!editor.selection) return;
                var selectedText = Editor.string(editor, editor.selection);
                if (!selectedText) return;
                var isActive = EditorUtils.isFormatActive(editor, format);
                Transforms.setNodes(editor, _define_property({}, format, isActive ? null : true), {
                    match: Text.isText,
                    split: true
                });
            }
        },
        {
            key: "highColor",
            value: /**
   * 为编辑器中的文本节点设置高亮颜色
   *
   * @param editor - 编辑器实例
   * @param color - 可选的高亮颜色字符串。如果未提供，则移除高亮颜色
   */ function highColor(editor, color) {
                if (!editor.selection) return;
                Transforms.setNodes(editor, {
                    highColor: color
                }, {
                    match: Text.isText,
                    split: true
                });
            }
        },
        {
            key: "setAlignment",
            value: /**
   * 设置文本对齐方式
   *
   * @param editor - 编辑器实例
   * @param alignment - 对齐方式：'left', 'center', 或 'right'
   */ function setAlignment(editor, alignment) {
                if (!editor.selection) return;
                Transforms.setNodes(editor, {
                    align: alignment
                }, {
                    match: function(n) {
                        return Element.isElement(n) && !Editor.isEditor(n);
                    }
                });
            }
        },
        {
            key: "isAlignmentActive",
            value: /**
   * 检查当前选中块的对齐方式
   *
   * @param editor - 编辑器实例
   * @param alignment - 要检查的对齐方式
   * @returns 是否处于指定的对齐方式
   */ function isAlignmentActive(editor, alignment) {
                try {
                    var nodeEntries = Array.from(Editor.nodes(editor, {
                        match: function(n) {
                            return Element.isElement(n) && n.align === alignment;
                        }
                    }));
                    return nodeEntries.length > 0;
                } catch (error) {
                    console.error('Error checking alignment active:', error);
                    return false;
                }
            }
        },
        {
            key: "checkEnd",
            value: /**
   * 检查编辑器末尾是否需要添加段落节点
   *
   * @param editor - 编辑器实例
   * @returns 如果添加了段落节点则返回 true，否则返回 false
   */ function checkEnd(editor) {
                try {
                    var _node_children, _node_children_;
                    var nodeEntries = Array.from(Editor.nodes(editor, {
                        at: [],
                        mode: 'highest',
                        match: function(n) {
                            return Element.isElement(n);
                        },
                        reverse: true
                    }));
                    if (nodeEntries.length === 0) return false;
                    var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 2), node = _nodeEntries_[0], path = _nodeEntries_[1];
                    var nodeString = Node.string(node);
                    var hasMediaChild = (node === null || node === void 0 ? void 0 : (_node_children = node.children) === null || _node_children === void 0 ? void 0 : _node_children.length) === 1 && (node === null || node === void 0 ? void 0 : (_node_children_ = node.children[0]) === null || _node_children_ === void 0 ? void 0 : _node_children_.type) === 'media';
                    if ((node === null || node === void 0 ? void 0 : node.type) !== 'paragraph' || nodeString || hasMediaChild) {
                        Transforms.insertNodes(editor, EditorUtils.p, {
                            at: Path.next(path)
                        });
                        return true;
                    }
                    return false;
                } catch (error) {
                    console.error('Error in checkEnd:', error);
                    return false;
                }
            }
        },
        {
            key: "checkSelEnd",
            value: /**
   * 检查指定路径是否在编辑器末尾
   *
   * @param editor - 编辑器实例
   * @param path - 要检查的路径
   * @returns 如果路径在末尾则返回 true，否则返回 false
   */ function checkSelEnd(editor, path) {
                try {
                    var currentNode = Editor.node(editor, path);
                    while(!Editor.isEditor(currentNode[0])){
                        if (Editor.hasPath(editor, Path.next(currentNode[1]))) {
                            return false;
                        }
                        currentNode = Editor.node(editor, Path.parent(currentNode[1]));
                    }
                    return true;
                } catch (error) {
                    console.error('Error in checkSelEnd:', error);
                    return false;
                }
            }
        },
        {
            key: "findPath",
            value: /**
   * 安全地查找元素对应的Slate路径
   *
   * @param editor - 编辑器实例
   * @param el - DOM元素
   * @returns 元素对应的路径，如果查找失败则返回编辑器起始路径
   */ function findPath(editor, el) {
                try {
                    return ReactEditor.findPath(editor, el);
                } catch (error) {
                    console.error('find path error', error);
                    return Editor.start(editor, []).path;
                }
            }
        },
        {
            key: "createMediaNode",
            value: /**
   * 创建媒体节点（图片、视频等）
   *
   * @param src - 媒体资源URL
   * @param type - 媒体类型
   * @param extraPros - 额外属性
   * @returns 创建的媒体节点
   */ function createMediaNode(src, type, extraPros) {
                if (!src) {
                    return {
                        text: ''
                    };
                }
                try {
                    var fullSrc = EditorUtils.normalizeUrl(src);
                    var urlParams = EditorUtils.parseUrlParams(fullSrc);
                    var altText = (extraPros === null || extraPros === void 0 ? void 0 : extraPros.alt) || urlParams.get('alt') || '';
                    if (type === 'image' && EditorUtils.isImageType(src, (extraPros === null || extraPros === void 0 ? void 0 : extraPros.alt) || type)) {
                        return EditorUtils.createImageNode(src, altText, urlParams, extraPros);
                    }
                    return EditorUtils.createGenericMediaNode(src, type, extraPros);
                } catch (error) {
                    console.error('Error creating media node:', error, src);
                    return EditorUtils.createGenericMediaNode(src, type, extraPros);
                }
            }
        },
        {
            key: "normalizeUrl",
            value: /**
   * 标准化URL，添加协议前缀
   */ function normalizeUrl(src) {
                if (src.match(/^(https?:\/\/|data:|file:)/)) {
                    return src;
                }
                var origin = window.location.origin || '';
                return src.startsWith('/') ? "".concat(origin).concat(src) : "".concat(origin, "/").concat(src);
            }
        },
        {
            key: "parseUrlParams",
            value: /**
   * 解析URL参数
   */ function parseUrlParams(url) {
                try {
                    return new URL(url).searchParams;
                } catch (unused) {
                    return new URLSearchParams();
                }
            }
        },
        {
            key: "isImageType",
            value: /**
   * 检查是否为图片类型
   */ function isImageType(src, alt) {
                return [
                    'image'
                ].includes(getMediaType(src, alt));
            }
        },
        {
            key: "createImageNode",
            value: /**
   * 创建图片节点
   */ function createImageNode(src, altText, urlParams, extraPros) {
                return {
                    type: 'card',
                    block: urlParams.get('block') || false,
                    children: [
                        {
                            type: 'card-before',
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        },
                        _object_spread_props(_object_spread({}, extraPros || {}), {
                            block: urlParams.get('block') || false,
                            type: 'image',
                            url: src,
                            mediaType: 'image',
                            alt: altText,
                            width: urlParams.get('width') || undefined,
                            height: urlParams.get('height') || undefined,
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        }),
                        {
                            type: 'card-after',
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        }
                    ]
                };
            }
        },
        {
            key: "createGenericMediaNode",
            value: /**
   * 创建通用媒体节点
   */ function createGenericMediaNode(src, type, extraPros) {
                return {
                    type: 'card',
                    children: [
                        {
                            type: 'card-before',
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        },
                        _object_spread_props(_object_spread({}, extraPros || {}), {
                            type: 'media',
                            url: src,
                            children: [
                                {
                                    text: ''
                                }
                            ],
                            mediaType: type
                        }),
                        {
                            type: 'card-after',
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        }
                    ]
                };
            }
        },
        {
            key: "wrapperCardNode",
            value: /**
   * 用卡片节点包装普通节点
   *
   * @param node - 要包装的节点
   * @param props - 额外属性
   * @returns 包装后的卡片节点
   */ function wrapperCardNode(node) {
                var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
                return _object_spread_props(_object_spread({
                    type: 'card'
                }, props), {
                    children: [
                        {
                            type: 'card-before',
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        },
                        node,
                        {
                            type: 'card-after',
                            children: [
                                {
                                    text: ''
                                }
                            ]
                        }
                    ]
                });
            }
        }
    ]);
    return EditorUtils;
}();
// 可清除的文本格式属性
_define_property(EditorUtils, "CLEARABLE_MARKS", [
    'url',
    'strikethrough',
    'italic',
    'code',
    'bold',
    'color',
    'textColor',
    'highColor'
]);
/**
   * 替换编辑器中当前选中的节点
   *
   * @param editor - 编辑器实例
   * @param newNode - 要插入的新节点数组
   *
   * @description
   * 该方法会查找当前选区中的最低块级节点，然后用新的节点替换它。
   * 替换过程包括：查找最低块级节点，选中整个节点，插入新节点来替换原内容。
   */ _define_property(EditorUtils, "replaceSelectedNode", function(editor, newNode) {
    var nodeEntries = Array.from(Editor.nodes(editor, {
        mode: 'lowest'
    }));
    if (nodeEntries.length === 0) {
        // 如果没有选中节点，则直接插入新节点
        Transforms.insertNodes(editor, newNode);
        return;
    }
    var _nodeEntries_ = _sliced_to_array(nodeEntries[0], 2), node = _nodeEntries_[0], path = _nodeEntries_[1];
    if (Text.isText(node) && node.text === '') {
        // 如果是空文本节点，则操作其父节点
        var parentPath = Path.parent(path);
        Transforms.removeNodes(editor, {
            at: parentPath
        });
        Transforms.insertNodes(editor, newNode, {
            at: parentPath,
            select: true
        });
    } else {
        // 直接插入新节点
        Transforms.insertNodes(editor, newNode, {
            select: true
        });
    }
});
export var getDefaultView = function(value) {
    return value && value.ownerDocument && value.ownerDocument.defaultView || null;
};
export var isDOMNode = function(value) {
    var window1 = getDefaultView(value);
    return !!window1 && _instanceof(value, window1.Node);
};
export var isEventHandled = function(event, handler) {
    if (!handler) {
        return false;
    }
    handler(event);
    return event.isDefaultPrevented() || event.isPropagationStopped();
};
export var hasTarget = function(editor, target) {
    return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
};
function checkText(domPoint) {
    var _domPoint_parentElement;
    if (!isDOMNode(domPoint)) {
        return false;
    }
    var leafNode = domPoint === null || domPoint === void 0 ? void 0 : (_domPoint_parentElement = domPoint.parentElement) === null || _domPoint_parentElement === void 0 ? void 0 : _domPoint_parentElement.closest('[data-slate-leaf]');
    if (!leafNode) {
        return false;
    }
    var textNode = leafNode.closest('[data-slate-node="text"]');
    return !!textNode;
}
export var isTargetInsideVoid = function(editor, target) {
    var slateNode = hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target);
    // @ts-ignore
    return Editor.isVoid(editor, slateNode);
};
/**
 * 基于 anchorNode 和 focusNode 创建新的 DOM Selection 对象
 *
 * @param anchorNode - 选区起始节点
 * @param anchorOffset - 起始节点中的偏移量
 * @param focusNode - 选区结束节点
 * @param focusOffset - 结束节点中的偏移量
 * @returns 新创建的 Selection 对象，如果创建失败则返回 null
 */ export function createSelectionFromNodes(anchorNode, anchorOffset, focusNode, focusOffset) {
    if (typeof window === 'undefined') {
        return null;
    }
    if (!anchorNode || !focusNode) {
        return null;
    }
    try {
        var selection = window.getSelection();
        if (!selection) {
            return null;
        }
        // 清除当前选区
        selection.removeAllRanges();
        // 使用 setBaseAndExtent 方法创建新的选区
        selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
        return selection;
    } catch (error) {
        console.error('创建 Selection 对象失败:', error);
        return null;
    }
}
/**
 * 基于 anchorNode 和 focusNode 创建 DOM Range 对象
 *
 * @param anchorNode - 选区起始节点
 * @param anchorOffset - 起始节点中的偏移量
 * @param focusNode - 选区结束节点
 * @param focusOffset - 结束节点中的偏移量
 * @returns 新创建的 DOM Range 对象，如果创建失败则返回 null
 */ export function createDomRangeFromNodes(anchorNode, anchorOffset, focusNode, focusOffset) {
    if (typeof window === 'undefined') {
        return null;
    }
    if (!anchorNode || !focusNode) {
        return null;
    }
    try {
        var range = document.createRange();
        range.setStart(anchorNode, anchorOffset);
        range.setEnd(focusNode, focusOffset);
        return range;
    } catch (error) {
        console.error('创建 DOM Range 对象失败:', error);
        return null;
    }
}
/**
 * 检查节点是否可选择
 *
 * @param editor - React 编辑器实例
 * @param node - 待检查的节点
 * @returns 节点是否可选择
 */ function isNodeSelectable(editor, node) {
    if (!node) return false;
    return hasTarget(editor, node) || isTargetInsideVoid(editor, node);
}
/**
 * 创建并转换 Range 对象
 *
 * @param editor - React 编辑器实例
 * @param anchorNode - 起始节点
 * @param focusNode - 结束节点
 * @param originalRange - 原始 Range 对象
 * @returns 转换后的 Slate Range
 */ function createAndConvertRange(editor, anchorNode, focusNode, originalRange) {
    try {
        // 创建新的 DOM Range
        var domRange = document.createRange();
        // 使用原始 Range 的偏移量，确保精确性
        domRange.setStart(anchorNode, originalRange.startOffset);
        domRange.setEnd(focusNode, originalRange.endOffset);
        // 转换为 Slate Range
        return ReactEditor.toSlateRange(editor, domRange, {
            exactMatch: true,
            suppressThrow: false
        });
    } catch (error) {
        console.error('创建并转换 Range 失败:', error);
        return null;
    }
}
/**
 * 从 DOM Selection 对象中提取并转换为 Slate Range
 *
 * @param editor - React 编辑器实例
 * @param domSelection - DOM Selection 对象
 * @returns 转换后的 Slate Range 对象，如果转换失败则返回 null
 */ export function getSelectionFromDomSelection(editor, domSelection) {
    // 检查 Selection 是否有有效的 Range
    if (!domSelection.rangeCount || domSelection.rangeCount === 0) {
        return null;
    }
    try {
        var range = domSelection.getRangeAt(0);
        if (!range) {
            return null;
        }
        // 获取起始和结束容器节点
        var anchorNode = range.startContainer;
        var focusNode = range.endContainer;
        // 验证节点是否可选择
        if (!isNodeSelectable(editor, anchorNode) || !isNodeSelectable(editor, focusNode)) {
            return null;
        }
        // 验证文本节点
        if (!checkText(anchorNode) || !checkText(focusNode)) {
            return null;
        }
        // 创建新的 Range 并转换
        return createAndConvertRange(editor, anchorNode, focusNode, range);
    } catch (error) {
        console.error('getSelectionFromDomSelection error:', error);
        return null;
    }
}
/**
 * 检查目标是否为可编辑的 DOM 节点。
 *
 * @param editor - React 编辑器实例。
 * @param target - 事件目标，可能为 null。
 * @returns 如果目标是可编辑的 DOM 节点，则返回 true。
 */ export var hasEditableTarget = function(editor, target) {
    return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target, {
        editable: true
    });
};
export function getPointStrOffset(editor, point) {
    var nodes = Node.fragment(editor, {
        anchor: {
            path: Node.first(editor, point.path)[1],
            offset: 0
        },
        focus: point
    });
    var str = Node.string({
        type: '',
        children: nodes
    });
    return str.length;
}
export function getRelativePath(path, anther) {
    var newPath = _to_consumable_array(path);
    var newAnther = _to_consumable_array(anther);
    var relativeLen = path.length - anther.length;
    if (relativeLen > 0) {
        newAnther.unshift(new Array(relativeLen).fill(0));
    } else if (relativeLen < 0) {
        return new Array(anther.length).fill(0);
        newPath.unshift(new Array(-relativeLen).fill(0));
    }
    var relativePath = [];
    for(var i = 0; i < newPath.length; i++){
        if (newPath[i] !== newAnther[i]) {
            relativePath.push(newPath[i] - newAnther[i]);
        } else {
            relativePath.push(0);
        }
    }
    return relativePath;
}
export function calcPath(path, anther) {
    var newPath = _to_consumable_array(path);
    var newAnther = _to_consumable_array(anther);
    var relativeLen = path.length - anther.length;
    if (relativeLen > 0) {
        newAnther.unshift(new Array(relativeLen).fill(0));
    } else if (relativeLen < 0) {
        newPath.unshift(new Array(-relativeLen).fill(0));
    }
    var relativePath = [];
    for(var i = 0; i < newPath.length; i++){
        relativePath.push(newPath[i] + newAnther[i]);
    }
    return relativePath;
}
export function isPath(path) {
    for(var i = 0; i < path.length; i++){
        var num = path[i];
        if (!(isFinite(num) && num >= 0)) {
            return false;
        }
    }
    return true;
}
export function findLeafPath(editor, path) {
    var node = Editor.leaf(editor, path, {
        edge: 'end'
    });
    if (!node) return path;
    return node[1];
}
/**
 * 转义正则表达式特殊字符
 *
 * @param string - 需要转义的字符串
 * @returns 转义后的字符串
 * @private
 */ export function escapeRegExp(string) {
    return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
/**
 * 清理和标准化 Markdown 搜索文本
 *
 * @param searchText - 原始搜索文本，可能包含 Markdown 语法
 * @returns 包含原文本和清理后文本的数组
 * @public
 */ export function normalizeMarkdownSearchText(searchText) {
    if (!searchText.trim()) return [];
    var searchVariants = new Set();
    // 添加原始文本
    searchVariants.add(searchText.trim());
    // 移除常见的 Markdown 语法
    var cleanText = searchText// 移除图片语法 ![alt](url) -> alt (必须在链接语法之前处理)
    .replace(/!\[([^\]]*)\]\([^)]+\)/g, '$1')// 移除链接语法 [text](url) -> text
    .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')// 移除粗体语法 **text** 或 __text__ -> text
    .replace(/\*\*(.*?)\*\*/g, '$1').replace(/__(.*?)__/g, '$1')// 移除斜体语法 *text* 或 _text_ -> text
    .replace(/\*(.*?)\*/g, '$1').replace(/_(.*?)_/g, '$1')// 移除行内代码语法 `code` -> code
    .replace(/`([^`]+)`/g, '$1')// 移除删除线语法 ~~text~~ -> text
    .replace(/~~(.*?)~~/g, '$1')// 移除标题语法 # text -> text
    .replace(/^#+\s+(.*)$/gm, '$1')// 移除引用语法 > text -> text
    .replace(/^>\s*(.*)$/gm, '$1')// 移除列表标记 - text 或 * text 或 + text -> text
    .replace(/^[\s]*[-*+]\s+(.*)$/gm, '$1')// 移除有序列表标记 1. text -> text
    .replace(/^\s*\d+\.\s+(.*)$/gm, '$1').trim();
    if (cleanText && cleanText !== searchText.trim()) {
        searchVariants.add(cleanText);
    }
    // 如果清理后的文本包含多个单词，也添加每个单词
    var words = cleanText.split(/\s+/).filter(function(word) {
        return word.length > 1;
    });
    if (words.length > 1) {
        words.forEach(function(word) {
            return searchVariants.add(word);
        });
    }
    // 移除空字符串
    return Array.from(searchVariants).filter(function(text) {
        return text.length > 0;
    });
}
/**
 * 在编辑器中按路径和文本搜索内容，支持 Markdown 文本的智能处理
 *
 * @param editor - 编辑器实例
 * @param pathDescription - 搜索范围的路径描述
 * @param searchText - 搜索文本，支持 Markdown 语法
 * @param options - 搜索选项
 * @param options.caseSensitive - 是否区分大小写，默认 false
 * @param options.wholeWord - 是否全词匹配，默认 false
 * @param options.maxResults - 最大结果数量，默认 2
 * @param options.includeMarkdownVariants - 是否包含 Markdown 语法的清理变体，默认 true
 * @returns 搜索结果数组，包含路径、范围、节点、链接信息等
 *
 * @description
 * 该函数支持以下功能：
 * - 自动清理 Markdown 语法（链接、粗体、斜体、代码等）
 * - 生成多个搜索变体以提高匹配率
 * - 避免重复匹配同一位置的文本
 * - 记录匹配的搜索变体信息
 * - 支持识别链接（a 标签）：返回结果包含 isLink 和 linkUrl 字段
 *
 * @example
 * // 搜索包含 Markdown 语法的文本
 * const results = findByPathAndText(editor, [0], "**粗体文本**");
 * // 将同时匹配 "**粗体文本**" 和 "粗体文本"
 *
 * @example
 * // 搜索链接文本
 * const results = findByPathAndText(editor, [0], "点击这里");
 * // 如果匹配到的是链接，results[0].isLink === true 且 results[0].linkUrl 包含 URL
 */ export function findByPathAndText(editor, pathDescription, searchText) {
    var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
    var _options_caseSensitive = options.caseSensitive, caseSensitive = _options_caseSensitive === void 0 ? false : _options_caseSensitive, _options_wholeWord = options.wholeWord, wholeWord = _options_wholeWord === void 0 ? false : _options_wholeWord, _options_maxResults = options.maxResults, maxResults = _options_maxResults === void 0 ? 2 : _options_maxResults, _options_includeMarkdownVariants = options.includeMarkdownVariants, includeMarkdownVariants = _options_includeMarkdownVariants === void 0 ? true : _options_includeMarkdownVariants;
    if (!searchText.trim()) return [];
    var results = [];
    // 获取所有搜索变体
    var searchVariants = includeMarkdownVariants ? normalizeMarkdownSearchText(searchText) : [
        searchText.trim()
    ];
    if (searchVariants.length === 0) return [];
    // 为每个搜索变体创建正则表达式
    var flags = caseSensitive ? 'g' : 'gi';
    var patterns = searchVariants.map(function(variant) {
        return {
            variant: variant,
            pattern: wholeWord ? new RegExp("\\b".concat(escapeRegExp(variant), "\\b"), flags) : new RegExp(escapeRegExp(variant), flags)
        };
    });
    try {
        // 根据 pathDescription 确定搜索范围
        var searchRange;
        if (pathDescription && pathDescription.length > 0) {
            // 路径数组模式：直接在指定路径中搜索
            try {
                if (Editor.hasPath(editor, pathDescription)) {
                    searchRange = [
                        pathDescription
                    ];
                }
            } catch (e) {
                console.debug('无效的搜索路径:', pathDescription, e);
                searchRange = undefined;
            }
        }
        // 获取文本节点
        var textNodesGenerator;
        if (searchRange && searchRange.length > 0) {
            // 在指定路径范围内搜索
            var allTextNodes = [];
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = searchRange[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var rangePath = _step.value;
                    try {
                        var _allTextNodes;
                        var rangeNodes = Array.from(Editor.nodes(editor, {
                            at: rangePath,
                            match: function(n) {
                                return Text.isText(n) && typeof n.text === 'string' && n.text.length > 0;
                            }
                        }));
                        (_allTextNodes = allTextNodes).push.apply(_allTextNodes, _to_consumable_array(rangeNodes));
                    } catch (e) {
                        continue;
                    }
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
            textNodesGenerator = allTextNodes;
        } else {
            // 在整个编辑器中搜索
            textNodesGenerator = Array.from(Editor.nodes(editor, {
                at: [],
                match: function(n) {
                    return Text.isText(n) && typeof n.text === 'string' && n.text.length > 0;
                }
            }));
        }
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            var _loop = function() {
                var _step_value = _sliced_to_array(_step1.value, 2), node = _step_value[0], path = _step_value[1];
                if (!Text.isText(node) || !node.text) return "continue";
                var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                try {
                    // 对每个搜索变体进行匹配
                    for(var _iterator = patterns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                        var _loop = function() {
                            // 获取父节点信息
                            var lineContent = node.text;
                            var nodeType = 'text';
                            try {
                                var parentPath = Path.parent(path);
                                if (Editor.hasPath(editor, parentPath)) {
                                    var parent = Node.get(editor, parentPath);
                                    if (Element.isElement(parent)) {
                                        lineContent = Node.string(parent);
                                        nodeType = parent.type || 'unknown';
                                    }
                                }
                            } catch (e) {
                            // 如果获取父节点失败，使用原始文本
                            }
                            var matchIndex = match.index;
                            var matchLength = match[0].length;
                            var matchText = match[0];
                            var range = {
                                anchor: {
                                    path: path,
                                    offset: matchIndex
                                },
                                focus: {
                                    path: path,
                                    offset: matchIndex + matchLength
                                }
                            };
                            // 检查是否已经有相同位置的匹配结果，避免重复
                            var isDuplicate = results.some(function(result) {
                                return Path.equals(result.path, path) && result.offset.start === matchIndex && result.offset.end === matchIndex + matchLength;
                            });
                            if (!isDuplicate) {
                                // 检查是否为链接节点（带有 url 属性的文本节点）
                                var isLink = Text.isText(node) && !!node.url;
                                var linkUrl = isLink ? node.url : undefined;
                                results.push({
                                    path: path,
                                    range: range,
                                    node: node,
                                    matchedText: matchText,
                                    offset: {
                                        start: matchIndex,
                                        end: matchIndex + matchLength
                                    },
                                    lineContent: lineContent.trim(),
                                    nodeType: nodeType,
                                    searchVariant: variant !== searchText.trim() ? variant : undefined,
                                    isLink: isLink,
                                    linkUrl: linkUrl
                                });
                            }
                            // 限制结果数量避免性能问题
                            if (results.length >= maxResults) return "break";
                        };
                        var _step_value1 = _step.value, variant = _step_value1.variant, pattern = _step_value1.pattern;
                        var match = void 0;
                        pattern.lastIndex = 0;
                        while((match = pattern.exec(node.text)) !== null){
                            var _ret = _loop();
                            if (_ret === "break") break;
                        }
                        if (results.length >= maxResults) break;
                    }
                } catch (err) {
                    _didIteratorError = true;
                    _iteratorError = err;
                } finally{
                    try {
                        if (!_iteratorNormalCompletion && _iterator.return != null) {
                            _iterator.return();
                        }
                    } finally{
                        if (_didIteratorError) {
                            throw _iteratorError;
                        }
                    }
                }
                if (results.length >= maxResults) return "break";
            };
            // 遍历文本节点查找匹配
            for(var _iterator1 = textNodesGenerator[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var _ret = _loop();
                if (_ret === "break") break;
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
    } catch (error) {
        console.error('查找过程中出错:', error);
    }
    return results;
}
