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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
use super::*;
impl TailwindInstruction {
#[inline(never)]
pub fn get_instance(&self) -> Result<Box<dyn TailwindInstance>> {
let element = self.view_elements();
let pattern = element.as_slice();
let arbitrary = self.view_arbitrary();
let neg = self.negative;
let instance = match pattern {
["aspect", rest @ ..] => TailwindAspect::parse(rest, arbitrary)?.boxed(),
["container"] => TailwindContainer::default().boxed(),
["columns", rest @ ..] => TailwindColumns::parse(rest, arbitrary)?.boxed(),
["break", rest @ ..] => TailwindBreak::parse(rest, arbitrary)?,
["box", rest @ ..] => Self::box_adaptor(rest, arbitrary)?,
["block"] => TailwindDisplay::from("block").boxed(),
["inline", "block"] => TailwindDisplay::from("inline-block").boxed(),
["inline"] => TailwindDisplay::from("inline").boxed(),
["flex"] => TailwindDisplay::from("flex").boxed(),
["inline", "flex"] => TailwindDisplay::from("inline-flex").boxed(),
["table"] => TailwindDisplay::from("table").boxed(),
["inline", "table"] => TailwindDisplay::from("inline-table").boxed(),
["table", "caption"] => TailwindDisplay::from("table-caption").boxed(),
["table", "cell"] => TailwindDisplay::from("table-cell").boxed(),
["table", "column"] => TailwindDisplay::from("table-column").boxed(),
["table", "column", "group"] => TailwindDisplay::from("table-column-group").boxed(),
["table", "footer", "group"] => TailwindDisplay::from("table-footer-group").boxed(),
["table", "header", "group"] => TailwindDisplay::from("table-header-group").boxed(),
["table", "row", "group"] => TailwindDisplay::from("table-row-group").boxed(),
["table", "row"] => TailwindDisplay::from("table-row").boxed(),
["flow", "root"] => TailwindDisplay::from("flow-root").boxed(),
["grid"] => TailwindDisplay::from("grid").boxed(),
["inline", "grid"] => TailwindDisplay::from("inline-grid").boxed(),
["contents"] => TailwindDisplay::from("contents").boxed(),
["list", "item"] => TailwindDisplay::from("inline-grid").boxed(),
["hidden"] => TailwindDisplay::from("hidden").boxed(),
["float", rest @ ..] => TailwindFloat::parse(rest, arbitrary)?.boxed(),
["clear", rest @ ..] => TailwindClear::parse(rest, arbitrary)?.boxed(),
["isolate"] => TailwindIsolation::from("isolate").boxed(),
["isolation", rest @ ..] => TailwindIsolation::parse(rest, arbitrary)?.boxed(),
["object", rest @ ..] => Self::object_adaptor(rest, arbitrary)?,
["overflow", rest @ ..] => Self::overflow_adaptor(rest, arbitrary)?,
["overscroll", rest @ ..] => Self::overscroll_adaptor(rest, arbitrary)?,
[s @ ("static" | "fixed" | "absolute" | "relative" | "sticky")] => TailwindPosition::from(*s).boxed(),
["inset", rest @ ..] => TailwindInset::parse(rest, arbitrary, neg)?.boxed(),
["top", rest @ ..] => TailwindTop::parse(rest, arbitrary, neg)?.boxed(),
["right", rest @ ..] => TailwindRight::parse(rest, arbitrary, neg)?.boxed(),
["bottom", rest @ ..] => TailwindBottom::parse(rest, arbitrary, neg)?.boxed(),
["left", rest @ ..] => TailwindLeft::parse(rest, arbitrary, neg)?.boxed(),
["visible"] => TailwindVisibility::from("visible").boxed(),
["invisible"] => TailwindVisibility::from("hidden").boxed(),
["z", rest @ ..] => TailwindZIndex::parse(rest, arbitrary, self.negative)?.boxed(),
["basis", rest @ ..] => TailwindBasis::parse(rest, arbitrary)?.boxed(),
["flex", rest @ ..] => TailwindFlex::adapt(rest, arbitrary)?,
["grow", rest @ ..] => TailWindGrow::parse(rest, arbitrary)?.boxed(),
["shrink", rest @ ..] => TailWindShrink::parse(rest, arbitrary)?.boxed(),
["order", rest @ ..] => TailWindOrder::parse(rest, arbitrary, self.negative)?.boxed(),
["grid", rest @ ..] => TailwindGrid::adapt(rest, arbitrary)?,
["col", rest @ ..] => TailwindColumn::parse(rest, arbitrary)?.boxed(),
["row", rest @ ..] => TailwindRow::parse(rest, arbitrary)?.boxed(),
["auto", rest @ ..] => TailwindGridAuto::parse(rest, arbitrary)?.boxed(),
["gap", rest @ ..] => TailwindGap::parse(rest, arbitrary)?.boxed(),
["justify", rest @ ..] => Self::justify_adaptor(rest, arbitrary)?,
["content", rest @ ..] => TailwindContent::adapt(rest, arbitrary)?,
["items", rest @ ..] => TailwindItems::parse(rest, arbitrary)?.boxed(),
["self", rest @ ..] => TailwindSelf::parse(rest, arbitrary)?.boxed(),
["place", rest @ ..] => TailwindPlace::parse(rest, arbitrary)?,
["p" | "pl" | "pr" | "pb" | "pt" | "px" | "py", ..] => TailwindPadding::parse(pattern, arbitrary, neg)?.boxed(),
["m" | "ml" | "mr" | "mb" | "mt" | "mx" | "my", ..] => TailwindMargin::parse(pattern, arbitrary, neg)?.boxed(),
["space", rest @ ..] => TailwindSpace::parse(rest, arbitrary, neg)?,
["w", rest @ ..] => TailwindSizing::parse_width(rest, arbitrary)?.boxed(),
["min", "w", rest @ ..] => TailwindSizing::parse_width_min(rest, arbitrary)?.boxed(),
["max", "w", rest @ ..] => TailwindSizing::parse_width_max(rest, arbitrary)?.boxed(),
["h", rest @ ..] => TailwindSizing::parse_width(rest, arbitrary)?.boxed(),
["min", "h", rest @ ..] => TailwindSizing::parse_width_min(rest, arbitrary)?.boxed(),
["max", "h", rest @ ..] => TailwindSizing::parse_width_max(rest, arbitrary)?.boxed(),
["font", rest @ ..] => font_adaptor(rest, arbitrary)?,
["text", rest @ ..] => text_adaptor(rest, arbitrary)?,
["antialiased"] => TailwindFontSmoothing::from("todo").boxed(),
["subpixel", "antialiased"] => TailwindFontSmoothing::from("todo").boxed(),
["italic"] => TailwindFontStyle::from("italic").boxed(),
["not", "italic"] => TailwindFontStyle::from("normal").boxed(),
["normal", "nums"] => TailwindFontVariantNumeric::from("normal").boxed(),
["ordinal"] => TailwindFontVariantNumeric::from("ordinal").boxed(),
["slashed", "zero"] => TailwindFontVariantNumeric::from("slashed-zero").boxed(),
["lining", "nums"] => TailwindFontVariantNumeric::from("lining-nums").boxed(),
["oldstyle", "nums"] => TailwindFontVariantNumeric::from("oldstyle-nums").boxed(),
["proportional", "nums"] => TailwindFontVariantNumeric::from("proportional-nums").boxed(),
["tabular", "nums"] => TailwindFontVariantNumeric::from("tabular-nums").boxed(),
["diagonal", "fractions"] => TailwindFontVariantNumeric::from("diagonal-fractions").boxed(),
["stacked", "fractions"] => TailwindFontVariantNumeric::from("stacked-fractions").boxed(),
["tracking", rest @ ..] => TailwindTracking::parse(rest, arbitrary)?.boxed(),
["leading", rest @ ..] => TailwindLeading::parse(rest, arbitrary)?.boxed(),
["list", rest @ ..] => TailwindList::parse(rest, arbitrary)?,
["underline"] => TailwindDecorationLine::from("underline").boxed(),
["overline"] => TailwindDecorationLine::from("overline").boxed(),
["line", "through"] => TailwindDecorationLine::from("line-through").boxed(),
["no", "underline"] => TailwindDecorationLine::from("none").boxed(),
["decoration", rest @ ..] => TailwindDecoration::parse(rest, arbitrary)?,
["underline", "offset", rest @ ..] => TailwindUnderlineOffset::parse(rest, arbitrary)?.boxed(),
["uppercase"] => TailwindTextTransform::from("uppercase").boxed(),
["lowercase"] => TailwindTextTransform::from("lowercase").boxed(),
["capitalize"] => TailwindTextTransform::from("capitalize").boxed(),
["normal", "case"] => TailwindTextTransform::from("none").boxed(),
["truncate"] => TailwindTextOverflow::Truncate.boxed(),
["indent", rest @ ..] => TailwindIndent::parse(rest, arbitrary)?.boxed(),
["align", rest @ ..] => TailwindAlign::parse(rest, arbitrary)?.boxed(),
["whitespace", rest @ ..] => TailwindWhiteSpace::parse(rest, arbitrary)?.boxed(),
["prose"] => todo!(),
["bg", rest @ ..] => Self::bg_adaptor(rest, arbitrary)?,
["from", rest @ ..] => TailwindFrom::parse(rest, arbitrary)?.boxed(),
["via", rest @ ..] => TailwindVia::parse(rest, arbitrary)?.boxed(),
["to", rest @ ..] => TailwindTo::parse(rest, arbitrary)?.boxed(),
["rounded", rest @ ..] => TailwindRounded::parse(rest, arbitrary)?.boxed(),
["border", rest @ ..] => TailwindBorder::adapt(rest, arbitrary)?,
["divide", rest @ ..] => TailwindDivide::parse(rest, arbitrary)?,
["outline", rest @ ..] => TailwindOutline::adapt(rest, arbitrary)?,
["ring", rest @ ..] => TailwindRing::adapt(rest, arbitrary)?,
["shadow", rest @ ..] => Self::shadow_adaptor(rest, arbitrary)?,
["opacity", rest @ ..] => TailwindOpacity::parse(rest, arbitrary, false)?.boxed(),
["mix", "blend", rest @ ..] => TailwindBlend::parse(rest, arbitrary)?.boxed(),
["blur", rest @ ..] => TailwindBlur::parse(rest, arbitrary, false)?.boxed(),
["brightness", rest @ ..] => TailwindBrightness::parse(rest, arbitrary, false)?.boxed(),
["contrast", rest @ ..] => TailwindContrast::parse(rest, arbitrary, false)?.boxed(),
["drop", "shadow", rest @ ..] => TailwindShadow::parse(rest, arbitrary, true)?.boxed(),
["grayscale", rest @ ..] => TailwindGrayscale::parse(rest, arbitrary, false)?.boxed(),
["hue", "rotate", rest @ ..] => TailwindHueRotate::parse(rest, arbitrary, false)?.boxed(),
["invert", rest @ ..] => TailwindInvert::parse(rest, arbitrary, false)?.boxed(),
["saturate", rest @ ..] => TailwindSaturate::parse(rest, arbitrary, false)?.boxed(),
["sepia", rest @ ..] => TailwindSepia::parse(rest, arbitrary, false)?.boxed(),
["backdrop", rest @ ..] => Self::backdrop_adaptor(rest, arbitrary)?,
["table", rest @ ..] => Self::table_adaptor(rest, arbitrary)?,
["transition", rest @ ..] => TailwindTransition::parse(rest, arbitrary)?.boxed(),
["duration", rest @ ..] => TailwindDuration::parse(rest, arbitrary)?.boxed(),
["ease", rest @ ..] => TailwindEase::parse(rest, arbitrary)?.boxed(),
["delay", rest @ ..] => TailwindDelay::parse(rest, arbitrary)?.boxed(),
["animate", rest @ ..] => TailwindAnimate::parse(rest, arbitrary)?.boxed(),
["scale", rest @ ..] => TailwindScale::parse(rest, arbitrary, neg)?.boxed(),
["rotate", rest @ ..] => TailwindRotate::parse(rest, arbitrary, neg)?.boxed(),
["translate", rest @ ..] => TailwindTranslate::parse(rest, arbitrary, neg)?.boxed(),
["skew", rest @ ..] => TailwindSkew::parse(rest, arbitrary, neg)?.boxed(),
["origin", rest @ ..] => TailwindOrigin::parse(rest, arbitrary)?.boxed(),
["accent", rest @ ..] => TailwindAccentColor::parse(rest, arbitrary)?.boxed(),
["appearance", rest @ ..] => TailwindAppearance::parse(rest, arbitrary)?.boxed(),
["cursor", rest @ ..] => TailwindCursor::parse(rest, arbitrary)?.boxed(),
["caret", rest @ ..] => TailwindCaretColor::parse(rest, arbitrary)?.boxed(),
["pointer", "events", rest @ ..] => TailwindPointerEvents::parse(rest, arbitrary)?.boxed(),
["resize", rest @ ..] => TailwindResize::parse(rest, arbitrary)?.boxed(),
["scroll", rest @ ..] => TailwindScroll::parse(rest, arbitrary, neg)?,
["snap", rest @ ..] => TailwindSnap::adapt(rest, arbitrary)?,
["touch", rest @ ..] => TailwindTorch::parse(rest, arbitrary)?.boxed(),
["select", rest @ ..] => TailwindSelect::parse(rest, arbitrary)?.boxed(),
["will", "change", rest @ ..] => TailwindWillChange::parse(rest, arbitrary)?.boxed(),
["fill", rest @ ..] => TailwindFillColor::parse(rest, arbitrary)?.boxed(),
["stroke", rest @ ..] => TailwindStroke::parse(rest, arbitrary)?,
["sr", "only"] => TailwindScreenReader::new(true).boxed(),
["not", "sr", "only"] => TailwindScreenReader::new(false).boxed(),
_ => return syntax_error!("Unknown instructions: {} + [{}]", element.join("-"), arbitrary),
};
Ok(instance)
}
#[inline]
fn bg_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
[s @ ("fixed" | "local" | "scroll")] => TailwindBackgroundAttachment::from(*s).boxed(),
["attach", rest @ ..] => TailwindBackgroundAttachment::parse(rest, arbitrary)?.boxed(),
["clip", "border"] => TailwindBackgroundClip::from("border-box").boxed(),
["clip", "padding"] => TailwindBackgroundClip::from("padding-box").boxed(),
["clip", "content"] => TailwindBackgroundClip::from("content-box").boxed(),
["clip", "text"] => TailwindBackgroundClip::from("text").boxed(),
["origin", rest @ ..] => TailwindBackgroundOrigin::parse(rest, arbitrary)?.boxed(),
["no", "repeat"] => TailwindBackgroundRepeat::from("repeat").boxed(),
["repeat", rest @ ..] => TailwindBackgroundRepeat::parse(rest, arbitrary)?.boxed(),
["auto"] => TailwindBackgroundSize::Auto.boxed(),
["cover"] => TailwindBackgroundSize::Cover.boxed(),
["contain"] => TailwindBackgroundSize::Contain.boxed(),
["blend", rest @ ..] => TailwindBackgroundBlend::parse(rest, arbitrary)?.boxed(),
_ => return syntax_error!("Unknown bg instructions: {}", str.join("-")),
};
Ok(out)
}
#[inline]
fn shadow_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
[] => todo!(),
["sm"] => todo!(),
_ => TailwindShadow::parse(str, arbitrary, false)?.boxed(),
};
Ok(out)
}
#[inline]
fn box_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
["decoration", rest @ ..] => TailwindBoxDecoration::parse(rest, arbitrary)?.boxed(),
["border"] => TailwindBoxSizing::from("border").boxed(),
["content"] => TailwindBoxSizing::from("content").boxed(),
_ => return syntax_error!("Unknown box instructions: {}", str.join("-")),
};
Ok(out)
}
#[inline]
fn justify_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
debug_assert!(arbitrary.is_none(), "forbidden arbitrary after justify");
let out = match str {
["items", rest @ ..] => TailwindJustifyItems::parse(rest, arbitrary)?.boxed(),
["self", rest @ ..] => TailwindJustifySelf::parse(rest, arbitrary)?.boxed(),
_ => TailwindJustifyContent::parse(str, arbitrary)?.boxed(),
};
Ok(out)
}
#[inline]
fn backdrop_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
debug_assert!(arbitrary.is_none(), "forbidden arbitrary after justify");
let out = match str {
["blur", rest @ ..] => TailwindBlur::parse(rest, arbitrary, true)?.boxed(),
["brightness", rest @ ..] => TailwindBrightness::parse(rest, arbitrary, true)?.boxed(),
["contrast", rest @ ..] => TailwindContrast::parse(rest, arbitrary, true)?.boxed(),
["grayscale", rest @ ..] => TailwindGrayscale::parse(rest, arbitrary, true)?.boxed(),
["hue", "rotate", rest @ ..] => TailwindHueRotate::parse(rest, arbitrary, true)?.boxed(),
["invert", rest @ ..] => TailwindInvert::parse(rest, arbitrary, true)?.boxed(),
["opacity", rest @ ..] => TailwindOpacity::parse(rest, arbitrary, true)?.boxed(),
["saturate", rest @ ..] => TailwindSaturate::parse(rest, arbitrary, true)?.boxed(),
["sepia", rest @ ..] => TailwindSepia::parse(rest, arbitrary, true)?.boxed(),
_ => return syntax_error!("Unknown backdrop instructions: {}", str.join("-")),
};
Ok(out)
}
#[inline]
fn table_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
[] => TailwindDisplay::from("table").boxed(),
_ => TailwindTableLayout::parse(str, arbitrary)?.boxed(),
};
Ok(out)
}
#[inline]
fn object_adaptor(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match pattern {
[s @ ("contain" | "cover" | "fill" | "none")] => TailwindObjectFit::from(*s).boxed(),
["scale", "down"] => TailwindObjectFit::from("scale-down").boxed(),
_ => TailwindObjectPosition::parse(pattern, arbitrary)?.boxed(),
};
Ok(out)
}
#[inline]
fn overflow_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
["x", pattern @ ..] => TailwindOverflow::parse(pattern, arbitrary, Some(true))?.boxed(),
["y", pattern @ ..] => TailwindOverflow::parse(pattern, arbitrary, Some(false))?.boxed(),
_ => TailwindOverflow::parse(str, arbitrary, None)?.boxed(),
};
Ok(out)
}
#[inline]
fn overscroll_adaptor(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
["x", pattern @ ..] => TailwindOverscroll::parse(pattern, arbitrary, Some(true))?.boxed(),
["y", pattern @ ..] => TailwindOverscroll::parse(pattern, arbitrary, Some(true))?.boxed(),
_ => TailwindOverscroll::parse(str, arbitrary, None)?.boxed(),
};
Ok(out)
}
}