/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

'use strict';

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

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var vectorComputed = require('../utils/vectorComputed.js');

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

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var SvgPathGenerator = /** @class */ (function () {
    function SvgPathGenerator(size) {
        this.size = size;
    }
    SvgPathGenerator.getPath = function (type, props) {
        var radius = props.radius, paths = props.paths;
        var generator = new SvgPathGenerator(200);
        if (type === 'custom') {
            return this.getCustomPath(paths);
        }
        var genFun = generator.getGenerage(type);
        if (!genFun) {
            return [];
        }
        return genFun(radius * 10);
    };
    SvgPathGenerator.getStrokeProps = function (stroke, strokeWidth, strokeType) {
        if (strokeType === 'line') {
            return {
                stroke: stroke,
                strokeWidth: strokeWidth
            };
        }
        else if (strokeType === 'dash') {
            return {
                stroke: stroke,
                strokeWidth: strokeWidth,
                strokeDasharray: "".concat(strokeWidth * 2, ",").concat(strokeWidth)
            };
        }
        else if (strokeType === 'dot') {
            return {
                stroke: stroke,
                strokeWidth: strokeWidth,
                strokeDasharray: "1,".concat(strokeWidth * 2),
                strokeLinecap: 'round',
                strokeLinejoin: 'miter'
            };
        }
    };
    SvgPathGenerator.prototype.toRadians = function (degrees) {
        return degrees * (Math.PI / 180);
    };
    SvgPathGenerator.prototype.getGenerage = function (type) {
        var ShapeConfig = {
            'square': this.getSquarePath.bind(this),
            'triangle': this.getTrianglePath.bind(this),
            'right-triangle': this.getRightTrianglePath.bind(this),
            'rectangle': this.getRectanglePath.bind(this),
            'convex-arc-rectangle': this.getConvexArcRectangle.bind(this),
            'concave-arc-rectangle': this.getConcaveArcRectangle.bind(this),
            'double-convex-arc-rectangle': this.getDConvexArcRectangle.bind(this),
            'double-concave-arc-rectangle': this.getDConcaveArcRectangle.bind(this),
            'barrel-rectangle': this.getBarrelRectangle.bind(this),
            'rhombus': this.getRhombusPath.bind(this),
            'parallelogram': this.getParallelogramPath.bind(this),
            'rectangle-1': this.getRectangleType1Path.bind(this),
            'rectangle-2': this.getRectangleType2Path.bind(this),
            'rectangle-3': this.getRectangleType3Path.bind(this),
            'pentagon': this.getPentagon.bind(this),
            'hexagon': this.getHexagon.bind(this),
            'octagon': this.getOctagonPath.bind(this),
            'hexagon-star': this.getHexagonStar.bind(this),
            'star': this.getStar.bind(this),
            'heart': this.getHeart.bind(this),
            'circle': this.getCirclePath.bind(this),
            'arrow': this.getArrowPath.bind(this),
            'leaf': this.getLeafPath.bind(this)
        };
        return ShapeConfig[type];
    };
    SvgPathGenerator.prototype.radiusPath = function (radius, _a, _b, _c) {
        var _d = tslib.__read(_a, 2), endX1 = _d[0], endY1 = _d[1];
        var _e = tslib.__read(_b, 2), startX = _e[0], startY = _e[1];
        var _f = tslib.__read(_c, 2), endX2 = _f[0], endY2 = _f[1];
        var flag = true;
        if (radius < 0) {
            radius = radius * -1;
            // 圆角向内
            flag = false;
        }
        var _g = vectorComputed.radiusStartEndPoint([startX, startY, endX1, endY1], [startX, startY, endX2, endY2], radius), start = _g.start, end = _g.end, mxRadius = _g.radius, sweepFlag = _g.sweepFlag;
        return [
            "".concat(start[0], ",").concat(start[1]),
            "".concat(mxRadius, " ").concat(mxRadius, " ").concat(0, " ").concat(0, " ").concat(flag ? sweepFlag : sweepFlag ^ 1, "\n       ").concat(end[0], ",").concat(end[1])
        ];
    };
    /**
     * 将 SVG 路径的每个角添加圆角
     *
     * @param {string[]} path
     * @param {number} radius
     * @returns
     * @memberof SvgPathGenerator
     */
    SvgPathGenerator.prototype.addRoundCornersToPath = function (points, radius) {
        var newPath = [];
        for (var i = 0; i < points.length; i++) {
            var nextItem = points[i + 1] || points[0];
            var preItem = points[i - 1] || points[points.length - 1];
            var _a = tslib.__read(points[i], 2), startX = _a[0], startY = _a[1];
            var _b = tslib.__read(nextItem, 2), endX1 = _b[0], endY1 = _b[1];
            var _c = tslib.__read(preItem, 2), endX2 = _c[0], endY2 = _c[1];
            if (!radius) {
                newPath.push("".concat(i === 0 ? 'M' : 'L').concat(startX, ",").concat(startY));
                continue;
            }
            var _d = tslib.__read(this.radiusPath(radius, [endX2, endY2], [startX, startY], [endX1, endY1]), 2), start = _d[0], A = _d[1];
            newPath.push("".concat(i === 0 ? 'M' : 'L').concat(start), "A".concat(A));
        }
        newPath.push('Z');
        return newPath;
    };
    // 正方形
    SvgPathGenerator.prototype.getSquarePath = function (radius) {
        var S = this.size;
        var ponits1 = [
            [0, 0],
            [S, 0],
            [S, S],
            [0, S]
        ];
        var path1 = this.addRoundCornersToPath(ponits1, radius);
        return [path1];
    };
    // 等边三角形
    SvgPathGenerator.prototype.getTrianglePath = function (radius) {
        var S = this.size;
        var height = Math.sin(this.toRadians(60)) * S;
        // 内切圆为最大圆角，其半径是高度的1/3
        var maxRadius = Math.min(radius, height / 3) || 0;
        // sin30度，所以斜边是R的2倍，斜边减去R就是高度移动的距离
        var dy = (S - height - maxRadius) / 2;
        var points1 = [
            [0, height + dy],
            [S / 2, dy],
            [S, height + dy]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 直角三角形
    SvgPathGenerator.prototype.getRightTrianglePath = function (radius) {
        var points1 = [
            [0, 0],
            [200, 200],
            [0, 200]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 矩形
    SvgPathGenerator.prototype.getRectanglePath = function (radius) {
        var S = this.size;
        var points1 = [
            [0, S / 4],
            [S, S / 4],
            [S, (S / 4) * 3],
            [0, (S / 4) * 3]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 凸弧矩形
    SvgPathGenerator.prototype.getConvexArcRectangle = function (radius) {
        var S = this.size;
        var w = S;
        var h = (S / 3) * 2;
        var x = (S - h) / 2 - radius / 4;
        var path1 = "\n      M 0 ".concat(h + x, "\n      L 0 ").concat(radius + x, "\n      Q ").concat(w / 2, " ").concat(x, " ").concat(w, " ").concat(radius + x, "\n      L ").concat(w, " ").concat(h + x, "\n      Z\n    ");
        return [path1];
    };
    // 凹弧矩形
    SvgPathGenerator.prototype.getConcaveArcRectangle = function (radius) {
        var S = this.size;
        var w = S;
        var h = S / 2;
        var x = (S - h) / 2;
        var path1 = "\n      M 0 ".concat(h + x, "\n      L 0 ").concat(x, "\n      Q ").concat(w / 2, " ").concat(radius + x, " ").concat(w, " ").concat(x, "\n      L ").concat(w, " ").concat(h + x, "\n      Z\n    ");
        return [path1];
    };
    // 双凸弧矩形
    SvgPathGenerator.prototype.getDConvexArcRectangle = function (radius) {
        var S = this.size;
        var dx = radius;
        var path1 = "\n      M 0 ".concat(S / 4, "\n      Q ").concat(S / 2, " ").concat(S / 4 - dx, " ").concat(S, " ").concat(S / 4, "\n      L ").concat(S, " ").concat((S / 4) * 3, "\n      Q ").concat(S / 2, " ").concat((S / 4) * 3 + dx, " 0 ").concat((S / 4) * 3, "\n      Z\n    ");
        return [path1];
    };
    // 双凹弧矩形
    SvgPathGenerator.prototype.getDConcaveArcRectangle = function (radius) {
        var S = this.size;
        var dx = radius;
        var path1 = "\n      M 0 ".concat(S / 4, "\n      Q ").concat(S / 2, " ").concat(S / 4 + dx, " ").concat(S, " ").concat(S / 4, "\n      L ").concat(S, " ").concat((S / 4) * 3, "\n      Q ").concat(S / 2, " ").concat((S / 4) * 3 - dx, " 0 ").concat((S / 4) * 3, "\n      Z\n    ");
        return [path1];
    };
    // 桶形矩形
    SvgPathGenerator.prototype.getBarrelRectangle = function (radius) {
        var S = this.size;
        var R = radius;
        var dx = R / 4;
        var path1 = "\n      M 0 ".concat(S / 4 - dx, "\n      Q ").concat(S / 2, " ").concat(S / 4 + R - dx, " ").concat(S, " ").concat(S / 4 - dx, "\n      L ").concat(S, " ").concat((S / 4) * 3 - dx, "\n      Q ").concat(S / 2, " ").concat((S / 4) * 3 + R - dx, " 0 ").concat((S / 4) * 3 - dx, "\n      Z\n    ");
        return [path1];
    };
    // 菱形
    SvgPathGenerator.prototype.getRhombusPath = function (radius) {
        var ponits1 = [
            [100, 0],
            [200, 100],
            [100, 200],
            [0, 100]
        ];
        var path1 = this.addRoundCornersToPath(ponits1, radius);
        return [path1];
    };
    // 平行四边形
    SvgPathGenerator.prototype.getParallelogramPath = function (radius) {
        var points1 = [
            [50, 0],
            [200, 0],
            [150, 200],
            [0, 200]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 矩形-类型1
    SvgPathGenerator.prototype.getRectangleType1Path = function () {
        var S = this.size;
        var x = 20;
        var points = [
            [x, 0],
            [S - x, 0],
            [S - x, x],
            [S, x],
            [S, S - x],
            [S - x, S - x],
            [S - x, S],
            [x, S],
            [x, S - x],
            [0, S - x],
            [0, x],
            [x, x]
        ];
        var path = this.addRoundCornersToPath(points, 0);
        return [path];
    };
    // 矩形-类型2
    SvgPathGenerator.prototype.getRectangleType2Path = function (radius) {
        var S = this.size;
        var dx = 35;
        var points = [
            [0, 0],
            [S - dx, 0],
            [S, S / 2],
            [S - dx, S],
            [0, S],
            [dx, S / 2]
        ];
        var path = this.addRoundCornersToPath(points, radius);
        return [path];
    };
    // 矩形-类型3
    SvgPathGenerator.prototype.getRectangleType3Path = function (radius) {
        var S = this.size;
        var dx = 35;
        var points = [
            [0, 0],
            [S - dx, 0],
            [S, S / 2],
            [S - dx, S],
            [0, S]
        ];
        var path = this.addRoundCornersToPath(points, radius);
        return [path];
    };
    // 星形
    SvgPathGenerator.prototype.getStar = function (radius) {
        var points = [
            [100, 11.1297757],
            [129.05723, 70.0061542],
            [194.031171, 79.4474205],
            [147.015586, 125.27629],
            [158.11446, 189.987692],
            [100, 159.435112],
            [41.8855403, 189.987692],
            [52.9844145, 125.27629],
            [5.96882894, 79.4474205],
            [70.9427701, 70.0061542]
        ];
        var path = this.addRoundCornersToPath(points, radius);
        return [path];
    };
    // 心形
    SvgPathGenerator.prototype.getHeart = function () {
        var path = "\n      M143.526375,12\n      C132.21418,12 124.346417,16.1423074 111.598905,27.0093876\n      C111.007635,27.5125184 107.668026,30.3835001 106.701139,31.2037806\n      C103.410893,33.9868624 98.5891073,33.9868624 95.2988609,31.2037806\n      C94.331974,30.3807731 90.9923649,27.5125184 90.4010952,27.0093876\n      C77.653583,16.1423074 69.78582,12 58.4736246,12\n      C24.0713382,12 2,39.4823959 2,79.1438299\n      C2,109.386491 32.9900653,146.921686 95.9859458,190.440184\n      C99.0044944,192.519939 102.995506,192.519939 106.014054,190.440184\n      C169.009935,146.924413 200,109.386491 200,79.1438299\n      C200,39.4823959 177.928662,12 143.526375,12\n    Z";
        return [path];
    };
    // 五边形
    SvgPathGenerator.prototype.getPentagon = function (radius) {
        var S = this.size;
        var a = S / (Math.tan(this.toRadians(54)) * 2);
        var b = S / 2;
        var c = Math.sqrt(a * a + b * b);
        var x1 = Math.sin(this.toRadians(18)) * c;
        var x2 = Math.cos(this.toRadians(18)) * c;
        var dx = (S - (a + x2)) / 2;
        var points1 = [
            [S, a + dx],
            [S - x1, a + x2 + dx],
            [x1, a + x2 + dx],
            [0, a + dx],
            [b, dx]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 六边形
    SvgPathGenerator.prototype.getHexagon = function (radius) {
        var points1 = [
            [100, 0.577350269],
            [186.10254, 50.2886751],
            [186.10254, 149.711325],
            [100, 199.42265],
            [13.8974596, 149.711325],
            [13.8974596, 50.2886751]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 正八边形
    SvgPathGenerator.prototype.getOctagonPath = function (radius) {
        var S = this.size;
        var x = S / (2 + Math.sqrt(2));
        var points1 = [
            [x, 0],
            [S - x, 0],
            [S, x],
            [S, S - x],
            [S - x, S],
            [x, S],
            [0, S - x],
            [0, x]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 六角星
    SvgPathGenerator.prototype.getHexagonStar = function (radius) {
        var points1 = [
            [149.380343, 14.4707367],
            [142.764632, 75.3098284],
            [198.760686, 100],
            [142.764632, 124.690172],
            [149.380343, 185.529263],
            [100, 149.380343],
            [50.6196568, 185.529263],
            [57.2353684, 124.690172],
            [1.23931367, 100],
            [57.2353684, 75.3098284],
            [50.6196568, 14.4707367],
            [100, 50.6196568]
        ];
        var path1 = this.addRoundCornersToPath(points1, radius);
        return [path1];
    };
    // 圆
    SvgPathGenerator.prototype.getCirclePath = function () {
        var path = "\n      M 100 0\n      A 100 100 0 0 1 100 200\n      A 100 100 0 0 1 100 0\n      Z\n    ";
        return [path];
    };
    // 箭头
    SvgPathGenerator.prototype.getArrowPath = function (radius) {
        var points = [
            [0, 75],
            [110, 75],
            [110, 30],
            [200, 100],
            [110, 170],
            [110, 125],
            [0, 125]
        ];
        return [this.addRoundCornersToPath(points, radius)];
    };
    // 树叶形状
    SvgPathGenerator.prototype.getLeafPath = function () {
        var path = "\n      M 0 140\n      Q 0 60 80 60\n      L 200 60\n      Q 200 140 120 140\n      Z\n    ";
        return [path];
    };
    SvgPathGenerator.getCustomPath = function (paths) {
        return paths || [];
    };
    return SvgPathGenerator;
}());
var Shape = function (props) {
    var BASE_SIZE = 200;
    var cx = props.classnames, className = props.className, shapeType = props.shapeType, color = props.color, _a = props.stroke, stroke = _a === void 0 ? 'currentColor' : _a, _b = props.strokeWidth, strokeWidth = _b === void 0 ? 0 : _b, _c = props.strokeType, strokeType = _c === void 0 ? 'line' : _c, _d = props.width, width = _d === void 0 ? BASE_SIZE : _d, _e = props.height, height = _e === void 0 ? BASE_SIZE : _e;
    var paths = SvgPathGenerator.getPath(shapeType, props);
    var strokeProps = SvgPathGenerator.getStrokeProps(stroke, strokeWidth, strokeType);
    var getStyle = React__default["default"].useCallback(function () { return [
        {
            width: width + 'px',
            height: height + 'px'
        },
        {
            transform: "scale(".concat(width / BASE_SIZE, ", ").concat(height / BASE_SIZE, ")")
        }
    ]; }, [width, height]);
    return (_J$X_("div", { className: cx('Shape', className), style: getStyle()[0], onClick: props.onClick },
        _J$X_("svg", { className: cx('Shape-svg'), width: BASE_SIZE, height: BASE_SIZE, style: getStyle()[1], fill: color ? color : 'currentColor', viewBox: "0 0 ".concat(BASE_SIZE, " ").concat(BASE_SIZE) }, paths.map(function (path, index) { return (_J$X_("path", tslib.__assign({}, strokeProps, { key: index, d: path }))); }))));
};
var Shape$1 = amisCore.themeable(Shape);

exports["default"] = Shape$1;
