{"version":3,"file":"anchor.mjs","names":["includes","block","inline","parseAnchor","anchor","isRtl","side","align","split","toPhysical","str","flipSide","center","top","bottom","left","right","flipAlign","flipCorner","getAxis"],"sources":["../../src/util/anchor.ts"],"sourcesContent":["// Utilities\nimport { includes } from '@/util/helpers'\n\nconst block = ['top', 'bottom'] as const\nconst inline = ['start', 'end', 'left', 'right'] as const\ntype Tblock = typeof block[number]\ntype Tinline = typeof inline[number]\nexport type Anchor =\n | Tblock\n | Tinline\n | 'center'\n | 'center center'\n | `${Tblock} ${Tinline | 'center'}`\n | `${Tinline} ${Tblock | 'center'}`\nexport type ParsedAnchor =\n | { side: 'center', align: 'center' }\n | { side: Tblock, align: 'left' | 'right' | 'center' }\n | { side: 'left' | 'right', align: Tblock | 'center' }\n\n/** Parse a raw anchor string into an object */\nexport function parseAnchor (anchor: Anchor, isRtl: boolean) {\n let [side, align] = anchor.split(' ') as [Tblock | Tinline | 'center', Tblock | Tinline | 'center' | undefined]\n if (!align) {\n align =\n includes(block, side) ? 'start'\n : includes(inline, side) ? 'top'\n : 'center'\n }\n\n return {\n side: toPhysical(side, isRtl),\n align: toPhysical(align, isRtl),\n } as ParsedAnchor\n}\n\nexport function toPhysical (str: 'center' | Tblock | Tinline, isRtl: boolean) {\n if (str === 'start') return isRtl ? 'right' : 'left'\n if (str === 'end') return isRtl ? 'left' : 'right'\n return str\n}\n\nexport function flipSide (anchor: ParsedAnchor) {\n return {\n side: {\n center: 'center',\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n }[anchor.side],\n align: anchor.align,\n } as ParsedAnchor\n}\n\nexport function flipAlign (anchor: ParsedAnchor) {\n return {\n side: anchor.side,\n align: {\n center: 'center',\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n }[anchor.align],\n } as ParsedAnchor\n}\n\nexport function flipCorner (anchor: ParsedAnchor) {\n return {\n side: anchor.align,\n align: anchor.side,\n } as ParsedAnchor\n}\n\nexport function getAxis (anchor: ParsedA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