From cdfd77ffffba8450fefc5ac923cdfa903c559b1b Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Wed, 4 Nov 2026 01:29:37 +0700 Subject: [PATCH] theme: dark mode + theme tokens (parity with web-at-transit) - ui/theme.css: token set copied value-for-value from the Next app (--c-surface/-ink/-border/-brand/-tint/-glass + radius), light and dark blocks - ui/theme.js: 3-mode switch (light / dark / auto=prefers-color-scheme) with a header dropdown, aria-haspopup/menu, Esc/outside close, live matchMedia listener - index.html: pre-paint theme script (no flash), theme.css link before _shared.css - remapped ~290 literal colours in _shared.css/index.html/partials to var(--c-*) so both projects render from the same tokens; dark patch block covers the remaining decorative gradients - DESIGN.md: new section 3.2 (theme tokens + where to add colours) - VERSION 2026.09.27.114 --- DESIGN.md | 11 ++ ui/_shared.css | 51 ++++---- ui/index.html | 194 +++++++++++++++++------------ ui/map.css | 52 ++++---- ui/partials/about.html | 10 +- ui/partials/blog.html | 70 +++++------ ui/partials/busDetail.html | 46 +++---- ui/partials/busStop.html | 88 ++++++------- ui/partials/checkSchedule.html | 16 +-- ui/partials/credits.html | 18 +-- ui/partials/home.html | 4 +- ui/partials/stats.html | 52 ++++---- ui/partials/stopDetail.html | 78 ++++++------ ui/responsive.css | 12 +- ui/sw.js | 2 +- ui/theme.css | 219 +++++++++++++++++++++++++++++++++ ui/theme.js | 146 ++++++++++++++++++++++ ui/version.json | 2 +- 18 files changed, 742 insertions(+), 329 deletions(-) create mode 100644 ui/theme.css create mode 100644 ui/theme.js diff --git a/DESIGN.md b/DESIGN.md index 052114d..c3565ab 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -115,6 +115,17 @@ - **ชื่อเฉพาะไม่แปล** — ชื่อสถานี จังหวัด สายรถ (ภาษาไทยเสมอ) - **ตรวจก่อน commit:** `python resource/tools/check-i18n.py` + +## 3.2 ธีม (light / dark / ตามอุปกรณ์) — `ui/theme.css` + +- **โทเคนสีทุกตัวอยู่ใน `ui/theme.css`** (`--c-*`) — ค่าเดียวกับ `web-at-transit/frontend/src/styles/theme.css` + (GUI สองโปรเจกต์ต้องตรงกัน ห้ามแก้ค่าข้างเดียว) +- โหมด: `light` · `dark` · `auto` = **ตามธีมอุปกรณ์** (`prefers-color-scheme`) ← ค่าเริ่มต้น +- ตั้งค่า: `` + `data-theme-mode="light|dark|auto"` · เก็บที่ `localStorage.at_theme` +- ปุ่มใน header = dropdown (ไอคอนเปลี่ยนตามโหมด) · สคริปต์ก่อน paint อยู่ใน `index.html` (กันจอขาววูบ) +- **ห้ามใส่ hex ใหม่ในไฟล์ CSS/partial** — ถ้าจำเป็นให้เพิ่มเป็นโทเคนคู่ light/dark ที่นี่ก่อน + (ยกเว้นสีที่ต้องคงที่ทุกธีม เช่น `#fff` บนพื้นแบรนด์ และไล่เฉดภาพประดับ) + ## 4. ตัวพิมพ์ (Typography) ```css diff --git a/ui/_shared.css b/ui/_shared.css index ca7446a..5aff477 100644 --- a/ui/_shared.css +++ b/ui/_shared.css @@ -56,8 +56,8 @@ font-size: .72rem; font-weight: 800; letter-spacing: .02em; - background: rgba(255, 255, 255, .92); - color: #1f2a44; + background: var(--c-glass); + color: var(--c-ink); backdrop-filter: blur(8px); box-shadow: 0 4px 10px rgba(15, 23, 42, .15); } @@ -146,8 +146,8 @@ border-radius: 999px; font-size: .7rem; font-weight: 700; - background: rgba(255, 255, 255, .92); - color: #1f2a44; + background: var(--c-glass); + color: var(--c-ink); backdrop-filter: blur(6px); box-shadow: 0 4px 10px rgba(15, 23, 42, .14); } @@ -169,7 +169,7 @@ overflow: hidden; box-shadow: 0 10px 24px rgba(63, 43, 94, .08); border: 1px solid rgba(231, 224, 246, .95); - background: #fff; + background: var(--c-surface); display: flex; flex-direction: column; transition: transform .18s ease, box-shadow .18s ease; @@ -221,7 +221,7 @@ width: 48px; height: 48px; border-radius: 12px; - background: #fff; + background: var(--c-surface); padding: 4px; object-fit: contain; } @@ -273,7 +273,7 @@ .mu-footer-col ul a:hover { color: #fff; } .mu-footer-col ul a::before { content: "›"; - color: #7a4cc0; + color: var(--c-brand-ink); font-weight: 800; } .mu-footer-contact a, @@ -311,7 +311,7 @@ gap: 12px; } .mu-sponsor-tile { - background: #fff; + background: var(--c-surface); border-radius: 12px; padding: 14px; display: flex; @@ -398,7 +398,7 @@ body:has(.mu-site-footer) .mu-footer { display: none; } .mu-search-field .ic { position: absolute; left: 12px; - color: #6f7b95; + color: var(--c-ink-2); pointer-events: none; } .mu-search-field input { @@ -421,8 +421,8 @@ body:has(.mu-site-footer) .mu-footer { display: none; } padding: 6px 12px; border: 1px solid #e4dcf2; border-radius: 999px; - background: #f0edf7; - color: #6d28d9; + background: var(--c-surface-3); + color: var(--c-brand-ink); font-family: inherit; font-weight: 700; font-size: .76rem; @@ -430,8 +430,8 @@ body:has(.mu-site-footer) .mu-footer { display: none; } cursor: pointer; transition: background .15s ease, color .15s ease, border-color .15s ease; } -.mu-lang-btn:hover { color: #5b21b6; border-color: #d9cdf0; } -.mu-lang-btn[aria-expanded="true"] { background: #fff; border-color: #cbb8ea; } +.mu-lang-btn:hover { color: var(--c-brand-ink); border-color: var(--c-border); } +.mu-lang-btn[aria-expanded="true"] { background: var(--c-surface); border-color: #cbb8ea; } .mu-lang-btn .ic { width: 15px; height: 15px; } .mu-lang-caret { width: 0 !important; @@ -449,8 +449,8 @@ body:has(.mu-site-footer) .mu-footer { display: none; } z-index: 1200; min-width: 168px; padding: 6px; - background: #fff; - border: 1px solid #e7e0f6; + background: var(--c-surface); + border: 1px solid var(--c-border); border-radius: 12px; box-shadow: 0 10px 28px rgba(15, 23, 42, .14); } @@ -465,7 +465,7 @@ body:has(.mu-site-footer) .mu-footer { display: none; } border: 0; border-radius: 8px; background: transparent; - color: #2c3550; + color: var(--c-ink); font-family: inherit; font-size: .84rem; font-weight: 600; @@ -473,14 +473,19 @@ body:has(.mu-site-footer) .mu-footer { display: none; } cursor: pointer; } .mu-lang-menu button:hover { background: #f6f2ff; } -.mu-lang-menu button[aria-checked="true"] { color: #7a4cc0; font-weight: 800; background: #f4f0fb; } +.mu-lang-menu button[aria-checked="true"] { color: var(--c-brand-ink); font-weight: 800; background: var(--c-brand-soft); } .mu-lang-menu button .mu-lang-code { margin-left: auto; font-family: ui-monospace, "IBM Plex Mono", monospace; font-size: .72rem; - color: #8a93a8; + color: var(--c-ink-3); } +/* ---------- ปุ่มธีม (dropdown 3 โหมด — สว่าง / มืด / ตามอุปกรณ์) ---------- */ +.mu-theme-btn { padding: 6px 9px; } +.mu-theme-icon { display: inline-flex; } +.mu-theme-icon svg { width: 16px; height: 16px; } + /* ============================================================ ปุ่ม + ฟอร์มคอนโทรล (shared — ทุกหน้าใช้ร่วมกัน) .mu-btn อยู่ที่นี่ (ไม่ใช่ใน partial) → หน้าไหนก็ได้สไตล์เดียวกัน @@ -510,18 +515,18 @@ body:has(.mu-site-footer) .mu-footer { display: none; } } .mu-btn.primary:hover { box-shadow: 0 10px 22px rgba(124, 58, 237, .35); } .mu-btn.ghost { - background: #fff; - border-color: #e7e2f6; - color: #7a4cc0; + background: var(--c-surface); + border-color: var(--c-border); + color: var(--c-brand-ink); box-shadow: 0 2px 8px rgba(63, 43, 94, .05); } -.mu-btn.ghost:hover { border-color: #d8c9f2; background: #faf7ff; } +.mu-btn.ghost:hover { border-color: #d8c9f2; background: var(--c-surface-2); } /* select แบบโมเดิร์น — custom chevron แทนลูกศร native (prefix #view ชนะ partial style) */ #view .mu-toolbar select { appearance: none; -webkit-appearance: none; - background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a4cc0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"), linear-gradient(180deg, #fff, #f8fbff); + background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a4cc0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"), linear-gradient(180deg, var(--c-surface), #f8fbff); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; diff --git a/ui/index.html b/ui/index.html index 87e791b..5e59025 100644 --- a/ui/index.html +++ b/ui/index.html @@ -3,19 +3,34 @@ + หน้าแรก | Atroute (mockup) - + - - - - - + + + + + +
diff --git a/ui/partials/home.html b/ui/partials/home.html index 03a1563..d3e04f1 100644 --- a/ui/partials/home.html +++ b/ui/partials/home.html @@ -4,14 +4,14 @@ .mu-share-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border: 1px solid #7a4cc0; border-radius: 8px; - background: #7a4cc0; color: #fff; font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer; + background: var(--c-brand); color: #fff; font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer; } .mu-share-btn:hover { background: #6a3cae; } .mu-share-btn:focus-visible { outline: 2px solid #2b2f42; outline-offset: 2px; } .mu-share-btn .ic { width: 18px; height: 18px; } .mu-share-status { margin: 0; font-size: .82rem; line-height: 1.7; color: #4b5570; text-align: right; } .mu-share-status:empty { display: none; } - .mu-share-url { display: inline-block; padding: 2px 6px; border: 1px solid #e7e2f6; border-radius: 8px; background: #faf9ff; font-size: .8rem; } + .mu-share-url { display: inline-block; padding: 2px 6px; border: 1px solid var(--c-border); border-radius: 8px; background: #faf9ff; font-size: .8rem; } .mu-share-line { display: inline-block; margin-left: 6px; font-weight: 700; color: #06c755; text-decoration: none; } .mu-share-line:hover { text-decoration: underline; } @media (max-width: 560px) { diff --git a/ui/partials/stats.html b/ui/partials/stats.html index 713fd6a..fdc0f53 100644 --- a/ui/partials/stats.html +++ b/ui/partials/stats.html @@ -2,17 +2,17 @@ .mu-page { background: linear-gradient(180deg, #fcfbff 0%, #f5f9ff 100%); } .st-wrap { max-width: 62rem; margin: 0 auto; padding: 32px 20px 64px; } .st-hero { margin-bottom: 22px; } - .st-hero h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 1.2rem + 1.4vw, 1.9rem); color: #1f2a44; letter-spacing: -.01em; } - .st-hero p { margin: 0; color: #66728f; font-size: .92rem; line-height: 1.65; max-width: 62ch; } + .st-hero h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 1.2rem + 1.4vw, 1.9rem); color: var(--c-ink); letter-spacing: -.01em; } + .st-hero p { margin: 0; color: var(--c-ink-2); font-size: .92rem; line-height: 1.65; max-width: 62ch; } .st-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } - .st-kpi { background: #fff; border: 1px solid #e7e0f6; border-radius: 14px; padding: 14px 16px; min-width: 0; } - .st-kpi b { display: block; font-size: 1.55rem; line-height: 1.2; color: #1f2a44; font-variant-numeric: tabular-nums; } - .st-kpi span { display: block; margin-top: 4px; font-size: .76rem; font-weight: 700; color: #6f7b95; letter-spacing: .01em; } + .st-kpi { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 14px; padding: 14px 16px; min-width: 0; } + .st-kpi b { display: block; font-size: 1.55rem; line-height: 1.2; color: var(--c-ink); font-variant-numeric: tabular-nums; } + .st-kpi span { display: block; margin-top: 4px; font-size: .76rem; font-weight: 700; color: var(--c-ink-2); letter-spacing: .01em; } - .st-card { background: #fff; border: 1px solid #e7e0f6; border-radius: 16px; padding: 18px 20px; margin-top: 16px; } - .st-card h2 { margin: 0 0 4px; font-size: 1rem; color: #1f2a44; } - .st-card .lead { margin: 0 0 14px; color: #6f7b95; font-size: .84rem; line-height: 1.6; } + .st-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 16px; padding: 18px 20px; margin-top: 16px; } + .st-card h2 { margin: 0 0 4px; font-size: 1rem; color: var(--c-ink); } + .st-card .lead { margin: 0 0 14px; color: var(--c-ink-2); font-size: .84rem; line-height: 1.6; } .st-grid2 { display: grid; gap: 16px; margin-top: 16px; } .st-grid2 > .st-card { margin-top: 0; } @@ -22,35 +22,35 @@ .st-bar i, .st-bar u { display: block; border-radius: 4px 4px 0 0; min-height: 2px; } .st-bar i { background: linear-gradient(180deg, #b694f6, #7a4cc0); } .st-bar u { background: #e9dffb; } - .st-bar em { font-style: normal; font-size: .6rem; color: #8a93a8; text-align: center; margin-top: 4px; white-space: nowrap; } - .st-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: .76rem; color: #6f7b95; } + .st-bar em { font-style: normal; font-size: .6rem; color: var(--c-ink-3); text-align: center; margin-top: 4px; white-space: nowrap; } + .st-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: .76rem; color: var(--c-ink-2); } .st-legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; } .st-table { width: 100%; border-collapse: collapse; font-size: .88rem; } - .st-table th { text-align: left; padding: 0 8px 6px 0; font-size: .7rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #8a93a8; border-bottom: 1px solid #efe9fb; } - .st-table td { padding: 8px 8px 8px 0; border-bottom: 1px solid #f5f1fc; color: #3a4462; vertical-align: top; } + .st-table th { text-align: left; padding: 0 8px 6px 0; font-size: .7rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--c-ink-3); border-bottom: 1px solid #efe9fb; } + .st-table td { padding: 8px 8px 8px 0; border-bottom: 1px solid #f5f1fc; color: var(--c-ink); vertical-align: top; } .st-table tr:last-child td { border-bottom: 0; } - .st-table .num { width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; color: #1f2a44; } - .st-table .when { color: #8a93a8; font-size: .74rem; white-space: nowrap; } - .st-table .term { font-weight: 700; color: #1f2a44; word-break: break-word; } - .st-table a { color: #7a4cc0; text-decoration: none; font-weight: 600; } + .st-table .num { width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; color: var(--c-ink); } + .st-table .when { color: var(--c-ink-3); font-size: .74rem; white-space: nowrap; } + .st-table .term { font-weight: 700; color: var(--c-ink); word-break: break-word; } + .st-table a { color: var(--c-brand-ink); text-decoration: none; font-weight: 600; } .st-table a:hover { text-decoration: underline; } - .st-empty { margin: 0; padding: 14px 0 4px; color: #8a93a8; font-size: .86rem; } + .st-empty { margin: 0; padding: 14px 0 4px; color: var(--c-ink-3); font-size: .86rem; } - .st-list { margin: 0 0 14px; padding-left: 1.15rem; color: #3a4462; font-size: .88rem; line-height: 1.75; } - .st-toggle { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid #e7e0f6; border-radius: 12px; background: #fbf9ff; font-size: .88rem; color: #3a4462; cursor: pointer; } - .st-toggle input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: #7a4cc0; flex: none; } - .st-toggle strong { display: block; color: #1f2a44; font-size: .9rem; margin-bottom: 2px; } + .st-list { margin: 0 0 14px; padding-left: 1.15rem; color: var(--c-ink); font-size: .88rem; line-height: 1.75; } + .st-toggle { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--c-border); border-radius: 12px; background: #fbf9ff; font-size: .88rem; color: var(--c-ink); cursor: pointer; } + .st-toggle input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--c-brand-ink); flex: none; } + .st-toggle strong { display: block; color: var(--c-ink); font-size: .9rem; margin-bottom: 2px; } .st-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; } - .st-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 9px 16px; border-radius: 10px; border: 1px solid #ddcff5; background: #fff; color: #7a4cc0; font: inherit; font-size: .86rem; font-weight: 700; cursor: pointer; } + .st-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 9px 16px; border-radius: 10px; border: 1px solid #ddcff5; background: var(--c-surface); color: var(--c-brand-ink); font: inherit; font-size: .86rem; font-weight: 700; cursor: pointer; } .st-btn:hover { background: #f7f2ff; } - .st-btn.is-solid { background: #7a4cc0; border-color: #7a4cc0; color: #fff; } + .st-btn.is-solid { background: var(--c-brand); border-color: var(--c-brand); color: #fff; } .st-btn.is-solid:hover { background: #6a3fb0; } - .st-btn.is-danger { border-color: #f0c9c9; color: #b3261e; } + .st-btn.is-danger { border-color: #f0c9c9; color: var(--c-danger); } .st-btn.is-danger:hover { background: #fdf3f3; } - .st-note { margin: 12px 0 0; font-size: .78rem; color: #8a93a8; } - .st-status { margin: 10px 0 0; min-height: 18px; font-size: .82rem; color: #1f7a3d; } + .st-note { margin: 12px 0 0; font-size: .78rem; color: var(--c-ink-3); } + .st-status { margin: 10px 0 0; min-height: 18px; font-size: .82rem; color: var(--c-ok); } @media (min-width: 520px) { .st-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } } @media (min-width: 768px) { .st-grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .st-wrap { padding: 40px 28px 72px; } } diff --git a/ui/partials/stopDetail.html b/ui/partials/stopDetail.html index 7b6b522..f1a2acb 100644 --- a/ui/partials/stopDetail.html +++ b/ui/partials/stopDetail.html @@ -1,27 +1,27 @@