diff --git a/DESIGN.md b/DESIGN.md index 54dbe78..c8b0d5d 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -74,8 +74,14 @@ part of that build, not leave them as an empty template. ## Motion contract (บังคับ) -- อนิเมชันทั้งหมดอยู่ใน `app/global.css` ใต้ `html.fx-motion` — คลาสนี้ถูกใส่โดยสคริปต์ใน `` (`MOTION_INIT_SCRIPT`, `app/lib/motion.ts`) **เฉพาะเมื่อผู้ใช้ไม่ได้ขอ `prefers-reduced-motion: reduce`** → ปิด JS หรือ reduced motion = ไม่มีอะไรถูกซ่อน (ห้ามเขียน `opacity:0` นอกขอบเขตนี้) -- ใช้ `transform`/`opacity` เท่านั้น ห้าม animate `width/height/top/left` · ระยะเวลา: เร็ว 160ms · ปกติ 280ms · **เปลี่ยนหน้า 460ms (`--fx-page`)** · reveal 640ms · หน่วงต่อชิ้นไม่เกิน ~240ms +- ทุกอนิเมชันใช้ **`transform` / `opacity` เท่านั้น** (ห้าม `width/height/top/left`) · ตัวแปร: `--fx-fast 160ms`, `--fx-base 280ms`, `--fx-page 460ms`, `--fx-slow 640ms`, `--fx-ease-out cubic-bezier(0.16,1,0.3,1)` · หน่วงต่อชิ้นไม่เกิน ~240ms +- **การเปิด/ปิดอนิเมชันมีสองชั้น — ต้องมีทั้งคู่**: + 1. **สถานะ "ซ่อนก่อน reveal"** ผูกกับ `html.fx-motion [data-reveal]{opacity:0}` — คลาสนี้ใส่โดยสคริปต์ใน `` (`MOTION_INIT_SCRIPT`) **และเติมซ้ำโดย ``** (effect ฝั่ง client) เพราะพบว่า hydration เขียนทับ `class` ของ `` ทำให้คลาสหลุด + 2. **ตัวอนิเมชัน** ผูกกับ `@media (prefers-reduced-motion: no-preference)` ไม่ใช่คลาส → ถ้าคลาสหลุดอีก อนิเมชันก็ยังทำงาน และถ้าผู้ใช้ขอ reduced motion ทุกอย่างนิ่ง+เห็นครบ +- ห้ามย้ายตัวอนิเมชันกลับไปผูกกับ `html.fx-motion` อย่างเดียว (เคสจริง: อนิเมชันหายทั้งเว็บหลัง hydration ลบคลาส) +- hover ของการ์ดใช้ `translate` (Tailwind `hover:-translate-y-1`) ไม่ใช้ `transform` เพราะชนกับ keyframe ของ reveal · `.fx-swap` (แกลเลอรี) ใช้ `@keyframes fx-swap-in` — ห้ามลบ keyframes นี้ + +- สรุปตำแหน่งโค้ด: `@keyframes` + สถานะซ่อน + media query อยู่ใน `app/global.css` ท้ายไฟล์ (`fx-*`) · สคริปต์ตั้งต้นอยู่ `app/lib/motion.ts` · ตัวเติมคลาสซ้ำคือ `` ใน `app/root.tsx` - "ค่อย ๆ โผล่เมื่อเลื่อนถึง" ใช้ `useReveal` (`app/hooks/use-reveal.ts`) หรือ `` (`app/components/site/Reveal.tsx`) — มีกฎกันค้างซ่อน: บล็อกที่เลื่อนผ่านไปแล้ว (หรือถูกข้ามด้วยการกระโดด scroll) ต้องโผล่ทันที - hover ของการ์ดใช้ `translate` (Tailwind `hover:-translate-y-1`) ไม่ใช้ `transform` เพราะชนกับ keyframe ของ reveal · ทุกอนิเมชันต้องมีคู่มือปิดใน `@media (prefers-reduced-motion: reduce)` @@ -105,6 +111,20 @@ part of that build, not leave them as an empty template. - **สิ่งที่ต่างโดยธรรมชาติ ไม่ต้องแก้**: Firefox ไม่มี `navigator.share` / install prompt · Safari ไม่มี install prompt (`beforeinstallprompt` ไม่มี แต่ `display: standalone` ใน manifest ทำให้ติดตั้งจากเมนูแชร์ได้) · iOS ล้าง cache ของ SW เมื่อไม่ใช้งาน 7 วัน (ITP) · inertia การเลื่อนต่างกัน - ทดสอบ: `/`, `/cinema/`, `/for-cinemas`, `/admin` ในทั้งสามเอนจิน — สกรอลบาร์/select/`
`/ปุ่ม/ขนาดช่องค้นหาต้องเท่ากัน (มือถือ 16px, เดสก์ท็อป 14px) +### ข้อยกเว้นต่อเบราว์เซอร์ (exception list — ตั้งใจปล่อยไว้) + +| เรื่อง | Chromium | Firefox | Safari | สิ่งที่ทำ | +|---|---|---|---|---| +| ความกว้างสกรอลบาร์ | 5px (`::-webkit-scrollbar`) | ได้แค่ `thin` (~8px) — `scrollbar-width` ไม่รับ px | overlay (ไม่แสดงถ้าไม่เลื่อน) | ยอมรับความต่างเล็กน้อย | +| สีสกรอลบาร์ตอน hover | เปลี่ยนได้ (`::-webkit-scrollbar-thumb:hover`) | **ไม่ได้** (ไม่มี pseudo-element ของ scrollbar) | ไม่ได้ | ปล่อย | +| ปุ่ม X ในช่องค้นหา | ซ่อนได้ (`::-webkit-search-cancel-button`) | **ซ่อนไม่ได้** → FF แสดง X เอง | แสดง X เอง | ปล่อย (เป็น UI ของเบราว์เซอร์) | +| `navigator.share` | ✅ (Windows/Android) | ❌ เดสก์ท็อป | ✅ ดีที่สุด | fallback คัดลอกลิงก์ | +| PWA install prompt | ✅ `beforeinstallprompt` | ❌ | ❌ (ติดตั้งผ่านเมนูแชร์) | ไม่พึ่ง event นี้ | +| `backdrop-filter` | เร็ว | ช้ากว่ามาก | กลาง | จำกัด blur ≤ 24px | +| ฟอนต์ไทย (shaping) | ต่างจาก FF เล็กน้อย | ต่างจาก Chromium เล็กน้อย | ต่างที่สุดถ้าไม่มี Noto | ยอมรับ — ทางแก้คือ self-host subset | +| `dvh` | ✅ | 101+ | 15.4+ | ใช้ได้ แต่ถ้าต้องรองรับเก่ากว่านี้ต้องมี `100vh` สำรอง | +| cache ของ SW | คงอยู่จน bump VERSION | คงอยู่ | **ถูกล้างหลังไม่ใช้งาน 7 วัน (ITP)** | ยอมรับ | + ## Agent-Native is structural, not visual This shell already meets the Agent-Native contract: data in SQL, actions as the diff --git a/app/global.css b/app/global.css index 50d3239..fa2b3e1 100644 --- a/app/global.css +++ b/app/global.css @@ -400,31 +400,6 @@ } } -/* สถานะตั้งต้น: ซ่อนเฉพาะเมื่อ motion เปิดอยู่ (JS ใส่คลาสแล้วเท่านั้น) */ -html.fx-motion [data-reveal] { - opacity: 0; -} - -html.fx-motion [data-reveal="rise"][data-revealed] { - animation: fx-rise-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms) - both; -} - -html.fx-motion [data-reveal="fade"][data-revealed] { - animation: fx-fade-in var(--fx-base) var(--fx-ease-out) var(--fx-delay, 0ms) - both; -} - -html.fx-motion [data-reveal="zoom"][data-revealed] { - animation: fx-pop-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms) - both; -} - -/* อนิเมชันตอนโหลด (ไม่ผูกกับ scroll) */ -html.fx-motion .fx-page { - animation: fx-page-in var(--fx-page) var(--fx-ease-out) both; -} - /* สลับภาพในแกลเลอรี (ปุ่มลูกศร) — จางเข้าเบา ๆ ไม่กระตุก */ @keyframes fx-swap-in { from { @@ -437,25 +412,59 @@ html.fx-motion .fx-page { } } -html.fx-motion .fx-swap { - animation: fx-swap-in 320ms var(--fx-ease-out) both; +/* ══ สถานะตั้งต้น + อนิเมชัน reveal ══════════════════════════════════════ + กันสองทาง: + 1) เนื้อหาห้ามหายถ้าปิด JS → สถานะ "ซ่อน" ผูกกับคลาส `html.fx-motion` + (คลาสถูกใส่โดยสคริปต์ใน และเสริมอีกครั้งจาก client effect) + 2) อนิเมชันต้องทำงานแม้คลาสหลุด (เคยเกิดจาก hydration ลบคลาส) → ตัวอนิเมชัน + ผูกกับ `@media (prefers-reduced-motion: no-preference)` แทน + ผลคือทุกเอนจิน (Chromium / Firefox / Safari) ได้อนิเมชันเหมือนกัน และ + ผู้ใช้ที่ขอ reduced motion ได้เนื้อหานิ่งครบทันที */ +html.fx-motion [data-reveal] { + opacity: 0; } -html.fx-motion .fx-drop { - animation: fx-drop-in var(--fx-base) var(--fx-ease-out) both; -} +@media (prefers-reduced-motion: no-preference) { + [data-reveal="rise"][data-revealed] { + animation: fx-rise-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms) + both; + } -html.fx-motion .fx-hero-image { - animation: fx-hero-zoom 1400ms var(--fx-ease-out) both; + [data-reveal="fade"][data-revealed] { + animation: fx-fade-in var(--fx-base) var(--fx-ease-out) var(--fx-delay, 0ms) + both; + } + + [data-reveal="zoom"][data-revealed] { + animation: fx-pop-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms) + both; + } + + /* อนิเมชันตอนโหลด (ไม่ผูกกับ scroll) */ + .fx-page { + animation: fx-page-in var(--fx-page) var(--fx-ease-out) both; + } + + .fx-swap { + animation: fx-swap-in 320ms var(--fx-ease-out) both; + } + + .fx-drop { + animation: fx-drop-in var(--fx-base) var(--fx-ease-out) both; + } + + .fx-hero-image { + animation: fx-hero-zoom 1400ms var(--fx-ease-out) both; + } } /* ทางออกสุดท้าย: ถ้าผู้ใช้ขอ reduced motion ให้ทุกอย่างนิ่งและเห็นครบ */ @media (prefers-reduced-motion: reduce) { - html.fx-motion [data-reveal], - html.fx-motion .fx-page, - html.fx-motion .fx-drop, - html.fx-motion .fx-swap, - html.fx-motion .fx-hero-image { + [data-reveal], + .fx-page, + .fx-drop, + .fx-swap, + .fx-hero-image { animation: none !important; opacity: 1 !important; transform: none !important; diff --git a/app/root.tsx b/app/root.tsx index 5a23e89..7f84454 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -124,6 +124,28 @@ function ServiceWorkerSetup() { return null; } +/** + * เติมคลาส `fx-motion` ซ้ำฝั่ง client + * + * ทำไมต้องมี: สคริปต์ใน ใส่คลาสนี้ก่อน paint แล้ว แต่พบว่า hydration + * เขียนทับ `class` ของ ทำให้คลาสหลุด → เนื้อหาที่ควร "ค่อย ๆ โผล่" + * กลายเป็นโผล่ทันที (อนิเมชันหาย) · effect นี้รันหลัง hydration จึงเติมกลับให้เสถียร + * ตัวอนิเมชันเองผูกกับ `@media (prefers-reduced-motion: no-preference)` แล้ว + * จึงยังทำงานได้แม้คลาสหลุด (คลาสมีหน้าที่แค่ "ซ่อนก่อน reveal" ไม่ให้กระพริบ) + */ +function MotionBootstrap() { + useEffect(() => { + const query = window.matchMedia("(prefers-reduced-motion: reduce)"); + const sync = () => { + document.documentElement.classList.toggle("fx-motion", !query.matches); + }; + sync(); + query.addEventListener("change", sync); + return () => query.removeEventListener("change", sync); + }, []); + return null; +} + export default function Root() { const [queryClient] = useState(() => createAgentNativeQueryClient()); const { content, localeFromUrl, shareOrigin } = @@ -141,6 +163,7 @@ export default function Root() { + diff --git a/public/sw.js b/public/sw.js index 371a2cc..7087571 100644 --- a/public/sw.js +++ b/public/sw.js @@ -18,7 +18,7 @@ * | โดเมนอื่น (รูป hotlink) | ไม่จัดการ | * | /app/* · /node_modules/* · /@* | ไม่จัดการ (โมดูลของ dev server) | */ -const VERSION = "v2.0.3"; +const VERSION = "v2.0.4"; const PAGES_CACHE = `alterflixhub-pages-${VERSION}`; const ASSETS_CACHE = `alterflixhub-assets-${VERSION}`;