PromoCursed/node_modules/.cache/babel-loader/6fd0d871f4f39ad9741fb048936b692126c54db46505fdd36909cc3ae77bf261.json

1 line
15 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import { getArrowOffsetToken } from '../style/placementArrow';\nexport function getOverflowOptions(placement, arrowOffset, arrowWidth, autoAdjustOverflow) {\n if (autoAdjustOverflow === false) {\n return {\n adjustX: false,\n adjustY: false\n };\n }\n const overflow = autoAdjustOverflow && typeof autoAdjustOverflow === 'object' ? autoAdjustOverflow : {};\n const baseOverflow = {};\n switch (placement) {\n case 'top':\n case 'bottom':\n baseOverflow.shiftX = arrowOffset.arrowOffsetHorizontal * 2 + arrowWidth;\n baseOverflow.shiftY = true;\n baseOverflow.adjustY = true;\n break;\n case 'left':\n case 'right':\n baseOverflow.shiftY = arrowOffset.arrowOffsetVertical * 2 + arrowWidth;\n baseOverflow.shiftX = true;\n baseOverflow.adjustX = true;\n break;\n }\n const mergedOverflow = Object.assign(Object.assign({}, baseOverflow), overflow);\n // Support auto shift\n if (!mergedOverflow.shiftX) {\n mergedOverflow.adjustX = true;\n }\n if (!mergedOverflow.shiftY) {\n mergedOverflow.adjustY = true;\n }\n return mergedOverflow;\n}\nconst PlacementAlignMap = {\n left: {\n points: ['cr', 'cl']\n },\n right: {\n points: ['cl', 'cr']\n },\n top: {\n points: ['bc', 'tc']\n },\n bottom: {\n points: ['tc', 'bc']\n },\n topLeft: {\n points: ['bl', 'tl']\n },\n leftTop: {\n points: ['tr', 'tl']\n },\n topRight: {\n points: ['br', 'tr']\n },\n rightTop: {\n points: ['tl', 'tr']\n },\n bottomRight: {\n points: ['tr', 'br']\n },\n rightBottom: {\n points: ['bl', 'br']\n },\n bottomLeft: {\n points: ['tl', 'bl']\n },\n leftBottom: {\n points: ['br', 'bl']\n }\n};\nconst ArrowCenterPlacementAlignMap = {\n topLeft: {\n points: ['bl', 'tc']\n },\n leftTop: {\n points: ['tr', 'cl']\n },\n topRight: {\n points: ['br', 'tc']\n },\n rightTop: {\n points: ['tl', 'cr']\n },\n bottomRight: {\n points: ['tr', 'bc']\n },\n rightBottom: {\n points: ['bl', 'cr']\n },\n bottomLeft: {\n points: ['tl', 'bc']\n },\n leftBottom: {\n points: ['br', 'cl']\n }\n};\nconst DisableAutoArrowList = new Set(['topLeft', 'topRight', 'bottomLeft', 'bottomRight', 'leftTop', 'leftBottom', 'rightTop', 'rightBottom']);\nexport default function getPlacements(config) {\n const {\n arrowWidth,\n autoAdjustOverflow,\n arrowPointAtCenter,\n offset,\n borderRadius,\n visibleFirst\n } = config;\n const halfArrowWidth = arrowWidth / 2;\n const placementMap = {};\n Object.keys(PlacementAlignMap).forEach(key => {\n const template = arrowPointAtCenter && ArrowCenterPlacementAlignMap[key] || PlacementAlignMap[key];\n const placementInfo = Object.assign(Object.assign({}, template), {\n offset: [0, 0],\n dynamicInset: true\n });\n placementMap[key] = placementInfo;\n // Disable autoArrow since design is fixed position\n if (DisableAutoArrowList.has(key)) {\n placementInfo.autoArrow = false;\n }\n // Static offset\n switch (key) {\n case 'top':\n case 'topLeft':\n case 'topRight':\n placementInfo.offset[1] = -halfArrowWidth - offset;\n break;\n case 'bottom':\n case 'bottomLeft':\n case 'bottomRight':\n placementInfo.offset[1] = halfArrowWidth + offset;\n break;\n case 'left':\n case 'leftTop':\n case 'leftBottom':\n placementInfo.offset[0] = -halfArrowWidth - offset;\n break;\n case 'right':\n case 'rightTop':\n case 'rightBottom':\n placementInfo.offset[0] = halfArrowWidth + offset;\n break;\n }\n // Dynamic offset\n const arrowOffset = getArrowOffsetToken({\n contentRadius: borderRadius,\n limitVerticalRadius: true\n });\n if (arrowPointAtCenter) {\n switch (key) {\n case 'topLeft':\n case 'bottomLeft':\n placementInfo.offset[0] = -arrowOffset.arrowOffsetHorizontal - halfArrowWidth;\n break;\n case 'topRight':\n case 'bottomRight':\n