{"version":3,"file":"ink.mjs","names":[],"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,SAAS,EACP,EACA,EACA,EACA,EACA,EACe,CASf,OARI,EACK,GAAc,GAAe,EAGlC,EACK,GAAe,EAGjB,CACT,CAEA,SAAS,EACP,EACA,EACS,CACT,OACE,EAAK,YAAc,EAAK,WACxB,EAAK,eAAiB,EAAK,cAC3B,EAAK,oBAAsB,EAAK,mBAChC,EAAK,QAAU,EAAK,OACpB,EAAK,cAAgB,EAAK,aAC1B,EAAK,aAAe,EAAK,YACzB,EAAK,UAAY,EAAK,SACtB,EAAK,gBAAkB,EAAK,eAC5B,EAAK,eAAiB,EAAK,cAC3B,EAAK,KAAO,EAAK,IACjB,EAAK,YAAc,EAAK,WACxB,EAAK,WAAa,EAAK,UACvB,EAAK,WAAa,EAAK,UACvB,EAAa,EAAK,YAAa,EAAK,WAAW,GAC/C,EAAa,EAAK,YAAa,EAAK,WAAW,GAC/C,EAAa,EAAK,aAAc,EAAK,YAAY,CAErD,CAmGA,MAAa,EAA4B,GAjGF,CACrC,YACA,cACA,cACA,eAAe,EACf,eAAe,GACf,oBAAoB,GACpB,QACA,cACA,aACA,UACA,gB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