From b4ef906141665101cfe3c9e6158e13bce90013e3 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 24 Jun 2026 11:02:44 +0800 Subject: [PATCH] refactor(lightbox): move .lightbox-* CSS into lightbox project, wire import --- input.css | 72 --------------------------------- libs/lightbox/src/index.ts | 1 + libs/lightbox/src/style.css | 71 ++++++++++++++++++++++++++++++++ libs/lightbox/src/vite-env.d.ts | 1 + 4 files changed, 73 insertions(+), 72 deletions(-) create mode 100644 libs/lightbox/src/style.css create mode 100644 libs/lightbox/src/vite-env.d.ts diff --git a/input.css b/input.css index 1ffaf9c..0d7a893 100644 --- a/input.css +++ b/input.css @@ -526,78 +526,6 @@ text-underline-offset: 0.3rem; } - /* ========== 统一灯箱(Medium 风格) ========== */ - .lightbox-overlay { - position: fixed; - inset: 0; - z-index: 50; - /* overflow:hidden 裁剪超大的 absolute img,防止原图(可能数千 px) - 撑大文档可滚动区,否则会触发非预期的 scroll 事件。 */ - overflow: hidden; - background: rgba(0, 0, 0, 0.92); - opacity: 1; - } - - /* 灯箱图片:绝对定位,尺寸/位置由 JS 的 transform 控制。 - transform-origin 为 top left,配合 translate+scale 实现原地缩放。 - 显式 width/height 由 JS 设置为原图尺寸,确保布局尺寸确定, - transform 只做视觉缩放,不改变占位。 */ - .lightbox-img { - position: absolute; - left: 0; - top: 0; - transform-origin: top left; - max-width: none; - max-height: none; - object-fit: contain; - opacity: 1; - } - - .lightbox-caption { - position: fixed; - left: 0; - right: 0; - bottom: 2rem; - text-align: center; - color: rgba(255, 255, 255, 0.85); - font-size: 0.95rem; - padding: 0 2rem; - pointer-events: none; - z-index: 2; - } - - .lightbox-counter { - position: fixed; - right: 1.5rem; - bottom: 1.5rem; - color: rgba(255, 255, 255, 0.7); - font-size: 0.85rem; - z-index: 2; - } - - .lightbox-nav { - position: fixed; - top: 50%; - transform: translateY(-50%); - background: transparent; - border: none; - color: rgba(255, 255, 255, 0.7); - font-size: 3rem; - line-height: 1; - width: 3rem; - height: 5rem; - cursor: pointer; - z-index: 2; - border-radius: 0.5rem; - transition: color 0.2s ease-out, background 0.2s ease-out; - } - .lightbox-nav:hover { - color: #fff; - background: rgba(255, 255, 255, 0.1); - } - .lightbox-prev { left: 1rem; } - .lightbox-next { right: 1rem; } - /* 卡片封面:blur-img 结构,固定 4:3 比例,hover 缩放 */ .post-card-cover-blur { margin: 0; diff --git a/libs/lightbox/src/index.ts b/libs/lightbox/src/index.ts index c30537c..1d1478f 100644 --- a/libs/lightbox/src/index.ts +++ b/libs/lightbox/src/index.ts @@ -1,4 +1,5 @@ import { fitCentered, transformFor, originalUrl, type Rect } from "./geometry"; +import "./style.css"; interface LightboxState { overlay: HTMLDivElement; diff --git a/libs/lightbox/src/style.css b/libs/lightbox/src/style.css new file mode 100644 index 0000000..d40aeec --- /dev/null +++ b/libs/lightbox/src/style.css @@ -0,0 +1,71 @@ +/* ========== 统一灯箱(Medium 风格) ========== */ +.lightbox-overlay { + position: fixed; + inset: 0; + z-index: 50; + /* overflow:hidden 裁剪超大的 absolute img,防止原图(可能数千 px) + 撑大文档可滚动区,否则会触发非预期的 scroll 事件。 */ + overflow: hidden; + background: rgba(0, 0, 0, 0.92); + opacity: 1; +} + +/* 灯箱图片:绝对定位,尺寸/位置由 JS 的 transform 控制。 + transform-origin 为 top left,配合 translate+scale 实现原地缩放。 + 显式 width/height 由 JS 设置为原图尺寸,确保布局尺寸确定, + transform 只做视觉缩放,不改变占位。 */ +.lightbox-img { + position: absolute; + left: 0; + top: 0; + transform-origin: top left; + max-width: none; + max-height: none; + object-fit: contain; + opacity: 1; +} + +.lightbox-caption { + position: fixed; + left: 0; + right: 0; + bottom: 2rem; + text-align: center; + color: rgba(255, 255, 255, 0.85); + font-size: 0.95rem; + padding: 0 2rem; + pointer-events: none; + z-index: 2; +} + +.lightbox-counter { + position: fixed; + right: 1.5rem; + bottom: 1.5rem; + color: rgba(255, 255, 255, 0.7); + font-size: 0.85rem; + z-index: 2; +} + +.lightbox-nav { + position: fixed; + top: 50%; + transform: translateY(-50%); + background: transparent; + border: none; + color: rgba(255, 255, 255, 0.7); + font-size: 3rem; + line-height: 1; + width: 3rem; + height: 5rem; + cursor: pointer; + z-index: 2; + border-radius: 0.5rem; + transition: color 0.2s ease-out, background 0.2s ease-out; +} +.lightbox-nav:hover { + color: #fff; + background: rgba(255, 255, 255, 0.1); +} +.lightbox-prev { left: 1rem; } +.lightbox-next { right: 1rem; } diff --git a/libs/lightbox/src/vite-env.d.ts b/libs/lightbox/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/libs/lightbox/src/vite-env.d.ts @@ -0,0 +1 @@ +///