/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var cx = require('classnames');
var close = require('../icons/close.svg.js');
var closeSmall = require('../icons/close-small.svg.js');
var statusClose = require('../icons/status-close.svg.js');
var undo = require('../icons/undo.svg.js');
var undoNormal = require('../icons/undo-normal.svg.js');
var redo = require('../icons/redo.svg.js');
var enter = require('../icons/enter.svg.js');
var volume = require('../icons/volume.svg.js');
var mute = require('../icons/mute.svg.js');
var play = require('../icons/play.svg.js');
var pause = require('../icons/pause.svg.js');
var leftArrow = require('../icons/left-arrow.svg.js');
var rightArrow = require('../icons/right-arrow.svg.js');
var arrowDoubleLeft = require('../icons/arrow-double-left.svg.js');
var arrowDoubleRight = require('../icons/arrow-double-right.svg.js');
var check = require('../icons/check.svg.js');
var plus = require('../icons/plus.svg.js');
var subPlus = require('../icons/sub-plus.svg.js');
var minus = require('../icons/minus.svg.js');
var pencil = require('../icons/pencil.svg.js');
var view = require('../icons/view.svg.js');
var remove = require('../icons/remove.svg.js');
var retry = require('../icons/retry.svg.js');
var upload = require('../icons/upload.svg.js');
var download = require('../icons/download.svg.js');
var file = require('../icons/file.svg.js');
var success = require('../icons/success.svg.js');
var fail = require('../icons/fail.svg.js');
var search = require('../icons/search.svg.js');
var back = require('../icons/back.svg.js');
var move = require('../icons/move.svg.js');
var info = require('../icons/info.svg.js');
var location = require('../icons/location.svg.js');
var dragBar = require('../icons/drag-bar.svg.js');
var reload = require('../icons/reload.svg.js');
var exchange = require('../icons/exchange.svg.js');
var columns = require('../icons/columns.svg.js');
var calendar = require('../icons/calendar.svg.js');
var clock = require('../icons/clock.svg.js');
var treeDown = require('../icons/tree-down.svg.js');
var cloudUpload = require('../icons/cloud-upload.svg.js');
var image = require('../icons/image.svg.js');
var refresh = require('../icons/refresh.svg.js');
var drag = require('../icons/drag.svg.js');
var edit = require('../icons/edit.svg.js');
var deskEmpty = require('../icons/desk-empty.svg.js');
var fullscreen = require('../icons/fullscreen.svg.js');
var unfullscreen = require('../icons/unfullscreen.svg.js');
var copy = require('../icons/copy.svg.js');
var filter = require('../icons/filter.svg.js');
var caret = require('../icons/caret.svg.js');
var rightArrowBold = require('../icons/right-arrow-bold.svg.js');
var downArrowBold = require('../icons/down-arrow-bold.svg.js');
var columnFilter = require('../icons/column-filter.svg.js');
var zoomIn = require('../icons/zoom-in.svg.js');
var zoomOut = require('../icons/zoom-out.svg.js');
var question = require('../icons/question.svg.js');
var question2 = require('../icons/question2.svg.js');
var questionMark = require('../icons/question-mark.svg.js');
var windowRestore = require('../icons/window-restore.svg.js');
var infoCircle = require('../icons/info-circle.svg.js');
var warning = require('../icons/warning.svg.js');
var warningMark = require('../icons/warning-mark.svg.js');
var schedule = require('../icons/schedule.svg.js');
var home = require('../icons/home.svg.js');
var folder = require('../icons/folder.svg.js');
var sortDefault = require('../icons/sort-default.svg.js');
var sortAsc = require('../icons/sort-asc.svg.js');
var sortDesc = require('../icons/sort-desc.svg.js');
var setting = require('../icons/setting.svg.js');
var plusCicle = require('../icons/plus-cicle.svg.js');
var plusFine = require('../icons/plus-fine.svg.js');
var ellipsisV = require('../icons/ellipsis-v.svg.js');
var expandAlt = require('../icons/expand-alt.svg.js');
var compressAlt = require('../icons/compress-alt.svg.js');
var transparent = require('../icons/transparent.svg.js');
var loadingOutline = require('../icons/loading-outline.svg.js');
var star = require('../icons/star.svg.js');
var alertSuccess = require('../icons/alert-success.svg.js');
var alertInfo = require('../icons/alert-info.svg.js');
var alertWarning = require('../icons/alert-warning.svg.js');
var alertDanger = require('../icons/alert-danger.svg.js');
var _function = require('../icons/function.svg.js');
var inputClear = require('../icons/input-clear.svg.js');
var sliderHandleIcon = require('../icons/slider-handle-icon.svg.js');
var trash = require('../icons/trash.svg.js');
var menu = require('../icons/menu.svg.js');
var userRemove = require('../icons/user-remove.svg.js');
var role = require('../icons/role.svg.js');
var department = require('../icons/department.svg.js');
var post = require('../icons/post.svg.js');
var dot = require('../icons/dot.svg.js');
var stepsFinsh = require('../icons/steps-finsh.svg.js');
var invisible = require('../icons/invisible.svg.js');
var date = require('../icons/date.svg.js');
var down = require('../icons/down.svg.js');
var rightDoubleArrow = require('../icons/right-double-arrow.svg.js');
var newEdit = require('../icons/new-edit.svg.js');
var rotateLeft = require('../icons/rotate-left.svg.js');
var rotateRight = require('../icons/rotate-right.svg.js');
var scaleOrigin = require('../icons/scale-origin.svg.js');
var _if = require('../icons/if.svg.js');
var rotateScreen = require('../icons/rotate-screen.svg.js');
var isObject = require('lodash/isObject');
var amisCore = require('amis-core');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
// 兼容原来的用法，后续不直接试用。
var closeIcon = _J$X_(close["default"], null);
var unDoIcon = _J$X_(undo["default"], null);
var reDoIcon = _J$X_(redo["default"], null);
var enterIcon = _J$X_(enter["default"], null);
var volumeIcon = _J$X_(volume["default"], null);
var muteIcon = _J$X_(mute["default"], null);
var playIcon = _J$X_(play["default"], null);
var pauseIcon = _J$X_(pause["default"], null);
var leftArrowIcon = _J$X_(leftArrow["default"], null);
var rightArrowIcon = _J$X_(rightArrow["default"], null);
var iconFactory = {};
function getIconNames() {
    return Object.keys(iconFactory);
}
function getIcon(key) {
    return iconFactory[key];
}
function hasIcon(iconName) {
    return !!getIcon(iconName);
}
function registerIcon(key, component) {
    iconFactory[key] = component;
}
registerIcon('close', close["default"]);
registerIcon('close-small', closeSmall["default"]);
registerIcon('status-close', statusClose["default"]);
registerIcon('undo', undo["default"]);
registerIcon('undo-normal', undoNormal["default"]);
registerIcon('full-screen', fullscreen["default"]);
registerIcon('un-fullscreen', unfullscreen["default"]);
registerIcon('redo', redo["default"]);
registerIcon('enter', enter["default"]);
registerIcon('volume', volume["default"]);
registerIcon('mute', mute["default"]);
registerIcon('play', play["default"]);
registerIcon('pause', pause["default"]);
registerIcon('left-arrow', leftArrow["default"]);
registerIcon('right-arrow', rightArrow["default"]);
registerIcon('prev', leftArrow["default"]);
registerIcon('next', rightArrow["default"]);
registerIcon('check', check["default"]);
registerIcon('plus', plus["default"]);
registerIcon('sub-plus', subPlus["default"]);
registerIcon('add', plus["default"]);
registerIcon('minus', minus["default"]);
registerIcon('pencil', pencil["default"]);
registerIcon('view', view["default"]);
registerIcon('remove', remove["default"]);
registerIcon('retry', retry["default"]);
registerIcon('upload', upload["default"]);
registerIcon('download', download["default"]);
registerIcon('file', file["default"]);
registerIcon('success', success["default"]);
registerIcon('fail', fail["default"]);
registerIcon('warning', warning["default"]);
registerIcon('warning-mark', warningMark["default"]);
registerIcon('search', search["default"]);
registerIcon('back', back["default"]);
registerIcon('move', move["default"]);
registerIcon('info', info["default"]);
registerIcon('info-circle', infoCircle["default"]);
registerIcon('location', location["default"]);
registerIcon('drag-bar', dragBar["default"]);
registerIcon('reload', reload["default"]);
registerIcon('exchange', exchange["default"]);
registerIcon('columns', columns["default"]);
registerIcon('calendar', calendar["default"]);
registerIcon('clock', clock["default"]);
registerIcon('copy', copy["default"]);
registerIcon('filter', filter["default"]);
registerIcon('column-filter', columnFilter["default"]);
registerIcon('caret', caret["default"]);
registerIcon('right-arrow-bold', rightArrowBold["default"]);
registerIcon('down-arrow-bold', downArrowBold["default"]);
registerIcon('zoom-in', zoomIn["default"]);
registerIcon('zoom-out', zoomOut["default"]);
registerIcon('question', question["default"]);
registerIcon('question2', question2["default"]);
registerIcon('question-mark', questionMark["default"]);
registerIcon('window-restore', windowRestore["default"]);
registerIcon('schedule', schedule["default"]);
registerIcon('home', home["default"]);
registerIcon('folder', folder["default"]);
registerIcon('sort-default', sortDefault["default"]);
registerIcon('sort-asc', sortAsc["default"]);
registerIcon('sort-desc', sortDesc["default"]);
registerIcon('setting', setting["default"]);
registerIcon('plus-cicle', plusCicle["default"]);
registerIcon('ellipsis-v', ellipsisV["default"]);
registerIcon('expand-alt', expandAlt["default"]);
registerIcon('compress-alt', compressAlt["default"]);
registerIcon('transparent', transparent["default"]);
registerIcon('loading-outline', loadingOutline["default"]);
registerIcon('star', star["default"]);
registerIcon('alert-success', alertSuccess["default"]);
registerIcon('alert-info', alertInfo["default"]);
registerIcon('alert-warning', alertWarning["default"]);
registerIcon('alert-danger', alertDanger["default"]);
registerIcon('alert-fail', alertDanger["default"]);
registerIcon('tree-down', treeDown["default"]);
registerIcon('function', _function["default"]);
registerIcon('input-clear', inputClear["default"]);
registerIcon('slider-handle', sliderHandleIcon["default"]);
registerIcon('cloud-upload', cloudUpload["default"]);
registerIcon('image', image["default"]);
registerIcon('refresh', refresh["default"]);
registerIcon('trash', trash["default"]);
registerIcon('menu', menu["default"]);
registerIcon('user-remove', userRemove["default"]);
registerIcon('role', role["default"]);
registerIcon('department', department["default"]);
registerIcon('post', post["default"]);
registerIcon('dot', dot["default"]);
registerIcon('drag', drag["default"]);
registerIcon('edit', edit["default"]);
registerIcon('desk-empty', deskEmpty["default"]);
registerIcon('invisible', invisible["default"]);
registerIcon('plus-fine', plusFine["default"]);
registerIcon('steps-finsh', stepsFinsh["default"]);
registerIcon('date', date["default"]);
registerIcon('remove', remove["default"]);
registerIcon('invisible', invisible["default"]);
registerIcon('down', down["default"]);
registerIcon('right-double-arrow', rightDoubleArrow["default"]);
registerIcon('arrow-double-left', arrowDoubleLeft["default"]);
registerIcon('arrow-double-right', arrowDoubleRight["default"]);
registerIcon('new-edit', newEdit["default"]);
registerIcon('rotate-left', rotateLeft["default"]);
registerIcon('rotate-right', rotateRight["default"]);
registerIcon('scale-origin', scaleOrigin["default"]);
registerIcon('if', _if["default"]);
registerIcon('rotate-screen', rotateScreen["default"]);
function svgString2Dom(icon, _a, vendorFn) {
    var className = _a.className, classNameProp = _a.classNameProp, style = _a.style, cx = _a.cx, events = _a.events, extra = _a.extra;
    icon = icon.replace(/\n/g, ' ').replace(/\s+/g, ' ');
    if (vendorFn) {
        var _b = vendorFn(icon, tslib.__assign(tslib.__assign({}, extra), { width: style === null || style === void 0 ? void 0 : style.width, height: style === null || style === void 0 ? void 0 : style.height })), newIcon = _b.icon, newStyle = _b.style;
        icon = newIcon;
        style = tslib.__assign(tslib.__assign({}, (style || {})), newStyle);
    }
    var svgStr = /<svg .*?>(.*?)<\/svg>/.exec(icon);
    var viewBox = /viewBox="(.*?)"/.exec(icon);
    var svgHTML = React.createElement('svg', tslib.__assign(tslib.__assign({}, events), { className: cx('icon', className, classNameProp), style: style, dangerouslySetInnerHTML: { __html: svgStr ? svgStr[1] : '' }, viewBox: (viewBox === null || viewBox === void 0 ? void 0 : viewBox[1]) || '0 0 16 16' }));
    return svgHTML;
}
function LinkIcon(_a) {
    var icon = _a.icon, vendorFn = _a.vendorFn, _b = _a.options, className = _b.className, classNameProp = _b.classNameProp, style = _b.style, cx = _b.cx, classPrefix = _b.classPrefix, events = _b.events, extra = _b.extra;
    var _c = tslib.__read(React__default["default"].useState(icon), 2), svgIcon = _c[0], setSvgIcon = _c[1];
    var _d = tslib.__read(React__default["default"].useState('img'), 2), svgType = _d[0], setSvgType = _d[1];
    React.useEffect(function () {
        if (icon.endsWith('.svg') && vendorFn) {
            try {
                fetch(icon)
                    .then(function (res) { return res.text(); })
                    .then(function (svg) {
                    setSvgType('svg');
                    setSvgIcon(svg);
                })
                    .catch(function (e) {
                    console.warn(e);
                    setSvgType('img');
                    setSvgIcon(icon);
                });
            }
            catch (warn) {
                console.warn(warn);
                setSvgType('img');
                setSvgIcon(icon);
            }
        }
    }, [icon, vendorFn]);
    return svgType === 'img' ? (_J$X_("img", tslib.__assign({}, events, { className: cx("".concat(classPrefix, "Icon"), className, classNameProp), src: icon, style: style }))) : (svgString2Dom(svgIcon, {
        className: className,
        classNameProp: classNameProp,
        style: style,
        cx: cx,
        events: events,
        extra: extra
    }, vendorFn));
}
function Icon(_a) {
    var _b;
    var icon = _a.icon, className = _a.className, _c = _a.classPrefix, classPrefix = _c === void 0 ? '' : _c, classNameProp = _a.classNameProp, iconContent = _a.iconContent, vendor = _a.vendor, iconCx = _a.cx, onClick = _a.onClick, onMouseEnter = _a.onMouseEnter, onMouseLeave = _a.onMouseLeave, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut, onMouseDown = _a.onMouseDown, onMouseUp = _a.onMouseUp, onMouseMove = _a.onMouseMove, onBlur = _a.onBlur, onFocus = _a.onFocus, onTouchStart = _a.onTouchStart, onTouchMove = _a.onTouchMove, onTouchEnd = _a.onTouchEnd, onTouchCancel = _a.onTouchCancel, style = _a.style, width = _a.width, height = _a.height, extra = _a.extra, testIdBuilder = _a.testIdBuilder;
    var cx = iconCx || cx__default["default"];
    var vendorFn = React.useMemo(function () { return amisCore.getCustomVendor(vendor); }, [vendor]);
    // style = {
    //   ...(style || {}),
    //   width: width || style?.width,
    //   height: height || style?.height
    // };
    if (width !== undefined) {
        style = tslib.__assign(tslib.__assign({}, style), { width: width });
    }
    if (height !== undefined) {
        style = tslib.__assign(tslib.__assign({}, style), { height: height });
    }
    if (typeof jest !== 'undefined' && icon) {
        iconContent = '';
    }
    if (!icon && !iconContent) {
        return null;
    }
    // 支持的事件
    var events = {
        onClick: onClick,
        onMouseEnter: onMouseEnter,
        onMouseLeave: onMouseLeave,
        onMouseOver: onMouseOver,
        onMouseOut: onMouseOut,
        onMouseDown: onMouseDown,
        onMouseUp: onMouseUp,
        onMouseMove: onMouseMove,
        onBlur: onBlur,
        onFocus: onFocus,
        onTouchStart: onTouchStart,
        onTouchMove: onTouchMove,
        onTouchEnd: onTouchEnd,
        onTouchCancel: onTouchCancel
    };
    // 直接的icon dom
    if (React__default["default"].isValidElement(icon)) {
        return React__default["default"].cloneElement(icon, tslib.__assign(tslib.__assign(tslib.__assign({}, events), (icon.props || {})), { className: cx__default["default"](cx(className, classNameProp), icon.props.className), style: style }));
    }
    if (iconContent) {
        // 从css变量中获取icon
        var refFn = function (dom) {
            if (dom) {
                var domStyle = getComputedStyle(dom);
                var svgStr = domStyle.getPropertyValue('content');
                var svg = /(<svg.*<\/svg>)/.exec(svgStr);
                if (svg) {
                    var svgHTML = svg[0].replace(/\\"/g, '"');
                    if (dom.svgHTMLClone !== svgHTML) {
                        dom.innerHTML = svgHTML;
                        // 存储svg，不直接用innerHTML是防止<circle />渲染后变成<circle></circle>的情况
                        dom.svgHTMLClone = svgHTML;
                        dom.style.display = '';
                    }
                }
            }
        };
        return (_J$X_("div", tslib.__assign({}, events, { className: cx(iconContent, className, classNameProp), ref: refFn, style: style }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getTestId())));
    }
    // 获取注册的icon
    var Component = getIcon(icon);
    if (Component) {
        return (_J$X_(Component, tslib.__assign({}, events, { className: cx(className, "icon-".concat(icon), classNameProp), 
            // @ts-ignore
            icon: icon, style: style }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getTestId())));
    }
    // 符合schema的icon
    if (isObject__default["default"](icon) &&
        icon.type === 'icon' &&
        icon.icon) {
        icon = icon.icon;
    }
    // icon是引用svg的情况
    if (isObject__default["default"](icon) &&
        typeof icon.id === 'string' &&
        icon.id.startsWith('svg-')) {
        var svg = icon;
        var id = "".concat(svg.id.replace(/^svg-/, ''));
        if (!document.getElementById(id)) {
            // 如果svg symbol不存在，则尝试将svg字符串赋值给icon，走svg字符串的逻辑
            icon = (_b = svg.svg) === null || _b === void 0 ? void 0 : _b.replace(/'/g, '');
        }
        else {
            return (_J$X_("svg", tslib.__assign({}, events, { className: cx('icon', 'icon-object', className, classNameProp), style: style }),
                _J$X_("use", { xlinkHref: '#' + id })));
        }
    }
    // 直接传入svg字符串
    if (typeof icon === 'string' && icon.startsWith('<svg')) {
        return svgString2Dom(icon, {
            className: className,
            classNameProp: classNameProp,
            style: style,
            cx: cx,
            events: events,
            extra: extra
        }, vendorFn);
    }
    // icon是链接
    var isURLIcon = typeof icon === 'string' && (icon === null || icon === void 0 ? void 0 : icon.indexOf('.')) !== -1;
    if (isURLIcon) {
        return (_J$X_(LinkIcon, { icon: icon, vendorFn: vendorFn, options: {
                className: className,
                classNameProp: classNameProp,
                style: style,
                cx: cx,
                classPrefix: classPrefix,
                events: events,
                extra: extra
            } }));
    }
    // icon是普通字符串
    var isIconfont = typeof icon === 'string';
    var iconPrefix = '';
    if (vendor === 'iconfont') {
        iconPrefix = "iconfont icon-".concat(icon);
    }
    else if (vendor === 'fa') {
        //默认是fontawesome v4，兼容之前配置
        iconPrefix = "".concat(vendor, " ").concat(vendor, "-").concat(icon);
    }
    else {
        // 如果vendor为空，则不设置前缀,这样可以支持fontawesome v5、fontawesome v6或者其他框架
        iconPrefix = icon;
    }
    if (isIconfont) {
        return (_J$X_("i", tslib.__assign({}, events, { className: cx(icon, className, classNameProp, iconPrefix), style: style })));
    }
    // 没有合适的图标
    return _J$X_("span", { className: "text-danger" },
        "\u6CA1\u6709 icon ",
        icon);
}

exports.CloseIcon = close["default"];
exports.UnDoIcon = undo["default"];
exports.ReDoIcon = redo["default"];
exports.EnterIcon = enter["default"];
exports.VolumeIcon = volume["default"];
exports.MuteIcon = mute["default"];
exports.PlayIcon = play["default"];
exports.PauseIcon = pause["default"];
exports.LeftArrowIcon = leftArrow["default"];
exports.RightArrowIcon = rightArrow["default"];
exports.CheckIcon = check["default"];
exports.PlusIcon = plus["default"];
exports.MinusIcon = minus["default"];
exports.PencilIcon = pencil["default"];
exports.ReloadIcon = reload["default"];
exports.DownArrowBoldIcon = downArrowBold["default"];
exports.FunctionIcon = _function["default"];
exports.InputClearIcon = inputClear["default"];
exports.MenuIcon = menu["default"];
exports.UserRemove = userRemove["default"];
exports.Role = role["default"];
exports.Department = department["default"];
exports.Post = post["default"];
exports.RightDoubleArrowIcon = rightDoubleArrow["default"];
exports.Icon = Icon;
exports.closeIcon = closeIcon;
exports["default"] = Icon;
exports.enterIcon = enterIcon;
exports.getIcon = getIcon;
exports.getIconNames = getIconNames;
exports.hasIcon = hasIcon;
exports.leftArrowIcon = leftArrowIcon;
exports.muteIcon = muteIcon;
exports.pauseIcon = pauseIcon;
exports.playIcon = playIcon;
exports.reDoIcon = reDoIcon;
exports.registerIcon = registerIcon;
exports.rightArrowIcon = rightArrowIcon;
exports.unDoIcon = unDoIcon;
exports.volumeIcon = volumeIcon;
