Skip to content

Commit 20a1d9b

Browse files
committed
chore: remove pdf dependencies
1 parent c4c7793 commit 20a1d9b

11 files changed

Lines changed: 106 additions & 803 deletions

File tree

api/tailwind/alignment.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@ package tailwind
33
import (
44
"regexp"
55
"strings"
6+
)
7+
8+
// Type is a representation of a column align.
9+
type Alignment string
610

7-
"github.com/flanksource/maroto/v2/pkg/consts/align"
11+
const (
12+
// Left represents a left horizontal align.
13+
Left Alignment = "L"
14+
// Right represents a right horizontal align.
15+
Right Alignment = "R"
16+
// Center represents a center horizontal and/or vertical align.
17+
Center Alignment = "C"
18+
// Top represents a top vertical align.
19+
Top Alignment = "T"
20+
// Bottom represents a bottom vertical align.
21+
Bottom Alignment = "B"
22+
// Middle represents a middle align (from gofpdf).
23+
Middle Alignment = "M"
24+
// Justify represents a horizontal alignment that distributes
25+
// the text evenly between the left and right margins.
26+
Justify Alignment = "J"
827
)
928

1029
// Compiled regex patterns for alignment parsing
@@ -28,7 +47,7 @@ const (
2847

2948
// ParsedAlignment contains both horizontal and vertical alignment information
3049
type ParsedAlignment struct {
31-
Horizontal align.Type
50+
Horizontal Alignment
3251
Vertical VerticalAlign
3352
}
3453

@@ -44,14 +63,14 @@ func NewAlignmentParser() *AlignmentParser {
4463
func (ap *AlignmentParser) ParseAlignment(style string) ParsedAlignment {
4564
classes := strings.Fields(style)
4665
alignment := ParsedAlignment{
47-
Horizontal: align.Left, // Default horizontal alignment
66+
Horizontal: Left, // Default horizontal alignment
4867
Vertical: VerticalMiddle, // Default vertical alignment
4968
}
5069

5170
// Parse alignment classes - last one wins for conflicts
5271
for _, class := range classes {
5372
if parsed := ap.parseAlignmentClass(class); parsed != nil {
54-
if parsed.Horizontal != align.Left || class == "text-left" {
73+
if parsed.Horizontal != Left || class == "text-left" {
5574
alignment.Horizontal = parsed.Horizontal
5675
}
5776
if parsed.Vertical != VerticalMiddle || strings.Contains(class, "align-") {
@@ -64,18 +83,18 @@ func (ap *AlignmentParser) ParseAlignment(style string) ParsedAlignment {
6483
}
6584

6685
// stringToHorizontalAlign converts string to horizontal alignment type
67-
func stringToHorizontalAlign(s string) align.Type {
86+
func stringToHorizontalAlign(s string) Alignment {
6887
switch s {
6988
case "left":
70-
return align.Left
89+
return Left
7190
case "center":
72-
return align.Center
91+
return Center
7392
case "right":
74-
return align.Right
93+
return Right
7594
case "justify":
76-
return align.Justify
95+
return Justify
7796
default:
78-
return align.Left
97+
return Left
7998
}
8099
}
81100

@@ -111,7 +130,7 @@ func (ap *AlignmentParser) parseAlignmentClass(class string) *ParsedAlignment {
111130
// Try standalone vertical alignment pattern
112131
if matches := verticalAlignRegex.FindStringSubmatch(class); matches != nil {
113132
vertical := stringToVerticalAlign(matches[1])
114-
return &ParsedAlignment{Horizontal: align.Left, Vertical: vertical}
133+
return &ParsedAlignment{Horizontal: Left, Vertical: vertical}
115134
}
116135

117136
return nil

api/tailwind/alignment_test.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,130 +2,128 @@ package tailwind
22

33
import (
44
"testing"
5-
6-
"github.com/flanksource/maroto/v2/pkg/consts/align"
75
)
86

97
func TestParseAlignment(t *testing.T) {
108
tests := []struct {
119
name string
1210
input string
13-
expectedHoriz align.Type
11+
expectedHoriz Alignment
1412
expectedVert VerticalAlign
1513
}{
1614
// Basic horizontal alignments
1715
{
1816
name: "text-left",
1917
input: "text-left",
20-
expectedHoriz: align.Left,
18+
expectedHoriz: Left,
2119
expectedVert: VerticalMiddle,
2220
},
2321
{
2422
name: "text-center",
2523
input: "text-center",
26-
expectedHoriz: align.Center,
24+
expectedHoriz: Center,
2725
expectedVert: VerticalMiddle,
2826
},
2927
{
3028
name: "text-right",
3129
input: "text-right",
32-
expectedHoriz: align.Right,
30+
expectedHoriz: Right,
3331
expectedVert: VerticalMiddle,
3432
},
3533
{
3634
name: "text-justify",
3735
input: "text-justify",
38-
expectedHoriz: align.Justify,
36+
expectedHoriz: Justify,
3937
expectedVert: VerticalMiddle,
4038
},
4139

4240
// Basic vertical alignments
4341
{
4442
name: "align-top",
4543
input: "align-top",
46-
expectedHoriz: align.Left,
44+
expectedHoriz: Left,
4745
expectedVert: VerticalTop,
4846
},
4947
{
5048
name: "align-middle",
5149
input: "align-middle",
52-
expectedHoriz: align.Left,
50+
expectedHoriz: Left,
5351
expectedVert: VerticalMiddle,
5452
},
5553
{
5654
name: "align-bottom",
5755
input: "align-bottom",
58-
expectedHoriz: align.Left,
56+
expectedHoriz: Left,
5957
expectedVert: VerticalBottom,
6058
},
6159

6260
// Extended syntax combinations
6361
{
6462
name: "text-left-top",
6563
input: "text-left-top",
66-
expectedHoriz: align.Left,
64+
expectedHoriz: Left,
6765
expectedVert: VerticalTop,
6866
},
6967
{
7068
name: "text-center-middle",
7169
input: "text-center-middle",
72-
expectedHoriz: align.Center,
70+
expectedHoriz: Center,
7371
expectedVert: VerticalMiddle,
7472
},
7573
{
7674
name: "text-right-bottom",
7775
input: "text-right-bottom",
78-
expectedHoriz: align.Right,
76+
expectedHoriz: Right,
7977
expectedVert: VerticalBottom,
8078
},
8179

8280
// Complex style strings (should extract alignment)
8381
{
8482
name: "style with text-center",
8583
input: "font-bold text-center bg-gray-100",
86-
expectedHoriz: align.Center,
84+
expectedHoriz: Center,
8785
expectedVert: VerticalMiddle,
8886
},
8987
{
9088
name: "style with align-top",
9189
input: "w-[200px] align-top font-mono",
92-
expectedHoriz: align.Left,
90+
expectedHoriz: Left,
9391
expectedVert: VerticalTop,
9492
},
9593
{
9694
name: "style with both alignments",
9795
input: "text-right align-bottom font-bold",
98-
expectedHoriz: align.Right,
96+
expectedHoriz: Right,
9997
expectedVert: VerticalBottom,
10098
},
10199

102100
// No alignment specified (defaults)
103101
{
104102
name: "no alignment",
105103
input: "font-bold bg-gray-100",
106-
expectedHoriz: align.Left,
104+
expectedHoriz: Left,
107105
expectedVert: VerticalMiddle,
108106
},
109107

110108
// Empty string
111109
{
112110
name: "empty string",
113111
input: "",
114-
expectedHoriz: align.Left,
112+
expectedHoriz: Left,
115113
expectedVert: VerticalMiddle,
116114
},
117115

118116
// Multiple alignment classes (last one should win for conflicting properties)
119117
{
120118
name: "multiple horizontal alignments",
121119
input: "text-left text-center text-right",
122-
expectedHoriz: align.Right,
120+
expectedHoriz: Right,
123121
expectedVert: VerticalMiddle,
124122
},
125123
{
126124
name: "multiple vertical alignments",
127125
input: "align-top align-middle align-bottom",
128-
expectedHoriz: align.Left,
126+
expectedHoriz: Left,
129127
expectedVert: VerticalBottom,
130128
},
131129
}
@@ -149,31 +147,31 @@ func TestRealWorldStyleStrings(t *testing.T) {
149147
tests := []struct {
150148
name string
151149
input string
152-
expectedHoriz align.Type
150+
expectedHoriz Alignment
153151
expectedVert VerticalAlign
154152
}{
155153
{
156154
name: "table header style",
157155
input: "font-bold bg-gray-800 text-white text-center align-middle",
158-
expectedHoriz: align.Center,
156+
expectedHoriz: Center,
159157
expectedVert: VerticalMiddle,
160158
},
161159
{
162160
name: "table cell style",
163161
input: "w-[20ch] text-left align-middle font-medium",
164-
expectedHoriz: align.Left,
162+
expectedHoriz: Left,
165163
expectedVert: VerticalMiddle,
166164
},
167165
{
168166
name: "price column style",
169167
input: "w-[10ch] text-right align-middle font-mono",
170-
expectedHoriz: align.Right,
168+
expectedHoriz: Right,
171169
expectedVert: VerticalMiddle,
172170
},
173171
{
174172
name: "status column style",
175173
input: "w-[12ch] text-center align-top font-bold text-green-600",
176-
expectedHoriz: align.Center,
174+
expectedHoriz: Center,
177175
expectedVert: VerticalTop,
178176
},
179177
}

api/tailwind/parsers_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package tailwind
22

33
import (
44
"testing"
5-
6-
"github.com/flanksource/maroto/v2/pkg/consts/align"
75
)
86

97
// TestRegexBasedSpacingParser tests the refactored spacing parser using regex
@@ -75,37 +73,37 @@ func TestRegexBasedAlignmentParser(t *testing.T) {
7573
tests := []struct {
7674
name string
7775
class string
78-
expectedHorizontal align.Type
76+
expectedHorizontal Alignment
7977
expectedVertical VerticalAlign
8078
}{
8179
{
8280
name: "text-left using regex",
8381
class: "text-left",
84-
expectedHorizontal: align.Left,
82+
expectedHorizontal: Left,
8583
expectedVertical: VerticalMiddle,
8684
},
8785
{
8886
name: "text-center using regex",
8987
class: "text-center",
90-
expectedHorizontal: align.Center,
88+
expectedHorizontal: Center,
9189
expectedVertical: VerticalMiddle,
9290
},
9391
{
9492
name: "text-right-top using regex",
9593
class: "text-right-top",
96-
expectedHorizontal: align.Right,
94+
expectedHorizontal: Right,
9795
expectedVertical: VerticalTop,
9896
},
9997
{
10098
name: "text-center-bottom using regex",
10199
class: "text-center-bottom",
102-
expectedHorizontal: align.Center,
100+
expectedHorizontal: Center,
103101
expectedVertical: VerticalBottom,
104102
},
105103
{
106104
name: "align-middle using regex",
107105
class: "align-middle",
108-
expectedHorizontal: align.Left,
106+
expectedHorizontal: Left,
109107
expectedVertical: VerticalMiddle,
110108
},
111109
}

0 commit comments

Comments
 (0)