-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
111 lines (102 loc) · 2.85 KB
/
index.js
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
/**
* clip-path
* The clip-path CSS property creates a clipping region
* that sets what part of an element should be shown.
* Parts that are inside the region are shown, while those outside are hidden.
* https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path
* */
const plugin = require("tailwindcss/plugin");
// globales del plugin
const className = "clip-path";
const cssRule = "clip-path";
//entradas de la configuracion
const myTheme = "clipPath";
const myThemeFunction = "clipPathFunc";
// clases de utilidad
const clipPath = {
none: "none",
margin: "margin-box",
padding: "padding-box",
content: "content-box",
fill: "fill-box",
stroke: "stroke-box",
view: "view-box",
inset: "inset(100px 50px)",
circle: "circle(50px at 0 100px)",
ellipse: "ellipse(50px 60px at 0 10% 20%)",
polygon: "polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)",
path: "path('M0.5,1 C0.5,1,0,0.7,0,0.3 A0.25,0.25,1,1,1,0.5,0.3 A0.25,0.25,1,1,1,1,0.3 C1,0.7,0.5,1,0.5,1 Z')",
inherit: "inherit",
initial: "initial",
revert: "revert",
"revert-layer": "revert-layer",
unset: "unset",
};
// clases con valores arbitrarios
const clipPathFunc = {
DEFAULT: "path",
inset: "inset",
circle: "circle",
ellipse: "ellipse",
polygon: "polygon",
url: "url",
};
module.exports = plugin(function ({ matchUtilities, addUtilities, theme, e }) {
function setRuleWithParams(withParams, className, cssRule) {
const ruleWithParams = Object.keys(withParams).reduce((result, key) => {
if (key == "DEFAULT") {
return {
...result,
[`${className}`]: (valor) => ({
[`${cssRule}`]: `${withParams[key]}(${valor})`,
}),
};
}
return {
...result,
[`${className}-${e(key)}`]: (valor) => ({
[`${cssRule}`]: `${withParams[key]}(${valor})`,
}),
};
}, {});
matchUtilities(ruleWithParams);
}
function setRule(values, className, cssRule) {
const utilidad = Object.keys(values).reduce((result, key) => {
if (key == "DEFAULT") {
return {
...result,
[`.${className}`]: {
[`${cssRule}`]: values[key],
},
};
}
if (typeof values[key] === "object") {
for (const subkey in values[key]) {
result = {
...result,
[`.${className}-${e(key)}-${e(subkey)}`]: {
[`${cssRule}`]: values[key][subkey],
},
};
}
return result;
}
return {
...result,
[`.${className}-${e(key)}`]: {
[`${cssRule}`]: values[key],
},
};
}, {});
addUtilities(utilidad);
}
// Utilidades
setRule({ ...theme(myTheme), ...clipPath }, className, cssRule);
// Valores arbitrarios
setRuleWithParams(
{ ...theme(myThemeFunction), ...clipPathFunc },
className,
cssRule
);
}, {});