123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // Utilities
- import { includes } from "./helpers.mjs";
- const block = ['top', 'bottom'];
- const inline = ['start', 'end', 'left', 'right'];
- /** Parse a raw anchor string into an object */
- export function parseAnchor(anchor, isRtl) {
- let [side, align] = anchor.split(' ');
- if (!align) {
- align = includes(block, side) ? 'start' : includes(inline, side) ? 'top' : 'center';
- }
- return {
- side: toPhysical(side, isRtl),
- align: toPhysical(align, isRtl)
- };
- }
- export function toPhysical(str, isRtl) {
- if (str === 'start') return isRtl ? 'right' : 'left';
- if (str === 'end') return isRtl ? 'left' : 'right';
- return str;
- }
- export function flipSide(anchor) {
- return {
- side: {
- center: 'center',
- top: 'bottom',
- bottom: 'top',
- left: 'right',
- right: 'left'
- }[anchor.side],
- align: anchor.align
- };
- }
- export function flipAlign(anchor) {
- return {
- side: anchor.side,
- align: {
- center: 'center',
- top: 'bottom',
- bottom: 'top',
- left: 'right',
- right: 'left'
- }[anchor.align]
- };
- }
- export function flipCorner(anchor) {
- return {
- side: anchor.align,
- align: anchor.side
- };
- }
- export function getAxis(anchor) {
- return includes(block, anchor.side) ? 'y' : 'x';
- }
- //# sourceMappingURL=anchor.mjs.map
|