// Native editable geometry and edges; scoped editorial typography for Stage 01.
export const isSkillsStory = name => /^strategy-(governance|quality|adoption|measurement|baseline|maintenance|stage01|stage02|six-months)(-mobile)?$/.test(name);
const escape = text => text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
export function skillsViewer(html, spec) {
if (spec.diagram_type !== 'architecture' || !spec.components.length) throw new Error('Skills story contract drift');
const stageMobile = /strategy-(stage0[12]|six-months)-mobile\//.test(spec.meta.output);
const detailSize = stageMobile ? 38 : spec.meta.output.includes('-mobile/') ? 34 : 32;
for (const node of spec.components) {
const pattern = new RegExp(`]*data-node-id="${node.id}"[^>]*>[\\s\\S]*?`);
const match = html.match(pattern);
if (!match) throw new Error(`Missing Skills node: ${node.id}`);
const original = match[0];
const rectangles = [...original.matchAll(/]*class="c-[^"]+"[^>]*\/>/g)];
if (rectangles.length !== 2) throw new Error('Skills shape contract drift');
const [x,y] = node.pos;
const lines = node.sublabel.split('\n');
if (!node.tag || !node.sublabel || lines.length > 4) throw new Error(`Skills copy exceeds capacity: ${node.id}`);
const text = (value, top, size, attrs) => `${escape(value)}`;
const content = text(node.tag, 40, detailSize, 'class="t-muted" data-detail="context"')
+ text(node.label, 89, stageMobile ? 40 : 36, 'class="t-primary" data-node-label="" font-weight="700"')
+ lines.map((line,i) => text(line, 138+i*42, detailSize, 'class="t-primary" data-detail="context"')).join('');
const prefix = original.slice(0,rectangles[1].index+rectangles[1][0].length).replaceAll('rx="6"','rx="0"');
html = html.replace(original,prefix+content+'');
}
const roots = [...html.matchAll(/