//#region src/value/scroll/offsets.ts /** * Preset scroll offsets matching framer-motion's ScrollOffset presets. * Use with useScroll's offset option to define scroll-linked animation ranges. * * @example * useScroll({ target: el, offset: ScrollOffset.Enter }) */ var ScrollOffset = { /** Progress 0→1 as target enters the container */ Enter: [[0, 1], [1, 1]], /** Progress 0→1 as target exits the container */ Exit: [[0, 0], [1, 0]], /** Progress 0→1 across any overlap between target and container */ Any: [[1, 0], [0, 1]], /** Progress 0→1 while target is fully contained within the container */ All: [[0, 0], [1, 1]] }; var presets = [ [ScrollOffset.Enter, "entry"], [ScrollOffset.Exit, "exit"], [ScrollOffset.Any, "cover"], [ScrollOffset.All, "contain"] ]; var stringToProgress = { start: 0, end: 1 }; function parseStringOffset(s) { const parts = s.trim().split(/\s+/); if (parts.length !== 2) return void 0; const a = stringToProgress[parts[0]]; const b = stringToProgress[parts[1]]; if (a === void 0 || b === void 0) return void 0; return [a, b]; } function normaliseOffset(offset) { if (offset.length !== 2) return void 0; const result = []; for (const item of offset) if (Array.isArray(item)) result.push(item); else if (typeof item === "string") { const parsed = parseStringOffset(item); if (!parsed) return void 0; result.push(parsed); } else return; return result; } function matchesPreset(offset, preset) { const normalised = normaliseOffset(offset); if (!normalised) return false; for (let i = 0; i < 2; i++) { const o = normalised[i]; const p = preset[i]; if (o[0] !== p[0] || o[1] !== p[1]) return false; } return true; } /** * Maps a ScrollOffset array to a ViewTimeline named range. * Returns undefined for unrecognised patterns — signals fallback to JS scroll tracking. * * Ported from framer-motion's internal render/dom/scroll/utils/offset-to-range.mjs */ function offsetToViewTimelineRange(offset) { if (!offset) return { rangeStart: "contain 0%", rangeEnd: "contain 100%" }; for (const [preset, name] of presets) if (matchesPreset(offset, preset)) return { rangeStart: `${name} 0%`, rangeEnd: `${name} 100%` }; } //#endregion export { ScrollOffset, offsetToViewTimelineRange };