{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"proof-of-work","type":"registry:component","title":"Proof Of Work","description":"A big title over a grid of work that flies in, or tumbles into view, as you scroll.","author":"DiMaac (HankTheTank) <https://dimaac.com>","dependencies":["gsap","@gsap/react"],"files":[{"path":"registry/dimaac/proof-of-work/proof-of-work.tsx","type":"registry:component","target":"components/dimaac/proof-of-work.tsx","content":"\"use client\";\n\nimport { useRef, type CSSProperties } from \"react\";\nimport { gsap } from \"gsap\";\nimport { ScrollTrigger } from \"gsap/ScrollTrigger\";\nimport { useGSAP } from \"@gsap/react\";\n\n// A title with a grid of work under it. Each piece arrives as you scroll to it, and there are two\n// ways it can arrive:\n//   \"rise\"  the picture flies up from below, tipped over 50 degrees, and settles upright\n//   \"fall\"  the picture sits under a solid tile, and the tile tumbles away down the page\n// The grid is plain CSS, so it works with any number of columns. Only the arrival is animated, so\n// with no JavaScript, or with reduced motion, every picture is simply there.\n\nif (typeof window !== \"undefined\") gsap.registerPlugin(useGSAP, ScrollTrigger);\n\nexport type ProofOfWorkItem = {\n  /** Address of the picture. */\n  image: string;\n  /** Alt text for the picture. Falls back to the title. */\n  imageAlt?: string;\n  /** The name of the piece, shown in capitals under the picture. */\n  title: string;\n  /** A short line under the title, such as the kind of work. */\n  subtitle?: string;\n};\n\nexport type ProofOfWorkProps = {\n  /** The pieces, in reading order. */\n  works: ProofOfWorkItem[];\n  /** The big heading above the grid. */\n  title?: string;\n  /** A small line under the heading. Leave it out to hide it. */\n  tagline?: string;\n  /** Which tag the heading uses. Pick h1 when this is the main title of the page. */\n  titleAs?: \"h1\" | \"h2\" | \"h3\";\n  /** How a piece arrives: \"rise\" flies the picture up from below, \"fall\" drops a cover tile away from it. */\n  effect?: \"rise\" | \"fall\";\n  /** How many columns the grid has from tablet width up. It is always one column on a phone. */\n  columns?: number;\n  /** The shape of every picture as a CSS aspect-ratio, e.g. \"4 / 5\", \"1 / 1\" or \"16 / 10\". */\n  aspectRatio?: string;\n  /** For \"rise\": how far each picture is tipped over before it settles, in degrees. The direction alternates. */\n  rotation?: number;\n  /** For \"rise\": how far below its place each picture starts, in pixels (a little less on phones). */\n  distance?: number;\n  /** How long one arrival takes, in seconds. */\n  duration?: number;\n  /** Extra wait for each column after the first, in seconds, so a row arrives left to right. */\n  columnDelay?: number;\n  /** The GSAP ease of the arrival. */\n  ease?: string;\n  /** For \"fall\": the colour of the cover tile. \"currentColor\" follows the text colour, so it works in light and dark. */\n  coverColor?: string;\n  /** Show a small running number next to each title. */\n  showNumbers?: boolean;\n  /** Play the arrival again, backwards, when you scroll back up past a piece. Off means it plays once. */\n  replay?: boolean;\n  /** When a piece arrives, as a ScrollTrigger start such as \"top 85%\". Leave it out for a good default per effect. */\n  start?: string;\n  /** The scrolling element. Leave it out to use the page; give it a selector or an element for an inner scroller. */\n  scroller?: string | HTMLElement;\n  /** Extra classes for the outer box. Set a background and a text colour here. */\n  className?: string;\n  /** Extra classes for the heading, e.g. a font family. */\n  titleClassName?: string;\n  /** Extra classes for each picture box, e.g. a radius. */\n  imageClassName?: string;\n};\n\n// The grid switches from one column to many at the same width as Tailwind's md: breakpoint\nconst WIDE_SCREEN = \"(min-width: 768px)\";\n\nexport function ProofOfWork({\n  works,\n  title = \"Proof of Work\",\n  tagline,\n  titleAs: Heading = \"h2\",\n  effect = \"rise\",\n  columns = 2,\n  aspectRatio = \"4 / 5\",\n  rotation = 50,\n  distance = 500,\n  duration = 1,\n  columnDelay = 0.25,\n  ease = \"power2.inOut\",\n  coverColor = \"currentColor\",\n  showNumbers = true,\n  replay = false,\n  start,\n  scroller,\n  className = \"\",\n  titleClassName = \"\",\n  imageClassName = \"\",\n}: ProofOfWorkProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n\n  useGSAP(\n    () => {\n      const root = rootRef.current;\n      if (!root) return;\n\n      const mm = gsap.matchMedia();\n\n      // Reduced motion adds nothing here: every picture stays where the page put it\n      mm.add({ motion: \"(prefers-reduced-motion: no-preference)\", wide: WIDE_SCREEN }, (context) => {\n        const { motion, wide } = context.conditions ?? {};\n        if (!motion) return;\n\n        const items = gsap.utils.toArray<HTMLElement>(\"[data-pow-item]\", root);\n        const columnCount = wide ? Math.max(1, Math.round(columns)) : 1;\n        const trigger = start ?? (effect === \"fall\" ? \"top 80%\" : \"top 88%\");\n        const scrollerBox = typeof scroller === \"string\" ? document.querySelector<HTMLElement>(scroller) : scroller;\n        const viewHeight = () => scrollerBox?.clientHeight ?? window.innerHeight;\n        // Phones are short, so the pictures start a little closer\n        const rise = wide ? distance : distance * 0.7;\n\n        items.forEach((item, index) => {\n          const media = item.querySelector<HTMLElement>(\"[data-pow-media]\");\n          const cover = item.querySelector<HTMLElement>(\"[data-pow-cover]\");\n          const caption = item.querySelector<HTMLElement>(\"[data-pow-caption]\");\n          if (!media) return;\n\n          // Each piece has its own timeline, started by its own ScrollTrigger. It plays once by default.\n          const arrival = gsap.timeline({\n            scrollTrigger: {\n              trigger: item,\n              scroller,\n              start: trigger,\n              once: !replay,\n              toggleActions: \"play none none reverse\",\n            },\n          });\n          // Pieces further along the row arrive a beat later\n          const wait = (index % columnCount) * columnDelay;\n\n          if (effect === \"rise\") {\n            arrival.fromTo(\n              media,\n              { rotation: index % 2 === 0 ? -rotation : rotation, y: rise, opacity: 0, transformOrigin: \"50% 50%\" },\n              { rotation: 0, y: 0, opacity: 1, duration, ease },\n              wait,\n            );\n          } else if (cover) {\n            // The tile is hidden by default so the page works without JavaScript. Show it now.\n            gsap.set(cover, { autoAlpha: 1 });\n            arrival.to(\n              cover,\n              {\n                x: () => gsap.utils.random(-100, 100),\n                // Far enough to leave the screen, but never past the bottom of this component\n                y: () => {\n                  const room = root.getBoundingClientRect().bottom - item.getBoundingClientRect().top;\n                  return Math.min(viewHeight() * 2 + gsap.utils.random(0, 400), room + 80);\n                },\n                rotation: () => gsap.utils.random(-180, 180),\n                // Near the bottom of the component the tile fades out, so it never gets cut off in view\n                opacity: () => (root.getBoundingClientRect().bottom - item.getBoundingClientRect().top < viewHeight() * 2 ? 0 : 1),\n                duration: duration * 1.35,\n                ease: \"power3.in\",\n              },\n              wait,\n            );\n            arrival.set(cover, { autoAlpha: 0 });\n          }\n\n          if (caption) {\n            arrival.fromTo(caption, { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.7, ease: \"power2.out\" }, wait + duration * 0.45);\n          }\n        });\n\n        // Fonts and pictures change the page height after the first measure, so measure again.\n        // A short delay turns a burst of changes into one measure.\n        let measure: gsap.core.Tween | undefined;\n        const observer = new ResizeObserver(() => {\n          measure?.kill();\n          measure = gsap.delayedCall(0.2, () => ScrollTrigger.refresh());\n        });\n        observer.observe(root);\n\n        return () => {\n          measure?.kill();\n          observer.disconnect();\n        };\n      });\n\n      return () => mm.revert();\n    },\n    { scope: rootRef, dependencies: [works.length, effect, columns, rotation, distance, duration, columnDelay, ease, replay, start, scroller], revertOnUpdate: true },\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={`relative w-full overflow-clip px-[clamp(1rem,4vw,4rem)] pt-[clamp(3rem,8vw,6rem)] pb-[clamp(4rem,12vh,10rem)] ${className}`}\n      style={{ \"--pow-columns\": Math.max(1, Math.round(columns)) } as CSSProperties}\n    >\n      <div className=\"mx-auto max-w-[1400px]\">\n        <header className=\"mb-[clamp(2.5rem,7vw,6rem)] text-center\">\n          <Heading className={`m-0 text-[clamp(2.75rem,13vw,11rem)] leading-[0.92] font-normal tracking-[-0.03em] ${titleClassName}`}>{title}</Heading>\n          {tagline ? <p className=\"mt-5 text-[11px] tracking-[0.18em] uppercase opacity-60\">{tagline}</p> : null}\n        </header>\n\n        <ul className=\"m-0 grid list-none grid-cols-1 gap-x-[clamp(1rem,3vw,3rem)] gap-y-[clamp(2.5rem,6vw,5rem)] p-0 md:grid-cols-[repeat(var(--pow-columns),minmax(0,1fr))]\">\n          {works.map((work, index) => (\n            <li key={`${index}-${work.image}`} data-pow-item className=\"group relative isolate min-w-0\" style={{ zIndex: works.length - index }}>\n              <figure className=\"m-0\">\n                <div className=\"relative\">\n                  <div\n                    data-pow-media\n                    className={`relative overflow-hidden ${imageClassName}`}\n                    style={{ aspectRatio, backgroundColor: \"color-mix(in srgb, currentColor 10%, transparent)\", willChange: \"transform, opacity\" }}\n                  >\n                    <img\n                      src={work.image}\n                      alt={work.imageAlt ?? work.title}\n                      loading=\"lazy\"\n                      decoding=\"async\"\n                      draggable={false}\n                      className=\"block h-full w-full object-cover transition-transform duration-[900ms] ease-out group-hover:scale-[1.04] motion-reduce:transition-none\"\n                    />\n                  </div>\n                  {/* The cover sits outside the clipped picture box, so it can tumble out of it */}\n                  {effect === \"fall\" ? <div data-pow-cover aria-hidden=\"true\" className={`invisible absolute inset-0 z-[2] ${imageClassName}`} style={{ backgroundColor: coverColor, willChange: \"transform\" }} /> : null}\n                </div>\n                <figcaption data-pow-caption className=\"mt-3 flex items-baseline justify-between gap-4\">\n                  <span className=\"min-w-0\">\n                    <span className=\"block text-[13px] font-semibold tracking-[0.04em] uppercase\">{work.title}</span>\n                    {work.subtitle ? <span className=\"mt-1 block text-[13px] opacity-65\">{work.subtitle}</span> : null}\n                  </span>\n                  {showNumbers ? (\n                    <span aria-hidden=\"true\" className=\"text-[11px] tabular-nums opacity-45\">\n                      {String(index + 1).padStart(2, \"0\")}\n                    </span>\n                  ) : null}\n                </figcaption>\n              </figure>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </div>\n  );\n}\n"}],"categories":["scroll","scrolltrigger","grid","portfolio","reveal","images"],"docs":"import { ProofOfWork } from \"@/components/dimaac/proof-of-work\". Give its parent a size: it fills it. Docs, playground and props: https://ui.dimaac.com/components/proof-of-work","meta":{"tier":"free","preview":"https://ui.dimaac.com/components/proof-of-work","credits":[{"by":"Kuba","url":"https://www.lummi.ai/photo/abstract-eye-close-up-uamae","what":"Abstract Eye Close-Up","source":"Lummi","licence":"Lummi License"},{"by":"Semihan Dosunmu","url":"https://www.lummi.ai/photo/avant-garde-fashion-pose-1yqoo","what":"Avant-Garde Fashion Pose","source":"Lummi","licence":"Lummi License"},{"by":"rena","url":"https://www.lummi.ai/photo/modern-architectural-design-aozka","what":"Modern Architectural Design","source":"Lummi","licence":"Lummi License"},{"by":"Dona Mara","url":"https://www.lummi.ai/photo/elegant-perfume-bottle-j5t5p","what":"Elegant Perfume Bottle","source":"Lummi","licence":"Lummi License"},{"by":"Ricardo Matos","url":"https://www.lummi.ai/photo/surreal-3d-planet-scene-ofhhw","what":"Surreal 3D Planet Scene","source":"Lummi","licence":"Lummi License"},{"by":"Beth Design Studio","url":"https://www.lummi.ai/photo/desert-wanderer-9puhu","what":"Desert Wanderer","source":"Lummi","licence":"Lummi License"},{"by":"Amino","url":"https://www.lummi.ai/photo/vivid-portrait-on-pink-oxbow","what":"Vivid Portrait on Pink","source":"Lummi","licence":"Lummi License"},{"by":"Viri Gutiérrez","url":"https://www.lummi.ai/photo/contemplative-silhouette-against-modern-minimalist-architecture-1-haa","what":"Contemplative Silhouette against Modern Minimalist Architecture","source":"Lummi","licence":"Lummi License"},{"by":"Bernardo Lickfold","url":"https://www.lummi.ai/photo/portrait-through-orange-frame-kld5i","what":"Portrait Through Orange Frame","source":"Lummi","licence":"Lummi License"},{"by":"Amino","url":"https://www.lummi.ai/photo/elegant-perfume-bottles-vnjg1","what":"Elegant Perfume Bottles","source":"Lummi","licence":"Lummi License"},{"by":"Nika","url":"https://www.lummi.ai/photo/intricate-natural-texture-buk3_","what":"Intricate Natural Texture","source":"Lummi","licence":"Lummi License"},{"by":"SHIHO","url":"https://www.lummi.ai/photo/vibrant-cylindrical-arrangement-pj9pp","what":"Vibrant Cylindrical Arrangement","source":"Lummi","licence":"Lummi License"}]}}