208 lines
5.4 KiB
JavaScript
208 lines
5.4 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/_util/placements.ts
|
|
var placements_exports = {};
|
|
__export(placements_exports, {
|
|
default: () => getPlacements,
|
|
getOverflowOptions: () => getOverflowOptions
|
|
});
|
|
module.exports = __toCommonJS(placements_exports);
|
|
var import_placementArrow = require("../style/placementArrow");
|
|
function getOverflowOptions(placement, arrowOffset, arrowWidth, autoAdjustOverflow) {
|
|
if (autoAdjustOverflow === false) {
|
|
return {
|
|
adjustX: false,
|
|
adjustY: false
|
|
};
|
|
}
|
|
const overflow = autoAdjustOverflow && typeof autoAdjustOverflow === "object" ? autoAdjustOverflow : {};
|
|
const baseOverflow = {};
|
|
switch (placement) {
|
|
case "top":
|
|
case "bottom":
|
|
baseOverflow.shiftX = arrowOffset.arrowOffsetHorizontal * 2 + arrowWidth;
|
|
baseOverflow.shiftY = true;
|
|
baseOverflow.adjustY = true;
|
|
break;
|
|
case "left":
|
|
case "right":
|
|
baseOverflow.shiftY = arrowOffset.arrowOffsetVertical * 2 + arrowWidth;
|
|
baseOverflow.shiftX = true;
|
|
baseOverflow.adjustX = true;
|
|
break;
|
|
}
|
|
const mergedOverflow = {
|
|
...baseOverflow,
|
|
...overflow
|
|
};
|
|
if (!mergedOverflow.shiftX) {
|
|
mergedOverflow.adjustX = true;
|
|
}
|
|
if (!mergedOverflow.shiftY) {
|
|
mergedOverflow.adjustY = true;
|
|
}
|
|
return mergedOverflow;
|
|
}
|
|
var PlacementAlignMap = {
|
|
left: {
|
|
points: ["cr", "cl"]
|
|
},
|
|
right: {
|
|
points: ["cl", "cr"]
|
|
},
|
|
top: {
|
|
points: ["bc", "tc"]
|
|
},
|
|
bottom: {
|
|
points: ["tc", "bc"]
|
|
},
|
|
topLeft: {
|
|
points: ["bl", "tl"]
|
|
},
|
|
leftTop: {
|
|
points: ["tr", "tl"]
|
|
},
|
|
topRight: {
|
|
points: ["br", "tr"]
|
|
},
|
|
rightTop: {
|
|
points: ["tl", "tr"]
|
|
},
|
|
bottomRight: {
|
|
points: ["tr", "br"]
|
|
},
|
|
rightBottom: {
|
|
points: ["bl", "br"]
|
|
},
|
|
bottomLeft: {
|
|
points: ["tl", "bl"]
|
|
},
|
|
leftBottom: {
|
|
points: ["br", "bl"]
|
|
}
|
|
};
|
|
var ArrowCenterPlacementAlignMap = {
|
|
topLeft: {
|
|
points: ["bl", "tc"]
|
|
},
|
|
leftTop: {
|
|
points: ["tr", "cl"]
|
|
},
|
|
topRight: {
|
|
points: ["br", "tc"]
|
|
},
|
|
rightTop: {
|
|
points: ["tl", "cr"]
|
|
},
|
|
bottomRight: {
|
|
points: ["tr", "bc"]
|
|
},
|
|
rightBottom: {
|
|
points: ["bl", "cr"]
|
|
},
|
|
bottomLeft: {
|
|
points: ["tl", "bc"]
|
|
},
|
|
leftBottom: {
|
|
points: ["br", "cl"]
|
|
}
|
|
};
|
|
var DisableAutoArrowList = /* @__PURE__ */ new Set([
|
|
"topLeft",
|
|
"topRight",
|
|
"bottomLeft",
|
|
"bottomRight",
|
|
"leftTop",
|
|
"leftBottom",
|
|
"rightTop",
|
|
"rightBottom"
|
|
]);
|
|
function getPlacements(config) {
|
|
const { arrowWidth, autoAdjustOverflow, arrowPointAtCenter, offset, borderRadius, visibleFirst } = config;
|
|
const halfArrowWidth = arrowWidth / 2;
|
|
const placementMap = {};
|
|
Object.keys(PlacementAlignMap).forEach((key) => {
|
|
const template = arrowPointAtCenter && ArrowCenterPlacementAlignMap[key] || PlacementAlignMap[key];
|
|
const placementInfo = {
|
|
...template,
|
|
offset: [0, 0],
|
|
dynamicInset: true
|
|
};
|
|
placementMap[key] = placementInfo;
|
|
if (DisableAutoArrowList.has(key)) {
|
|
placementInfo.autoArrow = false;
|
|
}
|
|
switch (key) {
|
|
case "top":
|
|
case "topLeft":
|
|
case "topRight":
|
|
placementInfo.offset[1] = -halfArrowWidth - offset;
|
|
break;
|
|
case "bottom":
|
|
case "bottomLeft":
|
|
case "bottomRight":
|
|
placementInfo.offset[1] = halfArrowWidth + offset;
|
|
break;
|
|
case "left":
|
|
case "leftTop":
|
|
case "leftBottom":
|
|
placementInfo.offset[0] = -halfArrowWidth - offset;
|
|
break;
|
|
case "right":
|
|
case "rightTop":
|
|
case "rightBottom":
|
|
placementInfo.offset[0] = halfArrowWidth + offset;
|
|
break;
|
|
}
|
|
const arrowOffset = (0, import_placementArrow.getArrowOffsetToken)({
|
|
contentRadius: borderRadius,
|
|
limitVerticalRadius: true
|
|
});
|
|
if (arrowPointAtCenter) {
|
|
switch (key) {
|
|
case "topLeft":
|
|
case "bottomLeft":
|
|
placementInfo.offset[0] = -arrowOffset.arrowOffsetHorizontal - halfArrowWidth;
|
|
break;
|
|
case "topRight":
|
|
case "bottomRight":
|
|
placementInfo.offset[0] = arrowOffset.arrowOffsetHorizontal + halfArrowWidth;
|
|
break;
|
|
case "leftTop":
|
|
case "rightTop":
|
|
placementInfo.offset[1] = -arrowOffset.arrowOffsetHorizontal - halfArrowWidth;
|
|
break;
|
|
case "leftBottom":
|
|
case "rightBottom":
|
|
placementInfo.offset[1] = arrowOffset.arrowOffsetHorizontal + halfArrowWidth;
|
|
break;
|
|
}
|
|
}
|
|
placementInfo.overflow = getOverflowOptions(key, arrowOffset, arrowWidth, autoAdjustOverflow);
|
|
if (visibleFirst) {
|
|
placementInfo.htmlRegion = "visibleFirst";
|
|
}
|
|
});
|
|
return placementMap;
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
getOverflowOptions
|
|
});
|