{"@context":"https://schema.org","@type":"WebPage","specVersion":"llm-replica/1.0","type":"docs-file","title":"MentionsDeck.tsx | Luis Krötz Docs","description":"MentionsDeck.tsx — code (12663 bytes)","route":"/docs/website/components/carousel/MentionsDeck.tsx","locale":"en","language":"en","canonical":"https://luiskr.com/docs/website/components/carousel/MentionsDeck.tsx","alternates":{"en":"https://luiskr.com/llm/en/docs/website/components/carousel/MentionsDeck.tsx.md"},"replicas":{"markdown":"https://luiskr.com/llm/en/docs/website/components/carousel/MentionsDeck.tsx.md","json":"https://luiskr.com/llm/en/docs/website/components/carousel/MentionsDeck.tsx.json"},"content":{"kind":"file","name":"MentionsDeck.tsx","path":"website/components/carousel/MentionsDeck.tsx","format":"code","size":12663,"mtime":"2026-11-12T12:58:25.677Z","docsContent":"https://luiskr.com/docs-content/website/components/carousel/MentionsDeck.tsx.json","text":"/**\n * @file MentionsDeck.tsx\n * @description <mentions-deck> — the \"Some mentions\" card deck inside the\n * home contact band: award/mention cards in a flat edge-to-edge strip\n * centered on the front card, auto-advancing on a dwell clock (≥50%\n * visibility + reduced-motion gated), dragged or swiped horizontally (or\n * stepped with dots + arrow keys). Shows the skeleton strip while\n * mention data loads.\n *\n * Facade — behavior lives in ./mentions-deck-* modules:\n *   mentions-deck/deck          strip geometry, measurement, pose + chrome writes\n *   mentions-deck/gestures      pointer-drag tracking (slop/velocity/settle)\n *   mentions-deck/interactions  goTo/click/nav/keys\n *   mentions-deck/autoplay      dwell-clock auto-advance + pause/resume\n *   mentions-deck/observer      ≥50% visibility gate + resize refit\n *   mentions-deck/events        scoped listener bindings\n *   mentions-deck/render        JSX template\n */\n\nimport { COMPONENT_TAGS } from '@core/tokens/elements/components.js'\nimport { MENTIONS_DECK_SELECTORS } from '@core/tokens/selectors/mentions-deck.js'\nimport { MENTIONS_DECK_LAYOUT } from '@core/tokens/motion/mentions-deck.js'\nimport { TRANSLATION_KEYS } from '@core/tokens/routes/translation-keys.js'\nimport { CHAR_STRINGS } from '@core/tokens/strings/chars.js'\nimport { BaseComponent } from '@core/Component.js'\nimport store from '@core/store.js'\nimport { FALLBACK_PAGES } from '@core/locale/fallback.js'\nimport { applyAnimationDesc } from '@core/utils/a11y/animation-desc.js'\nimport { ANIMATION_IDS } from '@core/tokens/data/animation-ids.js'\nimport mentionsDeckStyles from '@core/sass/components/carousel/mentions-deck.scss?tiers'\nimport {\n  startAutoplay,\n  stopAutoplay,\n  tickAutoplay,\n  pauseAutoplay,\n  resumeAutoplay,\n} from './mentions-deck/autoplay.js'\nimport { bindEvents } from './mentions-deck/events.js'\nimport { applyPoses, measure, updateChrome } from './mentions-deck/deck.js'\nimport {\n  cardIdxFromEvent,\n  goTo,\n  onCardClick,\n  onDotClick,\n  onKeyDown,\n} from './mentions-deck/interactions.js'\nimport { onPointerDown, onPointerEnd, onPointerMove } from './mentions-deck/gestures.js'\nimport { onResize, setupObserver } from './mentions-deck/observer.js'\nimport { renderMentionsDeck } from './mentions-deck/render.js'\nimport type { MentionItem, MentionsDeckTranslations } from './mentions-deck/types.js'\n\n/**\n * Bundled default heading for <mentions-deck> with any trailing colon stripped\n * so \"Some mentions:\" renders as \"SOME MENTIONS\" per the reference design.\n */\nconst DEFAULT_MENTIONS_TITLE = (\n  FALLBACK_PAGES[TRANSLATION_KEYS.ABOUT] as { mentions: string }\n).mentions.replace(/\\s*:\\s*$/, CHAR_STRINGS.EMPTY)\n\n/**\n * <mentions-deck> element — a looping flat strip for the award/mention\n * rows. Ring-offset geometry means the loop wraps natively (no clone\n * slides); a dwell-clock autoplay advances the front card while ≥50%\n * visible, and pointer drags slide the strip 1:1 with slop/flick settle.\n * All behavior delegates to `./mentions-deck/*`; this class is the state\n * holder + custom-element facade.\n */\nexport class MentionsDeck extends BaseComponent {\n  /** Mention rows pushed by the host — [] renders the skeleton strip. */\n  _items: MentionItem[] = []\n  /** Locale strings for the deck chrome (pages/HOME node). */\n  _translations: MentionsDeckTranslations | null = null\n  /** Section heading — defaults to the bundled about.mentions copy. */\n  _title: string = DEFAULT_MENTIONS_TITLE\n  /** Deck index of the front card. */\n  activeIdx = 0\n  /** Autoplay dwell per front card (ms) — pushes the strip when idle. */\n  duration: number = MENTIONS_DECK_LAYOUT.AUTOPLAY_MS\n  /** Measured card width px. */\n  _cardW: number = MENTIONS_DECK_LAYOUT.CARD_W_FALLBACK\n  _cardH: number = MENTIONS_DECK_LAYOUT.CARD_W_FALLBACK * MENTIONS_DECK_LAYOUT.CARD_H_RATIO\n  _step: number = MENTIONS_DECK_LAYOUT.CARD_W_FALLBACK * (1 + MENTIONS_DECK_LAYOUT.GAP_RATIO)\n  /** Front-card anchor x (px) — the strip centers on this point; it also\n   *  doubles as the edge distance the card dissolve measures against. */\n  _anchor: number = MENTIONS_DECK_LAYOUT.CARD_W_FALLBACK * MENTIONS_DECK_LAYOUT.ANCHOR_FRAC\n  /** Edge-dissolve lane px — card width × FADE_FRAC on wide decks, 0 on\n   *  mobile so partial neighbours peek at full opacity under the clip. */\n  _fadeSpan: number = MENTIONS_DECK_LAYOUT.CARD_W_FALLBACK * MENTIONS_DECK_LAYOUT.FADE_FRAC\n  /** Card width/height writes pending after a measure(). */\n  _sizesDirty = true\n  /** Live drag offset px — the strip's virtual front is activeIdx - _dragX/_step. */\n  _dragX = 0\n  _dragStartX = 0 // pointer-down clientX\n  _dragStartY = 0 // pointer-down clientY\n  _lastPX = 0 // last coalesced sample clientX (velocity window)\n  _lastT = 0 // last coalesced sample timestamp\n  _velX = 0 // flick velocity px/ms\n  _dragActive = false // slop committed — the gesture owns the strip\n  _gestureDead = false // vertical scroll won — ignore until next pointer-down\n  _pointerId: number | null = null // tracked pointer id (null = no gesture)\n  _suppressClick = false // trailing click after a committed drag — swallowed once\n  _rafId: number | null = null // pending pose write rAF\n  _cardEls: Element[] = [] // cached card nodes — the rAF loop never re-queries\n  _deckEl: Element | null = null // cached deck region — pose/size writes target it\n  /** Print job in flight — gates measure/applyPoses so the live posers\n   *  can't rewrite the inline fan geometry print.ts stripped for the\n   *  flat paper list. */\n  _printing = false\n  /** Any viewport visibility ever observed. */\n  isEnteredViewport = false\n  /** ≥50% visible — the autoplay gate. */\n  isFullyVisible = false\n  /** RAF cycle active flag. */\n  autoplayRunning = false\n  /** performance.now() at cycle start. */\n  autoplayStart: number | null = null\n  /** Accumulated pause→resume offset so dwell survives interruptions. */\n  autoplayElapsed = 0\n  /** Autoplay RAF handle. */\n  autoplayRafId: number | null = null\n  /** IntersectionObserver handle driving the visibility flags. */\n  observer: IntersectionObserver | null = null\n\n  constructor() {\n    super(mentionsDeckStyles)\n  }\n\n  /** The one-rAF-per-frame pose write armed by the drag path — a bound\n   *  field so the gesture loop allocates zero closures per frame. */\n  _dragTick = () => {\n    this._rafId = null\n\n    applyPoses(this)\n  }\n\n  /** Setter/getter — mention rows pushed by the host (identity-guarded\n   *  so repeat pushes with identical data don't restart autoplay). */\n\n  set items(val: MentionItem[] | null | undefined) {\n    const newItems = Array.isArray(val) ? val : []\n\n    if (\n      this._items === newItems ||\n      (this._items.length === newItems.length && this._items.every((it, i) => it === newItems[i]))\n    ) {\n      return\n    }\n\n    this._items = newItems\n\n    if (this._items.length && this.activeIdx >= this._items.length) {\n      this.activeIdx = this._items.length - 1\n    }\n\n    if (this._isMounted) {\n      this._updateDom()\n    }\n  }\n\n  get items(): MentionItem[] {\n    return this._items\n  }\n\n  /** Setter/getter — locale strings for the deck chrome. */\n\n  set translations(val: MentionsDeckTranslations | null) {\n    if (this._translations === val) return\n\n    this._translations = val\n\n    if (this._isMounted) {\n      this._updateDom()\n    }\n  }\n\n  get translations(): MentionsDeckTranslations | null {\n    return this._translations\n  }\n\n  /** Setter/getter — section heading text. */\n\n  override set title(val: string | null | undefined) {\n    const newTitle = (val || DEFAULT_MENTIONS_TITLE).replace(/\\s*:\\s*$/, CHAR_STRINGS.EMPTY)\n\n    if (this._title === newTitle) return\n\n    this._title = newTitle\n\n    if (this._isMounted) this._updateDom()\n  }\n\n  override get title(): string {\n    return this._title\n  }\n\n  /** Resolved copy — live translations over the build-time English\n   *  snapshot, so the hint renders text before Firebase resolves. */\n\n  get _t(): Required<MentionsDeckTranslations> {\n    const fb = FALLBACK_PAGES[TRANSLATION_KEYS.HOME] as Required<MentionsDeckTranslations>\n\n    return { ...fb, ...(this._translations as MentionsDeckTranslations) }\n  }\n\n  /** Mount: wire events/observer, subscribe to the store for reduced-motion/overlay. */\n  override onMounted() {\n    bindEvents(this)\n\n    setupObserver(this)\n\n    this.subscribe(store)\n\n    // The strip's slide motion is the carousel animation class — its\n    // crawler description already ships under components.animations.\n    applyAnimationDesc(this, ANIMATION_IDS.CAROUSEL)\n  }\n\n  /** Re-caches card nodes + re-measures after every render, then republishes\n   *  poses/chrome against the fresh DOM. */\n\n  override onUpdated() {\n    this._cardEls = this.$$(MENTIONS_DECK_SELECTORS.MENTIONS_DECK_CARD)\n\n    this._deckEl = this.$(MENTIONS_DECK_SELECTORS.MENTIONS_DECK_DECK)\n\n    measure(this)\n\n    applyPoses(this)\n\n    updateChrome(this)\n  }\n\n  /**\n   * Pref commits → kill autoplay immediately (no residual RAF); an\n   * overlay closing resumes a stopped cycle only when the deck is still\n   * ≥50% on screen. The !autoplayRunning guard matters: store commits\n   * arrive for unrelated state too, and a bare _startAutoplay would\n   * re-base the dwell clock on every commit.\n   */\n  override onStoreUpdate() {\n    if (store.getters.getReducedMotion() || store.getters.getOverlayOpen()) {\n      this._stopAutoplay()\n    } else if (this.isFullyVisible && !this.autoplayRunning) {\n      this._startAutoplay()\n    }\n  }\n\n  /** Teardown: stop RAF + observer — every async handle is released so nothing fires after disconnect. */\n  override onDestroy() {\n    this._stopAutoplay()\n\n    if (this.observer) {\n      this.observer.disconnect()\n\n      this.observer = null\n    }\n\n    if (this._rafId !== null) {\n      cancelAnimationFrame(this._rafId)\n\n      this._rafId = null\n    }\n  }\n\n  // ─── Delegates — ./mentions-deck/* ─────────────────────────────────────────\n  /** Deck measurement — see mentions-deck/deck.ts. */\n  measure(): void {\n    measure(this)\n  }\n  /** Strip pose write — see mentions-deck/deck.ts. */\n  applyPoses(): void {\n    applyPoses(this)\n  }\n  /** Dots/a11y refresh — see mentions-deck/deck.ts. */\n  updateChrome(): void {\n    updateChrome(this)\n  }\n  /** Navigate the strip to a deck index — see mentions-deck/interactions.ts. */\n  goTo(idx: number): void {\n    goTo(this, idx)\n  }\n  /** Dot-nav click. */\n  onDotClick(idx: number): void {\n    onDotClick(this, idx)\n  }\n  /** Card activation — side cards reposition, front card navigates. */\n  onCardClick(item: MentionItem, idx: number): void {\n    onCardClick(this, item, idx)\n  }\n  /** Delegated keydown — arrows step the strip. */\n  onKeyDown(e: Event): void {\n    onKeyDown(this, e)\n  }\n  /** Card/index resolution for the click path — see interactions.ts. */\n  cardIdxFromEvent(e: Event): { el: Element; idx: number } | null {\n    return cardIdxFromEvent(e)\n  }\n  /** Pointer-down drag arm — see mentions-deck/gestures.ts. */\n  onPointerDown(e: Event): void {\n    onPointerDown(this, e)\n  }\n  /** Pointer-move drag tracking — see mentions-deck/gestures.ts. */\n  onPointerMove(e: Event): void {\n    onPointerMove(this, e)\n  }\n  /** Pointer-up/cancel settle — see mentions-deck/gestures.ts. */\n  onPointerEnd(e: Event): void {\n    onPointerEnd(this, e)\n  }\n  /** Starts the autoplay RAF cycle (gated by visibility + reduced-motion). */\n  _startAutoplay(): void {\n    startAutoplay(this)\n  }\n  /** Stops the autoplay RAF cycle. */\n  _stopAutoplay(): void {\n    stopAutoplay(this)\n  }\n  /** Freezes the dwell clock (hover, committed drag). */\n  _pauseAutoplay(): void {\n    pauseAutoplay(this)\n  }\n  /** Re-arms the dwell clock after a pause. */\n  _resumeAutoplay(): void {\n    resumeAutoplay(this)\n  }\n  /** One autoplay frame — advances when dwell elapsed, then self-schedules. */\n  _tickAutoplay(): void {\n    tickAutoplay(this)\n  }\n  /** Creates the IntersectionObserver driving isEnteredViewport/isFullyVisible. */\n  _setupObserver(): void {\n    setupObserver(this)\n  }\n  /** Resize handler — remeasures card geometry and re-poses. */\n  _onResize(): void {\n    onResize(this)\n  }\n\n  /** JSX template (delegate — ./mentions-deck/render.tsx). */\n\n  override render() {\n    return renderMentionsDeck(this)\n  }\n}\n\n// Registration guard: define() throws on duplicate tag — `get` check keeps\n// module re-evaluation (HMR, coverage re-imports) safe.\nif (!customElements.get(COMPONENT_TAGS.MENTIONS_DECK)) {\n  customElements.define(COMPONENT_TAGS.MENTIONS_DECK, MentionsDeck)\n}\n","breadcrumbs":[{"name":"Website Module","path":"/docs/website"},{"name":"components","path":"/docs/website/components"},{"name":"carousel","path":"/docs/website/components/carousel"}]},"policy":{"ai-train":"yes","search":"yes","ai-input":"yes"},"generator":"generate-llm-pages.mjs","generated":"2026-11-19T15:46:51.755Z"}
