feat: initial project structure webapp
This commit is contained in:
commit
7a39f96256
8 files changed
+858
No files matched your search
@@ -0,0 +1,57 @@
|
||||
# CamCat — Web Camera Category PWA
|
||||
|
||||
Progressive Web App สำหรับถ่ายรูป จัดหมวดใน folder และแชร์เป็น zip
|
||||
|
||||
## Features
|
||||
|
||||
- 📷 ถ่ายรูปจากกล้อง (front/back switch)
|
||||
- 📁 สร้าง/แก้ชื่อ/ลบ folder
|
||||
- 🖼️ Gallery view พร้อมเลือกหลายรูป
|
||||
- 📦 Zip รูปที่เลือกเป็น .zip
|
||||
- 📤 Share ผ่าน Web Share API (หรือ download fallback)
|
||||
- 📊 EXIF data (camera model, date, GPS, ISO, aperture)
|
||||
- 💾 Offline storage (IndexedDB + Service Worker)
|
||||
- 📱 Installable PWA (Add to Home Screen)
|
||||
|
||||
## Install on Mobile
|
||||
|
||||
### Option 1: Serve locally
|
||||
```bash
|
||||
cd app
|
||||
python3 -m http.server 8080
|
||||
# บนมือถือเปิด: http://<IP>:8080
|
||||
```
|
||||
|
||||
### 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
|
||||
|
||||
```
|
||||
app/
|
||||
├── index.html # UI shell
|
||||
├── app.js # App logic (camera, folders, zip, share, EXIF)
|
||||
├── sw.js # Service Worker (offline cache)
|
||||
├── manifest.json # PWA manifest
|
||||
├── icon-192.png # App icon 192x192
|
||||
└── icon-512.png # App icon 512x512
|
||||
```
|
||||
|
||||
## Browser Support
|
||||
|
||||
- Chrome/Edge 90+ (full)
|
||||
- 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
@@ -0,0 +1,524 @@
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// 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);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
+203
@@ -0,0 +1,203 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<meta name="theme-color" content="#7C83FF">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<link rel="manifest" href="manifest.json">
|
||||
<link rel="icon" href="icon-192.png">
|
||||
<link rel="apple-touch-icon" href="icon-192.png">
|
||||
<title>CamCat — Camera Folder Organizer</title>
|
||||
<style>
|
||||
: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>
|
||||
<body>
|
||||
<div id="app">
|
||||
<header>
|
||||
<h1>📷 CamCat</h1>
|
||||
<div class="folder-pill" id="active-folder-pill">📁 Default</div>
|
||||
</header>
|
||||
|
||||
<main id="main"></main>
|
||||
|
||||
<nav>
|
||||
<button id="nav-camera" class="active" onclick="navigate('camera')">
|
||||
<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>
|
||||
Camera
|
||||
</button>
|
||||
<button id="nav-folders" onclick="navigate('folders')">
|
||||
<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>
|
||||
Folders
|
||||
</button>
|
||||
<button id="nav-gallery" onclick="navigate('gallery')">
|
||||
<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>
|
||||
Gallery
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal-overlay" id="modal-overlay">
|
||||
<div class="modal" id="modal-content"></div>
|
||||
</div>
|
||||
|
||||
<!-- Toast -->
|
||||
<div id="toast"></div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "Web Camera Category",
|
||||
"short_name": "CamCat",
|
||||
"description": "Take photos, organize into folders, zip & share — Progressive Web App",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait",
|
||||
"background_color": "#0F172A",
|
||||
"theme_color": "#7C83FF",
|
||||
"icons": [
|
||||
{
|
||||
"src": "icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "any maskable"
|
||||
},
|
||||
{
|
||||
"src": "icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any maskable"
|
||||
}
|
||||
],
|
||||
"categories": ["photography", "utilities"],
|
||||
"lang": "en",
|
||||
"dir": "ltr"
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Service Worker — Web Camera Category PWA
|
||||
// Caches app shell for offline use
|
||||
|
||||
const CACHE_NAME = "camcat-v1";
|
||||
const APP_SHELL = [
|
||||
"/",
|
||||
"/index.html",
|
||||
"/manifest.json",
|
||||
"/icon-192.png",
|
||||
"/icon-512.png",
|
||||
"https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js",
|
||||
];
|
||||
|
||||
// ── Install: cache app shell ──
|
||||
self.addEventListener("install", (e) => {
|
||||
e.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)).then(() => self.skipWaiting())
|
||||
);
|
||||
});
|
||||
|
||||
// ── Activate: clean old caches ──
|
||||
self.addEventListener("activate", (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) =>
|
||||
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
|
||||
).then(() => self.clients.claim())
|
||||
);
|
||||
});
|
||||
|
||||
// ── Fetch: cache-first for app shell, network-first for photos ──
|
||||
self.addEventListener("fetch", (e) => {
|
||||
const url = new URL(e.request.url);
|
||||
// Don't intercept non-GET
|
||||
if (e.request.method !== "GET") return;
|
||||
// Cache-first for same-origin
|
||||
if (url.origin === self.location.origin) {
|
||||
e.respondWith(
|
||||
caches.match(e.request).then((cached) => cached || fetch(e.request).then((resp) => {
|
||||
const clone = resp.clone();
|
||||
caches.open(CACHE_NAME).then((c) => c.put(e.request, clone));
|
||||
return resp;
|
||||
}).catch(() => caches.match("/index.html")))
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user