1 | const daisyuiInfo = require('./package.json')
|
2 | const colors = require('./colors/index')
|
3 | const utilities = require('./dist/utilities')
|
4 | const base = require('./dist/base')
|
5 | const unstyled = require('./dist/unstyled')
|
6 | const unstyledRtl = require('./dist/unstyled.rtl')
|
7 | const styled = require('./dist/styled')
|
8 | const styledRtl = require('./dist/styled.rtl')
|
9 | const utilitiesUnstyled = require('./dist/utilities-unstyled')
|
10 | const utilitiesStyled = require('./dist/utilities-styled')
|
11 | const themes = require('./colors/themes')
|
12 | const colorNames = require('./colors/colorNames')
|
13 | const hex2hsl = require('./colors/hex2hsl')
|
14 |
|
15 | const mainFunction = ({ addBase, addComponents, addUtilities, config }) => {
|
16 | let diasyuiIncludedItems = []
|
17 | let logs = false
|
18 | if (config('daisyui.logs') != false) {
|
19 | logs = true
|
20 | }
|
21 | if (logs) {
|
22 | console.log()
|
23 | console.log('\x1b[35m%s\x1b[0m', '🌼 DaisyUI components ' + daisyuiInfo.version, '\x1b[0m', daisyuiInfo.homepage)
|
24 | console.group()
|
25 | }
|
26 |
|
27 |
|
28 | if (config('daisyui.base') != false) {
|
29 | addBase(base)
|
30 | diasyuiIncludedItems.push('base')
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | let file = styled
|
36 | if (config('daisyui.styled') == false && config('daisyui.rtl') != true) {
|
37 | diasyuiIncludedItems.push('unstyled components')
|
38 | file = unstyled
|
39 | } else if (config('daisyui.styled') == false && config('daisyui.rtl') == true) {
|
40 | diasyuiIncludedItems.push('unstyled components')
|
41 | console.log('\x1b[36m%s\x1b[0m', ' Direction:', '\x1b[0m', 'RTL');
|
42 | file = unstyledRtl
|
43 | } else if (config('daisyui.styled') != false && config('daisyui.rtl') != true) {
|
44 | diasyuiIncludedItems.push('components')
|
45 | file = styled
|
46 | } else if (config('daisyui.styled') !== false && config('daisyui.rtl') == true) {
|
47 | diasyuiIncludedItems.push('components')
|
48 | console.log('\x1b[36m%s\x1b[0m', ' Direction:', '\x1b[0m', 'RTL');
|
49 | file = styledRtl
|
50 | }
|
51 | addComponents(file)
|
52 |
|
53 | let includedThemesObj = new Object()
|
54 |
|
55 | function convertThemeColorsToHsl(input) {
|
56 | let resultObj = {}
|
57 | if (typeof input === 'object' && input !== null) {
|
58 | Object.entries(input).forEach(([rule, value]) => {
|
59 | if(colorNames.hasOwnProperty(rule)){
|
60 | resultObj[colorNames[rule]] = hex2hsl(value)
|
61 | }else{
|
62 | resultObj[rule] = value
|
63 |
|
64 | }
|
65 | })
|
66 | return resultObj
|
67 | }
|
68 | return input
|
69 | }
|
70 |
|
71 |
|
72 | if (config('daisyui.themes') == false) {
|
73 | Object.entries(themes).forEach(([theme, index]) => {
|
74 | includedThemesObj[theme] = convertThemeColorsToHsl(themes[theme])
|
75 | });
|
76 | }
|
77 |
|
78 |
|
79 | if (config('daisyui.themes') != false) {
|
80 | Object.entries(themes).forEach(([theme, index]) => {
|
81 | includedThemesObj[theme] = convertThemeColorsToHsl(themes[theme])
|
82 | });
|
83 | }
|
84 |
|
85 |
|
86 | if(Array.isArray(config('daisyui.themes'))){
|
87 | config('daisyui.themes').forEach((item, index) => {
|
88 | if(typeof item === 'object' && item !== null){
|
89 | Object.entries(item).forEach(([customThemeName, customThemevalue]) => {
|
90 | includedThemesObj['[data-theme='+customThemeName+']'] = convertThemeColorsToHsl(customThemevalue)
|
91 | })
|
92 | }
|
93 | })
|
94 | }
|
95 |
|
96 | let themeOrder = []
|
97 | if (Array.isArray( config('daisyui.themes') )) {
|
98 | config('daisyui.themes').forEach((theme, index) => {
|
99 | if (typeof theme === 'object' && theme !== null){
|
100 | Object.entries(theme).forEach(([customThemeName, customThemevalue]) => {
|
101 | themeOrder.push(customThemeName)
|
102 | })
|
103 | }else if(includedThemesObj.hasOwnProperty('[data-theme='+theme+']')){
|
104 | themeOrder.push(theme)
|
105 | }
|
106 | })
|
107 | }else if (config('daisyui.themes') != false) {
|
108 | themeOrder= ['light','dark','cupcake','bumblebee','emerald','corporate','synthwave','retro','cyberpunk','valentine','halloween','garden','forest','aqua','lofi','pastel','fantasy','wireframe','black','luxury','dracula',]
|
109 | }else if (config('daisyui.themes') == false) {
|
110 | themeOrder.push('light')
|
111 | }
|
112 |
|
113 |
|
114 | themeOrder.forEach((themeName, index) => {
|
115 | if (index === 0) {
|
116 | addBase({[':root']: includedThemesObj['[data-theme='+themeName+']']})
|
117 | }else if (index === 1) {
|
118 |
|
119 | if (themeOrder[0] != 'dark' && themeOrder.includes('dark')){
|
120 | addBase({['@media (prefers-color-scheme: dark)']: {[':root']: includedThemesObj['[data-theme=dark]']}})
|
121 | }
|
122 |
|
123 | addBase({['[data-theme='+themeOrder[0]+']']: includedThemesObj['[data-theme='+themeOrder[0]+']']})
|
124 |
|
125 | addBase({['[data-theme='+themeOrder[1]+']']: includedThemesObj['[data-theme='+themeOrder[1]+']']})
|
126 | }else{
|
127 | addBase({['[data-theme='+themeName+']']: includedThemesObj['[data-theme='+themeName+']']})
|
128 | }
|
129 | })
|
130 | diasyuiIncludedItems.push('themes[' + themeOrder.length + ']')
|
131 |
|
132 |
|
133 |
|
134 | if (config('daisyui.utils') != false) {
|
135 | addComponents(utilities, { variants: ['responsive'] })
|
136 | addComponents(utilitiesUnstyled, { variants: ['responsive'] })
|
137 | addComponents(utilitiesStyled, { variants: ['responsive'] })
|
138 | diasyuiIncludedItems.push('utilities')
|
139 | }
|
140 | if (logs) {
|
141 | console.log('\x1b[32m%s\x1b[0m', '✔︎ Including:', '\x1b[0m', '' + diasyuiIncludedItems.join(', '));
|
142 | if (isTailwindInstalled === false) {
|
143 | console.log(`\n\x1b[33;1m! warning\x1b[0m - unable to require \x1b[36mtailwindcss/plugin\x1b[0m
|
144 | DaisyUI color are now only available for DaisyUI components.
|
145 | If you want to use DaisyUI color as utility classes (like 'bg-primary')
|
146 | you need to add this to your \x1b[34mtailwind.config.js\x1b[0m file:
|
147 | ───────────────────────────────────────
|
148 | \x1b[34mmodule.exports = {
|
149 | \x1b[32mtheme: {
|
150 | extend: {
|
151 | colors: require('daisyui/colors'),
|
152 | },
|
153 | },\x1b[0m
|
154 | \x1b[34m}\x1b[0m
|
155 | ───────────────────────────────────────
|
156 | `)
|
157 | }
|
158 | console.log()
|
159 | console.groupEnd()
|
160 | }
|
161 | }
|
162 |
|
163 |
|
164 | let isTailwindInstalled = false;
|
165 | try {
|
166 | require.resolve('tailwindcss/plugin')
|
167 | isTailwindInstalled = true
|
168 | } catch (er) {
|
169 | isTailwindInstalled = false
|
170 | }
|
171 | if (isTailwindInstalled !== false) {
|
172 | module.exports = require("tailwindcss/plugin")(
|
173 | mainFunction, { theme: { extend: { colors } } }
|
174 | );
|
175 | } else {
|
176 | module.exports = mainFunction;
|
177 | }
|
178 |
|