Skip to content

Commit 15e86fe

Browse files
author
Cem Yılmaz
committed
Added new plugins to support into plugins.ts
1 parent 6f18347 commit 15e86fe

File tree

3 files changed

+166
-11
lines changed

3 files changed

+166
-11
lines changed

src/parse.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const parse = (input: string, config?: Config): AST | Error => {
104104
if (valueWithoutModifier && valueWithoutModifier[0] === '[' && valueWithoutModifier[valueWithoutModifier.length - 1] === ']') {
105105
let arbitraryValue = valueWithoutModifier.slice(1, -1)
106106
const unitType = inferDataType(arbitraryValue, [...availablePlugins.values()].map(({type}) => type))
107-
const associatedPluginByType = availablePlugins!.find(plugin => plugin.type === unitType)
107+
let associatedPluginByType = availablePlugins!.find(plugin => plugin.type === unitType)
108108

109109
if (unitType === "color") {
110110
const color = CalculateHexFromString(arbitraryValue)
@@ -116,6 +116,12 @@ export const parse = (input: string, config?: Config): AST | Error => {
116116
}
117117
}
118118
valueWithoutModifier = findTailwindColorFromHex(color.hex, theme[associatedPluginByType?.scaleKey || "colors"]) || color.hex
119+
}else{
120+
//It's not color, but it's still an arbitrary. We are just going to do parse it
121+
//The result might not be correct, but it's better than nothing and even tailwind will parse it anyway
122+
if(availablePlugins.length > 0){
123+
associatedPluginByType = availablePlugins[0]
124+
}
119125
}
120126

121127
return {

src/plugins.ts

Lines changed: 153 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export const functionalPlugins = new Map<string, FunctionalPlugin[]>([
3636
["min-h", [
3737
{scaleKey: "minHeight", ns: 'minHeight', class: ['min-height'], type: 'length'},
3838
]],
39+
["max-h", [
40+
{scaleKey: "maxHeight", ns: 'maxHeight', class: ['max-height'], type: 'length'},
41+
]],
42+
["size", [
43+
{scaleKey: "size", ns: 'size', class: ['width', 'height'], type: 'length'},
44+
]],
3945
["m", [
4046
{scaleKey: "margin", ns: 'margin', class: ['margin'], type: 'length', supportNegative: true},
4147
]],
@@ -82,6 +88,16 @@ export const functionalPlugins = new Map<string, FunctionalPlugin[]>([
8288
{scaleKey: "fontSize", ns: 'fontSize', class: ['font-size'], type: 'length'},
8389
{scaleKey: "textColor", ns: 'textColor', class: ['color'], type: 'color'},
8490
]],
91+
["indent", [
92+
{scaleKey: "textIndent", ns: 'textIndent', class: ['text-indent'], type: 'length', supportNegative: true},
93+
]],
94+
["underline-offset", [
95+
{scaleKey: "textUnderlineOffset", ns: 'textUnderlineOffset', class: ['text-underline-offset'], type: 'number'},
96+
]],
97+
["decoration", [
98+
{scaleKey: "textDecorationThickness", ns: 'textDecorationThickness', class: ['text-decoration-thickness'], type: 'number'},
99+
{scaleKey: "textDecorationColor", ns: 'textDecorationColor', class: ['text-decoration-color'], type: 'color'},
100+
]],
85101
["font", [
86102
{scaleKey: "fontWeight", ns: 'fontWeight', class: ['font-weight'], type: 'number'},
87103
{scaleKey: "fontFamily", ns: 'fontFamily', class: ['font-family'], type: 'family-name'},
@@ -98,6 +114,18 @@ export const functionalPlugins = new Map<string, FunctionalPlugin[]>([
98114
{scaleKey: "backgroundSize", ns: 'backgroundSize', class: ['background-size'], type: 'bg-size'},
99115
{scaleKey: "backgroundColor", ns: 'backgroundColor', class: ['background-color'], type: 'color'},
100116
]],
117+
["from", [
118+
{scaleKey: "gradientColorStops", ns: 'gradientStopsFrom', class: ['--tw-gradient-from', '--tw-gradient-from-position'], type: 'color'},
119+
{scaleKey: "gradientColorStopPositions", ns: 'gradientColorFromStops', class: ['--tw-gradient-from', '--tw-gradient-from-position'], type: 'percentage'},
120+
]],
121+
["to", [
122+
{scaleKey: "gradientColorStops", ns: 'gradientStopsTo', class: ['--tw-gradient-to', '--tw-gradient-to-position'], type: 'color'},
123+
{scaleKey: "gradientColorStopPositions", ns: 'gradientColorToStops', class: ['--tw-gradient-from', '--tw-gradient-from-position'], type: 'percentage'},
124+
]],
125+
["via", [
126+
{scaleKey: "gradientColorStops", ns: 'gradientStopsVia', class: ['--tw-gradient-from'], type: 'color'},
127+
{scaleKey: "gradientColorStopPositions", ns: 'gradientColorViaStops', class: ['--tw-gradient-from', '--tw-gradient-from-position'], type: 'percentage'},
128+
]],
101129
["fill", [
102130
{scaleKey: "fill", ns: 'fillColor', class: ['fill'], type: 'color'},
103131
]],
@@ -138,6 +166,18 @@ export const functionalPlugins = new Map<string, FunctionalPlugin[]>([
138166
["gap-y", [
139167
{scaleKey: "gap", ns: 'gapY', class: ['gap'], type: 'length'},
140168
]],
169+
["divide-x", [
170+
{scaleKey: "divideWidth", ns: 'divideX', class: ['border-left-width', 'border-right-width'], type: 'length'},
171+
]],
172+
["divide-y", [
173+
{scaleKey: "divideWidth", ns: 'divideY', class: ['border-top-width', 'border-bottom-width'], type: 'length'},
174+
]],
175+
["divide", [
176+
{scaleKey: "divideColor", ns: 'divideColor', class: ['--tw-divide-color'], type: 'color'},
177+
]],
178+
["divide-opacity", [
179+
{scaleKey: "divideOpacity", ns: 'divideOpacity', class: ['--tw-divide-opacity'], type: 'number'},
180+
]],
141181
["col", [
142182
{scaleKey: "gridColumn", ns: 'gridColumn', class: ['grid-column'], type: 'number'},
143183
]],
@@ -157,9 +197,14 @@ export const functionalPlugins = new Map<string, FunctionalPlugin[]>([
157197
{scaleKey: "boxShadow", ns: 'boxShadow', class: ['box-shadow'], type: 'length'},
158198
]],
159199
["transition", [
160-
{scaleKey: "transitionProperty", ns: 'transitionProperty', class: ['transition-property'], type: 'number'},
200+
{scaleKey: "transitionProperty", ns: 'transitionProperty', class: ['transition-property'], type: 'named'},
201+
]],
202+
["duration", [
161203
{scaleKey: "transitionDuration", ns: 'transitionDuration', class: ['transition-duration'], type: 'number'},
162204
]],
205+
["delay", [
206+
{scaleKey: "transitionDelay", ns: 'transitionDelay', class: ['transition-delay'], type: 'number'},
207+
]],
163208
["scale", [
164209
{scaleKey: "scale", ns: 'scale', class: ['scale'], type: 'number', supportNegative: true},
165210
]],
@@ -217,17 +262,59 @@ export const functionalPlugins = new Map<string, FunctionalPlugin[]>([
217262
["order", [
218263
{scaleKey: "order", ns: 'order', class: ['order'], type: 'length', supportNegative: true},
219264
]],
265+
["blur", [
266+
{scaleKey: "blur", ns: 'blur', class: ['filter'], type: 'number'},
267+
]],
268+
["brightness", [
269+
{scaleKey: "brightness", ns: 'brightness', class: ['filter'], type: 'number'},
270+
]],
271+
["contrast", [
272+
{scaleKey: "contrast", ns: 'contrast', class: ['filter'], type: 'number'},
273+
]],
274+
["drop-shadow", [
275+
{scaleKey: "dropShadow", ns: 'dropShadow', class: ['filter'], type: 'number'},
276+
]],
277+
["hue-rotate", [
278+
{scaleKey: "hueRotate", ns: 'hueRotate', class: ['filter'], type: 'number'},
279+
]],
280+
["saturate", [
281+
{scaleKey: "saturate", ns: 'saturate', class: ['filter'], type: 'number'},
282+
]],
283+
["backdrop-blur", [
284+
{scaleKey: "blur", ns: 'blur', class: ['filter'], type: 'number'},
285+
]],
286+
["backdrop-brightness", [
287+
{scaleKey: "backdropBrightness", ns: 'backdropBrightness', class: ['backdrop-filter'], type: 'number'},
288+
]],
289+
["backdrop-contrast", [
290+
{scaleKey: "backdropContrast", ns: 'backdropContrast', class: ['backdrop-filter'], type: 'number'},
291+
]],
292+
["backdrop-drop-shadow", [
293+
{scaleKey: "backdropDropShadow", ns: 'backdropDropShadow', class: ['backdrop-filter'], type: 'number'},
294+
]],
295+
["backdrop-hue-rotate", [
296+
{scaleKey: "backdropHueRotate", ns: 'backdropHueRotate', class: ['backdrop-filter'], type: 'number'},
297+
]],
298+
["backdrop-saturate", [
299+
{scaleKey: "backdropSaturate", ns: 'backdropSaturate', class: ['backdrop-filter'], type: 'number'},
300+
]],
220301
]);
221302

222303
export const namedPlugins = new Map<string, NamedPlugin>([
223304
// Border Styles
224-
["border-solid", {class: ['border-style'], value: 'solid', ns: 'border'}],
225-
["border-dashed", {class: ['border-style'], value: 'dashed', ns: 'border'}],
226-
["border-dotted", {class: ['border-style'], value: 'dotted', ns: 'border'}],
227-
["border-double", {class: ['border-style'], value: 'double', ns: 'border'}],
228-
["border-none", {class: ['border-style'], value: 'none', ns: 'border'}],
305+
["border-solid", {class: ['border-style'], value: 'solid', ns: 'borderStyle'}],
306+
["border-dashed", {class: ['border-style'], value: 'dashed', ns: 'borderStyle'}],
307+
["border-dotted", {class: ['border-style'], value: 'dotted', ns: 'borderStyle'}],
308+
["border-double", {class: ['border-style'], value: 'double', ns: 'borderStyle'}],
309+
["border-none", {class: ['border-style'], value: 'none', ns: 'borderStyle'}],
229310
["ring-inset", {class: ['--tw-ring-inset'], value: 'inset', ns: 'ring'}],
230311

312+
["divide-solid", {class: ['divide-style'], value: 'solid', ns: 'divideStyle'}],
313+
["divide-dashed", {class: ['divide-style'], value: 'dashed', ns: 'divideStyle'}],
314+
["divide-dotted", {class: ['divide-style'], value: 'dotted', ns: 'divideStyle'}],
315+
["divide-double", {class: ['divide-style'], value: 'double', ns: 'divideStyle'}],
316+
["divide-none", {class: ['divide-style'], value: 'none', ns: 'divideStyle'}],
317+
231318
// Display
232319
["block", {class: ['display'], value: 'block', ns: 'display'}],
233320
["inline-block", {class: ['display'], value: 'inline-block', ns: 'display'}],
@@ -246,6 +333,25 @@ export const namedPlugins = new Map<string, NamedPlugin>([
246333
["visible", {class: ['visibility'], value: 'visible', ns: 'visibility'}],
247334
["invisible", {class: ['visibility'], value: 'hidden', ns: 'visibility'}],
248335

336+
// Hyphens
337+
["hyphens-none", {class: ['hyphens'], value: 'none', ns: 'hyphens'}],
338+
["hyphens-manual", {class: ['hyphens'], value: 'manual', ns: 'hyphens'}],
339+
["hyphens-auto", {class: ['hyphens'], value: 'auto', ns: 'hyphens'}],
340+
341+
// Word Break
342+
["break-normal", {class: ['word-break', 'overflow-wrap'], value: 'normal', ns: 'wordBreak'}],
343+
["break-words", {class: ['overflow-wrap'], value: 'break-word', ns: 'wordBreak'}],
344+
["break-all", {class: ['word-break'], value: 'break-all', ns: 'wordBreak'}],
345+
["break-keep", {class: ['word-break'], value: 'keep-all', ns: 'wordBreak'}],
346+
347+
// Whitespace
348+
["whitespace-normal", {class: ['white-space'], value: 'normal', ns: 'whitespace'}],
349+
["whitespace-nowrap", {class: ['white-space'], value: 'nowrap', ns: 'whitespace'}],
350+
["whitespace-pre", {class: ['white-space'], value: 'pre', ns: 'whitespace'}],
351+
["whitespace-pre-line", {class: ['white-space'], value: 'pre-line', ns: 'whitespace'}],
352+
["whitespace-pre-wrap", {class: ['white-space'], value: 'pre-wrap', ns: 'whitespace'}],
353+
["whitespace-break-spaces", {class: ['white-space'], value: 'break-spaces', ns: 'whitespace'}],
354+
249355
// Position
250356
["static", {class: ['position'], value: 'static', ns: 'position'}],
251357
["fixed", {class: ['position'], value: 'fixed', ns: 'position'}],
@@ -267,10 +373,30 @@ export const namedPlugins = new Map<string, NamedPlugin>([
267373
["overflow-y-visible", {class: ['overflow-y'], value: 'visible', ns: 'overflowY'}],
268374
["overflow-y-scroll", {class: ['overflow-y'], value: 'scroll', ns: 'overflowY'}],
269375

376+
// Text Align
377+
["text-left", {class: ['text-align'], value: 'left', ns: 'textAlign'}],
378+
["text-center", {class: ['text-align'], value: 'center', ns: 'textAlign'}],
379+
["text-right", {class: ['text-align'], value: 'right', ns: 'textAlign'}],
380+
["text-justify", {class: ['text-align'], value: 'justify', ns: 'textAlign'}],
381+
["text-start", {class: ['text-align'], value: 'start', ns: 'textAlign'}],
382+
["text-end", {class: ['text-align'], value: 'end', ns: 'textAlign'}],
383+
270384
// Text Decoration
271-
["underline", {class: ['text-decoration'], value: 'underline', ns: 'textDecoration'}],
272-
["line-through", {class: ['text-decoration'], value: 'line-through', ns: 'textDecoration'}],
273-
["no-underline", {class: ['text-decoration'], value: 'none', ns: 'textDecoration'}],
385+
["underline", {class: ['text-decoration-line'], value: 'underline', ns: 'textDecoration'}],
386+
["line-through", {class: ['text-decoration-line'], value: 'line-through', ns: 'textDecoration'}],
387+
["overline", {class: ['text-decoration-line'], value: 'overline', ns: 'textDecoration'}],
388+
["no-underline", {class: ['text-decoration-line'], value: 'none', ns: 'textDecoration'}],
389+
390+
// Text Wrap
391+
["text-wrap", {class: ['text-wrap'], value: 'wrap', ns: 'textWrap'}],
392+
["text-nowrap", {class: ['text-wrap'], value: 'nowrap', ns: 'textWrap'}],
393+
["text-balance", {class: ['text-wrap'], value: 'balance', ns: 'textWrap'}],
394+
["text-pretty", {class: ['text-wrap'], value: 'pretty', ns: 'textWrap'}],
395+
396+
// Text Overflow
397+
["truncate", {class: ['overflow', 'text-overflow', 'white-space'], value: '', ns: 'TextOverflow'}],
398+
["text-ellipsis", {class: ['text-overflow'], value: 'ellipsis', ns: 'textWrap'}],
399+
["text-clip", {class: ['text-overflow'], value: 'clip', ns: 'textWrap'}],
274400

275401
// Text Transform
276402
["uppercase", {class: ['text-transform'], value: 'uppercase', ns: 'textTransform'}],
@@ -331,6 +457,24 @@ export const namedPlugins = new Map<string, NamedPlugin>([
331457
["flex-shrink", {class: ['flex-shrink'], value: '1', ns: 'flexShrink'}],
332458
["flex-shrink-0", {class: ['flex-shrink'], value: '0', ns: 'flexShrink'}],
333459

460+
// Filters
461+
["grayscale", {class: ['filter'], value: 'grayscale(100%)', ns: 'grayScale'}],
462+
["grayscale-0", {class: ['filter'], value: 'grayscale(0)', ns: 'grayScale'}],
463+
["invert", {class: ['filter'], value: 'invert(100%)', ns: 'invert'}],
464+
["invert-0", {class: ['filter'], value: 'invert(0)', ns: 'invert'}],
465+
["sepia", {class: ['filter'], value: 'sepia(100%)', ns: 'sepia'}],
466+
["sepia-0", {class: ['filter'], value: 'sepia(0)', ns: 'sepia'}],
467+
["backdrop-grayscale", {class: ['backdrop-filter'], value: 'backdrop-grayscale(100%)', ns: 'backdropGrayScale'}],
468+
["backdrop-grayscale-0", {class: ['backdrop-filter'], value: 'backdrop-grayscale(0)', ns: 'backdropGrayScale'}],
469+
["backdrop-invert", {class: ['backdrop-filter'], value: 'backdrop-invert(100%)', ns: 'backdrop-invert'}],
470+
["backdrop-invert-0", {class: ['backdrop-filter'], value: 'backdrop-invert(0)', ns: 'backdrop-invert'}],
471+
["backdrop-sepia", {class: ['backdrop-filter'], value: 'backdrop-sepia(100%)', ns: 'backdrop-sepia'}],
472+
["backdrop-sepia-0", {class: ['backdrop-filter'], value: 'backdrop-sepia(0)', ns: 'backdrop-sepia'}],
473+
474+
["ease-linear", {class: ['transition-timing-function'], value: 'linear', ns: 'transitionTiming'}],
475+
["ease-in", {class: ['transition-timing-function'], value: 'cubic-bezier(0.4, 0, 1, 1)', ns: 'transitionTiming'}],
476+
["ease-out", {class: ['transition-timing-function'], value: 'cubic-bezier(0, 0, 0.2, 1)', ns: 'transitionTiming'}],
477+
["ease-in-out", {class: ['transition-timing-function'], value: 'cubic-bezier(0.4, 0, 0.2, 1)', ns: 'transitionTiming'}],
334478
])
335479

336480
export const variants = new Map<string, Variant["type"]>([

src/utils/string-builder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ export class StringBuilder {
5555

5656
}
5757

58+
static makeInputArbitraryFormat(input: string): string {
59+
//replace whitespaces with underscores
60+
return input.replace(/\s/g, '_')
61+
}
62+
5863
static makeArbitrary(input: string) {
59-
return "[" + input + "]"
64+
return "[" + StringBuilder.makeInputArbitraryFormat(input) + "]"
6065
}
6166
}

0 commit comments

Comments
 (0)