{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-sliding-number",
  "type": "registry:component",
  "title": "Sliding number",
  "description": "A number whose digits roll like a counter",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/presence.tsx",
      "target": "@ui/gpuixui/components/internal/presence.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { MotionProps } from \"@gpuix/react\";\nimport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceMotion as motionOfPresence,\n  presenceStyle,\n  transitionWindowMs,\n  type PresenceFrames,\n  type PresenceHitRule,\n  type PresenceSide,\n  type PresenceTiming,\n  type PresenceTransition,\n} from \"../../motion/presence.js\";\nimport {\n  MotionProvider,\n  useMotionPreference,\n  useSurfacePresence,\n  useSurfaceTiming,\n  type MotionProviderProps,\n  type SurfacePresence,\n} from \"../../motion/react/presence.js\";\nimport {\n  motionTiming,\n  type MotionLevel,\n  type MotionPreference,\n} from \"../../motion/timing.js\";\n\nexport { MotionProvider, useMotionPreference, type MotionProviderProps };\n\nexport type SurfaceFrames = PresenceFrames;\n\nexport type SurfaceTiming = PresenceTiming;\n\nexport type PanelSide = PresenceSide;\n\nexport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceStyle,\n  transitionWindowMs,\n};\nexport type { PresenceHitRule };\n\nexport { useSurfacePresence, useSurfaceTiming, type SurfacePresence };\n\nexport const moveTiming = (\n  level: MotionLevel,\n  preference: MotionPreference,\n): PresenceTransition => motionTiming(level, { phase: \"standard\", preference });\n\nexport const useMoveTiming = (level: MotionLevel): PresenceTransition =>\n  moveTiming(level, useMotionPreference());\n\nexport const presenceMotion = (\n  frames: SurfaceFrames,\n  presence: SurfacePresence,\n  timing: SurfaceTiming = presence.timing,\n): MotionProps => motionOfPresence(frames, presence.present, timing);\n\nexport const PresenceShield = ({ present }: { readonly present: boolean }) =>\n  present ? null : (\n    <div\n      testId=\"presence-shield\"\n      style={{ position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 }}\n    />\n  );\n\nexport const presenceTabStop = (\n  present: boolean,\n): { readonly tabIndex?: number } => (present ? {} : { tabIndex: -1 });\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/text.ts",
      "target": "@ui/gpuixui/components/internal/text.ts",
      "type": "registry:lib",
      "content": "import { pipe } from \"effect\";\nimport * as Option from \"effect/Option\";\nimport * as Str from \"effect/String\";\n\nexport const textOf = (value: unknown): string =>\n  typeof value === \"string\" ? value : \"\";\n\nexport const nameOf = (value: unknown): string | undefined =>\n  pipe(\n    Option.some(textOf(value)),\n    Option.map(Str.trim),\n    Option.filter(Str.isNonEmpty),\n    Option.getOrUndefined,\n  );\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/sliding-number.tsx",
      "target": "@ui/gpuixui/components/sliding-number.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { MotionProps, Props } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport type { MotionLevel } from \"../motion/timing.js\";\nimport { cn } from \"../tw/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport { useMotionPreference, useSurfaceTiming } from \"./internal/presence.js\";\nimport { recipeStyle } from \"./internal/recipe.js\";\nimport { nameOf } from \"./internal/text.js\";\nimport { textStyle, useTheme, type TextRole } from \"./internal/theme.js\";\nimport {\n  columnTop,\n  digitCells,\n  numberLayout,\n  type NumberCell,\n} from \"./sliding-number/logic.js\";\n\nexport interface SlidingNumberState {\n  readonly value: number;\n\n  readonly text: string;\n  readonly reducedMotion: boolean;\n}\n\nexport interface SlidingNumberProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly value: number;\n\n  readonly decimals?: number;\n\n  readonly prefix?: string;\n\n  readonly suffix?: string;\n\n  readonly label?: string;\n\n  readonly level?: MotionLevel;\n\n  readonly role?: TextRole;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<SlidingNumberState>;\n}\n\nconst DigitColumn = ({\n  cell,\n  metrics,\n  ink,\n  motion,\n}: {\n  readonly cell: NumberCell;\n  readonly metrics: ReturnType<typeof textStyle>;\n  readonly ink: { readonly color: string };\n  readonly motion: MotionProps;\n}) => (\n  <div\n    testId={`cell-${cell.key}`}\n    style={{\n      display: \"flex\",\n      flexDirection: \"column\",\n      alignItems: \"center\",\n      overflow: \"hidden\",\n      height: metrics.lineHeight,\n    }}\n  >\n    <div\n      testId={`cell-${cell.key}-plate`}\n      motion={motion}\n      style={{\n        position: \"relative\",\n        display: \"flex\",\n        flexDirection: \"column\",\n        alignItems: \"center\",\n      }}\n    >\n      {Arr.map(digitCells, (painted) => (\n        <text\n          key={painted}\n          role=\"presentation\"\n          style={{ ...metrics, ...ink, height: metrics.lineHeight }}\n        >\n          {String(painted)}\n        </text>\n      ))}\n    </div>\n  </div>\n);\n\nexport const SlidingNumber = ({\n  value,\n  decimals,\n  prefix,\n  suffix,\n  label,\n  level = \"normal\",\n  role = \"body\",\n  className,\n  style,\n  ...rest\n}: SlidingNumberProps) => {\n  const theme = useTheme();\n  const reducedMotion = useMotionPreference() === \"reduced\";\n  const timing = useSurfaceTiming(level);\n  const layout = numberLayout(value, { decimals, prefix, suffix });\n  const metrics = textStyle(theme, role);\n  const ink = { color: theme.colors.foreground };\n  const state: SlidingNumberState = {\n    value,\n    text: layout.text,\n    reducedMotion,\n  };\n\n  const cell = (current: NumberCell) =>\n    Option.match(current.digit, {\n      onNone: () => (\n        <text\n          key={current.key}\n          testId={`cell-${current.key}`}\n          role=\"presentation\"\n          style={{ ...metrics, ...ink }}\n        >\n          .\n        </text>\n      ),\n      onSome: (digit) => (\n        <DigitColumn\n          key={current.key}\n          cell={current}\n          metrics={metrics}\n          ink={ink}\n          motion={{\n            initial: false,\n            animate: { top: columnTop(digit, metrics.lineHeight) },\n            transition: timing.enter,\n          }}\n        />\n      ),\n    });\n\n  const fixed = (content: string, key?: string) => (\n    <text key={key} role=\"presentation\" style={{ ...metrics, ...ink }}>\n      {content}\n    </text>\n  );\n\n  return (\n    <div\n      {...rest}\n      role=\"status\"\n      aria-label={nameOf(label) ?? layout.text}\n      style={mergeStyles(\n        { display: \"flex\", flexDirection: \"row\", alignItems: \"flex-start\" },\n        mergeStyles(\n          recipeStyle(cn(className), theme),\n          resolveStyle(style, state),\n        ),\n      )}\n    >\n      {Arr.match(layout.cells, {\n        onEmpty: () => fixed(layout.text),\n        onNonEmpty: () => (\n          <>\n            {layout.negative ? fixed(\"-\") : null}\n            {prefix === undefined ? null : fixed(prefix)}\n            {Arr.map(layout.cells, cell)}\n            {suffix === undefined ? null : fixed(suffix)}\n          </>\n        ),\n      })}\n    </div>\n  );\n};\n\nexport const slidingNumberMeta = {\n  name: \"Sliding number\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"each column raises its plate inside a one-line clip, not a transform: the runtime scales nothing (upstream issue #102)\",\n    \"a column is as wide as its widest digit, because the runtime cannot measure a glyph before it is laid out, so the row is tabular by construction rather than by font\",\n    \"a carry rolls the digit back through its column rather than wrapping forward (9 → 0 travels the whole stack), and a roll takes one level whatever distance it covers\",\n    \"a value that loses a digit drops its column at once; only the columns that remain roll\",\n    \"no grouping separator and no currency formatting: `decimals`, `prefix` and `suffix` are the whole format\",\n  ],\n  docs: \"docs/sliding-number.mdx\",\n  example: \"examples/sliding-number.example.tsx\",\n  testFile: \"src/behaviour/sliding-number.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/components/src/sliding-number/logic.ts",
      "target": "@ui/gpuixui/components/sliding-number/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport * as Str from \"effect/String\";\n\nexport const slidingNumberDecimalsCap = 6;\n\nexport const digitCells: ReadonlyArray<number> = Arr.range(0, 9);\n\nconst PLAIN = /^(-?)(\\d+)(?:\\.(\\d+))?$/;\n\nexport interface NumberCell {\n  readonly key: string;\n\n  readonly digit: Option.Option<number>;\n}\n\nexport interface NumberLayout {\n  readonly negative: boolean;\n\n  readonly cells: ReadonlyArray<NumberCell>;\n\n  readonly text: string;\n}\n\nexport interface NumberFormat {\n  readonly decimals?: number;\n\n  readonly prefix?: string;\n\n  readonly suffix?: string;\n}\n\nexport const decimalsOf = (decimals: number | undefined): number =>\n  Option.fromNullishOr(decimals).pipe(\n    Option.filter(Number.isFinite),\n    Option.map((places) =>\n      Math.min(slidingNumberDecimalsCap, Math.max(0, Math.floor(places))),\n    ),\n    Option.getOrElse(() => 0),\n  );\n\nconst placeCells = (\n  part: string,\n  placeOf: (index: number, length: number) => number,\n  keyPrefix: \"i\" | \"f\",\n): ReadonlyArray<NumberCell> =>\n  Arr.map(Str.split(\"\")(part), (digit, index) => ({\n    key: `${keyPrefix}${placeOf(index, Str.length(part))}`,\n    digit: Option.some(Number(digit)),\n  }));\n\nconst pointCell: NumberCell = { key: \"point\", digit: Option.none() };\n\nexport const numberLayout = (\n  value: number,\n  format: NumberFormat = {},\n): NumberLayout => {\n  const decimals = decimalsOf(format.decimals);\n  const prefix = format.prefix ?? \"\";\n  const suffix = format.suffix ?? \"\";\n  const fixed = Number.isFinite(value) ? value.toFixed(decimals) : \"\";\n  return Option.match(Option.fromNullishOr(PLAIN.exec(fixed)), {\n    onNone: () => ({\n      negative: false,\n      cells: [],\n      text: `${prefix}${String(value)}${suffix}`,\n    }),\n    onSome: (match) => {\n      const sign = match[1] ?? \"\";\n      const integers = match[2] ?? \"\";\n      const fraction = match[3];\n      const digits = `${integers}${fraction ?? \"\"}`;\n      const cells = [\n        ...placeCells(integers, (index, length) => length - 1 - index, \"i\"),\n        ...Option.match(Option.fromNullishOr(fraction), {\n          onNone: () => [],\n          onSome: (places) => [\n            pointCell,\n            ...placeCells(places, (index) => index + 1, \"f\"),\n          ],\n        }),\n      ];\n\n      const negative =\n        sign === \"-\" &&\n        Arr.some(Str.split(\"\")(digits), (digit) => digit !== \"0\");\n      return {\n        negative,\n        cells,\n        text: `${negative ? \"-\" : \"\"}${prefix}${integers}${fraction === undefined ? \"\" : `.${fraction}`}${suffix}`,\n      };\n    },\n  });\n};\n\nexport const columnTop = (digit: number, lineHeight: number): number => {\n  if (!Number.isFinite(lineHeight)) return 0;\n  const offset = -digit * lineHeight;\n  return offset === 0 ? 0 : offset;\n};\n"
    }
  ],
  "docs": "[Sliding number](https://gpuixui.sudokw.com/components/sliding-number) — 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": "/components/sliding-number",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}