Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/adapters/figma-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ function transformNode(node: Node): AnalysisNode {
if ("style" in node) {
base.style = node.style as Record<string, unknown>;
}
if ("textTruncation" in node && (node.textTruncation === "DISABLED" || node.textTruncation === "ENDING")) {
base.textTruncation = node.textTruncation;
}
if ("maxLines" in node && typeof node.maxLines === "number") {
base.maxLines = node.maxLines;
}

// Handoff status
if ("devStatus" in node && node.devStatus) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/contracts/figma-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ const BaseAnalysisNodeSchema = z.object({
// Text analysis
characters: z.string().optional(),
style: z.record(z.string(), z.unknown()).optional(),
textTruncation: z.enum(["DISABLED", "ENDING"]).optional(),
maxLines: z.number().optional(),

// Handoff analysis
devStatus: z
Expand Down
164 changes: 164 additions & 0 deletions src/core/design-tree/design-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,4 +1089,168 @@ describe("generateDesignTree", () => {
expect(output).not.toContain("url(images/");
});
});

describe("text auto-resize and truncation", () => {
it("emits text-resize: auto for WIDTH_AND_HEIGHT", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "Title",
type: "TEXT",
characters: "Hello",
style: { fontFamily: "Inter", textAutoResize: "WIDTH_AND_HEIGHT" },
absoluteBoundingBox: { x: 0, y: 0, width: 100, height: 20 },
})
);

const output = generateDesignTree(file);

expect(output).toContain("text-resize: auto");
});

it("emits text-resize: fixed-height for HEIGHT", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "Body",
type: "TEXT",
characters: "Wrapped text",
style: { fontFamily: "Inter", textAutoResize: "HEIGHT" },
absoluteBoundingBox: { x: 0, y: 0, width: 300, height: 48 },
})
);

const output = generateDesignTree(file);

expect(output).toContain("text-resize: fixed-height");
});

it("emits text-resize: truncate with max-lines for TRUNCATE", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "Truncated",
type: "TEXT",
characters: "Long text that gets cut off",
style: { fontFamily: "Inter", textAutoResize: "TRUNCATE" },
maxLines: 2,
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
})
);

const output = generateDesignTree(file);

expect(output).toContain("text-resize: truncate");
expect(output).toContain("text-overflow: ellipsis");
expect(output).toContain("max-lines: 2");
});

it("emits text-overflow: ellipsis when textTruncation is ENDING", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "Ellipsis",
type: "TEXT",
characters: "Truncated text",
style: { fontFamily: "Inter", textAutoResize: "HEIGHT" },
textTruncation: "ENDING",
maxLines: 3,
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 60 },
})
);

const output = generateDesignTree(file);

expect(output).toContain("text-overflow: ellipsis");
expect(output).toContain("max-lines: 3");
});

it("emits paragraph-spacing when set", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "Paragraphs",
type: "TEXT",
characters: "First paragraph\n\nSecond paragraph",
style: { fontFamily: "Inter", paragraphSpacing: 16 },
absoluteBoundingBox: { x: 0, y: 0, width: 300, height: 100 },
})
);

const output = generateDesignTree(file);

expect(output).toContain("paragraph-spacing: 16px");
});

it("emits text-resize: truncate without max-lines when maxLines is not set", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "TruncateNoMax",
type: "TEXT",
characters: "Truncated",
style: { fontFamily: "Inter", textAutoResize: "TRUNCATE" },
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
})
);

const output = generateDesignTree(file);

expect(output).toContain("text-resize: truncate");
expect(output).toContain("text-overflow: ellipsis");
expect(output).not.toContain("max-lines:");
});

it("does not emit text-overflow for textTruncation: DISABLED", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "NoTruncation",
type: "TEXT",
characters: "Normal text",
style: { fontFamily: "Inter", textAutoResize: "HEIGHT" },
textTruncation: "DISABLED",
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
})
);

const output = generateDesignTree(file);

expect(output).not.toContain("text-overflow:");
});

