"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    leftPositionForHandle: ()=>leftPositionForHandle,
    topPositionForHandle: ()=>topPositionForHandle,
    transformForHandle: ()=>transformForHandle,
    snapToGrid: ()=>snapToGrid,
    HANDLE_CROSS_AXIS_SIZE_PX: ()=>HANDLE_CROSS_AXIS_SIZE_PX,
    heightForHandleWithPosition: ()=>heightForHandleWithPosition,
    HANDLE_EDGE_COVERAGE_RATIO: ()=>HANDLE_EDGE_COVERAGE_RATIO,
    bottomPositionForHandle: ()=>bottomPositionForHandle,
    calculateGridAlignedHandlePositions: ()=>calculateGridAlignedHandlePositions,
    pixelToPercent: ()=>pixelToPercent,
    rightPositionForHandle: ()=>rightPositionForHandle,
    widthForHandleWithPosition: ()=>widthForHandleWithPosition
});
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const external_constants_cjs_namespaceObject = require("../../constants.cjs");
const isHorizontalEdge = (position)=>position === react_cjs_namespaceObject.Position.Top || position === react_cjs_namespaceObject.Position.Bottom;
const isVerticalEdge = (position)=>position === react_cjs_namespaceObject.Position.Left || position === react_cjs_namespaceObject.Position.Right;
const HANDLE_CROSS_AXIS_SIZE_PX = 24;
const HANDLE_EDGE_COVERAGE_RATIO = 0.5;
const snapToGrid = (value, gridSize = external_constants_cjs_namespaceObject.GRID_SPACING)=>Math.round(value / gridSize) * gridSize;
const calculateGridAlignedHandlePositions = (nodeSize, numHandles, gridSize = external_constants_cjs_namespaceObject.GRID_SPACING)=>{
    if (0 === numHandles) return [];
    if (nodeSize <= 0) return [];
    if (1 === numHandles) return [
        nodeSize / 2
    ];
    const idealSpacing = nodeSize / (numHandles + 1);
    if (nodeSize % gridSize !== 0) {
        const positions = [];
        for(let i = 0; i < numHandles; i++)positions.push(idealSpacing * (i + 1));
        return positions;
    }
    const roundedSpacing = Math.round(idealSpacing / gridSize) * gridSize;
    let gridAlignedSpacing = Math.max(gridSize, roundedSpacing);
    let totalSpan = (numHandles - 1) * gridAlignedSpacing;
    let startPosition = (nodeSize - totalSpan) / 2;
    if (startPosition % gridSize !== 0 && gridAlignedSpacing > gridSize) {
        gridAlignedSpacing -= gridSize;
        totalSpan = (numHandles - 1) * gridAlignedSpacing;
        startPosition = (nodeSize - totalSpan) / 2;
    }
    const positions = [];
    for(let i = 0; i < numHandles; i++)positions.push(startPosition + i * gridAlignedSpacing);
    return positions;
};
const pixelToPercent = (pixelPosition, nodeSize)=>{
    if (0 === nodeSize) return 0;
    return pixelPosition / nodeSize * 100;
};
const widthForHandleWithPosition = ({ position, numHandles, customWidth })=>{
    if (customWidth) return `${customWidth}px`;
    return isHorizontalEdge(position) ? `${100 * HANDLE_EDGE_COVERAGE_RATIO / numHandles}%` : `${HANDLE_CROSS_AXIS_SIZE_PX}px`;
};
const heightForHandleWithPosition = ({ position, numHandles, customHeight })=>{
    if (customHeight) return `${customHeight}px`;
    return isHorizontalEdge(position) ? `${HANDLE_CROSS_AXIS_SIZE_PX}px` : `${100 * HANDLE_EDGE_COVERAGE_RATIO / numHandles}%`;
};
const topPositionForHandle = ({ position, positionPercent, customHeight, customTop, customBottom })=>{
    if (null != customTop) {
        if (isVerticalEdge(position)) {
            if (customHeight) return `${customTop + positionPercent / 100 * customHeight - customHeight / 2}px`;
            return `calc(${positionPercent}% + ${customTop / 2}px)`;
        }
        return `${customTop}px`;
    }
    if (null != customBottom) return 'unset';
    if (position === react_cjs_namespaceObject.Position.Top) return '0';
    if (position === react_cjs_namespaceObject.Position.Bottom) return 'unset';
    return `${positionPercent}%`;
};
const bottomPositionForHandle = ({ position, positionPercent, customHeight, customTop, customBottom })=>{
    if (null != customBottom) {
        if (isVerticalEdge(position)) {
            if (customHeight) return `${customBottom + positionPercent / 100 * customHeight - customHeight / 2}px`;
            return `calc(${positionPercent}% + ${customBottom / 2}px)`;
        }
        return `${customBottom}px`;
    }
    if (null != customTop) return 'unset';
    if (position === react_cjs_namespaceObject.Position.Bottom) return '0';
    return 'unset';
};
const leftPositionForHandle = ({ position, positionPercent, customWidth, customRight, customLeft })=>{
    if (null != customLeft) {
        if (isHorizontalEdge(position)) {
            if (customWidth) return `${customLeft + positionPercent / 100 * customWidth - customWidth / 2}px`;
            return `calc(${positionPercent}% + ${customLeft / 2}px)`;
        }
        return `${customLeft}px`;
    }
    if (null != customRight) return 'unset';
    if (position === react_cjs_namespaceObject.Position.Left) return '0';
    if (position === react_cjs_namespaceObject.Position.Right) return 'unset';
    return `${positionPercent}%`;
};
const rightPositionForHandle = ({ position, positionPercent, customWidth, customRight, customLeft })=>{
    if (null != customRight) {
        if (isHorizontalEdge(position)) {
            if (customWidth) return `${customRight + positionPercent / 100 * customWidth - customWidth / 2}px`;
            return `calc(${positionPercent}% + ${customRight / 2}px)`;
        }
        return `${customRight}px`;
    }
    if (null != customLeft) return 'unset';
    if (position === react_cjs_namespaceObject.Position.Right) return '0';
    return 'unset';
};
const transformForHandle = ({ position, customPositionAndOffsets })=>{
    const hasCustomVertical = (customPositionAndOffsets?.top != null || customPositionAndOffsets?.bottom != null) && customPositionAndOffsets?.height;
    const hasCustomHorizontal = (customPositionAndOffsets?.left != null || customPositionAndOffsets?.right != null) && customPositionAndOffsets?.width;
    const verticalPercent = hasCustomVertical ? '0%' : position === react_cjs_namespaceObject.Position.Bottom ? '50%' : '-50%';
    const horizontalPercent = hasCustomHorizontal ? '0%' : position === react_cjs_namespaceObject.Position.Right ? '50%' : '-50%';
    return `translate(${horizontalPercent}, ${verticalPercent})`;
};
exports.HANDLE_CROSS_AXIS_SIZE_PX = __webpack_exports__.HANDLE_CROSS_AXIS_SIZE_PX;
exports.HANDLE_EDGE_COVERAGE_RATIO = __webpack_exports__.HANDLE_EDGE_COVERAGE_RATIO;
exports.bottomPositionForHandle = __webpack_exports__.bottomPositionForHandle;
exports.calculateGridAlignedHandlePositions = __webpack_exports__.calculateGridAlignedHandlePositions;
exports.heightForHandleWithPosition = __webpack_exports__.heightForHandleWithPosition;
exports.leftPositionForHandle = __webpack_exports__.leftPositionForHandle;
exports.pixelToPercent = __webpack_exports__.pixelToPercent;
exports.rightPositionForHandle = __webpack_exports__.rightPositionForHandle;
exports.snapToGrid = __webpack_exports__.snapToGrid;
exports.topPositionForHandle = __webpack_exports__.topPositionForHandle;
exports.transformForHandle = __webpack_exports__.transformForHandle;
exports.widthForHandleWithPosition = __webpack_exports__.widthForHandleWithPosition;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "HANDLE_CROSS_AXIS_SIZE_PX",
    "HANDLE_EDGE_COVERAGE_RATIO",
    "bottomPositionForHandle",
    "calculateGridAlignedHandlePositions",
    "heightForHandleWithPosition",
    "leftPositionForHandle",
    "pixelToPercent",
    "rightPositionForHandle",
    "snapToGrid",
    "topPositionForHandle",
    "transformForHandle",
    "widthForHandleWithPosition"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
