{"version":3,"file":"chunk-Match.mjs","names":["_Fragment"],"sources":["../../src/flow/Match.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport React, { Children, type ReactNode, isValidElement } from 'react';\n\ntype RootProps<T> = {\n  /** The discriminant each `Case` is tested against. */\n  on: T;\n  /** Rendered when no `Case` matches. */\n  fallback?: ReactNode;\n  children: ReactNode;\n};\n\ntype CaseProps<T> = {\n  /** Matched by strict equality with `on`, or by a predicate on it. */\n  when: T | ((value: T) => boolean);\n  children?: ReactNode;\n};\n\n/** A function-typed `when` is a predicate — so `on` values must not themselves be functions. */\nconst isPredicate = <T,>(when: T | ((value: T) => boolean)): when is (value: T) => boolean =>\n  typeof when === 'function';\n\nconst MatchCase = <T,>({ children }: CaseProps<T>): ReactNode => <>{children}</>;\n\nMatchCase.displayName = 'Match.Case';\n\n/**\n * Structural mode switching after Solid's `<Switch>`/`<Match>` and the ui-template\n * `switch`/`match` grammar (named `Match` here: `Switch` is the toggle control): exactly the first matching branch is rendered; the rest never exist.\n *\n * @example\n * ```tsx\n * <Match.Root on={view} fallback={<ListView />}>\n *   <Match.Case when='grid'>\n *     <GridView />\n *   </Match.Case>\n * </Match.Root>\n * ```\n */\nconst MatchRoot = <T,>({ on, fallback = null, children }: RootProps<T>): ReactNode => {\n  for (const child of Children.toArray(children)) {\n    if (!isValidElement<CaseProps<T>>(child) || child.type !== MatchCase) {\n      continue;\n    }\n    const { when } = child.props;\n    if (isPredicate(when) ? when(on) : when === on) {\n      return child;\n    }\n  }\n\n  return <>{fallback}</>;\n};\n\nMatchRoot.displayName = 'Match.Root';\nexport type { CaseProps as CaseProps, RootProps as RootProps };\n\nexport { MatchCase as Case, MatchRoot as Root };\n"],"mappings":";;;;;;;;;AAuBA,IAAM,eAAmB,SACvB,OAAO,SAAS;AAElB,IAAM,aAAiB,EAAE,eAAwC,oBAAAA,YAAA,EAAG,SAAW,CAAA;AAE/E,UAAU,cAAc;;;;;;;;;;;;;;AAexB,IAAM,aAAiB,EAAE,IAAI,WAAW,MAAM,eAAwC;CACpF,KAAK,MAAM,SAAS,SAAS,QAAQ,QAAQ,GAAG;EAC9C,IAAI,CAAC,eAA6B,KAAK,KAAK,MAAM,SAAS,WACzD;EAEF,MAAM,EAAE,SAAS,MAAM;EACvB,IAAI,YAAY,IAAI,IAAI,KAAK,EAAE,IAAI,SAAS,IAC1C,OAAO;CAEX;CAEA,OAAO,oBAAAA,YAAA,EAAA,UAAG,SAAW,CAAA;AACvB;AAEA,UAAU,cAAc"}