{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fx-stars",
  "type": "registry:component",
  "title": "Stars",
  "description": "A decorative field of twinkling lights",
  "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-components.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/fx/src/stars.tsx",
      "target": "@ui/gpuixui/fx/stars.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { EventPayload, 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 {\n  measuredBox,\n  send,\n  useLocalSlice,\n  useLocalStore,\n  fadeOnly,\n  useMotionPreference,\n  useSurfaceTiming,\n  recipeStyle,\n  countOf,\n  durationOf,\n  seedOf,\n  sizeRangeOf,\n  useTheme,\n} from \"../components/authoring.js\";\nimport {\n  directionOf,\n  starAt,\n  starCount,\n  starCountCap,\n  starField,\n  starMaxSize,\n  starMinSize,\n  starTwinkleCap,\n  starTwinkleFloor,\n  starTwinkleMs,\n  type StarSpec,\n} from \"./stars/logic.js\";\nimport { makeStarsStore, type StarsStore } from \"./stars/store.js\";\n\nexport interface StarsState {\n  readonly count: number;\n  readonly reducedMotion: boolean;\n  readonly width: number;\n  readonly height: number;\n}\n\nexport interface StarsProps extends Omit<Props, \"children\" | \"style\"> {\n  readonly count?: number;\n\n  readonly seed?: number;\n\n  readonly minSize?: number;\n\n  readonly maxSize?: number;\n\n  readonly color?: string;\n\n  readonly twinkleMs?: number;\n\n  readonly level?: MotionLevel;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<StarsState>;\n}\n\ninterface StarProps {\n  readonly spec: StarSpec;\n  readonly ink: string;\n  readonly radius: number;\n  readonly still: boolean;\n  readonly store: StarsStore;\n}\n\nconst Star = ({ spec, ink, radius, still, store }: StarProps) => {\n  const direction = useLocalSlice(store.local, (state) =>\n    directionOf(state.directions, spec.key),\n  );\n  const motion: MotionProps = {\n    initial: { opacity: spec.dim },\n    animate: { opacity: starAt(spec, direction) },\n    transition: {\n      duration: spec.durationMs / 1000,\n      delay: spec.delayMs / 1000,\n      ease: \"easeInOut\",\n    },\n  };\n\n  return (\n    <div\n      testId={`star-${spec.key}`}\n      {...(still\n        ? {}\n        : {\n            motion,\n            onMotionComplete: () => send(store.turn(spec.key)),\n          })}\n      style={{\n        position: \"absolute\",\n        left: spec.x,\n        top: spec.y,\n        width: spec.size,\n        height: spec.size,\n        borderRadius: radius,\n        backgroundColor: ink,\n        opacity: spec.dim,\n\n        pointerEvents: \"none\",\n      }}\n    />\n  );\n};\n\nexport const Stars = ({\n  count,\n  seed,\n  minSize,\n  maxSize,\n  color,\n  twinkleMs,\n  level = \"slow\",\n  className,\n  style,\n  ...rest\n}: StarsProps) => {\n  const theme = useTheme();\n  const preference = useMotionPreference();\n  const timing = useSurfaceTiming(level);\n  const fieldCount = countOf(\n    Option.fromNullishOr(count),\n    starCount,\n    starCountCap,\n  );\n  const sizes = sizeRangeOf(\n    Option.fromNullishOr(minSize),\n    Option.fromNullishOr(maxSize),\n    starMinSize,\n    starMaxSize,\n  );\n  const layoutSeed = seedOf(Option.fromNullishOr(seed));\n  const twinkle = durationOf(\n    Option.fromNullishOr(twinkleMs),\n    starTwinkleMs,\n    starTwinkleFloor,\n    starTwinkleCap,\n  );\n  const ink = color ?? theme.colors.foreground;\n  const still = preference === \"reduced\";\n  const store = useLocalStore(makeStarsStore);\n\n  const box = useLocalSlice(store.local, (current) => current.box);\n\n  const noteBox = (event: EventPayload): void => {\n    send(store.measure(measuredBox(event)));\n  };\n\n  const specs: ReadonlyArray<StarSpec> = Option.match(box, {\n    onNone: () => [],\n    onSome: (measured) =>\n      starField({\n        width: measured.width,\n        height: measured.height,\n        count: fieldCount,\n        seed: layoutSeed,\n        minSize: sizes.min,\n        maxSize: sizes.max,\n        twinkleMs: twinkle,\n      }),\n  });\n\n  const state: StarsState = {\n    count: Arr.length(specs),\n    reducedMotion: still,\n    width: Option.match(box, {\n      onNone: () => 0,\n      onSome: (measured) => measured.width,\n    }),\n    height: Option.match(box, {\n      onNone: () => 0,\n      onSome: (measured) => measured.height,\n    }),\n  };\n\n  return (\n    <div\n      {...rest}\n      onLayout={noteBox}\n      motion={{ ...fadeOnly, transition: timing.enter }}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(className), theme), {\n          position: \"relative\",\n          overflow: \"hidden\",\n\n          pointerEvents: \"none\",\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      {Arr.map(specs, (spec) => (\n        <Star\n          key={spec.key}\n          spec={spec}\n          ink={ink}\n          radius={theme.radius.full}\n          still={still}\n          store={store}\n        />\n      ))}\n    </div>\n  );\n};\n\nexport const starsMeta = {\n  name: \"Stars\",\n  tier: 5,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"a star twinkles by tweening opacity in place: the runtime has no transform (upstream issue #102) and no filter, so a star never drifts, flares or blooms\",\n    \"the field measures its own box, so the caller must bound it; before the first layout it paints nothing\",\n    \"the runtime tweens a target once, so a twinkle is a ping-pong driven by onMotionComplete; a hidden field keeps running until it is unmounted or count is 0\",\n    \"the field publishes no accessibility node and takes no pointer input: name the content it sits behind, never the field\",\n    \"a size change re-draws the sky from the same seed, which restarts every twinkle (a tween cannot be resumed at an arbitrary progress)\",\n  ],\n  docs: \"docs/stars.mdx\",\n  example: \"examples/stars.example.tsx\",\n  testFile: \"src/behaviour/stars.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/fx/src/stars/logic.ts",
      "target": "@ui/gpuixui/fx/stars/logic.ts",
      "type": "registry:lib",
      "content": "import * as Arr from \"effect/Array\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Option from \"effect/Option\";\nimport { paintable, seededUnit, tenth } from \"../../components/authoring.js\";\n\nexport const starCount = 48;\n\nexport const starCountCap = 200;\n\nexport const starMinSize = 1;\nexport const starMaxSize = 3;\n\nexport const starTwinkleMs = 2_400;\n\nexport const starTwinkleFloor = 320;\n\nexport const starTwinkleCap = 20_000;\n\nconst durationFloorShare = 0.7;\nconst durationCeilingShare = 1.3;\n\nconst delayShare = 0.6;\n\nconst dimFloor = 0.15;\nconst dimCeiling = 0.4;\nconst glowFloor = 0.65;\nconst glowCeiling = 1;\n\nexport interface StarSpec {\n  readonly key: string;\n\n  readonly x: number;\n  readonly y: number;\n  readonly size: number;\n\n  readonly dim: number;\n  readonly glow: number;\n\n  readonly durationMs: number;\n\n  readonly delayMs: number;\n}\n\nexport interface StarFieldInput {\n  readonly width: number;\n  readonly height: number;\n  readonly count: number;\n  readonly seed: number;\n  readonly minSize: number;\n  readonly maxSize: number;\n  readonly twinkleMs: number;\n}\n\nexport type StarDirection = 1 | -1;\n\nexport interface StarBox {\n  readonly width: number;\n  readonly height: number;\n}\n\nexport const starAt = (spec: StarSpec, direction: StarDirection): number =>\n  direction === 1 ? spec.glow : spec.dim;\n\nexport const turned = (direction: StarDirection): StarDirection =>\n  direction === 1 ? -1 : 1;\n\nexport const directionOf = (\n  directions: HashMap.HashMap<string, StarDirection>,\n  key: string,\n): StarDirection => Option.getOrElse(HashMap.get(directions, key), () => 1);\n\nexport const sameBox = (\n  a: Option.Option<StarBox>,\n  b: Option.Option<StarBox>,\n): boolean =>\n  Option.match(a, {\n    onNone: () => Option.isNone(b),\n    onSome: (held) =>\n      Option.exists(\n        b,\n        (next) => held.width === next.width && held.height === next.height,\n      ),\n  });\n\nexport const starField = (input: StarFieldInput): ReadonlyArray<StarSpec> => {\n  if (!paintable(input.width) || !paintable(input.height)) return [];\n  const count = Math.min(Math.max(Math.round(input.count), 0), starCountCap);\n  if (count === 0) return [];\n  const maxSize = Math.max(input.maxSize, input.minSize);\n  const originX = Math.min(maxSize, input.width / 2);\n  const originY = Math.min(maxSize, input.height / 2);\n  const spanX = Math.max(input.width - originX * 2, 0);\n  const spanY = Math.max(input.height - originY * 2, 0);\n\n  return Arr.makeBy(count, (index) => {\n    const size = Math.round(\n      input.minSize +\n        seededUnit(input.seed, index, 2) * (maxSize - input.minSize),\n    );\n    const durationMs = Math.round(\n      input.twinkleMs *\n        (durationFloorShare +\n          seededUnit(input.seed, index, 4) *\n            (durationCeilingShare - durationFloorShare)),\n    );\n    return {\n      key: String(index),\n      x: tenth(originX + seededUnit(input.seed, index, 0) * spanX),\n      y: tenth(originY + seededUnit(input.seed, index, 1) * spanY),\n      size: Math.max(size, 1),\n      dim: tenth(\n        dimFloor + seededUnit(input.seed, index, 3) * (dimCeiling - dimFloor),\n      ),\n      glow: tenth(\n        glowFloor +\n          seededUnit(input.seed, index, 5) * (glowCeiling - glowFloor),\n      ),\n      durationMs,\n      delayMs: Math.round(\n        seededUnit(input.seed, index, 6) * durationMs * delayShare,\n      ),\n    };\n  });\n};\n"
    },
    {
      "path": "packages/fx/src/stars/store.ts",
      "target": "@ui/gpuixui/fx/stars/store.ts",
      "type": "registry:lib",
      "content": "import { Effect } from \"effect\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Option from \"effect/Option\";\nimport * as SubscriptionRef from \"effect/SubscriptionRef\";\nimport {\n  type MeasuredBox,\n  makeLocalState,\n  type LocalState,\n} from \"../../components/authoring.js\";\nimport {\n  directionOf,\n  sameBox,\n  turned,\n  type StarBox,\n  type StarDirection,\n} from \"./logic.js\";\n\nexport interface StarsStoreState {\n  readonly box: Option.Option<StarBox>;\n\n  readonly directions: HashMap.HashMap<string, StarDirection>;\n}\n\nexport interface StarsStore {\n  readonly local: LocalState<StarsStoreState>;\n\n  readonly measure: (box: Option.Option<MeasuredBox>) => Effect.Effect<void>;\n\n  readonly turn: (key: string) => Effect.Effect<void>;\n}\n\nexport const makeStarsStore: Effect.Effect<StarsStore> = Effect.gen(\n  function* () {\n    const local = yield* makeLocalState<StarsStoreState>({\n      box: Option.none(),\n      directions: HashMap.empty(),\n    });\n\n    const measure = Effect.fnUntraced(function* (\n      box: Option.Option<MeasuredBox>,\n    ) {\n      const current = yield* SubscriptionRef.get(local.state);\n      const next = Option.map(box, (measured) => ({\n        width: measured.width,\n        height: measured.height,\n      }));\n      if (sameBox(current.box, next)) return;\n      yield* local.write({ ...current, box: next });\n    });\n\n    const turn = Effect.fnUntraced(function* (key: string) {\n      const current = yield* SubscriptionRef.get(local.state);\n      yield* local.write({\n        ...current,\n        directions: HashMap.set(\n          current.directions,\n          key,\n          turned(directionOf(current.directions, key)),\n        ),\n      });\n    });\n\n    return {\n      local,\n      measure,\n      turn,\n    };\n  },\n);\n"
    }
  ],
  "docs": "[Stars](https://gpuixui.sudokw.com/effects/stars) — 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/stars",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}