add one ui theme
This commit is contained in:
1 parent
7a39f96256
commit
e19147dc73
18 files changed
+5299
-785
No files matched your search
+45
-40
@@ -1,57 +1,62 @@
|
|||||||
# CamCat — Web Camera Category PWA
|
# CamCat — Web Camera Category PWA (One UI)
|
||||||
|
|
||||||
Progressive Web App สำหรับถ่ายรูป จัดหมวดใน folder และแชร์เป็น zip
|
PWA ถ่ายรูปหน้างาน แยกโฟลเดอร์ตามไซต์ พร้อม Metadata, ZIP ทั้งโฟลเดอร์ และแชร์ผ่านระบบของมือถือ
|
||||||
|
หน้าตาออกแบบตามภาษา **Samsung One UI** (การ์ดมุมโค้ง 26px, พิลล์, ธีมสว่าง/มืด, ไอคอน SVG ล้วน)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- 📷 ถ่ายรูปจากกล้อง (front/back switch)
|
- กล้องหลัง/หน้า, ไฟแฟลช (torch), ซูมแบบ pills 1×/2×/3×, เส้นแบ่ง 3 ส่วน
|
||||||
- 📁 สร้าง/แก้ชื่อ/ลบ folder
|
- ถ่ายด้วย `ImageCapture.takePhoto()` (ความละเอียดเต็ม) fallback เป็น canvas
|
||||||
- 🖼️ Gallery view พร้อมเลือกหลายรูป
|
- เขียน EXIF ลงไฟล์จริง (Make/Model/DateTimeOriginal/GPS) ก่อนบันทึก → ติดไปตอนแชร์
|
||||||
- 📦 Zip รูปที่เลือกเป็น .zip
|
- โฟลเดอร์ชื่อเริ่มต้น `Site A <ปี พ.ศ.>-<เดือน>-<วัน>` อัตโนมัติ (Asia/Bangkok)
|
||||||
- 📤 Share ผ่าน Web Share API (หรือ download fallback)
|
- ZIP **ทุกรูปในโฟลเดอร์** + `metadata.json` แล้วดาวน์โหลดลงเครื่อง
|
||||||
- 📊 EXIF data (camera model, date, GPS, ISO, aperture)
|
- ปุ่มแชร์ = สร้าง ZIP แล้วส่งเข้า share sheet ของ Samsung ไปแอปอื่น (fallback = ดาวน์โหลด)
|
||||||
- 💾 Offline storage (IndexedDB + Service Worker)
|
- ธีมสว่าง/มืด/ตามระบบ (จำค่าไว้), safe-area, 100dvh, ปุ่ม ≥44px ตาม One UI
|
||||||
- 📱 Installable PWA (Add to Home Screen)
|
- QR ลิงก์ทดสอบบนมือถือ (ต้อง HTTPS) + หน้าข้อมูลอุปกรณ์/กล้อง (diagnostics)
|
||||||
|
- Offline: Service Worker + IndexedDB, ติดตั้งเป็น PWA ได้
|
||||||
|
|
||||||
## Install on Mobile
|
## Design (One UI)
|
||||||
|
|
||||||
|
| องค์ประกอบ | ค่า |
|
||||||
|
|---|---|
|
||||||
|
| สีหลัก light | bg `#F2F3F5` · card `#FFFFFF` · text `#101114` · accent `#0A72DE` |
|
||||||
|
| สีหลัก dark | bg `#000000` · card `#1B1B1D` · text `#F2F3F5` · accent `#4E9DFF` |
|
||||||
|
| มุมโค้ง | การ์ด 26px · ช่องกรอก 16px · ปุ่ม/ชิปเป็น pills |
|
||||||
|
| ตัวอักษร | One UI Sans → SF / Segoe / Roboto / Noto Sans Thai |
|
||||||
|
| ระยะ | 4/8px rhythm, ขอบข้าง 20px |
|
||||||
|
| Accessibility | ข้อความ ≥4.5:1, ปุ่ม ≥44px, reduced-motion, focus ring |
|
||||||
|
| หน้าเมนูกล้อง | โครมดำทั้งหน้าแบบ One UI Camera |
|
||||||
|
|
||||||
|
## รันทดสอบ
|
||||||
|
|
||||||
### Option 1: Serve locally
|
|
||||||
```bash
|
```bash
|
||||||
cd app
|
cd app
|
||||||
python3 -m http.server 8080
|
python -m http.server 8099 --bind 0.0.0.0
|
||||||
# บนมือถือเปิด: http://<IP>:8080
|
|
||||||
|
# กล้องใช้ได้เฉพาะ HTTPS — เปิด tunnel แล้วสแกน QR ในแอป
|
||||||
|
cloudflared tunnel --url http://127.0.0.1:8099
|
||||||
```
|
```
|
||||||
|
|
||||||
### Option 2: Deploy to hosting
|
|
||||||
Upload ไฟล์ใน `app/` ไปยัง static host (Netlify, Vercel, GitHub Pages)
|
|
||||||
|
|
||||||
### Install PWA
|
|
||||||
1. เปิด URL ใน browser (Chrome/Safari)
|
|
||||||
2. Menu → "Add to Home Screen" / "Install"
|
|
||||||
3. เปิดจาก icon บน home screen เหมือน native app
|
|
||||||
|
|
||||||
## Files
|
## Files
|
||||||
|
|
||||||
```
|
```
|
||||||
app/
|
app/
|
||||||
├── index.html # UI shell
|
├── index.html # shell + header/nav แบบ One UI
|
||||||
├── app.js # App logic (camera, folders, zip, share, EXIF)
|
├── css/app.css # design tokens + components (light/dark)
|
||||||
├── sw.js # Service Worker (offline cache)
|
├── js/config.js # ค่าคงที่ (Site A, timezone, quality)
|
||||||
├── manifest.json # PWA manifest
|
├── js/naming.js # ชื่อโฟลเดอร์/ไฟล์ ปี พ.ศ.
|
||||||
├── icon-192.png # App icon 192x192
|
├── js/db.js # IndexedDB (folders, images, thumbs)
|
||||||
└── icon-512.png # App icon 512x512
|
├── js/exif.js # อ่าน/เขียน EXIF (piexifjs)
|
||||||
|
├── js/device.js # ตรวจรุ่นเครื่อง (SM-S911B → Galaxy S23)
|
||||||
|
├── js/camera.js # getUserMedia, ImageCapture, torch, zoom
|
||||||
|
├── js/archive.js # ZIP + ดาวน์โหลด + Web Share (มี cache)
|
||||||
|
├── js/ui.js # markup + bottom sheet + toast
|
||||||
|
├── js/main.js # state, events, ธีม, diagnostics
|
||||||
|
├── vendor/ # jszip, piexif, qrcode (ใช้ offline)
|
||||||
|
├── sw.js · manifest.json · icon-*.png
|
||||||
|
└── README.md
|
||||||
```
|
```
|
||||||
|
|
||||||
## Browser Support
|
## Browser
|
||||||
|
|
||||||
- Chrome/Edge 90+ (full)
|
Chrome/Edge Android (Samsung S23 คือเครื่องทดสอบหลัก) · Safari 16+ (ไม่มี torch/zoom)
|
||||||
- Safari 15+ (camera + install)
|
|
||||||
- Firefox 88+ (no PWA install)
|
|
||||||
|
|
||||||
## Tech
|
|
||||||
|
|
||||||
- IndexedDB — local storage for folders + images
|
|
||||||
- MediaDevices API — camera access
|
|
||||||
- Web Share API — native share sheet
|
|
||||||
- JSZip — zip generation
|
|
||||||
- Service Worker — offline support
|
|
||||||
-524
@@ -1,524 +0,0 @@
|
|||||||
// ─────────────────────────────────────────────────────────────
|
|
||||||
// CamCat — Web Camera Category PWA
|
|
||||||
// Take photos → organize into folders → zip & share
|
|
||||||
// ─────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
// ── State ──
|
|
||||||
const DB_NAME = "camcat-db";
|
|
||||||
const STORE_FOLDERS = "folders";
|
|
||||||
const STORE_IMAGES = "images";
|
|
||||||
let db = null;
|
|
||||||
let currentView = "camera";
|
|
||||||
let activeFolderId = null;
|
|
||||||
let currentStream = null;
|
|
||||||
let facingMode = "environment";
|
|
||||||
let selectedImages = new Set();
|
|
||||||
let viewingImage = null;
|
|
||||||
|
|
||||||
// ── IndexedDB setup ──
|
|
||||||
function openDB() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const req = indexedDB.open(DB_NAME, 1);
|
|
||||||
req.onupgradeneeded = (e) => {
|
|
||||||
const d = e.target.result;
|
|
||||||
if (!d.objectStoreNames.contains(STORE_FOLDERS)) {
|
|
||||||
d.createObjectStore(STORE_FOLDERS, { keyPath: "id" });
|
|
||||||
}
|
|
||||||
if (!d.objectStoreNames.contains(STORE_IMAGES)) {
|
|
||||||
const s = d.createObjectStore(STORE_IMAGES, { keyPath: "id" });
|
|
||||||
s.createIndex("folderId", "folderId", { unique: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
req.onsuccess = () => resolve(req.result);
|
|
||||||
req.onerror = () => reject(req.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbGet(store, key) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(store, "readonly");
|
|
||||||
tx.objectStore(store).get(key).onsuccess = (e) => resolve(e.target.result);
|
|
||||||
tx.onerror = () => reject(tx.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbGetAll(store) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(store, "readonly");
|
|
||||||
tx.objectStore(store).getAll().onsuccess = (e) => resolve(e.target.result);
|
|
||||||
tx.onerror = () => reject(tx.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbGetByIndex(store, indexName, value) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(store, "readonly");
|
|
||||||
tx.objectStore(store).index(indexName).getAll(value).onsuccess = (e) => resolve(e.target.result);
|
|
||||||
tx.onerror = () => reject(tx.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbPut(store, obj) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(store, "readwrite");
|
|
||||||
tx.objectStore(store).put(obj).onsuccess = () => resolve(obj);
|
|
||||||
tx.onerror = () => reject(tx.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbDelete(store, key) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tx = db.transaction(store, "readwrite");
|
|
||||||
tx.objectStore(store).delete(key).onsuccess = () => resolve();
|
|
||||||
tx.onerror = () => reject(tx.error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Folder operations ──
|
|
||||||
async function createFolder(name) {
|
|
||||||
const folder = { id: "f_" + Date.now(), name, createdAt: Date.now() };
|
|
||||||
await dbPut(STORE_FOLDERS, folder);
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function renameFolder(id, name) {
|
|
||||||
const f = await dbGet(STORE_FOLDERS, id);
|
|
||||||
if (f) { f.name = name; await dbPut(STORE_FOLDERS, f); }
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteFolder(id) {
|
|
||||||
const imgs = await dbGetByIndex(STORE_IMAGES, "folderId", id);
|
|
||||||
for (const img of imgs) await dbDelete(STORE_IMAGES, img.id);
|
|
||||||
await dbDelete(STORE_FOLDERS, id);
|
|
||||||
if (activeFolderId === id) activeFolderId = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFolders() {
|
|
||||||
return dbGetAll(STORE_FOLDERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getActiveFolder() {
|
|
||||||
if (!activeFolderId) return null;
|
|
||||||
return dbGet(STORE_FOLDERS, activeFolderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setActiveFolder(id) {
|
|
||||||
activeFolderId = id;
|
|
||||||
const f = await dbGet(STORE_FOLDERS, id);
|
|
||||||
document.getElementById("active-folder-pill").textContent = "📁 " + (f ? f.name : "None");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Image operations ──
|
|
||||||
async function saveImage(blob, exifData) {
|
|
||||||
if (!activeFolderId) {
|
|
||||||
const folders = await getFolders();
|
|
||||||
if (folders.length === 0) {
|
|
||||||
const f = await createFolder("Default");
|
|
||||||
await setActiveFolder(f.id);
|
|
||||||
} else {
|
|
||||||
await setActiveFolder(folders[0].id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const img = {
|
|
||||||
id: "img_" + Date.now(),
|
|
||||||
folderId: activeFolderId,
|
|
||||||
blob: blob,
|
|
||||||
exif: exifData,
|
|
||||||
createdAt: Date.now(),
|
|
||||||
};
|
|
||||||
await dbPut(STORE_IMAGES, img);
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getImages(folderId) {
|
|
||||||
return dbGetByIndex(STORE_IMAGES, "folderId", folderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getImage(id) {
|
|
||||||
return dbGet(STORE_IMAGES, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── EXIF parsing (basic) ──
|
|
||||||
function parseEXIF(blob) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = () => {
|
|
||||||
const buf = new DataView(reader.result);
|
|
||||||
let exif = {};
|
|
||||||
try {
|
|
||||||
// Check JPEG SOI marker
|
|
||||||
if (buf.getUint16(0) !== 0xFFD8) return resolve({});
|
|
||||||
let offset = 2;
|
|
||||||
while (offset < buf.byteLength) {
|
|
||||||
if (buf.getUint16(offset) !== 0xFFE1) { offset += 2; continue; }
|
|
||||||
// Found APP1 (EXIF)
|
|
||||||
const exifLen = buf.getUint16(offset + 2);
|
|
||||||
const exifStart = offset + 4;
|
|
||||||
const tiffStart = exifStart + 6;
|
|
||||||
const bigEndian = buf.getUint16(tiffStart) === 0x4D4D;
|
|
||||||
const getU16 = (o) => bigEndian ? buf.getUint16(o) : buf.getUint16(o, true);
|
|
||||||
const getU32 = (o) => bigEndian ? buf.getUint32(o) : buf.getUint32(o, true);
|
|
||||||
const ifdOffset = tiffStart + getU32(tiffStart + 4);
|
|
||||||
const numEntries = getU16(ifdOffset);
|
|
||||||
const tags = {
|
|
||||||
0x010F: "Make", 0x0110: "Model", 0x0132: "DateTime",
|
|
||||||
0x0100: "ImageWidth", 0x0101: "ImageHeight",
|
|
||||||
0x011A: "FocalLength", 0x876D: "ISO",
|
|
||||||
0x829A: "ExposureTime", 0x829D: "FNumber",
|
|
||||||
};
|
|
||||||
for (let i = 0; i < numEntries; i++) {
|
|
||||||
const entry = ifdOffset + 2 + i * 12;
|
|
||||||
const tag = getU16(entry);
|
|
||||||
const type = getU16(entry + 2);
|
|
||||||
const count = getU32(entry + 4);
|
|
||||||
const valOffset = count > 4 ? tiffStart + getU32(entry + 8) : entry + 8;
|
|
||||||
const name = tags[tag];
|
|
||||||
if (!name) continue;
|
|
||||||
if (type === 2) { // ASCII
|
|
||||||
let s = "";
|
|
||||||
for (let j = 0; j < count - 1; j++) s += String.fromCharCode(buf.getUint8(valOffset + j));
|
|
||||||
exif[name] = s;
|
|
||||||
} else if (type === 3) { // SHORT
|
|
||||||
exif[name] = getU16(valOffset);
|
|
||||||
} else if (type === 4) { // LONG
|
|
||||||
exif[name] = getU32(valOffset);
|
|
||||||
} else if (type === 5) { // RATIONAL
|
|
||||||
exif[name] = (getU32(valOffset) / getU32(valOffset + 4)).toFixed(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (e) { /* ignore parse errors */ }
|
|
||||||
resolve(exif);
|
|
||||||
};
|
|
||||||
reader.readAsArrayBuffer(blob);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Camera ──
|
|
||||||
async function startCamera() {
|
|
||||||
if (currentStream) currentStream.getTracks().forEach(t => t.stop());
|
|
||||||
try {
|
|
||||||
currentStream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: { facingMode, width: { ideal: 4032 }, height: { ideal: 3024 } },
|
|
||||||
audio: false,
|
|
||||||
});
|
|
||||||
const video = document.getElementById("video");
|
|
||||||
if (video) { video.srcObject = currentStream; await video.play(); }
|
|
||||||
} catch (e) {
|
|
||||||
toast("Camera access denied: " + e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopCamera() {
|
|
||||||
if (currentStream) {
|
|
||||||
currentStream.getTracks().forEach(t => t.stop());
|
|
||||||
currentStream = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function takePhoto() {
|
|
||||||
const video = document.getElementById("video");
|
|
||||||
if (!video || !video.videoWidth) { toast("Camera not ready"); return; }
|
|
||||||
const canvas = document.createElement("canvas");
|
|
||||||
canvas.width = video.videoWidth;
|
|
||||||
canvas.height = video.videoHeight;
|
|
||||||
canvas.getContext("2d").drawImage(video, 0, 0);
|
|
||||||
const blob = await new Promise(r => canvas.toBlob(r, "image/jpeg", 0.9));
|
|
||||||
const exif = await parseEXIF(blob);
|
|
||||||
// Add GPS if available
|
|
||||||
if (navigator.geolocation) {
|
|
||||||
try {
|
|
||||||
const pos = await new Promise((res, rej) => navigator.geolocation.getCurrentPosition(res, rej, { timeout: 3000 }));
|
|
||||||
exif.GPS = `${pos.coords.latitude.toFixed(4)}, ${pos.coords.longitude.toFixed(4)}`;
|
|
||||||
} catch (e) { /* GPS not available */ }
|
|
||||||
}
|
|
||||||
await saveImage(blob, exif);
|
|
||||||
const f = await getActiveFolder();
|
|
||||||
toast(`📸 Saved to ${f ? f.name : "folder"}`);
|
|
||||||
// Flash effect
|
|
||||||
const flash = document.createElement("div");
|
|
||||||
flash.style.cssText = "position:fixed;inset:0;background:white;opacity:0.6;z-index:999;pointer-events:none";
|
|
||||||
document.body.appendChild(flash);
|
|
||||||
setTimeout(() => flash.remove(), 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Zip & Share ──
|
|
||||||
async function zipSelected() {
|
|
||||||
if (selectedImages.size === 0) { toast("Select images first"); return; }
|
|
||||||
toast("Creating ZIP...");
|
|
||||||
const zip = new JSZip();
|
|
||||||
const folder = await getActiveFolder();
|
|
||||||
const zipName = (folder ? folder.name : "photos") + "_" + selectedImages.size + "items";
|
|
||||||
for (const imgId of selectedImages) {
|
|
||||||
const img = await getImage(imgId);
|
|
||||||
if (img) {
|
|
||||||
const ext = "jpg";
|
|
||||||
zip.file(img.id + "." + ext, img.blob);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const zipBlob = await zip.generateAsync({ type: "blob" });
|
|
||||||
const file = new File([zipBlob], zipName + ".zip", { type: "application/zip" });
|
|
||||||
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
|
||||||
await navigator.share({ files: [file], title: zipName });
|
|
||||||
} else {
|
|
||||||
// Fallback: download
|
|
||||||
const url = URL.createObjectURL(zipBlob);
|
|
||||||
const a = document.createElement("a");
|
|
||||||
a.href = url; a.download = zipName + ".zip"; a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
}
|
|
||||||
selectedImages.clear();
|
|
||||||
toast("✅ ZIP shared");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function shareImage(imgId) {
|
|
||||||
const img = await getImage(imgId);
|
|
||||||
if (!img) return;
|
|
||||||
const file = new File([img.blob], img.id + ".jpg", { type: "image/jpeg" });
|
|
||||||
if (navigator.canShare && navigator.canShare({ files: [file] })) {
|
|
||||||
await navigator.share({ files: [file] });
|
|
||||||
} else {
|
|
||||||
const url = URL.createObjectURL(img.blob);
|
|
||||||
const a = document.createElement("a");
|
|
||||||
a.href = url; a.download = img.id + ".jpg"; a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Navigation & Rendering ──
|
|
||||||
function navigate(view) {
|
|
||||||
currentView = view;
|
|
||||||
document.querySelectorAll("nav button").forEach(b => b.classList.remove("active"));
|
|
||||||
document.getElementById("nav-" + view).classList.add("active");
|
|
||||||
if (view !== "camera") stopCamera();
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function render() {
|
|
||||||
const main = document.getElementById("main");
|
|
||||||
if (currentView === "camera") renderCamera(main);
|
|
||||||
else if (currentView === "folders") await renderFolders(main);
|
|
||||||
else if (currentView === "gallery") await renderGallery(main);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderCamera(main) {
|
|
||||||
main.innerHTML = `
|
|
||||||
<div id="camera-view">
|
|
||||||
<video id="video" autoplay playsinline muted></video>
|
|
||||||
<div class="camera-bar">
|
|
||||||
<button id="switch-cam" onclick="switchCamera()">
|
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"/></svg>
|
|
||||||
</button>
|
|
||||||
<button id="shutter" onclick="takePhoto()"></button>
|
|
||||||
<div style="width:44px"></div>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
startCamera();
|
|
||||||
}
|
|
||||||
|
|
||||||
function switchCamera() {
|
|
||||||
facingMode = facingMode === "environment" ? "user" : "environment";
|
|
||||||
startCamera();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function renderFolders(main) {
|
|
||||||
const folders = await getFolders();
|
|
||||||
let html = `<div class="section-head"><h2>📁 Folders</h2><button class="btn-primary" onclick="showNewFolderModal()">+ New</button></div><div class="folder-list">`;
|
|
||||||
if (folders.length === 0) {
|
|
||||||
html += `<div class="empty"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"/></svg><p>No folders yet</p></div>`;
|
|
||||||
} else {
|
|
||||||
for (const f of folders) {
|
|
||||||
const count = (await getImages(f.id)).length;
|
|
||||||
const isActive = f.id === activeFolderId;
|
|
||||||
html += `<div class="folder-item ${isActive ? "active" : ""}" onclick="selectFolder('${f.id}')">
|
|
||||||
<div><div class="name">${esc(f.name)}</div><div class="meta">${count} items${isActive ? " · Active" : ""}</div></div>
|
|
||||||
<div class="actions" onclick="event.stopPropagation()">
|
|
||||||
<button class="icon-btn" onclick="showRenameModal('${f.id}','${esc(f.name)}')" title="Rename">✏️</button>
|
|
||||||
<button class="icon-btn" onclick="confirmDeleteFolder('${f.id}','${esc(f.name)}')" title="Delete">🗑️</button>
|
|
||||||
</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
html += `</div>`;
|
|
||||||
main.innerHTML = html;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function selectFolder(id) {
|
|
||||||
await setActiveFolder(id);
|
|
||||||
await render();
|
|
||||||
const f = await getActiveFolder();
|
|
||||||
toast("📁 Active: " + (f ? f.name : ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function renderGallery(main) {
|
|
||||||
if (!activeFolderId) {
|
|
||||||
main.innerHTML = `<div class="empty"><p>Select a folder first</p></div>`;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const folder = await getActiveFolder();
|
|
||||||
const images = await getImages(activeFolderId);
|
|
||||||
let html = `<div class="section-head"><h2>🖼️ ${esc(folder ? folder.name : "")}</h2>
|
|
||||||
<div class="gallery-actions">
|
|
||||||
<button class="btn-ghost" onclick="zipSelected()">📦 Zip</button>
|
|
||||||
<button class="btn-ghost" onclick="shareSelected()">📤 Share</button>
|
|
||||||
</div></div>`;
|
|
||||||
if (images.length === 0) {
|
|
||||||
html += `<div class="empty"><p>No photos yet</p></div>`;
|
|
||||||
} else {
|
|
||||||
html += `<div class="gallery-grid">`;
|
|
||||||
for (const img of images) {
|
|
||||||
const url = URL.createObjectURL(img.blob);
|
|
||||||
const sel = selectedImages.has(img.id) ? "selected" : "";
|
|
||||||
html += `<div class="gallery-item ${sel}" onclick="toggleSelect('${img.id}')">
|
|
||||||
<img src="${url}" loading="lazy"><div class="check">✓</div>
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
html += `</div>`;
|
|
||||||
html += `<div class="gallery-bar"><span>${selectedImages.size} selected · ${images.length} total</span>
|
|
||||||
<span>${selectedImages.size > 0 ? '<button class="btn-ghost" onclick="clearSelection()">Clear</button>' : ''}</span></div>`;
|
|
||||||
}
|
|
||||||
main.innerHTML = html;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleSelect(id) {
|
|
||||||
if (selectedImages.has(id)) selectedImages.delete(id);
|
|
||||||
else selectedImages.add(id);
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearSelection() { selectedImages.clear(); render(); }
|
|
||||||
|
|
||||||
async function shareSelected() {
|
|
||||||
if (selectedImages.size === 0) { toast("Select images first"); return; }
|
|
||||||
if (selectedImages.size === 1) { await shareImage([...selectedImages][0]); return; }
|
|
||||||
await zipSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Image viewer with EXIF ──
|
|
||||||
async function showImageViewer(imgId) {
|
|
||||||
const img = await getImage(imgId);
|
|
||||||
if (!img) return;
|
|
||||||
const url = URL.createObjectURL(img.blob);
|
|
||||||
let exifHtml = "";
|
|
||||||
if (img.exif) {
|
|
||||||
const rows = Object.entries(img.exif).map(([k, v]) => `<div class="row"><span class="key">${k}</span><span class="val">${esc(String(v))}</span></div>`);
|
|
||||||
exifHtml = `<div class="exif-panel"><b>EXIF Data</b>${rows.join("")}</div>`;
|
|
||||||
}
|
|
||||||
document.getElementById("modal-content").innerHTML = `
|
|
||||||
<h3>Image</h3>
|
|
||||||
<img src="${url}" style="width:100%;border-radius:8px;margin-bottom:12px">
|
|
||||||
${exifHtml}
|
|
||||||
<div class="modal-actions" style="margin-top:12px">
|
|
||||||
<button class="btn-ghost" onclick="closeModal()">Close</button>
|
|
||||||
<button class="btn-primary" onclick="shareImage('${imgId}')">📤 Share</button>
|
|
||||||
</div>`;
|
|
||||||
document.getElementById("modal-overlay").classList.add("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Modals ──
|
|
||||||
function showNewFolderModal() {
|
|
||||||
document.getElementById("modal-content").innerHTML = `
|
|
||||||
<h3>New Folder</h3>
|
|
||||||
<input id="folder-name-input" placeholder="Folder name" autofocus>
|
|
||||||
<div class="modal-actions">
|
|
||||||
<button class="btn-ghost" onclick="closeModal()">Cancel</button>
|
|
||||||
<button class="btn-primary" onclick="doCreateFolder()">Create</button>
|
|
||||||
</div>`;
|
|
||||||
document.getElementById("modal-overlay").classList.add("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doCreateFolder() {
|
|
||||||
const name = document.getElementById("folder-name-input").value.trim();
|
|
||||||
if (!name) { toast("Enter a name"); return; }
|
|
||||||
const f = await createFolder(name);
|
|
||||||
await setActiveFolder(f.id);
|
|
||||||
closeModal();
|
|
||||||
await render();
|
|
||||||
toast("✅ Folder created");
|
|
||||||
}
|
|
||||||
|
|
||||||
function showRenameModal(id, name) {
|
|
||||||
document.getElementById("modal-content").innerHTML = `
|
|
||||||
<h3>Rename Folder</h3>
|
|
||||||
<input id="folder-name-input" value="${esc(name)}" autofocus>
|
|
||||||
<div class="modal-actions">
|
|
||||||
<button class="btn-ghost" onclick="closeModal()">Cancel</button>
|
|
||||||
<button class="btn-primary" onclick="doRenameFolder('${id}')">Rename</button>
|
|
||||||
</div>`;
|
|
||||||
document.getElementById("modal-overlay").classList.add("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doRenameFolder(id) {
|
|
||||||
const name = document.getElementById("folder-name-input").value.trim();
|
|
||||||
if (!name) { toast("Enter a name"); return; }
|
|
||||||
await renameFolder(id, name);
|
|
||||||
closeModal();
|
|
||||||
await render();
|
|
||||||
toast("✅ Renamed");
|
|
||||||
}
|
|
||||||
|
|
||||||
function confirmDeleteFolder(id, name) {
|
|
||||||
document.getElementById("modal-content").innerHTML = `
|
|
||||||
<h3>Delete "${esc(name)}"?</h3>
|
|
||||||
<p style="color:var(--muted);margin-bottom:12px">All photos in this folder will be deleted.</p>
|
|
||||||
<div class="modal-actions">
|
|
||||||
<button class="btn-ghost" onclick="closeModal()">Cancel</button>
|
|
||||||
<button class="btn-primary" style="background:var(--red)" onclick="doDeleteFolder('${id}')">Delete</button>
|
|
||||||
</div>`;
|
|
||||||
document.getElementById("modal-overlay").classList.add("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doDeleteFolder(id) {
|
|
||||||
await deleteFolder(id);
|
|
||||||
closeModal();
|
|
||||||
await render();
|
|
||||||
toast("✅ Deleted");
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeModal() {
|
|
||||||
document.getElementById("modal-overlay").classList.remove("show");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Toast ──
|
|
||||||
let toastTimer = null;
|
|
||||||
function toast(msg) {
|
|
||||||
const el = document.getElementById("toast");
|
|
||||||
el.textContent = msg;
|
|
||||||
el.classList.add("show");
|
|
||||||
clearTimeout(toastTimer);
|
|
||||||
toastTimer = setTimeout(() => el.classList.remove("show"), 2500);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Utils ──
|
|
||||||
function esc(s) { return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"); }
|
|
||||||
|
|
||||||
// ── Init ──
|
|
||||||
async function init() {
|
|
||||||
db = await openDB();
|
|
||||||
// Ensure default folder
|
|
||||||
const folders = await getFolders();
|
|
||||||
if (folders.length === 0) {
|
|
||||||
const f = await createFolder("Default");
|
|
||||||
await setActiveFolder(f.id);
|
|
||||||
} else {
|
|
||||||
await setActiveFolder(folders[0].id);
|
|
||||||
}
|
|
||||||
// Register service worker
|
|
||||||
if ("serviceWorker" in navigator) {
|
|
||||||
try { await navigator.serviceWorker.register("sw.js"); } catch (e) { console.warn("SW registration failed", e); }
|
|
||||||
}
|
|
||||||
// Request persistent storage
|
|
||||||
if (navigator.storage && navigator.storage.persist) {
|
|
||||||
await navigator.storage.persist();
|
|
||||||
}
|
|
||||||
await render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close modal on overlay click
|
|
||||||
document.getElementById("modal-overlay").addEventListener("click", (e) => {
|
|
||||||
if (e.target.id === "modal-overlay") closeModal();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Init on load
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
|
||||||
+853
@@ -0,0 +1,853 @@
|
|||||||
|
/* ============================================================
|
||||||
|
CamCat — One UI (Samsung) look & feel
|
||||||
|
ภาษาเดียวกับ One UI 6/7: การ์ดมุมโค้ง 26px, พิลล์แคปซูล,
|
||||||
|
พื้นผิวเรียบ ไม่มีเส้นขอบหนา, ไอคอน SVG 24px, ระยะ 4/8px
|
||||||
|
ปรับให้ Galaxy S23 (360–412 CSS px, safe area, 100dvh)
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* Light — ค่าเริ่มต้นแบบ One UI */
|
||||||
|
--bg: #F2F3F5;
|
||||||
|
--bg-2: #E8EAED;
|
||||||
|
--card: #FFFFFF;
|
||||||
|
--card-2: #F7F8F9;
|
||||||
|
--text: #101114;
|
||||||
|
--text-2: #5C6169;
|
||||||
|
--text-3: #62676F;
|
||||||
|
--line: rgba(16, 17, 20, 0.08);
|
||||||
|
--accent: #0A72DE;
|
||||||
|
--accent-text: #0E5FB8;
|
||||||
|
--accent-soft: #E4EFFC;
|
||||||
|
--on-accent: #FFFFFF;
|
||||||
|
--danger: #D93025;
|
||||||
|
--danger-soft: #FCE8E6;
|
||||||
|
--field: #EBEDF0;
|
||||||
|
|
||||||
|
--shadow-card: 0 1px 2px rgba(16, 17, 20, 0.05), 0 6px 18px rgba(16, 17, 20, 0.05);
|
||||||
|
--shadow-float: 0 6px 20px rgba(16, 17, 20, 0.14);
|
||||||
|
|
||||||
|
--radius-card: 26px;
|
||||||
|
--radius-row: 20px;
|
||||||
|
--radius-field: 16px;
|
||||||
|
--radius-pill: 999px;
|
||||||
|
|
||||||
|
--pad: 20px;
|
||||||
|
--gap: 12px;
|
||||||
|
--nav-h: 64px;
|
||||||
|
|
||||||
|
--safe-top: env(safe-area-inset-top, 0px);
|
||||||
|
--safe-bottom: env(safe-area-inset-bottom, 0px);
|
||||||
|
--safe-left: env(safe-area-inset-left, 0px);
|
||||||
|
--safe-right: env(safe-area-inset-right, 0px);
|
||||||
|
|
||||||
|
--ease: cubic-bezier(0.2, 0, 0, 1);
|
||||||
|
--dur: 180ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root:not([data-theme="light"]) {
|
||||||
|
--bg: #000000;
|
||||||
|
--bg-2: #101114;
|
||||||
|
--card: #1B1B1D;
|
||||||
|
--card-2: #232326;
|
||||||
|
--text: #F2F3F5;
|
||||||
|
--text-2: #A9AEB6;
|
||||||
|
--text-3: #7C8188;
|
||||||
|
--line: rgba(255, 255, 255, 0.10);
|
||||||
|
--accent: #4E9DFF;
|
||||||
|
--accent-text: #6FB3FF;
|
||||||
|
--accent-soft: #16304D;
|
||||||
|
--on-accent: #06121F;
|
||||||
|
--danger: #FF6B60;
|
||||||
|
--danger-soft: #3A1A18;
|
||||||
|
--field: #26272A;
|
||||||
|
--shadow-card: none;
|
||||||
|
--shadow-float: 0 8px 24px rgba(0, 0, 0, 0.55);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:root[data-theme="dark"] {
|
||||||
|
--bg: #000000;
|
||||||
|
--bg-2: #101114;
|
||||||
|
--card: #1B1B1D;
|
||||||
|
--card-2: #232326;
|
||||||
|
--text: #F2F3F5;
|
||||||
|
--text-2: #A9AEB6;
|
||||||
|
--text-3: #7C8188;
|
||||||
|
--line: rgba(255, 255, 255, 0.10);
|
||||||
|
--accent: #4E9DFF;
|
||||||
|
--accent-text: #6FB3FF;
|
||||||
|
--accent-soft: #16304D;
|
||||||
|
--on-accent: #06121F;
|
||||||
|
--danger: #FF6B60;
|
||||||
|
--danger-soft: #3A1A18;
|
||||||
|
--field: #26272A;
|
||||||
|
--shadow-card: none;
|
||||||
|
--shadow-float: 0 8px 24px rgba(0, 0, 0, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
button, input, label { touch-action: manipulation; }
|
||||||
|
|
||||||
|
html { height: 100%; background: var(--bg); }
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: "SamsungOneUI", "SF Pro Text", -apple-system, BlinkMacSystemFont,
|
||||||
|
"Segoe UI", Roboto, "Noto Sans Thai", "IBM Plex Sans Thai", sans-serif;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
height: 100vh;
|
||||||
|
height: 100dvh;
|
||||||
|
overflow: hidden;
|
||||||
|
overscroll-behavior: none;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 1.45;
|
||||||
|
letter-spacing: -0.1px;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100dvh;
|
||||||
|
padding-left: var(--safe-left);
|
||||||
|
padding-right: var(--safe-right);
|
||||||
|
background: var(--bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Header (One UI large title) ─────────────────────────── */
|
||||||
|
header {
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: calc(8px + var(--safe-top)) var(--pad) 10px;
|
||||||
|
background: var(--bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.head-text { flex: 1; min-width: 0; }
|
||||||
|
|
||||||
|
header h1 {
|
||||||
|
font-size: 23px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.4px;
|
||||||
|
line-height: 1.2;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.head-sub {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 3px;
|
||||||
|
margin-top: 2px;
|
||||||
|
max-width: 100%;
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
padding: 0;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
text-align: left;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
cursor: pointer;
|
||||||
|
min-height: 32px;
|
||||||
|
}
|
||||||
|
.head-sub svg { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.8; }
|
||||||
|
|
||||||
|
.head-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
|
||||||
|
|
||||||
|
.icon-round {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 0;
|
||||||
|
background: var(--card);
|
||||||
|
color: var(--text-2);
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.icon-round svg { width: 22px; height: 22px; }
|
||||||
|
.icon-round:active { transform: scale(0.94); background: var(--bg-2); }
|
||||||
|
|
||||||
|
/* ── Main ────────────────────────────────────────────────── */
|
||||||
|
main {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Bottom tabs (One UI) ────────────────────────────────── */
|
||||||
|
nav {
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: flex;
|
||||||
|
background: var(--card);
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
padding: 6px 6px calc(6px + var(--safe-bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
nav button {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 52px;
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 11.5px;
|
||||||
|
font-weight: 500;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 2px;
|
||||||
|
padding: 4px 2px;
|
||||||
|
border-radius: var(--radius-row);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: color var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav button .tab-ico {
|
||||||
|
width: 56px;
|
||||||
|
height: 30px;
|
||||||
|
border-radius: var(--radius-pill);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: background var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
nav button svg { width: 23px; height: 23px; }
|
||||||
|
nav button.active { color: var(--accent-text); font-weight: 600; }
|
||||||
|
nav button.active .tab-ico { background: var(--accent-soft); }
|
||||||
|
nav button:active .tab-ico { background: var(--bg-2); }
|
||||||
|
|
||||||
|
/* ── หน้าเมนูกล้อง: โครมทั้งหน้าเป็นดำแบบ One UI Camera ──── */
|
||||||
|
#app[data-view="camera"] { background: #000; }
|
||||||
|
#app[data-view="camera"] header { background: #000; color: #F5F6F7; }
|
||||||
|
#app[data-view="camera"] header h1 { color: #F5F6F7; }
|
||||||
|
#app[data-view="camera"] .head-sub { color: #A9AEB6; }
|
||||||
|
#app[data-view="camera"] .icon-round { background: #1B1B1D; color: #E7E8EA; box-shadow: none; }
|
||||||
|
#app[data-view="camera"] nav { background: #000; border-top-color: rgba(255, 255, 255, 0.10); }
|
||||||
|
#app[data-view="camera"] nav button { color: #8A9099; }
|
||||||
|
#app[data-view="camera"] nav button.active { color: #6FB3FF; }
|
||||||
|
#app[data-view="camera"] nav button.active .tab-ico { background: #16304D; }
|
||||||
|
#app[data-view="camera"] nav button:active .tab-ico { background: #232326; }
|
||||||
|
|
||||||
|
/* ── Camera (One UI Camera = black) ──────────────────────── */
|
||||||
|
#camera-view {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
background: #000;
|
||||||
|
color: #F5F6F7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#video {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
display: block;
|
||||||
|
background: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-lines {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 0.3;
|
||||||
|
background-image:
|
||||||
|
linear-gradient(to right, #fff 1px, transparent 1px),
|
||||||
|
linear-gradient(to bottom, #fff 1px, transparent 1px);
|
||||||
|
background-size: 33.333% 33.333%;
|
||||||
|
background-position: -1px -1px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.grid-lines.on { display: block; }
|
||||||
|
|
||||||
|
.cam-top {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cam-chip {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: rgba(28, 29, 32, 0.62);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
-webkit-backdrop-filter: blur(10px);
|
||||||
|
border: 0;
|
||||||
|
color: #fff;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.cam-chip svg { width: 21px; height: 21px; }
|
||||||
|
.cam-chip:active { transform: scale(0.93); }
|
||||||
|
.cam-chip[aria-pressed="true"] { background: #FFD54A; color: #201A00; }
|
||||||
|
|
||||||
|
.cam-bottom {
|
||||||
|
flex-shrink: 0;
|
||||||
|
background: #000;
|
||||||
|
padding: 10px 18px 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* zoom pills แบบ One UI Camera (1× / 2× / 3×) */
|
||||||
|
.zoom-pills {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
min-height: 40px;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
.zoom-pills[hidden] { display: none; }
|
||||||
|
|
||||||
|
.zoom-pill {
|
||||||
|
min-width: 44px;
|
||||||
|
height: 36px;
|
||||||
|
padding: 0 11px;
|
||||||
|
border-radius: var(--radius-pill);
|
||||||
|
border: 0;
|
||||||
|
background: rgba(255, 255, 255, 0.14);
|
||||||
|
color: #EDEEF0;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 12.5px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.zoom-pill.on { background: #FFD54A; color: #201A00; }
|
||||||
|
|
||||||
|
.shutter-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.shutter-side {
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumb-btn {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.18);
|
||||||
|
background: #1B1B1D;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #8A9099;
|
||||||
|
}
|
||||||
|
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||||
|
.thumb-btn:empty::after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 2px solid currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
#shutter {
|
||||||
|
width: 76px;
|
||||||
|
height: 76px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #FFFFFF;
|
||||||
|
border: 4px solid #000;
|
||||||
|
box-shadow: 0 0 0 3px #FFFFFF;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 90ms var(--ease), background 90ms var(--ease);
|
||||||
|
}
|
||||||
|
#shutter:active { transform: scale(0.9); background: #D7D9DD; }
|
||||||
|
#shutter:disabled { opacity: 0.45; }
|
||||||
|
|
||||||
|
#shot-count { font-size: 12px; color: #A9AEB6; font-weight: 500; }
|
||||||
|
|
||||||
|
/* ── Section heads / buttons ─────────────────────────────── */
|
||||||
|
.section-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 14px var(--pad) 10px;
|
||||||
|
}
|
||||||
|
.section-head h2 {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.3px;
|
||||||
|
line-height: 1.25;
|
||||||
|
}
|
||||||
|
.section-head .sub {
|
||||||
|
font-size: 12.5px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-weight: 400;
|
||||||
|
margin-top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
border-radius: var(--radius-pill);
|
||||||
|
border: 0;
|
||||||
|
padding: 0 18px;
|
||||||
|
min-height: 44px;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 7px;
|
||||||
|
transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.btn:active { transform: scale(0.97); }
|
||||||
|
.btn:disabled { opacity: 0.45; }
|
||||||
|
.btn svg { width: 18px; height: 18px; }
|
||||||
|
.btn-primary { background: var(--accent); color: var(--on-accent); }
|
||||||
|
.btn-ghost { background: var(--card); color: var(--text); box-shadow: var(--shadow-card); }
|
||||||
|
.btn-tonal { background: var(--accent-soft); color: var(--accent-text); }
|
||||||
|
.btn-danger { background: var(--danger); color: #fff; }
|
||||||
|
.btn-block { width: 100%; min-height: 52px; font-size: 15px; }
|
||||||
|
|
||||||
|
/* ── Folder list (One UI cards) ──────────────────────────── */
|
||||||
|
.folder-list {
|
||||||
|
padding: 0 var(--pad) 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.folder-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
background: var(--card);
|
||||||
|
border-radius: var(--radius-card);
|
||||||
|
padding: 12px 12px 12px 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.folder-item:active { transform: scale(0.985); background: var(--card-2); }
|
||||||
|
.folder-item.active { box-shadow: var(--shadow-card), inset 0 0 0 2px var(--accent); }
|
||||||
|
|
||||||
|
.f-ico {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 15px;
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--accent-text);
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.f-ico svg { width: 23px; height: 23px; }
|
||||||
|
|
||||||
|
.folder-item .f-main { flex: 1; min-width: 0; }
|
||||||
|
.folder-item .f-name {
|
||||||
|
font-size: 15.5px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: -0.1px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.folder-item .f-meta {
|
||||||
|
font-size: 12.5px;
|
||||||
|
color: var(--text-2);
|
||||||
|
margin-top: 1px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.folder-item .f-actions { display: flex; gap: 2px; flex-shrink: 0; }
|
||||||
|
|
||||||
|
.icon-btn {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
color: var(--text-2);
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.icon-btn svg { width: 20px; height: 20px; }
|
||||||
|
.icon-btn:active { background: var(--bg-2); }
|
||||||
|
.icon-btn.danger { color: var(--danger); }
|
||||||
|
|
||||||
|
.storage-line {
|
||||||
|
padding: 4px var(--pad) calc(20px + 4px);
|
||||||
|
font-size: 12.5px;
|
||||||
|
color: var(--text-2);
|
||||||
|
line-height: 1.7;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Gallery ─────────────────────────────────────────────── */
|
||||||
|
.gallery-view {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
.gallery-view .gallery-grid { flex: 1; align-content: start; }
|
||||||
|
|
||||||
|
.gallery-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 4px;
|
||||||
|
padding: 0 12px 12px;
|
||||||
|
}
|
||||||
|
.gallery-item {
|
||||||
|
position: relative;
|
||||||
|
aspect-ratio: 1;
|
||||||
|
border-radius: 10px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--card);
|
||||||
|
border: 0;
|
||||||
|
padding: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
.gallery-item:active { transform: scale(0.96); filter: brightness(0.9); }
|
||||||
|
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||||
|
|
||||||
|
.action-bar {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 10px 16px calc(12px + 2px);
|
||||||
|
background: linear-gradient(to top, var(--bg) 62%, rgba(0, 0, 0, 0));
|
||||||
|
}
|
||||||
|
.action-bar .btn { flex: 1; min-height: 52px; font-size: 14.5px; }
|
||||||
|
|
||||||
|
/* ── Empty / notice ──────────────────────────────────────── */
|
||||||
|
.empty {
|
||||||
|
text-align: center;
|
||||||
|
padding: 48px 28px;
|
||||||
|
color: var(--text-2);
|
||||||
|
font-size: 13.5px;
|
||||||
|
}
|
||||||
|
.empty .ico {
|
||||||
|
display: flex;
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
border-radius: 22px;
|
||||||
|
background: var(--card);
|
||||||
|
color: var(--text-2);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin: 0 auto 12px;
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
}
|
||||||
|
.empty .ico svg { width: 28px; height: 28px; }
|
||||||
|
|
||||||
|
.notice {
|
||||||
|
margin: 12px var(--pad);
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: var(--radius-row);
|
||||||
|
background: var(--danger-soft);
|
||||||
|
color: var(--text);
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.notice b { display: block; margin-bottom: 4px; font-size: 13.5px; }
|
||||||
|
.notice ol { margin: 6px 0 0 18px; }
|
||||||
|
.notice code {
|
||||||
|
background: rgba(0, 0, 0, 0.06);
|
||||||
|
padding: 1px 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Camera hero / permission ────────────────────────────── */
|
||||||
|
.hero {
|
||||||
|
padding: 28px 26px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 14px;
|
||||||
|
text-align: center;
|
||||||
|
height: 100%;
|
||||||
|
background: #000;
|
||||||
|
color: #F5F6F7;
|
||||||
|
}
|
||||||
|
.hero .ico {
|
||||||
|
width: 72px;
|
||||||
|
height: 72px;
|
||||||
|
border-radius: 24px;
|
||||||
|
background: #1B1B1D;
|
||||||
|
color: #A9AEB6;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.hero .ico svg { width: 34px; height: 34px; }
|
||||||
|
.hero.cover { position: absolute; inset: 0; z-index: 6; }
|
||||||
|
.hero h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
|
||||||
|
.hero p { font-size: 13.5px; color: #A9AEB6; line-height: 1.65; max-width: 300px; }
|
||||||
|
.hero .btn { min-height: 52px; padding: 0 26px; }
|
||||||
|
.hero.cover .notice {
|
||||||
|
max-width: 340px;
|
||||||
|
margin: 0;
|
||||||
|
text-align: left;
|
||||||
|
background: rgba(217, 48, 37, 0.16);
|
||||||
|
color: #FFD9D5;
|
||||||
|
}
|
||||||
|
.hero .notice code { background: rgba(255, 255, 255, 0.12); color: #F5F6F7; word-break: break-all; }
|
||||||
|
.hero .spinner { border-color: rgba(255, 255, 255, 0.18); border-top-color: #fff; }
|
||||||
|
|
||||||
|
/* ── Bottom sheet (One UI) ───────────────────────────────── */
|
||||||
|
.sheet-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 100;
|
||||||
|
background: rgba(0, 0, 0, 0.48);
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: center;
|
||||||
|
animation: fade-in 160ms var(--ease);
|
||||||
|
}
|
||||||
|
.sheet-overlay[hidden] { display: none; }
|
||||||
|
|
||||||
|
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
|
||||||
|
@keyframes sheet-up {
|
||||||
|
from { transform: translateY(24px); opacity: 0.4; }
|
||||||
|
to { transform: none; opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.sheet {
|
||||||
|
position: relative;
|
||||||
|
background: var(--bg);
|
||||||
|
width: 100%;
|
||||||
|
max-width: 520px;
|
||||||
|
max-height: 88vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
border-radius: 28px 28px 0 0;
|
||||||
|
padding: 26px var(--pad) calc(16px + var(--safe-bottom));
|
||||||
|
box-shadow: var(--shadow-float);
|
||||||
|
animation: sheet-up 220ms var(--ease);
|
||||||
|
}
|
||||||
|
.sheet::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 9px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
width: 38px;
|
||||||
|
height: 4px;
|
||||||
|
border-radius: var(--radius-pill);
|
||||||
|
background: var(--text-3);
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
.sheet h3 {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.3px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
.sheet .hint {
|
||||||
|
font-size: 12.5px;
|
||||||
|
color: var(--text-2);
|
||||||
|
margin-bottom: 14px;
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
.sheet img.preview {
|
||||||
|
width: 100%;
|
||||||
|
max-height: 44vh;
|
||||||
|
object-fit: contain;
|
||||||
|
border-radius: 18px;
|
||||||
|
background: #000;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"], input[type="search"] {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 52px;
|
||||||
|
padding: 0 16px;
|
||||||
|
background: var(--card);
|
||||||
|
border: 2px solid transparent;
|
||||||
|
border-radius: var(--radius-field);
|
||||||
|
color: var(--text);
|
||||||
|
font-size: 16px; /* ≥16px กัน Chrome Android ซูม */
|
||||||
|
font-family: inherit;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
transition: border-color var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
input[type="text"]:focus, input[type="search"]:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sheet-actions { display: flex; gap: 10px; }
|
||||||
|
.sheet-actions .btn { flex: 1; min-height: 52px; }
|
||||||
|
|
||||||
|
/* ── Metadata table (One UI list) ────────────────────────── */
|
||||||
|
.meta-table {
|
||||||
|
font-size: 13.5px;
|
||||||
|
margin-top: 4px;
|
||||||
|
background: var(--card);
|
||||||
|
border-radius: var(--radius-row);
|
||||||
|
padding: 2px 16px;
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
}
|
||||||
|
.meta-table .row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 14px;
|
||||||
|
padding: 11px 0;
|
||||||
|
border-bottom: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
.meta-table .row:last-child { border-bottom: 0; }
|
||||||
|
.meta-table .k { color: var(--text-2); flex-shrink: 0; }
|
||||||
|
.meta-table .v { text-align: right; word-break: break-word; font-weight: 500; }
|
||||||
|
|
||||||
|
/* ── QR ──────────────────────────────────────────────────── */
|
||||||
|
.qr-box {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 24px;
|
||||||
|
padding: 16px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.qr-box canvas, .qr-box img {
|
||||||
|
width: 232px !important;
|
||||||
|
height: 232px !important;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.qr-url {
|
||||||
|
font-size: 11.5px;
|
||||||
|
color: var(--text-2);
|
||||||
|
word-break: break-all;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
font-family: ui-monospace, Menlo, Consolas, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Toast (One UI pill) ─────────────────────────────────── */
|
||||||
|
#toast {
|
||||||
|
position: fixed;
|
||||||
|
left: 50%;
|
||||||
|
bottom: calc(88px + var(--safe-bottom));
|
||||||
|
transform: translate(-50%, 10px);
|
||||||
|
max-width: 86vw;
|
||||||
|
background: #2A2A2D;
|
||||||
|
color: #F2F3F5;
|
||||||
|
padding: 11px 20px;
|
||||||
|
border-radius: var(--radius-pill);
|
||||||
|
font-size: 13.5px;
|
||||||
|
text-align: center;
|
||||||
|
z-index: 200;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
box-shadow: var(--shadow-float);
|
||||||
|
transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
|
||||||
|
}
|
||||||
|
#toast.show { opacity: 1; transform: translate(-50%, 0); }
|
||||||
|
|
||||||
|
/* ── Progress ────────────────────────────────────────────── */
|
||||||
|
.progress-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
padding: 18px 0 10px;
|
||||||
|
}
|
||||||
|
.spinner {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border: 3px solid var(--line);
|
||||||
|
border-top-color: var(--accent);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
|
.progress-card .label { font-size: 13.5px; color: var(--text-2); }
|
||||||
|
|
||||||
|
/* ── Focus / reduced motion ──────────────────────────────── */
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid var(--accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
*, *::before, *::after {
|
||||||
|
animation-duration: 1ms !important;
|
||||||
|
animation-iteration-count: 1 !important;
|
||||||
|
transition-duration: 1ms !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Landscape (S23 หมุนจอ 832×384) ──────────────────────── */
|
||||||
|
@media (max-height: 560px) and (orientation: landscape) {
|
||||||
|
header { padding-top: calc(4px + var(--safe-top)); padding-bottom: 4px; }
|
||||||
|
header h1 { font-size: 19px; }
|
||||||
|
.head-sub { font-size: 12px; }
|
||||||
|
.cam-bottom { padding: 4px 16px 8px; }
|
||||||
|
.zoom-pills { min-height: 32px; margin-bottom: 2px; }
|
||||||
|
.zoom-pill { height: 30px; }
|
||||||
|
#shutter { width: 60px; height: 60px; box-shadow: 0 0 0 2px #FFFFFF; }
|
||||||
|
.thumb-btn { width: 42px; height: 42px; }
|
||||||
|
nav { padding: 4px 6px calc(4px + var(--safe-bottom)); }
|
||||||
|
nav button { min-height: 44px; font-size: 10.5px; padding: 2px; }
|
||||||
|
nav button .tab-ico { height: 24px; }
|
||||||
|
.section-head { padding: 8px var(--pad) 6px; }
|
||||||
|
.section-head h2 { font-size: 18px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Tablet / จอกว้าง ───────────────────────────────────── */
|
||||||
|
@media (min-width: 600px) {
|
||||||
|
:root { --pad: 28px; }
|
||||||
|
.sheet { border-radius: 28px; margin-bottom: 12px; }
|
||||||
|
.sheet-overlay { align-items: center; }
|
||||||
|
.gallery-grid { grid-template-columns: repeat(4, 1fr); }
|
||||||
|
}
|
||||||
+40
-177
@@ -1,203 +1,66 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="th">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
||||||
<meta name="theme-color" content="#7C83FF">
|
<meta name="theme-color" content="#F2F3F5" media="(prefers-color-scheme: light)">
|
||||||
|
<meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
|
||||||
|
<meta name="color-scheme" content="light dark">
|
||||||
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="format-detection" content="telephone=no">
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
<link rel="icon" href="icon-192.png">
|
<link rel="icon" href="icon-192.png">
|
||||||
<link rel="apple-touch-icon" href="icon-192.png">
|
<link rel="apple-touch-icon" href="icon-192.png">
|
||||||
<title>CamCat — Camera Folder Organizer</title>
|
<link rel="stylesheet" href="css/app.css">
|
||||||
<style>
|
<title>CamCat — ถ่ายรูปแยกโฟลเดอร์</title>
|
||||||
:root {
|
|
||||||
--bg: #0F172A; --surface: #1E293B; --surface-2: #334155;
|
|
||||||
--text: #F8FAFC; --muted: #94A3B8; --accent: #7C83FF;
|
|
||||||
--accent-2: #B06BFF; --accent-3: #FF6B9D;
|
|
||||||
--green: #2DD4A7; --red: #F87A7A; --border: rgba(255,255,255,0.08);
|
|
||||||
--radius: 12px;
|
|
||||||
}
|
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text);
|
|
||||||
height: 100vh; height: 100dvh; overflow: hidden; user-select: none;
|
|
||||||
}
|
|
||||||
/* ── App Shell ── */
|
|
||||||
#app { display: flex; flex-direction: column; height: 100dvh; }
|
|
||||||
/* ── Header ── */
|
|
||||||
header {
|
|
||||||
background: var(--surface); padding: 12px 16px; display: flex;
|
|
||||||
align-items: center; justify-content: space-between;
|
|
||||||
border-bottom: 1px solid var(--border); flex-shrink: 0;
|
|
||||||
}
|
|
||||||
header h1 { font-size: 18px; font-weight: 700; }
|
|
||||||
.folder-pill {
|
|
||||||
background: var(--accent); color: white; padding: 4px 12px;
|
|
||||||
border-radius: 20px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px;
|
|
||||||
}
|
|
||||||
/* ── Main; flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
|
|
||||||
/* ── Bottom Nav ── */
|
|
||||||
nav {
|
|
||||||
background: var(--surface); border-top: 1px solid var(--border);
|
|
||||||
display: flex; justify-content: space-around; padding: 8px 0; flex-shrink: 0;
|
|
||||||
}
|
|
||||||
nav button {
|
|
||||||
background: none; border: none; color: var(--muted); font-size: 11px;
|
|
||||||
display: flex; flex-direction: column; align-items: center; gap: 4px;
|
|
||||||
padding: 6px 16px; cursor: pointer; transition: color 0.2s;
|
|
||||||
}
|
|
||||||
nav button.active { color: var(--accent); }
|
|
||||||
nav button svg { width: 22px; height: 22px; }
|
|
||||||
/* ── Camera View ── */
|
|
||||||
#camera-view { display: flex; flex-direction: column; align-items: center; height: 100%; }
|
|
||||||
#video {
|
|
||||||
width: 100%; flex: 1; object-fit: cover; background: #000;
|
|
||||||
}
|
|
||||||
.camera-bar {
|
|
||||||
padding: 20px; display: flex; justify-content: center; align-items: center; gap: 30px;
|
|
||||||
background: var(--surface); width: 100%;
|
|
||||||
}
|
|
||||||
#shutter {
|
|
||||||
width: 64px; height: 64px; border-radius: 50%; background: var(--accent-3);
|
|
||||||
border: 4px solid white; cursor: pointer; font-size: 0; transition: transform 0.1s;
|
|
||||||
}
|
|
||||||
#shutter:active { transform: scale(0.9); }
|
|
||||||
#switch-cam {
|
|
||||||
width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2);
|
|
||||||
border: none; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center;
|
|
||||||
}
|
|
||||||
/* ── Folders View ── */
|
|
||||||
.section-head {
|
|
||||||
padding: 16px; display: flex; justify-content: space-between; align-items: center;
|
|
||||||
}
|
|
||||||
.section-head h2 { font-size: 16px; }
|
|
||||||
.btn-primary {
|
|
||||||
background: var(--accent); color: white; border: none; padding: 8px 16px;
|
|
||||||
border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
|
|
||||||
}
|
|
||||||
.btn-ghost {
|
|
||||||
background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
|
|
||||||
padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer;
|
|
||||||
}
|
|
||||||
.folder-list { padding: 0 16px 16px; }
|
|
||||||
.folder-item {
|
|
||||||
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
|
|
||||||
padding: 14px; margin-bottom: 8px; display: flex; justify-content: space-between;
|
|
||||||
align-items: center; cursor: pointer; transition: border-color 0.2s;
|
|
||||||
}
|
|
||||||
.folder-item:hover { border-color: var(--accent); }
|
|
||||||
.folder-item.active { border-color: var(--accent); background: rgba(124,131,255,0.08); }
|
|
||||||
.folder-item .name { font-weight: 600; font-size: 14px; }
|
|
||||||
.folder-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
|
||||||
.folder-item .actions { display: flex; gap: 8px; }
|
|
||||||
.icon-btn {
|
|
||||||
background: var(--surface-2); border: none; color: var(--muted); width: 32px; height: 32px;
|
|
||||||
border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center;
|
|
||||||
}
|
|
||||||
.icon-btn:hover { color: var(--text); }
|
|
||||||
/* ── Gallery View ── */
|
|
||||||
.gallery-grid {
|
|
||||||
display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 16px 16px;
|
|
||||||
}
|
|
||||||
.gallery-item {
|
|
||||||
aspect-ratio: 1; border-radius: 8px; overflow: hidden; position: relative; cursor: pointer;
|
|
||||||
border: 2px solid transparent; transition: border-color 0.15s;
|
|
||||||
}
|
|
||||||
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
|
|
||||||
.gallery-item.selected { border-color: var(--accent); }
|
|
||||||
.gallery-item .check {
|
|
||||||
position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
|
|
||||||
border-radius: 50%; background: var(--accent); color: white;
|
|
||||||
display: none; align-items: center; justify-content: center; font-size: 12px;
|
|
||||||
}
|
|
||||||
.gallery-item.selected .check { display: flex; }
|
|
||||||
.gallery-bar {
|
|
||||||
padding: 8px 16px; display: flex; justify-content: space-between; align-items: center;
|
|
||||||
background: var(--surface); font-size: 12px; color: var(--muted);
|
|
||||||
}
|
|
||||||
.gallery-actions { display: flex; gap: 8px; }
|
|
||||||
/* ── Image Viewer ── */
|
|
||||||
#image-viewer { padding: 16px; display: flex; flex-direction: column; height: 100%; }
|
|
||||||
#image-viewer img { flex: 1; border-radius: var(--radius); object-fit: contain; min-height: 0; }
|
|
||||||
.exif-panel {
|
|
||||||
background: var(--surface); border-radius: var(--radius); padding: 12px; margin-top: 12px;
|
|
||||||
font-size: 12px; line-height: 1.8; color: var(--muted); flex-shrink: 0; max-height: 200px; overflow-y: auto;
|
|
||||||
}
|
|
||||||
.exif-panel b { color: var(--text); font-size: 13px; }
|
|
||||||
.exif-panel .row { display: flex; justify-content: space-between; }
|
|
||||||
.exif-panel .key { color: var(--muted); }
|
|
||||||
.exif-panel .val { color: var(--text); }
|
|
||||||
/* ── Modal ── */
|
|
||||||
.modal-overlay {
|
|
||||||
position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100;
|
|
||||||
display: none; align-items: center; justify-content: center;
|
|
||||||
}
|
|
||||||
.modal-overlay.show { display: flex; }
|
|
||||||
.modal {
|
|
||||||
background: var(--surface); border-radius: 16px; padding: 20px; width: 90%; max-width: 360px;
|
|
||||||
}
|
|
||||||
.modal h3 { margin-bottom: 12px; }
|
|
||||||
.modal input {
|
|
||||||
width: 100%; padding: 12px; background: var(--bg); border: 1px solid var(--border);
|
|
||||||
border-radius: 8px; color: var(--text); font-size: 14px; margin-bottom: 12px;
|
|
||||||
}
|
|
||||||
.modal-actions { display: flex; gap: 8px; }
|
|
||||||
.modal-actions button { flex: 1; padding: 10px; border-radius: 8px; font-size: 14px; cursor: pointer; }
|
|
||||||
/* ── Toast ── */
|
|
||||||
#toast {
|
|
||||||
position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
|
|
||||||
background: var(--surface-2); color: var(--text); padding: 10px 20px;
|
|
||||||
border-radius: 20px; font-size: 13px; z-index: 200; opacity: 0;
|
|
||||||
transition: opacity 0.3s; pointer-events: none;
|
|
||||||
}
|
|
||||||
#toast.show { opacity: 1; }
|
|
||||||
/* ── Empty State ── */
|
|
||||||
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
|
|
||||||
.empty svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.3; }
|
|
||||||
/* ── Loading ── */
|
|
||||||
.spinner {
|
|
||||||
border: 3px solid var(--border); border-top-color: var(--accent);
|
|
||||||
border-radius: 50%; width: 32px; height: 32px; animation: spin 0.8s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin { to { transform: rotate(360deg); } }
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<header>
|
<header>
|
||||||
<h1>📷 CamCat</h1>
|
<div class="head-text">
|
||||||
<div class="folder-pill" id="active-folder-pill">📁 Default</div>
|
<h1>CamCat</h1>
|
||||||
|
<button class="head-sub" id="active-folder-pill" type="button" aria-label="โฟลเดอร์ที่ใช้งาน — แตะเพื่อเปลี่ยน">
|
||||||
|
<span id="active-folder-name">—</span>
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 18l6-6-6-6"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="head-actions">
|
||||||
|
<button class="icon-round" id="theme-toggle" type="button" aria-label="สลับธีมสว่าง/มืด"></button>
|
||||||
|
<button class="icon-round" type="button" data-action="diagnostics" aria-label="ข้อมูลอุปกรณ์และกล้อง">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main id="main"></main>
|
<main id="main" aria-live="polite"></main>
|
||||||
|
|
||||||
<nav>
|
<nav id="bottom-nav">
|
||||||
<button id="nav-camera" class="active" onclick="navigate('camera')">
|
<button id="nav-camera" class="active" type="button" data-view="camera" aria-label="กล้อง">
|
||||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 19a2 2 0 01-2 2H3a2 %200 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"/><circle cx="12" cy="13" r="4"/></svg>
|
<span class="tab-ico"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg></span>
|
||||||
Camera
|
<span>กล้อง</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="nav-folders" onclick="navigate('folders')">
|
<button id="nav-folders" type="button" data-view="folders" aria-label="โฟลเดอร์">
|
||||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"/></svg>
|
<span class="tab-ico"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg></span>
|
||||||
Folders
|
<span>โฟลเดอร์</span>
|
||||||
</button>
|
</button>
|
||||||
<button id="nav-gallery" onclick="navigate('gallery')">
|
<button id="nav-gallery" type="button" data-view="gallery" aria-label="รูปภาพ">
|
||||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>
|
<span class="tab-ico"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="3"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg></span>
|
||||||
Gallery
|
<span>รูปภาพ</span>
|
||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Modal -->
|
<div class="sheet-overlay" id="sheet-overlay" hidden aria-hidden="true">
|
||||||
<div class="modal-overlay" id="modal-overlay">
|
<div class="sheet" id="sheet-content" role="dialog" aria-modal="true"></div>
|
||||||
<div class="modal" id="modal-content"></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Toast -->
|
<div id="toast" role="status"></div>
|
||||||
<div id="toast"></div>
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js"></script>
|
<script src="vendor/jszip.min.js"></script>
|
||||||
<script src="app.js"></script>
|
<script src="vendor/piexif.js"></script>
|
||||||
|
<script src="vendor/qrcode.min.js"></script>
|
||||||
|
<script type="module" src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
// ── ZIP ทั้งโฟลเดอร์: สร้าง / ดาวน์โหลด / แชร์ผ่านระบบมือถือ ──
|
||||||
|
import { safeFileName, humanDateTime } from "./naming.js";
|
||||||
|
|
||||||
|
const cache = { signature: "", file: null, fileName: "" };
|
||||||
|
|
||||||
|
function signatureOf(folder, images) {
|
||||||
|
return `${folder.id}|${folder.updatedAt || folder.createdAt}|${images.map((i) => i.id).join(".")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function entryBase(folder) {
|
||||||
|
return safeFileName(folder.name).replace(/\s+/g, "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* สร้าง ZIP ของ "ทุกรูปในโฟลเดอร์" + metadata.json
|
||||||
|
* ใช้ compression: STORE เพราะ JPEG บีบอัดต่อไม่ได้แล้ว (เร็วขึ้นมากบนมือถือ)
|
||||||
|
*/
|
||||||
|
export async function buildZip(folder, images, onProgress) {
|
||||||
|
if (!window.JSZip) throw new Error("JSZip not loaded");
|
||||||
|
const zip = new JSZip();
|
||||||
|
const base = entryBase(folder);
|
||||||
|
const photos = [];
|
||||||
|
|
||||||
|
images.forEach((img, idx) => {
|
||||||
|
const seq = String(idx + 1).padStart(4, "0");
|
||||||
|
const name = img.name || `${base}_${seq}.jpg`;
|
||||||
|
zip.file(name, img.blob);
|
||||||
|
photos.push({ file: name, ...(img.meta || {}) });
|
||||||
|
});
|
||||||
|
|
||||||
|
zip.file(
|
||||||
|
"metadata.json",
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
folder: folder.name,
|
||||||
|
count: images.length,
|
||||||
|
generated_at: new Date().toISOString(),
|
||||||
|
generated_at_th: humanDateTime(Date.now()),
|
||||||
|
app: "CamCat 2.0.0",
|
||||||
|
photos,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const blob = await zip.generateAsync({ type: "blob", compression: "STORE" }, (m) => {
|
||||||
|
if (onProgress) onProgress(m.percent);
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileName = safeFileName(folder.name, "photos") + ".zip";
|
||||||
|
const file = new File([blob], fileName, { type: "application/zip" });
|
||||||
|
return { blob, file, fileName };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ใช้ cache ถ้ารายการรูปไม่เปลี่ยน — ทำให้กดแชร์แล้วเปิด share sheet ได้ทันที */
|
||||||
|
export async function ensureZip(folder, images, onProgress, { force = false } = {}) {
|
||||||
|
const sig = signatureOf(folder, images);
|
||||||
|
if (!force && cache.file && cache.signature === sig) return cache;
|
||||||
|
const { blob, file, fileName } = await buildZip(folder, images, onProgress);
|
||||||
|
cache.signature = sig;
|
||||||
|
cache.file = file;
|
||||||
|
cache.fileName = fileName;
|
||||||
|
cache.blob = blob;
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function invalidateZip() {
|
||||||
|
cache.signature = "";
|
||||||
|
cache.file = null;
|
||||||
|
cache.fileName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canShareFiles(file) {
|
||||||
|
try {
|
||||||
|
return !!(navigator.canShare && navigator.canShare({ files: [file] }));
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ดาวน์โหลดลงเครื่อง (Chrome Android → โฟลเดอร์ Download) */
|
||||||
|
export function downloadFile(file) {
|
||||||
|
const url = URL.createObjectURL(file);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = file.name;
|
||||||
|
a.rel = "noopener";
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* แชร์ผ่าน Web Share API ระดับไฟล์ → share sheet ของ Samsung → เลือกแอปปลายทาง
|
||||||
|
* คืน {ok, reason}
|
||||||
|
*/
|
||||||
|
export async function shareFile(file, { title, text } = {}) {
|
||||||
|
if (!navigator.share) return { ok: false, reason: "unsupported" };
|
||||||
|
const payload = { files: [file], title: title || file.name, text: text || "" };
|
||||||
|
if (navigator.canShare && !navigator.canShare({ files: [file] })) {
|
||||||
|
return { ok: false, reason: "nofiles" };
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await navigator.share(payload);
|
||||||
|
return { ok: true };
|
||||||
|
} catch (err) {
|
||||||
|
if (err && err.name === "AbortError") return { ok: false, reason: "cancelled" };
|
||||||
|
return { ok: false, reason: "failed", error: err };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
// ── กล้อง: getUserMedia + ImageCapture + torch + zoom ────────
|
||||||
|
import { JPEG_QUALITY, THUMB_MAX, THUMB_QUALITY } from "./config.js";
|
||||||
|
|
||||||
|
export const cam = {
|
||||||
|
stream: null,
|
||||||
|
track: null,
|
||||||
|
imageCapture: null,
|
||||||
|
caps: {},
|
||||||
|
facing: "environment",
|
||||||
|
torch: false,
|
||||||
|
zoom: null,
|
||||||
|
videoEl: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
function camError(code, cause) {
|
||||||
|
const e = new Error(code);
|
||||||
|
e.code = code;
|
||||||
|
e.cause = cause;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapError = (err) => {
|
||||||
|
const name = err?.name || "";
|
||||||
|
if (name === "NotAllowedError" || name === "PermissionDeniedError") return camError("denied", err);
|
||||||
|
if (name === "NotFoundError" || name === "DevicesNotFoundError") return camError("nocamera", err);
|
||||||
|
if (name === "NotReadableError" || name === "TrackStartError") return camError("busy", err);
|
||||||
|
if (name === "SecurityError") return camError("insecure", err);
|
||||||
|
if (name === "OverconstrainedError") return camError("constraints", err);
|
||||||
|
return camError("unknown", err);
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function permissionState() {
|
||||||
|
try {
|
||||||
|
if (!navigator.permissions?.query) return "unknown";
|
||||||
|
const s = await navigator.permissions.query({ name: "camera" });
|
||||||
|
return s.state; // granted | denied | prompt
|
||||||
|
} catch {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stopCamera() {
|
||||||
|
if (cam.stream) {
|
||||||
|
cam.stream.getTracks().forEach((t) => t.stop());
|
||||||
|
}
|
||||||
|
if (cam.videoEl) cam.videoEl.srcObject = null;
|
||||||
|
cam.stream = null;
|
||||||
|
cam.track = null;
|
||||||
|
cam.imageCapture = null;
|
||||||
|
cam.caps = {};
|
||||||
|
cam.torch = false;
|
||||||
|
cam.zoom = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* เปิดกล้องหลัง (ค่าเริ่มต้น) / หน้า
|
||||||
|
* ลำดับ constraint: 1080p → 720p → อะไรก็ได้ที่ใช้ได้ (S23 ผ่านหมด แต่กันกรณีรุ่นอื่น)
|
||||||
|
*/
|
||||||
|
export async function startCamera(videoEl, facing = "environment") {
|
||||||
|
if (!window.isSecureContext) throw camError("insecure");
|
||||||
|
if (!navigator.mediaDevices?.getUserMedia) throw camError("unsupported");
|
||||||
|
|
||||||
|
stopCamera();
|
||||||
|
cam.videoEl = videoEl;
|
||||||
|
cam.facing = facing;
|
||||||
|
|
||||||
|
const attempts = [
|
||||||
|
{ video: { facingMode: { ideal: facing }, width: { ideal: 1920 }, height: { ideal: 1080 }, frameRate: { ideal: 30 } }, audio: false },
|
||||||
|
{ video: { facingMode: { ideal: facing }, width: { ideal: 1280 }, height: { ideal: 720 } }, audio: false },
|
||||||
|
{ video: { facingMode: { ideal: facing } }, audio: false },
|
||||||
|
{ video: true, audio: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
let lastErr = null;
|
||||||
|
for (const constraints of attempts) {
|
||||||
|
try {
|
||||||
|
cam.stream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||||
|
break;
|
||||||
|
} catch (err) {
|
||||||
|
lastErr = err;
|
||||||
|
if (["NotAllowedError", "PermissionDeniedError", "SecurityError"].includes(err?.name)) throw mapError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!cam.stream) throw mapError(lastErr || new Error("no stream"));
|
||||||
|
|
||||||
|
cam.track = cam.stream.getVideoTracks()[0];
|
||||||
|
cam.caps = cam.track.getCapabilities ? cam.track.getCapabilities() : {};
|
||||||
|
try {
|
||||||
|
cam.imageCapture = typeof window.ImageCapture !== "undefined" ? new window.ImageCapture(cam.track) : null;
|
||||||
|
} catch { cam.imageCapture = null; }
|
||||||
|
|
||||||
|
videoEl.srcObject = cam.stream;
|
||||||
|
videoEl.muted = true;
|
||||||
|
videoEl.setAttribute("playsinline", "");
|
||||||
|
try { await videoEl.play(); } catch { /* autoplay may need gesture; caller retries */ }
|
||||||
|
|
||||||
|
return {
|
||||||
|
settings: cam.track.getSettings?.() || {},
|
||||||
|
caps: cam.caps,
|
||||||
|
torchAvailable: cam.caps.torch === true,
|
||||||
|
zoomRange: cam.caps.zoom || null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setTorch(on) {
|
||||||
|
if (!cam.track || cam.caps.torch !== true) return false;
|
||||||
|
try {
|
||||||
|
await cam.track.applyConstraints({ advanced: [{ torch: !!on }] });
|
||||||
|
cam.torch = !!on;
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setZoom(value) {
|
||||||
|
if (!cam.track || !cam.caps.zoom) return false;
|
||||||
|
const z = Number(value);
|
||||||
|
try {
|
||||||
|
await cam.track.applyConstraints({ advanced: [{ zoom: z }] });
|
||||||
|
cam.zoom = z;
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function makeThumb(blob) {
|
||||||
|
try {
|
||||||
|
const bmp = await createImageBitmap(blob);
|
||||||
|
const scale = Math.min(1, THUMB_MAX / Math.max(bmp.width, bmp.height));
|
||||||
|
const w = Math.max(1, Math.round(bmp.width * scale));
|
||||||
|
const h = Math.max(1, Math.round(bmp.height * scale));
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = w; canvas.height = h;
|
||||||
|
canvas.getContext("2d").drawImage(bmp, 0, 0, w, h);
|
||||||
|
bmp.close?.();
|
||||||
|
return await new Promise((res) => canvas.toBlob(res, "image/jpeg", THUMB_QUALITY));
|
||||||
|
} catch {
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ถ่ายภาพนิ่ง
|
||||||
|
* 1) ImageCapture.takePhoto() — ได้ JPEG ความละเอียดเต็มเซนเซอร์ + EXIF จากกล้อง (S23)
|
||||||
|
* 2) fallback: วาดเฟรมวิดีโอลง canvas
|
||||||
|
*/
|
||||||
|
export async function captureStill() {
|
||||||
|
if (!cam.track) throw camError("notready");
|
||||||
|
let blob = null;
|
||||||
|
let source = "canvas";
|
||||||
|
|
||||||
|
if (cam.imageCapture) {
|
||||||
|
try {
|
||||||
|
blob = await cam.imageCapture.takePhoto();
|
||||||
|
source = "imagecapture";
|
||||||
|
} catch { blob = null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
let width = 0, height = 0;
|
||||||
|
if (!blob) {
|
||||||
|
const v = cam.videoEl;
|
||||||
|
if (!v || !v.videoWidth) throw camError("notready");
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = v.videoWidth;
|
||||||
|
canvas.height = v.videoHeight;
|
||||||
|
canvas.getContext("2d").drawImage(v, 0, 0);
|
||||||
|
blob = await new Promise((res) => canvas.toBlob(res, "image/jpeg", JPEG_QUALITY));
|
||||||
|
width = canvas.width; height = canvas.height;
|
||||||
|
source = "canvas";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!width || !height) {
|
||||||
|
try {
|
||||||
|
const bmp = await createImageBitmap(blob);
|
||||||
|
width = bmp.width; height = bmp.height;
|
||||||
|
bmp.close?.();
|
||||||
|
} catch {
|
||||||
|
width = cam.videoEl?.videoWidth || 0;
|
||||||
|
height = cam.videoEl?.videoHeight || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const thumb = await makeThumb(blob);
|
||||||
|
return { blob, thumb, width, height, source, facing: cam.facing };
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// ── ค่าคงที่ทั้งแอป ──────────────────────────────────────────
|
||||||
|
export const APP_VERSION = "2.0.0";
|
||||||
|
export const DB_NAME = "camcat-db";
|
||||||
|
export const DB_VERSION = 2;
|
||||||
|
|
||||||
|
export const SITE_LABEL = "Site A"; // ชื่อไซต์ ใช้เป็น prefix ของโฟลเดอร์
|
||||||
|
export const TIME_ZONE = "Asia/Bangkok"; // ปี พ.ศ. คำนวณจากโซนนี้เสมอ
|
||||||
|
|
||||||
|
export const JPEG_QUALITY = 0.92;
|
||||||
|
export const THUMB_MAX = 480; // px ด้านยาว ของ thumbnail ใน gallery
|
||||||
|
export const THUMB_QUALITY = 0.7;
|
||||||
|
|
||||||
|
export const STORE_FOLDERS = "folders";
|
||||||
|
export const STORE_IMAGES = "images";
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// ── IndexedDB (folders + images + thumbnails) ────────────────
|
||||||
|
import { DB_NAME, DB_VERSION, STORE_FOLDERS, STORE_IMAGES } from "./config.js";
|
||||||
|
|
||||||
|
let db = null;
|
||||||
|
|
||||||
|
export function open() {
|
||||||
|
if (db) return Promise.resolve(db);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const req = indexedDB.open(DB_NAME, DB_VERSION);
|
||||||
|
req.onupgradeneeded = () => {
|
||||||
|
const d = req.result;
|
||||||
|
if (!d.objectStoreNames.contains(STORE_FOLDERS)) {
|
||||||
|
d.createObjectStore(STORE_FOLDERS, { keyPath: "id" });
|
||||||
|
}
|
||||||
|
if (!d.objectStoreNames.contains(STORE_IMAGES)) {
|
||||||
|
const s = d.createObjectStore(STORE_IMAGES, { keyPath: "id" });
|
||||||
|
s.createIndex("folderId", "folderId", { unique: false });
|
||||||
|
s.createIndex("createdAt", "createdAt", { unique: false });
|
||||||
|
} else {
|
||||||
|
// อัปเกรดจาก v1: เพิ่ม index createdAt ถ้ายังไม่มี (ของเดิมเรียงตาม id ได้อยู่แล้ว)
|
||||||
|
const s = req.transaction.objectStore(STORE_IMAGES);
|
||||||
|
if (!s.indexNames.contains("createdAt")) {
|
||||||
|
s.createIndex("createdAt", "createdAt", { unique: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
req.onsuccess = () => { db = req.result; resolve(db); };
|
||||||
|
req.onerror = () => reject(req.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function tx(store, mode) {
|
||||||
|
return db.transaction(store, mode).objectStore(store);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrap(request) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request.onsuccess = () => resolve(request.result);
|
||||||
|
request.onerror = () => reject(request.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── folders ──
|
||||||
|
export async function getFolders() {
|
||||||
|
const list = await wrap(tx(STORE_FOLDERS, "readonly").getAll());
|
||||||
|
return list.sort((a, b) => (a.createdAt || 0) - (b.createdAt || 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFolder(id) {
|
||||||
|
return wrap(tx(STORE_FOLDERS, "readonly").get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function putFolder(folder) {
|
||||||
|
await wrap(tx(STORE_FOLDERS, "readwrite").put(folder));
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function touchFolder(id) {
|
||||||
|
const f = await getFolder(id);
|
||||||
|
if (f) { f.updatedAt = Date.now(); await putFolder(f); }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteFolder(id) {
|
||||||
|
const imgs = await getImages(id);
|
||||||
|
for (const img of imgs) await deleteImage(img.id);
|
||||||
|
await wrap(tx(STORE_FOLDERS, "readwrite").delete(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── images ──
|
||||||
|
export async function getImages(folderId) {
|
||||||
|
const list = await wrap(tx(STORE_IMAGES, "readonly").index("folderId").getAll(folderId));
|
||||||
|
return list.sort((a, b) => a.createdAt - b.createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getImage(id) {
|
||||||
|
return wrap(tx(STORE_IMAGES, "readonly").get(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function putImage(img) {
|
||||||
|
await wrap(tx(STORE_IMAGES, "readwrite").put(img));
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteImage(id) {
|
||||||
|
await wrap(tx(STORE_IMAGES, "readwrite").delete(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function countImages(folderId) {
|
||||||
|
return wrap(tx(STORE_IMAGES, "readonly").index("folderId").count(folderId));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function storageInfo() {
|
||||||
|
if (!navigator.storage || !navigator.storage.estimate) return null;
|
||||||
|
try {
|
||||||
|
const { usage = 0, quota = 0 } = await navigator.storage.estimate();
|
||||||
|
return { usage, quota };
|
||||||
|
} catch { return null; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// ── ตรวจอุปกรณ์ / สภาพแวดล้อมการรัน ─────────────────────────
|
||||||
|
const SAMSUNG_MODELS = {
|
||||||
|
"SM-S911": "Galaxy S23",
|
||||||
|
"SM-S916": "Galaxy S23+",
|
||||||
|
"SM-S918": "Galaxy S23 Ultra",
|
||||||
|
"SM-S921": "Galaxy S24",
|
||||||
|
"SM-S926": "Galaxy S24+",
|
||||||
|
"SM-S928": "Galaxy S24 Ultra",
|
||||||
|
"SM-S931": "Galaxy S25",
|
||||||
|
"SM-S936": "Galaxy S25+",
|
||||||
|
"SM-S938": "Galaxy S25 Ultra",
|
||||||
|
"SM-G991": "Galaxy S21",
|
||||||
|
"SM-G996": "Galaxy S21+",
|
||||||
|
"SM-G998": "Galaxy S21 Ultra",
|
||||||
|
"SM-G780": "Galaxy S20 FE",
|
||||||
|
"SM-A546": "Galaxy A54",
|
||||||
|
"SM-A556": "Galaxy A55",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function detectDevice() {
|
||||||
|
const ua = navigator.userAgent || "";
|
||||||
|
const samsung = ua.match(/\b(SM-[A-Z0-9]{3,10})\b/i);
|
||||||
|
const android = ua.match(/Android\s+([\d.]+)/i);
|
||||||
|
const generic = ua.match(/Android[^;]*;\s*([^;)]+?)\s*(?:Build\/|\))/i);
|
||||||
|
const chrome = ua.match(/(Chrome|CriOS)\/([\d.]+)/i);
|
||||||
|
|
||||||
|
let code = samsung ? samsung[1].toUpperCase() : generic ? generic[1].trim() : "";
|
||||||
|
let brand = samsung ? "Samsung" : /iPhone/.test(ua) ? "Apple" : generic ? "Android" : "Unknown";
|
||||||
|
let model = code;
|
||||||
|
|
||||||
|
if (samsung) {
|
||||||
|
const key = code.slice(0, 8); // SM-S911B → SM-S911
|
||||||
|
model = SAMSUNG_MODELS[key] ? `Samsung ${SAMSUNG_MODELS[key]}` : `Samsung ${code}`;
|
||||||
|
} else if (/iPhone/.test(ua)) {
|
||||||
|
brand = "Apple";
|
||||||
|
model = "iPhone";
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: code || "ไม่ทราบรุ่น",
|
||||||
|
brand,
|
||||||
|
model: model || "ไม่ทราบรุ่น",
|
||||||
|
androidVersion: android ? android[1] : null,
|
||||||
|
chromeVersion: chrome ? chrome[2] : null,
|
||||||
|
ua,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function environment() {
|
||||||
|
const d = detectDevice();
|
||||||
|
const vv = window.visualViewport;
|
||||||
|
return {
|
||||||
|
...d,
|
||||||
|
url: location.href,
|
||||||
|
secureContext: window.isSecureContext === true,
|
||||||
|
protocol: location.protocol,
|
||||||
|
standalone: window.matchMedia("(display-mode: standalone)").matches,
|
||||||
|
dpr: window.devicePixelRatio,
|
||||||
|
viewport: `${window.innerWidth}×${window.innerHeight}`,
|
||||||
|
visualViewport: vv ? `${Math.round(vv.width)}×${Math.round(vv.height)}` : "—",
|
||||||
|
screen: `${screen.width}×${screen.height}`,
|
||||||
|
safeArea: getComputedStyle(document.documentElement).getPropertyValue("--safe-top").trim() || "0px",
|
||||||
|
touch: navigator.maxTouchPoints > 0,
|
||||||
|
share: !!(navigator.canShare && navigator.share),
|
||||||
|
imageCapture: typeof window.ImageCapture !== "undefined",
|
||||||
|
languages: navigator.languages?.join(", ") || navigator.language,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** นามสกุลอุปกรณ์สำหรับ EXIF Model */
|
||||||
|
export function exifModelName() {
|
||||||
|
const d = detectDevice();
|
||||||
|
return d.model || "Samsung Galaxy S23";
|
||||||
|
}
|
||||||
+147
@@ -0,0 +1,147 @@
|
|||||||
|
// ── อ่าน/เขียน EXIF (JPEG) ด้วย piexifjs ─────────────────────
|
||||||
|
// Metadata ที่ฝังในไฟล์จะติดไปกับรูปตอนแชร์ออกแอปอื่นด้วย
|
||||||
|
|
||||||
|
const piexif = () => (typeof window !== "undefined" ? window.piexif : undefined);
|
||||||
|
|
||||||
|
export function blobToDataURL(blob) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const r = new FileReader();
|
||||||
|
r.onload = () => resolve(r.result);
|
||||||
|
r.onerror = () => reject(r.error);
|
||||||
|
r.readAsDataURL(blob);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dataURLToBlob(dataUrl) {
|
||||||
|
const [head, b64] = dataUrl.split(",");
|
||||||
|
const mime = /:(.*?);/.exec(head)?.[1] || "image/jpeg";
|
||||||
|
const bin = atob(b64);
|
||||||
|
const bytes = new Uint8Array(bin.length);
|
||||||
|
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
||||||
|
return new Blob([bytes], { type: mime });
|
||||||
|
}
|
||||||
|
|
||||||
|
const rat = (v) => {
|
||||||
|
if (Array.isArray(v) && v.length === 2) return v[1] ? v[0] / v[1] : 0;
|
||||||
|
return typeof v === "number" ? v : 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const dmsToDecimal = (dms, ref) => {
|
||||||
|
if (!Array.isArray(dms) || dms.length < 3) return null;
|
||||||
|
const deg = rat(dms[0]) + rat(dms[1]) / 60 + rat(dms[2]) / 3600;
|
||||||
|
const v = Number(deg.toFixed(6));
|
||||||
|
return ref === "S" || ref === "W" ? -v : v;
|
||||||
|
};
|
||||||
|
|
||||||
|
const str = (v) => (typeof v === "string" ? v.replace(/\0+$/, "").trim() : undefined);
|
||||||
|
|
||||||
|
/** อ่าน EXIF จาก JPEG → object แบน (ค่าว่าง = ไม่มี tag) */
|
||||||
|
export async function readExif(blob) {
|
||||||
|
const px = piexif();
|
||||||
|
if (!px || !blob) return {};
|
||||||
|
try {
|
||||||
|
const dataUrl = await blobToDataURL(blob);
|
||||||
|
if (!dataUrl.startsWith("data:image/jpeg")) return {};
|
||||||
|
const exif = px.load(dataUrl) || {};
|
||||||
|
const o = exif["0th"] || {};
|
||||||
|
const e = exif["Exif"] || {};
|
||||||
|
const g = exif["GPS"] || {};
|
||||||
|
return {
|
||||||
|
make: str(o[271]),
|
||||||
|
model: str(o[272]),
|
||||||
|
software: str(o[305]),
|
||||||
|
dateTime: str(o[306]) || str(e[36867]),
|
||||||
|
dateTimeOriginal: str(e[36867]),
|
||||||
|
orientation: typeof o[274] === "number" ? o[274] : undefined,
|
||||||
|
width: e[40962] || o[256] || undefined,
|
||||||
|
height: e[40963] || o[257] || undefined,
|
||||||
|
iso: typeof e[34855] === "number" ? e[34855] : undefined,
|
||||||
|
fNumber: e[33437] ? rat(e[33437]) : undefined,
|
||||||
|
exposureTime: e[33434] ? rat(e[33434]) : undefined,
|
||||||
|
focalLength: e[37386] ? rat(e[37386]) : undefined,
|
||||||
|
lensModel: str(e[42036]),
|
||||||
|
gps: g[2] ? {
|
||||||
|
lat: dmsToDecimal(g[2], str(g[1])),
|
||||||
|
lng: dmsToDecimal(g[4], str(g[3])),
|
||||||
|
altitude: g[6] ? rat(g[6]) * (str(g[5]) === "1" ? -1 : 1) : null,
|
||||||
|
dateStamp: str(g[29]),
|
||||||
|
timeStamp: Array.isArray(g[7]) ? g[7].map(rat) : null,
|
||||||
|
} : null,
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const decToDms = (dec) => {
|
||||||
|
const abs = Math.abs(dec);
|
||||||
|
const d = Math.floor(abs);
|
||||||
|
const minFloat = (abs - d) * 60;
|
||||||
|
const m = Math.floor(minFloat);
|
||||||
|
const s = Math.round((minFloat - m) * 60 * 100);
|
||||||
|
return [[d, 1], [m, 1], [s, 100]];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ฝัง EXIF ลง JPEG ก่อนบันทึก
|
||||||
|
* meta = { make, model, dateTime, gps:{lat,lng,altitude}, width, height, folder, source }
|
||||||
|
* คืน Blob ใหม่ (ถ้าฝังไม่ได้คืน blob เดิม)
|
||||||
|
*/
|
||||||
|
export async function writeExif(blob, meta = {}) {
|
||||||
|
const px = piexif();
|
||||||
|
if (!px || !blob || blob.type !== "image/jpeg") return blob;
|
||||||
|
try {
|
||||||
|
const dataUrl = await blobToDataURL(blob);
|
||||||
|
let existing = {};
|
||||||
|
try { existing = px.load(dataUrl) || {}; } catch { existing = {}; }
|
||||||
|
|
||||||
|
const zeroth = Object.assign({}, existing["0th"] || {});
|
||||||
|
const exif = Object.assign({}, existing["Exif"] || {});
|
||||||
|
const gps = Object.assign({}, existing["GPS"] || {});
|
||||||
|
|
||||||
|
zeroth[271] = meta.make || "Samsung";
|
||||||
|
zeroth[272] = meta.model || "Samsung Galaxy S23";
|
||||||
|
zeroth[305] = "CamCat " + (meta.version || "2.0.0");
|
||||||
|
zeroth[306] = meta.dateTime;
|
||||||
|
if (meta.folder) zeroth[270] = "Folder: " + meta.folder; // ImageDescription (IFD0)
|
||||||
|
if (!zeroth[274]) zeroth[274] = 1;
|
||||||
|
zeroth[282] = [72, 1];
|
||||||
|
zeroth[283] = [72, 1];
|
||||||
|
zeroth[296] = 2;
|
||||||
|
|
||||||
|
exif[36867] = meta.dateTime; // DateTimeOriginal
|
||||||
|
exif[36868] = meta.dateTime; // DateTimeDigitized
|
||||||
|
if (meta.width) exif[40962] = meta.width;
|
||||||
|
if (meta.height) exif[40963] = meta.height;
|
||||||
|
|
||||||
|
if (meta.gps && Number.isFinite(meta.gps.lat) && Number.isFinite(meta.gps.lng)) {
|
||||||
|
gps[0] = [2, 3, 0, 0];
|
||||||
|
gps[1] = meta.gps.lat >= 0 ? "N" : "S";
|
||||||
|
gps[2] = decToDms(meta.gps.lat);
|
||||||
|
gps[3] = meta.gps.lng >= 0 ? "E" : "W";
|
||||||
|
gps[4] = decToDms(meta.gps.lng);
|
||||||
|
if (Number.isFinite(meta.gps.altitude)) {
|
||||||
|
gps[5] = meta.gps.altitude >= 0 ? 0 : 1;
|
||||||
|
gps[6] = [Math.round(Math.abs(meta.gps.altitude) * 100), 100];
|
||||||
|
}
|
||||||
|
gps[29] = meta.dateTime.slice(0, 10).replace(/:/g, ":");
|
||||||
|
}
|
||||||
|
|
||||||
|
const dict = { "0th": zeroth, Exif: exif, GPS: gps, Interop: existing.Interop || {}, "1st": existing["1st"] || {}, thumbnail: null };
|
||||||
|
const inserted = px.insert(px.dump(dict), dataUrl);
|
||||||
|
return dataURLToBlob(inserted);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("writeExif failed", err);
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 1/125 · f/1.8 · 50mm */
|
||||||
|
export function formatExposure(exif = {}) {
|
||||||
|
const bits = [];
|
||||||
|
if (exif.fNumber) bits.push("f/" + exif.fNumber.toFixed(1));
|
||||||
|
if (exif.exposureTime) bits.push(exif.exposureTime >= 1 ? exif.exposureTime.toFixed(1) + "s" : "1/" + Math.round(1 / exif.exposureTime) + "s");
|
||||||
|
if (exif.iso) bits.push("ISO " + exif.iso);
|
||||||
|
if (exif.focalLength) bits.push(Math.round(exif.focalLength) + "mm");
|
||||||
|
return bits.join(" · ");
|
||||||
|
}
|
||||||
+763
@@ -0,0 +1,763 @@
|
|||||||
|
// ── CamCat 2.0 — wiring หลัก ────────────────────────────────
|
||||||
|
import {
|
||||||
|
APP_VERSION,
|
||||||
|
} from "./config.js";
|
||||||
|
import * as db from "./db.js";
|
||||||
|
import * as ui from "./ui.js";
|
||||||
|
import * as camApi from "./camera.js";
|
||||||
|
import { cam } from "./camera.js";
|
||||||
|
import { writeExif, readExif } from "./exif.js";
|
||||||
|
import { detectDevice, exifModelName, environment } from "./device.js";
|
||||||
|
import {
|
||||||
|
defaultFolderName, exifDateString, safeFileName, uniqueName,
|
||||||
|
} from "./naming.js";
|
||||||
|
import { ensureZip, invalidateZip, downloadFile, shareFile, canShareFiles } from "./archive.js";
|
||||||
|
|
||||||
|
const LS_FOLDER = "camcat.activeFolder";
|
||||||
|
const LS_FACING = "camcat.facing";
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
view: "camera",
|
||||||
|
folders: [],
|
||||||
|
folder: null,
|
||||||
|
images: [],
|
||||||
|
counts: [],
|
||||||
|
camReady: false,
|
||||||
|
camError: null,
|
||||||
|
camAllowed: false,
|
||||||
|
torchAvailable: false,
|
||||||
|
torchOn: false,
|
||||||
|
zoomRange: null,
|
||||||
|
zoomValue: null,
|
||||||
|
grid: false,
|
||||||
|
busy: false,
|
||||||
|
facing: localStorage.getItem(LS_FACING) || "environment",
|
||||||
|
storage: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const thumbUrls = new Map();
|
||||||
|
const main = document.getElementById("main");
|
||||||
|
let videoEl = null;
|
||||||
|
let prebuildTimer = null;
|
||||||
|
let gpsCache = { value: null, at: 0, denied: false };
|
||||||
|
|
||||||
|
const device = detectDevice();
|
||||||
|
|
||||||
|
// ── helpers ─────────────────────────────────────────────────
|
||||||
|
function thumbUrl(img) {
|
||||||
|
if (!thumbUrls.has(img.id)) {
|
||||||
|
thumbUrls.set(img.id, URL.createObjectURL(img.thumb || img.blob));
|
||||||
|
}
|
||||||
|
return thumbUrls.get(img.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dropThumb(id) {
|
||||||
|
const u = thumbUrls.get(id);
|
||||||
|
if (u) { URL.revokeObjectURL(u); thumbUrls.delete(id); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function setPill(name) {
|
||||||
|
const el = document.getElementById("active-folder-name");
|
||||||
|
if (el) el.textContent = name || "—";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── ธีมสว่าง/มืด (One UI) ────────────────────────────────── */
|
||||||
|
const LS_THEME = "camcat.theme";
|
||||||
|
const ICON_SUN = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4.2"/><path d="M12 2v2.2M12 19.8V22M2 12h2.2M19.8 12H22M4.9 4.9l1.6 1.6M17.5 17.5l1.6 1.6M19.1 4.9l-1.6 1.6M6.5 17.5l-1.6 1.6"/></svg>`;
|
||||||
|
const ICON_MOON = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 13.4A9 9 0 1 1 10.6 3a7 7 0 0 0 10.4 10.4z"/></svg>`;
|
||||||
|
|
||||||
|
function effectiveDark() {
|
||||||
|
const forced = document.documentElement.dataset.theme;
|
||||||
|
if (forced === "dark") return true;
|
||||||
|
if (forced === "light") return false;
|
||||||
|
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
function paintThemeButton() {
|
||||||
|
const btn = document.getElementById("theme-toggle");
|
||||||
|
if (!btn) return;
|
||||||
|
const dark = effectiveDark();
|
||||||
|
btn.innerHTML = dark ? ICON_SUN : ICON_MOON;
|
||||||
|
btn.setAttribute("aria-label", dark ? "เปลี่ยนเป็นธีมสว่าง" : "เปลี่ยนเป็นธีมมืด");
|
||||||
|
const meta = document.querySelector('meta[name="theme-color"]:not([media])');
|
||||||
|
if (meta) meta.setAttribute("content", dark ? "#000000" : "#F2F3F5");
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyTheme(mode, { announce = false } = {}) {
|
||||||
|
if (mode === "light" || mode === "dark") document.documentElement.dataset.theme = mode;
|
||||||
|
else document.documentElement.removeAttribute("data-theme");
|
||||||
|
localStorage.setItem(LS_THEME, mode);
|
||||||
|
paintThemeButton();
|
||||||
|
if (announce) ui.toast(mode === "auto" ? "ธีม: ตามระบบ" : mode === "dark" ? "ธีมมืด" : "ธีมสว่าง");
|
||||||
|
}
|
||||||
|
|
||||||
|
function cycleTheme() {
|
||||||
|
const modes = ["auto", "light", "dark"];
|
||||||
|
const cur = localStorage.getItem(LS_THEME) || "auto";
|
||||||
|
applyTheme(modes[(modes.indexOf(cur) + 1) % modes.length] || "auto", { announce: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function flash() {
|
||||||
|
const el = document.createElement("div");
|
||||||
|
el.style.cssText = "position:fixed;inset:0;background:#fff;opacity:.55;z-index:999;pointer-events:none;transition:opacity .18s";
|
||||||
|
document.body.appendChild(el);
|
||||||
|
requestAnimationFrame(() => { el.style.opacity = "0"; });
|
||||||
|
setTimeout(() => el.remove(), 220);
|
||||||
|
}
|
||||||
|
|
||||||
|
function nextFileName(folderName, images) {
|
||||||
|
const base = safeFileName(folderName).replace(/\s+/g, "_");
|
||||||
|
let max = 0;
|
||||||
|
const re = new RegExp("^" + base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "_(\\d{4})\\.jpg$");
|
||||||
|
for (const img of images) {
|
||||||
|
const m = re.exec(img.name || "");
|
||||||
|
if (m) max = Math.max(max, Number(m[1]));
|
||||||
|
}
|
||||||
|
return `${base}_${String(max + 1).padStart(4, "0")}.jpg`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getGps() {
|
||||||
|
if (gpsCache.denied) return null;
|
||||||
|
if (gpsCache.value && Date.now() - gpsCache.at < 5 * 60 * 1000) return gpsCache.value;
|
||||||
|
if (!navigator.geolocation) return null;
|
||||||
|
try {
|
||||||
|
const pos = await new Promise((res, rej) =>
|
||||||
|
navigator.geolocation.getCurrentPosition(res, rej, { enableHighAccuracy: true, timeout: 7000, maximumAge: 60000 })
|
||||||
|
);
|
||||||
|
gpsCache = {
|
||||||
|
value: {
|
||||||
|
lat: pos.coords.latitude,
|
||||||
|
lng: pos.coords.longitude,
|
||||||
|
accuracy: pos.coords.accuracy,
|
||||||
|
altitude: Number.isFinite(pos.coords.altitude) ? pos.coords.altitude : null,
|
||||||
|
},
|
||||||
|
at: Date.now(),
|
||||||
|
denied: false,
|
||||||
|
};
|
||||||
|
return gpsCache.value;
|
||||||
|
} catch (err) {
|
||||||
|
if (err && err.code === 1) gpsCache.denied = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── camera view ─────────────────────────────────────────────
|
||||||
|
function syncCam(overrides = {}) {
|
||||||
|
ui.syncCameraControls({
|
||||||
|
torchAvailable: state.torchAvailable && state.camReady,
|
||||||
|
torchOn: state.torchOn,
|
||||||
|
zoomRange: state.camReady ? state.zoomRange : null,
|
||||||
|
zoomValue: state.zoomValue,
|
||||||
|
gridOn: state.grid,
|
||||||
|
count: state.images.length,
|
||||||
|
thumbUrl: state.images.length ? thumbUrl(state.images[state.images.length - 1]) : null,
|
||||||
|
ready: state.camReady,
|
||||||
|
...overrides,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderCameraView() {
|
||||||
|
main.innerHTML = ui.cameraShell();
|
||||||
|
videoEl = document.getElementById("video");
|
||||||
|
paintOverlay();
|
||||||
|
syncCam();
|
||||||
|
}
|
||||||
|
|
||||||
|
function paintOverlay() {
|
||||||
|
const ov = document.getElementById("cam-overlay");
|
||||||
|
if (!ov) return;
|
||||||
|
if (state.camReady) { ov.innerHTML = ""; return; }
|
||||||
|
|
||||||
|
if (!window.isSecureContext) {
|
||||||
|
ov.innerHTML = ui.hero("insecure", {
|
||||||
|
title: "ต้องเปิดผ่าน HTTPS",
|
||||||
|
text: "เบราว์เซอร์อนุญาตให้ใช้กล้องเฉพาะหน้าที่เป็น HTTPS หรือ localhost เท่านั้น",
|
||||||
|
steps: [
|
||||||
|
"เปิดลิงก์ที่ขึ้นต้นด้วย <code>https://</code> (เช่น ลิงก์ tunnel ที่แนบ QR มาให้)",
|
||||||
|
"หรือใน Chrome พิมพ์ <code>chrome://flags/#unsafely-treat-insecure-origin-as-secure</code> แล้วใส่ <code>" + ui.esc(location.origin) + "</code>",
|
||||||
|
"กด Relaunch แล้วเปิดหน้านี้ใหม่",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.camError === "denied") {
|
||||||
|
ov.innerHTML = ui.hero("denied", {
|
||||||
|
title: "ยังไม่ได้อนุญาตให้ใช้กล้อง",
|
||||||
|
text: "ต้องอนุญาตสิทธิ์กล้องให้เบราว์เซอร์ก่อน",
|
||||||
|
steps: [
|
||||||
|
"เปิด การตั้งค่า → แอป → Chrome (หรือเบราว์เซอร์ที่ใช้) → สิทธิ์ → กล้อง → อนุญาต",
|
||||||
|
"กลับมาแล้วกดปุ่มลองใหม่ด้านล่าง",
|
||||||
|
"ถ้าเคยกดบล็อกไว้ ให้กดไอคอนกุญแจ/รูปกล้องบนแถบที่อยู่ แล้วเลือก รีเซ็ตสิทธิ์",
|
||||||
|
],
|
||||||
|
action: { act: "retry-camera", label: "ลองใหม่" },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.camError === "busy") {
|
||||||
|
ov.innerHTML = ui.hero("denied", {
|
||||||
|
title: "กล้องถูกแอปอื่นใช้งานอยู่",
|
||||||
|
text: "ปิดแอปกล้อง/วิดีโอคอลอื่น แล้วลองใหม่",
|
||||||
|
action: { act: "retry-camera", label: "ลองใหม่" },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.camError === "nocamera") {
|
||||||
|
ov.innerHTML = ui.hero("denied", {
|
||||||
|
title: "ไม่พบกล้อง",
|
||||||
|
text: "เบราว์เซอร์มองไม่เห็นกล้องของเครื่อง",
|
||||||
|
action: { act: "retry-camera", label: "ลองใหม่" },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.camError) {
|
||||||
|
ov.innerHTML = ui.hero("denied", {
|
||||||
|
title: "เปิดกล้องไม่สำเร็จ",
|
||||||
|
text: "รหัสข้อผิดพลาด: " + state.camError,
|
||||||
|
action: { act: "retry-camera", label: "ลองใหม่" },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ov.innerHTML = ui.hero("idle", {
|
||||||
|
title: "พร้อมถ่ายรูป",
|
||||||
|
text: `รูปจะถูกบันทึกเข้าโฟลเดอร์ ${state.folder ? state.folder.name : "ค่าเริ่มต้น"} พร้อมข้อมูล EXIF`,
|
||||||
|
action: { act: "start-camera", label: "เปิดกล้อง" },
|
||||||
|
note: window.isSecureContext ? "" : "ต้องเป็น HTTPS",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startCameraFlow() {
|
||||||
|
if (!videoEl) renderCameraView();
|
||||||
|
const ov = document.getElementById("cam-overlay");
|
||||||
|
if (ov && !state.camReady) {
|
||||||
|
ov.innerHTML = `<div class="hero cover"><div class="spinner"></div><p>กำลังเปิดกล้อง…</p></div>`;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await camApi.startCamera(videoEl, state.facing);
|
||||||
|
state.camReady = true;
|
||||||
|
state.camError = null;
|
||||||
|
state.camAllowed = true;
|
||||||
|
state.torchAvailable = !!res.torchAvailable;
|
||||||
|
state.zoomRange = res.zoomRange;
|
||||||
|
state.zoomValue = res.zoomRange ? res.zoomRange.min : null;
|
||||||
|
state.torchOn = false;
|
||||||
|
cam.track?.addEventListener("ended", () => {
|
||||||
|
state.camReady = false;
|
||||||
|
paintOverlay();
|
||||||
|
});
|
||||||
|
localStorage.setItem(LS_FACING, state.facing);
|
||||||
|
} catch (err) {
|
||||||
|
state.camReady = false;
|
||||||
|
state.camError = err.code || "unknown";
|
||||||
|
}
|
||||||
|
paintOverlay();
|
||||||
|
syncCam();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleTorch() {
|
||||||
|
const on = !state.torchOn;
|
||||||
|
const ok = await camApi.setTorch(on);
|
||||||
|
if (!ok) { ui.toast("เครื่องนี้เปิดไฟแฟลชผ่านเว็บไม่ได้"); return; }
|
||||||
|
state.torchOn = on;
|
||||||
|
syncCam();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function switchCamera() {
|
||||||
|
state.facing = state.facing === "environment" ? "user" : "environment";
|
||||||
|
state.camReady = false;
|
||||||
|
state.torchOn = false;
|
||||||
|
await startCameraFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── shoot ───────────────────────────────────────────────────
|
||||||
|
async function shoot() {
|
||||||
|
if (state.busy) return;
|
||||||
|
if (!state.camReady) { ui.toast("กล้องยังไม่พร้อม"); return; }
|
||||||
|
state.busy = true;
|
||||||
|
const shutter = document.getElementById("shutter");
|
||||||
|
if (shutter) shutter.disabled = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const folder = state.folder;
|
||||||
|
if (!folder) throw new Error("ยังไม่มีโฟลเดอร์");
|
||||||
|
|
||||||
|
const shot = await camApi.captureStill();
|
||||||
|
const gps = await getGps();
|
||||||
|
const at = Date.now();
|
||||||
|
const exifBlob = await writeExif(shot.blob, {
|
||||||
|
make: "Samsung",
|
||||||
|
model: exifModelName(),
|
||||||
|
dateTime: exifDateString(new Date(at)),
|
||||||
|
gps,
|
||||||
|
width: shot.width,
|
||||||
|
height: shot.height,
|
||||||
|
folder: folder.name,
|
||||||
|
source: shot.source,
|
||||||
|
version: APP_VERSION,
|
||||||
|
});
|
||||||
|
const exifRead = await readExif(exifBlob);
|
||||||
|
const name = nextFileName(folder.name, state.images);
|
||||||
|
|
||||||
|
const record = {
|
||||||
|
id: "img_" + at + "_" + Math.random().toString(36).slice(2, 7),
|
||||||
|
folderId: folder.id,
|
||||||
|
name,
|
||||||
|
blob: exifBlob,
|
||||||
|
thumb: shot.thumb,
|
||||||
|
size: exifBlob.size,
|
||||||
|
createdAt: at,
|
||||||
|
meta: {
|
||||||
|
width: shot.width,
|
||||||
|
height: shot.height,
|
||||||
|
device: exifModelName(),
|
||||||
|
facing: shot.facing,
|
||||||
|
facingLabel: shot.facing === "environment" ? "กล้องหลัง" : "กล้องหน้า",
|
||||||
|
source: shot.source,
|
||||||
|
sourceLabel: shot.source === "imagecapture" ? "ImageCapture (ความละเอียดเต็ม)" : "วิดีโอ (canvas)",
|
||||||
|
gps: gps ? { lat: gps.lat, lng: gps.lng, accuracy: gps.accuracy } : null,
|
||||||
|
exif: exifRead,
|
||||||
|
app: `CamCat ${APP_VERSION}`,
|
||||||
|
takenAtIso: new Date(at).toISOString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
await db.putImage(record);
|
||||||
|
await db.touchFolder(folder.id);
|
||||||
|
state.images.push(record);
|
||||||
|
state.counts = state.counts.map((c, i) => (state.folders[i]?.id === folder.id ? c + 1 : c));
|
||||||
|
|
||||||
|
flash();
|
||||||
|
invalidateZip();
|
||||||
|
syncCam({ thumbUrl: thumbUrl(record) });
|
||||||
|
ui.toast(`บันทึก ${name} · ${shot.width}×${shot.height}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
ui.toast("ถ่ายไม่สำเร็จ: " + (err.code || err.message));
|
||||||
|
} finally {
|
||||||
|
state.busy = false;
|
||||||
|
if (shutter) shutter.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── folder data ─────────────────────────────────────────────
|
||||||
|
async function loadFolders() {
|
||||||
|
state.folders = await db.getFolders();
|
||||||
|
state.counts = [];
|
||||||
|
for (const f of state.folders) state.counts.push(await db.countImages(f.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function selectFolder(id, { silent = false } = {}) {
|
||||||
|
const f = await db.getFolder(id);
|
||||||
|
if (!f) return;
|
||||||
|
state.folder = f;
|
||||||
|
state.images = await db.getImages(id);
|
||||||
|
localStorage.setItem(LS_FOLDER, id);
|
||||||
|
setPill(f.name);
|
||||||
|
if (!silent) ui.toast("ใช้งาน: " + f.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureDefaultFolder() {
|
||||||
|
await loadFolders();
|
||||||
|
if (!state.folders.length) {
|
||||||
|
const folder = { id: "f_" + Date.now(), name: defaultFolderName(), createdAt: Date.now(), updatedAt: Date.now() };
|
||||||
|
await db.putFolder(folder);
|
||||||
|
await loadFolders();
|
||||||
|
await selectFolder(folder.id, { silent: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const remembered = localStorage.getItem(LS_FOLDER);
|
||||||
|
const target =
|
||||||
|
state.folders.find((f) => f.id === remembered) ||
|
||||||
|
state.folders.find((f) => f.name === defaultFolderName()) ||
|
||||||
|
state.folders[state.folders.length - 1];
|
||||||
|
await selectFolder(target.id, { silent: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── views ───────────────────────────────────────────────────
|
||||||
|
async function navigate(view) {
|
||||||
|
state.view = view;
|
||||||
|
document.getElementById("app").dataset.view = view;
|
||||||
|
document.querySelectorAll("nav button").forEach((b) => b.classList.toggle("active", b.dataset.view === view));
|
||||||
|
if (view !== "camera") {
|
||||||
|
camApi.stopCamera();
|
||||||
|
state.camReady = false;
|
||||||
|
}
|
||||||
|
await render();
|
||||||
|
// กลับเข้าหน้ากล้อง: ถ้าเคยอนุญาตแล้วให้เปิดกล้องให้เลย
|
||||||
|
if (view === "camera" && state.camAllowed && !state.camReady) {
|
||||||
|
await startCameraFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function render() {
|
||||||
|
if (state.view === "camera") {
|
||||||
|
await loadFolders();
|
||||||
|
renderCameraView();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (state.view === "folders") {
|
||||||
|
await loadFolders();
|
||||||
|
state.storage = await db.storageInfo();
|
||||||
|
main.innerHTML = ui.renderFolders({
|
||||||
|
folders: state.folders,
|
||||||
|
counts: state.counts,
|
||||||
|
activeId: state.folder?.id,
|
||||||
|
storage: state.storage,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (state.view === "gallery") {
|
||||||
|
renderGallery();
|
||||||
|
schedulePrebuild();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderGallery() {
|
||||||
|
main.innerHTML = ui.renderGallery({
|
||||||
|
folder: state.folder,
|
||||||
|
images: state.images,
|
||||||
|
thumbUrl: (img) => thumbUrl(img),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── ZIP: ดาวน์โหลด / แชร์ ───────────────────────────────────
|
||||||
|
function schedulePrebuild() {
|
||||||
|
clearTimeout(prebuildTimer);
|
||||||
|
if (!state.images.length || !navigator.share) return;
|
||||||
|
prebuildTimer = setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
await ensureZip(state.folder, state.images, null);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("prebuild zip failed", e);
|
||||||
|
}
|
||||||
|
}, 1200);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function zipFlow(mode) {
|
||||||
|
if (!state.folder) { ui.toast("ยังไม่เลือกโฟลเดอร์"); return; }
|
||||||
|
if (!state.images.length) { ui.toast("ยังไม่มีรูปในโฟลเดอร์นี้"); return; }
|
||||||
|
if (state.busy) return;
|
||||||
|
state.busy = true;
|
||||||
|
|
||||||
|
ui.progressSheet(`กำลังรวม ${state.images.length} รูปเป็น ZIP`);
|
||||||
|
try {
|
||||||
|
const { file } = await ensureZip(state.folder, state.images, (p) =>
|
||||||
|
ui.progressUpdate(p, `กำลังรวม ${state.images.length} รูป`)
|
||||||
|
);
|
||||||
|
ui.closeSheet();
|
||||||
|
|
||||||
|
if (mode === "download") {
|
||||||
|
downloadFile(file);
|
||||||
|
ui.toast(`ดาวน์โหลด ${file.name} (${ui.fmtBytes(file.size)})`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!canShareFiles(file)) {
|
||||||
|
downloadFile(file);
|
||||||
|
ui.toast("เครื่องนี้แชร์ไฟล์ผ่านเว็บไม่ได้ — ดาวน์โหลด ZIP ให้แล้ว");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const res = await shareFile(file, {
|
||||||
|
title: state.folder.name,
|
||||||
|
text: `รูปจาก ${state.folder.name} (${state.images.length} รูป)`,
|
||||||
|
});
|
||||||
|
if (res.ok) ui.toast("เปิดเมนูแชร์ของเครื่องแล้ว");
|
||||||
|
else if (res.reason === "cancelled") ui.toast("ยกเลิกการแชร์");
|
||||||
|
else if (res.reason === "unsupported" || res.reason === "nofiles") {
|
||||||
|
downloadFile(file);
|
||||||
|
ui.toast("แชร์ไฟล์ไม่ได้ — ดาวน์โหลด ZIP ให้แล้ว");
|
||||||
|
} else {
|
||||||
|
downloadFile(file);
|
||||||
|
ui.toast("แชร์ไม่สำเร็จ — ดาวน์โหลด ZIP ให้แล้ว");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
ui.closeSheet();
|
||||||
|
ui.toast("สร้าง ZIP ไม่สำเร็จ: " + err.message);
|
||||||
|
} finally {
|
||||||
|
state.busy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── photo sheet ─────────────────────────────────────────────
|
||||||
|
async function openPhoto(id) {
|
||||||
|
const rec = await db.getImage(id);
|
||||||
|
if (!rec) return;
|
||||||
|
const url = URL.createObjectURL(rec.blob);
|
||||||
|
ui.openSheet(ui.photoSheet({ record: rec, url, folderName: state.folder?.name }));
|
||||||
|
const img = document.querySelector("#sheet-content img.preview");
|
||||||
|
if (img) img.addEventListener("load", () => URL.revokeObjectURL(url), { once: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deletePhoto(id) {
|
||||||
|
await db.deleteImage(id);
|
||||||
|
dropThumb(id);
|
||||||
|
state.images = state.images.filter((i) => i.id !== id);
|
||||||
|
if (state.folder) await db.touchFolder(state.folder.id);
|
||||||
|
invalidateZip();
|
||||||
|
ui.closeSheet();
|
||||||
|
if (state.view === "gallery") renderGallery();
|
||||||
|
else if (state.view === "camera") renderCameraView();
|
||||||
|
ui.toast("ลบรูปแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function shareOnePhoto(id) {
|
||||||
|
const rec = await db.getImage(id);
|
||||||
|
if (!rec) return;
|
||||||
|
const file = new File([rec.blob], rec.name || "photo.jpg", { type: "image/jpeg" });
|
||||||
|
if (!canShareFiles(file)) {
|
||||||
|
downloadFile(file);
|
||||||
|
ui.toast("แชร์ไม่ได้ — ดาวน์โหลดรูปให้แล้ว");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const res = await shareFile(file, { title: rec.name });
|
||||||
|
ui.toast(res.ok ? "เปิดเมนูแชร์แล้ว" : res.reason === "cancelled" ? "ยกเลิก" : "แชร์ไม่สำเร็จ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── diagnostics ─────────────────────────────────────────────
|
||||||
|
async function showDiagnostics() {
|
||||||
|
const env = environment();
|
||||||
|
const s = cam.track?.getSettings?.() || {};
|
||||||
|
const caps = cam.caps || {};
|
||||||
|
const st = await db.storageInfo();
|
||||||
|
const rows = [
|
||||||
|
["รุ่นเครื่อง", env.code && env.code !== env.model ? `${env.model} (${env.code})` : env.model],
|
||||||
|
["แบรนด์ / Android", `${env.brand}${env.androidVersion ? " / " + env.androidVersion : ""}`],
|
||||||
|
["Chrome", env.chromeVersion || "—"],
|
||||||
|
["หน้าจอ CSS", `${env.viewport} @${env.dpr}x`],
|
||||||
|
["visualViewport", env.visualViewport],
|
||||||
|
["จอจริง (px)", env.screen],
|
||||||
|
["โหมดติดตั้ง", env.standalone ? "PWA (standalone)" : "เบราว์เซอร์"],
|
||||||
|
["ความปลอดภัย", env.secureContext ? "HTTPS — ใช้กล้องได้" : "ไม่ปลอดภัย — กล้องถูกบล็อก"],
|
||||||
|
["URL", env.url],
|
||||||
|
["สตรีมกล้อง", s.width ? `${s.width}×${s.height} @${Math.round(s.frameRate || 0)}fps` : "ยังไม่เปิด"],
|
||||||
|
["หันกล้อง", s.facingMode || "—"],
|
||||||
|
["ImageCapture", env.imageCapture ? "มี (ถ่ายเต็มความละเอียด)" : "ไม่มี (ใช้ canvas)"],
|
||||||
|
["ไฟแฟลช", caps.torch ? "รองรับ" : "ไม่รองรับ"],
|
||||||
|
["ซูม", caps.zoom ? `${caps.zoom.min}–${caps.zoom.max} (step ${caps.zoom.step || "?"})` : "ไม่รองรับ"],
|
||||||
|
["โฟกัส", Array.isArray(caps.focusMode) ? caps.focusMode.join(", ") : "—"],
|
||||||
|
["แชร์ไฟล์", env.share ? "รองรับ Web Share ไฟล์" : "ไม่รองรับ"],
|
||||||
|
["พื้นที่เก็บข้อมูล", st ? `${ui.fmtBytes(st.usage)} / ${ui.fmtBytes(st.quota)}` : "—"],
|
||||||
|
["โฟลเดอร์ / รูป", `${state.folders.length} / ${state.images.length}`],
|
||||||
|
];
|
||||||
|
ui.openSheet(ui.diagnosticsSheet(rows));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── QR ลิงก์ทดสอบ ───────────────────────────────────────────
|
||||||
|
function showQr() {
|
||||||
|
const url = location.origin + location.pathname;
|
||||||
|
ui.openSheet(ui.qrSheet(url));
|
||||||
|
const holder = document.getElementById("qr-holder");
|
||||||
|
if (!holder) return;
|
||||||
|
if (!window.QRCode) { ui.toast("โหลดตัวสร้าง QR ไม่สำเร็จ"); return; }
|
||||||
|
holder.innerHTML = "";
|
||||||
|
new window.QRCode(holder, {
|
||||||
|
text: url,
|
||||||
|
width: 232,
|
||||||
|
height: 232,
|
||||||
|
colorDark: "#0F172A",
|
||||||
|
colorLight: "#FFFFFF",
|
||||||
|
correctLevel: window.QRCode.CorrectLevel.M,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyLink() {
|
||||||
|
const url = location.origin + location.pathname;
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(url);
|
||||||
|
ui.toast("คัดลอกลิงก์แล้ว");
|
||||||
|
} catch {
|
||||||
|
ui.toast("คัดลอกอัตโนมัติไม่ได้ — กดค้างที่ลิงก์เพื่อคัดลอก");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── folder modals ───────────────────────────────────────────
|
||||||
|
async function openNewFolder() {
|
||||||
|
await loadFolders();
|
||||||
|
const base = defaultFolderName();
|
||||||
|
const suggested = uniqueName(base, state.folders.map((f) => f.name));
|
||||||
|
ui.openSheet(ui.folderSheet("new", { suggested }));
|
||||||
|
setTimeout(() => document.getElementById("folder-name-input")?.select(), 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmNewFolder() {
|
||||||
|
const input = document.getElementById("folder-name-input");
|
||||||
|
const raw = input.value.trim();
|
||||||
|
if (!raw) { ui.toast("ใส่ชื่อโฟลเดอร์ก่อน"); return; }
|
||||||
|
await loadFolders();
|
||||||
|
const name = uniqueName(raw, state.folders.map((f) => f.name));
|
||||||
|
const folder = { id: "f_" + Date.now(), name, createdAt: Date.now(), updatedAt: Date.now() };
|
||||||
|
await db.putFolder(folder);
|
||||||
|
await selectFolder(folder.id, { silent: true });
|
||||||
|
await loadFolders();
|
||||||
|
ui.closeSheet();
|
||||||
|
ui.toast("สร้างโฟลเดอร์: " + name);
|
||||||
|
if (state.view === "camera") renderCameraView();
|
||||||
|
else await render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openRenameFolder(id) {
|
||||||
|
const f = state.folders.find((x) => x.id === id);
|
||||||
|
if (!f) return;
|
||||||
|
ui.openSheet(ui.folderSheet("rename", { id, name: f.name }));
|
||||||
|
setTimeout(() => document.getElementById("folder-name-input")?.select(), 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmRenameFolder(id) {
|
||||||
|
const raw = document.getElementById("folder-name-input").value.trim();
|
||||||
|
if (!raw) { ui.toast("ใส่ชื่อก่อน"); return; }
|
||||||
|
const f = await db.getFolder(id);
|
||||||
|
if (!f) return;
|
||||||
|
await loadFolders();
|
||||||
|
f.name = uniqueName(raw, state.folders.filter((x) => x.id !== id).map((x) => x.name));
|
||||||
|
f.updatedAt = Date.now();
|
||||||
|
await db.putFolder(f);
|
||||||
|
if (state.folder?.id === id) state.folder = f;
|
||||||
|
invalidateZip();
|
||||||
|
ui.closeSheet();
|
||||||
|
await loadFolders();
|
||||||
|
await render();
|
||||||
|
ui.toast("เปลี่ยนชื่อแล้ว: " + f.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmDeleteFolder(id) {
|
||||||
|
const f = state.folders.find((x) => x.id === id);
|
||||||
|
const imgs = await db.getImages(id);
|
||||||
|
for (const img of imgs) dropThumb(img.id);
|
||||||
|
await db.deleteFolder(id);
|
||||||
|
invalidateZip();
|
||||||
|
ui.closeSheet();
|
||||||
|
await loadFolders();
|
||||||
|
if (state.folder?.id === id) {
|
||||||
|
if (state.folders.length) await selectFolder(state.folders[0].id, { silent: true });
|
||||||
|
else {
|
||||||
|
const folder = { id: "f_" + Date.now(), name: defaultFolderName(), createdAt: Date.now(), updatedAt: Date.now() };
|
||||||
|
await db.putFolder(folder);
|
||||||
|
await loadFolders();
|
||||||
|
await selectFolder(folder.id, { silent: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await render();
|
||||||
|
ui.toast("ลบโฟลเดอร์แล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── events ──────────────────────────────────────────────────
|
||||||
|
document.addEventListener("click", async (e) => {
|
||||||
|
const el = e.target.closest("[data-action]");
|
||||||
|
if (el) {
|
||||||
|
const action = el.dataset.action;
|
||||||
|
const id = el.dataset.id;
|
||||||
|
switch (action) {
|
||||||
|
case "start-camera":
|
||||||
|
case "retry-camera": await startCameraFlow(); break;
|
||||||
|
case "shoot": await shoot(); break;
|
||||||
|
case "toggle-torch": await toggleTorch(); break;
|
||||||
|
case "switch-camera": await switchCamera(); break;
|
||||||
|
case "zoom-set": {
|
||||||
|
const z = Number(el.dataset.zoom);
|
||||||
|
const ok = await camApi.setZoom(z);
|
||||||
|
if (ok) state.zoomValue = z;
|
||||||
|
syncCam();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "toggle-grid":
|
||||||
|
state.grid = !state.grid;
|
||||||
|
syncCam();
|
||||||
|
break;
|
||||||
|
case "open-last":
|
||||||
|
if (state.images.length) await openPhoto(state.images[state.images.length - 1].id);
|
||||||
|
break;
|
||||||
|
case "select-folder":
|
||||||
|
await selectFolder(id);
|
||||||
|
await render();
|
||||||
|
break;
|
||||||
|
case "new-folder": await openNewFolder(); break;
|
||||||
|
case "rename-folder": openRenameFolder(id); break;
|
||||||
|
case "delete-folder": {
|
||||||
|
const f = state.folders.find((x) => x.id === id);
|
||||||
|
const count = await db.countImages(id);
|
||||||
|
ui.openSheet(ui.folderSheet("delete", { id, name: f ? f.name : "", count }));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "confirm-new-folder": await confirmNewFolder(); break;
|
||||||
|
case "confirm-rename-folder": await confirmRenameFolder(id); break;
|
||||||
|
case "confirm-delete-folder": await confirmDeleteFolder(id); break;
|
||||||
|
case "open-photo": await openPhoto(id); break;
|
||||||
|
case "delete-photo": await deletePhoto(id); break;
|
||||||
|
case "share-photo": await shareOnePhoto(id); break;
|
||||||
|
case "zip-download": await zipFlow("download"); break;
|
||||||
|
case "zip-share": await zipFlow("share"); break;
|
||||||
|
case "diagnostics": await showDiagnostics(); break;
|
||||||
|
case "show-qr": showQr(); break;
|
||||||
|
case "copy-url": await copyLink(); break;
|
||||||
|
case "close-sheet": ui.closeSheet(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.target.id === "sheet-overlay") ui.closeSheet();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("bottom-nav").addEventListener("click", (e) => {
|
||||||
|
const btn = e.target.closest("button[data-view]");
|
||||||
|
if (btn) navigate(btn.dataset.view);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("active-folder-pill").addEventListener("click", () => navigate("folders"));
|
||||||
|
document.getElementById("theme-toggle").addEventListener("click", () => cycleTheme());
|
||||||
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
|
||||||
|
if ((localStorage.getItem(LS_THEME) || "auto") === "auto") paintThemeButton();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key !== "Enter" && e.key !== " ") return;
|
||||||
|
const el = e.target.closest?.('[data-action][role="button"]');
|
||||||
|
if (!el) return;
|
||||||
|
e.preventDefault();
|
||||||
|
el.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", async () => {
|
||||||
|
if (document.hidden) {
|
||||||
|
if (state.view === "camera") { camApi.stopCamera(); state.camReady = false; }
|
||||||
|
} else if (state.view === "camera" && state.camAllowed) {
|
||||||
|
await startCameraFlow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── init ────────────────────────────────────────────────────
|
||||||
|
async function init() {
|
||||||
|
await db.open();
|
||||||
|
await ensureDefaultFolder();
|
||||||
|
setPill(state.folder?.name || "—");
|
||||||
|
applyTheme(localStorage.getItem(LS_THEME) || "auto");
|
||||||
|
|
||||||
|
if (navigator.storage?.persist) { try { await navigator.storage.persist(); } catch {} }
|
||||||
|
|
||||||
|
if ("serviceWorker" in navigator) {
|
||||||
|
try { await navigator.serviceWorker.register("sw.js", { scope: "./" }); } catch (e) { console.warn("SW", e); }
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("app").dataset.view = state.view;
|
||||||
|
renderCameraView();
|
||||||
|
|
||||||
|
const wanted = new URLSearchParams(location.search).get("view");
|
||||||
|
if (wanted === "gallery" || wanted === "folders") {
|
||||||
|
await navigate(wanted);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const perm = await camApi.permissionState();
|
||||||
|
if (perm === "granted") {
|
||||||
|
await startCameraFlow();
|
||||||
|
} else {
|
||||||
|
paintOverlay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
// ── ตั้งชื่อโฟลเดอร์/ไฟล์ (ปี พ.ศ. ตามเวลาไทย) ───────────────
|
||||||
|
import { SITE_LABEL, TIME_ZONE } from "./config.js";
|
||||||
|
|
||||||
|
const partsFmt = new Intl.DateTimeFormat("en-GB", {
|
||||||
|
timeZone: TIME_ZONE,
|
||||||
|
year: "numeric", month: "2-digit", day: "2-digit",
|
||||||
|
hour: "2-digit", minute: "2-digit", second: "2-digit",
|
||||||
|
hour12: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export function bkkParts(date = new Date()) {
|
||||||
|
const p = {};
|
||||||
|
for (const { type, value } of partsFmt.formatToParts(date)) p[type] = value;
|
||||||
|
const year = Number(p.year);
|
||||||
|
return {
|
||||||
|
year,
|
||||||
|
thaiYear: year + 543,
|
||||||
|
month: p.month,
|
||||||
|
day: p.day,
|
||||||
|
hour: p.hour === "24" ? "00" : p.hour,
|
||||||
|
minute: p.minute,
|
||||||
|
second: p.second,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "Site A 2569-10-24" */
|
||||||
|
export function defaultFolderName(date = new Date()) {
|
||||||
|
const p = bkkParts(date);
|
||||||
|
return `${SITE_LABEL} ${p.thaiYear}-${p.month}-${p.day}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** EXIF DateTimeOriginal: "YYYY:MM:DD HH:MM:SS" (เวลาไทย) */
|
||||||
|
export function exifDateString(date = new Date()) {
|
||||||
|
const p = bkkParts(date);
|
||||||
|
return `${p.year}:${p.month}:${p.day} ${p.hour}:${p.minute}:${p.second}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ชื่อไฟล์: 20261024-171230 */
|
||||||
|
export function fileStamp(date = new Date()) {
|
||||||
|
const p = bkkParts(date);
|
||||||
|
return `${p.year}${p.month}${p.day}-${p.hour}${p.minute}${p.second}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** วันที่แบบอ่านง่าย: 24/10/2569 17:12 */
|
||||||
|
export function humanDateTime(ts) {
|
||||||
|
const p = bkkParts(new Date(ts));
|
||||||
|
return `${p.day}/${p.month}/${p.thaiYear} ${p.hour}:${p.minute}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ตัดอักขระต้องห้ามของ Windows/Android ออก */
|
||||||
|
export function safeFileName(name, fallback = "file") {
|
||||||
|
const cleaned = String(name)
|
||||||
|
.replace(/[\\/:*?"<>|\u0000-\u001f]/g, "-")
|
||||||
|
.replace(/\s+/g, " ")
|
||||||
|
.trim()
|
||||||
|
.replace(/^\.+/, "");
|
||||||
|
return cleaned || fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ให้ได้ชื่อไม่ซ้ำในรายการที่มีอยู่: base, base (2), base (3) */
|
||||||
|
export function uniqueName(base, existingNames) {
|
||||||
|
const taken = new Set(existingNames);
|
||||||
|
if (!taken.has(base)) return base;
|
||||||
|
let n = 2;
|
||||||
|
while (taken.has(`${base} (${n})`)) n++;
|
||||||
|
return `${base} (${n})`;
|
||||||
|
}
|
||||||
+319
@@ -0,0 +1,319 @@
|
|||||||
|
// ── UI: markup + toast + bottom sheet ────────────────────────
|
||||||
|
import { humanDateTime } from "./naming.js";
|
||||||
|
import { formatExposure } from "./exif.js";
|
||||||
|
|
||||||
|
export const esc = (s) =>
|
||||||
|
String(s ?? "")
|
||||||
|
.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """).replace(/'/g, "'");
|
||||||
|
|
||||||
|
export function fmtBytes(n) {
|
||||||
|
if (!Number.isFinite(n) || n <= 0) return "0 B";
|
||||||
|
if (n < 1024) return n + " B";
|
||||||
|
if (n < 1024 ** 2) return (n / 1024).toFixed(1) + " KB";
|
||||||
|
if (n < 1024 ** 3) return (n / 1024 ** 2).toFixed(1) + " MB";
|
||||||
|
return (n / 1024 ** 3).toFixed(2) + " GB";
|
||||||
|
}
|
||||||
|
|
||||||
|
const ICON = {
|
||||||
|
torch: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 2h6l-1 7h4l-7 13 1-8H8z"/></svg>`,
|
||||||
|
flip: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.5 9a9 9 0 0 1 14.9-3.4L23 10M1 14l4.6 4.4A9 9 0 0 0 20.5 15"/></svg>`,
|
||||||
|
grid: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18M15 3v18M3 9h18M3 15h18"/></svg>`,
|
||||||
|
pencil: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/></svg>`,
|
||||||
|
trash: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6"/><path d="M10 11v6M14 11v6"/></svg>`,
|
||||||
|
zip: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M12 2v4M10 6h4M10 10h4M10 14h4"/></svg>`,
|
||||||
|
share: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V3"/><path d="M8 7l4-4 4 4"/><path d="M4 14v5a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5"/></svg>`,
|
||||||
|
camera: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>`,
|
||||||
|
lock: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>`,
|
||||||
|
block: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M5.6 5.6l12.8 12.8"/></svg>`,
|
||||||
|
folder: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>`,
|
||||||
|
image: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>`,
|
||||||
|
};
|
||||||
|
|
||||||
|
// ── Toast ──
|
||||||
|
let toastTimer = null;
|
||||||
|
export function toast(msg, ms = 2600) {
|
||||||
|
const el = document.getElementById("toast");
|
||||||
|
el.textContent = msg;
|
||||||
|
el.classList.add("show");
|
||||||
|
clearTimeout(toastTimer);
|
||||||
|
toastTimer = setTimeout(() => el.classList.remove("show"), ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Bottom sheet ──
|
||||||
|
export function openSheet(html) {
|
||||||
|
const overlay = document.getElementById("sheet-overlay");
|
||||||
|
document.getElementById("sheet-content").innerHTML = html;
|
||||||
|
overlay.hidden = false;
|
||||||
|
overlay.setAttribute("aria-hidden", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function closeSheet() {
|
||||||
|
const overlay = document.getElementById("sheet-overlay");
|
||||||
|
overlay.hidden = true;
|
||||||
|
overlay.setAttribute("aria-hidden", "true");
|
||||||
|
document.getElementById("sheet-content").innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isSheetOpen() {
|
||||||
|
return !document.getElementById("sheet-overlay").hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Camera ──
|
||||||
|
export function cameraShell() {
|
||||||
|
return `
|
||||||
|
<div id="camera-view">
|
||||||
|
<div class="stage">
|
||||||
|
<video id="video" autoplay playsinline muted></video>
|
||||||
|
<div class="grid-lines" id="grid-lines"></div>
|
||||||
|
<div class="cam-top">
|
||||||
|
<button class="cam-chip" type="button" data-action="toggle-grid" aria-label="เส้นแบ่ง 3 ส่วน">${ICON.grid}</button>
|
||||||
|
<button class="cam-chip" type="button" id="chip-torch" data-action="toggle-torch" aria-pressed="false" aria-label="ไฟแฟลช" hidden>${ICON.torch}</button>
|
||||||
|
<button class="cam-chip" type="button" data-action="switch-camera" aria-label="สลับกล้องหน้า/หลัง">${ICON.flip}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="cam-bottom">
|
||||||
|
<div class="zoom-pills" id="zoom-pills" hidden></div>
|
||||||
|
<div class="shutter-row">
|
||||||
|
<div class="shutter-side"><button class="thumb-btn" id="last-thumb" type="button" data-action="open-last" aria-label="รูปล่าสุด"></button></div>
|
||||||
|
<button id="shutter" type="button" data-action="shoot" aria-label="ถ่ายรูป"></button>
|
||||||
|
<div class="shutter-side"><span id="shot-count"></span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="cam-overlay"></div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function overlay(html) {
|
||||||
|
const el = document.getElementById("cam-overlay");
|
||||||
|
if (el) el.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hero(kind, { title, text = "", steps = [], action = null, note = "" }) {
|
||||||
|
const stepsHtml = steps.length
|
||||||
|
? `<ol>${steps.map((s) => `<li>${s}</li>`).join("")}</ol>`
|
||||||
|
: "";
|
||||||
|
const actionHtml = action
|
||||||
|
? `<button class="btn btn-primary" type="button" data-action="${action.act}">${action.label}</button>`
|
||||||
|
: "";
|
||||||
|
return `<div class="hero cover">
|
||||||
|
<div class="ico">${kind === "denied" ? ICON.block : kind === "insecure" ? ICON.lock : ICON.camera}</div>
|
||||||
|
<h2>${esc(title)}</h2>
|
||||||
|
${text ? `<p>${esc(text)}</p>` : ""}
|
||||||
|
${stepsHtml ? `<div class="notice" style="text-align:left">${stepsHtml}</div>` : ""}
|
||||||
|
${actionHtml}
|
||||||
|
${note ? `<p style="font-size:11px">${note}</p>` : ""}
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function syncCameraControls({ torchAvailable, torchOn, zoomRange, zoomValue, gridOn, count, thumbUrl, ready }) {
|
||||||
|
const chip = document.getElementById("chip-torch");
|
||||||
|
if (chip) {
|
||||||
|
chip.hidden = !torchAvailable;
|
||||||
|
chip.setAttribute("aria-pressed", torchOn ? "true" : "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
const pills = document.getElementById("zoom-pills");
|
||||||
|
if (pills) {
|
||||||
|
const min = zoomRange ? Number(zoomRange.min) : 1;
|
||||||
|
const max = zoomRange ? Number(zoomRange.max) : 1;
|
||||||
|
if (zoomRange && max > min) {
|
||||||
|
const levels = [1, 2, 3].filter((z) => z >= min - 0.05 && z <= max + 0.05);
|
||||||
|
if (!levels.length) levels.push(min);
|
||||||
|
const current = zoomValue ?? min;
|
||||||
|
pills.hidden = false;
|
||||||
|
pills.innerHTML = levels
|
||||||
|
.map(
|
||||||
|
(z) =>
|
||||||
|
`<button class="zoom-pill ${Math.abs(current - z) < 0.25 ? "on" : ""}" type="button" data-action="zoom-set" data-zoom="${z}" aria-label="ซูม ${z} เท่า" aria-pressed="${Math.abs(current - z) < 0.25}">${z}×</button>`
|
||||||
|
)
|
||||||
|
.join("");
|
||||||
|
} else {
|
||||||
|
pills.hidden = true;
|
||||||
|
pills.innerHTML = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const grid = document.getElementById("grid-lines");
|
||||||
|
if (grid) grid.classList.toggle("on", !!gridOn);
|
||||||
|
const cnt = document.getElementById("shot-count");
|
||||||
|
if (cnt) cnt.textContent = count ? count + " รูป" : "";
|
||||||
|
const thumb = document.getElementById("last-thumb");
|
||||||
|
if (thumb && thumbUrl) thumb.innerHTML = `<img src="${thumbUrl}" alt="รูปล่าสุด">`;
|
||||||
|
const sh = document.getElementById("shutter");
|
||||||
|
if (sh) sh.disabled = !ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Folders ──
|
||||||
|
export function renderFolders({ folders, counts, activeId, storage }) {
|
||||||
|
const total = counts.reduce((a, b) => a + b, 0);
|
||||||
|
let html = `<div class="section-head">
|
||||||
|
<div><h2>โฟลเดอร์</h2><div class="sub">${folders.length} โฟลเดอร์ · ${total} รูป</div></div>
|
||||||
|
<button class="btn btn-primary" type="button" data-action="new-folder">+ โฟลเดอร์ใหม่</button>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
if (!folders.length) {
|
||||||
|
html += `<div class="empty"><span class="ico">${ICON.folder}</span>ยังไม่มีโฟลเดอร์</div>`;
|
||||||
|
} else {
|
||||||
|
html += `<div class="folder-list">`;
|
||||||
|
folders.forEach((f, i) => {
|
||||||
|
const active = f.id === activeId;
|
||||||
|
html += `<div class="folder-item ${active ? "active" : ""}" data-action="select-folder" data-id="${esc(f.id)}" role="button" tabindex="0" aria-label="โฟลเดอร์ ${esc(f.name)} · ${counts[i]} รูป">
|
||||||
|
<span class="f-ico" aria-hidden="true">${ICON.folder}</span>
|
||||||
|
<div class="f-main">
|
||||||
|
<div class="f-name">${esc(f.name)}</div>
|
||||||
|
<div class="f-meta">${counts[i]} รูป${active ? " · ใช้งานอยู่" : ""}</div>
|
||||||
|
</div>
|
||||||
|
<div class="f-actions">
|
||||||
|
<button class="icon-btn" type="button" data-action="rename-folder" data-id="${esc(f.id)}" aria-label="เปลี่ยนชื่อโฟลเดอร์">${ICON.pencil}</button>
|
||||||
|
<button class="icon-btn danger" type="button" data-action="delete-folder" data-id="${esc(f.id)}" aria-label="ลบโฟลเดอร์">${ICON.trash}</button>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
});
|
||||||
|
html += `</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
html += `<div class="storage-line">
|
||||||
|
พื้นที่เก็บในเครื่อง${storage ? ` · ใช้ ${fmtBytes(storage.usage)} จาก ${fmtBytes(storage.quota)}` : ""}
|
||||||
|
<br><button class="btn btn-ghost" type="button" style="min-height:34px;height:34px;font-size:11px;margin-top:8px" data-action="diagnostics">ข้อมูลอุปกรณ์และกล้อง</button>
|
||||||
|
<button class="btn btn-ghost" type="button" style="min-height:34px;height:34px;font-size:11px;margin-top:8px;margin-left:6px" data-action="show-qr">QR ลิงก์ทดสอบ</button>
|
||||||
|
</div>`;
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Gallery ──
|
||||||
|
export function renderGallery({ folder, images, thumbUrl }) {
|
||||||
|
const bytes = images.reduce((a, i) => a + (i.size || i.blob?.size || 0), 0);
|
||||||
|
let html = `<div class="gallery-view"><div class="section-head">
|
||||||
|
<div><h2>${esc(folder ? folder.name : "ยังไม่เลือกโฟลเดอร์")}</h2>
|
||||||
|
<div class="sub">${images.length} รูป · ${fmtBytes(bytes)}</div></div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
if (!folder) {
|
||||||
|
return html + `<div class="empty"><span class="ico">${ICON.folder}</span>เลือกโฟลเดอร์ก่อน</div></div>`;
|
||||||
|
}
|
||||||
|
if (!images.length) {
|
||||||
|
return html + `<div class="empty"><span class="ico">${ICON.image}</span>ยังไม่มีรูปในโฟลเดอร์นี้</div></div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
html += `<div class="gallery-grid">`;
|
||||||
|
images.forEach((img) => {
|
||||||
|
html += `<button class="gallery-item" type="button" data-action="open-photo" data-id="${esc(img.id)}">
|
||||||
|
<img src="${thumbUrl(img)}" alt="${esc(img.name || "")}" loading="lazy" decoding="async">
|
||||||
|
</button>`;
|
||||||
|
});
|
||||||
|
html += `</div>`;
|
||||||
|
|
||||||
|
html += `<div class="action-bar">
|
||||||
|
<button class="btn btn-ghost" type="button" data-action="zip-download">${ICON.zip} ZIP (${images.length})</button>
|
||||||
|
<button class="btn btn-primary" type="button" data-action="zip-share">${ICON.share} แชร์ ZIP</button>
|
||||||
|
</div>`;
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Photo sheet ──
|
||||||
|
export function photoSheet({ record, url, folderName }) {
|
||||||
|
const m = record.meta || {};
|
||||||
|
const rows = [
|
||||||
|
["ไฟล์", record.name || "-"],
|
||||||
|
["ขนาด", fmtBytes(record.size || record.blob?.size || 0)],
|
||||||
|
["ความละเอียด", m.width && m.height ? `${m.width} × ${m.height} (${(m.width * m.height / 1e6).toFixed(1)} MP)` : "—"],
|
||||||
|
["ถ่ายเมื่อ", humanDateTime(record.createdAt)],
|
||||||
|
["โฟลเดอร์", folderName || "-"],
|
||||||
|
["อุปกรณ์", m.device || "—"],
|
||||||
|
["กล้อง", m.facingLabel || "—"],
|
||||||
|
["ที่มาไฟล์", m.sourceLabel || "—"],
|
||||||
|
];
|
||||||
|
if (m.gps) rows.push(["พิกัด GPS", `${m.gps.lat.toFixed(6)}, ${m.gps.lng.toFixed(6)}${m.gps.accuracy ? ` (±${Math.round(m.gps.accuracy)} ม.)` : ""}`]);
|
||||||
|
if (m.exif && (m.exif.fNumber || m.exif.iso || m.exif.exposureTime)) rows.push(["ค่าแสง EXIF", formatExposure(m.exif)]);
|
||||||
|
if (m.exif?.model) {
|
||||||
|
const make = (m.exif.make || "").trim();
|
||||||
|
const model = m.exif.model.trim();
|
||||||
|
const label = make && !model.toLowerCase().startsWith(make.toLowerCase()) ? `${make} ${model}` : model;
|
||||||
|
rows.push(["รุ่นใน EXIF", label]);
|
||||||
|
}
|
||||||
|
if (m.exif?.orientation) rows.push(["Orientation", String(m.exif.orientation)]);
|
||||||
|
if (m.exif?.dateTimeOriginal) rows.push(["EXIF DateTimeOriginal", m.exif.dateTimeOriginal]);
|
||||||
|
|
||||||
|
const rowsHtml = rows
|
||||||
|
.map(([k, v]) => `<div class="row"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span></div>`)
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
return `
|
||||||
|
<h3>${esc(record.name || "รูปภาพ")}</h3>
|
||||||
|
<div class="hint">${esc(humanDateTime(record.createdAt))}</div>
|
||||||
|
<img class="preview" src="${url}" alt="">
|
||||||
|
<div class="meta-table">${rowsHtml}</div>
|
||||||
|
<div class="sheet-actions" style="margin-top:14px">
|
||||||
|
<button class="btn btn-ghost" type="button" data-action="close-sheet">ปิด</button>
|
||||||
|
<button class="btn btn-primary" type="button" data-action="share-photo" data-id="${esc(record.id)}">${ICON.share} แชร์รูปนี้</button>
|
||||||
|
</div>
|
||||||
|
<div class="sheet-actions" style="margin-top:8px">
|
||||||
|
<button class="btn btn-danger btn-block" type="button" data-action="delete-photo" data-id="${esc(record.id)}">${ICON.trash} ลบรูปนี้</button>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Folder sheet ──
|
||||||
|
export function folderSheet(mode, { id = "", name = "", suggested = "", count = 0 }) {
|
||||||
|
if (mode === "delete") {
|
||||||
|
return `<h3>ลบโฟลเดอร์นี้?</h3>
|
||||||
|
<div class="hint">"${esc(name)}" · ${count} รูป จะถูกลบทั้งหมดและกู้คืนไม่ได้</div>
|
||||||
|
<div class="sheet-actions">
|
||||||
|
<button class="btn btn-ghost" type="button" data-action="close-sheet">ยกเลิก</button>
|
||||||
|
<button class="btn btn-danger" type="button" data-action="confirm-delete-folder" data-id="${esc(id)}">ลบ</button>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
const isNew = mode === "new";
|
||||||
|
return `<h3>${isNew ? "โฟลเดอร์ใหม่" : "เปลี่ยนชื่อโฟลเดอร์"}</h3>
|
||||||
|
<div class="hint">ชื่อเริ่มต้นอิงวันที่ไทย (พ.ศ.) ของวันนี้ — แก้ไขได้</div>
|
||||||
|
<input id="folder-name-input" type="text" inputmode="text" autocomplete="off"
|
||||||
|
value="${esc(isNew ? suggested : name)}" placeholder="Site A 2569-10-24">
|
||||||
|
${isNew ? `<div class="hint" style="margin-top:-6px">ถ้าชื่อซ้ำ ระบบจะเติม (2) ให้อัตโนมัติ</div>` : ""}
|
||||||
|
<div class="sheet-actions">
|
||||||
|
<button class="btn btn-ghost" type="button" data-action="close-sheet">ยกเลิก</button>
|
||||||
|
<button class="btn btn-primary" type="button" data-action="${isNew ? "confirm-new-folder" : "confirm-rename-folder"}" data-id="${esc(id)}">
|
||||||
|
${isNew ? "สร้าง" : "บันทึก"}
|
||||||
|
</button>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── QR ลิงก์ทดสอบบนมือถือ ────────────────────────────
|
||||||
|
export function qrSheet(url) {
|
||||||
|
return `<h3>ทดสอบบนมือถือ</h3>
|
||||||
|
<div class="hint">สแกนด้วยกล้อง Samsung S23 แล้วเปิดใน Chrome</div>
|
||||||
|
<div class="qr-box"><div id="qr-holder"></div></div>
|
||||||
|
<div class="qr-url">${esc(url)}</div>
|
||||||
|
<div class="hint">กล้องใช้ได้เฉพาะหน้า HTTPS — ถ้าลิงก์ขึ้นต้น http:// กล้องจะถูกบล็อก</div>
|
||||||
|
<div class="sheet-actions">
|
||||||
|
<button class="btn btn-ghost" type="button" data-action="copy-url">คัดลอกลิงก์</button>
|
||||||
|
<button class="btn btn-primary" type="button" data-action="zip-share">${ICON.share} แชร์ ZIP</button>
|
||||||
|
</div></div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Diagnostics ──
|
||||||
|
export function diagnosticsSheet(rows) {
|
||||||
|
const body = rows
|
||||||
|
.map(([k, v]) => `<div class="row"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span></div>`)
|
||||||
|
.join("");
|
||||||
|
return `<h3>ข้อมูลอุปกรณ์และกล้อง</h3>
|
||||||
|
<div class="hint">ใช้ตรวจว่ารันบน S23 จริงและกล้องได้ความละเอียดเท่าไร</div>
|
||||||
|
<div class="meta-table">${body}</div>
|
||||||
|
<div class="sheet-actions" style="margin-top:14px">
|
||||||
|
<button class="btn btn-ghost btn-block" type="button" data-action="close-sheet">ปิด</button>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Progress ──
|
||||||
|
export function progressSheet(label) {
|
||||||
|
openSheet(`<div class="progress-card" id="progress-card">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<div class="label" id="progress-label">${esc(label)}</div>
|
||||||
|
</div>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function progressUpdate(pct, label) {
|
||||||
|
const card = document.getElementById("progress-card");
|
||||||
|
if (!card) return;
|
||||||
|
const p = Math.max(0, Math.min(100, Math.round(pct)));
|
||||||
|
card.innerHTML = `<div class="spinner"></div><div class="label">${esc(label || "")} ${p}%</div>`;
|
||||||
|
}
|
||||||
+25
-17
@@ -1,27 +1,35 @@
|
|||||||
{
|
{
|
||||||
"name": "Web Camera Category",
|
"id": "./",
|
||||||
|
"name": "CamCat — ถ่ายรูปแยกโฟลเดอร์",
|
||||||
"short_name": "CamCat",
|
"short_name": "CamCat",
|
||||||
"description": "Take photos, organize into folders, zip & share — Progressive Web App",
|
"description": "ถ่ายรูปด้วยกล้องมือถือ แยกโฟลเดอร์ตามไซต์ พร้อม EXIF/GPS, ZIP ทั้งโฟลเดอร์ และแชร์ผ่านระบบของเครื่อง",
|
||||||
"start_url": "/",
|
"start_url": "./",
|
||||||
|
"scope": "./",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
|
"display_override": ["standalone", "fullscreen"],
|
||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"background_color": "#0F172A",
|
"background_color": "#F2F3F5",
|
||||||
"theme_color": "#7C83FF",
|
"theme_color": "#F2F3F5",
|
||||||
|
"lang": "th",
|
||||||
|
"dir": "ltr",
|
||||||
|
"categories": ["photography", "productivity", "utilities"],
|
||||||
"icons": [
|
"icons": [
|
||||||
|
{ "src": "icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
|
||||||
|
{ "src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
|
||||||
|
{ "src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
|
||||||
|
],
|
||||||
|
"shortcuts": [
|
||||||
{
|
{
|
||||||
"src": "icon-192.png",
|
"name": "ถ่ายรูป",
|
||||||
"sizes": "192x192",
|
"short_name": "กล้อง",
|
||||||
"type": "image/png",
|
"url": "./?view=camera",
|
||||||
"purpose": "any maskable"
|
"icons": [{ "src": "icon-192.png", "sizes": "192x192" }]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "icon-512.png",
|
"name": "รูปในโฟลเดอร์",
|
||||||
"sizes": "512x512",
|
"short_name": "รูปภาพ",
|
||||||
"type": "image/png",
|
"url": "./?view=gallery",
|
||||||
"purpose": "any maskable"
|
"icons": [{ "src": "icon-192.png", "sizes": "192x192" }]
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"categories": ["photography", "utilities"],
|
|
||||||
"lang": "en",
|
|
||||||
"dir": "ltr"
|
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,77 @@
|
|||||||
// Service Worker — Web Camera Category PWA
|
// Service Worker — CamCat 2.0
|
||||||
// Caches app shell for offline use
|
// กลยุทธ์: navigation = network-first (ได้เวอร์ชันใหม่ก่อน) · asset = stale-while-revalidate
|
||||||
|
const CACHE = "camcat-v2.1.1";
|
||||||
|
|
||||||
const CACHE_NAME = "camcat-v1";
|
const ASSETS = [
|
||||||
const APP_SHELL = [
|
"./",
|
||||||
"/",
|
"./index.html",
|
||||||
"/index.html",
|
"./manifest.json",
|
||||||
"/manifest.json",
|
"./css/app.css",
|
||||||
"/icon-192.png",
|
"./js/config.js",
|
||||||
"/icon-512.png",
|
"./js/naming.js",
|
||||||
"https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js",
|
"./js/db.js",
|
||||||
|
"./js/exif.js",
|
||||||
|
"./js/device.js",
|
||||||
|
"./js/camera.js",
|
||||||
|
"./js/archive.js",
|
||||||
|
"./js/ui.js",
|
||||||
|
"./js/main.js",
|
||||||
|
"./vendor/jszip.min.js",
|
||||||
|
"./vendor/piexif.js",
|
||||||
|
"./vendor/qrcode.min.js",
|
||||||
|
"./icon-192.png",
|
||||||
|
"./icon-512.png",
|
||||||
];
|
];
|
||||||
|
|
||||||
// ── Install: cache app shell ──
|
|
||||||
self.addEventListener("install", (e) => {
|
self.addEventListener("install", (e) => {
|
||||||
e.waitUntil(
|
e.waitUntil(
|
||||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)).then(() => self.skipWaiting())
|
caches.open(CACHE)
|
||||||
|
.then((c) => Promise.allSettled(ASSETS.map((u) => c.add(new Request(u, { cache: "reload" })))))
|
||||||
|
.then(() => self.skipWaiting())
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Activate: clean old caches ──
|
|
||||||
self.addEventListener("activate", (e) => {
|
self.addEventListener("activate", (e) => {
|
||||||
e.waitUntil(
|
e.waitUntil(
|
||||||
caches.keys().then((keys) =>
|
caches.keys()
|
||||||
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
|
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
|
||||||
).then(() => self.clients.claim())
|
.then(() => self.clients.claim())
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Fetch: cache-first for app shell, network-first for photos ──
|
|
||||||
self.addEventListener("fetch", (e) => {
|
self.addEventListener("fetch", (e) => {
|
||||||
const url = new URL(e.request.url);
|
const req = e.request;
|
||||||
// Don't intercept non-GET
|
if (req.method !== "GET") return;
|
||||||
if (e.request.method !== "GET") return;
|
const url = new URL(req.url);
|
||||||
// Cache-first for same-origin
|
if (url.origin !== self.location.origin) return;
|
||||||
if (url.origin === self.location.origin) {
|
|
||||||
|
// หน้าเว็บ: เอาจากเครือข่ายก่อน ถ้าออฟไลน์ค่อยใช้แคช
|
||||||
|
if (req.mode === "navigate") {
|
||||||
e.respondWith(
|
e.respondWith(
|
||||||
caches.match(e.request).then((cached) => cached || fetch(e.request).then((resp) => {
|
fetch(req)
|
||||||
const clone = resp.clone();
|
.then((resp) => {
|
||||||
caches.open(CACHE_NAME).then((c) => c.put(e.request, clone));
|
const clone = resp.clone();
|
||||||
return resp;
|
caches.open(CACHE).then((c) => c.put(req, clone));
|
||||||
}).catch(() => caches.match("/index.html")))
|
return resp;
|
||||||
|
})
|
||||||
|
.catch(() => caches.match(req).then((r) => r || caches.match("./index.html")))
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ไฟล์อื่น: คืนแคชทันที + อัปเดตเบื้องหลัง
|
||||||
|
e.respondWith(
|
||||||
|
caches.match(req).then((cached) => {
|
||||||
|
const network = fetch(req)
|
||||||
|
.then((resp) => {
|
||||||
|
if (resp && resp.ok) {
|
||||||
|
const clone = resp.clone();
|
||||||
|
caches.open(CACHE).then((c) => c.put(req, clone));
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
})
|
||||||
|
.catch(() => cached);
|
||||||
|
return cached || network;
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
/*!
|
||||||
|
|
||||||
|
JSZip v3.10.1 - A JavaScript class for generating and reading zip files
|
||||||
|
<http://stuartk.com/jszip>
|
||||||
|
|
||||||
|
(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
|
||||||
|
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/main/LICENSE.markdown.
|
||||||
|
|
||||||
|
JSZip uses the library pako released under the MIT license :
|
||||||
|
https://github.com/nodeca/pako/blob/main/LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
|
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JSZip=e()}}(function(){return function s(a,o,h){function u(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(l)return l(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=o[r]={exports:{}};a[r][0].call(i.exports,function(e){var t=a[r][1][e];return u(t||e)},i,i.exports,s,a,o,h)}return o[r].exports}for(var l="function"==typeof require&&require,e=0;e<h.length;e++)u(h[e]);return u}({1:[function(e,t,r){"use strict";var d=e("./utils"),c=e("./support"),p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(e){for(var t,r,n,i,s,a,o,h=[],u=0,l=e.length,f=l,c="string"!==d.getTypeOf(e);u<e.length;)f=l-u,n=c?(t=e[u++],r=u<l?e[u++]:0,u<l?e[u++]:0):(t=e.charCodeAt(u++),r=u<l?e.charCodeAt(u++):0,u<l?e.charCodeAt(u++):0),i=t>>2,s=(3&t)<<4|r>>4,a=1<f?(15&r)<<2|n>>6:64,o=2<f?63&n:64,h.push(p.charAt(i)+p.charAt(s)+p.charAt(a)+p.charAt(o));return h.join("")},r.decode=function(e){var t,r,n,i,s,a,o=0,h=0,u="data:";if(e.substr(0,u.length)===u)throw new Error("Invalid base64 input, it looks like a data url.");var l,f=3*(e=e.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(e.charAt(e.length-1)===p.charAt(64)&&f--,e.charAt(e.length-2)===p.charAt(64)&&f--,f%1!=0)throw new Error("Invalid base64 input, bad content length.");for(l=c.uint8array?new Uint8Array(0|f):new Array(0|f);o<e.length;)t=p.indexOf(e.charAt(o++))<<2|(i=p.indexOf(e.charAt(o++)))>>4,r=(15&i)<<4|(s=p.indexOf(e.charAt(o++)))>>2,n=(3&s)<<6|(a=p.indexOf(e.charAt(o++))),l[h++]=t,64!==s&&(l[h++]=r),64!==a&&(l[h++]=n);return l}},{"./support":30,"./utils":32}],2:[function(e,t,r){"use strict";var n=e("./external"),i=e("./stream/DataWorker"),s=e("./stream/Crc32Probe"),a=e("./stream/DataLengthProbe");function o(e,t,r,n,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=r,this.compression=n,this.compressedContent=i}o.prototype={getContentWorker:function(){var e=new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),t=this;return e.on("end",function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),e},getCompressedWorker:function(){return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},o.createWorkerFrom=function(e,t,r){return e.pipe(new s).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression",t)},t.exports=o},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,r){"use strict";var n=e("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new n("STORE compression")},uncompressWorker:function(){return new n("STORE decompression")}},r.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,r){"use strict";var n=e("./utils");var o=function(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t}();t.exports=function(e,t){return void 0!==e&&e.length?"string"!==n.getTypeOf(e)?function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a<s;a++)e=e>>>8^i[255&(e^t[a])];return-1^e}(0|t,e,e.length,0):function(e,t,r,n){var i=o,s=n+r;e^=-1;for(var a=n;a<s;a++)e=e>>>8^i[255&(e^t.charCodeAt(a))];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,r){"use strict";r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(e,t,r){"use strict";var n=null;n="undefined"!=typeof Promise?Promise:e("lie"),t.exports={Promise:n}},{lie:37}],7:[function(e,t,r){"use strict";var n="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=e("pako"),s=e("./utils"),a=e("./stream/GenericWorker"),o=n?"uint8array":"array";function h(e,t){a.call(this,"FlateWorker/"+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}r.magic="\b\0",s.inherits(h,a),h.prototype.processChunk=function(e){this.meta=e.meta,null===this._pako&&this._createPako(),this._pako.push(s.transformTo(o,e.data),!1)},h.prototype.flush=function(){a.prototype.flush.call(this),null===this._pako&&this._createPako(),this._pako.push([],!0)},h.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this._pako=null},h.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var t=this;this._pako.onData=function(Line truncated
|
||||||
Vendored
+2482
File diff suppressed because it is too large.
Load diff
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this.parsedData=[];for(var b=[],d=0,e=this.data.length;e>d;d++){var f=this.data.charCodeAt(d);f>65536?(b[0]=240|(1835008&f)>>>18,b[1]=128|(258048&f)>>>12,b[2]=128|(4032&f)>>>6,b[3]=128|63&f):f>2048?(b[0]=224|(61440&f)>>>12,b[1]=128|(4032&f)>>>6,b[2]=128|63&f):f>128?(b[0]=192|(1984&f)>>>6,b[1]=128|63&f):b[0]=f,this.parsedData=this.parsedData.concat(b)}this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(a,b){this.typeNumber=a,this.errorCorrectLevel=b,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function i(a,b){if(void 0==a.length)throw new Error(a.length+"/"+b);for(var c=0;c<a.length&&0==a[c];)c++;this.num=new Array(a.length-c+b);for(var d=0;d<a.length-c;d++)this.num[d]=a[d+c]}function j(a,b){this.totalCount=a,this.dataCount=b}function k(){this.buffer=[],this.length=0}function m(){return"undefined"!=typeof CanvasRenderingContext2D}function n(){var a=!1,b=navigator.userAgent;return/android/i.test(b)&&(a=!0,aMat=b.toString().match(/android ([0-9]\.[0-9])/i),aMat&&aMat[1]&&(a=parseFloat(aMat[1]))),a}function r(a,b){for(var c=1,e=s(a),f=0,g=l.length;g>=f;f++){var h=0;switch(b){case d.L:h=l[f][0];break;case d.M:h=l[f][1];break;case d.Q:h=l[f][2];break;case d.H:h=l[f][3]}if(h>=e)break;c++}if(c>l.length)throw new Error("Too long data");return c}function s(a){var b=encodeURI(a).toString().replace(/\%[0-9a-fA-F]{2}/g,"a");return b.length+(b.length!=a?3:0)}a.prototype={getLength:function(){return this.parsedData.length},write:function(a){for(var b=0,c=this.parsedData.length;c>b;b++)a.put(this.parsedData[b],8)}},b.prototype={addData:function(b){var c=new a(b);this.dataList.push(c),this.dataCache=null},isDark:function(a,b){if(0>a||this.moduleCount<=a||0>b||this.moduleCount<=b)throw new Error(a+","+b);return this.modules[a][b]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var d=0;d<this.moduleCount;d++){this.modules[d]=new Array(this.moduleCount);for(var e=0;e<this.moduleCount;e++)this.modules[d][e]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(a,c),this.typeNumber>=7&&this.setupTypeNumber(a),null==this.dataCache&&(this.dataCache=b.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,b){for(var c=-1;7>=c;c++)if(!(-1>=a+c||this.moduleCount<=a+c))for(var d=-1;7>=d;d++)-1>=b+d||this.moduleCount<=b+d||(this.modules[a+c][b+d]=c>=0&&6>=c&&(0==d||6==d)||d>=0&&6>=d&&(0==c||6==c)||c>=2&&4>=c&&d>=2&&4>=d?!0:!1)},getBestMaskPattern:function(){for(var a=0,b=0,c=0;8>c;c++){this.makeImpl(!0,c);var d=f.getLostPoint(this);(0==c||a>d)&&(a=d,b=c)}return b},createMovieClip:function(a,b,c){var d=a.createEmptyMovieClip(b,c),e=1;this.make();for(var f=0;f<this.modules.length;f++)for(var g=f*e,h=0;h<this.modules[f].length;h++){var i=h*e,j=this.modules[f][h];j&&(d.beginFill(0,100),d.moveTo(i,g),d.lineTo(i+e,g),d.lineTo(i+e,g+e),d.lineTo(i,g+e),d.endFill())}return d},setupTimingPattern:function(){for(var a=8;a<this.moduleCount-8;a++)null==this.modules[a][6]&&(this.modules[a][6]=0==a%2);for(var b=8;b<this.moduleCount-8;b++)null==this.modules[6][b]&&(this.modules[6][b]=0==b%2)},setupPositionAdjustPattern:function(){for(var a=f.getPatternPosition(this.typeNumber),b=0;b<a.length;b++)for(var c=0;c<a.length;c++){var d=a[b],e=a[c];if(null==this.modules[d][e])for(var g=-2;2>=g;g++)for(var h=-2;2>=h;h++)this.modules[d+g][e+h]=-2==g||2==g||-2==h||2==h||0==g&&0==h?!0:!1}},setupTypeNumber:function(a){for(var b=f.getBCHTypeNumber(this.typeNumber),c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[Math.floor(c/3)][c%3+this.moduleCount-8-3]=d}for(var c=0;18>c;c++){var d=!a&&1==(1&b>>c);this.modules[c%3+this.moduleCount-8-3][Math.floor(c/3)]=d}},setupTypeInfo:function(a,b){for(var c=this.errorCorrectLevel<<3|b,d=f.getBCHTypeInfo(c),e=0;15>e;e++){var g=!a&&1==(1&d>>e);6>e?this.modules[e][8]=g:8>e?this.modules[e+1][8]=g:this.modules[this.moduleCount-15+e][8]=g}for(var e=0;15>e;e++){var g=!a&&1==(1&d>>e);8>e?this.modules[8][this.moduleCount-e-1]=g:9>e?this.modules[8][15-e-1+1]=g:this.modules[8][15-e-1]=g}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,b){for(var c=-1,d=this.moduleCount-1,e=7,g=0,h=this.moduleCount-1;h>0;h-=2)for(6==h&&h--;;){for(var i=0;2>i;i++)if(null==this.modules[d][h-i]){var j=!1;g<a.length&&(j=1==(1&a[g]>>>e));var k=f.getMask(b,d,h-i);k&&(j=!j),this.modules[d][h-i]=j,e--,-1==e&&(g++,e=7)}if(d+=c,0>d||this.moduleCount<=d){d-=c,c=-c;break}}}},b.PAD0=236,b.PAD1=17,b.createData=function(a,c,d){for(var e=j.getRSBlocks(a,cLine truncated
|
||||||
Reference in new issue
Block a user