/** * ค่าคงที่ของ motion (ใช้ร่วมทุกหน้า) * * สคริปต์นี้ถูกฝังใน (root.tsx) และรันก่อน paint เพื่อใส่คลาส `fx-motion` * ให้ เฉพาะเมื่อผู้ใช้ไม่ได้ขอ reduced motion → เนื้อหาไม่กระพริบตอนโหลด * และถ้าปิด JS ไว้ก็ไม่มีคลาสนี้ = ไม่มีอะไรถูกซ่อน (progressive enhancement) */ export const MOTION_INIT_SCRIPT = `(function(){try{var m=window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)");if(m&&m.matches){return}document.documentElement.classList.add("fx-motion")}catch(e){}})();`; /** รูปแบบการโผล่ของบล็อก — ตรงกับ selector `[data-reveal="…"]` ใน global.css */ export type RevealKind = "rise" | "fade" | "zoom"; /** * เลื่อนหน้าไปที่ element โดยเคารพการตั้งค่า "ลดการเคลื่อนไหว" ของผู้ใช้ * (ผู้ที่ปิดอนิเมชันจะกระโดดไปทันที ไม่มีการเลื่อนแบบ smooth) */ export function scrollIntoViewRespectMotion( element: HTMLElement | null, block: ScrollLogicalPosition = "start", ): void { if (!element) return; const reduceMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches; element.scrollIntoView({ behavior: reduceMotion ? "auto" : "smooth", block, }); }