diff --git a/packages/compress-core/.gitattributes b/packages/compress-core/.gitattributes new file mode 100644 index 00000000..83364b94 --- /dev/null +++ b/packages/compress-core/.gitattributes @@ -0,0 +1,5 @@ +# Keep one line ending in the repository; Windows checkouts may still be CRLF. +* text=auto +*.png binary +*.webp binary +*.woff2 binary \ No newline at end of file diff --git a/packages/compress-core/.gitignore b/packages/compress-core/.gitignore new file mode 100644 index 00000000..aa007d89 --- /dev/null +++ b/packages/compress-core/.gitignore @@ -0,0 +1,20 @@ +node_modules/ + +# What this plugin writes on the machine it runs on, none of it belongs in the repo: +# per-request byte counts, captured requests, temp files. +requests.jsonl +*.jsonl +captures/ +page/captures/ +# The two files the hook republishes for the page to load: index metadata and the +# savings summary, generated on this machine, never shipped. +page/captures-index.js +page/compress-stats.js +page/compress-ccr-status.js +# Local safety nets: timestamped .bak copies and dated backup snapshots. +*.bak +*.bak.* +backup/ +*.tmp +*.log +.DS_Store diff --git a/packages/compress-core/DEBUGGING.md b/packages/compress-core/DEBUGGING.md new file mode 100644 index 00000000..ec61c64e --- /dev/null +++ b/packages/compress-core/DEBUGGING.md @@ -0,0 +1,48 @@ +# 面板点不动的时候先看这里 + +这份记录写的是 0.4.0 之前的那次 UI 交互失效:**magpie 设置面板里所有按钮都没反应**——预设点不动,齿轮和烧瓶切不了视图,策略开关也按不动。 + +结论先说:跟 iframe 沙箱没关系。是渲染函数抛了异常,`init()` 中断在半路,按钮的监听根本没绑上。 + +## 排查走过弯路 + +现象很容易让人怀疑沙箱,下面这几条**都不是**原因: + +- `sandbox="allow-scripts"` 加 `connect-src 'none'` 的 CSP:页面确实拿不到网络,但点击、`hidden`、`style.display` 全都不受影响。 +- 视图切换的写法(只用 `hidden`、只用 `display`、两者都写):三种都试过,都没用——因为压根没走到那一步。 +- 脚本加载顺序、`node --check` 语法检查、HTML 是否被浏览器缓存:都查过,全是干净的。 +- 也不要在 iframe 里靠 `console.log` 找线索:magpie 主界面的 devtools 里看不到插件 iframe 的输出,日志会静悄悄地丢掉。 + +## 真正的原因 + +`paint()` 是按「想当然的接口」写的,magpie 一挂载就抛错: + +- 把 `V.engines()` 当 map/对象遍历,它其实是数组; +- 调了 `page/ui.js` 里不存在的 `U.row` / `U.box`; +- 读了 `page/view.js` 的 TEXT 里不存在的字段(例如 `T.status`)。 + +第一行就 `TypeError`。而 `init()` 的顺序是「先渲染、后绑定事件」,异常把 `init()` 打断在渲染那一步,后面 `bindViewButtons()` 之类的绑定一次都没执行——所以整个面板死掉。表现上跟「沙箱拦住点击」一模一样,排查方向很容易被带跑。 + +修法:每个渲染函数外面套一层 `safePaint()`,单个区块炸掉不再拖死整轮;然后所有渲染严格按 `page/view.js` / `page/ui.js` 的真实契约重写。 + +## 契约(不要再猜) + +- `page/view.js:293` `cards(strategies, stats, lang)` → 返回卡片数组,每项 `{id, label, why, description, badge, tone, available, requires, on, rule}`。 +- `page/ui.js:6` `el(tag, cls, text)`、`page/ui.js:13` `clear(host)`、`page/ui.js:21` `switchButton(on, disabled, onChange, label)`、`page/ui.js:37` `meter(host, m, T)`、`rows(host, cards, ctx)`,其中 `ctx = {T, open, config, onToggle, onSwitch, onField}`。 +- 会话索引**不在** `options.stats.captures[]` 里:`stats-writer.js` 已经不再写 `plugins.json`,那个字段是冻死的旧值。索引由钩子发布成页面同目录的 `page/captures-index.js`,页面用 `