{"version":3,"file":"styloviz-core-gestures.mjs","names":[],"sources":["../../../../projects/core/gestures/swipe-gesture.ts","../../../../projects/core/gestures/swipe-reveal.ts"],"sourcesContent":["/**\n * swipe-gesture.ts — the one drag-to-dismiss gesture the kit's sliding\n * surfaces share (FL-J3-OF-20, `OF-05-M3`).\n *\n * ★★★ IT WAS WRITTEN ONCE, IN THE SIDEBAR, AND THE DRAWER NEEDED IT TOO. The\n *     sidebar's drawer followed a finger and closed past a third of its width;\n *     the Drawer — the same surface with four edges — had no gesture at all,\n *     and the action sheet planned on top of it needs the same one again. So\n *     the tracking lives here, and each surface keeps only its own rule for\n *     WHEN a release dismisses.\n *\n * What it owns, and every caller would otherwise get subtly different:\n *\n *  - **Touch and pen only** — a mouse drag over a panel is a text selection.\n *    The caller decides by not calling `svSwipeGesture` for `pointerType ===\n *    'mouse'`; {@link svIsSwipePointer} says the same thing in one place.\n *  - **Axis lock** — nothing is reported until the pointer has moved 8px, and\n *    then only if it moved along the gesture's axis. A vertical scroll inside\n *    a side drawer must never drag the drawer.\n *  - **Velocity** — measured over the last 100 ms of movement, so a flick that\n *    covers 40px quickly can dismiss where a slow 40px drag springs back.\n *  - **Teardown** — document listeners exist only while a finger is down, and\n *    the returned function removes them (call it on destroy).\n */\n\n/** The physical direction a surface leaves in. */\nexport type SvSwipeDirection = 'left' | 'right' | 'up' | 'down';\n\n/** A finished gesture, measured along its direction. */\nexport interface SvSwipeSample {\n  /** Pixels moved toward `toward` (negative when moved the other way). */\n  readonly travel: number;\n  /** Speed toward `toward` at release, in px/ms (negative when moving away). */\n  readonly velocity: number;\n}\n\n/** Options for {@link svSwipeGesture}. */\nexport interface SvSwipeGestureOptions {\n  /** The direction that counts as positive travel. Read when the gesture starts. */\n  readonly toward: SvSwipeDirection;\n  /** Each move along the axis, with the travel so far. */\n  readonly onMove?: (travel: number) => void;\n  /**\n   * The release. `null` when the gesture never locked onto this axis (a\n   * scroll, a tap) — the caller should just reset.\n   */\n  readonly onEnd: (sample: SvSwipeSample | null) => void;\n}\n\n/** Pixels of movement before a gesture commits to an axis. */\nconst AXIS_LOCK_PX = 8;\n/** The window velocity is measured over. */\nconst VELOCITY_WINDOW_MS = 100;\n\n/** True for the pointers a swipe belongs to: touch and pen, never a mouse. */\nexport function svIsSwipePointer(event: PointerEvent): boolean {\n  return event.pointerType !== 'mouse';\n}\n\n/**\n * Track one swipe from `start` (a `pointerdown`). Returns a function that\n * stops tracking without reporting — call it from the owner's destroy.\n */\nexport function svSwipeGesture(start: PointerEvent, options: SvSwipeGestureOptions): () => void {\n  if (typeof document === 'undefined') return () => undefined;\n  const horizontal = options.toward === 'left' || options.toward === 'right';\n  const sign = options.toward === 'right' || options.toward === 'down' ? 1 : -1;\n  let axis: 'x' | 'y' | null = null;\n  let travel = 0;\n  const samples: { t: number; travel: number }[] = [{ t: stamp(start), travel: 0 }];\n\n  const move = (e: PointerEvent): void => {\n    const dx = e.clientX - start.clientX;\n    const dy = e.clientY - start.clientY;\n    if (axis === null && Math.hypot(dx, dy) > AXIS_LOCK_PX) axis = Math.abs(dx) > Math.abs(dy) ? 'x' : 'y';\n    if (axis !== (horizontal ? 'x' : 'y')) return;\n    travel = (horizontal ? dx : dy) * sign;\n    const t = stamp(e);\n    samples.push({ t, travel });\n    while (samples.length > 2 && t - samples[0].t > VELOCITY_WINDOW_MS) samples.shift();\n    options.onMove?.(travel);\n  };\n\n  let done = false;\n  const stop = (): void => {\n    if (done) return;\n    done = true;\n    document.removeEventListener('pointermove', move);\n    document.removeEventListener('pointerup', end);\n    document.removeEventListener('pointercancel', end);\n  };\n  const end = (): void => {\n    stop();\n    if (axis !== (horizontal ? 'x' : 'y')) { options.onEnd(null); return; }\n    const first = samples[0];\n    const last = samples[samples.length - 1];\n    const dt = last.t - first.t;\n    options.onEnd({ travel, velocity: dt > 0 ? (last.travel - first.travel) / dt : 0 });\n  };\n\n  document.addEventListener('pointermove', move);\n  document.addEventListener('pointerup', end);\n  document.addEventListener('pointercancel', end);\n  return stop;\n}\n\n/** Thresholds for {@link svSwipeDismisses}. */\nexport interface SvSwipeDismissRule {\n  /** Pixels of travel that always dismiss. @default min(96, extent / 3) */\n  readonly distance?: number;\n  /** Speed (px/ms) that dismisses a shorter flick. `0` turns flicks off. @default 0.5 */\n  readonly velocity?: number;\n}\n\n/**\n * Whether a release dismisses: far enough, or fast enough toward the edge.\n *\n * ★ A flick still has to have MOVED (16px): a tap with a jittery finger can\n *   report a large instantaneous speed over two pixels.\n */\nexport function svSwipeDismisses(sample: SvSwipeSample | null, extent: number, rule: SvSwipeDismissRule = {}): boolean {\n  if (!sample || sample.travel <= 0) return false;\n  const distance = rule.distance ?? Math.min(96, extent / 3);\n  if (sample.travel > distance) return true;\n  const velocity = rule.velocity ?? 0.5;\n  return velocity > 0 && sample.travel >= 16 && sample.velocity >= velocity;\n}\n\n/** The event's own time — every real event has one; a synthetic one may not. */\nfunction stamp(e: Event): number {\n  if (typeof e.timeStamp === 'number' && Number.isFinite(e.timeStamp)) return e.timeStamp;\n  return typeof performance !== 'undefined' ? performance.now() : Date.now();\n}\n","/**\n * swipe-reveal.ts — the rules for a row that slides aside to show actions\n * behind it (FL-F8, `sv-list-view`'s swipe actions).\n *\n * ★★ PURE, AND IN LOGICAL TERMS. A row reveals its START actions when it moves\n *    toward its end edge, and its END actions when it moves toward its start —\n *    right and left in a left-to-right page, the other way round in a\n *    right-to-left one. Every number here is already logical (positive = toward\n *    the end edge, revealing the start actions); the component converts the\n *    pointer's physical travel once, at the edge, with {@link svSwipeLogical}.\n *    Written once here so the free and Pro list views cannot drift apart on\n *    where a release lands.\n *\n * The gesture itself (touch/pen only, the 8px axis lock that leaves vertical\n * scrolling alone, velocity) is `svSwipeGesture`'s.\n */\n\n/** Which edge's actions are showing. */\nexport type SvSwipeRevealSide = 'start' | 'end';\n\n/** The geometry and options one release is judged against. */\nexport interface SvSwipeRevealRule {\n  /** The row's width in px. */\n  readonly width: number;\n  /** Width of one action button in px. */\n  readonly actionWidth: number;\n  /** How many actions sit behind the start edge (revealed by a positive offset). */\n  readonly startCount: number;\n  /** How many actions sit behind the end edge (revealed by a negative offset). */\n  readonly endCount: number;\n  /** May a long swipe run the side's first action outright? */\n  readonly fullSwipe: boolean;\n  /** Fraction of the row's width past which a release is a full swipe. @default 0.6 */\n  readonly fullSwipeRatio?: number;\n  /** Speed (px/ms) toward the open side that opens a short flick. @default 0.4 */\n  readonly flickVelocity?: number;\n}\n\n/** Where a release lands. */\nexport type SvSwipeRevealOutcome =\n  | { readonly kind: 'close' }\n  | { readonly kind: 'open'; readonly side: SvSwipeRevealSide }\n  | { readonly kind: 'commit'; readonly side: SvSwipeRevealSide };\n\n/** Physical travel → logical: in a right-to-left row, moving right is moving toward the start. */\nexport function svSwipeLogical(physical: number, rtl: boolean): number {\n  return rtl ? -physical : physical;\n}\n\n/** The width of one side's tray of actions. */\nexport function svSwipeTrayWidth(side: SvSwipeRevealSide, rule: Pick<SvSwipeRevealRule, 'actionWidth' | 'startCount' | 'endCount'>): number {\n  return (side === 'start' ? rule.startCount : rule.endCount) * rule.actionWidth;\n}\n\n/**\n * Where the row may be while a finger drags it.\n *\n * ★ A side with no actions does not move at all — a row that slides to show\n *   nothing reads as broken. Past its tray the row keeps following, which is\n *   what lets a full swipe happen, but never further than the row is wide.\n */\nexport function svSwipeClamp(offset: number, rule: SvSwipeRevealRule): number {\n  if (!Number.isFinite(offset)) return 0;\n  if (offset > 0 && rule.startCount === 0) return 0;\n  if (offset < 0 && rule.endCount === 0) return 0;\n  const limit = rule.fullSwipe ? rule.width : Math.max(svSwipeTrayWidth(offset > 0 ? 'start' : 'end', rule), 0);\n  return Math.max(-limit, Math.min(limit, offset));\n}\n\n/**\n * Judge a release.\n *\n * - Past `fullSwipeRatio` of the width (and `fullSwipe` on): **commit** the\n *   side's first action.\n * - A flick back toward the middle: **close**.\n * - Past half the tray, or a flick toward it after at least 16px: **open**.\n * - Anything else: **close**.\n *\n * @param offset   logical offset at release (already clamped)\n * @param velocity logical speed at release, px/ms (positive = toward the end edge)\n */\nexport function svSwipeRelease(offset: number, velocity: number, rule: SvSwipeRevealRule): SvSwipeRevealOutcome {\n  if (!Number.isFinite(offset) || offset === 0) return { kind: 'close' };\n  const side: SvSwipeRevealSide = offset > 0 ? 'start' : 'end';\n  const count = side === 'start' ? rule.startCount : rule.endCount;\n  if (count === 0) return { kind: 'close' };\n\n  const travel = Math.abs(offset);\n  const ratio = rule.fullSwipeRatio ?? 0.6;\n  if (rule.fullSwipe && rule.width > 0 && travel >= rule.width * ratio) return { kind: 'commit', side };\n\n  const tray = svSwipeTrayWidth(side, rule);\n  const toward = side === 'start' ? velocity : -velocity;\n  const flick = rule.flickVelocity ?? 0.4;\n  // A flick back toward the middle closes, wherever the row happens to be.\n  if (Number.isFinite(toward) && toward <= -flick) return { kind: 'close' };\n  if (travel >= tray / 2 || (travel >= 16 && Number.isFinite(toward) && toward >= flick)) return { kind: 'open', side };\n  return { kind: 'close' };\n}\n"],"mappings":"AAkDA,MAAM,eAAe;AAErB,MAAM,qBAAqB;AAG3B,SAAgB,iBAAiB,OAAmB;CAClD,OAAO,MAAM,gBAAgB;AAC/B;AAMA,SAAgB,eAAe,OAAqB,SAA8B;CAChF,IAAI,OAAO,aAAa,aAAa,aAAa;CAClD,MAAM,aAAa,QAAQ,WAAW,UAAU,QAAQ,WAAW;CACnE,MAAM,OAAO,QAAQ,WAAW,WAAW,QAAQ,WAAW,SAAS,IAAI;CAC3E,IAAI,OAAyB;CAC7B,IAAI,SAAS;CACb,MAAM,UAA2C,CAAC;EAAE,GAAG,MAAM,KAAK;EAAG,QAAQ;CAAC,CAAE;CAEhF,MAAM,QAAQ,MAAyB;EACrC,MAAM,KAAK,EAAE,UAAU,MAAM;EAC7B,MAAM,KAAK,EAAE,UAAU,MAAM;EAC7B,IAAI,SAAS,QAAQ,KAAK,MAAM,IAAI,EAAE,IAAI,cAAc,OAAO,KAAK,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,IAAI,MAAM;EACnG,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