Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(ui): stabilize shared photo lightbox

longmeidaoca6a6c50df21
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md
index 5c5239063..50106e6cd 100644
--- a/docs/HANDOFF.md
+++ b/docs/HANDOFF.md
@@ -23,7 +23,7 @@
- AV 厂牌官网普遍先给年龄确认页,不穿过它只能拿到约 10 KB 的空壳。判据必须是锚文本而不是 URL:否定链接指向站外(实测 `dasdas.jp`、`muku.tv` 的「いいえ」都指向 dmm.com),肯定链接「はい(入室する)」指向站内,两者的 href 看不出区别。跟错就离开了厂牌域名,抓到的账号也就不再属于这个厂牌。实现见 `scripts/find_studio_socials.py`,`test_age_gate_is_crossed_by_the_affirmative_link_only` 守这条线。
- 二手结论不能当证据:搜索摘要曾称 `@EBODY_` 已注销,实测直接解析到 400×400 活跃头像。凡是「某账号/端点已失效」这类判断,取证方式是自己请求一次,不是转述搜索结果。
- **图集就是目录**:账本没有图集实体,也不需要一个。`<作品目录>\P\001.jpg` 这种约定在 A:/B: 上到处都是,所以 `/api/photos` 按 `path` 去掉文件名分组,图集 ID 取该目录里最小的资产 ID——稳定、可反查目录,又不用把真实路径发给前端(和 `q_item` 一致)。同名目录在两个来源下算两个图集:文件不同、计费口径也不同。叶子目录只写 `P`、`图片` 这类通用名时,标题取上一级目录名。
-- **瀑布流只读缩略图,原图只在灯箱里读**。图片资产没有接触印相可裁,只能读原图;PikPak 一张动辄几 MB,一屏几十张就是几十兆计费流量。`/photo-thumb` 用 Pillow 缩到 640 宽存进 `photo_root`,每张只回源一次,`/photo` 只服务灯箱当前和相邻的大图。瀑布流用 CSS `column-count`:图片行没有 `width`/`height`,等宽多列流式排版正好不需要比例,也就不必等图加载完再算位置。灯箱继续复用 Swiper 14.2.0,但主画布必须直接固定到视口,顶部工具和底部缩略图只作覆盖层;不要再用三行 grid 承接 Swiper 的百分比高度。关注图集箭头、灯箱翻页和沉浸动作列共用 48 px tonal 圆钮,禁止恢复浏览器默认按钮内边距或额外描边。
+- **瀑布流只读缩略图,原图只在灯箱里读**。图片资产没有接触印相可裁,只能读原图;PikPak 一张动辄几 MB,一屏几十张就是几十兆计费流量。`/photo-thumb` 用 Pillow 缩到 640 宽存进 `photo_root`,每张只回源一次,`/photo` 只服务灯箱当前和相邻的大图。瀑布流用 CSS `column-count`:图片行没有 `width`/`height`,等宽多列流式排版正好不需要比例,也就不必等图加载完再算位置。灯箱继续复用 Swiper 14.2.0,但必须等它的 CSS 和 JS 同时就绪后再构造,并在 Peach CSS 中保留仅作用于主轮播直接子级的 flex/单 slide 兜底;否则首次打开会把多张图当普通块元素重叠显示。主画布固定到视口,信息、页码、缩放、适应窗口和原大小统一放在底部,缩放百分比相对原图像素而非适应窗口的初始尺寸;底部当前缩略图由主轮播切换事件主动滚到中央。图片覆盖层的箭头和关闭钮共享 48 px 几何、24 px 居中图标与黑色 60% 表面,首尾无效方向完全隐藏;沉浸动作列只共享几何,仍使用适合其独立深色表面的白色 10% tonal 色。禁止恢复浏览器默认按钮内边距或额外描边。
- 人工复核入口固定为 `/review`,候选 API 为 `GET /api/review`、`POST /api/review/decision`。候选来自 writer 本机 `peach-data/generated` 下的 CSV;每项尽量带代表封面与原视频入口,审核状态写 `review_decision`。元数据与创作者标签批准后写相应真相/投影,Logo、头像、身份和媒体失败只记录决定;封面抓取的成功、尺寸和缺失是机械状态,不进入人工复核。双机同时在线时,reader 的 `GET /api/review` 只通过 Peach CA 严格校验的 HTTPS 读取 writer 已归一化 JSON,先确认目标 `/healthz` 是 `ledger_sync=writer`,绕过外网代理并原子缓存到本机 `review/writer-review.json`;macOS 合并文件 CA 与系统/登录钥匙串中受信任的同名 Peach CA,只读取公钥证书,不导出私钥。launchd 主体被本地网络权限挡住时,使用系统 `/usr/bin/curl` 经回环 Stash 代理发起同一严格请求;仅限 HTTPS、8 MiB 上限,令牌走 stdin,非回环代理拒绝。writer 临时离线时只展示上次缓存。reader 永远禁用批准、跳过和拒绝,关注管理也禁用新增、检查、移除和凭据修改,并链接到 writer。不得为修复空页面而同步整个 `generated`、SQLite/WAL,或把真实写入端点加入 reader 白名单。
## 无摩擦接手
diff --git a/docs/REUSE.md b/docs/REUSE.md
index 359815d9f..e9f44f4fe 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -47,7 +47,7 @@
| 播放器设置与影院布局 | Video.js 8.24.0 的 `playbackRate`、既有 QualityLevel、原生 tooltip 与控制栏插槽;YouTube `e937390a` 实际 DOM/CSS/JS 提供可复现的几何、状态、动画和图形证据 | Peach 在现有 DOM 上组合氛围模式、播放速度、真实清晰度和影院模式,并复用 59 px 两排控制栏、40→111 px 横向音量、4→6 px 进度动画、右侧共享胶囊、整行悬停的 274 px 设置菜单和视口级全屏;普通视图 `contain` 保全片源,全屏按用户明确要求改用 `cover` 铺满视口,接受非等比例片源的边缘裁切。全屏命中同时使用 Video.js/原生类和 `isFullscreen()` 同步的 `data-peach-fullscreen`,并覆盖 `body.vjs-full-window` 回退,不能再靠单个 CSS 类推断运行态;标准、WebKit、Gecko 等浏览器专用伪类必须放进 forgiving `:is(...)` 或拆成独立规则,不能在普通 selector list 混写后让某浏览器因未知伪类废掉整组声明。用户要求精准图形的设置项、radio 选中勾、菜单箭头、中央 bezel 与 loading 只 vendoring 当前锁定版本的 SVG path/spinner 结构,音量 hover 与滑轨中心沿用上游外层伪元素和 50% 几何,tooltip 仅补 Peach 两排控制栏需要的显式层级与越界可见;不复制播放器控制逻辑、不迁移到 Video.js 10 Menu,也不引入重复现有质量选择的插件 |
| 播放器时刻预览 | Video.js 原生进度控件 + Peach 既有 `/poster?id=&c=0…8` 九宫格切片 | 本地媒体用已有接触表提供近似时刻缩略图;在线视频只显示时刻。`videojs-vtt-thumbnails` 与 `videojs-sprite-thumbnails` 都要求另建 sprite/VTT 契约,本项目不为已有能力新增依赖或重复抽帧 |
| 分卷文件命名 | [Plex 官方命名](https://support.plex.tv/articles/naming-and-organizing-your-movie-media-files/)的 `cd/disc/disk/dvd/part/pt + 数字` 与 [Kodi 官方 File Stacking](https://kodi.wiki/view/File_stacking)只作行为证据;运行时复用当前树的 `part_marker`,不新增扫描器依赖 | 兼容馆藏已有的裸数字和 A–H 后缀;仅连续、唯一标记自动合卡,保留每个 asset 和播放会话,不拼接或改写媒体 |
-| 照片灯箱轮播 | Swiper 14.2.0(MIT,本地固定版本,按需 `<script>` 注入)的 Thumbs / Keyboard / Zoom 模块 | 图集来源与顺序、缩略图缓存与计费口径、瀑布流本身(CSS `column-count`,不经过 Swiper) |
+| 照片灯箱轮播 | Swiper 14.2.0(MIT,本地固定版本,按需加载 CSS/JS)的 Thumbs / Keyboard / Zoom 模块 | 构造轮播前必须同时等到样式与脚本就绪,并保留 scoped 的单 slide 结构样式防止首载竞态重叠;Swiper 管轮播、键盘、缩放变换与缩略图,Peach 管图集来源与顺序、当前缩略图居中、相对原图百分比、适应窗口/原大小语义、缩略图缓存与计费口径。瀑布流本身继续用 CSS `column-count`,不经过 Swiper。 |
| 导航排序 | 浏览器原生 HTML Drag and Drop | 桌面鼠标直接拖动、落点提示、上下移动按钮作为键盘与触屏回退、`localStorage` 持久化;不为单列排序引入额外运行时依赖 |
| 图标 | 固定版本的本地 Lucide 子集;Health Icons 24 px outline(CC0)用于领域图标 | 标签、状态和交互设计 |
| 资源文本中间省略 | Vercel Geist `MiddleTruncate` 行为契约 + 浏览器原生 `ResizeObserver`、`Intl.Segmenter`、Canvas 测量 | 文件名、路径、URL、ID 等资源标识用 `data-middle-truncate`;标题、说明、人名、标签等语义文本保留末尾省略;页面源测试登记全部末尾省略选择器,新增截断未先分类会失败 |
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 62c1fac0e..8e837876f 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -20,7 +20,7 @@
## 已核验能力
- 2026-09-01 非原生容器的浏览器转码已改为性能优先:缓存未命中时以可取消 ffprobe 探测,H.264 8-bit 视频优先直接复制到 MP4,AAC 同时复制;其他 Windows 视频先走 CUDA/NVDEC + `scale_cuda` + H.264 NVENC `p1`,解码器不支持时保留 NVENC 编码,两条失败才回退原 `libx264 veryfast`,macOS 保持封装复制或软件转码。真实 CloudDrive POC 中,H.264/AAC 的 30 秒 MKV 片段封装耗时 0.64 秒,1080p HEVC 的 30 秒硬件转码耗时 1.60 秒;生产源码对 1 MB、3.8 秒 AVI 的实际策略为 `ffprobe → cuda-nvenc`,含网盘首次读取和进程启动共 5.59 秒,输出 H.264 `yuv420p` + AAC,临时缓存已删除。变基后工作树与集成后主目录 Windows 正式全量均为 1586 项通过、13 项按平台跳过;生产托盘已正常重启并重新拥有 80/443,项目 CA 严格 HTTPS `/healthz` 返回 200、0.7.13、writer、非只读。未替换 EXE,未写真实 ledger、候选或原媒体,旧转码缓存继续有效。
-- 2026-09-01 图片媒体控件与灯箱布局收口:关注图集箭头、照片灯箱翻页/关闭和沉浸动作列共用 48 px YouTube Shorts tonal 圆钮,去掉旧描边与浏览器默认按钮内边距,24 px SVG 在圆心对齐;灯箱主画布改为固定视口,顶部工具和底部缩略图只作覆盖层,消除超宽视口下 Swiper 主图行塌成 0、原图贴左溢出的布局错误。女优资料页本地照片与关注在线图片继续复用同一套 Swiper 14.2.0 灯箱;未新增依赖、API 或 ledger 字段,未写真实 ledger、候选或媒体。
+- 2026-09-01 图片灯箱按用户截图再次纠偏:女优/厂牌本地照片和关注在线图片继续复用同一套 Swiper 14.2.0;首次重叠的根因是只等脚本、不等样式就构造轮播,现在 CSS/JS 同时就绪后才初始化,并用 scoped flex 结构保证任一时刻只画一张主图。上一张、下一张和关闭统一为 48 px、黑色 60% 覆盖层圆钮,首尾无效方向完全隐藏;信息、页码和缩放回到底部,缩放条按原图像素显示 10%–400%,补齐「适应窗口」与「原大小」,主图切换时把当前缩略图主动滚到中央。沉浸动作列只共享 48/24 px 几何,保留白色 10% tonal 表面。`catalog` 588 项、`follow` 501 项(1 项按平台跳过)及 Windows 正式全量 1587 项(13 项按平台跳过)通过;未新增依赖、API 或 ledger 字段,未写真实 ledger、候选或媒体。
- 2026-09-01 资料页移动端按 beeg 收口,链接改为写入前必须能打开:窄屏改单列居中、头像在名字上方(左像右文是给宽屏的,手机上 92 px 头像旁只剩两百多像素,别名和链接被挤成两三行);社媒收成 42×42 纯图标,handle 变成 sr-only 加 `title`(handle 是网址的一部分,写出来只是把 URL 抄一遍);删掉外链箭头;X 改用内联品牌 SVG——它本来就挡 favicon 请求,资料页上那个空白白圆就是它,而 416 条社媒里 372 条是 x.com/twitter.com。`.sorts .javlayout` 补 `flex:none`:`.sorts` 是不换行的横向滚动条,`.javlayout` 是带 `min-width:0` 的 fieldset,两条合起来允许它被压到内容宽度以下,窄屏上三个 34 px 版式按钮叠在一起并压住「发行时间」;`.sorts button` 早有 `flex:0 0 auto`,但 fieldset 不是 button,选不到它。375 px 实测横向溢出 0、版式组右缘 177 < 「发行时间」左缘 188,桌面 1280 px 仍是两列左对齐。**用户由一条 404 揭出的数据事故**:首批 703 条链接一条都没验就装进了账本,逐条实测 708 条里 152 条打不开(21%),其中 126 条 404 是确证已没了、26 条只是取不到(`linktr.ee` 403 挡爬虫、`facebook.com` 400、`x.com` 500、连接失败与超时各一)。根因是把 minnano-av 的旧快照当成现在的事实——T-POWERS 改过站,`/official/talent/X` 早已 404,正确形态是 `/talent/X/`,而资料页上它和好链接一模一样。可达性门槛因此放进安装器(所有来源进入账本的唯一入口),并新增 `--prune-dead`;「取不到不等于没了」写成 `is_gone` 判据,只有 404/410 才算删除依据。清理 126 条待用户授权。
- 2026-09-01 实体链接从「采了没处安装」变成可安装:`entity_link` 表、`q_entity` 的 `links` 契约和资料页 favicon 渲染 2026-08 就已就绪,缺的只有安装路径,因此 8178 个实体长期只有 5 条链接(3 条来自迁移 `0003` 的种子,2 条来自 Stash 导入)。这是本仓库第四次出现同一形态,前三次是 `creator_tags`、`studio_logos`、`performer_avatars`。新增 `install_entity_links.py`(默认 dry-run,`--apply` 必须同时给 `--backup`,靠 `UNIQUE(entity_id,url)` 幂等,URL 归一后重跑为零写入,实体解析按 id → 规范名 → 别名,非法行照样出现在计划里并写明拒绝原因)。女优侧新增 `harvest_performer_links.py`:minnano-av 检索唯一命中时会跳到 `actressNNN.html`,**只采信最终地址**——检索页正文里同样有一堆 `actressNNN.html`,那是「相关女优」,按正文解析会把别人的社媒安到这个人头上;为此给共享 `HttpResponse` 补了 `url` 字段,此前两个 transport 都开着 `follow_redirects` 却把最终地址丢了。关键是名字链:账本 performer 规范名是简体中文,日文站按它搜 12 位只中 1 位,改用 `entity_alias` 里的日文写法后同样 12 位全中,罗马字不进链。全量 541 位(26 位按非 JAV 跳过)产出 689 条链接、409 位有链接,`social` 400 条、`official` 289 条,事务所 T-POWERS 128、マインズ 48、Bambi 32 等;132 条未取得中 51 条需人工消歧、7 条没有可用于日文站的名字。厂牌侧新增 `harvest_studio_sites.py`(按厂牌名规则化推域名当假设,能否采信取决于取回页面的标题自述厂牌名,另设停放页与空壳页两道拒绝——抢注页同样回 200 且标题里同样有厂牌名,只看标题会把它采信成官网再被下游当作社媒来源),并把 2026-08 人工看图确认的 14 条厂牌 X handle 转成可安装格式,3 条 `未取得` 标记正确排除。资料页外链 favicon 补上 `referrerpolicy="no-referrer"`:锚点的 `rel="noreferrer"` 只管点击跳转,管不到这个 `<img>`,同页 taste 行早已是 no-referrer,链接从 5 条涨到七百多条后这一处漏才真正有代价。经用户授权已写入真实 ledger:写入前备份 `database/ledger.pre-entity-links-20260901.db`,`entity_link` 5 → 708(+703,与计划一致,0 条跳过),`asset` 75499、`entity` 8178、`asset_tag` 81196、`asset_entity` 145922 均未变,`integrity_check=ok`、外键违规 0。服务实时读账本,无需重启:项目 CA 严格 HTTPS `/healthz` 返回 0.7.13、`db=available`,`/api/entity` 实测释爱丽丝由 0 条变 2 条(`New Actor eXperience` + `X @alice_710_`)、凉森玲梦 2 条(`T-POWERS` + `X @remu19971203`)、Glory Quest 1 条。厂牌官网这一路的首轮结论已作废并重做:当时 56 个厂牌只命中 3 个,53 个失败里 49 个是 `PoolTimeout`——客户端连接池耗尽,不是「这些站不存在」。真实成因是这种形态下**失败的连接会漏掉池槽**,池子多大只决定它第几个请求崩(我一度误判成闲置隧道占满,把池调小反而更早崩);改成每个请求新建 client 并立刻关掉后 `PoolTimeout` 归零。判据同时补了三道,每一道都由实测假阳性推动:标题只回显域名的通用站(`prestige.com` 标题就是 `prestige.com`,而真站是 `prestige-av.com`);标题自述在出售域名(`kawaii.com - domain for sale` 的关键词在正文第 81683 字节,超出任何窗口,但它写在标题里,此前从不搜标题;`Attackers - The Domain Name Attackers.com is Now For Sale.` 中间插了词);以及最关键的——「标题含厂牌名」证明不了这是**这个**厂牌的站,`madonna.com` 是歌手、`hunter.com` 是 Hunter Engineering、`bazooka.com` 是车载音响,全都 200、非停放页、标题含厂牌名,缺的那一半是「这一页是不是 AV 厂牌站」。日站普遍把品牌名写成假名(`本中`、`無垢`、`ダスッ`),拉丁名比标题对整类真站必然失败,因此补了「域名由厂牌名推出 + 页面是成人站」这条替代路径,且该判据必须落在**最终**主机上——实测 `Natural High` 的推导域名重定向到了 `linkedin.com/in/fareedkhan`,按请求地址判会把一个 LinkedIn 个人主页确认成厂牌官网。最终 56 个厂牌 12 条 `ok`(Prestige、MOODYZ、Idea Pocket、FALENO、Wanz Factory、Deep's、Tameike Goro、Muku、Hon Naka、Glory Quest、Fitch、HEYZO)、8 条 `weak` 待人工确认、36 条未取得;`s1s1s1.com`、`madonna-av.com` 这类推不出来的域名要靠 `--seeds` 人工补。
- 2026-09-01 在线图片详情复用既有照片灯箱,但不再显示只适用于本地资产的“在资源管理器中显示”:信息面板改为显示安全的来源、合集序号(有多张时)和浏览器实际解码得到的像素尺寸,来源已提供大小时再追加大小;本地图片原有文件信息和定位能力保持不变。真实关注条目 `3559` 的 Rule34.xxx 图片在 1280×720 与 390×844 下均显示 `Rule34.xxx · 3000 × 4000`,本地定位按钮隐藏,页面无横向溢出且控制台错误为 0。Windows `follow` 497 项通过、1 项按平台跳过;改动只有静态 JS/CSS,无需重启生产服务,未写真实 ledger、候选或媒体。
diff --git a/docs/reference-snapshots/youtube-player-controls-user-screenshot.md b/docs/reference-snapshots/youtube-player-controls-user-screenshot.md
index 675984a65..bf044da9a 100644
--- a/docs/reference-snapshots/youtube-player-controls-user-screenshot.md
+++ b/docs/reference-snapshots/youtube-player-controls-user-screenshot.md
@@ -92,9 +92,12 @@
- 实际左侧播放钮为 40×40 px、`padding:0`、`border:0`、`border-radius:50%`、
`background:rgba(0,0,0,.3)`;右侧控制组仍是 40 px 高共享胶囊,内部单钮为
48×40 px、透明、无边框和内边距。
-- Peach 图片翻页属于独立媒体动作,不复制播放器底栏的 48×40 胶囊单钮;它复用已经按
- YouTube Shorts 用户截图锁定的 48×48 tonal 圆钮:无描边、无默认按钮内边距、24 px
- 图标居中。图片灯箱继续使用 Swiper 14.2.0,不复制 YouTube 播放控制逻辑。
+- Peach 图片翻页属于独立媒体动作,不复制播放器底栏的 48×40 胶囊单钮;它只复用
+ YouTube Shorts 用户截图锁定的 48×48 几何:无描边、无默认按钮内边距、24 px 图标居中。
+ 用户 2026-09-01 的灯箱纠偏截图证明,把独立表面的 tonal 色也强行共用会形成三种视觉:
+ 图片覆盖层的上一张、下一张与关闭统一改为黑色 60% 圆钮,沉浸动作列仍用白色 10%。
+ 首张不显示上一张、末张不显示下一张;信息、缩放及适应窗口/原大小操作放在底部,
+ 当前缩略图居中。灯箱继续使用 Swiper 14.2.0,不复制 YouTube 播放控制逻辑。
## 2026-08-30 实时页面纠偏
diff --git a/docs/reference-sources.json b/docs/reference-sources.json
index 1ff2d306b..9ea893a13 100644
--- a/docs/reference-sources.json
+++ b/docs/reference-sources.json
@@ -202,7 +202,7 @@
"url": "https://www.youtube.com/watch?v=jNQXAC9IVRw",
"snapshot": "docs/reference-snapshots/youtube-player-controls-user-screenshot.md",
"checked_on": "2026-09-01",
- "sha256": "b360608a2728541f8ad7f51bd56ffa90224dd6d8ef895f94f5cac9b72fb3a1eb",
+ "sha256": "d20e01e3796c82c3c16442ce6dbb304f50a4940f5ec0183c356703c9953c7caf",
"role": "实际 YouTube e937390a DOM、CSS、JS 与用户截图锁定播放器几何、状态和设置面板;官方帮助锁定氛围模式和影院模式语义。",
"consumers": [
"web/app.css",
diff --git a/tests/test_follow_web.py b/tests/test_follow_web.py
index d8e210a2d..65ee45a34 100644
--- a/tests/test_follow_web.py
+++ b/tests/test_follow_web.py
@@ -1821,8 +1821,8 @@ class FollowWebSourceTests(unittest.TestCase):
self.assertPageLacks("event.currentTarget.innerHTML=icon('check')")
def test_follow_image_collections_use_buttons_dots_and_arrow_keys(self):
- self.assertPageContains('class="media-circle followimagearrow prev"')
- self.assertPageContains('class="media-circle followimagearrow next"')
+ self.assertPageContains('class="media-circle media-overlay followimagearrow prev"')
+ self.assertPageContains('class="media-circle media-overlay followimagearrow next"')
self.assertPageContains('class="followimagedots" role="group"')
self.assertPageContains('data-follow-image-item="${image.index}"')
self.assertPageContains("imageDots.length&&(e.key==='ArrowLeft'||e.key==='ArrowRight')")
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index b2a4d1b77..5ba05305f 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -2569,6 +2569,9 @@ class WebUiSourceTests(unittest.TestCase):
def test_photo_lightbox_loads_swiper_lazily_with_thumbs_and_keyboard(self):
self.assertPageContains("'/vendor/swiper/14.2.0/swiper-bundle.min.js'")
+ self.assertPageContains("swiperLoader=Promise.all([")
+ self.assertPageContains("style.addEventListener('load',resolve,{once:true})")
+ self.assertPageContains("]).then(([,SwiperCtor])=>SwiperCtor)")
self.assertPageContains("thumbs:{swiper:strip}")
self.assertPageContains("keyboard:{enabled:true}")
self.assertPageContains(".photolight{position:fixed;inset:0;z-index:200;background:#000;display:block;overflow:hidden}")
@@ -2581,16 +2584,16 @@ class WebUiSourceTests(unittest.TestCase):
依赖;否则超宽视口会把主图行收成 0,让原图按自然尺寸贴到左边溢出。
"""
self.assertPageContains(
- ".photolight .photomain{position:absolute;inset:0;min-width:0;min-height:0;width:100%;height:100%}")
+ ".photolight .photomain{position:absolute;inset:0;min-width:0;min-height:0;width:100%;height:100%;overflow:hidden}")
self.assertPageContains(
- ".photolight .photomain .swiper-wrapper{width:100%;height:100%}")
+ ".photolight .photomain>.swiper-wrapper{display:flex;width:100%;height:100%}")
self.assertPageContains(
- ".photolight .photomain .swiper-slide{width:100%;height:100%;min-width:0;min-height:0;")
+ ".photolight .photomain>.swiper-wrapper>.swiper-slide{flex:0 0 100%;width:100%;height:100%;min-width:0;")
self.assertPageContains(
".photolight .photomain .swiper-zoom-container{width:100%;height:100%;"
"min-height:0;min-width:0;")
- self.assertPageContains("box-sizing:border-box;display:grid;place-items:center;padding:64px 72px 24px")
- self.assertPageContains(".photolight.has-strip .photomain .swiper-zoom-container{padding-bottom:104px}")
+ self.assertPageContains("box-sizing:border-box;display:grid;place-items:center;padding:24px 72px 76px")
+ self.assertPageContains(".photolight.has-strip .photomain .swiper-zoom-container{padding-bottom:148px}")
self.assertPageContains(
".photolight .photomain img{max-width:100%;max-height:100%;"
"min-width:0;min-height:0;")
@@ -2604,8 +2607,8 @@ class WebUiSourceTests(unittest.TestCase):
两者同为 0-1-0 特指度且 `.next` 写在后面,padding、border-top 和背景色会
整块盖过来,图标被挤得偏右下——实测偏移 5px/2px。
"""
- self.assertPageContains('class="media-circle photonav back"')
- self.assertPageContains('class="media-circle photonav fwd"')
+ self.assertPageContains('class="media-circle media-overlay photonav back"')
+ self.assertPageContains('class="media-circle media-overlay photonav fwd"')
self.assertPageContains(".photonav.back{left:14px}.photonav.fwd{right:14px}")
self.assertPageContains(".photonav.fwd svg{transform:rotate(180deg)}")
self.assertPageLacks('class="photonav prev"')
@@ -2623,29 +2626,41 @@ class WebUiSourceTests(unittest.TestCase):
):
self.assertPageContains(rule)
- def test_photo_navigation_reuses_the_youtube_tonal_media_button(self):
+ def test_photo_navigation_reuses_one_overlay_button_treatment(self):
self.assertPageContains(
".media-circle{box-sizing:border-box;width:48px;height:48px;padding:0;border:0;border-radius:50%;")
- self.assertPageContains("background:rgba(255,255,255,.1);color:#f1f1f1;display:grid;place-items:center")
- self.assertPageContains('class="media-circle followimagearrow prev"')
- self.assertPageContains('class="media-circle followimagearrow next"')
- self.assertPageContains('class="media-circle photoclose"')
- self.assertPageContains('class="media-circle photonav back"')
+ self.assertPageContains(".media-circle.media-overlay{background:rgba(0,0,0,.6);color:#fff;backdrop-filter:blur(16px)}")
+ self.assertPageContains('class="media-circle media-overlay followimagearrow prev"')
+ self.assertPageContains('class="media-circle media-overlay followimagearrow next"')
+ self.assertPageContains('class="media-circle media-overlay photoclose"')
+ self.assertPageContains('class="media-circle media-overlay photonav back"')
self.assertPageContains('class="media-circle" id="tokDislike"')
self.assertPageContains(".followimagearrow{position:absolute;z-index:4;top:50%;transform:translateY(-50%)}")
+ self.assertPageContains(".photonav.swiper-button-disabled{opacity:0;visibility:hidden;pointer-events:none}")
def test_lightbox_offers_wheel_paging_and_an_explicit_zoom_bar(self):
- # zoom 模块只有 in/out/toggle,没有「缩到这个倍数」;`in()` 用的就是
- # maxRatio,所以先改上限再 in 等于设定值。
self.assertPageContains("mousewheel:{enabled:true,forceToAxis:false}")
- self.assertPageContains("main.params.zoom.maxRatio=scale;main.zoom.in()")
- self.assertPageContains('<input type="range" min="1" max="${ZOOM_MAX}"')
+ self.assertPageContains("const PHOTO_ZOOM_MIN=10,PHOTO_ZOOM_MAX=400,PHOTO_ZOOM_STEP=10")
+ self.assertPageContains("return Math.min(100,img.offsetWidth/img.naturalWidth*100,img.offsetHeight/img.naturalHeight*100)")
+ self.assertPageContains("else main.zoom.in(ratio)")
+ self.assertPageContains('<input type="range" min="${PHOTO_ZOOM_MIN}" max="${PHOTO_ZOOM_MAX}"')
# zoomChange 的第一个参数是 swiper 实例,倍数在第二个;接错了写进 NaN。
self.assertPageContains("main.on('zoomChange',(_swiper,scale)=>")
+ self.assertPageContains('data-photo-scale="fit" aria-label="适应窗口"')
+ self.assertPageContains('data-photo-scale="original" aria-label="原大小"')
# 文本字形受字体基线影响,会让圆按钮里的 +/- 肉眼偏上或偏下;SVG 几何才稳定居中。
self.assertPageContains('data-zoom-step="-1" aria-label="缩小">${icon(\'minus\')}')
self.assertPageContains('data-zoom-step="1" aria-label="放大">${icon(\'plus\')}')
self.assertPageContains(".photozoom button svg{width:15px;height:15px;display:block;")
+ self.assertPageContains(".photobar{position:absolute;z-index:4;bottom:14px;")
+ self.assertPageContains(".photolight.has-strip .photobar{bottom:98px}")
+
+ def test_lightbox_centers_the_active_thumbnail(self):
+ self.assertPageContains("centeredSlides:true,slideToClickedSlide:true")
+ self.assertPageContains("const centerThumb=(at,speed=200)=>strip.slideTo(at,speed)")
+ self.assertPageContains("centerThumb(this.activeIndex)")
+ self.assertPageContains("centerThumb(index,0)")
+ self.assertPageLacks("centeredSlidesBounds:true")
def test_lightbox_photo_detail_reveals_by_asset_id_without_leaking_a_path(self):
self.assertPageContains('aria-label="图片详情" title="图片详情">${icon(\'info\')}</button>')
@@ -2674,8 +2689,8 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("box-sizing:border-box;display:grid;align-items:start;gap:14px;padding:16px")
self.assertPageContains(".photodetail .srcstate:empty{display:none}")
self.assertPageContains(".photodetail>button{min-height:44px}")
- self.assertPageContains(".photodetailtoggle{width:44px;height:44px}")
- self.assertPageContains(".photodetailtoggle{justify-self:start;width:30px;height:30px;display:grid;place-items:center")
+ self.assertPageContains(".photodetailtoggle{width:40px;height:40px}")
+ self.assertPageContains(".photodetailtoggle{justify-self:start;width:40px;height:40px;display:grid;place-items:center")
# Lucide 的 info 圆点是长度 .01 的短线;没有圆头时会缩成几乎不可见的横杠。
css = (Path(__file__).resolve().parents[1] / "web" / "app.css").read_text(
encoding="utf-8")
@@ -2688,7 +2703,7 @@ class WebUiSourceTests(unittest.TestCase):
def test_lightbox_remeasures_when_the_window_resizes(self):
# Swiper 只在构造那一刻量一次容器;灯箱是插进已布好版的页面里的,
# 窗口一改大小 slide 就停在旧宽度,大图按错误的框缩放。
- self.assertPageContains("new ResizeObserver(()=>{main.update();strip.update()})")
+ self.assertPageContains("new ResizeObserver(()=>{main.update();strip.update();zoomBar.resize()})")
self.assertPageContains("activeLightbox.resize?.disconnect()")
def test_failed_review_decisions_are_shown_instead_of_silently_swallowed(self):
diff --git a/web/app.css b/web/app.css
index 330d48306..a0600cae2 100644
--- a/web/app.css
+++ b/web/app.css
@@ -441,14 +441,15 @@ body.entity-open .index{overflow-x:visible}
border-radius:8px;overflow:hidden;cursor:zoom-in;break-inside:avoid;line-height:0}
.photocell img{width:100%;height:auto;display:block;background:var(--sunk)}
.photocell:hover img{filter:brightness(1.06)}
-/* YouTube Shorts 参考中的 48px tonal 圆钮是媒体表面的共同按钮:无描边、无浏览器
- 默认内边距,24px 图标严格落在中心。关注图集、图片灯箱和沉浸动作列都复用这一层。 */
+/* 媒体圆钮只共享 48/24 的几何与图标居中;表面色由使用场景决定。 */
.media-circle{box-sizing:border-box;width:48px;height:48px;padding:0;border:0;border-radius:50%;
background:rgba(255,255,255,.1);color:#f1f1f1;display:grid;place-items:center;cursor:pointer}
.media-circle:hover{background:rgba(255,255,255,.18)}
.media-circle:focus-visible{outline:2px solid var(--tungsten);outline-offset:3px}
.media-circle svg{display:block;width:24px;height:24px;flex:none;stroke:currentColor;fill:none;
stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
+.media-circle.media-overlay{background:rgba(0,0,0,.6);color:#fff;backdrop-filter:blur(16px)}
+.media-circle.media-overlay:hover{background:rgba(0,0,0,.78)}
/* 灯箱本体只负责固定视口;主图、顶部工具和底部缩略图各自绝对定位。
旧三行 grid 会和动态后载的 Swiper 百分比高度形成循环,超宽视口下主图行收成 0,
结果就是工具跑到顶部、缩略图贴左、原图按自然尺寸溢出。 */
@@ -456,12 +457,15 @@ body.entity-open .index{overflow-x:visible}
body.photolight-open{overflow:hidden}
/* 主画布始终占满视口,安全内边距为顶部工具、左右翻页和底部缩略图留位;
单图没有缩略图条,底部空间会自动还给图片。 */
-.photolight .photomain{position:absolute;inset:0;min-width:0;min-height:0;width:100%;height:100%}
-.photolight .photomain .swiper-wrapper{width:100%;height:100%}
-.photolight .photomain .swiper-slide{width:100%;height:100%;min-width:0;min-height:0;display:grid;place-items:center}
+.photolight .photomain{position:absolute;inset:0;min-width:0;min-height:0;width:100%;height:100%;overflow:hidden}
+/* Swiper 的 CSS 和脚本虽会一起等待,仍保留最小结构样式,避免缓存/首载竞态把所有
+ slide 当普通块元素同时画出来。只限定 photomain 的直接子级,不影响底部缩略图。 */
+.photolight .photomain>.swiper-wrapper{display:flex;width:100%;height:100%}
+.photolight .photomain>.swiper-wrapper>.swiper-slide{flex:0 0 100%;width:100%;height:100%;min-width:0;
+ min-height:0;display:grid;place-items:center}
.photolight .photomain .swiper-zoom-container{width:100%;height:100%;min-height:0;min-width:0;
- box-sizing:border-box;display:grid;place-items:center;padding:64px 72px 24px}
-.photolight.has-strip .photomain .swiper-zoom-container{padding-bottom:104px}
+ box-sizing:border-box;display:grid;place-items:center;padding:24px 72px 76px}
+.photolight.has-strip .photomain .swiper-zoom-container{padding-bottom:148px}
.photolight .photomain img{max-width:100%;max-height:100%;min-width:0;min-height:0;
object-fit:contain;display:block}
.photoclose{position:absolute;top:12px;right:14px;z-index:5}
@@ -471,22 +475,27 @@ body.photolight-open{overflow:hidden}
样式盖到灯箱按钮上,图标被挤得偏右下。翻页方向只翻图标,不转整个按钮。 */
.photonav.back{left:14px}.photonav.fwd{right:14px}
.photonav.fwd svg{transform:rotate(180deg)}
-.photonav.swiper-button-disabled{opacity:.3;pointer-events:none}
-/* 详情、页码和缩放条覆盖在顶部;右侧给关闭钮留出 58px,不再参与主图尺寸计算。 */
-.photobar{position:absolute;z-index:4;top:12px;left:14px;right:72px;display:grid;
+.photonav.swiper-button-disabled{opacity:0;visibility:hidden;pointer-events:none}
+/* 详情、页码和缩放操作统一落在底部;多图时整体抬到缩略图条上方。 */
+.photobar{position:absolute;z-index:4;bottom:14px;left:14px;right:14px;display:grid;
grid-template-columns:1fr auto 1fr;align-items:center;min-height:48px;pointer-events:none}
+.photolight.has-strip .photobar{bottom:98px}
.photobar>*{pointer-events:auto}
-.photocount{text-align:center;color:rgba(255,255,255,.72);font-size:var(--fs-xs)}
-.photodetailtoggle{justify-self:start;width:30px;height:30px;display:grid;place-items:center;border:0;padding:0;
- border-radius:50%;background:transparent;color:rgba(255,255,255,.72);cursor:pointer}
-.photodetailtoggle:hover,.photodetailtoggle[aria-expanded="true"]{background:rgba(255,255,255,.12);color:#fff}
+.photocount{justify-self:center;padding:7px 11px;border-radius:var(--pill-radius);background:rgba(0,0,0,.6);
+ color:rgba(255,255,255,.82);font-size:var(--fs-xs);backdrop-filter:blur(16px)}
+.photodetailtoggle{justify-self:start;width:40px;height:40px;display:grid;place-items:center;border:0;padding:0;
+ border-radius:50%;background:rgba(0,0,0,.6);color:rgba(255,255,255,.82);cursor:pointer;backdrop-filter:blur(16px)}
+.photodetailtoggle:hover,.photodetailtoggle[aria-expanded="true"]{background:rgba(0,0,0,.78);color:#fff}
.photodetailtoggle svg{width:20px;height:20px;display:block;stroke:currentColor;fill:none;stroke-width:2;
stroke-linecap:round;stroke-linejoin:round}
-.photozoom{justify-self:end;display:flex;align-items:center;gap:8px;color:rgba(255,255,255,.72)}
-.photozoom button{width:24px;height:24px;display:grid;place-items:center;border:0;border-radius:50%;
- padding:0;background:rgba(255,255,255,.12);color:#fff;cursor:pointer}
+.photozoom{justify-self:end;display:flex;align-items:center;gap:7px;padding:4px;border-radius:var(--pill-radius);
+ background:rgba(0,0,0,.6);color:rgba(255,255,255,.82);backdrop-filter:blur(16px)}
+.photozoom button{width:28px;height:28px;display:grid;place-items:center;border:0;border-radius:50%;
+ padding:0;background:transparent;color:#fff;cursor:pointer}
.photozoom button svg{width:15px;height:15px;display:block;stroke:currentColor;fill:none;stroke-width:2}
.photozoom button:hover{background:rgba(255,255,255,.22)}
+.photozoom .photoscale{width:30px}
+.photozoom .photooriginal{width:38px;border-radius:var(--control-radius);font-size:var(--fs-xs)}
.fcollapse{overflow:hidden;transition:height .2s ease-in-out}
/* Geist Skeleton:整页/大区块等待内容结构时先占住稳定区域。 */
@@ -523,7 +532,7 @@ body.photolight-open{overflow:hidden}
.photozoom input::-moz-range-track{height:4px;border-radius:var(--pill-radius);background:rgba(255,255,255,.28)}
.photozoom input::-moz-range-thumb{width:14px;height:14px;border:0;border-radius:50%;background:#fff}
.photozoom b{font-weight:400;font-size:var(--fs-xs);width:38px;text-align:right}
-.photodetail{position:absolute;z-index:5;left:14px;top:68px;width:min(360px,calc(100vw - 28px));
+.photodetail{position:absolute;z-index:5;left:14px;bottom:72px;width:min(360px,calc(100vw - 28px));
box-sizing:border-box;display:grid;align-items:start;gap:14px;padding:16px;
border:1px solid rgba(255,255,255,.16);border-radius:var(--floating-radius);background:rgba(18,18,20,.96);
color:#fff;box-shadow:0 18px 48px rgba(0,0,0,.45),0 2px 8px rgba(0,0,0,.32);backdrop-filter:blur(18px)}
@@ -539,6 +548,7 @@ body.photolight-open{overflow:hidden}
.photodetail>button svg{width:16px;height:16px;display:block;stroke:currentColor;fill:none;stroke-width:2}
.photodetail .srcstate{color:rgba(255,255,255,.62)}
.photodetail .srcstate:empty{display:none}
+.photolight.has-strip .photodetail{bottom:156px}
.photolight .photostrip{position:absolute;z-index:3;left:72px;right:72px;bottom:14px;width:auto;height:72px;padding:0}
.photolight:not(.has-strip) .photostrip{display:none}
.photolight .photostrip .swiper-slide{width:auto;height:72px;opacity:.5;cursor:pointer;border-radius:6px;overflow:hidden}
@@ -549,10 +559,13 @@ body.photolight-open{overflow:hidden}
.photowall{column-count:2;column-gap:8px}
.photosets{grid-template-columns:repeat(auto-fill,minmax(132px,1fr));gap:12px}
.photozoom input{width:72px}.photozoom b{display:none}
- .photolight .photomain .swiper-zoom-container{padding:64px 12px 12px}
- .photolight.has-strip .photomain .swiper-zoom-container{padding-bottom:82px}
- .photobar{left:12px;right:64px;min-height:44px}.photodetailtoggle{width:44px;height:44px}
- .photodetail{left:12px;top:64px;width:calc(100vw - 24px)}.photodetail>button{min-height:44px}
+ .photolight .photomain .swiper-zoom-container{padding:12px 12px 70px}
+ .photolight.has-strip .photomain .swiper-zoom-container{padding-bottom:136px}
+ .photobar{left:12px;right:12px;bottom:10px;min-height:44px}
+ .photolight.has-strip .photobar{bottom:80px}
+ .photodetailtoggle{width:40px;height:40px}
+ .photodetail{left:12px;bottom:62px;width:calc(100vw - 24px)}
+ .photolight.has-strip .photodetail{bottom:132px}.photodetail>button{min-height:44px}
.photolight .photostrip{left:56px;right:56px;bottom:12px}
.photolight .photostrip,.photolight .photostrip .swiper-slide{height:56px}
.photoclose{top:10px;right:10px}.photonav{width:44px;height:44px}.photonav.back{left:8px}.photonav.fwd{right:8px}}
diff --git a/web/app.js b/web/app.js
index d5742f13e..48a0f161d 100644
--- a/web/app.js
+++ b/web/app.js
@@ -2688,8 +2688,8 @@ async function openFollowDetail(id,push=true,mediaIndex=null,preserveReturn=fals
:item.thumb_url
?`<img class="followdetailposter" src="${esc(item.thumb_url)}" alt="${esc(item.title)}" referrerpolicy="no-referrer">`
:`<div class="followdetailplaceholder">${sourceIcon(item.provider)}<span>没有可用预览</span></div>`;
- const imageControls=imageCarousel?`<button class="media-circle followimagearrow prev" data-follow-image-step="-1" aria-label="上一张图片" title="上一张">${icon('chevron-left')}</button>
- <button class="media-circle followimagearrow next" data-follow-image-step="1" aria-label="下一张图片" title="下一张">${icon('chevron-right')}</button>
+ const imageControls=imageCarousel?`<button class="media-circle media-overlay followimagearrow prev" data-follow-image-step="-1" aria-label="上一张图片" title="上一张">${icon('chevron-left')}</button>
+ <button class="media-circle media-overlay followimagearrow next" data-follow-image-step="1" aria-label="下一张图片" title="下一张">${icon('chevron-right')}</button>
<div class="followimagedots" role="group" aria-label="${imageMedia.length} 张图片">${imageMedia.map((image,index)=>`<button data-follow-image-item="${image.index}" aria-current="${index===imagePosition}" aria-label="第 ${index+1} 张,共 ${imageMedia.length} 张" title="第 ${index+1} 张"></button>`).join('')}</div>`:'';
const badges=followBadges({primary:item,variants:[],duplicates:[],has_wip:item.variant_kind==='wip'});
// 卡片只消费 general 内容投影;详情保留来源记录的全部类型,并按类型着色。
@@ -4330,42 +4330,63 @@ const photoSlide=item=>item.follow
?{src:item.src,thumb:item.thumb||item.src,name:item.name||'',asset:null,
source:item.source||'在线图片',size:item.size,position:item.position,total:item.total}
:{src:`/photo?id=${item.id}`,thumb:`/photo-thumb?id=${item.id}`,name:item.name||'',asset:item};
-const loadSwiper=()=>swiperLoader||(swiperLoader=new Promise((resolve,reject)=>{
- const style=document.createElement('link');
- style.rel='stylesheet';style.href='/vendor/swiper/14.2.0/swiper-bundle.min.css';
- document.head.appendChild(style);
- const script=document.createElement('script');
- script.src='/vendor/swiper/14.2.0/swiper-bundle.min.js';
- script.onload=()=>resolve(window.Swiper);
- script.onerror=()=>{swiperLoader=null;reject(new Error('swiper unavailable'))};
- document.head.appendChild(script)}));
+const loadSwiper=()=>swiperLoader||(swiperLoader=Promise.all([
+ new Promise((resolve,reject)=>{
+ const href='/vendor/swiper/14.2.0/swiper-bundle.min.css';
+ const existing=document.querySelector(`link[href="${href}"]`);
+ if(existing?.sheet){resolve();return}
+ const style=existing||document.createElement('link');
+ style.rel='stylesheet';style.href=href;
+ style.addEventListener('load',resolve,{once:true});
+ style.addEventListener('error',()=>reject(new Error('swiper styles unavailable')),{once:true});
+ if(!existing)document.head.appendChild(style)}),
+ window.Swiper?Promise.resolve(window.Swiper):new Promise((resolve,reject)=>{
+ const script=document.createElement('script');
+ script.src='/vendor/swiper/14.2.0/swiper-bundle.min.js';
+ script.onload=()=>resolve(window.Swiper);
+ script.onerror=()=>reject(new Error('swiper unavailable'));
+ document.head.appendChild(script)})
+]).then(([,SwiperCtor])=>SwiperCtor).catch(error=>{swiperLoader=null;throw error}));
const photoLightKeys=e=>{if(e.key!=='Escape')return;
e.preventDefault();e.stopImmediatePropagation();
if(activeLightbox?.detail?.isOpen()){activeLightbox.detail.dismiss(true);return}
closePhotoLightbox()};
-const ZOOM_MAX=4;
+const PHOTO_ZOOM_MIN=10,PHOTO_ZOOM_MAX=400,PHOTO_ZOOM_STEP=10;
-/* 缩放条。Swiper 的 zoom 模块只给 in/out/toggle,没有「缩到这个倍数」的入口,
- 但 `zoom.in()` 用的就是 `params.zoom.maxRatio`——先改上限再 in,就等于设定值。
- 双击和触控板捏合仍由模块自己处理,`zoomChange` 负责把滑块同步回来。 */
+/* 缩放条显示相对原图像素的百分比,而不是相对「适应窗口」的变换倍数。
+ 因此大图初始可能是 34%,原大小才是 100%;Swiper 14 的 zoom.in(number)
+ 能直接接收目标倍数,既可低于 1 也可高于 1。 */
function wirePhotoZoom(box, main){
const slider=box.querySelector('.photozoom input');
const label=box.querySelector('.photozoom b');
- const show=scale=>{slider.value=scale;label.textContent=Math.round(scale*100)+'%'};
+ let target='fit';
+ const image=()=>main.slides[main.activeIndex]?.querySelector('img');
+ const fitPercent=()=>{
+ const img=image();
+ if(!img?.naturalWidth||!img.naturalHeight)return 100;
+ return Math.min(100,img.offsetWidth/img.naturalWidth*100,img.offsetHeight/img.naturalHeight*100)
+ };
+ const show=percent=>{const value=Math.round(percent);slider.value=value;label.textContent=value+'%'};
const apply=raw=>{
- const scale=Math.min(ZOOM_MAX,Math.max(1,Math.round(raw*10)/10));
- show(scale);
- if(scale<=1){main.zoom.out();return}
- main.params.zoom.maxRatio=scale;main.zoom.in();
+ const fit=fitPercent();
+ const percent=raw==='fit'?fit:Math.min(PHOTO_ZOOM_MAX,Math.max(PHOTO_ZOOM_MIN,Number(raw)||fit));
+ target=raw==='fit'?'fit':percent;show(percent);
+ const ratio=percent/fit;
+ if(Math.abs(ratio-1)<.001)main.zoom.out();
+ else main.zoom.in(ratio);
};
+ const reset=()=>requestAnimationFrame(()=>apply('fit'));
slider.oninput=()=>apply(Number(slider.value));
box.querySelectorAll('[data-zoom-step]').forEach(b=>
- b.onclick=()=>apply(Number(slider.value)+Number(b.dataset.zoomStep)*0.5));
- // 翻页会把缩放清回 1,滑块得跟着回位,否则它显示 200% 而图是原始大小。
- main.on('slideChange',()=>show(1));
- // `zoomChange` 的第一个参数是 swiper 实例,倍数在第二个;接错了滑块会写进 NaN。
- main.on('zoomChange',(_swiper,scale)=>show(Math.min(ZOOM_MAX,Math.max(1,scale||1))));
- return {show};
+ b.onclick=()=>apply(Number(slider.value)+Number(b.dataset.zoomStep)*PHOTO_ZOOM_STEP));
+ box.querySelector('[data-photo-scale="fit"]').onclick=()=>apply('fit');
+ box.querySelector('[data-photo-scale="original"]').onclick=()=>apply(100);
+ main.on('slideChange',reset);
+ main.on('zoomChange',(_swiper,scale)=>{if(scale)show(fitPercent()*scale)});
+ box.querySelectorAll('.photomain img').forEach(img=>{
+ if(!img.complete)img.addEventListener('load',()=>{if(img===image())apply(target)})});
+ reset();
+ return {resize:()=>apply(target)};
}
/* 图片详情只展示安全元数据,定位仍只把 asset id 交给服务端。绝不能为了显示路径把
@@ -4429,12 +4450,12 @@ async function openPhotoLightbox(index,source=null){
closePhotoLightbox();
const box=document.createElement('div');
box.className='photolight'+(items.length>1?' has-strip':'');
- box.innerHTML=`<button class="media-circle photoclose" type="button" aria-label="关闭">${icon('x')}</button>
+ box.innerHTML=`<button class="media-circle media-overlay photoclose" type="button" aria-label="关闭">${icon('x')}</button>
<div class="swiper photomain"><div class="swiper-wrapper">${items.map(item=>
`<div class="swiper-slide"><div class="swiper-zoom-container"><img src="${esc(item.src)}"
alt="${esc(item.name)}" loading="lazy" referrerpolicy="no-referrer"></div></div>`).join('')}</div>
- <button class="media-circle photonav back" type="button" aria-label="上一张">${icon('chevron-left')}</button>
- <button class="media-circle photonav fwd" type="button" aria-label="下一张">${icon('chevron-left')}</button></div>
+ <button class="media-circle media-overlay photonav back" type="button" aria-label="上一张">${icon('chevron-left')}</button>
+ <button class="media-circle media-overlay photonav fwd" type="button" aria-label="下一张">${icon('chevron-left')}</button></div>
<div class="photobar">
<button class="photodetailtoggle" type="button" aria-expanded="false" aria-controls="photoDetail"
aria-haspopup="dialog"
@@ -4442,9 +4463,12 @@ async function openPhotoLightbox(index,source=null){
<div class="photocount mono" aria-live="polite">${index+1} / ${items.length}</div>
<div class="photozoom">
<button type="button" data-zoom-step="-1" aria-label="缩小">${icon('minus')}</button>
- <input type="range" min="1" max="${ZOOM_MAX}" step="0.1" value="1" aria-label="缩放">
+ <input type="range" min="${PHOTO_ZOOM_MIN}" max="${PHOTO_ZOOM_MAX}" step="1" value="100" aria-label="缩放">
<button type="button" data-zoom-step="1" aria-label="放大">${icon('plus')}</button>
- <b class="mono">100%</b></div></div>
+ <b class="mono">100%</b>
+ <button class="photoscale" type="button" data-photo-scale="fit" aria-label="适应窗口" title="适应窗口">${icon('maximize')}</button>
+ <button class="photoscale photooriginal mono" type="button" data-photo-scale="original" aria-label="原大小" title="原大小">1:1</button>
+ </div></div>
<section class="photodetail" id="photoDetail" role="dialog" aria-modal="false"
aria-labelledby="photoDetailTitle" hidden>
<div class="photodetailcopy"><h2 id="photoDetailTitle" data-middle-truncate tabindex="-1"></h2><span class="photodetailmeta"></span></div>
@@ -4458,21 +4482,24 @@ async function openPhotoLightbox(index,source=null){
const counter=box.querySelector('.photocount');
const strip=new SwiperCtor(box.querySelector('.photostrip'),{
slidesPerView:'auto',spaceBetween:8,freeMode:true,watchSlidesProgress:true,
- centeredSlides:true,centeredSlidesBounds:true,slideToClickedSlide:true});
+ centeredSlides:true,slideToClickedSlide:true});
+ const centerThumb=(at,speed=200)=>strip.slideTo(at,speed);
const main=new SwiperCtor(box.querySelector('.photomain'),{
- initialSlide:index,zoom:{maxRatio:ZOOM_MAX},keyboard:{enabled:true},lazyPreloadPrevNext:1,
+ initialSlide:index,zoom:{minRatio:.01,maxRatio:100},keyboard:{enabled:true},lazyPreloadPrevNext:1,
// 上下滚也翻页:看图时手在滚轮上,没人愿意为了换一张去够左右键或按钮。
mousewheel:{enabled:true,forceToAxis:false},
thumbs:{swiper:strip},
navigation:{prevEl:box.querySelector('.photonav.back'),nextEl:box.querySelector('.photonav.fwd')},
- on:{slideChange(){counter.textContent=`${this.activeIndex+1} / ${items.length}`}}});
+ on:{slideChange(){counter.textContent=`${this.activeIndex+1} / ${items.length}`;
+ centerThumb(this.activeIndex)}}});
+ centerThumb(index,0);
const zoomBar=wirePhotoZoom(box,main);
const detail=wirePhotoDetail(box,items,index);
main.on('slideChange',()=>detail.paint(main.activeIndex));
/* Swiper 只在自己构造的那一刻量一次容器。灯箱是插进已经布好版的页面里的,
窗口一改大小(或首屏字体、滚动条落定得比构造晚)slide 就停在旧宽度上,
大图按错误的框缩放,看起来就是「显示不全」。挂个 ResizeObserver 让它重量。 */
- const resize=new ResizeObserver(()=>{main.update();strip.update()});
+ const resize=new ResizeObserver(()=>{main.update();strip.update();zoomBar.resize()});
resize.observe(box);
activeLightbox={box,main,strip,resize,zoomBar,detail};
box.querySelector('.photoclose').onclick=closePhotoLightbox;