{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "island-toast",
  "title": "Island Toast",
  "description": "Dynamic-island toast stack: pills that open, fold behind each other and swipe away.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "@ikas/animated-check",
    "@ikas/button",
    "@ikas/motion",
    "@ikas/spinner",
    "@ikas/status",
    "@ikas/theme",
    "@ikas/utils"
  ],
  "files": [
    {
      "path": "registry/ui/island-toast.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  useDragControls,\n  useMotionValue,\n  useReducedMotion,\n  useTransform,\n  type PanInfo,\n  type Transition,\n} from \"motion/react\"\nimport { AlertTriangleIcon, InfoIcon, OctagonAlertIcon, XIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { statusTint } from \"@/lib/status\"\nimport { EASE_OUT, FADE_IN, FADE_OUT, INSTANT, ISLAND_SPRING, SPRING_EXIT } from \"@/lib/motion\"\nimport { buttonVariants } from \"@/components/ui/button\"\nimport { Spinner } from \"@/components/ui/spinner\"\nimport { AnimatedCheckIcon } from \"@/components/ikas/animated-check\"\n\ntype IslandType = \"default\" | \"success\" | \"info\" | \"warning\" | \"error\" | \"loading\"\n\ntype IslandPosition = \"top-left\" | \"top-center\" | \"top-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\"\n\ntype IslandOptions = {\n  /** Sending the same id again updates that toast in place, wherever it sits in the stack. */\n  id?: string | number\n  /** Second line, shown when the toast opens. */\n  description?: React.ReactNode\n  /** One action button. The toast closes after it runs. */\n  action?: { label: string; onClick: () => void }\n  /** Milliseconds before the toast leaves. Defaults to the Toaster's duration. `Infinity` keeps it. */\n  duration?: number\n  /** Sends the toast to the IslandToaster with the same `id`. */\n  toasterId?: string\n  /** Runs when the toast leaves, by timer, swipe, close button or `island.dismiss`. */\n  onDismiss?: () => void\n}\n\ntype IslandToast = IslandOptions & { id: string | number; type: IslandType; title: React.ReactNode }\n\n/* ---------- Store: island() works from anywhere, like toast() ---------- */\n\nlet store: IslandToast[] = []\nconst EMPTY: IslandToast[] = []\nconst listeners = new Set<() => void>()\nlet counter = 0\n\nconst emit = () => listeners.forEach((listener) => listener())\nconst subscribe = (listener: () => void) => {\n  listeners.add(listener)\n  return () => listeners.delete(listener)\n}\n\n/** Mounted IslandToasters per `id`. A toast with no toaster to show it is dropped after a grace period. */\nconst mounted = new Map<string | undefined, number>()\n/** Long enough for a toaster that mounts in the same render pass, or right after, to pick the toast up. */\nconst ORPHAN_GRACE = 1000\n\nfunction sweep() {\n  const next = store.filter((t) => mounted.get(t.toasterId))\n  if (next.length === store.length) return\n  store = next\n  emit()\n}\n\nfunction upsert(type: IslandType, title: React.ReactNode, options: IslandOptions = {}) {\n  const id = options.id ?? `island-${++counter}`\n  const next: IslandToast = { ...options, id, type, title }\n  store = store.some((t) => t.id === id) ? store.map((t) => (t.id === id ? next : t)) : [...store, next]\n  emit()\n  if (!mounted.get(options.toasterId)) window.setTimeout(sweep, ORPHAN_GRACE)\n  return id\n}\n\nfunction dismiss(id?: string | number) {\n  const gone = id == null ? store : store.filter((t) => t.id === id)\n  store = id == null ? [] : store.filter((t) => t.id !== id)\n  gone.forEach((t) => t.onDismiss?.())\n  emit()\n}\n\ntype PromiseMessages<T> = {\n  loading: React.ReactNode\n  success: React.ReactNode | ((data: T) => React.ReactNode)\n  error: React.ReactNode | ((error: unknown) => React.ReactNode)\n}\n\n/**\n * island(\"Kural silindi\", { description, action }) shows a toast and returns its id.\n * island.success / info / warning / error / loading set the status; island.promise\n * shows loading and resolves the same toast to success or error. It returns the promise\n * it was given: awaiting it gives the data or throws, and ignoring it leaves no unhandled\n * rejection, since the toast already handles both outcomes.\n */\nconst island = Object.assign((title: React.ReactNode, options?: IslandOptions) => upsert(\"default\", title, options), {\n  success: (title: React.ReactNode, options?: IslandOptions) => upsert(\"success\", title, options),\n  info: (title: React.ReactNode, options?: IslandOptions) => upsert(\"info\", title, options),\n  warning: (title: React.ReactNode, options?: IslandOptions) => upsert(\"warning\", title, options),\n  error: (title: React.ReactNode, options?: IslandOptions) => upsert(\"error\", title, options),\n  loading: (title: React.ReactNode, options?: IslandOptions) => upsert(\"loading\", title, options),\n  promise<T>(promise: Promise<T> | (() => Promise<T>), messages: PromiseMessages<T>, options?: IslandOptions) {\n    const id = upsert(\"loading\", messages.loading, options)\n    const p = typeof promise === \"function\" ? promise() : promise\n    p.then(\n      (data) => upsert(\"success\", typeof messages.success === \"function\" ? messages.success(data) : messages.success, { ...options, id }),\n      (error) => upsert(\"error\", typeof messages.error === \"function\" ? messages.error(error) : messages.error, { ...options, id })\n    )\n    return p\n  },\n  dismiss,\n})\n\n/* ---------- Toaster ---------- */\n\nconst PILL_H = 36\nconst OPEN_W = 332\nconst PEEK = 8\nconst GAP = 8\n/** Swipe toward the edge: this far, or a flick of 0.11 px/ms (motion reports px/s). */\nconst SWIPE_DISTANCE = 40\nconst SWIPE_VELOCITY = 110\n/** How far a swipe goes before the toast has faded to its floor. */\nconst SWIPE_FADE = 80\nconst RADIUS = 18\n\ntype Morph = keyof typeof ISLAND_SPRING\n\nconst tint: Record<IslandType, string> = {\n  default: statusTint.neutral,\n  loading: statusTint.neutral,\n  success: statusTint.success,\n  info: statusTint.info,\n  warning: statusTint.warning,\n  error: statusTint.danger,\n}\n\nfunction StatusIcon({ type }: { type: IslandType }) {\n  if (type === \"success\")\n    return (\n      <span className=\"flex size-4 items-center justify-center rounded-full bg-(--s-icon) text-(--s-fg)\">\n        <AnimatedCheckIcon className=\"size-2.5\" strokeWidth={3.5} />\n      </span>\n    )\n  if (type === \"loading\") return <Spinner className=\"size-4 text-icon\" />\n  const Icon = type === \"info\" ? InfoIcon : type === \"warning\" ? AlertTriangleIcon : type === \"error\" ? OctagonAlertIcon : null\n  return Icon ? <Icon className=\"size-4 text-(--s-icon)\" /> : null\n}\n\ntype Layout = { w: number; h: number; y: number; scale: number; opacity: number; wide: boolean; content: boolean; body: boolean }\n\ntype ItemProps = {\n  toast: IslandToast\n  layout: Layout\n  /** Which ISLAND_SPRING carries this render's size change. */\n  morph: Morph\n  tone: NonNullable<IslandToasterProps[\"tone\"]>\n  edge: 1 | -1\n  justify: string\n  openW: number\n  front: boolean\n  swipeable: boolean\n  z: number\n  reduce: boolean\n  onMeasure: (id: string | number, w: number, h: number) => void\n  onClose: (id: string | number) => void\n  onDragChange: (dragging: boolean) => void\n}\n\n/** Content swaps one rich state for the next: the old one leaves, then the new one enters (mode=\"wait\"). */\nconst swap = {\n  enter: (morph: Morph) => ({ opacity: 0, scale: morph === \"fold\" ? 1.04 : 0.96, filter: \"blur(4px)\" }),\n  center: { opacity: 1, scale: 1, filter: \"blur(0px)\" },\n  exit: (morph: Morph) => ({ opacity: 0, scale: morph === \"fold\" ? 0.96 : 1.04, filter: \"blur(4px)\" }),\n}\n\nfunction Item({ toast: t, layout, morph, tone, edge, justify, openW, front, swipeable, z, reduce, onMeasure, onClose, onDragChange }: ItemProps) {\n  const [entered, setEntered] = React.useState(false)\n  const controls = useDragControls()\n  // Swipe: the toast tracks the finger 1:1 toward its edge and fades with the distance.\n  const dragY = useMotionValue(0)\n  const dragOpacity = useTransform(dragY, edge === -1 ? [-SWIPE_FADE, 0] : [0, SWIPE_FADE], edge === -1 ? [0.4, 1] : [1, 0.4])\n\n  // The content remounts when it swaps, so measuring follows the mounted nodes (ref callbacks).\n  const nodes = React.useRef<{ head: HTMLElement | null; body: HTMLElement | null }>({ head: null, body: null })\n  const observe = React.useCallback(\n    (key: \"head\" | \"body\", node: HTMLElement | null) => {\n      if (!node) return\n      nodes.current[key] = node\n      const measure = () => {\n        const { head, body } = nodes.current\n        if (head && body) onMeasure(t.id, head.offsetWidth, body.offsetHeight)\n      }\n      const ro = new ResizeObserver(measure)\n      ro.observe(node)\n      measure()\n      return () => {\n        ro.disconnect()\n        if (nodes.current[key] === node) nodes.current[key] = null\n      }\n    },\n    [t.id, onMeasure]\n  )\n  const headRef = React.useCallback((node: HTMLDivElement | null) => observe(\"head\", node), [observe])\n  const bodyRef = React.useCallback((node: HTMLDivElement | null) => observe(\"body\", node), [observe])\n\n  // Enters from beyond its edge by its own height and leaves the same way; layers behind fade where they are.\n  const travel = layout.h + 24\n  const hasBody = Boolean(t.description || t.action)\n  const position: Transition = reduce\n    ? { ...INSTANT, opacity: { duration: 0.12 } }\n    : { ...(entered ? ISLAND_SPRING.stack : ISLAND_SPRING.enter), opacity: FADE_IN }\n  const exit = reduce\n    ? { opacity: 0, transition: FADE_OUT }\n    : front\n      ? { opacity: 0, y: edge * travel, transition: { ...SPRING_EXIT, opacity: { duration: 0.15, ease: EASE_OUT, delay: 0.05 } } }\n      : { opacity: 0, scale: 0.95, transition: { ...SPRING_EXIT, opacity: { duration: 0.12, ease: EASE_OUT } } }\n\n  const onDragEnd = (_: unknown, info: PanInfo) => {\n    onDragChange(false)\n    if (edge * info.offset.y > SWIPE_DISTANCE || edge * info.velocity.y > SWIPE_VELOCITY) return onClose(t.id)\n    // Not far enough: back into place, seeded with the release speed; a little bounce, since the drag applied force.\n    animate(dragY, 0, reduce ? { duration: 0.12 } : { ...ISLAND_SPRING.release, velocity: info.velocity.y })\n  }\n\n  const contentKey = `${t.type}:${typeof t.title === \"string\" ? t.title : \"\"}`\n\n  return (\n    <div className={cn(\"pointer-events-none absolute inset-x-0 flex\", edge === -1 ? \"top-0\" : \"bottom-0\", justify)} style={{ zIndex: z }}>\n      {/* Position in the stack: enter, shift back, leave. */}\n      <motion.div\n        initial={reduce ? { opacity: 0 } : { opacity: 0, y: edge * travel }}\n        animate={{ y: layout.y, scale: layout.scale, opacity: layout.opacity }}\n        exit={exit}\n        transition={position}\n        onAnimationComplete={() => setEntered(true)}\n        className={cn(layout.opacity ? \"pointer-events-auto\" : \"pointer-events-none\", edge === -1 ? \"origin-bottom\" : \"origin-top\")}\n      >\n        {/* Swipe layer. Tracking stays under reduced motion: the user is producing the motion. */}\n        <motion.div\n          drag={swipeable ? \"y\" : false}\n          dragListener={false}\n          dragControls={controls}\n          dragMomentum={false}\n          // Free toward the edge, rubber-band the other way.\n          dragConstraints={edge === -1 ? { bottom: 0 } : { top: 0 }}\n          dragElastic={0.2}\n          onPointerDown={(e) => {\n            // A press on the close or action button is a press, not the start of a swipe.\n            if (swipeable && !(e.target as HTMLElement).closest(\"button\")) controls.start(e)\n          }}\n          onDragStart={() => onDragChange(true)}\n          onDragEnd={onDragEnd}\n          style={{ y: dragY, opacity: dragOpacity, touchAction: swipeable ? \"pan-x\" : undefined }}\n        >\n          {/* The island: morphs between fixed sizes with a layout animation; radius inline so it doesn't warp. */}\n          <motion.div\n            layout\n            data-slot=\"island-toast\"\n            data-type={t.type}\n            aria-hidden={!layout.content}\n            transition={reduce ? INSTANT : ISLAND_SPRING[morph]}\n            style={{ width: layout.w, height: layout.h, borderRadius: RADIUS }}\n            className={cn(\"relative overflow-hidden shadow-overlay\", tone === \"dark\" && \"bg-island\", tone === \"light\" && \"light bg-popover\")}\n          >\n            {/* dark: the content reads the dark palette, the box keeps the page's shadow. */}\n            <motion.div\n              layout\n              initial={false}\n              animate={{ opacity: layout.content ? 1 : 0 }}\n              transition={{ layout: reduce ? INSTANT : ISLAND_SPRING[morph], opacity: layout.content ? { ...FADE_IN, delay: 0.04 } : FADE_OUT }}\n              className={cn(\"absolute inset-0 text-foreground tabular-nums\", tone === \"dark\" && \"dark\", tint[t.type])}\n            >\n              <AnimatePresence mode=\"wait\" initial={false} custom={morph}>\n                <motion.div\n                  key={contentKey}\n                  custom={morph}\n                  variants={reduce ? { enter: { opacity: 0 }, center: { opacity: 1 }, exit: { opacity: 0 } } : swap}\n                  initial=\"enter\"\n                  animate=\"center\"\n                  exit=\"exit\"\n                  transition={reduce ? { duration: 0.12 } : { duration: 0.15, ease: EASE_OUT }}\n                  className=\"absolute inset-0\"\n                >\n                  <motion.div\n                    ref={headRef}\n                    layout=\"position\"\n                    transition={reduce ? INSTANT : ISLAND_SPRING[morph]}\n                    className={cn(\n                      \"absolute top-0 flex h-9 items-center gap-2 pr-3.5 pl-[11px]\",\n                      layout.wide ? \"left-0\" : \"left-1/2 w-max -translate-x-1/2\",\n                      t.type === \"default\" && \"pl-3.5\"\n                    )}\n                    style={layout.wide ? { width: openW } : undefined}\n                  >\n                    {t.type !== \"default\" && (\n                      <span className=\"grid size-4 shrink-0 place-items-center\">\n                        <StatusIcon type={t.type} />\n                      </span>\n                    )}\n                    <span className={cn(\"min-w-0 truncate text-[13px] leading-[18px] font-medium\", layout.wide && \"flex-1\")}>{t.title}</span>\n                    {layout.wide && (\n                      <button\n                        type=\"button\"\n                        aria-label=\"Kapat\"\n                        onClick={() => onClose(t.id)}\n                        // 24px to see, 44px to hit.\n                        className={cn(\n                          buttonVariants({ variant: \"ghost\", size: \"icon-xs\" }),\n                          \"relative size-6 rounded-full text-muted-foreground before:absolute before:-inset-2.5\"\n                        )}\n                      >\n                        <XIcon />\n                      </button>\n                    )}\n                  </motion.div>\n                  <motion.div\n                    initial={false}\n                    animate={{ opacity: layout.body ? 1 : 0 }}\n                    transition={layout.body ? { ...FADE_IN, delay: 0.06 } : FADE_OUT}\n                    className={cn(\"absolute left-0\", layout.body ? \"pointer-events-auto\" : \"pointer-events-none\")}\n                    style={{ top: PILL_H, width: openW }}\n                  >\n                    {/* Description and the one action share a row, so short content leaves no empty band. */}\n                    <div ref={bodyRef} className={cn(\"flex items-center gap-3\", hasBody && \"pr-3 pb-3 pl-[35px]\", t.type === \"default\" && \"pl-3.5\")}>\n                      {t.description && <p className=\"min-w-0 flex-1 text-[12.5px] leading-[17px] text-muted-foreground\">{t.description}</p>}\n                      {t.action && (\n                        <button\n                          type=\"button\"\n                          className={cn(buttonVariants({ variant: \"outline\", size: \"xs\" }), \"ml-auto\")}\n                          onClick={() => {\n                            t.action?.onClick()\n                            onClose(t.id)\n                          }}\n                        >\n                          {t.action.label}\n                        </button>\n                      )}\n                    </div>\n                  </motion.div>\n                </motion.div>\n              </AnimatePresence>\n            </motion.div>\n          </motion.div>\n        </motion.div>\n      </motion.div>\n    </div>\n  )\n}\n\n/** Two live regions: errors and warnings interrupt, the rest wait their turn. */\nfunction Announcer({ toast }: { toast?: IslandToast }) {\n  const [message, setMessage] = React.useState({ polite: \"\", assertive: \"\" })\n  const text = toast ? [toast.title, toast.description].filter((part) => typeof part === \"string\").join(\". \") : \"\"\n  const loud = toast?.type === \"error\" || toast?.type === \"warning\"\n  const key = toast ? `${toast.id}:${toast.type}:${text}` : \"\"\n  React.useEffect(() => {\n    if (!key) return\n    // Clear, then set a frame later, so the same message is announced again.\n    let second = 0\n    const first = requestAnimationFrame(() => {\n      setMessage({ polite: \"\", assertive: \"\" })\n      second = requestAnimationFrame(() => setMessage(loud ? { polite: \"\", assertive: text } : { polite: text, assertive: \"\" }))\n    })\n    return () => {\n      cancelAnimationFrame(first)\n      cancelAnimationFrame(second)\n    }\n  }, [key, loud, text])\n  return (\n    <>\n      <div className=\"sr-only\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n        {message.polite}\n      </div>\n      <div className=\"sr-only\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\">\n        {message.assertive}\n      </div>\n    </>\n  )\n}\n\ntype IslandToasterProps = {\n  /** dark: opaque ink in both themes. light: white in both themes. */\n  tone?: \"dark\" | \"light\"\n  /** Edge and side the stack sits on. Top grows down, bottom grows up. */\n  position?: IslandPosition\n  /** Toasts shown at once: the front one plus folded layers behind it, and rows in the open list. */\n  visibleToasts?: number\n  /** Default milliseconds per toast; one with a description or action gets 1.5× so it can be read. */\n  duration?: number\n  /** Distance from the viewport edge in px. */\n  offset?: number\n  /** Shows only the toasts sent with the same `toasterId`. Without it, only toasts sent without one. */\n  id?: string\n  /** On the viewport layer; pass `absolute` to pin the stack inside a positioned parent. */\n  className?: string\n}\n\ntype Timer = { dismiss?: number; open: number[]; left: number; start: number }\n\nconst stopTimer = (timer?: Timer) => {\n  if (!timer) return\n  window.clearTimeout(timer.dismiss)\n  timer.open.forEach((x) => window.clearTimeout(x))\n  timer.open = []\n}\n\n/**\n * A dynamic-island toast stack: each toast is a 36px pill that opens to show its\n * description and action. New toasts go to the front and fold the older ones behind\n * it; hover or focus opens the stack as a list and pauses every timer. Swipe toward\n * the edge, the close button or Esc dismisses. Mount once; call island() anywhere.\n */\nfunction IslandToaster({ tone = \"dark\", position = \"top-center\", visibleToasts = 3, duration = 4000, offset = 16, id, className }: IslandToasterProps) {\n  const reduce = useReducedMotion() ?? false\n  const all = React.useSyncExternalStore(subscribe, () => store, () => EMPTY)\n  const toasts = React.useMemo(() => all.filter((t) => t.toasterId === id), [all, id])\n  const [list, setList] = React.useState(false)\n  const [openId, setOpenId] = React.useState<string | number | null>(null)\n  const [sizes, setSizes] = React.useState<Record<string, { w: number; h: number }>>({})\n  const [rootW, setRootW] = React.useState(0)\n  const rootRef = React.useRef<HTMLElement>(null)\n  const timers = React.useRef(new Map<string | number, Timer>())\n  const seen = React.useRef(new Map<string | number, IslandToast>())\n  const frontRef = React.useRef<string | number | undefined>(undefined)\n  const hovering = React.useRef(false)\n  const hidden = React.useRef(false)\n  const dragging = React.useRef(false)\n  const paused = React.useRef(false)\n\n  const [vertical, side] = position.split(\"-\") as [\"top\" | \"bottom\", \"left\" | \"center\" | \"right\"]\n  const edge = vertical === \"top\" ? -1 : 1\n  const justify = side === \"left\" ? \"justify-start\" : side === \"right\" ? \"justify-end\" : \"justify-center\"\n  const openW = Math.min(OPEN_W, rootW ? rootW - 24 : OPEN_W)\n\n  // A new front toast (a newcomer, or the next one once the front left) starts folded; an empty stack closes the list.\n  const frontId = toasts[toasts.length - 1]?.id\n  const [prevFront, setPrevFront] = React.useState(frontId)\n  if (frontId !== prevFront) {\n    setPrevFront(frontId)\n    setOpenId(null)\n    if (frontId === undefined) setList(false)\n  }\n\n  React.useLayoutEffect(() => {\n    const root = rootRef.current\n    if (!root) return\n    const ro = new ResizeObserver(() => setRootW(root.offsetWidth))\n    ro.observe(root)\n    setRootW(root.offsetWidth)\n    return () => ro.disconnect()\n  }, [])\n\n  const onMeasure = React.useCallback(\n    (key: string | number, w: number, h: number) =>\n      setSizes((s) => (s[key]?.w === w && s[key]?.h === h ? s : { ...s, [key]: { w, h } })),\n    []\n  )\n\n  // Each toast keeps its own clock. The front one opens itself after 150ms when it has a body,\n  // and folds 1.5s before it leaves; a resumed clock does the same with the time it has left.\n  const run = (t: IslandToast, timer: Timer) => {\n    timer.start = Date.now()\n    timer.dismiss = window.setTimeout(() => dismiss(t.id), timer.left)\n    if (t.description || t.action) {\n      timer.open.push(window.setTimeout(() => frontRef.current === t.id && setOpenId(t.id), 150))\n      timer.open.push(window.setTimeout(() => setOpenId((o) => (o === t.id ? null : o)), Math.max(timer.left - 1500, 300)))\n    }\n  }\n  const arm = (t: IslandToast) => {\n    stopTimer(timers.current.get(t.id))\n    const ms = t.duration ?? (t.description || t.action ? duration * 1.5 : duration)\n    const timer: Timer = { open: [], left: ms, start: Date.now() }\n    timers.current.set(t.id, timer)\n    if (t.type === \"loading\" || !Number.isFinite(ms) || paused.current) return\n    run(t, timer)\n  }\n\n  // Timers freeze while the list is open, a toast is being swiped or the tab is hidden, then resume with what was left.\n  const syncTimers = () => {\n    const frozen = hovering.current || hidden.current || dragging.current\n    const now = Date.now()\n    if (frozen && !paused.current)\n      timers.current.forEach((timer) => {\n        stopTimer(timer)\n        timer.left -= now - timer.start\n      })\n    if (!frozen && paused.current)\n      timers.current.forEach((timer, key) => {\n        const t = seen.current.get(key)\n        if (!t || t.type === \"loading\" || !Number.isFinite(timer.left)) return\n        timer.left = Math.max(timer.left, 1200)\n        run(t, timer)\n      })\n    paused.current = frozen\n  }\n\n  // Start a clock for every new or changed toast; forget the ones that left.\n  const handleToasts = (current: IslandToast[]) => {\n    frontRef.current = current[current.length - 1]?.id\n    const ids = new Set(current.map((t) => t.id))\n    for (const [key, timer] of timers.current)\n      if (!ids.has(key)) {\n        stopTimer(timer)\n        timers.current.delete(key)\n        seen.current.delete(key)\n      }\n    for (const t of current) {\n      if (seen.current.get(t.id) === t) continue\n      seen.current.set(t.id, t)\n      arm(t)\n    }\n    if (!current.length && hovering.current) {\n      hovering.current = false\n      syncTimers()\n    }\n  }\n  const handleVisibility = () => {\n    hidden.current = document.hidden\n    syncTimers()\n  }\n  // Effects call the latest handlers without re-subscribing (useEffectEvent needs React 19.2).\n  const handlers = React.useRef({ handleToasts, handleVisibility })\n  React.useLayoutEffect(() => {\n    handlers.current = { handleToasts, handleVisibility }\n  })\n\n  React.useEffect(() => handlers.current.handleToasts(toasts), [toasts])\n  React.useEffect(() => {\n    const handler = () => handlers.current.handleVisibility()\n    document.addEventListener(\"visibilitychange\", handler)\n    return () => document.removeEventListener(\"visibilitychange\", handler)\n  }, [])\n\n  React.useEffect(() => {\n    const map = timers.current\n    return () => map.forEach(stopTimer)\n  }, [])\n\n  React.useEffect(() => {\n    mounted.set(id, (mounted.get(id) ?? 0) + 1)\n    return () => {\n      const left = (mounted.get(id) ?? 1) - 1\n      if (left) mounted.set(id, left)\n      else mounted.delete(id)\n      // Deferred, so a remount (Strict Mode, a moved toaster) keeps its toasts.\n      window.setTimeout(sweep, ORPHAN_GRACE)\n    }\n  }, [id])\n\n  const openList = () => {\n    if (hovering.current || !toasts.length) return\n    hovering.current = true\n    setList(true)\n    syncTimers()\n  }\n  const onDragChange = (value: boolean) => {\n    dragging.current = value\n    syncTimers()\n  }\n  const closeList = () => {\n    if (!hovering.current) return\n    hovering.current = false\n    setList(false)\n    setOpenId(null)\n    syncTimers()\n  }\n\n  // Layout: collapsed = the front toast plus folded layers that take its size; list = every toast at full size.\n  const order = [...toasts].reverse()\n  const front = order[0]\n  const frontSize = front ? sizes[front.id] : undefined\n  const frontOpen = Boolean(front && openId === front.id)\n  const wF = frontOpen ? openW : Math.max(frontSize?.w ?? 120, PILL_H)\n  const hF = frontOpen ? PILL_H + (frontSize?.h ?? 0) : PILL_H\n  const dir = edge === -1 ? 1 : -1\n  const layouts: Layout[] = []\n  let listH = 0\n  for (let i = 0; i < order.length; i++) {\n    const visible = i < visibleToasts\n    if (list) {\n      const h = PILL_H + (sizes[order[i].id]?.h ?? 0)\n      layouts.push({ w: openW, h, y: dir * listH, scale: 1, opacity: visible ? 1 : 0, wide: true, content: true, body: true })\n      if (visible) listH += h + GAP\n      continue\n    }\n    const depth = Math.min(i, visibleToasts)\n    // Each layer back fades a little, so same-colored layers read as separate toasts.\n    layouts.push({\n      w: wF,\n      h: hF,\n      y: dir * PEEK * depth,\n      scale: 1 - 0.05 * depth,\n      opacity: visible ? 1 - 0.2 * depth : 0,\n      wide: i === 0 && frontOpen,\n      content: i === 0,\n      body: i === 0 && frontOpen,\n    })\n  }\n  const morph: Morph = list ? \"stack\" : frontOpen ? \"open\" : \"fold\"\n  const boxW = list ? openW : wF\n  const boxH = !order.length ? 0 : list ? listH - GAP : hF + PEEK * Math.min(order.length - 1, visibleToasts - 1)\n\n  return (\n    <section\n      ref={rootRef}\n      aria-label=\"Bildirimler\"\n      data-slot=\"island-toaster\"\n      className={cn(\"pointer-events-none fixed inset-x-0 z-[100] flex px-3\", vertical === \"top\" ? \"items-start\" : \"items-end\", justify, className)}\n      style={vertical === \"top\" ? { top: offset } : { bottom: offset }}\n    >\n      <motion.div\n        tabIndex={order.length ? 0 : -1}\n        aria-label={order.length ? `${order.length} bildirim` : undefined}\n        onPointerEnter={(e) => e.pointerType === \"mouse\" && openList()}\n        onPointerLeave={(e) => e.pointerType === \"mouse\" && closeList()}\n        onClick={openList}\n        onFocus={openList}\n        onBlur={(e) => !e.currentTarget.contains(e.relatedTarget as Node) && closeList()}\n        onKeyDown={(e) => e.key === \"Escape\" && front && dismiss(front.id)}\n        initial={false}\n        animate={{ width: boxW, height: boxH }}\n        transition={reduce ? INSTANT : ISLAND_SPRING[morph]}\n        className={cn(\"relative rounded-[18px] outline-none focus-visible:ring-3 focus-visible:ring-ring/30\", order.length && \"pointer-events-auto\")}\n      >\n        <AnimatePresence initial={false}>\n          {order.map((t, i) => (\n            <Item\n              key={t.id}\n              toast={t}\n              layout={layouts[i]}\n              morph={morph}\n              tone={tone}\n              edge={edge}\n              justify={justify}\n              openW={openW}\n              front={i === 0}\n              swipeable={i === 0 && !list}\n              z={100 - i}\n              reduce={reduce}\n              onMeasure={onMeasure}\n              onClose={dismiss}\n              onDragChange={onDragChange}\n            />\n          ))}\n        </AnimatePresence>\n      </motion.div>\n      <Announcer toast={toasts[toasts.length - 1]} />\n    </section>\n  )\n}\n\nexport { IslandToaster, island, type IslandToasterProps, type IslandOptions, type IslandPosition, type IslandType }\n",
      "type": "registry:ui"
    }
  ],
  "docs": "https://builders.ikas.com/tr/docs/app-development/ui-kit/components/toast",
  "categories": [
    "feedback",
    "motion"
  ],
  "type": "registry:ui"
}