{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"morning-widget","type":"registry:ui","title":"Morning Widget","description":"A squircle card on a drifting sunrise mesh that greets you by name, rolls a live clock digit by digit and rotates motivational lines.","dependencies":["motion","lucide-react","figma-squircle","react-use-measure"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/morning-widget.tsx","type":"registry:ui","content":"\"use client\";\n\n// Adapted from Calamansi UI by fujiDevv (MIT License).\n// https://github.com/fujiDevv/calamansi-ui\n\nimport {\n  useCallback,\n  useEffect,\n  useMemo,\n  useState,\n  type PointerEvent as ReactPointerEvent,\n  type ReactNode,\n} from \"react\";\nimport { AnimatePresence, motion, useMotionValue, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport { Sun } from \"lucide-react\";\nimport { getSvgPath } from \"figma-squircle\";\nimport useMeasure from \"react-use-measure\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MotivationQuote = {\n  /** The line shown in the card. */\n  text: string;\n  /** Phrases from `text` to render in the emphasis colour. Matched literally. */\n  emphasis?: string[];\n};\n\nexport type MorningWidgetVariant = \"white\" | \"calamansi\" | \"slate\" | \"citrus\";\n\nexport type MorningWidgetProps = {\n  /** Name the greeting is addressed to. Default: \"Friend\" */\n  name?: string;\n  /** Quotes the card rotates through. Default: a five line starter set. */\n  quotes?: MotivationQuote[];\n  /** Show the live clock above the card. Default: true */\n  showClock?: boolean;\n  /** Clock format. Default: \"12h\" */\n  timeFormat?: \"12h\" | \"24h\";\n  /** Seconds a quote stays up before the next one, or 0 to hold it. Default: 9 */\n  interval?: number;\n  /** Lean the widget towards the pointer. Default: true */\n  tilt?: boolean;\n  /** Surface palette. Default: \"calamansi\" */\n  variant?: MorningWidgetVariant;\n  /** Extra class names merged onto the outer container. */\n  className?: string;\n};\n\nconst DEFAULT_QUOTES: MotivationQuote[] = [\n  {\n    text: \"You have to start delegating tasks, now go carpe diem :)\",\n    emphasis: [\"delegating tasks\", \"carpe diem\"],\n  },\n  {\n    text: \"Believe you can and you're halfway there. Keep pushing forward!\",\n    emphasis: [\"halfway there\", \"pushing forward\"],\n  },\n  {\n    text: \"Make today so awesome that yesterday gets jealous.\",\n    emphasis: [\"today so awesome\", \"jealous\"],\n  },\n  {\n    text: \"Focus on progress, not perfection. You got this!\",\n    emphasis: [\"progress\", \"perfection\"],\n  },\n  {\n    text: \"Don't count the days, make the days count.\",\n    emphasis: [\"count the days\", \"days count\"],\n  },\n];\n\n/**\n * Every size and inset below is written in `cqw` — one percent of the widget's\n * own width — so the card is an exact scale of its 519px design from a phone\n * preview up to full width. The @container on the outer element is what those\n * units resolve against; nothing here needs a media query. The corner is the one\n * exception: it is the kit's squircle, so it holds the same curve as every other\n * component instead of drifting with the width.\n *\n * The palette picks the four blobs the mesh is built from plus the base they sit\n * on, and the ink that reads on top of them: a neutral dawn for `white`, the\n * Calamansi greens by default, and citrus keeps the warm sunrise.\n */\nconst VARIANTS: Record<MorningWidgetVariant, { mesh: string; ink: string }> = {\n  white: {\n    mesh: [\n      \"[--mesh-base:#f5f5f6] [--mesh-a:#dadbdf] [--mesh-b:#c7c8cd] [--mesh-c:#e8e8eb] [--mesh-d:#d2d3d8]\",\n      \"dark:[--mesh-base:#0c0c0d] dark:[--mesh-a:#2c2c31] dark:[--mesh-b:#1e1e22] dark:[--mesh-c:#39393f] dark:[--mesh-d:#26262a]\",\n    ].join(\" \"),\n    ink: \"text-foreground\",\n  },\n  calamansi: {\n    mesh: [\n      \"[--mesh-base:#eff6e0] [--mesh-a:#7d9c52] [--mesh-b:#b4e84c] [--mesh-c:#5c7a67] [--mesh-d:#a8d06a]\",\n      \"dark:[--mesh-base:#0f1409] dark:[--mesh-a:#4f7d3a] dark:[--mesh-b:#86b81f] dark:[--mesh-c:#2b4a24] dark:[--mesh-d:#6f9a4a]\",\n    ].join(\" \"),\n    ink: \"text-white\",\n  },\n  slate: {\n    mesh: [\n      \"[--mesh-base:#eeecf6] [--mesh-a:#8b84b4] [--mesh-b:#7d8bc9] [--mesh-c:#5a6a9c] [--mesh-d:#a99fd6]\",\n      \"dark:[--mesh-base:#0d0c16] dark:[--mesh-a:#4a4b8f] dark:[--mesh-b:#33406b] dark:[--mesh-c:#6f68b8] dark:[--mesh-d:#2a3560]\",\n    ].join(\" \"),\n    ink: \"text-white\",\n  },\n  citrus: {\n    mesh: [\n      \"[--mesh-base:#ffe7cc] [--mesh-a:#fcaf58] [--mesh-b:#ff8d8d] [--mesh-c:#ffc93d] [--mesh-d:#ffb6a0]\",\n      \"dark:[--mesh-base:#17100a] dark:[--mesh-a:#b8714a] dark:[--mesh-b:#8a4530] dark:[--mesh-c:#a8623a] dark:[--mesh-d:#6d3a25]\",\n    ].join(\" \"),\n    ink: \"text-white\",\n  },\n};\n\nconst MESH_BACKGROUND = [\n  \"radial-gradient(circle at 10% 20%, var(--mesh-a) 0%, transparent 55%)\",\n  \"radial-gradient(circle at 85% 50%, var(--mesh-b) 0%, transparent 60%)\",\n  \"radial-gradient(circle at 50% 90%, var(--mesh-c) 0%, transparent 65%)\",\n  \"radial-gradient(circle at 90% 90%, var(--mesh-d) 0%, transparent 50%)\",\n  \"var(--mesh-base)\",\n].join(\", \");\n\n/** Fixed slots keep ticking digits from nudging the clock, like tabular figures. */\nconst slotWidth = (glyph: string) =>\n  glyph === \":\" || glyph === \".\" ? \"0.34em\" : \"0.62em\";\n\nfunction escapeRegExp(value: string) {\n  return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/** Splits a quote into plain and emphasised runs, so the phrase stays normal inline flow. */\nfunction quoteParts(quote?: MotivationQuote) {\n  if (!quote) return [{ value: \"\", emphasis: false }];\n\n  const { text, emphasis = [] } = quote;\n  if (emphasis.length === 0) return [{ value: text, emphasis: false }];\n\n  const pattern = new RegExp(`(${emphasis.map(escapeRegExp).join(\"|\")})`, \"g\");\n\n  return text\n    .split(pattern)\n    .filter((value) => value.length > 0)\n    .map((value) => ({ value, emphasis: emphasis.includes(value) }));\n}\n\n/**\n * One character of the clock. The slot keeps a fixed width and the glyph stays\n * in normal flow, so inline baseline alignment with the AM/PM badge is untouched\n * while the outgoing glyph rolls away.\n */\nfunction RollingGlyph({\n  glyph,\n  width,\n  className,\n  reduceMotion,\n}: {\n  glyph: string;\n  width?: string;\n  className?: string;\n  reduceMotion: boolean;\n}) {\n  return (\n    <span\n      className={cn(\"relative inline-block h-[1em] text-center\", className)}\n      style={width ? { width } : undefined}\n    >\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          key={glyph}\n          className=\"block\"\n          initial={reduceMotion ? false : { y: \"0.85em\", opacity: 0 }}\n          animate={{ y: 0, opacity: 1 }}\n          exit={reduceMotion ? { opacity: 0 } : { y: \"-0.85em\", opacity: 0 }}\n          transition={{ type: \"spring\", stiffness: 330, damping: 30 }}\n        >\n          {glyph}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\n/**\n * A Calamansi squircle card holding a drifting sunrise mesh: it greets you by\n * name, keeps the time, leans towards the pointer and cycles motivational quotes\n * with a staged reveal. The palette recolours the mesh and the ink on it.\n */\nexport function MorningWidget({\n  name = \"Friend\",\n  quotes = DEFAULT_QUOTES,\n  showClock = true,\n  timeFormat = \"12h\",\n  interval = 9,\n  tilt = true,\n  variant = \"calamansi\",\n  className,\n}: MorningWidgetProps) {\n  const reduceMotion = Boolean(useReducedMotion());\n\n  const [index, setIndex] = useState(0);\n  const [clock, setClock] = useState({ time: \"9:41\", ampm: \"AM\" });\n  const [partOfDay, setPartOfDay] = useState<\n    \"Morning\" | \"Afternoon\" | \"Evening\"\n  >(\"Morning\");\n  // reading the card (pointer or focus) holds the rotation in place\n  const [held, setHeld] = useState(false);\n\n  const pointerX = useMotionValue(0.5);\n  const pointerY = useMotionValue(0.5);\n  const rotateX = useSpring(useTransform(pointerY, [0, 1], [8, -8]), {\n    stiffness: 180,\n    damping: 20,\n    mass: 0.6,\n  });\n  const rotateY = useSpring(useTransform(pointerX, [0, 1], [-8, 8]), {\n    stiffness: 180,\n    damping: 20,\n    mass: 0.6,\n  });\n\n  useEffect(() => {\n    const tick = () => {\n      const now = new Date();\n      const hours24 = now.getHours();\n\n      setPartOfDay(\n        hours24 < 12 ? \"Morning\" : hours24 < 18 ? \"Afternoon\" : \"Evening\",\n      );\n      setClock({\n        time: `${timeFormat === \"12h\" ? hours24 % 12 || 12 : hours24}:${String(\n          now.getMinutes(),\n        ).padStart(2, \"0\")}`,\n        ampm: hours24 >= 12 ? \"PM\" : \"AM\",\n      });\n    };\n\n    tick();\n    const timer = setInterval(tick, 1000);\n    return () => clearInterval(timer);\n  }, [timeFormat]);\n\n  const advance = useCallback(() => {\n    setIndex((current) => (current + 1) % Math.max(quotes.length, 1));\n  }, [quotes.length]);\n\n  // a timeout rather than an interval, so a manual click restarts the countdown\n  useEffect(() => {\n    if (!interval || held || quotes.length < 2) return;\n\n    const timer = setTimeout(advance, interval * 1000);\n    return () => clearTimeout(timer);\n  }, [advance, held, index, interval, quotes.length]);\n\n  const track = (event: ReactPointerEvent<HTMLDivElement>) => {\n    // touch has no hover to lean towards, and tracking a drag fights the scroll\n    if (!tilt || reduceMotion || event.pointerType === \"touch\") return;\n\n    const bounds = event.currentTarget.getBoundingClientRect();\n    pointerX.set((event.clientX - bounds.left) / bounds.width);\n    pointerY.set((event.clientY - bounds.top) / bounds.height);\n  };\n\n  const reset = () => {\n    pointerX.set(0.5);\n    pointerY.set(0.5);\n  };\n\n  return (\n    <div\n      className={cn(\"@container relative w-full max-w-[519px]\", className)}\n      style={{ perspective: 1500 }}\n    >\n      <motion.div\n        onPointerMove={track}\n        onPointerEnter={() => setHeld(true)}\n        onPointerLeave={() => {\n          reset();\n          setHeld(false);\n        }}\n        style={reduceMotion ? undefined : { rotateX, rotateY }}\n        className=\"relative aspect-[519/477] w-full [transform-style:preserve-3d]\"\n      >\n        <div\n          data-slot=\"morning-widget\"\n          className={cn(\n            \"relative size-full select-none\",\n            VARIANTS[variant].mesh,\n            VARIANTS[variant].ink,\n          )}\n        >\n          {/*\n            The mesh lives inside the squircle layer rather than on the card, so\n            the drift, the bloom and the sheen are all clipped to the shape — and\n            the corner is the kit's curve, not a cqw radius.\n          */}\n          <Squircle className=\"bg-[var(--mesh-base)]\">\n            {/* Sunrise mesh. It drifts on its own so the surface keeps breathing. */}\n            <motion.div\n              aria-hidden=\"true\"\n              className=\"absolute -inset-1/4\"\n              style={{ background: MESH_BACKGROUND }}\n              animate={\n                reduceMotion\n                  ? undefined\n                  : { scale: [1, 1.08, 1], rotate: [0, 2, 0] }\n              }\n              transition={{ duration: 22, repeat: Infinity, ease: \"easeInOut\" }}\n            />\n\n            {/* Warm bloom in the top corner, swelling like a sunrise. */}\n            <motion.div\n              aria-hidden=\"true\"\n              className=\"absolute -top-1/4 -left-1/4 size-3/4 rounded-full\"\n              style={{\n                background:\n                  \"radial-gradient(circle, rgba(255,255,255,0.5) 0%, transparent 65%)\",\n              }}\n              animate={\n                reduceMotion ? undefined : { opacity: [0.45, 0.85, 0.45] }\n              }\n              transition={{ duration: 9, repeat: Infinity, ease: \"easeInOut\" }}\n            />\n\n            {/* A soft light crossing the surface every few seconds. */}\n            <motion.div\n              aria-hidden=\"true\"\n              className=\"absolute -inset-1/4\"\n              style={{\n                background:\n                  \"linear-gradient(115deg, transparent 38%, rgba(255,255,255,0.4) 50%, transparent 62%)\",\n              }}\n              animate={reduceMotion ? undefined : { x: [\"-40%\", \"40%\"] }}\n              transition={{\n                duration: 7,\n                repeat: Infinity,\n                repeatDelay: 4,\n                ease: \"easeInOut\",\n              }}\n            />\n          </Squircle>\n\n          {showClock && (\n            /* the row carries the shadow, leaving the heading free to clip its rolling digits */\n            <div className=\"pointer-events-none absolute top-[8.4%] left-[10%] z-30 drop-shadow-sm\">\n              <h1 className=\"text-[17.5cqw] leading-none font-bold tracking-[-0.03em] tabular-nums [clip-path:inset(0_-0.3em)]\">\n                <span className=\"sr-only\">\n                  {clock.time}\n                  {timeFormat === \"12h\" ? ` ${clock.ampm}` : \"\"}\n                </span>\n\n                <span aria-hidden=\"true\">\n                  {[...clock.time].map((glyph, glyphIndex) => (\n                    <RollingGlyph\n                      key={glyphIndex}\n                      glyph={glyph}\n                      width={slotWidth(glyph)}\n                      reduceMotion={reduceMotion}\n                    />\n                  ))}\n\n                  {timeFormat === \"12h\" && (\n                    <RollingGlyph\n                      glyph={clock.ampm}\n                      className=\"ml-[1.5cqw] text-[7.9cqw] tracking-[-0.02em]\"\n                      reduceMotion={reduceMotion}\n                    />\n                  )}\n                </span>\n              </h1>\n            </div>\n          )}\n\n          <motion.button\n            type=\"button\"\n            onClick={advance}\n            onFocus={() => setHeld(true)}\n            onBlur={() => setHeld(false)}\n            onPointerEnter={() => setHeld(true)}\n            onPointerLeave={() => setHeld(false)}\n            title=\"Show the next motivation\"\n            whileHover={reduceMotion ? undefined : { y: -4 }}\n            whileTap={reduceMotion ? undefined : { scale: 0.985 }}\n            transition={{ type: \"spring\", stiffness: 320, damping: 26 }}\n            className=\"absolute bottom-[2.5%] left-[2.3%] z-20 flex aspect-[477/216] w-[91.9%] cursor-pointer flex-col justify-center rounded-[28px] bg-white px-[6.4cqw] text-left shadow-[0_0.6cqw_1.6cqw_rgba(0,0,0,0.05)] outline-none select-none focus-visible:ring-[0.5cqw] focus-visible:ring-foreground/25 dark:bg-[#1c1c1f] dark:shadow-[0_0.6cqw_1.6cqw_rgba(0,0,0,0.3)]\"\n          >\n            <span className=\"mb-[2.3cqw] flex items-center gap-[1.9cqw]\">\n              <motion.span\n                className=\"size-[5.6cqw] shrink-0 text-[#ffc20c] dark:text-[#ffc93d]\"\n                animate={\n                  reduceMotion\n                    ? undefined\n                    : held\n                      ? { rotate: 34, scale: 1.12 }\n                      : { rotate: [0, 12, 0], scale: 1 }\n                }\n                transition={\n                  held\n                    ? { type: \"spring\", stiffness: 320, damping: 18 }\n                    : { duration: 6, repeat: Infinity, ease: \"easeInOut\" }\n                }\n              >\n                <Sun className=\"size-full\" strokeWidth={2.5} />\n              </motion.span>\n\n              <span className=\"min-w-0 truncate bg-gradient-to-r from-amber-500/75 to-muted-foreground/55 bg-clip-text text-[4.8cqw] font-extrabold tracking-[-0.01em] text-transparent uppercase dark:from-amber-300/85 dark:to-muted-foreground/70\">\n                <AnimatePresence initial={false} mode=\"wait\">\n                  <motion.span\n                    key={partOfDay}\n                    className=\"inline-block\"\n                    initial={reduceMotion ? false : { y: \"0.5em\", opacity: 0 }}\n                    animate={{ y: 0, opacity: 1 }}\n                    exit={\n                      reduceMotion\n                        ? { opacity: 0 }\n                        : { y: \"-0.5em\", opacity: 0 }\n                    }\n                    transition={{ duration: 0.24, ease: [0.16, 1, 0.3, 1] }}\n                  >\n                    {partOfDay}\n                  </motion.span>\n                </AnimatePresence>{\" \"}\n                {name}\n              </span>\n\n              {/* position dots, so the deck reads as a deck */}\n              <span\n                aria-hidden=\"true\"\n                className=\"ml-auto flex shrink-0 items-center gap-[0.8cqw] text-muted-foreground\"\n              >\n                {quotes.map((_, dotIndex) => (\n                  <motion.span\n                    key={dotIndex}\n                    className=\"block h-[0.9cqw] rounded-full bg-current\"\n                    animate={{\n                      width: dotIndex === index ? \"2.6cqw\" : \"0.9cqw\",\n                      opacity: dotIndex === index ? 1 : 0.35,\n                    }}\n                    transition={{ type: \"spring\", stiffness: 380, damping: 30 }}\n                  />\n                ))}\n              </span>\n            </span>\n\n            <span aria-live=\"polite\" className=\"relative block min-h-[13.5cqw]\">\n              <AnimatePresence mode=\"wait\" initial={false}>\n                <motion.span\n                  key={index}\n                  className=\"block text-[5.6cqw] leading-[1.18] font-semibold tracking-[-0.04em] text-muted-foreground/70\"\n                  initial={reduceMotion ? false : { y: \"0.35em\", opacity: 0 }}\n                  animate={{ y: 0, opacity: 1 }}\n                  exit={\n                    reduceMotion ? { opacity: 0 } : { y: \"-0.3em\", opacity: 0 }\n                  }\n                  transition={{ duration: 0.3, ease: [0.16, 1, 0.3, 1] }}\n                >\n                  {quoteParts(quotes[index]).map((part, partIndex) => (\n                    <motion.span\n                      key={`${partIndex}-${part.value}`}\n                      className={cn(\n                        part.emphasis && \"font-bold text-foreground\",\n                      )}\n                      initial={reduceMotion ? false : { opacity: 0 }}\n                      animate={{ opacity: 1 }}\n                      exit={{ opacity: 0 }}\n                      transition={{\n                        duration: 0.3,\n                        delay: reduceMotion ? 0 : partIndex * 0.05,\n                      }}\n                    >\n                      {part.value}\n                    </motion.span>\n                  ))}\n                </motion.span>\n              </AnimatePresence>\n            </span>\n          </motion.button>\n        </div>\n      </motion.div>\n    </div>\n  );\n}\n\n/* ─── Squircle surface (inlined from Calamansi's lib/squircle) ───────────────\n   A superellipse painted on its own layer, inset to the parent, clipped with a\n   figma-squircle path measured from the layout box. */\nfunction Squircle({\n  className,\n  radius = 28,\n  share,\n  lift = true,\n  filter,\n  border,\n  borderWidth = 1,\n  children,\n}: {\n  className?: string;\n  radius?: number;\n  share?: number;\n  lift?: boolean;\n  filter?: string;\n  border?: string;\n  borderWidth?: number;\n  children?: ReactNode;\n}) {\n  const [ref, bounds] = useMeasure({ offsetSize: true });\n  const corner = share && bounds.height > 0 ? Math.min(radius, bounds.height * share) : radius;\n  const fallback = share ? `min(${radius}px, ${share * 100}%)` : radius;\n  const path = useMemo(\n    () =>\n      bounds.width > 0 && bounds.height > 0\n        ? getSvgPath({ width: bounds.width, height: bounds.height, cornerRadius: corner, cornerSmoothing: 1 })\n        : null,\n    [bounds.width, bounds.height, corner],\n  );\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute inset-0 block\"\n      style={{ filter: filter ?? (lift ? \"drop-shadow(0 14px 28px rgba(0, 0, 0, 0.24))\" : undefined) }}\n    >\n      <span\n        ref={ref}\n        style={path ? { clipPath: `path('${path}')` } : { borderRadius: fallback }}\n        className={cn(\"relative block size-full overflow-hidden\", className)}\n      >\n        {children}\n        {border &&\n          (path ? (\n            <svg aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 size-full\" fill=\"none\">\n              {/* only the inner half of the stroke survives the clip */}\n              <path d={path} className={border} stroke=\"currentColor\" strokeWidth={borderWidth * 2} />\n            </svg>\n          ) : (\n            <span\n              aria-hidden=\"true\"\n              className={cn(\"pointer-events-none absolute inset-0 block\", border)}\n              style={{ borderRadius: fallback, boxShadow: `inset 0 0 0 ${borderWidth}px currentColor` }}\n            />\n          ))}\n      </span>\n    </span>\n  );\n}\n"}]}