{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-liquid-button",
  "type": "registry:component",
  "title": "Liquid button",
  "description": "An action a soft fill floods into on hover",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-components.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/liquid-button.tsx",
      "target": "@ui/gpuixui/fx/liquid-button.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { EventPayload } from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport type { MotionLevel } from \"../motion/timing.js\";\nimport * as Option from \"effect/Option\";\nimport { useEffect } from \"react\";\nimport {\n  Button,\n  actionOnColor,\n  type ButtonProps,\n  measuredBox,\n  measuredPoint,\n  send,\n  useLocalState,\n  useLocalStore,\n  transitionWindowMs,\n  useMotionPreference,\n  useSurfaceTiming,\n  alpha,\n  useTheme,\n} from \"../components/authoring.js\";\nimport {\n  liquidAcross,\n  liquidEmpty,\n  liquidOpacity,\n} from \"./liquid-button/logic.js\";\nimport { makeLiquidStore, type Flood } from \"./liquid-button/store.js\";\n\nconst frameFor = (flood: Flood, full: number) =>\n  flood.filled ? liquidAcross(full) : liquidEmpty(flood.drain, full);\n\nexport interface LiquidButtonProps extends ButtonProps {\n  readonly level?: MotionLevel;\n\n  readonly liquidColor?: string;\n}\n\nexport const LiquidButton = ({\n  variant = \"secondary\",\n  size = \"md\",\n  disabled = false,\n  level = \"normal\",\n  liquidColor,\n  onMouseMove,\n  onMouseLeave,\n  onLayout,\n  style,\n  children,\n  ...rest\n}: LiquidButtonProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const timing = useSurfaceTiming(level).enter;\n  const store = useLocalStore(makeLiquidStore);\n  const { box, flood } = useLocalState(store.local);\n  const wash =\n    liquidColor ?? alpha(actionOnColor(theme, variant), liquidOpacity);\n  const inert = disabled || preference === \"reduced\";\n\n  const windowMs = transitionWindowMs(timing);\n\n  useEffect(() => {\n    if (inert) send(store.clear);\n  }, [inert, store]);\n\n  useEffect(() => {\n    send(store.retime(windowMs));\n  }, [store, windowMs]);\n\n  const measure = (event: EventPayload) => {\n    send(store.measure(measuredBox(event)));\n    onLayout?.(event);\n  };\n\n  const move = (event: EventPayload) => {\n    onMouseMove?.(event);\n    send(store.move(measuredPoint(event), inert));\n  };\n\n  const leave = (event: EventPayload) => {\n    onMouseLeave?.(event);\n    send(store.leave(measuredPoint(event), inert, windowMs));\n  };\n\n  const layer = Option.match(flood, {\n    onNone: () => null,\n    onSome: (current) =>\n      Option.match(box, {\n        onNone: () => null,\n        onSome: (measured) => (\n          <div\n            key={current.run}\n            testId=\"liquid\"\n            motion={{\n              initial: liquidEmpty(current.entry, measured.width),\n              animate: frameFor(current, measured.width),\n              transition: timing,\n            }}\n            style={{\n              position: \"absolute\",\n              top: 0,\n              height: measured.height,\n              backgroundColor: wash,\n              pointerEvents: \"none\",\n            }}\n          />\n        ),\n      }),\n  });\n\n  return (\n    <Button\n      {...rest}\n      variant={variant}\n      size={size}\n      disabled={disabled}\n      onMouseMove={move}\n      onMouseLeave={leave}\n      onLayout={measure}\n      style={mergeStyles({ position: \"relative\", overflow: \"hidden\" }, style)}\n    >\n      {}\n      {layer}\n      {children}\n    </Button>\n  );\n};\n\nexport const liquidButtonMeta = {\n  name: \"Liquid button\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"the flood travels on inset left/width, not a transform: the runtime scales nothing (upstream issue #102)\",\n    \"a reduced-motion reader and a disabled action get no flood; the control's own hover fill is the feedback that remains\",\n    \"the layer is born at one measured edge, so a control that resizes during the sweep retargets to the new width rather than restarting\",\n    \"the flood crosses the label: the copy is tinted while the wash passes\",\n  ],\n  docs: \"docs/liquid-button.mdx\",\n  example: \"examples/liquid-button.example.tsx\",\n  testFile: \"src/behaviour/liquid-button.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/liquid-button/logic.ts",
      "target": "@ui/gpuixui/fx/liquid-button/logic.ts",
      "type": "registry:lib",
      "content": "import type { MotionStyle } from \"@gpuix/react\";\n\nexport type LiquidEdge = \"left\" | \"right\";\n\nexport const liquidOpacity = 0.16;\n\nexport const liquidEdge = (\n  pointerX: number,\n  box: { readonly x: number; readonly width: number },\n): LiquidEdge => (pointerX < box.x + box.width / 2 ? \"left\" : \"right\");\n\nconst span = (full: number): number =>\n  Number.isFinite(full) && full > 0 ? full : 0;\n\nexport const liquidEmpty = (edge: LiquidEdge, full: number): MotionStyle =>\n  edge === \"left\" ? { left: 0, width: 0 } : { left: span(full), width: 0 };\n\nexport const liquidAcross = (full: number): MotionStyle => ({\n  left: 0,\n  width: span(full),\n});\n\nexport const liquidFrame = (\n  edge: LiquidEdge,\n  full: number,\n  filled: boolean,\n): MotionStyle => (filled ? liquidAcross(full) : liquidEmpty(edge, full));\n"
    },
    {
      "path": "packages/fx/src/liquid-button/store.ts",
      "target": "@ui/gpuixui/fx/liquid-button/store.ts",
      "type": "registry:lib",
      "content": "import { Effect } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport * as Ref from \"effect/Ref\";\nimport * as SubscriptionRef from \"effect/SubscriptionRef\";\nimport {\n  type MeasuredBox,\n  type MeasuredPoint,\n  makeLocalState,\n  type LocalState,\n} from \"../../components/authoring.js\";\nimport { liquidEdge, type LiquidEdge } from \"./logic.js\";\n\nexport interface Flood {\n  readonly entry: LiquidEdge;\n  readonly drain: LiquidEdge;\n  readonly filled: boolean;\n  readonly run: number;\n}\n\nexport interface LiquidState {\n  readonly box: Option.Option<MeasuredBox>;\n  readonly flood: Option.Option<Flood>;\n}\n\nexport interface LiquidStore {\n  readonly local: LocalState<LiquidState>;\n\n  readonly measure: (box: Option.Option<MeasuredBox>) => Effect.Effect<void>;\n\n  readonly move: (\n    point: Option.Option<MeasuredPoint>,\n    inert: boolean,\n  ) => Effect.Effect<void>;\n\n  readonly leave: (\n    point: Option.Option<MeasuredPoint>,\n    inert: boolean,\n    windowMs: number,\n  ) => Effect.Effect<void>;\n\n  readonly clear: Effect.Effect<void>;\n\n  readonly retime: (windowMs: number) => Effect.Effect<void>;\n}\n\nexport const makeLiquidStore: Effect.Effect<LiquidStore> = Effect.gen(\n  function* () {\n    const local = yield* makeLocalState<LiquidState>({\n      box: Option.none(),\n      flood: Option.none(),\n    });\n    const lastX = yield* Ref.make(Option.none<number>());\n\n    const edgeAt = (\n      box: Option.Option<MeasuredBox>,\n      x: Option.Option<number>,\n    ): Option.Option<LiquidEdge> =>\n      Option.flatMap(x, (value) =>\n        Option.map(box, (surface) => liquidEdge(value, surface)),\n      );\n\n    const xOf = (point: Option.Option<MeasuredPoint>) =>\n      Option.match(point, {\n        onNone: () => Ref.get(lastX),\n        onSome: (measured) => Effect.succeed(Option.some(measured.x)),\n      });\n\n    const dropFlood = Effect.gen(function* () {\n      const current = yield* SubscriptionRef.get(local.state);\n      if (Option.isNone(current.flood)) return;\n      yield* local.write({ ...current, flood: Option.none() });\n    });\n\n    const measure = Effect.fnUntraced(function* (\n      box: Option.Option<MeasuredBox>,\n    ) {\n      const current = yield* SubscriptionRef.get(local.state);\n      yield* local.write({ ...current, box });\n    });\n\n    const move = Effect.fnUntraced(function* (\n      point: Option.Option<MeasuredPoint>,\n      inert: boolean,\n    ) {\n      yield* Option.match(point, {\n        onNone: () => Effect.void,\n        onSome: (measured) => Ref.set(lastX, Option.some(measured.x)),\n      });\n      const current = yield* SubscriptionRef.get(local.state);\n\n      if (inert || Option.exists(current.flood, (flood) => flood.filled))\n        return;\n      const edge = edgeAt(current.box, yield* xOf(point));\n      if (Option.isNone(edge)) return;\n\n      yield* local.cancel;\n      yield* local.write({\n        ...current,\n        flood: Option.some({\n          entry: edge.value,\n          drain: edge.value,\n          filled: true,\n          run: Option.match(current.flood, {\n            onNone: () => 0,\n            onSome: (previous) => previous.run + 1,\n          }),\n        }),\n      });\n    });\n\n    const leave = Effect.fnUntraced(function* (\n      point: Option.Option<MeasuredPoint>,\n      inert: boolean,\n      windowMs: number,\n    ) {\n      if (inert) return;\n      const current = yield* SubscriptionRef.get(local.state);\n      const drain = edgeAt(current.box, yield* xOf(point));\n      const flood = Option.map(current.flood, (previous) => ({\n        ...previous,\n        drain: Option.getOrElse(drain, () => previous.entry),\n        filled: false,\n      }));\n      if (Option.isNone(flood)) return;\n      yield* local.write({ ...current, flood });\n      yield* local.after(windowMs, dropFlood);\n    });\n\n    const clear = Effect.gen(function* () {\n      yield* local.cancel;\n      yield* dropFlood;\n    });\n\n    const retime = Effect.fnUntraced(function* (windowMs: number) {\n      const current = yield* SubscriptionRef.get(local.state);\n      if (!Option.exists(current.flood, (flood) => !flood.filled)) return;\n      yield* local.after(windowMs, dropFlood);\n    });\n\n    return { local, measure, move, leave, clear, retime };\n  },\n);\n"
    }
  ],
  "docs": "[Liquid button](https://gpuixui.sudokw.com/effects/liquid-button) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/effects/liquid-button",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}