1 |
- {"version":3,"file":"location.mjs","names":["useRtl","computed","parseAnchor","propsFactory","oppositeMap","center","top","bottom","left","right","makeLocationProps","location","String","useLocation","props","opposite","arguments","length","undefined","offset","isRtl","locationStyles","side","align","split","value","getOffset","styles","transform"],"sources":["../../src/composables/location.ts"],"sourcesContent":["// Composables\nimport { useRtl } from '@/composables/locale'\n\n// Utilities\nimport { computed } from 'vue'\nimport { parseAnchor, propsFactory } from '@/util'\n\n// Types\nimport type { CSSProperties, PropType } from 'vue'\nimport type { Anchor } from '@/util'\n\nconst oppositeMap = {\n center: 'center',\n top: 'bottom',\n bottom: 'top',\n left: 'right',\n right: 'left',\n} as const\n\nexport interface LocationProps {\n location: Anchor | undefined\n}\n\nexport const makeLocationProps = propsFactory({\n location: String as PropType<Anchor>,\n}, 'location')\n\nexport function useLocation (props: LocationProps, opposite = false, offset?: (side: string) => number) {\n const { isRtl } = useRtl()\n\n const locationStyles = computed(() => {\n if (!props.location) return {}\n\n const { side, align } = parseAnchor(\n props.location.split(' ').length > 1\n ? props.location\n : `${props.location} center` as Anchor,\n isRtl.value\n )\n\n function getOffset (side: string) {\n return offset\n ? offset(side)\n : 0\n }\n\n const styles = {} as CSSProperties\n\n if (side !== 'center') {\n if (opposite) styles[oppositeMap[side]] = `calc(100% - ${getOffset(side)}px)`\n else styles[side] = 0\n }\n if (align !== 'center') {\n if (opposite) styles[oppositeMap[align]] = `calc(100% - ${getOffset(align)}px)`\n else styles[align] = 0\n } else {\n if (side === 'center') styles.top = styles.left = '50%'\n else {\n styles[({\n top: 'left',\n bottom: 'left',\n left: 'top',\n right: 'top',\n } as const)[side]] = '50%'\n }\n styles.transform = {\n top: 'translateX(-50%)',\n bottom: 'translateX(-50%)',\n left: 'translateY(-50%)',\n right: 'translateY(-50%)',\n center: 'translate(-50%, -50%)',\n }[side]\n }\n\n return styles\n })\n\n return { locationStyles }\n}\n"],"mappings":"AAAA;AAAA,SACSA,MAAM,wBAEf;AACA,SAASC,QAAQ,QAAQ,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