it("does not emit paragraph-spacing for 0", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "ZeroSpacing",
type: "TEXT",
characters: "Text",
style: { fontFamily: "Inter", paragraphSpacing: 0 },
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
})
);

const output = generateDesignTree(file);

expect(output).not.toContain("paragraph-spacing:");
});

it("does not emit text-resize for NONE or missing textAutoResize", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "Plain",
type: "TEXT",
characters: "No resize",
style: { fontFamily: "Inter" },
absoluteBoundingBox: { x: 0, y: 0, width: 100, height: 20 },
})
);

const output = generateDesignTree(file);

expect(output).not.toContain("text-resize:");
});
});
Comment on lines +1093 to +1255
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Good test coverage with a few edge cases to consider.

The test suite covers the main scenarios well. Consider adding these edge cases for completeness:

  1. TRUNCATE mode without maxLines - verifies only text-resize: truncate is emitted
  2. textTruncation: "DISABLED" - verifies no text-overflow: ellipsis is emitted
  3. paragraphSpacing: 0 - verifies no paragraph-spacing is emitted (falsy value)
💡 Optional: Additional edge case tests
it("emits text-resize: truncate without max-lines when maxLines is not set", () => {
  const file = makeFile(
    makeNode({
      id: "1:1",
      name: "TruncateNoMax",
      type: "TEXT",
      characters: "Truncated",
      style: { fontFamily: "Inter", textAutoResize: "TRUNCATE" },
      absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
    })
  );

  const output = generateDesignTree(file);

  expect(output).toContain("text-resize: truncate");
  expect(output).not.toContain("max-lines:");
});

it("does not emit text-overflow for textTruncation: DISABLED", () => {
  const file = makeFile(
    makeNode({
      id: "1:1",
      name: "NoTruncation",
      type: "TEXT",
      characters: "Normal text",
      style: { fontFamily: "Inter", textAutoResize: "HEIGHT" },
      textTruncation: "DISABLED",
      absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
    })
  );

  const output = generateDesignTree(file);

  expect(output).not.toContain("text-overflow:");
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/design-tree/design-tree.test.ts` around lines 1093 - 1200, Add three
edge-case tests to the existing "text auto-resize and truncation" suite using
makeFile/makeNode and generateDesignTree: (1) a TRUNCATE text node without
maxLines that asserts output contains "text-resize: truncate" and does NOT
contain "max-lines:"; (2) a text node with textTruncation: "DISABLED" (and
textAutoResize e.g. "HEIGHT") that asserts output does NOT contain
"text-overflow:"; (3) a text node with style.paragraphSpacing: 0 that asserts
output does NOT contain "paragraph-spacing:". Use unique test names like "emits
text-resize: truncate without max-lines", "does not emit text-overflow for
DISABLED", and "does not emit paragraph-spacing for 0" to match the existing
pattern.

});
28 changes: 28 additions & 0 deletions src/core/design-tree/design-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,34 @@ function renderNode(

const textColor = getFill(node);
if (textColor) styles.push(`color: ${textColor}`);

// Text auto-resize behavior
const textAutoResize = s["textAutoResize"] as string | undefined;
if (textAutoResize === "WIDTH_AND_HEIGHT") {
styles.push("text-resize: auto");
} else if (textAutoResize === "HEIGHT") {
styles.push("text-resize: fixed-height");
} else if (textAutoResize === "TRUNCATE") {
styles.push("text-resize: truncate");
styles.push("text-overflow: ellipsis");
if (node.maxLines != null) {
styles.push(`max-lines: ${node.maxLines}`);
}
}

// Text truncation (when textAutoResize is not TRUNCATE but truncation is set)
if (textAutoResize !== "TRUNCATE" && node.textTruncation === "ENDING") {
styles.push("text-overflow: ellipsis");
if (node.maxLines != null) {
styles.push(`max-lines: ${node.maxLines}`);
}
}

// Paragraph spacing
const paragraphSpacing = s["paragraphSpacing"] as number | undefined;
if (paragraphSpacing) {
styles.push(`paragraph-spacing: ${paragraphSpacing}px`);
}
}

// Text content
Expand Down
Loading