{"version":3,"file":"router.mjs","names":["computed","nextTick","onScopeDispose","resolveDynamicComponent","toRef","getCurrentInstance","hasEvent","IN_BROWSER","propsFactory","useRoute","vm","proxy","$route","useRouter","$router","useLink","props","attrs","RouterLink","isLink","href","to","isClickable","value","link","undefined","route","navigate","isActive","exact","isExactActive","makeRouterProps","String","replace","Boolean","Object","inTransition","useBackButton","router","cb","popped","removeBefore","removeAfter","window","addEventListener","onPopstate","beforeEach","from","next","setTimeout","afterEach","removeEventListener","e","state","replaced"],"sources":["../../src/composables/router.tsx"],"sourcesContent":["// Utilities\nimport {\n computed,\n nextTick,\n onScopeDispose,\n resolveDynamicComponent,\n toRef,\n} from 'vue'\nimport { getCurrentInstance, hasEvent, IN_BROWSER, propsFactory } from '@/util'\n\n// Types\nimport type { ComputedRef, PropType, Ref, SetupContext } from 'vue'\nimport type {\n RouterLink as _RouterLink,\n useLink as _useLink,\n NavigationGuardNext,\n RouteLocationNormalizedLoaded,\n RouteLocationRaw,\n Router,\n UseLinkOptions,\n} from 'vue-router'\nimport type { EventProp } from '@/util'\n\nexport function useRoute (): Ref {\n const vm = getCurrentInstance('useRoute')\n\n return computed(() => vm?.proxy?.$route)\n}\n\nexport function useRouter (): Router | undefined {\n return getCurrentInstance('useRouter')?.proxy?.$router\n}\n\nexport interface LinkProps {\n href: string | undefined\n replace: boolean | undefined\n to: RouteLocationRaw | undefined\n exact: boolean | undefined\n}\n\nexport interface LinkListeners {\n onClick?: EventProp | undefined\n onClickOnce?: EventProp | undefined\n}\n\nexport interface UseLink extends Omit>, 'href'> {\n isLink: ComputedRef\n isClickable: ComputedRef\n href: Ref\n}\n\nexport function useLink (props: LinkProps & LinkListeners, attrs: SetupContext['attrs']): UseLink {\n const RouterLink = resolveDynamicComponent('RouterLink') as typeof _RouterLink | string\n\n const isLink = computed(() => !!(props.href || props.to))\n const isClickable = computed(() => {\n return isLink?.value || hasEvent(attrs, 'click') || hasEvent(props, 'click')\n })\n\n if (typeof RouterLink === 'string') {\n return {\n isLink,\n isClickable,\n href: toRef(props, 'href'),\n }\n }\n\n const link = props.to ? RouterLink.useLink(props as UseLinkOptions) : undefined\n\n return {\n isLink,\n isClickable,\n route: link?.route,\n navigate: link?.navigate,\n isActive: link && computed(() => props.exact ? link.isExactActive?.value : link.isActive?.value),\n href: computed(() => props.to ? link?.route.value.href : props.href),\n }\n}\n\nexport const makeRouterProps = propsFactory({\n href: String,\n replace: Boolean,\n to: [String, Object] as PropType,\n exact: Boolean,\n}, 'router')\n\nlet inTransition = false\nexport function useBackButton (router: Router | undefined, cb: (next: NavigationGuardNext) => void) {\n let popped = false\n let removeBefore: (() => void) | undefined\n let removeAfter: (() => void) | undefined\n\n if (IN_BROWSER) {\n nextTick(() => {\n window.addEventListener('popstate', onPopstate)\n removeBefore = router?.beforeEach((to, from, next) => {\n if (!inTransition) {\n setTimeout(() => popped ? cb(next) : next())\n } else {\n popped ? cb(next) : next()\n }\n inTransition = true\n })\n removeAfter = router?.afterEach(() => {\n inTransition = false\n })\n })\n onScopeDispose(() => {\n window.removeEventListener('popstate', onPopstate)\n removeBefore?.()\n removeAfter?.()\n })\n }\n\n function onPopstate (e: PopStateEvent) {\n if (e.state?.replaced) return\n\n popped = true\n setTimeout(() => (popped = false))\n }\n}\n"],"mappings":"AAAA;AACA,SACEA,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,uBAAuB,EACvBC,KAAK,QACA,KAAK;AAAA,SACHC,kBAAkB,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,YAAY,6BAE/D;AAaA,OAAO,SAASC,QAAQA,CAAA,EAAoD;EAC1E,MAAMC,EAAE,GAAGL,kBAAkB,CAAC,UAAU,CAAC;EAEzC,OAAOL,QAAQ,CAAC,MAAMU,EAAE,EAAEC,KAAK,EAAEC,MAAM,CAAC;AAC1C;AAEA,OAAO,SAASC,SAASA,CAAA,EAAwB;EAC/C,OAAOR,kBAAkB,CAAC,WAAW,CAAC,EAAEM,KAAK,EAAEG,OAAO;AACxD;A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