{"version":3,"file":"_list-item-reveal.cjs","names":[],"sources":["../../../src/content/list/_list-item-reveal.ts"],"sourcesContent":["import { createPanGesture, type PanGesture, type PanGestureDetail } from '@vielzeug/gesture';\nimport type { Readable } from '@vielzeug/ripple';\nimport type { ListItemRevealSide } from './list-item';\n\n/** Drag distance (px) past which the action panel snaps fully open on release. */\nconst REVEAL_THRESHOLD = 64;\n/** Drag distance (px) past which the swipe auto-confirms the action — \"swiped all the way\". */\nconst CONFIRM_THRESHOLD = REVEAL_THRESHOLD * 3;\n/** Fraction of CONFIRM_THRESHOLD past which `data-confirming` warns the drag is about to fire. */\nconst CONFIRM_WARNING_RATIO = 0.85;\n\nexport type RevealStateOptions = {\n  disabled: Readable<boolean>;\n  hasActions: (side: ListItemRevealSide) => boolean;\n  /** The full-swipe-through gesture fired — emit `confirm` and click the slot's own action. */\n  onConfirm: (side: ListItemRevealSide) => void;\n};\n\n/**\n * The swipe-reveal-confirm gesture behind `ore-list-item`'s `actions-left`/`actions-right` slots\n * — isolated here since it's the one genuinely tricky part of the component (three distance\n * thresholds, inline style/attribute choreography during an active drag). Deliberately *not* a\n * shared primitive: `createPanGesture` itself already is one (shared with `ore-toast`),\n * but this two-stage reveal/confirm layer on top of it has exactly one consumer today —\n * generalizing it further would be speculative, not reusable.\n *\n * Only sets/clears the `revealed`/`data-dragging`/`data-confirming` attributes and `--_swipe-x`\n * style — it does not itself emit `reveal`/`conceal`. `ore-list-item` already watches `revealed`\n * for transitions (to cover *both* this gesture and a directly-set attribute uniformly), so this\n * module setting the attribute is enough to drive both that watcher and `list.css`'s\n * `[revealed]` styling.\n */\nexport function createRevealState(el: HTMLElement, target: Element, options: RevealStateOptions): PanGesture {\n  const resolveSide = (detail: PanGestureDetail): ListItemRevealSide => (detail.distance < 0 ? 'right' : 'left');\n\n  // Inline `--_swipe-x` override during an active drag lets the row (and both action panels,\n  // which read the same variable) follow the pointer 1:1 with no transition lag. Clearing it\n  // hands control back to the `[revealed]`/`:focus-within` CSS rules in list-item.css, which\n  // then animate normally via the CSS `transition`.\n  const resetInline = (): void => {\n    el.removeAttribute('data-dragging');\n    el.removeAttribute('data-confirming');\n    el.style.removeProperty('--_swipe-x');\n  };\n\n  let pan: PanGesture;\n\n  pan = createPanGesture(target, {\n    axis: 'x',\n    disabled: () => options.disabled.value,\n    onEnd: (detail) => {\n      resetInline();\n\n      if (detail.reason !== 'release') return;\n\n      const side = resolveSide(detail);\n\n      if (options.hasActions(side) && Math.abs(detail.distance) >= REVEAL_THRESHOLD) el.setAttribute('revealed', side);\n    },\n    onMove: (detail) => {\n      const side = resolveSide(detail);\n\n      if (!options.hasActions(side)) return;\n\n      const distance = Math.abs(detail.distance);\n\n      if (distance >= CONFIRM_THRESHOLD) {\n        pan.cancel();\n        el.removeAttribute('revealed');\n        options.onConfirm(side);\n\n        return;\n      }\n\n      const revealProgress = Math.min(distance / REVEAL_THRESHOLD, 1);\n\n      el.setAttribute('data-dragging', '');\n      el.toggleAttribute('data-confirming', distance / CONFIRM_THRESHOLD >= CONFIRM_WARNING_RATIO);\n      el.style.setProperty('--_swipe-x', String((side === 'left' ? 1 : -1) * revealProgress));\n    },\n    pointerCapture: false,\n  });\n\n  return pan;\n}\n"],"mappings":"mCAKA,IAAM,EAAmB,GAEnB,EAAoB,IAEpB,EAAwB,IAuB9B,SAAgB,EAAkB,EAAiB,EAAiB,EAAyC,CAC3G,IAAM,EAAe,GAAkD,EAAO,SAAW,EAAI,QAAU,OAMjG,MAA0B,CAC9B,EAAG,gBAAgB,eAAe,EAClC,EAAG,gBAAgB,iBAAiB,EACpC,EAAG,MAAM,eAAe,YAAY,CACtC,EAEI,EAsCJ,MApCA,IAAA,EAAM,EAAA,iBAAA,CAAiB,EAAQ,CAC7B,KAAM,IACN,aAAgB,EAAQ,SAAS,MACjC,MAAQ,GAAW,CAGjB,GAFA,EAAY,EAER,EAAO,SAAW,UAAW,OAEjC,IAAM,EAAO,EAAY,CAAM,EAE3B,EAAQ,WAAW,CAAI,GAAK,KAAK,IAAI,EAAO,QAAQ,GAAK,GAAkB,EAAG,aAAa,WAAY,CAAI,CACjH,EACA,OAAS,GAAW,CAClB,IAAM,EAAO,EAAY,CAAM,EAE/B,GAAI,CAAC,EAAQ,WAAW,CAAI,EAAG,OAE/B,IAAM,EAAW,KAAK,IAAI,EAAO,QAAQ,EAEzC,GAAI,GAAY,EAAmB,CACjC,EAAI,OAAO,EACX,EAAG,gBAAgB,UAAU,EAC7B,EAAQ,UAAU,CAAI,EAEtB,MACF,CAEA,IAAM,EAAiB,KAAK,IAAI,EAAW,EAAkB,CAAC,EAE9D,EAAG,aAAa,gBAAiB,EAAE,EACnC,EAAG,gBAAgB,kBAAmB,EAAW,GAAqB,CAAqB,EAC3F,EAAG,MAAM,YAAY,aAAc,QAAQ,IAAS,OAAS,EAAI,IAAM,CAAc,CAAC,CACxF,EACA,eAAgB,EAClB,CAAC,EAEM,CACT"}