Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>library-extradirs-quota · qa-hifi demo</title>
<style>
/* ===== 界面本体样式 =====
规则:任何文案/几何/颜色值只准来自内嵌 truth(门 A/D 会抓手写漂移)。
chrome 工具区样式由 qa-chrome 注入,不要在这里覆盖 qa-* 类。 */
.panel { font-family: ui-sans-serif, system-ui, sans-serif; padding: 20px 24px; max-width: 480px; }
.quota-title { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
html.dark .quota-title { color: #ececec; }
html:not(.dark) .quota-title { color: #1a1a1a; }
.row { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 10px; border-radius: 6px; }
html:not(.dark) .row:hover { background: #f3f3f3; }
html.dark .row:hover { background: #2a2a2a; }
.dir-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
html:not(.dark) .dir-label { color: #1a1a1a; }
html.dark .dir-label { color: #ececec; }
.remove { border: 0; background: transparent; cursor: pointer; font-size: 12px; opacity: .7; }
.add-btn { margin-top: 8px; height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid #ccc; background: transparent; font-size: 13px; cursor: pointer; }
.add-btn[disabled] { opacity: .45; cursor: not-allowed; }
.count-badge { margin-left: 8px; font-size: 12px; opacity: .7; }
.fill-btn { margin-top: 16px; font-size: 12px; opacity: .8; }
</style>
</head>
<body>
<!-- 真值块:由 `node <skill>/scripts/truth.mjs --demo <dir> --embed` 写入,禁止手抄 -->
<script id="qa-truth" type="application/json">{"copy":{"en":{"addReadOnly":{"provenance":{"hash":"01d196d1ba0bf8eed63c80e32bb9311afa1899896954e14a3437305b374ea153","locator":"extraDirs.addReadOnly","locatorKeyPath":"extraDirs.addReadOnly","source":"../../../apps/desktop/src/renderer/i18n/locales/en/common.json"},"value":"Add read-only directory…"},"atLimit":{"provenance":{"hash":"01d196d1ba0bf8eed63c80e32bb9311afa1899896954e14a3437305b374ea153","locator":"extraDirs.atLimit","locatorKeyPath":"extraDirs.atLimit","source":"../../../apps/desktop/src/renderer/i18n/locales/en/common.json"},"value":"Limit reached ({{max}})"},"empty":{"provenance":{"hash":"01d196d1ba0bf8eed63c80e32bb9311afa1899896954e14a3437305b374ea153","locator":"extraDirs.empty","locatorKeyPath":"extraDirs.empty","source":"../../../apps/desktop/src/renderer/i18n/locales/en/common.json"},"value":"No reference directories yet"},"libraryReadOnlyLabel":{"provenance":{"hash":"01d196d1ba0bf8eed63c80e32bb9311afa1899896954e14a3437305b374ea153","locator":"extraDirs.libraryReadOnlyLabel","locatorKeyPath":"extraDirs.libraryReadOnlyLabel","source":"../../../apps/desktop/src/renderer/i18n/locales/en/common.json"},"value":"Mivo Library (Read-Only)"},"sectionTitle":{"provenance":{"hash":"01d196d1ba0bf8eed63c80e32bb9311afa1899896954e14a3437305b374ea153","locator":"extraDirs.sectionTitle","locatorKeyPath":"extraDirs.sectionTitle","source":"../../../apps/desktop/src/renderer/i18n/locales/en/common.json"},"value":"Directories"},"tooltipCount":{"provenance":{"hash":"01d196d1ba0bf8eed63c80e32bb9311afa1899896954e14a3437305b374ea153","locator":"extraDirs.tooltipCount","locatorKeyPath":"extraDirs.tooltipCount","source":"../../../apps/desktop/src/renderer/i18n/locales/en/common.json"},"value":"{{count}} additional directories"}},"zh-CN":{"addReadOnly":{"provenance":{"hash":"a132ae2714e665285d533dc7420be5dddc3d5fe76a473c93c121ee8a8a81cf45","locator":"extraDirs.addReadOnly","locatorKeyPath":"extraDirs.addReadOnly","source":"../../../apps/desktop/src/renderer/i18n/locales/zh-CN/common.json"},"value":"添加只读目录…"},"atLimit":{"provenance":{"hash":"a132ae2714e665285d533dc7420be5dddc3d5fe76a473c93c121ee8a8a81cf45","locator":"extraDirs.atLimit","locatorKeyPath":"extraDirs.atLimit","source":"../../../apps/desktop/src/renderer/i18n/locales/zh-CN/common.json"},"value":"已达上限 {{max}} 个"},"empty":{"provenance":{"hash":"a132ae2714e665285d533dc7420be5dddc3d5fe76a473c93c121ee8a8a81cf45","locator":"extraDirs.empty","locatorKeyPath":"extraDirs.empty","source":"../../../apps/desktop/src/renderer/i18n/locales/zh-CN/common.json"},"value":"还没有引用目录"},"libraryReadOnlyLabel":{"provenance":{"hash":"a132ae2714e665285d533dc7420be5dddc3d5fe76a473c93c121ee8a8a81cf45","locator":"extraDirs.libraryReadOnlyLabel","locatorKeyPath":"extraDirs.libraryReadOnlyLabel","source":"../../../apps/desktop/src/renderer/i18n/locales/zh-CN/common.json"},"value":"Mivo 作品库(只读)"},"sectionTitle":{"provenance":{"hash":"a132ae2714e665285d533dc7420be5dddc3d5fe76a473c93c121ee8a8a81cf45","locator":"extraDirs.sectionTitle","locatorKeyPath":"extraDirs.sectionTitle","source":"../../../apps/desktop/src/renderer/i18n/locales/zh-CN/common.json"},"value":"目录"},"tooltipCount":{"provenance":{"hash":"a132ae2714e665285d533dc7420be5dddc3d5fe76a473c93c121ee8a8a81cf45","locator":"extraDirs.tooltipCount","locatorKeyPath":"extraDirs.tooltipCount","source":"../../../apps/desktop/src/renderer/i18n/locales/zh-CN/common.json"},"value":"{{count}} 个附加目录"}}},"quota":{"max":{"provenance":{"hash":"bb32200175be9d3e9b4e511035055527c9479fbf71991c971cc2abd62285afdf","locator":"extraDirsValidator EXTRA_DIRS_MAX","locatorPattern":"export const EXTRA_DIRS_MAX = (\\d+)","source":"../../../apps/desktop/src/main/maker-ipc/extraDirsValidator.ts"},"value":"10"},"slotPrefix":{"provenance":{"hash":"4e09c3991697512f0586c4086f8cf5fc6760b222db9757d69307dfc6e201ed53","locator":"extraDirsActions LIBRARY_EXTRA_DIR_SLOT_PREFIX","locatorPattern":"export const LIBRARY_EXTRA_DIR_SLOT_PREFIX = '([^']+)'","source":"../../../apps/desktop/src/renderer/components/new-chat/extraDirsActions.ts"},"value":"cindy-library:"}},"wiring":{"chatInputBadgeSites":{"provenance":{"hash":"986fbad8f0facaa5e51065df571cd66a2777550f0222b528b6562c2e3b7ee1f3","locator":"ChatInput ExtraDirsButton extraDirsCount 公式次数","source":"../../../apps/desktop/src/renderer/components/new-chat/ChatInput.tsx"},"value":1},"chatInputQuotaSites":{"provenance":{"hash":"986fbad8f0facaa5e51065df571cd66a2777550f0222b528b6562c2e3b7ee1f3","locator":"ChatInput 加目录/可写目录两处配额公式次数","source":"../../../apps/desktop/src/renderer/components/new-chat/ChatInput.tsx"},"value":1},"panelLabelSites":{"provenance":{"hash":"61f32f3cbe901707f4657a058298f1db960b737274067202f7ddb7b9ecaf0c84","locator":"AtMentionPanel extraDirDisplayLabel(p, libraryReadOnlyLabel) 次数","source":"../../../apps/desktop/src/renderer/components/new-chat/AtMentionPanel.tsx"},"value":2},"panelNoRemoveSites":{"provenance":{"hash":"61f32f3cbe901707f4657a058298f1db960b737274067202f7ddb7b9ecaf0c84","locator":"AtMentionPanel library 槽不画移除按钮","source":"../../../apps/desktop/src/renderer/components/new-chat/AtMentionPanel.tsx"},"value":1}}}</script>
<script>
// ===== demo 配置(作者唯一要写的部分;字段说明见 qa-chrome 头注释) =====
window.__qaDemo = {
name: 'library-extradirs-quota',
pr: null,
summary: {
what: 'composer 引用目录把 cindy-library: 当系统槽:不占用户 10 名额,显示「Mivo 作品库(只读)」且不可移除。',
how: 'ChatInput 配额走 countUserExtraDirs;AtMentionPanel 用 extraDirDisplayLabel,library 槽不画移除按钮。',
accept: '未满员可添加;10 个用户目录 + library 槽时加号禁用且计数仍为 10;系统项文案来自源码。',
},
matrix: {
plat: { label: '端', options: [{ v: 'desktop', label: '桌面' }] },
region: { label: '区域', options: [{ v: 'cn', label: '中国大陆' }] },
os: { label: '系统', options: [{ v: 'mac', label: 'macOS' }] },
mode: { label: '主题', options: [{ v: 'light', label: 'Light' }, { v: 'dark', label: 'Dark' }] },
lang: { label: '语言', options: [{ v: 'zh-CN', label: '简中' }, { v: 'en', label: 'EN' }] },
},
defaultPrefs: { plat: 'desktop', region: 'cn', os: 'mac', mode: 'light', lang: 'zh-CN' },
initialState: 'mixed',
states: {
mixed: {},
full: {},
},
tabStates: [],
adaptive: null,
// adaptive: { min: { w: 960, h: 640 }, initial: { w: 1200, h: 800 }, bandLabel: (w, h) => (w < 1100 ? '压缩档' : '标准档') },
scale: () => 1,
renderApp(ctx) {
const t = ctx.truth;
const lang = ctx.prefs.lang === 'en' ? 'en' : 'zh-CN';
const copy = t.copy[lang];
const max = Number(t.quota.max);
const prefix = t.quota.slotPrefix;
const systemLabel = copy.libraryReadOnlyLabel;
const userCount = ctx.state === 'full' ? max : 2;
const atLimit = userCount >= max;
const addLabel = atLimit
? copy.atLimit.replace('{{max}}', String(max))
: copy.addReadOnly;
const badge = copy.tooltipCount.replace('{{count}}', String(userCount));
const users = Array.from({ length: userCount }, (_, i) => 'refs-' + (i + 1));
const row = (label, system) => {
const el = document.createElement('div');
el.className = 'row';
el.setAttribute('data-node-id', system ? 'library-slot' : 'user-dir-' + label);
const name = document.createElement('span');
name.className = 'dir-label';
name.textContent = label;
el.appendChild(name);
if (!system) {
const rm = document.createElement('button');
rm.type = 'button';
rm.className = 'remove';
rm.textContent = '×';
el.appendChild(rm);
}
return el;
};
ctx.frame.innerHTML = '';
const panel = document.createElement('div');
panel.className = 'panel';
panel.setAttribute('data-node-id', 'extra-dirs-panel');
const head = document.createElement('div');
head.style.display = 'flex';
head.style.alignItems = 'baseline';
const title = document.createElement('h2');
title.className = 'quota-title';
title.setAttribute('data-node-id', 'section-title');
title.textContent = copy.sectionTitle;
const badgeEl = document.createElement('span');
badgeEl.className = 'count-badge';
badgeEl.textContent = badge;
head.appendChild(title);
head.appendChild(badgeEl);
panel.appendChild(head);
panel.appendChild(row(systemLabel, true));
users.forEach((name) => panel.appendChild(row(name, false)));
const add = document.createElement('button');
add.type = 'button';
add.className = 'add-btn';
add.setAttribute('data-node-id', 'add-extra-dir');
add.textContent = addLabel;
add.disabled = atLimit;
panel.appendChild(add);
if (ctx.state !== 'full') {
const fill = document.createElement('button');
fill.type = 'button';
fill.className = 'fill-btn';
fill.setAttribute('data-qa-goto', 'full');
fill.setAttribute('data-node-id', 'fill-quota');
fill.textContent = prefix + 'fill';
fill.addEventListener('click', () => ctx.setState('full'));
panel.appendChild(fill);
}
ctx.frame.appendChild(panel);
},
};
</script>
<script>
/* QA_CHROME_BEGIN — 标准 chrome 运行时,由 init.mjs 内联;勿手改。
升级:node <skill>/scripts/init.mjs --dir <demo-dir> --update-chrome */
/* qa-chrome.js — qa-hifi-demo 标准 chrome 运行时(由 init.mjs 内联进 index.html)。
*
* 诞生背景:__qa 五个 API + 偏好持久化 + matrix 切换器 + 状态补齐 tab 曾由每个 demo
* 重新实现一遍——10 个 demo 写出 10 种偏好切换器(replay.mjs clickPref 要猜 7 种 selector
* 就是后果)。本文件是「demo 合约」的唯一标准实现;demo 作者只提供 window.__qaDemo 配置:
*
* window.__qaDemo = {
* name: 'my-demo', // 必填,localStorage key 用
* pr: 123, // 可选,PR 号徽标
* summary: { what, how, accept }, // 三段说明(各 ≤2 行)
* matrix: { // 五维切换器;键固定 plat/region/os/mode/lang
* plat: { label: '端', options: [{ v: 'desk', label: '桌面' }, ...] },
* region: { label: '区域', options: [...] },
* os: { label: '系统', options: [...] },
* mode: { label: '主题', options: [...] },
* lang: { label: '语言', options: [...] },
* },
* defaultPrefs: { plat, region, os, mode, lang }, // 必填,全 string
* initialState: 'entry', // 必填
* states: { entry: {}, scanning: {}, ... }, // 必填:id → {}(可带 onEnter(ctx))
* tabStates: [{ id, label, note }], // via:null 状态(注意与 spec.states 对齐)
* adaptive: null | { min: {w,h}, initial: {w,h}, bandLabel: (w,h)=>string },
* scale: (prefs) => 1, // 设计px→CSS px(默认 1)
* renderApp(ctx) { ... }, // 必填:渲染界面本体进 ctx.frame
* };
*
* ctx = { truth, prefs, state, frame, setState(id), chrome }。truth 已解包(叶子裸值)。
* 标准 DOM 合约(verify.mjs replay.mjs 的第一优先 selector,别改):
* 偏好入口 [data-qa-pref="key:value"]
* 状态 tab [data-qa-state-tab]
* 状态入口 [data-qa-goto="<state-id>"]
* 帧容器 .frame
*/
(() => {
'use strict';
const cfg = window.__qaDemo;
if (!cfg) throw new Error('qa-chrome: 缺 window.__qaDemo 配置(必须在本脚本之前定义)');
for (const key of ['name', 'defaultPrefs', 'initialState', 'states', 'renderApp']) {
if (!cfg[key]) throw new Error(`qa-chrome: __qaDemo.${key} 必填`);
}
// ---------- truth ----------
const truthEl = document.getElementById('qa-truth');
if (!truthEl) throw new Error('qa-chrome: 缺 <script id="qa-truth"> 内嵌真值块');
const RAW_TRUTH = JSON.parse(truthEl.textContent);
const unwrap = (n) => {
if (n && typeof n === 'object' && !Array.isArray(n) && 'value' in n && n.provenance) return n.value;
if (Array.isArray(n)) return n.map(unwrap);
if (n && typeof n === 'object') return Object.fromEntries(Object.entries(n).map(([k, v]) => [k, unwrap(v)]));
return n;
};
const TRUTH = unwrap(RAW_TRUTH);
// ---------- prefs(五维,localStorage 持久化;流程状态不持久化) ----------
const PREF_KEYS = ['plat', 'region', 'os', 'mode', 'lang'];
const STORE_KEY = `qa-hifi:${cfg.name}:prefs`;
let stored = null;
try { stored = JSON.parse(localStorage.getItem(STORE_KEY) || 'null'); } catch {}
const prefs = { ...cfg.defaultPrefs };
if (stored && typeof stored === 'object') for (const k of PREF_KEYS) if (typeof stored[k] === 'string') prefs[k] = stored[k];
const persistPrefs = () => { try { localStorage.setItem(STORE_KEY, JSON.stringify(prefs)); } catch {} };
// ---------- state ----------
let state = cfg.initialState;
if (!(state in cfg.states)) throw new Error(`qa-chrome: initialState "${state}" 不在 states 里`);
// ---------- chrome DOM ----------
const css = `
:root { --qa-bg:#f4f5f7; --qa-panel:#fff; --qa-ink:#1c1e21; --qa-sub:#6b7280; --qa-line:#e5e7eb; --qa-acc:#2563eb; }
body.qa-dark { --qa-bg:#111318; --qa-panel:#1b1e25; --qa-ink:#e8eaed; --qa-sub:#9aa0a6; --qa-line:#2c313a; --qa-acc:#5b8def; }
body { margin:0; background:var(--qa-bg); color:var(--qa-ink); font:14px/1.5 -apple-system,"PingFang SC","Microsoft YaHei",sans-serif; }
.qa-chrome { padding:12px 16px; border-bottom:1px solid var(--qa-line); background:var(--qa-panel); }
.qa-head { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.qa-title { font-size:15px; font-weight:600; }
.qa-badge { font-size:12px; padding:1px 8px; border-radius:999px; background:var(--qa-acc); color:#fff; }
.qa-summary { margin:6px 0 0; padding:0; list-style:none; color:var(--qa-sub); font-size:12px; }
.qa-summary b { color:var(--qa-ink); font-weight:600; }
.qa-ctl { display:flex; gap:14px; flex-wrap:wrap; margin-top:10px; align-items:center; }
.qa-seg { display:flex; align-items:center; gap:6px; }
.qa-seg-label { font-size:12px; color:var(--qa-sub); }
.qa-seg-group { display:inline-flex; border:1px solid var(--qa-line); border-radius:8px; overflow:hidden; }
.qa-seg-group button { border:0; background:transparent; color:var(--qa-ink); padding:3px 10px; font-size:12px; cursor:pointer; }
.qa-seg-group button.on { background:var(--qa-acc); color:#fff; }
.qa-tabbtn { margin-left:auto; border:1px solid var(--qa-line); background:transparent; color:var(--qa-ink); border-radius:8px; padding:3px 12px; font-size:12px; cursor:pointer; }
.qa-tabbtn.on { background:var(--qa-acc); color:#fff; border-color:var(--qa-acc); }
.qa-tabpanel { display:none; margin-top:10px; border:1px dashed var(--qa-line); border-radius:8px; padding:10px; }
.qa-tabpanel.on { display:block; }
.qa-tabpanel .qa-tab-entry { display:flex; gap:8px; align-items:baseline; padding:4px 0; }
.qa-tabpanel .qa-tab-entry button { border:1px solid var(--qa-acc); color:var(--qa-acc); background:transparent; border-radius:6px; padding:2px 10px; font-size:12px; cursor:pointer; }
.qa-tabpanel .qa-tab-note { color:var(--qa-sub); font-size:12px; }
.qa-stage { display:flex; justify-content:center; padding:28px 16px; }
.qa-framewrap { position:relative; }
.frame { position:relative; background:var(--qa-panel); border:1px solid var(--qa-line); border-radius:12px; overflow:hidden; box-shadow:0 8px 30px rgba(0,0,0,.08); }
.qa-size-badge { position:absolute; left:0; bottom:-22px; font-size:11px; color:var(--qa-sub); }
.qa-handle { position:absolute; z-index:9; }
.qa-handle-e { right:-6px; top:0; width:12px; height:100%; cursor:ew-resize; }
.qa-handle-s { bottom:-6px; left:0; height:12px; width:100%; cursor:ns-resize; }
.qa-handle-se { right:-8px; bottom:-8px; width:16px; height:16px; cursor:nwse-resize; }
`;
const styleEl = document.createElement('style');
styleEl.textContent = css;
document.head.appendChild(styleEl);
const chromeEl = document.createElement('div');
chromeEl.className = 'qa-chrome';
const head = document.createElement('div');
head.className = 'qa-head';
const title = document.createElement('span');
title.className = 'qa-title';
title.textContent = cfg.name;
head.appendChild(title);
if (cfg.pr) {
const badge = document.createElement('span');
badge.className = 'qa-badge';
badge.textContent = `PR #${cfg.pr}`;
head.appendChild(badge);
}
chromeEl.appendChild(head);
if (cfg.summary) {
const ul = document.createElement('ul');
ul.className = 'qa-summary';
for (const [k, label] of [['what', '做了什么'], ['how', '怎么做'], ['accept', '怎么验收']]) {
if (!cfg.summary[k]) continue;
const li = document.createElement('li');
const b = document.createElement('b');
b.textContent = `${label}:`;
li.appendChild(b);
li.appendChild(document.createTextNode(cfg.summary[k]));
ul.appendChild(li);
}
chromeEl.appendChild(ul);
}
const ctl = document.createElement('div');
ctl.className = 'qa-ctl';
const segButtons = {};
for (const key of PREF_KEYS) {
const dim = cfg.matrix?.[key];
if (!dim || !Array.isArray(dim.options) || dim.options.length === 0) continue;
const seg = document.createElement('div');
seg.className = 'qa-seg';
const label = document.createElement('span');
label.className = 'qa-seg-label';
label.textContent = dim.label ?? key;
seg.appendChild(label);
const group = document.createElement('div');
group.className = 'qa-seg-group';
for (const opt of dim.options) {
const btn = document.createElement('button');
btn.type = 'button';
btn.dataset.qaPref = `${key}:${opt.v}`;
btn.textContent = opt.label ?? opt.v;
btn.addEventListener('click', () => { prefs[key] = opt.v; persistPrefs(); render(); });
group.appendChild(btn);
(segButtons[key] ??= []).push({ v: opt.v, btn });
}
seg.appendChild(group);
ctl.appendChild(seg);
}
// 状态补齐 tab(via:null 状态的唯一取证入口;进 tab 必须写理由)
const tabStates = Array.isArray(cfg.tabStates) ? cfg.tabStates : [];
let tabOpen = false;
let tabBtn = null;
let tabPanel = null;
if (tabStates.length) {
tabBtn = document.createElement('button');
tabBtn.type = 'button';
tabBtn.className = 'qa-tabbtn';
tabBtn.dataset.qaStateTab = '';
tabBtn.textContent = '状态补齐';
tabBtn.addEventListener('click', () => { tabOpen = !tabOpen; render(); });
ctl.appendChild(tabBtn);
tabPanel = document.createElement('div');
tabPanel.className = 'qa-tabpanel';
for (const ts of tabStates) {
if (!(ts.id in cfg.states)) throw new Error(`qa-chrome: tabStates "${ts.id}" 不在 states 里`);
const row = document.createElement('div');
row.className = 'qa-tab-entry';
const btn = document.createElement('button');
btn.type = 'button';
btn.dataset.qaGoto = ts.id;
btn.textContent = ts.label ?? ts.id;
btn.addEventListener('click', () => { gotoState(ts.id); });
row.appendChild(btn);
const note = document.createElement('span');
note.className = 'qa-tab-note';
note.textContent = ts.note ?? '';
row.appendChild(note);
tabPanel.appendChild(row);
}
}
chromeEl.appendChild(ctl);
if (tabPanel) chromeEl.appendChild(tabPanel);
document.body.prepend(chromeEl);
// ---------- 帧 + 拉伸 ----------
const stage = document.createElement('div');
stage.className = 'qa-stage';
const frameWrap = document.createElement('div');
frameWrap.className = 'qa-framewrap';
const frame = document.createElement('div');
frame.className = 'frame';
frameWrap.appendChild(frame);
stage.appendChild(frameWrap);
document.body.appendChild(stage);
const ad = cfg.adaptive ?? null;
let frameW = ad?.initial?.w ?? ad?.min?.w ?? 960;
let frameH = ad?.initial?.h ?? ad?.min?.h ?? 640;
let sizeBadge = null;
// 拖拽手柄与 __qa.resize 走同一代码路径(setFrameSize),内部 clamp 到 adaptive.min
function setFrameSize(w, h) {
if (ad?.min) { w = Math.max(ad.min.w, w); h = Math.max(ad.min.h, h); }
frameW = Math.round(w);
frameH = Math.round(h);
frame.style.width = `${frameW}px`;
frame.style.height = `${frameH}px`;
if (sizeBadge) {
const band = typeof ad?.bandLabel === 'function' ? ` · ${ad.bandLabel(frameW, frameH)}` : '';
sizeBadge.textContent = `${frameW}×${frameH}${band}`;
}
render();
}
if (ad) {
sizeBadge = document.createElement('div');
sizeBadge.className = 'qa-size-badge';
frameWrap.appendChild(sizeBadge);
for (const [dirCls, dx, dy] of [['e', 1, 0], ['s', 0, 1], ['se', 1, 1]]) {
const handle = document.createElement('div');
handle.className = `qa-handle qa-handle-${dirCls}`;
handle.addEventListener('pointerdown', (e) => {
e.preventDefault();
const startX = e.clientX;
const startY = e.clientY;
const startW = frameW;
const startH = frameH;
const move = (ev) => setFrameSize(startW + (ev.clientX - startX) * dx, startH + (ev.clientY - startY) * dy);
const up = () => { window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', up); };
window.addEventListener('pointermove', move);
window.addEventListener('pointerup', up);
});
frameWrap.appendChild(handle);
}
}
// ---------- 状态机 ----------
function gotoState(id) {
if (!(id in cfg.states)) throw new Error(`qa-chrome: unknown state "${id}"`);
state = id;
const onEnter = cfg.states[id]?.onEnter;
render();
if (typeof onEnter === 'function') onEnter(ctx());
}
function ctx() {
return { truth: TRUTH, rawTruth: RAW_TRUTH, prefs: { ...prefs }, state, frame, setState: gotoState, chrome: chromeEl };
}
// ---------- 渲染 ----------
function render() {
document.body.classList.toggle('qa-dark', prefs.mode === 'dark');
for (const key of Object.keys(segButtons)) {
for (const { v, btn } of segButtons[key]) btn.classList.toggle('on', prefs[key] === v);
}
if (tabBtn) tabBtn.classList.toggle('on', tabOpen);
if (tabPanel) tabPanel.classList.toggle('on', tabOpen);
cfg.renderApp(ctx());
}
// ---------- __qa API(demo 合约) ----------
window.__qa = {
current: () => state,
goto: (id) => { gotoState(id); },
prefs: () => ({ ...prefs }),
scale: () => (typeof cfg.scale === 'function' ? Number(cfg.scale({ ...prefs })) : 1),
resize: (w, h) => { setFrameSize(Number(w), Number(h)); },
metrics: (ids) => {
const fr = frame.getBoundingClientRect();
const probes = {};
for (const id of ids ?? []) {
const el = frame.querySelector(`[data-qa-probe="${id}"]`);
if (!el) { probes[id] = null; continue; }
const r = el.getBoundingClientRect();
probes[id] = { x: r.x - fr.x, y: r.y - fr.y, w: r.width, h: r.height };
}
return { frame: { w: fr.width, h: fr.height }, probes };
},
};
// ---------- 启动 ----------
setFrameSize(frameW, frameH);
})();
/* QA_CHROME_END */
</script>
</body>
</html>