-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
import { describe, expect, it } from "vitest";
import type * as figma from "../../../figma";
import { defaultPreferenecs, type Preferences } from "../../../preferences";
import { fromNode } from "./fromNode";
import { serializeStyle } from "./serialize";
describe("fromNode", () => {
describe("padding", () => {
it("Should have v/h padding rule for v/h paddings", () => {
const input: figma.Node & figma.HasLegacyPadding = {
id: "",
name: "",
type: "",
horizontalPadding: 1,
verticalPadding: 2,
};
expect(
fromNode(input, defaultPreferenecs).map((s) =>
serializeStyle(s, defaultPreferenecs),
),
).toContain("padding: 2px 1px;");
});
it("Should have single-value padding rule for v/h paddings are the same value", () => {
const input: figma.Node & figma.HasLegacyPadding = {
id: "",
name: "",
type: "",
horizontalPadding: 5,
verticalPadding: 5,
};
expect(
fromNode(input, defaultPreferenecs).map((s) =>
serializeStyle(s, defaultPreferenecs),
),
).toContain("padding: 5px;");
});
it("Should have four-value padding", () => {
const input: figma.Node & figma.HasPadding = {
id: "",
name: "",
type: "",
paddingTop: 1,
paddingRight: 2,
paddingBottom: 3,
paddingLeft: 4,
};
expect(
fromNode(input, defaultPreferenecs).map((s) =>
serializeStyle(s, defaultPreferenecs),
),
).toContain("padding: 1px 2px 3px 4px;");
});
});
describe("effects", () => {
it("Should convert inner shadow effect", () => {
const input: figma.Node & figma.HasEffects = {
id: "",
name: "",
type: "",
effects: [
{
type: "INNER_SHADOW",
radius: 5,
spread: 1,
visible: true,
offset: { x: 3, y: 4 },
color: { r: 1, g: 1, b: 1, a: 1 },
blendMode: "NORMAL",
} satisfies figma.ShadowEffect,
],
};
const preferences: Preferences = {
...defaultPreferenecs,
cssColorNotation: "hex",
};
expect(
fromNode(input, preferences).map((s) => serializeStyle(s, preferences)),
).toContain("box-shadow: 3px 4px 5px 1px #ffffff inset;");
});
it("Should skip invisible effects", () => {
const input: figma.Node & figma.HasEffects = {
id: "",
name: "",
type: "",
effects: [
{
type: "INNER_SHADOW",
radius: 5,
spread: 1,
visible: false,
offset: { x: 3, y: 4 },
color: { r: 1, g: 1, b: 1, a: 1 },
blendMode: "NORMAL",
} satisfies figma.ShadowEffect,
],
};
const preferences: Preferences = {
...defaultPreferenecs,
cssColorNotation: "hex",
};
expect(
fromNode(input, preferences).map((s) => serializeStyle(s, preferences)),
).not.toContain("box-shadow: 3px 4px 5px 1px #ffffff inset;");
});
});
});