Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(check): flag connectors that point at nothing and stylesheets that leak into the frame (#3736)
Xuanru Lie5d89f770fbe
diff --git a/packages/cli/src/commands/layout-audit.browser.js b/packages/cli/src/commands/layout-audit.browser.jsindex 0655e1650d..adc09b1323 100644--- a/packages/cli/src/commands/layout-audit.browser.js+++ b/packages/cli/src/commands/layout-audit.browser.js@@ -1300,7 +1300,7 @@const threshold = Math.max(32, Math.min(rootRect.width, rootRect.height) * 0.02);const MIN_CONNECTOR_CHORD_PX = 8;for (const svg of Array.from(root.querySelectorAll("svg"))) {- if (!isVisibleElement(svg) || hasAllowOverflowFlag(svg)) continue;+ if (!isVisibleElement(svg)) continue;for (const path of Array.from(svg.querySelectorAll("path"))) {if (path.closest(CONNECTOR_SKIP_CONTAINERS)) continue;if (!isConnectorPath(svg, path)) continue;@@ -1333,7 +1333,16 @@// Paste-into-`d` bug: both raw endpoints land on distinct anchors as screen pixels.const userStartKey = attachmentKey(user.start);const userEndKey = attachmentKey(user.end);- if (!userStartKey || !userEndKey || userStartKey === userEndKey) continue;+ const pasteBug = Boolean(userStartKey && userEndKey && userStartKey !== userEndKey);+ // Guessed marked shaft: both frames miss. Same-anchor grazes attach in user-space+ // and must stay skipped. Name-only decorative flow/arrow paths stay skipped.+ // 80px keeps short marker glyphs (chevrons, tips) out.+ const markedMiss =+ renderedChord >= 80 &&+ !userStartKey &&+ !userEndKey &&+ (path.hasAttribute("marker-start") || path.hasAttribute("marker-end"));+ if (!pasteBug && !markedMiss) continue;const gap = Math.round(Math.min(Math.min(...anchors.compact.map((a) => distanceToRect(rendered.start, a.rect))),@@ -1346,7 +1355,113 @@time,selector: selectorFor(path),containerSelector: selectorFor(svg),- message: `Connector path endpoints render ${gap}px from the nearest anchorable element, but the path's user-space coordinates would attach if read as screen pixels — screen/viewport numbers were likely written into SVG \`d\` without inverting the CTM.`,+ message: pasteBug+ ? `Connector path endpoints render ${gap}px from the nearest anchorable element, but the path's user-space coordinates would attach if read as screen pixels — screen/viewport numbers were likely written into SVG \`d\` without inverting the CTM.`+ : `Connector path endpoints render ${gap}px from the nearest anchorable element — a marked shaft that meets no node.`,+ rect: toRect({+ left: Math.min(rendered.start.x, rendered.end.x),+ top: Math.min(rendered.start.y, rendered.end.y),+ right: Math.max(rendered.start.x, rendered.end.x),+ bottom: Math.max(rendered.start.y, rendered.end.y),+ width: Math.abs(rendered.end.x - rendered.start.x),+ height: Math.abs(rendered.end.y - rendered.start.y),+ }),+ fixHint: pasteBug+ ? "Convert measured screen coordinates into the SVG's user space (subtract the SVG rect / invert getScreenCTM) before writing path `d`, and keep the SVG a direct child of the stage."+ : "Measure the settled node boxes and write `d` in the SVG's user space (invert getScreenCTM), or grow a layout-owned shaft from the source node.",+ });+ }+ }+ return issues;+ }++ function shaftIsPainted(path) {+ if (IGNORE_TAGS.has(path.tagName) || hasIgnoreFlag(path)) return false;+ const style = getComputedStyle(path);+ if (+ style.display === "none" ||+ style.visibility === "hidden" ||+ style.visibility === "collapse"+ ) {+ return false;+ }+ return opacityChain(path) >= 0.2;+ }++ function shaftDashHidden(path) {+ if (typeof path.getTotalLength !== "function") return false;+ let total;+ try {+ total = path.getTotalLength();+ } catch {+ return false;+ }+ if (!Number.isFinite(total) || total <= 0) return false;+ const style = getComputedStyle(path);+ const offset = Number.parseFloat(style.strokeDashoffset || "0");+ const dash = Number.parseFloat(String(style.strokeDasharray || "").split(/[\s,]+/)[0] || "0");+ return offset >= total * 0.9 && dash >= total * 0.9;+ }++ function connectorEndpointCandidates(root, rootRect) {+ const candidates = [];+ const rootArea = rectArea(rootRect);+ for (const element of Array.from(root.querySelectorAll("*"))) {+ if (element.closest("svg") || IGNORE_TAGS.has(element.tagName) || hasIgnoreFlag(element))+ continue;+ const style = getComputedStyle(element);+ const opaque = RASTER_TAGS.has(element.tagName) || hasOpaqueBackground(style);+ if (!opaque && !textContentFor(element)) continue;+ const rect = toRect(element.getBoundingClientRect());+ const area = rectArea(rect);+ if (area < 400 || area > rootArea * 0.15) continue;+ candidates.push({ rect, element });+ }+ return candidates;+ }++ function connectorOrphanIssues(root, rootRect, time) {+ const issues = [];+ let candidates = null;+ const threshold = Math.max(32, Math.min(rootRect.width, rootRect.height) * 0.02);+ for (const svg of Array.from(root.querySelectorAll("svg"))) {+ if (!isVisibleElement(svg)) continue;+ for (const path of Array.from(svg.querySelectorAll("path"))) {+ if (path.closest(CONNECTOR_SKIP_CONTAINERS)) continue;+ if (!isConnectorPath(svg, path)) continue;+ if (!shaftIsPainted(path) || shaftDashHidden(path)) continue;+ const user = pathUserEndpoints(path);+ const rendered = pathScreenEndpoints(svg, path, user);+ if (!user || !rendered) continue;+ const renderedChord = Math.hypot(+ rendered.end.x - rendered.start.x,+ rendered.end.y - rendered.start.y,+ );+ if (renderedChord < 80) continue;+ if (candidates === null) candidates = connectorEndpointCandidates(root, rootRect);+ const dark = [];+ for (const point of [rendered.start, rendered.end]) {+ let best = null;+ let attached = false;+ for (const candidate of candidates) {+ const gap = distanceToRect(point, candidate.rect);+ if (gap > threshold) continue;+ if (isVisibleElement(candidate.element)) {+ attached = true;+ break;+ }+ if (best === null || gap < best.gap) best = { gap, candidate };+ }+ if (!attached && best !== null) dark.push(best.candidate);+ }+ if (dark.length === 0) continue;+ issues.push({+ code: "connector_orphan",+ severity: "warning",+ time,+ selector: selectorFor(path),+ containerSelector: selectorFor(svg),+ message: `Connector shaft is visible while ${dark.length === 2 ? "both endpoints are" : `its endpoint ${selectorFor(dark[0].element)} is`} not on stage.`,rect: toRect({left: Math.min(rendered.start.x, rendered.end.x),top: Math.min(rendered.start.y, rendered.end.y),@@ -1356,7 +1471,7 @@height: Math.abs(rendered.end.y - rendered.start.y),}),fixHint:- "Convert measured screen coordinates into the SVG's user space (subtract the SVG rect / invert getScreenCTM) before writing path `d`, and keep the SVG a direct child of the stage.",+ "Show the shaft only after both ends are on, and hide it with the earlier exit. Do not give the line its own clock.",});}}@@ -1467,6 +1582,7 @@issues.push(...escaped.issues);issues.push(...panelOutOfCanvasIssues(root, rootRect, time, tolerance, escaped.flagged));issues.push(...connectorDetachmentIssues(root, rootRect, time));+ issues.push(...connectorOrphanIssues(root, rootRect, time));return issues;};diff --git a/packages/cli/src/commands/layout-audit.browser.test.ts b/packages/cli/src/commands/layout-audit.browser.test.tsindex 3886d27d77..d5c829cd4d 100644--- a/packages/cli/src/commands/layout-audit.browser.test.ts+++ b/packages/cli/src/commands/layout-audit.browser.test.ts@@ -1107,6 +1107,38 @@ describe("layout-audit.browser coordinate-frame findings", () => {expect(runAudit().filter((issue) => issue.code === "connector_detached")).toEqual([]);});+ it("flags a long marked shaft whose rendered ends miss every node", () => {+ document.body.innerHTML = `+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">+ <div id="n1"></div>+ <div id="n2"></div>+ <svg id="schematic-svg">+ <defs><marker id="arrowhead"><path id="tip" d="M 0 0 L 8 4 L 0 8" /></marker></defs>+ <path id="path-input" d="M 40 540 L 720 540" marker-end="url(#arrowhead)" />+ </svg>+ </div>+ `;+ installGeometry(+ {+ root: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ n1: rect({ left: 900, top: 400, width: 160, height: 160 }),+ n2: rect({ left: 1400, top: 400, width: 160, height: 160 }),+ "schematic-svg": rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ },+ {+ n1: { backgroundColor: "rgb(30, 40, 50)" },+ n2: { backgroundColor: "rgb(30, 40, 50)" },+ },+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_detached");+ expect(issues).toHaveLength(1);+ expect(issues[0]).toMatchObject({ selector: "#path-input" });+ expect(issues[0]?.message).toContain("marked shaft that meets no node");+ });+// Same DOM node via painted-inside + compact-near-miss must share one identity (not p0 vs c0).it("skips same-anchor cross-tier arrows that only graze one node", () => {document.body.innerHTML = `@@ -1301,6 +1333,427 @@ describe("layout-audit.browser coordinate-frame findings", () => {expect(runAudit().filter((issue) => issue.code === "connector_detached")).toEqual([]);});++ const orphanDom = `+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">+ <div id="n1"></div>+ <div id="n2"></div>+ <div id="caption">Pipeline overview</div>+ <div id="footer">Confidential</div>+ <svg id="connectors">+ <defs><marker id="arrowhead"><path id="tip" d="M 0 0 L 8 4 L 0 8" /></marker></defs>+ <path id="path-input" d="M 360 480 L 1400 480" marker-end="url(#arrowhead)" />+ </svg>+ </div>+ `;+ const orphanRects = {+ root: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ n1: rect({ left: 200, top: 400, width: 160, height: 160 }),+ n2: rect({ left: 1400, top: 400, width: 160, height: 160 }),+ caption: rect({ left: 200, top: 100, width: 600, height: 80 }),+ footer: rect({ left: 200, top: 900, width: 600, height: 60 }),+ connectors: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ };+ const orphanStyles = (overrides: Record<string, Record<string, string>>) => ({+ n1: { backgroundColor: "rgb(30, 40, 50)" },+ n2: { backgroundColor: "rgb(30, 40, 50)" },+ caption: { backgroundColor: "rgb(30, 40, 50)" },+ footer: { backgroundColor: "rgb(30, 40, 50)" },+ ...overrides,+ });++ it("flags a shaft whose own endpoint node is not on stage", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]).toMatchObject({ selector: "#path-input" });+ expect(issues[0]?.message).toContain("#n2");+ });++ it("names both endpoints when neither is on stage", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({+ n1: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" },+ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" },+ }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]?.message).toContain("both endpoints");+ });++ it("still flags a dark endpoint while other elements are on stage", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]?.message).toContain("#n2");+ });++ it("flags a horizontal shaft, whose bounding box has no height", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();+ const flat = document.getElementById("path-input");+ if (flat) {+ const box = { left: 360, top: 480, right: 1400, bottom: 480, width: 1040, height: 0 };+ flat.getBoundingClientRect = () => ({ ...box, x: box.left, y: box.top, toJSON: () => box });+ }++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]?.message).toContain("#n2");+ });++ it("does not orphan a shaft whose endpoints are both on stage", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(orphanRects, orphanStyles({}));+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("does not orphan a shaft whose ends meet no node at all", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ { ...orphanRects, n1: rect({ left: 900, top: 900, width: 160, height: 160 }) },+ orphanStyles({}),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("orphans an unmarked flow-layer shaft whose endpoint node is hidden", () => {+ document.body.innerHTML = `+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">+ <div id="n1"></div>+ <div id="n2"></div>+ <div id="caption">Pipeline overview</div>+ <div id="footer">Confidential</div>+ <svg id="flow-svg" class="flow-svg">+ <path id="path-to-commitment" d="M 360 480 L 1400 480" />+ </svg>+ </div>+ `;+ installGeometry(+ {+ ...orphanRects,+ "flow-svg": orphanRects.connectors,+ },+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]).toMatchObject({ selector: "#path-to-commitment" });+ });++ it("does not orphan an unnamed decorative path that runs between real nodes", () => {+ document.body.innerHTML = orphanDom+ .replace(+ '<path id="path-input" d="M 360 480 L 1400 480" marker-end="url(#arrowhead)" />',+ '<path id="drafting-line" d="M 360 480 L 1400 480" />',+ )+ .replace('<svg id="connectors">', '<svg id="decor">');+ installGeometry(+ { ...orphanRects, decor: orphanRects.connectors },+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("orphans that same path once it carries an arrowhead", () => {+ document.body.innerHTML = orphanDom.replace('<svg id="connectors">', '<svg id="decor">');+ installGeometry(+ { ...orphanRects, decor: orphanRects.connectors },+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toHaveLength(1);+ });++ it("does not orphan a shaft still hidden behind its dash offset", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({+ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" },+ "path-input": { strokeDasharray: "100", strokeDashoffset: "100" },+ }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ const guardDom = (edge: string) => `+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">+ <div id="n1"></div>+ ${edge === "in-svg" ? "" : '<div id="edge"></div>'}+ <svg id="connectors">+ <defs><marker id="arrowhead"><path id="tip" d="M 0 0 L 8 4 L 0 8" /></marker></defs>+ ${edge === "in-svg" ? '<rect id="edge" />' : ""}+ <path id="path-input" d="M 360 480 L 1400 480" marker-end="url(#arrowhead)" />+ </svg>+ </div>+ `;+ const guardBase = {+ root: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ n1: rect({ left: 200, top: 400, width: 160, height: 160 }),+ connectors: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ };+ const opaqueHidden = { backgroundColor: "rgb(30, 40, 50)", opacity: "0" };+ const endpointGuardCases = [+ {+ name: "an element inside the connector svg is never an endpoint",+ dom: "in-svg",+ edgeRect: rect({ left: 1400, top: 400, width: 160, height: 160 }),+ edgeStyle: opaqueHidden,+ },+ {+ name: "a box with neither paint nor text is never an endpoint",+ dom: "outside",+ edgeRect: rect({ left: 1400, top: 400, width: 160, height: 160 }),+ edgeStyle: { opacity: "0" },+ },+ {+ name: "a box below the area floor is never an endpoint",+ dom: "outside",+ edgeRect: rect({ left: 1400, top: 470, width: 16, height: 16 }),+ edgeStyle: opaqueHidden,+ },+ {+ name: "a box larger than a stage fraction is never an endpoint",+ dom: "outside",+ edgeRect: rect({ left: 1000, top: 200, width: 1200, height: 600 }),+ edgeStyle: opaqueHidden,+ },+ ];+ for (const guard of endpointGuardCases) {+ it(guard.name, () => {+ document.body.innerHTML = guardDom(guard.dom);+ installGeometry(+ { ...guardBase, edge: guard.edgeRect },+ { n1: { backgroundColor: "rgb(30, 40, 50)" }, edge: guard.edgeStyle },+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });+ }++ it("skips a connector layer the composition has taken off screen", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({+ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" },+ connectors: { display: "none" },+ }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("skips the arrowhead glyph living in defs", () => {+ document.body.innerHTML = orphanDom.replace(+ '<path id="tip" d="M 0 0 L 8 4 L 0 8" />',+ '<path id="tip" class="connector" d="M 360 480 L 1400 480" marker-end="url(#arrowhead)" />',+ );+ installGeometry(+ orphanRects,+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]).toMatchObject({ selector: "#path-input" });+ });++ it("skips a marked stub too short to read as a link", () => {+ document.body.innerHTML = orphanDom.replace(+ 'd="M 360 480 L 1400 480"',+ 'd="M 360 480 L 400 480"',+ );+ installGeometry(+ { ...orphanRects, n2: rect({ left: 400, top: 400, width: 160, height: 160 }) },+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("does not blame a staged halo that sits on a live node", () => {+ document.body.innerHTML = orphanDom.replace(+ '<div id="n2"></div>',+ '<div id="n2-halo"></div>\n <div id="n2"></div>',+ );+ installGeometry(+ { ...orphanRects, "n2-halo": rect({ left: 1390, top: 390, width: 180, height: 180 }) },+ orphanStyles({ "n2-halo": { backgroundColor: "rgb(80, 90, 100)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("orphans a dark endpoint when the connector svg allows overflow", () => {+ document.body.innerHTML = orphanDom.replace(+ '<svg id="connectors">',+ '<svg id="connectors" data-layout-allow-overflow>',+ );+ installGeometry(+ orphanRects,+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_orphan");+ expect(issues).toHaveLength(1);+ expect(issues[0]).toMatchObject({ selector: "#path-input" });+ });++ const hiddenShaftStyles: Array<Record<string, string>> = [+ { opacity: "0" },+ { display: "none" },+ { visibility: "hidden" },+ { visibility: "collapse" },+ ];+ for (const hidden of hiddenShaftStyles) {+ const label = Object.entries(hidden)+ .map(([k, v]) => `${k}: ${v}`)+ .join(", ");+ it(`stays quiet while the shaft itself is still staged hidden (${label})`, () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ orphanRects,+ orphanStyles({+ n2: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" },+ "path-input": hidden,+ }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });+ }++ it("cannot reach an endpoint node hidden with display:none", () => {+ document.body.innerHTML = orphanDom;+ installGeometry(+ { ...orphanRects, n2: rect({ left: 0, top: 0, width: 0, height: 0 }) },+ orphanStyles({ n2: { backgroundColor: "rgb(30, 40, 50)", display: "none" } }),+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ const issues = runAudit();+ expect(issues.filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ expect(issues.filter((issue) => issue.code === "connector_detached")).toEqual([]);+ });++ it("does not blame a hidden element that sits well past the endpoint", () => {+ document.body.innerHTML = `+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">+ <div id="n1"></div>+ <div id="ghost"></div>+ <svg id="connectors">+ <defs><marker id="arrowhead"><path id="tip" d="M 0 0 L 8 4 L 0 8" /></marker></defs>+ <path id="path-input" d="M 360 480 L 1400 480" marker-end="url(#arrowhead)" />+ </svg>+ </div>+ `;+ installGeometry(+ {+ root: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ n1: rect({ left: 200, top: 400, width: 160, height: 160 }),+ ghost: rect({ left: 1500, top: 400, width: 160, height: 160 }),+ connectors: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ },+ {+ n1: { backgroundColor: "rgb(30, 40, 50)" },+ ghost: { backgroundColor: "rgb(30, 40, 50)", opacity: "0" },+ },+ );+ installConnectorGeometry({ e: 0, f: 0 });+ installAuditScript();++ expect(runAudit().filter((issue) => issue.code === "connector_orphan")).toEqual([]);+ });++ it("detaches a paste-bug shaft when the connector svg allows overflow", () => {+ document.body.innerHTML = `+ <div id="root" data-composition-id="main" data-width="1920" data-height="1080">+ <div id="n1"></div>+ <div id="n2"></div>+ <svg id="connector-svg" data-layout-allow-overflow>+ <defs><marker id="arrow"><path id="tip" d="M 0 0 L 8 4 L 0 8" /></marker></defs>+ <path id="detached" class="connector-line" d="M 980 580 L 380 280" />+ </svg>+ </div>+ `;+ installGeometry(+ {+ root: rect({ left: 0, top: 0, width: 1920, height: 1080 }),+ n1: rect({ left: 900, top: 500, width: 160, height: 160 }),+ n2: rect({ left: 300, top: 200, width: 160, height: 160 }),+ "connector-svg": rect({ left: 80, top: 227, width: 1740, height: 830 }),+ },+ {+ n1: { backgroundColor: "rgb(30, 40, 50)" },+ n2: { backgroundColor: "rgb(30, 40, 50)" },+ },+ );+ installConnectorGeometry({ e: 80, f: 227 });+ installAuditScript();++ const issues = runAudit().filter((issue) => issue.code === "connector_detached");+ expect(issues).toHaveLength(1);+ expect(issues[0]).toMatchObject({ selector: "#detached" });+ });});describe("layout-audit.browser content overlap", () => {diff --git a/packages/cli/src/utils/checkBrowser.ts b/packages/cli/src/utils/checkBrowser.tsindex 21a12db9dc..006172e738 100644--- a/packages/cli/src/utils/checkBrowser.ts+++ b/packages/cli/src/utils/checkBrowser.ts@@ -1221,6 +1221,7 @@ const LAYOUT_ISSUE_CODES: readonly LayoutIssueCode[] = ["escaped_container","panel_out_of_canvas","connector_detached",+ "connector_orphan","rotation_pivot_drift","off_pivot_rotation","motion_appears_late",diff --git a/packages/cli/src/utils/layoutAudit.test.ts b/packages/cli/src/utils/layoutAudit.test.tsindex c4048d16e3..b92389122e 100644--- a/packages/cli/src/utils/layoutAudit.test.ts+++ b/packages/cli/src/utils/layoutAudit.test.ts@@ -437,12 +437,32 @@ describe("persistence-tiered severity (#U10)", () => {"escaped_container","panel_out_of_canvas","connector_detached",+ "connector_orphan",] as const) {const collapsed = collapseStaticLayoutIssues([{ ...issue(code, "warning"), time: 3 }], 9);expect(collapsed[0]).toMatchObject({ severity: "info", occurrences: 1 });}});+ it("keeps id-less connector findings apart by geometry, so each stays a single sample", () => {+ for (const code of ["connector_detached", "connector_orphan"] as const) {+ const shaft = { ...issue(code, "warning"), selector: "svg path" };+ const collapsed = collapseStaticLayoutIssues(+ [+ { ...shaft, time: 1, rect: { ...shaft.rect, left: 100, top: 100 } },+ { ...shaft, time: 3, rect: { ...shaft.rect, left: 600, top: 300 } },+ { ...shaft, time: 5, rect: { ...shaft.rect, left: 1200, top: 700 } },+ ],+ 9,+ );++ expect(collapsed).toHaveLength(3);+ for (const finding of collapsed) {+ expect(finding).toMatchObject({ severity: "info", occurrences: 1 });+ }+ }+ });+it("keeps a held but small canvas_overflow at info", () => {const breach = {...issue("canvas_overflow", "info"),diff --git a/packages/cli/src/utils/layoutAudit.ts b/packages/cli/src/utils/layoutAudit.tsindex b8f2985f88..cc498f09e7 100644--- a/packages/cli/src/utils/layoutAudit.ts+++ b/packages/cli/src/utils/layoutAudit.ts@@ -23,6 +23,7 @@ export type LayoutIssueCode =| "escaped_container"| "panel_out_of_canvas"| "connector_detached"+ | "connector_orphan"// Cross-sample rotation finding — a spinning element whose bbox center drifts// because it pivots about the wrong point (bad transformOrigin/svgOrigin).| "rotation_pivot_drift"@@ -203,6 +204,7 @@ const PERSISTENCE_TIERED_CODES: ReadonlySet<LayoutIssueCode> = new Set(["escaped_container","panel_out_of_canvas","connector_detached",+ "connector_orphan",]);const CONTIGUOUS_SAMPLE_GAP_MS = CONTENT_OVERLAP_HELD_ERROR_MS * 2;@@ -385,8 +387,10 @@ function staticIssueKey(issue: LayoutIssue): string {}function framePositionKey(issue: LayoutIssue): string {- // connector_detached shares it: id-less paths collapse to one selector, so distinct lines need geometry in the key.- return issue.code === "frame_out_of_frame" || issue.code === "connector_detached"+ // connector_detached and connector_orphan share it: id-less paths collapse to one selector, so distinct lines need geometry in the key.+ return issue.code === "frame_out_of_frame" ||+ issue.code === "connector_detached" ||+ issue.code === "connector_orphan"? `${Math.round(issue.rect.left)},${Math.round(issue.rect.top)}`: "";}diff --git a/packages/lint/src/rules/core.test.ts b/packages/lint/src/rules/core.test.tsindex d11d9a4b67..12502b48e1 100644--- a/packages/lint/src/rules/core.test.ts+++ b/packages/lint/src/rules/core.test.ts@@ -294,6 +294,79 @@ describe("core rules", () => {expect(finding).toBeUndefined();});+ it("reports error when an extra style closer dumps CSS as text", async () => {+ const html = compositionWithBodyPrefix(+ "",+ `+ <style>+ .editorial-block { color: #fff; }+ </style>+ </style>+ .leftover { color: red; }+ <div class="editorial-block">Hello</div>+`,+ );+ const result = await lintHyperframeHtml(html);+ const finding = result.findings.find((f) => f.code === "unbalanced_style_tags");+ expect(finding).toBeDefined();+ expect(finding?.severity).toBe("error");+ expect(finding?.message).toContain("extra </style>");+ });++ it("does not count style text inside a script closed with a spaced end tag", async () => {+ const html = compositionWithBodyPrefix(+ "",+ `+ <style>+ .editorial-block { color: #fff; }+ </style>+ <script>+ const marker = "</style>";+ </script >+ <div class="editorial-block">Hello</div>+`,+ );+ const result = await lintHyperframeHtml(html);+ expect(result.findings.find((f) => f.code === "unbalanced_style_tags")).toBeUndefined();+ });++ it("reports an extra closer written as </style >", async () => {+ const html = compositionWithBodyPrefix(+ "",+ `+ <style>+ .editorial-block { color: #fff; }+ </style >+ </style >+ .leftover { color: red; }+ <div class="editorial-block">Hello</div>+`,+ );+ const result = await lintHyperframeHtml(html);+ expect(result.findings.find((f) => f.code === "unbalanced_style_tags")?.severity).toBe("error");+ });++ it("does not count a closer that only appears inside an html comment", async () => {+ const html = compositionWithBodyPrefix(+ "",+ `+ <style>+ .editorial-block { color: #fff; }+ </style>+ <!-- dropped the second sheet: </style> -->+ <div class="editorial-block">Hello</div>+`,+ );+ const result = await lintHyperframeHtml(html);+ expect(result.findings.find((f) => f.code === "unbalanced_style_tags")).toBeUndefined();+ });++ it("does not report paired style blocks", async () => {+ const html = compositionWithBodyPrefix("", `<div class="editorial-block">Hello</div>`);+ const result = await lintHyperframeHtml(html);+ expect(result.findings.find((f) => f.code === "unbalanced_style_tags")).toBeUndefined();+ });+it("reports error when CSS block comment syntax leaks into visible markup", async () => {const html = compositionWithBodyPrefix("",diff --git a/packages/lint/src/rules/core.ts b/packages/lint/src/rules/core.tsindex d387a42d53..6f8569034b 100644--- a/packages/lint/src/rules/core.ts+++ b/packages/lint/src/rules/core.ts@@ -231,6 +231,35 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [return findings;},+ // unbalanced_style_tags+ ({ source }) => {+ let opens = 0;+ let closes = 0;+ let firstTag = "";+ for (const match of source.matchAll(+ /<script\b[\s\S]*?<\/script[^>]*>|<style\b|<\/style\s*>/gi,+ )) {+ const token = match[0].toLowerCase();+ if (token.startsWith("<script")) continue;+ if (token.startsWith("</style")) closes += 1;+ else opens += 1;+ if (!firstTag) firstTag = match[0];+ }+ if (opens === closes) return [];+ return [+ {+ code: "unbalanced_style_tags",+ severity: "error",+ message:+ opens > closes+ ? "A <style> block is never closed, so following markup is parsed as CSS and disappears from the frame."+ : "An extra </style> closes the stylesheet early, so trailing CSS renders as visible on-screen text.",+ fixHint: "Keep <style> and </style> paired. One extra closer dumps CSS into the body.",+ snippet: truncateSnippet(firstTag || "<style>"),+ },+ ];+ },+// visible_markup_comment({ source }) => {const snippet = findVisibleMarkupCommentLeak(source);