{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-motion-grid",
  "type": "registry:component",
  "title": "Motion grid",
  "description": "Cells that travel to their new slots when order changes",
  "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",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/motion-grid.tsx",
      "target": "@ui/gpuixui/fx/motion-grid.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { 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 type { ReactNode } from \"react\";\nimport {\n  useMotionPreference,\n  useSurfaceTiming,\n  recipeStyle,\n  nameOf,\n  useTheme,\n} from \"../components/authoring.js\";\nimport {\n  motionGridHeight,\n  itemsOf,\n  motionGridLayout,\n  motionGridRows,\n  motionGridSlot,\n  motionGridWidth,\n} from \"./motion-grid/logic.js\";\n\nexport interface MotionGridItem {\n  readonly id: string;\n\n  readonly content: ReactNode;\n}\n\nexport interface MotionGridState {\n  readonly count: number;\n\n  readonly columns: number;\n\n  readonly rows: number;\n  readonly reducedMotion: boolean;\n}\n\nexport interface MotionGridProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly items: ReadonlyArray<MotionGridItem>;\n\n  readonly columns?: number;\n\n  readonly cellWidth?: number;\n\n  readonly rowHeight?: number;\n\n  readonly gap?: number;\n\n  readonly level?: MotionLevel;\n\n  readonly label?: string;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<MotionGridState>;\n}\n\nexport const MotionGrid = ({\n  items: storedItems,\n  columns,\n  cellWidth,\n  rowHeight,\n  gap,\n  level = \"normal\",\n  label,\n  className,\n  style,\n  ...rest\n}: MotionGridProps) => {\n  const theme = useTheme();\n  const items = itemsOf(storedItems);\n  const preference = useMotionPreference();\n  const timing = useSurfaceTiming(level).enter;\n  const layout = motionGridLayout({\n    columns: Option.fromNullishOr(columns),\n    cellWidth: Option.fromNullishOr(cellWidth),\n    rowHeight: Option.fromNullishOr(rowHeight),\n    gap: Option.fromNullishOr(gap),\n  });\n  const count = Arr.length(items);\n  const rows = motionGridRows(count, layout.columns);\n  const reduced = preference === \"reduced\";\n  const gridName = nameOf(label);\n  const state: MotionGridState = {\n    count,\n    columns: layout.columns,\n    rows,\n    reducedMotion: reduced,\n  };\n\n  return (\n    <div\n      {...rest}\n      {...(gridName === undefined\n        ? {}\n        : { role: \"group\", \"aria-label\": gridName })}\n      motion={{\n        initial: false,\n        animate: { height: motionGridHeight(layout, rows) },\n        transition: timing,\n      }}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(className), theme), {\n          position: \"relative\",\n          width: motionGridWidth(layout),\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      {items.map((item, index) => {\n        const slot = motionGridSlot(layout, index);\n        return (\n          <div\n            key={item.id}\n            testId={`motion-grid-cell-${item.id}`}\n            motion={{\n              initial: reduced ? false : { opacity: 0 },\n              animate: { opacity: 1, left: slot.left, top: slot.top },\n              transition: timing,\n            }}\n            style={{\n              position: \"absolute\",\n              width: slot.width,\n              height: slot.height,\n            }}\n          >\n            {item.content}\n          </div>\n        );\n      })}\n    </div>\n  );\n};\n\nexport const motionGridMeta = {\n  name: \"Motion grid\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"no cell sizes its row: every cell is absolutely positioned so its inset can be tweened, so the caller names cellWidth and rowHeight instead of the content measuring\",\n    \"a reorder moves a cell's left/top inset, not a transform: the runtime has no transform (upstream issue #102), so there is no scale or rotate on the way\",\n    \"a cell's key is its id, so two cells sharing an id cannot both animate\",\n    \"the wrapper paints nothing and clips nothing, because a caller's card or shadow owns its own look\",\n  ],\n  docs: \"docs/motion-grid.mdx\",\n  example: \"examples/motion-grid.example.tsx\",\n  testFile: \"src/behaviour/motion-grid.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/motion-grid/logic.ts",
      "target": "@ui/gpuixui/fx/motion-grid/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\n\nexport const motionGridColumnCount = 3;\n\nexport const motionGridCellWidth = 160;\n\nexport const motionGridRowHeight = 120;\n\nexport const motionGridGap = 12;\n\nconst isCell = <Cell extends { readonly id: string }>(\n  entry: unknown,\n): entry is Cell => {\n  if (typeof entry !== \"object\" || entry === null || !(\"id\" in entry)) {\n    return false;\n  }\n  const id = entry.id;\n  return typeof id === \"string\" && id.trim().length > 0;\n};\n\nexport const itemsOf = <Cell extends { readonly id: string }>(\n  value: ReadonlyArray<Cell> | null | undefined,\n): ReadonlyArray<Cell> => {\n  const list = Option.getOrElse(\n    Option.filter(Option.fromNullishOr(value), (entries): boolean =>\n      Arr.isArray(entries),\n    ),\n    () => [],\n  );\n  return Arr.filter(list, isCell);\n};\n\nexport interface MotionGridLayout {\n  readonly columns: number;\n\n  readonly cellWidth: number;\n\n  readonly rowHeight: number;\n\n  readonly gap: number;\n}\n\nexport interface MotionGridOptions {\n  readonly columns: Option.Option<number>;\n  readonly cellWidth: Option.Option<number>;\n  readonly rowHeight: Option.Option<number>;\n  readonly gap: Option.Option<number>;\n}\n\nconst wholePixels = (\n  value: Option.Option<number>,\n  house: number,\n  floor: number,\n): number =>\n  Option.match(value, {\n    onNone: () => house,\n    onSome: (next) =>\n      Number.isFinite(next) ? Math.max(floor, Math.round(next)) : house,\n  });\n\nconst columnCount = (value: Option.Option<number>): number =>\n  Option.match(value, {\n    onNone: () => motionGridColumnCount,\n    onSome: (next) =>\n      Number.isFinite(next)\n        ? Math.max(1, Math.floor(next))\n        : motionGridColumnCount,\n  });\n\nexport const motionGridLayout = (\n  options: MotionGridOptions,\n): MotionGridLayout => ({\n  columns: columnCount(options.columns),\n  cellWidth: wholePixels(options.cellWidth, motionGridCellWidth, 1),\n  rowHeight: wholePixels(options.rowHeight, motionGridRowHeight, 1),\n  gap: wholePixels(options.gap, motionGridGap, 0),\n});\n\nexport const motionGridRows = (count: number, columns: number): number =>\n  count <= 0 ? 0 : Math.ceil(count / columns);\n\nexport const motionGridWidth = (layout: MotionGridLayout): number =>\n  layout.columns * layout.cellWidth + (layout.columns - 1) * layout.gap;\n\nexport const motionGridHeight = (\n  layout: MotionGridLayout,\n  rows: number,\n): number =>\n  rows <= 0 ? 0 : rows * layout.rowHeight + (rows - 1) * layout.gap;\n\nexport interface MotionGridSlot {\n  readonly left: number;\n  readonly top: number;\n  readonly width: number;\n  readonly height: number;\n}\n\nexport const motionGridSlot = (\n  layout: MotionGridLayout,\n  index: number,\n): MotionGridSlot => {\n  const column = index % layout.columns;\n  const row = Math.floor(index / layout.columns);\n  return {\n    left: column * (layout.cellWidth + layout.gap),\n    top: row * (layout.rowHeight + layout.gap),\n    width: layout.cellWidth,\n    height: layout.rowHeight,\n  };\n};\n"
    }
  ],
  "docs": "[Motion grid](https://gpuixui.sudokw.com/effects/motion-grid) — 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/motion-grid",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}