{
  "id": "flip-bento-grid",
  "kind": "element",
  "title": "Flip bento grid",
  "summary": "A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.",
  "url": "https://enrichr.dev/elements/flip-bento-grid.html",
  "section": "gallery",
  "techniques": [
    "pointer-interaction"
  ],
  "stack": [
    "Vanilla JS",
    "CSS"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "playful",
    "polished"
  ],
  "intents": [
    "bento grid hover expand",
    "flip animation image grid",
    "photo grid tile grows on hover",
    "gsap flip bento gallery without gsap",
    "animated css grid layout change"
  ],
  "status": "tested",
  "params": [
    {
      "key": "grow",
      "label": "Large tile size (x small tiles)",
      "type": "range",
      "min": 1.5,
      "max": 5,
      "step": 0.5,
      "value": 3
    },
    {
      "key": "duration",
      "label": "Move duration (s)",
      "type": "range",
      "min": 0.1,
      "max": 1.5,
      "step": 0.05,
      "value": 0.4
    },
    {
      "key": "gap",
      "label": "Gap (px)",
      "type": "range",
      "min": 0,
      "max": 40,
      "step": 1,
      "value": 15
    },
    {
      "key": "radius",
      "label": "Corner radius (px)",
      "type": "range",
      "min": 0,
      "max": 40,
      "step": 1,
      "value": 12
    },
    {
      "key": "tour",
      "label": "Auto tour (s between steps, 0 = off)",
      "type": "range",
      "min": 0,
      "max": 8,
      "step": 0.5,
      "value": 2.5
    },
    {
      "key": "background",
      "label": "Background",
      "type": "color",
      "value": "#0c1e18"
    },
    {
      "key": "edge",
      "label": "Tile edge and glow",
      "type": "color",
      "value": "#fbf8f1"
    },
    {
      "key": "accent",
      "label": "Focus ring",
      "type": "color",
      "value": "#e6ff55"
    }
  ],
  "license": "Free to use in personal and client projects during the preview. Final licence terms will be published here before any paid tier starts; ask before reselling the code as a collection.",
  "contract": "function mount(root, opts) -> { update(partialOpts), destroy() }; root must contain the element markup",
  "exports": {
    "claude": "Add the \"Flip bento grid\" element to this project.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSteps:\n1. Look at the project first to see its framework and where components, styles and static files live. Follow its conventions.\n2. Fetch https://enrichr.dev/elements/flip-bento-grid.json if you can read URLs (fields: source.markup, source.css, source.js, params); otherwise use the source at the end of this message.\n3. Add the files, mount it where I tell you (default: the top of the home page), and pass the settings below as the opts.\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n5. Run the dev server and check it. with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "chatgpt": "I want the \"Flip bento grid\" element on my website. Below is its complete source. Please:\n1. Build one self-contained index.html that I can open locally to see it working (put the CSS in a <style> tag and the JavaScript in a <script> tag, with the markup in the body).\n2. Then explain, step by step, which parts go where in my own site, and how to mount it. My stack is: [tell me yours, or say \"plain HTML\"].\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "cursor": "Add the \"Flip bento grid\" element to this codebase.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nUse Composer / agent mode. First search the repo for how components, styles and scripts are organised, then add the files in the matching places, mount it on the page I name, and run the app to confirm it works. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nOptional: save this as .cursor/rules/enrichr-flip-bento-grid.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Flip bento grid element\nalwaysApply: false\n---\nmount(root, opts) expects the element markup inside root and returns { update, destroy }. Always call destroy() on unmount and never edit the ef- class names.",
    "v0": "Create a Next.js (App Router) client component for the \"Flip bento grid\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- flip-bento-grid.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nUse this component as the wrapper (adjust the import paths):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./flip-bento-grid\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function FlipBentoGrid(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRender it on the home page so I can see it. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "lovable": "Add the \"Flip bento grid\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- flip-bento-grid.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nWrapper component (src/components/FlipBentoGrid.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./flip-bento-grid\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function FlipBentoGrid(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRemove the \"use client\" line if it is not needed. Show it on the home page. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "bolt": "Create a small Vite project (vanilla JavaScript, no framework unless I already have one) that shows the \"Flip bento grid\" element.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, then a script tag), style.css (the CSS below), flip-bento-grid.js (the JavaScript below) and main.js that sets the container's innerHTML to the markup and calls mount(container, opts) with the settings below. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "replit": "Create a new HTML, CSS and JavaScript Repl that shows the \"Flip bento grid\" element. No packages, no server code.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, link style.css, load flip-bento-grid.js and then main.js), style.css (the CSS below), flip-bento-grid.js (the JavaScript below), main.js (sets the container's innerHTML to the markup, then calls mount(container, opts) with the settings below). Press Run to preview. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "figma": "Designer handoff notes for the \"Flip bento grid\" element (Enrichr Library). Figma cannot run this JavaScript inside a design file, so use it as a motion reference and hand the code to a developer.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nWhat it does: The photos sit in a CSS grid with three columns and three rows. The large tile's column and row get 3fr and the others 1fr, so hovering a tile only has to change two grid-template values. The move uses FLIP, the technique GSAP Flip is built on: measure every tile, switch the tracks, measure again, then pin each tile with position absolute at its old box and tween left, top, width and height to the new box over 0.4 seconds with a power2.out ease. Tweening the size rather than a scale keeps each photo cropped with object-fit cover instead of stretched. If the pointer reaches another tile mid-move, the first measurement is taken from where the tiles are on screen, so the grid never jumps. Leaving the grid puts the centre tile back. An optional auto tour enlarges tiles in turn while nobody is hovering, which is what makes the Library preview move.\nAccessibility: Every tile is focusable with the Tab key and focus enlarges it exactly like hover; leaving the grid with the keyboard restores the centre tile. Each photo has alt text and a visible lime focus ring. On touch screens a tap picks a tile. With prefers-reduced-motion the layout still changes but instantly, with no tween, and the auto tour is off.\n\nTunable settings:\n- Large tile size (x small tiles): range 1.5 to 5, step 0.5, default 3\n- Move duration (s): range 0.1 to 1.5, step 0.05, default 0.4\n- Gap (px): range 0 to 40, step 1, default 15\n- Corner radius (px): range 0 to 40, step 1, default 12\n- Auto tour (s between steps, 0 = off): range 0 to 8, step 0.5, default 2.5\n- Background: color, default #0c1e18\n- Tile edge and glow: color, default #fbf8f1\n- Focus ring: color, default #e6ff55\n\nCurrent settings:\n{{SETTINGS}}\n\nFor the developer: Element contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nIn Figma:\n- Draw the resting state as a frame and the end state as a second frame; link them with Smart Animate to show the motion in a prototype.\n- Put the settings above in the frame's notes or Dev Mode annotations so the developer matches them.\n- Link https://enrichr.dev/elements/flip-bento-grid.html in the handoff: the live demo and the copy-ready code are there. Developers can paste the prompts for Claude, Cursor or v0 from the Export menu.\nNothing is copied from another designer's file; this is original code from Enrichr.",
    "framer": "Add the \"Flip bento grid\" element to Framer as a code component. Framer code components are React, so wrap the vanilla code like this. Check it in the Framer editor, as Framer's component API can change.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. In Framer: Assets > Code > New component. Name it FlipBentoGrid.\n2. Paste the JavaScript below into a separate code file named flip-bento-grid.js in the same project, with  export { mount };  and  export const markup = \"<the markup string>\";  added. Put the CSS into the component as a <style> tag.\n3. Component:\n```tsx\nimport { addPropertyControls, ControlType } from \"framer\"\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./flip-bento-grid\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function FlipBentoGrid(props: any) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n\naddPropertyControls(FlipBentoGrid, {\n  grow: { type: ControlType.Number, title: \"Large tile size\", min: 1.5, max: 5, step: 0.5, defaultValue: 3 },\n  duration: { type: ControlType.Number, title: \"Move duration\", min: 0.1, max: 1.5, step: 0.05, defaultValue: 0.4 },\n  gap: { type: ControlType.Number, title: \"Gap\", min: 0, max: 40, step: 1, defaultValue: 15 },\n  radius: { type: ControlType.Number, title: \"Corner radius\", min: 0, max: 40, step: 1, defaultValue: 12 },\n  tour: { type: ControlType.Number, title: \"Auto tour\", min: 0, max: 8, step: 0.5, defaultValue: 2.5 },\n  background: { type: ControlType.Color, title: \"Background\", defaultValue: \"#0c1e18\" },\n  edge: { type: ControlType.Color, title: \"Tile edge and glow\", defaultValue: \"#fbf8f1\" },\n  accent: { type: ControlType.Color, title: \"Focus ring\", defaultValue: \"#e6ff55\" },\n})\n```\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "webflow": "Add the \"Flip bento grid\" element to a Webflow site with an Embed element. Test it on the published or preview site: scripts in embeds may not run inside the Designer canvas.\n\nThis is the \"Flip bento grid\" element from the Enrichr Library: A 3 by 3 bento grid of photos where the one under the pointer grows into the big tile and the rest reflow around it, animated with FLIP.\nPage: https://enrichr.dev/elements/flip-bento-grid.html\nMachine-readable spec: https://enrichr.dev/elements/flip-bento-grid.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. Add an Embed element where it should appear. Paste a <style> block with the CSS, one container <div id=\"enrichr-flip-bento-grid\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-flip-bento-grid\"), { ...your settings... });\n   (set the container's innerHTML to the markup first, as in the contract).\n2. Embed elements have a size limit (check Webflow's current number). If the code is longer, host the JS and CSS as files and link them from Custom code in the page settings, then keep only the container and the mount call in the Embed.\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}"
  },
  "exportTools": [
    "claude",
    "chatgpt",
    "cursor",
    "v0",
    "lovable",
    "bolt",
    "replit",
    "figma",
    "framer",
    "webflow"
  ],
  "accessibility": "Every tile is focusable with the Tab key and focus enlarges it exactly like hover; leaving the grid with the keyboard restores the centre tile. Each photo has alt text and a visible lime focus ring. On touch screens a tap picks a tile. With prefers-reduced-motion the layout still changes but instantly, with no tween, and the auto tour is off.",
  "performance": "Nothing runs while the grid is still. A move animates nine boxes for 0.4 seconds with one requestAnimationFrame loop, and the inline styles are removed at the end so the grid goes back to plain CSS layout. The auto tour is a single timer that skips its step off screen and in hidden tabs, and a resize mid-move finishes the move at once.",
  "dependencies": [],
  "codepen": "https://codepen.io/Enrichr-Dev/pen/NPpeBOV",
  "source": {
    "markup": "<div class=\"ef-fbg\">\n  <div class=\"ef-fbg__grid\" role=\"group\" aria-label=\"Photo grid. Hover or focus a photo to make it the large one\">\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"0\" data-row=\"0\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-2.jpg\" alt=\"Corgi sitting in a field of flowers\" style=\"object-position: 50% 40%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"1\" data-row=\"0\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-4.jpg\" alt=\"A corgi and a terrier running down a dirt road\" style=\"object-position: 50% 60%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"2\" data-row=\"0\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-3.jpg\" alt=\"Corgi standing on a rock among autumn leaves\" style=\"object-position: 50% 45%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"0\" data-row=\"1\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-5.jpg\" alt=\"Corgi lying down on a white background\" style=\"object-position: 45% 50%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"1\" data-row=\"1\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-1.jpg\" alt=\"Corgi puppy in front of an orange wall\" style=\"object-position: 50% 35%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"2\" data-row=\"1\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-6.jpg\" alt=\"Corgi standing on a white background\" style=\"object-position: 50% 50%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"0\" data-row=\"2\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-3.jpg\" alt=\"Close crop of the corgi on the rock\" style=\"object-position: 30% 70%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"1\" data-row=\"2\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-2.jpg\" alt=\"Close crop of the flowers around the corgi\" style=\"object-position: 50% 85%\" decoding=\"async\"></div>\n    <div class=\"ef-fbg__item\" tabindex=\"0\" data-col=\"2\" data-row=\"2\"><img class=\"ef-fbg__img\" src=\"/img/library/corgi-4.jpg\" alt=\"Close crop of the dirt road\" style=\"object-position: 85% 50%\" decoding=\"async\"></div>\n  </div>\n</div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-fbg { --ef-fbg-gap: 15px; --ef-fbg-r: 12px; --ef-fbg-bg: #0c1e18; --ef-fbg-edge: #fbf8f1; --ef-fbg-acc: #e6ff55; position: relative; width: 100%; min-height: 26rem; box-sizing: border-box; overflow: hidden; border-radius: 1rem; background: var(--ef-fbg-bg); }\n.ef-fbg .ef-fbg__grid { position: absolute; inset: 5%; margin: auto; max-width: 1000px; max-height: 800px; display: grid; gap: var(--ef-fbg-gap); grid-template-columns: 1fr 3fr 1fr; grid-template-rows: 1fr 3fr 1fr; }\n.ef-fbg .ef-fbg__item { position: relative; box-sizing: border-box; min-width: 0; min-height: 0; margin: 0; overflow: hidden; cursor: pointer; border-radius: var(--ef-fbg-r); border: 1px solid color-mix(in srgb, var(--ef-fbg-edge) 50%, transparent); box-shadow: 0 4px 6px color-mix(in srgb, var(--ef-fbg-edge) 25%, transparent); background: color-mix(in srgb, var(--ef-fbg-edge) 8%, var(--ef-fbg-bg)); outline: none; -webkit-tap-highlight-color: transparent; }\n.ef-fbg .ef-fbg__item:hover, .ef-fbg .ef-fbg__item:focus-visible { z-index: 10; }\n.ef-fbg .ef-fbg__item:focus-visible { box-shadow: 0 0 0 3px var(--ef-fbg-acc), 0 4px 6px color-mix(in srgb, var(--ef-fbg-edge) 25%, transparent); }\n.ef-fbg .ef-fbg__img { position: absolute; inset: 0; z-index: 1; display: block; width: 100%; height: 100%; max-width: none; margin: 0; object-fit: cover; user-select: none; -webkit-user-drag: none; pointer-events: none; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Flip bento grid: a 3 by 3 grid of photos where the photo under the pointer takes the big middle-sized track and the\n// others reflow around it. The hovered tile's column and row become the large track (3fr against 1fr by default); when\n// the pointer leaves the grid the centre tile is large again. Every change is animated with FLIP: measure each tile, switch\n// the grid tracks, measure again, then pin each tile absolutely at its old box and tween left, top, width and height to the\n// new box over 0.4 s with a power2.out ease (1 - (1 - p)^3), the same as GSAP Flip.from with absolute: true. A new hover\n// mid-move starts from where the tiles are on screen, so nothing jumps. Keyboard focus works like hover; a tap picks a tile\n// on touch screens. An optional tour enlarges tiles in turn while nobody is hovering, so a preview moves on its own.\n// Reduced motion switches the layout instantly and turns the tour off. The tour pauses off screen and in hidden tabs.\n// mount(root, { grow (large track, x the small ones), duration (s), gap (px), radius (px), tour (s between tour steps, 0 = off),\n//               background, edge (tile border and glow), accent (focus ring) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var box = root.querySelector(\".ef-fbg\");\n  var grid = root.querySelector(\".ef-fbg__grid\");\n  var items = Array.prototype.slice.call(root.querySelectorAll(\".ef-fbg__item\"));\n  var TOUR = [0, 8, 2, 6, 5, 1, 3, 7, 4]; // tile indexes the tour visits: corners, then edges, then home\n  var opts = {}, col = 1, row = 1, raf = 0, start = 0, from = null, to = null;\n  var inside = false, focused = false, visible = true, io = null, ro = null, tourTimer = 0, tourStep = 0, destroyed = false, offs = [];\n\n  function num(v, d) { v = Number(v); return isFinite(v) ? v : d; }\n  function tracks(active) { var t = [1, 1, 1]; t[active] = opts.grow; return t.map(function (v) { return v + \"fr\"; }).join(\" \"); }\n  function layout() { grid.style.gridTemplateColumns = tracks(col); grid.style.gridTemplateRows = tracks(row); }\n  // each tile's box inside the grid's padding box, as it is drawn right now (mid-animation included)\n  function measure() {\n    var g = grid.getBoundingClientRect();\n    return items.map(function (el) {\n      var r = el.getBoundingClientRect();\n      return { x: r.left - g.left - grid.clientLeft, y: r.top - g.top - grid.clientTop, w: r.width, h: r.height };\n    });\n  }\n  function place(el, b) { var s = el.style; s.position = \"absolute\"; s.left = b.x + \"px\"; s.top = b.y + \"px\"; s.width = b.w + \"px\"; s.height = b.h + \"px\"; }\n  function release() { items.forEach(function (el) { var s = el.style; s.position = s.left = s.top = s.width = s.height = \"\"; }); }\n  function ease(p) { return 1 - Math.pow(1 - p, 3); } // GSAP power2.out\n  function frame(now) {\n    var p = Math.min(1, (now - start) / (opts.duration * 1000)), e = ease(p);\n    items.forEach(function (el, i) {\n      var a = from[i], b = to[i];\n      place(el, { x: a.x + (b.x - a.x) * e, y: a.y + (b.y - a.y) * e, w: a.w + (b.w - a.w) * e, h: a.h + (b.h - a.h) * e });\n    });\n    if (p < 1) raf = requestAnimationFrame(frame);\n    else { raf = 0; release(); }\n  }\n  function stop() { if (raf) { cancelAnimationFrame(raf); raf = 0; } release(); }\n  // FLIP: First (where the tiles are now), Last (where the new tracks put them), Invert (pin them at First), Play\n  function flip(c, r) {\n    if (c === col && r === row) return;\n    var first = measure();\n    if (raf) { cancelAnimationFrame(raf); raf = 0; }\n    release();\n    col = c; row = r; layout();\n    if (reduce || opts.duration <= 0 || !box.isConnected) return;\n    var last = measure();\n    from = first; to = last;\n    items.forEach(function (el, i) { place(el, first[i]); });\n    start = performance.now();\n    raf = requestAnimationFrame(frame);\n  }\n  function pick(el) { flip(num(el.getAttribute(\"data-col\"), 1), num(el.getAttribute(\"data-row\"), 1)); }\n\n  function idle() { return !inside && !focused; }\n  function schedule() {\n    clearTimeout(tourTimer); tourTimer = 0;\n    if (reduce || destroyed || !(opts.tour > 0)) return;\n    tourTimer = setTimeout(tourTick, opts.tour * 1000);\n  }\n  function tourTick() {\n    tourTimer = 0;\n    if (destroyed) return;\n    if (idle() && visible && !document.hidden) { pick(items[TOUR[tourStep % TOUR.length]] || items[4]); tourStep++; }\n    schedule();\n  }\n\n  function on(el, type, fn) { el.addEventListener(type, fn); offs.push(function () { el.removeEventListener(type, fn); }); }\n  items.forEach(function (el) {\n    on(el, \"pointerenter\", function () { inside = true; clearTimeout(tourTimer); pick(el); });\n    on(el, \"focus\", function () { focused = true; clearTimeout(tourTimer); pick(el); });\n  });\n  // leaving the grid puts the centre tile back, like the original's mouseleave; a lifted finger is not a leave\n  on(grid, \"pointerleave\", function (e) { if (e.pointerType === \"touch\") return; inside = false; flip(1, 1); schedule(); });\n  on(grid, \"focusout\", function (e) { if (grid.contains(e.relatedTarget)) return; focused = false; if (!inside) flip(1, 1); schedule(); });\n\n  function update(next) {\n    opts = Object.assign({ grow: 3, duration: 0.4, gap: 15, radius: 12, tour: 2.5, background: \"#0c1e18\", edge: \"#fbf8f1\", accent: \"#e6ff55\" }, opts, next || {});\n    opts.grow = Math.max(1, num(opts.grow, 3)); opts.duration = Math.max(0, num(opts.duration, 0.4));\n    opts.gap = Math.max(0, num(opts.gap, 15)); opts.radius = Math.max(0, num(opts.radius, 12)); opts.tour = Math.max(0, num(opts.tour, 2.5));\n    box.style.setProperty(\"--ef-fbg-gap\", opts.gap + \"px\");\n    box.style.setProperty(\"--ef-fbg-r\", opts.radius + \"px\");\n    box.style.setProperty(\"--ef-fbg-bg\", opts.background);\n    box.style.setProperty(\"--ef-fbg-edge\", opts.edge);\n    box.style.setProperty(\"--ef-fbg-acc\", opts.accent);\n    if (destroyed) return;\n    stop(); layout();\n    if (idle()) schedule();\n  }\n\n  update(o);\n  if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(box); }\n  // a resize mid-move would leave tiles pinned at stale boxes; finish the move and let the grid reflow\n  if (\"ResizeObserver\" in window) { ro = new ResizeObserver(function () { if (raf) stop(); }); ro.observe(box); }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; stop(); clearTimeout(tourTimer);\n      offs.forEach(function (f) { f(); }); offs = [];\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n    }\n  };\n}"
  }
}