{"@context":"https://schema.org","@type":"WebPage","specVersion":"llm-replica/1.0","type":"docs-file","title":"info.ts | Luis Krötz Docs","description":"info.ts — code (17984 bytes)","route":"/docs/website/components/home/cardstack/info.ts","locale":"en","language":"en","canonical":"https://luiskr.com/docs/website/components/home/cardstack/info.ts","alternates":{"en":"https://luiskr.com/llm/en/docs/website/components/home/cardstack/info.ts.md"},"replicas":{"markdown":"https://luiskr.com/llm/en/docs/website/components/home/cardstack/info.ts.md","json":"https://luiskr.com/llm/en/docs/website/components/home/cardstack/info.ts.json"},"content":{"kind":"file","name":"info.ts","path":"website/components/home/cardstack/info.ts","format":"code","size":17984,"mtime":"2026-11-18T22:54:56.458Z","docsContent":"https://luiskr.com/docs-content/website/components/home/cardstack/info.ts.json","text":"/**\n * @file cardstack/info.ts — the active-project text column of\n * <card-stack>: splits a CMS item into title / body / route, and\n * republishes the column when the coverflow front changes. The title\n * rides the paper-burn — the old name combusts to ash, the text swaps\n * while the ink is hidden, and the same session rebuilds the new glyphs\n * (burn-out → burn-in). The description keeps its <draw-text> writer.\n */\n\nimport { ATTR_VALUES } from '@core/tokens/attrs/values.js'\nimport { COMMON_ATTRS } from '@core/tokens/attrs/common.js'\nimport { FORM_ATTRS } from '@core/tokens/attrs/form.js'\nimport { LINK_ATTRS } from '@core/tokens/attrs/link.js'\nimport { CARD_STACK_CLASSES } from '@core/tokens/classes/card-stack.js'\nimport { CARD_STACK_SELECTORS } from '@core/tokens/selectors/card-stack.js'\nimport { CARD_STACK_LAYOUT } from '@core/tokens/motion/card-stack.js'\nimport { COMPONENT_TAGS } from '@core/tokens/elements/components.js'\nimport { LOCALES } from '@core/tokens/locales.js'\nimport { ROUTE_PATHS } from '@core/tokens/routes/paths.js'\nimport store from '@core/store.js'\nimport { mountBurn } from '@core/utils/burn/mount.js'\nimport { frame } from '@core/utils/burn/loop.js'\nimport { setBurnDirWasm } from '@core/utils/burn/wasm.js'\nimport type { BurnCard, BurnClasses, BurnItem } from '@core/utils/burn/types.js'\nimport type { CardStackInfo, CardStackItem } from './types.js'\nimport type { CardStack } from '../CardStack.js'\n\n/**\n * The class-name contract the burn pipeline runs against — the text\n * column doubles as the title overlay (the combustion canvas anchors\n * inside it) and the details container. ITEM_BURNED stays undefined so\n * the rebuild flip is driven by the swap callback instead of a class.\n */\nconst BURN_CLS: BurnClasses = {\n  ITEM_BURNING: CARD_STACK_CLASSES.CARD_STACK_INFO_BURNING,\n  ITEM_BURNED: undefined,\n  TITLE_OVERLAY: CARD_STACK_CLASSES.CARD_STACK_INFO,\n  TITLE: CARD_STACK_CLASSES.CARD_STACK_INFO_TITLE,\n  TITLE_BURNING: CARD_STACK_CLASSES.CARD_STACK_INFO_TITLE_BURNING,\n  TITLE_BURN: CARD_STACK_CLASSES.CARD_STACK_INFO_TITLE_BURN,\n  TITLE_SLOT: CARD_STACK_CLASSES.CARD_STACK_INFO_TITLE_SLOT,\n  TITLE_DUP: CARD_STACK_CLASSES.CARD_STACK_INFO_TITLE_DUP,\n  TITLE_REWRITE: CARD_STACK_CLASSES.CARD_STACK_INFO_TITLE_REWRITE,\n  DETAILS: CARD_STACK_CLASSES.CARD_STACK_INFO,\n}\n\n/**\n * Localized destination URL for one project card — the language prefix\n * rides in front of /portfolio/<slug> on every non-English locale.\n * @param item Project metadata containing the route slug.\n * @returns Localized portfolio URL, or an empty string without a slug.\n */\nexport function projectHref(item: CardStackItem): string {\n  if (!item.link) return ATTR_VALUES.EMPTY\n\n  const lang = store.getters.getLang()\n\n  const prefix = lang === LOCALES.EN ? ATTR_VALUES.EMPTY : `${ROUTE_PATHS.ROOT}${lang}`\n\n  return `${prefix}${ROUTE_PATHS.PORTFOLIO}${item.link}`\n}\n\n/**\n * The first-sentence cut for the in-card summary — a sentence ender\n * (`.`, `!`, `?`) followed by whitespace/markup/end-of-string, or a\n * `<br>`/newline break. CMS descriptions lead with a one-line project\n * brief, so the first sentence IS the mobile summary.\n */\nconst SUMMARY_CUT = /[.!?](?=\\s|<)|<br\\s*\\/?>|\\n/\n\n/**\n * The stacked-card summary of a CMS description — the text up to the\n * first sentence ender (the ender kept) or the first markup break.\n * The full description stays mounted in the desktop text column on\n * every tier (visually hidden on stacked layouts but present in the\n * DOM), so search engines index the long-form copy as the canonical\n * description while the card copy reads as its summary — same content\n * at two lengths, both valid. A description with no sentence break\n * passes through whole — the uniform pile height sizes every card to\n * the tallest summary, so nothing truncates.\n * @param body The full CMS description (may carry `<br>` markup).\n * @returns The leading-sentence summary, or the input unchanged when\n *   no cut point exists.\n */\nfunction mobileSummary(body: string): string {\n  const cut = body.search(SUMMARY_CUT)\n\n  if (cut < 0) return body\n\n  const char = body[cut]\n\n  return body.slice(0, char === '<' || char === '\\n' ? cut : cut + 1)\n}\n\n/**\n * Everything the text column shows for one item.\n * @param item The portfolio item (undefined before data lands).\n * @returns The column copy — all-empty for a missing item.\n */\nexport function cardInfo(item: CardStackItem | undefined): CardStackInfo {\n  if (!item) {\n    return {\n      title: ATTR_VALUES.EMPTY,\n      body: ATTR_VALUES.EMPTY,\n      summary: ATTR_VALUES.EMPTY,\n      href: ATTR_VALUES.EMPTY,\n    }\n  }\n\n  return {\n    title: item.label || item.title || ATTR_VALUES.EMPTY,\n    body: item.description || ATTR_VALUES.EMPTY,\n    summary: item.description ? mobileSummary(item.description) : ATTR_VALUES.EMPTY,\n    href: projectHref(item),\n  }\n}\n\n/**\n * Re-targets one column slot's <draw-text> writer. Writing a new `text`\n * attribute replays the writer (DrawText resets + re-triggers on text\n * change); an unchanged value is a no-op there, so re-publishing the\n * same front never re-types. An empty text hides the whole slot — an\n * inline wrapper with no text would still take a line-height of room.\n * @param host The CardStack element.\n * @param sel The slot's selector.\n * @param text The slot's new text.\n */\nfunction setSlotText(host: CardStack, sel: string, text: string): void {\n  const slot = host.$(sel)\n\n  if (!slot) return\n\n  slot.toggleAttribute(COMMON_ATTRS.HIDDEN, !text)\n\n  slot.querySelector(COMPONENT_TAGS.DRAW_TEXT)?.setAttribute(FORM_ATTRS.TEXT, text)\n}\n\n/**\n * Publishes the next project name on the title — the paper-burn owns\n * the transition: the live session (or a freshly mounted one) consumes\n * whatever raster it holds, then at the consume beat the DOM text swaps\n * and the session flips into rebuild — `lastBox` is cleared so\n * syncPaper re-rasterizes the NEW title and deposit motes knit it back.\n * A live session is re-armed rather than stacked: mid-consume navs just\n * re-aim the beat to the latest name, and a mid-rebuild nav flips back\n * to consume from exactly where the knit left off (the same rebasing\n * armCardBurn applies on re-hover). Reduced motion or a degenerate box\n * (hidden column, zero rect) swaps instantly.\n * @param host The CardStack element.\n * @param item The item the burn paces itself on (description length).\n * @param next The title text to land on.\n */\nfunction burnTitle(host: CardStack, item: BurnItem | undefined, next: string): void {\n  const titleEl = host.$(CARD_STACK_SELECTORS.CARD_STACK_INFO_TITLE) as HTMLElement | null\n\n  if (!titleEl) return\n\n  // An empty name collapses the slot — an empty inline box would still\n  // take a line-height of room (and the burn would mount on a\n  // degenerate rect anyway).\n  titleEl.toggleAttribute(COMMON_ATTRS.HIDDEN, !next)\n\n  const infoEl = host.$(CARD_STACK_SELECTORS.CARD_STACK_INFO)\n\n  const session = infoEl ? (infoEl as BurnCard)._burn : null\n\n  // Idle fast-path — no burn pending and the ink already reads `next`.\n  if (titleEl.textContent === next && !session) return\n\n  const swap = (): void => {\n    titleEl.textContent = next\n\n    // The swap may land beats after this call — re-query so a rebuilt\n    // (or removed) column is consulted, not the mount-time node.\n    const live = (host.$(CARD_STACK_SELECTORS.CARD_STACK_INFO) as BurnCard | null)?._burn\n\n    if (live && live.dir > 0) {\n      // Consume beat: hand the rebuild the new raster — without this the\n      // frozen arm-time paper would knit the OLD name back.\n      live.lastBox = ATTR_VALUES.EMPTY\n\n      live.dir = -1\n\n      live.prog = 1\n    }\n  }\n\n  if (session) {\n    session.onBurned = swap\n\n    if (session.dir < 0) {\n      // Mid-knit — re-consume the partially rebuilt title from the point\n      // the rebuild reached (prog maps back onto the forward clock), so\n      // whatever text is under the needle burns out before `next` knits.\n      session.dir = 1\n\n      session.t = session.prog * (session.dur / 1000)\n\n      setBurnDirWasm(session)\n\n      if (!session.raf) session.raf = requestAnimationFrame(() => frame(session))\n    }\n\n    return\n  }\n\n  // Touch devices skip the canvas pipeline outright — the per-nav\n  // rasterize + deposit-mote pass costs a full composited layer the\n  // mobile GPU budget can't spare, so the title just swaps text.\n  if (\n    store.getters.getReducedMotion?.() ||\n    store.getters.getInputMethod?.() === COMMON_ATTRS.TOUCH ||\n    !infoEl\n  ) {\n    titleEl.textContent = next\n\n    return\n  }\n\n  if (\n    !mountBurn(\n      infoEl,\n      infoEl as HTMLElement,\n      titleEl,\n      item || {},\n      BURN_CLS,\n      CARD_STACK_LAYOUT.BURN_SPEED,\n      swap\n    )\n  ) {\n    titleEl.textContent = next\n  }\n}\n\n/**\n * The burn contract for the in-card project title — the card element\n * doubles as the session host and the canvas overlay (it is already\n * absolutely positioned, so it is the containing block the canvas\n * anchors to). ITEM_BURNED stays undefined: each card's title is\n * fixed text, so the burn only knits in / consumes — never swaps.\n */\nconst CARD_BURN_CLS: BurnClasses = {\n  ITEM_BURNING: CARD_STACK_CLASSES.CARD_STACK_CARD_BURNING,\n  ITEM_BURNED: undefined,\n  TITLE_OVERLAY: CARD_STACK_CLASSES.CARD_STACK_CARD,\n  TITLE: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO_TITLE,\n  TITLE_BURNING: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO_TITLE_BURNING,\n  TITLE_BURN: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO_TITLE_BURN,\n  TITLE_SLOT: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO_TITLE_SLOT,\n  TITLE_DUP: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO_TITLE_DUP,\n  TITLE_REWRITE: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO_TITLE_REWRITE,\n  DETAILS: CARD_STACK_CLASSES.CARD_STACK_CARD_INFO,\n}\n\n/**\n * The card element that held the front on the previous chrome pass —\n * the card whose in-card title burns OUT on the next nav. Keyed by host\n * so a re-rendered deck resets the baseline.\n */\nconst _burnFront = new WeakMap<CardStack, Element>()\n\n/**\n * Mounts or re-arms one card's in-card title burn toward `want` (1 =\n * consume, −1 = knit). A live session flips direction in place — a card\n * mid-knit that loses the front re-consumes from the knit point, and a\n * consumed session knits back when its card returns. A mount taken\n * while the section is held off-screen gets banked immediately so the\n * draw-in waits for the re-entry release. Reduced motion or a\n * degenerate box leaves the title's plain ink.\n * @param host The CardStack element.\n * @param cardEl The card whose title burns.\n * @param want Direction — 1 consume, −1 knit.\n * @param cards The deck's cached card list (item index lookup).\n */\nfunction spinCardBurn(host: CardStack, cardEl: Element, want: number, cards: Element[]): void {\n  const card = cardEl as BurnCard\n\n  const s = card._burn\n\n  if (s) {\n    if (s.dir !== want) {\n      s.dir = want\n\n      if (want < 0) s.prog = 1\n      else s.t = s.prog * (s.dur / 1000)\n\n      setBurnDirWasm(s)\n    }\n\n    // _burnHeld gates the re-arm — an off-screen nav retimes the\n    // session but the draw-in stays banked until holdBurns releases.\n    if (!s.raf && !host._burnHeld) s.raf = requestAnimationFrame(() => frame(s))\n\n    return\n  }\n\n  // Touch devices never arm in-card burns — the raster session costs a\n  // composited overlay per card the mobile GPU budget can't spare.\n  if (\n    store.getters.getReducedMotion?.() ||\n    store.getters.getInputMethod?.() === COMMON_ATTRS.TOUCH\n  ) {\n    return\n  }\n\n  const titleEl = cardEl.querySelector(\n    CARD_STACK_SELECTORS.CARD_STACK_CARD_INFO_TITLE\n  ) as HTMLElement | null\n\n  if (!titleEl) return\n\n  const idx = cards.indexOf(cardEl)\n\n  if (\n    !mountBurn(\n      cardEl,\n      cardEl as HTMLElement,\n      titleEl,\n      host.deckItems[idx] || {},\n      CARD_BURN_CLS,\n      CARD_STACK_LAYOUT.BURN_SPEED,\n      null\n    )\n  ) {\n    return\n  }\n\n  const ns = card._burn\n\n  if (ns && want < 0) {\n    ns.dir = -1\n\n    ns.prog = 1\n\n    setBurnDirWasm(ns)\n  }\n\n  // mountBurn self-arms its first frame — a mount taken while the\n  // section is held off-screen gets banked immediately so the\n  // draw-in waits for the re-entry release.\n  if (ns && host._burnHeld && ns.raf) {\n    cancelAnimationFrame(ns.raf)\n\n    ns.raf = 0\n  }\n}\n\n/**\n * Arms the outgoing front's burn-out BEFORE the pose pass drops\n * --active — goTo calls it ahead of applyPoses. The flip bottom-anchors\n * the card's info column instantly (in-flow → absolute bottom:0), so a\n * post-flip mount records the RELOCATED box ~130px above where the\n * title visibly stood — the raster then combusts the name on top of\n * the card's cover image and the burn reads as displaced. Mounting\n * pre-flip freezes the anchor at the last-lit in-flow geometry: the\n * burn plays where the title stood and rides the card's deal transform\n * out, glued. Live sessions just re-aim — a card mid-knit re-consumes\n * from the knit point.\n * @param host The CardStack element.\n */\nexport function armOutgoingTitleBurn(host: CardStack): void {\n  const tier = host._tier\n\n  // Same stacked+in-card-copy gate as burnCardTitles — image-only\n  // bands have no title to arm.\n  if (!tier?.STACKED || !tier.IN_CARD_INFO) return\n\n  const prev = _burnFront.get(host)\n\n  // activeIdx already holds the TARGET index when goTo calls this —\n  // _burnFront still names the card actually leaving the front. A\n  // re-click on the current front keeps the pairing intact.\n  if (!prev || prev === host._cardEls[host.activeIdx]) return\n\n  spinCardBurn(host, prev, 1, host._cardEls)\n}\n\n/**\n * The in-card paper-burn on stacked tiers — the front card's title\n * knits IN (the loop runs dir −1 from prog 1: deposit motes rebuild\n * the glyphs, then teardown hands the pristine raster back to the DOM\n * ink), and the card that just left the front burns OUT (the default\n * forward consume) as it slides into the pile. Live sessions flip\n * direction rather than stack: a card mid-knit that loses the front\n * re-consumes from the knit point, and a consumed session knits back\n * when its card returns. Reduced motion or a degenerate box leaves\n * the title's plain ink.\n * @param host The CardStack element.\n */\nexport function burnCardTitles(host: CardStack): void {\n  const tier = host._tier\n\n  // Image-only stacked bands (768–1279 landscape) hide the in-card\n  // copy — mounting a session on invisible titles just burns rAF.\n  if (!tier?.STACKED || !tier.IN_CARD_INFO) return\n\n  const cards = host._cardEls\n\n  const front = cards[host.activeIdx]\n\n  const prev = _burnFront.get(host)\n\n  _burnFront.set(host, front)\n\n  if (prev && prev !== front) spinCardBurn(host, prev, 1, cards)\n\n  if (front) spinCardBurn(host, front, -1, cards)\n}\n\n/**\n * Scroll-visibility hold for every burn session the deck owns — the\n * in-card title knits/consumes AND the text column's burn swap. The\n * section's IntersectionObserver calls it with the inverse of\n * isIntersecting: a hold cancels each live session's rAF in place\n * (prog/dir survive — the knit freezes exactly where it was, which\n * also stops an off-screen mount's first frame spending the draw-in\n * before the user ever sees it), and a release re-arms any session\n * still active so the draw animation plays out on the frame the\n * deck scrolls back into view. Sessions that already ran to\n * completion (`active` false) stay parked — a finished burn must not\n * resurrect on re-entry.\n * @param host The CardStack element.\n * @param held True while the section is off-screen.\n */\nexport function holdBurns(host: CardStack, held: boolean): void {\n  host._burnHeld = held\n\n  if (held) {\n    for (const cardEl of host._cardEls) {\n      const s = (cardEl as BurnCard)._burn\n\n      if (s?.raf) {\n        cancelAnimationFrame(s.raf)\n\n        s.raf = 0\n      }\n    }\n\n    const info = (host.$(CARD_STACK_SELECTORS.CARD_STACK_INFO) as BurnCard | null)?._burn\n\n    if (info?.raf) {\n      cancelAnimationFrame(info.raf)\n\n      info.raf = 0\n    }\n\n    return\n  }\n\n  // Release — the live pairing re-aims through burnCardTitles (each\n  // spin re-reads front/prev so a nav taken while held resolves to the\n  // current pairing, not a stale one). A nav taken WHILE held also\n  // orphans the previous front's parked session — _burnFront already\n  // advanced, so spin never visits it again — so every remaining\n  // parked session sweeps up with a direct re-arm alongside the text\n  // column's own (which has no spin caller either).\n  burnCardTitles(host)\n\n  for (const cardEl of host._cardEls) {\n    const s = (cardEl as BurnCard)._burn\n\n    if (s && !s.raf && s.active) {\n      s.raf = requestAnimationFrame(() => frame(s))\n    }\n  }\n\n  const info = (host.$(CARD_STACK_SELECTORS.CARD_STACK_INFO) as BurnCard | null)?._burn\n\n  if (info && !info.raf && info.active) {\n    info.raf = requestAnimationFrame(() => frame(info))\n  }\n}\n\n/**\n * Publishes the front card's copy into the text column without a\n * re-render — the title burns out/in, the description writer re-types,\n * and the \"Check out\" link follows the new route (`hidden` when the\n * item has none, so no dead link stays focusable). On stacked tiers\n * the same burn also fires on the in-card project titles.\n * @param host The CardStack element.\n */\nexport function writeInfo(host: CardStack): void {\n  const item = host.deckItems[host.activeIdx]\n\n  const info = cardInfo(item)\n\n  burnTitle(host, item, info.title)\n\n  setSlotText(host, CARD_STACK_SELECTORS.CARD_STACK_INFO_DESC, info.body)\n\n  // The in-card summary is plain static text (draw-text is a\n  // desktop-only writer living in the column above) — nothing here\n  // touches it, so a swipe can never clear/retype the copy and every\n  // card's measured box stays constant.\n\n  const cta = host.$(CARD_STACK_SELECTORS.CARD_STACK_INFO_CTA)\n\n  if (!cta) return\n\n  cta.setAttribute(LINK_ATTRS.HREF, info.href)\n\n  cta.toggleAttribute(COMMON_ATTRS.HIDDEN, !info.href)\n\n  burnCardTitles(host)\n}\n","breadcrumbs":[{"name":"Website Module","path":"/docs/website"},{"name":"components","path":"/docs/website/components"},{"name":"home","path":"/docs/website/components/home"},{"name":"cardstack","path":"/docs/website/components/home/cardstack"}]},"policy":{"ai-train":"yes","search":"yes","ai-input":"yes"},"generator":"generate-llm-pages.mjs","generated":"2026-11-19T15:46:51.755Z"}
