MCPcopy Create free account
hub / github.com/benjitaylor/agentation / formatReferenceFrame

Function formatReferenceFrame

package/src/components/design-mode/output.ts:33–55  ·  view source on GitHub ↗

* Generate a reference frame section with viewport, content area, and * pixel-to-CSS translation formulas. Included in all non-compact output.

(layout: PageLayout)

Source from the content-addressed store, hash-verified

31 * pixel-to-CSS translation formulas. Included in all non-compact output.
32 */
33function formatReferenceFrame(layout: PageLayout): string {
34 const { viewport, contentArea } = layout;
35 let out = "### Reference Frame\n";
36 out += `- Viewport: \`${viewport.width}×${viewport.height}px\`\n`;
37
38 if (contentArea) {
39 const ca = contentArea;
40 out += `- Content area: \`${ca.width}px\` wide, left edge at \`x=${ca.left}\`, right at \`x=${ca.right}\` (\`${ca.selector}\`)\n`;
41 out += `- Pixel → CSS translation:\n`;
42 out += ` - **Horizontal position in container**: \`element.x - ${ca.left}\` → use as \`margin-left\` or \`left\`\n`;
43 out += ` - **Width as % of container**: \`element.width / ${ca.width} × 100\` → use as \`width: X%\`\n`;
44 out += ` - **Vertical gap between elements**: \`nextElement.y - (prevElement.y + prevElement.height)\` → use as \`margin-top\` or \`gap\`\n`;
45 out += ` - **Centered**: if \`|element.centerX - ${ca.centerX}| < 20px\` → use \`margin-inline: auto\`\n`;
46 } else {
47 out += `- No distinct content container — elements positioned relative to full viewport\n`;
48 out += `- Pixel → CSS translation:\n`;
49 out += ` - **Width as % of viewport**: \`element.width / ${viewport.width} × 100\` → use as \`width: X%\`\n`;
50 out += ` - **Centered**: if \`|(element.x + element.width/2) - ${Math.round(viewport.width / 2)}| < 20px\` → use \`margin-inline: auto\`\n`;
51 }
52
53 out += "\n";
54 return out;
55}
56
57/**
58 * Format parent layout context for an element.

Callers 2

generateDesignOutputFunction · 0.85
generateRearrangeOutputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…