/
factories.ts
254 lines (211 loc) · 5.55 KB
/
factories.ts
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import { TMPElement, TMPNode } from "./builder";
export enum Align {
Left = "left",
Center = "center",
Right = "right",
}
const hex = (h: number) => h.toString(16).padStart(2, "0");
/**
* Create a text element.
*/
export function text(node: TMPNode, parse = false) {
if (typeof node === "string") {
if (node.includes("<") && !parse) {
return new TMPElement("noparse", {}, node);
} else {
return node;
}
}
return new TMPElement("noparse", {}, node);
}
/**
* Create an alignment element.
*/
export function align(align: Align, ...content: TMPNode[]) {
return new TMPElement("align", { align }, content);
}
/**
* Create an alpha modulator element.
*/
export function alpha(alpha: string | number, ...content: TMPNode[]) {
return new TMPElement("alpha", { alpha }, content);
}
/**
* Create a colour element.
*/
export function color(
clr: string | [number, number, number, number],
...content: TMPNode[]
): TMPElement {
if (typeof clr === "string") {
return new TMPElement("color", { color: clr }, content);
}
const [r, g, b, a] = clr;
return color(hex(r) + hex(g) + hex(b) + hex(a), ...content);
}
/**
* Create a bold element.
*/
export function bold(...content: TMPNode[]) {
return new TMPElement("b", {}, content);
}
export { bold as b };
/**
* Create an italics element.
*/
export function italics(...content: TMPNode[]) {
return new TMPElement("i", {}, content);
}
export { italics as i };
/**
* Create a spacing element.
*/
export function spacing(spacing: string | number, ...content: TMPNode[]) {
return new TMPElement("cspace", { cspace: spacing }, content);
}
export { spacing as cspace };
/**
* Create a font element.
*/
export function font(face: string, ...content: TMPNode[]) {
return new TMPElement("font", { font: face }, content);
}
/**
* Create an indentation element.
*/
export function indent(indent: string | number, ...content: TMPNode[]) {
return new TMPElement("indent", { indent }, content);
}
/**
* Create a line height element.
*/
export function lnheight(height: string | number, ...content: TMPNode[]) {
return new TMPElement("line-height", { lineheight: height }, content);
}
/**
* Create a line indent element.
*/
export function lnindent(indent: string | number, ...content: TMPNode[]) {
return new TMPElement("line-indent", { "line-indent": indent }, content);
}
/**
* Create a link element.
*/
export function link(resource: string, ...content: TMPNode[]) {
return new TMPElement("link", { link: resource }, content);
}
/**
* Create a lowercase element.
*/
export function lowercase(...content: TMPNode[]) {
return new TMPElement("lowercase", {}, content);
}
/**
* Create an uppercase element.
*/
export function uppercase(...content: TMPNode[]) {
return new TMPElement("uppercase", {}, content);
}
/**
* Create a smallcaps element.
*/
export function smallcaps(...content: TMPNode[]) {
return new TMPElement("smallcaps", {}, content);
}
/**
* Create a margin element.
*/
export function margin(margin: string | number, ...content: TMPNode[]) {
return new TMPElement("margin", { margin }, content);
}
/**
* Create a highlight element.
*/
export function highlight(
color: string | [number, number, number, number],
...content: TMPNode[]
): TMPElement {
if (typeof color === "string") {
return new TMPElement("mark", { mark: color }, content);
}
const [r, g, b, a] = color;
return highlight(hex(r) + hex(g) + hex(b) + hex(a), ...content);
}
export { highlight as mark };
/**
* Create a monospace element.
*/
export function monospace(spacing: string | number, ...content: TMPNode[]) {
return new TMPElement("mspace", { mspace: spacing }, content);
}
export { monospace as mono };
/**
* Create a non-breaking space element.
*/
export function nbspace(...content: TMPNode[]) {
return new TMPElement("nobr", {}, content);
}
/**
* Create a page break element.
*/
export function nextpage() {
return new TMPElement("page", {});
}
/**
* Create a position element.
*/
export function pos(x: string | number, ...content: TMPNode[]) {
return new TMPElement("pos", { pos: x }, content);
}
/**
* Create a font size element.
*/
export function size(size: string | number, ...content: TMPNode[]) {
return new TMPElement("size", { size }, content);
}
/**
* Create a space element.
*/
export function space(space: string | number) {
return new TMPElement("space", { space });
}
/**
* Create a strikethrough element.
*/
export function strikethrough(...content: TMPNode[]) {
return new TMPElement("s", {}, content);
}
export { strikethrough as strike, strikethrough as st, strikethrough as s };
/**
* Create an underline element.
*/
export function underline(...content: TMPNode[]) {
return new TMPElement("u", {}, content);
}
export { underline as u };
/**
* Create a subscript element.
*/
export function subscript(...content: TMPNode[]) {
return new TMPElement("sub", {}, content);
}
export { subscript as sub };
/**
* Create a superscript element.
*/
export function superscript(...content: TMPNode[]) {
return new TMPElement("sup", {}, content);
}
export { superscript as sup };
/**
* Create a vertical offset element.
*/
export function voffset(offset: string | number, ...content: TMPNode[]) {
return new TMPElement("voffset", { voffset: offset }, content);
}
/**
* Create a width element.
*/
export function width(width: string | number, ...content: TMPNode[]) {
return new TMPElement("width", { width }, content);
}