From 1e3a1f6b9ad39dcd506bad93ed31d1594a3c0a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chen=20Quan=20/=20=E9=99=88=E5=85=A8?= Date: Tue, 17 Nov 2026 15:17:50 +0800 Subject: [PATCH] fix: keep all 24 cat comics accessible without scripts --- scripts/runtime-files.mjs | 27 +++ src/home/album/README.md | 9 + src/home/album/cat-album.css | 36 ++++ src/home/album/cat-album.html | 53 ++++++ src/home/album/cat-album.mjs | 11 +- .../album/pages/cat-album-air-burial.html | 32 ++++ .../album/pages/cat-album-all-innocent.html | 32 ++++ .../pages/cat-album-bedroom-edition.html | 32 ++++ .../album/pages/cat-album-blanket-move.html | 32 ++++ src/home/album/pages/cat-album-boss.html | 32 ++++ .../album/pages/cat-album-dont-throw.html | 32 ++++ .../album/pages/cat-album-evening-show.html | 32 ++++ .../pages/cat-album-expression-check.html | 32 ++++ src/home/album/pages/cat-album-got-it.html | 32 ++++ .../pages/cat-album-grooming-service.html | 32 ++++ src/home/album/pages/cat-album-last-bite.html | 32 ++++ .../album/pages/cat-album-models-ready.html | 32 ++++ src/home/album/pages/cat-album-new-bed.html | 32 ++++ src/home/album/pages/cat-album-on-time.html | 32 ++++ .../album/pages/cat-album-open-is-enough.html | 32 ++++ .../album/pages/cat-album-photo-retake.html | 32 ++++ .../pages/cat-album-same-destination.html | 32 ++++ .../album/pages/cat-album-squeeze-in.html | 32 ++++ .../album/pages/cat-album-standby-sound.html | 32 ++++ .../album/pages/cat-album-substitute.html | 32 ++++ .../album/pages/cat-album-tail-please.html | 32 ++++ .../album/pages/cat-album-third-exit.html | 32 ++++ src/home/album/pages/cat-album-warmth.html | 32 ++++ .../pages/cat-album-window-audience.html | 32 ++++ src/home/index.html | 8 +- tests/delivery/cat-album-delivery.test.mjs | 99 ++++++++++- tests/delivery/cat-guide-delivery.test.mjs | 2 +- tests/delivery/delivery.test.mjs | 28 ++- tests/home/cat-album-ui.test.mjs | 161 ++++++++++++++++++ 34 files changed, 1191 insertions(+), 11 deletions(-) create mode 100644 src/home/album/README.md create mode 100644 src/home/album/cat-album.html create mode 100644 src/home/album/pages/cat-album-air-burial.html create mode 100644 src/home/album/pages/cat-album-all-innocent.html create mode 100644 src/home/album/pages/cat-album-bedroom-edition.html create mode 100644 src/home/album/pages/cat-album-blanket-move.html create mode 100644 src/home/album/pages/cat-album-boss.html create mode 100644 src/home/album/pages/cat-album-dont-throw.html create mode 100644 src/home/album/pages/cat-album-evening-show.html create mode 100644 src/home/album/pages/cat-album-expression-check.html create mode 100644 src/home/album/pages/cat-album-got-it.html create mode 100644 src/home/album/pages/cat-album-grooming-service.html create mode 100644 src/home/album/pages/cat-album-last-bite.html create mode 100644 src/home/album/pages/cat-album-models-ready.html create mode 100644 src/home/album/pages/cat-album-new-bed.html create mode 100644 src/home/album/pages/cat-album-on-time.html create mode 100644 src/home/album/pages/cat-album-open-is-enough.html create mode 100644 src/home/album/pages/cat-album-photo-retake.html create mode 100644 src/home/album/pages/cat-album-same-destination.html create mode 100644 src/home/album/pages/cat-album-squeeze-in.html create mode 100644 src/home/album/pages/cat-album-standby-sound.html create mode 100644 src/home/album/pages/cat-album-substitute.html create mode 100644 src/home/album/pages/cat-album-tail-please.html create mode 100644 src/home/album/pages/cat-album-third-exit.html create mode 100644 src/home/album/pages/cat-album-warmth.html create mode 100644 src/home/album/pages/cat-album-window-audience.html create mode 100644 tests/home/cat-album-ui.test.mjs diff --git a/scripts/runtime-files.mjs b/scripts/runtime-files.mjs index bfdb1d4..edc1df4 100644 --- a/scripts/runtime-files.mjs +++ b/scripts/runtime-files.mjs @@ -83,7 +83,34 @@ const groups = { "cat-comic-warmth.jpg", "cat-comic-window-audience.jpg", ], + "src/home/album/pages": [ + "cat-album-standby-sound.html", + "cat-album-third-exit.html", + "cat-album-blanket-move.html", + "cat-album-window-audience.html", + "cat-album-open-is-enough.html", + "cat-album-dont-throw.html", + "cat-album-expression-check.html", + "cat-album-grooming-service.html", + "cat-album-squeeze-in.html", + "cat-album-models-ready.html", + "cat-album-same-destination.html", + "cat-album-tail-please.html", + "cat-album-on-time.html", + "cat-album-all-innocent.html", + "cat-album-got-it.html", + "cat-album-air-burial.html", + "cat-album-photo-retake.html", + "cat-album-bedroom-edition.html", + "cat-album-evening-show.html", + "cat-album-last-bite.html", + "cat-album-new-bed.html", + "cat-album-substitute.html", + "cat-album-boss.html", + "cat-album-warmth.html", + ], "src/home/album": [ + "cat-album.html", "cat-album-episodes.mjs", "cat-album.css", "cat-album.mjs", diff --git a/src/home/album/README.md b/src/home/album/README.md new file mode 100644 index 0000000..cbb144d --- /dev/null +++ b/src/home/album/README.md @@ -0,0 +1,9 @@ +# 三猫小相册 + +- `cat-album-episodes.mjs` 是已批准公开的漫画目录,按新到旧排列;不要扫描素材源文件夹来自动补齐。 +- 首页正常点击由 `cat-album.mjs` 打开原弹窗;真实链接始终指向 `cat-album.html`,脚本或弹窗不可用时仍能进入完整目录。 +- `cat-album.html` 和 `pages/` 是目录的静态阅读副本。目录不放漫画大图,单篇页只加载所选的一张,且没有脚本依赖。原生图片懒加载在关闭脚本时可能失效,所以不能把整册图片放进隐藏区域当后备。 +- 新漫画经确认后,更新目录、静态目录与阅读页、首页显示总数,以及 `scripts/runtime-files.mjs` 和交付文件清单。阅读页首尾循环,新增一期也要同步页码与相邻链接。 +- `tests/delivery/cat-album-delivery.test.mjs` 精确核对所有页面的标题、说明、图片、顺序、总数和前后链接,防止静态副本与弹窗内容分叉;`tests/home/cat-album-ui.test.mjs` 覆盖弹窗与失败降级。 + +修改后运行 `npm run verify`,并实际检查正常点击、禁用脚本、脚本请求失败、手机尺寸和键盘翻阅。没有发布授权时只交付本地预览。 diff --git a/src/home/album/cat-album.css b/src/home/album/cat-album.css index 3c5369d..a9a408f 100644 --- a/src/home/album/cat-album.css +++ b/src/home/album/cat-album.css @@ -187,3 +187,39 @@ body:has(.cat-album-dialog[open]) { overflow: hidden; } object-position: center bottom; } .cat-cast-list strong { color: var(--home-ink); } + +.cat-album-header p a { display: inline-flex; align-items: center; min-height: 44px; color: var(--home-accent); text-decoration: underline; text-underline-offset: 3px; } +.cat-album-library { min-height: 100dvh; background: var(--home-bg); color: var(--home-ink); } +.cat-album-return { display: inline-flex; align-items: center; min-height: 44px; color: var(--home-accent); font-size: 14px; } +.cat-album-library-main { width: min(100% - 40px, 760px); margin: 42px auto 64px; } +.cat-album-library-heading { display: flex; align-items: center; gap: 22px; margin-bottom: 28px; } +.cat-album-library-heading > img { width: 76px; height: 95px; border-radius: 8px; transform: rotate(-5deg); } +.cat-album-library-heading h1 { font-size: clamp(28px, 5vw, 42px); line-height: 1.2; letter-spacing: -.04em; } +.cat-album-library-heading p { margin-top: 10px; color: var(--home-muted); font-size: 15px; line-height: 1.6; } +.cat-album-chapters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } +.cat-album-chapter { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 62px; padding: 15px 20px; border: 1px solid var(--home-line); border-radius: 14px; background: var(--home-surface); font-size: 17px; font-weight: 650; } +.cat-album-chapter::after { content: '›'; color: var(--home-accent); font-size: 24px; } +.cat-album-chapter:hover { border-color: var(--home-accent); } +.cat-album-chapter:active { background: var(--home-bg); } +.cat-album-reading-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 20px; } +.cat-album-reading-heading h1 { font-size: clamp(26px, 5vw, 40px); letter-spacing: -.04em; } +#cat-album-reading-count { flex: none; color: var(--home-muted); font-size: 14px; font-variant-numeric: tabular-nums; } +.cat-album-reading-nav { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-block: 8px; border-block: 1px solid var(--home-line); background: var(--home-bg); } +.cat-album-reading-nav a { display: flex; align-items: center; justify-content: center; min-height: 44px; padding-inline: 12px; border-radius: 9px; color: var(--home-accent); font-size: 14px; font-weight: 650; } +.cat-album-reading-nav a:hover { background: var(--home-surface); } +.cat-album-reading-figure figcaption { margin-block: 18px; font-size: 15px; line-height: 1.6; color: var(--home-muted); } +.cat-album-reading-figure img { display: block; width: 100%; height: auto; border-radius: 5px; background: #fff7e9; } +.cat-album-original { display: inline-flex; align-items: center; min-height: 44px; color: var(--home-accent); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; } +.cat-album-library-end { margin-top: 30px; color: var(--home-muted); font-size: 14px; line-height: 1.7; } +.cat-album-library-end a { display: inline-flex; align-items: center; min-height: 44px; color: var(--home-accent); text-decoration: underline; text-underline-offset: 3px; } +@media (prefers-color-scheme: dark) { + .cat-album-library { color-scheme: dark; --home-bg: #101012; --home-surface: #1c1c1e; --home-ink: #f5f5f7; --home-muted: #a9a9b0; --home-accent: #ff94c5; --home-line: #37373b; } +} +@media (max-width: 520px) { + .cat-album-library-main { width: calc(100% - 32px); margin-top: 28px; } + .cat-album-library-heading { gap: 16px; } + .cat-album-library-heading > img { width: 56px; height: 70px; } + .cat-album-library-heading p { font-size: 13px; } + .cat-album-chapters { grid-template-columns: 1fr; } + .cat-album-chapter { padding-inline: 15px; } +} diff --git a/src/home/album/cat-album.html b/src/home/album/cat-album.html new file mode 100644 index 0000000..8020fab --- /dev/null +++ b/src/home/album/cat-album.html @@ -0,0 +1,53 @@ + + + + + + + + + + 三猫小相册 · 算法游乐场 + + + +
+ 算法游乐场 + 回去玩 +
+
+
+ +

三猫小相册

全部 24 篇。点一个标题,慢慢看。

+
+ +

看完了?回去陪三猫玩算法

+
+ + diff --git a/src/home/album/cat-album.mjs b/src/home/album/cat-album.mjs index f54d17c..c50c9a0 100644 --- a/src/home/album/cat-album.mjs +++ b/src/home/album/cat-album.mjs @@ -39,12 +39,17 @@ if (entry && typeof dialog?.showModal === 'function') { entry.addEventListener('click', event => { if (event.defaultPrevented || event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return; - event.preventDefault(); if (!dialog.open) { - render(); - dialog.showModal(); + try { + render(); + dialog.showModal(); + } catch { + // Keep the real album link usable if this browser cannot open the dialog. + return; + } close.focus(); } + event.preventDefault(); }); document.getElementById('cat-album-prev').addEventListener('click', () => turn(-1)); document.getElementById('cat-album-next').addEventListener('click', () => turn(1)); diff --git a/src/home/album/pages/cat-album-air-burial.html b/src/home/album/pages/cat-album-air-burial.html new file mode 100644 index 0000000..ba6e3e7 --- /dev/null +++ b/src/home/album/pages/cat-album-air-burial.html @@ -0,0 +1,32 @@ + + + + + + + + + + 空气施工 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

空气施工

16 / 24
+ +
+
忙活了半天,沙子一粒没动。
+ 五格漫画。臭臭认真在猫砂盆的入口和内壁刨了几下,嘿姆和波比来验收,发现沙子没动。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-all-innocent.html b/src/home/album/pages/cat-album-all-innocent.html new file mode 100644 index 0000000..995708f --- /dev/null +++ b/src/home/album/pages/cat-album-all-innocent.html @@ -0,0 +1,32 @@ + + + + + + + + + + 全员无辜 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

全员无辜

14 / 24
+ +
+
脸上在澄清,嘴巴在招供。
+ 四格漫画。三猫对着散落的碎纸一脸无辜,波比当面又忍不住咬纸。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-bedroom-edition.html b/src/home/album/pages/cat-album-bedroom-edition.html new file mode 100644 index 0000000..860ba80 --- /dev/null +++ b/src/home/album/pages/cat-album-bedroom-edition.html @@ -0,0 +1,32 @@ + + + + + + + + + + 卧室限定版 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

卧室限定版

18 / 24
+ +
+
另外两位已关机,嘿姆还在值夜班。
+ 四格漫画。波比和臭臭在门外睡觉,嘿姆探望卧室,最后在床脚朝门口守着。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-blanket-move.html b/src/home/album/pages/cat-album-blanket-move.html new file mode 100644 index 0000000..c8eb4bd --- /dev/null +++ b/src/home/album/pages/cat-album-blanket-move.html @@ -0,0 +1,32 @@ + + + + + + + + + + 毯子搬家 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

毯子搬家

3 / 24
+ +
+
喊走了嘿姆,忘了自己的脚。
+ 四格漫画。波比请嘿姆挪开还是拖不动毯子,臭臭指出波比自己的后脚正踩着它。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-boss.html b/src/home/album/pages/cat-album-boss.html new file mode 100644 index 0000000..b180168 --- /dev/null +++ b/src/home/album/pages/cat-album-boss.html @@ -0,0 +1,32 @@ + + + + + + + + + + 老板还没起床 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

老板还没起床

23 / 24
+ +
+
老板还没醒,工作室已经开工了。
+ 三格漫画。嘿姆招呼大家开会,接着追着波比跑。三只猫把早上的热闹都包办了。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-dont-throw.html b/src/home/album/pages/cat-album-dont-throw.html new file mode 100644 index 0000000..2e56f06 --- /dev/null +++ b/src/home/album/pages/cat-album-dont-throw.html @@ -0,0 +1,32 @@ + + + + + + + + + + 别扔! · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

别扔!

6 / 24
+ +
+
臭臭负责舒服,波比负责回收。
+ 四格漫画。臭臭等梳毛,波比把梳下来的小毛团护住,当球拨着玩。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-evening-show.html b/src/home/album/pages/cat-album-evening-show.html new file mode 100644 index 0000000..8b62e0d --- /dev/null +++ b/src/home/album/pages/cat-album-evening-show.html @@ -0,0 +1,32 @@ + + + + + + + + + + 晚间固定节目 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

晚间固定节目

19 / 24
+ +
+
晚间节目开场了。
+ 五格漫画。夜里嘿姆追波比,波比躲上猫爬架,臭臭在沙发旁围观。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-expression-check.html b/src/home/album/pages/cat-album-expression-check.html new file mode 100644 index 0000000..2b99fd9 --- /dev/null +++ b/src/home/album/pages/cat-album-expression-check.html @@ -0,0 +1,32 @@ + + + + + + + + + + 表情验收 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

表情验收

7 / 24
+ +
+
态度改了,眉头还在值班。
+ 四格漫画。嘿姆嫌自己的打印小像太凶,坐在旁边示范温柔,却和小像更像了。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-got-it.html b/src/home/album/pages/cat-album-got-it.html new file mode 100644 index 0000000..b974b2f --- /dev/null +++ b/src/home/album/pages/cat-album-got-it.html @@ -0,0 +1,32 @@ + + + + + + + + + + 抓到了 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

抓到了

15 / 24
+ +
+
两路包抄,包到了人家的午觉。
+ 四格漫画。嘿姆安排包抄,波比扑住羽毛,却发现逗猫棒另一端被臭臭枕着。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-grooming-service.html b/src/home/album/pages/cat-album-grooming-service.html new file mode 100644 index 0000000..44d7423 --- /dev/null +++ b/src/home/album/pages/cat-album-grooming-service.html @@ -0,0 +1,32 @@ + + + + + + + + + + 顺毛服务 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

顺毛服务

8 / 24
+ +
+
早期虚构小剧场。毛是顺了,天线也立好了。
+ 四格虚构漫画。臭臭帮波比顺平毛撮,毛撮反而翘成一根小天线,嘿姆在一旁点评。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-last-bite.html b/src/home/album/pages/cat-album-last-bite.html new file mode 100644 index 0000000..e92d66d --- /dev/null +++ b/src/home/album/pages/cat-album-last-bite.html @@ -0,0 +1,32 @@ + + + + + + + + + + 最后一口 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

最后一口

20 / 24
+ +
+
你们慢慢客气,我先不客气了。
+ 四格漫画。嘿姆和波比互让最后一粒零食,臭臭先把它吃掉了。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-models-ready.html b/src/home/album/pages/cat-album-models-ready.html new file mode 100644 index 0000000..3dde9a8 --- /dev/null +++ b/src/home/album/pages/cat-album-models-ready.html @@ -0,0 +1,32 @@ + + + + + + + + + + 模特到齐 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

模特到齐

10 / 24
+ +
+
模特一个不少,空白一点不剩。
+ 五格漫画。三只猫先后在手账上摆好姿势,也把画画的位置全占了。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-new-bed.html b/src/home/album/pages/cat-album-new-bed.html new file mode 100644 index 0000000..b0c02e3 --- /dev/null +++ b/src/home/album/pages/cat-album-new-bed.html @@ -0,0 +1,32 @@ + + + + + + + + + + 新窝验收 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

新窝验收

21 / 24
+ +
+
嘿姆忙着验收,波比已经入住。
+ 四格漫画。嘿姆转去验收纸箱,波比趁机住进新猫窝。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-on-time.html b/src/home/album/pages/cat-album-on-time.html new file mode 100644 index 0000000..f1820cb --- /dev/null +++ b/src/home/album/pages/cat-album-on-time.html @@ -0,0 +1,32 @@ + + + + + + + + + + 到点了 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

到点了

13 / 24
+ +
+
两位等开饭,一位等开梳。
+ 四格漫画。嘿姆和波比准时等饭,臭臭守着的却是梳子。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-open-is-enough.html b/src/home/album/pages/cat-album-open-is-enough.html new file mode 100644 index 0000000..8ed7c3f --- /dev/null +++ b/src/home/album/pages/cat-album-open-is-enough.html @@ -0,0 +1,32 @@ + + + + + + + + + + 开了就行 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

开了就行

5 / 24
+ +
+
门负责通行,猫负责堵门。
+ 四格漫画。嘿姆催开门,门一开,三猫却并排趴在门槛上。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-photo-retake.html b/src/home/album/pages/cat-album-photo-retake.html new file mode 100644 index 0000000..2fa5c06 --- /dev/null +++ b/src/home/album/pages/cat-album-photo-retake.html @@ -0,0 +1,32 @@ + + + + + + + + + + 这张不算 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

这张不算

17 / 24
+ +
+
盯紧了全场,没盯住自己的哈欠。
+ 四格漫画。三猫准备合影,监督拍照的嘿姆偏偏被拍到了哈欠。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-same-destination.html b/src/home/album/pages/cat-album-same-destination.html new file mode 100644 index 0000000..a7d8674 --- /dev/null +++ b/src/home/album/pages/cat-album-same-destination.html @@ -0,0 +1,32 @@ + + + + + + + + + + 谁跟着谁 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

谁跟着谁

11 / 24
+ +
+
绕了半个家,原来都奔着同一袋。
+ 四格漫画。波比以为嘿姆在跟踪自己,绕路后才发现臭臭早就在零食袋前等着了。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-squeeze-in.html b/src/home/album/pages/cat-album-squeeze-in.html new file mode 100644 index 0000000..39a4d44 --- /dev/null +++ b/src/home/album/pages/cat-album-squeeze-in.html @@ -0,0 +1,32 @@ + + + + + + + + + + 挤一挤 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

挤一挤

9 / 24
+ +
+
说好各占一点,最后挤成一碗。
+ 四格漫画。三猫轮流挤上豆袋,软软的坐面一点点陷下去。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-standby-sound.html b/src/home/album/pages/cat-album-standby-sound.html new file mode 100644 index 0000000..45055e2 --- /dev/null +++ b/src/home/album/pages/cat-album-standby-sound.html @@ -0,0 +1,32 @@ + + + + + + + + + + 待机声 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

待机声

1 / 24
+ +
+
打印机还没开,老大已经在待机了。
+ 四格漫画。波比和臭臭循着嗡声找到工作台,机器还没开,桌下的嘿姆却睡得正香。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-substitute.html b/src/home/album/pages/cat-album-substitute.html new file mode 100644 index 0000000..22a1162 --- /dev/null +++ b/src/home/album/pages/cat-album-substitute.html @@ -0,0 +1,32 @@ + + + + + + + + + + 替身计划,只撑了三秒 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

替身计划,只撑了三秒

22 / 24
+ +
+
波比打印了一个替身,以为自己终于能清静一会儿。
+ 四格漫画。波比打印了一个替身。嘿姆打量替身,波比却先按捺不住,最后被追的还是波比。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-tail-please.html b/src/home/album/pages/cat-album-tail-please.html new file mode 100644 index 0000000..4c3e543 --- /dev/null +++ b/src/home/album/pages/cat-album-tail-please.html @@ -0,0 +1,32 @@ + + + + + + + + + + 尾巴借过 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

尾巴借过

12 / 24
+ +
+
路借到了,尾巴忘收了。
+ 四格漫画。嘿姆收尾让波比通过,波比经过时自己的尾巴却蹭到了嘿姆脸边。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-third-exit.html b/src/home/album/pages/cat-album-third-exit.html new file mode 100644 index 0000000..0866ed4 --- /dev/null +++ b/src/home/album/pages/cat-album-third-exit.html @@ -0,0 +1,32 @@ + + + + + + + + + + 第三个出口 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

第三个出口

2 / 24
+ +
+
两头都在催,只好走天窗。
+ 四格漫画。嘿姆和波比分别守在隧道两头,臭臭从中间的圆洞探出头。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-warmth.html b/src/home/album/pages/cat-album-warmth.html new file mode 100644 index 0000000..5fd3acb --- /dev/null +++ b/src/home/album/pages/cat-album-warmth.html @@ -0,0 +1,32 @@ + + + + + + + + + + 保温测试 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

保温测试

24 / 24
+ +
+
阳光挪了窝,波比没挪成。
+ 四格漫画。阳光移开了,波比想继续晒太阳,却没能顺利挪到新的位置。 +
+ 查看原图 +
+ + diff --git a/src/home/album/pages/cat-album-window-audience.html b/src/home/album/pages/cat-album-window-audience.html new file mode 100644 index 0000000..845614f --- /dev/null +++ b/src/home/album/pages/cat-album-window-audience.html @@ -0,0 +1,32 @@ + + + + + + + + + + 窗外的观众 · 三猫小相册 + + + +
+ 算法游乐场 + 回去玩 +
+
+

窗外的观众

4 / 24
+ +
+
看鸟看着看着,自己成了节目。
+ 四格漫画。三猫在玻璃内看鸟,鸟越聚越多,转头看回窗里的三只猫。 +
+ 查看原图 +
+ + diff --git a/src/home/index.html b/src/home/index.html index 291fc47..32f518d 100644 --- a/src/home/index.html +++ b/src/home/index.html @@ -6,7 +6,7 @@ - + 算法游乐场 · 算法,玩着就懂了 @@ -24,9 +24,9 @@
A* 寻路演示 · 找到路,三猫再出发
改一格,给三猫找近路 - + - 三猫小相册玩累了,翻一篇漫画 + 三猫小相册24 篇漫画,选一篇歇歇 @@ -34,7 +34,7 @@
-

三猫小剧场

玩累了,翻一篇漫画。

+

三猫小剧场

查看全部 24 篇

diff --git a/tests/delivery/cat-album-delivery.test.mjs b/tests/delivery/cat-album-delivery.test.mjs index 8f6ec94..95a6b87 100644 --- a/tests/delivery/cat-album-delivery.test.mjs +++ b/tests/delivery/cat-album-delivery.test.mjs @@ -5,26 +5,121 @@ import {join} from 'node:path'; import {tmpdir} from 'node:os'; import {build} from '../../scripts/build.mjs'; import {startServer} from '../../scripts/serve.mjs'; +import {episodes} from '../../src/home/album/cat-album-episodes.mjs'; const assets = [ - 'cat-album.css', 'cat-album.mjs', 'cat-album-cover.jpg', + 'cat-album.html', 'cat-album.css', 'cat-album.mjs', 'cat-album-cover.jpg', 'cat-comic-substitute.jpg', 'cat-comic-boss.jpg', 'cat-comic-warmth.jpg', ]; +const chapterFile = episode => episode.file.replace(/^cat-comic-/, 'cat-album-').replace(/\.jpg$/, '.html'); +const decode = value => value.replace(/&(?:amp|lt|gt|quot|apos|#39|#\d+|#x[0-9a-f]+);/gi, entity => { + const named = {'&':'&', '<':'<', '>':'>', '"':'"', ''':"'", ''':"'"}; + if (Object.hasOwn(named, entity.toLowerCase())) return named[entity.toLowerCase()]; + return String.fromCodePoint(entity[2].toLowerCase() === 'x' + ? parseInt(entity.slice(3, -1), 16) : parseInt(entity.slice(2, -1), 10)); +}); +const text = markup => decode(markup.replace(/<[^>]*>/g, '')).replace(/\s+/g, ' ').trim(); +const attributes = markup => Object.fromEntries([...markup.matchAll(/([\w-]+)\s*=\s*(["'])(.*?)\2/g)] + .map(([, name, , value]) => [name, decode(value)])); +const links = html => [...html.matchAll(/]*)>([\s\S]*?)<\/a>/gi)] + .map(([, attrs, content]) => ({attributes: attributes(attrs), text: text(content)})); +const hasClass = (element, name) => (element.attributes.class ?? '').split(/\s+/).includes(name); + +function elementById(html, id) { + const elements = [...html.matchAll(new RegExp(`<([a-z][\\w:-]*)\\b([^>]*\\bid=["']${id}["'][^>]*)>([\\s\\S]*?)<\\/\\1>`, 'gi'))]; + assert.equal(elements.length, 1, `${id} appears exactly once`); + return {attributes: attributes(elements[0][2]), text: text(elements[0][3])}; +} + +function assertVisibleTotals(html, expectedOccurrences, label) { + const totals = [...html.matchAll(/<([a-z][\w:-]*)\b([^>]*\bdata-album-total=["'][^"']*["'][^>]*)>([\s\S]*?)<\/\1>/gi)]; + assert.equal(totals.length, expectedOccurrences, `${label} exposes each displayed album total`); + for (const [, , attrs, content] of totals) { + assert.equal(attributes(attrs)['data-album-total'], String(episodes.length), label); + assert.match(text(content), new RegExp(`(?:^|[^\\d])${episodes.length}\\s*篇`), `${label} visible count matches the catalog`); + assert.doesNotMatch(attrs, /\b(?:hidden|aria-hidden\s*=\s*["']true["'])/, `${label} count is visible`); + } +} + test('the built homepage has an optional album beside the still-working experiment link', async () => { const out = await mkdtemp(join(tmpdir(), 'cat-album-build-')); try { await build(undefined, out); const home = await readFile(join(out, 'index.html'), 'utf8'); assert.match(home, /href="\.\/pathfinding\.html#path-lab"/); - assert.match(home, /href="\.\/cat-comic-standby-sound\.jpg"[^>]*id="cat-album-entry"/); + assert.match(home, /href="\.\/cat-album\.html"[^>]*id="cat-album-entry"/); assert.match(home, /]+aria-labelledby="cat-album-title"/); for (const asset of assets) assert.ok((await readFile(join(out, asset))).length > 0, asset); + for (const episode of episodes) assert.ok((await readFile(join(out, chapterFile(episode)))).length > 0, episode.title); } finally { await rm(out, {recursive:true, force:true}); } }); +test('the no-script album directory lists every chapter without requesting full comic images', async () => { + const server = await startServer({port:0}); + const base = 'http://127.0.0.1:' + server.address().port; + try { + const home = await (await fetch(base)).text(); + assertVisibleTotals(home, 2, 'homepage'); + const href = elementById(home, 'cat-album-entry').attributes.href; + assert.equal(href, './cat-album.html'); + const response = await fetch(new URL(href, base)); + assert.equal(response.status, 200); + assert.match(response.headers.get('content-type'), /text\/html/, 'a failed module must not send readers to one JPEG'); + const html = await response.text(); + assert.equal([...html.matchAll(/]*cat-comic-/gi)].length, 0, 'the no-script directory must not request every full comic'); + const chapters = links(html).filter(link => hasClass(link, 'cat-album-chapter')); + assert.deepEqual(chapters.map(link => ({href: link.attributes.href, title: link.text})), + episodes.map(episode => ({href: './' + chapterFile(episode), title: episode.title})), + 'chapter count, order, exact titles and destinations match the published catalog'); + assert.match(html, /href="\.\/#cat-album-entry"/, 'the collection has a real return link'); + assert.doesNotMatch(html, / server.close(resolve)); + } +}); + +test('every no-script chapter has one exact comic and working circular reading navigation', async () => { + const server = await startServer({port:0}); + const base = 'http://127.0.0.1:' + server.address().port; + try { + for (const [index, episode] of episodes.entries()) { + const file = chapterFile(episode); + const response = await fetch(base + '/' + file); + assert.equal(response.status, 200, file); + assert.match(response.headers.get('content-type'), /text\/html/, file); + const html = await response.text(); + assert.doesNotMatch(html, /]*)>/gi)].map(([, attrs]) => attributes(attrs)); + assert.equal(images.length, 1, `${file} loads only its selected comic`); + assert.deepEqual({id: images[0].id, src: images[0].src, alt: images[0].alt, + width: images[0].width, height: images[0].height}, + {id: 'cat-album-reading-image', src: './' + episode.file, alt: episode.alt, + width: String(episode.width), height: String(episode.height)}, file); + const previous = episodes[(index + episodes.length - 1) % episodes.length]; + const next = episodes[(index + 1) % episodes.length]; + assert.equal(elementById(html, 'cat-album-reading-prev').attributes.href, './' + chapterFile(previous), file); + assert.equal(elementById(html, 'cat-album-reading-next').attributes.href, './' + chapterFile(next), file); + const pageLinks = links(html); + assert.ok(pageLinks.some(link => link.attributes.href === './cat-album.html'), `${file} links back to the directory`); + const originals = pageLinks.filter(link => hasClass(link, 'cat-album-original')); + assert.equal(originals.length, 1, `${file} has one original-image link`); + assert.equal(originals[0].attributes.href, './' + episode.file, file); + const image = await fetch(base + '/' + episode.file); + assert.equal(image.status, 200, episode.file); + assert.equal(image.headers.get('content-type'), 'image/jpeg', episode.file); + } + } finally { + await new Promise(resolve => server.close(resolve)); + } +}); + test('the local preview serves the real covers and does not expose the source project', async () => { const server = await startServer({port:0}); const base = 'http://127.0.0.1:' + server.address().port; diff --git a/tests/delivery/cat-guide-delivery.test.mjs b/tests/delivery/cat-guide-delivery.test.mjs index aaa775b..83dc7ad 100644 --- a/tests/delivery/cat-guide-delivery.test.mjs +++ b/tests/delivery/cat-guide-delivery.test.mjs @@ -9,7 +9,7 @@ test('built experiments keep shared navigation and studio sprites, without shipp const out = await mkdtemp(join(tmpdir(), 'cat-guides-')); try { const files = await build(undefined, out); - const labs = files.filter(file => file.endsWith('.html') && file!=='index.html'); + const labs = files.filter(file => file.endsWith('.html') && file !== 'index.html' && !file.startsWith('cat-album')); for (const lab of labs) { const html = await readFile(join(out, lab), 'utf8'); assert.match(html, /src="\.\/navigation\.mjs(?:\?[^"]*)?"/, lab); diff --git a/tests/delivery/delivery.test.mjs b/tests/delivery/delivery.test.mjs index c5cdecf..1215cb3 100644 --- a/tests/delivery/delivery.test.mjs +++ b/tests/delivery/delivery.test.mjs @@ -95,7 +95,33 @@ files.push('sand-history.mjs'); files.push('sand-bowl.mjs'); files.push('firefly-beat.mjs','firefly-beat-ui.mjs','firefly-beat.css'); files.push('rsi.html','rsi.css','rsi.mjs','rsi-core.mjs','rsi-session.mjs');files.push('recommendation.html','home.css','home.mjs','home-core.mjs','home-preview-sand.jpg','home-preview-neural.jpg','home-preview-recommendation.jpg','home-preview-pathfinding.jpg','home-preview-firefly.jpg','home-preview-evolution.jpg','home-preview-mining.jpg','home-preview-pixel.jpg','home-preview-world-model.jpg','home-preview-rsi.jpg'); -files.push('cat-album.css','cat-album.mjs','cat-album-cover.jpg','cat-comic-substitute.jpg','cat-comic-boss.jpg','cat-comic-warmth.jpg'); +files.push('cat-album.html','cat-album.css','cat-album.mjs','cat-album-cover.jpg','cat-comic-substitute.jpg','cat-comic-boss.jpg','cat-comic-warmth.jpg'); +files.push( + 'cat-album-standby-sound.html', + 'cat-album-third-exit.html', + 'cat-album-blanket-move.html', + 'cat-album-window-audience.html', + 'cat-album-open-is-enough.html', + 'cat-album-dont-throw.html', + 'cat-album-expression-check.html', + 'cat-album-grooming-service.html', + 'cat-album-squeeze-in.html', + 'cat-album-models-ready.html', + 'cat-album-same-destination.html', + 'cat-album-tail-please.html', + 'cat-album-on-time.html', + 'cat-album-all-innocent.html', + 'cat-album-got-it.html', + 'cat-album-air-burial.html', + 'cat-album-photo-retake.html', + 'cat-album-bedroom-edition.html', + 'cat-album-evening-show.html', + 'cat-album-last-bite.html', + 'cat-album-new-bed.html', + 'cat-album-substitute.html', + 'cat-album-boss.html', + 'cat-album-warmth.html', +); files.push('cat-album-episodes.mjs', 'cat-comic-standby-sound.jpg','cat-comic-third-exit.jpg','cat-comic-blanket-move.jpg', 'cat-comic-window-audience.jpg','cat-comic-open-is-enough.jpg','cat-comic-dont-throw.jpg', diff --git a/tests/home/cat-album-ui.test.mjs b/tests/home/cat-album-ui.test.mjs new file mode 100644 index 0000000..bd21071 --- /dev/null +++ b/tests/home/cat-album-ui.test.mjs @@ -0,0 +1,161 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {readFile} from 'node:fs/promises'; +import {episodes} from '../../src/home/album/cat-album-episodes.mjs'; + +let bootId = 0; + +async function boot(t, {modalSupported = true, modalFails = false} = {}) { + const html = await readFile(new URL('../../src/home/index.html', import.meta.url), 'utf8'); + const nodes = new Map(); + const document = {activeElement: null, getElementById: id => nodes.get(id) ?? null}; + class Element { + constructor(markup) { + this.listeners = new Map(); + this.attributes = Object.fromEntries([...markup.matchAll(/\b([\w-]+)="([^"]*)"/g)] + .map(([, name, value]) => [name, value])); + this.hidden = /\shidden(?:\s|>)/.test(markup); + this.textContent = ''; + this.scrollTop = 0; + this.options = []; + this.selectedIndex = -1; + } + setAttribute(name, value) { this.attributes[name] = String(value); } + getAttribute(name) { return this.attributes[name] ?? null; } + addEventListener(type, listener) { + if (!this.listeners.has(type)) this.listeners.set(type, []); + this.listeners.get(type).push(listener); + } + dispatchEvent(event) { + // Browser dispatch reports handler exceptions without cancelling navigation. + const errors = []; + for (const listener of this.listeners.get(event.type) ?? []) { + try { listener(event); } catch (error) { errors.push(error); } + } + return errors; + } + focus() { document.activeElement = this; } + add(option) { + this.options.push(option); + if (this.selectedIndex < 0) this.selectedIndex = 0; + } + } + for (const [markup, id] of html.matchAll(/<[^<>]+\bid="(cat-album[^" ]*)"[^<>]*>/g)) { + nodes.set(id, new Element(markup)); + } + const get = suffix => nodes.get('cat-album' + (suffix ? '-' + suffix : '')); + const dialog = get(''); + dialog.open = false; + if (modalSupported) dialog.showModal = () => { + if (modalFails) throw new DOMException('The dialog cannot open in this document', 'InvalidStateError'); + dialog.open = true; + }; + dialog.close = () => { + dialog.open = false; + dialog.dispatchEvent(new Event('close')); + }; + function Option(text, value) { this.text = text; this.textContent = text; this.value = value; } + for (const [key, value] of Object.entries({document, Option})) { + const prior = Object.getOwnPropertyDescriptor(globalThis, key); + Object.defineProperty(globalThis, key, {value, configurable: true}); + t.after(() => prior ? Object.defineProperty(globalThis, key, prior) : delete globalThis[key]); + } + await import(`../../src/home/album/cat-album.mjs?album-ui-test=${++bootId}`); + const fire = (suffix, type = 'click', fields = {}) => { + const event = Object.assign(new Event(type, {cancelable: true}), { + button: 0, altKey: false, ctrlKey: false, metaKey: false, shiftKey: false, ...fields, + }); + const errors = get(suffix).dispatchEvent(event); + return {event, errors}; + }; + return {document, dialog, get, fire}; +} + +test('an ordinary album click opens the complete published selection and first comic', async t => { + const ui = await boot(t); + const {event, errors} = ui.fire('entry'); + assert.deepEqual(errors, []); + assert.equal(event.defaultPrevented, true); + assert.equal(ui.dialog.open, true); + assert.equal(ui.get('picker').options.length, 24); + assert.deepEqual(ui.get('picker').options.map(option => [option.text, option.value]), + episodes.map(episode => [episode.title, episode.file])); + assert.equal(ui.get('count').textContent, '1 / 24'); + assert.equal(ui.get('episode-title').textContent, '待机声'); + assert.equal(ui.get('page').src, './cat-comic-standby-sound.jpg'); + assert.equal(ui.get('page').hidden, false); + assert.equal(ui.get('error').hidden, true); + assert.equal(ui.document.activeElement, ui.get('close')); +}); + +test('next and previous change the displayed comic and wrap through the complete album', async t => { + const ui = await boot(t); + ui.fire('entry'); + ui.get('scroll').scrollTop = 500; + ui.fire('next'); + assert.equal(ui.get('count').textContent, '2 / 24'); + assert.equal(ui.get('episode-title').textContent, '第三个出口'); + assert.equal(ui.get('page').src, './cat-comic-third-exit.jpg'); + assert.equal(ui.get('picker').selectedIndex, 1); + assert.equal(ui.get('scroll').scrollTop, 0); + ui.fire('prev'); + assert.equal(ui.get('page').src, './cat-comic-standby-sound.jpg'); + ui.fire('prev'); + assert.equal(ui.get('count').textContent, '24 / 24'); + assert.equal(ui.get('page').src, './cat-comic-warmth.jpg'); + ui.fire('next'); + assert.equal(ui.get('count').textContent, '1 / 24'); + assert.equal(ui.get('page').src, './cat-comic-standby-sound.jpg'); +}); + +test('choosing the last episode renders its own caption, image and accessible description', async t => { + const ui = await boot(t); + ui.fire('entry'); + ui.get('picker').selectedIndex = 23; + ui.fire('picker', 'change'); + assert.equal(ui.get('count').textContent, '24 / 24'); + assert.equal(ui.get('episode-title').textContent, '保温测试'); + assert.equal(ui.get('caption').textContent, '阳光挪了窝,波比没挪成。'); + assert.equal(ui.get('page').src, './cat-comic-warmth.jpg'); + assert.equal(ui.get('page').alt, '四格漫画。阳光移开了,波比想继续晒太阳,却没能顺利挪到新的位置。'); + assert.equal(ui.get('page').width, 1122); + assert.equal(ui.get('page').height, 1402); +}); + +test('closing the album returns focus to the original homepage entry', async t => { + const ui = await boot(t); + ui.fire('entry'); + ui.fire('close'); + assert.equal(ui.dialog.open, false); + assert.equal(ui.document.activeElement, ui.get('entry')); +}); + +test('modified and non-primary clicks retain the original link instead of opening a modal', async t => { + const ui = await boot(t); + const href = ui.get('entry').getAttribute('href'); + for (const fields of [{altKey: true}, {ctrlKey: true}, {metaKey: true}, {shiftKey: true}, {button: 1}]) { + const {event, errors} = ui.fire('entry', 'click', fields); + assert.deepEqual(errors, []); + assert.equal(event.defaultPrevented, false); + assert.equal(ui.dialog.open, false); + assert.equal(ui.get('entry').getAttribute('href'), href); + } +}); + +test('browsers without native modal support keep the entry link available', async t => { + const ui = await boot(t, {modalSupported: false}); + const {event, errors} = ui.fire('entry'); + assert.deepEqual(errors, []); + assert.equal(event.defaultPrevented, false); + assert.equal(ui.dialog.open, false); +}); + +test('a failed showModal leaves native link navigation available instead of trapping the visitor', async t => { + const ui = await boot(t, {modalFails: true}); + ui.get('entry').focus(); + const {event, errors} = ui.fire('entry'); + assert.equal(event.defaultPrevented, false, 'the full album link must remain usable when the modal cannot open'); + assert.deepEqual(errors, [], 'the controller handles the modal failure'); + assert.equal(ui.dialog.open, false); + assert.equal(ui.document.activeElement, ui.get('entry')); +});