{"version":3,"file":"ink.mjs","names":["EMPTY_OPTIONS","EMPTY_PARAMS","useRoute","RouterErrorBoundary","shallowEqual","useRouter","useNavigator","useRouteNode","useRouterTransition","useIsActiveRoute","useRouteUtils","RouterProviderCore","pickPriority","isFocused","focusValue","activeValue","baseValue","isRouteActive","areInkLinkPropsEqual","prev","next","InkLink","memo","router","useFocus","id","autoFocus","routeName","routeParams","routeSearch","activeStrict","ignoreQueryParams","paramsForNav","useInput","key","onSelect","error","routeOptions","finalColor","focusColor","activeColor","color","finalInverse","focusInverse","activeInverse","inverse","textProps","jsx","Text","InkRouterProvider"],"sources":["../../src/components/InkLink.tsx","../../src/components/InkRouterProvider.tsx"],"sourcesContent":["import { Text, useFocus, useInput } from \"ink\";\nimport { memo } from \"react\";\n\nimport { EMPTY_OPTIONS, EMPTY_PARAMS } from \"../constants\";\nimport { shallowEqual } from \"../dom-utils\";\nimport { useIsActiveRoute } from \"../hooks/useIsActiveRoute\";\nimport { useRouter } from \"../hooks/useRouter\";\n\nimport type { InkLinkProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\n/**\n * Pick the most specific value across focus / active / base priority.\n * Focus wins over active; active wins over base. Each layer falls through\n * to the next when its value is undefined, matching the original explicit\n * if/else cascade for both `color` and `inverse`.\n */\nfunction pickPriority<T>(\n  isFocused: boolean,\n  isRouteActive: boolean,\n  focusValue: T | undefined,\n  activeValue: T | undefined,\n  baseValue: T | undefined,\n): T | undefined {\n  if (isFocused) {\n    return focusValue ?? activeValue ?? baseValue;\n  }\n\n  if (isRouteActive) {\n    return activeValue ?? baseValue;\n  }\n\n  return baseValue;\n}\n\nfunction areInkLinkPropsEqual(\n  prev: Readonly<InkLinkProps>,\n  next: Readonly<InkLinkProps>,\n): boolean {\n  return (\n    prev.routeName === next.routeName &&\n    prev.activeStrict === next.activeStrict &&\n    prev.ignoreQueryParams === next.ignoreQueryParams &&\n    prev.color === next.color &&\n    prev.activeColor === next.activeColor &&\n    prev.focusColor === next.focusColor &&\n    prev.inverse === next.inverse &&\n    prev.activeInverse === next.activeInverse &&\n    prev.focusInverse === next.focusInverse &&\n    prev.id === next.id &&\n    prev.autoFocus === next.autoFocus &&\n    prev.onSelect === next.onSelect &&\n    prev.children === next.children &&\n    shallowEqual(prev.routeParams, next.routeParams) &&\n    shallowEqual(prev.routeSearch, next.routeSearch) &&\n    shallowEqual(prev.routeOptions, next.routeOptions)\n  );\n}\n\nconst InkLinkImpl: FC<InkLinkProps> = ({\n  routeName,\n  routeParams,\n  routeSearch,\n  routeOptions = EMPTY_OPTIONS,\n  activeStrict = false,\n  ignoreQueryParams = true,\n  color,\n  activeColor,\n  focusColor,\n  inverse,\n  activeInverse,\n  focusInverse,\n  id,\n  autoFocus,\n  onSelect,\n  children,\n}) => {\n  const router = useRouter();\n  const { isFocused } = useFocus({\n    ...(id !== undefined && { id }),\n    ...(autoFocus !== undefined && { autoFocus }),\n  });\n\n  // Pass `routeParams` straight through (possibly `undefined`) so a no-params\n  // `<InkLink>` and a manual `useIsActiveRoute(routeName)` share ONE cached\n  // active-route source — `createActiveRouteSource` keys `undefined` as \"\" but\n  // EMPTY_PARAMS ({}) as \"{}\", so defaulting before the call would split the\n  // same question into a second eager subscription (#776).\n  const isRouteActive = useIsActiveRoute(\n    routeName,\n    routeParams,\n    routeSearch,\n    activeStrict,\n    ignoreQueryParams,\n  );\n\n  // Navigation needs a concrete params object — default here only.\n  const paramsForNav = routeParams ?? EMPTY_PARAMS;\n\n  // No useCallback: `useInput` consumes the handler via its own internal\n  // ref; a stable identity provides no cache-bail-out benefit here. Same\n  // reasoning as Link's handleClick.\n  useInput(\n    (_input, key) => {\n      if (key.return) {\n        // Isolate a throwing `onSelect`: unlike the DOM `<Link>` (where the\n        // browser contains event-listener exceptions), an uncaught throw here\n        // escapes into ink's stdin handler → `uncaughtException` crashes a real\n        // CLI, and it also swallows the navigation below. Log and still\n        // navigate — mirrors `route-announcer`'s consumer-callback isolation.\n        try {\n          onSelect?.();\n        } catch (error) {\n          console.error(\n            \"[real-router] InkLink onSelect threw; proceeding with navigation.\",\n            error,\n          );\n        }\n        // Query channel at position 3 (RFC-4 M2 / #1548) — from `routeSearch`;\n        // options at position 4.\n        router\n          .navigate(routeName, paramsForNav, routeSearch, routeOptions)\n          .catch(() => {});\n      }\n    },\n    { isActive: isFocused },\n  );\n\n  const finalColor = pickPriority(\n    isFocused,\n    isRouteActive,\n    focusColor,\n    activeColor,\n    color,\n  );\n  const finalInverse = pickPriority(\n    isFocused,\n    isRouteActive,\n    focusInverse,\n    activeInverse,\n    inverse,\n  );\n\n  const textProps: { color?: string; inverse?: boolean } = {};\n\n  if (finalColor !== undefined) {\n    textProps.color = finalColor;\n  }\n\n  if (finalInverse !== undefined) {\n    textProps.inverse = finalInverse;\n  }\n\n  return <Text {...textProps}>{children}</Text>;\n};\n\nexport const InkLink: FC<InkLinkProps> = memo(\n  InkLinkImpl,\n  areInkLinkPropsEqual,\n);\n\nInkLink.displayName = \"InkLink\";\n","import { RouterProviderCore } from \"../RouterProviderCore\";\n\nimport type { InkRouterProviderProps } from \"../ink-types\";\nimport type { FC } from \"react\";\n\n// Composes the DOM-free RouterProviderCore (not the full RouterProvider) so the\n// terminal /ink chunk never pulls in the scroll-spy / view-transitions /\n// announcer / scroll-restore factories — none can run without a DOM (#800).\nexport const InkRouterProvider: FC<InkRouterProviderProps> = ({\n  router,\n  children,\n}) => <RouterProviderCore router={router}>{children}</RouterProviderCore>;\n"],"mappings":"oSAiBA,SAASY,EACP,EACA,EACA,EACA,EACA,EACe,CASf,OARIC,EACKC,GAAcC,GAAeC,EAGlCC,EACKF,GAAeC,EAGjBA,CACT,CAEA,SAASE,EACP,EACA,EACS,CACT,OACEC,EAAK,YAAcC,EAAK,WACxBD,EAAK,eAAiBC,EAAK,cAC3BD,EAAK,oBAAsBC,EAAK,mBAChCD,EAAK,QAAUC,EAAK,OACpBD,EAAK,cAAgBC,EAAK,aAC1BD,EAAK,aAAeC,EAAK,YACzBD,EAAK,UAAYC,EA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