{"version":3,"file":"tiltMath.mjs","names":[],"sources":["../../../../package/common/tilt/tiltMath.ts"],"sourcesContent":["export type TiltAxisLock = 'x' | 'y' | 'none';\n\nexport interface ComputeTiltOptions {\n  maxTiltX: number;\n  maxTiltY: number;\n  easing: (t: number) => number;\n  lockAxis: TiltAxisLock;\n}\n\nexport interface TiltResult {\n  rotateX: number;\n  rotateY: number;\n}\n\n/**\n * Eases faster near the edges (|t| close to 1) and flatter near the center (|t| close to 0),\n * while staying odd-symmetric so tilt direction always matches cursor direction.\n */\nexport function defaultTiltEasing(t: number): number {\n  const clamped = Math.max(-1, Math.min(1, t));\n  return Math.sign(clamped) * Math.pow(Math.abs(clamped), 1.6);\n}\n\nfunction clamp(value: number, max: number): number {\n  return Math.max(-max, Math.min(max, value));\n}\n\n/**\n * Computes the tilt rotation for a pointer at (x, y) relative to `rect`'s top-left corner.\n * Vertical cursor position drives rotateX (tilts top/bottom edges), horizontal drives rotateY.\n */\nexport function computeTilt(\n  x: number,\n  y: number,\n  rect: { width: number; height: number },\n  { maxTiltX, maxTiltY, easing, lockAxis }: ComputeTiltOptions,\n): TiltResult {\n  const nx = rect.width > 0 ? (x / rect.width) * 2 - 1 : 0;\n  const ny = rect.height > 0 ? (y / rect.height) * 2 - 1 : 0;\n\n  const rotateX = lockAxis === 'x' ? 0 : clamp(-easing(ny) * maxTiltX, maxTiltX);\n  const rotateY = lockAxis === 'y' ? 0 : clamp(easing(nx) * maxTiltY, maxTiltY);\n\n  return { rotateX, rotateY };\n}\n"],"mappings":"aAkBA,SAAgB,EAAkB,EAAmB,CACnD,IAAM,EAAU,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,CAAC,CAAC,EAC3C,OAAO,KAAK,KAAK,CAAO,EAAa,KAAK,IAAI,CAAO,GAAG,GAC1D,CAEA,SAAS,EAAM,EAAe,EAAqB,CACjD,OAAO,KAAK,IAAI,CAAC,EAAK,KAAK,IAAI,EAAK,CAAK,CAAC,CAC5C,CAMA,SAAgB,EACd,EACA,EACA,EACA,CAAE,WAAU,WAAU,SAAQ,YAClB,CACZ,IAAM,EAAK,EAAK,MAAQ,EAAK,EAAI,EAAK,MAAS,EAAI,EAAI,EACjD,EAAK,EAAK,OAAS,EAAK,EAAI,EAAK,OAAU,EAAI,EAAI,EAKzD,MAAO,CAAE,QAHO,IAAa,IAAM,EAAI,EAAM,CAAC,EAAO,CAAE,EAAI,EAAU,CAAQ,EAG3D,QAFF,IAAa,IAAM,EAAI,EAAM,EAAO,CAAE,EAAI,EAAU,CAAQ,CAElD,CAC5B"}