diff --git a/ui/_shared.css b/ui/_shared.css index a1f4ef2..b266d61 100644 --- a/ui/_shared.css +++ b/ui/_shared.css @@ -491,3 +491,28 @@ body:has(.mu-site-footer) .mu-footer { display: none; } outline: 2px solid #7a4cc0; outline-offset: 2px; } + +/* ---------- ปุ่มติดตั้งแอป (PWA — inject จาก pwa.js) ---------- */ +.mu-install-btn { + position: fixed; + bottom: 20px; + right: 20px; + z-index: 100; + display: none; /* โผล่เมื่อ beforeinstallprompt เท่านั้น */ + align-items: center; + gap: 8px; + min-height: 48px; + padding: 12px 20px; + border: none; + border-radius: 999px; + cursor: pointer; + font-family: inherit; + font-size: .95rem; + font-weight: 700; + color: #fff; + background: linear-gradient(135deg, #a855f7, #7c3aed); + box-shadow: 0 10px 24px rgba(124, 58, 237, .35); + transition: transform .15s ease; +} +.mu-install-btn:active { transform: translateY(1px); } +.mu-install-btn svg { width: 20px; height: 20px; } diff --git a/ui/index.html b/ui/index.html index c173b5e..f199ded 100644 --- a/ui/index.html +++ b/ui/index.html @@ -2,6 +2,7 @@ + หน้าแรก | AT Transit (mockup) @@ -13,7 +14,7 @@ /* Page-specific: hero */ .mu-hero { position: relative; overflow: hidden; } - .mu-hero-map { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .14; filter: saturate(1.1); z-index: 0; pointer-events: none; } + .mu-hero-map { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .3; filter: saturate(1.1); z-index: 0; pointer-events: none; } .mu-hero-content { position: relative; z-index: 1; } /* ===== maintheme-style cards: solid gradient block with big centered number ===== */ @@ -64,7 +65,7 @@ /* Hero */ .mu-hero { position: relative; overflow: hidden; padding: 56px 0 64px; background: linear-gradient(180deg, #f0ebff 0%, #ffe8ee 50%, #fff4d6 100%); text-align: center; } - .mu-hero-map { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .14; filter: saturate(1.1); z-index: 0; pointer-events: none; } + .mu-hero-map { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .3; filter: saturate(1.1); z-index: 0; pointer-events: none; } .mu-blob { position: absolute; border-radius: 50%; filter: blur(50px); opacity: .55; z-index: 0; } .mu-blob.one { width: 220px; height: 220px; background: #b794f4; top: -50px; left: 8%; } .mu-blob.two { width: 260px; height: 260px; background: #f9a8d4; top: 40%; right: 8%; } @@ -374,6 +375,17 @@ ป้ายหยุดรถ รายละเอียดสายรถ +
+ + + + +
@@ -444,5 +456,19 @@ el.textContent = n.toLocaleString('en-US'); })(); + + diff --git a/ui/manifest.json b/ui/manifest.json index 8b57281..01bbf8c 100644 --- a/ui/manifest.json +++ b/ui/manifest.json @@ -1,4 +1,5 @@ { + "id": "./index.html", "name": "AT Transit — สถานีขนส่งผู้โดยสารจังหวัดอ่างทอง", "short_name": "AT Transit", "description": "ค้นหาเส้นทาง ตารางเดินรถ และจุดจอดในจังหวัดอ่างทองและจังหวัดใกล้เคียง", @@ -10,6 +11,30 @@ "orientation": "any", "background_color": "#fcfbff", "theme_color": "#7a4cc0", + "categories": ["travel", "navigation", "transportation"], + "shortcuts": [ + { + "name": "เช็กเวลาเดินรถ", + "short_name": "เช็กเวลา", + "description": "ดูตารางเวลาเดินรถทุกจุดจอด", + "url": "./index.html#/check", + "icons": [{ "src": "../.image/icons/minibus-192x192.png", "sizes": "192x192", "type": "image/png" }] + }, + { + "name": "ป้ายหยุดรถ", + "short_name": "ป้ายหยุดรถ", + "description": "ค้นหาป้ายหยุดรถทั้งหมด", + "url": "./index.html#/stops", + "icons": [{ "src": "../.image/icons/minibus-192x192.png", "sizes": "192x192", "type": "image/png" }] + }, + { + "name": "รายละเอียดสายรถ", + "short_name": "สายรถ", + "description": "ดูรายละเอียดเส้นทางเดินรถ", + "url": "./index.html#/routes", + "icons": [{ "src": "../.image/icons/minibus-192x192.png", "sizes": "192x192", "type": "image/png" }] + } + ], "icons": [ { "src": "../.image/icons/minibus-192x192.png", diff --git a/ui/offline.html b/ui/offline.html new file mode 100644 index 0000000..3ddf3ab --- /dev/null +++ b/ui/offline.html @@ -0,0 +1,74 @@ + + + + + + + ออฟไลน์ | AT Transit + + + +
+ +

คุณกำลังออฟไลน์

+

เชื่อมต่ออินเทอร์เน็ตไม่ได้ — ไม่สามารถโหลดเนื้อหาล่าสุดได้ โปรดตรวจสอบการเชื่อมต่อแล้วลองใหม่อีกครั้ง

+ +
+ กลับหน้าแรก +
+ + diff --git a/ui/pwa.js b/ui/pwa.js index 02f6736..6cc4c12 100644 --- a/ui/pwa.js +++ b/ui/pwa.js @@ -12,6 +12,38 @@ var CHECK_INTERVAL_MS = 30 * 60 * 1000; // ตรวจอัปเดตทุก 30 นาที + /* ---- ปุ่มติดตั้งแอป (ก่อน install prompt) ---- */ + var deferredPrompt = null; + var installBtn = null; + + function makeInstallBtn() { + var btn = document.createElement("button"); + btn.type = "button"; + btn.className = "mu-install-btn"; + btn.innerHTML = ' ติดตั้งแอป'; + btn.addEventListener("click", function () { + if (!deferredPrompt) return; + deferredPrompt.prompt(); + deferredPrompt.userChoice.then(function () { + deferredPrompt = null; + if (installBtn) installBtn.style.display = "none"; + }); + }); + document.body.appendChild(btn); + return btn; + } + + window.addEventListener("beforeinstallprompt", function (e) { + e.preventDefault(); + deferredPrompt = e; + if (!installBtn) installBtn = makeInstallBtn(); + installBtn.style.display = "inline-flex"; + }); + + window.addEventListener("appinstalled", function () { + if (installBtn) installBtn.style.display = "none"; + }); + window.addEventListener("load", function () { navigator.serviceWorker .register("./sw.js", { updateViaCache: "none" }) diff --git a/ui/responsive.css b/ui/responsive.css index c526c6a..ed37c53 100644 --- a/ui/responsive.css +++ b/ui/responsive.css @@ -17,7 +17,25 @@ /* ---------- base: มือถือ ---------- */ html { -webkit-text-size-adjust: 100%; } -body { font-size: 15px; } +body { font-size: 16px; } + +/* --- ขยายขนาด component บนมือถือ (desktop-oriented เดิมเล็กเกิน) --- */ +/* topbar อยู่ใน section ด้านล่าง — content ใน #view ใช้ prefix ชนะ partial style */ +#view .mu-btn { font-size: .95rem; min-height: 48px; } +#view .mu-badge { font-size: 1.05rem; } +#view .mu-zone-tag { font-size: 1rem; } +#view .mu-zone-desc, #view .mu-zone-sub { font-size: 1.05rem; } +#view .mu-route-name { font-size: 1.2rem; } +#view .mu-next-trip { font-size: .95rem; } +#view .mu-meta-pill { font-size: .95rem; } +#view .mu-route-type-badge { font-size: .85rem; } +#view .mu-stop-summary-meta { font-size: .85rem; } +#view .mu-time-chip { font-size: .95rem; min-height: 40px; } +#view .mu-info-card .label { font-size: .85rem; } +#view .mu-info-card .value { font-size: 1.1rem; } +#view .mu-stat p { font-size: .9rem; } +#view .mu-hero-lead { font-size: 1rem; } +#view .mu-select-box select { font-size: 1rem; } /* --- กัน overflow พื้นฐาน (padding/รูป/grid/ข้อความยาว ไม่ให้ล้นจอมือถือ) --- */ *, *::before, *::after { box-sizing: border-box; } @@ -35,21 +53,49 @@ img, svg, video { max-width: 100%; height: auto; } .mu-container { padding: 0 16px; } main.mu-container { padding-top: 24px; padding-bottom: 24px; } -/* --- topbar: 2 แถวบนมือถือ (brand+lang บรรทัด1, nav บรรทัด2) — ไม่มี scroll ซ้ายขวา --- */ +/* --- topbar: hamburger menu บนมือถือ (brand + lang + ☰ บรรทัดเดียว) --- */ .mu-topbar-inner { gap: 8px; padding: 10px 14px; flex-wrap: wrap; } .mu-logo-img { width: 36px; height: 36px; } .mu-brand { gap: 8px; flex-shrink: 0; } -.mu-brand-title { font-size: .92rem; white-space: nowrap; } +.mu-brand-title { font-size: 1.05rem; white-space: nowrap; } .mu-brand-subtitle { display: none; } /* กันล้น — โผล่กลับ ≥768px */ -.mu-nav { order: 3; width: 100%; justify-content: space-between; margin-left: 0; gap: 8px; } -.mu-nav a { font-size: .76rem; padding: 10px 2px; white-space: nowrap; } /* tap target ≥44px */ -.mu-lang-switch { margin-left: auto; padding: 2px; } -.mu-lang-btn { font-size: .68rem; padding: 8px 12px; min-height: 40px; min-width: 40px; } /* tap target */ +.mu-nav { display: none; } /* ซ่อน nav — ใช้ hamburger แทน */ +.mu-lang-switch { order: 3; margin-left: auto; padding: 2px; } +.mu-lang-btn { font-size: .8rem; padding: 8px 12px; min-height: 40px; min-width: 40px; } /* tap target */ .mu-action-btn { display: none; } /* กันล้นบนจอเล็ก — โผล่กลับ ≥1024px */ -/* --- hero (หน้าแรก) — ลดช่องว่างแนวตั้ง --- */ -.mu-hero { padding: 20px 0 22px; } -.mu-hero h1 { font-size: clamp(1.6rem, 7vw, 2.4rem); margin-bottom: 10px; line-height: 1.28; } +/* hamburger menu (ขวาสุด) */ +.mu-menu { display: block; position: relative; order: 4; margin-left: 2px; } +.mu-menu-btn { + display: flex; align-items: center; justify-content: center; + width: 44px; height: 44px; + border: none; background: transparent; cursor: pointer; + color: #1f2a44; list-style: none; + border-radius: 10px; +} +.mu-menu-btn::-webkit-details-marker { display: none; } +.mu-menu-btn svg { width: 26px; height: 26px; } +.mu-menu-panel { + position: absolute; top: calc(100% + 8px); right: 0; + min-width: 220px; + background: #fff; border: 1px solid #e7e2f6; border-radius: 14px; + box-shadow: 0 12px 28px rgba(20, 40, 90, .16); + padding: 8px; + z-index: 60; + display: flex; flex-direction: column; gap: 2px; +} +.mu-menu-panel a { + display: flex; align-items: center; + min-height: 48px; padding: 10px 14px; + border-radius: 10px; + color: #1f2a44; text-decoration: none; + font-size: 1.05rem; font-weight: 600; +} +.mu-menu-panel a:hover, .mu-menu-panel a:active { background: #f5efff; } + +/* --- hero (หน้าแรก) — ช่องว่าง + ตัวหนังสือใหญ่ขึ้น --- */ +.mu-hero { padding: 30px 0 34px; } +.mu-hero h1 { font-size: clamp(1.9rem, 8vw, 2.9rem); margin-bottom: 14px; line-height: 1.28; } .mu-badge { margin-bottom: 10px; padding: 5px 14px; } .mu-hero-lead { margin: 0 0 8px; } .mu-hero-actions { flex-direction: column; align-items: stretch; padding: 0 6px; margin-top: 10px; gap: 8px; } @@ -72,7 +118,7 @@ main.mu-container { padding-top: 14px; padding-bottom: 14px; } .mu-zone { margin-bottom: 20px; } .mu-zone-head { margin-bottom: 10px; gap: 10px; } .mu-grid { gap: 12px; } -.mu-route-info { padding: 12px 12px 13px; } +.mu-route-info { padding: 16px 16px 18px; } .mu-route-name { margin-bottom: 6px; } .mu-route-chip-wrap { gap: 6px; } .mu-next-trip { padding: 3px 10px; font-size: .74rem; } @@ -85,6 +131,7 @@ main.mu-container { padding-top: 14px; padding-bottom: 14px; } #view .mu-toolbar select, #view .mu-toolbar .mu-btn { width: 100%; min-height: 44px; } #view .mu-search-field { width: 100%; min-width: 0; } +#view .mu-search-field input { min-height: 44px; } #view .mu-province-strip { display: flex; flex-wrap: wrap; padding-bottom: 6px; } @@ -102,7 +149,7 @@ main.mu-container { padding-top: 14px; padding-bottom: 14px; } #view .mu-photo-strip { grid-template-columns: repeat(2, 1fr); gap: 8px; } #view .mu-quickpick { display: flex; flex-wrap: wrap; gap: 8px; } #view .mu-inline-actions { flex-wrap: wrap; } -#view .mu-back-btn { width: 100%; justify-content: center; padding: 10px; } +#view .mu-back-btn { width: 100%; justify-content: center; padding: 10px; min-height: 44px; } #view .mu-schedule-note { font-size: .82rem; } /* --- stopDetail --- */ @@ -146,8 +193,9 @@ main.mu-container { padding-top: 14px; padding-bottom: 14px; } .mu-brand-title { font-size: 1.05rem; } .mu-topbar-inner { gap: 18px; padding: 14px 28px; flex-wrap: nowrap; } .mu-logo-img { width: 44px; height: 44px; } - .mu-nav { order: 0; width: auto; margin-left: auto; justify-content: flex-start; gap: 24px; } + .mu-nav { order: 0; width: auto; margin-left: auto; justify-content: flex-start; gap: 24px; display: flex; } .mu-nav a { font-size: .92rem; } + .mu-menu { display: none; } .mu-lang-btn { font-size: .72rem; padding: 6px 10px; } .mu-hero { padding: 44px 0 52px; } .mu-hero-actions { margin-top: 14px; } diff --git a/ui/sw.js b/ui/sw.js index c1746be..d2a37c7 100644 --- a/ui/sw.js +++ b/ui/sw.js @@ -13,11 +13,12 @@ - ขั้นตอนอัปเดต: ดู AGENTS.md หัวข้อ PWA ============================================================ */ -const VERSION = "2026.09.02.9"; // ← bump ทุกครั้งที่แก้ SW เอง +const VERSION = "2026.09.12.1"; // ← bump ทุกครั้งที่แก้ SW เอง const CACHE = `at-transit-${VERSION}`; const PRECACHE = [ "./index.html", + "./offline.html", "./busStop.html", "./busDetail.html", "./busDetailExpanded.html", @@ -87,9 +88,14 @@ self.addEventListener("fetch", (event) => { return; } - // หน้า HTML + CSS + JS + partials + ข้อมูล JSON → network-first + // หน้า HTML (navigation) → network-first แต่ถ้าออฟไลน์ไม่มี cache → offline.html + if (request.destination === "document") { + event.respondWith(networkFirstDocument(request)); + return; + } + + // CSS + JS + partials + ข้อมูล JSON → network-first if ( - request.destination === "document" || url.pathname.endsWith(".css") || url.pathname.endsWith(".js") || url.pathname.endsWith(".html") || @@ -121,6 +127,21 @@ async function networkFirst(request) { } } +/* สำหรับ navigation: ถ้าออฟไลน์และไม่มี cache ให้หน้า offline.html */ +async function networkFirstDocument(request) { + const cache = await caches.open(CACHE); + try { + const res = await fetch(request, { cache: "no-store" }); + if (res.ok) cache.put(request, res.clone()); + return res; + } catch { + const hit = await cache.match(request); + if (hit) return hit; + const offline = await cache.match("./offline.html"); + return offline || Response.error(); + } +} + async function cacheFirst(request) { const hit = await caches.match(request); if (hit) return hit;