{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"magnetic-field","type":"registry:ui","title":"MagneticField","description":"Items are pulled toward a magnet and lean toward it, light ones more than heavy ones, then spring home. The magnet is the pointer or a draggable puck.","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["effects"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/internals-motion.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/magnetic-field/MagnetPuck.tsx","content":"\"use client\";\n\nimport { forwardRef, useContext, useEffect, useRef, useState } from \"react\";\nimport type {\n\tFocusEvent as ReactFocusEvent,\n\tHTMLAttributes,\n\tKeyboardEvent as ReactKeyboardEvent,\n\tPointerEvent as ReactPointerEvent,\n\tReactNode,\n} from \"react\";\nimport { cn } from \"../../utils\";\nimport { useComposedRefs } from \"../../internals/dom/use-composed-refs\";\nimport { useFancyId } from \"../../internals/use-id\";\nimport type { MagneticPoint } from \"./magnetic-field-core\";\nimport { MAGNETIC_FIELD_KEY } from \"./types\";\nimport \"./magnetic-field.css\";\n\n/** Read after the name, so keyboard and screen-reader users learn the keys. */\nconst KEY_HINT = \"Space or Enter picks it up and puts it down; the arrow keys move it.\";\n\n/** Arrow-key step, px; Shift multiplies it by four. */\nconst KEY_STEP = 8;\nconst KEY_STEP_LARGE = 32;\n\nconst DEFAULT_POSITION: MagneticPoint = { x: 48, y: 48 };\n\nexport interface MagnetPuckOwnProps {\n\t/**\n\t * The puck's centre in px, relative to its positioned parent (the field's\n\t * padding box when it sits inside a `MagneticField`, where the field must\n\t * be that parent: no positioned element in between). Controlled when\n\t * given: dragging and the arrow keys then only report the new position\n\t * through `onPositionChange`. Leave it out to let the puck keep its own,\n\t * seeded from `defaultPosition`.\n\t */\n\tposition?: MagneticPoint;\n\t/** Initial centre when uncontrolled (no `position` prop given). */\n\tdefaultPosition?: MagneticPoint;\n\t/** Called with each new position while the puck is dragged or moved with the keyboard. */\n\tonPositionChange?: (position: MagneticPoint) => void;\n\t/** Diameter in px. */\n\tsize?: number;\n\t/**\n\t * Whether the puck keeps attracting once released. By default it attracts\n\t * only while held, and the items spring back when it is let go.\n\t */\n\tsticky?: boolean;\n\t/**\n\t * Accessible name. The puck is also described by a built-in hint naming\n\t * its keys; pass `aria-describedby` to replace it.\n\t */\n\tlabel?: string;\n\t/** Called when the puck is picked up (pointer down, or Space/Enter) and put down. */\n\tonHeldChange?: (held: boolean) => void;\n\t/** A custom face. Leave it out for the default black disc. */\n\tchildren?: ReactNode;\n\t/** Additional CSS classes. */\n\tclassName?: string;\n}\n\n/** Native `<div>` attributes are forwarded to the puck. */\nexport interface MagnetPuckProps\n\textends MagnetPuckOwnProps, Omit<HTMLAttributes<HTMLDivElement>, keyof MagnetPuckOwnProps> {}\n\ntype Holder = \"pointer\" | \"keyboard\" | null;\n\nexport const MagnetPuck = forwardRef<HTMLDivElement, MagnetPuckProps>(function MagnetPuck(\n\t{\n\t\tposition: positionProp,\n\t\tdefaultPosition = DEFAULT_POSITION,\n\t\tonPositionChange,\n\t\tsize = 40,\n\t\tsticky = false,\n\t\tlabel = \"Magnet\",\n\t\tonHeldChange,\n\t\tchildren,\n\t\tclassName,\n\t\tstyle,\n\t\tonPointerDown,\n\t\tonPointerMove,\n\t\tonPointerUp,\n\t\tonPointerCancel,\n\t\tonLostPointerCapture,\n\t\tonKeyDown,\n\t\tonBlur,\n\t\t...rest\n\t},\n\tforwardedRef\n) {\n\t// Undefined outside a MagneticField: the puck is then a plain draggable,\n\t// and the consumer feeds `position` into a `source=\"manual\"` field.\n\tconst ctx = useContext(MAGNETIC_FIELD_KEY);\n\n\tconst hintId = `${useFancyId()}-hint`;\n\n\tconst nodeRef = useRef<HTMLDivElement | null>(null);\n\tconst composedRef = useComposedRefs(forwardedRef, nodeRef);\n\n\tconst isControlled = positionProp !== undefined;\n\tconst [uncontrolled, setUncontrolled] = useState<MagneticPoint>(() => ({\n\t\tx: defaultPosition.x,\n\t\ty: defaultPosition.y,\n\t}));\n\tconst position = isControlled ? positionProp : uncontrolled;\n\n\t/** Who holds the puck: a pointer drag, the keyboard (Space/Enter), or nobody. */\n\tconst [holder, setHolderState] = useState<Holder>(null);\n\t// Mirrors `holder` synchronously, so two events dispatched in one task (a\n\t// pointerdown then a blur) see each other's write before React re-renders.\n\tconst holderRef = useRef<Holder>(null);\n\tconst held = holder !== null;\n\n\t// The position the latest handler wrote, for the same reason: a second\n\t// keydown in the same task must step from the first one's result.\n\tconst positionRef = useRef<MagneticPoint>(position);\n\tpositionRef.current = position;\n\n\tconst activePointerId = useRef<number | null>(null);\n\tconst dragStart = useRef({ x: 0, y: 0 });\n\tconst dragOrigin = useRef<MagneticPoint>({ x: 0, y: 0 });\n\n\tfunction setHolder(next: Holder) {\n\t\tconst was = holderRef.current !== null;\n\t\tholderRef.current = next;\n\t\tsetHolderState(next);\n\t\tif (was !== (next !== null)) onHeldChange?.(next !== null);\n\t}\n\n\t/**\n\t * Keeps the whole disc inside the positioned parent's padding box, the box\n\t * `position` is measured in. An axis whose size reads 0 (not laid out yet,\n\t * or jsdom) is left unclamped rather than pinned to the corner.\n\t */\n\tfunction clampToParent(p: MagneticPoint): MagneticPoint {\n\t\tconst el = nodeRef.current;\n\t\tconst parent = (el?.offsetParent as HTMLElement | null) ?? el?.parentElement ?? null;\n\t\tif (!parent) return p;\n\t\tconst half = size / 2;\n\t\tconst w = parent.clientWidth;\n\t\tconst h = parent.clientHeight;\n\t\treturn {\n\t\t\tx: w > 0 ? Math.min(Math.max(p.x, half), Math.max(half, w - half)) : p.x,\n\t\t\ty: h > 0 ? Math.min(Math.max(p.y, half), Math.max(half, h - half)) : p.y,\n\t\t};\n\t}\n\n\tfunction moveTo(p: MagneticPoint) {\n\t\tconst next = clampToParent(p);\n\t\tconst current = positionRef.current;\n\t\tif (next.x === current.x && next.y === current.y) return;\n\t\tpositionRef.current = next;\n\t\tif (!isControlled) setUncontrolled(next);\n\t\tonPositionChange?.(next);\n\t}\n\n\tfunction releasePointer() {\n\t\tif (activePointerId.current === null) return;\n\t\t// Cleared first: releasing capture may dispatch `lostpointercapture`\n\t\t// synchronously, and that handler must find nothing left to end.\n\t\tconst id = activePointerId.current;\n\t\tactivePointerId.current = null;\n\t\tnodeRef.current?.releasePointerCapture?.(id);\n\t}\n\n\tfunction release() {\n\t\treleasePointer();\n\t\tsetHolder(null);\n\t}\n\n\tfunction handlePointerDown(event: ReactPointerEvent<HTMLDivElement>) {\n\t\tonPointerDown?.(event);\n\t\tif (event.pointerType === \"mouse\" && event.button !== 0) return;\n\t\tif (activePointerId.current !== null) return;\n\t\tactivePointerId.current = event.pointerId;\n\t\tdragStart.current = { x: event.clientX, y: event.clientY };\n\t\tconst current = positionRef.current;\n\t\tdragOrigin.current = { x: current.x, y: current.y };\n\t\t// Keeps pointermove/pointerup flowing to the puck even when a fast drag\n\t\t// outruns it. Optional call: jsdom implements neither capture method.\n\t\tnodeRef.current?.setPointerCapture?.(event.pointerId);\n\t\tsetHolder(\"pointer\");\n\t}\n\n\tfunction handlePointerMove(event: ReactPointerEvent<HTMLDivElement>) {\n\t\tonPointerMove?.(event);\n\t\tif (event.pointerId !== activePointerId.current) return;\n\t\tmoveTo({\n\t\t\tx: dragOrigin.current.x + event.clientX - dragStart.current.x,\n\t\t\ty: dragOrigin.current.y + event.clientY - dragStart.current.y,\n\t\t});\n\t}\n\n\tfunction endPointer(event: ReactPointerEvent<HTMLDivElement>) {\n\t\tif (event.pointerId !== activePointerId.current) return;\n\t\trelease();\n\t}\n\n\tfunction handleKeyDown(event: ReactKeyboardEvent<HTMLDivElement>) {\n\t\tonKeyDown?.(event);\n\t\tconst step = event.shiftKey ? KEY_STEP_LARGE : KEY_STEP;\n\t\tlet dx = 0;\n\t\tlet dy = 0;\n\t\tswitch (event.key) {\n\t\t\tcase \"ArrowLeft\":\n\t\t\t\tdx = -step;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowRight\":\n\t\t\t\tdx = step;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowUp\":\n\t\t\t\tdy = -step;\n\t\t\t\tbreak;\n\t\t\tcase \"ArrowDown\":\n\t\t\t\tdy = step;\n\t\t\t\tbreak;\n\t\t\tcase \" \":\n\t\t\tcase \"Enter\":\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif (event.repeat) return;\n\t\t\t\tif (holderRef.current !== null) release();\n\t\t\t\telse setHolder(\"keyboard\");\n\t\t\t\treturn;\n\t\t\tcase \"Escape\":\n\t\t\t\tif (holderRef.current === null) return;\n\t\t\t\tevent.preventDefault();\n\t\t\t\trelease();\n\t\t\t\treturn;\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tevent.preventDefault();\n\t\tconst current = positionRef.current;\n\t\tmoveTo({ x: current.x + dx, y: current.y + dy });\n\t}\n\n\tfunction handleBlur(event: ReactFocusEvent<HTMLDivElement>) {\n\t\tonBlur?.(event);\n\t\t// A keyboard hold has nothing left to end it once focus moves away.\n\t\tif (holderRef.current === \"keyboard\") release();\n\t}\n\n\t// Feeds the field's \"puck\" channel while the puck attracts: held, or\n\t// released with `sticky`. A plain object is passed so the core never keeps\n\t// a reference to a consumer's position object. No per-run cleanup:\n\t// clearing between two positions of one drag would blink the channel to null.\n\tconst x = position.x;\n\tconst y = position.y;\n\tconst attracting = held || sticky;\n\tuseEffect(() => {\n\t\tif (!ctx) return;\n\t\tctx.setSource(attracting ? { x, y } : null, \"puck\");\n\t}, [ctx, x, y, attracting]);\n\n\t// Unmounting a held or sticky puck lets the items go.\n\tuseEffect(() => {\n\t\treturn () => {\n\t\t\tctx?.setSource(null, \"puck\");\n\t\t};\n\t}, [ctx]);\n\n\t// A window that loses focus mid-drag (Alt+Tab, a system dialog) may never\n\t// deliver the pointerup: drop the puck rather than leave it stuck in hand.\n\tconst releaseRef = useRef(release);\n\treleaseRef.current = release;\n\tuseEffect(() => {\n\t\tif (!held) return;\n\t\tconst onWindowBlur = () => releaseRef.current();\n\t\twindow.addEventListener(\"blur\", onWindowBlur);\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\"blur\", onWindowBlur);\n\t\t};\n\t}, [held]);\n\n\treturn (\n\t\t<div\n\t\t\t{...rest}\n\t\t\tref={composedRef}\n\t\t\tclassName={cn(\"ft-magnet-puck\", className)}\n\t\t\trole=\"button\"\n\t\t\ttabIndex={0}\n\t\t\taria-label={label}\n\t\t\taria-describedby={rest[\"aria-describedby\"] ?? hintId}\n\t\t\taria-pressed={held}\n\t\t\tdata-held={held || undefined}\n\t\t\tstyle={{\n\t\t\t\t...style,\n\t\t\t\twidth: `${size}px`,\n\t\t\t\theight: `${size}px`,\n\t\t\t\ttransform: `translate3d(${position.x - size / 2}px, ${position.y - size / 2}px, 0)`,\n\t\t\t}}\n\t\t\tonPointerDown={handlePointerDown}\n\t\t\tonPointerMove={handlePointerMove}\n\t\t\tonPointerUp={(event) => {\n\t\t\t\tonPointerUp?.(event);\n\t\t\t\tendPointer(event);\n\t\t\t}}\n\t\t\tonPointerCancel={(event) => {\n\t\t\t\tonPointerCancel?.(event);\n\t\t\t\tendPointer(event);\n\t\t\t}}\n\t\t\tonLostPointerCapture={(event) => {\n\t\t\t\tonLostPointerCapture?.(event);\n\t\t\t\tendPointer(event);\n\t\t\t}}\n\t\t\tonKeyDown={handleKeyDown}\n\t\t\tonBlur={handleBlur}\n\t\t>\n\t\t\t{children ?? <span className=\"ft-magnet-puck-face\" aria-hidden=\"true\" />}\n\t\t\t<span id={hintId} className=\"ft-magnet-puck-hint\">\n\t\t\t\t{KEY_HINT}\n\t\t\t</span>\n\t\t</div>\n\t);\n});\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/MagnetPuck.tsx"},{"path":"react/src/components/magnetic-field/MagneticField.tsx","content":"\"use client\";\n\nimport { forwardRef, useCallback, useEffect, useRef, useState } from \"react\";\nimport type { HTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"../../utils\";\nimport { useComposedRefs } from \"../../internals/dom/use-composed-refs\";\nimport { useElementRef } from \"../../internals/dom/use-element-ref\";\nimport { useLiveRef } from \"../../internals/dom/use-live-ref\";\nimport { observeInView } from \"../../internals/motion/in-view\";\nimport { useReducedMotion } from \"../../internals/motion/media-query\";\nimport {\n\tcreateMagneticFieldCore,\n\tcreateMagneticFieldHub,\n\tMAGNETIC_FIELD_DEFAULTS,\n\tresolveSpring,\n} from \"./magnetic-field-core\";\nimport type {\n\tMagneticFieldCore,\n\tMagneticFieldOptions,\n\tMagneticFieldSource,\n\tMagneticPoint,\n\tMagneticSpring,\n\tMagneticSpringPreset,\n} from \"./magnetic-field-core\";\nimport { attachLayoutInvalidation, attachPointerSource } from \"./magnetic-field-source\";\nimport { MAGNETIC_FIELD_KEY } from \"./types\";\nimport type { MagneticFieldContext } from \"./types\";\nimport \"./magnetic-field.css\";\n\nexport interface MagneticFieldOwnProps {\n\t/** Where the magnet comes from. `\"pointer\"` follows a mouse or pen anywhere within `radius` of an item (touch is ignored); `\"manual\"` reads `position` instead. A `MagnetPuck` placed inside the field drives it in either mode while it is held. */\n\tsource?: MagneticFieldSource;\n\t/** The magnet's position in px, relative to the field's padding box, used when `source` is `\"manual\"`. `null` means no magnet, and the items spring back to rest. */\n\tposition?: MagneticPoint | null;\n\t/** Falloff distance from the item's edge, in px: an item pulls hardest when the magnet touches or overlaps it, and not at all once the magnet is `radius` px beyond its nearest edge. */\n\tradius?: number;\n\t/** Global pull multiplier, applied on top of each item's own `strength`. `0` turns the effect off without detaching anything. */\n\tstrength?: number;\n\t/** Largest distance, in px, that any item travels toward the magnet. */\n\tmaxTranslate?: number;\n\t/** Largest lean, in degrees. Items lean toward the magnet's side like a crowd turning its head: clockwise when it is to their left, counter-clockwise when it is to their right. */\n\tmaxRotate?: number;\n\t/** How items move and settle: `\"soft\"`, `\"default\"` or `\"snappy\"`, or your own `{ stiffness, damping, mass }` (missing keys come from `\"default\"`). */\n\tspring?: MagneticSpringPreset | Partial<MagneticSpring>;\n\t/** `1` attracts and `-1` repels. Only translation flips; the lean stays the same. */\n\tpolarity?: 1 | -1;\n\t/** Detaches every listener and springs each item back to rest. */\n\tdisabled?: boolean;\n\t/** Called when the field wakes up (a magnet is engaged or an item is still settling) and when it goes back to sleep. */\n\tonActiveChange?: (active: boolean) => void;\n\t/** The content. Wrap each element that should react in a `MagneticItem`. */\n\tchildren?: ReactNode;\n\t/** Additional CSS classes. */\n\tclassName?: string;\n}\n\n/** Native `<div>` attributes and listeners are forwarded to the root. */\nexport interface MagneticFieldProps\n\textends\n\t\tMagneticFieldOwnProps,\n\t\tOmit<HTMLAttributes<HTMLDivElement>, keyof MagneticFieldOwnProps> {}\n\nexport const MagneticField = forwardRef<HTMLDivElement, MagneticFieldProps>(function MagneticField(\n\t{\n\t\tsource = \"pointer\",\n\t\tposition = null,\n\t\tradius = MAGNETIC_FIELD_DEFAULTS.radius,\n\t\tstrength = MAGNETIC_FIELD_DEFAULTS.strength,\n\t\tmaxTranslate = MAGNETIC_FIELD_DEFAULTS.maxTranslate,\n\t\tmaxRotate = MAGNETIC_FIELD_DEFAULTS.maxRotate,\n\t\tspring = \"default\",\n\t\tpolarity = 1,\n\t\tdisabled = false,\n\t\tonActiveChange,\n\t\tchildren,\n\t\tclassName,\n\t\t...rest\n\t},\n\tforwardedRef\n) {\n\tconst [node, nodeRef] = useElementRef<HTMLDivElement>();\n\tconst composedRef = useComposedRefs(forwardedRef, nodeRef);\n\n\t// One hub for the field's whole life: items and pucks register through it\n\t// whether or not the core exists yet (their effects run before this\n\t// component's), and it replays them into each core. Created once, so the\n\t// context value never changes and no item ever re-registers because the\n\t// field re-rendered; a development double-mount reuses the same buffer.\n\tconst [hub] = useState(createMagneticFieldHub);\n\tconst context: MagneticFieldContext = hub;\n\n\tconst reduced = useReducedMotion();\n\n\tconst [core, setCore] = useState<MagneticFieldCore | null>(null);\n\tconst [active, setActive] = useState(false);\n\n\tconst onActiveChangeRef = useLiveRef(onActiveChange);\n\tconst handleActive = useCallback(\n\t\t(next: boolean) => {\n\t\t\tsetActive(next);\n\t\t\tonActiveChangeRef.current?.(next);\n\t\t},\n\t\t[onActiveChangeRef]\n\t);\n\n\t// The spring is resolved to plain numbers so an inline `{ stiffness }`\n\t// literal, a new object every render, does not re-run the update effect.\n\tconst resolved = resolveSpring(spring);\n\tconst { stiffness, damping, mass } = resolved;\n\n\tconst options: Partial<MagneticFieldOptions> = {\n\t\tradius,\n\t\tstrength,\n\t\tmaxTranslate,\n\t\tmaxRotate,\n\t\tspring: resolved,\n\t\tpolarity,\n\t\treducedMotion: reduced,\n\t\tdisabled,\n\t\tonActiveChange: handleActive,\n\t};\n\tconst optionsRef = useLiveRef(options);\n\n\t// The core lives exactly as long as the root node.\n\tuseEffect(() => {\n\t\tif (!node) return;\n\t\tconst next = createMagneticFieldCore(node, optionsRef.current);\n\t\tsetCore(next);\n\t\thub.attach(next);\n\t\treturn () => {\n\t\t\thub.detach();\n\t\t\tnext.destroy();\n\t\t\tsetCore(null);\n\t\t\tsetActive(false);\n\t\t};\n\t}, [node, hub, optionsRef]);\n\n\t// Every prop change goes through one update; the core ignores no-ops.\n\tuseEffect(() => {\n\t\tcore?.update({\n\t\t\tradius,\n\t\t\tstrength,\n\t\t\tmaxTranslate,\n\t\t\tmaxRotate,\n\t\t\tspring: { stiffness, damping, mass },\n\t\t\tpolarity,\n\t\t\treducedMotion: reduced,\n\t\t\tdisabled,\n\t\t\tonActiveChange: handleActive,\n\t\t});\n\t}, [\n\t\tcore,\n\t\tradius,\n\t\tstrength,\n\t\tmaxTranslate,\n\t\tmaxRotate,\n\t\tstiffness,\n\t\tdamping,\n\t\tmass,\n\t\tpolarity,\n\t\treduced,\n\t\tdisabled,\n\t\thandleActive,\n\t]);\n\n\t// Listeners exist only while something can move: the field is enabled,\n\t// motion is allowed, and the field (inflated by `radius`) is on screen.\n\tconst onVisibleRef = useRef<((visible: boolean) => void) | null>(null);\n\tuseEffect(() => {\n\t\tif (!core || !node) return;\n\t\tconst c = core;\n\t\tconst usePointer = source === \"pointer\";\n\t\tif (disabled || reduced || !usePointer) c.clearSource(\"pointer\");\n\t\tif (disabled || reduced) return;\n\n\t\tlet detachPointer: (() => void) | null = null;\n\t\tlet detachLayout: (() => void) | null = null;\n\n\t\tonVisibleRef.current = (visible) => {\n\t\t\tif (visible) {\n\t\t\t\tdetachLayout ??= attachLayoutInvalidation(c);\n\t\t\t\tif (usePointer) detachPointer ??= attachPointerSource(c, node.ownerDocument, node);\n\t\t\t} else {\n\t\t\t\tdetachPointer?.();\n\t\t\t\tdetachPointer = null;\n\t\t\t\tdetachLayout?.();\n\t\t\t\tdetachLayout = null;\n\t\t\t\tc.clearSource(\"pointer\");\n\t\t\t}\n\t\t};\n\n\t\treturn () => {\n\t\t\tonVisibleRef.current = null;\n\t\t\tdetachPointer?.();\n\t\t\tdetachLayout?.();\n\t\t\tc.clearSource(\"pointer\");\n\t\t};\n\t}, [core, node, source, disabled, reduced]);\n\n\t// The in-view observer alone depends on `radius`: a new margin replaces it\n\t// without detaching the pointer, so a resting pointer keeps pulling. Keep\n\t// its deps a superset of the effect above: it reads the ref that one sets.\n\tuseEffect(() => {\n\t\tconst onVisible = onVisibleRef.current;\n\t\tif (!node || !onVisible) return;\n\t\tconst io = observeInView(node, {\n\t\t\tonce: false,\n\t\t\tthreshold: 0,\n\t\t\trootMargin: `${radius}px`,\n\t\t\tonChange: onVisible,\n\t\t});\n\t\treturn () => io.destroy();\n\t}, [core, node, source, disabled, reduced, radius]);\n\n\t// The controlled magnet. Written through the hub so it survives a core swap.\n\tconst manualX = source === \"manual\" && position ? position.x : null;\n\tconst manualY = source === \"manual\" && position ? position.y : null;\n\tuseEffect(() => {\n\t\thub.setSource(\n\t\t\tmanualX === null || manualY === null ? null : { x: manualX, y: manualY },\n\t\t\t\"manual\"\n\t\t);\n\t}, [hub, manualX, manualY]);\n\n\treturn (\n\t\t<MAGNETIC_FIELD_KEY.Provider value={context}>\n\t\t\t<div\n\t\t\t\tref={composedRef}\n\t\t\t\tclassName={cn(\"ft-magnetic-field\", className)}\n\t\t\t\t{...rest}\n\t\t\t\tdata-source={source}\n\t\t\t\tdata-active={active || undefined}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t</MAGNETIC_FIELD_KEY.Provider>\n\t);\n});\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/MagneticField.tsx"},{"path":"react/src/components/magnetic-field/MagneticItem.tsx","content":"\"use client\";\n\nimport { forwardRef, useContext, useEffect } from \"react\";\nimport type { HTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"../../utils\";\nimport { useComposedRefs } from \"../../internals/dom/use-composed-refs\";\nimport { useElementRef } from \"../../internals/dom/use-element-ref\";\nimport { useLiveRef } from \"../../internals/dom/use-live-ref\";\nimport { MAGNETIC_FIELD_KEY } from \"./types\";\nimport \"./magnetic-field.css\";\n\nexport interface MagneticItemOwnProps {\n\t/** How heavy the item is. Above 1 it moves and leans less and settles more slowly; below 1 it is livelier. */\n\tmass?: number;\n\t/** Per-item pull multiplier, applied on top of the field's `strength`. */\n\tstrength?: number;\n\t/** Whether the item moves toward the magnet. */\n\tpull?: boolean;\n\t/** Whether the item leans toward the magnet. */\n\trotate?: boolean;\n\t/** Renders `<span>` wrappers with `display: inline-block` instead of block `<div>`s, for items that sit inside a line of text or an inline row. */\n\tinline?: boolean;\n\t/** The element that reacts. */\n\tchildren?: ReactNode;\n\t/** Additional CSS classes, on the static outer wrapper. */\n\tclassName?: string;\n}\n\n/** Native attributes and listeners are forwarded to the static outer wrapper. */\nexport interface MagneticItemProps\n\textends MagneticItemOwnProps, Omit<HTMLAttributes<HTMLElement>, keyof MagneticItemOwnProps> {}\n\nexport const MagneticItem = forwardRef<HTMLElement, MagneticItemProps>(function MagneticItem(\n\t{\n\t\tmass = 1,\n\t\tstrength = 1,\n\t\tpull = true,\n\t\trotate = true,\n\t\tinline = false,\n\t\tchildren,\n\t\tclassName,\n\t\t...rest\n\t},\n\tforwardedRef\n) {\n\t// Undefined outside a MagneticField: the item then renders the same markup\n\t// and simply never moves.\n\tconst ctx = useContext(MAGNETIC_FIELD_KEY);\n\n\tconst [outer, outerRef] = useElementRef<HTMLElement>();\n\tconst [inner, innerRef] = useElementRef<HTMLElement>();\n\tconst composedOuterRef = useComposedRefs<HTMLElement>(forwardedRef, outerRef);\n\n\tconst optionsRef = useLiveRef({ mass, strength, pull, rotate });\n\n\tuseEffect(() => {\n\t\tif (!ctx || !outer || !inner) return;\n\t\treturn ctx.register(outer, inner, optionsRef.current);\n\t}, [ctx, outer, inner, optionsRef]);\n\n\tuseEffect(() => {\n\t\tif (ctx && outer) ctx.updateItem(outer, { mass, strength, pull, rotate });\n\t}, [ctx, outer, mass, strength, pull, rotate]);\n\n\tconst Tag = inline ? \"span\" : \"div\";\n\n\treturn (\n\t\t<Tag\n\t\t\tref={composedOuterRef}\n\t\t\tclassName={cn(\"ft-magnetic-item\", className)}\n\t\t\t{...rest}\n\t\t\tdata-inline={inline || undefined}\n\t\t>\n\t\t\t<Tag ref={innerRef} className=\"ft-magnetic-item-inner\">\n\t\t\t\t{children}\n\t\t\t</Tag>\n\t\t</Tag>\n\t);\n});\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/MagneticItem.tsx"},{"path":"react/src/components/magnetic-field/index.ts","content":"\"use client\";\n\nexport { MagneticField } from \"./MagneticField\";\nexport type { MagneticFieldProps } from \"./MagneticField\";\nexport { MagneticItem } from \"./MagneticItem\";\nexport type { MagneticItemProps } from \"./MagneticItem\";\nexport { MagnetPuck } from \"./MagnetPuck\";\nexport type { MagnetPuckProps } from \"./MagnetPuck\";\nexport { MAGNETIC_FIELD_SPRINGS } from \"./magnetic-field-core\";\nexport type {\n\tMagneticPoint,\n\tMagneticSpring,\n\tMagneticSpringPreset,\n\tMagneticFieldSource,\n} from \"./magnetic-field-core\";\nexport { MAGNETIC_FIELD_KEY } from \"./types\";\nexport type { MagneticFieldContext } from \"./types\";\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/index.ts"},{"path":"react/src/components/magnetic-field/magnetic-field-core.ts","content":"\"use client\";\n\n/**\n * MagneticField engine — framework-free, byte-identical in the Svelte, React\n * and Vue trees.\n *\n * Every `MagneticItem` is a static outer node (measured, never transformed)\n * around an inner node that reads three CSS custom properties:\n * `--ft-mf-x` / `--ft-mf-y` (px) and `--ft-mf-r` (deg). This core owns those\n * properties. It keeps one magnet point per input channel, works out a\n * target offset and lean for each item from its distance to the magnet, and\n * steps three springs per item (x, y, rotation) toward it in a single\n * `requestAnimationFrame` loop shared by the whole field. The loop sleeps as\n * soon as every spring is at rest, so a still field schedules nothing.\n *\n * Each frame reads first (the root rect and any stale item rects), then\n * computes targets, then steps, then writes, so no frame forces a reflow per\n * item. Geometry is in field-local px measured from the root's PADDING box,\n * the same box an absolutely positioned child of the root lives in (scrolled\n * content included, when the root itself scrolls).\n *\n * Nothing here touches a browser global at import time; `ResizeObserver`,\n * `requestAnimationFrame` and `performance` are only reached inside functions.\n */\n\nexport interface MagneticPoint {\n\tx: number;\n\ty: number;\n}\n\nexport interface MagneticSpring {\n\tstiffness: number;\n\tdamping: number;\n\tmass: number;\n}\n\nexport type MagneticSpringPreset = \"soft\" | \"default\" | \"snappy\";\n\n/** Where the field's own magnet comes from (a `MagnetPuck` can drive it in either mode). */\nexport type MagneticFieldSource = \"pointer\" | \"manual\";\n\n/** The input channels, in falling priority: puck, then manual, then pointer. */\nexport type MagneticSourceChannel = \"pointer\" | \"manual\" | \"puck\";\n\n/**\n * Spring presets. `default` is near-critical (no visible overshoot, settles in\n * about a third of a second); `soft` overshoots a little; `snappy` is quicker.\n */\nexport const MAGNETIC_FIELD_SPRINGS: Readonly<\n\tRecord<MagneticSpringPreset, Readonly<MagneticSpring>>\n> = Object.freeze({\n\tsoft: Object.freeze({ stiffness: 170, damping: 18, mass: 1 }),\n\tdefault: Object.freeze({ stiffness: 230, damping: 30, mass: 1 }),\n\tsnappy: Object.freeze({ stiffness: 320, damping: 36, mass: 1 }),\n});\n\nexport const MAGNETIC_FIELD_DEFAULTS = Object.freeze({\n\tradius: 220,\n\tstrength: 1,\n\tmaxTranslate: 24,\n\tmaxRotate: 6,\n\tpolarity: 1 as 1 | -1,\n});\n\nexport interface MagneticItemOptions {\n\t/** Heavier items move and lean less and settle more slowly. Clamped to [0.25, 10]. */\n\tmass: number;\n\t/** Per-item pull multiplier. */\n\tstrength: number;\n\t/** Whether the item moves toward the magnet. */\n\tpull: boolean;\n\t/** Whether the item leans toward the magnet. */\n\trotate: boolean;\n}\n\nexport interface MagneticFieldOptions {\n\tradius: number;\n\tstrength: number;\n\tmaxTranslate: number;\n\tmaxRotate: number;\n\tspring: MagneticSpring;\n\tpolarity: 1 | -1;\n\treducedMotion: boolean;\n\tdisabled: boolean;\n\tonActiveChange?: (active: boolean) => void;\n}\n\n/** Item rect in field-local px (relative to the root's PADDING box). */\nexport interface MagneticRect {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n}\n\nexport interface MagneticTarget {\n\t/** Translation in px. */\n\tx: number;\n\ty: number;\n\t/** Lean in degrees, positive = clockwise. */\n\tr: number;\n\t/** Translation falloff, 0..1. */\n\tf: number;\n}\n\nconst SUBSTEP = 1 / 240;\nconst MAX_DT = 1 / 30;\nconst FIRST_DT = 1 / 60;\nconst REST_POSITION = 0.01;\nconst MIN_ITEM_MASS = 0.25;\nconst MAX_ITEM_MASS = 10;\n/** Below this centre distance (or `maxTranslate`, if larger) the pull fades linearly to 0. */\nconst MIN_CORE = 16;\n/** Gain of the lean's horizontal-side curve. */\nconst LEAN_GAIN = 3;\n/** The lean reaches twice as far as the pull. */\nconst LEAN_REACH = 2;\n/**\n * Targets smaller than this (px for the pull, deg for the lean) cannot be\n * seen and snap to 0, so an item at the far edge of the lean's reach counts\n * as at rest instead of keeping the field engaged for a 0.02deg tilt.\n */\nconst MIN_VISIBLE = 0.05;\n\nconst DEFAULT_ITEM: Readonly<MagneticItemOptions> = Object.freeze({\n\tmass: 1,\n\tstrength: 1,\n\tpull: true,\n\trotate: true,\n});\n\nconst ZERO: Readonly<MagneticTarget> = Object.freeze({ x: 0, y: 0, r: 0, f: 0 });\n\nfunction clamp(v: number, lo: number, hi: number): number {\n\treturn v < lo ? lo : v > hi ? hi : v;\n}\n\nfunction finite(v: number, fallback: number): number {\n\treturn Number.isFinite(v) ? v : fallback;\n}\n\nfunction smoothstep(x: number): number {\n\tconst t = clamp(x, 0, 1);\n\treturn t * t * (3 - 2 * t);\n}\n\nfunction itemMass(mass: number): number {\n\treturn clamp(finite(mass, 1), MIN_ITEM_MASS, MAX_ITEM_MASS);\n}\n\n/** A preset name or a partial config, completed from `default`. */\nexport function resolveSpring(\n\tspring?: MagneticSpringPreset | Partial<MagneticSpring>\n): MagneticSpring {\n\tconst base = MAGNETIC_FIELD_SPRINGS.default;\n\tif (spring === undefined || spring === null) return { ...base };\n\tif (typeof spring === \"string\") return { ...(MAGNETIC_FIELD_SPRINGS[spring] ?? base) };\n\tconst stiffness = finite(spring.stiffness ?? base.stiffness, base.stiffness);\n\tconst damping = finite(spring.damping ?? base.damping, base.damping);\n\tconst mass = finite(spring.mass ?? base.mass, base.mass);\n\treturn {\n\t\tstiffness: Math.max(1e-3, stiffness),\n\t\tdamping: Math.max(0, damping),\n\t\tmass: Math.max(1e-3, mass),\n\t};\n}\n\n/**\n * The spring an item of `mass` actually runs: mass scales the inertia and\n * damping scales with its square root, so every item keeps the same damping\n * ratio and only its tempo changes. `rotation` doubles the stiffness (and\n * scales damping by √2) so the lean leads the pull, again at the same ratio.\n */\nexport function itemSpring(base: MagneticSpring, mass: number, rotation = false): MagneticSpring {\n\tconst m = itemMass(mass);\n\tconst k = rotation ? 2 : 1;\n\treturn {\n\t\tstiffness: base.stiffness * k,\n\t\tdamping: base.damping * Math.sqrt(m) * Math.sqrt(k),\n\t\tmass: base.mass * m,\n\t};\n}\n\n/** Distance from `p` to the nearest edge of `r`; 0 inside. */\nexport function rectDistance(p: MagneticPoint, r: MagneticRect): number {\n\tconst dx = Math.max(r.left - p.x, 0, p.x - (r.left + r.width));\n\tconst dy = Math.max(r.top - p.y, 0, p.y - (r.top + r.height));\n\treturn Math.hypot(dx, dy);\n}\n\n/** `smoothstep(1 - d / radius)`: 1 at or inside the edge, 0 at `radius` and beyond. */\nexport function falloff(d: number, radius: number): number {\n\treturn radius > 0 ? smoothstep(1 - d / radius) : 0;\n}\n\n/**\n * Where an item wants to be for a magnet at `p` (null: no magnet, rest).\n *\n * Pull: toward the magnet along the line from the item's centre, scaled by the\n * edge-distance falloff, the strengths and `1 / mass`, capped at\n * `maxTranslate`, and faded to 0 within `max(16, maxTranslate)` px of the\n * centre so the item never jumps past the magnet nor flips direction as the\n * magnet crosses its middle. `polarity` flips it.\n *\n * Lean: the item tilts toward the magnet's horizontal side, like a crowd\n * turning its head: clockwise when the magnet is to its left, counter-clockwise\n * to its right, whatever the height. It saturates quickly, so items lean\n * almost fully while barely moving, and its falloff reaches twice as far as the\n * pull's. `polarity` does not flip it.\n */\nexport function itemTarget(\n\tp: MagneticPoint | null,\n\tr: MagneticRect,\n\tfield: Pick<\n\t\tMagneticFieldOptions,\n\t\t\"radius\" | \"strength\" | \"maxTranslate\" | \"maxRotate\" | \"polarity\"\n\t>,\n\titem: MagneticItemOptions\n): MagneticTarget {\n\tif (!p) return { ...ZERO };\n\tconst d = rectDistance(p, r);\n\tconst f = falloff(d, field.radius);\n\tconst fr = falloff(d, field.radius * LEAN_REACH);\n\tif (fr <= 0) return { ...ZERO };\n\n\tconst m = itemMass(item.mass);\n\tconst gain = Math.max(0, finite(field.strength, 0) * finite(item.strength, 0)) / m;\n\tconst maxT = Math.max(0, finite(field.maxTranslate, 0));\n\tconst maxR = Math.max(0, finite(field.maxRotate, 0));\n\tconst cx = r.left + r.width / 2;\n\tconst cy = r.top + r.height / 2;\n\tconst dx = p.x - cx;\n\tconst dy = p.y - cy;\n\tconst len = Math.hypot(dx, dy);\n\n\tlet x = 0;\n\tlet y = 0;\n\tlet rot = 0;\n\tif (item.pull && len > 0 && f > 0) {\n\t\tconst core = Math.max(MIN_CORE, maxT);\n\t\tconst k = Math.min(maxT, maxT * gain * f) * Math.min(1, len / core);\n\t\tconst sign = field.polarity === -1 ? -1 : 1;\n\t\tx = (sign * k * dx) / len;\n\t\ty = (sign * k * dy) / len;\n\t}\n\tif (item.rotate && len > 0) {\n\t\tconst scale = Math.max(len, r.width / 2);\n\t\tconst side = Math.tanh((LEAN_GAIN * -dx) / scale);\n\t\trot = clamp(maxR * gain * side * fr, -maxR, maxR);\n\t}\n\tif (Math.hypot(x, y) < MIN_VISIBLE) {\n\t\tx = 0;\n\t\ty = 0;\n\t}\n\tif (Math.abs(rot) < MIN_VISIBLE) rot = 0;\n\t// Normalise -0 so the written strings never read \"-0.00\".\n\treturn { x: x || 0, y: y || 0, r: rot || 0, f };\n}\n\n/** One spring: position, velocity, target. */\nexport interface MagneticSpringState {\n\tx: number;\n\tv: number;\n\ttarget: number;\n}\n\n/**\n * Advances a spring by `dt` seconds (clamped to 1/30) in fixed 1/240 s\n * semi-implicit Euler substeps. Snaps to the target and returns false once\n * within `rest` with a speed under `rest * 10`; true while still moving.\n */\nexport function stepSpring(\n\ts: MagneticSpringState,\n\tcfg: MagneticSpring,\n\tdt: number,\n\trest: number\n): boolean {\n\tlet left = Math.min(Math.max(dt, 0), MAX_DT);\n\twhile (left > 1e-9) {\n\t\tconst h = Math.min(SUBSTEP, left);\n\t\tconst a = (-cfg.stiffness * (s.x - s.target) - cfg.damping * s.v) / cfg.mass;\n\t\ts.v += a * h;\n\t\ts.x += s.v * h;\n\t\tleft -= h;\n\t}\n\tif (Math.abs(s.x - s.target) < rest && Math.abs(s.v) < rest * 10) {\n\t\ts.x = s.target;\n\t\ts.v = 0;\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport interface MagneticFieldCore {\n\t/** Sets a channel's magnet in field-local px (`null` clears it). Channel defaults to `\"manual\"`. */\n\tsetSource(point: MagneticPoint | null, channel?: MagneticSourceChannel): void;\n\t/** Sets a channel's magnet in client px. Channel defaults to `\"pointer\"`. */\n\tsetClientSource(clientX: number, clientY: number, channel?: MagneticSourceChannel): void;\n\t/** Clears one channel, or every channel when called without one. */\n\tclearSource(channel?: MagneticSourceChannel): void;\n\t/** Starts driving an item. Returns its unregister function. */\n\tregister(outer: HTMLElement, inner: HTMLElement, opts?: Partial<MagneticItemOptions>): () => void;\n\tupdateItem(outer: HTMLElement, opts: Partial<MagneticItemOptions>): void;\n\tupdate(opts: Partial<MagneticFieldOptions>): void;\n\t/** Marks every cached rect stale (after a scroll or resize). */\n\tinvalidate(): void;\n\t/** Whether any item is pulled or still settling. */\n\treadonly active: boolean;\n\t/** Stops the loop and the observer and leaves every item at rest. */\n\tdestroy(): void;\n}\n\ninterface ChannelPoint {\n\tx: number;\n\ty: number;\n\tclient: boolean;\n}\n\ninterface Item {\n\touter: HTMLElement;\n\tinner: HTMLElement;\n\topts: MagneticItemOptions;\n\trect: MagneticRect | null;\n\trectDirty: boolean;\n\tsx: MagneticSpringState;\n\tsy: MagneticSpringState;\n\tsr: MagneticSpringState;\n\tcfg: MagneticSpring;\n\tcfgR: MagneticSpring;\n\t/** Last strings written, to skip unchanged style writes. */\n\twx: string;\n\twy: string;\n\twr: string;\n\t/** Whether the inner node currently carries `will-change: transform`. */\n\tpromoted: boolean;\n}\n\nconst CHANNELS: readonly MagneticSourceChannel[] = [\"puck\", \"manual\", \"pointer\"];\n\nfunction px(v: number): string {\n\treturn `${(v || 0).toFixed(2)}px`;\n}\n\nfunction deg(v: number): string {\n\treturn `${(v || 0).toFixed(2)}deg`;\n}\n\nfunction sameItemOptions(a: MagneticItemOptions, b: MagneticItemOptions): boolean {\n\treturn (\n\t\ta.mass === b.mass && a.strength === b.strength && a.pull === b.pull && a.rotate === b.rotate\n\t);\n}\n\nfunction normaliseItem(opts?: Partial<MagneticItemOptions>): MagneticItemOptions {\n\treturn {\n\t\tmass: opts?.mass ?? DEFAULT_ITEM.mass,\n\t\tstrength: opts?.strength ?? DEFAULT_ITEM.strength,\n\t\tpull: opts?.pull ?? DEFAULT_ITEM.pull,\n\t\trotate: opts?.rotate ?? DEFAULT_ITEM.rotate,\n\t};\n}\n\nexport function createMagneticFieldCore(\n\troot: HTMLElement,\n\tinitial?: Partial<MagneticFieldOptions>\n): MagneticFieldCore {\n\tconst options: MagneticFieldOptions = {\n\t\tradius: initial?.radius ?? MAGNETIC_FIELD_DEFAULTS.radius,\n\t\tstrength: initial?.strength ?? MAGNETIC_FIELD_DEFAULTS.strength,\n\t\tmaxTranslate: initial?.maxTranslate ?? MAGNETIC_FIELD_DEFAULTS.maxTranslate,\n\t\tmaxRotate: initial?.maxRotate ?? MAGNETIC_FIELD_DEFAULTS.maxRotate,\n\t\tspring: resolveSpring(initial?.spring),\n\t\tpolarity: initial?.polarity === -1 ? -1 : 1,\n\t\treducedMotion: initial?.reducedMotion ?? false,\n\t\tdisabled: initial?.disabled ?? false,\n\t\tonActiveChange: initial?.onActiveChange,\n\t};\n\n\tconst items = new Map<HTMLElement, Item>();\n\tconst channels: Record<MagneticSourceChannel, ChannelPoint | null> = {\n\t\tpuck: null,\n\t\tmanual: null,\n\t\tpointer: null,\n\t};\n\n\tlet originX = 0;\n\tlet originY = 0;\n\tlet rootDirty = true;\n\tlet targetsDirty = true;\n\tlet frame = 0;\n\tlet lastT = 0;\n\tlet active = false;\n\tlet destroyed = false;\n\n\tconst observer =\n\t\ttypeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(() => invalidate());\n\tobserver?.observe(root);\n\n\tfunction anyChannel(): boolean {\n\t\treturn channels.puck !== null || channels.manual !== null || channels.pointer !== null;\n\t}\n\n\t/** The magnet in field-local px: the first channel holding a point. */\n\tfunction magnet(): MagneticPoint | null {\n\t\tif (options.disabled) return null;\n\t\tfor (const name of CHANNELS) {\n\t\t\tconst c = channels[name];\n\t\t\tif (c) return c.client ? { x: c.x - originX, y: c.y - originY } : { x: c.x, y: c.y };\n\t\t}\n\t\treturn null;\n\t}\n\n\tfunction setActive(next: boolean): void {\n\t\tif (next === active) return;\n\t\tactive = next;\n\t\toptions.onActiveChange?.(next);\n\t}\n\n\tfunction write(item: Item): void {\n\t\tconst x = px(item.sx.x);\n\t\tconst y = px(item.sy.x);\n\t\tconst r = deg(item.sr.x);\n\t\tconst style = item.inner.style;\n\t\tif (x !== item.wx) style.setProperty(\"--ft-mf-x\", (item.wx = x));\n\t\tif (y !== item.wy) style.setProperty(\"--ft-mf-y\", (item.wy = y));\n\t\tif (r !== item.wr) style.setProperty(\"--ft-mf-r\", (item.wr = r));\n\t}\n\n\t/**\n\t * `will-change` follows the springs, not the targets: an item held still\n\t * by a resting pointer or a sticky puck gives its compositor layer back\n\t * once it has settled, and gets it again on the next move.\n\t */\n\tfunction setPromoted(item: Item, promoted: boolean): void {\n\t\tif (promoted === item.promoted) return;\n\t\titem.promoted = promoted;\n\t\titem.inner.style.willChange = promoted ? \"transform\" : \"\";\n\t}\n\n\tfunction resetItem(item: Item): void {\n\t\tfor (const s of [item.sx, item.sy, item.sr]) {\n\t\t\ts.x = 0;\n\t\t\ts.v = 0;\n\t\t\ts.target = 0;\n\t\t}\n\t\twrite(item);\n\t\tsetPromoted(item, false);\n\t}\n\n\tfunction snapAll(): void {\n\t\tcancel();\n\t\tfor (const item of items.values()) resetItem(item);\n\t\ttargetsDirty = true;\n\t\tsetActive(false);\n\t}\n\n\tfunction cancel(): void {\n\t\tif (frame) cancelAnimationFrame(frame);\n\t\tframe = 0;\n\t\tlastT = 0;\n\t}\n\n\tfunction kick(): void {\n\t\tif (destroyed) return;\n\t\tif (options.reducedMotion) {\n\t\t\tsnapAll();\n\t\t\treturn;\n\t\t}\n\t\tif (!frame && typeof requestAnimationFrame === \"function\") {\n\t\t\tframe = requestAnimationFrame(step);\n\t\t}\n\t}\n\n\tfunction measure(): void {\n\t\tif (rootDirty) {\n\t\t\tconst r = root.getBoundingClientRect();\n\t\t\t// The scroll offsets keep a scrolling root's local space fixed to its\n\t\t\t// content, where its absolutely positioned children (a puck) live.\n\t\t\toriginX = r.left + (root.clientLeft || 0) - (root.scrollLeft || 0);\n\t\t\toriginY = r.top + (root.clientTop || 0) - (root.scrollTop || 0);\n\t\t\trootDirty = false;\n\t\t}\n\t\tfor (const item of items.values()) {\n\t\t\tif (!item.rectDirty) continue;\n\t\t\tconst r = item.outer.getBoundingClientRect();\n\t\t\titem.rect = {\n\t\t\t\tleft: r.left - originX,\n\t\t\t\ttop: r.top - originY,\n\t\t\t\twidth: r.width,\n\t\t\t\theight: r.height,\n\t\t\t};\n\t\t\titem.rectDirty = false;\n\t\t}\n\t}\n\n\tfunction retarget(): void {\n\t\tconst p = magnet();\n\t\tfor (const item of items.values()) {\n\t\t\tconst t = item.rect && p ? itemTarget(p, item.rect, options, item.opts) : ZERO;\n\t\t\titem.sx.target = t.x;\n\t\t\titem.sy.target = t.y;\n\t\t\titem.sr.target = t.r;\n\t\t}\n\t\ttargetsDirty = false;\n\t}\n\n\tfunction step(): void {\n\t\tframe = 0;\n\t\tif (destroyed) return;\n\t\tconst t = performance.now();\n\t\tconst dt = lastT ? Math.min(MAX_DT, (t - lastT) / 1000) : FIRST_DT;\n\t\t// A wake re-reads every rect once: a ResizeObserver misses position-only\n\t\t// moves (a reorder, a grid change), and an idle field hears of no layout.\n\t\tif (!lastT) markStale();\n\t\tlastT = t;\n\n\t\t// Read phase: every layout read happens before any write below.\n\t\tmeasure();\n\t\tif (targetsDirty) retarget();\n\n\t\tlet moving = false;\n\t\tlet anyEngaged = false;\n\t\tfor (const item of items.values()) {\n\t\t\tlet itemMoving = false;\n\t\t\tif (stepSpring(item.sx, item.cfg, dt, REST_POSITION)) itemMoving = true;\n\t\t\tif (stepSpring(item.sy, item.cfg, dt, REST_POSITION)) itemMoving = true;\n\t\t\tif (stepSpring(item.sr, item.cfgR, dt, REST_POSITION)) itemMoving = true;\n\t\t\twrite(item);\n\t\t\tsetPromoted(item, itemMoving);\n\t\t\tconst engaged =\n\t\t\t\titemMoving || item.sx.target !== 0 || item.sy.target !== 0 || item.sr.target !== 0;\n\t\t\tif (itemMoving) moving = true;\n\t\t\tif (engaged) anyEngaged = true;\n\t\t}\n\n\t\tif (moving || targetsDirty) frame = requestAnimationFrame(step);\n\t\telse lastT = 0;\n\t\tsetActive(anyEngaged);\n\t}\n\n\t/** Whether a higher-priority channel holds a point, so `channel` cannot steer. */\n\tfunction shadowed(channel: MagneticSourceChannel): boolean {\n\t\tfor (const name of CHANNELS) {\n\t\t\tif (name === channel) return false;\n\t\t\tif (channels[name] !== null) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tfunction setChannel(channel: MagneticSourceChannel, next: ChannelPoint | null): void {\n\t\tif (destroyed) return;\n\t\tconst prev = channels[channel];\n\t\tif (prev === next) return;\n\t\tif (prev && next && prev.x === next.x && prev.y === next.y && prev.client === next.client) {\n\t\t\treturn;\n\t\t}\n\t\tchannels[channel] = next;\n\t\t// Kept for when the higher channel lets go, but nothing to retarget now.\n\t\tif (shadowed(channel)) return;\n\t\ttargetsDirty = true;\n\t\t// A magnet moving about far from every item of a field at rest changes\n\t\t// no target: store it and skip the wake. The next wake retargets.\n\t\tif (!active && !frame && outOfReach(prev) && outOfReach(next)) return;\n\t\tkick();\n\t}\n\n\t/**\n\t * Whether a channel point is known to lie beyond the lean's reach of every\n\t * item (or is empty). False whenever a rect it depends on is stale.\n\t */\n\tfunction outOfReach(c: ChannelPoint | null): boolean {\n\t\tif (!c) return true;\n\t\tif (c.client && rootDirty) return false;\n\t\tconst p = c.client ? { x: c.x - originX, y: c.y - originY } : { x: c.x, y: c.y };\n\t\tconst reach = options.radius * LEAN_REACH;\n\t\tfor (const item of items.values()) {\n\t\t\tif (item.rectDirty || !item.rect) return false;\n\t\t\tif (rectDistance(p, item.rect) < reach) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tfunction markStale(): void {\n\t\trootDirty = true;\n\t\tfor (const item of items.values()) item.rectDirty = true;\n\t\ttargetsDirty = true;\n\t}\n\n\t/** Whether an item is pulled or still settling (springs read as they stand). */\n\tfunction engaged(item: Item): boolean {\n\t\tfor (const s of [item.sx, item.sy, item.sr]) {\n\t\t\tif (s.target !== 0 || s.x !== s.target || s.v !== 0) return true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tfunction invalidate(): void {\n\t\tif (destroyed) return;\n\t\tmarkStale();\n\t\t// Wake only when something can change: a magnet is set or an item is off rest.\n\t\tif (anyChannel() || active) kick();\n\t}\n\n\tfunction updateSprings(item: Item): void {\n\t\titem.cfg = itemSpring(options.spring, item.opts.mass);\n\t\titem.cfgR = itemSpring(options.spring, item.opts.mass, true);\n\t}\n\n\treturn {\n\t\tsetSource(point, channel = \"manual\") {\n\t\t\tsetChannel(\n\t\t\t\tchannel,\n\t\t\t\tpoint && Number.isFinite(point.x) && Number.isFinite(point.y)\n\t\t\t\t\t? { x: point.x, y: point.y, client: false }\n\t\t\t\t\t: null\n\t\t\t);\n\t\t},\n\t\tsetClientSource(clientX, clientY, channel = \"pointer\") {\n\t\t\tif (!Number.isFinite(clientX) || !Number.isFinite(clientY)) return;\n\t\t\tsetChannel(channel, { x: clientX, y: clientY, client: true });\n\t\t},\n\t\tclearSource(channel) {\n\t\t\tif (channel) {\n\t\t\t\tsetChannel(channel, null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const name of CHANNELS) setChannel(name, null);\n\t\t},\n\t\tregister(outer, inner, opts) {\n\t\t\tif (destroyed) return () => {};\n\t\t\tconst existing = items.get(outer);\n\t\t\tif (existing && existing.inner !== inner) resetItem(existing);\n\t\t\tconst item: Item = {\n\t\t\t\touter,\n\t\t\t\tinner,\n\t\t\t\topts: normaliseItem(opts),\n\t\t\t\trect: null,\n\t\t\t\trectDirty: true,\n\t\t\t\tsx: existing && existing.inner === inner ? existing.sx : { x: 0, v: 0, target: 0 },\n\t\t\t\tsy: existing && existing.inner === inner ? existing.sy : { x: 0, v: 0, target: 0 },\n\t\t\t\tsr: existing && existing.inner === inner ? existing.sr : { x: 0, v: 0, target: 0 },\n\t\t\t\tcfg: options.spring,\n\t\t\t\tcfgR: options.spring,\n\t\t\t\twx: \"\",\n\t\t\t\twy: \"\",\n\t\t\t\twr: \"\",\n\t\t\t\tpromoted: false,\n\t\t\t};\n\t\t\tupdateSprings(item);\n\t\t\titems.set(outer, item);\n\t\t\twrite(item);\n\t\t\tobserver?.observe(outer);\n\t\t\ttargetsDirty = true;\n\t\t\tif (anyChannel() || active) kick();\n\t\t\treturn () => {\n\t\t\t\tif (items.get(outer) !== item) return;\n\t\t\t\titems.delete(outer);\n\t\t\t\tobserver?.unobserve(outer);\n\t\t\t\tresetItem(item);\n\t\t\t\t// A running loop recounts on its next frame; an asleep one would\n\t\t\t\t// leave `active` stuck on the item that just left.\n\t\t\t\tif (!frame) setActive([...items.values()].some(engaged));\n\t\t\t};\n\t\t},\n\t\tupdateItem(outer, opts) {\n\t\t\tconst item = items.get(outer);\n\t\t\tif (!item || destroyed) return;\n\t\t\tconst next = normaliseItem({ ...item.opts, ...opts });\n\t\t\tif (sameItemOptions(item.opts, next)) return;\n\t\t\tconst massChanged = next.mass !== item.opts.mass;\n\t\t\titem.opts = next;\n\t\t\tif (massChanged) updateSprings(item);\n\t\t\ttargetsDirty = true;\n\t\t\tif (anyChannel() || active) kick();\n\t\t},\n\t\tupdate(opts) {\n\t\t\tif (destroyed) return;\n\t\t\tconst wasReduced = options.reducedMotion;\n\t\t\tlet changed = false;\n\t\t\tif (opts.radius !== undefined && opts.radius !== options.radius) {\n\t\t\t\toptions.radius = opts.radius;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t\tif (opts.strength !== undefined && opts.strength !== options.strength) {\n\t\t\t\toptions.strength = opts.strength;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t\tif (opts.maxTranslate !== undefined && opts.maxTranslate !== options.maxTranslate) {\n\t\t\t\toptions.maxTranslate = opts.maxTranslate;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t\tif (opts.maxRotate !== undefined && opts.maxRotate !== options.maxRotate) {\n\t\t\t\toptions.maxRotate = opts.maxRotate;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t\tif (opts.polarity !== undefined) {\n\t\t\t\tconst polarity = opts.polarity === -1 ? -1 : 1;\n\t\t\t\tif (polarity !== options.polarity) {\n\t\t\t\t\toptions.polarity = polarity;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (opts.disabled !== undefined && opts.disabled !== options.disabled) {\n\t\t\t\toptions.disabled = opts.disabled;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t\tif (opts.reducedMotion !== undefined && opts.reducedMotion !== options.reducedMotion) {\n\t\t\t\toptions.reducedMotion = opts.reducedMotion;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t\tif (opts.spring !== undefined) {\n\t\t\t\tconst spring = resolveSpring(opts.spring);\n\t\t\t\tconst s = options.spring;\n\t\t\t\tif (\n\t\t\t\t\tspring.stiffness !== s.stiffness ||\n\t\t\t\t\tspring.damping !== s.damping ||\n\t\t\t\t\tspring.mass !== s.mass\n\t\t\t\t) {\n\t\t\t\t\t// Position and velocity carry over: only the tempo changes.\n\t\t\t\t\toptions.spring = spring;\n\t\t\t\t\tfor (const item of items.values()) updateSprings(item);\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\"onActiveChange\" in opts) options.onActiveChange = opts.onActiveChange;\n\t\t\tif (!changed) return;\n\t\t\ttargetsDirty = true;\n\t\t\tif (options.reducedMotion) {\n\t\t\t\tif (!wasReduced || active) snapAll();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (anyChannel() || active) kick();\n\t\t},\n\t\tinvalidate,\n\t\tget active() {\n\t\t\treturn active;\n\t\t},\n\t\tdestroy() {\n\t\t\tif (destroyed) return;\n\t\t\tcancel();\n\t\t\tobserver?.disconnect();\n\t\t\tfor (const item of items.values()) resetItem(item);\n\t\t\titems.clear();\n\t\t\tfor (const name of CHANNELS) channels[name] = null;\n\t\t\tactive = false;\n\t\t\tdestroyed = true;\n\t\t},\n\t};\n}\n\n/**\n * The context value a field hands its items and pucks: a registration buffer\n * that outlives the core. Items and pucks may mount before the field's core\n * exists (child effects run first in every framework) and may outlive it (a\n * strict-mode remount destroys and recreates the core); the hub replays every\n * registered item and the last point of each channel into whichever core is\n * attached.\n */\nexport interface MagneticFieldHub {\n\tregister(outer: HTMLElement, inner: HTMLElement, opts?: Partial<MagneticItemOptions>): () => void;\n\tupdateItem(outer: HTMLElement, opts: Partial<MagneticItemOptions>): void;\n\tsetSource(point: MagneticPoint | null, channel: MagneticSourceChannel): void;\n\t/** Hands the buffer to `core`: replays every item and the last point of each channel. */\n\tattach(core: MagneticFieldCore): void;\n\t/** Forgets the core (about to be destroyed). The buffer is kept. */\n\tdetach(): void;\n}\n\ninterface HubEntry {\n\tinner: HTMLElement;\n\topts: Partial<MagneticItemOptions>;\n\tunregister: (() => void) | null;\n}\n\nexport function createMagneticFieldHub(): MagneticFieldHub {\n\tconst entries = new Map<HTMLElement, HubEntry>();\n\tconst sources: Record<MagneticSourceChannel, MagneticPoint | null> = {\n\t\tpuck: null,\n\t\tmanual: null,\n\t\tpointer: null,\n\t};\n\tlet core: MagneticFieldCore | null = null;\n\n\tfunction detach(): void {\n\t\tfor (const entry of entries.values()) {\n\t\t\tentry.unregister?.();\n\t\t\tentry.unregister = null;\n\t\t}\n\t\tcore = null;\n\t}\n\n\treturn {\n\t\tregister(outer, inner, opts) {\n\t\t\tentries.get(outer)?.unregister?.();\n\t\t\tconst entry: HubEntry = { inner, opts: { ...opts }, unregister: null };\n\t\t\tentries.set(outer, entry);\n\t\t\tif (core) entry.unregister = core.register(outer, inner, entry.opts);\n\t\t\treturn () => {\n\t\t\t\tif (entries.get(outer) !== entry) return;\n\t\t\t\tentries.delete(outer);\n\t\t\t\tentry.unregister?.();\n\t\t\t\tentry.unregister = null;\n\t\t\t};\n\t\t},\n\t\tupdateItem(outer, opts) {\n\t\t\tconst entry = entries.get(outer);\n\t\t\tif (!entry) return;\n\t\t\tentry.opts = { ...entry.opts, ...opts };\n\t\t\tcore?.updateItem(outer, opts);\n\t\t},\n\t\tsetSource(point, channel) {\n\t\t\tsources[channel] = point ? { x: point.x, y: point.y } : null;\n\t\t\tcore?.setSource(sources[channel], channel);\n\t\t},\n\t\tattach(next) {\n\t\t\tif (core) detach();\n\t\t\tcore = next;\n\t\t\tfor (const [outer, entry] of entries) {\n\t\t\t\tentry.unregister = next.register(outer, entry.inner, entry.opts);\n\t\t\t}\n\t\t\tfor (const name of CHANNELS) {\n\t\t\t\tconst p = sources[name];\n\t\t\t\tif (p) next.setSource(p, name);\n\t\t\t}\n\t\t},\n\t\tdetach,\n\t};\n}\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/magnetic-field-core.ts"},{"path":"react/src/components/magnetic-field/magnetic-field-source.ts","content":"\"use client\";\n\n/**\n * MagneticField input adapters — framework-free, byte-identical in the Svelte,\n * React and Vue trees (listed explicitly in shared-cores.json).\n *\n * The core (`magnetic-field-core.ts`) never listens to anything: it is fed a\n * magnet position per channel and told when the layout may have moved. This\n * module owns the two listener sets that do the feeding:\n *\n * - `attachPointerSource` turns a mouse or pen anywhere on the page into the\n *   `\"pointer\"` channel. It listens on the DOCUMENT, not the field root: the\n *   pull reaches `radius` px beyond every item, so most of the approach\n *   happens outside the root's box. The component gates the attachment with an\n *   in-view observer whose margin is that radius, so an off-screen field costs\n *   nothing.\n * - `attachLayoutInvalidation` tells the core that rects may be stale after a\n *   scroll (of the page or of any scrolling ancestor) or a window resize.\n *\n * Handlers never compute anything: they store the latest client position in\n * the core, which coalesces to at most one target pass per frame.\n *\n * Both functions return their own teardown and are safe to call during SSR\n * (they attach nothing and return a no-op). No browser global is touched at\n * import time.\n */\n\nimport type { MagneticFieldCore } from \"./magnetic-field-core\";\n\nconst NOOP = () => {};\n\n/** The root class every stack's `MagnetPuck` renders. */\nconst PUCK_SELECTOR = \".ft-magnet-puck\";\n\n/**\n * Feeds the core's `\"pointer\"` channel from a mouse or pen moving anywhere on\n * `target` (the current document by default).\n *\n * - Touch is ignored: a finger has no hover, and a tap would yank the items\n *   toward it for one frame and drop them. Touch users drive the field with a\n *   `MagnetPuck` instead.\n * - Only the primary pointer counts, so a second pen or mouse cannot fight the\n *   first.\n * - A pointer over a `MagnetPuck` (hovering it, or dragging it with pointer\n *   capture) clears the channel instead of feeding it: the puck is the magnet\n *   there. Otherwise, letting go of a puck would release nothing, since the\n *   cursor resting on it would take over at the very same point. The channel\n *   comes back as soon as the pointer moves off the puck. With a `root`, only\n *   a puck inside it counts: another field's puck is that field's magnet.\n * - The channel is cleared when the pointer leaves the page (to the browser\n *   chrome, another window, or a pen lifted out of hover range), when the\n *   window loses focus (a keyboard tab switch moves no pointer), and when the\n *   page is hidden. Without these, the last pull would freeze on screen until\n *   the pointer came back.\n */\nexport function attachPointerSource(\n\tcore: Pick<MagneticFieldCore, \"setClientSource\" | \"clearSource\">,\n\ttarget?: Document,\n\troot?: Element\n): () => void {\n\tconst doc = target ?? (typeof document === \"undefined\" ? undefined : document);\n\tif (!doc) return NOOP;\n\tconst win = doc.defaultView;\n\n\tconst clear = () => core.clearSource(\"pointer\");\n\n\tconst onMove = (event: PointerEvent) => {\n\t\tif (event.pointerType === \"touch\" || !event.isPrimary) return;\n\t\tconst target = event.target as Element | null;\n\t\tconst puck = typeof target?.closest === \"function\" ? target.closest(PUCK_SELECTOR) : null;\n\t\tif (puck && (!root || root.contains(puck))) {\n\t\t\tclear();\n\t\t\treturn;\n\t\t}\n\t\tcore.setClientSource(event.clientX, event.clientY, \"pointer\");\n\t};\n\n\t// `pointerout` bubbles, and its `relatedTarget` is null exactly when the\n\t// pointer left the document (or a pen left hover range), which makes it the\n\t// dependable \"left the page\" signal. `pointerleave` on the document is kept\n\t// as well: some engines fire it there and not the former in edge cases.\n\tconst onOut = (event: PointerEvent) => {\n\t\tif (event.pointerType === \"touch\" || !event.isPrimary) return;\n\t\tif (event.relatedTarget === null) clear();\n\t};\n\n\tconst onLeave = (event: PointerEvent) => {\n\t\tif (event.pointerType === \"touch\" || !event.isPrimary) return;\n\t\tclear();\n\t};\n\n\tconst onVisibility = () => {\n\t\tif (doc.visibilityState === \"hidden\") clear();\n\t};\n\n\tdoc.addEventListener(\"pointermove\", onMove, { passive: true });\n\tdoc.addEventListener(\"pointerout\", onOut, { passive: true });\n\tdoc.addEventListener(\"pointerleave\", onLeave, { passive: true });\n\tdoc.addEventListener(\"visibilitychange\", onVisibility);\n\twin?.addEventListener(\"blur\", clear);\n\n\treturn () => {\n\t\tdoc.removeEventListener(\"pointermove\", onMove);\n\t\tdoc.removeEventListener(\"pointerout\", onOut);\n\t\tdoc.removeEventListener(\"pointerleave\", onLeave);\n\t\tdoc.removeEventListener(\"visibilitychange\", onVisibility);\n\t\twin?.removeEventListener(\"blur\", clear);\n\t\tclear();\n\t};\n}\n\n/**\n * Calls `core.invalidate()` whenever the field may have moved on screen\n * without resizing: a scroll of the page or of any scrolling ancestor\n * (captured on the window, since `scroll` does not bubble), or a window\n * resize. Size changes of the root and the items themselves are the core's\n * own `ResizeObserver`'s job.\n *\n * `invalidate()` only marks the cached rects dirty and wakes the loop when\n * something is engaged, so a fast scroll costs one rect read per frame at most.\n */\nexport function attachLayoutInvalidation(core: Pick<MagneticFieldCore, \"invalidate\">): () => void {\n\tif (typeof window === \"undefined\") return NOOP;\n\tconst win = window;\n\tconst onChange = () => core.invalidate();\n\n\twin.addEventListener(\"scroll\", onChange, { capture: true, passive: true });\n\twin.addEventListener(\"resize\", onChange, { passive: true });\n\n\treturn () => {\n\t\twin.removeEventListener(\"scroll\", onChange, { capture: true });\n\t\twin.removeEventListener(\"resize\", onChange);\n\t};\n}\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/magnetic-field-source.ts"},{"path":"react/src/components/magnetic-field/magnetic-field.css","content":"/* MagneticField — copied from the three Svelte `<style>` blocks\n   (MagneticField.svelte, MagneticItem.svelte, MagnetPuck.svelte). Every rule\n   is anchored on one of the component's own root classes. */\n\n.ft-magnetic-field {\n\tposition: relative;\n}\n\n/* The outer node is never transformed: it is the box the field measures. */\n.ft-magnetic-item {\n\tposition: relative;\n\tdisplay: block;\n}\n\n.ft-magnetic-item[data-inline] {\n\tdisplay: inline-block;\n}\n\n/* Registered as non-inherited: a write on an inner then restyles that node\n   alone, not its whole subtree. The values the core writes (\"3.21px\",\n   \"1.20deg\") match these syntaxes. */\n@property --ft-mf-x {\n\tsyntax: \"<length>\";\n\tinherits: false;\n\tinitial-value: 0px;\n}\n\n@property --ft-mf-y {\n\tsyntax: \"<length>\";\n\tinherits: false;\n\tinitial-value: 0px;\n}\n\n@property --ft-mf-r {\n\tsyntax: \"<angle>\";\n\tinherits: false;\n\tinitial-value: 0deg;\n}\n\n/* The core writes the three variables; the fallbacks keep SSR markup at rest.\n   A 2D transform keeps a resting item off the compositor: the core promotes\n   an item with `will-change` only while it moves. */\n.ft-magnetic-item-inner {\n\tdisplay: block;\n\ttransform: translate(var(--ft-mf-x, 0px), var(--ft-mf-y, 0px)) rotate(var(--ft-mf-r, 0deg));\n\ttransform-origin: 50% 50%;\n}\n\n.ft-magnetic-item[data-inline] > .ft-magnetic-item-inner {\n\tdisplay: inline-block;\n}\n\n.ft-magnet-puck {\n\tposition: absolute;\n\tleft: 0;\n\ttop: 0;\n\tz-index: 1;\n\tdisplay: grid;\n\tplace-items: center;\n\tborder-radius: 9999px;\n\ttouch-action: none;\n\tuser-select: none;\n\t-webkit-user-select: none;\n\t-webkit-tap-highlight-color: transparent;\n\tcursor: grab;\n}\n\n.ft-magnet-puck[data-held] {\n\tcursor: grabbing;\n}\n\n.ft-magnet-puck:focus {\n\toutline: none;\n}\n\n.ft-magnet-puck:focus-visible {\n\toutline: 2px solid\n\t\tvar(--ft-accent, light-dark(oklch(0.5432 0.2528 300.22), oklch(0.604 0.2606 301.75)));\n\toutline-offset: 3px;\n}\n\n/* A matte black disc: a soft top-left sheen, an inner rim and a cast shadow\n   that deepens when it is lifted. Readable on light and dark surfaces: the rim\n   and the sheen brighten under a dark color scheme. */\n.ft-magnet-puck .ft-magnet-puck-face {\n\twidth: 100%;\n\theight: 100%;\n\tborder-radius: inherit;\n\tbackground: radial-gradient(\n\t\tcircle at 34% 28%,\n\t\tlight-dark(#3b3b3d, #4a4a4d) 0%,\n\t\t#161617 46%,\n\t\t#050505 100%\n\t);\n\tbox-shadow:\n\t\tinset 0 1px 1px rgb(255 255 255 / 0.16),\n\t\tinset 0 -3px 6px rgb(0 0 0 / 0.55),\n\t\t0 0 0 1px light-dark(rgb(255 255 255 / 0.07), rgb(255 255 255 / 0.16)),\n\t\t0 6px 14px -6px rgb(0 0 0 / 0.55);\n\ttransition:\n\t\tscale 160ms ease-out,\n\t\tbox-shadow 160ms ease-out;\n}\n\n.ft-magnet-puck[data-held] .ft-magnet-puck-face {\n\tscale: 1.06;\n\tbox-shadow:\n\t\tinset 0 1px 1px rgb(255 255 255 / 0.18),\n\t\tinset 0 -3px 6px rgb(0 0 0 / 0.55),\n\t\t0 0 0 1px light-dark(rgb(255 255 255 / 0.08), rgb(255 255 255 / 0.2)),\n\t\t0 14px 24px -8px rgb(0 0 0 / 0.6);\n}\n\n/* The keyboard hint the puck is described by: read, never seen. */\n.ft-magnet-puck .ft-magnet-puck-hint {\n\tposition: absolute;\n\twidth: 1px;\n\theight: 1px;\n\tmargin: -1px;\n\tpadding: 0;\n\toverflow: hidden;\n\tclip-path: inset(50%);\n\twhite-space: nowrap;\n\tborder: 0;\n}\n\n@media (prefers-reduced-motion: reduce) {\n\t.ft-magnet-puck .ft-magnet-puck-face {\n\t\ttransition: none;\n\t}\n}\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/magnetic-field.css"},{"path":"react/src/components/magnetic-field/types.ts","content":"\"use client\";\n\nimport { createContext } from \"react\";\nimport type { MagneticFieldHub } from \"./magnetic-field-core\";\n\n/**\n * The contract between a `MagneticField` and the `MagneticItem`s and\n * `MagnetPuck`s inside it.\n *\n * The context value is the field's registration hub (see\n * `createMagneticFieldHub` in `magnetic-field-core.ts`): a stable object,\n * created once per field, that buffers registrations until the field's core\n * exists and replays them into it. Children only ever see these three methods.\n */\nexport type MagneticFieldContext = Pick<MagneticFieldHub, \"register\" | \"updateItem\" | \"setSource\">;\n\n/**\n * React's context object plays the role of the Svelte source's `Symbol` key,\n * so the exported name is kept and the value is a `React.Context`. Read it as\n * optional: an item or a puck rendered outside a field gets `undefined`.\n */\nexport const MAGNETIC_FIELD_KEY = createContext<MagneticFieldContext | undefined>(undefined);\nMAGNETIC_FIELD_KEY.displayName = \"MagneticFieldContext\";\n","type":"registry:ui","target":"@ui/fancy/components/magnetic-field/types.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/magnetic-field?framework=react"}}