Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
172 lines
9.4 KiB
JavaScript
172 lines
9.4 KiB
JavaScript
// Independent, read-only extractor for the INSTALLED official TeamSpeak 6 client UI styles.
|
|
// QA-only. It reads the installed files in place, records their sha256, and derives the active
|
|
// style layers the official runtime applies (main.css + platform module + theme module), by
|
|
// resolving the bundle's own webpack request maps instead of hard-coded module ids. It resolves
|
|
// :root custom properties per theme with provenance (source, selector, character offset).
|
|
// Nothing from the official bundle is written into the repository or the product. A reference
|
|
// page built from these layers is a RECONSTRUCTED TEMPLATE (official classes + official CSS,
|
|
// synthetic DOM), not the official runtime or its native bridge.
|
|
import { createHash } from 'node:crypto';
|
|
import { readFileSync, existsSync } from 'node:fs';
|
|
import { pathToFileURL } from 'node:url';
|
|
import path from 'node:path';
|
|
import vm from 'node:vm';
|
|
|
|
export const DEFAULT_OFFICIAL_DIR = path.join(process.env.LOCALAPPDATA ?? '', 'Programs', 'TeamSpeak', 'html', 'client_ui');
|
|
// Hashes of the build inspected on 2026-11-01 (client 6.0 bundle, CEF 151). Drift is reported, never ignored.
|
|
export const INSPECTED_SHA256 = {
|
|
'main.css': 'bc700401d04954d07f82570b060335e2278166db4f618f6cf3dcf8fde1834adf',
|
|
'main.js': '9d6bea2ee5333086555c36584621c1b3462a83042ce746d3229d6766a9b82c39',
|
|
'index.html': '96c60720ca4c6e59a6efc14fe97f8844749d196b0f3925604709e9b37b84f793',
|
|
};
|
|
const sha256 = data => createHash('sha256').update(data).digest('hex');
|
|
const ROOT_SELECTORS = new Set([':root', '::after', '::before', ':after', ':before']);
|
|
|
|
// Minimal CSS rule walker: tracks @media/@supports nesting so nested rules are not mistaken for
|
|
// top-level ones. Comments and strings are skipped. Returns { selector, body, offset, at[] }.
|
|
export function parseRules(text) {
|
|
const rules = [], stack = [];
|
|
let i = 0, start = 0;
|
|
while (i < text.length) {
|
|
const c = text[i];
|
|
if (c === '/' && text[i + 1] === '*') { i = text.indexOf('*/', i + 2) + 2 || text.length; continue; }
|
|
if (c === '"' || c === "'") { i++; while (i < text.length && text[i] !== c) i += text[i] === '\\' ? 2 : 1; i++; continue; }
|
|
if (c === '{') {
|
|
const prelude = text.slice(start, i).trim();
|
|
if (prelude.startsWith('@')) { stack.push({ at: prelude }); start = i + 1; i++; continue; }
|
|
let depth = 1, j = i + 1;
|
|
while (j < text.length && depth) { if (text[j] === '{') depth++; else if (text[j] === '}') depth--; j++; }
|
|
rules.push({ selector: prelude, body: text.slice(i + 1, j - 1), offset: start + (text.slice(start, i).length - text.slice(start, i).trimStart().length), at: stack.map(s => s.at) });
|
|
i = j; start = i; continue;
|
|
}
|
|
if (c === '}') { stack.pop(); start = i + 1; }
|
|
if (c === ';' && !stack.length) start = i + 1; // @import/@charset lines
|
|
i++;
|
|
}
|
|
return rules;
|
|
}
|
|
|
|
export function declarations(body) {
|
|
const out = [];
|
|
const re = /(--[\w-]+|[a-z-]+)\s*:\s*((?:[^;()]|\([^()]*(?:\([^()]*\)[^()]*)*\))*)/gi;
|
|
for (const m of body.matchAll(re)) out.push({ name: m[1], value: m[2].trim(), index: m.index });
|
|
return out;
|
|
}
|
|
|
|
// Extract a JS string literal starting at `at` (quote char), verified to be a pure literal before evaluation.
|
|
function stringLiteral(source, at) {
|
|
const quote = source[at];
|
|
let j = at + 1;
|
|
while (j < source.length && source[j] !== quote) j += source[j] === '\\' ? 2 : 1;
|
|
const literal = source.slice(at, j + 1);
|
|
if (!/^(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1$/.test(literal) || (quote === '`' && literal.includes('${'))) throw new Error(`Not a pure string literal at ${at}`);
|
|
return { text: vm.runInNewContext(literal, Object.create(null), { timeout: 1000 }), end: j + 1 };
|
|
}
|
|
|
|
// style-loader wrapper module → the css-loader module it injects → its CSS string literal.
|
|
function styleModule(js, wrapper) {
|
|
const head = new RegExp(`[,{]${wrapper}:\\(e,t,n\\)=>\\{[^]{0,400}?g=n\\((\\d+)\\)`).exec(js);
|
|
if (!head) return null;
|
|
const cssId = head[1];
|
|
const body = new RegExp(`[,{]${cssId}:\\(e,t,n\\)=>\\{[^]{0,400}?\\.push\\(\\[e\\.id,`).exec(js);
|
|
if (!body) return null;
|
|
const literalAt = body.index + body[0].length;
|
|
const { text } = stringLiteral(js, literalAt);
|
|
return { wrapper, cssId, offset: literalAt, sha256: sha256(text), css: text };
|
|
}
|
|
|
|
// Resolve the bundle's webpack request map ("./teamspeak.dark.scss": wrapperId) to the injected CSS.
|
|
function cssModuleForRequest(js, request) {
|
|
for (const m of js.matchAll(new RegExp(`"\\./${request.replace(/\./g, '\\.')}":(\\d+)`, 'g'))) {
|
|
const found = styleModule(js, m[1]);
|
|
if (found) return { request, mapOffset: m.index, ...found };
|
|
}
|
|
throw new Error(`Official CSS module for ${request} not found`);
|
|
}
|
|
|
|
// Platform style module selected by `window.os` at startup (macos/linux/windows), read from the bundle.
|
|
function platformModule(js, platform) {
|
|
const m = /"macos"===window\.os\?e\((\d+)\)\.A\.use\(\):"linux"===window\.os\?e\((\d+)\)\.A\.use\(\):"windows"===window\.os&&e\((\d+)\)\.A\.use\(\)/.exec(js);
|
|
if (!m) throw new Error('Official platform style switch not found');
|
|
const found = styleModule(js, { macos: m[1], linux: m[2], windows: m[3] }[platform]);
|
|
if (!found) throw new Error(`Official ${platform} platform style module not found`);
|
|
return { request: `platform:${platform}`, mapOffset: m.index, ...found };
|
|
}
|
|
|
|
function rootDeclarations(css, source) {
|
|
const out = [];
|
|
for (const rule of parseRules(css)) {
|
|
if (rule.at.length) continue;
|
|
const parts = rule.selector.split(',').map(s => s.trim());
|
|
if (!parts.includes(':root') || !parts.every(s => ROOT_SELECTORS.has(s))) continue;
|
|
const bodyStart = css.indexOf('{', rule.offset) + 1;
|
|
for (const d of declarations(rule.body)) if (d.name.startsWith('--')) out.push({ ...d, source, selector: rule.selector, offset: bodyStart + d.index });
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function resolveVar(map, value, seen = new Set()) {
|
|
let out = '', i = 0;
|
|
while (i < value.length) {
|
|
const k = value.indexOf('var(', i);
|
|
if (k < 0) { out += value.slice(i); break; }
|
|
out += value.slice(i, k);
|
|
let depth = 1, j = k + 4;
|
|
while (j < value.length && depth) { if (value[j] === '(') depth++; else if (value[j] === ')') depth--; j++; }
|
|
const inner = value.slice(k + 4, j - 1);
|
|
const comma = inner.indexOf(',');
|
|
const name = (comma < 0 ? inner : inner.slice(0, comma)).trim();
|
|
const fallback = comma < 0 ? undefined : inner.slice(comma + 1).trim();
|
|
if (map.has(name) && !seen.has(name)) out += resolveVar(map, map.get(name).value, new Set([...seen, name]));
|
|
else if (fallback !== undefined) out += resolveVar(map, fallback, seen);
|
|
else out += `UNRESOLVED(${name})`;
|
|
i = j;
|
|
}
|
|
return out.trim();
|
|
}
|
|
|
|
/**
|
|
* @param {{ dir?: string, platform?: 'windows'|'linux'|'macos', requireInspectedHashes?: boolean }} o
|
|
*/
|
|
export function loadOfficialReference({ dir = DEFAULT_OFFICIAL_DIR, platform = 'windows', requireInspectedHashes = true } = {}) {
|
|
const files = {};
|
|
for (const name of Object.keys(INSPECTED_SHA256)) {
|
|
const file = path.join(dir, name);
|
|
if (!existsSync(file)) throw new Error(`Official client UI file missing: ${file}`);
|
|
const data = readFileSync(file);
|
|
files[name] = { path: file, bytes: data.length, sha256: sha256(data), inspected: INSPECTED_SHA256[name] };
|
|
files[name].matchesInspected = files[name].sha256 === INSPECTED_SHA256[name];
|
|
}
|
|
const drift = Object.entries(files).filter(([, f]) => !f.matchesInspected).map(([n]) => n);
|
|
if (requireInspectedHashes && drift.length) throw new Error(`Official client UI changed since inspection (${drift.join(', ')}); re-inspect before comparing.`);
|
|
const mainCss = readFileSync(files['main.css'].path, 'utf8');
|
|
const js = readFileSync(files['main.js'].path, 'utf8');
|
|
const modules = {
|
|
platform: platformModule(js, platform),
|
|
dark: cssModuleForRequest(js, 'teamspeak.dark.scss'),
|
|
light: cssModuleForRequest(js, 'teamspeak.light.scss'),
|
|
small: cssModuleForRequest(js, 'small.scss'),
|
|
large: cssModuleForRequest(js, 'large.scss'),
|
|
};
|
|
// Official order: main.css <link>, then style-loader tags appended to <head> on use():
|
|
// platform module at bundle evaluation, theme module when the app component is created.
|
|
const tokens = {};
|
|
for (const theme of ['dark', 'light']) {
|
|
const map = new Map();
|
|
const layers = [['main.css', mainCss], [`main.js#${modules.platform.request}(${modules.platform.cssId})`, modules.platform.css], [`main.js#teamspeak.${theme}.scss(${modules[theme].cssId})`, modules[theme].css]];
|
|
for (const [source, css] of layers) for (const d of rootDeclarations(css, source)) map.set(d.name, d);
|
|
tokens[theme] = Object.fromEntries([...map].map(([name, d]) => [name, { value: d.value, resolved: resolveVar(map, d.value), source: d.source, offset: d.offset }]));
|
|
}
|
|
// Root-relative asset URLs (fonts/images) are rewritten to the installed directory for a
|
|
// transient QA page only; the rewritten text must never be committed or packaged.
|
|
const base = pathToFileURL(dir + path.sep).href;
|
|
const rewrite = css => css.replace(/url\((['"]?)\/(?!\/)/g, (_m, q) => `url(${q}${base}`);
|
|
return {
|
|
dir, platform, files, drift,
|
|
modules: Object.fromEntries(Object.entries(modules).map(([k, m]) => [k, { request: m.request, wrapper: m.wrapper, cssId: m.cssId, offset: m.offset, sha256: m.sha256, bytes: m.css.length }])),
|
|
tokens,
|
|
stylesheetsFor(theme) { return [rewrite(mainCss), modules.platform.css, modules[theme].css]; },
|
|
rules: { mainCss: () => parseRules(mainCss), module: key => parseRules(modules[key].css) },
|
|
};
|
|
}
|