commit d29db4536fda94422b08e6f59bb013fc61c7c4e6 Author: Hardwell99 <3022256519@qq.com> Date: Tue Dec 1 15:23:42 2026 +0800 first commit diff --git a/assets/img/image_1793460848264.jpg b/assets/img/image_1793460848264.jpg new file mode 100644 index 0000000..147e029 Binary files /dev/null and b/assets/img/image_1793460848264.jpg differ diff --git a/assets/img/image_1793460860160.jpg b/assets/img/image_1793460860160.jpg new file mode 100644 index 0000000..acc79c0 Binary files /dev/null and b/assets/img/image_1793460860160.jpg differ diff --git a/assets/img/img-1793461002823ced2d91c9da728bb542c2bc058558b4408aa157643495cf5506880ad5df47bb4.jpg b/assets/img/img-1793461002823ced2d91c9da728bb542c2bc058558b4408aa157643495cf5506880ad5df47bb4.jpg new file mode 100644 index 0000000..61aa1be Binary files /dev/null and b/assets/img/img-1793461002823ced2d91c9da728bb542c2bc058558b4408aa157643495cf5506880ad5df47bb4.jpg differ diff --git a/assets/img/img-179346101086003d303cdf2070b49e746a3dc977b85eddaf5cc9c263ec36782c8159e42225393.jpg b/assets/img/img-179346101086003d303cdf2070b49e746a3dc977b85eddaf5cc9c263ec36782c8159e42225393.jpg new file mode 100644 index 0000000..ed35b73 Binary files /dev/null and b/assets/img/img-179346101086003d303cdf2070b49e746a3dc977b85eddaf5cc9c263ec36782c8159e42225393.jpg differ diff --git a/assets/img/img-1793461014140ea2625d5252d11546fac841dfee9d62866f39afd60b4a1a0d89dc51cfae39b39.jpg b/assets/img/img-1793461014140ea2625d5252d11546fac841dfee9d62866f39afd60b4a1a0d89dc51cfae39b39.jpg new file mode 100644 index 0000000..d681a3a Binary files /dev/null and b/assets/img/img-1793461014140ea2625d5252d11546fac841dfee9d62866f39afd60b4a1a0d89dc51cfae39b39.jpg differ diff --git a/assets/img/img-1793461022627f07484dd63b425f2bb137de3762d9d55d01133e3056d43b7a1d0e7b2d05295e8.jpg b/assets/img/img-1793461022627f07484dd63b425f2bb137de3762d9d55d01133e3056d43b7a1d0e7b2d05295e8.jpg new file mode 100644 index 0000000..51b6210 Binary files /dev/null and b/assets/img/img-1793461022627f07484dd63b425f2bb137de3762d9d55d01133e3056d43b7a1d0e7b2d05295e8.jpg differ diff --git a/assets/img/img-1793461026364d156fea2ecf33d42e1f26ce6f36efdf1ba14f6ea64e86fc314ff3989fc3911ac.jpg b/assets/img/img-1793461026364d156fea2ecf33d42e1f26ce6f36efdf1ba14f6ea64e86fc314ff3989fc3911ac.jpg new file mode 100644 index 0000000..2909f66 Binary files /dev/null and b/assets/img/img-1793461026364d156fea2ecf33d42e1f26ce6f36efdf1ba14f6ea64e86fc314ff3989fc3911ac.jpg differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..ff6b050 --- /dev/null +++ b/index.html @@ -0,0 +1,92 @@ + + + + + + + + Jisoo Showcase + + + + + + + +
+ + + + + + + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..76e6582 --- /dev/null +++ b/script.js @@ -0,0 +1,238 @@ +(() => { + "use strict"; + + /* PHOTOS:START */ + const photos = [ + { src: "assets/img/image_1793460848264.jpg" }, + { src: "assets/img/image_1793460860160.jpg" }, + { src: "assets/img/img-1793461002823ced2d91c9da728bb542c2bc058558b4408aa157643495cf5506880ad5df47bb4.jpg" }, + { src: "assets/img/img-179346101086003d303cdf2070b49e746a3dc977b85eddaf5cc9c263ec36782c8159e42225393.jpg" }, + { src: "assets/img/img-1793461014140ea2625d5252d11546fac841dfee9d62866f39afd60b4a1a0d89dc51cfae39b39.jpg" }, + { src: "assets/img/img-1793461022627f07484dd63b425f2bb137de3762d9d55d01133e3056d43b7a1d0e7b2d05295e8.jpg" }, + { src: "assets/img/img-1793461026364d156fea2ecf33d42e1f26ce6f36efdf1ba14f6ea64e86fc314ff3989fc3911ac.jpg" } + ]; + /* PHOTOS:END */ + + const gallery = document.getElementById("gallery"); + if (!gallery || !photos.length) return; + + const nameOf = (src) => src.split("/").pop() || src; + let activeIndex = -1; + let cardWidth = 168; + let cardGap = 20; + + /* 列宽上限随照片数量与间距动态计算,避免固定 6 列假设 */ + const fitCard = () => `min(var(--card-width), calc((100vw - ${photos.length - 1} * var(--gap)) / ${photos.length}))`; + + function renderColumns() { + const base = fitCard(); + gallery.style.gridTemplateColumns = photos + .map((_, i) => (i === activeIndex + ? `min(calc(${base} * 2.4), 52vw)` + : base)) + .join(" "); + } + + const boxes = photos.map((photo, index) => { + const box = document.createElement("div"); + box.className = "box"; + box.style.setProperty("--img", `url("${photo.src}")`); + box.style.setProperty("--delay", `${Math.min(index, 12) * 60}ms`); + box.style.setProperty("--stagger", "0px"); + box.tabIndex = 0; + box.setAttribute("role", "img"); + box.setAttribute("aria-label", nameOf(photo.src)); + + const activate = () => { + if (activeIndex === index) return; + activeIndex = index; + boxes.forEach((item, i) => item.classList.toggle("is-active", i === index)); + renderColumns(); + }; + + box.addEventListener("mouseenter", activate); + box.addEventListener("focus", activate); + box.addEventListener("click", activate); + gallery.append(box); + return box; + }); + + /* ---------- Settings panel ---------- */ + + const toggle = document.getElementById("settings-toggle"); + const panel = document.getElementById("settings-panel"); + const close = document.getElementById("settings-close"); + const card = document.getElementById("range-card"); + const height = document.getElementById("range-height"); + const gap = document.getElementById("range-gap"); + const duration = document.getElementById("range-duration"); + const stagger = document.getElementById("range-stagger"); + const cardValue = document.getElementById("value-card"); + const heightValue = document.getElementById("value-height"); + const gapValue = document.getElementById("value-gap"); + const durationValue = document.getElementById("value-duration"); + const staggerValue = document.getElementById("value-stagger"); + const swatches = document.getElementById("swatches"); + const shapePicker = document.getElementById("shape-picker"); + + function setPanel(open) { + panel?.classList.toggle("is-open", open); + panel?.setAttribute("aria-hidden", String(!open)); + toggle?.setAttribute("aria-expanded", String(open)); + } + toggle?.addEventListener("click", () => setPanel(!panel?.classList.contains("is-open"))); + close?.addEventListener("click", () => setPanel(false)); + document.addEventListener("keydown", (event) => { + if (event.key === "Escape" && panel?.classList.contains("is-open")) setPanel(false); + }); + + const THEMES = { + default: { a: "#08060f", b: "#6366f1", c: "#d946ef" }, + violet: { a: "#8357eb", b: "#6a3de0", c: "#a86ff5" }, + space: { a: "#0d0b1e", b: "#1b1440", c: "#2a1d52" }, + teal: { a: "#062a30", b: "#0a3d40", c: "#0e5560" }, + sand: { a: "#f3e2c7", b: "#f7d9a8", c: "#e8b98a" }, + black: { a: "#050507", b: "#101018", c: "#16161f" } + }; + const THEME_LABELS = { + default: "默认", violet: "violet", space: "space", + teal: "teal", sand: "sand", black: "black" + }; + + const hexToRgb = (hex) => { + const raw = hex.replace("#", ""); + const full = raw.length === 3 ? raw.split("").map((ch) => ch + ch).join("") : raw; + return `${parseInt(full.slice(0, 2), 16)}, ${parseInt(full.slice(2, 4), 16)}, ${parseInt(full.slice(4, 6), 16)}`; + }; + + function applyTheme(name) { + const theme = THEMES[name] || THEMES.default; + const root = document.documentElement.style; + root.setProperty("--bg", theme.a); + root.setProperty("--glow-a", hexToRgb(theme.b)); + root.setProperty("--glow-b", hexToRgb(theme.c)); + if (swatches) { + swatches.querySelectorAll(".swatch").forEach((item) => { + const active = item.dataset.theme === name; + item.classList.toggle("is-active", active); + item.setAttribute("aria-pressed", String(active)); + }); + } + } + + if (swatches) { + Object.entries(THEMES).forEach(([name, theme]) => { + const button = document.createElement("button"); + button.type = "button"; + button.className = "swatch"; + button.dataset.theme = name; + button.setAttribute("aria-label", `背景:${THEME_LABELS[name]}`); + button.setAttribute("aria-pressed", "false"); + const dot = document.createElement("span"); + dot.className = "swatch-dot"; + dot.style.background = `linear-gradient(135deg, ${theme.a} 0 33%, ${theme.b} 33% 66%, ${theme.c} 66% 100%)`; + const label = document.createElement("span"); + label.className = "swatch-label"; + label.textContent = THEME_LABELS[name]; + button.append(dot, label); + button.addEventListener("click", () => applyTheme(name)); + swatches.append(button); + }); + } + + const SHAPES = [ + { + name: "parallelogram", + label: "平行四边形", + path: "M5 4h15l-5 16H0z" + }, + { + name: "quad", + label: "四边形", + path: "M2 3h16v18H2z" + }, + { + name: "hexagon", + label: "六边形", + path: "M9 1h4l5 6v10l-5 6H4l-5-6V7z" + } + ]; + + function applyShape(name) { + gallery.dataset.shape = name; + if (!shapePicker) return; + shapePicker.querySelectorAll(".shape-chip").forEach((item) => { + const active = item.dataset.shape === name; + item.classList.toggle("is-active", active); + item.setAttribute("aria-pressed", String(active)); + }); + } + + if (shapePicker) { + SHAPES.forEach((shape) => { + const button = document.createElement("button"); + button.type = "button"; + button.className = "shape-chip"; + button.dataset.shape = shape.name; + button.setAttribute("aria-label", `卡片形状:${shape.label}`); + button.setAttribute("aria-pressed", "false"); + const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg"); + icon.setAttribute("viewBox", "0 0 20 24"); + icon.setAttribute("aria-hidden", "true"); + const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); + path.setAttribute("d", shape.path); + icon.append(path); + const label = document.createElement("span"); + label.textContent = shape.label; + button.append(icon, label); + button.addEventListener("click", () => applyShape(shape.name)); + shapePicker.append(button); + }); + } + + function applyCard() { + cardWidth = Number(card?.value ?? 200); + gallery.style.setProperty("--card-width", `${cardWidth}px`); + renderColumns(); + if (cardValue) cardValue.textContent = `${cardWidth}px`; + } + function applyHeight() { + const value = Number(height?.value ?? 660); + gallery.style.setProperty("--card-height", `${value}px`); + if (heightValue) heightValue.textContent = `${value}px`; + } + function applyGap() { + cardGap = Number(gap?.value ?? 20); + gallery.style.setProperty("--gap", `${cardGap}px`); + renderColumns(); + if (gapValue) gapValue.textContent = `${cardGap}px`; + } + function applyDuration() { + const value = Number(duration?.value ?? 960); + document.documentElement.style.setProperty("--duration", `${value}ms`); + if (durationValue) durationValue.textContent = `${value}ms`; + } + function applyStagger() { + const value = Number(stagger?.value ?? 0); + boxes.forEach((box, index) => { + const up = index % 2 === 0; + box.style.setProperty("--stagger", `${(up ? -1 : 1) * value}px`); + /* 向上偏移的卡片向左倾,向下偏移的卡片保持向右倾 */ + box.classList.toggle("tilt-left", up); + }); + if (staggerValue) staggerValue.textContent = `${value}px`; + } + + card?.addEventListener("input", applyCard); + height?.addEventListener("input", applyHeight); + gap?.addEventListener("input", applyGap); + duration?.addEventListener("input", applyDuration); + stagger?.addEventListener("input", applyStagger); + applyCard(); + applyHeight(); + applyGap(); + applyDuration(); + applyStagger(); + applyShape("hexagon"); + applyTheme("default"); +})(); diff --git a/style.css b/style.css new file mode 100644 index 0000000..8794189 --- /dev/null +++ b/style.css @@ -0,0 +1,347 @@ +/* ============================================================ + Jisoo Showcase — 纯人物图片画廊 + 默认全灰 · hover 展开并恢复彩色 · 最后 hover 的保持展开 + 缓动:非线性 cubic-bezier + ============================================================ */ + +:root { + --bg: #08060f; + --glow-a: 99, 102, 241; + --glow-b: 217, 70, 239; + --violet: #8b5cf6; + --magenta: #d946ef; + --indigo: #6366f1; + --gradient: linear-gradient(120deg, var(--indigo), var(--violet) 52%, var(--magenta)); + --line: rgba(167, 139, 250, 0.16); + --surface: rgba(22, 17, 38, 0.86); + --muted: #9b92b8; + --ease: cubic-bezier(0.16, 1, 0.3, 1); + --skew: 56px; + --card-width: 168px; + --card-height: 660px; + --gap: 12px; + --duration: 960ms; +} + +* { box-sizing: border-box; margin: 0; padding: 0; } + +body { + display: grid; + place-content: center; + min-height: 100vh; + padding: 48px 24px; + background: + radial-gradient(920px 600px at 12% -8%, rgba(var(--glow-a), 0.18), transparent 62%), + radial-gradient(760px 560px at 96% 4%, rgba(var(--glow-b), 0.12), transparent 60%), + var(--bg); + transition: background-color 620ms var(--ease); + overflow-x: hidden; +} + +.ambient { + position: fixed; + width: 440px; + height: 440px; + border-radius: 50%; + filter: blur(130px); + pointer-events: none; + z-index: 0; +} +.ambient-a { top: -140px; left: -120px; background: rgb(var(--glow-a)); opacity: 0.18; } +.ambient-b { bottom: -200px; right: -120px; background: rgb(var(--glow-b)); opacity: 0.12; } + +.gallery { + position: relative; + z-index: 1; + display: grid; + grid-template-columns: repeat(6, min(var(--card-width), calc((100vw - 5 * var(--gap)) / 6))); + justify-content: center; + gap: var(--gap); + --skew: 52px; + width: 94vw; + height: var(--card-height); + transition: + grid-template-columns var(--duration) var(--ease), + width var(--duration) var(--ease), + height var(--duration) var(--ease); +} + +.box { + position: relative; + min-width: 0; + background-image: var(--img), linear-gradient(160deg, #1b1533, #100c1e); + background-size: cover, cover; + background-repeat: no-repeat, no-repeat; + /* 默认焦点居中;展开时上移到人物头部,见 .box.is-active */ + background-position: center 50%, center center; + filter: grayscale(100%) opacity(38%) drop-shadow(0 16px 28px rgba(0, 0, 0, 0.5)); + cursor: pointer; + outline: none; + transition: + filter var(--duration) var(--ease), + transform var(--duration) var(--ease), + background-position var(--duration) var(--ease); + animation: box-in var(--duration) var(--ease) both; + animation-delay: var(--delay, 0ms); +} +@keyframes box-in { from { opacity: 0; transform: translateY(20px); } } + +.box { transform: translateY(var(--stagger, 0px)); } + +/* ---------- Card shapes ---------- */ +/* 默认:平行四边形。左右边垂直,上下边倾斜;--skew-a/b 决定倾斜方向 */ +.gallery[data-shape="parallelogram"] .box, +.gallery:not([data-shape]) .box { + --skew-a: var(--skew); + --skew-b: 0px; + clip-path: polygon(0 var(--skew-a), 100% var(--skew-b), 100% calc(100% - var(--skew-a)), 0 calc(100% - var(--skew-b))); +} +/* 向上偏移的卡片翻转斜切方向:向左倾 */ +.gallery[data-shape="parallelogram"] .box.tilt-left, +.gallery:not([data-shape]) .box.tilt-left { + --skew-a: 0px; + --skew-b: var(--skew); +} + +/* 四边形:规则矩形,四条边横平竖直 */ +.gallery[data-shape="quad"] .box { + clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); +} + +/* 六边形:顶部与底部各一个尖角,左右两侧为垂直边 */ +.gallery[data-shape="hexagon"] .box { + clip-path: polygon( + 50% 0, 100% var(--skew), + 100% calc(100% - var(--skew)), 50% 100%, + 0 calc(100% - var(--skew)), 0 var(--skew) + ); +} + +.box.is-active { + /* 焦点上移到人物头部,与列宽变化同步过渡 */ + background-position: center 12%, center center; + filter: grayscale(0%) opacity(100%) + drop-shadow(0 0 12px rgba(167, 139, 250, 0.55)) + drop-shadow(0 22px 48px rgba(124, 58, 237, 0.4)); +} + +/* ---------- Settings ---------- */ + +.settings-toggle { + position: fixed; + right: 26px; + top: 50%; + transform: translateY(-50%); + z-index: 20; + width: 36px; + height: 36px; + display: grid; + place-items: center; + border-radius: 11px; + border: 1px solid rgba(167, 139, 250, 0.14); + background: rgba(22, 17, 38, 0.34); + backdrop-filter: blur(6px); + -webkit-backdrop-filter: blur(6px); + color: rgba(205, 191, 240, 0.34); + cursor: pointer; + box-shadow: none; + transition: color 320ms var(--ease), border-color 320ms var(--ease), background 320ms var(--ease), box-shadow 320ms var(--ease), transform 320ms var(--ease); +} +.settings-toggle svg { + width: 17px; + height: 17px; + fill: none; + stroke: currentColor; + stroke-width: 1.6; + stroke-linecap: round; + stroke-linejoin: round; +} +.settings-toggle:hover, .settings-toggle[aria-expanded="true"] { + color: #fff; + border-color: rgba(167, 139, 250, 0.5); + background: rgba(22, 17, 38, 0.88); + box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 16px rgba(139, 92, 246, 0.28); +} +.settings-toggle[aria-expanded="true"] svg { transform: rotate(60deg); } +.settings-toggle svg { transition: transform 420ms var(--ease); } + +.settings-panel { + position: fixed; + right: 92px; + top: 50%; + transform: translate(16px, -50%); + z-index: 20; + width: 300px; + padding: 22px 22px 26px; + border-radius: 22px; + border: 1px solid rgba(167, 139, 250, 0.32); + background: rgba(18, 14, 32, 0.92); + backdrop-filter: blur(18px); + -webkit-backdrop-filter: blur(18px); + box-shadow: 0 26px 70px rgba(0, 0, 0, 0.6), 0 0 32px rgba(124, 58, 237, 0.22); + opacity: 0; + visibility: hidden; + pointer-events: none; + transition: opacity 380ms var(--ease), transform 380ms var(--ease), visibility 380ms; +} +.settings-panel.is-open { + opacity: 1; + visibility: visible; + pointer-events: auto; + transform: translate(0, -50%); +} +.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; } +.settings-title { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.22em; color: #cdbff0; } +.settings-close { + width: 26px; + height: 26px; + border-radius: 8px; + border: 1px solid rgba(167, 139, 250, 0.24); + background: rgba(255, 255, 255, 0.04); + color: var(--muted, #9b92b8); + font-size: 18px; + line-height: 1; + cursor: pointer; +} +.settings-close:hover { color: #fff; border-color: var(--magenta); } + +.control + .control { margin-top: 22px; } +.control-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; } +.control-head label, .control-label { font-size: 13px; color: #e8e0ff; } +.control-head output { + font-family: var(--font-mono); + font-size: 11px; + color: #cdbff0; + background: rgba(139, 92, 246, 0.14); + border: 1px solid rgba(167, 139, 250, 0.24); + border-radius: 7px; + padding: 3px 8px; +} + +.control input[type="range"] { + -webkit-appearance: none; + appearance: none; + width: 100%; + height: 6px; + border-radius: 999px; + background: linear-gradient(90deg, var(--indigo), var(--violet) 52%, var(--magenta)); + outline: none; + cursor: pointer; +} +.control input[type="range"]::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 18px; + height: 18px; + border-radius: 50%; + background: #fff; + border: 3px solid var(--violet); + box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2), 0 0 14px rgba(217, 70, 239, 0.55); + transition: transform 220ms var(--ease); +} +.control input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.14); } +.control input[type="range"]::-moz-range-thumb { + width: 14px; + height: 14px; + border-radius: 50%; + background: #fff; + border: 3px solid var(--violet); + box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2), 0 0 14px rgba(217, 70, 239, 0.55); +} + +.shape-picker { display: flex; flex-wrap: wrap; gap: 8px; } +.shape-chip { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 7px 13px 7px 9px; + border-radius: 999px; + border: 1px solid rgba(167, 139, 250, 0.18); + background: rgba(255, 255, 255, 0.03); + color: #bdb2d8; + font-family: inherit; + font-size: 12px; + cursor: pointer; + transition: color 300ms var(--ease), border-color 300ms var(--ease), background 300ms var(--ease), box-shadow 300ms var(--ease); +} +.shape-chip svg { + width: 15px; + height: 15px; + flex: none; + fill: none; + stroke: currentColor; + stroke-width: 1.5; + stroke-linejoin: round; +} +.shape-chip:hover { color: #fff; border-color: rgba(167, 139, 250, 0.5); } +.shape-chip.is-active { + color: #fff; + border-color: transparent; + background: var(--gradient); + box-shadow: 0 6px 18px rgba(139, 92, 246, 0.38), 0 0 14px rgba(217, 70, 239, 0.24); +} + +.swatches { display: flex; flex-wrap: wrap; gap: 8px; } +.swatch { + display: inline-flex; + align-items: center; + gap: 7px; + padding: 7px 13px 7px 8px; + border-radius: 999px; + border: 1px solid rgba(167, 139, 250, 0.18); + background: rgba(255, 255, 255, 0.03); + color: #bdb2d8; + font-family: inherit; + font-size: 12px; + cursor: pointer; + transition: color 300ms var(--ease), border-color 300ms var(--ease), background 300ms var(--ease), box-shadow 300ms var(--ease); +} +.swatch:hover { color: #fff; border-color: rgba(167, 139, 250, 0.5); } +.swatch.is-active { + color: #fff; + border-color: transparent; + background: var(--gradient); + box-shadow: 0 6px 18px rgba(139, 92, 246, 0.38), 0 0 14px rgba(217, 70, 239, 0.24); +} +.swatch-dot { + width: 14px; + height: 14px; + flex: none; + border-radius: 50%; + border: 1px solid rgba(255, 255, 255, 0.4); +} + +@media (max-width: 720px) { + body { padding: 32px 16px; place-content: start center; } + .gallery { + grid-template-columns: 1fr !important; + justify-content: stretch; + width: 92vw !important; + height: auto; + gap: var(--gap); + } + .box { + height: min(var(--card-height), 340px); + transform: none !important; + --skew: 24px; + filter: grayscale(100%) opacity(38%) drop-shadow(0 12px 22px rgba(0, 0, 0, 0.5)); + } + .box.is-active { + filter: grayscale(0%) opacity(100%) + drop-shadow(0 0 10px rgba(167, 139, 250, 0.5)) + drop-shadow(0 16px 36px rgba(124, 58, 237, 0.38)); + } + .settings-toggle { right: 16px; top: auto; bottom: 20px; transform: none; } + .settings-panel { + right: 16px; + left: 16px; + top: auto; + bottom: 82px; + width: auto; + transform: translateY(16px); + } + .settings-panel.is-open { transform: translateY(0); } +} +@media (prefers-reduced-motion: reduce) { + *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } +} diff --git a/update-photos.bat b/update-photos.bat new file mode 100644 index 0000000..e501609 --- /dev/null +++ b/update-photos.bat @@ -0,0 +1,51 @@ +@echo off +rem ============================================================ +rem Update photos in script.js +rem Scans assets\img for images and rewrites the photos array +rem between /* PHOTOS:START */ and /* PHOTOS:END */ markers. +rem Usage: update-photos.bat (interactive) +rem update-photos.bat --auto (no pause, for CI / scripts) +rem ============================================================ +setlocal +cd /d "%~dp0" + +set "AUTO=0" +if /i "%~1"=="--auto" set "AUTO=1" + +if not exist "assets\img" ( + echo [ERROR] assets\img folder not found. + if "%AUTO%"=="0" pause + exit /b 1 +) +if not exist "script.js" ( + echo [ERROR] script.js not found. + if "%AUTO%"=="0" pause + exit /b 1 +) + +powershell -NoProfile -ExecutionPolicy Bypass -Command ^ + "$ErrorActionPreference='Stop';" ^ + "$exts='.jpg','.jpeg','.png','.gif','.webp','.bmp','.avif';" ^ + "$files=@(Get-ChildItem -LiteralPath 'assets/img' -File | Where-Object { $exts -contains $_.Extension.ToLower() } | Sort-Object Name);" ^ + "if ($files.Count -eq 0) { Write-Host '[ERROR] No images found in assets/img'; exit 1 };" ^ + "$q=[char]34;" ^ + "$entries=@($files | ForEach-Object { ' { src: ' + $q + 'assets/img/' + $_.Name + $q + ' }' });" ^ + "$nl=[Environment]::NewLine;" ^ + "$block='/* PHOTOS:START */' + $nl + ' const photos = [' + $nl + ($entries -join (',' + $nl)) + $nl + ' ];' + $nl + ' /* PHOTOS:END */';" ^ + "$content=Get-Content -LiteralPath 'script.js' -Raw -Encoding UTF8;" ^ + "if ($content -notmatch 'PHOTOS:START') { Write-Host '[ERROR] PHOTOS markers not found in script.js'; exit 1 };" ^ + "$pattern='(?s)/\* PHOTOS:START \*/.*?/\* PHOTOS:END \*/';" ^ + "$new=[regex]::Replace($content, $pattern, $block.Replace('$','$$'));" ^ + "[System.IO.File]::WriteAllText((Resolve-Path 'script.js').Path, $new, (New-Object System.Text.UTF8Encoding($false)));" ^ + "Write-Host ('[OK] ' + $files.Count + ' image(s) written to script.js:');" ^ + "$files | ForEach-Object { Write-Host (' - ' + $_.Name) }" + +if errorlevel 1 ( + echo. + echo Update failed. + if "%AUTO%"=="0" pause + exit /b 1 +) + +echo. +if "%AUTO%"=="0" pause