1 | const postcssJs = require("postcss-js")
|
2 | const postcssPrefix = require('./lib/postcss-prefixer')
|
3 |
|
4 | const daisyuiInfo = require("../package.json");
|
5 | const colors = require("./colors/index");
|
6 | const utilities = require("../dist/utilities");
|
7 | const base = require("../dist/base");
|
8 | const unstyled = require("../dist/unstyled");
|
9 | const unstyledRtl = require("../dist/unstyled.rtl");
|
10 | const styled = require("../dist/styled");
|
11 | const styledRtl = require("../dist/styled.rtl");
|
12 | const utilitiesUnstyled = require("../dist/utilities-unstyled");
|
13 | const utilitiesStyled = require("../dist/utilities-styled");
|
14 | const themes = require("./colors/themes");
|
15 | const colorFunctions = require("./colors/functions");
|
16 |
|
17 | const mainFunction = ({ addBase, addComponents, addUtilities, config, postcss }) => {
|
18 | let diasyuiIncludedItems = [];
|
19 | let logs = false;
|
20 | if (config("daisyui.logs") != false) {
|
21 | logs = true;
|
22 | }
|
23 | if (logs) {
|
24 | console.log();
|
25 | console.log(
|
26 | "\x1b[35m%s\x1b[0m",
|
27 | "🌼 daisyUI components " + daisyuiInfo.version,
|
28 | "\x1b[0m",
|
29 | daisyuiInfo.homepage
|
30 | );
|
31 | console.group();
|
32 | }
|
33 |
|
34 |
|
35 | if (config("daisyui.base") != false) {
|
36 | addBase(base);
|
37 | diasyuiIncludedItems.push("base");
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 | let file = styled;
|
43 | if (config("daisyui.styled") == false && config("daisyui.rtl") != true) {
|
44 | diasyuiIncludedItems.push("unstyled components");
|
45 | file = unstyled;
|
46 | } else if (
|
47 | config("daisyui.styled") == false &&
|
48 | config("daisyui.rtl") == true
|
49 | ) {
|
50 | diasyuiIncludedItems.push("unstyled components");
|
51 | console.log("\x1b[36m%s\x1b[0m", " Direction:", "\x1b[0m", "RTL");
|
52 | file = unstyledRtl;
|
53 | } else if (
|
54 | config("daisyui.styled") != false &&
|
55 | config("daisyui.rtl") != true
|
56 | ) {
|
57 | diasyuiIncludedItems.push("components");
|
58 | file = styled;
|
59 | } else if (
|
60 | config("daisyui.styled") !== false &&
|
61 | config("daisyui.rtl") == true
|
62 | ) {
|
63 | diasyuiIncludedItems.push("components");
|
64 | console.log("\x1b[36m%s\x1b[0m", " Direction:", "\x1b[0m", "RTL");
|
65 | file = styledRtl;
|
66 | }
|
67 |
|
68 |
|
69 | const prefix = config("daisyui.prefix")
|
70 | let postcssJsProcess
|
71 | if (prefix) {
|
72 | try {
|
73 | postcssJsProcess = postcssJs.sync(postcssPrefix({ prefix, ignore: [] }))
|
74 | } catch (error) {
|
75 | logs && console.error(`Error occurred and prevent applying the "prefix" option:`, error)
|
76 | }
|
77 | }
|
78 | const shouldApplyPrefix = prefix && postcssJsProcess;
|
79 | if (shouldApplyPrefix) {
|
80 | file = postcssJsProcess(file)
|
81 | }
|
82 |
|
83 | addComponents(file);
|
84 |
|
85 | const themeInjector = colorFunctions.injectThemes(addBase, config, themes)
|
86 | themeInjector;
|
87 |
|
88 | diasyuiIncludedItems.push("themes[" + themeInjector.themeOrder.length + "]");
|
89 |
|
90 |
|
91 | if (config("daisyui.utils") != false) {
|
92 | addComponents(utilities, { variants: ["responsive"] });
|
93 |
|
94 | let toAdd = utilitiesUnstyled
|
95 | if (shouldApplyPrefix) {
|
96 | toAdd = postcssJsProcess(toAdd);
|
97 | }
|
98 | addComponents(toAdd, { variants: ["responsive"] });
|
99 |
|
100 | toAdd = utilitiesStyled
|
101 | if (shouldApplyPrefix) {
|
102 | toAdd = postcssJsProcess(toAdd);
|
103 | }
|
104 | addComponents(toAdd, { variants: ["responsive"] });
|
105 | diasyuiIncludedItems.push("utilities");
|
106 | }
|
107 | if (logs) {
|
108 | console.log(
|
109 | "\x1b[32m%s\x1b[0m",
|
110 | "✔︎ Including:",
|
111 | "\x1b[0m",
|
112 | "" + diasyuiIncludedItems.join(", ")
|
113 | );
|
114 | console.log();
|
115 | console.groupEnd();
|
116 | }
|
117 | };
|
118 |
|
119 | module.exports = require("tailwindcss/plugin")(mainFunction, {
|
120 | theme: { extend: { colors } },
|
121 | });
|